package org.apache.wsdm.interop.wcm.impl.ui;
import javax.swing.JPanel;
import javax.swing.JFrame;
import java.awt.Dimension;
import javax.swing.JLabel;
import java.awt.FlowLayout;
import javax.swing.SwingConstants;
import javax.swing.JProgressBar;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.Plot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultIntervalCategoryDataset;
import org.jfree.data.xy.CategoryTableXYDataset;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import java.awt.BorderLayout;
import java.util.Date;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
/**
* This code was generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* *************************************
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED
* for this machine, so Jigloo or this code cannot be used legally
* for any corporate or commercial purpose.
* *************************************
*/
public class TemperatureJPanel extends javax.swing.JPanel {
private JLabel jLabelTemperature;
private JPanel jPanelChartContainer;
private JPanel jPanelThermometer;
private JLabel jLabelOneTwenty;
private JLabel jLabelStatusValue;
private JLabel jLabelFifty;
private JLabel jLabelZero;
private JLabel jLabelStatus;
private JLabel jLabelCostValue;
private JLabel jLabelCost;
private JLabel jLabelStationNameValue;
private JLabel jLabelStationName;
private JPanel jPanelData;
private JProgressBar jProgressBarTemp;
private ChartPanel jPanelChart;
private int interval=100;
private XYSeries series;
private int tickCount;
private boolean smoothData=false;
/**
* Auto-generated main method to display this
* JPanel inside a new JFrame.
*/
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.getContentPane().add(new TemperatureJPanel());
frame.pack();
frame.show();
}
public TemperatureJPanel() {
super();
initGUI();
addChart();
}
public void setSmooth(boolean value){
smoothData=value;
}
/**
*
*/
private void addChart() {
series = new XYSeries("Temperature");
XYDataset xyDataset=new XYSeriesCollection(series);
JFreeChart chart=ChartFactory.createTimeSeriesChart("History","Time","Temperature",
xyDataset,false,false,false);
//chart.getXYPlot()
jPanelChart=new ChartPanel(chart);
jPanelChart.setOpaque(false);
jPanelChartContainer.add(jPanelChart);
}
private void initGUI() {
try {
this.setPreferredSize(new java.awt.Dimension(400, 372));
GridBagLayout thisLayout = new GridBagLayout();
thisLayout.columnWeights = new double[] {0.1,0.1,0.1,0.1};
thisLayout.columnWidths = new int[] {7,7,7,7};
thisLayout.rowWeights = new double[] {0.1,0.1,0.1,0.1};
thisLayout.rowHeights = new int[] {7,7,7,7};
this.setLayout(thisLayout);
{
jLabelTemperature = new JLabel();
this.add(jLabelTemperature, new GridBagConstraints(
0,
0,
1,
1,
0.0,
0.1,
GridBagConstraints.CENTER,
GridBagConstraints.NONE,
new Insets(0, 15, 0, 0),
0,
0));
jLabelTemperature.setText("?? � F");
jLabelTemperature.setFont(new java.awt.Font("Dialog",1,36));
jLabelTemperature.setBounds(7, 9, 107, 47);
jLabelTemperature.setHorizontalAlignment(SwingConstants.CENTER);
}
{
jPanelData = new JPanel();
this.add(jPanelData, new GridBagConstraints(
1,
0,
3,
1,
0.0,
0.1,
GridBagConstraints.CENTER,
GridBagConstraints.HORIZONTAL,
new Insets(0, 0, 0, 0),
0,
0));
FlowLayout jPanelDataLayout = new FlowLayout();
jPanelData.setOpaque(false);
jPanelData.setBounds(130, 17, 264, 37);
jPanelData.setLayout(jPanelDataLayout);
{
jLabelStationName = new JLabel();
jPanelData.add(jLabelStationName);
jLabelStationName.setText("Station:");
jLabelStationName.setFont(new java.awt.Font("Dialog",1,14));
}
{
jLabelStationNameValue = new JLabel();
jPanelData.add(jLabelStationNameValue);
jLabelStationNameValue.setText("?");
jLabelStationNameValue.setFont(new java.awt.Font("Dialog",0,14));
}
{
jLabelCost = new JLabel();
jPanelData.add(jLabelCost);
jLabelCost.setText(" Cost:");
jLabelCost.setFont(new java.awt.Font("Dialog",1,14));
}
{
jLabelCostValue = new JLabel();
jPanelData.add(jLabelCostValue);
jLabelCostValue.setText("?");
jLabelCostValue.setFont(new java.awt.Font("Dialog",0,14));
}
{
jLabelStatus = new JLabel();
jPanelData.add(jLabelStatus);
jLabelStatus.setText(" Status:");
jLabelStatus.setFont(new java.awt.Font("Dialog",1,14));
}
{
jLabelStatusValue = new JLabel();
jPanelData.add(jLabelStatusValue);
jLabelStatusValue.setText("?");
jLabelStatusValue.setFont(new java.awt.Font("Dialog",0,14));
}
}
{
jPanelThermometer = new JPanel();
this.add(jPanelThermometer, new GridBagConstraints(
0,
1,
1,
3,
0.1,
0.9,
GridBagConstraints.NORTH,
GridBagConstraints.VERTICAL,
new Insets(0, 0, 0, 0),
0,
0));
GridBagLayout jPanelThermometerLayout = new GridBagLayout();
jPanelThermometerLayout.columnWeights = new double[] {0.1,0.1};
jPanelThermometerLayout.columnWidths = new int[] {7,7};
jPanelThermometerLayout.rowWeights = new double[] {0.1,0.1,0.1};
jPanelThermometerLayout.rowHeights = new int[] {7,7,7};
jPanelThermometer.setLayout(jPanelThermometerLayout);
jPanelThermometer.setBounds(19, 73, 68, 263);
{
jProgressBarTemp = new JProgressBar();
jPanelThermometer.add(
jProgressBarTemp,
new GridBagConstraints(
0,
1,
1,
1,
0.0,
0.0,
GridBagConstraints.CENTER,
GridBagConstraints.BOTH,
new Insets(0, 0, 0, 0),
0,
0));
jProgressBarTemp.setBounds(34, 56, 17, 220);
jProgressBarTemp
.setForeground(new java.awt.Color(255, 0, 0));
jProgressBarTemp.setOrientation(SwingConstants.VERTICAL);
jProgressBarTemp.setMaximum(120);
jProgressBarTemp.setPreferredSize(new java.awt.Dimension(
14,
208));
}
{
jLabelOneTwenty = new JLabel();
jPanelThermometer.add(
jLabelOneTwenty,
new GridBagConstraints(
1,
0,
1,
1,
0.0,
0.0,
GridBagConstraints.SOUTHWEST,
GridBagConstraints.NONE,
new Insets(0, 0, 0, 0),
0,
0));
jLabelOneTwenty.setText("120");
jLabelOneTwenty.setBounds(59, 53, 22, 15);
}
{
jLabelFifty = new JLabel();
jPanelThermometer.add(jLabelFifty, new GridBagConstraints(
1,
1,
1,
1,
0.0,
0.0,
GridBagConstraints.WEST,
GridBagConstraints.NONE,
new Insets(0, 0, 0, 0),
0,
0));
jLabelFifty.setText(" 60");
jLabelFifty.setBounds(59, 157, 21, 17);
}
{
jLabelZero = new JLabel();
jPanelThermometer.add(jLabelZero, new GridBagConstraints(
1,
2,
1,
1,
0.0,
0.0,
GridBagConstraints.NORTHWEST,
GridBagConstraints.NONE,
new Insets(0, 0, 0, 0),
0,
0));
jLabelZero.setText("0");
jLabelZero.setBounds(58, 267, 17, 15);
}
}
{
jPanelChartContainer = new JPanel();
this.add(jPanelChartContainer, new GridBagConstraints(
1,
1,
3,
3,
0.9,
0.9,
GridBagConstraints.NORTHWEST,
GridBagConstraints.BOTH,
new Insets(0, 0, 20, 20),
0,
0));
BorderLayout jPanelChartContainerLayout = new BorderLayout();
jPanelChartContainer.setOpaque(false);
jPanelChartContainer.setLayout(jPanelChartContainerLayout);
jPanelChartContainer.setBounds(83, 79, 301, 244);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public void addMeasurement(int temperature){
if(smoothData&&jProgressBarTemp.getValue()!=0){
int prev = jProgressBarTemp.getValue();
int diff = Math.abs(temperature-prev);
if(diff>20)
return;
}
Date time = new Date();
series.add(time.getTime(),(double)temperature);
jProgressBarTemp.setValue(temperature);
jLabelTemperature.setText(""+temperature+"� F");
tickCount++;
}
public void setStation(String stationName){
jLabelStationNameValue.setText(stationName);
}
public void setCost(String cost){
jLabelCostValue.setText("$"+cost);
}
public void setStatus(String status){
jLabelStatusValue.setText(status);
}
}