mirror of
https://github.com/correl/mage.git
synced 2025-01-12 11:08:01 +00:00
* UI: fixed that server messages and tables list is not refresh after re-connect (#4194);
This commit is contained in:
parent
a2592ef36e
commit
c95f14f64c
2 changed files with 29 additions and 20 deletions
|
@ -105,7 +105,7 @@ public class TablesPane extends MagePane {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void activated() {
|
public void activated() {
|
||||||
tablesPanel.startTasks();
|
tablesPanel.startUpdateTasks(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -633,23 +633,31 @@ public class TablesPanel extends javax.swing.JPanel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startTasks() {
|
public void startUpdateTasks(boolean refreshImmediately) {
|
||||||
if (SessionHandler.getSession() != null) {
|
if (SessionHandler.getSession() != null) {
|
||||||
if (updateTablesTask == null || updateTablesTask.isDone()) {
|
// active tables and server messages
|
||||||
|
if (updateTablesTask == null || updateTablesTask.isDone() || refreshImmediately) {
|
||||||
|
if (updateTablesTask != null) updateTablesTask.cancel(true);
|
||||||
updateTablesTask = new UpdateTablesTask(roomId, this);
|
updateTablesTask = new UpdateTablesTask(roomId, this);
|
||||||
updateTablesTask.execute();
|
updateTablesTask.execute();
|
||||||
}
|
}
|
||||||
if (updatePlayersTask == null || updatePlayersTask.isDone()) {
|
|
||||||
updatePlayersTask = new UpdatePlayersTask(roomId, this.chatPanelMain);
|
// finished tables
|
||||||
updatePlayersTask.execute();
|
|
||||||
}
|
|
||||||
if (this.btnStateFinished.isSelected()) {
|
if (this.btnStateFinished.isSelected()) {
|
||||||
if (updateMatchesTask == null || updateMatchesTask.isDone()) {
|
if (updateMatchesTask == null || updateMatchesTask.isDone() || refreshImmediately) {
|
||||||
|
if (updateMatchesTask != null) updateMatchesTask.cancel(true);
|
||||||
updateMatchesTask = new UpdateMatchesTask(roomId, this);
|
updateMatchesTask = new UpdateMatchesTask(roomId, this);
|
||||||
updateMatchesTask.execute();
|
updateMatchesTask.execute();
|
||||||
}
|
}
|
||||||
} else if (updateMatchesTask != null) {
|
} else {
|
||||||
updateMatchesTask.cancel(true);
|
if (updateMatchesTask != null) updateMatchesTask.cancel(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// players list
|
||||||
|
if (updatePlayersTask == null || updatePlayersTask.isDone() || refreshImmediately) {
|
||||||
|
if (updatePlayersTask != null) updatePlayersTask.cancel(true);
|
||||||
|
updatePlayersTask = new UpdatePlayersTask(roomId, this.chatPanelMain);
|
||||||
|
updatePlayersTask.execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -688,7 +696,7 @@ public class TablesPanel extends javax.swing.JPanel {
|
||||||
}
|
}
|
||||||
if (chatRoomId != null) {
|
if (chatRoomId != null) {
|
||||||
this.chatPanelMain.getUserChatPanel().connect(chatRoomId);
|
this.chatPanelMain.getUserChatPanel().connect(chatRoomId);
|
||||||
startTasks();
|
startUpdateTasks(true);
|
||||||
this.setVisible(true);
|
this.setVisible(true);
|
||||||
this.repaint();
|
this.repaint();
|
||||||
} else {
|
} else {
|
||||||
|
@ -696,7 +704,7 @@ public class TablesPanel extends javax.swing.JPanel {
|
||||||
}
|
}
|
||||||
//tableModel.setSession(session);
|
//tableModel.setSession(session);
|
||||||
|
|
||||||
reloadMessages();
|
reloadServerMessages();
|
||||||
|
|
||||||
MageFrame.getUI().addButton(MageComponents.NEW_GAME_BUTTON, btnNewTable);
|
MageFrame.getUI().addButton(MageComponents.NEW_GAME_BUTTON, btnNewTable);
|
||||||
|
|
||||||
|
@ -705,7 +713,7 @@ public class TablesPanel extends javax.swing.JPanel {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void reloadMessages() {
|
protected void reloadServerMessages() {
|
||||||
// reload server messages
|
// reload server messages
|
||||||
java.util.List<String> serverMessages = SessionHandler.getServerMessages();
|
java.util.List<String> serverMessages = SessionHandler.getServerMessages();
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
|
@ -1581,7 +1589,7 @@ public class TablesPanel extends javax.swing.JPanel {
|
||||||
} else {
|
} else {
|
||||||
this.jSplitPaneTables.setDividerLocation(this.jPanelTables.getHeight());
|
this.jSplitPaneTables.setDividerLocation(this.jPanelTables.getHeight());
|
||||||
}
|
}
|
||||||
this.startTasks();
|
this.startUpdateTasks(true);
|
||||||
}//GEN-LAST:event_btnStateFinishedActionPerformed
|
}//GEN-LAST:event_btnStateFinishedActionPerformed
|
||||||
|
|
||||||
private void btnRatedbtnFilterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRatedbtnFilterActionPerformed
|
private void btnRatedbtnFilterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRatedbtnFilterActionPerformed
|
||||||
|
@ -1666,6 +1674,7 @@ class UpdateTablesTask extends SwingWorker<Void, Collection<TableView>> {
|
||||||
|
|
||||||
private final UUID roomId;
|
private final UUID roomId;
|
||||||
private final TablesPanel panel;
|
private final TablesPanel panel;
|
||||||
|
private boolean isFirstRun = true;
|
||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(UpdateTablesTask.class);
|
private static final Logger logger = Logger.getLogger(UpdateTablesTask.class);
|
||||||
|
|
||||||
|
@ -1693,10 +1702,13 @@ class UpdateTablesTask extends SwingWorker<Void, Collection<TableView>> {
|
||||||
@Override
|
@Override
|
||||||
protected void process(java.util.List<Collection<TableView>> view) {
|
protected void process(java.util.List<Collection<TableView>> view) {
|
||||||
panel.updateTables(view.get(0));
|
panel.updateTables(view.get(0));
|
||||||
|
|
||||||
|
// update server messages
|
||||||
count++;
|
count++;
|
||||||
if (count > 60) {
|
if (isFirstRun || count > 60) {
|
||||||
count = 0;
|
count = 0;
|
||||||
panel.reloadMessages();
|
isFirstRun = false;
|
||||||
|
panel.reloadServerMessages();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1766,10 +1778,7 @@ class UpdateMatchesTask extends SwingWorker<Void, Collection<MatchView>> {
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground() throws Exception {
|
protected Void doInBackground() throws Exception {
|
||||||
while (!isCancelled()) {
|
while (!isCancelled()) {
|
||||||
Collection<MatchView> matches = SessionHandler.getFinishedMatches(roomId);
|
this.publish(SessionHandler.getFinishedMatches(roomId));
|
||||||
if (!matches.isEmpty()) {
|
|
||||||
this.publish(matches);
|
|
||||||
}
|
|
||||||
TimeUnit.SECONDS.sleep(TablesPanel.REFRESH_FINISHED_TABLES_SECS);
|
TimeUnit.SECONDS.sleep(TablesPanel.REFRESH_FINISHED_TABLES_SECS);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
Loading…
Reference in a new issue