diff --git a/pmd-jbuilder/lib/PMDOpenTool.jar b/pmd-jbuilder/lib/PMDOpenTool.jar index a39ab1d6ff..dc03dd88b5 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 new file mode 100644 index 0000000000..c9f4d2dafa --- /dev/null +++ b/pmd-jbuilder/src/net/sourceforge/pmd/jbuilder/AcceleratorPropertyGroup.java @@ -0,0 +1,70 @@ +/** + *
Title: JBuilder OpenTool for PMD
+ *Description: Provides an environemnt for using the PMD aplication from within JBuilder
+ *Copyright: Copyright (c) 2002
+ *Company: InfoEther
+ * @author David Craine + * @version 1.0 + * + * formatted with JxBeauty (c) johann.langhofer@nextra.at + */ + + +package net.sourceforge.pmd.jbuilder; + +import com.borland.primetime.properties.PropertyGroup; +import com.borland.primetime.properties.PropertyPageFactory; +import com.borland.primetime.properties.GlobalProperty; +import com.borland.primetime.properties.PropertyPage; +import net.sourceforge.pmd.RuleSetFactory; +import net.sourceforge.pmd.RuleSet; +import java.util.Iterator; +import java.util.HashMap; +import com.borland.primetime.ide.MessageCategory; +import com.borland.primetime.ide.Browser; +import java.util.Enumeration; + + + +/** + * put your documentation comment here + */ +public class AcceleratorPropertyGroup + implements PropertyGroup { + + public static AcceleratorPropertyGroup currentInstance = null; + + /** + * Standard Constructor + */ + public AcceleratorPropertyGroup () { + currentInstance = this; + } + + + /** + * Called by JBuilder + */ + public void initializeProperties () { + } + + /** + * Create the panel that will go in the property page + * @param topic Topic of page (represented as a tab in the property page) + * @return Factory for creating property pages - this factory will create RuleSetPropertyPages + */ + public PropertyPageFactory getPageFactory (Object topic) { + if (topic == Constants.RULESETS_TOPIC) { + return new PropertyPageFactory("PMD HotKey Condiguration", "Set the HotKeys for PMD") { + + public PropertyPage createPropertyPage () { + return new AcceleratorPropertyPage(); + } + }; + } + return null; + } +} + + + diff --git a/pmd-jbuilder/src/net/sourceforge/pmd/jbuilder/AcceleratorPropertyPage.java b/pmd-jbuilder/src/net/sourceforge/pmd/jbuilder/AcceleratorPropertyPage.java new file mode 100644 index 0000000000..060d0fc891 --- /dev/null +++ b/pmd-jbuilder/src/net/sourceforge/pmd/jbuilder/AcceleratorPropertyPage.java @@ -0,0 +1,128 @@ +/** + *Title: JBuilder OpenTool for PMD
+ *Description: Provides an environemnt for using the PMD aplication from within JBuilder
+ *Copyright: Copyright (c) 2002
+ *Company: InfoEther
+ * @author David Craine + * @version 1.0 + * + * formatted with JxBeauty (c) johann.langhofer@nextra.at + */ + + +package net.sourceforge.pmd.jbuilder; + +import java.awt.*; +import java.awt.event.*; +import java.util.*; + +import javax.swing.*; +import javax.swing.border.*; + +import com.borland.primetime.help.*; +import com.borland.primetime.ide.*; +import com.borland.primetime.properties.*; +import com.borland.jbcl.layout.*; +import java.io.InputStream; +import net.sourceforge.pmd.RuleSetFactory; +import net.sourceforge.pmd.RuleSet; + + + +public class AcceleratorPropertyPage extends PropertyPage { + private JPanel jPanel1 = new JPanel(); + private JLabel jLabel1 = new JLabel(); + private JComboBox jComboBox1 = new JComboBox(); + private JPanel jPanel2 = new JPanel(); + private JTextField jTextField1 = new JTextField(); + int keycode; + int modifiers; + private FlowLayout flowLayout1 = new FlowLayout(); + private JTextField jTextField2 = new JTextField(); + private JTextField jTextField3 = new JTextField(); + private VerticalFlowLayout verticalFlowLayout1 = new VerticalFlowLayout(); + + /** + * Constuctor + */ + public AcceleratorPropertyPage () { + try { + jbInit(); + init2(); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + + /** + * Initialize the interface components + * @exception Exception thows any exceptions that occur + */ + protected void jbInit () throws Exception { + this.setLayout(verticalFlowLayout1); + jLabel1.setText("Select the Action"); + jPanel2.setLayout(flowLayout1); + jTextField2.setPreferredSize(new Dimension(50, 21)); + jTextField2.setEditable(false); + jTextField3.setPreferredSize(new Dimension(50, 21)); + jTextField3.setEditable(false); + jTextField1.setPreferredSize(new Dimension(50, 21)); + this.add(jPanel1, null); + jPanel1.add(jLabel1, null); + jPanel1.add(jComboBox1, null); + this.add(jPanel2, null); + jPanel2.add(jTextField1, null); + jPanel2.add(jTextField2, null); + jPanel2.add(jTextField3, null); + } + + + /** + * non-Jbuilder specific initialization stuff + */ + private void init2() { + jTextField1.addKeyListener(new KeyAdapter() { + + public void keyPressed(KeyEvent e) + { + keycode = e.getKeyCode(); + modifiers = e.getModifiers(); + if(e.isActionKey()) + { + jTextField2.setText(KeyEvent.getKeyText(keycode)); + jTextField3.setText(KeyEvent.getKeyModifiersText(modifiers)); + jTextField1.setText(""); + + } + } + + public void keyTyped(KeyEvent e) + { + jTextField2.setText(KeyEvent.getKeyText(keycode)); + jTextField3.setText(KeyEvent.getKeyModifiersText(modifiers)); + jTextField1.setText(""); + } + + }); + } + + public void writeProperties () { + } + + /** + * get the Help TOpic + * @return help topic + */ + public HelpTopic getHelpTopic () { + return null; + } + + /** + * Called by JBuilder to setup the initial property settings. + */ + public void readProperties () {} + +} + + diff --git a/pmd-jbuilder/src/net/sourceforge/pmd/jbuilder/PMDOpenTool.java b/pmd-jbuilder/src/net/sourceforge/pmd/jbuilder/PMDOpenTool.java index 8501255b33..16a956889f 100644 --- a/pmd-jbuilder/src/net/sourceforge/pmd/jbuilder/PMDOpenTool.java +++ b/pmd-jbuilder/src/net/sourceforge/pmd/jbuilder/PMDOpenTool.java @@ -26,6 +26,7 @@ import com.borland.primetime.node.*; import com.borland.primetime.properties.*; import com.borland.primetime.viewer.*; import net.sourceforge.pmd.*; +import java.awt.event.ActionEvent; @@ -49,9 +50,10 @@ public class PMDOpenTool { */ public static void initOpenTool (byte majorVersion, byte minorVersion) { if (majorVersion == PrimeTime.CURRENT_MAJOR_VERSION) { - GROUP_PMD.add(ACTION_PMDCheck); - GROUP_PMD.add(ACTION_PMDConfig); + GROUP_PMD.add(B_ACTION_PMDCheck); + GROUP_PMD.add(B_ACTION_PMDConfig); JBuilderMenu.GROUP_Tools.add(GROUP_PMD); + registerWithContentManager(); registerWithProjectView(); @@ -63,10 +65,19 @@ public class PMDOpenTool { ImportedRuleSetPropertyGroup ipropGrp = new ImportedRuleSetPropertyGroup(); ActiveRuleSetPropertyGroup apropGrp = new ActiveRuleSetPropertyGroup(); ConfigureRuleSetPropertyGroup cpropGrp = new ConfigureRuleSetPropertyGroup(); + 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); PropertyManager.registerPropertyGroup(apropGrp); PropertyManager.registerPropertyGroup(cpropGrp); PropertyManager.registerPropertyGroup(ipropGrp); + PropertyManager.registerPropertyGroup(accpropGrp); } } @@ -79,7 +90,7 @@ public class PMDOpenTool { ContextActionProvider cap = new ContextActionProvider() { public Action getContextAction (Browser browser, Node[] nodes) { - return ACTION_PMDCheck; + return B_ACTION_PMDCheck; } }; ContentManager.registerContextActionProvider(cap); @@ -88,10 +99,9 @@ public class PMDOpenTool { private static void registerWithProjectView() { ContextActionProvider cap = new ContextActionProvider() { public Action getContextAction (Browser browser, Node[] nodes) { - //Browser.getActiveBrowser().getMessageView().addMessage(msgCat, browser.getProjectView().getSelectedNode().toString()); Node node = browser.getProjectView().getSelectedNode(); if (node instanceof JBProject || node instanceof PackageNode) - return ACTION_PMDProjectCheck; + return B_ACTION_PMDProjectCheck; return null; } }; @@ -105,7 +115,6 @@ public class PMDOpenTool { * @return A Ruleset and any embedded rulesets */ private static RuleSet constructRuleSets () { - Browser.getActiveBrowser().getMessageView().addMessage(Constants.MSGCAT_TEST, "building ruleset"); RuleSet masterRuleSet = new RuleSet(); for (Iterator iter = ActiveRuleSetPropertyGroup.currentInstance.ruleSets.values().iterator(); iter.hasNext(); ) { RuleSetProperty rsp = (RuleSetProperty)iter.next(); @@ -142,28 +151,47 @@ public class PMDOpenTool { return null; } + + //create EditorAction for performing a PMD Check + public static EditorAction E_ACTION_PMDCheck = + new EditorAction("Displays PMD statistics about a Java File") { + public void actionPerformed(ActionEvent e) { + pmdCheck(); + } + }; + + //create EditorAction for performing a PMD Check on a project + public static EditorAction E_ACTION_PMDCheckProject = + new EditorAction("Displays PMD statistics about a Java File") { + public void actionPerformed(ActionEvent e) { + pmdCheckProject(); + } + }; + //create the Menu action item for initiating the PMD check - public static BrowserAction ACTION_PMDCheck = + public static BrowserAction B_ACTION_PMDCheck = // A new action with short menu string, mnemonic, and long menu string new BrowserAction("PMD Checker", 'P', "Displays PMD statistics about a Java File") { // The function called when the menu is selected public void actionPerformed (Browser browser) { - Node node = Browser.getActiveBrowser().getActiveNode(); - if (node instanceof JavaFileNode) { - Browser.getActiveBrowser().getMessageView().clearMessages(msgCat); //clear the message window - TextNodeViewer viewer = (TextNodeViewer)Browser.getActiveBrowser().getViewerOfType(node, - TextNodeViewer.class); - if (viewer != null) { - Document doc = viewer.getEditor().getDocument(); - try { - checkCode(doc.getText(0, doc.getLength()), (JavaFileNode)node, null); - } - catch (Exception e){ - e.printStackTrace(); - } - } - } + pmdCheck(); + } + }; + + //Create the menu action item for configuring PMD + public static BrowserAction B_ACTION_PMDConfig = new BrowserAction("Configure PMD", + 'C', "Configure the PMD Settings") { + public void actionPerformed (Browser browser) { + PropertyManager.showPropertyDialog(browser, "PMD Options", Constants.RULESETS_TOPIC, + PropertyDialog.getLastSelectedPage()); + } + }; + + //create the project menu action for running a PMD check against all the java files within the active project + public static BrowserAction B_ACTION_PMDProjectCheck = new BrowserAction ("PMD Check Project", 'P', "Check all the java files in the project") { + public void actionPerformed(Browser browser) { + pmdCheckProject(); } }; @@ -202,51 +230,56 @@ public class PMDOpenTool { } - //Create the menu action item for configuring PMD - public static BrowserAction ACTION_PMDConfig = new BrowserAction("Configure PMD", - 'C', "Configure the PMD Settings") { - public void actionPerformed (Browser browser) { - PropertyManager.showPropertyDialog(browser, "PMD Options", Constants.RULESETS_TOPIC, - PropertyDialog.getLastSelectedPage()); - } - }; - - //create the project menu action for running a PMD check against all the java files within the active project - public static BrowserAction ACTION_PMDProjectCheck = new BrowserAction ("PMD Check Project", 'P', "Check all the java files in the project") { - public void actionPerformed(Browser browser) { - Node[] nodes = browser.getActiveBrowser().getActiveProject().getDisplayChildren(); + private static void pmdCheck() { + Node node = Browser.getActiveBrowser().getActiveNode(); + if (node instanceof JavaFileNode) { Browser.getActiveBrowser().getMessageView().clearMessages(msgCat); //clear the message window - RuleSet rules = constructRuleSets(); - for (int i=0; i