[refactoring][minor] Replaced all tabs with four spaces.

This commit is contained in:
North 2012-06-19 23:50:20 +03:00
parent e646e4768d
commit 239a4fb100
2891 changed files with 79411 additions and 79411 deletions

View file

@ -30,5 +30,5 @@
<artifactId>junit</artifactId>
<version>4.8.2</version>
</dependency>
</dependencies>
</dependencies>
</project>

View file

@ -55,65 +55,65 @@ import java.util.concurrent.ExecutionException;
*/
public class ConnectDialog extends JDialog {
private final static Logger logger = Logger.getLogger(ConnectDialog.class);
private ConsoleFrame console;
private Connection connection;
private ConnectTask task;
private final static Logger logger = Logger.getLogger(ConnectDialog.class);
private ConsoleFrame console;
private Connection connection;
private ConnectTask task;
/** Creates new form ConnectDialog */
public ConnectDialog() {
initComponents();
cbProxyType.setModel(new DefaultComboBoxModel(Connection.ProxyType.values()));
cbProxyType.setModel(new DefaultComboBoxModel(Connection.ProxyType.values()));
}
public void showDialog(ConsoleFrame console) {
this.console = console;
this.txtServer.setText(ConsoleFrame.getPreferences().get("serverAddress", "localhost"));
this.txtPort.setText(ConsoleFrame.getPreferences().get("serverPort", Integer.toString(17171)));
this.chkAutoConnect.setSelected(Boolean.parseBoolean(ConsoleFrame.getPreferences().get("autoConnect", "false")));
this.txtProxyServer.setText(ConsoleFrame.getPreferences().get("proxyAddress", "localhost"));
this.txtProxyPort.setText(ConsoleFrame.getPreferences().get("proxyPort", Integer.toString(17171)));
this.cbProxyType.setSelectedItem(Connection.ProxyType.valueOf(ConsoleFrame.getPreferences().get("proxyType", "NONE").toUpperCase()));
this.txtProxyUserName.setText(ConsoleFrame.getPreferences().get("proxyUsername", ""));
this.txtPasswordField.setText(ConsoleFrame.getPreferences().get("proxyPassword", ""));
this.showProxySettings();
this.setModal(true);
this.setLocation(50, 50);
this.setVisible(true);
}
public void showDialog(ConsoleFrame console) {
this.console = console;
this.txtServer.setText(ConsoleFrame.getPreferences().get("serverAddress", "localhost"));
this.txtPort.setText(ConsoleFrame.getPreferences().get("serverPort", Integer.toString(17171)));
this.chkAutoConnect.setSelected(Boolean.parseBoolean(ConsoleFrame.getPreferences().get("autoConnect", "false")));
this.txtProxyServer.setText(ConsoleFrame.getPreferences().get("proxyAddress", "localhost"));
this.txtProxyPort.setText(ConsoleFrame.getPreferences().get("proxyPort", Integer.toString(17171)));
this.cbProxyType.setSelectedItem(Connection.ProxyType.valueOf(ConsoleFrame.getPreferences().get("proxyType", "NONE").toUpperCase()));
this.txtProxyUserName.setText(ConsoleFrame.getPreferences().get("proxyUsername", ""));
this.txtPasswordField.setText(ConsoleFrame.getPreferences().get("proxyPassword", ""));
this.showProxySettings();
this.setModal(true);
this.setLocation(50, 50);
this.setVisible(true);
}
private void showProxySettings() {
if (cbProxyType.getSelectedItem() == Connection.ProxyType.SOCKS) {
this.pnlProxy.setVisible(true);
this.pnlProxyAuth.setVisible(false);
this.pnlProxySettings.setVisible(true);
}
else if (cbProxyType.getSelectedItem() == Connection.ProxyType.HTTP) {
this.pnlProxy.setVisible(true);
this.pnlProxyAuth.setVisible(true);
this.pnlProxySettings.setVisible(true);
}
else if (cbProxyType.getSelectedItem() == Connection.ProxyType.NONE) {
this.pnlProxy.setVisible(false);
this.pnlProxyAuth.setVisible(false);
this.pnlProxySettings.setVisible(false);
}
this.pack();
this.repaint();
}
private void showProxySettings() {
if (cbProxyType.getSelectedItem() == Connection.ProxyType.SOCKS) {
this.pnlProxy.setVisible(true);
this.pnlProxyAuth.setVisible(false);
this.pnlProxySettings.setVisible(true);
}
else if (cbProxyType.getSelectedItem() == Connection.ProxyType.HTTP) {
this.pnlProxy.setVisible(true);
this.pnlProxyAuth.setVisible(true);
this.pnlProxySettings.setVisible(true);
}
else if (cbProxyType.getSelectedItem() == Connection.ProxyType.NONE) {
this.pnlProxy.setVisible(false);
this.pnlProxyAuth.setVisible(false);
this.pnlProxySettings.setVisible(false);
}
this.pack();
this.repaint();
}
private void saveSettings() {
ConsoleFrame.getPreferences().put("serverAddress", txtServer.getText());
ConsoleFrame.getPreferences().put("serverPort", txtPort.getText());
ConsoleFrame.getPreferences().put("autoConnect", Boolean.toString(chkAutoConnect.isSelected()));
ConsoleFrame.getPreferences().put("proxyAddress", txtProxyServer.getText());
ConsoleFrame.getPreferences().put("proxyPort", txtProxyPort.getText());
ConsoleFrame.getPreferences().put("proxyType", cbProxyType.getSelectedItem().toString());
ConsoleFrame.getPreferences().put("proxyUsername", txtProxyUserName.getText());
char[] input = txtPasswordField.getPassword();
ConsoleFrame.getPreferences().put("proxyPassword", new String(input));
Arrays.fill(input, '0');
}
private void saveSettings() {
ConsoleFrame.getPreferences().put("serverAddress", txtServer.getText());
ConsoleFrame.getPreferences().put("serverPort", txtPort.getText());
ConsoleFrame.getPreferences().put("autoConnect", Boolean.toString(chkAutoConnect.isSelected()));
ConsoleFrame.getPreferences().put("proxyAddress", txtProxyServer.getText());
ConsoleFrame.getPreferences().put("proxyPort", txtProxyPort.getText());
ConsoleFrame.getPreferences().put("proxyType", cbProxyType.getSelectedItem().toString());
ConsoleFrame.getPreferences().put("proxyUsername", txtProxyUserName.getText());
char[] input = txtPasswordField.getPassword();
ConsoleFrame.getPreferences().put("proxyPassword", new String(input));
Arrays.fill(input, '0');
}
/** This method is called from within the constructor to
* initialize the form.
@ -378,151 +378,151 @@ public class ConnectDialog extends JDialog {
pack();
}// </editor-fold>//GEN-END:initComponents
private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
ConsoleFrame.getPreferences().put("autoConnect", Boolean.toString(chkAutoConnect.isSelected()));
if (task != null && !task.isDone())
task.cancel(true);
else
this.setVisible(false);
}//GEN-LAST:event_btnCancelActionPerformed
private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
ConsoleFrame.getPreferences().put("autoConnect", Boolean.toString(chkAutoConnect.isSelected()));
if (task != null && !task.isDone())
task.cancel(true);
else
this.setVisible(false);
}//GEN-LAST:event_btnCancelActionPerformed
private void btnConnectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnConnectActionPerformed
if (txtPassword.getPassword().length == 0) {
JOptionPane.showMessageDialog(rootPane, "Please provide a password");
return;
}
if (txtServer.getText().trim().isEmpty()) {
JOptionPane.showMessageDialog(rootPane, "Please provide a server address");
return;
}
if (txtPort.getText().trim().isEmpty()) {
JOptionPane.showMessageDialog(rootPane, "Please provide a port number");
return;
}
if (Integer.valueOf(txtPort.getText()) < 1 || Integer.valueOf(txtPort.getText()) > 65535 ) {
JOptionPane.showMessageDialog(rootPane, "Invalid port number");
txtPort.setText(ConsoleFrame.getPreferences().get("serverPort", Integer.toString(17171)));
return;
}
private void btnConnectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnConnectActionPerformed
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
connection = new Connection();
connection.setHost(this.txtServer.getText());
connection.setPort(Integer.valueOf(this.txtPort.getText()));
connection.setPassword(new String(txtPassword.getPassword()));
if (txtPassword.getPassword().length == 0) {
JOptionPane.showMessageDialog(rootPane, "Please provide a password");
return;
}
if (txtServer.getText().trim().isEmpty()) {
JOptionPane.showMessageDialog(rootPane, "Please provide a server address");
return;
}
if (txtPort.getText().trim().isEmpty()) {
JOptionPane.showMessageDialog(rootPane, "Please provide a port number");
return;
}
if (Integer.valueOf(txtPort.getText()) < 1 || Integer.valueOf(txtPort.getText()) > 65535 ) {
JOptionPane.showMessageDialog(rootPane, "Invalid port number");
txtPort.setText(ConsoleFrame.getPreferences().get("serverPort", Integer.toString(17171)));
return;
}
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
connection = new Connection();
connection.setHost(this.txtServer.getText());
connection.setPort(Integer.valueOf(this.txtPort.getText()));
connection.setPassword(new String(txtPassword.getPassword()));
connection.setProxyType((ProxyType) this.cbProxyType.getSelectedItem());
if (!this.cbProxyType.getSelectedItem().equals(ProxyType.NONE)) {
connection.setProxyHost(this.txtProxyServer.getText());
connection.setProxyPort(Integer.valueOf(this.txtProxyPort.getText()));
connection.setProxyUsername(this.txtProxyUserName.getText());
connection.setProxyPassword(new String(this.txtPasswordField.getPassword()));
connection.setProxyHost(this.txtProxyServer.getText());
connection.setProxyPort(Integer.valueOf(this.txtProxyPort.getText()));
connection.setProxyUsername(this.txtProxyUserName.getText());
connection.setProxyPassword(new String(this.txtPasswordField.getPassword()));
}
logger.debug("connecting: " + connection.getProxyType() + " " + connection.getProxyHost() + " " + connection.getProxyPort());
task = new ConnectTask();
task.execute();
logger.debug("connecting: " + connection.getProxyType() + " " + connection.getProxyHost() + " " + connection.getProxyPort());
task = new ConnectTask();
task.execute();
}//GEN-LAST:event_btnConnectActionPerformed
}//GEN-LAST:event_btnConnectActionPerformed
private class ConnectTask extends SwingWorker<Boolean, Void> {
private class ConnectTask extends SwingWorker<Boolean, Void> {
private boolean result = false;
private boolean result = false;
@Override
protected Boolean doInBackground() throws Exception {
lblStatus.setText("Connecting...");
btnConnect.setEnabled(false);
result = console.connect(connection);
return result;
}
@Override
protected Boolean doInBackground() throws Exception {
lblStatus.setText("Connecting...");
btnConnect.setEnabled(false);
result = console.connect(connection);
return result;
}
@Override
protected void done() {
try {
get();
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
btnConnect.setEnabled(true);
if (result) {
lblStatus.setText("");
connected();
}
else {
lblStatus.setText("Could not connect");
}
} catch (InterruptedException ex) {
logger.fatal("Update Players Task error", ex);
} catch (ExecutionException ex) {
logger.fatal("Update Players Task error", ex);
} catch (CancellationException ex) {}
}
}
@Override
protected void done() {
try {
get();
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
btnConnect.setEnabled(true);
if (result) {
lblStatus.setText("");
connected();
}
else {
lblStatus.setText("Could not connect");
}
} catch (InterruptedException ex) {
logger.fatal("Update Players Task error", ex);
} catch (ExecutionException ex) {
logger.fatal("Update Players Task error", ex);
} catch (CancellationException ex) {}
}
}
private void connected() {
this.saveSettings();
this.setVisible(false);
}
private void connected() {
this.saveSettings();
this.setVisible(false);
}
private void keyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_keyTyped
char c = evt.getKeyChar();
if (!Character.isDigit(c))
evt.consume();
}//GEN-LAST:event_keyTyped
private void keyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_keyTyped
char c = evt.getKeyChar();
if (!Character.isDigit(c))
evt.consume();
}//GEN-LAST:event_keyTyped
private void chkAutoConnectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chkAutoConnectActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_chkAutoConnectActionPerformed
private void chkAutoConnectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chkAutoConnectActionPerformed
private void txtProxyPortkeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtProxyPortkeyTyped
// TODO add your handling code here:
}//GEN-LAST:event_txtProxyPortkeyTyped
// TODO add your handling code here:
}//GEN-LAST:event_chkAutoConnectActionPerformed
private void txtProxyPortkeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtProxyPortkeyTyped
// TODO add your handling code here:
}//GEN-LAST:event_txtProxyPortkeyTyped
private void findPublicServerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
BufferedReader in = null;
try {
URL serverListURL = new URL("http://download.magefree.com/files/server-list.txt");
in = new BufferedReader(new InputStreamReader(serverListURL.openStream()));
List<String> servers = new ArrayList<String>();
String inputLine;
while ((inputLine = in.readLine()) != null) {
System.out.println("Found server: "+inputLine);
servers.add(inputLine);
}
if (servers.size() == 0) {
JOptionPane.showMessageDialog(null, "Couldn't find any server.");
return;
}
BufferedReader in = null;
try {
URL serverListURL = new URL("http://download.magefree.com/files/server-list.txt");
in = new BufferedReader(new InputStreamReader(serverListURL.openStream()));
String selectedServer = (String) JOptionPane.showInputDialog(null,
"Choose MAGE Public Server:", "Input",
JOptionPane.INFORMATION_MESSAGE, null, servers.toArray(),
servers.get(0));
if (selectedServer != null) {
String[] params = selectedServer.split(":");
if (params.length == 3) {
this.txtServer.setText(params[1]);
this.txtPort.setText(params[2]);
} else {
JOptionPane.showMessageDialog(null, "Wrong server data format.");
}
}
List<String> servers = new ArrayList<String>();
String inputLine;
while ((inputLine = in.readLine()) != null) {
System.out.println("Found server: "+inputLine);
servers.add(inputLine);
}
in.close();
} catch(Exception ex) {
logger.error(ex,ex);
} finally {
if (in != null) try { in.close(); } catch (Exception e) {}
}
if (servers.size() == 0) {
JOptionPane.showMessageDialog(null, "Couldn't find any server.");
return;
}
String selectedServer = (String) JOptionPane.showInputDialog(null,
"Choose MAGE Public Server:", "Input",
JOptionPane.INFORMATION_MESSAGE, null, servers.toArray(),
servers.get(0));
if (selectedServer != null) {
String[] params = selectedServer.split(":");
if (params.length == 3) {
this.txtServer.setText(params[1]);
this.txtPort.setText(params[2]);
} else {
JOptionPane.showMessageDialog(null, "Wrong server data format.");
}
}
in.close();
} catch(Exception ex) {
logger.error(ex,ex);
} finally {
if (in != null) try { in.close(); } catch (Exception e) {}
}
}//GEN-LAST:event_jButton1ActionPerformed
private void cbProxyTypeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbProxyTypeActionPerformed
this.showProxySettings();
}//GEN-LAST:event_cbProxyTypeActionPerformed
private void cbProxyTypeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbProxyTypeActionPerformed
this.showProxySettings();
}//GEN-LAST:event_cbProxyTypeActionPerformed
private void txtPasswordFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtPasswordFieldActionPerformed
// TODO add your handling code here:

View file

@ -57,7 +57,7 @@ public class ConsoleFrame extends javax.swing.JFrame implements MageClient {
private static Session session;
private ConnectDialog connectDialog;
private static Preferences prefs = Preferences.userNodeForPackage(ConsoleFrame.class);
private final static MageVersion version = new MageVersion(0, 8, 6, "r2");
private final static MageVersion version = new MageVersion(0, 8, 6, "r2");
/**
* @return the session
@ -70,36 +70,36 @@ public class ConsoleFrame extends javax.swing.JFrame implements MageClient {
return prefs;
}
@Override
public MageVersion getVersion() {
return version;
}
@Override
public MageVersion getVersion() {
return version;
}
/** Creates new form ConsoleFrame */
/** Creates new form ConsoleFrame */
public ConsoleFrame() {
initComponents();
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
session = new SessionImpl(this);
connectDialog = new ConnectDialog();
} catch (Exception ex) {
logger.fatal("", ex);
}
initComponents();
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
session = new SessionImpl(this);
connectDialog = new ConnectDialog();
} catch (Exception ex) {
logger.fatal("", ex);
}
}
public boolean connect(Connection connection) {
if (session.connect(connection)) {
this.consolePanel1.start();
return true;
}
return false;
this.consolePanel1.start();
return true;
}
return false;
}
public void setStatusText(String status) {
public void setStatusText(String status) {
this.lblStatus.setText(status);
}
public void enableButtons() {
public void enableButtons() {
btnConnect.setEnabled(true);
btnConnect.setText("Disconnect");
btnSendMessage.setEnabled(true);
@ -177,16 +177,16 @@ public class ConsoleFrame extends javax.swing.JFrame implements MageClient {
pack();
}// </editor-fold>//GEN-END:initComponents
private void btnConnectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnConnectActionPerformed
private void btnConnectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnConnectActionPerformed
if (session.isConnected()) {
if (JOptionPane.showConfirmDialog(this, "Are you sure you want to disconnect?", "Confirm disconnect", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
this.consolePanel1.stop();
this.consolePanel1.stop();
session.disconnect(false);
}
} else {
connectDialog.showDialog(this);
}
}//GEN-LAST:event_btnConnectActionPerformed
}//GEN-LAST:event_btnConnectActionPerformed
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);
@ -205,10 +205,10 @@ public class ConsoleFrame extends javax.swing.JFrame implements MageClient {
}
});
}
private ConsoleFrame getFrame() {
return this;
}
private ConsoleFrame getFrame() {
return this;
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnConnect;
@ -218,79 +218,79 @@ public class ConsoleFrame extends javax.swing.JFrame implements MageClient {
private javax.swing.JLabel lblStatus;
// End of variables declaration//GEN-END:variables
@Override
public UUID getId() {
return null;
}
@Override
public UUID getId() {
return null;
}
@Override
public void connected(final String message) {
if (SwingUtilities.isEventDispatchThread()) {
setStatusText(message);
enableButtons();
}
else {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
setStatusText(message);
enableButtons();
}
});
}
}
@Override
public void connected(final String message) {
if (SwingUtilities.isEventDispatchThread()) {
setStatusText(message);
enableButtons();
}
else {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
setStatusText(message);
enableButtons();
}
});
}
}
@Override
public void disconnected() {
if (SwingUtilities.isEventDispatchThread()) {
consolePanel1.stop();
setStatusText("Not connected");
disableButtons();
}
else {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
consolePanel1.stop();
setStatusText("Not connected");
disableButtons();
}
});
}
}
@Override
public void disconnected() {
if (SwingUtilities.isEventDispatchThread()) {
consolePanel1.stop();
setStatusText("Not connected");
disableButtons();
}
else {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
consolePanel1.stop();
setStatusText("Not connected");
disableButtons();
}
});
}
}
@Override
public void showMessage(final String message) {
if (SwingUtilities.isEventDispatchThread()) {
JOptionPane.showMessageDialog(this, message);
}
else {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
JOptionPane.showMessageDialog(getFrame(), message);
}
});
}
}
@Override
public void showMessage(final String message) {
if (SwingUtilities.isEventDispatchThread()) {
JOptionPane.showMessageDialog(this, message);
}
else {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
JOptionPane.showMessageDialog(getFrame(), message);
}
});
}
}
@Override
public void showError(final String message) {
if (SwingUtilities.isEventDispatchThread()) {
JOptionPane.showMessageDialog(this, message, "Error", JOptionPane.ERROR_MESSAGE);
}
else {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
JOptionPane.showMessageDialog(getFrame(), message, "Error", JOptionPane.ERROR_MESSAGE);
}
});
}
}
@Override
public void showError(final String message) {
if (SwingUtilities.isEventDispatchThread()) {
JOptionPane.showMessageDialog(this, message, "Error", JOptionPane.ERROR_MESSAGE);
}
else {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
JOptionPane.showMessageDialog(getFrame(), message, "Error", JOptionPane.ERROR_MESSAGE);
}
});
}
}
@Override
public void processCallback(ClientCallback callback) {
}
@Override
public void processCallback(ClientCallback callback) {
}
}

