moved up a level
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@793 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -1,178 +0,0 @@
|
||||
package net.sourceforge.pmd.swingui.viewer;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.io.File;
|
||||
import javax.swing.border.EtchedBorder;
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.JTree;
|
||||
import javax.swing.tree.DefaultTreeCellRenderer;
|
||||
import javax.swing.tree.TreePath;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Donald A. Leckie
|
||||
* @since August 17, 2002
|
||||
* @version $Revision$, $Date$
|
||||
*/
|
||||
class DirectoryTree extends JTree
|
||||
{
|
||||
private PMDViewer m_pmdViewer;
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
*
|
||||
*/
|
||||
protected DirectoryTree(PMDViewer pmdViewer)
|
||||
{
|
||||
super(new DirectoryTreeModel());
|
||||
|
||||
m_pmdViewer = pmdViewer;
|
||||
|
||||
setRootVisible(true);
|
||||
setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
|
||||
setCellRenderer(new DirectoryTreeNodeRenderer());
|
||||
((DirectoryTreeModel) getModel()).setDirectoryTree(this);
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
*
|
||||
*/
|
||||
protected void setupFiles()
|
||||
{
|
||||
String message = "Locating file system root directories. Please wait...";
|
||||
SetupFilesThread setupFilesThread = new SetupFilesThread(message);
|
||||
|
||||
MessageDialog.show(m_pmdViewer, message, setupFilesThread);
|
||||
}
|
||||
|
||||
/**
|
||||
********************************************************************************
|
||||
********************************************************************************
|
||||
********************************************************************************
|
||||
*/
|
||||
private class SetupFilesThread extends JobThread
|
||||
{
|
||||
|
||||
/**
|
||||
****************************************************************************
|
||||
*
|
||||
* @param name
|
||||
*/
|
||||
private SetupFilesThread(String threadName)
|
||||
{
|
||||
super(threadName);
|
||||
}
|
||||
|
||||
/**
|
||||
***************************************************************************
|
||||
*
|
||||
*/
|
||||
public void run()
|
||||
{
|
||||
DirectoryTreeModel treeModel = (DirectoryTreeModel) getModel();
|
||||
|
||||
treeModel.setupFiles();
|
||||
|
||||
DirectoryTreeNode treeNode = (DirectoryTreeNode) treeModel.getRoot();
|
||||
TreePath treePath = new TreePath(treeNode.getPath());
|
||||
|
||||
expandPath(treePath);
|
||||
|
||||
// This is very important; otherwise, the message window would remain open
|
||||
// with no way to close it because the "close icon" was made non-functional.
|
||||
closeWindow();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
********************************************************************************
|
||||
********************************************************************************
|
||||
********************************************************************************
|
||||
*/
|
||||
private class DirectoryTreeNodeRenderer extends DefaultTreeCellRenderer
|
||||
{
|
||||
|
||||
private Icon m_defaultClosedIcon;
|
||||
private Icon m_defaultLeafIcon;
|
||||
private Icon m_defaultOpenIcon;
|
||||
|
||||
/**
|
||||
***************************************************************************
|
||||
*
|
||||
*/
|
||||
protected DirectoryTreeNodeRenderer()
|
||||
{
|
||||
super();
|
||||
|
||||
m_defaultClosedIcon = getDefaultClosedIcon();
|
||||
m_defaultLeafIcon = getDefaultLeafIcon();
|
||||
m_defaultOpenIcon = getDefaultOpenIcon();
|
||||
}
|
||||
|
||||
/**
|
||||
**************************************************************************
|
||||
*
|
||||
* @param tree
|
||||
* @param object
|
||||
* @param isSelected
|
||||
* @param isExpanded
|
||||
* @param isLeaf
|
||||
* @param row
|
||||
* @param hasFocus
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Component getTreeCellRendererComponent(JTree tree,
|
||||
Object object,
|
||||
boolean isSelected,
|
||||
boolean isExpanded,
|
||||
boolean isLeaf,
|
||||
int row,
|
||||
boolean hasFocus)
|
||||
{
|
||||
DirectoryTreeNode treeNode = (DirectoryTreeNode) object;
|
||||
Object userObject = treeNode.getUserObject();
|
||||
|
||||
if (userObject instanceof String)
|
||||
{
|
||||
// The root node will display either an open or closed icon.
|
||||
setClosedIcon(m_defaultClosedIcon);
|
||||
setLeafIcon(m_defaultClosedIcon);
|
||||
setOpenIcon(m_defaultOpenIcon);
|
||||
}
|
||||
else if (((File) userObject).isFile())
|
||||
{
|
||||
// A file cannot have any children; therefore, the default icon settings are used.
|
||||
setClosedIcon(m_defaultClosedIcon);
|
||||
setLeafIcon(m_defaultLeafIcon);
|
||||
setOpenIcon(m_defaultOpenIcon);
|
||||
}
|
||||
else
|
||||
{
|
||||
// A directory may or may not have children. The following conditions are used:
|
||||
//
|
||||
// For a file
|
||||
// always use the leaf icon
|
||||
// For a directory
|
||||
// has no children --- use closed folder icon
|
||||
// has children
|
||||
// is expanded --- use open folder icon
|
||||
// is collapsed --- use closed folder icon
|
||||
//
|
||||
setClosedIcon(m_defaultClosedIcon);
|
||||
setLeafIcon(m_defaultClosedIcon);
|
||||
setOpenIcon(m_defaultOpenIcon);
|
||||
}
|
||||
|
||||
return super.getTreeCellRendererComponent(tree,
|
||||
object,
|
||||
isSelected,
|
||||
isExpanded,
|
||||
isLeaf,
|
||||
row,
|
||||
hasFocus);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,151 +0,0 @@
|
||||
package net.sourceforge.pmd.swingui.viewer;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.util.Enumeration;
|
||||
import javax.swing.tree.DefaultTreeModel;
|
||||
import javax.swing.tree.TreePath;
|
||||
import javax.swing.event.TreeExpansionEvent;
|
||||
import javax.swing.event.TreeWillExpandListener;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Donald A. Leckie
|
||||
* @since August 17, 2002
|
||||
* @version $Revision$, $Date$
|
||||
*/
|
||||
class DirectoryTreeModel
|
||||
extends DefaultTreeModel
|
||||
implements TreeWillExpandListener
|
||||
{
|
||||
|
||||
private DirectoryTree m_directoryTree;
|
||||
|
||||
/**
|
||||
*****************************************************************************
|
||||
*/
|
||||
protected DirectoryTreeModel()
|
||||
{
|
||||
super(DirectoryTreeNode.createRootNode());
|
||||
}
|
||||
|
||||
/**
|
||||
********************************************************************************
|
||||
*
|
||||
*/
|
||||
protected void setupFiles()
|
||||
{
|
||||
DirectoryTreeNode rootNode = (DirectoryTreeNode) getRoot();
|
||||
File[] fileSystemRoots = File.listRoots();
|
||||
|
||||
if (fileSystemRoots != null)
|
||||
{
|
||||
for (int n1 = 0; n1 < fileSystemRoots.length; n1++)
|
||||
{
|
||||
File fileSystemRoot;
|
||||
DirectoryTreeNode fileSystemRootNode;
|
||||
|
||||
fileSystemRoot = fileSystemRoots[n1];
|
||||
fileSystemRootNode = new DirectoryTreeNode(fileSystemRoot);
|
||||
|
||||
rootNode.add(fileSystemRootNode);
|
||||
|
||||
File[] files = fileSystemRoot.listFiles(new FilesFilter());
|
||||
|
||||
if (files != null)
|
||||
{
|
||||
for (int n2 = 0; n2 < files.length; n2++)
|
||||
{
|
||||
fileSystemRootNode.add(new DirectoryTreeNode(files[n2]));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
********************************************************************************
|
||||
*
|
||||
* @param directory
|
||||
*/
|
||||
protected void setDirectoryTree(DirectoryTree directoryTree)
|
||||
{
|
||||
m_directoryTree = directoryTree;
|
||||
|
||||
m_directoryTree.addTreeWillExpandListener(this);
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* Called before a directory tree node in the tree will be expanded. The tree node
|
||||
* to be expanded will contain a directory. The tree node will contain children
|
||||
* consisting of subdirectories and/or files. The subdirectory tree nodes will have
|
||||
* child tree nodes added so that they may be expanded.
|
||||
*
|
||||
* @param event
|
||||
*
|
||||
* @throws ExpandVetoException
|
||||
*/
|
||||
public void treeWillExpand(TreeExpansionEvent event)
|
||||
{
|
||||
TreePath treePath;
|
||||
DirectoryTreeNode treeNode;
|
||||
Enumeration children;
|
||||
|
||||
treePath = event.getPath();
|
||||
treeNode = (DirectoryTreeNode) treePath.getLastPathComponent();
|
||||
children = treeNode.children();
|
||||
|
||||
while (children.hasMoreElements())
|
||||
{
|
||||
DirectoryTreeNode childTreeNode = (DirectoryTreeNode) children.nextElement();
|
||||
File directory = (File) childTreeNode.getUserObject();
|
||||
File[] files = directory.listFiles(new FilesFilter());
|
||||
|
||||
if (files != null)
|
||||
{
|
||||
for (int n = 0; n < files.length; n++)
|
||||
{
|
||||
childTreeNode.add(new DirectoryTreeNode(files[n]));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* Called before a directory tree node in the tree will be collapsed. The tree node
|
||||
* to be collapsed will contain a directory. The tree node will contain children
|
||||
* consisting of subdirectories and/or files. The subdirectory tree nodes will have
|
||||
* their child tree nodes removed since they will no longer be visible.
|
||||
*
|
||||
* @param event
|
||||
*
|
||||
* @throws ExpandVetoException
|
||||
*/
|
||||
public void treeWillCollapse(TreeExpansionEvent event)
|
||||
{
|
||||
TreePath treePath = event.getPath();
|
||||
DirectoryTreeNode treeNode = (DirectoryTreeNode) treePath.getLastPathComponent();
|
||||
for (Enumeration children = treeNode.children(); children.hasMoreElements();) {
|
||||
DirectoryTreeNode childTreeNode = (DirectoryTreeNode) children.nextElement();
|
||||
childTreeNode.removeAllChildren();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
*******************************************************************************
|
||||
*******************************************************************************
|
||||
*/
|
||||
private class FilesFilter implements FileFilter
|
||||
{
|
||||
|
||||
public boolean accept(File file)
|
||||
{
|
||||
return file.isDirectory() && (file.isHidden() == false);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,67 +0,0 @@
|
||||
package net.sourceforge.pmd.swingui.viewer;
|
||||
|
||||
import java.io.File;
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Donald A. Leckie
|
||||
* @since August 17, 2002
|
||||
* @version $Revision$, $Date$
|
||||
*/
|
||||
class DirectoryTreeNode extends DefaultMutableTreeNode
|
||||
{
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
*/
|
||||
private DirectoryTreeNode(String name)
|
||||
{
|
||||
super(name);
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @param directory
|
||||
*/
|
||||
protected DirectoryTreeNode(File directory)
|
||||
{
|
||||
super(directory);
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @return The directory or file name.
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
Object userObject = getUserObject();
|
||||
|
||||
if (userObject instanceof String)
|
||||
{
|
||||
return (String) userObject;
|
||||
}
|
||||
|
||||
File file = ((File) userObject);
|
||||
String name = file.getName();
|
||||
|
||||
if ((name != null) && (name.length() > 0))
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
return file.getPath();
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @return A new root node.
|
||||
*/
|
||||
protected static DirectoryTreeNode createRootNode()
|
||||
{
|
||||
return new DirectoryTreeNode("File Directories");
|
||||
}
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
package net.sourceforge.pmd.swingui.viewer;
|
||||
|
||||
class JobThread extends Thread
|
||||
{
|
||||
|
||||
private MessageDialog m_messageDialog;
|
||||
|
||||
/**
|
||||
*********************************************************************************
|
||||
*
|
||||
* @param threadName
|
||||
*/
|
||||
protected JobThread(String threadName)
|
||||
{
|
||||
super(threadName);
|
||||
}
|
||||
|
||||
/**
|
||||
*********************************************************************************
|
||||
*
|
||||
* @return messageDialog
|
||||
*/
|
||||
protected MessageDialog getMessageDialog()
|
||||
{
|
||||
return m_messageDialog;
|
||||
}
|
||||
|
||||
/**
|
||||
*********************************************************************************
|
||||
*
|
||||
* @param messageDialog
|
||||
*/
|
||||
protected void setMessageDialog(MessageDialog messageDialog)
|
||||
{
|
||||
m_messageDialog = messageDialog;
|
||||
}
|
||||
|
||||
/**
|
||||
*********************************************************************************
|
||||
*
|
||||
*/
|
||||
protected void closeWindow()
|
||||
{
|
||||
m_messageDialog.setVisible(false);
|
||||
}
|
||||
}
|
@ -1,164 +0,0 @@
|
||||
package net.sourceforge.pmd.swingui.viewer;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Rectangle;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.PrintStream;
|
||||
import java.lang.Thread;
|
||||
import javax.swing.border.BevelBorder;
|
||||
import javax.swing.border.CompoundBorder;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.border.EtchedBorder;
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.SwingConstants;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Donald A. Leckie
|
||||
* @since August 17, 2002
|
||||
* @version $Revision$, $Date$
|
||||
*/
|
||||
class MessageDialog extends JDialog
|
||||
{
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
*
|
||||
* @param parentWindow
|
||||
* @param title
|
||||
* @param job
|
||||
*/
|
||||
private MessageDialog(JFrame parentWindow, String title, String message)
|
||||
{
|
||||
super(parentWindow, title, true);
|
||||
|
||||
int dialogWidth = 400;
|
||||
int dialogHeight = 100;
|
||||
Rectangle parentWindowBounds = parentWindow.getBounds();
|
||||
int x = parentWindowBounds.x + (parentWindowBounds.width - dialogWidth) / 2;
|
||||
int y = parentWindowBounds.y + (parentWindowBounds.height - dialogHeight) / 2;
|
||||
|
||||
setBounds(x, y, dialogWidth, dialogHeight);
|
||||
|
||||
JPanel basePanel = new JPanel();
|
||||
|
||||
{
|
||||
EtchedBorder etchedBorder;
|
||||
EmptyBorder emptyBorder;
|
||||
CompoundBorder compoundBorder;
|
||||
|
||||
etchedBorder = new EtchedBorder(EtchedBorder.LOWERED);
|
||||
emptyBorder = new EmptyBorder(15,15,15,15);
|
||||
compoundBorder = new CompoundBorder(etchedBorder, emptyBorder);
|
||||
|
||||
basePanel.setBorder(compoundBorder);
|
||||
}
|
||||
|
||||
basePanel.setLayout(new BorderLayout());
|
||||
getContentPane().add(basePanel, BorderLayout.CENTER);
|
||||
|
||||
JLabel messageArea = new JLabel(message);
|
||||
|
||||
{
|
||||
BevelBorder bevelBorder;
|
||||
EtchedBorder etchedBorder;
|
||||
EmptyBorder emptyBorder;
|
||||
CompoundBorder compoundBorder;
|
||||
|
||||
bevelBorder = new BevelBorder(BevelBorder.LOWERED);
|
||||
etchedBorder = new EtchedBorder(EtchedBorder.LOWERED);
|
||||
emptyBorder = new EmptyBorder(3,3,3,3);
|
||||
compoundBorder = new CompoundBorder(bevelBorder, etchedBorder);
|
||||
compoundBorder = new CompoundBorder(compoundBorder, emptyBorder);
|
||||
|
||||
messageArea.setBorder(compoundBorder);
|
||||
}
|
||||
|
||||
messageArea.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
messageArea.setVerticalAlignment(SwingConstants.CENTER);
|
||||
basePanel.add(messageArea, BorderLayout.CENTER);
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
*
|
||||
*/
|
||||
protected void setJobFinished()
|
||||
{
|
||||
setVisible(false);
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
*
|
||||
* @param parentWindow
|
||||
* @param title
|
||||
* @param job
|
||||
*/
|
||||
protected static void show(JFrame parentWindow, String message, JobThread job)
|
||||
{
|
||||
if (job != null)
|
||||
{
|
||||
if (message == null)
|
||||
{
|
||||
message = "No message.";
|
||||
}
|
||||
|
||||
MessageDialog dialog = new MessageDialog(parentWindow, "Message", message);
|
||||
|
||||
job.setMessageDialog(dialog);
|
||||
job.start();
|
||||
dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
|
||||
dialog.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
*
|
||||
* @param parentWindow
|
||||
* @param exception
|
||||
*/
|
||||
protected static void show(JFrame parentWindow, String message, Exception exception)
|
||||
{
|
||||
if (exception != null)
|
||||
{
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream(1000);
|
||||
PrintStream writer = new PrintStream(stream);
|
||||
|
||||
exception.printStackTrace(writer);
|
||||
|
||||
if (message == null) {
|
||||
message = stream.toString();
|
||||
} else {
|
||||
message = message + "\n" + stream.toString();
|
||||
}
|
||||
|
||||
writer.close();
|
||||
MessageDialog dialog = new MessageDialog(parentWindow, "Exception", message);
|
||||
|
||||
dialog.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
*
|
||||
* @param parentWindow
|
||||
* @param exception
|
||||
*/
|
||||
protected static void show(JFrame parentWindow, String message)
|
||||
{
|
||||
if (message == null) {
|
||||
message = "There is no message.";
|
||||
}
|
||||
|
||||
MessageDialog dialog = new MessageDialog(parentWindow, "message", message);
|
||||
|
||||
dialog.setVisible(true);
|
||||
}
|
||||
}
|
@ -1,206 +0,0 @@
|
||||
package net.sourceforge.pmd.swingui.viewer;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.*;
|
||||
import javax.xml.parsers.*;
|
||||
import org.w3c.dom.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Donald A. Leckie
|
||||
* @since August 17, 2002
|
||||
* @version $Revision$, $Date$
|
||||
*/
|
||||
public class PMDViewer extends JFrame
|
||||
{
|
||||
|
||||
private DirectoryTree m_directoryTree;
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
*
|
||||
*/
|
||||
public PMDViewer()
|
||||
{
|
||||
super("PMD Viewer");
|
||||
|
||||
int windowWidth = 900;
|
||||
int windowHeight = 900;
|
||||
int windowMargin = 20;
|
||||
Dimension screenSize = getToolkit().getScreenSize();
|
||||
int windowLocationX = (screenSize.width - windowWidth) / 2;
|
||||
int windowLocationY = (screenSize.height - windowHeight) / 2;
|
||||
|
||||
setLocation(windowLocationX, windowLocationY);
|
||||
setSize(windowWidth, windowHeight);
|
||||
setResizable(true);
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
//
|
||||
// Create the source file chooser label that will go into the split pane's top panel.
|
||||
//
|
||||
JLabel selectSourceFileLabel = new JLabel();
|
||||
|
||||
{
|
||||
selectSourceFileLabel.setFont(new Font("Dialog", Font.BOLD, 12));
|
||||
selectSourceFileLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 0));
|
||||
selectSourceFileLabel.setText("Select a source file and its analysis results will appear below.");
|
||||
}
|
||||
|
||||
//
|
||||
// Create the directory tree that will go into the split pane's top panel on the left.
|
||||
//
|
||||
m_directoryTree = new DirectoryTree(this);
|
||||
|
||||
//
|
||||
// Create a scroll pane for the file list.
|
||||
//
|
||||
JScrollPane directoryTreeScrollPane = new JScrollPane(m_directoryTree);
|
||||
|
||||
{
|
||||
directoryTreeScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
||||
directoryTreeScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
|
||||
directoryTreeScrollPane.getViewport().setBackground(Color.white);
|
||||
directoryTreeScrollPane.setAutoscrolls(true);
|
||||
directoryTreeScrollPane.setBorder(BorderFactory.createEtchedBorder());
|
||||
}
|
||||
|
||||
//
|
||||
// Create the file list that will go into the split pane's top panel on the right.
|
||||
//
|
||||
SourceFileList sourceFileList = new SourceFileList();
|
||||
{
|
||||
sourceFileList.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
|
||||
sourceFileList.setBackground(Color.white);
|
||||
sourceFileList.setDirectoryTree(m_directoryTree);
|
||||
}
|
||||
|
||||
//
|
||||
// Create a scroll pane for the file list.
|
||||
//
|
||||
JScrollPane fileListScrollPane = new JScrollPane(sourceFileList);
|
||||
|
||||
{
|
||||
fileListScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
||||
fileListScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
|
||||
fileListScrollPane.getViewport().setBackground(Color.white);
|
||||
fileListScrollPane.setAutoscrolls(true);
|
||||
fileListScrollPane.setBorder(BorderFactory.createEtchedBorder());
|
||||
}
|
||||
|
||||
//
|
||||
// Create a split pane for the directory tree and file list.
|
||||
//
|
||||
JSplitPane directoryAndFileSplitPane = new JSplitPane();
|
||||
|
||||
{
|
||||
directoryAndFileSplitPane.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
|
||||
directoryAndFileSplitPane.setDividerLocation(0.5);
|
||||
directoryAndFileSplitPane.setDividerSize(5);
|
||||
directoryAndFileSplitPane.setLeftComponent(directoryTreeScrollPane);
|
||||
directoryAndFileSplitPane.setRightComponent(fileListScrollPane);
|
||||
}
|
||||
|
||||
//
|
||||
// The editor pane where the results are stored. An editor pane is used so that
|
||||
// the user can enter notes and copy the results.
|
||||
//
|
||||
ResultsEditorPane resultsEditorPane = new ResultsEditorPane(this);
|
||||
|
||||
{
|
||||
resultsEditorPane.setSelectionColor(Color.blue);
|
||||
resultsEditorPane.setSourceFileList(sourceFileList);
|
||||
}
|
||||
|
||||
//
|
||||
// The scroll pane that contains the editor pane.
|
||||
//
|
||||
JScrollPane resultsScrollPane = new JScrollPane(resultsEditorPane);
|
||||
|
||||
{
|
||||
resultsScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
||||
resultsScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
|
||||
resultsScrollPane.getViewport().setBackground(Color.white);
|
||||
resultsScrollPane.setAutoscrolls(true);
|
||||
resultsScrollPane.setBorder(BorderFactory.createEtchedBorder());
|
||||
}
|
||||
|
||||
//
|
||||
// Create the split pane that contains the top panel and bottom panels.
|
||||
//
|
||||
JSplitPane mainSplitPane = new JSplitPane();
|
||||
|
||||
{
|
||||
mainSplitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
|
||||
mainSplitPane.setDividerLocation(0.75);
|
||||
mainSplitPane.setDividerSize(5);
|
||||
mainSplitPane.setTopComponent(directoryAndFileSplitPane);
|
||||
mainSplitPane.setBottomComponent(resultsScrollPane);
|
||||
}
|
||||
|
||||
//
|
||||
// Create the content panel that will contain the split pane.
|
||||
//
|
||||
JPanel contentPanel = new JPanel(new BorderLayout());
|
||||
|
||||
{
|
||||
Border outsideBorder = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED);
|
||||
Border insideBorder = BorderFactory.createEmptyBorder(windowMargin,windowMargin,windowMargin,windowMargin);
|
||||
Border compoundBorder = BorderFactory.createCompoundBorder(outsideBorder, insideBorder);
|
||||
|
||||
contentPanel.setBorder(compoundBorder);
|
||||
contentPanel.add(selectSourceFileLabel, BorderLayout.NORTH);
|
||||
contentPanel.add(mainSplitPane, BorderLayout.CENTER);
|
||||
}
|
||||
|
||||
//
|
||||
// Put the content panel into the frame's content pane.
|
||||
//
|
||||
getContentPane().add(contentPanel);
|
||||
}
|
||||
|
||||
/**
|
||||
*********************************************************************************
|
||||
*
|
||||
* @param args
|
||||
*/
|
||||
public void setupFiles()
|
||||
{
|
||||
m_directoryTree.setupFiles();
|
||||
}
|
||||
|
||||
/**
|
||||
*********************************************************************************
|
||||
*
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Setup the User Interface based on this computer's operating system.
|
||||
// This must be done before calling Java and Swing classes that call the GUI.
|
||||
String useLookAndFeel = UIManager.getSystemLookAndFeelClassName();
|
||||
|
||||
UIManager.setLookAndFeel(useLookAndFeel);
|
||||
|
||||
PMDViewer pmdViewer = new PMDViewer();
|
||||
|
||||
pmdViewer.setVisible(true);
|
||||
pmdViewer.setupFiles();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
exception.printStackTrace();
|
||||
}
|
||||
catch (Error error)
|
||||
{
|
||||
error.printStackTrace();
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
}
|
@ -1,180 +0,0 @@
|
||||
package net.sourceforge.pmd.swingui.viewer;
|
||||
|
||||
import java.awt.Font;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
import javax.swing.JEditorPane;
|
||||
import net.sourceforge.pmd.PMD;
|
||||
import net.sourceforge.pmd.renderers.XMLRenderer;
|
||||
import net.sourceforge.pmd.Report;
|
||||
import net.sourceforge.pmd.RuleContext;
|
||||
import net.sourceforge.pmd.RuleSet;
|
||||
import net.sourceforge.pmd.RuleSetFactory;
|
||||
import net.sourceforge.pmd.RuleSetNotFoundException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Donald A. Leckie
|
||||
* @since August 17, 2002
|
||||
* @version $Revision$, $Date$
|
||||
*/
|
||||
class ResultsEditorPane extends JEditorPane implements ListSelectionListener
|
||||
{
|
||||
|
||||
private PMDViewer m_pmdViewer;
|
||||
private SourceFileList m_sourceFileList;
|
||||
private PMD m_pmd;
|
||||
private RuleContext m_ruleContext;
|
||||
private RuleSet m_ruleSet;
|
||||
|
||||
/**
|
||||
********************************************************************************
|
||||
*/
|
||||
protected ResultsEditorPane(PMDViewer pmdViewer)
|
||||
{
|
||||
super();
|
||||
|
||||
setFont(new Font("Monospaced", Font.PLAIN, 12));
|
||||
|
||||
m_pmdViewer = pmdViewer;
|
||||
m_pmd = new PMD();
|
||||
m_ruleContext = new RuleContext();
|
||||
RuleSetFactory ruleSetFactory = new RuleSetFactory();
|
||||
Iterator ruleSets = null;
|
||||
m_ruleSet = new RuleSet();
|
||||
|
||||
try
|
||||
{
|
||||
ruleSets = ruleSetFactory.getRegisteredRuleSets();
|
||||
}
|
||||
catch (RuleSetNotFoundException exception)
|
||||
{
|
||||
String message = "Could not get registered rule sets.";
|
||||
|
||||
MessageDialog.show(m_pmdViewer, message, exception);
|
||||
m_pmdViewer.setVisible(false);
|
||||
}
|
||||
|
||||
if (ruleSets.hasNext() == false)
|
||||
{
|
||||
String message = "There are no rule sets.";
|
||||
|
||||
MessageDialog.show(m_pmdViewer, message);
|
||||
m_pmdViewer.setVisible(false);
|
||||
}
|
||||
|
||||
while (ruleSets.hasNext())
|
||||
{
|
||||
m_ruleSet.addRuleSet((RuleSet) ruleSets.next());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
********************************************************************************
|
||||
*
|
||||
* @param sourceFileList
|
||||
*/
|
||||
protected void setSourceFileList(SourceFileList sourceFileList)
|
||||
{
|
||||
m_sourceFileList = sourceFileList;
|
||||
|
||||
m_sourceFileList.addListSelectionListener(this);
|
||||
}
|
||||
|
||||
/**
|
||||
********************************************************************************
|
||||
*
|
||||
* @param event
|
||||
*/
|
||||
public void valueChanged(ListSelectionEvent event)
|
||||
{
|
||||
int index = event.getFirstIndex();
|
||||
File file = m_sourceFileList.getFile(index);
|
||||
|
||||
// Swing may generate a changing event more than once. All changing events, except
|
||||
// the last event, with have the "value is adjusting" flag set true. We want only
|
||||
// the last event.
|
||||
if (event.getValueIsAdjusting() == false) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (file == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_ruleContext.setSourceCodeFilename(file.getPath());
|
||||
m_ruleContext.setReport(new Report());
|
||||
|
||||
AnalyzeThread analyzeThread = new AnalyzeThread("Analyze", file);
|
||||
|
||||
MessageDialog.show(m_pmdViewer, "Analyzing. Please wait...", analyzeThread);
|
||||
/*
|
||||
try
|
||||
{
|
||||
setText("Analyzing. Please wait...");
|
||||
paintImmediately(getBounds());
|
||||
m_pmd.processFile(new FileInputStream(file), m_ruleSet, m_ruleContext);
|
||||
setText((new TextRenderer()).render(fileName, m_ruleContext.getReport()));
|
||||
}
|
||||
catch (FileNotFoundException exception)
|
||||
{
|
||||
MessageDialog.show(m_pmdViewer, null, exception);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
********************************************************************************
|
||||
********************************************************************************
|
||||
********************************************************************************
|
||||
*/
|
||||
private class AnalyzeThread extends JobThread
|
||||
{
|
||||
private File m_file;
|
||||
private ResultsEditorPane m_resultsEditorPane;
|
||||
|
||||
/**
|
||||
****************************************************************************
|
||||
*
|
||||
* @param name
|
||||
*/
|
||||
private AnalyzeThread(String threadName, File file)
|
||||
{
|
||||
super(threadName);
|
||||
|
||||
m_file = file;
|
||||
m_resultsEditorPane = ResultsEditorPane.this;
|
||||
}
|
||||
|
||||
/**
|
||||
***************************************************************************
|
||||
*
|
||||
*/
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
m_pmd.processFile(new FileInputStream(m_file),
|
||||
m_resultsEditorPane.m_ruleSet,
|
||||
m_resultsEditorPane.m_ruleContext);
|
||||
setText((new TextRenderer()).render(m_file.getPath(),
|
||||
m_ruleContext.getReport()));
|
||||
}
|
||||
catch (FileNotFoundException exception)
|
||||
{
|
||||
MessageDialog.show(m_pmdViewer, null, exception);
|
||||
}
|
||||
|
||||
// This is very important; otherwise, the message window would remain open
|
||||
// with no way to close it because the "close icon" was made non-functional.
|
||||
closeWindow();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,155 +0,0 @@
|
||||
package net.sourceforge.pmd.swingui.viewer;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.util.Vector;
|
||||
import javax.swing.event.TreeSelectionEvent;
|
||||
import javax.swing.event.TreeSelectionListener;
|
||||
import javax.swing.JList;
|
||||
import javax.swing.tree.TreePath;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Donald A. Leckie
|
||||
* @since August 17, 2002
|
||||
* @version $Revision$, $Date$
|
||||
*/
|
||||
class SourceFileList extends JList implements TreeSelectionListener
|
||||
{
|
||||
|
||||
private DirectoryTree m_directoryTree;
|
||||
private File m_lastDirectory;
|
||||
|
||||
//Constants
|
||||
private final String JAVA = ".java";
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
*/
|
||||
protected SourceFileList()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
*
|
||||
* @param index
|
||||
*/
|
||||
protected File getFile(int index)
|
||||
{
|
||||
if ((index < 0) || (index >= getModel().getSize()))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
SourceFileListEntry entry;
|
||||
|
||||
entry = (SourceFileListEntry) getModel().getElementAt(index);
|
||||
|
||||
return entry.getFile();
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
*
|
||||
* @param directoryTree
|
||||
*/
|
||||
protected void setDirectoryTree(DirectoryTree directoryTree)
|
||||
{
|
||||
m_directoryTree = directoryTree;
|
||||
|
||||
m_directoryTree.addTreeSelectionListener(this);
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
*
|
||||
* @param directoryTree
|
||||
*/
|
||||
public void valueChanged(TreeSelectionEvent event)
|
||||
{
|
||||
TreePath treePath = event.getPath();
|
||||
DirectoryTreeNode treeNode = (DirectoryTreeNode) treePath.getLastPathComponent();
|
||||
Object userObject = treeNode.getUserObject();
|
||||
|
||||
if ((userObject instanceof File) && (userObject != m_lastDirectory))
|
||||
{
|
||||
File directory = (File) userObject;
|
||||
m_lastDirectory = directory;
|
||||
File[] files = directory.listFiles(new FilesFilter());
|
||||
Vector fileNames = new Vector();
|
||||
|
||||
if (files != null)
|
||||
{
|
||||
for (int n = 0; n < files.length; n++)
|
||||
{
|
||||
fileNames.add(new SourceFileListEntry(files[n]));
|
||||
}
|
||||
}
|
||||
|
||||
setListData(fileNames);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
*******************************************************************************
|
||||
*******************************************************************************
|
||||
*/
|
||||
private class FilesFilter implements FileFilter
|
||||
{
|
||||
|
||||
public boolean accept(File file)
|
||||
{
|
||||
if (file.isFile() && !file.isHidden())
|
||||
{
|
||||
return file.getName().toLowerCase().endsWith(JAVA);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
*******************************************************************************
|
||||
*******************************************************************************
|
||||
*/
|
||||
private class SourceFileListEntry
|
||||
{
|
||||
|
||||
private File m_file;
|
||||
|
||||
/**
|
||||
********************************************************************************
|
||||
*/
|
||||
protected SourceFileListEntry(File file)
|
||||
{
|
||||
m_file = file;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @return The directory or file name.
|
||||
*/
|
||||
private File getFile()
|
||||
{
|
||||
return m_file;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @return The directory or file name.
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
if ((m_file.getName() != null) && (m_file.getName().length() > 0)) {
|
||||
return m_file.getName();
|
||||
}
|
||||
return m_file.getPath();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,111 +0,0 @@
|
||||
package net.sourceforge.pmd.swingui.viewer;
|
||||
|
||||
import java.util.Iterator;
|
||||
import net.sourceforge.pmd.Report;
|
||||
import net.sourceforge.pmd.Rule;
|
||||
import net.sourceforge.pmd.RuleViolation;
|
||||
import net.sourceforge.pmd.renderers.Renderer;
|
||||
|
||||
/**
|
||||
*
|
||||
* Converts the violations list into a text string for viewing.
|
||||
*
|
||||
* @author Donald A. Leckie
|
||||
* @since August 17, 2002
|
||||
* @version $Revision$, $Date$
|
||||
*/
|
||||
class TextRenderer
|
||||
{
|
||||
|
||||
/**
|
||||
* The end of line string for this machine.
|
||||
*/
|
||||
protected String EOL = System.getProperty("line.separator", "\n");
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
*
|
||||
* @param report
|
||||
*
|
||||
* @return Formatted text.
|
||||
*/
|
||||
public String render(String fileName, Report report)
|
||||
{
|
||||
StringBuffer outputText = new StringBuffer(500);
|
||||
Iterator violations = report.iterator();
|
||||
|
||||
outputText.append("Source File: ");
|
||||
outputText.append(fileName);
|
||||
outputText.append(EOL);
|
||||
|
||||
if (violations.hasNext() == false)
|
||||
{
|
||||
outputText.append("\nNo rule violations detected.");
|
||||
}
|
||||
|
||||
while (violations.hasNext())
|
||||
{
|
||||
RuleViolation ruleViolation = (RuleViolation) violations.next();
|
||||
Rule rule = ruleViolation.getRule();
|
||||
|
||||
//
|
||||
// Line Number
|
||||
//
|
||||
outputText.append(EOL);
|
||||
outputText.append("Line: ");
|
||||
outputText.append(ruleViolation.getLine());
|
||||
outputText.append(EOL);
|
||||
|
||||
//
|
||||
// Rule Name
|
||||
//
|
||||
outputText.append("Rule Name: ");
|
||||
outputText.append(rule.getName());
|
||||
outputText.append(EOL);
|
||||
|
||||
//
|
||||
// Rule Message
|
||||
//
|
||||
String ruleMessage = ruleViolation.getDescription();
|
||||
|
||||
if (ruleMessage == null) {
|
||||
ruleMessage = "";
|
||||
} else {
|
||||
ruleMessage = ruleMessage.replace('\n', ' ').trim();
|
||||
}
|
||||
|
||||
outputText.append("Rule: ");
|
||||
outputText.append(ruleMessage);
|
||||
outputText.append(EOL);
|
||||
|
||||
//
|
||||
// Rule Description
|
||||
//
|
||||
String description = rule.getDescription();
|
||||
|
||||
if (description == null) {
|
||||
description = "";
|
||||
} else {
|
||||
description = description.replace('\n', ' ').trim();
|
||||
}
|
||||
|
||||
outputText.append("Description: ");
|
||||
outputText.append(description);
|
||||
outputText.append(EOL);
|
||||
|
||||
//
|
||||
// Rule Example
|
||||
//
|
||||
String example = rule.getExample();
|
||||
|
||||
if ((example != null) && (example.length() > 0))
|
||||
{
|
||||
outputText.append("Example: ");
|
||||
outputText.append(example);
|
||||
outputText.append(EOL);
|
||||
}
|
||||
}
|
||||
|
||||
return outputText.toString();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user