From 025eb4037332c8810f4681f63c4c70d6349c6100 Mon Sep 17 00:00:00 2001 From: Tom Copeland Date: Thu, 14 Nov 2002 13:34:54 +0000 Subject: [PATCH] added directory popup feature git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@1243 51baf565-9d33-0410-a72c-fc3788e3496d --- pmd-jedit/config/pmd.props | 1 - .../sourceforge/pmd/jedit/PMDJEditPlugin.java | 41 ++++++++++++------- .../sourceforge/pmd/jedit/PMDOptionPane.java | 24 ++++++++--- 3 files changed, 45 insertions(+), 21 deletions(-) diff --git a/pmd-jedit/config/pmd.props b/pmd-jedit/config/pmd.props index 8e509afd40..9e491ecbd2 100644 --- a/pmd-jedit/config/pmd.props +++ b/pmd-jedit/config/pmd.props @@ -23,4 +23,3 @@ pmd-check-current-directory-recursively.label=Check directory recursively # options.PMD.title=PMD 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 f0838f2fcc..046d9d898e 100644 --- a/pmd-jedit/src/net/sourceforge/pmd/jedit/PMDJEditPlugin.java +++ b/pmd-jedit/src/net/sourceforge/pmd/jedit/PMDJEditPlugin.java @@ -22,8 +22,8 @@ import net.sourceforge.pmd.*; public class PMDJEditPlugin extends EditPlugin { public static final String NAME = "PMD"; - public static final String PROPERTY_PREFIX = "plugin.net.sourceforge.pmd.jedit."; public static final String OPTION_RULES_PREFIX = "options.pmd.rules."; + public static final String OPTION_UI_DIRECTORY_POPUP = "options.pmd.ui.directorypopup"; public static class JavaFileOrDirectoryFilter implements FilenameFilter { public boolean accept(File dir, String filename) { @@ -60,31 +60,42 @@ public class PMDJEditPlugin extends EditPlugin { } public void instanceCheckDirectory(View view) { - final VFSBrowser browser = (VFSBrowser)view.getDockableWindowManager().getDockable("vfs.browser"); - if(browser == null) { - JOptionPane.showMessageDialog(jEdit.getFirstView(), "Can't run PMD on a directory unless the file browser is open", NAME, JOptionPane.ERROR_MESSAGE); - return; - } - new Thread(new Runnable () { - public void run() { - processFiles(findFilesInDirectory(browser.getDirectory())); + if (jEdit.getBooleanProperty(PMDJEditPlugin.OPTION_UI_DIRECTORY_POPUP)) { + final String dir = JOptionPane.showInputDialog(jEdit.getFirstView(), "Please type in a directory to scan", NAME, JOptionPane.QUESTION_MESSAGE); + process(findFilesInDirectory(dir)); + } else { + final VFSBrowser browser = (VFSBrowser)view.getDockableWindowManager().getDockable("vfs.browser"); + if(browser == null) { + JOptionPane.showMessageDialog(jEdit.getFirstView(), "Can't run PMD on a directory unless the file browser is open", NAME, JOptionPane.ERROR_MESSAGE); + return; } - }).start(); + process(findFilesInDirectory(browser.getDirectory())); + } } + public static void checkDirectoryRecursively(View view) { instance.instanceCheckDirectoryRecursively(view); } public void instanceCheckDirectoryRecursively(View view) { - final VFSBrowser browser = (VFSBrowser)view.getDockableWindowManager().getDockable("vfs.browser"); - if(browser == null) { - JOptionPane.showMessageDialog(jEdit.getFirstView(), "Can't run PMD on a directory unless the file browser is open", NAME, JOptionPane.ERROR_MESSAGE); - return; + if (jEdit.getBooleanProperty(PMDJEditPlugin.OPTION_UI_DIRECTORY_POPUP)) { + final String dir = JOptionPane.showInputDialog(jEdit.getFirstView(), "Please type in a directory to scan recursively", NAME, JOptionPane.QUESTION_MESSAGE); + process(findFilesRecursively(dir)); + } else { + final VFSBrowser browser = (VFSBrowser)view.getDockableWindowManager().getDockable("vfs.browser"); + if(browser == null) { + JOptionPane.showMessageDialog(jEdit.getFirstView(), "Can't run PMD on a directory unless the file browser is open", NAME, JOptionPane.ERROR_MESSAGE); + return; + } + process(findFilesRecursively(browser.getDirectory())); } + } + + private void process(final List files) { new Thread(new Runnable () { public void run() { - processFiles(findFilesRecursively(browser.getDirectory())); + processFiles(files); } }).start(); } diff --git a/pmd-jedit/src/net/sourceforge/pmd/jedit/PMDOptionPane.java b/pmd-jedit/src/net/sourceforge/pmd/jedit/PMDOptionPane.java index cd747039c4..d567dc473a 100644 --- a/pmd-jedit/src/net/sourceforge/pmd/jedit/PMDOptionPane.java +++ b/pmd-jedit/src/net/sourceforge/pmd/jedit/PMDOptionPane.java @@ -7,6 +7,7 @@ package net.sourceforge.pmd.jedit; import org.gjt.sp.jedit.OptionPane; import org.gjt.sp.jedit.AbstractOptionPane; +import org.gjt.sp.jedit.jEdit; import javax.swing.*; import javax.swing.border.EmptyBorder; @@ -63,6 +64,8 @@ public class PMDOptionPane extends AbstractOptionPane implements OptionPane { private SelectedRules rules; private JTextArea exampleTextArea= new JTextArea(10, 50); + private JCheckBox directoryPopupBox; + public PMDOptionPane() { super(PMDJEditPlugin.NAME); try { @@ -87,14 +90,25 @@ public class PMDOptionPane extends AbstractOptionPane implements OptionPane { 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); + if (!jEdit.getProperties().containsKey(PMDJEditPlugin.OPTION_UI_DIRECTORY_POPUP)) { + jEdit.setBooleanProperty(PMDJEditPlugin.OPTION_UI_DIRECTORY_POPUP, false); + } + + directoryPopupBox = new JCheckBox("Ask for directory?", jEdit.getBooleanProperty(PMDJEditPlugin.OPTION_UI_DIRECTORY_POPUP)); + + JPanel mainPanel = new JPanel(); + mainPanel.setLayout(new BorderLayout()); + mainPanel.add(rulesPanel, BorderLayout.NORTH); + mainPanel.add(textPanel, BorderLayout.CENTER); + mainPanel.add(directoryPopupBox, BorderLayout.SOUTH); + + addComponent(mainPanel); } public void save() { rules.save(); + if (directoryPopupBox != null) { + jEdit.setBooleanProperty(PMDJEditPlugin.OPTION_UI_DIRECTORY_POPUP, directoryPopupBox.isSelected()); + } } }