View file

@ -52,57 +52,57 @@ import org.apache.log4j.Logger;
*/
public class ConsolePanel extends javax.swing.JPanel {
private final static Logger logger = Logger.getLogger(ConsolePanel.class);
private final static Logger logger = Logger.getLogger(ConsolePanel.class);
private TableUserModel tableUserModel;
private TableTableModel tableTableModel;
private UpdateUsersTask updateUsersTask;
private UpdateTablesTask updateTablesTask;
private TableUserModel tableUserModel;
private TableTableModel tableTableModel;
private UpdateUsersTask updateUsersTask;
private UpdateTablesTask updateTablesTask;
/** Creates new form ConsolePanel */
public ConsolePanel() {
this.tableUserModel = new TableUserModel();
this.tableTableModel = new TableTableModel();
initComponents();
this.tblUsers.createDefaultColumnsFromModel();
this.tblTables.createDefaultColumnsFromModel();
}
/** Creates new form ConsolePanel */
public ConsolePanel() {
this.tableUserModel = new TableUserModel();
this.tableTableModel = new TableTableModel();
initComponents();
this.tblUsers.createDefaultColumnsFromModel();
this.tblTables.createDefaultColumnsFromModel();
}
public void update(List<UserView> users) {
int row = this.tblUsers.getSelectedRow();
tableUserModel.loadData(users);
this.tblUsers.repaint();
this.tblUsers.getSelectionModel().setSelectionInterval(row, row);
}
public void update(Collection<TableView> tables) {
int row = this.tblTables.getSelectedRow();
tableTableModel.loadData(tables);
this.tblTables.repaint();
this.tblTables.getSelectionModel().setSelectionInterval(row, row);
}
public void start() {
updateUsersTask = new UpdateUsersTask(ConsoleFrame.getSession(), this);
updateTablesTask = new UpdateTablesTask(ConsoleFrame.getSession(), ConsoleFrame.getSession().getMainRoomId(), this);
updateUsersTask.execute();
updateTablesTask.execute();
}
public void stop() {
if (updateUsersTask != null && !updateUsersTask.isDone())
updateUsersTask.cancel(true);
if (updateTablesTask != null && !updateTablesTask.isDone())
updateTablesTask.cancel(true);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
public void update(List<UserView> users) {
int row = this.tblUsers.getSelectedRow();
tableUserModel.loadData(users);
this.tblUsers.repaint();
this.tblUsers.getSelectionModel().setSelectionInterval(row, row);
}
public void update(Collection<TableView> tables) {
int row = this.tblTables.getSelectedRow();
tableTableModel.loadData(tables);
this.tblTables.repaint();
this.tblTables.getSelectionModel().setSelectionInterval(row, row);
}
public void start() {
updateUsersTask = new UpdateUsersTask(ConsoleFrame.getSession(), this);
updateTablesTask = new UpdateTablesTask(ConsoleFrame.getSession(), ConsoleFrame.getSession().getMainRoomId(), this);
updateUsersTask.execute();
updateTablesTask.execute();
}
public void stop() {
if (updateUsersTask != null && !updateUsersTask.isDone())
updateUsersTask.cancel(true);
if (updateTablesTask != null && !updateTablesTask.isDone())
updateTablesTask.cancel(true);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
@ -243,15 +243,15 @@ public class ConsolePanel extends javax.swing.JPanel {
);
}// </editor-fold>//GEN-END:initComponents
private void btnDisconnectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDisconnectActionPerformed
int row = this.tblUsers.getSelectedRow();
ConsoleFrame.getSession().disconnectUser((String)tableUserModel.getValueAt(row, 3));
}//GEN-LAST:event_btnDisconnectActionPerformed
private void btnDisconnectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDisconnectActionPerformed
int row = this.tblUsers.getSelectedRow();
ConsoleFrame.getSession().disconnectUser((String)tableUserModel.getValueAt(row, 3));
}//GEN-LAST:event_btnDisconnectActionPerformed
private void btnDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeleteActionPerformed
int row = this.tblTables.getSelectedRow();
ConsoleFrame.getSession().removeTable((UUID)tableTableModel.getValueAt(row, 7));
}//GEN-LAST:event_btnDeleteActionPerformed
private void btnDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeleteActionPerformed
int row = this.tblTables.getSelectedRow();
ConsoleFrame.getSession().removeTable((UUID)tableTableModel.getValueAt(row, 7));
}//GEN-LAST:event_btnDeleteActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnDelete;
@ -272,40 +272,40 @@ public class ConsolePanel extends javax.swing.JPanel {
class TableUserModel extends AbstractTableModel {
private String[] columnNames = new String[]{"User Name", "Host", "Time Connected"};
private UserView[] users = new UserView[0];
private UserView[] users = new UserView[0];
public void loadData(List<UserView> users) {
this.users = users.toArray(new UserView[0]);
this.fireTableDataChanged();
}
public void loadData(List<UserView> users) {
this.users = users.toArray(new UserView[0]);
this.fireTableDataChanged();
}
@Override
public int getRowCount() {
return users.length;
}
@Override
public int getRowCount() {
return users.length;
}
@Override
public int getColumnCount() {
return columnNames.length;
}
@Override
public int getColumnCount() {
return columnNames.length;
}
@Override
public Object getValueAt(int arg0, int arg1) {
switch (arg1) {
case 0:
return users[arg0].getUserName();
case 1:
return users[arg0].getHost();
case 2:
return users[arg0].getConnectionTime().toString();
case 3:
return users[arg0].getSessionId();
}
return "";
}
@Override
public Object getValueAt(int arg0, int arg1) {
switch (arg1) {
case 0:
return users[arg0].getUserName();
case 1:
return users[arg0].getHost();
case 2:
return users[arg0].getConnectionTime().toString();
case 3:
return users[arg0].getSessionId();
}
return "";
}
@Override
public String getColumnName(int columnIndex) {
@Override
public String getColumnName(int columnIndex) {
String colName = "";
if (columnIndex <= getColumnCount())
@ -314,65 +314,65 @@ class TableUserModel extends AbstractTableModel {
return colName;
}
@Override
@Override
public Class getColumnClass(int columnIndex){
return String.class;
return String.class;
}
@Override
@Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
return false;
return false;
}
}
class TableTableModel extends AbstractTableModel {
private String[] columnNames = new String[]{"Table Name", "Owner", "Game Type", "Deck Type", "Status"};
private TableView[] tables = new TableView[0];
private TableView[] tables = new TableView[0];
public void loadData(Collection<TableView> tables) {
this.tables = tables.toArray(new TableView[0]);
this.fireTableDataChanged();
}
public void loadData(Collection<TableView> tables) {
this.tables = tables.toArray(new TableView[0]);
this.fireTableDataChanged();
}
@Override
public int getRowCount() {
return tables.length;
}
@Override
public int getRowCount() {
return tables.length;
}
@Override
public int getColumnCount() {
return columnNames.length;
}
@Override
public int getColumnCount() {
return columnNames.length;
}
@Override
public Object getValueAt(int arg0, int arg1) {
switch (arg1) {
case 0:
return tables[arg0].getTableName();
case 1:
return tables[arg0].getControllerName();
case 2:
return tables[arg0].getGameType().toString();
case 3:
return tables[arg0].getDeckType().toString();
case 4:
return tables[arg0].getTableState().toString();
case 5:
return tables[arg0].isTournament();
case 6:
if (!tables[arg0].getGames().isEmpty())
return tables[arg0].getGames().get(0);
return null;
case 7:
return tables[arg0].getTableId();
}
return "";
}
@Override
public Object getValueAt(int arg0, int arg1) {
switch (arg1) {
case 0:
return tables[arg0].getTableName();
case 1:
return tables[arg0].getControllerName();
case 2:
return tables[arg0].getGameType().toString();
case 3:
return tables[arg0].getDeckType().toString();
case 4:
return tables[arg0].getTableState().toString();
case 5:
return tables[arg0].isTournament();
case 6:
if (!tables[arg0].getGames().isEmpty())
return tables[arg0].getGames().get(0);
return null;
case 7:
return tables[arg0].getTableId();
}
return "";
}
@Override
public String getColumnName(int columnIndex) {
@Override
public String getColumnName(int columnIndex) {
String colName = "";
if (columnIndex <= getColumnCount())
@ -381,94 +381,94 @@ class TableTableModel extends AbstractTableModel {
return colName;
}
@Override
@Override
public Class getColumnClass(int columnIndex){
return String.class;
return String.class;
}
@Override
@Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
if (columnIndex != 5)
return false;
return true;
if (columnIndex != 5)
return false;
return true;
}
}
class UpdateUsersTask extends SwingWorker<Void, List<UserView>> {
private Session session;
private ConsolePanel panel;
private Session session;
private ConsolePanel panel;
private final static Logger logger = Logger.getLogger(UpdateUsersTask.class);
private final static Logger logger = Logger.getLogger(UpdateUsersTask.class);
UpdateUsersTask(Session session, ConsolePanel panel) {
this.session = session;
this.panel = panel;
}
UpdateUsersTask(Session session, ConsolePanel panel) {
this.session = session;
this.panel = panel;
}
@Override
protected Void doInBackground() throws Exception {
while (!isCancelled()) {
this.publish(session.getUsers());
Thread.sleep(1000);
}
return null;
}
@Override
protected Void doInBackground() throws Exception {
while (!isCancelled()) {
this.publish(session.getUsers());
Thread.sleep(1000);
}
return null;
}
@Override
protected void process(List<List<UserView>> view) {
panel.update(view.get(0));
}
@Override
protected void process(List<List<UserView>> view) {
panel.update(view.get(0));
}
@Override
protected void done() {
try {
get();
} catch (InterruptedException ex) {
logger.fatal("Update Users Task error", ex);
} catch (ExecutionException ex) {
logger.fatal("Update Users Task error", ex);
} catch (CancellationException ex) {}
}
@Override
protected void done() {
try {
get();
} catch (InterruptedException ex) {
logger.fatal("Update Users Task error", ex);
} catch (ExecutionException ex) {
logger.fatal("Update Users Task error", ex);
} catch (CancellationException ex) {}
}
}
class UpdateTablesTask extends SwingWorker<Void, Collection<TableView>> {
private Session session;
private UUID roomId;
private ConsolePanel panel;
private Session session;
private UUID roomId;
private ConsolePanel panel;
private final static Logger logger = Logger.getLogger(UpdateTablesTask.class);
private final static Logger logger = Logger.getLogger(UpdateTablesTask.class);
UpdateTablesTask(Session session, UUID roomId, ConsolePanel panel) {
this.session = session;
this.roomId = roomId;
this.panel = panel;
}
UpdateTablesTask(Session session, UUID roomId, ConsolePanel panel) {
this.session = session;
this.roomId = roomId;
this.panel = panel;
}
@Override
protected Void doInBackground() throws Exception {
while (!isCancelled()) {
this.publish(session.getTables(roomId));
Thread.sleep(1000);
}
return null;
}
@Override
protected Void doInBackground() throws Exception {
while (!isCancelled()) {
this.publish(session.getTables(roomId));
Thread.sleep(1000);
}
return null;
}
@Override
protected void process(List<Collection<TableView>> view) {
panel.update(view.get(0));
}
@Override
protected void process(List<Collection<TableView>> view) {
panel.update(view.get(0));
}
@Override
protected void done() {
try {
get();
} catch (InterruptedException ex) {
logger.fatal("Update Tables Task error", ex);
} catch (ExecutionException ex) {
logger.fatal("Update Tables Task error", ex);
} catch (CancellationException ex) {}
}
@Override
protected void done() {
try {
get();
} catch (InterruptedException ex) {
logger.fatal("Update Tables Task error", ex);
} catch (ExecutionException ex) {
logger.fatal("Update Tables Task error", ex);
} catch (CancellationException ex) {}
}
}