package org.apache.wsdm.interop.wcm.impl.ui;
import java.awt.BorderLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.util.Observable;
import java.util.Observer;
import javax.swing.DefaultComboBoxModel;
import javax.swing.DefaultListModel;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.ListModel;
import javax.swing.ListSelectionModel;
import javax.swing.SwingUtilities;
import javax.swing.border.LineBorder;
import javax.swing.event.ListSelectionListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.JCheckBox;
import org.apache.ws.muws.interop.client.WcmMessage;
/**
* 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 MessagesJPanel extends javax.swing.JPanel implements Observer {
private JLabel jLabelTitle;
private JPanel jPanelRight;
private JPanel jPanelLeft;
private JList jListTime;
private JScrollPane jScrollPaneTime;
private JScrollPane jScrollPaneRequest;
private JCheckBox jCheckBoxUpdate;
private JLabel jLabelTime;
private JLabel jLabelRequest;
private JPanel jPanelRequest;
private JLabel jLabelResponse;
private JPanel jPanelResponse;
private JEditorPane response;
private JEditorPane request;
private JScrollPane jScrollPaneResponse;
private JSplitPane jSplitPaneReqRes;
private JPanel jPanelTimePanel;
private JPanel jPanelMessageBody;
private DefaultListModel listModel;
/**
* Auto-generated main method to display this
* JPanel inside a new JFrame.
*/
public static void main(String[] args) {
JFrame frame = new JFrame();
MessagesJPanel mp = new MessagesJPanel();
frame.getContentPane().add(mp);
frame.pack();
frame.show();
mp.setMessage(new WcmMessage("Blah,blah,blah","boogies are cool\nthen U die"));
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mp.setMessage(new WcmMessage("tookie tookie\ntonga","flabber\nwiggle\nwoo\n"));
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mp.setMessage(new WcmMessage("Boom Boom Voom","dwaddle wingle woodel\n pew"));
}
public MessagesJPanel() {
super();
initGUI();
listModel=new DefaultListModel();
jListTime.setModel(listModel);
}
private void initGUI() {
try {
BorderLayout thisLayout = new BorderLayout();
this.setLayout(thisLayout);
this.setPreferredSize(new java.awt.Dimension(583, 196));
{
jLabelTitle = new JLabel();
this.add(jLabelTitle, BorderLayout.NORTH);
jLabelTitle.setText(" Messages");
jLabelTitle.setBackground(new java.awt.Color(0,0,160));
jLabelTitle.setBorder(new LineBorder(new java.awt.Color(0,0,0), 1, false));
}
{
jPanelMessageBody = new JPanel();
GridBagLayout jPanel1Layout = new GridBagLayout();
jPanelMessageBody.setPreferredSize(new java.awt.Dimension(400, 284));
this.add(jPanelMessageBody, BorderLayout.CENTER);
jPanelMessageBody.setLayout(jPanel1Layout);
{
jPanelTimePanel = new JPanel();
BorderLayout jPanel1Layout1 = new BorderLayout();
jPanelTimePanel.setLayout(jPanel1Layout1);
jPanelMessageBody.add(
jPanelTimePanel,
new GridBagConstraints(
0,
0,
1,
1,
0.0,
1.0,
GridBagConstraints.NORTHEAST,
GridBagConstraints.BOTH,
new Insets(0, 0, 0, 0),
0,
0));
jPanelTimePanel.setMinimumSize(new java.awt.Dimension(100, 10));
jPanelTimePanel.setPreferredSize(new java.awt.Dimension(100, 10));
jPanelTimePanel.setRequestFocusEnabled(false);
jPanelTimePanel.setMaximumSize(new java.awt.Dimension(100, 32767));
jPanelTimePanel.setSize(90, 278);
{
jLabelTime = new JLabel();
jPanelTimePanel.add(jLabelTime, BorderLayout.NORTH);
jLabelTime.setText(" Time");
}
{
jScrollPaneTime = new JScrollPane();
jPanelTimePanel.add(jScrollPaneTime, BorderLayout.CENTER);
jScrollPaneTime.setSize(90, 262);
jScrollPaneTime.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
{
ListModel jListTimeModel = new DefaultComboBoxModel(
new String[] { "Item One", "Item Two" });
jListTime = new JList();
jScrollPaneTime.setViewportView(jListTime);
jListTime.setModel(jListTimeModel);
jListTime.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
jListTime.setFocusable(false);
jListTime
.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent evt) {
updateMessages(evt.getSource());
}
});
}
}
{
jCheckBoxUpdate = new JCheckBox();
jPanelTimePanel
.add(jCheckBoxUpdate, BorderLayout.SOUTH);
jCheckBoxUpdate.setText("Auto Update");
jCheckBoxUpdate.setFont(new java.awt.Font("Dialog",0,9));
}
}
{
jSplitPaneReqRes = new JSplitPane();
jPanelMessageBody.add(
jSplitPaneReqRes,
new GridBagConstraints(
5,
0,
1,
GridBagConstraints.REMAINDER,
0.85,
1.0,
GridBagConstraints.CENTER,
GridBagConstraints.BOTH,
new Insets(0, 0, 0, 0),
0,
0));
jSplitPaneReqRes.setDividerLocation(200);
jSplitPaneReqRes.setMinimumSize(new java.awt.Dimension(5, 28));
{
jPanelLeft = new JPanel();
BorderLayout jPanelLeftLayout = new BorderLayout();
jPanelLeft.setLayout(jPanelLeftLayout);
jSplitPaneReqRes.add(jPanelLeft, JSplitPane.LEFT);
{
jLabelRequest = new JLabel();
jPanelLeft.add(jLabelRequest, BorderLayout.NORTH);
jLabelRequest.setText(" Request");
}
{
jScrollPaneRequest = new JScrollPane();
jPanelLeft.add(
jScrollPaneRequest,
BorderLayout.CENTER);
jScrollPaneRequest
.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
{
jPanelRequest = new JPanel();
BorderLayout jPanelRequestLayout = new BorderLayout();
jPanelRequest.setEnabled(false);
jPanelRequest.setLayout(jPanelRequestLayout);
jScrollPaneRequest
.setViewportView(jPanelRequest);
{
request = new JEditorPane();
jPanelRequest.add(
getRequest(),
BorderLayout.CENTER);
request
.setPreferredSize(new java.awt.Dimension(
200,
257));
request.setEditable(false);
request
.setMinimumSize(new java.awt.Dimension(
50,
22));
}
}
}
}
{
jPanelRight = new JPanel();
BorderLayout jPanel1Layout2 = new BorderLayout();
jSplitPaneReqRes.add(jPanelRight, JSplitPane.RIGHT);
jPanelRight.setLayout(jPanel1Layout2);
{
jLabelResponse = new JLabel();
jPanelRight.add(jLabelResponse, BorderLayout.NORTH);
jLabelResponse.setText(" Response");
}
{
jScrollPaneResponse = new JScrollPane();
jPanelRight.add(jScrollPaneResponse, BorderLayout.CENTER);
jScrollPaneResponse
.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
{
jPanelResponse = new JPanel();
jScrollPaneResponse.setViewportView(jPanelResponse);
BorderLayout jPanelResponseLayout = new BorderLayout();
jPanelResponse.setLayout(jPanelResponseLayout);
{
response = new JEditorPane();
jPanelResponse.add(
getResponse(),
BorderLayout.CENTER);
response
.setPreferredSize(new java.awt.Dimension(
200,
257));
response.setEditable(false);
response
.setMinimumSize(new java.awt.Dimension(
5,
22));
}
}
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* @param source
*/
protected void updateMessages(Object source) {
if(jListTime.getSelectedValue()==null){
response.setText("");
request.setText("");
return;
}
WcmMessage value=(WcmMessage) jListTime.getSelectedValue();
response.setText(value.getResponse());
request.setText(value.getRequest());
}
public JEditorPane getRequest() {
return request;
}
public JEditorPane getResponse() {
return response;
}
public void setMessage(final WcmMessage message){
//listModel.addElement(message);
SwingUtilities.invokeLater(new Runnable(){
public void run() {
listModel.add(0,message);
if(listModel.getSize()==1){
jListTime.setSelectedIndex(0);
}
if(jCheckBoxUpdate.isSelected()){
jListTime.setSelectedIndex(0);
}
}});
}
/* (non-Javadoc)
* @see java.util.Observer#update(java.util.Observable, java.lang.Object)
*/
public void update(Observable o, Object arg) {
if(arg instanceof WcmMessage){
setMessage((WcmMessage)arg);
}
}
public void clearMessages(){
listModel.removeAllElements();
response.setText("");
request.setText("");
}
}