Commit [df4d25] Maximize Restore History

General updates -- upgrade to PMD 2.4.5, updates to option panes, action for designer.

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@6915 51baf565-9d33-0410-a72c-fc3788e3496d

Dale Anson Dale Anson 2009-04-20

added src/net/sourceforge/pmd/jedit/PMDGeneralOptionPane.java
changed src/net/sourceforge/pmd/jedit/PMDJEditPlugin.java
changed src/net/sourceforge/pmd/jedit/SelectedRules.java
changed actions.xml
changed build.xml
changed pmd.props
copied src/net/sourceforge/pmd/jedit/PMDOptionPane.java -> src/net/sourceforge/pmd/jedit/PMDRulesOptionPane.java
src/net/sourceforge/pmd/jedit/PMDGeneralOptionPane.java Diff Switch to side-by-side view
Loading...
src/net/sourceforge/pmd/jedit/PMDJEditPlugin.java Diff Switch to side-by-side view
Loading...
src/net/sourceforge/pmd/jedit/SelectedRules.java Diff Switch to side-by-side view
Loading...
actions.xml Diff Switch to side-by-side view
Loading...
build.xml Diff Switch to side-by-side view
Loading...
pmd.props Diff Switch to side-by-side view
Loading...
src/net/sourceforge/pmd/jedit/PMDOptionPane.java to src/net/sourceforge/pmd/jedit/PMDRulesOptionPane.java
--- a/src/net/sourceforge/pmd/jedit/PMDOptionPane.java
+++ b/src/net/sourceforge/pmd/jedit/PMDRulesOptionPane.java
@@ -14,8 +14,6 @@
 import org.gjt.sp.util.StringList;
 
 import javax.swing.BorderFactory;
-import javax.swing.JCheckBox;
-import javax.swing.JComboBox;
 import javax.swing.JLabel;
 import javax.swing.JOptionPane;
 import javax.swing.JPanel;
@@ -26,29 +24,21 @@
 import javax.swing.tree.TreePath;
 import java.awt.BorderLayout;
 import java.awt.FlowLayout;
-import java.awt.GridLayout;
 import java.awt.event.MouseEvent;
 import java.util.List;
 
