001: /* --------------
002: * DialDemo3.java
003: * --------------
004: * (C) Copyright 2006, by Object Refinery Limited.
005: */
006:
007: package org.jfree.experimental.chart.demo;
008:
009: import java.awt.BasicStroke;
010: import java.awt.BorderLayout;
011: import java.awt.Color;
012: import java.awt.Dimension;
013: import java.awt.GradientPaint;
014: import java.awt.Point;
015:
016: import javax.swing.JFrame;
017: import javax.swing.JPanel;
018: import javax.swing.JSlider;
019: import javax.swing.event.ChangeEvent;
020: import javax.swing.event.ChangeListener;
021:
022: import org.jfree.chart.ChartPanel;
023: import org.jfree.chart.JFreeChart;
024: import org.jfree.data.general.DefaultValueDataset;
025: import org.jfree.experimental.chart.plot.dial.DialBackground;
026: import org.jfree.experimental.chart.plot.dial.DialPlot;
027: import org.jfree.experimental.chart.plot.dial.DialPointer;
028: import org.jfree.experimental.chart.plot.dial.StandardDialFrame;
029: import org.jfree.experimental.chart.plot.dial.StandardDialScale;
030: import org.jfree.ui.GradientPaintTransformType;
031: import org.jfree.ui.StandardGradientPaintTransformer;
032:
033: /**
034: * A sample application showing the use of a {@link DialPlot}.
035: */
036: public class DialDemo3 extends JFrame implements ChangeListener {
037:
038: /** A slider to update the dataset value. */
039: JSlider slider;
040:
041: /** The dataset. */
042: DefaultValueDataset dataset;
043:
044: /**
045: * Creates a new instance.
046: *
047: * @param title the frame title.
048: */
049: public DialDemo3(String title) {
050: super (title);
051:
052: this .dataset = new DefaultValueDataset(50);
053: // get data for diagrams
054: DialPlot plot = new DialPlot();
055: plot.setView(0.21, 0.0, 0.58, 0.30);
056: plot.setDataset(this .dataset);
057:
058: StandardDialFrame dialFrame = new StandardDialFrame(60.0, 60.0);
059: dialFrame.setInnerRadius(0.60);
060: dialFrame.setOuterRadius(0.90);
061: dialFrame.setForegroundPaint(Color.darkGray);
062: dialFrame.setStroke(new BasicStroke(3.0f));
063: plot.setDialFrame(dialFrame);
064:
065: GradientPaint gp = new GradientPaint(new Point(), new Color(
066: 255, 255, 255), new Point(), new Color(240, 240, 240));
067: DialBackground sdb = new DialBackground(gp);
068: sdb
069: .setGradientPaintTransformer(new StandardGradientPaintTransformer(
070: GradientPaintTransformType.VERTICAL));
071: plot.addLayer(sdb);
072:
073: StandardDialScale scale = new StandardDialScale(0, 100, 115.0,
074: -50.0);
075: scale.setTickRadius(0.88);
076: scale.setTickLabelOffset(0.07);
077: scale.setMajorTickIncrement(25.0);
078: scale.setTickLabelPaint(null);
079: plot.addScale(0, scale);
080:
081: DialPointer needle = new DialPointer.Pin();
082: needle.setRadius(0.82);
083: plot.addLayer(needle);
084: JFreeChart chart1 = new JFreeChart(plot);
085: chart1.setTitle("Dial Demo 3");
086: ChartPanel cp1 = new ChartPanel(chart1);
087:
088: cp1.setPreferredSize(new Dimension(400, 250));
089: this .slider = new JSlider(0, 100);
090: this .slider.setMajorTickSpacing(10);
091: this .slider.setPaintLabels(true);
092: this .slider.addChangeListener(this );
093: JPanel content = new JPanel(new BorderLayout());
094: content.add(cp1);
095: content.add(this .slider, BorderLayout.SOUTH);
096: setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
097: setContentPane(content);
098:
099: }
100:
101: /**
102: * Handle a change in the slider by updating the dataset value. This
103: * automatically triggers a chart repaint.
104: *
105: * @param e the event.
106: */
107: public void stateChanged(ChangeEvent e) {
108: this .dataset.setValue(new Integer(this .slider.getValue()));
109: }
110:
111: /**
112: * Starting point for the demo application.
113: *
114: * @param args ignored.
115: */
116: public static void main(String[] args) {
117:
118: DialDemo3 app = new DialDemo3("JFreeChart - Demo Dial 3");
119: app.pack();
120: app.setVisible(true);
121:
122: }
123: }
|