HTML rendering improvements and message dialog/thread improvements.
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@809 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -51,13 +51,14 @@ class HTMLResultRenderer
|
||||
writer.write("<h3><center><font color=\"blue\">PMD Analysis Results</font></center></h3>");
|
||||
writer.write("<b>Source File:</b> ");
|
||||
writer.write(fileName);
|
||||
writer.write("<br>");
|
||||
|
||||
//
|
||||
// Create a table.
|
||||
//
|
||||
if (violations.hasNext() == false)
|
||||
{
|
||||
writer.write("No rule violations detected.");
|
||||
writer.write("<p>No rule violations detected.");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1,19 +1,19 @@
|
||||
package net.sourceforge.pmd.swingui;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.lang.Thread;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Donald A. Leckie
|
||||
* @since August 17, 2002
|
||||
* @version $Revision$, $Date$
|
||||
*/
|
||||
abstract class JobThread extends Thread
|
||||
{
|
||||
|
||||
private List m_listeners;
|
||||
|
||||
//Constants
|
||||
public static final String STARTED_JOB_THREAD = "Started Job Thread";
|
||||
public static final String FINISHED_JOB_THREAD = "Finished Job Thread";
|
||||
/**
|
||||
*********************************************************************************
|
||||
*
|
||||
@ -29,7 +29,7 @@ abstract class JobThread extends Thread
|
||||
*
|
||||
* @param listener
|
||||
*/
|
||||
protected void addListener(ActionListener listener)
|
||||
protected void addListener(JobThreadListener listener)
|
||||
{
|
||||
if (m_listeners == null)
|
||||
{
|
||||
@ -43,15 +43,49 @@ abstract class JobThread extends Thread
|
||||
*********************************************************************************
|
||||
*
|
||||
*/
|
||||
private void notifyListeners(ActionEvent event)
|
||||
private void notifyJobThreadStarted(JobThreadEvent event)
|
||||
{
|
||||
if (m_listeners != null)
|
||||
{
|
||||
for (int n = 0; n < m_listeners.size(); n++)
|
||||
{
|
||||
ActionListener listener = (ActionListener) m_listeners.get(n);
|
||||
JobThreadListener listener = (JobThreadListener) m_listeners.get(n);
|
||||
|
||||
listener.actionPerformed(event);
|
||||
listener.jobThreadStarted(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*********************************************************************************
|
||||
*
|
||||
*/
|
||||
private void notifyJobThreadFinished(JobThreadEvent event)
|
||||
{
|
||||
if (m_listeners != null)
|
||||
{
|
||||
for (int n = 0; n < m_listeners.size(); n++)
|
||||
{
|
||||
JobThreadListener listener = (JobThreadListener) m_listeners.get(n);
|
||||
|
||||
listener.jobThreadFinished(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*********************************************************************************
|
||||
*
|
||||
*/
|
||||
protected void notifyJobThreadStatus(JobThreadEvent event)
|
||||
{
|
||||
if (m_listeners != null)
|
||||
{
|
||||
for (int n = 0; n < m_listeners.size(); n++)
|
||||
{
|
||||
JobThreadListener listener = (JobThreadListener) m_listeners.get(n);
|
||||
|
||||
listener.jobThreadStatus(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -61,7 +95,7 @@ abstract class JobThread extends Thread
|
||||
*
|
||||
* @param listener
|
||||
*/
|
||||
protected void removeListener(ActionListener listener)
|
||||
protected void removeListener(JobThreadListener listener)
|
||||
{
|
||||
m_listeners.remove(listener);
|
||||
}
|
||||
@ -72,9 +106,9 @@ abstract class JobThread extends Thread
|
||||
*/
|
||||
public void run()
|
||||
{
|
||||
notifyListeners(new ActionEvent(this, 1, STARTED_JOB_THREAD));
|
||||
notifyJobThreadStarted(new JobThreadEvent(this));
|
||||
process();
|
||||
notifyListeners(new ActionEvent(this, 2, FINISHED_JOB_THREAD));
|
||||
notifyJobThreadFinished(new JobThreadEvent(this));
|
||||
}
|
||||
|
||||
/**
|
||||
|
48
pmd/src/net/sourceforge/pmd/swingui/JobThreadEvent.java
Normal file
48
pmd/src/net/sourceforge/pmd/swingui/JobThreadEvent.java
Normal file
@ -0,0 +1,48 @@
|
||||
package net.sourceforge.pmd.swingui;
|
||||
|
||||
import java.util.EventObject;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Donald A. Leckie
|
||||
* @since August 27, 2002
|
||||
* @version $Revision$, $Date$
|
||||
*/
|
||||
class JobThreadEvent extends EventObject
|
||||
{
|
||||
|
||||
private String m_message;
|
||||
|
||||
/**
|
||||
*********************************************************************************
|
||||
*
|
||||
* @param source
|
||||
*/
|
||||
protected JobThreadEvent(JobThread source)
|
||||
{
|
||||
super(source);
|
||||
}
|
||||
|
||||
/**
|
||||
*********************************************************************************
|
||||
*
|
||||
* @param source
|
||||
* @param message
|
||||
*/
|
||||
protected JobThreadEvent(JobThread source, String message)
|
||||
{
|
||||
super(source);
|
||||
|
||||
m_message = message;
|
||||
}
|
||||
|
||||
/**
|
||||
*********************************************************************************
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected String getMessage()
|
||||
{
|
||||
return (m_message != null) ? m_message : "";
|
||||
}
|
||||
}
|
35
pmd/src/net/sourceforge/pmd/swingui/JobThreadListener.java
Normal file
35
pmd/src/net/sourceforge/pmd/swingui/JobThreadListener.java
Normal file
@ -0,0 +1,35 @@
|
||||
package net.sourceforge.pmd.swingui;
|
||||
|
||||
import java.util.EventListener;
|
||||
import java.util.EventObject;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Donald A. Leckie
|
||||
* @since August 27, 2002
|
||||
* @version $Revision$, $Date$
|
||||
*/
|
||||
interface JobThreadListener extends EventListener
|
||||
{
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
*
|
||||
* @parameter event
|
||||
*/
|
||||
public void jobThreadStarted(JobThreadEvent event);
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
*
|
||||
* @parameter event
|
||||
*/
|
||||
public void jobThreadFinished(JobThreadEvent event);
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
*
|
||||
* @parameter event
|
||||
*/
|
||||
public void jobThreadStatus(JobThreadEvent event);
|
||||
}
|
@ -1,8 +1,6 @@
|
||||
package net.sourceforge.pmd.swingui;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.Rectangle;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.PrintStream;
|
||||
@ -23,9 +21,10 @@ import javax.swing.SwingConstants;
|
||||
* @since August 17, 2002
|
||||
* @version $Revision$, $Date$
|
||||
*/
|
||||
class MessageDialog extends JDialog implements ActionListener
|
||||
class MessageDialog extends JDialog implements JobThreadListener
|
||||
{
|
||||
|
||||
private JLabel m_messageArea;
|
||||
private JobThread m_jobThread;
|
||||
|
||||
/**
|
||||
@ -42,7 +41,7 @@ class MessageDialog extends JDialog implements ActionListener
|
||||
int dialogHeight = 100;
|
||||
Rectangle parentWindowBounds = PMDViewer.getWindow().getBounds();
|
||||
int x = parentWindowBounds.x + (parentWindowBounds.width - dialogWidth) / 2;
|
||||
int y = parentWindowBounds.y + (parentWindowBounds.height - dialogHeight) / 2;;
|
||||
int y = parentWindowBounds.y + (parentWindowBounds.height - dialogHeight) / 2;
|
||||
|
||||
setBounds(x, y, dialogWidth, dialogHeight);
|
||||
|
||||
@ -63,7 +62,7 @@ class MessageDialog extends JDialog implements ActionListener
|
||||
basePanel.setLayout(new BorderLayout());
|
||||
getContentPane().add(basePanel, BorderLayout.CENTER);
|
||||
|
||||
JLabel messageArea = new JLabel(message);
|
||||
m_messageArea = new JLabel(message);
|
||||
|
||||
{
|
||||
BevelBorder bevelBorder;
|
||||
@ -77,27 +76,41 @@ class MessageDialog extends JDialog implements ActionListener
|
||||
compoundBorder = new CompoundBorder(bevelBorder, etchedBorder);
|
||||
compoundBorder = new CompoundBorder(compoundBorder, emptyBorder);
|
||||
|
||||
messageArea.setBorder(compoundBorder);
|
||||
m_messageArea.setBorder(compoundBorder);
|
||||
}
|
||||
|
||||
messageArea.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
messageArea.setVerticalAlignment(SwingConstants.CENTER);
|
||||
basePanel.add(messageArea, BorderLayout.CENTER);
|
||||
m_messageArea.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
m_messageArea.setVerticalAlignment(SwingConstants.CENTER);
|
||||
basePanel.add(m_messageArea, BorderLayout.CENTER);
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
*
|
||||
* @parameter event
|
||||
*/
|
||||
public void actionPerformed(ActionEvent event)
|
||||
public void jobThreadStarted(JobThreadEvent event)
|
||||
{
|
||||
if (event.getSource().equals(m_jobThread))
|
||||
{
|
||||
if (event.getActionCommand().equals(JobThread.FINISHED_JOB_THREAD))
|
||||
{
|
||||
setVisible(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
*
|
||||
* @parameter event
|
||||
*/
|
||||
public void jobThreadFinished(JobThreadEvent event)
|
||||
{
|
||||
setVisible(false);
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
*
|
||||
* @parameter event
|
||||
*/
|
||||
public void jobThreadStatus(JobThreadEvent event)
|
||||
{
|
||||
m_messageArea.setText(event.getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -32,13 +32,13 @@ public class PMDViewer extends JFrame
|
||||
*******************************************************************************
|
||||
*
|
||||
*/
|
||||
public PMDViewer()
|
||||
private PMDViewer()
|
||||
{
|
||||
super("PMD Viewer");
|
||||
|
||||
m_pmdViewer = this;
|
||||
|
||||
int windowWidth = 1000;
|
||||
int windowWidth = 1200;
|
||||
int windowHeight = 1000;
|
||||
int windowMargin = 10;
|
||||
Dimension screenSize = getToolkit().getScreenSize();
|
||||
@ -195,7 +195,7 @@ public class PMDViewer extends JFrame
|
||||
*
|
||||
* @param args
|
||||
*/
|
||||
public void setupFiles()
|
||||
private void setupFiles()
|
||||
{
|
||||
m_directoryTree.setupFiles();
|
||||
}
|
||||
|
@ -137,8 +137,21 @@ class ResultsViewer extends JEditorPane implements ListSelectionListener
|
||||
m_resultsViewer.m_ruleSet,
|
||||
m_resultsViewer.m_ruleContext);
|
||||
|
||||
HTMLResultRenderer renderer = new HTMLResultRenderer();
|
||||
setText(renderer.render(m_file.getPath(), m_ruleContext.getReport()));
|
||||
JobThreadEvent event;
|
||||
|
||||
event = new JobThreadEvent(this, "Rendering analysis results into HTML page. Please wait...");
|
||||
|
||||
notifyJobThreadStatus(event);
|
||||
|
||||
HTMLResultRenderer renderer;
|
||||
String htmlText;
|
||||
|
||||
renderer = new HTMLResultRenderer();
|
||||
htmlText = renderer.render(m_file.getPath(), m_ruleContext.getReport());
|
||||
event = new JobThreadEvent(this, "Storing HTML page into viewer. Please wait...");
|
||||
|
||||
notifyJobThreadStatus(event);
|
||||
setText(htmlText);
|
||||
}
|
||||
catch (FileNotFoundException exception)
|
||||
{
|
||||
|
Reference in New Issue
Block a user