-public class PMDOptionPane extends AbstractOptionPane implements OptionPane {
+public class PMDRulesOptionPane extends AbstractOptionPane implements OptionPane {
 
     SelectedRules rules;
 
     JTextArea exampleTextArea = new JTextArea( 15, 50 );
 
-    private JCheckBox chkRunPMDOnSave, chkShowProgressBar, chkIgnoreLiterals, chkPrintRule;
-
-    JTextField txtMinTileSize;
-
     JTextField txtCustomRules;
-
-    JComboBox comboRenderer;
-
-    JComboBox javaVersionBox;
 
     CheckboxTree tree;
 
-    public PMDOptionPane() {
+
+    public PMDRulesOptionPane() {
         super( PMDJEditPlugin.NAME );
         try {
             rules = new SelectedRules();
@@ -74,16 +64,16 @@
         // individual rules.  Using the PROPAGATE_PRESERVING_UNCHECK checking mode
         // means the ruleset will be checked if one or more of the rules it contains
         // is checked.
-        if (rules != null) {
+        if ( rules == null ) {
+            JOptionPane.showMessageDialog( null, "Error loading rules. Check any custom rulesets for errors.", "Error Loading Rules", JOptionPane.ERROR_MESSAGE );
+        }
+        else {
             tree = new CheckboxTree( rules.getRoot() );
             tree.getCheckingModel().setCheckingMode( TreeCheckingModel.CheckingMode.PROPAGATE_PRESERVING_UNCHECK );
             tree.setCheckingPaths( rules.getCheckingModel().getCheckingPaths() );
             tree.setRootVisible( false );
             tree.addMouseMotionListener( new MyMouseMotionAdapter() );
             rulesPanel.add( new JScrollPane( tree ), BorderLayout.CENTER );
-        }
-        else {
-            JOptionPane.showMessageDialog(null, "Error loading rules. Check any custom rulesets for errors.", "Error Loading Rules", JOptionPane.ERROR_MESSAGE);
         }
 
         // Custom Rule Panel Definition.
@@ -96,74 +86,19 @@
         JPanel textPanel = new JPanel( new BorderLayout() );
         textPanel.setBorder( BorderFactory.createTitledBorder( "Example" ) );
         textPanel.add( new JScrollPane( exampleTextArea ), BorderLayout.CENTER );
-        javaVersionBox = new JComboBox( PMDJEditPlugin.sourceTypes );
-
-        chkRunPMDOnSave = new JCheckBox( "Run PMD on Save", jEdit.getBooleanProperty( PMDJEditPlugin.RUN_PMD_ON_SAVE ) );
-        chkShowProgressBar = new JCheckBox( "Show PMD Progress Bar", jEdit.getBooleanProperty( PMDJEditPlugin.SHOW_PROGRESS ) );
-        chkIgnoreLiterals = new JCheckBox( "Ignore Literals & identifiers when detecting Duplicate Code", jEdit.getBooleanProperty( PMDJEditPlugin.IGNORE_LITERALS ) );
-        chkPrintRule = new JCheckBox( "Print Rulename in ErrorList", jEdit.getBooleanProperty( PMDJEditPlugin.PRINT_RULE ) );
-
-        JPanel pnlSouth = new JPanel( new GridLayout( 0, 1 ) );
-
-        JPanel pnlTileSize = new JPanel();
-        ( ( FlowLayout ) pnlTileSize.getLayout() ).setAlignment( FlowLayout.LEFT );
-        JLabel lblMinTileSize = new JLabel( "Minimum Tile Size :" );
-        txtMinTileSize = new JTextField( jEdit.getProperty( PMDJEditPlugin.DEFAULT_TILE_MINSIZE_PROPERTY, "100" ), 5 );
-        pnlTileSize.add( lblMinTileSize );
-        pnlTileSize.add( txtMinTileSize );
-
-        comboRenderer = new JComboBox( new String[] { "None", "Text", "Html", "XML", "CSV" } );
-        comboRenderer.setSelectedItem( jEdit.getProperty( PMDJEditPlugin.RENDERER ) );
-        JLabel lblRenderer = new JLabel( "Export Output as " );
-
-        pnlTileSize.add( lblRenderer );
-        pnlTileSize.add( comboRenderer );
-
-        int stidx = jEdit.getIntegerProperty( PMDJEditPlugin.JAVA_VERSION_PROPERTY, 1 );
-        javaVersionBox.setSelectedIndex( stidx );
-
-        pnlTileSize.add( chkShowProgressBar );
 
         JPanel mainPanel = new JPanel();
         mainPanel.setLayout( new BorderLayout() );
+        mainPanel.add( rulesPanel, BorderLayout.CENTER );
+        mainPanel.add( textPanel, BorderLayout.SOUTH );
 
-        mainPanel.add( rulesPanel, BorderLayout.NORTH );
-        mainPanel.add( textPanel, BorderLayout.CENTER );
-
-        pnlSouth.add( javaVersionBox );
-        pnlSouth.add( chkRunPMDOnSave );
-        pnlSouth.add( chkIgnoreLiterals );
-        pnlSouth.add( chkPrintRule );
-        pnlSouth.add( pnlTileSize );
-        mainPanel.add( pnlSouth, BorderLayout.SOUTH );
         addComponent( mainPanel );
     }
 
     public void _save() {
-        if (rules != null) {
+        if ( rules != null ) {
             rules.save( tree.getCheckingModel() );
         }
-
-        jEdit.setIntegerProperty( PMDJEditPlugin.JAVA_VERSION_PROPERTY,
-                javaVersionBox.getSelectedIndex() );
-        jEdit.setIntegerProperty( PMDJEditPlugin.DEFAULT_TILE_MINSIZE_PROPERTY,
-                ( txtMinTileSize.getText().length() == 0 ) ? 100 : Integer
-                .parseInt( txtMinTileSize.getText() ) );
-
-        // If the user has checked "Run PMD on save", set the plugin to load on jEdit
-        // start up so that the "run on save" feature works right away.  Unchecking
-        // "Run PMD on save" sets the "activate" property back to "defer", which is
-        // the default.
-        boolean on_save = chkRunPMDOnSave.isSelected();
-        jEdit.setBooleanProperty( PMDJEditPlugin.RUN_PMD_ON_SAVE, on_save );
-        jEdit.setProperty( "plugin.net.sourceforge.pmd.jedit.PMDJEditPlugin.activate", on_save ? "startup" : "defer" );
-
-        jEdit.setBooleanProperty( PMDJEditPlugin.IGNORE_LITERALS,
-                ( chkIgnoreLiterals.isSelected() ) );
-        jEdit.setProperty( PMDJEditPlugin.RENDERER, ( String ) comboRenderer.getSelectedItem() );
-        jEdit.setBooleanProperty( PMDJEditPlugin.SHOW_PROGRESS, chkShowProgressBar
-                .isSelected() );
-        jEdit.setBooleanProperty( PMDJEditPlugin.PRINT_RULE, chkPrintRule.isSelected() );
 
         if ( txtCustomRules != null ) {
             jEdit.setProperty( PMDJEditPlugin.CUSTOM_RULES_PATH_KEY, txtCustomRules
@@ -172,15 +107,28 @@
     }
 
     private class MyMouseMotionAdapter extends java.awt.event.MouseMotionAdapter {
-        public void mouseMoved( MouseEvent e ) {
-            TreePath path = tree.getPathForLocation( e.getX(), e.getY() );
-            DefaultMutableTreeNode node = ( DefaultMutableTreeNode ) path.getLastPathComponent();
-            if ( node != null ) {
-                Object userObject = node.getUserObject();
-                if ( userObject instanceof RuleNode ) {
-                    List<String> examples = ( ( ( RuleNode ) userObject ).getRule() ).getExamples();
-                    exampleTextArea.setText( StringList.join( examples, "\n---------\n" ) );
-                    exampleTextArea.setCaretPosition( 0 );
+        public void mouseMoved( MouseEvent event ) {
+            TreePath path = tree.getPathForLocation( event.getX(), event.getY() );
+            if ( path != null ) {
+                DefaultMutableTreeNode node = ( DefaultMutableTreeNode ) path.getLastPathComponent();
+                if ( node != null ) {
+                    Object userObject = node.getUserObject();
+                    if ( userObject instanceof RuleNode ) {
+                        List<String> examples = ( ( RuleNode ) userObject ).getRule().getExamples();
+                        exampleTextArea.setLineWrap( false );
+                        exampleTextArea.setWrapStyleWord( false );
+                        exampleTextArea.setText( StringList.join( examples, "\n---------\n" ) );
+                        exampleTextArea.setCaretPosition( 0 );
+                    }
+                    else if ( userObject instanceof RuleSetNode ) {
+                        String description = ( ( RuleSetNode ) userObject ).getRuleSet().getDescription();
+                        description = description.trim();
+                        description = description.replaceAll( "\n", " " );
+                        exampleTextArea.setLineWrap( true );
+                        exampleTextArea.setWrapStyleWord( true );
+                        exampleTextArea.setText( description );
+                        exampleTextArea.setCaretPosition( 0 );
+                    }
                 }
             }
         }