From 2b91b88551b5de5895d27752560ab5dacd049286 Mon Sep 17 00:00:00 2001 From: ingmargoudt Date: Thu, 16 Mar 2017 09:46:22 +0100 Subject: [PATCH] fixing some additional singleton classes --- .../src/main/java/mage/client/MageFrame.java | 28 +++++++------- .../main/java/mage/client/cards/BigCard.java | 2 +- .../main/java/mage/client/cards/CardArea.java | 2 +- .../client/cards/CardDraggerGlassPane.java | 2 +- .../main/java/mage/client/cards/CardGrid.java | 2 +- .../main/java/mage/client/cards/Cards.java | 4 +- .../java/mage/client/cards/CardsList.java | 2 +- .../java/mage/client/cards/DraftGrid.java | 4 +- .../java/mage/client/cards/DragCardGrid.java | 2 +- .../mage/client/combat/CombatManager.java | 12 +++--- .../components/ability/AbilityPicker.java | 2 +- .../components/ext/dlg/impl/ChoiceDialog.java | 34 ++++++++--------- .../components/ext/dlg/impl/StackDialog.java | 18 ++++----- .../mage/client/components/tray/MageTray.java | 13 +++---- .../client/deckeditor/DeckEditorPane.java | 4 +- .../client/deckeditor/DeckEditorPanel.java | 8 ++-- .../viewer/CollectionViewerPane.java | 4 +- .../viewer/CollectionViewerPanel.java | 2 +- .../collection/viewer/MageBook.java | 2 +- .../collection/viewer/TestMageBook.java | 2 +- .../client/deckeditor/table/TableModel.java | 2 +- .../client/dialog/CardInfoWindowDialog.java | 8 ++-- .../mage/client/dialog/PickChoiceDialog.java | 2 +- .../mage/client/dialog/PickNumberDialog.java | 2 +- .../mage/client/dialog/PickPileDialog.java | 2 +- .../mage/client/dialog/ShowCardsDialog.java | 2 +- .../client/dialog/TableWaitingDialog.java | 6 +-- .../java/mage/client/draft/DraftPane.java | 4 +- .../java/mage/client/draft/DraftPanel.java | 6 +-- .../mage/client/game/BattlefieldPanel.java | 10 ++--- .../main/java/mage/client/game/GamePanel.java | 38 +++++++++---------- .../plugins/adapters/MageActionCallback.java | 4 +- .../mage/client/plugins/impl/Plugins.java | 9 ++--- .../client/remote/CallbackClientImpl.java | 6 +-- .../java/mage/client/table/TablesPane.java | 4 +- .../java/mage/client/util/GameManager.java | 8 +--- .../mage/client/util/SettingsManager.java | 8 +--- .../layout/impl/OldCardLayoutStrategy.java | 4 +- .../java/org/mage/card/arcane/CardPanel.java | 14 +++---- .../card/arcane/CardPanelComponentImpl.java | 16 ++++---- .../card/utils/impl/ImageManagerImpl.java | 10 ++--- 41 files changed, 148 insertions(+), 166 deletions(-) diff --git a/Mage.Client/src/main/java/mage/client/MageFrame.java b/Mage.Client/src/main/java/mage/client/MageFrame.java index 22bcd2c147..d0fc5e02dc 100644 --- a/Mage.Client/src/main/java/mage/client/MageFrame.java +++ b/Mage.Client/src/main/java/mage/client/MageFrame.java @@ -229,14 +229,14 @@ public class MageFrame extends javax.swing.JFrame implements MageClient { } ManaSymbols.loadImages(); - Plugins.getInstance().loadPlugins(); + Plugins.instance.loadPlugins(); initComponents(); desktopPane.setDesktopManager(new MageDesktopManager()); setSize(1024, 768); - SettingsManager.getInstance().setScreenWidthAndHeight(1024, 768); + SettingsManager.instance.setScreenWidthAndHeight(1024, 768); DialogManager.updateParams(768, 1024, false); this.setExtendedState(JFrame.MAXIMIZED_BOTH); @@ -265,7 +265,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient { setBackground(); addMageLabel(); setAppIcon(); - MageTray.getInstance().install(); + MageTray.instance.install(); desktopPane.add(ArrowBuilder.getBuilder().getArrowsManagerPanel(), JLayeredPane.DRAG_LAYER); @@ -274,7 +274,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient { public void componentResized(ComponentEvent e) { int width = ((JComponent) e.getSource()).getWidth(); int height = ((JComponent) e.getSource()).getHeight(); - SettingsManager.getInstance().setScreenWidthAndHeight(width, height); + SettingsManager.instance.setScreenWidthAndHeight(width, height); if (!liteMode && !grayMode) { backgroundPane.setSize(width, height); } @@ -295,8 +295,8 @@ public class MageFrame extends javax.swing.JFrame implements MageClient { mageToolbar.add(createSwitchPanelsButton(), 0); mageToolbar.add(new javax.swing.JToolBar.Separator(), 1); - if (Plugins.getInstance().isCounterPluginLoaded()) { - int i = Plugins.getInstance().getGamesPlayed(); + if (Plugins.instance.isCounterPluginLoaded()) { + int i = Plugins.instance.getGamesPlayed(); JLabel label = new JLabel(" Games played: " + String.valueOf(i)); desktopPane.add(label, JLayeredPane.DEFAULT_LAYER + 1); label.setVisible(true); @@ -338,7 +338,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient { } private void addTooltipContainer() { - final JEditorPane cardInfoPane = (JEditorPane) Plugins.getInstance().getCardInfoPane(); + final JEditorPane cardInfoPane = (JEditorPane) Plugins.instance.getCardInfoPane(); if (cardInfoPane == null) { return; } @@ -422,8 +422,8 @@ public class MageFrame extends javax.swing.JFrame implements MageClient { } String filename = "/background.jpg"; try { - if (Plugins.getInstance().isThemePluginLoaded()) { - backgroundPane = (ImagePanel) Plugins.getInstance().updateTablePanel(new HashMap<>()); + if (Plugins.instance.isThemePluginLoaded()) { + backgroundPane = (ImagePanel) Plugins.instance.updateTablePanel(new HashMap<>()); } else { InputStream is = this.getClass().getResourceAsStream(filename); BufferedImage background = ImageIO.read(is); @@ -460,7 +460,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient { } private void setAppIcon() { - Image image = ImageManagerImpl.getInstance().getAppImage(); + Image image = ImageManagerImpl.instance.getAppImage(); setIconImage(image); } @@ -1323,7 +1323,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient { public void sendUserReplay(PlayerAction playerAction, UserRequestMessage userRequestMessage) { switch (playerAction) { case CLIENT_DOWNLOAD_SYMBOLS: - Plugins.getInstance().downloadSymbols(); + Plugins.instance.downloadSymbols(); break; case CLIENT_DOWNLOAD_CARD_IMAGES: DownloadPictures.startDownload(null, missingCards); @@ -1361,7 +1361,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient { } CardRepository.instance.closeDB(); tablesPane.cleanUp(); - Plugins.getInstance().shutdown(); + Plugins.instance.shutdown(); dispose(); System.exit(0); break; @@ -1390,7 +1390,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient { setGUISizeTooltipContainer(); - Plugins.getInstance().changeGUISize(); + Plugins.instance.changeGUISize(); CountryUtil.changeGUISize(); for (Component component : desktopPane.getComponents()) { if (component instanceof MageDialog) { @@ -1410,7 +1410,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient { } } catch (Exception ex) { - + ex.printStackTrace(); } this.revalidate(); diff --git a/Mage.Client/src/main/java/mage/client/cards/BigCard.java b/Mage.Client/src/main/java/mage/client/cards/BigCard.java index 3dd8910da5..8048c8977f 100644 --- a/Mage.Client/src/main/java/mage/client/cards/BigCard.java +++ b/Mage.Client/src/main/java/mage/client/cards/BigCard.java @@ -81,7 +81,7 @@ public class BigCard extends JComponent { public BigCard(boolean rotated) { initComponents(); - if (!Plugins.getInstance().isCardPluginLoaded()) { + if (!Plugins.instance.isCardPluginLoaded()) { initBounds(rotated); } setDoubleBuffered(true); diff --git a/Mage.Client/src/main/java/mage/client/cards/CardArea.java b/Mage.Client/src/main/java/mage/client/cards/CardArea.java index 4ead4cf4dd..e14e810134 100644 --- a/Mage.Client/src/main/java/mage/client/cards/CardArea.java +++ b/Mage.Client/src/main/java/mage/client/cards/CardArea.java @@ -148,7 +148,7 @@ public class CardArea extends JPanel implements MouseListener { tmp.setAbility(card); // cross-reference, required for ability picker card = tmp; } - MageCard cardPanel = Plugins.getInstance().getMageCard(card, bigCard, cardDimension, gameId, true, true); + MageCard cardPanel = Plugins.instance.getMageCard(card, bigCard, cardDimension, gameId, true, true); cardPanel.setBounds(rectangle); cardPanel.addMouseListener(this); diff --git a/Mage.Client/src/main/java/mage/client/cards/CardDraggerGlassPane.java b/Mage.Client/src/main/java/mage/client/cards/CardDraggerGlassPane.java index b813b53bfe..ed9ae1f67f 100644 --- a/Mage.Client/src/main/java/mage/client/cards/CardDraggerGlassPane.java +++ b/Mage.Client/src/main/java/mage/client/cards/CardDraggerGlassPane.java @@ -57,7 +57,7 @@ public class CardDraggerGlassPane implements MouseListener, MouseMotionListener currentCards = new ArrayList<>(source.dragCardList()); // Make a view for the first one and add it to us - dragView = Plugins.getInstance().getMageCard(currentCards.get(0), null, new Dimension(100, 140), null, true, false); + dragView = Plugins.instance.getMageCard(currentCards.get(0), null, new Dimension(100, 140), null, true, false); for (MouseListener l: dragView.getMouseListeners()) { dragView.removeMouseListener(l); } diff --git a/Mage.Client/src/main/java/mage/client/cards/CardGrid.java b/Mage.Client/src/main/java/mage/client/cards/CardGrid.java index 1180ccab47..04eb29c0d4 100644 --- a/Mage.Client/src/main/java/mage/client/cards/CardGrid.java +++ b/Mage.Client/src/main/java/mage/client/cards/CardGrid.java @@ -133,7 +133,7 @@ public class CardGrid extends javax.swing.JLayeredPane implements MouseListener, } private void addCard(CardView card, BigCard bigCard, UUID gameId, boolean drawImage) { - MageCard cardImg = Plugins.getInstance().getMageCard(card, bigCard, cardDimension, gameId, drawImage, true); + MageCard cardImg = Plugins.instance.getMageCard(card, bigCard, cardDimension, gameId, drawImage, true); cards.put(card.getId(), cardImg); cardImg.addMouseListener(this); add(cardImg); diff --git a/Mage.Client/src/main/java/mage/client/cards/Cards.java b/Mage.Client/src/main/java/mage/client/cards/Cards.java index 6996657d74..aa81cc691b 100644 --- a/Mage.Client/src/main/java/mage/client/cards/Cards.java +++ b/Mage.Client/src/main/java/mage/client/cards/Cards.java @@ -98,7 +98,7 @@ public class Cards extends javax.swing.JPanel { jScrollPane1.getViewport().setOpaque(false); jScrollPane1.setBorder(EMPTY_BORDER); } - if (Plugins.getInstance().isCardPluginLoaded()) { + if (Plugins.instance.isCardPluginLoaded()) { cardArea.setLayout(null); } cardArea.setBorder(EMPTY_BORDER); @@ -263,7 +263,7 @@ public class Cards extends javax.swing.JPanel { } private void addCard(CardView card, BigCard bigCard, UUID gameId) { - MageCard mageCard = Plugins.getInstance().getMageCard(card, bigCard, getCardDimension(), gameId, true, true); + MageCard mageCard = Plugins.instance.getMageCard(card, bigCard, getCardDimension(), gameId, true, true); if (zone != null) { mageCard.setZone(zone); } diff --git a/Mage.Client/src/main/java/mage/client/cards/CardsList.java b/Mage.Client/src/main/java/mage/client/cards/CardsList.java index 99c2b22551..45d106c187 100644 --- a/Mage.Client/src/main/java/mage/client/cards/CardsList.java +++ b/Mage.Client/src/main/java/mage/client/cards/CardsList.java @@ -425,7 +425,7 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar } private MageCard addCard(CardView card, BigCard bigCard, UUID gameId) { - MageCard cardImg = Plugins.getInstance().getMageCard(card, bigCard, cardDimension, gameId, true, true); + MageCard cardImg = Plugins.instance.getMageCard(card, bigCard, cardDimension, gameId, true, true); cardArea.add(cardImg); cardImg.update(card); cardImg.addMouseListener(this); diff --git a/Mage.Client/src/main/java/mage/client/cards/DraftGrid.java b/Mage.Client/src/main/java/mage/client/cards/DraftGrid.java index 89c8149d09..dc91515619 100644 --- a/Mage.Client/src/main/java/mage/client/cards/DraftGrid.java +++ b/Mage.Client/src/main/java/mage/client/cards/DraftGrid.java @@ -127,7 +127,7 @@ public class DraftGrid extends javax.swing.JPanel implements MouseListener { List sortedCards = new ArrayList<>(booster.values()); sortedCards.sort(new CardViewRarityComparator()); for (CardView card: sortedCards) { - MageCard cardImg = Plugins.getInstance().getMageCard(card, bigCard, dimension, null, true, true); + MageCard cardImg = Plugins.instance.getMageCard(card, bigCard, dimension, null, true, true); cardImg.addMouseListener(this); add(cardImg); cardImg.update(card); @@ -156,7 +156,7 @@ public class DraftGrid extends javax.swing.JPanel implements MouseListener { } private void hidePopup() { - Plugins.getInstance().getActionCallback().mouseExited(null, null); + Plugins.instance.getActionCallback().mouseExited(null, null); } /** This method is called from within the constructor to diff --git a/Mage.Client/src/main/java/mage/client/cards/DragCardGrid.java b/Mage.Client/src/main/java/mage/client/cards/DragCardGrid.java index f1a332f427..d1bb0977e2 100644 --- a/Mage.Client/src/main/java/mage/client/cards/DragCardGrid.java +++ b/Mage.Client/src/main/java/mage/client/cards/DragCardGrid.java @@ -1767,7 +1767,7 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg updateCounts(); // Create the card view - final MageCard cardPanel = Plugins.getInstance().getMageCard(card, lastBigCard, new Dimension(getCardWidth(), getCardHeight()), null, true, true); + final MageCard cardPanel = Plugins.instance.getMageCard(card, lastBigCard, new Dimension(getCardWidth(), getCardHeight()), null, true, true); cardPanel.update(card); cardPanel.setTextOffset(0); diff --git a/Mage.Client/src/main/java/mage/client/combat/CombatManager.java b/Mage.Client/src/main/java/mage/client/combat/CombatManager.java index ef07232384..695a507133 100644 --- a/Mage.Client/src/main/java/mage/client/combat/CombatManager.java +++ b/Mage.Client/src/main/java/mage/client/combat/CombatManager.java @@ -118,12 +118,12 @@ public class CombatManager { blockerPoint.translate(-parentPoint.x, -parentPoint.y); Point attackerPoint = attackerCard.getLocationOnScreen(); attackerPoint.translate(-parentPoint.x, -parentPoint.y); - double yRateA = (attackerCard.getSize().height / SettingsManager.getInstance().getCardSize().height); - double xRateA = (attackerCard.getSize().width / SettingsManager.getInstance().getCardSize().width); - double yRateB = (blockerCard.getSize().height / SettingsManager.getInstance().getCardSize().height); - double xRateB = (blockerCard.getSize().width / SettingsManager.getInstance().getCardSize().width); - ArrowBuilder.getBuilder().addArrow(gameId, (int) blockerPoint.getX() + (int)(55*xRateB), (int) blockerPoint.getY() + (int)(25*xRateB), - (int) attackerPoint.getX() + (int)(70*xRateA), (int) attackerPoint.getY() + (int)(25*yRateA), Color.blue, ArrowBuilder.Type.COMBAT); + double yRateA = (attackerCard.getSize().height / SettingsManager.instance.getCardSize().height); + double xRateA = (attackerCard.getSize().width / SettingsManager.instance.getCardSize().width); + double yRateB = (blockerCard.getSize().height / SettingsManager.instance.getCardSize().height); + double xRateB = (blockerCard.getSize().width / SettingsManager.instance.getCardSize().width); + ArrowBuilder.getBuilder().addArrow(gameId, (int) blockerPoint.getX() + (int) (55 * xRateB), (int) blockerPoint.getY() + (int) (25 * xRateB), + (int) attackerPoint.getX() + (int) (70 * xRateA), (int) attackerPoint.getY() + (int) (25 * yRateA), Color.blue, ArrowBuilder.Type.COMBAT); globalBlockersCount++; } } diff --git a/Mage.Client/src/main/java/mage/client/components/ability/AbilityPicker.java b/Mage.Client/src/main/java/mage/client/components/ability/AbilityPicker.java index d2c4262e4f..7a60696a10 100644 --- a/Mage.Client/src/main/java/mage/client/components/ability/AbilityPicker.java +++ b/Mage.Client/src/main/java/mage/client/components/ability/AbilityPicker.java @@ -112,7 +112,7 @@ public class AbilityPicker extends JXPanel implements MouseWheelListener { this.selected = false; // back to false - waiting for selection setVisible(true); - Point centered = SettingsManager.getInstance().getComponentPosition(DIALOG_WIDTH, DIALOG_HEIGHT); + Point centered = SettingsManager.instance.getComponentPosition(DIALOG_WIDTH, DIALOG_HEIGHT); this.setLocation(centered.x, centered.y); GuiDisplayUtil.keepComponentInsideScreen(centered.x, centered.y, this); diff --git a/Mage.Client/src/main/java/mage/client/components/ext/dlg/impl/ChoiceDialog.java b/Mage.Client/src/main/java/mage/client/components/ext/dlg/impl/ChoiceDialog.java index 10324cd923..938a99483a 100644 --- a/Mage.Client/src/main/java/mage/client/components/ext/dlg/impl/ChoiceDialog.java +++ b/Mage.Client/src/main/java/mage/client/components/ext/dlg/impl/ChoiceDialog.java @@ -130,7 +130,7 @@ public class ChoiceDialog extends IDialogPanel { return; } - java.util.List toRemove = new ArrayList<>(); + ArrayList toRemove = new ArrayList<>(); for (int i = getComponentCount() - 1; i > 0; i--) { Component o = getComponent(i); if (o instanceof MageCard) { @@ -141,10 +141,10 @@ public class ChoiceDialog extends IDialogPanel { remove(toRemove.get(i)); } - java.util.List cardList = new ArrayList<>(cards.values()); + ArrayList cardList = new ArrayList<>(cards.values()); - int width = SettingsManager.getInstance().getCardSize().width; - int height = SettingsManager.getInstance().getCardSize().height; + int width = SettingsManager.instance.getCardSize().width; + int height = SettingsManager.instance.getCardSize().height; int dx = 0; int dy = 30; @@ -161,7 +161,7 @@ public class ChoiceDialog extends IDialogPanel { } CardView card = cardList.get(i); - MageCard cardImg = Plugins.getInstance().getMageCard(card, bigCard, getCardDimension(), gameId, true, true); + MageCard cardImg = Plugins.instance.getMageCard(card, bigCard, getCardDimension(), gameId, true, true); cardImg.setLocation(dx, dy + j*(height + 30)); add(cardImg); @@ -174,9 +174,9 @@ public class ChoiceDialog extends IDialogPanel { private HoverButton getJButtonOK() { if (jButtonOK == null) { - jButtonOK = new HoverButton("", ImageManagerImpl.getInstance().getDlgAcceptButtonImage(), - ImageManagerImpl.getInstance().getDlgActiveAcceptButtonImage(), - ImageManagerImpl.getInstance().getDlgAcceptButtonImage(), + jButtonOK = new HoverButton("", ImageManagerImpl.instance.getDlgAcceptButtonImage(), + ImageManagerImpl.instance.getDlgActiveAcceptButtonImage(), + ImageManagerImpl.instance.getDlgAcceptButtonImage(), new Rectangle(60, 60)); int w = getDlgParams().rect.width - 75; int h = getDlgParams().rect.height - 90; @@ -190,9 +190,9 @@ public class ChoiceDialog extends IDialogPanel { private HoverButton getJButtonPrevPage() { if (jButtonPrevPage == null) { - jButtonPrevPage = new HoverButton("", ImageManagerImpl.getInstance().getDlgPrevButtonImage(), - ImageManagerImpl.getInstance().getDlgActivePrevButtonImage(), - ImageManagerImpl.getInstance().getDlgPrevButtonImage(), + jButtonPrevPage = new HoverButton("", ImageManagerImpl.instance.getDlgPrevButtonImage(), + ImageManagerImpl.instance.getDlgActivePrevButtonImage(), + ImageManagerImpl.instance.getDlgPrevButtonImage(), new Rectangle(60, 60)); int w = getDlgParams().rect.width - 75; int h = getDlgParams().rect.height - 90; @@ -229,9 +229,9 @@ public class ChoiceDialog extends IDialogPanel { */ private HoverButton getJButtonNextPage() { if (jButtonNextPage == null) { - jButtonNextPage = new HoverButton("", ImageManagerImpl.getInstance().getDlgNextButtonImage(), - ImageManagerImpl.getInstance().getDlgActiveNextButtonImage(), - ImageManagerImpl.getInstance().getDlgNextButtonImage(), + jButtonNextPage = new HoverButton("", ImageManagerImpl.instance.getDlgNextButtonImage(), + ImageManagerImpl.instance.getDlgActiveNextButtonImage(), + ImageManagerImpl.instance.getDlgNextButtonImage(), new Rectangle(60, 60)); int w = getDlgParams().rect.width - 75; int h = getDlgParams().rect.height - 90; @@ -317,9 +317,9 @@ public class ChoiceDialog extends IDialogPanel { */ private HoverButton getJButtonCancel() { if (jButtonCancel == null) { - jButtonCancel = new HoverButton("", ImageManagerImpl.getInstance().getDlgCancelButtonImage(), - ImageManagerImpl.getInstance().getDlgActiveCancelButtonImage(), - ImageManagerImpl.getInstance().getDlgCancelButtonImage(), + jButtonCancel = new HoverButton("", ImageManagerImpl.instance.getDlgCancelButtonImage(), + ImageManagerImpl.instance.getDlgActiveCancelButtonImage(), + ImageManagerImpl.instance.getDlgCancelButtonImage(), new Rectangle(60, 60)); int w = getDlgParams().rect.width - 75; int h = getDlgParams().rect.height - 90; diff --git a/Mage.Client/src/main/java/mage/client/components/ext/dlg/impl/StackDialog.java b/Mage.Client/src/main/java/mage/client/components/ext/dlg/impl/StackDialog.java index d7644731e1..df8cbd65ec 100644 --- a/Mage.Client/src/main/java/mage/client/components/ext/dlg/impl/StackDialog.java +++ b/Mage.Client/src/main/java/mage/client/components/ext/dlg/impl/StackDialog.java @@ -110,7 +110,7 @@ public class StackDialog extends IDialogPanel { /** * Display spells and theis targets above them */ - int dx = (SettingsManager.getInstance().getCardSize().width + 15) * (cards.size() - 1); + int dx = (SettingsManager.instance.getCardSize().width + 15) * (cards.size() - 1); int dy = 30; for (CardView card : cards.values()) { @@ -124,21 +124,21 @@ public class StackDialog extends IDialogPanel { card = tmp; } - MageCard cardImg = Plugins.getInstance().getMageCard(card, bigCard, getCardDimension(), gameId, true, true); + MageCard cardImg = Plugins.instance.getMageCard(card, bigCard, getCardDimension(), gameId, true, true); //cardImg.setBorder(BorderFactory.createLineBorder(Color.red)); cardImg.setLocation(dx, dy); jLayeredPane.add(cardImg, JLayeredPane.DEFAULT_LAYER, 1); - dx -= (SettingsManager.getInstance().getCardSize().width + 15); + dx -= (SettingsManager.instance.getCardSize().width + 15); } } private HoverButton getJButtonAccept() { if (jButtonAccept == null) { - jButtonAccept = new HoverButton("", ImageManagerImpl.getInstance().getDlgAcceptButtonImage(), - ImageManagerImpl.getInstance().getDlgActiveAcceptButtonImage(), - ImageManagerImpl.getInstance().getDlgAcceptButtonImage(), + jButtonAccept = new HoverButton("", ImageManagerImpl.instance.getDlgAcceptButtonImage(), + ImageManagerImpl.instance.getDlgActiveAcceptButtonImage(), + ImageManagerImpl.instance.getDlgAcceptButtonImage(), new Rectangle(60, 60)); int w = getDlgParams().rect.width - 90; int h = getDlgParams().rect.height - 90; @@ -160,9 +160,9 @@ public class StackDialog extends IDialogPanel { private HoverButton getJButtonResponse() { if (jButtonResponse == null) { - jButtonResponse = new HoverButton("", ImageManagerImpl.getInstance().getDlgCancelButtonImage(), - ImageManagerImpl.getInstance().getDlgActiveCancelButtonImage(), - ImageManagerImpl.getInstance().getDlgCancelButtonImage(), + jButtonResponse = new HoverButton("", ImageManagerImpl.instance.getDlgCancelButtonImage(), + ImageManagerImpl.instance.getDlgActiveCancelButtonImage(), + ImageManagerImpl.instance.getDlgCancelButtonImage(), new Rectangle(60, 60)); int w = getDlgParams().rect.width - 90; int h = getDlgParams().rect.height - 90; diff --git a/Mage.Client/src/main/java/mage/client/components/tray/MageTray.java b/Mage.Client/src/main/java/mage/client/components/tray/MageTray.java index c18789322c..c193da98e3 100644 --- a/Mage.Client/src/main/java/mage/client/components/tray/MageTray.java +++ b/Mage.Client/src/main/java/mage/client/components/tray/MageTray.java @@ -9,9 +9,9 @@ import org.mage.plugins.card.utils.impl.ImageManagerImpl; /** * @author noxx */ -public class MageTray { +public enum MageTray { - private static final MageTray instance = new MageTray(); + instance; private static final Logger log = Logger.getLogger(MageTray.class); @@ -19,11 +19,8 @@ public class MageTray { private Image flashedImage; private TrayIcon trayIcon; - private static int state = 0; + private int state = 0; - public static MageTray getInstance() { - return instance; - } public void install() { if (!SystemTray.isSupported()) { @@ -32,8 +29,8 @@ public class MageTray { } try { - mainImage = ImageManagerImpl.getInstance().getAppSmallImage(); - flashedImage = ImageManagerImpl.getInstance().getAppFlashedImage(); + mainImage = ImageManagerImpl.instance.getAppSmallImage(); + flashedImage = ImageManagerImpl.instance.getAppFlashedImage(); trayIcon = new TrayIcon(mainImage); trayIcon.setImageAutoSize(true); diff --git a/Mage.Client/src/main/java/mage/client/deckeditor/DeckEditorPane.java b/Mage.Client/src/main/java/mage/client/deckeditor/DeckEditorPane.java index c8730d3455..dc522a686b 100644 --- a/Mage.Client/src/main/java/mage/client/deckeditor/DeckEditorPane.java +++ b/Mage.Client/src/main/java/mage/client/deckeditor/DeckEditorPane.java @@ -55,9 +55,9 @@ public class DeckEditorPane extends MagePane { public DeckEditorPane() { this.setDefaultCloseOperation(DISPOSE_ON_CLOSE); boolean initialized = false; - if (Plugins.getInstance().isThemePluginLoaded()) { + if (Plugins.instance.isThemePluginLoaded()) { Map uiMap = new HashMap<>(); - JComponent container = Plugins.getInstance().updateTablePanel(uiMap); + JComponent container = Plugins.instance.updateTablePanel(uiMap); if (container != null) { deckEditorPanel1 = new mage.client.deckeditor.DeckEditorPanel(); initComponents(container); diff --git a/Mage.Client/src/main/java/mage/client/deckeditor/DeckEditorPanel.java b/Mage.Client/src/main/java/mage/client/deckeditor/DeckEditorPanel.java index b055778607..32afd8a7bf 100644 --- a/Mage.Client/src/main/java/mage/client/deckeditor/DeckEditorPanel.java +++ b/Mage.Client/src/main/java/mage/client/deckeditor/DeckEditorPanel.java @@ -288,7 +288,7 @@ public class DeckEditorPanel extends javax.swing.JPanel { this.deckArea.clearDeckEventListeners(); this.deckArea.addDeckEventListener( (Listener) event -> { - if (mode == DeckEditorMode.FREE_BUILDING){ + if (mode == DeckEditorMode.FREE_BUILDING) { switch (event.getEventName()) { case "double-click": { SimpleCardView cardView = (SimpleCardView) event.getSource(); @@ -336,7 +336,7 @@ public class DeckEditorPanel extends javax.swing.JPanel { break; } } - }else{ + } else { // constructing phase or sideboarding during match -> card goes always to sideboard switch (event.getEventName()) { case "double-click": @@ -541,7 +541,7 @@ public class DeckEditorPanel extends javax.swing.JPanel { } private void hidePopup() { - Plugins.getInstance().getActionCallback().mouseExited(null, null); + Plugins.instance.getActionCallback().mouseExited(null, null); } public void removeDeckEditor() { @@ -631,7 +631,7 @@ public class DeckEditorPanel extends javax.swing.JPanel { bigCard.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))); - cardInfoPane = Plugins.getInstance().getCardInfoPane(); + cardInfoPane = Plugins.instance.getCardInfoPane(); if (cardInfoPane != null && System.getProperty("testCardInfo") != null) { cardInfoPane.setPreferredSize(new Dimension(170, 150)); cardInfoPane.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(200, 0, 0))); diff --git a/Mage.Client/src/main/java/mage/client/deckeditor/collection/viewer/CollectionViewerPane.java b/Mage.Client/src/main/java/mage/client/deckeditor/collection/viewer/CollectionViewerPane.java index f851570985..51acb6e70e 100644 --- a/Mage.Client/src/main/java/mage/client/deckeditor/collection/viewer/CollectionViewerPane.java +++ b/Mage.Client/src/main/java/mage/client/deckeditor/collection/viewer/CollectionViewerPane.java @@ -46,9 +46,9 @@ public class CollectionViewerPane extends MagePane { public CollectionViewerPane() { boolean initialized = false; this.setTitle("Collection Viewer"); - if (Plugins.getInstance().isThemePluginLoaded()) { + if (Plugins.instance.isThemePluginLoaded()) { Map uiComponents = new HashMap<>(); - JComponent container = Plugins.getInstance().updateTablePanel(uiComponents); + JComponent container = Plugins.instance.updateTablePanel(uiComponents); if (container != null) { collectionViewerPanel = new CollectionViewerPanel(); initComponents(container); diff --git a/Mage.Client/src/main/java/mage/client/deckeditor/collection/viewer/CollectionViewerPanel.java b/Mage.Client/src/main/java/mage/client/deckeditor/collection/viewer/CollectionViewerPanel.java index e3137ee353..447db6bc4b 100644 --- a/Mage.Client/src/main/java/mage/client/deckeditor/collection/viewer/CollectionViewerPanel.java +++ b/Mage.Client/src/main/java/mage/client/deckeditor/collection/viewer/CollectionViewerPanel.java @@ -185,7 +185,7 @@ public final class CollectionViewerPanel extends JPanel { } private void hidePopup() { - Plugins.getInstance().getActionCallback().mouseExited(null, null); + Plugins.instance.getActionCallback().mouseExited(null, null); } public void removeCollectionViewer() { diff --git a/Mage.Client/src/main/java/mage/client/deckeditor/collection/viewer/MageBook.java b/Mage.Client/src/main/java/mage/client/deckeditor/collection/viewer/MageBook.java index 5bbb699088..bf9fdb1ecf 100644 --- a/Mage.Client/src/main/java/mage/client/deckeditor/collection/viewer/MageBook.java +++ b/Mage.Client/src/main/java/mage/client/deckeditor/collection/viewer/MageBook.java @@ -236,7 +236,7 @@ public class MageBook extends JComponent { if (cardDimension == null) { cardDimension = new Dimension(Config.dimensions.frameWidth, Config.dimensions.frameHeight); } - final MageCard cardImg = Plugins.getInstance().getMageCard(card, bigCard, cardDimension, gameId, true, true); + final MageCard cardImg = Plugins.instance.getMageCard(card, bigCard, cardDimension, gameId, true, true); cardImg.setBounds(rectangle); jLayeredPane.add(cardImg, JLayeredPane.DEFAULT_LAYER, 10); cardImg.update(card); diff --git a/Mage.Client/src/main/java/mage/client/deckeditor/collection/viewer/TestMageBook.java b/Mage.Client/src/main/java/mage/client/deckeditor/collection/viewer/TestMageBook.java index 341fa3b4cd..2a004ef8c4 100644 --- a/Mage.Client/src/main/java/mage/client/deckeditor/collection/viewer/TestMageBook.java +++ b/Mage.Client/src/main/java/mage/client/deckeditor/collection/viewer/TestMageBook.java @@ -11,7 +11,7 @@ import org.mage.card.arcane.ManaSymbols; */ public class TestMageBook extends JFrame { public static void main(String[] args) { - Plugins.getInstance().loadPlugins(); + Plugins.instance.loadPlugins(); ManaSymbols.loadImages(); CardScanner.scan(); JFrame frame = new TestMageBook(); diff --git a/Mage.Client/src/main/java/mage/client/deckeditor/table/TableModel.java b/Mage.Client/src/main/java/mage/client/deckeditor/table/TableModel.java index eb6dbc1fed..31ea45eb34 100644 --- a/Mage.Client/src/main/java/mage/client/deckeditor/table/TableModel.java +++ b/Mage.Client/src/main/java/mage/client/deckeditor/table/TableModel.java @@ -406,7 +406,7 @@ public class TableModel extends AbstractTableModel implements ICardGrid { CardView card = view.get(row); if (!card.getId().equals(bigCard.getCardId())) { if (!MageFrame.isLite()) { - Image image = Plugins.getInstance().getOriginalImage(card); + Image image = Plugins.instance.getOriginalImage(card); if (image != null && image instanceof BufferedImage) { // XXX: scaled to fit width bigCard.setCard(card.getId(), EnlargeMode.NORMAL, image, new ArrayList<>(), false); diff --git a/Mage.Client/src/main/java/mage/client/dialog/CardInfoWindowDialog.java b/Mage.Client/src/main/java/mage/client/dialog/CardInfoWindowDialog.java index 801cbc5c79..f5bc858288 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/CardInfoWindowDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/CardInfoWindowDialog.java @@ -83,11 +83,11 @@ public class CardInfoWindowDialog extends MageDialog { this.setModal(false); switch (this.showType) { case LOOKED_AT: - this.setFrameIcon(new ImageIcon(ImageManagerImpl.getInstance().getLookedAtImage())); + this.setFrameIcon(new ImageIcon(ImageManagerImpl.instance.getLookedAtImage())); this.setClosable(true); break; case REVEAL: - this.setFrameIcon(new ImageIcon(ImageManagerImpl.getInstance().getRevealedImage())); + this.setFrameIcon(new ImageIcon(ImageManagerImpl.instance.getRevealedImage())); this.setClosable(true); break; case REVEAL_TOP_LIBRARY: @@ -106,7 +106,7 @@ public class CardInfoWindowDialog extends MageDialog { }); break; case EXILE: - this.setFrameIcon(new ImageIcon(ImageManagerImpl.getInstance().getExileImage())); + this.setFrameIcon(new ImageIcon(ImageManagerImpl.instance.getExileImage())); break; default: // no icon yet @@ -189,7 +189,7 @@ public class CardInfoWindowDialog extends MageDialog { int width = CardInfoWindowDialog.this.getWidth(); int height = CardInfoWindowDialog.this.getHeight(); if (width > 0 && height > 0) { - Point centered = SettingsManager.getInstance().getComponentPosition(width, height); + Point centered = SettingsManager.instance.getComponentPosition(width, height); if (!positioned) { int xPos = centered.x / 2; int yPos = centered.y / 2; diff --git a/Mage.Client/src/main/java/mage/client/dialog/PickChoiceDialog.java b/Mage.Client/src/main/java/mage/client/dialog/PickChoiceDialog.java index 6b63e6cfec..07095dbded 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/PickChoiceDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/PickChoiceDialog.java @@ -82,7 +82,7 @@ public class PickChoiceDialog extends MageDialog { mageDialogState.setStateToDialog(this); } else { - Point centered = SettingsManager.getInstance().getComponentPosition(getWidth(), getHeight()); + Point centered = SettingsManager.instance.getComponentPosition(getWidth(), getHeight()); this.setLocation(centered.x, centered.y); GuiDisplayUtil.keepComponentInsideScreen(centered.x, centered.y, this); } diff --git a/Mage.Client/src/main/java/mage/client/dialog/PickNumberDialog.java b/Mage.Client/src/main/java/mage/client/dialog/PickNumberDialog.java index 81eeb13f29..018c2bb44e 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/PickNumberDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/PickNumberDialog.java @@ -60,7 +60,7 @@ public class PickNumberDialog extends MageDialog { this.btnCancel.setVisible(false); this.pack(); - Point centered = SettingsManager.getInstance().getComponentPosition(getWidth(), getHeight()); + Point centered = SettingsManager.instance.getComponentPosition(getWidth(), getHeight()); this.setLocation(centered.x, centered.y); GuiDisplayUtil.keepComponentInsideScreen(centered.x, centered.y, this); diff --git a/Mage.Client/src/main/java/mage/client/dialog/PickPileDialog.java b/Mage.Client/src/main/java/mage/client/dialog/PickPileDialog.java index cba441aa7d..9fcfdfdd24 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/PickPileDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/PickPileDialog.java @@ -107,7 +107,7 @@ public class PickPileDialog extends MageDialog { } pack(); - Point centered = SettingsManager.getInstance().getComponentPosition(getWidth(), getHeight()); + Point centered = SettingsManager.instance.getComponentPosition(getWidth(), getHeight()); this.setLocation(centered.x, centered.y); GuiDisplayUtil.keepComponentInsideScreen(centered.x, centered.y, this); diff --git a/Mage.Client/src/main/java/mage/client/dialog/ShowCardsDialog.java b/Mage.Client/src/main/java/mage/client/dialog/ShowCardsDialog.java index 91503043f2..d26d318012 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/ShowCardsDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/ShowCardsDialog.java @@ -134,7 +134,7 @@ public class ShowCardsDialog extends MageDialog { int width = ShowCardsDialog.this.getWidth(); int height = ShowCardsDialog.this.getHeight(); if (width > 0 && height > 0) { - Point centered = SettingsManager.getInstance().getComponentPosition(width, height); + Point centered = SettingsManager.instance.getComponentPosition(width, height); ShowCardsDialog.this.setLocation(centered.x, centered.y); positioned = true; GuiDisplayUtil.keepComponentInsideScreen(centered.x, centered.y, ShowCardsDialog.this); diff --git a/Mage.Client/src/main/java/mage/client/dialog/TableWaitingDialog.java b/Mage.Client/src/main/java/mage/client/dialog/TableWaitingDialog.java index 23300752f4..3f1292c447 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/TableWaitingDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/TableWaitingDialog.java @@ -432,12 +432,12 @@ class UpdateSeatsTask extends SwingWorker { if (current != count) { if (count > 0) { if (current > count) { - MageTray.getInstance().displayMessage("New player joined your game."); + MageTray.instance.displayMessage("New player joined your game."); AudioManager.playPlayerJoinedTable(); } else { - MageTray.getInstance().displayMessage("A player left your game."); + MageTray.instance.displayMessage("A player left your game."); } - MageTray.getInstance().blink(); + MageTray.instance.blink(); } count = current; } diff --git a/Mage.Client/src/main/java/mage/client/draft/DraftPane.java b/Mage.Client/src/main/java/mage/client/draft/DraftPane.java index d3862c5d50..2805cac5a8 100644 --- a/Mage.Client/src/main/java/mage/client/draft/DraftPane.java +++ b/Mage.Client/src/main/java/mage/client/draft/DraftPane.java @@ -52,9 +52,9 @@ public class DraftPane extends MagePane { */ public DraftPane() { boolean initialized = false; - if (Plugins.getInstance().isThemePluginLoaded()) { + if (Plugins.instance.isThemePluginLoaded()) { Map uiComponents = new HashMap<>(); - JComponent container = Plugins.getInstance().updateTablePanel(uiComponents); + JComponent container = Plugins.instance.updateTablePanel(uiComponents); if (container != null) { draftPanel1 = new mage.client.draft.DraftPanel(); initComponents(container); diff --git a/Mage.Client/src/main/java/mage/client/draft/DraftPanel.java b/Mage.Client/src/main/java/mage/client/draft/DraftPanel.java index ce5a118398..56b22b9b38 100644 --- a/Mage.Client/src/main/java/mage/client/draft/DraftPanel.java +++ b/Mage.Client/src/main/java/mage/client/draft/DraftPanel.java @@ -328,7 +328,7 @@ public class DraftPanel extends javax.swing.JPanel { if (view != null) { loadCardsToPickedCardsArea(view.getPicks()); draftBooster.loadBooster(EMPTY_VIEW, bigCard); - Plugins.getInstance().getActionCallback().hideOpenComponents(); + Plugins.instance.getActionCallback().hideOpenComponents(); setMessage("Waiting for other players"); } } @@ -340,8 +340,8 @@ public class DraftPanel extends javax.swing.JPanel { ); setMessage("Pick a card"); if (!MageFrame.getInstance().isActive()) { - MageTray.getInstance().displayMessage("Pick the next card."); - MageTray.getInstance().blink(); + MageTray.instance.displayMessage("Pick the next card."); + MageTray.instance.blink(); } countdown.stop(); this.timeout = draftPickView.getTimeout(); diff --git a/Mage.Client/src/main/java/mage/client/game/BattlefieldPanel.java b/Mage.Client/src/main/java/mage/client/game/BattlefieldPanel.java index b5a90c9da6..1b7167bf28 100644 --- a/Mage.Client/src/main/java/mage/client/game/BattlefieldPanel.java +++ b/Mage.Client/src/main/java/mage/client/game/BattlefieldPanel.java @@ -252,8 +252,8 @@ public class BattlefieldPanel extends javax.swing.JLayeredPane { if (cardDimension == null) { cardDimension = new Dimension(Config.dimensions.frameWidth, Config.dimensions.frameHeight); } - final MagePermanent perm = Plugins.getInstance().getMagePermanent(permanent, bigCard, cardDimension, gameId, true); - if (!Plugins.getInstance().isCardPluginLoaded()) { + final MagePermanent perm = Plugins.instance.getMagePermanent(permanent, bigCard, cardDimension, gameId, true); + if (!Plugins.instance.isCardPluginLoaded()) { //perm.setBounds(findEmptySpace(new Dimension(Config.dimensions.frameWidth, Config.dimensions.frameHeight))); } else { //perm.setAlpha(0); @@ -262,12 +262,12 @@ public class BattlefieldPanel extends javax.swing.JLayeredPane { BattlefieldPanel.this.jPanel.add(perm, 10); //this.jPanel.add(perm); - if (!Plugins.getInstance().isCardPluginLoaded()) { + if (!Plugins.instance.isCardPluginLoaded()) { moveToFront(perm); perm.update(permanent); } else { moveToFront(jPanel); - Plugins.getInstance().onAddCard(perm, 1); + Plugins.instance.onAddCard(perm, 1); /*Thread t = new Thread(new Runnable() { @Override public void run() { @@ -299,7 +299,7 @@ public class BattlefieldPanel extends javax.swing.JLayeredPane { } else if (comp instanceof MagePermanent) { if (((MagePermanent) comp).getOriginal().getId().equals(permanentId)) { Thread t = new Thread(() -> { - Plugins.getInstance().onRemoveCard((MagePermanent) comp, count); + Plugins.instance.onRemoveCard((MagePermanent) comp, count); comp.setVisible(false); BattlefieldPanel.this.jPanel.remove(comp); }); diff --git a/Mage.Client/src/main/java/mage/client/game/GamePanel.java b/Mage.Client/src/main/java/mage/client/game/GamePanel.java index 7604e43c97..700a750685 100644 --- a/Mage.Client/src/main/java/mage/client/game/GamePanel.java +++ b/Mage.Client/src/main/java/mage/client/game/GamePanel.java @@ -219,7 +219,7 @@ public final class GamePanel extends javax.swing.JPanel { jLayeredBackgroundPane.add(jSplitPane0, JLayeredPane.DEFAULT_LAYER); Map myUi = getUIComponents(jLayeredBackgroundPane); - Plugins.getInstance().updateGamePanel(myUi); + Plugins.instance.updateGamePanel(myUi); // Enlarge jlayeredpane on resize of game panel addComponentListener(new ComponentAdapter() { @@ -332,7 +332,7 @@ public final class GamePanel extends javax.swing.JPanel { pickTargetDialog.cleanUp(); pickTargetDialog.removeDialog(); } - Plugins.getInstance().getActionCallback().hideOpenComponents(); + Plugins.instance.getActionCallback().hideOpenComponents(); try { Component popupContainer = MageFrame.getUI().getComponent(MageComponents.POPUP_CONTAINER); popupContainer.setVisible(false); @@ -839,7 +839,7 @@ public final class GamePanel extends javax.swing.JPanel { gamePane.setTitle(sb.toString()); } - GameManager.getInstance().setStackSize(game.getStack().size()); + GameManager.instance.setStackSize(game.getStack().size()); displayStack(game, bigCard, feedbackPanel, gameId); for (ExileView exile : game.getExile()) { @@ -902,7 +902,7 @@ public final class GamePanel extends javax.swing.JPanel { this.repaint(); } - static final int BORDER_SIZE = 2; + private static final int BORDER_SIZE = 2; private void updateSkipButtons(boolean turn, boolean endOfTurn, boolean nextMain, boolean allTurns, boolean stack, boolean endStepBeforeYourStep) { if (turn) { //F4 @@ -1249,7 +1249,7 @@ public final class GamePanel extends javax.swing.JPanel { } private void hideAll() { - ActionCallback callback = Plugins.getInstance().getActionCallback(); + ActionCallback callback = Plugins.instance.getActionCallback(); ((MageActionCallback) callback).hideGameUpdate(gameId); } @@ -1442,7 +1442,7 @@ public final class GamePanel extends javax.swing.JPanel { btnCancelSkip.setContentAreaFilled(false); btnCancelSkip.setBorder(new EmptyBorder(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE)); - btnCancelSkip.setIcon(new ImageIcon(ImageManagerImpl.getInstance().getCancelSkipButtonImage())); + btnCancelSkip.setIcon(new ImageIcon(ImageManagerImpl.instance.getCancelSkipButtonImage())); btnCancelSkip.setToolTipText("Cancel all skip actions (" + getCachedKeyText(KEY_CONTROL_CANCEL_SKIP) + ")."); btnCancelSkip.setFocusable(false); @@ -1457,7 +1457,7 @@ public final class GamePanel extends javax.swing.JPanel { btnSkipToNextTurn.setContentAreaFilled(false); btnSkipToNextTurn.setBorder(new EmptyBorder(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE)); - btnSkipToNextTurn.setIcon(new ImageIcon(ImageManagerImpl.getInstance().getSkipNextTurnButtonImage())); + btnSkipToNextTurn.setIcon(new ImageIcon(ImageManagerImpl.instance.getSkipNextTurnButtonImage())); btnSkipToNextTurn.setToolTipText("Skip to next turn (" + getCachedKeyText(KEY_CONTROL_NEXT_TURN) + ")."); btnSkipToNextTurn.setFocusable(false); @@ -1481,7 +1481,7 @@ public final class GamePanel extends javax.swing.JPanel { btnSkipToEndTurn.setContentAreaFilled(false); btnSkipToEndTurn.setBorder(new EmptyBorder(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE)); - btnSkipToEndTurn.setIcon(new ImageIcon(ImageManagerImpl.getInstance().getSkipEndTurnButtonImage())); + btnSkipToEndTurn.setIcon(new ImageIcon(ImageManagerImpl.instance.getSkipEndTurnButtonImage())); btnSkipToEndTurn.setToolTipText("Skip to (opponents/next) end of turn step (" + getCachedKeyText(KEY_CONTROL_END_STEP) + ") - adjust using preferences."); btnSkipToEndTurn.setFocusable(false); @@ -1514,7 +1514,7 @@ public final class GamePanel extends javax.swing.JPanel { btnSkipToNextMain.setContentAreaFilled(false); btnSkipToNextMain.setBorder(new EmptyBorder(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE)); - btnSkipToNextMain.setIcon(new ImageIcon(ImageManagerImpl.getInstance().getSkipMainButtonImage())); + btnSkipToNextMain.setIcon(new ImageIcon(ImageManagerImpl.instance.getSkipMainButtonImage())); btnSkipToNextMain.setToolTipText("Skip to (your) next main phase (" + getCachedKeyText(KEY_CONTROL_MAIN_STEP) + ") - adjust using preferences."); btnSkipToNextMain.setFocusable(false); @@ -1538,7 +1538,7 @@ public final class GamePanel extends javax.swing.JPanel { btnSkipToYourTurn.setContentAreaFilled(false); btnSkipToYourTurn.setBorder(new EmptyBorder(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE)); - btnSkipToYourTurn.setIcon(new ImageIcon(ImageManagerImpl.getInstance().getSkipYourNextTurnButtonImage())); + btnSkipToYourTurn.setIcon(new ImageIcon(ImageManagerImpl.instance.getSkipYourNextTurnButtonImage())); btnSkipToYourTurn.setToolTipText("Skip to your next turn (" + getCachedKeyText(KEY_CONTROL_YOUR_TURN) + ")."); btnSkipToYourTurn.setFocusable(false); @@ -1562,7 +1562,7 @@ public final class GamePanel extends javax.swing.JPanel { btnSkipToEndStepBeforeYourTurn.setContentAreaFilled(false); btnSkipToEndStepBeforeYourTurn.setBorder(new EmptyBorder(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE)); - btnSkipToEndStepBeforeYourTurn.setIcon(new ImageIcon(ImageManagerImpl.getInstance().getSkipEndStepBeforeYourTurnButtonImage())); + btnSkipToEndStepBeforeYourTurn.setIcon(new ImageIcon(ImageManagerImpl.instance.getSkipEndStepBeforeYourTurnButtonImage())); btnSkipToEndStepBeforeYourTurn.setToolTipText("Skip to the end step before your turn (" + getCachedKeyText(KEY_CONTROL_PRIOR_END) + ") - adjust using preferences."); btnSkipToEndStepBeforeYourTurn.setFocusable(false); @@ -1586,7 +1586,7 @@ public final class GamePanel extends javax.swing.JPanel { btnSkipStack.setContentAreaFilled(false); btnSkipStack.setBorder(new EmptyBorder(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE)); - btnSkipStack.setIcon(new ImageIcon(ImageManagerImpl.getInstance().getSkipStackButtonImage())); + btnSkipStack.setIcon(new ImageIcon(ImageManagerImpl.instance.getSkipStackButtonImage())); btnSkipStack.setToolTipText("Skip until stack is resolved (" + getCachedKeyText(KEY_CONTROL_SKIP_STACK) + ")."); btnSkipStack.setFocusable(false); @@ -1610,7 +1610,7 @@ public final class GamePanel extends javax.swing.JPanel { btnConcede.setContentAreaFilled(false); btnConcede.setBorder(new EmptyBorder(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE)); - btnConcede.setIcon(new ImageIcon(ImageManagerImpl.getInstance().getConcedeButtonImage())); + btnConcede.setIcon(new ImageIcon(ImageManagerImpl.instance.getConcedeButtonImage())); btnConcede.setToolTipText("Concede the current game."); btnConcede.setFocusable(false); btnConcede.addMouseListener(new MouseAdapter() { @@ -1638,7 +1638,7 @@ public final class GamePanel extends javax.swing.JPanel { this.getActionMap().put("ENLARGE", new AbstractAction() { @Override public void actionPerformed(ActionEvent actionEvent) { - ActionCallback callback = Plugins.getInstance().getActionCallback(); + ActionCallback callback = Plugins.instance.getActionCallback(); ((MageActionCallback) callback).enlargeCard(EnlargeMode.NORMAL); } }); @@ -1648,7 +1648,7 @@ public final class GamePanel extends javax.swing.JPanel { this.getActionMap().put("ENLARGE_SOURCE", new AbstractAction() { @Override public void actionPerformed(ActionEvent actionEvent) { - ActionCallback callback = Plugins.getInstance().getActionCallback(); + ActionCallback callback = Plugins.instance.getActionCallback(); ((MageActionCallback) callback).enlargeCard(EnlargeMode.ALTERNATE); } }); @@ -1697,7 +1697,7 @@ public final class GamePanel extends javax.swing.JPanel { this.getActionMap().put("ENLARGE_RELEASE", new AbstractAction() { @Override public void actionPerformed(ActionEvent actionEvent) { - ActionCallback callback = Plugins.getInstance().getActionCallback(); + ActionCallback callback = Plugins.instance.getActionCallback(); ((MageActionCallback) callback).hideEnlargedCard(); } }); @@ -1718,7 +1718,7 @@ public final class GamePanel extends javax.swing.JPanel { btnSwitchHands.setContentAreaFilled(false); btnSwitchHands.setBorder(new EmptyBorder(0, 0, 0, 0)); - btnSwitchHands.setIcon(new ImageIcon(ImageManagerImpl.getInstance().getSwitchHandsButtonImage())); + btnSwitchHands.setIcon(new ImageIcon(ImageManagerImpl.instance.getSwitchHandsButtonImage())); btnSwitchHands.setFocusable(false); btnSwitchHands.setToolTipText("Switch between your hand cards and hand cards of controlled players."); btnSwitchHands.addMouseListener(new MouseAdapter() { @@ -1732,7 +1732,7 @@ public final class GamePanel extends javax.swing.JPanel { btnStopWatching.setContentAreaFilled(false); btnStopWatching.setBorder(new EmptyBorder(0, 0, 0, 0)); - btnStopWatching.setIcon(new ImageIcon(ImageManagerImpl.getInstance().getStopWatchButtonImage())); + btnStopWatching.setIcon(new ImageIcon(ImageManagerImpl.instance.getStopWatchButtonImage())); btnStopWatching.setFocusable(false); btnStopWatching.setToolTipText("Stop watching this game."); btnStopWatching.addMouseListener(new MouseAdapter() { @@ -2192,7 +2192,7 @@ public final class GamePanel extends javax.swing.JPanel { hoverButtons = new LinkedHashMap<>(); } Rectangle rect = new Rectangle(36, 36); - HoverButton button = new HoverButton("", ImageManagerImpl.getInstance().getPhaseImage(name), rect); + HoverButton button = new HoverButton("", ImageManagerImpl.instance.getPhaseImage(name), rect); button.setToolTipText(name.replaceAll("_", " ")); button.setPreferredSize(new Dimension(36, 36)); button.addMouseListener(mouseAdapter); diff --git a/Mage.Client/src/main/java/mage/client/plugins/adapters/MageActionCallback.java b/Mage.Client/src/main/java/mage/client/plugins/adapters/MageActionCallback.java index 31ed09a63c..baddaf08b1 100644 --- a/Mage.Client/src/main/java/mage/client/plugins/adapters/MageActionCallback.java +++ b/Mage.Client/src/main/java/mage/client/plugins/adapters/MageActionCallback.java @@ -106,7 +106,7 @@ public class MageActionCallback implements ActionCallback { public synchronized void refreshSession() { if (cardInfoPane == null) { - cardInfoPane = Plugins.getInstance().getCardInfoPane(); + cardInfoPane = Plugins.instance.getCardInfoPane(); } } @@ -268,7 +268,7 @@ public class MageActionCallback implements ActionCallback { @Override public void mouseMoved(MouseEvent e, TransferData transferData) { - if (!Plugins.getInstance().isCardPluginLoaded()) { + if (!Plugins.instance.isCardPluginLoaded()) { return; } if (!popupData.card.equals(transferData.card)) { diff --git a/Mage.Client/src/main/java/mage/client/plugins/impl/Plugins.java b/Mage.Client/src/main/java/mage/client/plugins/impl/Plugins.java index 47a0ec9456..1fd7a2e725 100644 --- a/Mage.Client/src/main/java/mage/client/plugins/impl/Plugins.java +++ b/Mage.Client/src/main/java/mage/client/plugins/impl/Plugins.java @@ -8,6 +8,7 @@ import java.util.HashMap; import java.util.Map; import java.util.UUID; import javax.swing.JComponent; + import mage.cards.MageCard; import mage.cards.MagePermanent; import mage.cards.action.ActionCallback; @@ -31,11 +32,10 @@ import org.apache.log4j.Logger; import org.mage.plugins.card.CardPluginImpl; import org.mage.plugins.theme.ThemePluginImpl; -public class Plugins implements MagePlugins { - +public enum Plugins implements MagePlugins { + instance; public static final String PLUGINS_DIRECTORY = "plugins/"; - private static final MagePlugins instance = new Plugins(); private static final Logger LOGGER = Logger.getLogger(Plugins.class); private static PluginManager pm; @@ -45,9 +45,6 @@ public class Plugins implements MagePlugins { private static final MageActionCallback mageActionCallback = new MageActionCallback(); private final Map sortingOptions = new HashMap<>(); - public static MagePlugins getInstance() { - return instance; - } @Override public void loadPlugins() { diff --git a/Mage.Client/src/main/java/mage/client/remote/CallbackClientImpl.java b/Mage.Client/src/main/java/mage/client/remote/CallbackClientImpl.java index 3185af1bee..af2a653105 100644 --- a/Mage.Client/src/main/java/mage/client/remote/CallbackClientImpl.java +++ b/Mage.Client/src/main/java/mage/client/remote/CallbackClientImpl.java @@ -87,7 +87,7 @@ public class CallbackClientImpl implements CallbackClient { switch (callback.getMethod()) { case "startGame": { TableClientMessage message = (TableClientMessage) callback.getData(); - GameManager.getInstance().setCurrentPlayerUUID(message.getPlayerId()); + GameManager.instance.setCurrentPlayerUUID(message.getPlayerId()); gameStarted(message.getGameId(), message.getPlayerId()); break; } @@ -457,8 +457,8 @@ public class CallbackClientImpl implements CallbackClient { handleException(ex); } - if (Plugins.getInstance().isCounterPluginLoaded()) { - Plugins.getInstance().addGamesPlayed(); + if (Plugins.instance.isCounterPluginLoaded()) { + Plugins.instance.addGamesPlayed(); } } diff --git a/Mage.Client/src/main/java/mage/client/table/TablesPane.java b/Mage.Client/src/main/java/mage/client/table/TablesPane.java index dad29c460f..30600ae3c7 100644 --- a/Mage.Client/src/main/java/mage/client/table/TablesPane.java +++ b/Mage.Client/src/main/java/mage/client/table/TablesPane.java @@ -45,9 +45,9 @@ public class TablesPane extends MagePane { */ public TablesPane() { boolean initialized = false; - if (Plugins.getInstance().isThemePluginLoaded()) { + if (Plugins.instance.isThemePluginLoaded()) { tablesPanel = new mage.client.table.TablesPanel(); - JComponent container = Plugins.getInstance().updateTablePanel(tablesPanel.getUIComponents()); + JComponent container = Plugins.instance.updateTablePanel(tablesPanel.getUIComponents()); if (container != null) { initComponents(container); container.add(tablesPanel); diff --git a/Mage.Client/src/main/java/mage/client/util/GameManager.java b/Mage.Client/src/main/java/mage/client/util/GameManager.java index 081014d478..a796174e44 100644 --- a/Mage.Client/src/main/java/mage/client/util/GameManager.java +++ b/Mage.Client/src/main/java/mage/client/util/GameManager.java @@ -7,12 +7,8 @@ import java.util.UUID; * * @author nantuko */ -public class GameManager { - private static final GameManager instance = new GameManager(); - - public static GameManager getInstance() { - return instance; - } +public enum GameManager { + instance; public void setStackSize(int stackSize) { this.stackSize = stackSize; diff --git a/Mage.Client/src/main/java/mage/client/util/SettingsManager.java b/Mage.Client/src/main/java/mage/client/util/SettingsManager.java index bb0062f7f9..4b76553aa4 100644 --- a/Mage.Client/src/main/java/mage/client/util/SettingsManager.java +++ b/Mage.Client/src/main/java/mage/client/util/SettingsManager.java @@ -9,12 +9,8 @@ import org.mage.card.arcane.CardPanel; * * @author nantuko */ -public class SettingsManager { - private static final SettingsManager instance = new SettingsManager(); - - public static SettingsManager getInstance() { - return instance; - } +public enum SettingsManager { + instance; public int getScreenWidth() { return screenWidth; diff --git a/Mage.Client/src/main/java/mage/client/util/layout/impl/OldCardLayoutStrategy.java b/Mage.Client/src/main/java/mage/client/util/layout/impl/OldCardLayoutStrategy.java index 84201c3189..13890e801a 100644 --- a/Mage.Client/src/main/java/mage/client/util/layout/impl/OldCardLayoutStrategy.java +++ b/Mage.Client/src/main/java/mage/client/util/layout/impl/OldCardLayoutStrategy.java @@ -35,7 +35,7 @@ public class OldCardLayoutStrategy implements CardLayoutStrategy { Map permanents = battlefieldPanel.getPermanents(); JLayeredPane jPanel = battlefieldPanel.getMainPanel(); - int height = Plugins.getInstance().sortPermanents(battlefieldPanel.getUiComponentsList(), permanents.values(), battlefieldPanel.isTopPanelBattlefield()); + int height = Plugins.instance.sortPermanents(battlefieldPanel.getUiComponentsList(), permanents.values(), battlefieldPanel.isTopPanelBattlefield()); jPanel.setPreferredSize(new Dimension(width - 30, height)); for (PermanentView permanent : battlefieldPanel.getBattlefield().values()) { @@ -54,7 +54,7 @@ public class OldCardLayoutStrategy implements CardLayoutStrategy { int position = jLayeredPane.getPosition(perm); perm.getLinks().clear(); Rectangle rectangleBaseCard = perm.getBounds(); - if (!Plugins.getInstance().isCardPluginLoaded()) { + if (!Plugins.instance.isCardPluginLoaded()) { for (UUID attachmentId : permanent.getAttachments()) { MagePermanent link = permanents.get(attachmentId); if (link != null) { diff --git a/Mage.Client/src/main/java/org/mage/card/arcane/CardPanel.java b/Mage.Client/src/main/java/org/mage/card/arcane/CardPanel.java index 0483922aa1..fd32e3d393 100644 --- a/Mage.Client/src/main/java/org/mage/card/arcane/CardPanel.java +++ b/Mage.Client/src/main/java/org/mage/card/arcane/CardPanel.java @@ -136,7 +136,7 @@ public abstract class CardPanel extends MagePermanent implements MouseListener, dayNightButton = new JButton(""); dayNightButton.setSize(32, 32); dayNightButton.setToolTipText("This permanent is a double faced card. To see the back face card, push this button or turn mouse wheel down while hovering with the mouse pointer over the permanent."); - BufferedImage day = ImageManagerImpl.getInstance().getDayImage(); + BufferedImage day = ImageManagerImpl.instance.getDayImage(); dayNightButton.setIcon(new ImageIcon(day)); dayNightButton.addActionListener(e -> { // if card is being rotated, ignore action performed @@ -159,9 +159,9 @@ public abstract class CardPanel extends MagePermanent implements MouseListener, showCopySourceButton.setSize(32, 32); showCopySourceButton.setToolTipText("This permanent is copying a target. To see original card, push this button or turn mouse wheel down while hovering with the mouse pointer over the permanent."); showCopySourceButton.setVisible(((PermanentView) this.gameCard).isCopy()); - showCopySourceButton.setIcon(new ImageIcon(ImageManagerImpl.getInstance().getCopyInformIconImage())); + showCopySourceButton.setIcon(new ImageIcon(ImageManagerImpl.instance.getCopyInformIconImage())); showCopySourceButton.addActionListener(e -> { - ActionCallback callback1 = Plugins.getInstance().getActionCallback(); + ActionCallback callback1 = Plugins.instance.getActionCallback(); ((MageActionCallback) callback1).enlargeCard(EnlargeMode.COPY); }); @@ -553,9 +553,9 @@ public abstract class CardPanel extends MagePermanent implements MouseListener, if (card.canTransform()) { BufferedImage transformIcon; if (isTransformed() || card.isTransformed()) { - transformIcon = ImageManagerImpl.getInstance().getNightImage(); + transformIcon = ImageManagerImpl.instance.getNightImage(); } else { - transformIcon = ImageManagerImpl.getInstance().getDayImage(); + transformIcon = ImageManagerImpl.instance.getDayImage(); } if (dayNightButton != null) { dayNightButton.setVisible(!isPermanent); @@ -763,7 +763,7 @@ public abstract class CardPanel extends MagePermanent implements MouseListener, this.transformed = !this.transformed; if (transformed) { if (dayNightButton != null) { // if transformbable card is copied, button can be null - BufferedImage night = ImageManagerImpl.getInstance().getNightImage(); + BufferedImage night = ImageManagerImpl.instance.getNightImage(); dayNightButton.setIcon(new ImageIcon(night)); } if (this.gameCard.getSecondCardFace() == null) { @@ -776,7 +776,7 @@ public abstract class CardPanel extends MagePermanent implements MouseListener, } } else { if (dayNightButton != null) { // if transformbable card is copied, button can be null - BufferedImage day = ImageManagerImpl.getInstance().getDayImage(); + BufferedImage day = ImageManagerImpl.instance.getDayImage(); dayNightButton.setIcon(new ImageIcon(day)); } if (!isPermanent) { // use only for custom transformation (when pressing day-night button) diff --git a/Mage.Client/src/main/java/org/mage/card/arcane/CardPanelComponentImpl.java b/Mage.Client/src/main/java/org/mage/card/arcane/CardPanelComponentImpl.java index 1e9e227f62..5319493b3d 100644 --- a/Mage.Client/src/main/java/org/mage/card/arcane/CardPanelComponentImpl.java +++ b/Mage.Client/src/main/java/org/mage/card/arcane/CardPanelComponentImpl.java @@ -207,15 +207,15 @@ public class CardPanelComponentImpl extends CardPanel { // Ability icon if (newGameCard.isAbility()) { if (newGameCard.getAbilityType() == AbilityType.TRIGGERED) { - setTypeIcon(ImageManagerImpl.getInstance().getTriggeredAbilityImage(), "Triggered Ability"); + setTypeIcon(ImageManagerImpl.instance.getTriggeredAbilityImage(), "Triggered Ability"); } else if (newGameCard.getAbilityType() == AbilityType.ACTIVATED) { - setTypeIcon(ImageManagerImpl.getInstance().getActivatedAbilityImage(), "Activated Ability"); + setTypeIcon(ImageManagerImpl.instance.getActivatedAbilityImage(), "Activated Ability"); } } // Token icon if (this.gameCard.isToken()) { - setTypeIcon(ImageManagerImpl.getInstance().getTokenIconImage(), "Token Permanent"); + setTypeIcon(ImageManagerImpl.instance.getTokenIconImage(), "Token Permanent"); } displayTitleAnyway = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_SHOW_CARD_NAMES, "true").equals("true"); @@ -243,7 +243,7 @@ public class CardPanelComponentImpl extends CardPanel { add(ptText); // Sickness overlay - BufferedImage sickness = ImageManagerImpl.getInstance().getSicknessImage(); + BufferedImage sickness = ImageManagerImpl.instance.getSicknessImage(); overlayPanel = new ImagePanel(sickness, ImagePanelStyle.SCALED); overlayPanel.setOpaque(false); add(overlayPanel); @@ -620,21 +620,21 @@ public class CardPanelComponentImpl extends CardPanel { case "+1/+1": if (counterView.getCount() != plusCounter) { plusCounter = counterView.getCount(); - plusCounterLabel.setIcon(getCounterImageWithAmount(plusCounter, ImageManagerImpl.getInstance().getCounterImageGreen(), getCardWidth())); + plusCounterLabel.setIcon(getCounterImageWithAmount(plusCounter, ImageManagerImpl.instance.getCounterImageGreen(), getCardWidth())); } plusCounterLabel.setVisible(true); break; case "-1/-1": if (counterView.getCount() != minusCounter) { minusCounter = counterView.getCount(); - minusCounterLabel.setIcon(getCounterImageWithAmount(minusCounter, ImageManagerImpl.getInstance().getCounterImageRed(), getCardWidth())); + minusCounterLabel.setIcon(getCounterImageWithAmount(minusCounter, ImageManagerImpl.instance.getCounterImageRed(), getCardWidth())); } minusCounterLabel.setVisible(true); break; case "loyalty": if (counterView.getCount() != loyaltyCounter) { loyaltyCounter = counterView.getCount(); - loyaltyCounterLabel.setIcon(getCounterImageWithAmount(loyaltyCounter, ImageManagerImpl.getInstance().getCounterImageViolet(), getCardWidth())); + loyaltyCounterLabel.setIcon(getCounterImageWithAmount(loyaltyCounter, ImageManagerImpl.instance.getCounterImageViolet(), getCardWidth())); } loyaltyCounterLabel.setVisible(true); break; @@ -643,7 +643,7 @@ public class CardPanelComponentImpl extends CardPanel { name = counterView.getName(); otherCounter = counterView.getCount(); otherCounterLabel.setToolTipText(name); - otherCounterLabel.setIcon(getCounterImageWithAmount(otherCounter, ImageManagerImpl.getInstance().getCounterImageGrey(), getCardWidth())); + otherCounterLabel.setIcon(getCounterImageWithAmount(otherCounter, ImageManagerImpl.instance.getCounterImageGrey(), getCardWidth())); otherCounterLabel.setVisible(true); } } diff --git a/Mage.Client/src/main/java/org/mage/plugins/card/utils/impl/ImageManagerImpl.java b/Mage.Client/src/main/java/org/mage/plugins/card/utils/impl/ImageManagerImpl.java index f6de00cdc1..9b08854b3f 100644 --- a/Mage.Client/src/main/java/org/mage/plugins/card/utils/impl/ImageManagerImpl.java +++ b/Mage.Client/src/main/java/org/mage/plugins/card/utils/impl/ImageManagerImpl.java @@ -17,15 +17,11 @@ import mage.client.util.gui.BufferedImageBuilder; import org.mage.plugins.card.utils.ImageManager; import org.mage.plugins.card.utils.Transparency; -public class ImageManagerImpl implements ImageManager { +public enum ImageManagerImpl implements ImageManager { + instance; - private static final ImageManagerImpl instance = new ImageManagerImpl(); - - public static ImageManagerImpl getInstance() { - return instance; - } - public ImageManagerImpl() { + ImageManagerImpl() { init(); }