001: package tide.exttools.JLint;
002:
003: import tide.project.*;
004: import tide.editor.*;
005: import javax.swing.*;
006: import java.awt.BorderLayout;
007: import java.awt.FlowLayout;
008: import java.awt.Insets;
009: import java.awt.event.*;
010: import javax.swing.border.*;
011: import java.util.*;
012: import java.io.*;
013: import snow.utils.*;
014: import snow.utils.storage.*;
015: import snow.utils.gui.*;
016:
017: /** The settings of JLint
018: */
019: public class JLintSettingsDialog extends JDialog {
020: private final FileField jlintPath = new FileField("", false,
021: "Give the JLint executable path", JFileChooser.FILES_ONLY);
022: final private JButton viewOpts = new JButton("available options");
023: private final ProgressModalDialog pmd; // NOPMD
024:
025: private final JTextArea ignoredSubstringsTA = new JTextArea(5, 35);
026: public boolean dialogWasAccepted = false;
027:
028: public final static String defaultJLintLocation = "c:/java/jlint/jlint.exe";
029: public final static String homepage = "http://jlint.sourceforge.net/";
030: public final static String directDownloadLink = "http://switch.dl.sourceforge.net/sourceforge/jlint/jlint-3.0-bin-windows.zip";
031:
032: public JLintSettingsDialog(final JFrame parent,
033: final ProjectSettings settings) {
034: super (parent, "JLint static checker", true);
035: pmd = new ProgressModalDialog(parent, "JLint analysis");
036:
037: JComponent ta = GUIUtils
038: .createReadOnlyDescriptionArea("JLint is an external tool available at "
039: + homepage
040: + " ."
041: + "\r\nIt checks class files for common problems and potential optimizations.");
042: add(ta, BorderLayout.NORTH);
043:
044: JPanel inputPanel = new JPanel();
045: add(inputPanel, BorderLayout.CENTER);
046: GridLayout3 gl3 = new GridLayout3(2, inputPanel);
047:
048: JButton help = new JButton("JLint Homepage", Icons
049: .createHelpIcon(16, true));
050: help.setMargin(new Insets(0, 2, 0, 2));
051: help.setFocusPainted(false);
052: gl3.addSeparator();
053: gl3.add(help);
054: gl3.addSeparator();
055: help.addActionListener(new ActionListener() {
056: public void actionPerformed(ActionEvent ae) {
057: try {
058: SysUtils.openBrowser(homepage);
059: } catch (Exception e) {
060: JOptionPane.showMessageDialog(null,
061: "Can't open browser for " + homepage
062: + "\nerr:" + e.getMessage(),
063: "Error", JOptionPane.ERROR_MESSAGE);
064: }
065: }
066: });
067:
068: gl3.addSeparator();
069:
070: gl3.add("JLint application");
071: gl3.add(jlintPath);
072: jlintPath.setPath(settings.getProperty("JLint_path",
073: defaultJLintLocation));
074: if (MainEditorFrame.instance != null) {
075: jlintPath.offerRememberedGlobalCompletion(
076: MainEditorFrame.instance.globalProperties,
077: "knownJLints");
078: }
079: jlintPath.setComponentWidth(350);
080: jlintPath.setAutoColorized();
081: if (SysUtils.is_Windows_OS()) {
082: jlintPath.allowedExtensions.add("exe");
083: jlintPath.fileTypeDescription = "Windows executables";
084: }
085:
086: gl3.add("Options");
087: JPanel argumentsPanel = new JPanel(new FlowLayout(
088: FlowLayout.LEFT, 0, 0));
089: viewOpts.setMargin(new Insets(0, 2, 0, 2));
090: viewOpts.setFocusPainted(false);
091: JTextField argsField = new JTextField(settings.getProperty(
092: "JLint_Options", ""), 25);
093: gl3.add(argumentsPanel);
094: argumentsPanel.add(argsField);
095: argumentsPanel.add(viewOpts);
096: viewOpts.addActionListener(new ActionListener() {
097: public void actionPerformed(ActionEvent ae) {
098: displayOptions();
099: }
100: });
101:
102: gl3.add("");
103: final JCheckBox autoRemIrrelevant = new JCheckBox(
104: "Auto remove messages declared as irrelevant", settings
105: .getBooleanProperty("JLint_ignoreIrrelevant",
106: false));
107: gl3.add(autoRemIrrelevant);
108:
109: gl3.add("Ignored substrings");
110: gl3.add(new JScrollPane(ignoredSubstringsTA));
111: ignoredSubstringsTA.setText(settings.getProperty(
112: "JLint_ignoredSubstrings", getStandardIgnoring()));
113: ignoredSubstringsTA.setCaretPosition(0);
114:
115: final CloseControlPanel ccp = new CloseControlPanel(this , true,
116: true, "Ok");
117: add(ccp, BorderLayout.SOUTH);
118:
119: pack();
120: this .setLocationRelativeTo(parent);
121: this .setVisible(true); // MODAL => waits
122:
123: if (ccp.getWasCancelled())
124: return;
125: dialogWasAccepted = true;
126:
127: // save settings
128: settings.setProperty("JLint_path", jlintPath.getPath()
129: .getAbsolutePath());
130: settings.setProperty("JLint_Options", argsField.getText());
131: settings.setProperty("JLint_ignoredSubstrings",
132: ignoredSubstringsTA.getText());
133: settings.setBooleanProperty("JLint_ignoreIrrelevant",
134: autoRemIrrelevant.isSelected());
135:
136: jlintPath.rememberPathForGlobalCompletion(
137: MainEditorFrame.instance.globalProperties,
138: "knownJLints");
139:
140: } // Constructor
141:
142: /** @return true if jlint path is present.
143: Used to detect if a setup dialog should be shown when starting the tool (if not found).
144: */
145: public static boolean isConfigured() {
146: ProjectSettings actualProject = MainEditorFrame.instance
147: .getActualProject();
148: return new File(actualProject.getProperty("JLint_path",
149: defaultJLintLocation)).exists();
150: }
151:
152: /** @return the lines, ignoring blanks
153: */
154: public static List<String> getLines(String text) {
155: List<String> lt = new ArrayList<String>();
156: BufferedReader br = new BufferedReader(new StringReader(text));
157: String line = null;
158: try {
159: while ((line = br.readLine()) != null) {
160: String ltr = line.trim();
161: if (ltr.length() > 0) {
162: lt.add(ltr);
163: }
164: }
165: } catch (Exception egn) {
166: egn.printStackTrace();
167: }
168: return lt;
169: }
170:
171: public static String getStandardIgnoring() {
172: return "Method javax/swing/JPanel.add(java.awt.Component) is not overridden by method with the same name of derived class"
173: + "\r\nimplementing 'Runnable' interface is not synchronized";
174: }
175:
176: /** read the options from command line
177: */
178: private void displayOptions() {
179: //ProjectSettings actualProject = MainEditorFrame.instance.getActualProject();
180: StringBuilder comp = new StringBuilder();
181: try {
182: Vector<String> args = new Vector<String>();
183: args.add(jlintPath.getPath().getAbsolutePath());
184: args.add("-help");
185: comp.append(ProcessUtils.readWholeProcessStack(args));
186: //? comp.append("\r\nYou can also pass the option -J-Xmx256m to increase the memory for large projects doc creation");
187: } catch (Exception e) {
188: comp.append("\r\nError: " + e.getMessage());
189: e.printStackTrace();
190: }
191:
192: JDialog optionsDialog = new JDialog(this ,
193: "Available JLint options", false);
194: JTextPane tp = new JTextPane();
195: tp.setFont(MainEditorFrame.fixedWidthFontForProcesses);
196: tp.setText(comp.toString().trim());
197: optionsDialog.add(new JScrollPane(tp), BorderLayout.CENTER);
198: CloseControlPanel ccp = new CloseControlPanel(optionsDialog,
199: false, true, "Close");
200: optionsDialog.add(ccp, BorderLayout.SOUTH);
201: tp.setEditable(false);
202: tp.setCaretPosition(0);
203: optionsDialog.setSize(800, 550);
204: optionsDialog.setLocationRelativeTo(viewOpts);
205: optionsDialog.setVisible(true);
206: }
207:
208: /*test* public static void main(String[] aa)
209: {
210: JFrame f = new JFrame("Test");
211: f.setDefaultCloseOperation(f.EXIT_ON_CLOSE);
212: ProjectSettings props = new ProjectSettings();
213: new JLintSettingsDialog(f, props);
214: System.exit(0);
215: }*/
216:
217: }
|