mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 04:52:07 -08:00
initial commit - only table pane chat is working atm
This commit is contained in:
parent
f9bad74ca7
commit
e45345d87a
84 changed files with 5370 additions and 3992 deletions
|
|
@ -30,5 +30,10 @@
|
|||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>mage-network</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ package mage.server.console;
|
|||
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
|
@ -44,13 +45,17 @@ import javax.swing.Box;
|
|||
import javax.swing.JOptionPane;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.UIManager;
|
||||
import mage.interfaces.MageClient;
|
||||
import mage.interfaces.callback.ClientCallback;
|
||||
import mage.interfaces.ServerState;
|
||||
//import mage.interfaces.MageClient;
|
||||
//import mage.interfaces.callback.ClientCallback;
|
||||
import mage.remote.Connection;
|
||||
import mage.remote.Session;
|
||||
import mage.remote.SessionImpl;
|
||||
//import mage.remote.Session;
|
||||
//import mage.remote.SessionImpl;
|
||||
import mage.utils.MageVersion;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.mage.network.Client;
|
||||
import org.mage.network.interfaces.MageClient;
|
||||
import org.mage.network.model.MessageType;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -60,7 +65,7 @@ public class ConsoleFrame extends javax.swing.JFrame implements MageClient {
|
|||
|
||||
private static final Logger logger = Logger.getLogger(ConsoleFrame.class);
|
||||
|
||||
private static Session session;
|
||||
private static Client client;
|
||||
private ConnectDialog connectDialog;
|
||||
private static final Preferences prefs = Preferences.userNodeForPackage(ConsoleFrame.class);
|
||||
private static final MageVersion version = new MageVersion(MageVersion.MAGE_VERSION_MAJOR, MageVersion.MAGE_VERSION_MINOR, MageVersion.MAGE_VERSION_PATCH, MageVersion.MAGE_VERSION_MINOR_PATCH, MageVersion.MAGE_VERSION_INFO);
|
||||
|
|
@ -69,15 +74,14 @@ public class ConsoleFrame extends javax.swing.JFrame implements MageClient {
|
|||
/**
|
||||
* @return the session
|
||||
*/
|
||||
public static Session getSession() {
|
||||
return session;
|
||||
public static Client getClient() {
|
||||
return client;
|
||||
}
|
||||
|
||||
public static Preferences getPreferences() {
|
||||
return prefs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MageVersion getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
|
@ -95,22 +99,22 @@ public class ConsoleFrame extends javax.swing.JFrame implements MageClient {
|
|||
initComponents();
|
||||
try {
|
||||
UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
|
||||
session = new SessionImpl(this);
|
||||
client = new Client();
|
||||
connectDialog = new ConnectDialog();
|
||||
} catch (Exception ex) {
|
||||
logger.fatal("", ex);
|
||||
}
|
||||
|
||||
pingTaskExecutor.scheduleAtFixedRate(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
session.ping();
|
||||
}
|
||||
}, 60, 60, TimeUnit.SECONDS);
|
||||
// pingTaskExecutor.scheduleAtFixedRate(new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
// session.ping();
|
||||
// }
|
||||
// }, 60, 60, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
public boolean connect(Connection connection) {
|
||||
if (session.connect(connection)) {
|
||||
if (client.connect(connection.getUsername(), connection.getHost(), connection.getPort(), version, this)) {
|
||||
this.consolePanel1.start();
|
||||
return true;
|
||||
}
|
||||
|
|
@ -200,10 +204,10 @@ public class ConsoleFrame extends javax.swing.JFrame implements MageClient {
|
|||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
private void btnConnectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnConnectActionPerformed
|
||||
if (session.isConnected()) {
|
||||
if (client.isConnected()) {
|
||||
if (JOptionPane.showConfirmDialog(this, "Are you sure you want to disconnect?", "Confirm disconnect", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
|
||||
this.consolePanel1.stop();
|
||||
session.disconnect(false);
|
||||
client.disconnect();
|
||||
}
|
||||
} else {
|
||||
connectDialog.showDialog(this);
|
||||
|
|
@ -213,7 +217,7 @@ public class ConsoleFrame extends javax.swing.JFrame implements MageClient {
|
|||
private void btnSendMessageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSendMessageActionPerformed
|
||||
String message = JOptionPane.showInputDialog(null, "Type message to send", "Broadcast message", JOptionPane.INFORMATION_MESSAGE);
|
||||
if (message != null) {
|
||||
session.sendBroadcastMessage(message);
|
||||
client.sendBroadcastMessage(message);
|
||||
}
|
||||
}//GEN-LAST:event_btnSendMessageActionPerformed
|
||||
|
||||
|
|
@ -262,7 +266,6 @@ public class ConsoleFrame extends javax.swing.JFrame implements MageClient {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnected(boolean errorCall) {
|
||||
if (SwingUtilities.isEventDispatchThread()) {
|
||||
consolePanel1.stop();
|
||||
|
|
@ -281,7 +284,6 @@ public class ConsoleFrame extends javax.swing.JFrame implements MageClient {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showMessage(final String message) {
|
||||
if (SwingUtilities.isEventDispatchThread()) {
|
||||
JOptionPane.showMessageDialog(this, message);
|
||||
|
|
@ -296,7 +298,6 @@ public class ConsoleFrame extends javax.swing.JFrame implements MageClient {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showError(final String message) {
|
||||
if (SwingUtilities.isEventDispatchThread()) {
|
||||
JOptionPane.showMessageDialog(this, message, "Error", JOptionPane.ERROR_MESSAGE);
|
||||
|
|
@ -311,16 +312,16 @@ public class ConsoleFrame extends javax.swing.JFrame implements MageClient {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processCallback(ClientCallback callback) {
|
||||
}
|
||||
// @Override
|
||||
// public void processCallback(ClientCallback callback) {
|
||||
// }
|
||||
|
||||
public void exitApp() {
|
||||
if (session.isConnected()) {
|
||||
if (client.isConnected()) {
|
||||
if (JOptionPane.showConfirmDialog(this, "You are currently connected. Are you sure you want to disconnect?", "Confirm disconnect", JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION) {
|
||||
return;
|
||||
}
|
||||
session.disconnect(false);
|
||||
client.disconnect();
|
||||
} else {
|
||||
if (JOptionPane.showConfirmDialog(this, "Are you sure you want to exit?", "Confirm exit", JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION) {
|
||||
return;
|
||||
|
|
@ -329,4 +330,29 @@ public class ConsoleFrame extends javax.swing.JFrame implements MageClient {
|
|||
dispose();
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void inform(String message, MessageType type) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receiveChatMessage(UUID chatId, String user, String message) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receiveBroadcastMessage(String message) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setServerState(ServerState state) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerState getServerState() {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,10 +45,11 @@ import static javax.swing.JTable.AUTO_RESIZE_OFF;
|
|||
import javax.swing.SwingWorker;
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
import javax.swing.table.TableRowSorter;
|
||||
import mage.remote.Session;
|
||||
//import mage.remote.Session;
|
||||
import mage.view.TableView;
|
||||
import mage.view.UserView;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.mage.network.Client;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -93,8 +94,8 @@ public class ConsolePanel extends javax.swing.JPanel {
|
|||
|
||||
|
||||
public void start() {
|
||||
updateUsersTask = new UpdateUsersTask(ConsoleFrame.getSession(), this);
|
||||
updateTablesTask = new UpdateTablesTask(ConsoleFrame.getSession(), ConsoleFrame.getSession().getMainRoomId(), this);
|
||||
updateUsersTask = new UpdateUsersTask(ConsoleFrame.getClient(), this);
|
||||
updateTablesTask = new UpdateTablesTask(ConsoleFrame.getClient(), ConsoleFrame.getClient().getMainRoomId(), this);
|
||||
updateUsersTask.execute();
|
||||
updateTablesTask.execute();
|
||||
}
|
||||
|
|
@ -268,17 +269,17 @@ public class ConsolePanel extends javax.swing.JPanel {
|
|||
|
||||
private void btnDisconnectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDisconnectActionPerformed
|
||||
int row = this.tblUsers.convertRowIndexToModel(tblUsers.getSelectedRow());
|
||||
ConsoleFrame.getSession().disconnectUser((String)tableUserModel.getValueAt(row, 3));
|
||||
ConsoleFrame.getClient().disconnectUser((String)tableUserModel.getValueAt(row, 3));
|
||||
}//GEN-LAST:event_btnDisconnectActionPerformed
|
||||
|
||||
private void btnRemoveTableActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoveTableActionPerformed
|
||||
int row = this.tblTables.convertRowIndexToModel(tblTables.getSelectedRow());
|
||||
ConsoleFrame.getSession().removeTable((UUID)tableTableModel.getValueAt(row, 7));
|
||||
ConsoleFrame.getClient().removeTable((UUID)tableTableModel.getValueAt(row, 7));
|
||||
}//GEN-LAST:event_btnRemoveTableActionPerformed
|
||||
|
||||
private void btnEndSessionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEndSessionActionPerformed
|
||||
int row = this.tblUsers.convertRowIndexToModel(tblUsers.getSelectedRow());
|
||||
ConsoleFrame.getSession().endUserSession((String) tableUserModel.getValueAt(row, 3));
|
||||
ConsoleFrame.getClient().endUserSession((String) tableUserModel.getValueAt(row, 3));
|
||||
}//GEN-LAST:event_btnEndSessionActionPerformed
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
|
|
@ -433,21 +434,21 @@ class TableTableModel extends AbstractTableModel {
|
|||
|
||||
class UpdateUsersTask extends SwingWorker<Void, List<UserView>> {
|
||||
|
||||
private final Session session;
|
||||
private final Client client;
|
||||
private final ConsolePanel panel;
|
||||
private List<UserView> previousUsers;
|
||||
|
||||
private static final Logger logger = Logger.getLogger(UpdateUsersTask.class);
|
||||
|
||||
UpdateUsersTask(Session session, ConsolePanel panel) {
|
||||
this.session = session;
|
||||
UpdateUsersTask(Client client, ConsolePanel panel) {
|
||||
this.client = client;
|
||||
this.panel = panel;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground() throws Exception {
|
||||
while (!isCancelled()) {
|
||||
List<UserView> users = session.getUsers();
|
||||
List<UserView> users = client.getUsers();
|
||||
|
||||
if (previousUsers == null || checkUserListChanged(users)) {
|
||||
logger.debug("Need to update the user list");
|
||||
|
|
@ -503,14 +504,14 @@ class UpdateUsersTask extends SwingWorker<Void, List<UserView>> {
|
|||
|
||||
class UpdateTablesTask extends SwingWorker<Void, Collection<TableView>> {
|
||||
|
||||
private final Session session;
|
||||
private final Client client;
|
||||
private final UUID roomId;
|
||||
private final ConsolePanel panel;
|
||||
|
||||
private static final Logger logger = Logger.getLogger(UpdateTablesTask.class);
|
||||
|
||||
UpdateTablesTask(Session session, UUID roomId, ConsolePanel panel) {
|
||||
this.session = session;
|
||||
UpdateTablesTask(Client client, UUID roomId, ConsolePanel panel) {
|
||||
this.client = client;
|
||||
this.roomId = roomId;
|
||||
this.panel = panel;
|
||||
}
|
||||
|
|
@ -518,7 +519,7 @@ class UpdateTablesTask extends SwingWorker<Void, Collection<TableView>> {
|
|||
@Override
|
||||
protected Void doInBackground() throws Exception {
|
||||
while (!isCancelled()) {
|
||||
this.publish(session.getTables(roomId));
|
||||
this.publish(client.getTables(roomId));
|
||||
Thread.sleep(3000);
|
||||
}
|
||||
return null;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue