Permalink
Browse files

Restored the monitor to functioning state

  • Loading branch information...
1 parent 3214318 commit f2f51752c3f8dc8579503f704702c7e6464de175 @rumour committed Apr 26, 2012
@@ -22,16 +22,13 @@
package org.gamehost.jtrek.monitor;
/**
- * Created by IntelliJ IDEA.
* User: Jay
* Date: Mar 9, 2004
* Time: 6:52:19 PM
- * To change this template use File | Settings | File Templates.
*/
public class Monitor {
-
public static void main(String[] args) {
MonitorUI m = new MonitorUI();
- m.show();
+ m.setVisible(true);
}
}
@@ -39,22 +39,26 @@
public class MonitorUI extends JFrame {
private static final long serialVersionUID = 4991642289515404201L;
- MigLayout layout = new MigLayout();
+
JMenuBar menuBar = new JMenuBar();
JScrollPane shipScrollPane = new JScrollPane();
JScrollPane playerScrollPane = new JScrollPane();
+ JScrollPane messageScrollPane = new JScrollPane();
+
+ JLabel shipCountLabel = new JLabel();
JLabel shipLabel = new JLabel();
JLabel playerLabel = new JLabel();
+ JLabel messageLabel = new JLabel();
+
JList shipList = new JList();
JList playerList = new JList();
- JScrollPane messageScrollPane = new JScrollPane();
- JLabel messageLabel = new JLabel();
+
JTextArea messageTextArea = new JTextArea();
- JLabel shipCountLabel = new JLabel();
- JMenu editMenu = new JMenu();
- JMenuItem optionsMI = new JMenuItem();
+
JMenu fileMenu = new JMenu();
+ JMenuItem optionsMI = new JMenuItem();
JMenuItem exitMI = new JMenuItem();
+
OptionsDialog dlg;
private String buffer = "";
@@ -80,17 +84,18 @@ public MonitorUI() {
}
}
- public void show() {
- super.show();
+ public void setVisible(boolean show) {
+ super.setVisible(show);
launchOptions();
doConnect();
}
private void initUI() throws Exception {
- JPanel panel = new JPanel(new MigLayout());
- panel.setMinimumSize(new Dimension(680, 275));
- getContentPane().setLayout(layout);
+ setLayout(new BorderLayout());
+ setTitle("JTrek Monitor");
+ setResizable(true);
+ setMinimumSize(new Dimension(480, 400));
shipLabel.setText("Active Ships");
playerLabel.setText("Players Monitoring");
@@ -99,13 +104,26 @@ private void initUI() throws Exception {
messageTextArea.setToolTipText("");
messageTextArea.setEditable(false);
messageTextArea.setText("");
- messageTextArea.setFont(new java.awt.Font("Courier New", 0, 10));
+ messageTextArea.setFont(new Font("Courier New", 0, 10));
shipCountLabel.setHorizontalAlignment(SwingConstants.RIGHT);
shipCountLabel.setText("Disconnected");
+ JPanel panel = new JPanel(new MigLayout("ins 0, wrap 1", "[fill, grow]", "[][][fill, grow, 0:0][][fill, grow, 0:0][][fill, grow, 0:0]"));
+
+ panel.add(shipCountLabel, "right");
+ panel.add(shipLabel);
+ panel.add(shipScrollPane);
+ panel.add(playerLabel);
+ panel.add(playerScrollPane);
+ panel.add(messageLabel);
+ panel.add(messageScrollPane);
+
+ messageScrollPane.getViewport().add(messageTextArea);
+ playerScrollPane.getViewport().add(playerList);
+ shipScrollPane.getViewport().add(shipList);
+
fileMenu.setText("File");
- editMenu.setText("Edit");
exitMI.setText("Exit");
optionsMI.setText("Options ...");
@@ -127,26 +145,12 @@ public void actionPerformed(ActionEvent e) {
}
});
- menuBar.add(fileMenu);
- //menuBar.add(editMenu);
- editMenu.add(optionsMI);
+ fileMenu.add(optionsMI);
fileMenu.add(exitMI);
+ menuBar.add(fileMenu);
- getContentPane().add(menuBar);
- this.getContentPane().add(shipCountLabel);
- this.getContentPane().add(shipLabel);
- this.getContentPane().add(shipScrollPane);
- this.getContentPane().add(playerLabel);
- this.getContentPane().add(playerScrollPane);
- this.getContentPane().add(messageLabel);
- this.getContentPane().add(messageScrollPane);
-
- messageScrollPane.getViewport().add(messageTextArea, null);
- playerScrollPane.getViewport().add(playerList, null);
- shipScrollPane.getViewport().add(shipList, null);
-
- setTitle("JTrek Monitor");
- setResizable(false);
+ add(menuBar, BorderLayout.NORTH);
+ add(panel, BorderLayout.CENTER);
pack();
}
@@ -227,8 +231,7 @@ private String getBlockedInput(boolean waitForCarriageReturn) {
}
public void processData(String data) {
- //System.out.println(data);
- if (data.indexOf("DISC:ACK") != -1) {
+ if (data.contains("DISC:ACK")) {
// disconnected from server
isConnected = false;
try {
@@ -237,7 +240,7 @@ public void processData(String data) {
e.printStackTrace();
}
}
- else if (data.indexOf("SHIPS:") != -1) {
+ else if (data.contains("SHIPS:")) {
// parse ship data
int colonLoc = data.indexOf(":");
int tildeLoc = data.indexOf("~");
@@ -252,7 +255,7 @@ else if (data.indexOf("SHIPS:") != -1) {
shipScrollPane.getViewport().add(shipList, null);
}
- else if (data.indexOf("MON:") != -1) {
+ else if (data.contains("MON:")) {
// parse people monitoring
int colonLoc = data.indexOf(":");
int tildeLoc = data.indexOf("~");
@@ -267,37 +270,35 @@ else if (data.indexOf("MON:") != -1) {
playerScrollPane.getViewport().add(playerList, null);
}
- else if (data.indexOf("COUNT:") != -1) {
+ else if (data.contains("COUNT:")) {
// parse ship count
int colonLoc = data.indexOf(":");
- int ships = new Integer(data.substring(colonLoc + 1)).intValue();
+ int ships = new Integer(data.substring(colonLoc + 1));
if (ships == 1) {
shipCountLabel.setText("" + ships + " Active Ship");
} else {
shipCountLabel.setText("" + ships + " Active Ships");
}
}
- else if (data.indexOf("BOT:") != -1) {
+ else if (data.contains("BOT:")) {
// parse bot count
int colonLoc = data.indexOf(":");
- int bots = new Integer(data.substring(colonLoc + 1)).intValue();
+ int bots = new Integer(data.substring(colonLoc + 1));
if (bots == 1) {
shipCountLabel.setText(shipCountLabel.getText() + " (" + bots + " bot)");
} else {
shipCountLabel.setText(shipCountLabel.getText() + " (" + bots + " bots)");
}
}
- else if (data.indexOf("MSG:") != -1) {
+ else if (data.contains("MSG:")) {
// parse message
int colonLoc = data.indexOf(":");
String msgStr = data.substring(colonLoc + 1);
messageTextArea.append(msgStr + "\r\n");
}
-
}
private void login(String data) {
- //System.out.println(data);
if (data.equals("USER:ACK")) {
loggedIn = true;
} else {
@@ -352,14 +353,14 @@ private void doConnect() {
loginUser = dlg.playerField.getText();
loginPwd = new String(dlg.passwordField.getPassword());
- if (hostName == null || portNumber == null || loginUser == null || loginPwd == null ||
+ if (hostName == null || portNumber == null || loginUser == null ||
hostName.equals("") || portNumber.equals("") || loginUser.equals("") || loginPwd.equals("")) {
messageTextArea.append("*** ERROR: need to fill out all fields on options screen before connecting. ***\r\n");
return;
}
try {
- socket = new Socket(hostName, new Integer(portNumber).intValue());
+ socket = new Socket(hostName, new Integer(portNumber));
while (!socket.isConnected()) {
try {
@@ -383,7 +384,6 @@ private void doConnect() {
// send login data
out.write(("USER:"+loginUser+"~"+loginPwd+"\r").getBytes());
-
while (isConnected) {
if (loggedIn && !getInitialData) {
out.write("START\r".getBytes());
@@ -407,9 +407,9 @@ private void doConnect() {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
+ isConnected = false;
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
-
}
} catch (UnknownHostException u) {
u.printStackTrace();
@@ -425,7 +425,6 @@ private void launchOptions() {
dlg.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x, (frmSize.height - dlgSize.height) / 2 + loc.y);
dlg.setModal(true);
dlg.pack();
- dlg.show();
+ dlg.setVisible(true);
}
-}
-
+}
@@ -29,15 +29,12 @@
import java.awt.event.ActionListener;
/**
- * Created by IntelliJ IDEA.
* User: Jay
* Date: Mar 9, 2004
* Time: 3:18:58 PM
- * To change this template use File | Settings | File Templates.
*/
public class OptionsDialog extends JDialog {
private static final long serialVersionUID = -8170448039012790669L;
- MigLayout layout = new MigLayout();
JLabel addressLabel = new JLabel();
protected JTextField addressField = new JTextField();
JLabel portLabel = new JLabel();
@@ -50,6 +47,8 @@
public OptionsDialog(JFrame parent) {
super(parent);
+ setLayout(new BorderLayout());
+
initUI();
}
@@ -64,28 +63,32 @@ private void initUI() {
playerField.setText("");
passwordField.setText("");
- JPanel panel = new JPanel(new MigLayout());
+ JPanel panel = new JPanel(new MigLayout("ins 0, wrap 2", "[right][fill,grow]"));
+ panel.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
panel.setMinimumSize(new Dimension(270, 101));
panel.add(addressLabel);
panel.add(addressField);
panel.add(portLabel);
panel.add(portField);
- panel.add(playerField);
panel.add(playerLabel);
+ panel.add(playerField);
panel.add(passwordLabel);
panel.add(passwordField);
- panel.add(okButton);
+ panel.add(okButton, "skip 1");
okButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
saveOptions();
}
});
+
+ add(panel, BorderLayout.CENTER);
+ pack();
}
private void saveOptions() {
// could persist the field settings to a config file here
- this.hide();
+ setVisible(false);
}
}

0 comments on commit f2f5175

Please sign in to comment.