mirror of
https://github.com/magefree/mage.git
synced 2025-12-20 02:30:08 -08:00
GUI: fixed that server's lobby do not remember divider position after app restart (tables, matches and chat sizes)
This commit is contained in:
parent
f78177a540
commit
f0c38cdb87
7 changed files with 36 additions and 32 deletions
|
|
@ -324,9 +324,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
|
|||
// create default server lobby and hide it until connect
|
||||
tablesPane = new TablesPane();
|
||||
desktopPane.add(tablesPane, javax.swing.JLayeredPane.DEFAULT_LAYER);
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
this.hideServerLobby();
|
||||
});
|
||||
SwingUtilities.invokeLater(this::hideServerLobby);
|
||||
|
||||
addTooltipContainer();
|
||||
setBackground();
|
||||
|
|
@ -1608,8 +1606,9 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void disconnected(final boolean askToReconnect) {
|
||||
public void disconnected(boolean askToReconnect, boolean keepMySessionActive) {
|
||||
if (SwingUtilities.isEventDispatchThread()) {
|
||||
// TODO: need research, it can generate wrong logs due diff threads source (doInBackground, swing, server events, etc)
|
||||
// REMOTE task, e.g. connecting
|
||||
LOGGER.info("Disconnected from server side");
|
||||
} else {
|
||||
|
|
@ -1617,11 +1616,11 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
|
|||
LOGGER.info("Disconnected from client side");
|
||||
}
|
||||
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
Runnable runOnExit = () -> {
|
||||
// user already disconnected, can't do any online actions like quite chat
|
||||
// but try to keep session
|
||||
// TODO: why it ignore askToReconnect here, but use custom reconnect dialog later?! Need research
|
||||
SessionHandler.disconnect(false, true);
|
||||
SessionHandler.disconnect(false, keepMySessionActive);
|
||||
setConnectButtonText(NOT_CONNECTED_BUTTON);
|
||||
disableButtons();
|
||||
hideGames();
|
||||
|
|
@ -1632,7 +1631,13 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
|
|||
message.setButton2("Yes", PlayerAction.CLIENT_RECONNECT);
|
||||
showUserRequestDialog(message);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
if (SwingUtilities.isEventDispatchThread()) {
|
||||
runOnExit.run();
|
||||
} else {
|
||||
SwingUtilities.invokeLater(runOnExit);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -30,8 +30,6 @@ import org.apache.log4j.Logger;
|
|||
import org.mage.card.arcane.CardRendererUtils;
|
||||
import org.ocpsoft.prettytime.Duration;
|
||||
import org.ocpsoft.prettytime.PrettyTime;
|
||||
import org.ocpsoft.prettytime.TimeFormat;
|
||||
import org.ocpsoft.prettytime.units.JustNow;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
|
|
@ -645,8 +643,24 @@ public class TablesPanel extends javax.swing.JPanel {
|
|||
btnQuickStartMCTS.setFont(GUISizeHelper.menuFont);
|
||||
}
|
||||
|
||||
private void restoreDividerLocations() {
|
||||
Rectangle currentBounds = MageFrame.getDesktop().getBounds();
|
||||
if (currentBounds != null) {
|
||||
String firstDivider = PreferencesDialog.getCachedValue(KEY_TABLES_DIVIDER_LOCATION_1, null);
|
||||
String tableDivider = PreferencesDialog.getCachedValue(KEY_TABLES_DIVIDER_LOCATION_2, null);
|
||||
String chatDivider = PreferencesDialog.getCachedValue(KEY_TABLES_DIVIDER_LOCATION_3, null);
|
||||
GuiDisplayUtil.restoreDividerLocations(currentBounds, firstDivider, jSplitPane1);
|
||||
GuiDisplayUtil.restoreDividerLocations(currentBounds, tableDivider, jSplitPaneTables);
|
||||
GuiDisplayUtil.restoreDividerLocations(currentBounds, chatDivider, chatPanelMain);
|
||||
}
|
||||
}
|
||||
|
||||
private void saveDividerLocations() {
|
||||
// save divider locations and divider saveDividerLocations
|
||||
// save divider locations
|
||||
if (this.jSplitPane1.getDividerLocation() == -1) {
|
||||
// server lobby hidden by default, so ignore that settings
|
||||
return;
|
||||
}
|
||||
GuiDisplayUtil.saveCurrentBoundsToPrefs();
|
||||
GuiDisplayUtil.saveDividerLocationToPrefs(KEY_TABLES_DIVIDER_LOCATION_1, this.jSplitPane1.getDividerLocation());
|
||||
GuiDisplayUtil.saveDividerLocationToPrefs(KEY_TABLES_DIVIDER_LOCATION_2, this.jSplitPaneTables.getDividerLocation());
|
||||
|
|
@ -663,18 +677,6 @@ public class TablesPanel extends javax.swing.JPanel {
|
|||
TableUtil.saveColumnWidthAndOrderToPrefs(tableTables, KEY_TABLES_COLUMNS_WIDTH, KEY_TABLES_COLUMNS_ORDER);
|
||||
}
|
||||
|
||||
private void restoreDividers() {
|
||||
Rectangle currentBounds = MageFrame.getDesktop().getBounds();
|
||||
if (currentBounds != null) {
|
||||
String firstDivider = PreferencesDialog.getCachedValue(KEY_TABLES_DIVIDER_LOCATION_1, null);
|
||||
String tableDivider = PreferencesDialog.getCachedValue(KEY_TABLES_DIVIDER_LOCATION_2, null);
|
||||
String chatDivider = PreferencesDialog.getCachedValue(KEY_TABLES_DIVIDER_LOCATION_3, null);
|
||||
GuiDisplayUtil.restoreDividerLocations(currentBounds, firstDivider, jSplitPane1);
|
||||
GuiDisplayUtil.restoreDividerLocations(currentBounds, tableDivider, jSplitPaneTables);
|
||||
GuiDisplayUtil.restoreDividerLocations(currentBounds, chatDivider, chatPanelMain);
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String, JComponent> getUIComponents() {
|
||||
Map<String, JComponent> components = new HashMap<>();
|
||||
|
||||
|
|
@ -778,12 +780,9 @@ public class TablesPanel extends javax.swing.JPanel {
|
|||
//tableModel.setSession(session);
|
||||
|
||||
reloadServerMessages();
|
||||
|
||||
MageFrame.getUI().addButton(MageComponents.NEW_GAME_BUTTON, btnNewTable);
|
||||
|
||||
// divider locations have to be set with delay else values set are overwritten with system defaults
|
||||
Executors.newSingleThreadScheduledExecutor().schedule(() -> restoreDividers(), 300, TimeUnit.MILLISECONDS);
|
||||
|
||||
restoreDividerLocations();
|
||||
}
|
||||
|
||||
protected void reloadServerMessages() {
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ public class MultiConnectTest {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void disconnected(boolean askToReconnect) {
|
||||
public void disconnected(boolean askToReconnect, boolean keepMySessionActive) {
|
||||
logger.info("disconnected");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ public interface MageClient extends CallbackClient {
|
|||
|
||||
void connected(String message);
|
||||
|
||||
void disconnected(boolean askToReconnect);
|
||||
void disconnected(boolean askToReconnect, boolean keepMySessionActive);
|
||||
|
||||
void showMessage(String message);
|
||||
|
||||
|
|
|
|||
|
|
@ -552,7 +552,7 @@ public class SessionImpl implements Session {
|
|||
if (askForReconnect) {
|
||||
client.showError("Network error. Can't connect to " + connection.getHost());
|
||||
}
|
||||
client.disconnected(askForReconnect); // MageFrame with check to reconnect
|
||||
client.disconnected(askForReconnect, keepMySessionActive); // MageFrame with check to reconnect
|
||||
pingTime.clear();
|
||||
}
|
||||
|
||||
|
|
@ -568,7 +568,7 @@ public class SessionImpl implements Session {
|
|||
|
||||
@Override
|
||||
public synchronized void connectReconnect(Throwable throwable) {
|
||||
client.disconnected(true);
|
||||
client.disconnected(true, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -243,7 +243,7 @@ public class ConsoleFrame extends javax.swing.JFrame implements MageClient {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void disconnected(boolean askToReconnect) {
|
||||
public void disconnected(boolean askToReconnect, boolean keepMySessionActive) {
|
||||
if (SwingUtilities.isEventDispatchThread()) {
|
||||
consolePanel1.stop();
|
||||
setStatusText("Not connected");
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ public class SimpleMageClient implements MageClient {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void disconnected(boolean askToReconnect) {
|
||||
public void disconnected(boolean askToReconnect, boolean keepMySessionActive) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue