You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by le...@apache.org on 2002/03/04 09:58:11 UTC

cvs commit: jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/altprofile/profiler/gui LineChart.java ProfileSampleFrame.java

leif        02/03/04 00:58:11

  Modified:    src/scratchpad/org/apache/avalon/excalibur/altprofile/profiler/gui
                        LineChart.java ProfileSampleFrame.java
  Log:
  Add support for subsecond sample intervals.
  
  Revision  Changes    Path
  1.2       +402 -243  jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/altprofile/profiler/gui/LineChart.java
  
  Index: LineChart.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/altprofile/profiler/gui/LineChart.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- LineChart.java	3 Mar 2002 15:59:44 -0000	1.1
  +++ LineChart.java	4 Mar 2002 08:58:11 -0000	1.2
  @@ -21,209 +21,294 @@
   import javax.swing.JComponent;
   
   /**
  + * Draws a nice pretty chart given a set of data.
    *
    * @author <a href="mailto:leif@silveregg.co.jp">Leif Mortenson</a>
  - * @version CVS $Revision: 1.1 $ $Date: 2002/03/03 15:59:44 $
  + * @version CVS $Revision: 1.2 $ $Date: 2002/03/04 08:58:11 $
    * @since 4.1
    */
  +
  +/*
  + * Disclaimer.  I know that this code is ugly.  It is taken from an old
  + *  project and works. :-)
  + */
   public class LineChart
       extends JComponent
       implements MouseListener, MouseMotionListener
   {
  -    private static final long _baseTime;
  -    private Color _lineColor = Color.red;
  -    private Color _lightLineColor = new Color(255, 128, 128);
  -    private Color _lightGridColor = new Color(192, 192, 192);
  -    private Color _darkGridColor = new Color(128, 128, 128);
  -    private Color _frameColor = Color.black;
  -    private Color _crossColor = Color.blue;
  -    private Color _maskFrameColor = new Color(128, 128, 255, 192);
  -    private Color _maskColor = new Color(224, 224, 255, 192);
  -    private int _hInt;
  -    private int _tickSecs;
  -    private String _format;
  -    private String _dFormat;
  -    private int _average;
  -    private int _min;
  -    private int _max;
  -    private int[] _values;
  -    private float[] _aValues;
  -    private boolean _mouseOver;
  -    private boolean _mousePressed;
  -    private int _mouseX;
  -    private int _mouseY;
  +    /** Time at the beginning of the year. */
  +    //private static final long m_baseTime;
  +    
  +    private Color m_lineColor = Color.red;
  +    private Color m_lightLineColor = new Color(255, 128, 128);
  +    private Color m_lightGridColor = new Color(192, 192, 192);
  +    private Color m_darkGridColor = new Color(128, 128, 128);
  +    private Color m_frameColor = Color.black;
  +    private Color m_crossColor = Color.blue;
  +    private Color m_maskFrameColor = new Color(128, 128, 255, 192);
  +    private Color m_maskColor = new Color(224, 224, 255, 192);
  +    
  +    /** Number of sample points between vertical lines. */
  +    private int m_lineSampleInterval;
  +    
  +    /** The number of milliseconds represented by each data sample. */
  +    private long m_sampleInterval;
  +    
  +    /**
  +     * Format of the text which is displayed along the x (time) axis of the
  +     *  chart.
  +     */
  +    private String m_format;
  +    
  +    /**
  +     * Format of the text which is displayed over the component as
  +     *	the user moves the mouse over the line chart.
  +     */
  +    private String m_dFormat;
       
  -    static {
  -        // Set the base time to the beginning of this year in seconds
  +    /** Number of sample points to use when calculating the moving average. */
  +    private int m_averageWindow;
  +    /** Time of the last sample point. */
  +    private long m_time;
  +    
  +    /** Sample point data. */
  +    private int[] m_values;
  +    
  +    /** Moving average of the sample point data. */
  +    private float[] m_averageWindowValues;
  +    
  +    /** Minimum value in m_values. */
  +    private int m_min;
  +    
  +    /** Maximum value in m_values. */
  +    private int m_max;
  +    
  +    private boolean m_mouseOver;
  +    private boolean m_mousePressed;
  +    private int m_mouseX;
  +    private int m_mouseY;
  +    
  +    /*
  +    static
  +    {
  +        // Set the base time to the beginning of this year
           Calendar calendar = Calendar.getInstance();
           int year = calendar.get(Calendar.YEAR);
           calendar.clear();
  -        calendar.set(Calendar.YEAR, year);
  -        _baseTime = calendar.getTime().getTime() / 1000;
  +        calendar.set( Calendar.YEAR, year );
  +        m_baseTime = calendar.getTime().getTime();
       }
  +    */
       
       /*---------------------------------------------------------------
        * Constructor
        *-------------------------------------------------------------*/
       /**
  -     * Creates a new LineChart.
  -     *
  -     *
  -     */
  -    public LineChart(int horizontalInterval, int tickSeconds, String format, String detailFormat) {
  -        this(horizontalInterval, tickSeconds, format, detailFormat, 0);
  -    }
  -    
  -    /**
  -     * @param horizontalInterval The interval in data points at which to place vertical
  +     * @param lineSampleInterval The interval in data points at which to place vertical
        *	lines and labels along the x (time) axis.
  -     * @param tickSeconds The number of seconds represented by each data point.
  +     * @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}" where {0} is
  -     *	replaced by the month, {1} by the day, {2} by the hour, {3} by the minute and {4}
  -     *	by the second.
  +     *	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.
        * @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}" where {0} is replaced by the month, {1} by the day, {2} by the
  -     *	hour, {3} by the minute and {4} by the second.
  +     *	"{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.
        * @param averageWindow Number of data points to do a moving average over when the
        *	mouse is pressed on the component.
        */
  -    LineChart(int horizontalInterval, int tickSeconds, String format, String detailFormat, int averageWindow) {
  -        _hInt = horizontalInterval;
  -        _tickSecs = tickSeconds;
  -        _format = format;
  -        _dFormat = detailFormat;
  -        _average = averageWindow;
  -        
  -        setBackground(Color.white);
  -        setValues(new int[0]);
  -        addMouseListener(this);
  -        addMouseMotionListener(this);
  +    public LineChart( int lineSampleInterval,
  +                      long sampleInterval,
  +                      String format,
  +                      String detailFormat,
  +                      int averageWindow)
  +    {
  +        m_lineSampleInterval = lineSampleInterval;
  +        m_sampleInterval = sampleInterval;
  +        m_format = format;
  +        m_dFormat = detailFormat;
  +        m_averageWindow = averageWindow;
  +        
  +        setBackground( Color.white );
  +        setValues( new int[0], System.currentTimeMillis() );
  +        addMouseListener( this );
  +        addMouseMotionListener( this );
       }
       
       /*---------------------------------------------------------------
        * Methods
        *-------------------------------------------------------------*/
  -    synchronized void setValues(int[] values) {
  +    /**
  +     * Sets the data samples to be displayed by the line chart.
  +     *
  +     * @param values Array of data samples.
  +     * @param time The time of the start of the last sample point.
  +     */
  +    public void setValues( int[] values, long time )
  +    {
           int max = 0;
           int min = Integer.MAX_VALUE;
  -        for (int i = 0; i < values.length; i++) {
  +        for ( int i = 0; i < values.length; i++ )
  +        {
               int v = values[i];
               if (v > max) max = v;
               if (v < min) min = v;
           }
  -        if ((max - min) < 10) {
  -            max += ((10 - (max - min)) / 2);
  -            min -= (10 - (max - min));
  +        if ( ( max - min ) < 10 )
  +        {
  +            max += ( ( 10 - ( max - min ) ) / 2 );
  +            min -= ( 10 - ( max - min ) );
           }
  -        if (min < 0) {
  +        if ( min < 0 )
  +        {
               max += -min;
               min = 0;
           }
       
  -        float[] aValues = new float[values.length];
  -        if (_average > 1) {
  +        float[] averageValues = new float[values.length];
  +        if ( m_averageWindow > 1 )
  +        {
               int total = 0;
  -            for (int i = 0; i < values.length; i++) {
  +            for ( int i = 0; i < values.length; i++ )
  +            {
                   total += values[i];
  -                if (i >= _average - 1) {
  -                    if (i >= _average) {
  -                        total -= values[i - _average];
  +                if ( i >= m_averageWindow - 1 )
  +                {
  +                    if ( i >= m_averageWindow )
  +                    {
  +                        total -= values[i - m_averageWindow];
                       }
  -                    aValues[i] = (float)total / _average;
  -                } else {
  -                    aValues[i] = Float.MIN_VALUE;
  +                    averageValues[i] = (float)total / m_averageWindow;
  +                }
  +                else
  +                {
  +                    averageValues[i] = Float.MIN_VALUE;
                   }
               }
           }
           
  -        synchronized(this) {		
  -            _values = values;
  -            _aValues = aValues;
  -            _min = min;
  -            _max = max;
  +        synchronized (this)
  +        {
  +            m_time = time;
  +            m_values = values;
  +            m_averageWindowValues = averageValues;
  +            m_min = min;
  +            m_max = max;
           }
  +        
           repaint();
       }
       
  -    private String getFormattedTime(Date dTime, boolean detailed) {
  +    private String getFormattedTime( Date dTime, boolean detailed )
  +    {
           Calendar calendar = Calendar.getInstance();
           calendar.setTime(dTime);
           
           int v;
  -        String month, day, hour, minute, second;
  +        String month, day, hour, minute, second, hundreths;
           
           // Substitute the month
  -        v = calendar.get(Calendar.MONTH) - Calendar.JANUARY + 1;
  -        if (v < 10) {
  -            month = "0" + Integer.toString(v);
  -        } else {
  -            month = Integer.toString(v);
  -        }
  -        
  -        // Substiture the Day
  -        v = calendar.get(Calendar.DAY_OF_MONTH);
  -        if (v < 10) {
  -            day = "0" + Integer.toString(v);
  -        } else {
  -            day = Integer.toString(v);
  +        v = calendar.get( Calendar.MONTH ) - Calendar.JANUARY + 1;
  +        if ( v < 10 )
  +        {
  +            month = "0" + Integer.toString( v );
  +        }
  +        else
  +        {
  +            month = Integer.toString( v );
  +        }
  +        
  +        // Substitute the Day
  +        v = calendar.get( Calendar.DAY_OF_MONTH );
  +        if ( v < 10 )
  +        {
  +            day = "0" + Integer.toString( v );
  +        }
  +        else
  +        {
  +            day = Integer.toString( v );
           }
   
  -        // Substiture the Hour
  -        v = calendar.get(Calendar.HOUR_OF_DAY);
  -        if (v < 10) {
  -            hour = "0" + Integer.toString(v);
  -        } else {
  -            hour = Integer.toString(v);
  +        // Substitute the Hour
  +        v = calendar.get( Calendar.HOUR_OF_DAY );
  +        if ( v < 10 )
  +        {
  +            hour = "0" + Integer.toString( v );
  +        }
  +        else
  +        {
  +            hour = Integer.toString( v );
           }
   
  -        // Substiture the Minute
  -        v = calendar.get(Calendar.MINUTE);
  -        if (v < 10) {
  -            minute = "0" + Integer.toString(v);
  -        } else {
  -            minute = Integer.toString(v);
  -        }
  -        
  -        // Substiture the Second
  -        v = calendar.get(Calendar.SECOND);
  -        if (v < 10) {
  -            second = "0" + Integer.toString(v);
  -        } else {
  -            second = Integer.toString(v);
  +        // Substitute the Minute
  +        v = calendar.get( Calendar.MINUTE );
  +        if ( v < 10 )
  +        {
  +            minute = "0" + Integer.toString( v );
  +        }
  +        else
  +        {
  +            minute = Integer.toString( v );
  +        }
  +        
  +        // Substitute the Second
  +        v = calendar.get( Calendar.SECOND );
  +        if ( v < 10 )
  +        {
  +            second = "0" + Integer.toString( v );
  +        }
  +        else
  +        {
  +            second = Integer.toString( v );
  +        }
  +        
  +        // Substitute the Hudreths of a Second
  +        v = calendar.get( Calendar.MILLISECOND ) / 10;
  +        if ( v < 10 )
  +        {
  +            hundreths = "0" + Integer.toString( v );
  +        }
  +        else
  +        {
  +            hundreths = Integer.toString( v );
           }
           
           String format;
  -        if (detailed) {
  -            format = MessageFormat.format(_dFormat, new Object[] {month, day, hour, minute, second});
  -        } else {
  -            format = MessageFormat.format(_format, new Object[] {month, day, hour, minute, second});
  +        if ( detailed )
  +        {
  +            format = MessageFormat.format( m_dFormat,
  +                new Object[] { month, day, hour, minute, second, hundreths } );
  +        }
  +        else
  +        {
  +            format = MessageFormat.format( m_format,
  +                new Object[] { month, day, hour, minute, second, hundreths } );
           }
           return format;
       }
       
  -    public synchronized void paintComponent(Graphics g) {
  +    public synchronized void paintComponent( Graphics g )
  +    {
           Dimension size = getSize();
           Insets insets = getInsets();
           
  -        // Figure out the time at the beginning of the day
  -        long now = System.currentTimeMillis() / 1000;
  -        now = now - ((now - _baseTime) % _tickSecs);
  -        
  -        g.setColor(getBackground());
  -        g.fillRect(insets.left, insets.top, size.width - insets.left - insets.right, size.height - insets.top - insets.bottom);
  +        g.setColor( getBackground() );
  +        g.fillRect( insets.left, insets.top, size.width - insets.left - insets.right,
  +            size.height - insets.top - insets.bottom );
           
           // Resolve the vertical interval
           int vInt = 1;
  -        while ((_max - _min) / vInt > 20) {
  +        while ( ( m_max - m_min ) / vInt > 20)
  +        {
               vInt *= 10;
           }
           
           FontMetrics fm = g.getFontMetrics();
  -        int hlw = fm.stringWidth(Integer.toString(_max));
  +        int hlw = fm.stringWidth( Integer.toString( m_max ) );
           int fh = fm.getAscent();
           int hh = fh / 2;
               
  @@ -232,84 +317,122 @@
           int w = size.width - l - insets.right - 1 - 5;
           int h = size.height - t - insets.bottom - 1 - fh;
   
  -        // Draw the vertical grid
  -        int lInt = (int)Math.ceil((float)fh / (vInt * h / (_max - _min)));
  +        // Draw the vertical grid (Left to Right lines)
  +        int lInt = (int)Math.ceil( (float)fh / ( vInt * h / ( m_max - m_min ) ) );
           int lNum = 0;
  -        for (int i = ((int)Math.ceil((float)_min / vInt)) * vInt; i < _max; i += vInt) {
  -            int y = t + h - (h * (i - _min) / (_max - _min));
  +        for ( int i = ( (int)Math.ceil( (float)m_min / vInt ) ) * vInt; i < m_max; i += vInt )
  +        {
  +            int y = t + h - ( h * ( i - m_min ) / ( m_max - m_min ) );
               
  -            if (lNum >= lInt) lNum = 0;
  -            if (lNum == 0) {
  -                String lbl = Integer.toString(i);
  -                g.setColor(_frameColor);
  -                g.drawString(lbl, l - 5 - fm.stringWidth(lbl), y + hh);
  +            if ( lNum >= lInt )
  +            {
  +                lNum = 0;
  +            }
  +            if ( lNum == 0 )
  +            {
  +                String lbl = Integer.toString( i );
  +                g.setColor( m_frameColor );
  +                g.drawString( lbl, l - 5 - fm.stringWidth( lbl ), y + hh );
   
  -                g.setColor(_darkGridColor);
  -            } else {
  -                g.setColor(_lightGridColor);
  +                g.setColor( m_darkGridColor );
  +            }
  +            else
  +            {
  +                g.setColor( m_lightGridColor );
               }
               lNum++;
               
  -            g.drawLine(l, y, l + w, y);
  +            g.drawLine( l, y, l + w, y );
           }
  -
  -        // Draw the horizontal grid
  -        String format = MessageFormat.format(_format, new String[] {"00", "00","00", "00"});
  -        int fw = fm.stringWidth(format) + 10;
  -        
  -        if ((_values.length > 0) && (w > 0)) {
  -            lInt = (int)Math.ceil((float)fw / (_hInt * w / (_values.length)));
  -        } else {
  +        
  +        
  +        
  +        // Draw the horizontal grid (Top to Bottom lines)
  +        
  +        // Figure out how wide a label is for formatting.
  +        String format = MessageFormat.format( m_format, new String[] { "00", "00","00", "00" } );
  +        int fw = fm.stringWidth( format ) + 10;
  +        
  +        // Figure out what internal of lines we can place labels under.
  +        if ( ( m_values.length > 0 ) && ( w > 0 ) )
  +        {
  +            lInt = (int)Math.ceil( (float)fw / ( m_lineSampleInterval * w / ( m_values.length ) ) );
  +        }
  +        else
  +        {
               lInt = 1;
           }
  +        
  +        // 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 );
  +        
  +        // Draw each of the lines.
           lNum = 0;
  -        for (int i = 0; i < _values.length; i++) {
  -            long time = now - (_values.length - i - 1) * _tickSecs;
  -            if ((((time - _baseTime) / _tickSecs) % _hInt) == 0) {
  -                int x = l + i * w / (_values.length - 1);
  +        for ( int i = 0; i < m_values.length; i++ )
  +        {
  +            long time = m_time - ( m_values.length - i - 1 ) * m_sampleInterval;
  +            if ( ( ( ( time - baseTime ) / m_sampleInterval ) % m_lineSampleInterval ) == 0 )
  +            {
  +                int x = l + i * w / ( m_values.length - 1 );
                   
  -                if ((lNum >= lInt) || (lNum == 0)) {
  -                    format = getFormattedTime(new Date(time * 1000), false);
  +                // Draw a label under the line if line should have a label.
  +                if ( ( lNum >= lInt ) || ( lNum == 0 ) )
  +                {
  +                    format = getFormattedTime( new Date( time ), false );
                       
  -                    if (x - fm.stringWidth(format) / 2 >= l) {
  -                        g.setColor(_frameColor);
  -                        g.drawString(format, x - fm.stringWidth(format) / 2, t + h + fh);
  +                    if ( x - fm.stringWidth( format ) / 2 >= l )
  +                    {
  +                        g.setColor( m_frameColor );
  +                        g.drawString( format, x - fm.stringWidth( format ) / 2, t + h + fh );
                   
  -                        g.setColor(_darkGridColor);
  +                        g.setColor( m_darkGridColor );
                           lNum = 1;
  -                    } else {
  -                        g.setColor(_lightGridColor);
                       }
  -                } else {
  -                    g.setColor(_lightGridColor);
  +                    else
  +                    {
  +                        g.setColor( m_lightGridColor );
  +                    }
  +                }
  +                else
  +                {
  +                    g.setColor( m_lightGridColor );
                       lNum++;
                   }
                   
                   // Draw the vertical line
  -                g.drawLine(x, t, x, t + h);
  +                g.drawLine( x, t, x, t + h );
               }
           }
           
  +        
  +        
           // Draw the frame
  -        g.setColor(_frameColor);
  -        g.drawLine(l, t, l, t + h);
  -        g.drawLine(l, t + h, l + w, t + h);
  +        g.setColor( m_frameColor );
  +        g.drawLine( l, t, l, t + h );
  +        g.drawLine( l, t + h, l + w, t + h );
           
           // Draw the counts
  -        if ((_average > 0) && (_mousePressed)) {
  -            g.setColor(_lightLineColor);
  -        } else {
  -            g.setColor(_lineColor);
  +        if ( ( m_averageWindow > 0 ) && ( m_mousePressed ) )
  +        {
  +            g.setColor( m_lightLineColor );
  +        }
  +        else
  +        {
  +            g.setColor( m_lineColor );
           }
           
           int lx = 0;
           int ly = 0;
  -        for (int i = 0; i < _values.length; i++) {
  -            int x = l + i * w / (_values.length - 1);
  -            int y = t + h - (h * (_values[i] - _min) / (_max - _min));
  +        for ( int i = 0; i < m_values.length; i++ )
  +        {
  +            int x = l + i * w / ( m_values.length - 1 );
  +            int y = t + h - ( h * ( m_values[i] - m_min ) / ( m_max - m_min ) );
               
  -            if (i > 0) {
  -                g.drawLine(lx, ly, x, y);
  +            if ( i > 0 )
  +            {
  +                g.drawLine( lx, ly, x, y );
               }
               
               lx = x;
  @@ -317,16 +440,20 @@
           }
           
           // Draw the average chart
  -        if ((_average > 0) && (_mousePressed)) {
  -            g.setColor(_lineColor);
  +        if ( ( m_averageWindow > 0 ) && ( m_mousePressed ) )
  +        {
  +            g.setColor( m_lineColor );
               lx = 0;
               ly = 0;
  -            for (int i = _average; i < _aValues.length; i++) {
  -                int x = l + i * w / (_aValues.length - 1);
  -                int y = t + h - (int)(h * (_aValues[i] - _min) / (_max - _min));
  +            for ( int i = m_averageWindow; i < m_averageWindowValues.length; i++ )
  +            {
  +                int x = l + i * w / ( m_averageWindowValues.length - 1 );
  +                int y = t + h - (int)( h * ( m_averageWindowValues[i] - m_min ) /
  +                    ( m_max - m_min ) );
                   
  -                if (i > _average) {
  -                    g.drawLine(lx, ly, x, y);
  +                if ( i > m_averageWindow )
  +                {
  +                    g.drawLine( lx, ly, x, y );
                   }
                   
                   lx = x;
  @@ -334,98 +461,125 @@
               }
           }
           
  -        // Make the label visible if the user tracks over any part of the chart rather than just on the cart area.
  -        //if ((_mouseOver) && (_mouseX >= l) && (_mouseX <= l + w) && (_mouseY >= t) && (_mouseY <= t + h)) {
  -        if ((_mouseOver) && (_mouseX >= l) && (_mouseX <= l + w)) {
  +        // Make the label visible if the user tracks over any part of the chart.
  +        if ( ( m_mouseOver ) && ( m_mouseX >= l ) && ( m_mouseX <= l + w ) )
  +        {
               // Figure out where the mouse is
  -            int index = (int)Math.round((float)(_values.length - 1) * (_mouseX - l) / w);
  -            if ((_average > 0) && (_mousePressed)) {
  +            int index = (int)Math.round( (float)( m_values.length - 1 ) * ( m_mouseX - l ) / w );
  +            if ( ( m_averageWindow > 0 ) && ( m_mousePressed ) )
  +            {
                   // Draw the label for the average data
  -                if ((index >= _average) && (index < _aValues.length)) {
  -                    int mx = l + index * w / (_aValues.length - 1);
  -                    int my = t + h - (int)(h * (_aValues[index] - _min) / (_max - _min));
  -                    float mc = (float)((int)(_aValues[index] * 100)) / 100;
  -                    long mt = now - (_aValues.length - index - 1) * _tickSecs;
  +                if ( ( index >= m_averageWindow ) && ( index < m_averageWindowValues.length ) )
  +                {
  +                    int mx = l + index * w / ( m_averageWindowValues.length - 1 );
  +                    int my = t + h - (int)( h * ( m_averageWindowValues[index] - m_min ) /
  +                        ( m_max - m_min ) );
  +                    float mc = (float)( (int)( m_averageWindowValues[index] * 100 ) ) / 100;
  +                    long mt = m_time - ( m_averageWindowValues.length - index - 1 ) * m_sampleInterval;
                       
  -                    g.setColor(_crossColor);
  -                    g.drawLine(mx, t, mx, t + h);
  -                    g.drawLine(l, my, l + w, my);
  -                    format = mc + " : " + getFormattedTime(new Date(mt * 1000), true);
  -                    int tw = fm.stringWidth(format);
  +                    g.setColor( m_crossColor );
  +                    g.drawLine( mx, t, mx, t + h );
  +                    g.drawLine( l, my, l + w, my );
  +                    format = mc + " : " + getFormattedTime( new Date( mt ), true );
  +                    int tw = fm.stringWidth( format );
                       int ll, lt;
  +                    
                       // Decide where to put the label
  -                    if (mx + 5 + tw < l + w) {
  +                    if ( mx + 5 + tw < l + w )
  +                    {
                           // Ok on the right
                           ll = mx + 4;
  -                        if (my + 5 + fh < t + h) {
  +                        if ( my + 5 + fh < t + h )
  +                        {
                               // Ok on the bottom
                               lt = my + 4;
  -                        } else {
  +                        }
  +                        else
  +                        {
                               // Must go on the top
                               lt = my - 4 - fh;
                           }
  -                    } else {
  +                    }
  +                    else
  +                    {
                           // Must go on the left
                           ll = mx - 4 - tw;
  -                        if (my + 5 + fh < t + h) {
  +                        if ( my + 5 + fh < t + h )
  +                        {
                               // Ok on the bottom
                               lt = my + 4;
  -                        } else {
  +                        }
  +                        else
  +                        {
                               // Must go on the top
                               lt = my - 4 - fh;
                           }
                       }
  +                    
                       // Paint the label
  -                    g.setColor(_maskFrameColor);
  -                    g.drawRect(ll - 1, lt - 1, tw + 2, fh + 2);
  -                    g.setColor(_maskColor);
  -                    g.fillRect(ll - 1, lt - 1, tw + 2, fh + 2);
  -                    g.setColor(_crossColor);
  -                    g.drawString(format, ll, lt + fh);
  +                    g.setColor( m_maskFrameColor );
  +                    g.drawRect( ll - 1, lt - 1, tw + 2, fh + 2 );
  +                    g.setColor( m_maskColor );
  +                    g.fillRect( ll - 1, lt - 1, tw + 2, fh + 2 );
  +                    g.setColor( m_crossColor );
  +                    g.drawString( format, ll, lt + fh );
                   }
  -            } else {
  +            }
  +            else
  +            {
                   // Draw the label for the regular data
  -                if ((index >= 0) && (index < _values.length)) {
  -                    int mx = l + index * w / (_values.length - 1);
  -                    int my = t + h - (h * (_values[index] - _min) / (_max - _min));
  -                    int mc = _values[index];
  -                    long mt = now - (_values.length - index - 1) * _tickSecs;
  +                if ( ( index >= 0 ) && ( index < m_values.length ) )
  +                {
  +                    int mx = l + index * w / ( m_values.length - 1 );
  +                    int my = t + h - ( h * ( m_values[index] - m_min ) / ( m_max - m_min ) );
  +                    int mc = m_values[index];
  +                    long mt = m_time - ( m_values.length - index - 1 ) * m_sampleInterval;
                       
  -                    g.setColor(_crossColor);
  -                    g.drawLine(mx, t, mx, t + h);
  -                    g.drawLine(l, my, l + w, my);
  -                    format = mc + " : " + getFormattedTime(new Date(mt * 1000), true);
  -                    int tw = fm.stringWidth(format);
  +                    g.setColor( m_crossColor );
  +                    g.drawLine( mx, t, mx, t + h );
  +                    g.drawLine( l, my, l + w, my );
  +                    format = mc + " : " + getFormattedTime( new Date( mt ), true );
  +                    int tw = fm.stringWidth( format );
                       int ll, lt;
  +                    
                       // Decide where to put the label
  -                    if (mx + 5 + tw < l + w) {
  +                    if ( mx + 5 + tw < l + w )
  +                    {
                           // Ok on the right
                           ll = mx + 4;
  -                        if (my + 5 + fh < t + h) {
  +                        if ( my + 5 + fh < t + h )
  +                        {
                               // Ok on the bottom
                               lt = my + 4;
  -                        } else {
  +                        }
  +                        else
  +                        {
                               // Must go on the top
                               lt = my - 4 - fh;
                           }
  -                    } else {
  +                    }
  +                    else
  +                    {
                           // Must go on the left
                           ll = mx - 4 - tw;
  -                        if (my + 5 + fh < t + h) {
  +                        if ( my + 5 + fh < t + h )
  +                        {
                               // Ok on the bottom
                               lt = my + 4;
  -                        } else {
  +                        }
  +                        else
  +                        {
                               // Must go on the top
                               lt = my - 4 - fh;
                           }
                       }
                       // Paint the label
  -                    g.setColor(_maskFrameColor);
  -                    g.drawRect(ll - 1, lt - 1, tw + 2, fh + 2);
  -                    g.setColor(_maskColor);
  -                    g.fillRect(ll - 1, lt - 1, tw + 2, fh + 2);
  -                    g.setColor(_crossColor);
  -                    g.drawString(format, ll, lt + fh);
  +                    g.setColor( m_maskFrameColor );
  +                    g.drawRect( ll - 1, lt - 1, tw + 2, fh + 2 );
  +                    g.setColor( m_maskColor );
  +                    g.fillRect( ll - 1, lt - 1, tw + 2, fh + 2 );
  +                    g.setColor( m_crossColor );
  +                    g.drawString( format, ll, lt + fh );
                   }
               }
           }
  @@ -434,39 +588,44 @@
       /*---------------------------------------------------------------
        * MouseListener Methods
        *-------------------------------------------------------------*/
  -    public void mouseClicked(MouseEvent event) {
  -    }
  +    public void mouseClicked( MouseEvent event ) {}
       
  -    public void mousePressed(MouseEvent event) {
  -        _mousePressed = true;
  +    public void mousePressed( MouseEvent event )
  +    {
  +        m_mousePressed = true;
       }
       
  -    public void mouseReleased(MouseEvent event) {
  -        _mousePressed = false;
  +    public void mouseReleased( MouseEvent event )
  +    {
  +        m_mousePressed = false;
       }
       
  -    public void mouseEntered(MouseEvent event) {
  -        _mouseOver = true;
  +    public void mouseEntered( MouseEvent event )
  +    {
  +        m_mouseOver = true;
           repaint();
       }
       
  -    public void mouseExited(MouseEvent event) {
  -        _mouseOver = false;
  +    public void mouseExited( MouseEvent event )
  +    {
  +        m_mouseOver = false;
           repaint();
       }
       
       /*---------------------------------------------------------------
        * MouseMotionListener Methods
        *-------------------------------------------------------------*/
  -    public void mouseDragged(MouseEvent event) {
  -        _mouseX = event.getX();
  -        _mouseY = event.getY();
  +    public void mouseDragged( MouseEvent event )
  +    {
  +        m_mouseX = event.getX();
  +        m_mouseY = event.getY();
           repaint();
       }
       
  -    public void mouseMoved(MouseEvent event) {
  -        _mouseX = event.getX();
  -        _mouseY = event.getY();
  +    public void mouseMoved( MouseEvent event )
  +    {
  +        m_mouseX = event.getX();
  +        m_mouseY = event.getY();
           repaint();
       }
   }
  
  
  
  1.2       +13 -6     jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/altprofile/profiler/gui/ProfileSampleFrame.java
  
  Index: ProfileSampleFrame.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/altprofile/profiler/gui/ProfileSampleFrame.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ProfileSampleFrame.java	3 Mar 2002 15:59:44 -0000	1.1
  +++ ProfileSampleFrame.java	4 Mar 2002 08:58:11 -0000	1.2
  @@ -19,7 +19,7 @@
   /**
    *
    * @author <a href="mailto:leif@silveregg.co.jp">Leif Mortenson</a>
  - * @version CVS $Revision: 1.1 $ $Date: 2002/03/03 15:59:44 $
  + * @version CVS $Revision: 1.2 $ $Date: 2002/03/04 08:58:11 $
    * @since 4.1
    */
   class ProfileSampleFrame
  @@ -54,10 +54,10 @@
           String detailFormat;
           if ( interval < 1000 )
           {
  -            // Once per second.
  -            hInterval = (int)(1000 / interval);
  +            // Once per 10 seconds.
  +            hInterval = (int)(10000 / interval);
               format = "{2}:{3}:{4}";
  -            detailFormat = "{0}/{1} {2}:{3}:{4}";
  +            detailFormat = "{0}/{1} {2}:{3}:{4}.{5}";
           }
           else if ( interval < 60000 )
           {
  @@ -66,6 +66,13 @@
               format = "{2}:{3}:{4}";
               detailFormat = "{0}/{1} {2}:{3}:{4}";
           }
  +        else if ( interval < 600000 )
  +        {
  +            // Once per 10 minutes
  +            hInterval = (int)(600000 / interval);
  +            format = "{0}/{1} {2}:{3}";
  +            detailFormat = "{0}/{1} {2}:{3}";
  +        }
           else if ( interval < 3600000 )
           {
               // Once per hour.
  @@ -88,7 +95,7 @@
               detailFormat = "{0}/{1} {2}:{3}";
           }
           
  -        m_lineChart = new LineChart( hInterval, (int)descriptor.getInterval() / 1000, format, detailFormat, 20 );
  +        m_lineChart = new LineChart( hInterval, (int)descriptor.getInterval(), format, detailFormat, 20 );
           
           getContentPane().add( m_lineChart );
           
  @@ -155,7 +162,7 @@
           
           int[] samples = snapshot.getSamples();
           
  -        m_lineChart.setValues( samples );
  +        m_lineChart.setValues( samples, snapshot.getTime() );
       }
   }
   
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>