package org.apache.interop.wcdisplay;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
import javax.swing.JTextField;
import javax.swing.JToggleButton;
import javax.swing.SwingUtilities;
import javax.swing.Timer;
import javax.swing.WindowConstants;
import javax.swing.border.BevelBorder;
import org.apache.interop.smgr.ConnectionListener;
import org.apache.ws.muws.interop.client.FaultException;
import org.apache.wsdm.interop.wcm.impl.ui.MessagesJPanel;
import org.apache.wsdm.interop.wcm.impl.ui.TemperatureJPanel;
import org.apache.xmlbeans.XmlException;
import org.apache.interop.common.LocationJPanel;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
/**
* 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 WcDisplayApp extends javax.swing.JFrame implements ConnectionListener {
private JSplitPane jSplitPaneGraphMessage;
private TemperatureJPanel temperatureJPanel1;
private LocationJPanel jPanelLocation;
private MessagesJPanel messagesJPanel;
private ActionListener m_taskPerformer;
private Timer m_timer;
private DisplayAppConnection m_connection;
private ImageIcon stillIcon=new ImageIcon(getClass().getClassLoader().getResource("org/apache/interop/wcdisplay/hp-still.gif"));
private ImageIcon aniIcon=new ImageIcon(getClass().getClassLoader().getResource("org/apache/interop/wcdisplay/hp-ani.gif"));
/**
* Auto-generated main method to display this JFrame
*/
public static void main(String[] args) {
WcDisplayApp inst = new WcDisplayApp();
inst.setVisible(true);
}
public WcDisplayApp() {
super();
initGUI();
setTitle("WCDisplay ");
jPanelLocation.setConnectionListener(this);
temperatureJPanel1.setSmooth(true);
}
private void initGUI() {
try {
this.setSize(731, 558);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent evt) {
System.out.println("this.windowClosing, event=" + evt);
try {
jPanelLocation.save();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
{
jPanelLocation = new LocationJPanel();
FlowLayout jPanel1Layout = new FlowLayout();
jPanel1Layout.setAlignment(FlowLayout.LEFT);
this.getContentPane().add(jPanelLocation, BorderLayout.NORTH);
jPanelLocation.setBackground(new java.awt.Color(239,239,239));
}
{
jSplitPaneGraphMessage = new JSplitPane();
this.getContentPane().add(
jSplitPaneGraphMessage,
BorderLayout.CENTER);
jSplitPaneGraphMessage.setOrientation(JSplitPane.VERTICAL_SPLIT);
jSplitPaneGraphMessage.setDividerLocation(300);
jSplitPaneGraphMessage.setPreferredSize(new java.awt.Dimension(684, 590));
{
temperatureJPanel1 = new TemperatureJPanel();
jSplitPaneGraphMessage.add(temperatureJPanel1, JSplitPane.LEFT);
}
{
messagesJPanel = new MessagesJPanel();
jSplitPaneGraphMessage
.add(messagesJPanel, JSplitPane.RIGHT);
messagesJPanel.setPreferredSize(new java.awt.Dimension(669, 241));
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Sets the app to the connected and polling state if true, idle if false;
* @param b
* @throws XmlException
* @throws FaultException
*/
public void setConnectionState(boolean b) {
if(b){
SwingUtilities.invokeLater(new Runnable(){
public void run() {
messagesJPanel.clearMessages();
}})
;
int delay=0; //milliseconds
try {
m_connection=new DisplayAppConnection(messagesJPanel,jPanelLocation.getEpr("weather-client-config-epr.xml"));// Builds EPR
delay = m_connection.getDelay();
} catch (XmlException e1) {
e1.printStackTrace();
return;
} catch (FaultException e1) {
e1.printStackTrace();
return;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
m_taskPerformer = new ActionListener() {
public void actionPerformed(ActionEvent evt) {
try {
updateDisplay();
} catch (FaultException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
};
m_taskPerformer.actionPerformed(null);
m_timer=new Timer(delay, m_taskPerformer);
m_timer.start();
} else {
// SwingUtilities.invokeLater(new Runnable(){
// public void run() {
// jLabelAniStatus.setIcon(stillIcon);
// }})
// ;
m_connection.deleteObservers();
m_connection=null;
if(m_timer!=null){
m_timer.stop();
m_timer=null; // Collect me
m_taskPerformer=null;
}
}
}
/**
* @throws FaultException
*
*/
protected void updateDisplay() throws FaultException {
m_connection.updateWsEpr();
if(m_connection.getStatus()!=null){
temperatureJPanel1.setStatus(m_connection.getStatus());
}
if(m_connection.getPrice()!=null){
temperatureJPanel1.setCost(m_connection.getPrice());
}
if(m_connection.getStationName()!=null){
temperatureJPanel1.setStation(m_connection.getStationName());
}
if(m_connection.getTemperature()>-1){
temperatureJPanel1.addMeasurement(m_connection.getTemperature());
}
}
/* (non-Javadoc)
* @see org.apache.interop.smgr.ConnectionListener#onConnect()
*/
public void onConnect() {
setConnectionState(true);
}
/* (non-Javadoc)
* @see org.apache.interop.smgr.ConnectionListener#onDisconnect()
*/
public void onDisconnect() {
setConnectionState(false);
}
}