001    /**
002     *  Licensed to the Apache Software Foundation (ASF) under one or more
003     *  contributor license agreements.  See the NOTICE file distributed with
004     *  this work for additional information regarding copyright ownership.
005     *  The ASF licenses this file to You under the Apache License, Version 2.0
006     *  (the "License"); you may not use this file except in compliance with
007     *  the License.  You may obtain a copy of the License at
008     *
009     *     http://www.apache.org/licenses/LICENSE-2.0
010     *
011     *  Unless required by applicable law or agreed to in writing, software
012     *  distributed under the License is distributed on an "AS IS" BASIS,
013     *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     *  See the License for the specific language governing permissions and
015     *  limitations under the License.
016     */
017    package org.apache.geronimo.samples.daytrader.client;
018    
019    import java.awt.*;
020    import java.awt.event.*;
021    import javax.swing.*;
022    import org.apache.geronimo.samples.daytrader.client.table.*;
023    
024    public class TradeClientGUI extends JFrame implements ActionListener, WindowListener {
025            private JMenuItem resetItem;
026            private JMenuItem exitItem;
027            private JMenuItem propItem;
028            private TradeClient client;
029            private JTextField statusMsg;
030            private JLabel webLabel, ejbLabel;
031            private TradeClientGUIProperties props;
032    
033            private static final String TRADELOGO_FILENAME = "/images/dayTraderLogo.gif";
034            private static final String WEBSPHERELOGO_FILENAME = "/images/copyRight.gif";
035    
036            public TradeClientGUI(TradeClient client) {
037                    this.client = client;
038                    
039                    JTabbedPane overallPanel = new JTabbedPane();
040    
041                    // Panel 1 - Streaming quotes
042                    JPanel streamerPanel = new JPanel();
043                    streamerPanel.setBorder(new javax.swing.border.BevelBorder(javax.swing.border.BevelBorder.RAISED));
044                    JPanel topBarPanel = new JPanel();
045                    topBarPanel.setLayout(new BoxLayout(topBarPanel, BoxLayout.X_AXIS));
046                    JPanel topImagePanel = new JPanel();
047                    topImagePanel.setLayout(new BorderLayout());
048    
049                    statusMsg = new JTextField("");
050    
051                    SortableTable auditTable = new SortableTable(client.getAuditStats());
052                    auditTable.setDefaultRenderer(ChangeModel.class, new ChangeRenderer());
053                    auditTable.setDefaultRenderer(AuditModel.class, new AuditRenderer());
054                    auditTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
055    
056                    JScrollPane scrollpane1 = new JScrollPane(auditTable);
057    
058                    ImageIcon iconTrade = new ImageIcon(this.getClass().getResource(TRADELOGO_FILENAME));
059    //              ImageIcon iconWS = new ImageIcon(this.getClass().getResource(WEBSPHERELOGO_FILENAME));
060    
061                    topImagePanel.add(new JLabel(iconTrade), BorderLayout.WEST);
062    //              topImagePanel.add(new JLabel(iconWS), BorderLayout.EAST);
063    
064                    streamerPanel.setLayout(new BorderLayout());
065                    streamerPanel.add(topImagePanel, BorderLayout.NORTH);
066                    streamerPanel.add(scrollpane1, BorderLayout.CENTER);
067                    streamerPanel.add(statusMsg, BorderLayout.SOUTH);
068            
069                    // Overall Frame
070                    setTitle("Trade Client Application");
071                    addWindowListener(this);
072    
073                    JMenuBar jmb = new JMenuBar();
074                    JMenu file = new JMenu ("File");
075                    exitItem = new JMenuItem("Exit");
076                    resetItem = new JMenuItem("Reset");
077                    propItem = new JMenuItem("Properties");
078        file.add(exitItem);
079                    file.add(resetItem);
080                    file.add(propItem);
081        exitItem.addActionListener(this);
082                    resetItem.addActionListener(this);
083        propItem.addActionListener(this);
084                    jmb.add(file);
085                    setJMenuBar(jmb);
086    
087                    overallPanel.addTab("Streamer", streamerPanel);
088                    getContentPane().add(overallPanel, java.awt.BorderLayout.CENTER);
089                    setSize(800, 600);
090    
091                    props = new TradeClientGUIProperties(client, this);
092                    props.pack();
093    
094                    setVisible(true);
095            }
096    
097            public void updateStatusMessage(String message) {
098                    statusMsg.setText(message);
099            }
100    
101            public void actionPerformed(ActionEvent e) {
102                    if (e.getSource() == resetItem) {
103                            try {
104                                    client.reset();
105                            }
106                            catch (Exception ex)    {
107                                    System.err.println("Caught an unexpected exception!");
108                                    ex.printStackTrace();
109                            }
110                    }
111                    if (e.getSource() == propItem) {
112                            props.setVisible(true);
113                    }
114                    if (e.getSource() == exitItem) {
115                            client.closeClient();
116                    }
117            }
118    
119            public void windowClosing(WindowEvent e) {
120                    client.closeClient();
121            }
122    
123            public void windowOpened(WindowEvent e) {}
124            public void windowClosed(WindowEvent e) {}
125            public void windowIconified(WindowEvent e) {}
126            public void windowDeiconified(WindowEvent e) {}
127            public void windowActivated(WindowEvent e) {}
128            public void windowDeactivated(WindowEvent e) {}
129    }