diff --git a/pmd-jbuilder/lib/PMDOpenTool.jar b/pmd-jbuilder/lib/PMDOpenTool.jar index f8ec00ce8b..caf5f6019b 100644 Binary files a/pmd-jbuilder/lib/PMDOpenTool.jar and b/pmd-jbuilder/lib/PMDOpenTool.jar differ diff --git a/pmd-jbuilder/src/net/sourceforge/pmd/jbuilder/AcceleratorPropertyGroup.java b/pmd-jbuilder/src/net/sourceforge/pmd/jbuilder/AcceleratorPropertyGroup.java index c9f4d2dafa..3d901a0bfb 100644 --- a/pmd-jbuilder/src/net/sourceforge/pmd/jbuilder/AcceleratorPropertyGroup.java +++ b/pmd-jbuilder/src/net/sourceforge/pmd/jbuilder/AcceleratorPropertyGroup.java @@ -23,6 +23,8 @@ import java.util.HashMap; import com.borland.primetime.ide.MessageCategory; import com.borland.primetime.ide.Browser; import java.util.Enumeration; +import com.borland.primetime.properties.GlobalIntegerProperty; +import java.awt.event.KeyEvent; @@ -33,6 +35,18 @@ public class AcceleratorPropertyGroup implements PropertyGroup { public static AcceleratorPropertyGroup currentInstance = null; + static GlobalIntegerProperty PROP_CHECKFILE_KEY; + static GlobalIntegerProperty PROP_CHECKFILE_MOD; + static GlobalIntegerProperty PROP_CHECKPROJ_KEY; + static GlobalIntegerProperty PROP_CHECKPROJ_MOD; + + static { + PROP_CHECKFILE_KEY = new GlobalIntegerProperty(Constants.RULESETS, "checkfilekey", 'P'); + PROP_CHECKFILE_MOD = new GlobalIntegerProperty(Constants.RULESETS, "checkfilemod", KeyEvent.CTRL_MASK|KeyEvent.SHIFT_MASK); + PROP_CHECKPROJ_KEY = new GlobalIntegerProperty(Constants.RULESETS, "checkprojkey", 'J'); + PROP_CHECKPROJ_MOD = new GlobalIntegerProperty(Constants.RULESETS, "checkprojmod", KeyEvent.CTRL_MASK|KeyEvent.SHIFT_MASK); + + } /** * Standard Constructor diff --git a/pmd-jbuilder/src/net/sourceforge/pmd/jbuilder/AcceleratorPropertyPage.java b/pmd-jbuilder/src/net/sourceforge/pmd/jbuilder/AcceleratorPropertyPage.java index f9a3d5532f..350aac9f39 100644 --- a/pmd-jbuilder/src/net/sourceforge/pmd/jbuilder/AcceleratorPropertyPage.java +++ b/pmd-jbuilder/src/net/sourceforge/pmd/jbuilder/AcceleratorPropertyPage.java @@ -34,8 +34,6 @@ public class AcceleratorPropertyPage extends PropertyPage { private JLabel jLabel1 = new JLabel(); private JComboBox jComboBox1 = new JComboBox(); private JPanel jPanel2 = new JPanel(); - int keycode; - int modifiers; private FlowLayout flowLayout1 = new FlowLayout(); private JTextField jTextField2 = new JTextField(); private JTextField jTextField3 = new JTextField(); @@ -43,6 +41,7 @@ public class AcceleratorPropertyPage extends PropertyPage { private JPanel jPanel3 = new JPanel(); private JLabel jLabel2 = new JLabel(); private JLabel jLabel3 = new JLabel(); + private int[][]keys = new int[2][2]; //data structure to hold keycode and modifier info for 2 distinct actions /** * Constuctor @@ -75,6 +74,11 @@ public class AcceleratorPropertyPage extends PropertyPage { jLabel3.setPreferredSize(new Dimension(60, 17)); jLabel3.setHorizontalAlignment(SwingConstants.CENTER); jLabel3.setText("Key"); + jComboBox1.addItemListener(new java.awt.event.ItemListener() { + public void itemStateChanged(ItemEvent e) { + jComboBox1_itemStateChanged(e); + } + }); this.add(jPanel1, null); jPanel1.add(jLabel1, null); jPanel1.add(jComboBox1, null); @@ -86,22 +90,34 @@ public class AcceleratorPropertyPage extends PropertyPage { jPanel2.add(jTextField2, null); } + private void initKeys() { + keys[0][0] = AcceleratorPropertyGroup.PROP_CHECKFILE_KEY.getInteger(); + keys[0][1] = AcceleratorPropertyGroup.PROP_CHECKFILE_MOD.getInteger(); + keys[1][0] = AcceleratorPropertyGroup.PROP_CHECKPROJ_KEY.getInteger(); + keys[1][1] = AcceleratorPropertyGroup.PROP_CHECKPROJ_MOD.getInteger(); + + } /** * non-Jbuilder specific initialization stuff */ private void init2() { - jComboBox1.addItem("Check File"); - jComboBox1.addItem("Check Project"); + initKeys(); + jComboBox1.addItem("Check File"); //item 0 + jComboBox1.addItem("Check Project"); //item 1 + int selectedItem = jComboBox1.getSelectedIndex(); + jTextField2.setText(KeyEvent.getKeyText(keys[selectedItem][0])); + jTextField3.setText(KeyEvent.getKeyModifiersText(keys[selectedItem][1])); jTextField2.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { - keycode = e.getKeyCode(); - modifiers = e.getModifiers(); + int item = jComboBox1.getSelectedIndex(); + keys[item][0] = e.getKeyCode(); + keys[item][1] = e.getModifiers(); if(e.isActionKey()) { - jTextField2.setText(KeyEvent.getKeyText(keycode)); - jTextField3.setText(KeyEvent.getKeyModifiersText(modifiers)); + jTextField2.setText(KeyEvent.getKeyText(keys[item][0])); + jTextField3.setText(KeyEvent.getKeyModifiersText(keys[item][1])); //jTextField2.setText(""); } @@ -109,8 +125,9 @@ public class AcceleratorPropertyPage extends PropertyPage { public void keyTyped(KeyEvent e) { - jTextField2.setText(KeyEvent.getKeyText(keycode)); - jTextField3.setText(KeyEvent.getKeyModifiersText(modifiers)); + int item = jComboBox1.getSelectedIndex(); + jTextField2.setText(KeyEvent.getKeyText(keys[item][0])); + jTextField3.setText(KeyEvent.getKeyModifiersText(keys[item][1])); //jTextField2.setText(""); } @@ -118,6 +135,18 @@ public class AcceleratorPropertyPage extends PropertyPage { } public void writeProperties () { + //we need to tell the PMDOpenbTool to clear it's current key bindings before we save the new ones + PMDOpenTool.clearShortCuts(); + + //now we can save the new key bindings to the global properties + AcceleratorPropertyGroup.PROP_CHECKFILE_KEY.setInteger(keys[0][0]); + AcceleratorPropertyGroup.PROP_CHECKFILE_MOD.setInteger(keys[0][1]); + AcceleratorPropertyGroup.PROP_CHECKPROJ_KEY.setInteger(keys[1][0]); + AcceleratorPropertyGroup.PROP_CHECKPROJ_MOD.setInteger(keys[1][1]); + + //now we can tell PMDOpenTool to recreate the bindings based on the new global values + PMDOpenTool.registerShortCuts(); + } /** @@ -133,6 +162,13 @@ public class AcceleratorPropertyPage extends PropertyPage { */ public void readProperties () {} + void jComboBox1_itemStateChanged(ItemEvent e) { + int selectedItem = jComboBox1.getSelectedIndex(); + jTextField2.setText(KeyEvent.getKeyText(keys[selectedItem][0])); + jTextField3.setText(KeyEvent.getKeyModifiersText(keys[selectedItem][1])); + + } + } diff --git a/pmd-jbuilder/src/net/sourceforge/pmd/jbuilder/PMDOpenTool.java b/pmd-jbuilder/src/net/sourceforge/pmd/jbuilder/PMDOpenTool.java index 16a956889f..e702aaecce 100644 --- a/pmd-jbuilder/src/net/sourceforge/pmd/jbuilder/PMDOpenTool.java +++ b/pmd-jbuilder/src/net/sourceforge/pmd/jbuilder/PMDOpenTool.java @@ -68,11 +68,7 @@ public class PMDOpenTool { AcceleratorPropertyGroup accpropGrp = new AcceleratorPropertyGroup(); //register the Keymap shortcuts - EditorManager.getKeymap().addActionForKeyStroke(KeyStroke.getKeyStroke('P', Event.CTRL_MASK | Event.SHIFT_MASK), - E_ACTION_PMDCheck); - - EditorManager.getKeymap().addActionForKeyStroke(KeyStroke.getKeyStroke('J', Event.CTRL_MASK | Event.SHIFT_MASK), - E_ACTION_PMDCheckProject); + registerShortCuts(); PropertyManager.registerPropertyGroup(apropGrp); PropertyManager.registerPropertyGroup(cpropGrp); @@ -82,6 +78,25 @@ public class PMDOpenTool { } } + + static void clearShortCuts() { + EditorManager.getKeymap().removeKeyStrokeBinding(KeyStroke.getKeyStroke(AcceleratorPropertyGroup.PROP_CHECKFILE_KEY.getInteger(), + AcceleratorPropertyGroup.PROP_CHECKFILE_MOD.getInteger())); + EditorManager.getKeymap().removeKeyStrokeBinding(KeyStroke.getKeyStroke(AcceleratorPropertyGroup.PROP_CHECKPROJ_KEY.getInteger(), + AcceleratorPropertyGroup.PROP_CHECKPROJ_MOD.getInteger())); + } + + static void registerShortCuts() { + + EditorManager.getKeymap().addActionForKeyStroke(KeyStroke.getKeyStroke(AcceleratorPropertyGroup.PROP_CHECKFILE_KEY.getInteger(), + AcceleratorPropertyGroup.PROP_CHECKFILE_MOD.getInteger()), + E_ACTION_PMDCheck); + + EditorManager.getKeymap().addActionForKeyStroke(KeyStroke.getKeyStroke(AcceleratorPropertyGroup.PROP_CHECKPROJ_KEY.getInteger(), + AcceleratorPropertyGroup.PROP_CHECKPROJ_MOD.getInteger()), + E_ACTION_PMDCheckProject); + } + /** * Registers an "PMD Checker" action with the ContentManager (Tabs) * The action will not be visible if multiple nodes are selected