| 1 |
/* |
| 2 |
** This file is part of Filius, a network construction and simulation software. |
| 3 |
** |
| 4 |
** Originally created at the University of Siegen, Institute "Didactics of |
| 5 |
** Informatics and E-Learning" by a students' project group: |
| 6 |
** members (2006-2007): |
| 7 |
** André Asschoff, Johannes Bade, Carsten Dittich, Thomas Gerding, |
| 8 |
** Nadja Haßler, Ernst Johannes Klebert, Michell Weyer |
| 9 |
** supervisors: |
| 10 |
** Stefan Freischlad (maintainer until 2009), Peer Stechert |
| 11 |
** Project is maintained since 2010 by Christian Eibl <[email protected]> |
| 12 |
** and Stefan Freischlad |
| 13 |
** Filius is free software: you can redistribute it and/or modify |
| 14 |
** it under the terms of the GNU General Public License as published by |
| 15 |
** the Free Software Foundation, either version 2 of the License, or |
| 16 |
** (at your option) version 3. |
| 17 |
** |
| 18 |
** Filius is distributed in the hope that it will be useful, |
| 19 |
** but WITHOUT ANY WARRANTY; without even the implied |
| 20 |
** warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 21 |
** PURPOSE. See the GNU General Public License for more details. |
| 22 |
** |
| 23 |
** You should have received a copy of the GNU General Public License |
| 24 |
** along with Filius. If not, see <http://www.gnu.org/licenses/>. |
| 25 |
*/ |
| 26 |
package filius.gui.anwendungssicht; |
| 27 |
|
| 28 |
import java.awt.BorderLayout; |
| 29 |
import java.awt.Dimension; |
| 30 |
import java.awt.event.ActionEvent; |
| 31 |
import java.awt.event.ActionListener; |
| 32 |
import java.util.Observable; |
| 33 |
|
| 34 |
import javax.swing.BorderFactory; |
| 35 |
import javax.swing.Box; |
| 36 |
import javax.swing.JButton; |
| 37 |
import javax.swing.JLabel; |
| 38 |
import javax.swing.JPanel; |
| 39 |
import javax.swing.JScrollPane; |
| 40 |
import javax.swing.JTextArea; |
| 41 |
import javax.swing.JTextField; |
| 42 |
|
| 43 |
import filius.software.clientserver.ServerAnwendung; |
| 44 |
import filius.software.clientserver.ServerBaustein; |
| 45 |
|
| 46 |
/** |
| 47 |
* <p> |
| 48 |
* Diese Klasse stellt die Benutzungsoberflaeche fuer das Server-Programm einer einfachen Client-Server-Anwendung zur |
| 49 |
* Verfuegung. |
| 50 |
* </p> |
| 51 |
* <p> |
| 52 |
* Nachrichten von der Anwendung werden nach dem Beobachtermuster durch die Benachrichtigung der Beobachter angenommen |
| 53 |
* und verarbeitet. |
| 54 |
* </p> |
| 55 |
*/ |
| 56 |
public class GUIApplicationServerBausteinWindow extends GUIApplicationWindow { |
| 57 |
|
| 58 |
private static final long serialVersionUID = 1L; |
| 59 |
|
| 60 |
/** |
| 61 |
* Textbereich zur Ausgabe von Log-Daten, die vom Server-Programm erzeugt und durch Benachrichtigung der Beobachter |
| 62 |
* an die graphische Benutzungsoberflaeche weiter gegeben werden |
| 63 |
*/ |
| 64 |
private JTextArea taLog; |
| 65 |
|
| 66 |
/** |
| 67 |
* Schaltflaeche zum Starten bzw. Stoppen des Server-Programms, d. h. zum Starten bzw. Beenden der |
| 68 |
* Verbindungsannahme durch den Server |
| 69 |
*/ |
| 70 |
private JButton bStartStop; |
| 71 |
|
| 72 |
/** |
| 73 |
* Textfeld zur Eingabe des Ports, an dem der Server eingehende Verbindungsanfragen entgegen nimmt. |
| 74 |
*/ |
| 75 |
private JTextField tfPort; |
| 76 |
|
| 77 |
/** |
| 78 |
* Standard-Konstruktor, der automatisch zur Erzeugung der graphischen Benutzungsoberflaeche fuer diese Anwendung |
| 79 |
* aufgerufen wird. |
| 80 |
*/ |
| 81 |
public GUIApplicationServerBausteinWindow(GUIDesktopPanel desktop, String appName) { |
| 82 |
super(desktop, appName); |
| 83 |
initialisiereKomponenten(); |
| 84 |
} |
| 85 |
|
| 86 |
/** Methode zur Initialisierung der graphischen Komponenten */ |
| 87 |
private void initialisiereKomponenten() { |
| 88 |
JPanel hauptPanel; |
| 89 |
JScrollPane spLogScroller; |
| 90 |
JLabel lbPort; |
| 91 |
Box hBox, vBox; |
| 92 |
|
| 93 |
hauptPanel = new JPanel(new BorderLayout()); |
| 94 |
vBox = Box.createVerticalBox(); |
| 95 |
vBox.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); |
| 96 |
vBox.add(Box.createVerticalStrut(5)); |
| 97 |
|
| 98 |
hBox = Box.createHorizontalBox(); |
| 99 |
|
| 100 |
bStartStop = new JButton(); |
| 101 |
bStartStop.addActionListener(new ActionListener() { |
| 102 |
public void actionPerformed(ActionEvent e) { |
| 103 |
if (e.getActionCommand().equals("start")) { |
| 104 |
((ServerAnwendung) holeAnwendung()).setPort(Integer.parseInt(tfPort.getText())); |
| 105 |
((ServerAnwendung) holeAnwendung()).setAktiv(true); |
| 106 |
((ServerAnwendung) holeAnwendung()).setPort(Integer.parseInt(tfPort.getText())); |
| 107 |
} else { |
| 108 |
((ServerAnwendung) holeAnwendung()).setAktiv(false); |
| 109 |
} |
| 110 |
aktualisieren(); |
| 111 |
} |
| 112 |
}); |
| 113 |
hBox.add(bStartStop); |
| 114 |
hBox.add(Box.createHorizontalStrut(5)); |
| 115 |
|
| 116 |
lbPort = new JLabel(messages.getString("serverbaustein_msg1")); |
| 117 |
hBox.add(lbPort); |
| 118 |
tfPort = new JTextField("" + ((ServerAnwendung) holeAnwendung()).getPort()); |
| 119 |
hBox.add(tfPort); |
| 120 |
|
| 121 |
vBox.add(hBox); |
| 122 |
vBox.add(Box.createVerticalStrut(5)); |
| 123 |
|
| 124 |
taLog = new JTextArea(); |
| 125 |
taLog.setEditable(false); |
| 126 |
spLogScroller = new JScrollPane(taLog); |
| 127 |
spLogScroller.setPreferredSize(new Dimension(400, 400)); |
| 128 |
vBox.add(spLogScroller); |
| 129 |
vBox.add(Box.createVerticalStrut(5)); |
| 130 |
|
| 131 |
hauptPanel.add(vBox, BorderLayout.CENTER); |
| 132 |
|
| 133 |
add(hauptPanel, BorderLayout.CENTER); |
| 134 |
|
| 135 |
aktualisieren(); |
| 136 |
} |
| 137 |
|
| 138 |
/** |
| 139 |
* Methode zum aktualisieren der Komponenten der graphischen Benutzungsoberflaeche in Abhaengigkeit vom Zustand der |
| 140 |
* Anwendung |
| 141 |
*/ |
| 142 |
public void aktualisieren() { |
| 143 |
ServerBaustein server; |
| 144 |
|
| 145 |
server = (ServerBaustein) holeAnwendung(); |
| 146 |
if (server.isAktiv()) { |
| 147 |
tfPort.setEditable(false); |
| 148 |
bStartStop.setText(messages.getString("serverbaustein_msg2")); |
| 149 |
bStartStop.setActionCommand("stop"); |
| 150 |
} else { |
| 151 |
bStartStop.setText(messages.getString("serverbaustein_msg3")); |
| 152 |
bStartStop.setActionCommand("start"); |
| 153 |
tfPort.setEditable(true); |
| 154 |
} |
| 155 |
} |
| 156 |
|
| 157 |
/** |
| 158 |
* Diese Methode wird automatisch ausgefuehrt, wenn der eine Nachricht an den Beobachter der Anwendung gesendet |
| 159 |
* wird. Der Parameter arg enthaelt die Nachricht, die von der Anwendung verschickt wurde. |
| 160 |
*/ |
| 161 |
public void update(Observable o, Object arg) { |
| 162 |
taLog.append(arg.toString() + "\n"); |
| 163 |
aktualisieren(); |
| 164 |
} |
| 165 |
} |