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