diff --git a/pmd-jedit/config/pmd.props b/pmd-jedit/config/pmd.props
index 5180b3897f..72d1d4bad3 100644
--- a/pmd-jedit/config/pmd.props
+++ b/pmd-jedit/config/pmd.props
@@ -7,7 +7,7 @@ plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.version=0.7
plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.docs=jedit.html
plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.depend.0=jdk 1.3
plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.depend.1=jedit 04.00.99.00
-plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.jars=pmd-0.7.jar
+plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.jars=pmd-0.8.jar
#
# Menu properties
diff --git a/pmd-jedit/etc/build.xml b/pmd-jedit/etc/build.xml
index c8b8f139c8..f8991d799d 100644
--- a/pmd-jedit/etc/build.xml
+++ b/pmd-jedit/etc/build.xml
@@ -4,7 +4,7 @@
-
+
diff --git a/pmd-jedit/src/net/sourceforge/pmd/jedit/PMDJEditPlugin.java b/pmd-jedit/src/net/sourceforge/pmd/jedit/PMDJEditPlugin.java
index a904375660..3fbc4e4905 100644
--- a/pmd-jedit/src/net/sourceforge/pmd/jedit/PMDJEditPlugin.java
+++ b/pmd-jedit/src/net/sourceforge/pmd/jedit/PMDJEditPlugin.java
@@ -25,8 +25,8 @@ public class PMDJEditPlugin extends EditPlugin {
public static final String NAME = "PMD";
public static final String PROPERTY_PREFIX = "plugin.net.sourceforge.pmd.jedit.";
- public static final String OPTION_RULESETS_PREFIX = "options.pmd.rulesets.";
-
+ public static final String OPTION_RULES_PREFIX = "options.pmd.rules.";
+
public static class JavaFileOrDirectoryFilter implements FilenameFilter {
public boolean accept(File dir, String filename) {
return filename.endsWith("java") || (new File(dir.getAbsolutePath() + System.getProperty("file.separator") + filename).isDirectory());
@@ -41,13 +41,13 @@ public class PMDJEditPlugin extends EditPlugin {
}
private DefaultErrorSource errorSource;
-
+
// boilerplate JEdit code
public void start() {
errorSource = new DefaultErrorSource(NAME);
ErrorSource.registerErrorSource(errorSource);
}
-
+
public void createMenuItems(Vector menuItems) {
menuItems.addElement(GUIUtilities.loadMenu("pmd-menu"));
}
@@ -68,7 +68,7 @@ public class PMDJEditPlugin extends EditPlugin {
JOptionPane.showMessageDialog(jEdit.getFirstView(), "Can't run PMD on a directory unless the file browser is open", NAME, JOptionPane.ERROR_MESSAGE);
return;
}
- processFiles(findFilesInDirectory(browser.getDirectory()), browser);
+ processFiles(findFilesInDirectory(browser.getDirectory()));
}
public static void checkDirectoryRecursively(View view) {
@@ -82,7 +82,7 @@ public class PMDJEditPlugin extends EditPlugin {
JOptionPane.showMessageDialog(jEdit.getFirstView(), "Can't run PMD on a directory unless the file browser is open", NAME, JOptionPane.ERROR_MESSAGE);
return;
}
- processFiles(findFilesRecursively(browser.getDirectory()), browser);
+ processFiles(findFilesRecursively(browser.getDirectory()));
}
public static void check(Buffer buffer, View view) {
@@ -94,11 +94,11 @@ public class PMDJEditPlugin extends EditPlugin {
errorSource.clear();
PMD pmd = new PMD();
- SelectedRuleSetsMap selectedRuleSets = new SelectedRuleSetsMap();
+ SelectedRules selectedRuleSets = new SelectedRules();
RuleContext ctx = new RuleContext();
ctx.setReport(new Report());
ctx.setSourceCodeFilename(buffer.getPath());
- pmd.processFile(new StringReader(view.getTextArea().getText()), selectedRuleSets.getSelectedRuleSets(), ctx);
+ pmd.processFile(new StringReader(view.getTextArea().getText()), selectedRuleSets.getSelectedRules(), ctx);
if (ctx.getReport().isEmpty()) {
JOptionPane.showMessageDialog(jEdit.getFirstView(), "No problems found", "PMD", JOptionPane.INFORMATION_MESSAGE);
errorSource.clear();
@@ -113,13 +113,13 @@ public class PMDJEditPlugin extends EditPlugin {
rsne.printStackTrace();
}
}
-
- private void processFiles(List files, VFSBrowser browser) {
+
+ private void processFiles(List files) {
errorSource.clear();
PMD pmd = new PMD();
- SelectedRuleSetsMap selectedRuleSets = null;
+ SelectedRules selectedRuleSets = null;
try {
- selectedRuleSets = new SelectedRuleSetsMap();
+ selectedRuleSets = new SelectedRules();
} catch (RuleSetNotFoundException rsne) {
// should never happen since rulesets are fetched via getRegisteredRuleSet, nonetheless:
System.out.println("PMD ERROR: Couldn't find a ruleset");
@@ -136,7 +136,7 @@ public class PMDJEditPlugin extends EditPlugin {
ctx.setReport(new Report());
ctx.setSourceCodeFilename(file.getAbsolutePath());
try {
- pmd.processFile(new FileInputStream(file), selectedRuleSets.getSelectedRuleSets(), ctx);
+ pmd.processFile(new FileInputStream(file), selectedRuleSets.getSelectedRules(), ctx);
} catch (FileNotFoundException fnfe) {
// should never happen, but if it does, carry on to the next file
System.out.println("PMD ERROR: Unable to open file " + file.getAbsolutePath());
diff --git a/pmd-jedit/src/net/sourceforge/pmd/jedit/PMDOptionPane.java b/pmd-jedit/src/net/sourceforge/pmd/jedit/PMDOptionPane.java
index 0be0f94845..483be5e4cd 100644
--- a/pmd-jedit/src/net/sourceforge/pmd/jedit/PMDOptionPane.java
+++ b/pmd-jedit/src/net/sourceforge/pmd/jedit/PMDOptionPane.java
@@ -11,24 +11,57 @@ import org.gjt.sp.jedit.jEdit;
import org.gjt.sp.jedit.View;
import javax.swing.*;
+import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
import java.util.Map;
import java.util.HashMap;
import java.util.Iterator;
import net.sourceforge.pmd.RuleSetNotFoundException;
import net.sourceforge.pmd.RuleSet;
+import net.sourceforge.pmd.Rule;
public class PMDOptionPane extends AbstractOptionPane implements OptionPane {
- private SelectedRuleSetsMap selectedRuleSets;
+ public static class CheckboxList extends JList {
+ public class CheckboxListCellRenderer implements ListCellRenderer {
+ public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
+ JCheckBox box = (JCheckBox)value;
+ box.setEnabled(isEnabled());
+ box.setFont(getFont());
+ box.setFocusPainted(false);
+ box.setBorderPainted(true);
+ box.setBorder(isSelected ? UIManager.getBorder("List.focusCellHighlightBorder") : new EmptyBorder(1,1,1,1));
+ return box;
+ }
+ }
+
+ public CheckboxList(Object[] args) {
+ super(args);
+ setCellRenderer(new CheckboxListCellRenderer());
+ addMouseListener(new MouseAdapter() {
+ public void mousePressed(MouseEvent e) {
+ int index = locationToIndex(e.getPoint());
+ if (index != -1) {
+ JCheckBox box = (JCheckBox)getModel().getElementAt(index);
+ box.setSelected(!box.isSelected());
+ repaint();
+ }
+ }
+ });
+ }
+ }
+
+ private SelectedRules rules;
public PMDOptionPane() {
super(PMDJEditPlugin.NAME);
try {
- selectedRuleSets = new SelectedRuleSetsMap();
+ rules = new SelectedRules();
} catch (RuleSetNotFoundException rsne) {
rsne.printStackTrace();
}
@@ -36,17 +69,13 @@ public class PMDOptionPane extends AbstractOptionPane implements OptionPane {
public void init() {
removeAll();
- addComponent(new JLabel("Please see http://pmd.sourceforge.net/ for more information on what's in each rule set."));
- for (Iterator i = selectedRuleSets.keys(); i.hasNext();) {
- RuleSet rs = (RuleSet)i.next();
- JPanel oneBoxPanel = new JPanel();
- oneBoxPanel.add((JCheckBox)selectedRuleSets.get(rs));
- oneBoxPanel.add(new JLabel(rs.getDescription()));
- addComponent(oneBoxPanel);
- }
+ addComponent(new JLabel("Please see http://pmd.sf.net/ for more information"));
+ JList list = new CheckboxList(rules.getAllBoxes());
+ list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
+ addComponent(new JScrollPane(list));
}
public void save() {
- selectedRuleSets.save();
+ rules.save();
}
}
diff --git a/pmd-jedit/src/net/sourceforge/pmd/jedit/SelectedRuleSetsMap.java b/pmd-jedit/src/net/sourceforge/pmd/jedit/SelectedRuleSetsMap.java
deleted file mode 100644
index e4b3fe94e0..0000000000
--- a/pmd-jedit/src/net/sourceforge/pmd/jedit/SelectedRuleSetsMap.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * User: tom
- * Date: Jul 9, 2002
- * Time: 1:18:38 PM
- */
-package net.sourceforge.pmd.jedit;
-
-import org.gjt.sp.jedit.jEdit;
-
-import javax.swing.*;
-import java.util.*;
-import java.awt.Color;
-
-import net.sourceforge.pmd.RuleSetFactory;
-import net.sourceforge.pmd.RuleSet;
-import net.sourceforge.pmd.RuleSetNotFoundException;
-
-public class SelectedRuleSetsMap {
-
- private Map ruleSets = new TreeMap(new Comparator() {
- public int compare(Object o1, Object o2) {
- RuleSet r1 = (RuleSet)o1;
- RuleSet r2 = (RuleSet)o2;
- return r1.getName().compareTo(r2.getName());
- }
- });
-
- public SelectedRuleSetsMap() throws RuleSetNotFoundException {
- RuleSetFactory rsf = new RuleSetFactory();
- for (Iterator i = rsf.getRegisteredRuleSets(); i.hasNext();) {
- RuleSet rs = (RuleSet)i.next();
- ruleSets.put(rs, createCheckBox(rs.getName()));
- }
- }
-
- public Iterator keys() {
- return ruleSets.keySet().iterator();
- }
-
- public int size() {
- return ruleSets.size();
- }
-
- public JCheckBox get(Object key) {
- return (JCheckBox)ruleSets.get(key);
- }
-
- public void save() {
- for (Iterator i = keys(); i.hasNext();) {
- RuleSet rs = (RuleSet)i.next();
- jEdit.setBooleanProperty(PMDJEditPlugin.OPTION_RULESETS_PREFIX + rs.getName(), get(rs).isSelected());
- }
- }
-
- public RuleSet getSelectedRuleSets() {
- RuleSet newRuleSet = new RuleSet();
- for (Iterator i = keys(); i.hasNext();) {
- RuleSet rs = (RuleSet)i.next();
- if (get(rs).isSelected()) {
- newRuleSet.addRuleSet(rs);
- }
- }
- return newRuleSet;
- }
-
- private JCheckBox createCheckBox(String name) {
- JCheckBox box = new JCheckBox(name);
- box.setSelected(jEdit.getBooleanProperty(PMDJEditPlugin.OPTION_RULESETS_PREFIX + name, true));
- return box;
- }
-}
diff --git a/pmd-jedit/src/net/sourceforge/pmd/jedit/SelectedRules.java b/pmd-jedit/src/net/sourceforge/pmd/jedit/SelectedRules.java
new file mode 100644
index 0000000000..ec1c4ba24c
--- /dev/null
+++ b/pmd-jedit/src/net/sourceforge/pmd/jedit/SelectedRules.java
@@ -0,0 +1,81 @@
+/*
+ * User: tom
+ * Date: Jul 9, 2002
+ * Time: 1:18:38 PM
+ */
+package net.sourceforge.pmd.jedit;
+
+import org.gjt.sp.jedit.jEdit;
+
+import javax.swing.*;
+import java.util.*;
+import java.awt.Color;
+
+import net.sourceforge.pmd.RuleSetFactory;
+import net.sourceforge.pmd.RuleSet;
+import net.sourceforge.pmd.RuleSetNotFoundException;
+import net.sourceforge.pmd.Rule;
+
+public class SelectedRules {
+
+ private Map rules = new TreeMap(new Comparator() {
+ public int compare(Object o1, Object o2) {
+ Rule r1 = (Rule)o1;
+ Rule r2 = (Rule)o2;
+ return r1.getName().compareTo(r2.getName());
+ }
+ });
+
+ public SelectedRules() throws RuleSetNotFoundException {
+ RuleSetFactory rsf = new RuleSetFactory();
+ for (Iterator i = rsf.getRegisteredRuleSets(); i.hasNext();) {
+ RuleSet rs = (RuleSet)i.next();
+ for (Iterator j = rs.getRules().iterator(); j.hasNext();) {
+ Rule rule = (Rule)j.next();
+ rules.put(rule, createCheckBox(rule.getName()));
+ }
+ }
+ }
+
+ public int size() {
+ return rules.size();
+ }
+
+ public JCheckBox get(Object key) {
+ return (JCheckBox)rules.get(key);
+ }
+
+ public Object[] getAllBoxes() {
+ Object[] foo = new Object[rules.size()];
+ int idx = 0;
+ for (Iterator i = rules.values().iterator(); i.hasNext();) {
+ foo[idx] = i.next();
+ idx++;
+ }
+ return foo;
+ }
+
+ public void save() {
+ for (Iterator i = rules.keySet().iterator(); i.hasNext();) {
+ Rule rule = (Rule)i.next();
+ jEdit.setBooleanProperty(PMDJEditPlugin.OPTION_RULES_PREFIX + rule.getName(), get(rule).isSelected());
+ }
+ }
+
+ public RuleSet getSelectedRules() {
+ RuleSet newRuleSet = new RuleSet();
+ for (Iterator i = rules.keySet().iterator(); i.hasNext();) {
+ Rule rule = (Rule)i.next();
+ if (get(rule).isSelected()) {
+ newRuleSet.addRule(rule);
+ }
+ }
+ return newRuleSet;
+ }
+
+ private JCheckBox createCheckBox(String name) {
+ JCheckBox box = new JCheckBox(name);
+ box.setSelected(jEdit.getBooleanProperty(PMDJEditPlugin.OPTION_RULES_PREFIX + name, true));
+ return box;
+ }
+}