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.event.*;
020    import javax.swing.*;
021    
022    public class TradeClientGUIProperties extends JDialog implements ActionListener, WindowListener {
023            private JTextField updateInterval, maxPerSecond;
024            private JButton okButton;
025            private TradeClient client;
026    
027            public TradeClientGUIProperties(TradeClient client, TradeClientGUI gui) {
028                    super(gui, true);
029                    this.client = client;
030    
031                    JPanel buttonPanel = new JPanel();
032                    okButton = new JButton("OK");
033                    buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
034                    buttonPanel.add(okButton);
035                    okButton.addActionListener(this);
036    
037                    JPanel mainPanel = new JPanel();
038                    mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
039    
040                    JPanel panel = new JPanel();
041                    panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
042    
043                    JLabel label1 = new JLabel("Update Interval:");
044                    updateInterval = new JTextField(String.valueOf(client.getUpdateInterval()), 3);
045                    panel.add(label1);
046                    panel.add(updateInterval);
047    
048                    mainPanel.add(panel);
049    
050                    mainPanel.add(buttonPanel);
051    
052                    getContentPane().add(mainPanel, java.awt.BorderLayout.CENTER);
053                    setDefaultCloseOperation(HIDE_ON_CLOSE);
054                    addWindowListener(this);
055                    setTitle("Trade Streamer Client Configuration Properties");
056            }
057    
058            private void updateUpdateInterval() {
059                    String udi = updateInterval.getText().trim();
060                    int udii = TradeClient.DEFAULT_UPDATE_INTERVAL;
061                    try {
062                            udii = Integer.parseInt(udi);
063                    }
064                    catch (NumberFormatException nfe) {
065                            updateInterval.setText(String.valueOf(udii));
066                    }
067                    client.setUpdateInterval(udii);
068            }
069    
070            public void actionPerformed(ActionEvent e) {
071                    if (e.getSource() == okButton) {
072                            updateUpdateInterval();
073                            setVisible(false);
074                    }
075            }
076    
077            public void windowClosing(WindowEvent e) {
078                    updateUpdateInterval();
079            }
080    
081            public void windowOpened(WindowEvent e) {}
082            public void windowClosed(WindowEvent e) {}
083            public void windowIconified(WindowEvent e) {}
084            public void windowDeiconified(WindowEvent e) {}
085            public void windowActivated(WindowEvent e) {}
086            public void windowDeactivated(WindowEvent e) {}
087    
088    }