You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@excalibur.apache.org by le...@apache.org on 2004/08/02 06:44:47 UTC
svn commit: rev 35574 - excalibur/trunk/containerkit/instrument/client/src/java/org/apache/excalibur/instrument/client
Author: leif
Date: Sun Aug 1 21:44:46 2004
New Revision: 35574
Modified:
excalibur/trunk/containerkit/instrument/client/src/java/org/apache/excalibur/instrument/client/InstrumentClientFrame.java
excalibur/trunk/containerkit/instrument/client/src/java/org/apache/excalibur/instrument/client/InstrumentSampleFrame.java
excalibur/trunk/containerkit/instrument/client/src/java/org/apache/excalibur/instrument/client/LineChart.java
excalibur/trunk/containerkit/instrument/client/src/java/org/apache/excalibur/instrument/client/MenuBar.java
Log:
Add antialias support for charts.
Modified: excalibur/trunk/containerkit/instrument/client/src/java/org/apache/excalibur/instrument/client/InstrumentClientFrame.java
==============================================================================
--- excalibur/trunk/containerkit/instrument/client/src/java/org/apache/excalibur/instrument/client/InstrumentClientFrame.java (original)
+++ excalibur/trunk/containerkit/instrument/client/src/java/org/apache/excalibur/instrument/client/InstrumentClientFrame.java Sun Aug 1 21:44:46 2004
@@ -82,6 +82,8 @@
private JSplitPane m_splitPane;
private MenuBar m_menuBar;
private StatusBar m_statusBar;
+
+ private boolean m_antialias;
private File m_desktopFile;
private File m_desktopFileDir;
@@ -302,6 +304,8 @@
frameState.getAttributeAsInteger( "divider-location" ) );
m_splitPane.setLastDividerLocation(
frameState.getAttributeAsInteger( "last-divider-location" ) );
+ // Antialias.
+ m_antialias = frameState.getAttributeAsBoolean( "antialias", false );
}
catch ( ConfigurationException e )
{
@@ -580,6 +584,8 @@
// Split Pane state
frameState.setAttribute( "divider-location", Integer.toString( m_splitPane.getDividerLocation() ) );
frameState.setAttribute( "last-divider-location", Integer.toString( m_splitPane.getLastDividerLocation() ) );
+ // Antialias
+ frameState.setAttribute( "antialias", Boolean.toString( m_antialias ) );
// Add frame state
state.addChild( frameState );
@@ -670,6 +676,15 @@
int screenHeight = screenSize.height;
setLocation( screenWidth / 20, screenHeight / 20 );
setSize( screenWidth * 9 / 10, screenHeight * 8 / 10 );
+ }
+
+ boolean isAntialias()
+ {
+ return m_antialias;
+ }
+ void setAntialias( boolean antialias )
+ {
+ m_antialias = antialias;
}
void updateConnectionTab( InstrumentManagerConnection connection )
Modified: excalibur/trunk/containerkit/instrument/client/src/java/org/apache/excalibur/instrument/client/InstrumentSampleFrame.java
==============================================================================
--- excalibur/trunk/containerkit/instrument/client/src/java/org/apache/excalibur/instrument/client/InstrumentSampleFrame.java (original)
+++ excalibur/trunk/containerkit/instrument/client/src/java/org/apache/excalibur/instrument/client/InstrumentSampleFrame.java Sun Aug 1 21:44:46 2004
@@ -277,50 +277,58 @@
{
// Once per 10 seconds.
hInterval = (int)( 10000 / interval );
- format = "{2}:{3}:{4}";
- detailFormat = "{0}/{1} {2}:{3}:{4}.{5}";
+ format = "{3}:{4}:{5}";
+ detailFormat = "{1}/{2} {3}:{4}:{5}.{6}";
}
else if( interval < 60000 )
{
// Once per minute.
hInterval = (int)( 60000 / interval );
- format = "{2}:{3}:{4}";
- detailFormat = "{0}/{1} {2}:{3}:{4}";
+ format = "{3}:{4}:{5}";
+ detailFormat = "{1}/{2} {3}:{4}:{5}";
}
else if( interval < 600000 )
{
// Once per 10 minutes
hInterval = (int)( 600000 / interval );
- format = "{0}/{1} {2}:{3}";
- detailFormat = "{0}/{1} {2}:{3}";
+ format = "{1}/{2} {3}:{4}";
+ detailFormat = "{1}/{2} {3}:{4}";
}
else if( interval < 3600000 )
{
// Once per hour.
hInterval = (int)( 3600000 / interval );
- format = "{0}/{1} {2}:{3}";
- detailFormat = "{0}/{1} {2}:{3}";
+ format = "{1}/{2} {3}:{4}";
+ detailFormat = "{1}/{2} {3}:{4}";
}
else if( interval < 86400000 )
{
// Once per day.
hInterval = (int)( 86400000 / interval );
- format = "{0}/{1}";
- detailFormat = "{0}/{1} {2}:{3}";
+ format = "{1}/{2}";
+ detailFormat = "{1}/{2} {3}:{4}";
+ }
+ else if( interval < 604800000 )
+ {
+ // Once per week.
+ hInterval = (int)( 604800000 / interval );
+ format = "{0}/{1}/{2}";
+ detailFormat = "{0}/{1}/{2}";
}
else
{
// Default to every 10 points.
hInterval = 10;
- format = "{0}/{1} {2}:{3}";
- detailFormat = "{0}/{1} {2}:{3}";
+ format = "{0}/{1}/{2}";
+ detailFormat = "{0}/{1}/{2}";
}
// Make sure that the content pane is empty.
getContentPane().removeAll();
// Actually create the chart and add it to the content pane
- m_lineChart = new LineChart( hInterval, interval, format, detailFormat, 20 );
+ m_lineChart = new LineChart(
+ hInterval, interval, format, detailFormat, 20, getFrame().isAntialias() );
getContentPane().add( m_lineChart );
}
@@ -425,6 +433,11 @@
}
else
{
+ if ( m_lineChart != null )
+ {
+ m_lineChart.setAntialias( getFrame().isAntialias() );
+ }
+
// Request a snapshot from the connection
InstrumentSampleSnapshotData snapshot =
m_connection.getSampleSnapshot( m_instrumentSampleName );
Modified: excalibur/trunk/containerkit/instrument/client/src/java/org/apache/excalibur/instrument/client/LineChart.java
==============================================================================
--- excalibur/trunk/containerkit/instrument/client/src/java/org/apache/excalibur/instrument/client/LineChart.java (original)
+++ excalibur/trunk/containerkit/instrument/client/src/java/org/apache/excalibur/instrument/client/LineChart.java Sun Aug 1 21:44:46 2004
@@ -21,7 +21,9 @@
import java.awt.Dimension;
import java.awt.FontMetrics;
import java.awt.Graphics;
+import java.awt.Graphics2D;
import java.awt.Insets;
+import java.awt.RenderingHints;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
@@ -36,13 +38,14 @@
* Draws a nice pretty chart given a set of data.
*
* @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
- * @version CVS $Revision: 1.4 $ $Date: 2004/02/28 11:47:23 $
- * @since 4.1
*/
public class LineChart
extends JComponent
implements MouseListener, MouseMotionListener
{
+ /** Stores the time-zone offset for this JVM. */
+ private static long m_zoneOffset;
+
private Color m_lineColor = Color.red;
private Color m_lightLineColor = new Color( 255, 128, 128 );
private Color m_lightGridColor = new Color( 192, 192, 192 );
@@ -72,6 +75,10 @@
/** Number of sample points to use when calculating the moving average. */
private int m_averageWindow;
+
+ /** True if Antialiasing should be used when rendering the chart. */
+ private boolean m_antialias;
+
/** Time of the last sample point. */
private long m_time;
@@ -99,6 +106,15 @@
private int m_mouseY;
/*---------------------------------------------------------------
+ * Static Initializer
+ *-------------------------------------------------------------*/
+ static
+ {
+ Calendar now = Calendar.getInstance();
+ m_zoneOffset = now.get( Calendar.ZONE_OFFSET );
+ }
+
+ /*---------------------------------------------------------------
* Constructor
*-------------------------------------------------------------*/
/**
@@ -107,29 +123,32 @@
* @param sampleInterval The number of milliseconds represented by each data sample.
* @param format Format of the text which is displayed along the x (time) axis of
* the chart. The text will display the time of the line chart at a particular
- * interval. The text should take the format "{0}/{1} {2}:{3}:{4}.{5}" where {0} is
- * replaced by the month, {1} by the day, {2} by the hour, {3} by the minute, {4}
- * by the second, and {5} by the hundereths of a second.
+ * interval. The text should take the format "{0}/{1}/{2} {3}:{4}:{5}.{6}" where
+ * {0} is replaced by the year, {1} by the month, {2} by the day, {3} by the hour,
+ * {4} by the minute, {5} by the second, and {6} by the hundereths of a second.
* @param detailFormat Format of the text which is displayed over the component as
* the user moves the mouse over the line chart. The text will display the exact
* value of the line chart at a particular point. The text should take the format
- * "{0}/{1} {2}:{3}:{4}.{5}" where {0} is replaced by the month, {1} by the day,
- * {2} by the hour, {3} by the minute, {4} by the second, and {5} by the hundereths
- * of a second.
+ * "{0}/{1}/{2} {3}:{4}:{5}.{6}" where {0} is replaced by the year, {1} by the
+ * month, {2} by the day, {3} by the hour, {4} by the minute, {5} by the second,
+ * and {6} by the hundereths of a second.
* @param averageWindow Number of data points to do a moving average over when the
* mouse is pressed on the component.
+ * @param antialias True if Antialiasing should be used when rendering the chart.
*/
public LineChart( int lineSampleInterval,
long sampleInterval,
String format,
String detailFormat,
- int averageWindow )
+ int averageWindow,
+ boolean antialias )
{
m_lineSampleInterval = lineSampleInterval;
m_sampleInterval = sampleInterval;
m_format = format;
m_dFormat = detailFormat;
m_averageWindow = averageWindow;
+ m_antialias = antialias;
setBackground( Color.white );
setValues( new int[ 0 ], System.currentTimeMillis() );
@@ -141,6 +160,17 @@
* Methods
*-------------------------------------------------------------*/
/**
+ * Sets the antialias flag to control whether or not antialiasing will be
+ * used when rendering the component.
+ *
+ * @param antialias True to use antialiasing.
+ */
+ public void setAntialias( boolean antialias )
+ {
+ m_antialias = antialias;
+ }
+
+ /**
* Sets the data samples to be displayed by the line chart.
*
* @param values Array of data samples.
@@ -213,8 +243,12 @@
calendar.setTime( dTime );
int v;
- String month, day, hour, minute, second, hundreths;
+ String year, month, day, hour, minute, second, hundreths;
+ // Substitute the year
+ v = calendar.get( Calendar.YEAR );
+ year = Integer.toString( v );
+
// Substitute the month
v = calendar.get( Calendar.MONTH ) - Calendar.JANUARY + 1;
if( v < 10 )
@@ -285,12 +319,12 @@
if( detailed )
{
format = MessageFormat.format( m_dFormat,
- new Object[]{month, day, hour, minute, second, hundreths} );
+ new Object[]{year, month, day, hour, minute, second, hundreths} );
}
else
{
format = MessageFormat.format( m_format,
- new Object[]{month, day, hour, minute, second, hundreths} );
+ new Object[]{year, month, day, hour, minute, second, hundreths} );
}
return format;
}
@@ -316,8 +350,8 @@
{
if( chartHeight > 0 )
{
- int horizonalLineLabeledInterval = (int)Math.ceil(
- (float)fontHeight / ( yLabelInterval * chartHeight / ( m_max - m_min ) ) );
+ int horizonalLineLabeledInterval = (int)Math.ceil( (float)fontHeight
+ / ( (long)yLabelInterval * chartHeight / ( m_max - m_min ) ) );
int horizontalLineNumber = 0;
for( int i = ( (int)Math.ceil( (float)m_min / yLabelInterval ) ) * yLabelInterval;
i < m_max; i += yLabelInterval )
@@ -394,7 +428,7 @@
// Calculate a base time for drawing the vertical lines.
long baseTime = ( ( m_time - m_values.length * m_sampleInterval ) /
( m_sampleInterval * m_lineSampleInterval ) ) *
- ( m_sampleInterval * m_lineSampleInterval );
+ ( m_sampleInterval * m_lineSampleInterval ) - m_zoneOffset;
// Draw each of the lines.
int verticalLineNumber = 0;
@@ -730,6 +764,23 @@
{
Dimension size = getSize();
Insets insets = getInsets();
+
+ // If we directly test whether g is a Graphics2D using instanceof then the class
+ // must exist. If it exists then it will be a Graphics2D.
+ if ( g.getClass().getName().indexOf( "Graphics2D" ) >= 0 )
+ {
+ Graphics2D g2 = (Graphics2D)g;
+ if ( m_antialias )
+ {
+ g2.setRenderingHint(
+ RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );
+ }
+ else
+ {
+ g2.setRenderingHint(
+ RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF );
+ }
+ }
g.setColor( getBackground() );
g.fillRect( insets.left, insets.top, size.width - insets.left - insets.right,
Modified: excalibur/trunk/containerkit/instrument/client/src/java/org/apache/excalibur/instrument/client/MenuBar.java
==============================================================================
--- excalibur/trunk/containerkit/instrument/client/src/java/org/apache/excalibur/instrument/client/MenuBar.java (original)
+++ excalibur/trunk/containerkit/instrument/client/src/java/org/apache/excalibur/instrument/client/MenuBar.java Sun Aug 1 21:44:46 2004
@@ -18,6 +18,7 @@
package org.apache.excalibur.instrument.client;
import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
import javax.swing.AbstractAction;
import javax.swing.Action;
@@ -39,6 +40,8 @@
extends JMenuBar
{
protected InstrumentClientFrame m_frame;
+
+ boolean m_showUnconfigured = true;
private JMenu m_menuFile;
@@ -58,10 +61,7 @@
add( buildFileMenu() );
add( buildInstrumentManagerMenu() );
-
- // Build the options menu so its defaults are used, but don't use it for now.
- buildOptionsMenu();
-
+ add( buildOptionsMenu() );
add( buildWindowMenu() );
}
@@ -243,7 +243,7 @@
{
managerMenu.removeAll();
- boolean showAll = m_menuItemShowUnconfigured.getState();
+ boolean showAll = m_showUnconfigured;
// Delete
Action deleteAction = new AbstractAction( "Delete" )
@@ -330,7 +330,7 @@
{
instrumentableMenu.removeAll();
- boolean showAll = m_menuItemShowUnconfigured.getState();
+ boolean showAll = m_showUnconfigured;
// Child Instrumentables
InstrumentableData[] children = instrumentable.getInstrumentables();
@@ -445,7 +445,7 @@
{
instrumentMenu.removeAll();
- boolean showAll = m_menuItemShowUnconfigured.getState();
+ boolean showAll = m_showUnconfigured;
// Create Sample
Action createAction = new AbstractAction( "Create Sample..." )
@@ -500,12 +500,47 @@
m_menuOptions = new LargeMenu( "Options" );
m_menuOptions.setMnemonic( 'O' );
+ m_menuOptions.addMenuListener( new MenuListener()
+ {
+ public void menuSelected( MenuEvent event )
+ {
+ rebuildOptionsMenu();
+ }
+
+ public void menuDeselected( MenuEvent event )
+ {
+ }
+
+ public void menuCanceled( MenuEvent event )
+ {
+ }
+ } );
+
+ /*
// Show Unconfigured Profilables option
m_menuItemShowUnconfigured =
new JCheckBoxMenuItem( "Show Unconfigured Instruments", true );
m_menuOptions.add( m_menuItemShowUnconfigured );
+ */
return m_menuOptions;
+ }
+
+ protected void rebuildOptionsMenu()
+ {
+ m_menuOptions.removeAll();
+
+ final JCheckBoxMenuItem antialias =
+ new JCheckBoxMenuItem( "Antialias", m_frame.isAntialias() );
+ antialias.setMnemonic( 'a' );
+ antialias.addActionListener( new ActionListener()
+ {
+ public void actionPerformed( ActionEvent event )
+ {
+ m_frame.setAntialias( antialias.getState() );
+ }
+ } );
+ m_menuOptions.add( antialias );
}
private JMenu buildWindowMenu()
---------------------------------------------------------------------
To unsubscribe, e-mail: scm-unsubscribe@excalibur.apache.org
For additional commands, e-mail: scm-help@excalibur.apache.org