[Icemud-commits] IceMUD/src/mud/server/gui GameGUI.java,1.7,1.8 ServerPanel.java,1.1,1.2
Status: Alpha
Brought to you by:
gamerscloset
From: <jc...@us...> - 2003-12-04 16:32:44
|
Update of /cvsroot/icemud/IceMUD/src/mud/server/gui In directory sc8-pr-cvs1:/tmp/cvs-serv13445/IceMUD/src/mud/server/gui Modified Files: GameGUI.java ServerPanel.java Log Message: Mainly bugfixes. Changed the structure of the GameGUI class, moving all the initialization code into mud.server.Initialise, which seems a bit more intuitive. Index: GameGUI.java =================================================================== RCS file: /cvsroot/icemud/IceMUD/src/mud/server/gui/GameGUI.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** GameGUI.java 30 Oct 2003 22:04:33 -0000 1.7 --- GameGUI.java 4 Dec 2003 16:32:41 -0000 1.8 *************** *** 29,142 **** *********************************************************************************/ package mud.server.gui; - import mud.server.*; import mud.engine.HeartBeat; - import mud.engine.Interpreter; import mud.world.*; - import mud.world.classes.Classes; - import mud.world.races.Race; - import java.util.*; - import java.io.*; import java.awt.event.*; - import javax.swing.*; import java.awt.*; - import java.util.logging.*; ! public class GameGUI extends Thread { ! public GameGUI(String inSql) { ! ! sConnectionString = inSql; ! } - - public void run() { ! //createDisplay(); ! ! try { ! ! /* Setup logs and log directories */ ! Logger lCurrent = Logger.getLogger("error"); ! new File("logs").mkdir(); ! FileHandler fh = new FileHandler("logs/error.log"); ! String sUserLogPath = "logs" + File.separator + "users"; ! new File(sUserLogPath).mkdir(); ! new File("plugins").mkdir(); ! ! fh.setFormatter(new SimpleFormatter()); ! lCurrent.addHandler(fh); ! lCurrent.setLevel(Level.ALL); ! ! lCurrent = Logger.getLogger("warning"); ! fh = new FileHandler("logs/warning.log"); ! fh.setFormatter(new SimpleFormatter()); ! lCurrent.addHandler(fh); ! lCurrent.setLevel(Level.ALL); ! ! System.out.println("Creating world..."); ! new World(); ! World.setConnectionString(sConnectionString); ! ! World.loadSocials(); ! World.loadMessages(); ! World.loadSpells(); ! World.loadSkills(); ! World.loadText(); ! World.loadHelp(); ! ! Classes.init(); ! Race.init(); ! ! World.loadWorld(); ! World.loadZones(); ! World.loadMobs(); ! World.loadItems(); ! World.loadBoards(); ! World.loadSpecials(); ! ! System.out.println("Done creating world..."); ! System.out.println("Filling world..."); ! ! World.processZones(); ! World.loadNotes(); ! World.loadShops(); ! ! System.out.println("Done filling..."); ! ! new Interpreter().loadCommands(); ! ! /* This is temporary to make debugging faster */ ! //display.setDisplayButtonEnabled(true); ! //display.setClickButtonEnabled(true); ! display = new ServerPanel(); ! World.sShutdown = false; ! new HeartBeat().start(); ! (sh = new ServerHandler(display)).start(); ! ! /* End Temporary */ ! ! } catch (IOException ioe) { ! java.util.logging.Logger.getLogger("error").severe(ioe.toString()); ! } ! ! ! } - - private static void createDisplay() { ! JFrame frame; ! display = new ServerPanel(); ! display.clearTable(); ! /* Here we start building the UI */ ! frame = new JFrame("Server"); ! frame.setContentPane(display); ! frame.pack(); ! frame.setVisible(true); ! frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent we) { --- 29,67 ---- *********************************************************************************/ package mud.server.gui; import mud.server.*; import mud.engine.HeartBeat; import mud.world.*; import java.util.*; import java.awt.event.*; import java.awt.*; ! /** ! * ! * @author jcb62 ! * Created by on Dec 4, 2003: ! * ! * A class to deal with creating, displaying and interfacing with ! * the server's GUI ! */ + public class GameGUI extends Thread { ! public GameGUI() { ! super(); } ! public void run() { ! ServerPanel display = createDisplay(); ! World.sShutdown = false; ! new HeartBeat().start(); ! (sh = new ServerHandler(display)).start(); } ! /* Displays two JFrames, one with results, one with server status */ ! private static ServerPanel createDisplay() { ! System.out.println("In create display"); ! final ServerPanel sp = new ServerPanel(); ! sp.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent we) { *************** *** 146,150 **** sh.kill(); Window window = (Window) we.getSource(); ! window.hide(); System.exit(0); } --- 71,75 ---- sh.kill(); Window window = (Window) we.getSource(); ! window.dispose(); System.exit(0); } *************** *** 152,176 **** /* Now we listen for events on the UI */ ! display.addRunListener(new ActionListener() { public void actionPerformed(ActionEvent e) { ! if (display.reverseRun().equals("D")) { sh.kill(); } else { World.sShutdown = false; new HeartBeat().start(); ! (sh = new ServerHandler(display)).start(); } ! display.clearTable(); } }); /* Open a window to the server */ ! display.addConnectListener(new ActionListener() { public void actionPerformed(ActionEvent e) { } }); ! ! } --- 77,101 ---- /* Now we listen for events on the UI */ ! sp.addRunListener(new ActionListener() { public void actionPerformed(ActionEvent e) { ! if (sh.isRunning()) { sh.kill(); } else { World.sShutdown = false; new HeartBeat().start(); ! (sh = new ServerHandler(sp)).start(); } ! sp.clearTable(); } }); /* Open a window to the server */ ! sp.addConnectListener(new ActionListener() { public void actionPerformed(ActionEvent e) { } }); ! return sp; ! } *************** *** 187,196 **** private static ServerHandler sh = null; ! protected static ServerPanel display; ! protected static Hashtable handoff = new Hashtable(); protected static Vector threads = new Vector(); - protected static Vector sockets = new Vector(); - - private static String sConnectionString; } --- 112,117 ---- private static ServerHandler sh = null; ! private static ServerPanel sp; protected static Vector threads = new Vector(); } Index: ServerPanel.java =================================================================== RCS file: /cvsroot/icemud/IceMUD/src/mud/server/gui/ServerPanel.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ServerPanel.java 14 Oct 2003 14:23:12 -0000 1.1 --- ServerPanel.java 4 Dec 2003 16:32:41 -0000 1.2 *************** *** 40,102 **** public ServerPanel() { ! serverPane = new JPanel(); GridBagLayout gridbag = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); ! c.fill = GridBagConstraints.HORIZONTAL; ! c.weightx = 1.0; ! serverPane.setLayout(gridbag); ! ! /* Port to listen to */ ! includeLabel("Port:"); port = new TextField("23", 4); serverPane.add(port); /* Start/Stop button */ ! includeButton(); ! ! conButton = new Button("Connect"); ! conButton.setEnabled(false); ! conButton.setBackground(Color.lightGray); ! conButton.setForeground(Color.black); ! conButton.setFont(new Font("ARIAL", Font.BOLD, 14)); ! serverPane.add(conButton); ! /* Results Table */ ! resultPane = new JPanel(); ! addTable(); ! ! /* Put it all together */ ! gridbag = new GridBagLayout(); ! c = new GridBagConstraints(); - c.fill = GridBagConstraints.HORIZONTAL; - - setLayout(gridbag); - c.weighty = 0.0; c.gridy = 0; ! ! gridbag.setConstraints(serverPane, c); ! add(serverPane); ! c.fill = GridBagConstraints.BOTH; c.weighty = 1.0; c.weightx = 1.0; c.gridy = 1; ! gridbag.setConstraints(resultPane, c); ! add(resultPane); ! ! setBorder(BorderFactory.createEmptyBorder(10,10,10,10)); ! } ! public void addTable(){ ! ! myModel = new DefaultTableModel(); ! String rows[][] = {{" ", " ", "", "", "", "", "", ""}}; String columns[] = {"#", "Status", --- 40,95 ---- public ServerPanel() { ! JFrame serverJF = new JFrame("Server Status"); ! JPanel serverPane = new JPanel(); ! serverJF.setContentPane(serverPane); GridBagLayout gridbag = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); ! c.fill = GridBagConstraints.HORIZONTAL; // arrange data ! c.weightx = 1.0; // left to right ! /* Port to listen to */ ! addLabel(serverPane, "Port:"); port = new TextField("23", 4); serverPane.add(port); /* Start/Stop button */ ! dynButton = addButton(serverPane, startLabel, "test_start"); ! /* Connect button */ ! conButton = addButton(serverPane, "Connect", "test_connect"); ! ! serverPane.setBorder(BorderFactory.createEmptyBorder(10,10,10,10)); ! serverPane.setLayout(gridbag); ! gridbag.setConstraints(serverPane, c); ! serverJF.pack(); ! serverJF.show(); ! ! /* ************************************************************/ /* Results Table */ ! JFrame resultJF = new JFrame("Results"); ! JPanel resultPane = new JPanel(); ! resultJF.setContentPane(resultPane); ! addTable(resultPane); c.gridy = 0; ! c.fill = GridBagConstraints.BOTH; c.weighty = 1.0; c.weightx = 1.0; c.gridy = 1; ! ! resultPane.setLayout(gridbag); gridbag.setConstraints(resultPane, c); ! resultJF.pack(); ! resultJF.show(); ! } ! public void addTable(Container cp){ ! myModel = new DefaultTableModel(); ! //String rows[][] = {{"", "", "", "", "", "", "", ""}}; ! String rows[][] = {}; String columns[] = {"#", "Status", *************** *** 142,152 **** c.weighty = 1.0; ! resultPane.setLayout(gridbag); gridbag.setConstraints(scrollPane, c); ! resultPane.add(scrollPane); } /* Return the # of rows we have so far */ ! public int getRowCount(){ return (myModel.getRowCount() - 1); } /* Change the value at a specified location in the table */ --- 135,147 ---- c.weighty = 1.0; ! cp.setLayout(gridbag); gridbag.setConstraints(scrollPane, c); ! cp.add(scrollPane); } /* Return the # of rows we have so far */ ! public int getRowCount(){ ! return (myModel.getRowCount() - 1); ! } /* Change the value at a specified location in the table */ *************** *** 162,203 **** myModel.removeRow(0); } - - /* (Dis/En)able the search features of the UI */ - public String reverseRun(){ - - if ( clickButton.getLabel().equals( connectLabel ) ) { - clickButton.setLabel(disconnectLabel); - return "C"; - } else { - clickButton.setLabel(connectLabel); - return "D"; - } - } /* Add a blank row to the table */ public int addRow(){ ! String strRow = Integer.toString(myModel.getRowCount(), 10); ! String newRow[] = {strRow, " ", "", "", "", "", "", ""}; myModel.addRow(newRow); return (myModel.getRowCount() - 1); } ! /* Start Button */ ! public void includeButton() ! { ! clickButton = new Button(connectLabel); ! clickButton.setEnabled(false); ! clickButton.setActionCommand("test"); ! clickButton.setBackground(Color.lightGray); ! clickButton.setForeground(Color.black); ! clickButton.setFont(new Font("ARIAL", Font.BOLD, 14)); ! serverPane.add(clickButton); } /* Listener for the button */ public void addRunListener(ActionListener al){ ! clickButton.addActionListener(al); } --- 157,185 ---- myModel.removeRow(0); } /* Add a blank row to the table */ public int addRow(){ ! String strRow = Integer.toString(myModel.getRowCount()); ! String newRow[] = {strRow, "", "", "", "", "", "", ""}; myModel.addRow(newRow); return (myModel.getRowCount() - 1); } ! /* add Button to supplied container */ ! public Button addButton(Container cp, String text, String command) { ! Button newButton = new Button(text); ! newButton.setActionCommand(command); ! newButton.setBackground(Color.lightGray); ! newButton.setForeground(Color.black); ! newButton.setFont(new Font("ARIAL", Font.BOLD, 10)); ! cp.add(newButton); ! return newButton; } /* Listener for the button */ public void addRunListener(ActionListener al){ ! dynButton.addActionListener(al); } *************** *** 205,214 **** conButton.addActionListener(al); } /* Add a label to the serverPane */ ! public void includeLabel(String strLabel){ JLabel newLabel = new JLabel(strLabel); newLabel.setForeground(Color.black); ! serverPane.add(newLabel); } --- 187,198 ---- conButton.addActionListener(al); } + + public void addWindowListener(WindowAdapter wa){}; /* Add a label to the serverPane */ ! public void addLabel(Container cp, String strLabel){ JLabel newLabel = new JLabel(strLabel); newLabel.setForeground(Color.black); ! cp.add(newLabel); } *************** *** 216,225 **** /* Return the # of levels to process */ public static int getLevels(){ ! return stringToInt(levels.getText()); } /* Return the Port to listen on */ public static int getPort(){ ! int iport = 0; try { --- 200,209 ---- /* Return the # of levels to process */ public static int getLevels(){ ! return Integer.parseInt(levels.getText()); } /* Return the Port to listen on */ public static int getPort(){ ! int iport=2223; try { *************** *** 234,242 **** } - /* Convert an String to an Integer */ - public static int stringToInt(String value) { - return Integer.parseInt(value); - } - /* Center the UI */ public void center() --- 218,221 ---- *************** *** 247,265 **** } ! public static void setDisplayButtonEnabled(boolean value) { conButton.setEnabled(value); } ! public static void setClickButtonEnabled(boolean value) { clickButton.setEnabled(value); } - public JPanel serverPane; - public JPanel resultPane; public static TextField levels; public static TextField port; private static DefaultTableModel myModel; ! public static Button clickButton; ! public static Button conButton; // dynamic button labels: ! public static String connectLabel = " Start Server "; ! public static String disconnectLabel = " Stop Server "; } --- 226,242 ---- } ! public void setDisplayButtonEnabled(boolean value) { conButton.setEnabled(value); } ! public void setClickButtonEnabled(boolean value) { dynButton.setEnabled(value); } public static TextField levels; public static TextField port; private static DefaultTableModel myModel; ! public Button dynButton; ! public Button conButton; // dynamic button labels: ! final public String startLabel = " Start Server "; ! final public String stopLabel = " Stop Server "; } |