diff --git a/pmd-jedit/config/pmd.props b/pmd-jedit/config/pmd.props index 46f8e1c3ae..538086e4b9 100644 --- a/pmd-jedit/config/pmd.props +++ b/pmd-jedit/config/pmd.props @@ -16,3 +16,6 @@ pmd-menu=pmd.check - pmd.options pmd-menu.label=PMD pmd.check.label=$Check active buffer pmd.options.label=$Options + +options.pmd.label=PMD + diff --git a/pmd-jedit/src/net/sourceforge/pmd/jedit/PMDJEditPlugin.java b/pmd-jedit/src/net/sourceforge/pmd/jedit/PMDJEditPlugin.java index f2e92c1113..69647eb683 100644 --- a/pmd-jedit/src/net/sourceforge/pmd/jedit/PMDJEditPlugin.java +++ b/pmd-jedit/src/net/sourceforge/pmd/jedit/PMDJEditPlugin.java @@ -24,6 +24,7 @@ public class PMDJEditPlugin extends EBPlugin { public static final String MENU = "pmd-menu"; public static final String PROPERTY_PREFIX = "plugin.net.sourceforge.pmd.jedit."; public static final String OPTION_PREFIX = "options.pmd."; + public static final String OPTION_RULESETS_PREFIX = "options.pmd.rulesets."; private static PMDJEditPlugin instance = new PMDJEditPlugin(); @@ -39,29 +40,19 @@ public class PMDJEditPlugin extends EBPlugin { public void createMenuItems(Vector menuItems) { menuItems.addElement(GUIUtilities.loadMenu(MENU)); } - - public void createOptionPanes(OptionsDialog dialog) { - OptionGroup grp = new OptionGroup("PMD"); - grp.addOptionPane(new PMDOptionPane()); - dialog.addOptionGroup(grp); - } // boilerplate JEdit code public void instanceCheck(View view) { - String text = view.getTextArea().getText(); - PMD pmd = new PMD(); - ReportFactory rf = new ReportFactory(); RuleContext ctx = new RuleContext(); RuleSetFactory ruleSetFactory = new RuleSetFactory(); RuleSet rules = ruleSetFactory.createRuleSet(pmd.getClass().getClassLoader().getResourceAsStream("rulesets/unusedcode.xml")); - ctx.setReport(rf.createReport("xml")); ctx.setSourceCodeFilename("this"); try { // TODO switch to use StringReader once PMD 0.4 gets released - pmd.processFile(new StringBufferInputStream(text), rules, ctx); + pmd.processFile(new StringBufferInputStream(view.getTextArea().getText()), rules, ctx); StringBuffer msg = new StringBuffer(); for (Iterator i = ctx.getReport().iterator(); i.hasNext();) { @@ -78,7 +69,7 @@ public class PMDJEditPlugin extends EBPlugin { } public void instanceDisplayPreferencesDialog(View view) { - + PMDOptionPane options = new PMDOptionPane(); } diff --git a/pmd-jedit/src/net/sourceforge/pmd/jedit/PMDOptionPane.java b/pmd-jedit/src/net/sourceforge/pmd/jedit/PMDOptionPane.java index ae64f622ff..fc25eac01f 100644 --- a/pmd-jedit/src/net/sourceforge/pmd/jedit/PMDOptionPane.java +++ b/pmd-jedit/src/net/sourceforge/pmd/jedit/PMDOptionPane.java @@ -10,12 +10,70 @@ import org.gjt.sp.jedit.AbstractOptionPane; import org.gjt.sp.jedit.jEdit; import org.gjt.sp.jedit.View; +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionListener; +import java.awt.event.ActionEvent; +import java.util.Map; +import java.util.HashMap; +import java.util.Iterator; + public class PMDOptionPane extends AbstractOptionPane implements OptionPane { - private static final String NAME = "PMD Options"; + private static class SelectedRuleSetsMap { + private Map selections = new HashMap(); + + public SelectedRuleSetsMap() { + selections.put("basic", createCheckBox("basic")); + selections.put("unusedcode", createCheckBox("unusedcode")); + selections.put("design", createCheckBox("design")); + } + + public Iterator keys() { + return selections.keySet().iterator(); + } + + public int size() { + return selections.size(); + } + + public JCheckBox get(Object key) { + return (JCheckBox)selections.get(key); + } + + public void save() { + for (Iterator i = keys(); i.hasNext();) { + String key = (String)i.next(); + jEdit.setBooleanProperty(PMDJEditPlugin.OPTION_RULESETS_PREFIX + key, get(key).isSelected()); + } + } + + private JCheckBox createCheckBox(String name) { + JCheckBox box = new JCheckBox(); + box.setSelected(jEdit.getBooleanProperty(PMDJEditPlugin.OPTION_RULESETS_PREFIX + name, true)); + return box; + } + } + + private class SaveAL implements ActionListener { + public void actionPerformed(ActionEvent e) { + selectedRuleSets.save(); + } + } + + private class CloseAL implements ActionListener { + public void actionPerformed(ActionEvent e) { + JOptionPane.showMessageDialog(null, "hi"); + } + } + + private static final String NAME = "PMD Options"; + + private SelectedRuleSetsMap selectedRuleSets = new SelectedRuleSetsMap(); public PMDOptionPane() { super(NAME); + _init(); } public String getName() { @@ -23,13 +81,37 @@ public class PMDOptionPane extends AbstractOptionPane implements OptionPane { } public void _init() { - throw new RuntimeException("HI!!!!"); -/* - for (int i = 0; i < jEdit.getViews().length; i++) { - View v = jEdit.getViews()[i]; - v.getStatus().setMessage("HOWDY"); + super._init(); + + JPanel checkBoxPanel = new JPanel(); + checkBoxPanel.setBackground(Color.white); + checkBoxPanel.setLayout(new GridLayout(selectedRuleSets.size(), 2)); + for (Iterator i = selectedRuleSets.keys(); i.hasNext();) { + String key = (String)i.next(); + JPanel oneBoxPanel = new JPanel(); + oneBoxPanel.add(new JLabel(key, JLabel.LEFT)); + oneBoxPanel.add((JCheckBox)selectedRuleSets.get(key)); + checkBoxPanel.add(oneBoxPanel); } -*/ + + JButton saveButton = new JButton("Save"); + saveButton.addActionListener(new SaveAL()); + JPanel buttonPanel = new JPanel(); + buttonPanel.add(saveButton); + + JButton closeButton = new JButton("Close"); + closeButton.addActionListener(new CloseAL()); + buttonPanel.add(closeButton); + + JDialog dialog = new JDialog(jEdit.getFirstView(), "PMD", true); + dialog.setTitle("PMD"); + dialog.getContentPane().setLayout(new BorderLayout()); + dialog.getContentPane().add(checkBoxPanel, BorderLayout.CENTER); + dialog.getContentPane().add(buttonPanel, BorderLayout.SOUTH); + dialog.setSize(new Dimension(500,300)); + dialog.pack(); + dialog.setLocationRelativeTo(jEdit.getFirstView()); + dialog.setVisible(true); } } diff --git a/pmd-jedit/src/net/sourceforge/pmd/jedit/SelectedRuleSetsMap.java b/pmd-jedit/src/net/sourceforge/pmd/jedit/SelectedRuleSetsMap.java new file mode 100644 index 0000000000..e81e3aba01 --- /dev/null +++ b/pmd-jedit/src/net/sourceforge/pmd/jedit/SelectedRuleSetsMap.java @@ -0,0 +1,48 @@ +/* + * 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.Map; +import java.util.HashMap; +import java.util.Iterator; + +public class SelectedRuleSetsMap { + private Map selections = new HashMap(); + + public SelectedRuleSetsMap() { + selections.put("basic", createCheckBox("basic")); + selections.put("unusedcode", createCheckBox("unusedcode")); + selections.put("design", createCheckBox("design")); + } + + public Iterator keys() { + return selections.keySet().iterator(); + } + + public int size() { + return selections.size(); + } + + public JCheckBox get(Object key) { + return (JCheckBox)selections.get(key); + } + + public void save() { + for (Iterator i = keys(); i.hasNext();) { + String key = (String)i.next(); + jEdit.setBooleanProperty(PMDJEditPlugin.OPTION_RULESETS_PREFIX + key, get(key).isSelected()); + } + } + + private JCheckBox createCheckBox(String name) { + JCheckBox box = new JCheckBox(); + box.setSelected(jEdit.getBooleanProperty(PMDJEditPlugin.OPTION_RULESETS_PREFIX + name, true)); + return box; + } +}