mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 04:52:07 -08:00
completed Room handling
This commit is contained in:
parent
e7bb3a0dbf
commit
bc51a8fc79
13 changed files with 357 additions and 147 deletions
|
|
@ -370,8 +370,8 @@ public class ChatPanel extends javax.swing.JPanel {
|
|||
private final String[] columnNames = new String[]{"Players", "Info", "Games", "Connection"};
|
||||
private UsersView[] players = new UsersView[0];
|
||||
|
||||
public void loadData(Collection<RoomUsersView> roomUserInfoList) throws MageRemoteException {
|
||||
RoomUsersView roomUserInfo = roomUserInfoList.iterator().next();
|
||||
public void loadData(RoomUsersView roomUserInfo) throws MageRemoteException {
|
||||
// RoomUsersView roomUserInfo = roomUserInfoList.iterator().next();
|
||||
this.players = roomUserInfo.getUsersView().toArray(new UsersView[0]);
|
||||
JTableHeader th = jTablePlayers.getTableHeader();
|
||||
TableColumnModel tcm = th.getColumnModel();
|
||||
|
|
@ -535,9 +535,9 @@ public class ChatPanel extends javax.swing.JPanel {
|
|||
}
|
||||
}//GEN-LAST:event_txtMessageKeyTyped
|
||||
|
||||
public void setRoomUserInfo(List<Collection<RoomUsersView>> view) {
|
||||
public void setRoomUserInfo(RoomUsersView view) {
|
||||
try {
|
||||
tableModel.loadData(view.get(0));
|
||||
tableModel.loadData(view);
|
||||
} catch (Exception ex) {
|
||||
this.players.clear();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -91,6 +91,7 @@ import mage.remote.MageRemoteException;
|
|||
//import mage.remote.Session;
|
||||
import mage.view.MatchView;
|
||||
import mage.view.RoomUsersView;
|
||||
import mage.view.RoomView;
|
||||
import mage.view.TableView;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.mage.card.arcane.Util;
|
||||
|
|
@ -107,9 +108,9 @@ public class TablesPanel extends javax.swing.JPanel {
|
|||
private TableTableModel tableModel;
|
||||
private MatchesTableModel matchesModel;
|
||||
private UUID roomId;
|
||||
private UpdateTablesTask updateTablesTask;
|
||||
private UpdatePlayersTask updatePlayersTask;
|
||||
private UpdateMatchesTask updateMatchesTask;
|
||||
private UpdateRoomTask updateRoomTask;
|
||||
// private UpdatePlayersTask updatePlayersTask;
|
||||
// private UpdateMatchesTask updateMatchesTask;
|
||||
private JoinTableDialog joinTableDialog;
|
||||
private NewTableDialog newTableDialog;
|
||||
private NewTournamentDialog newTournamentDialog;
|
||||
|
|
@ -389,38 +390,38 @@ public class TablesPanel extends javax.swing.JPanel {
|
|||
|
||||
public void startTasks() {
|
||||
if (client != null) {
|
||||
if (updateTablesTask == null || updateTablesTask.isDone()) {
|
||||
updateTablesTask = new UpdateTablesTask(client, roomId, this);
|
||||
updateTablesTask.execute();
|
||||
}
|
||||
if (updatePlayersTask == null || updatePlayersTask.isDone()) {
|
||||
updatePlayersTask = new UpdatePlayersTask(client, roomId, this.chatPanel);
|
||||
updatePlayersTask.execute();
|
||||
}
|
||||
if (this.btnStateFinished.isSelected()) {
|
||||
if (updateMatchesTask == null || updateMatchesTask.isDone()) {
|
||||
updateMatchesTask = new UpdateMatchesTask(client, roomId, this);
|
||||
updateMatchesTask.execute();
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (updateMatchesTask != null) {
|
||||
updateMatchesTask.cancel(true);
|
||||
}
|
||||
if (updateRoomTask == null || updateRoomTask.isDone()) {
|
||||
updateRoomTask = new UpdateRoomTask(client, roomId, this, this.chatPanel);
|
||||
updateRoomTask.execute();
|
||||
}
|
||||
// if (updatePlayersTask == null || updatePlayersTask.isDone()) {
|
||||
// updatePlayersTask = new UpdatePlayersTask(client, roomId, this.chatPanel);
|
||||
// updatePlayersTask.execute();
|
||||
// }
|
||||
// if (this.btnStateFinished.isSelected()) {
|
||||
// if (updateMatchesTask == null || updateMatchesTask.isDone()) {
|
||||
// updateMatchesTask = new UpdateMatchesTask(client, roomId, this);
|
||||
// updateMatchesTask.execute();
|
||||
// }
|
||||
// }
|
||||
// else {
|
||||
// if (updateMatchesTask != null) {
|
||||
// updateMatchesTask.cancel(true);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
public void stopTasks() {
|
||||
if (updateTablesTask != null) {
|
||||
updateTablesTask.cancel(true);
|
||||
}
|
||||
if (updatePlayersTask != null) {
|
||||
updatePlayersTask.cancel(true);
|
||||
}
|
||||
if (updateMatchesTask != null) {
|
||||
updateMatchesTask.cancel(true);
|
||||
if (updateRoomTask != null) {
|
||||
updateRoomTask.cancel(true);
|
||||
}
|
||||
// if (updatePlayersTask != null) {
|
||||
// updatePlayersTask.cancel(true);
|
||||
// }
|
||||
// if (updateMatchesTask != null) {
|
||||
// updateMatchesTask.cancel(true);
|
||||
// }
|
||||
}
|
||||
|
||||
public void showTables(UUID roomId) {
|
||||
|
|
@ -1402,28 +1403,30 @@ class TableTableModel extends AbstractTableModel {
|
|||
|
||||
}
|
||||
|
||||
class UpdateTablesTask extends SwingWorker<Void, Collection<TableView>> {
|
||||
class UpdateRoomTask extends SwingWorker<Void, RoomView> {
|
||||
|
||||
private final Client client;
|
||||
private final UUID roomId;
|
||||
private final TablesPanel panel;
|
||||
private final ChatPanel chat;
|
||||
|
||||
private static final Logger logger = Logger.getLogger(UpdateTablesTask.class);
|
||||
private static final Logger logger = Logger.getLogger(UpdateRoomTask.class);
|
||||
|
||||
private int count = 0;
|
||||
|
||||
UpdateTablesTask(Client client, UUID roomId, TablesPanel panel) {
|
||||
UpdateRoomTask(Client client, UUID roomId, TablesPanel panel, ChatPanel chat) {
|
||||
this.client = client;
|
||||
this.roomId = roomId;
|
||||
this.panel = panel;
|
||||
this.chat = chat;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground() throws Exception {
|
||||
while (!isCancelled()) {
|
||||
Collection<TableView> tables = client.getTables(roomId);
|
||||
if (tables != null) {
|
||||
this.publish(tables);
|
||||
RoomView room = client.getRoom(roomId);
|
||||
if (room != null) {
|
||||
this.publish(room);
|
||||
}
|
||||
Thread.sleep(3000);
|
||||
}
|
||||
|
|
@ -1431,8 +1434,10 @@ class UpdateTablesTask extends SwingWorker<Void, Collection<TableView>> {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void process(List<Collection<TableView>> view) {
|
||||
panel.updateTables(view.get(0));
|
||||
protected void process(List<RoomView> view) {
|
||||
panel.updateTables(view.get(0).getTableViews());
|
||||
panel.updateMatches(view.get(0).getMatchViews());
|
||||
chat.setRoomUserInfo(view.get(0).getRoomUsersView());
|
||||
count++;
|
||||
if (count > 60) {
|
||||
count = 0;
|
||||
|
|
@ -1451,44 +1456,44 @@ class UpdateTablesTask extends SwingWorker<Void, Collection<TableView>> {
|
|||
|
||||
}
|
||||
|
||||
class UpdatePlayersTask extends SwingWorker<Void, Collection<RoomUsersView>> {
|
||||
|
||||
private final Client client;
|
||||
private final UUID roomId;
|
||||
private final ChatPanel chat;
|
||||
|
||||
private static final Logger logger = Logger.getLogger(UpdatePlayersTask.class);
|
||||
|
||||
UpdatePlayersTask(Client client, UUID roomId, ChatPanel chat) {
|
||||
this.client = client;
|
||||
this.roomId = roomId;
|
||||
this.chat = chat;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground() throws Exception {
|
||||
while (!isCancelled()) {
|
||||
this.publish(client.getRoomUsers(roomId));
|
||||
Thread.sleep(3000);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void process(List<Collection<RoomUsersView>> roomUserInfo) {
|
||||
chat.setRoomUserInfo(roomUserInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void done() {
|
||||
try {
|
||||
get();
|
||||
} catch (InterruptedException | ExecutionException ex) {
|
||||
logger.fatal("Update Players Task error", ex);
|
||||
} catch (CancellationException ex) {}
|
||||
}
|
||||
|
||||
}
|
||||
//class UpdatePlayersTask extends SwingWorker<Void, Collection<RoomUsersView>> {
|
||||
//
|
||||
// private final Client client;
|
||||
// private final UUID roomId;
|
||||
// private final ChatPanel chat;
|
||||
//
|
||||
// private static final Logger logger = Logger.getLogger(UpdatePlayersTask.class);
|
||||
//
|
||||
// UpdatePlayersTask(Client client, UUID roomId, ChatPanel chat) {
|
||||
// this.client = client;
|
||||
// this.roomId = roomId;
|
||||
// this.chat = chat;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected Void doInBackground() throws Exception {
|
||||
// while (!isCancelled()) {
|
||||
// this.publish(client.getRoomUsers(roomId));
|
||||
// Thread.sleep(3000);
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected void process(List<Collection<RoomUsersView>> roomUserInfo) {
|
||||
// chat.setRoomUserInfo(roomUserInfo);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected void done() {
|
||||
// try {
|
||||
// get();
|
||||
// } catch (InterruptedException | ExecutionException ex) {
|
||||
// logger.fatal("Update Players Task error", ex);
|
||||
// } catch (CancellationException ex) {}
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
||||
class MatchesTableModel extends AbstractTableModel {
|
||||
|
||||
|
|
@ -1592,47 +1597,47 @@ class MatchesTableModel extends AbstractTableModel {
|
|||
|
||||
}
|
||||
|
||||
class UpdateMatchesTask extends SwingWorker<Void, Collection<MatchView>> {
|
||||
|
||||
private final Client client;
|
||||
private final UUID roomId;
|
||||
private final TablesPanel panel;
|
||||
|
||||
private static final Logger logger = Logger.getLogger(UpdateTablesTask.class);
|
||||
|
||||
UpdateMatchesTask(Client client, UUID roomId, TablesPanel panel) {
|
||||
this.client = client;
|
||||
this.roomId = roomId;
|
||||
this.panel = panel;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground() throws Exception {
|
||||
while (!isCancelled()) {
|
||||
Collection<MatchView> matches = client.getFinishedMatches(roomId);
|
||||
if (matches != null) {
|
||||
this.publish(matches);
|
||||
}
|
||||
Thread.sleep(10000);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void process(List<Collection<MatchView>> view) {
|
||||
panel.updateMatches(view.get(0));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void done() {
|
||||
try {
|
||||
get();
|
||||
} catch (InterruptedException | ExecutionException ex) {
|
||||
logger.fatal("Update Matches Task error", ex);
|
||||
} catch (CancellationException ex) {}
|
||||
}
|
||||
|
||||
}
|
||||
//class UpdateMatchesTask extends SwingWorker<Void, Collection<MatchView>> {
|
||||
//
|
||||
// private final Client client;
|
||||
// private final UUID roomId;
|
||||
// private final TablesPanel panel;
|
||||
//
|
||||
// private static final Logger logger = Logger.getLogger(UpdateTablesTask.class);
|
||||
//
|
||||
// UpdateMatchesTask(Client client, UUID roomId, TablesPanel panel) {
|
||||
// this.client = client;
|
||||
// this.roomId = roomId;
|
||||
// this.panel = panel;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected Void doInBackground() throws Exception {
|
||||
// while (!isCancelled()) {
|
||||
// Collection<MatchView> matches = client.getFinishedMatches(roomId);
|
||||
// if (matches != null) {
|
||||
// this.publish(matches);
|
||||
// }
|
||||
// Thread.sleep(10000);
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected void process(List<Collection<MatchView>> view) {
|
||||
// panel.updateMatches(view.get(0));
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected void done() {
|
||||
// try {
|
||||
// get();
|
||||
// } catch (InterruptedException | ExecutionException ex) {
|
||||
// logger.fatal("Update Matches Task error", ex);
|
||||
// } catch (CancellationException ex) {}
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
||||
class GameChooser extends JPopupMenu {
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue