forked from phoedos/pmd
modified to show example in option pane, fixed a property, general twiddling
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@710 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -21,6 +21,6 @@ pmd-check-current-directory-recursively.label=Check directory recursively
|
||||
#
|
||||
# Option pane properties
|
||||
#
|
||||
options.pmd.title=PMD
|
||||
options.pmd.label=PMD
|
||||
options.PMD.title=PMD
|
||||
options.PMD.label=PMD
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
???? 2002 - 0.8:
|
||||
Fixed GUI lockup problem.
|
||||
Added example text to option pane.
|
||||
|
||||
August 2 2002 - 0.7:
|
||||
Updated to use pmd-0.8
|
||||
|
Binary file not shown.
@ -27,7 +27,29 @@ import net.sourceforge.pmd.Rule;
|
||||
|
||||
public class PMDOptionPane extends AbstractOptionPane implements OptionPane {
|
||||
|
||||
public static class CheckboxList extends JList {
|
||||
public class CheckboxList extends JList {
|
||||
|
||||
private class MyMouseAdapter extends MouseAdapter {
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
int index = locationToIndex(e.getPoint());
|
||||
if (index != -1) {
|
||||
JCheckBox box = (JCheckBox)getModel().getElementAt(index);
|
||||
String example = rules.getRule(box).getExample();
|
||||
exampleTextArea.setText(example);
|
||||
exampleTextArea.setCaretPosition(0);
|
||||
}
|
||||
}
|
||||
|
||||
public void mousePressed(MouseEvent e) {
|
||||
int index = locationToIndex(e.getPoint());
|
||||
if (index != -1) {
|
||||
JCheckBox box = (JCheckBox)getModel().getElementAt(index);
|
||||
box.setSelected(!box.isSelected());
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class CheckboxListCellRenderer implements ListCellRenderer {
|
||||
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
|
||||
JCheckBox box = (JCheckBox)value;
|
||||
@ -43,21 +65,13 @@ public class PMDOptionPane extends AbstractOptionPane implements OptionPane {
|
||||
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();
|
||||
}
|
||||
}
|
||||
});
|
||||
addMouseListener(new MyMouseAdapter());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private SelectedRules rules;
|
||||
|
||||
private JTextArea exampleTextArea= new JTextArea(10, 50);
|
||||
public PMDOptionPane() {
|
||||
super(PMDJEditPlugin.NAME);
|
||||
try {
|
||||
@ -69,10 +83,24 @@ public class PMDOptionPane extends AbstractOptionPane implements OptionPane {
|
||||
|
||||
public void init() {
|
||||
removeAll();
|
||||
|
||||
addComponent(new JLabel("Please see http://pmd.sf.net/ for more information"));
|
||||
|
||||
JPanel rulesPanel = new JPanel();
|
||||
rulesPanel.setBorder(BorderFactory.createTitledBorder("Rules"));
|
||||
JList list = new CheckboxList(rules.getAllBoxes());
|
||||
list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
|
||||
addComponent(new JScrollPane(list));
|
||||
rulesPanel.add(new JScrollPane(list), BorderLayout.NORTH);
|
||||
|
||||
JPanel textPanel = new JPanel();
|
||||
textPanel.setBorder(BorderFactory.createTitledBorder("Example"));
|
||||
textPanel.add(new JScrollPane(exampleTextArea));
|
||||
|
||||
JPanel panel = new JPanel();
|
||||
panel.setLayout(new BorderLayout());
|
||||
panel.add(rulesPanel, BorderLayout.NORTH);
|
||||
panel.add(textPanel, BorderLayout.SOUTH);
|
||||
addComponent(panel);
|
||||
}
|
||||
|
||||
public void save() {
|
||||
|
@ -18,6 +18,7 @@ import net.sourceforge.pmd.Rule;
|
||||
|
||||
public class SelectedRules {
|
||||
|
||||
// Rule -> JCheckBox
|
||||
private Map rules = new TreeMap(new Comparator() {
|
||||
public int compare(Object o1, Object o2) {
|
||||
Rule r1 = (Rule)o1;
|
||||
@ -41,6 +42,17 @@ public class SelectedRules {
|
||||
return rules.size();
|
||||
}
|
||||
|
||||
public Rule getRule(JCheckBox candidate) {
|
||||
for (Iterator i = rules.keySet().iterator(); i.hasNext();) {
|
||||
Rule rule = (Rule)i.next();
|
||||
JCheckBox box = (JCheckBox)rules.get(rule);
|
||||
if (box.equals(candidate)) {
|
||||
return rule;
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("Couldn't find a rule that mapped to the passed in JCheckBox " + candidate);
|
||||
}
|
||||
|
||||
public JCheckBox get(Object key) {
|
||||
return (JCheckBox)rules.get(key);
|
||||
}
|
||||
|
Reference in New Issue
Block a user