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;
021import com.ganteater.ae.processor.annotation.CommandDescription;
022
023@CommandDescription("`DialScale` View Type example:\r\n"
024                + "\r\n"
025                + "```xml\r\n"
026                + "<View name=\"dialView\" reuse=\"true\" type=\"DialScale\" title=\"Dial Scale\" /> \r\n"
027                + "<Loop name=\"column\" numbers=\"10\">\r\n"
028                + "     <Rnd name=\"value\" symbols=\"3\" type=\"number\" /> \r\n"
029                + "     <Out view=\"dialView\" row=\"1\" column=\"$var{column}\" level=\"debug\">$var{value}</Out> \r\n"
030                + "     <Wait delay=\"100\" /> \r\n"
031                + "</Loop> \r\n"
032                + "```")
033public class DialScale extends View {
034        private static final long serialVersionUID = 1L;
035
036        private DefaultValueDataset dataset;
037
038        private DialPlot dialplot;
039
040        private double lower;
041
042        private double upper;
043
044        private double increment;
045
046        private int count;
047
048        public void init(Properties params, AEManager manager) {
049                super.init(params, manager);
050                setLayout(new FlowLayout());
051
052                dataset = new DefaultValueDataset();
053
054                String title = params.getProperty("title", "");
055                String label = params.getProperty("label", "");
056                lower = Double.parseDouble(params.getProperty("lower", "0"));
057                upper = Double.parseDouble(params.getProperty("upper", "100"));
058                increment = Double.parseDouble(params.getProperty("increment", "10"));
059                count = Integer.parseInt(params.getProperty("count", "10"));
060
061                dialplot = new DialPlot();
062                dialplot.setDataset(dataset);
063                dialplot.setDialFrame(new StandardDialFrame());
064                dialplot.setBackground(new DialBackground());
065                DialTextAnnotation dialtextannotation = new DialTextAnnotation(label);
066                dialtextannotation.setFont(new Font("Dialog", 1, 14));
067                dialtextannotation.setRadius(0.69999999999999996D);
068                dialplot.addLayer(dialtextannotation);
069                DialValueIndicator dialvalueindicator = new DialValueIndicator(0);
070                dialplot.addLayer(dialvalueindicator);
071                StandardDialScale standarddialscale = new StandardDialScale(lower, upper, -120D, -300D, 10D, 4);
072                standarddialscale.setMajorTickIncrement(increment);
073                standarddialscale.setMinorTickCount(count);
074                standarddialscale.setTickRadius(0.88D);
075                standarddialscale.setTickLabelOffset(0.14999999999999999D);
076                standarddialscale.setTickLabelFont(new Font("Dialog", 0, 14));
077                dialplot.addScale(0, standarddialscale);
078                dialplot.addPointer(new org.jfree.chart.plot.dial.DialPointer.Pin());
079                DialCap dialcap = new DialCap();
080                dialplot.setCap(dialcap);
081                JFreeChart jfreechart = new JFreeChart(title, dialplot);
082
083                ChartPanel chartpanel = new ChartPanel(jfreechart, true);
084                chartpanel.setPreferredSize(new Dimension(AEFrame.MINIMUM_WIN_WIDTH, AEFrame.MINIMUM_WIN_WIDTH));
085                add(chartpanel);
086        }
087
088        @Override
089        public synchronized void out(Object data, Properties properties) {
090                double value = 0;
091
092                if (data instanceof String) {
093                        value = Double.parseDouble((String) data);
094                }
095
096                String type = properties.getProperty("type");
097
098                if (type == null) {
099                        dataset.setValue(value);
100                }
101        }
102
103}