Update of /cvsroot/jrobin/src/org/jrobin/demo/graph
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10276/org/jrobin/demo/graph
Modified Files:
SwingDemo.java SwingDemoPanel.java
Log Message:
Graph gets resized when frame gets resized.
Index: SwingDemo.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/demo/graph/SwingDemo.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** SwingDemo.java 11 Jul 2004 22:06:55 -0000 1.1
--- SwingDemo.java 15 Jul 2004 07:49:10 -0000 1.2
***************
*** 32,35 ****
--- 32,37 ----
import java.io.IOException;
import java.awt.*;
+ import java.awt.event.ComponentAdapter;
+ import java.awt.event.ComponentEvent;
import java.util.Date;
***************
*** 41,48 ****
public class SwingDemo
{
! static JFrame frame = null;
! static JPanel demoPanel = null;
! static RrdGraph graph = null;
! static RrdGraphDef gDef = null;
static final String rrd = "SwingDemo.rrd";
--- 43,50 ----
public class SwingDemo
{
! static JFrame frame = null;
! static SwingDemoPanel demoPanel = null;
! static RrdGraph graph = null;
! static RrdGraphDef gDef = null;
static final String rrd = "SwingDemo.rrd";
***************
*** 80,84 ****
gDef.time( "@l@lTime period: @t", "MMM dd, yyyy HH:mm:ss", START );
gDef.time( "to @t@l", "HH:mm:ss", end );
! gDef.time("@l@lGenerated: @t@c", "HH:mm:ss" );
// create graph finally
--- 82,86 ----
gDef.time( "@l@lTime period: @t", "MMM dd, yyyy HH:mm:ss", START );
gDef.time( "to @t@l", "HH:mm:ss", end );
! gDef.time("@lGenerated: @t@c", "HH:mm:ss" );
// create graph finally
***************
*** 93,96 ****
--- 95,105 ----
frame.pack();
+
+ frame.addComponentListener(new ComponentAdapter() {
+ public void componentResized(ComponentEvent e) {
+ Dimension d = frame.getContentPane().getSize();
+ demoPanel.setGraphDimension(d);
+ }
+ });
frame.setBounds( 10, 10, 504, 303 );
frame.show();
Index: SwingDemoPanel.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/demo/graph/SwingDemoPanel.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** SwingDemoPanel.java 11 Jul 2004 22:06:55 -0000 1.1
--- SwingDemoPanel.java 15 Jul 2004 07:49:10 -0000 1.2
***************
*** 38,41 ****
--- 38,42 ----
{
private RrdGraph graph;
+ private int width, height;
SwingDemoPanel( RrdGraph graph )
***************
*** 50,54 ****
// Render the image directly on the Graphics object of the JPanel
// Width and height of 0 means autoscale the graph
! graph.renderImage( (Graphics2D) g, 0, 0 );
}
catch ( Exception e ) {
--- 51,57 ----
// Render the image directly on the Graphics object of the JPanel
// Width and height of 0 means autoscale the graph
! graph.specifyImageSize(true);
! graph.renderImage( (Graphics2D) g, width, height );
!
}
catch ( Exception e ) {
***************
*** 56,58 ****
--- 59,67 ----
}
}
+
+ void setGraphDimension(Dimension d) {
+ width = d.width;
+ height = d.height;
+ repaint();
+ }
}
|