1 6 7 package org.jfree.experimental.chart.demo; 8 9 import java.awt.BasicStroke ; 10 import java.awt.BorderLayout ; 11 import java.awt.Color ; 12 import java.awt.Dimension ; 13 import java.awt.Font ; 14 import java.awt.GradientPaint ; 15 import java.awt.Point ; 16 17 import javax.swing.JFrame ; 18 import javax.swing.JPanel ; 19 import javax.swing.JSlider ; 20 import javax.swing.event.ChangeEvent ; 21 import javax.swing.event.ChangeListener ; 22 23 import org.jfree.chart.ChartPanel; 24 import org.jfree.chart.JFreeChart; 25 import org.jfree.data.general.DefaultValueDataset; 26 import org.jfree.experimental.chart.plot.dial.DialBackground; 27 import org.jfree.experimental.chart.plot.dial.DialPlot; 28 import org.jfree.experimental.chart.plot.dial.DialPointer; 29 import org.jfree.experimental.chart.plot.dial.StandardDialFrame; 30 import org.jfree.experimental.chart.plot.dial.StandardDialScale; 31 import org.jfree.ui.GradientPaintTransformType; 32 import org.jfree.ui.StandardGradientPaintTransformer; 33 34 37 public class DialDemo4 extends JFrame implements ChangeListener { 38 39 40 JSlider slider; 41 42 43 DefaultValueDataset dataset; 44 45 50 public DialDemo4(String title) { 51 super(title); 52 53 this.dataset = new DefaultValueDataset(50); 54 DialPlot plot = new DialPlot(); 56 plot.setView(0.78, 0.37, 0.22, 0.26); 57 plot.setDataset(this.dataset); 58 59 StandardDialFrame dialFrame = new StandardDialFrame(-10.0, 20.0); 60 dialFrame.setInnerRadius(0.70); 61 dialFrame.setOuterRadius(0.90); 62 dialFrame.setForegroundPaint(Color.darkGray); 63 dialFrame.setStroke(new BasicStroke (3.0f)); 64 plot.setDialFrame(dialFrame); 65 66 GradientPaint gp = new GradientPaint (new Point (), 67 new Color (255, 255, 255), new Point (), 68 new Color (240, 240, 240)); 69 DialBackground sdb = new DialBackground(gp); 70 sdb.setGradientPaintTransformer(new StandardGradientPaintTransformer( 71 GradientPaintTransformType.VERTICAL)); 72 plot.addLayer(sdb); 73 74 StandardDialScale scale = new StandardDialScale(0, 100, -8, 16.0); 75 scale.setTickRadius(0.82); 76 scale.setTickLabelOffset(-0.04); 77 scale.setMajorTickIncrement(25.0); 78 scale.setTickLabelFont(new Font ("Dialog", Font.PLAIN, 14)); 79 80 plot.addScale(0, scale); 81 82 DialPointer needle = new DialPointer.Pin(); 83 needle.setRadius(0.84); 84 plot.addLayer(needle); 85 JFreeChart chart1 = new JFreeChart(plot); 86 chart1.setTitle("Dial Demo 4"); 87 ChartPanel cp1 = new ChartPanel(chart1); 88 89 cp1.setPreferredSize(new Dimension (400, 250)); 90 slider = new JSlider (0, 100); 91 slider.setMajorTickSpacing(10); 92 slider.setPaintLabels(true); 93 slider.addChangeListener(this); 94 JPanel content = new JPanel (new BorderLayout ()); 95 content.add(cp1); 96 content.add(slider, BorderLayout.SOUTH); 97 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 98 setContentPane(content); 99 100 } 101 102 108 public void stateChanged(ChangeEvent e) { 109 this.dataset.setValue(new Integer (slider.getValue())); 110 } 111 112 117 public static void main(String [] args) { 118 119 DialDemo4 app = new DialDemo4("JFreeChart - Demo Dial 4"); 120 app.pack(); 121 app.setVisible(true); 122 123 } 124 } 125 | Popular Tags |