mirror of
https://github.com/magefree/mage.git
synced 2025-12-20 10:40:06 -08:00
GUI, preferences: improved theme switch at runtime (fixed main menu update);
This commit is contained in:
parent
feaa30f616
commit
2631b31b8a
5 changed files with 56 additions and 26 deletions
|
|
@ -306,7 +306,6 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
|
||||||
errorDialog = new ErrorDialog();
|
errorDialog = new ErrorDialog();
|
||||||
errorDialog.setLocation(100, 100);
|
errorDialog.setLocation(100, 100);
|
||||||
desktopPane.add(errorDialog, JLayeredPane.MODAL_LAYER);
|
desktopPane.add(errorDialog, JLayeredPane.MODAL_LAYER);
|
||||||
UI.addComponent(MageComponents.DESKTOP_PANE, desktopPane);
|
|
||||||
|
|
||||||
PING_SENDER_EXECUTOR.scheduleAtFixedRate(SessionHandler::ping, TablesPanel.PING_SERVER_SECS, TablesPanel.PING_SERVER_SECS, TimeUnit.SECONDS);
|
PING_SENDER_EXECUTOR.scheduleAtFixedRate(SessionHandler::ping, TablesPanel.PING_SERVER_SECS, TablesPanel.PING_SERVER_SECS, TimeUnit.SECONDS);
|
||||||
|
|
||||||
|
|
@ -317,6 +316,10 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
|
||||||
desktopPane.add(tablesPane, javax.swing.JLayeredPane.DEFAULT_LAYER);
|
desktopPane.add(tablesPane, javax.swing.JLayeredPane.DEFAULT_LAYER);
|
||||||
SwingUtilities.invokeLater(this::hideServerLobby);
|
SwingUtilities.invokeLater(this::hideServerLobby);
|
||||||
|
|
||||||
|
// save links for global/shared components
|
||||||
|
UI.addComponent(MageComponents.DESKTOP_PANE, desktopPane);
|
||||||
|
UI.addComponent(MageComponents.DESKTOP_TOOLBAR, mageToolbar);
|
||||||
|
|
||||||
addTooltipContainer();
|
addTooltipContainer();
|
||||||
setBackground();
|
setBackground();
|
||||||
addMageLabel();
|
addMageLabel();
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ public enum MageComponents {
|
||||||
NEW_TABLE_OK_BUTTON("btnOK"),
|
NEW_TABLE_OK_BUTTON("btnOK"),
|
||||||
TABLE_WAITING_START_BUTTON("btnStart"),
|
TABLE_WAITING_START_BUTTON("btnStart"),
|
||||||
DESKTOP_PANE("desktopPane"),
|
DESKTOP_PANE("desktopPane"),
|
||||||
|
DESKTOP_TOOLBAR("desktopToolbar"),
|
||||||
CARD_INFO_PANE("cardInfoPane"),
|
CARD_INFO_PANE("cardInfoPane"),
|
||||||
POPUP_CONTAINER("popupContainer"),
|
POPUP_CONTAINER("popupContainer"),
|
||||||
CARD_PREVIEW_PANE("cardPreviewPane"),
|
CARD_PREVIEW_PANE("cardPreviewPane"),
|
||||||
|
|
|
||||||
|
|
@ -3,18 +3,22 @@ package mage.client.components;
|
||||||
import mage.util.ThreadUtils;
|
import mage.util.ThreadUtils;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import java.awt.Component;
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
import java.util.EnumMap;
|
import java.util.EnumMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
import javax.swing.JButton;
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GUI helper class to store global/shared components list like menus, buttons, panels
|
||||||
|
* See MageComponents for all shared components
|
||||||
|
*/
|
||||||
public class MageUI {
|
public class MageUI {
|
||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(MageUI.class);
|
private static final Logger logger = Logger.getLogger(MageUI.class);
|
||||||
|
|
||||||
private final Map<MageComponents, Component> ui = new EnumMap<>(MageComponents.class);
|
private final Map<MageComponents, Component> ui = new EnumMap<>(MageComponents.class); // components list
|
||||||
private final Map<MageComponents, Object> sync = new EnumMap<>(MageComponents.class);
|
private final Map<MageComponents, Object> sync = new EnumMap<>(MageComponents.class); // waiting for components init
|
||||||
|
|
||||||
public static final ThreadPoolExecutor threadPoolPopups;
|
public static final ThreadPoolExecutor threadPoolPopups;
|
||||||
private static int threadCount;
|
private static int threadCount;
|
||||||
|
|
@ -69,16 +73,23 @@ public class MageUI {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Component getComponent(MageComponents name) throws InterruptedException {
|
public Component getComponent(MageComponents name) throws InterruptedException {
|
||||||
|
return getComponent(name, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Component getComponent(MageComponents name, boolean waitComponentInit) throws InterruptedException {
|
||||||
Object componentSync;
|
Object componentSync;
|
||||||
synchronized (ui) {
|
synchronized (ui) {
|
||||||
if (ui.containsKey(name)) {
|
if (ui.containsKey(name)) {
|
||||||
return ui.get(name);
|
return ui.get(name);
|
||||||
} else {
|
|
||||||
componentSync = new Object();
|
|
||||||
sync.put(name, componentSync);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (waitComponentInit) {
|
||||||
|
// start waiting until component init from other places like plugins
|
||||||
|
componentSync = new Object();
|
||||||
|
synchronized (sync) {
|
||||||
|
sync.put(name, componentSync);
|
||||||
|
}
|
||||||
synchronized (componentSync) {
|
synchronized (componentSync) {
|
||||||
componentSync.wait();
|
componentSync.wait();
|
||||||
if (!ui.containsKey(name)) {
|
if (!ui.containsKey(name)) {
|
||||||
|
|
@ -86,7 +97,9 @@ public class MageUI {
|
||||||
}
|
}
|
||||||
return ui.get(name);
|
return ui.get(name);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addButton(MageComponents name, JButton button) {
|
public void addButton(MageComponents name, JButton button) {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package mage.client.util.gui;
|
package mage.client.util.gui;
|
||||||
|
|
||||||
import mage.client.MageFrame;
|
import mage.client.MageFrame;
|
||||||
|
import mage.client.components.MageComponents;
|
||||||
import mage.client.dialog.PreferencesDialog;
|
import mage.client.dialog.PreferencesDialog;
|
||||||
import mage.client.table.PlayersChatPanel;
|
import mage.client.table.PlayersChatPanel;
|
||||||
import mage.client.util.GUISizeHelper;
|
import mage.client.util.GUISizeHelper;
|
||||||
|
|
@ -512,6 +513,17 @@ public final class GuiDisplayUtil {
|
||||||
for (Frame frame : Frame.getFrames()) {
|
for (Frame frame : Frame.getFrames()) {
|
||||||
refreshLookAndFill(frame);
|
refreshLookAndFill(frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// re-render hidden/shared components
|
||||||
|
Arrays.stream(MageComponents.values()).forEach(compName -> {
|
||||||
|
try {
|
||||||
|
Component comp = MageFrame.getUI().getComponent(compName, false);
|
||||||
|
if (comp != null) {
|
||||||
|
SwingUtilities.updateComponentTreeUI(comp);
|
||||||
|
}
|
||||||
|
} catch (InterruptedException ignore) {
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void refreshLookAndFill(Window window) {
|
private static void refreshLookAndFill(Window window) {
|
||||||
|
|
|
||||||
|
|
@ -462,17 +462,18 @@ public enum ImageManagerImpl implements ImageManager {
|
||||||
private static BufferedImage imageDlgNextButton;
|
private static BufferedImage imageDlgNextButton;
|
||||||
private static BufferedImage imageDlgActiveNextButton;
|
private static BufferedImage imageDlgActiveNextButton;
|
||||||
|
|
||||||
private static BufferedImage imageCancelSkipButton;
|
// TODO: enable buttons and related GUI refresh on theme change
|
||||||
private static BufferedImage imageSwitchHandsButton;
|
private static BufferedImage imageCancelSkipButton; // theme depends
|
||||||
private static BufferedImage imageStopWatchingButton;
|
private static BufferedImage imageSwitchHandsButton; // theme depends
|
||||||
private static BufferedImage imageConcedeButton;
|
private static BufferedImage imageStopWatchingButton; // theme depends
|
||||||
private static BufferedImage imageSkipNextTurnButton;
|
private static BufferedImage imageConcedeButton; // theme depends
|
||||||
private static BufferedImage imageSkipToEndTurnButton;
|
private static BufferedImage imageSkipNextTurnButton; // theme depends
|
||||||
private static BufferedImage imageSkipToMainButton;
|
private static BufferedImage imageSkipToEndTurnButton; // theme depends
|
||||||
private static BufferedImage imageSkipStackButton;
|
private static BufferedImage imageSkipToMainButton; // theme depends
|
||||||
private static BufferedImage imageSkipUntilEndStepBeforeYourTurnButton;
|
private static BufferedImage imageSkipStackButton; // theme depends
|
||||||
private static BufferedImage imageSkipYourNextTurnButton;
|
private static BufferedImage imageSkipUntilEndStepBeforeYourTurnButton; // theme depends
|
||||||
private static BufferedImage imageToggleRecordMacroButton;
|
private static BufferedImage imageSkipYourNextTurnButton; // theme depends
|
||||||
|
private static BufferedImage imageToggleRecordMacroButton; // theme depends
|
||||||
|
|
||||||
private static Map<String, Image> phasesImages;
|
private static Map<String, Image> phasesImages; // theme depends
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue