001package com.ganteater.ae.desktop.view;
002
003import java.awt.Dimension;
004import java.awt.FlowLayout;
005import java.awt.Font;
006import java.util.Properties;
007
008import org.jfree.chart.ChartPanel;
009import org.jfree.chart.JFreeChart;
010import org.jfree.chart.plot.dial.DialBackground;
011import org.jfree.chart.plot.dial.DialCap;
012import org.jfree.chart.plot.dial.DialPlot;
013import org.jfree.chart.plot.dial.DialTextAnnotation;
014import org.jfree.chart.plot.dial.DialValueIndicator;
015import org.jfree.chart.plot.dial.StandardDialFrame;
016import org.jfree.chart.plot.dial.StandardDialScale;
017import org.jfree.data.general.DefaultValueDataset;
018
019import com.ganteater.ae.AEManager;
020import com.ganteater.ae.desktop.ui.AEFrame;
021
022public class DialScale extends PresentationPanel {
023        private static final long serialVersionUID = 1L;
024
025        private DefaultValueDataset dataset;
026
027        private DialPlot dialplot;
028
029        private double lower;
030
031        private double upper;
032
033        private double increment;
034
035        private int count;
036
037        public DialScale(Properties params, AEManager manager) {
038                super(params);
039                setLayout(new FlowLayout());
040
041                dataset = new DefaultValueDataset();
042
043                String title = params.getProperty("title", "");
044                String label = params.getProperty("label", "");
045                lower = Double.parseDouble(params.getProperty("lower", "0"));
046                upper = Double.parseDouble(params.getProperty("upper", "100"));
047                increment = Double.parseDouble(params.getProperty("increment", "10"));
048                count = Integer.parseInt(params.getProperty("count", "10"));
049
050                dialplot = new DialPlot();
051                dialplot.setDataset(dataset);
052                dialplot.setDialFrame(new StandardDialFrame());
053                dialplot.setBackground(new DialBackground());
054                DialTextAnnotation dialtextannotation = new DialTextAnnotation(label);
055                dialtextannotation.setFont(new Font("Dialog", 1, 14));
056                dialtextannotation.setRadius(0.69999999999999996D);
057                dialplot.addLayer(dialtextannotation);
058                DialValueIndicator dialvalueindicator = new DialValueIndicator(0);
059                dialplot.addLayer(dialvalueindicator);
060                StandardDialScale standarddialscale = new StandardDialScale(lower, upper, -120D, -300D, 10D, 4);
061                standarddialscale.setMajorTickIncrement(increment);
062                standarddialscale.setMinorTickCount(count);
063                standarddialscale.setTickRadius(0.88D);
064                standarddialscale.setTickLabelOffset(0.14999999999999999D);
065                standarddialscale.setTickLabelFont(new Font("Dialog", 0, 14));
066                dialplot.addScale(0, standarddialscale);
067                dialplot.addPointer(new org.jfree.chart.plot.dial.DialPointer.Pin());
068                DialCap dialcap = new DialCap();
069                dialplot.setCap(dialcap);
070                JFreeChart jfreechart = new JFreeChart(title, dialplot);
071
072                ChartPanel chartpanel = new ChartPanel(jfreechart, true);
073                chartpanel.setPreferredSize(new Dimension(AEFrame.MINIMUM_WIN_WIDTH, AEFrame.MINIMUM_WIN_WIDTH));
074                add(chartpanel);
075        }
076
077        @Override
078        public synchronized void out(Object data, Properties properties) {
079                double value = 0;
080
081                if (data instanceof String) {
082                        value = Double.parseDouble((String) data);
083                }
084
085                String type = properties.getProperty("type");
086
087                if (type == null) {
088                        dataset.setValue(value);
089                }
090        }
091
092}