001: /*
002: * Jacareto Copyright (c) 2002-2005
003: * Applied Computer Science Research Group, Darmstadt University of
004: * Technology, Institute of Mathematics & Computer Science,
005: * Ludwigsburg University of Education, and Computer Based
006: * Learning Research Group, Aachen University. All rights reserved.
007: *
008: * Jacareto is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU General Public
010: * License as published by the Free Software Foundation; either
011: * version 2 of the License, or (at your option) any later version.
012: *
013: * Jacareto is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016: * General Public License for more details.
017: *
018: * You should have received a copy of the GNU General Public
019: * License along with Jacareto; if not, write to the Free
020: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
021: *
022: */
023:
024: package jacareto.cleverphl.gui;
025:
026: import jacareto.cleverphl.CleverPHL;
027: import jacareto.cleverphl.connection.ConnectionListenerThread;
028:
029: import java.awt.GridBagConstraints;
030: import java.awt.GridBagLayout;
031: import java.awt.event.ActionEvent;
032: import java.awt.event.ActionListener;
033: import java.awt.event.WindowEvent;
034: import java.awt.event.WindowListener;
035:
036: import javax.swing.JButton;
037: import javax.swing.JLabel;
038: import javax.swing.JPanel;
039: import javax.swing.border.EmptyBorder;
040:
041: /**
042: * Window to start and stop the server functionality.
043: *
044: * @author uak <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
045: * @version 1.0
046: */
047: public class ServerPropertiesFrame extends CleverPHLFrame implements
048: ActionListener, WindowListener {
049: /** The thread for the ConnectionListener */
050: private ConnectionListenerThread con;
051:
052: /** The CleverPHL instance. */
053: private CleverPHL clleverPHL;
054:
055: /** The ok button. */
056: private JButton connectButton;
057:
058: /** The cancel button. */
059: private JButton cancelButton;
060:
061: /** The text field of the port number. */
062: private WholeNumberField portField;
063:
064: /**
065: * Creates a new frame (visible).
066: *
067: * @param cleverPHL the CleverPHL instance
068: */
069: public ServerPropertiesFrame(CleverPHL cleverPHL) {
070: super (cleverPHL, "CleverPHL.ServerPropertiesFrame", null);
071:
072: this .clleverPHL = cleverPHL;
073: getContentPane().setLayout(new GridBagLayout());
074:
075: setTitle("Server properties");
076: addWindowListener(this );
077:
078: // The panel with the text fields
079: JPanel textFieldPanel = new JPanel();
080: textFieldPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
081: textFieldPanel.setLayout(new GridBagLayout());
082:
083: portField = new WholeNumberField(80, 5);
084:
085: //The standard port, which is used is port 4444
086: portField.setText("4444");
087:
088: JLabel portFieldLabel = new JLabel("Port:");
089:
090: portFieldLabel.setLabelFor(portField);
091: textFieldPanel.add(portFieldLabel);
092: textFieldPanel.add(portField);
093:
094: getContentPane().add(textFieldPanel);
095:
096: // The panel with the buttons
097: JPanel buttonPanel = new JPanel();
098: GridBagConstraints c = new GridBagConstraints();
099: c.gridx = 0;
100: c.gridy = 10;
101: c.weightx = 40;
102: c.ipadx = 5;
103: c.anchor = GridBagConstraints.SOUTHEAST;
104:
105: connectButton = new JButton();
106: cancelButton = new JButton();
107: cancelButton.setEnabled(false);
108: connectButton.setText("Start Listening");
109: connectButton.addActionListener(new ActionListener() {
110: public void actionPerformed(ActionEvent e) {
111: try {
112: // make window invisible instead of closing it.
113: setVisible(false);
114:
115: int port = portField.getValue();
116:
117: if (con == null) {
118: // a new thread is instantiated, listening on the specified ports for incoming connection
119: con = new ConnectionListenerThread(clleverPHL,
120: port);
121: con.setName("ServerThread");
122:
123: con.start();
124: }
125:
126: connectButton.setEnabled(false);
127: cancelButton.setEnabled(true);
128: } catch (Exception ex) {
129: // generate exception dialog
130: System.out.println(ex);
131: }
132: }
133: });
134: cancelButton.setText("Stop Listening");
135: cancelButton.addActionListener(new ActionListener() {
136: public void actionPerformed(ActionEvent e) {
137: // We have to get rid of the "ServerThread"
138: if (con != null) {
139: con.stopThread();
140: }
141:
142: // Now we close the window
143: dispose();
144: connectButton.setEnabled(true);
145: cancelButton.setEnabled(false);
146: }
147: });
148:
149: buttonPanel.add(connectButton);
150: buttonPanel.add(cancelButton);
151:
152: getContentPane().add(buttonPanel, c);
153:
154: validate();
155: pack();
156: setResizable(false);
157:
158: //setLocation (100, 100);
159: setVisible(true);
160: }
161:
162: /**
163: * Called when one of the two buttons has been pressed.
164: *
165: * @param e the action event
166: */
167: public void actionPerformed(ActionEvent e) {
168: }
169:
170: /* (non-Javadoc)
171: * @see java.awt.event.WindowListener#windowOpened(java.awt.event.WindowEvent)
172: */
173: public void windowOpened(WindowEvent e) {
174: }
175:
176: /* (non-Javadoc)
177: * @see java.awt.event.WindowListener#windowClosing(java.awt.event.WindowEvent)
178: */
179: public void windowClosing(WindowEvent e) {
180: }
181:
182: /* (non-Javadoc)
183: * @see java.awt.event.WindowListener#windowClosed(java.awt.event.WindowEvent)
184: */
185: public void windowClosed(WindowEvent e) {
186: }
187:
188: /* (non-Javadoc)
189: * @see java.awt.event.WindowListener#windowIconified(java.awt.event.WindowEvent)
190: */
191: public void windowIconified(WindowEvent e) {
192: }
193:
194: /* (non-Javadoc)
195: * @see java.awt.event.WindowListener#windowDeiconified(java.awt.event.WindowEvent)
196: */
197: public void windowDeiconified(WindowEvent e) {
198: }
199:
200: /* (non-Javadoc)
201: * @see java.awt.event.WindowListener#windowActivated(java.awt.event.WindowEvent)
202: */
203: public void windowActivated(WindowEvent e) {
204: }
205:
206: /* (non-Javadoc)
207: * @see java.awt.event.WindowListener#windowDeactivated(java.awt.event.WindowEvent)
208: */
209: public void windowDeactivated(WindowEvent e) {
210: }
211: }
|