|
From: <sno...@us...> - 2013-10-23 21:34:13
|
Revision: 110
http://sourceforge.net/p/openrpg/svn/110
Author: snowdog_
Date: 2013-10-23 21:34:11 +0000 (Wed, 23 Oct 2013)
Log Message:
-----------
Added rudimentary network module GUI to client. Client no longer auto-connects to local server. Removed unused MainWindow class.
Modified Paths:
--------------
trunk/src/openrpg2/client/core/ORPGClient.java
trunk/src/openrpg2/common/core/network/NetworkClientModule.java
Added Paths:
-----------
trunk/src/openrpg2/client/core/modules/network/
trunk/src/openrpg2/client/core/modules/network/NetworkClientModuleGUI.java
Removed Paths:
-------------
trunk/src/openrpg2/client/core/MainWindow.java
Deleted: trunk/src/openrpg2/client/core/MainWindow.java
===================================================================
--- trunk/src/openrpg2/client/core/MainWindow.java 2013-09-24 03:18:13 UTC (rev 109)
+++ trunk/src/openrpg2/client/core/MainWindow.java 2013-10-23 21:34:11 UTC (rev 110)
@@ -1,74 +0,0 @@
-/*
- * MainWindow.java
- *
- * Created on July 12, 2005, 11:31 AM
- *
- * To change this template, choose Tools | Options and locate the template under
- * the Source Creation and Management node. Right-click the template and choose
- * Open. You can then make changes to the template in the Source Editor.
- */
-
-package openrpg2.client.core;
-
-import javax.swing.JFrame;
-import java.awt.Toolkit;
-import java.awt.Dimension;
-
-
-
-
-/**
- * Container class for the OpenRPG2 main gui window.
- * @author snowdog
- */
-public class MainWindow {
-
- /**
- * instance of JFrame
- */
- protected JFrame mainframe;
-
- /** Creates a new instance of MainWindow */
- public MainWindow() {
-
- // CREATE THE MAIN GUI FRAME
- mainframe = new JFrame("OpenRPG2 v2.0.1 build 9");
- mainframe.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE);
-
-
-
- Toolkit tk = Toolkit.getDefaultToolkit();
- Dimension screen = tk.getScreenSize();
-
- // Make full size of screen.
- mainframe.setSize((int)screen.getWidth()/2,(int)screen.getHeight()/2);
-
- mainframe.setLocationRelativeTo(null); //center on screen
-
- }
-
-
- /** Shows the main window */
- public void show(){
- mainframe.setVisible(true);
- }
-
- /** Hides the main window */
- public void hide(){
- mainframe.setVisible(false);
- }
-
- /**
- * Allows for the JFrame object to be accessed from outside package.
- * This breaks abstraction rules but may be required by other components
- * to simplify GUI construction and avoid creating a complete interface within this class<br>
- * <I><B>NOTE</B> Should be used with extreme caution and only when absolutely required for application
- * Functionality</I>
- * @return reference to internal main window object
- */
-
- public JFrame getJFrame(){
- return mainframe;
- }
-
-}
Modified: trunk/src/openrpg2/client/core/ORPGClient.java
===================================================================
--- trunk/src/openrpg2/client/core/ORPGClient.java 2013-09-24 03:18:13 UTC (rev 109)
+++ trunk/src/openrpg2/client/core/ORPGClient.java 2013-10-23 21:34:11 UTC (rev 110)
@@ -99,10 +99,12 @@
-
+ /*
+ * MOVING TO CLIENT NETWORK MODULE
if ( ! nc.connect() ){
System.out.println("DEBUG: ORPGClient::execute() connection in NetworkClient failed!!");
}
+ */
}
private void ___DEBUG___SIMULATE_LOADING_TIME(int x){
Added: trunk/src/openrpg2/client/core/modules/network/NetworkClientModuleGUI.java
===================================================================
--- trunk/src/openrpg2/client/core/modules/network/NetworkClientModuleGUI.java (rev 0)
+++ trunk/src/openrpg2/client/core/modules/network/NetworkClientModuleGUI.java 2013-10-23 21:34:11 UTC (rev 110)
@@ -0,0 +1,86 @@
+/*
+ * NetworkClientModuleGUI.java
+ *
+ * Author: Snowdog
+ * Created: October 22, 2013, 11:00 AM
+ *
+ * ====================================================================
+ * Copyright (C) 2005-2013 The OpenRPG Project (www.openrpg.com)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License on www.gnu.org for more details.
+ * ====================================================================
+ */
+package openrpg2.client.core.modules.network;
+
+import java.awt.BorderLayout;
+import java.awt.Dimension;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import javax.swing.BoxLayout;
+import javax.swing.JButton;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JTextField;
+import openrpg2.common.core.event.ORPGEvent;
+import openrpg2.common.core.network.NetworkClientModule;
+import openrpg2.common.core.network.NetworkConnection;
+
+public class NetworkClientModuleGUI extends JPanel implements ActionListener{
+ private JTextField t;
+ private JButton b1;
+ private JButton b2;
+ private JLabel s;
+ private NetworkClientModule ncm;
+ public NetworkClientModuleGUI(NetworkClientModule m){
+ ncm = m;
+ this.setLayout(new BorderLayout());
+ this.setPreferredSize(new Dimension(300,100));
+ JLabel i = new JLabel("Super Simplistic Network Selector");
+ this.add(i,BorderLayout.NORTH);
+ String st = "Status: Not Connected";
+ if( m.isConnected() ){ st = "Status: Connected"; }
+ s = new JLabel(st);
+ this.add(s,BorderLayout.SOUTH);
+ this.t = new JTextField();
+ this.t.setText(NetworkConnection.DEFAULT_HOST);
+ this.add(t,BorderLayout.CENTER);
+
+ JPanel bp = new JPanel();
+ bp.setLayout(new BoxLayout(bp, BoxLayout.Y_AXIS));
+ b1 = new JButton("Connect");
+ b1.addActionListener(this);
+ bp.add(b1);
+ b2 = new JButton("Disonnect");
+ b2.addActionListener(this);
+ bp.add(b2);
+ this.add(bp,BorderLayout.EAST);
+ }
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ if( this.b1 == e.getSource()){ this.connect(); }
+ if( this.b2 == e.getSource()){ this.disconnect(); }
+ }
+
+ public void connect(){
+ s.setText("Status: Connecting...");
+ if( this.ncm.connectTo(this.t.getText()) ){
+ s.setText("Status: Connected");
+ }else{
+ s.setText("Status: Connection Failed!");
+ }
+ }
+ public void disconnect(){
+ s.setText("Status: Disconnecting...");
+ if( this.ncm.disconnect()){ s.setText("Status: Disconnected"); }
+ else{ s.setText("Status: Disconnect Error!"); }
+ }
+}
Modified: trunk/src/openrpg2/common/core/network/NetworkClientModule.java
===================================================================
--- trunk/src/openrpg2/common/core/network/NetworkClientModule.java 2013-09-24 03:18:13 UTC (rev 109)
+++ trunk/src/openrpg2/common/core/network/NetworkClientModule.java 2013-10-23 21:34:11 UTC (rev 110)
@@ -21,10 +21,12 @@
package openrpg2.common.core.network;
+import java.net.InetSocketAddress;
import java.util.Observable;
import java.util.Observer;
import java.util.logging.Level;
import java.util.logging.Logger;
+import openrpg2.client.core.modules.network.NetworkClientModuleGUI;
import openrpg2.common.core.ORPGConstants;
import openrpg2.common.core.ORPGMessage;
import openrpg2.common.core.engine.ModuleCommunicationException;
@@ -59,10 +61,13 @@
private NetworkClient network = null;
private int networkId = 0;
-
+ private NetworkClientModuleGUI guiPanel;
/** Creates a new instance of NetworkClientModule */
public NetworkClientModule(NetworkClient networkReference ) {
network = networkReference;
+ this.guiPanel = new NetworkClientModuleGUI(this);
+ this.setModuleAuthor("Snowdog");
+ this.setModuleShortDescription("Core Network Module");
}
@Override
@@ -71,7 +76,8 @@
modCom.registerMessageType(ORPGConstants.TYPE_NETWORK, this);
this.modCom.registerEventSender(this, NetworkClientModule.EVENT_JOINED_SERVER);
this.modCom.registerEventSender(this, NetworkClientModule.EVENT_DISCONNECT);
-
+
+ this.modCom.registerGUIComponent("Network", this.guiPanel);
}
@Override
@@ -111,7 +117,7 @@
* with a NOOP message.
*/
private void handleHeartbeatMessage(){
- System.out.println("heartbeat requested!");
+ //System.out.println("heartbeat requested!");
ORPGMessage m = new ORPGMessage();
m.setMessageType(ORPGConstants.TYPE_NETWORK);
m.setHeader(NetworkClientModule.HEADER_OP, NetworkClientModule.OP_NOOP);
@@ -141,7 +147,27 @@
this.log.finer("Server connection Id set to "+this.networkId);
System.out.println("id = "+this.networkId);
}
+
+ public boolean isConnected(){
+ if( this.network == null){ return false; }
+ return this.network.isConnected();
+ }
+
+ public boolean connectTo(String ipaddress){
+ return this.network.connect(new InetSocketAddress(ipaddress, NetworkConnection.DEFAULT_PORT));
+ }
+ public boolean disconnect(){
+ ORPGEvent e = new ORPGEvent(this, NetworkClientModule.EVENT_DISCONNECT);
+ this.modCom.generateEvent(e); //notify other modules of DISCONNECT event.
+
+ System.err.println("DISCONNECT FUNCTION INCOMPLETE!");
+ //TODO a) perhaps a pause here to allow modules time to do any tasks due to disconnect.
+ //TODO b) send a message to the server indicating our intent to disconnect (server will tell other clients)
+ this.network.disconnect();
+ return this.network.isConnected();
+
+ }
/**
* Observer callback function for network changes.
* @param o NetworkConnectionAlerter object (ignored)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|