1 6 7 package org.jfree.experimental.chart.demo; 8 9 import java.awt.BorderLayout ; 10 import java.awt.Color ; 11 import java.awt.Dimension ; 12 import java.awt.Font ; 13 import java.awt.GradientPaint ; 14 import java.awt.Point ; 15 import javax.swing.JFrame ; 16 import javax.swing.JPanel ; 17 import javax.swing.JSlider ; 18 import javax.swing.event.ChangeEvent ; 19 import javax.swing.event.ChangeListener ; 20 import org.jfree.chart.ChartPanel; 21 import org.jfree.chart.JFreeChart; 22 import org.jfree.experimental.chart.plot.dial.DialPlot; 23 import org.jfree.experimental.chart.plot.dial.SimpleDialFrame; 24 import org.jfree.experimental.chart.plot.dial.DialTextAnnotation; 25 import org.jfree.experimental.chart.plot.dial.StandardDialRange; 26 import org.jfree.experimental.chart.plot.dial.StandardDialScale; 27 import org.jfree.experimental.chart.plot.dial.DialBackground; 28 import org.jfree.experimental.chart.plot.dial.DialCap; 29 import org.jfree.experimental.chart.plot.dial.DialPointer; 30 import org.jfree.experimental.chart.plot.dial.DialValueIndicator; 31 import org.jfree.data.general.DefaultValueDataset; 32 import org.jfree.ui.GradientPaintTransformType; 33 import org.jfree.ui.StandardGradientPaintTransformer; 34 35 38 public class DialDemo1 extends JFrame implements ChangeListener { 39 40 41 JSlider slider; 42 43 44 DefaultValueDataset dataset; 45 46 51 public DialDemo1(String title) { 52 super(title); 53 54 dataset = new DefaultValueDataset(10.0); 55 56 DialPlot plot = new DialPlot(); 58 plot.setView(0.0, 0.0, 1.0, 1.0); 59 plot.setDataset(dataset); 60 SimpleDialFrame dialFrame = new SimpleDialFrame(); 61 dialFrame.setBackgroundPaint(Color.lightGray); 62 dialFrame.setForegroundPaint(Color.darkGray); 63 plot.setDialFrame(dialFrame); 64 65 GradientPaint gp = new GradientPaint (new Point (), 66 new Color (255, 255, 255), new Point (), 67 new Color (170, 170, 220)); 68 DialBackground db = new DialBackground(gp); 69 db.setGradientPaintTransformer(new StandardGradientPaintTransformer( 70 GradientPaintTransformType.VERTICAL)); 71 plot.setBackground(db); 72 73 DialTextAnnotation annotation1 = new DialTextAnnotation("Temperature"); 74 annotation1.setFont(new Font ("Dialog", Font.BOLD, 14)); 75 annotation1.setRadius(0.7); 76 77 plot.addLayer(annotation1); 78 79 DialValueIndicator dvi = new DialValueIndicator(0, "c"); 80 plot.addLayer(dvi); 81 82 StandardDialScale scale = new StandardDialScale(-40, 60, -120, -300); 83 scale.setTickRadius(0.88); 84 scale.setTickLabelOffset(0.15); 85 scale.setTickLabelFont(new Font ("Dialog", Font.PLAIN, 14)); 86 plot.addScale(0, scale); 87 88 StandardDialRange range = new StandardDialRange(40.0, 60.0, Color.red); 89 range.setInnerRadius(0.52); 90 range.setOuterRadius(0.55); 91 plot.addLayer(range); 92 93 StandardDialRange range2 = new StandardDialRange(10.0, 40.0, 94 Color.orange); 95 range2.setInnerRadius(0.52); 96 range2.setOuterRadius(0.55); 97 plot.addLayer(range2); 98 99 StandardDialRange range3 = new StandardDialRange(-40.0, 10.0, 100 Color.green); 101 range3.setInnerRadius(0.52); 102 range3.setOuterRadius(0.55); 103 plot.addLayer(range3); 104 105 DialPointer needle = new DialPointer.Pointer(); 106 plot.addLayer(needle); 107 108 DialCap cap = new DialCap(); 109 cap.setRadius(0.10); 110 plot.setCap(cap); 111 112 JFreeChart chart1 = new JFreeChart(plot); 113 chart1.setTitle("Demo Dial 1"); 114 ChartPanel cp1 = new ChartPanel(chart1); 115 cp1.setPreferredSize(new Dimension (400, 400)); 116 slider = new JSlider (-40, 60); 117 slider.setMajorTickSpacing(10); 118 slider.setPaintLabels(true); 119 slider.addChangeListener(this); 120 JPanel content = new JPanel (new BorderLayout ()); 121 content.add(cp1); 122 content.add(slider, BorderLayout.SOUTH); 123 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 124 setContentPane(content); 125 } 126 127 133 public void stateChanged(ChangeEvent e) { 134 this.dataset.setValue(new Integer (slider.getValue())); 135 } 136 137 142 public static void main(String [] args) { 143 DialDemo1 app = new DialDemo1("JFreeChart - Demo Dial 1"); 144 app.pack(); 145 app.setVisible(true); 146 } 147 148 } 149 | Popular Tags |