diff --git a/.gitattributes b/.gitattributes index 85c214cc353..57c09a0072d 100644 --- a/.gitattributes +++ b/.gitattributes @@ -15034,6 +15034,7 @@ src/main/java/forge/gui/toolbox/FAbsolutePositioner.java -text src/main/java/forge/gui/toolbox/FButton.java -text src/main/java/forge/gui/toolbox/FCheckBox.java -text src/main/java/forge/gui/toolbox/FComboBoxPanel.java -text +src/main/java/forge/gui/toolbox/FComboBoxWrapper.java -text src/main/java/forge/gui/toolbox/FLabel.java -text src/main/java/forge/gui/toolbox/FList.java -text src/main/java/forge/gui/toolbox/FOverlay.java -text @@ -15145,7 +15146,6 @@ src/main/java/forge/net/protocol/toserver/IPacketSrv.java -text src/main/java/forge/net/protocol/toserver/IncorrectPacketSrv.java -text src/main/java/forge/net/protocol/toserver/package-info.java -text src/main/java/forge/package-info.java svneol=native#text/plain -src/main/java/forge/properties/ForgeLookAndFeel.java -text src/main/java/forge/properties/ForgePreferences.java svneol=native#text/plain src/main/java/forge/properties/NewConstants.java svneol=native#text/plain src/main/java/forge/properties/Preferences.java svneol=native#text/plain diff --git a/CHANGES.txt b/CHANGES.txt index ccfa7f7a11b..ae0f47fe7b3 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -11,6 +11,8 @@ Release Notes - Commander - The Commander gaming mode has been added and is located in the Variant view. This is a work in progress and is not finished at this time. You are invited to play test this variant. +- Switch Theme/Skin Without Restart - +You can now switch between themes/skins from any screen without restarting via Layout > Theme on main menu or via combo box on Preferences page of Home screen - Card Overlays - Card overlays are now always displayed regardless of card image size if the display card overlays option is turned on in your user preferences. diff --git a/src/main/java/forge/ImageCache.java b/src/main/java/forge/ImageCache.java index 36b49dfa6f1..ce21f25fd6b 100644 --- a/src/main/java/forge/ImageCache.java +++ b/src/main/java/forge/ImageCache.java @@ -25,8 +25,6 @@ import java.util.Set; import java.util.concurrent.ExecutionException; import javax.imageio.ImageIO; -import javax.swing.ImageIcon; - import org.apache.commons.lang3.StringUtils; import com.google.common.cache.CacheBuilder; @@ -39,6 +37,7 @@ import forge.card.CardRules; import forge.card.CardSplitType; import forge.game.player.IHasIcon; import forge.gui.toolbox.FSkin; +import forge.gui.toolbox.FSkin.SkinIcon; import forge.item.BoosterPack; import forge.item.PaperCard; import forge.item.PaperToken; @@ -125,7 +124,7 @@ public class ImageCache { * retrieve an icon from the cache. returns the current skin's ICO_UNKNOWN if the icon image is not found * in the cache and cannot be loaded from disk. */ - public static ImageIcon getIcon(IHasIcon ihi) { + public static SkinIcon getIcon(IHasIcon ihi) { String imageKey = ihi.getIconImageKey(); final BufferedImage i; if (_missingIconKeys.contains(imageKey) || @@ -133,7 +132,7 @@ public class ImageCache { _missingIconKeys.add(imageKey); return FSkin.getIcon(FSkin.InterfaceIcons.ICO_UNKNOWN); } - return new ImageIcon(i); + return new FSkin.UnskinnedIcon(i); } /** diff --git a/src/main/java/forge/control/FControl.java b/src/main/java/forge/control/FControl.java index c5a47e38d94..cf93b7d88c6 100644 --- a/src/main/java/forge/control/FControl.java +++ b/src/main/java/forge/control/FControl.java @@ -68,7 +68,6 @@ import forge.gui.menubar.FMenuBar; import forge.gui.menubar.MenuUtil; import forge.gui.toolbox.FSkin; import forge.net.FServer; -import forge.properties.ForgeLookAndFeel; import forge.properties.ForgePreferences; import forge.properties.ForgePreferences.FPref; import forge.properties.NewConstants; @@ -173,19 +172,14 @@ public enum FControl implements KeyEventDispatcher { * @param isHeadlessMode */ public void initialize() { // Preloads skin components (using progress bar). - FSkin.loadFull(); - - // This must be done here or at least between the skin being loaded - // and any GUI controls being created. - FSkin.setProgessBarMessage("Setting look and feel..."); - setForgeLookAndFeel(); + FSkin.loadFull(true); createMenuBar(); this.shortcuts = KeyboardShortcuts.attachKeyboardShortcuts(); this.display = FView.SINGLETON_INSTANCE.getLpnDocument(); - FSkin.setProgessBarMessage("About to load current quest."); + FView.SINGLETON_INSTANCE.setSplashProgessBarMessage("About to load current quest."); // Preload quest data if present final File dirQuests = new File(NewConstants.QUEST_SAVE_DIR); final String questname = Singletons.getModel().getQuestPreferences().getPref(QPref.CURRENT_QUEST); @@ -213,7 +207,7 @@ public enum FControl implements KeyEventDispatcher { setGlobalKeyboardHandler(); - FSkin.setProgessBarMessage("Opening main window..."); + FView.SINGLETON_INSTANCE.setSplashProgessBarMessage("Opening main window..."); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { Singletons.getView().initialize(); } }); } @@ -223,11 +217,6 @@ public enum FControl implements KeyEventDispatcher { manager.addKeyEventDispatcher(this); } - private void setForgeLookAndFeel() { - ForgeLookAndFeel laf = new ForgeLookAndFeel(); - laf.setForgeLookAndFeel(Singletons.getView().getFrame()); - } - private void createMenuBar() { this.menuBar = new FMenuBar(Singletons.getView().getFrame()); this.menuBar.setVisible(MenuUtil.isMenuBarVisible()); diff --git a/src/main/java/forge/gui/CardDetailPanel.java b/src/main/java/forge/gui/CardDetailPanel.java index fe41b202a0e..1a611c4bacb 100644 --- a/src/main/java/forge/gui/CardDetailPanel.java +++ b/src/main/java/forge/gui/CardDetailPanel.java @@ -91,8 +91,9 @@ public class CardDetailPanel extends FPanel { labelConstrains.weightx = 1.0; final JPanel cdLabels = new JPanel(new GridLayout(0, 1, 0, 5)); - cdLabels.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME)); - cdLabels.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); + final FSkin.JComponentSkin cdLabelsSkin = FSkin.get(cdLabels); + cdLabelsSkin.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME)); + cdLabelsSkin.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); this.nameCostLabel = new FLabel.Builder().build(); this.typeLabel = new FLabel.Builder().build(); this.powerToughnessLabel = new FLabel.Builder().build(); @@ -101,8 +102,9 @@ public class CardDetailPanel extends FPanel { cdLabels.add(this.powerToughnessLabel); final JPanel idr = new JPanel(new GridBagLayout()); - idr.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME)); - idr.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); + FSkin.JComponentSkin idrSkin = FSkin.get(idr); + idrSkin.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME)); + idrSkin.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); final GridBagConstraints c1 = new GridBagConstraints(); final GridBagConstraints c2 = new GridBagConstraints(); diff --git a/src/main/java/forge/gui/CardPicturePanel.java b/src/main/java/forge/gui/CardPicturePanel.java index c54fe0667e9..26589a1fa60 100644 --- a/src/main/java/forge/gui/CardPicturePanel.java +++ b/src/main/java/forge/gui/CardPicturePanel.java @@ -27,6 +27,8 @@ import forge.Card; import forge.CardCharacteristicName; import forge.ImageCache; import forge.Singletons; +import forge.gui.toolbox.FSkin; +import forge.gui.toolbox.FSkin.JComponentSkin; import forge.gui.toolbox.imaging.FImagePanel; import forge.gui.toolbox.imaging.FImagePanel.AutoSizeImageMode; import forge.gui.toolbox.imaging.FImageUtil; @@ -46,12 +48,14 @@ public final class CardPicturePanel extends JPanel { private Object displayed; private final FImagePanel panel; + private final JComponentSkin panelSkin; private BufferedImage currentImage; public CardPicturePanel() { super(new BorderLayout()); this.panel = new FImagePanel(); + this.panelSkin = FSkin.get(this.panel); this.add(this.panel); } @@ -67,7 +71,7 @@ public final class CardPicturePanel extends JPanel { } public void setCardImage(CardCharacteristicName flipState) { - BufferedImage image = FImageUtil.getImage((Card)displayed, flipState); + BufferedImage image = FImageUtil.getImage((Card)displayed, flipState, this.panelSkin); if (image != null && image != this.currentImage) { this.currentImage = image; this.panel.setImage(image, getAutoSizeImageMode()); @@ -91,7 +95,7 @@ public final class CardPicturePanel extends JPanel { image = ImageCache.getOriginalImage(ImageCache.getImageKey(item, false), true); } else if (displayed instanceof Card) { - image = FImageUtil.getImage((Card)displayed); + image = FImageUtil.getImage((Card)displayed, this.panelSkin); } return image; diff --git a/src/main/java/forge/gui/DualListBox.java b/src/main/java/forge/gui/DualListBox.java index 01cad7c9fba..a1efcb3d9e8 100644 --- a/src/main/java/forge/gui/DualListBox.java +++ b/src/main/java/forge/gui/DualListBox.java @@ -77,8 +77,8 @@ public class DualListBox extends FPanel { setPreferredSize(new Dimension(650, 300)); setLayout(new GridLayout(0, 3)); - setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME)); - setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); + this.skin.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME)); + this.skin.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); final Runnable onAdd = new Runnable() { @SuppressWarnings("unchecked") diff --git a/src/main/java/forge/gui/FNetOverlay.java b/src/main/java/forge/gui/FNetOverlay.java index f69636e6bfd..91d4c2a37cc 100644 --- a/src/main/java/forge/gui/FNetOverlay.java +++ b/src/main/java/forge/gui/FNetOverlay.java @@ -7,7 +7,6 @@ import java.awt.event.ActionListener; import java.text.SimpleDateFormat; import java.util.Date; -import javax.swing.BorderFactory; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextArea; @@ -68,10 +67,11 @@ public enum FNetOverlay { * Semi-transparent overlay panel. Should be used with layered panes. */ private FNetOverlay() { + FSkin.JComponentSkin pnlSkin = FSkin.get(pnl); pnl.setOpaque(false); pnl.setVisible(false); - pnl.setBackground(FSkin.getColor(FSkin.Colors.CLR_ZEBRA)); - pnl.setBorder(BorderFactory.createLineBorder(FSkin.getColor(FSkin.Colors.CLR_BORDERS))); + pnlSkin.setBackground(FSkin.getColor(FSkin.Colors.CLR_ZEBRA)); + pnlSkin.setLineBorder(FSkin.getColor(FSkin.Colors.CLR_BORDERS)); pnl.setLayout(new MigLayout("insets 0, gap 0, ax center, wrap 2")); // pnl.add(new FLabel.Builder().text("Loading new game...").fontSize(22).build(), "h 40px!, align center"); @@ -80,7 +80,7 @@ public enum FNetOverlay { txtLog.setOpaque(true); txtLog.setFocusable(true); - txtLog.setBackground(FSkin.getColor(FSkin.Colors.CLR_ZEBRA)); + FSkin.get(txtLog).setBackground(FSkin.getColor(FSkin.Colors.CLR_ZEBRA)); JScrollPane _operationLogScroller = new JScrollPane(txtLog); _operationLogScroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); @@ -88,7 +88,7 @@ public enum FNetOverlay { new SmartScroller(_operationLogScroller); pnl.add(_operationLogScroller, "pushx, hmin 24, pushy, growy, growx, gap 2px 2px 2px 0, sx 2"); - txtInput.setBorder(BorderFactory.createLineBorder(FSkin.getColor(FSkin.Colors.CLR_BORDERS))); + FSkin.get(txtInput).setLineBorder(FSkin.getColor(FSkin.Colors.CLR_BORDERS)); pnl.add(txtInput, "pushx, growx, h 26px!, gap 2px 2px 2px 0"); pnl.add(cmdSend, "w 60px!, h 28px!, gap 0 0 2px 0"); diff --git a/src/main/java/forge/gui/ImportDialog.java b/src/main/java/forge/gui/ImportDialog.java index 26531b4eb1b..e3540371b2e 100644 --- a/src/main/java/forge/gui/ImportDialog.java +++ b/src/main/java/forge/gui/ImportDialog.java @@ -34,7 +34,6 @@ import java.util.Set; import java.util.TreeMap; import java.util.concurrent.ConcurrentSkipListMap; -import javax.swing.JComboBox; import javax.swing.JFileChooser; import javax.swing.JOptionPane; import javax.swing.JPanel; @@ -61,6 +60,7 @@ import forge.error.BugReporter; import forge.gui.ImportSourceAnalyzer.OpType; import forge.gui.toolbox.FButton; import forge.gui.toolbox.FCheckBox; +import forge.gui.toolbox.FComboBoxWrapper; import forge.gui.toolbox.FLabel; import forge.gui.toolbox.FOverlay; import forge.gui.toolbox.FPanel; @@ -307,7 +307,7 @@ public class ImportDialog { private final Runnable _onAnalyzerDone; private final boolean _isMigration; private final FLabel _unknownDeckLabel; - private final JComboBox<_UnknownDeckChoice> _unknownDeckCombo; + private final FComboBoxWrapper<_UnknownDeckChoice> _unknownDeckCombo; private final FCheckBox _moveCheckbox; private final FCheckBox _overwriteCheckbox; private final JTextArea _operationLog; @@ -340,7 +340,7 @@ public class ImportDialog { _addSelectionWidget(knownDeckPanel, OpType.UNKNOWN_DECK, "Unknown decks"); JPanel unknownDeckPanel = new JPanel(new MigLayout("insets 0, gap 5")); unknownDeckPanel.setOpaque(false); - _unknownDeckCombo = new JComboBox<_UnknownDeckChoice>(); + _unknownDeckCombo = new FComboBoxWrapper<_UnknownDeckChoice>(); _unknownDeckCombo.addItem(new _UnknownDeckChoice("Constructed", NewConstants.DECK_CONSTRUCTED_DIR)); _unknownDeckCombo.addItem(new _UnknownDeckChoice("Draft", NewConstants.DECK_DRAFT_DIR)); _unknownDeckCombo.addItem(new _UnknownDeckChoice("Planar", NewConstants.DECK_PLANE_DIR)); @@ -351,7 +351,7 @@ public class ImportDialog { }); _unknownDeckLabel = new FLabel.Builder().text("Treat unknown decks as:").build(); unknownDeckPanel.add(_unknownDeckLabel); - unknownDeckPanel.add(_unknownDeckCombo); + _unknownDeckCombo.addTo(unknownDeckPanel); knownDeckPanel.add(unknownDeckPanel, "span"); cbPanel.add(knownDeckPanel, "aligny top"); @@ -816,7 +816,7 @@ public class ImportDialog { private final boolean _move; private final boolean _overwrite; - public _Importer(String srcDir, Map>> selections, JComboBox<_UnknownDeckChoice> unknownDeckCombo, + public _Importer(String srcDir, Map>> selections, FComboBoxWrapper<_UnknownDeckChoice> unknownDeckCombo, JTextArea operationLog, JProgressBar progressBar, boolean move, boolean overwrite) { _srcDir = srcDir; _operationLog = operationLog; diff --git a/src/main/java/forge/gui/MouseUtil.java b/src/main/java/forge/gui/MouseUtil.java index a779ce7db89..0181165afff 100644 --- a/src/main/java/forge/gui/MouseUtil.java +++ b/src/main/java/forge/gui/MouseUtil.java @@ -25,5 +25,4 @@ public final class MouseUtil { public static void setMouseCursor(MouseCursor cursor) { FView.SINGLETON_INSTANCE.getLpnDocument().setCursor(Cursor.getPredefinedCursor(cursor.getValue())); } - } diff --git a/src/main/java/forge/gui/SOverlayUtils.java b/src/main/java/forge/gui/SOverlayUtils.java index 218ecdb02b8..e9239794890 100644 --- a/src/main/java/forge/gui/SOverlayUtils.java +++ b/src/main/java/forge/gui/SOverlayUtils.java @@ -12,8 +12,6 @@ import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.Timer; -import javax.swing.border.LineBorder; - import net.miginfocom.swing.MigLayout; import forge.Singletons; import forge.gui.match.TargetingOverlay; @@ -44,7 +42,7 @@ public final class SOverlayUtils { // (which is preset with null layout and close button) final FPanel pnl = new FPanel(); pnl.setLayout(new MigLayout("insets 0, gap 0, ax center, wrap")); - pnl.setBackground(FSkin.getColor(FSkin.Colors.CLR_ACTIVE)); + FSkin.get(pnl).setBackground(FSkin.getColor(FSkin.Colors.CLR_ACTIVE)); pnl.setBounds(new Rectangle(((w - pnlW) / 2), ((h - pnlH) / 2), pnlW, pnlH)); pnl.add(new FLabel.Builder().icon(FSkin.getIcon(FSkin.InterfaceIcons.ICO_LOGO)).build(), @@ -70,7 +68,7 @@ public final class SOverlayUtils { final JLabel lblLoading = new JLabel(""); lblLoading.setOpaque(true); - lblLoading.setBackground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); + FSkin.get(lblLoading).setBackground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); lblLoading.setMinimumSize(new Dimension(0, 20)); pnlLoading.setBounds(((w - 170) / 2), ((h - 80) / 2), 170, 80); @@ -104,9 +102,10 @@ public final class SOverlayUtils { final int w = overlay.getWidth(); final JButton btnCloseTopRight = new JButton("X"); + final FSkin.JComponentSkin btnCloseTopRightSkin = FSkin.get(btnCloseTopRight); btnCloseTopRight.setBounds(w - 25, 10, 15, 15); - btnCloseTopRight.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); - btnCloseTopRight.setBorder(new LineBorder(FSkin.getColor(FSkin.Colors.CLR_TEXT), 1)); + btnCloseTopRightSkin.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); + btnCloseTopRightSkin.setLineBorder(FSkin.getColor(FSkin.Colors.CLR_TEXT)); btnCloseTopRight.setOpaque(false); btnCloseTopRight.setBackground(new Color(0, 0, 0)); btnCloseTopRight.setFocusPainted(false); diff --git a/src/main/java/forge/gui/deckeditor/CDeckEditorUI.java b/src/main/java/forge/gui/deckeditor/CDeckEditorUI.java index 9a86a026f8b..e8e2d78b9f4 100644 --- a/src/main/java/forge/gui/deckeditor/CDeckEditorUI.java +++ b/src/main/java/forge/gui/deckeditor/CDeckEditorUI.java @@ -439,7 +439,12 @@ public enum CDeckEditorUI implements ICDoc, IMenuProvider { // show a popup with the current search string, highlighted in red if not found popupLabel.setText(searchStr + " (hit Enter for next match, Esc to cancel)"); - popupLabel.setForeground(found ? FSkin.getColor(FSkin.Colors.CLR_TEXT) : new Color(255, 0, 0)); + if (found) { + FSkin.get(popupLabel).setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); + } + else { + FSkin.get(popupLabel).setForeground(new Color(255, 0, 0)); + } if (popupShowing) { _setPopupSize(); @@ -448,7 +453,7 @@ public enum CDeckEditorUI implements ICDoc, IMenuProvider { PopupFactory factory = PopupFactory.getSharedInstance(); Point tableLoc = tableView.getTable().getTableHeader().getLocationOnScreen(); popup = factory.getPopup(null, popupLabel, tableLoc.x + 10, tableLoc.y + 10); - SwingUtilities.getRoot(popupLabel).setBackground(FSkin.getColor(FSkin.Colors.CLR_INACTIVE)); + FSkin.get(SwingUtilities.getRoot(popupLabel)).setBackground(FSkin.getColor(FSkin.Colors.CLR_INACTIVE)); popupTimer = new Timer(5000, new ActionListener() { @Override diff --git a/src/main/java/forge/gui/deckeditor/views/VCardCatalog.java b/src/main/java/forge/gui/deckeditor/views/VCardCatalog.java index a8c17e7f16f..2737500fdc3 100644 --- a/src/main/java/forge/gui/deckeditor/views/VCardCatalog.java +++ b/src/main/java/forge/gui/deckeditor/views/VCardCatalog.java @@ -6,12 +6,11 @@ import java.awt.FlowLayout; import java.util.HashMap; import java.util.Map; -import javax.swing.BorderFactory; -import javax.swing.JComboBox; import javax.swing.JComponent; import javax.swing.JPanel; import javax.swing.JSpinner; import javax.swing.JTextField; + import net.miginfocom.swing.MigLayout; import org.apache.commons.lang3.tuple.Pair; @@ -24,6 +23,7 @@ import forge.gui.framework.DragCell; import forge.gui.framework.DragTab; import forge.gui.framework.EDocID; import forge.gui.framework.IVDoc; +import forge.gui.toolbox.FComboBoxWrapper; import forge.gui.toolbox.FLabel; import forge.gui.toolbox.FSkin; import forge.gui.toolbox.FSpinner; @@ -82,7 +82,7 @@ public enum VCardCatalog implements IVDoc { .text("Add filter") .tooltip("Click to add custom filters to the card list") .reactOnMouseDown().build(); - private final JComboBox cbSearchMode = new JComboBox(); + private final FComboBoxWrapper cbSearchMode = new FComboBoxWrapper(); private final JTextField txfSearch = new FTextField.Builder().ghostText("Search").build(); private final FLabel lblName = new FLabel.Builder().text("Name").hoverable().selectable().selected().build(); private final FLabel lblType = new FLabel.Builder().text("Type").hoverable().selectable().selected().build(); @@ -144,7 +144,7 @@ public enum VCardCatalog implements IVDoc { pnlSearch.add(txfSearch, "pushx, growx"); cbSearchMode.addItem("in"); cbSearchMode.addItem("not in"); - pnlSearch.add(cbSearchMode, "center"); + cbSearchMode.addTo(pnlSearch, "center"); pnlSearch.add(lblName, "w pref+8, h pref+8"); pnlSearch.add(lblType, "w pref+8, h pref+8"); pnlSearch.add(lblText, "w pref+8, h pref+8"); @@ -227,7 +227,7 @@ public enum VCardCatalog implements IVDoc { public FLabel getLblText() { return lblText; } public FLabel getBtnAddRestriction() { return btnAddRestriction; } - public JComboBox getCbSearchMode() { return cbSearchMode; } + public FComboBoxWrapper getCbSearchMode() { return cbSearchMode; } public JTextField getTxfSearch() { return txfSearch; } public Map getStatLabels() { @@ -264,7 +264,7 @@ public enum VCardCatalog implements IVDoc { final JPanel pnl = new JPanel(new MigLayout("insets 2, gap 2, h 30!")); pnl.setOpaque(false); - pnl.setBorder(BorderFactory.createMatteBorder(1, 2, 1, 2, FSkin.getColor(FSkin.Colors.CLR_TEXT))); + FSkin.get(pnl).setMatteBorder(1, 2, 1, 2, FSkin.getColor(FSkin.Colors.CLR_TEXT)); pnl.add(component, "h 30!, center"); pnl.add(new FLabel.Builder().text("X").fontSize(10).hoverable(true) diff --git a/src/main/java/forge/gui/deckeditor/views/VEditorPreferences.java b/src/main/java/forge/gui/deckeditor/views/VEditorPreferences.java index b6390d58c88..e76b7e61955 100644 --- a/src/main/java/forge/gui/deckeditor/views/VEditorPreferences.java +++ b/src/main/java/forge/gui/deckeditor/views/VEditorPreferences.java @@ -4,8 +4,6 @@ import javax.swing.JCheckBox; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; -import javax.swing.border.MatteBorder; - import net.miginfocom.swing.MigLayout; import forge.gui.deckeditor.controllers.CEditorPreferences; import forge.gui.framework.DragCell; @@ -74,36 +72,38 @@ public enum VEditorPreferences implements IVDoc { //========== Constructor private VEditorPreferences() { - lblStats.setBorder(new MatteBorder(0, 0, 1, 0, FSkin.getColor(FSkin.Colors.CLR_BORDERS))); - lblCatalog.setBorder(new MatteBorder(0, 0, 1, 0, FSkin.getColor(FSkin.Colors.CLR_BORDERS))); - lblDeck.setBorder(new MatteBorder(0, 0, 1, 0, FSkin.getColor(FSkin.Colors.CLR_BORDERS))); - lblDisplay.setBorder(new MatteBorder(0, 0, 1, 0, FSkin.getColor(FSkin.Colors.CLR_BORDERS))); + FSkin.get(lblStats).setMatteBorder(0, 0, 1, 0, FSkin.getColor(FSkin.Colors.CLR_BORDERS)); + FSkin.get(lblCatalog).setMatteBorder(0, 0, 1, 0, FSkin.getColor(FSkin.Colors.CLR_BORDERS)); + FSkin.get(lblDeck).setMatteBorder(0, 0, 1, 0, FSkin.getColor(FSkin.Colors.CLR_BORDERS)); + FSkin.get(lblDisplay).setMatteBorder(0, 0, 1, 0, FSkin.getColor(FSkin.Colors.CLR_BORDERS)); - chbCatalogColor.setFont(FSkin.getFont(12)); - chbCatalogRarity.setFont(FSkin.getFont(12)); - chbCatalogCMC.setFont(FSkin.getFont(12)); - chbCatalogSet.setFont(FSkin.getFont(12)); - chbCatalogAI.setFont(FSkin.getFont(12)); - chbCatalogRanking.setFont(FSkin.getFont(12)); - chbCatalogPower.setFont(FSkin.getFont(12)); - chbCatalogToughness.setFont(FSkin.getFont(12)); - chbCatalogOwned.setFont(FSkin.getFont(12)); + FSkin.SkinFont font = FSkin.getFont(12); - chbDeckColor.setFont(FSkin.getFont(12)); - chbDeckRarity.setFont(FSkin.getFont(12)); - chbDeckCMC.setFont(FSkin.getFont(12)); - chbDeckSet.setFont(FSkin.getFont(12)); - chbDeckAI.setFont(FSkin.getFont(12)); - chbDeckRanking.setFont(FSkin.getFont(12)); - chbDeckPower.setFont(FSkin.getFont(12)); - chbDeckToughness.setFont(FSkin.getFont(12)); + FSkin.get(chbCatalogColor).setFont(font); + FSkin.get(chbCatalogRarity).setFont(font); + FSkin.get(chbCatalogCMC).setFont(font); + FSkin.get(chbCatalogSet).setFont(font); + FSkin.get(chbCatalogAI).setFont(font); + FSkin.get(chbCatalogRanking).setFont(font); + FSkin.get(chbCatalogPower).setFont(font); + FSkin.get(chbCatalogToughness).setFont(font); + FSkin.get(chbCatalogOwned).setFont(font); - chbDeckStats.setFont(FSkin.getFont(12)); - chbElasticColumns.setFont(FSkin.getFont(12)); + FSkin.get(chbDeckColor).setFont(font); + FSkin.get(chbDeckRarity).setFont(font); + FSkin.get(chbDeckCMC).setFont(font); + FSkin.get(chbDeckSet).setFont(font); + FSkin.get(chbDeckAI).setFont(font); + FSkin.get(chbDeckRanking).setFont(font); + FSkin.get(chbDeckPower).setFont(font); + FSkin.get(chbDeckToughness).setFont(font); + + FSkin.get(chbDeckStats).setFont(font); + FSkin.get(chbElasticColumns).setFont(font); chbDeckStats.setSelected(true); chbElasticColumns.setSelected(false); - chbCardDisplayUnique.setFont(FSkin.getFont(12)); + FSkin.get(chbCardDisplayUnique).setFont(font); chbCardDisplayUnique.setSelected(false); pnl.add(lblStats, "h 25px!, gap 5px 5px 5px 5px, ax center, span 2 1"); diff --git a/src/main/java/forge/gui/deckeditor/views/VProbabilities.java b/src/main/java/forge/gui/deckeditor/views/VProbabilities.java index f51470a8afa..50ac2e805f0 100644 --- a/src/main/java/forge/gui/deckeditor/views/VProbabilities.java +++ b/src/main/java/forge/gui/deckeditor/views/VProbabilities.java @@ -9,8 +9,6 @@ import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.SwingConstants; -import javax.swing.border.MatteBorder; - import net.miginfocom.swing.MigLayout; import forge.deck.DeckBase; import forge.gui.deckeditor.CDeckEditorUI; @@ -66,10 +64,13 @@ public enum VProbabilities implements IVDoc { scroller.getViewport().setBorder(null); scroller.getVerticalScrollBar().setUnitIncrement(16); - lblSampleHand.setBorder(new MatteBorder(1, 0, 1, 0, FSkin.getColor(FSkin.Colors.CLR_BORDERS))); - lblSampleHand.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); - lblRemainingDraws.setBorder(new MatteBorder(1, 0, 1, 0, FSkin.getColor(FSkin.Colors.CLR_BORDERS))); - lblRemainingDraws.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); + FSkin.JLabelSkin labelSkin = FSkin.get(lblSampleHand); + labelSkin.setMatteBorder(1, 0, 1, 0, FSkin.getColor(FSkin.Colors.CLR_BORDERS)); + labelSkin.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); + + labelSkin = FSkin.get(lblRemainingDraws); + labelSkin.setMatteBorder(1, 0, 1, 0, FSkin.getColor(FSkin.Colors.CLR_BORDERS)); + labelSkin.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); // Core layout pnlContent.add(lblReshuffle, "w 96%!, h 29px!, gap 2% 0 5px 5px"); @@ -188,7 +189,7 @@ public enum VProbabilities implements IVDoc { if (zebra) { lbl.setOpaque(true); - lbl.setBackground(FSkin.getColor(FSkin.Colors.CLR_ZEBRA)); + FSkin.get(lbl).setBackground(FSkin.getColor(FSkin.Colors.CLR_ZEBRA)); } return lbl; diff --git a/src/main/java/forge/gui/deckeditor/views/VStatistics.java b/src/main/java/forge/gui/deckeditor/views/VStatistics.java index 5f3c2f0652a..61038d7b2d9 100644 --- a/src/main/java/forge/gui/deckeditor/views/VStatistics.java +++ b/src/main/java/forge/gui/deckeditor/views/VStatistics.java @@ -2,7 +2,6 @@ package forge.gui.deckeditor.views; import java.awt.Font; -import javax.swing.ImageIcon; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; @@ -15,6 +14,7 @@ import forge.gui.framework.EDocID; import forge.gui.framework.IVDoc; import forge.gui.toolbox.FLabel; import forge.gui.toolbox.FSkin; +import forge.gui.toolbox.FSkin.SkinImage; import forge.gui.toolbox.itemmanager.SItemManagerUtil; /** @@ -61,20 +61,13 @@ public enum VStatistics implements IVDoc { private final JLabel lblSorcery = buildLabel(SItemManagerUtil.StatTypes.SORCERY, true); // CMC labels - private final JLabel lblCMC0 = buildLabel( - new ImageIcon(FSkin.getImage(FSkin.ColorlessManaImages.IMG_0, 16, 16)), true); - private final JLabel lblCMC1 = buildLabel( - new ImageIcon(FSkin.getImage(FSkin.ColorlessManaImages.IMG_1, 16, 16)), false); - private final JLabel lblCMC2 = buildLabel( - new ImageIcon(FSkin.getImage(FSkin.ColorlessManaImages.IMG_2, 16, 16)), true); - private final JLabel lblCMC3 = buildLabel( - new ImageIcon(FSkin.getImage(FSkin.ColorlessManaImages.IMG_3, 16, 16)), false); - private final JLabel lblCMC4 = buildLabel( - new ImageIcon(FSkin.getImage(FSkin.ColorlessManaImages.IMG_4, 16, 16)), true); - private final JLabel lblCMC5 = buildLabel( - new ImageIcon(FSkin.getImage(FSkin.ColorlessManaImages.IMG_5, 16, 16)), false); - private final JLabel lblCMC6 = buildLabel( - new ImageIcon(FSkin.getImage(FSkin.ColorlessManaImages.IMG_6, 16, 16)), true); + private final JLabel lblCMC0 = buildLabel(FSkin.getImage(FSkin.ColorlessManaImages.IMG_0, 16, 16), true); + private final JLabel lblCMC1 = buildLabel(FSkin.getImage(FSkin.ColorlessManaImages.IMG_1, 16, 16), false); + private final JLabel lblCMC2 = buildLabel(FSkin.getImage(FSkin.ColorlessManaImages.IMG_2, 16, 16), true); + private final JLabel lblCMC3 = buildLabel(FSkin.getImage(FSkin.ColorlessManaImages.IMG_3, 16, 16), false); + private final JLabel lblCMC4 = buildLabel(FSkin.getImage(FSkin.ColorlessManaImages.IMG_4, 16, 16), true); + private final JLabel lblCMC5 = buildLabel(FSkin.getImage(FSkin.ColorlessManaImages.IMG_5, 16, 16), false); + private final JLabel lblCMC6 = buildLabel(FSkin.getImage(FSkin.ColorlessManaImages.IMG_6, 16, 16), true); // Layout containers private final JScrollPane scroller = new JScrollPane(pnlStats); @@ -251,14 +244,14 @@ public enum VStatistics implements IVDoc { //========== Other methods - private JLabel buildLabel(ImageIcon icon, boolean zebra) { + private JLabel buildLabel(SkinImage icon, boolean zebra) { final JLabel lbl = new FLabel.Builder().text("0") .icon(icon).iconScaleAuto(false) .fontSize(11).build(); if (zebra) { lbl.setOpaque(true); - lbl.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); + FSkin.get(lbl).setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); } return lbl; diff --git a/src/main/java/forge/gui/download/GuiDownloader.java b/src/main/java/forge/gui/download/GuiDownloader.java index 2ce359fcd83..0019df4e123 100644 --- a/src/main/java/forge/gui/download/GuiDownloader.java +++ b/src/main/java/forge/gui/download/GuiDownloader.java @@ -44,7 +44,6 @@ import javax.swing.JTextField; import javax.swing.SwingConstants; import javax.swing.SwingUtilities; import javax.swing.SwingWorker; -import javax.swing.border.LineBorder; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; @@ -130,8 +129,8 @@ public abstract class GuiDownloader extends DefaultBoundedRangeModel implements radProxySocks.addChangeListener(new ProxyHandler(2)); radProxyNone.setSelected(true); - btnClose.setBorder(new LineBorder(FSkin.getColor(FSkin.Colors.CLR_TEXT), 1)); - btnStart.setFont(FSkin.getFont(18)); + FSkin.get(btnClose).setLineBorder(FSkin.getColor(FSkin.Colors.CLR_TEXT)); + FSkin.get(btnStart).setFont(FSkin.getFont(18)); btnStart.setVisible(false); barProgress.reset(); diff --git a/src/main/java/forge/gui/framework/DragCell.java b/src/main/java/forge/gui/framework/DragCell.java index f0b9bbab02f..59caa36f36a 100644 --- a/src/main/java/forge/gui/framework/DragCell.java +++ b/src/main/java/forge/gui/framework/DragCell.java @@ -4,7 +4,6 @@ import java.awt.Color; import java.awt.Dimension; import java.awt.Font; import java.awt.Graphics; -import java.awt.Image; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.ArrayList; @@ -21,6 +20,8 @@ import com.google.common.collect.Lists; import forge.Singletons; import forge.gui.toolbox.FPanel; import forge.gui.toolbox.FSkin; +import forge.gui.toolbox.FSkin.JLabelSkin; +import forge.gui.toolbox.FSkin.SkinImage; import forge.properties.ForgePreferences; import forge.properties.ForgePreferences.FPref; import forge.view.FView; @@ -443,12 +444,12 @@ public final class DragCell extends JPanel implements ILocalRepaint { /** Paints dragging handle image the length of the label. */ private class DragHandle extends JLabel { - private final Image img = FSkin.getImage(FSkin.LayoutImages.IMG_HANDLE); - private final int imgW = img.getWidth(null); - private final int imgH = img.getHeight(null); + private final JLabelSkin skin; + private final SkinImage img = FSkin.getImage(FSkin.LayoutImages.IMG_HANDLE); private boolean hovered = false; public DragHandle() { + this.skin = FSkin.get(this); this.addMouseListener(SRearrangingUtil.getRearrangeClickEvent()); this.addMouseMotionListener(SRearrangingUtil.getRearrangeDragEvent()); @@ -469,10 +470,14 @@ public final class DragCell extends JPanel implements ILocalRepaint { public void paintComponent(final Graphics g) { super.paintComponent(g); if (!hovered) { return; } + + final Dimension imgSize = img.getSizeForPaint(g); + final int imgW = imgSize.width; if (imgW < 1) { return; } + final int imgH = imgSize.height; for (int x = 0; x < getWidth(); x += imgW) { - g.drawImage(img, x, ((getHeight() - imgH) / 2), null); + skin.drawImage(g, img, x, ((getHeight() - imgH) / 2)); } } } diff --git a/src/main/java/forge/gui/framework/DragTab.java b/src/main/java/forge/gui/framework/DragTab.java index 6ca416becf7..076c30f4fe6 100644 --- a/src/main/java/forge/gui/framework/DragTab.java +++ b/src/main/java/forge/gui/framework/DragTab.java @@ -15,6 +15,7 @@ import forge.gui.toolbox.FSkin; */ @SuppressWarnings("serial") public final class DragTab extends JLabel implements ILocalRepaint { + private final FSkin.JLabelSkin skin; private boolean selected = false; private int priority = 10; @@ -27,11 +28,12 @@ public final class DragTab extends JLabel implements ILocalRepaint { */ public DragTab(final String title0) { super(title0); + skin = FSkin.get(this); setToolTipText(title0); setOpaque(false); setSelected(false); setBorder(new EmptyBorder(2, 5, 2, 5)); - setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); + skin.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); this.addMouseListener(SRearrangingUtil.getRearrangeClickEvent()); this.addMouseMotionListener(SRearrangingUtil.getRearrangeDragEvent()); @@ -76,15 +78,15 @@ public final class DragTab extends JLabel implements ILocalRepaint { @Override public void paintComponent(final Graphics g) { if (!selected) { - g.setColor(FSkin.getColor(FSkin.Colors.CLR_INACTIVE)); + skin.setGraphicsColor(g, FSkin.getColor(FSkin.Colors.CLR_INACTIVE)); g.fillRoundRect(0, 0, getWidth() - 1, getHeight() * 2, 6, 6); - g.setColor(FSkin.getColor(FSkin.Colors.CLR_BORDERS)); + skin.setGraphicsColor(g, FSkin.getColor(FSkin.Colors.CLR_BORDERS)); g.drawRoundRect(0, 0, getWidth() - 1, getHeight() * 2, 6, 6); } else { - g.setColor(FSkin.getColor(FSkin.Colors.CLR_ACTIVE)); + skin.setGraphicsColor(g, FSkin.getColor(FSkin.Colors.CLR_ACTIVE)); g.fillRoundRect(0, 0, getWidth() - 1, getHeight() * 2, 6, 6); - g.setColor(FSkin.getColor(FSkin.Colors.CLR_BORDERS)); + skin.setGraphicsColor(g, FSkin.getColor(FSkin.Colors.CLR_BORDERS)); g.drawRoundRect(0, 0, getWidth() - 1, getHeight() * 2, 6, 6); } diff --git a/src/main/java/forge/gui/framework/SRearrangingUtil.java b/src/main/java/forge/gui/framework/SRearrangingUtil.java index 5f6e7cd63e5..d91af81685f 100644 --- a/src/main/java/forge/gui/framework/SRearrangingUtil.java +++ b/src/main/java/forge/gui/framework/SRearrangingUtil.java @@ -2,8 +2,6 @@ package forge.gui.framework; import java.awt.Container; import java.awt.Cursor; -import java.awt.Point; -import java.awt.Toolkit; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; @@ -12,10 +10,10 @@ import java.awt.event.MouseMotionListener; import java.util.ArrayList; import java.util.List; -import javax.swing.JLayeredPane; import javax.swing.JPanel; import forge.gui.toolbox.FSkin; +import forge.gui.toolbox.FSkin.SkinCursor; import forge.view.FView; /** @@ -43,26 +41,20 @@ public final class SRearrangingUtil { private static int tempW; private static int tempH; - private static JPanel pnlPreview = FView.SINGLETON_INSTANCE.getPnlPreview(); - private static JLayeredPane pnlDocument = FView.SINGLETON_INSTANCE.getLpnDocument(); - private static DragCell cellTarget = null; - private static DragCell cellSrc = null; - private static DragCell cellNew = null; - private static Dropzone dropzone = Dropzone.NONE; - private static List> docsToMove = new ArrayList>(); - private static IVDoc srcSelectedDoc = null; + private static JPanel pnlPreview = FView.SINGLETON_INSTANCE.getPnlPreview(); + private static FView.DocumentPane pnlDocument = FView.SINGLETON_INSTANCE.getLpnDocument(); + private static DragCell cellTarget = null; + private static DragCell cellSrc = null; + private static DragCell cellNew = null; + private static Dropzone dropzone = Dropzone.NONE; + private static List> docsToMove = new ArrayList>(); + private static IVDoc srcSelectedDoc = null; - private static final Toolkit TOOLS = Toolkit.getDefaultToolkit(); - private static final Cursor CUR_L = TOOLS.createCustomCursor( - FSkin.getImage(FSkin.LayoutImages.IMG_CUR_L), new Point(16, 16), "CUR_L"); - private static final Cursor CUR_T = TOOLS.createCustomCursor( - FSkin.getImage(FSkin.LayoutImages.IMG_CUR_T), new Point(16, 16), "CUR_T"); - private static final Cursor CUR_B = TOOLS.createCustomCursor( - FSkin.getImage(FSkin.LayoutImages.IMG_CUR_B), new Point(16, 16), "CUR_B"); - private static final Cursor CUR_R = TOOLS.createCustomCursor( - FSkin.getImage(FSkin.LayoutImages.IMG_CUR_R), new Point(16, 16), "CUR_R"); - private static final Cursor CUR_TAB = TOOLS.createCustomCursor( - FSkin.getImage(FSkin.LayoutImages.IMG_CUR_TAB), new Point(16, 16), "CUR_TAB"); + private static final SkinCursor CUR_L = FSkin.getCursor(FSkin.LayoutImages.IMG_CUR_L, 16, 16, "CUR_L"); + private static final SkinCursor CUR_T = FSkin.getCursor(FSkin.LayoutImages.IMG_CUR_T, 16, 16, "CUR_T"); + private static final SkinCursor CUR_B = FSkin.getCursor(FSkin.LayoutImages.IMG_CUR_B, 16, 16, "CUR_B"); + private static final SkinCursor CUR_R = FSkin.getCursor(FSkin.LayoutImages.IMG_CUR_R, 16, 16, "CUR_R"); + private static final SkinCursor CUR_TAB = FSkin.getCursor(FSkin.LayoutImages.IMG_CUR_TAB, 16, 16, "CUR_TAB"); private static final MouseListener MAD_REARRANGE = new MouseAdapter() { @Override diff --git a/src/main/java/forge/gui/home/CHomeUI.java b/src/main/java/forge/gui/home/CHomeUI.java index 73b7ad19e5f..b4a0800a65c 100644 --- a/src/main/java/forge/gui/home/CHomeUI.java +++ b/src/main/java/forge/gui/home/CHomeUI.java @@ -114,7 +114,6 @@ public enum CHomeUI implements ICDoc, IMenuProvider { private void setupMyMenuBar() { Singletons.getControl().getMenuBar().setupMenuBar(this); - Singletons.getControl().getMenuBar().setStatusText("F1 : hide menu"); } /* (non-Javadoc) diff --git a/src/main/java/forge/gui/home/LblGroup.java b/src/main/java/forge/gui/home/LblGroup.java index dbe21cb5699..502e63679e8 100644 --- a/src/main/java/forge/gui/home/LblGroup.java +++ b/src/main/java/forge/gui/home/LblGroup.java @@ -1,9 +1,7 @@ package forge.gui.home; -import java.awt.Color; import java.awt.Component; import java.awt.Dimension; -import java.awt.GradientPaint; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.event.MouseAdapter; @@ -14,6 +12,8 @@ import javax.swing.JLabel; import forge.Singletons; import forge.gui.framework.ILocalRepaint; import forge.gui.toolbox.FSkin; +import forge.gui.toolbox.FSkin.JLabelSkin; +import forge.gui.toolbox.FSkin.SkinColor; import forge.properties.ForgePreferences.FPref; /** @@ -28,12 +28,13 @@ public class LblGroup extends JLabel implements ILocalRepaint { private boolean hovered = false; - private final Color clrTheme = FSkin.getColor(FSkin.Colors.CLR_THEME); - private final Color l20 = FSkin.stepColor(clrTheme, 20); - private final Color l25 = FSkin.stepColor(clrTheme, 25); - private final Color l40 = FSkin.stepColor(clrTheme, 40); - private final Color d20 = FSkin.stepColor(clrTheme, -20); - private final Color d80 = FSkin.stepColor(clrTheme, -80); + private final JLabelSkin skin; + private final SkinColor clrTheme = FSkin.getColor(FSkin.Colors.CLR_THEME); + private final SkinColor l20 = clrTheme.stepColor(20); + private final SkinColor l25 = clrTheme.stepColor(25); + private final SkinColor l40 = clrTheme.stepColor(40); + private final SkinColor d20 = clrTheme.stepColor(-20); + private final SkinColor d80 = clrTheme.stepColor(-80); /** * Custom JLabel for title of menu item groups. @@ -44,9 +45,10 @@ public class LblGroup extends JLabel implements ILocalRepaint { public LblGroup(final EMenuGroup e0) { super(" " + e0.getTitle()); - - this.setFont(FSkin.getBoldFont(14)); - this.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); + + skin = FSkin.get(this); + skin.setFont(FSkin.getBoldFont(14)); + skin.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); this.addMouseListener(new MouseAdapter() { @Override @@ -128,16 +130,15 @@ public class LblGroup extends JLabel implements ILocalRepaint { int w = getWidth(); int h = getHeight(); - g.setColor(l20); + skin.setGraphicsColor(g, l20); g.fillRect(0, 0, getWidth(), getHeight()); - GradientPaint edge = new GradientPaint(w - 10, 0, l25, w, 0, d80, false); - g2d.setPaint(edge); + skin.setGraphicsGradientPaint(g2d, w - 10, 0, l25, w, 0, d80); g2d.fillRect(w - 10, 0, w, h); - g2d.setColor(l40); + skin.setGraphicsColor(g, l40); g2d.drawLine(0, 0, w - 6, 0); - g2d.setColor(d20); + skin.setGraphicsColor(g, d20); g2d.drawLine(0, h - 1, w - 6, h - 1); } diff --git a/src/main/java/forge/gui/home/LblHeader.java b/src/main/java/forge/gui/home/LblHeader.java index 74198272004..b44e0d7aec9 100644 --- a/src/main/java/forge/gui/home/LblHeader.java +++ b/src/main/java/forge/gui/home/LblHeader.java @@ -1,6 +1,5 @@ package forge.gui.home; -import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; @@ -8,16 +7,19 @@ import javax.swing.JLabel; import javax.swing.border.EmptyBorder; import forge.gui.toolbox.FSkin; +import forge.gui.toolbox.FSkin.JLabelSkin; +import forge.gui.toolbox.FSkin.SkinColor; /** * Standardized header label for top of menu display panel. */ @SuppressWarnings("serial") public class LblHeader extends JLabel { - private final Color clr = FSkin.stepColor(FSkin.getColor(FSkin.Colors.CLR_THEME), 0); - private final Color a100 = FSkin.alphaColor(clr, 100); - private final Color d40 = FSkin.stepColor(clr, -40); - private final Color d80 = FSkin.stepColor(clr, -80); + private final JLabelSkin skin; + private final SkinColor clr = FSkin.getColor(FSkin.Colors.CLR_THEME).stepColor(0); + private final SkinColor a100 = clr.alphaColor(100); + private final SkinColor d40 = clr.stepColor(-40); + private final SkinColor d80 = clr.stepColor(-80); /** * Constructor. @@ -25,8 +27,9 @@ public class LblHeader extends JLabel { */ public LblHeader(final String txt0) { super(txt0); - this.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); - this.setFont(FSkin.getFont(18)); + skin = FSkin.get(this); + skin.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); + skin.setFont(FSkin.getFont(18)); this.setBorder(new EmptyBorder(5, 30, 0, 0)); } @@ -36,13 +39,13 @@ public class LblHeader extends JLabel { int w = getWidth(); int h = getHeight(); - g2d.setColor(d80); + skin.setGraphicsColor(g2d, d80); g2d.fillRect(0, 5, w, h - 5); - g2d.setColor(a100); + skin.setGraphicsColor(g2d, a100); g2d.fillRect(5, 0, w - 5, h - 5); - g2d.setColor(d40); + skin.setGraphicsColor(g2d, d40); g2d.drawRect(5, 0, w - 6, h - 6); super.paintComponent(g); diff --git a/src/main/java/forge/gui/home/LblMenuItem.java b/src/main/java/forge/gui/home/LblMenuItem.java index f9e380ea61a..c11a035527f 100644 --- a/src/main/java/forge/gui/home/LblMenuItem.java +++ b/src/main/java/forge/gui/home/LblMenuItem.java @@ -1,8 +1,6 @@ package forge.gui.home; -import java.awt.Color; import java.awt.Dimension; -import java.awt.GradientPaint; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.event.MouseAdapter; @@ -13,6 +11,8 @@ import javax.swing.JLabel; import forge.gui.framework.ICDoc; import forge.gui.framework.ILocalRepaint; import forge.gui.toolbox.FSkin; +import forge.gui.toolbox.FSkin.JLabelSkin; +import forge.gui.toolbox.FSkin.SkinColor; /** * Custom JLabel for an item in the menu. Handles listening @@ -24,14 +24,14 @@ public class LblMenuItem extends JLabel implements ILocalRepaint { private boolean selected = false; private boolean hovered = false; - private final Color clrTheme = FSkin.getColor(FSkin.Colors.CLR_THEME); - private final Color l00 = FSkin.stepColor(clrTheme, 0); - private final Color l20 = FSkin.stepColor(clrTheme, 20); - private final Color d20 = FSkin.stepColor(clrTheme, -20); - private final Color d60 = FSkin.stepColor(clrTheme, -60); - private final Color d80 = FSkin.stepColor(clrTheme, -80); - - private final GradientPaint edge = new GradientPaint(200 - 8, 0, l00, 200, 0, d80, false); + private final JLabelSkin skin; + private final SkinColor clrTheme = FSkin.getColor(FSkin.Colors.CLR_THEME); + private final SkinColor l00 = clrTheme.stepColor(0); + private final SkinColor l20 = clrTheme.stepColor(20); + private final SkinColor d20 = clrTheme.stepColor(-20); + private final SkinColor d60 = clrTheme.stepColor(-60); + private final SkinColor d80 = clrTheme.stepColor(-80); + private final SkinColor alpha100 = l00.alphaColor(100); /** * Custom JLabel for an item in the menu. Handles listening @@ -41,8 +41,10 @@ public class LblMenuItem extends JLabel implements ILocalRepaint { */ public LblMenuItem(final IVSubmenu doc0) { super(" " + doc0.getMenuTitle()); - this.setFont(FSkin.getFont(14)); - this.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); + + skin = FSkin.get(this); + skin.setFont(FSkin.getFont(14)); + FSkin.get(this).setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); this.addMouseListener(new MouseAdapter() { @Override @@ -82,23 +84,23 @@ public class LblMenuItem extends JLabel implements ILocalRepaint { int h = getHeight(); if (this.selected) { - g2d.setColor(FSkin.alphaColor(l00, 100)); + skin.setGraphicsColor(g2d, alpha100); g2d.fillRect(0, 0, w, h); - g2d.setColor(d20); + skin.setGraphicsColor(g2d, d20); g2d.drawLine(0, 0, w - 3, 0); - g2d.setColor(l20); + skin.setGraphicsColor(g2d, l20); g2d.drawLine(0, h - 1, w - 3, h - 1); } else if (this.hovered) { - g2d.setColor(d60); + skin.setGraphicsColor(g2d, d60); g2d.fillRect(0, 0, getWidth(), h); - g2d.setPaint(edge); + skin.setGraphicsGradientPaint(g2d, 200 - 8, 0, l00, 200, 0, d80); g2d.fillRect(w - 2, 0, w, h); - g2d.setColor(d20); + skin.setGraphicsColor(g2d, d20); g2d.drawLine(0, 0, w - 3, 0); - g2d.setColor(l20); + skin.setGraphicsColor(g2d, l20); g2d.drawLine(0, h - 1, w - 3, h - 1); } diff --git a/src/main/java/forge/gui/home/PnlGroup.java b/src/main/java/forge/gui/home/PnlGroup.java index c6f913e486a..b3ff239460d 100644 --- a/src/main/java/forge/gui/home/PnlGroup.java +++ b/src/main/java/forge/gui/home/PnlGroup.java @@ -1,7 +1,5 @@ package forge.gui.home; -import java.awt.Color; -import java.awt.GradientPaint; import java.awt.Graphics; import java.awt.Graphics2D; @@ -10,6 +8,8 @@ import javax.swing.JPanel; import net.miginfocom.swing.MigLayout; import forge.gui.toolbox.FSkin; +import forge.gui.toolbox.FSkin.JComponentSkin; +import forge.gui.toolbox.FSkin.SkinColor; /** * Custom JPanel for containing LblMenuItem components. @@ -17,20 +17,22 @@ import forge.gui.toolbox.FSkin; */ @SuppressWarnings("serial") public class PnlGroup extends JPanel { - private final Color clrTheme = FSkin.getColor(FSkin.Colors.CLR_THEME); - private final Color l00 = FSkin.stepColor(clrTheme, 0); - private final Color l10 = FSkin.stepColor(clrTheme, 10); - private final Color d20 = FSkin.stepColor(clrTheme, -20); - private final Color d60 = FSkin.stepColor(clrTheme, -60); - private final Color d80 = FSkin.stepColor(clrTheme, -80); + private final JComponentSkin skin; + private final SkinColor clrTheme = FSkin.getColor(FSkin.Colors.CLR_THEME); + private final SkinColor l00 = clrTheme.stepColor(0); + private final SkinColor l10 = clrTheme.stepColor(10); + private final SkinColor d20 = clrTheme.stepColor(-20); + private final SkinColor d60 = clrTheme.stepColor(-60); + private final SkinColor d80 = clrTheme.stepColor(-80); /** * Custom JPanel for containing LblMenuItem components. * Mostly just handles repainting. */ public PnlGroup() { + this.skin = FSkin.get(this); this.setLayout(new MigLayout("insets 10px 0 10px 0, gap 0, wrap")); - this.setBackground(d20); + this.skin.setBackground(d20); this.setOpaque(false); } @@ -44,15 +46,14 @@ public class PnlGroup extends JPanel { final int w = getWidth(); final int h = getHeight(); - g2d.setColor(d20); + skin.setGraphicsColor(g2d, d20); // Selected in this group, don't draw background under selected label. if (getY() < yTop && yTop < getY() + h) { g2d.fillRect(0, 0, w, lbl.getY()); g2d.fillRect(0, lbl.getY() + lbl.getHeight(), w, h); - GradientPaint edge = new GradientPaint(w - 8, 0, l00, w, 0, d80, false); - g2d.setPaint(edge); + skin.setGraphicsGradientPaint(g2d, w - 8, 0, l00, w, 0, d80); g2d.fillRect(w - 6, 0, w, lbl.getY()); g2d.fillRect(w - 6, lbl.getY() + lbl.getHeight(), w, h); } @@ -60,15 +61,14 @@ public class PnlGroup extends JPanel { else { g2d.fillRect(0, 0, w, h); - GradientPaint edge = new GradientPaint(w - 8, 0, l00, w, 0, d80, false); - g2d.setPaint(edge); + skin.setGraphicsGradientPaint(g2d, w - 8, 0, l00, w, 0, d80); g2d.fillRect(w - 6, 0, w, h); } - g2d.setColor(l10); + skin.setGraphicsColor(g2d, l10); g2d.drawLine(0, h - 1, w - 1, h - 1); - g2d.setColor(d60); + skin.setGraphicsColor(g2d, d60); g2d.drawLine(0, 0, w - 1, 0); g2d.dispose(); diff --git a/src/main/java/forge/gui/home/StartButton.java b/src/main/java/forge/gui/home/StartButton.java index 20302f888ee..7fab3820702 100644 --- a/src/main/java/forge/gui/home/StartButton.java +++ b/src/main/java/forge/gui/home/StartButton.java @@ -13,24 +13,25 @@ import forge.gui.toolbox.FSkin; @SuppressWarnings("serial") public class StartButton extends JButton { public StartButton() { + final FSkin.AbstractButtonSkin skin = FSkin.get(this); setOpaque(false); setContentAreaFilled(false); setBorder(null); setBorderPainted(false); setRolloverEnabled(true); - setRolloverIcon(FSkin.getIcon(FSkin.ButtonImages.IMG_BTN_START_OVER)); - setIcon(FSkin.getIcon(FSkin.ButtonImages.IMG_BTN_START_UP)); - setPressedIcon(FSkin.getIcon(FSkin.ButtonImages.IMG_BTN_START_DOWN)); + skin.setRolloverIcon(FSkin.getIcon(FSkin.ButtonImages.IMG_BTN_START_OVER)); + skin.setIcon(FSkin.getIcon(FSkin.ButtonImages.IMG_BTN_START_UP)); + skin.setPressedIcon(FSkin.getIcon(FSkin.ButtonImages.IMG_BTN_START_DOWN)); addFocusListener(new FocusListener() { @Override public void focusLost(FocusEvent arg0) { - setIcon(FSkin.getIcon(FSkin.ButtonImages.IMG_BTN_START_UP)); + skin.setIcon(FSkin.getIcon(FSkin.ButtonImages.IMG_BTN_START_UP)); } @Override public void focusGained(FocusEvent arg0) { - setIcon(FSkin.getIcon(FSkin.ButtonImages.IMG_BTN_START_OVER)); + skin.setIcon(FSkin.getIcon(FSkin.ButtonImages.IMG_BTN_START_OVER)); } }); diff --git a/src/main/java/forge/gui/home/VHomeUI.java b/src/main/java/forge/gui/home/VHomeUI.java index d3a5994d5f8..4f2120cc3e1 100644 --- a/src/main/java/forge/gui/home/VHomeUI.java +++ b/src/main/java/forge/gui/home/VHomeUI.java @@ -17,9 +17,7 @@ */ package forge.gui.home; -import java.awt.Color; import java.awt.Dimension; -import java.awt.GradientPaint; import java.awt.Graphics; import java.awt.Graphics2D; import java.util.ArrayList; @@ -63,6 +61,8 @@ import forge.gui.home.variant.VSubmenuVanguard; import forge.gui.toolbox.FLabel; import forge.gui.toolbox.FScrollPanel; import forge.gui.toolbox.FSkin; +import forge.gui.toolbox.FSkin.JComponentSkin; +import forge.gui.toolbox.FSkin.SkinColor; import forge.properties.NewConstants; import forge.properties.ForgePreferences.FPref; import forge.view.FView; @@ -79,8 +79,8 @@ public enum VHomeUI implements IVTopLevelUI { /** */ SINGLETON_INSTANCE; - private final Color clrTheme = FSkin.getColor(FSkin.Colors.CLR_THEME); - private final Color l00 = FSkin.stepColor(clrTheme, 0); + private final SkinColor clrTheme = FSkin.getColor(FSkin.Colors.CLR_THEME); + private final SkinColor l00 = clrTheme.stepColor(0); private final List> allSubmenus = new ArrayList>(); private final Map allSubmenuLabels = new HashMap(); @@ -191,7 +191,7 @@ public enum VHomeUI implements IVTopLevelUI { } pnlMenu.add(pnlSubmenus, "w 100%!, h 100% - " + pnlMainMenuHeight + "px!"); - pnlDisplay.setBackground(FSkin.alphaColor(l00, 100)); + FSkin.get(pnlDisplay).setBackground(l00.alphaColor(100)); } /** @return {@link forge.gui.toolbox.ExperimentalLabel} */ @@ -258,8 +258,11 @@ public enum VHomeUI implements IVTopLevelUI { /** */ public class PnlDisplay extends JPanel implements ILocalRepaint { + private final JComponentSkin skin; + /** Constructor. */ public PnlDisplay() { + this.skin = FSkin.get(this); this.setOpaque(false); } @@ -274,7 +277,7 @@ public enum VHomeUI implements IVTopLevelUI { super.paintComponent(g); final Graphics2D g2d = (Graphics2D) g.create(); - g2d.setColor(this.getBackground()); + skin.setGraphicsColor(g2d, skin.getBackground()); g2d.fillRect(0, 0, getWidth(), getHeight()); g2d.dispose(); @@ -282,9 +285,11 @@ public enum VHomeUI implements IVTopLevelUI { } private class PnlMenu extends JPanel { - private final Color d80 = FSkin.stepColor(clrTheme, -80); + private final JComponentSkin skin; + private final SkinColor d80 = clrTheme.stepColor(-80); public PnlMenu() { + this.skin = FSkin.get(this); this.setLayout(new MigLayout("insets 0, gap 0, wrap, hidemode 3")); this.setOpaque(false); } @@ -316,15 +321,14 @@ public enum VHomeUI implements IVTopLevelUI { } } - g2d.setColor(l00); + skin.setGraphicsColor(g2d, l00); g2d.fillRect(0, y1, w, h1); if (h2 > 0) { g2d.fillRect(0, y2, w, h2); } int x = w - 8; - GradientPaint edge = new GradientPaint(x, 0, l00, w, 0, d80, false); - g2d.setPaint(edge); + skin.setGraphicsGradientPaint(g2d, x, 0, l00, w, 0, d80); g2d.fillRect(x, y1, w, h1); if (h2 > 0) { g2d.fillRect(x, y2, w, h2); diff --git a/src/main/java/forge/gui/home/gauntlet/ContestGauntletLister.java b/src/main/java/forge/gui/home/gauntlet/ContestGauntletLister.java index f3847933ff9..ea8bd587cf8 100644 --- a/src/main/java/forge/gui/home/gauntlet/ContestGauntletLister.java +++ b/src/main/java/forge/gui/home/gauntlet/ContestGauntletLister.java @@ -12,8 +12,6 @@ import java.util.List; import javax.swing.JPanel; import javax.swing.SwingConstants; -import javax.swing.border.MatteBorder; - import net.miginfocom.swing.MigLayout; import forge.Command; import forge.gauntlet.GauntletData; @@ -30,7 +28,8 @@ public class ContestGauntletLister extends JPanel { private RowPanel previousSelect; private RowPanel[] rows; private Command cmdRowSelect; - private final Color clrDefault, clrHover, clrActive, clrBorders; + private final Color clrDefault; + private final FSkin.SkinColor clrHover, clrActive, clrBorders; /** */ public ContestGauntletLister() { @@ -61,7 +60,7 @@ public class ContestGauntletLister extends JPanel { // Note: careful with the widths of the rows here; // scroll panes will have difficulty dynamically resizing if 100% width is set. final JPanel rowTitle = new JPanel(); - rowTitle.setBackground(FSkin.getColor(FSkin.Colors.CLR_ZEBRA)); + FSkin.get(rowTitle).setBackground(FSkin.getColor(FSkin.Colors.CLR_ZEBRA)); rowTitle.setLayout(new MigLayout("insets 0, gap 0")); rowTitle.add(new FLabel.Builder().build(), "w 30px!, h 20px!, gap 1% 0 5px 0"); @@ -129,21 +128,21 @@ public class ContestGauntletLister extends JPanel { setOpaque(false); setBackground(new Color(0, 0, 0, 0)); setLayout(new MigLayout("insets 0, gap 0")); - setBorder(new MatteBorder(0, 0, 1, 0, clrBorders)); + FSkin.get(this).setMatteBorder(0, 0, 1, 0, clrBorders); gauntletData = gd0; this.addMouseListener(new MouseAdapter() { @Override public void mouseEntered(MouseEvent e) { if (!selected) { - ((RowPanel) e.getSource()).setBackground(clrHover); + FSkin.get(((RowPanel) e.getSource())).setBackground(clrHover); ((RowPanel) e.getSource()).setOpaque(true); } } @Override public void mouseExited(MouseEvent e) { if (!selected) { - ((RowPanel) e.getSource()).setBackground(clrDefault); + FSkin.get(((RowPanel) e.getSource())).setBackground(clrDefault); ((RowPanel) e.getSource()).setOpaque(false); } } @@ -157,7 +156,7 @@ public class ContestGauntletLister extends JPanel { public void setSelected(boolean b0) { selected = b0; setOpaque(b0); - setBackground(b0 ? clrActive : clrHover); + FSkin.get(this).setBackground(b0 ? clrActive : clrHover); } public boolean isSelected() { diff --git a/src/main/java/forge/gui/home/gauntlet/QuickGauntletLister.java b/src/main/java/forge/gui/home/gauntlet/QuickGauntletLister.java index c4cfcc3684f..e6dc080cf97 100644 --- a/src/main/java/forge/gui/home/gauntlet/QuickGauntletLister.java +++ b/src/main/java/forge/gui/home/gauntlet/QuickGauntletLister.java @@ -11,12 +11,10 @@ import java.util.Collections; import java.util.Comparator; import java.util.List; -import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.SwingConstants; -import javax.swing.border.MatteBorder; import net.miginfocom.swing.MigLayout; import forge.Command; @@ -24,6 +22,7 @@ import forge.gauntlet.GauntletData; import forge.gauntlet.GauntletIO; import forge.gui.toolbox.FLabel; import forge.gui.toolbox.FSkin; +import forge.gui.toolbox.FSkin.SkinIcon; /** * Creates file list/table for quick deleting, editing, and basic info. @@ -31,11 +30,12 @@ import forge.gui.toolbox.FSkin; */ @SuppressWarnings("serial") public class QuickGauntletLister extends JPanel { - private ImageIcon icoDelete, icoDeleteOver; + private SkinIcon icoDelete, icoDeleteOver; private RowPanel previousSelect; private RowPanel[] rows; private Command cmdRowSelect, cmdRowDelete; - private final Color clrDefault, clrHover, clrActive, clrBorders; + private final Color clrDefault; + private final FSkin.SkinColor clrHover, clrActive, clrBorders; /** */ public QuickGauntletLister() { @@ -70,7 +70,7 @@ public class QuickGauntletLister extends JPanel { // Note: careful with the widths of the rows here; // scroll panes will have difficulty dynamically resizing if 100% width is set. final JPanel rowTitle = new JPanel(); - rowTitle.setBackground(FSkin.getColor(FSkin.Colors.CLR_ZEBRA)); + FSkin.get(rowTitle).setBackground(FSkin.getColor(FSkin.Colors.CLR_ZEBRA)); rowTitle.setLayout(new MigLayout("insets 0, gap 0")); rowTitle.add(new FLabel.Builder().build(), "w 30px!, h 20px!, gap 1% 0 5px 0"); @@ -126,10 +126,11 @@ public class QuickGauntletLister extends JPanel { private class DeleteButton extends JButton { public DeleteButton(final RowPanel r0) { super(); + FSkin.AbstractButtonSkin skin = FSkin.get(this); setRolloverEnabled(true); - setPressedIcon(icoDeleteOver); - setRolloverIcon(icoDeleteOver); - setIcon(icoDelete); + skin.setPressedIcon(icoDeleteOver); + skin.setRolloverIcon(icoDeleteOver); + skin.setIcon(icoDelete); setOpaque(false); setContentAreaFilled(false); setBorder(null); @@ -140,14 +141,14 @@ public class QuickGauntletLister extends JPanel { @Override public void mouseEntered(MouseEvent e) { if (!r0.selected) { - r0.setBackground(clrHover); + FSkin.get(r0).setBackground(clrHover); r0.setOpaque(true); } } @Override public void mouseExited(MouseEvent e) { if (!r0.selected) { - r0.setBackground(clrDefault); + FSkin.get(r0).setBackground(clrDefault); r0.setOpaque(false); } } @@ -168,21 +169,21 @@ public class QuickGauntletLister extends JPanel { setOpaque(false); setBackground(new Color(0, 0, 0, 0)); setLayout(new MigLayout("insets 0, gap 0")); - setBorder(new MatteBorder(0, 0, 1, 0, clrBorders)); + FSkin.get(this).setMatteBorder(0, 0, 1, 0, clrBorders); gauntletData = gd0; this.addMouseListener(new MouseAdapter() { @Override public void mouseEntered(MouseEvent e) { if (!selected) { - ((RowPanel) e.getSource()).setBackground(clrHover); + FSkin.get(((RowPanel) e.getSource())).setBackground(clrHover); ((RowPanel) e.getSource()).setOpaque(true); } } @Override public void mouseExited(MouseEvent e) { if (!selected) { - ((RowPanel) e.getSource()).setBackground(clrDefault); + FSkin.get(((RowPanel) e.getSource())).setBackground(clrDefault); ((RowPanel) e.getSource()).setOpaque(false); } } @@ -196,7 +197,7 @@ public class QuickGauntletLister extends JPanel { public void setSelected(boolean b0) { selected = b0; setOpaque(b0); - setBackground(b0 ? clrActive : clrHover); + FSkin.get(this).setBackground(b0 ? clrActive : clrHover); } public boolean isSelected() { diff --git a/src/main/java/forge/gui/home/gauntlet/VSubmenuGauntletBuild.java b/src/main/java/forge/gui/home/gauntlet/VSubmenuGauntletBuild.java index ea8eba3ed23..2dbe1c30a46 100644 --- a/src/main/java/forge/gui/home/gauntlet/VSubmenuGauntletBuild.java +++ b/src/main/java/forge/gui/home/gauntlet/VSubmenuGauntletBuild.java @@ -2,7 +2,6 @@ package forge.gui.home.gauntlet; import java.awt.Color; -import javax.swing.ImageIcon; import javax.swing.JLabel; import javax.swing.JList; import javax.swing.JPanel; @@ -74,22 +73,22 @@ public enum VSubmenuGauntletBuild implements IVSubmenu { private final FLabel btnUp = new FLabel.Builder() .tooltip("Move this deck up in the gauntlet").hoverable(true) .iconScaleAuto(true).iconScaleFactor(1.0) - .icon(new ImageIcon(FSkin.getImage(FSkin.LayoutImages.IMG_CUR_T))).build(); + .icon(FSkin.getImage(FSkin.LayoutImages.IMG_CUR_T)).build(); private final FLabel btnDown = new FLabel.Builder() .tooltip("Move this deck down in the gauntlet").hoverable(true) .iconScaleAuto(true).iconScaleFactor(1.0) - .icon(new ImageIcon(FSkin.getImage(FSkin.LayoutImages.IMG_CUR_B))).build(); + .icon(FSkin.getImage(FSkin.LayoutImages.IMG_CUR_B)).build(); private final FLabel btnRight = new FLabel.Builder() .tooltip("Add this deck to the gauntlet").hoverable(true) .iconScaleAuto(true).iconScaleFactor(1.0) - .icon(new ImageIcon(FSkin.getImage(FSkin.LayoutImages.IMG_CUR_R))).build(); + .icon(FSkin.getImage(FSkin.LayoutImages.IMG_CUR_R)).build(); private final FLabel btnLeft = new FLabel.Builder() .tooltip("Remove this deck from the gauntlet").hoverable(true) .iconScaleAuto(true).iconScaleFactor(1.0) - .icon(new ImageIcon(FSkin.getImage(FSkin.LayoutImages.IMG_CUR_L))).build(); + .icon(FSkin.getImage(FSkin.LayoutImages.IMG_CUR_L)).build(); private final FLabel btnSave = new FLabel.Builder() .fontSize(14) @@ -116,7 +115,7 @@ public enum VSubmenuGauntletBuild implements IVSubmenu { .text(" ").hoverable(true).build(); private VSubmenuGauntletBuild() { - lblTitle.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); + FSkin.get(lblTitle).setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); // File handling panel diff --git a/src/main/java/forge/gui/home/gauntlet/VSubmenuGauntletContests.java b/src/main/java/forge/gui/home/gauntlet/VSubmenuGauntletContests.java index 14a4bb54536..0d6e0fdfc57 100644 --- a/src/main/java/forge/gui/home/gauntlet/VSubmenuGauntletContests.java +++ b/src/main/java/forge/gui/home/gauntlet/VSubmenuGauntletContests.java @@ -59,11 +59,11 @@ public enum VSubmenuGauntletContests implements IVSubmenu { private final StartButton btnStart = new StartButton(); private VSubmenuGauntletLoad() { - lblTitle.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); + FSkin.get(lblTitle).setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); scrLoad.setBorder(null); } diff --git a/src/main/java/forge/gui/home/gauntlet/VSubmenuGauntletQuick.java b/src/main/java/forge/gui/home/gauntlet/VSubmenuGauntletQuick.java index 24f99d97b35..f91a640b59e 100644 --- a/src/main/java/forge/gui/home/gauntlet/VSubmenuGauntletQuick.java +++ b/src/main/java/forge/gui/home/gauntlet/VSubmenuGauntletQuick.java @@ -22,6 +22,7 @@ import forge.gui.toolbox.FCheckBox; import forge.gui.toolbox.FLabel; import forge.gui.toolbox.FPanel; import forge.gui.toolbox.FSkin; +import forge.gui.toolbox.FSkin.JComponentSkin; import forge.gui.toolbox.special.FDeckChooser; /** @@ -81,30 +82,28 @@ public enum VSubmenuGauntletQuick implements IVSubmenu { private final StartButton btnStart = new StartButton(); private VSubmenuGauntletQuick() { - lblTitle.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); + FSkin.get(lblTitle).setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); boxUserDecks.setSelected(true); boxQuestDecks.setSelected(true); boxThemeDecks.setSelected(true); boxColorDecks.setSelected(true); - + JComponentSkin sliOpponentsSkin = FSkin.get(sliOpponents); sliOpponents.setMajorTickSpacing(5); sliOpponents.setMinorTickSpacing(0); sliOpponents.setPaintTicks(false); sliOpponents.setPaintLabels(true); sliOpponents.setSnapToTicks(true); sliOpponents.setOpaque(false); - sliOpponents.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); - sliOpponents.setFont(FSkin.getFont(12)); - - + sliOpponentsSkin.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); + sliOpponentsSkin.setFont(FSkin.getFont(12)); scrLoad.setOpaque(false); scrLoad.getViewport().setOpaque(false); scrLoad.setBorder(null); - pnlOptions.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); + FSkin.get(pnlOptions).setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); pnlOptions.add(lblOptions, "h 30px!, w 96%!, gap 2% 0 0 5px"); pnlOptions.add(sliOpponents, "h 40px!, w 96%!, gap 2% 0 0 5px, ax center"); pnlOptions.add(lblDesc1, "w 96%!, gap 2% 0 0 20px"); diff --git a/src/main/java/forge/gui/home/quest/IVQuestStats.java b/src/main/java/forge/gui/home/quest/IVQuestStats.java index 36c94ab1e8a..5cc09e4f1d6 100644 --- a/src/main/java/forge/gui/home/quest/IVQuestStats.java +++ b/src/main/java/forge/gui/home/quest/IVQuestStats.java @@ -1,9 +1,9 @@ package forge.gui.home.quest; import javax.swing.JCheckBox; -import javax.swing.JComboBox; import javax.swing.JLabel; +import forge.gui.toolbox.FComboBoxWrapper; import forge.gui.toolbox.FLabel; /** Dictates methods required for a panel with stats/pet display. */ @@ -45,8 +45,8 @@ public interface IVQuestStats { /** @return {@link javax.swing.JLabel} */ JLabel getLblWinStreak(); - /** @return {@link javax.swing.JComboBox} */ - JComboBox getCbxPet(); + /** @return {@link javax.swing.FComboBoxWrapper} */ + FComboBoxWrapper getCbxPet(); /** @return {@link javax.swing.JCheckBox} */ JCheckBox getCbPlant(); diff --git a/src/main/java/forge/gui/home/quest/PnlEvent.java b/src/main/java/forge/gui/home/quest/PnlEvent.java index e8b61021ffe..b5e308e8b8f 100644 --- a/src/main/java/forge/gui/home/quest/PnlEvent.java +++ b/src/main/java/forge/gui/home/quest/PnlEvent.java @@ -2,10 +2,10 @@ package forge.gui.home.quest; import java.awt.AlphaComposite; import java.awt.Color; +import java.awt.Dimension; import java.awt.GradientPaint; import java.awt.Graphics; import java.awt.Graphics2D; -import java.awt.Image; import java.awt.image.BufferedImage; import javax.swing.JPanel; @@ -17,6 +17,9 @@ import net.miginfocom.swing.MigLayout; import forge.ImageCache; import forge.gui.toolbox.FRadioButton; import forge.gui.toolbox.FSkin; +import forge.gui.toolbox.FSkin.JComponentSkin; +import forge.gui.toolbox.FSkin.SkinColor; +import forge.gui.toolbox.FSkin.SkinImage; import forge.gui.toolbox.FTextArea; import forge.quest.QuestEvent; @@ -29,16 +32,16 @@ import forge.quest.QuestEvent; class PnlEvent extends JPanel { private final QuestEvent event; private final JRadioButton rad; - private final Image img; - private final int wSrc, hSrc; + private final SkinImage img; private final int wImg = 100; private final int hImg = 100; private final int hRfl = 20; + private final JComponentSkin skin; private final Color clr1 = new Color(255, 0, 255, 100); private final Color clr2 = new Color(255, 255, 0, 0); - private final Color clr3 = FSkin.alphaColor(FSkin.getColor(FSkin.Colors.CLR_THEME2), 200); + private final SkinColor clr3 = FSkin.getColor(FSkin.Colors.CLR_THEME2).alphaColor(200); /** * Panels for displaying duels and challenges.
@@ -49,19 +52,17 @@ class PnlEvent extends JPanel { */ public PnlEvent(final QuestEvent e0) { super(); + this.skin = FSkin.get(this); this.event = e0; - img = ImageCache.getIcon(e0).getImage(); - - wSrc = img.getWidth(null); - hSrc = img.getHeight(null); + img = ImageCache.getIcon(e0); // Title and description this.rad = new FRadioButton(event.getTitle() + " (" + event.getDifficulty().getTitle() + ")"); - this.rad.setFont(FSkin.getBoldFont(16)); + FSkin.get(this.rad).setFont(FSkin.getBoldFont(16)); final FTextArea tarDesc = new FTextArea(); tarDesc.setText(event.getDescription()); - tarDesc.setFont(FSkin.getItalicFont(12)); + FSkin.get(tarDesc).setFont(FSkin.getItalicFont(12)); // Change listener for radio button this.rad.addChangeListener(new ChangeListener() { @@ -93,16 +94,19 @@ class PnlEvent extends JPanel { @Override public void paintComponent(final Graphics g) { Graphics2D g2d = (Graphics2D) g.create(); - g2d.setPaint(new GradientPaint(0, 0, clr3, getWidth(), 0, clr2)); + skin.setGraphicsGradientPaint(g2d, 0, 0, clr3, getWidth(), 0, clr2); g2d.fillRect(0, 0, getWidth(), getHeight()); // Padding here g2d.translate(5, 5); + + Dimension srcSize = img.getSizeForPaint(g2d); + int wSrc = srcSize.width; + int hSrc = srcSize.height; - g2d.drawImage(img, + skin.drawImage(g2d, img, 0, 0, wImg, hImg, // Destination - 0, 0, wSrc, hSrc, // Source - null); + 0, 0, wSrc, hSrc); // Source // Gap between image and reflection set here g2d.translate(0, hImg + 2); @@ -111,10 +115,9 @@ class PnlEvent extends JPanel { BufferedImage refl = new BufferedImage(wImg, hImg, BufferedImage.TYPE_INT_ARGB); Graphics2D gRefl = refl.createGraphics(); - gRefl.drawImage(img, + skin.drawImage(gRefl, img, 0, hRfl, wImg, 0, // Destination - 0, hSrc - hRfl * hSrc / hImg, wSrc, hSrc, // Source - null); + 0, hSrc - hRfl * hSrc / hImg, wSrc, hSrc); // Source gRefl.setPaint(new GradientPaint(0, 0, clr1, 0, hRfl, clr2)); gRefl.setComposite(AlphaComposite.DstIn); diff --git a/src/main/java/forge/gui/home/quest/QuestFileLister.java b/src/main/java/forge/gui/home/quest/QuestFileLister.java index 50b84861d9b..fa0f9fd1f76 100644 --- a/src/main/java/forge/gui/home/quest/QuestFileLister.java +++ b/src/main/java/forge/gui/home/quest/QuestFileLister.java @@ -9,13 +9,10 @@ import java.util.Collections; import java.util.Comparator; import java.util.List; -import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.SwingConstants; -import javax.swing.border.MatteBorder; - import net.miginfocom.swing.MigLayout; import forge.Command; import forge.gui.toolbox.FLabel; @@ -29,11 +26,12 @@ import forge.quest.data.QuestData; */ @SuppressWarnings("serial") public class QuestFileLister extends JPanel { - private ImageIcon icoDelete, icoDeleteOver, icoEdit, icoEditOver; + private FSkin.SkinIcon icoDelete, icoDeleteOver, icoEdit, icoEditOver; private RowPanel previousSelect; private RowPanel[] rows; private Command cmdRowSelect, cmdRowDelete, cmdRowEdit; - private final Color clrDefault, clrHover, clrActive, clrBorders; + private final Color clrDefault; + private final FSkin.SkinColor clrHover, clrActive, clrBorders; /** */ public QuestFileLister() { @@ -81,7 +79,7 @@ public class QuestFileLister extends JPanel { // Note: careful with the widths of the rows here; // scroll panes will have difficulty dynamically resizing if 100% width is set. final JPanel rowTitle = new JPanel(); - rowTitle.setBackground(FSkin.getColor(FSkin.Colors.CLR_ZEBRA)); + FSkin.get(rowTitle).setBackground(FSkin.getColor(FSkin.Colors.CLR_ZEBRA)); rowTitle.setLayout(new MigLayout("insets 0, gap 0")); rowTitle.add(new FLabel.Builder().text("Delete").fontAlign(SwingConstants.CENTER).build(), "w 15%!, h 20px!, gap 0 0 5px 0"); rowTitle.add(new FLabel.Builder().text("Rename").fontAlign(SwingConstants.CENTER).build(), "w 15%!, h 20px!, gap 0 0 5px 0"); @@ -117,10 +115,11 @@ public class QuestFileLister extends JPanel { private class DeleteButton extends JButton { public DeleteButton(final RowPanel r0) { super(); + FSkin.AbstractButtonSkin skin = FSkin.get(this); setRolloverEnabled(true); - setPressedIcon(icoDeleteOver); - setRolloverIcon(icoDeleteOver); - setIcon(icoDelete); + skin.setPressedIcon(icoDeleteOver); + skin.setRolloverIcon(icoDeleteOver); + skin.setIcon(icoDelete); setOpaque(false); setContentAreaFilled(false); setBorder(null); @@ -131,14 +130,14 @@ public class QuestFileLister extends JPanel { @Override public void mouseEntered(MouseEvent e) { if (!r0.selected) { - r0.setBackground(clrHover); + FSkin.get(r0).setBackground(clrHover); r0.setOpaque(true); } } @Override public void mouseExited(MouseEvent e) { if (!r0.selected) { - r0.setBackground(clrDefault); + FSkin.get(r0).setBackground(clrDefault); r0.setOpaque(false); } } @@ -153,10 +152,11 @@ public class QuestFileLister extends JPanel { private class EditButton extends JButton { public EditButton(final RowPanel r0) { super(); + FSkin.AbstractButtonSkin skin = FSkin.get(this); setRolloverEnabled(true); - setPressedIcon(icoEditOver); - setRolloverIcon(icoEditOver); - setIcon(icoEdit); + skin.setPressedIcon(icoEditOver); + skin.setRolloverIcon(icoEditOver); + skin.setIcon(icoEdit); setOpaque(false); setContentAreaFilled(false); setBorder(null); @@ -167,14 +167,14 @@ public class QuestFileLister extends JPanel { @Override public void mouseEntered(MouseEvent e) { if (!r0.selected) { - r0.setBackground(clrHover); + FSkin.get(r0).setBackground(clrHover); r0.setOpaque(true); } } @Override public void mouseExited(MouseEvent e) { if (!r0.selected) { - r0.setBackground(clrDefault); + FSkin.get(r0).setBackground(clrDefault); r0.setOpaque(false); } } @@ -195,21 +195,21 @@ public class QuestFileLister extends JPanel { setOpaque(false); setBackground(new Color(0, 0, 0, 0)); setLayout(new MigLayout("insets 0, gap 0")); - setBorder(new MatteBorder(0, 0, 1, 0, clrBorders)); + FSkin.get(this).setMatteBorder(0, 0, 1, 0, clrBorders); questData = qd0; this.addMouseListener(new MouseAdapter() { @Override public void mouseEntered(MouseEvent e) { if (!selected) { - ((RowPanel) e.getSource()).setBackground(clrHover); + FSkin.get(((RowPanel) e.getSource())).setBackground(clrHover); ((RowPanel) e.getSource()).setOpaque(true); } } @Override public void mouseExited(MouseEvent e) { if (!selected) { - ((RowPanel) e.getSource()).setBackground(clrDefault); + FSkin.get(((RowPanel) e.getSource())).setBackground(clrDefault); ((RowPanel) e.getSource()).setOpaque(false); } } @@ -223,7 +223,7 @@ public class QuestFileLister extends JPanel { public void setSelected(boolean b0) { selected = b0; setOpaque(b0); - setBackground(b0 ? clrActive : clrHover); + FSkin.get(this).setBackground(b0 ? clrActive : clrHover); } public boolean isSelected() { diff --git a/src/main/java/forge/gui/home/quest/QuestPreferencesHandler.java b/src/main/java/forge/gui/home/quest/QuestPreferencesHandler.java index fba3b462c20..142260b9f0b 100644 --- a/src/main/java/forge/gui/home/quest/QuestPreferencesHandler.java +++ b/src/main/java/forge/gui/home/quest/QuestPreferencesHandler.java @@ -7,7 +7,6 @@ import java.awt.event.FocusEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; -import javax.swing.ImageIcon; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.SwingConstants; @@ -16,6 +15,7 @@ import net.miginfocom.swing.MigLayout; import forge.Singletons; import forge.gui.toolbox.FLabel; import forge.gui.toolbox.FSkin; +import forge.gui.toolbox.FSkin.JTextComponentSkin; import forge.quest.data.QuestPreferences; import forge.quest.data.QuestPreferences.QPref; @@ -63,7 +63,7 @@ public class QuestPreferencesHandler extends JPanel { pnlRewards.setLayout(new MigLayout("insets 0, gap 0, wrap 2")); pnlRewards.add(new FLabel.Builder().text("Rewards") - .icon(new ImageIcon("res/images/icons/CoinIcon.png")).build(), + .icon(new FSkin.UnskinnedIcon("res/images/icons/CoinIcon.png")).build(), "w 100%!, h 30px!, span 2 1"); pnlRewards.add(lblErrRewards, "w 100%!, h 30px!, span 2 1"); @@ -104,7 +104,7 @@ public class QuestPreferencesHandler extends JPanel { pnlDifficulty.setOpaque(false); pnlDifficulty.setLayout(new MigLayout("insets 0, gap 0, wrap 5")); - pnlDifficulty.add(new FLabel.Builder().text("Difficulty Adjustments").icon(new ImageIcon("res/images/icons/NotesIcon.png")).build(), "w 100%!, h 30px!, span 5 1"); + pnlDifficulty.add(new FLabel.Builder().text("Difficulty Adjustments").icon(new FSkin.UnskinnedIcon("res/images/icons/NotesIcon.png")).build(), "w 100%!, h 30px!, span 5 1"); pnlDifficulty.add(lblErrDifficulty, "w 100%!, h 30px!, span 5 1"); constraints1 = "w 60px!, h 26px!"; @@ -184,7 +184,7 @@ public class QuestPreferencesHandler extends JPanel { pnlBooster.setLayout(new MigLayout("insets 0, gap 0, wrap 2")); pnlBooster.add(new FLabel.Builder().text("Booster Pack Ratios") - .icon(new ImageIcon("res/images/icons/BookIcon.png")).build(), + .icon(new FSkin.UnskinnedIcon("res/images/icons/BookIcon.png")).build(), "w 100%!, h 30px!, span 2 1"); pnlBooster.add(lblErrBooster, "w 100%!, h 30px!, span 2 1"); @@ -204,7 +204,7 @@ public class QuestPreferencesHandler extends JPanel { pnlShop.setLayout(new MigLayout("insets 0, gap 0, wrap 2")); pnlShop.add(new FLabel.Builder().text("Shop Preferences") - .icon(new ImageIcon("res/images/icons/CoinIcon.png")).build(), "w 100%!, h 30px!, span 2 1"); + .icon(new FSkin.UnskinnedIcon("res/images/icons/CoinIcon.png")).build(), "w 100%!, h 30px!, span 2 1"); pnlShop.add(lblErrShop, "w 100%!, h 30px!, span 2 1"); constraints1 = "w 60px, h 26px!"; @@ -240,7 +240,8 @@ public class QuestPreferencesHandler extends JPanel { private class PrefInput extends JTextField { private final QPref qpref; private final ErrType err; - private final Color clrHover, clrActive, clrText; + private final JTextComponentSkin skin; + private final FSkin.SkinColor clrHover, clrActive, clrText; private boolean isFocus = false; private String previousText = ""; @@ -255,16 +256,17 @@ public class QuestPreferencesHandler extends JPanel { this.qpref = qp0; this.err = e0; + this.skin = FSkin.get(this); this.clrHover = FSkin.getColor(FSkin.Colors.CLR_HOVER); this.clrActive = FSkin.getColor(FSkin.Colors.CLR_ACTIVE); this.clrText = FSkin.getColor(FSkin.Colors.CLR_TEXT); this.setOpaque(false); this.setBorder(null); - this.setFont(FSkin.getFont(13)); - this.setForeground(clrText); - this.setCaretColor(clrText); - this.setBackground(clrHover); + this.skin.setFont(FSkin.getFont(13)); + this.skin.setForeground(clrText); + this.skin.setCaretColor(clrText); + this.skin.setBackground(clrHover); this.setHorizontalAlignment(SwingConstants.CENTER); this.setText(prefs.getPref(qpref)); this.setPreviousText(prefs.getPref(qpref)); @@ -290,14 +292,14 @@ public class QuestPreferencesHandler extends JPanel { public void focusGained(FocusEvent e) { isFocus = true; setOpaque(true); - setBackground(clrActive); + skin.setBackground(clrActive); } @Override public void focusLost(FocusEvent e) { isFocus = false; setOpaque(false); - setBackground(clrHover); + skin.setBackground(clrHover); // TODO for slight performance improvement // check if value has changed before validating diff --git a/src/main/java/forge/gui/home/quest/SSubmenuQuestUtil.java b/src/main/java/forge/gui/home/quest/SSubmenuQuestUtil.java index 81e49e80396..32c515a437c 100644 --- a/src/main/java/forge/gui/home/quest/SSubmenuQuestUtil.java +++ b/src/main/java/forge/gui/home/quest/SSubmenuQuestUtil.java @@ -124,10 +124,14 @@ public class SSubmenuQuestUtil { if (view.equals(VSubmenuChallenges.SINGLETON_INSTANCE)) { view.getLblZep().setVisible(qCtrl.getAssets().hasItem(QuestItemType.ZEPPELIN)); - view.getLblZep().setEnabled(qCtrl.getAssets().getItemLevel( - QuestItemType.ZEPPELIN) == 2 ? false : true); - view.getLblZep().setForeground(qCtrl.getAssets().getItemLevel( - QuestItemType.ZEPPELIN) == 2 ? Color.gray : FSkin.getColor(FSkin.Colors.CLR_TEXT)); + if (qCtrl.getAssets().getItemLevel(QuestItemType.ZEPPELIN) == 2) { + view.getLblZep().setEnabled(false); + FSkin.get(view.getLblZep()).setForeground(Color.gray); + } + else { + view.getLblZep().setEnabled(true); + FSkin.get(view.getLblZep()).setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); + } } else { view.getLblZep().setVisible(false); @@ -193,7 +197,7 @@ public class SSubmenuQuestUtil { lblCurrentDeck.setText("Build, then select a deck in the \"Decks\" submenu. "); } else { - lblCurrentDeck.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); + FSkin.get(lblCurrentDeck).setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); lblCurrentDeck.setText("Your current deck is \"" + SSubmenuQuestUtil.getCurrentDeck().getName() + "\"."); } diff --git a/src/main/java/forge/gui/home/quest/VSubmenuChallenges.java b/src/main/java/forge/gui/home/quest/VSubmenuChallenges.java index 262ea1e4b2c..028336213c3 100644 --- a/src/main/java/forge/gui/home/quest/VSubmenuChallenges.java +++ b/src/main/java/forge/gui/home/quest/VSubmenuChallenges.java @@ -4,7 +4,6 @@ import java.awt.Font; import javax.swing.JButton; import javax.swing.JCheckBox; -import javax.swing.JComboBox; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.ScrollPaneConstants; @@ -20,6 +19,7 @@ import forge.gui.home.LblHeader; import forge.gui.home.StartButton; import forge.gui.home.VHomeUI; import forge.gui.toolbox.FCheckBox; +import forge.gui.toolbox.FComboBoxWrapper; import forge.gui.toolbox.FLabel; import forge.gui.toolbox.FScrollPane; import forge.gui.toolbox.FSkin; @@ -46,7 +46,7 @@ public enum VSubmenuChallenges implements IVSubmenu, IVQuest ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); private final JButton btnStart = new StartButton(); - private final JComboBox cbxPet = new JComboBox(); + private final FComboBoxWrapper cbxPet = new FComboBoxWrapper(); private final JCheckBox cbPlant = new FCheckBox("Summon Plant"); private final JLabel lblZep = new FLabel.Builder().text("Launch
Zeppelin") .hoverable(true).icon(FSkin.getIcon(FSkin.QuestIcons.ICO_ZEP)) @@ -109,7 +109,7 @@ public enum VSubmenuChallenges implements IVSubmenu, IVQuest pnlStats.add(lblLife, constraints); pnlStats.add(lblWorld, constraints); pnlStats.add(cbPlant, constraints); - pnlStats.add(cbxPet, constraints); + cbxPet.addTo(pnlStats, constraints); pnlStats.add(lblZep, "w 130px!, h 60px!, gap 0 0 0 5px"); pnlStats.setOpaque(false); } @@ -248,7 +248,7 @@ public enum VSubmenuChallenges implements IVSubmenu, IVQuest } @Override - public JComboBox getCbxPet() { + public FComboBoxWrapper getCbxPet() { return cbxPet; } diff --git a/src/main/java/forge/gui/home/quest/VSubmenuDuels.java b/src/main/java/forge/gui/home/quest/VSubmenuDuels.java index 69447b5bd0c..7a907bb411d 100644 --- a/src/main/java/forge/gui/home/quest/VSubmenuDuels.java +++ b/src/main/java/forge/gui/home/quest/VSubmenuDuels.java @@ -4,7 +4,6 @@ import java.awt.Font; import javax.swing.JButton; import javax.swing.JCheckBox; -import javax.swing.JComboBox; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.ScrollPaneConstants; @@ -20,6 +19,7 @@ import forge.gui.home.LblHeader; import forge.gui.home.StartButton; import forge.gui.home.VHomeUI; import forge.gui.toolbox.FCheckBox; +import forge.gui.toolbox.FComboBoxWrapper; import forge.gui.toolbox.FLabel; import forge.gui.toolbox.FScrollPane; import forge.gui.toolbox.FSkin; @@ -45,7 +45,7 @@ public enum VSubmenuDuels implements IVSubmenu, IVQuestStats { ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); private final JButton btnStart = new StartButton(); - private final JComboBox cbxPet = new JComboBox(); + private final FComboBoxWrapper cbxPet = new FComboBoxWrapper(); private final JCheckBox cbPlant = new FCheckBox("Summon Plant"); private final JLabel lblZep = new FLabel.Builder().text("Launch Zeppelin").fontSize(14).build(); @@ -107,7 +107,7 @@ public enum VSubmenuDuels implements IVSubmenu, IVQuestStats { pnlStats.add(lblLife, constraints); pnlStats.add(lblWorld, constraints); pnlStats.add(cbPlant, constraints); - pnlStats.add(cbxPet, constraints); + cbxPet.addTo(pnlStats, constraints); pnlStats.setOpaque(false); } @@ -241,7 +241,7 @@ public enum VSubmenuDuels implements IVSubmenu, IVQuestStats { } @Override - public JComboBox getCbxPet() { + public FComboBoxWrapper getCbxPet() { return cbxPet; } diff --git a/src/main/java/forge/gui/home/quest/VSubmenuQuestData.java b/src/main/java/forge/gui/home/quest/VSubmenuQuestData.java index c5afdc50199..a8069f055c4 100644 --- a/src/main/java/forge/gui/home/quest/VSubmenuQuestData.java +++ b/src/main/java/forge/gui/home/quest/VSubmenuQuestData.java @@ -7,7 +7,6 @@ import java.util.HashMap; import java.util.Map; import javax.swing.JCheckBox; -import javax.swing.JComboBox; import javax.swing.JLabel; import javax.swing.JList; import javax.swing.JPanel; @@ -31,6 +30,7 @@ import forge.gui.home.EMenuGroup; import forge.gui.home.IVSubmenu; import forge.gui.home.VHomeUI; import forge.gui.toolbox.FCheckBox; +import forge.gui.toolbox.FComboBoxWrapper; import forge.gui.toolbox.FLabel; import forge.gui.toolbox.FRadioButton; import forge.gui.toolbox.FScrollPane; @@ -79,33 +79,33 @@ public enum VSubmenuQuestData implements IVSubmenu { private final JCheckBox boxFantasy = new FCheckBox("Fantasy Mode"); private final JLabel lblStartingWorld = new FLabel.Builder().text("Starting world:").build(); - private final JComboBox cbxStartingWorld = new JComboBox(); + private final FComboBoxWrapper cbxStartingWorld = new FComboBoxWrapper(); /* Second column */ private final JLabel lblStartingPool = new FLabel.Builder().text("Starting pool:").build(); - private final JComboBox cbxStartingPool = new JComboBox(); + private final FComboBoxWrapper cbxStartingPool = new FComboBoxWrapper(); private final JLabel lblUnrestricted = new FLabel.Builder().text("All cards will be available to play.").build(); private final JLabel lblPreconDeck = new FLabel.Builder().text("Starter/Event deck:").build(); - private final JComboBox cbxPreconDeck = new JComboBox(); + private final FComboBoxWrapper cbxPreconDeck = new FComboBoxWrapper(); private final JLabel lblFormat = new FLabel.Builder().text("Sanctioned format:").build(); - private final JComboBox cbxFormat = new JComboBox(); + private final FComboBoxWrapper cbxFormat = new FComboBoxWrapper(); private final JLabel lblCustomDeck = new FLabel.Builder().text("Custom deck:").build(); - private final JComboBox cbxCustomDeck = new JComboBox(); + private final FComboBoxWrapper cbxCustomDeck = new FComboBoxWrapper(); private final FLabel btnDefineCustomFormat = new FLabel.Builder().opaque(true).hoverable(true).text("Define custom format").build(); private final FLabel btnPrizeDefineCustomFormat = new FLabel.Builder().opaque(true).hoverable(true).text("Define custom format").build(); private final JLabel lblPrizedCards = new FLabel.Builder().text("Prized cards:").build(); - private final JComboBox cbxPrizedCards = new JComboBox(); + private final FComboBoxWrapper cbxPrizedCards = new FComboBoxWrapper(); private final JLabel lblPrizeFormat = new FLabel.Builder().text("Sanctioned format:").build(); - private final JComboBox cbxPrizeFormat = new JComboBox(); + private final FComboBoxWrapper cbxPrizeFormat = new FComboBoxWrapper(); private final JLabel lblPrizeUnrestricted = new FLabel.Builder().text("All cards will be available to win.").build(); private final JLabel lblPrizeSameAsStarting = new FLabel.Builder().text("Only sets found in starting pool will be available.").build(); @@ -199,8 +199,8 @@ public enum VSubmenuQuestData implements IVSubmenu { */ @SuppressWarnings("unchecked") private VSubmenuQuestData() { - lblTitle.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); - lblTitleNew.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); + FSkin.get(lblTitle).setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); + FSkin.get(lblTitleNew).setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); scrQuests.setBorder(null); @@ -302,28 +302,28 @@ public enum VSubmenuQuestData implements IVSubmenu { pnlRestrictions.setLayout(new MigLayout("insets 0, gap 0, wrap 2", "[120, al right][240, fill]", "[|]12[|]6[]")); pnlRestrictions.add(lblStartingPool, constraints + lblWidthStart); - pnlRestrictions.add(cbxStartingPool, constraints + cboWidthStart); + cbxStartingPool.addTo(pnlRestrictions, constraints + cboWidthStart); /* out of these 3 groups only one will be visible */ pnlRestrictions.add(lblUnrestricted, constraints + hidemode + "spanx 2"); pnlRestrictions.add(lblPreconDeck, constraints + lblWidthStart); - pnlRestrictions.add(cbxPreconDeck, constraints + cboWidthStart); + cbxPreconDeck.addTo(pnlRestrictions, constraints + cboWidthStart); pnlRestrictions.add(lblCustomDeck, constraints + lblWidthStart); - pnlRestrictions.add(cbxCustomDeck, constraints + cboWidthStart); // , skip 1 + cbxCustomDeck.addTo(pnlRestrictions, constraints + cboWidthStart); // , skip 1 pnlRestrictions.add(lblFormat, constraints + lblWidthStart); - pnlRestrictions.add(cbxFormat, constraints + cboWidthStart); // , skip 1 + cbxFormat.addTo(pnlRestrictions, constraints + cboWidthStart); // , skip 1 pnlRestrictions.add(btnDefineCustomFormat, constraints + hidemode + "spanx 2, w 240px"); // Prized cards options pnlRestrictions.add(lblPrizedCards, constraints + lblWidth); - pnlRestrictions.add(cbxPrizedCards, constraints + cboWidth); + cbxPrizedCards.addTo(pnlRestrictions, constraints + cboWidth); pnlRestrictions.add(lblPrizeFormat, constraints + lblWidthStart); - pnlRestrictions.add(cbxPrizeFormat, constraints + cboWidthStart); // , skip 1 + cbxPrizeFormat.addTo(pnlRestrictions, constraints + cboWidthStart); // , skip 1 pnlRestrictions.add(btnPrizeDefineCustomFormat, constraints + hidemode + "spanx 2, w 240px"); pnlRestrictions.add(lblPrizeSameAsStarting, constraints + hidemode + "spanx 2"); pnlRestrictions.add(lblPrizeUnrestricted, constraints + hidemode + "spanx 2"); @@ -331,7 +331,7 @@ public enum VSubmenuQuestData implements IVSubmenu { pnlRestrictions.add(cboAllowUnlocks, constraints + "spanx 2, ax right"); pnlRestrictions.add(lblStartingWorld, constraints + lblWidthStart); - pnlRestrictions.add(cbxStartingWorld, constraints + cboWidthStart); + cbxStartingWorld.addTo(pnlRestrictions, constraints + cboWidthStart); // cboAllowUnlocks.setOpaque(false); pnlRestrictions.setOpaque(false); diff --git a/src/main/java/forge/gui/home/quest/VSubmenuQuestDecks.java b/src/main/java/forge/gui/home/quest/VSubmenuQuestDecks.java index 84cb34c7401..7ec30757743 100644 --- a/src/main/java/forge/gui/home/quest/VSubmenuQuestDecks.java +++ b/src/main/java/forge/gui/home/quest/VSubmenuQuestDecks.java @@ -44,7 +44,7 @@ public enum VSubmenuQuestDecks implements IVSubmenu { * Constructor. */ private VSubmenuQuestDecks() { - lblTitle.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); + FSkin.get(lblTitle).setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); scr.setBorder(null); scr.getViewport().setBorder(null); diff --git a/src/main/java/forge/gui/home/quest/VSubmenuQuestPrefs.java b/src/main/java/forge/gui/home/quest/VSubmenuQuestPrefs.java index 603f63190bd..952c76f0466 100644 --- a/src/main/java/forge/gui/home/quest/VSubmenuQuestPrefs.java +++ b/src/main/java/forge/gui/home/quest/VSubmenuQuestPrefs.java @@ -25,6 +25,8 @@ import forge.gui.toolbox.FLabel; import forge.gui.toolbox.FPanel; import forge.gui.toolbox.FScrollPane; import forge.gui.toolbox.FSkin; +import forge.gui.toolbox.FSkin.JTextComponentSkin; +import forge.gui.toolbox.FSkin.SkinColor; import forge.quest.data.QuestPreferences; import forge.quest.data.QuestPreferences.QPref; @@ -76,7 +78,7 @@ public enum VSubmenuQuestPrefs implements IVSubmenu { * Constructor. */ private VSubmenuQuestPrefs() { - lblTitle.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); + FSkin.get(lblTitle).setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); pnlContent.setOpaque(false); pnlContent.setLayout(new MigLayout("insets 0, gap 0, wrap")); @@ -89,7 +91,7 @@ public enum VSubmenuQuestPrefs implements IVSubmenu { // Rewards panel final FPanel pnlTitleRewards = new FPanel(); pnlTitleRewards.setLayout(new MigLayout("insets 0, align center")); - pnlTitleRewards.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); + FSkin.get(pnlTitleRewards).setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); pnlTitleRewards.add(new FLabel.Builder().text("Rewards") .icon(FSkin.getIcon(FSkin.QuestIcons.ICO_COIN)) .fontSize(16).build(), "h 95%!, gap 0 0 2.5% 0"); @@ -101,7 +103,7 @@ public enum VSubmenuQuestPrefs implements IVSubmenu { // Booster panel final FPanel pnlTitleBooster = new FPanel(); pnlTitleBooster.setLayout(new MigLayout("insets 0, align center")); - pnlTitleBooster.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); + FSkin.get(pnlTitleBooster).setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); pnlTitleBooster.add(new FLabel.Builder().text("Booster Pack Ratios") .icon(FSkin.getIcon(FSkin.QuestIcons.ICO_BOOK)) .fontSize(16).build(), "h 95%!, gap 0 0 2.5% 0"); @@ -112,7 +114,7 @@ public enum VSubmenuQuestPrefs implements IVSubmenu { // Difficulty table panel final FPanel pnlTitleDifficulty = new FPanel(); pnlTitleDifficulty.setLayout(new MigLayout("insets 0, align center")); - pnlTitleDifficulty.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); + FSkin.get(pnlTitleDifficulty).setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); pnlTitleDifficulty.add(new FLabel.Builder().text("Difficulty Adjustments") .icon(FSkin.getIcon(FSkin.QuestIcons.ICO_NOTES)) .fontSize(16).build(), "h 95%!, gap 0 0 2.5% 0"); @@ -123,7 +125,7 @@ public enum VSubmenuQuestPrefs implements IVSubmenu { // Shop panel final FPanel pnlTitleShop = new FPanel(); pnlTitleShop.setLayout(new MigLayout("insets 0, align center")); - pnlTitleShop.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); + FSkin.get(pnlTitleShop).setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); pnlTitleShop.add(new FLabel.Builder().text("Shop Preferences") .icon(FSkin.getIcon(FSkin.QuestIcons.ICO_COIN)) .fontSize(16).build(), "h 95%!, gap 0 0 2.5% 0"); @@ -373,7 +375,8 @@ public enum VSubmenuQuestPrefs implements IVSubmenu { public class PrefInput extends JTextField { private final QPref qpref; private final QuestPreferencesErrType err; - private final Color clrHover, clrActive, clrText; + private final JTextComponentSkin skin; + private final SkinColor clrHover, clrActive, clrText; private boolean isFocus = false; private String previousText = ""; @@ -388,16 +391,17 @@ public enum VSubmenuQuestPrefs implements IVSubmenu { this.qpref = qp0; this.err = e0; + this.skin = FSkin.get(this); this.clrHover = FSkin.getColor(FSkin.Colors.CLR_HOVER); this.clrActive = FSkin.getColor(FSkin.Colors.CLR_ACTIVE); this.clrText = FSkin.getColor(FSkin.Colors.CLR_TEXT); this.setOpaque(false); this.setBorder(null); - this.setFont(FSkin.getFont(13)); - this.setForeground(clrText); - this.setCaretColor(clrText); - this.setBackground(clrHover); + this.skin.setFont(FSkin.getFont(13)); + this.skin.setForeground(clrText); + this.skin.setCaretColor(clrText); + this.skin.setBackground(clrHover); this.setHorizontalAlignment(SwingConstants.CENTER); this.setText(prefs.getPref(qpref)); this.setPreviousText(prefs.getPref(qpref)); @@ -423,14 +427,14 @@ public enum VSubmenuQuestPrefs implements IVSubmenu { public void focusGained(FocusEvent e) { isFocus = true; setOpaque(true); - setBackground(clrActive); + skin.setBackground(clrActive); } @Override public void focusLost(FocusEvent e) { isFocus = false; setOpaque(false); - setBackground(clrHover); + skin.setBackground(clrHover); CSubmenuQuestPrefs.validateAndSave(PrefInput.this); } diff --git a/src/main/java/forge/gui/home/sanctioned/VSubmenuConstructed.java b/src/main/java/forge/gui/home/sanctioned/VSubmenuConstructed.java index c4515e62c9c..87e93819a48 100644 --- a/src/main/java/forge/gui/home/sanctioned/VSubmenuConstructed.java +++ b/src/main/java/forge/gui/home/sanctioned/VSubmenuConstructed.java @@ -48,7 +48,7 @@ public enum VSubmenuConstructed implements IVSubmenu { private VSubmenuConstructed() { - lblTitle.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); + FSkin.get(lblTitle).setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); pnlStart = new JPanel(new MigLayout("insets 0, gap 0, wrap 2")); final String strCheckboxConstraints = "pushy, gap 0 20px 0 0"; @@ -59,8 +59,6 @@ public enum VSubmenuConstructed implements IVSubmenu { //pnlStart.add(cbAiVsAi, strCheckboxConstraintsTop); pnlStart.add(cbArtifacts, strCheckboxConstraints); pnlStart.add(cbRemoveSmall, strCheckboxConstraints); - - } /* (non-Javadoc) diff --git a/src/main/java/forge/gui/home/sanctioned/VSubmenuDraft.java b/src/main/java/forge/gui/home/sanctioned/VSubmenuDraft.java index 60eac6d8298..5fcccbbcc1b 100644 --- a/src/main/java/forge/gui/home/sanctioned/VSubmenuDraft.java +++ b/src/main/java/forge/gui/home/sanctioned/VSubmenuDraft.java @@ -79,7 +79,7 @@ public enum VSubmenuDraft implements IVSubmenu { lstAI.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); btnStart.setEnabled(false); - lblTitle.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); + FSkin.get(lblTitle).setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); JXButtonPanel grpPanel = new JXButtonPanel(); grpPanel.add(radSingle, "w 200px!, h 30px!"); diff --git a/src/main/java/forge/gui/home/sanctioned/VSubmenuSealed.java b/src/main/java/forge/gui/home/sanctioned/VSubmenuSealed.java index 13f74fe82af..da164feb6c0 100644 --- a/src/main/java/forge/gui/home/sanctioned/VSubmenuSealed.java +++ b/src/main/java/forge/gui/home/sanctioned/VSubmenuSealed.java @@ -30,6 +30,7 @@ import forge.gui.toolbox.FLabel; import forge.gui.toolbox.FPanel; import forge.gui.toolbox.FScrollPane; import forge.gui.toolbox.FSkin; +import forge.gui.toolbox.FSkin.JTextComponentSkin; import forge.gui.toolbox.special.DeckLister; /** @@ -79,7 +80,7 @@ public enum VSubmenuSealed implements IVSubmenu { private VSubmenuSealed() { btnStart.setEnabled(false); - lblTitle.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); + FSkin.get(lblTitle).setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); } /* (non-Javadoc) @@ -165,9 +166,10 @@ public enum VSubmenuSealed implements IVSubmenu { // Init directions text pane final JTextPane tpnDirections = new JTextPane(); + JTextComponentSkin tpnDirectionsSkin = FSkin.get(tpnDirections); tpnDirections.setOpaque(false); - tpnDirections.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); - tpnDirections.setFont(FSkin.getFont(15)); + tpnDirectionsSkin.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); + tpnDirectionsSkin.setFont(FSkin.getFont(15)); tpnDirections.setAlignmentX(SwingConstants.CENTER); tpnDirections.setFocusable(false); tpnDirections.setEditable(false); diff --git a/src/main/java/forge/gui/home/settings/CSubmenuPreferences.java b/src/main/java/forge/gui/home/settings/CSubmenuPreferences.java index 3eac7878b91..8275cc89463 100644 --- a/src/main/java/forge/gui/home/settings/CSubmenuPreferences.java +++ b/src/main/java/forge/gui/home/settings/CSubmenuPreferences.java @@ -24,6 +24,7 @@ import forge.gui.toolbox.FComboBoxPanel; import forge.gui.toolbox.FSkin; import forge.properties.ForgePreferences; import forge.properties.ForgePreferences.FPref; + import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -199,7 +200,7 @@ public enum CSubmenuPreferences implements ICDoc { File f = new File(fd); f.delete(); } - + private void initializeGameLogVerbosityComboBox() { FPref userSetting = FPref.DEV_LOG_ENTRY_TYPE; FComboBoxPanel panel = this.view.getGameLogVerbosityComboBoxPanel(); @@ -217,13 +218,22 @@ public enum CSubmenuPreferences implements ICDoc { } private void initializeSkinsComboBox() { - FPref userSetting = FPref.UI_SKIN; - FComboBoxPanel panel = this.view.getSkinsComboBoxPanel(); + final FComboBoxPanel panel = this.view.getSkinsComboBoxPanel(); String[] installedSkins = FSkin.getSkinNamesArray(true); validatePreferredSkinName(installedSkins); - JComboBox comboBox = createComboBox(installedSkins, userSetting); - String selectedItem = this.prefs.getPref(userSetting); + final JComboBox comboBox = new JComboBox(installedSkins); + String selectedItem = this.prefs.getPref(FPref.UI_SKIN); panel.setComboBox(comboBox, selectedItem); + comboBox.addItemListener(new ItemListener() { + @Override + public void itemStateChanged(final ItemEvent e) { + FSkin.changeSkin(panel.getSelectedItem().toString()); + } + }); + } + + public void updateCurrentSkin() { + this.view.getSkinsComboBoxPanel().setSelectedItem(this.prefs.getPref(FPref.UI_SKIN)); } private void validatePreferredSkinName(String[] installedSkins) { @@ -240,7 +250,7 @@ public enum CSubmenuPreferences implements ICDoc { } private void addComboBoxListener(final JComboBox comboBox, final ForgePreferences.FPref setting) { - comboBox.addItemListener(new ItemListener() { + comboBox.addItemListener(new ItemListener() { @SuppressWarnings("unchecked") @Override public void itemStateChanged(final ItemEvent e) { @@ -248,7 +258,6 @@ public enum CSubmenuPreferences implements ICDoc { CSubmenuPreferences.this.prefs.setPref(setting, selectedType.toString()); CSubmenuPreferences.this.prefs.save(); } - }); + }); } - } diff --git a/src/main/java/forge/gui/home/settings/VSubmenuAvatars.java b/src/main/java/forge/gui/home/settings/VSubmenuAvatars.java index 60f62b5cc58..9b81f3621dd 100644 --- a/src/main/java/forge/gui/home/settings/VSubmenuAvatars.java +++ b/src/main/java/forge/gui/home/settings/VSubmenuAvatars.java @@ -1,10 +1,8 @@ package forge.gui.home.settings; import java.awt.Dimension; -import java.awt.Image; import java.util.Map; -import javax.swing.ImageIcon; import javax.swing.JPanel; import javax.swing.ScrollPaneConstants; @@ -21,6 +19,7 @@ import forge.gui.home.VHomeUI; import forge.gui.toolbox.FLabel; import forge.gui.toolbox.FScrollPane; import forge.gui.toolbox.FSkin; +import forge.gui.toolbox.FSkin.SkinImage; import forge.properties.ForgePreferences.FPref; /** @@ -76,7 +75,7 @@ public enum VSubmenuAvatars implements IVSubmenu { @SuppressWarnings("serial") private void populateAvatars() { - final Map avatarMap = FSkin.getAvatars(); + final Map avatarMap = FSkin.getAvatars(); final JPanel pnlAvatarPics = new JPanel(new WrapLayout()); final JPanel pnlAvatarUsers = new JPanel(new MigLayout("insets 0, gap 0, align center")); @@ -121,16 +120,16 @@ public enum VSubmenuAvatars implements IVSubmenu { if (humanIndex >= FSkin.getAvatars().size()) { humanIndex = 0; } if (aiIndex >= FSkin.getAvatars().size()) { aiIndex = 0; } - lblAvatarAI.setIcon(new ImageIcon(FSkin.getAvatars().get(aiIndex))); - lblAvatarHuman.setIcon(new ImageIcon(FSkin.getAvatars().get(humanIndex))); + lblAvatarAI.setIcon(FSkin.getAvatars().get(aiIndex)); + lblAvatarHuman.setIcon(FSkin.getAvatars().get(humanIndex)); Singletons.getModel().getPreferences().setPref(FPref.UI_AVATARS, humanIndex + "," + aiIndex); Singletons.getModel().getPreferences().save(); } @SuppressWarnings("serial") - private FLabel makeAvatarLabel(final Image img0, final int index0) { - final FLabel lbl = new FLabel.Builder().icon(new ImageIcon(img0)).iconScaleFactor(1.0) + private FLabel makeAvatarLabel(final SkinImage img0, final int index0) { + final FLabel lbl = new FLabel.Builder().icon(img0).iconScaleFactor(1.0) .iconInBackground(true).hoverable(true).build(); final Dimension size = new Dimension(100, 100); @@ -145,12 +144,12 @@ public enum VSubmenuAvatars implements IVSubmenu { .getPref(FPref.UI_AVATARS).split(","); if (lblAvatarAI.getSelected()) { - lblAvatarAI.setIcon(new ImageIcon(FSkin.getAvatars().get(index0))); + lblAvatarAI.setIcon(FSkin.getAvatars().get(index0)); lblAvatarAI.repaintSelf(); indices[1] = String.valueOf(index0); } else { - lblAvatarHuman.setIcon(new ImageIcon(FSkin.getAvatars().get(index0))); + lblAvatarHuman.setIcon(FSkin.getAvatars().get(index0)); lblAvatarHuman.repaintSelf(); indices[0] = String.valueOf(index0); } diff --git a/src/main/java/forge/gui/home/settings/VSubmenuPreferences.java b/src/main/java/forge/gui/home/settings/VSubmenuPreferences.java index caa1cfa0a2f..0176ac41b5c 100644 --- a/src/main/java/forge/gui/home/settings/VSubmenuPreferences.java +++ b/src/main/java/forge/gui/home/settings/VSubmenuPreferences.java @@ -17,11 +17,10 @@ import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.ScrollPaneConstants; import javax.swing.SwingConstants; -import javax.swing.border.MatteBorder; - import net.miginfocom.swing.MigLayout; import org.apache.commons.lang3.StringUtils; + import forge.GameLogEntryType; import forge.Singletons; import forge.control.KeyboardShortcuts; @@ -285,7 +284,7 @@ public enum VSubmenuPreferences implements IVSubmenu { private class OptionsCheckBox extends FCheckBox { public OptionsCheckBox(final String txt0) { super(txt0); - setFont(FSkin.getBoldFont(12)); + FSkin.get(this).setFont(FSkin.getBoldFont(12)); } } @@ -294,10 +293,11 @@ public enum VSubmenuPreferences implements IVSubmenu { private class SectionLabel extends JLabel { public SectionLabel(final String txt0) { super(txt0); - setBorder(new MatteBorder(0, 0, 1, 0, FSkin.getColor(FSkin.Colors.CLR_BORDERS))); + FSkin.JLabelSkin skin = FSkin.get(this); + skin.setMatteBorder(0, 0, 1, 0, FSkin.getColor(FSkin.Colors.CLR_BORDERS)); setHorizontalAlignment(SwingConstants.CENTER); - setFont(FSkin.getBoldFont(16)); - setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); + skin.setFont(FSkin.getBoldFont(16)); + skin.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); } } @@ -306,8 +306,9 @@ public enum VSubmenuPreferences implements IVSubmenu { private class NoteLabel extends JLabel { public NoteLabel(final String txt0) { super(txt0); - setFont(FSkin.getItalicFont(12)); - setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); + FSkin.JLabelSkin skin = FSkin.get(this); + skin.setFont(FSkin.getItalicFont(12)); + skin.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); } } @@ -330,7 +331,7 @@ public enum VSubmenuPreferences implements IVSubmenu { public KeyboardShortcutField(final Shortcut shortcut0) { super(); this.setEditable(false); - this.setFont(FSkin.getFont(14)); + FSkin.get(this).setFont(FSkin.getFont(14)); final FPref prefKey = shortcut0.getPrefKey(); reload(prefKey); @@ -344,7 +345,7 @@ public enum VSubmenuPreferences implements IVSubmenu { this.addFocusListener(new FocusAdapter() { @Override public void focusGained(final FocusEvent evt) { - KeyboardShortcutField.this.setBackground(FSkin.getColor(FSkin.Colors.CLR_ACTIVE)); + FSkin.get(KeyboardShortcutField.this).setBackground(FSkin.getColor(FSkin.Colors.CLR_ACTIVE)); } @Override @@ -352,7 +353,7 @@ public enum VSubmenuPreferences implements IVSubmenu { Singletons.getModel().getPreferences().setPref(prefKey, getCodeString()); Singletons.getModel().getPreferences().save(); shortcut0.attach(); - KeyboardShortcutField.this.setBackground(Color.white); + FSkin.get(KeyboardShortcutField.this).setBackground(Color.white); } }); } diff --git a/src/main/java/forge/gui/home/settings/VSubmenuReleaseNotes.java b/src/main/java/forge/gui/home/settings/VSubmenuReleaseNotes.java index fad1ba0e78d..29d2c6c6a82 100644 --- a/src/main/java/forge/gui/home/settings/VSubmenuReleaseNotes.java +++ b/src/main/java/forge/gui/home/settings/VSubmenuReleaseNotes.java @@ -66,9 +66,11 @@ public enum VSubmenuReleaseNotes implements IVSubmenu { tar.setWrapStyleWord(true); tar.setEditable(false); tar.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); + + FSkin.JTextComponentSkin tarSkin = FSkin.get(tar); tar.setFont(FSkin.getFixedFont(16)); - tar.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); - tar.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); + tarSkin.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); + tarSkin.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); scroller = new JScrollPane(tar); pnlMain.add(scroller, "w 100%!, h 100%!"); diff --git a/src/main/java/forge/gui/home/variant/VSubmenuArchenemy.java b/src/main/java/forge/gui/home/variant/VSubmenuArchenemy.java index fa0d6ea23ba..e8216b5530e 100644 --- a/src/main/java/forge/gui/home/variant/VSubmenuArchenemy.java +++ b/src/main/java/forge/gui/home/variant/VSubmenuArchenemy.java @@ -75,7 +75,7 @@ public enum VSubmenuArchenemy implements IVSubmenu { private VSubmenuArchenemy() { - lblTitle.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); + FSkin.get(lblTitle).setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); //This listener will look for any of the radio buttons being selected //and call the method that shows/hides tabs appropriately. diff --git a/src/main/java/forge/gui/home/variant/VSubmenuCommander.java b/src/main/java/forge/gui/home/variant/VSubmenuCommander.java index 5b61c2eaca1..de87de9f146 100644 --- a/src/main/java/forge/gui/home/variant/VSubmenuCommander.java +++ b/src/main/java/forge/gui/home/variant/VSubmenuCommander.java @@ -71,7 +71,7 @@ public enum VSubmenuCommander implements IVSubmenu { private VSubmenuCommander() { - lblTitle.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); + FSkin.get(lblTitle).setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); Vector cmdDeckListData = new Vector(); if(Singletons.getModel().getDecks().getCommander().size() > 0) { diff --git a/src/main/java/forge/gui/home/variant/VSubmenuPlanechase.java b/src/main/java/forge/gui/home/variant/VSubmenuPlanechase.java index 15ece3ea382..054f807c9ef 100644 --- a/src/main/java/forge/gui/home/variant/VSubmenuPlanechase.java +++ b/src/main/java/forge/gui/home/variant/VSubmenuPlanechase.java @@ -75,7 +75,7 @@ public enum VSubmenuPlanechase implements IVSubmenu { private VSubmenuPlanechase() { - lblTitle.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); + FSkin.get(lblTitle).setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); //This listener will look for any of the radio buttons being selected //and call the method that shows/hides tabs appropriately. diff --git a/src/main/java/forge/gui/home/variant/VSubmenuVanguard.java b/src/main/java/forge/gui/home/variant/VSubmenuVanguard.java index 8855ddbf20d..b786983b5be 100644 --- a/src/main/java/forge/gui/home/variant/VSubmenuVanguard.java +++ b/src/main/java/forge/gui/home/variant/VSubmenuVanguard.java @@ -87,7 +87,7 @@ public enum VSubmenuVanguard implements IVSubmenu { private VSubmenuVanguard() { - lblTitle.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); + FSkin.get(lblTitle).setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); Vector humanListData = new Vector(); Vector aiListData = new Vector(); diff --git a/src/main/java/forge/gui/match/CMatchUI.java b/src/main/java/forge/gui/match/CMatchUI.java index ba551ba95aa..b52db1a3b47 100644 --- a/src/main/java/forge/gui/match/CMatchUI.java +++ b/src/main/java/forge/gui/match/CMatchUI.java @@ -24,7 +24,6 @@ import java.util.List; import java.util.Map; import java.util.Set; -import javax.swing.ImageIcon; import javax.swing.JMenu; import org.apache.commons.lang3.tuple.Pair; @@ -63,6 +62,7 @@ import forge.gui.match.nonsingleton.VHand; import forge.gui.match.views.VPlayers; import forge.gui.menubar.IMenuProvider; import forge.gui.toolbox.FSkin; +import forge.gui.toolbox.FSkin.SkinImage; import forge.gui.toolbox.special.PhaseLabel; import forge.item.InventoryItem; import forge.properties.ForgePreferences.FPref; @@ -92,18 +92,18 @@ public enum CMatchUI implements ICDoc, IMenuProvider { uiEvents.register(visitor); } - private ImageIcon getPlayerAvatar(final Player p, final int defaultIndex) { + private SkinImage getPlayerAvatar(final Player p, final int defaultIndex) { LobbyPlayer lp = p.getLobbyPlayer(); if (null != lp.getIconImageKey()) { return ImageCache.getIcon(lp); } int avatarIdx = lp.getAvatarIndex(); - return new ImageIcon(FSkin.getAvatars().get(0 <= avatarIdx ? avatarIdx : defaultIndex)); + return FSkin.getAvatars().get(0 <= avatarIdx ? avatarIdx : defaultIndex); } - private void setAvatar(VField view, ImageIcon img) { + private void setAvatar(VField view, SkinImage img) { view.getLblAvatar().setIcon(img); view.getLblAvatar().getResizeTimer().start(); } diff --git a/src/main/java/forge/gui/match/GameLogPanel.java b/src/main/java/forge/gui/match/GameLogPanel.java index e9e16ebcc58..68ea43edb09 100644 --- a/src/main/java/forge/gui/match/GameLogPanel.java +++ b/src/main/java/forge/gui/match/GameLogPanel.java @@ -1,9 +1,7 @@ package forge.gui.match; import java.awt.AWTEvent; -import java.awt.Color; import java.awt.Dimension; -import java.awt.Font; import java.awt.Rectangle; import java.awt.event.ComponentAdapter; import java.awt.event.ComponentEvent; @@ -18,7 +16,6 @@ import javax.swing.JTextArea; import javax.swing.ScrollPaneConstants; import javax.swing.Scrollable; import javax.swing.SwingUtilities; -import javax.swing.UIManager; import javax.swing.border.EmptyBorder; import javax.swing.plaf.LayerUI; @@ -26,13 +23,15 @@ import net.miginfocom.swing.MigLayout; import forge.gui.MouseUtil; import forge.gui.MouseUtil.MouseCursor; import forge.gui.toolbox.FSkin; +import forge.gui.toolbox.FSkin.JTextComponentSkin; +import forge.gui.toolbox.FSkin.SkinFont; @SuppressWarnings("serial") public class GameLogPanel extends JPanel { private JScrollPane scrollPane; private MyScrollablePanel scrollablePanel; - private Font textFont = UIManager.getDefaults().getFont("TextArea.font"); + private SkinFont textFont = FSkin.getFont(); private LayerUI layerUI = new GameLogPanelLayerUI(); private JLayer layer; @@ -146,28 +145,27 @@ public class GameLogPanel extends JPanel { } - public void setTextFont(Font newFont) { + public void setTextFont(SkinFont newFont) { this.textFont = newFont; } private JTextArea createNewLogEntryJTextArea(String text, boolean useAlternateBackColor) { final JTextArea tar = new JTextArea(text); - tar.setFont(textFont); + final JTextComponentSkin tarSkin = FSkin.get(tar); + tarSkin.setFont(textFont); tar.setBorder(new EmptyBorder(3, 4, 3, 4)); tar.setFocusable(false); tar.setEditable(false); tar.setLineWrap(true); tar.setWrapStyleWord(true); - tar.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); - setTextAreaBackground(tar, useAlternateBackColor); - return tar; - } + tarSkin.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); - private void setTextAreaBackground(JTextArea tar, boolean useAlternateBackColor) { - Color skinColor = FSkin.getColor(FSkin.Colors.CLR_THEME2); + FSkin.SkinColor skinColor = FSkin.getColor(FSkin.Colors.CLR_THEME2); if (useAlternateBackColor) { skinColor = skinColor.darker(); } tar.setOpaque(true); - tar.setBackground(skinColor); + tarSkin.setBackground(skinColor); + + return tar; } protected final class MyScrollablePanel extends JPanel implements Scrollable { diff --git a/src/main/java/forge/gui/match/GauntletWinLose.java b/src/main/java/forge/gui/match/GauntletWinLose.java index c1fbb264cac..423f71f10a2 100644 --- a/src/main/java/forge/gui/match/GauntletWinLose.java +++ b/src/main/java/forge/gui/match/GauntletWinLose.java @@ -182,7 +182,7 @@ public class GauntletWinLose extends ControlWinLose { final JPanel pnl = this.getView().getPnlCustom(); pnl.setLayout(new MigLayout("insets 0, gap 0, wrap, ax center")); pnl.setOpaque(true); - pnl.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); + FSkin.get(pnl).setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); pnl.add(lblTitle, "gap 0 0 20px 10px, ax center"); pnl.add(pnlResults, "w 96%!, growy, pushy, gap 2% 0 0 0"); diff --git a/src/main/java/forge/gui/match/LimitedWinLose.java b/src/main/java/forge/gui/match/LimitedWinLose.java index f0592f5ad57..113d188f0b4 100644 --- a/src/main/java/forge/gui/match/LimitedWinLose.java +++ b/src/main/java/forge/gui/match/LimitedWinLose.java @@ -129,7 +129,7 @@ public class LimitedWinLose extends ControlWinLose { // + " Total Wins: " + gauntlet.getWins() // + " Total Losses: " + gauntlet.getLosses()); this.lblTemp2.setHorizontalAlignment(SwingConstants.CENTER); - this.lblTemp2.setFont(FSkin.getFont(17)); + FSkin.get(this.lblTemp2).setFont(FSkin.getFont(17)); this.lblTemp2.setForeground(Color.white); this.lblTemp2.setIconTextGap(50); this.getView().getPnlCustom().add(this.lblTemp1, LimitedWinLose.CONSTRAINTS_TITLE); @@ -207,7 +207,7 @@ public class LimitedWinLose extends ControlWinLose { private class TitleLabel extends JLabel { TitleLabel(final String msg) { super(msg); - this.setFont(FSkin.getFont(18)); + FSkin.get(this).setFont(FSkin.getFont(18)); this.setPreferredSize(new Dimension(200, 40)); this.setHorizontalAlignment(SwingConstants.CENTER); this.setForeground(Color.white); diff --git a/src/main/java/forge/gui/match/QuestWinLose.java b/src/main/java/forge/gui/match/QuestWinLose.java index 2581de3197c..1bf0a61291a 100644 --- a/src/main/java/forge/gui/match/QuestWinLose.java +++ b/src/main/java/forge/gui/match/QuestWinLose.java @@ -19,14 +19,12 @@ package forge.gui.match; import java.awt.Color; import java.awt.Dimension; -import java.awt.Image; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map.Entry; import javax.swing.BorderFactory; -import javax.swing.ImageIcon; import javax.swing.JLabel; import javax.swing.SwingConstants; @@ -55,6 +53,7 @@ import forge.gui.SOverlayUtils; import forge.gui.home.quest.CSubmenuChallenges; import forge.gui.home.quest.CSubmenuDuels; import forge.gui.toolbox.FSkin; +import forge.gui.toolbox.FSkin.SkinIcon; import forge.item.BoosterPack; import forge.item.PaperCard; import forge.item.InventoryItem; @@ -85,7 +84,7 @@ import forge.util.MyRandom; public class QuestWinLose extends ControlWinLose { private final transient boolean wonMatch; private final transient ViewWinLose view; - private transient ImageIcon icoTemp; + private transient SkinIcon icoTemp; private transient JLabel lblTemp1; private transient JLabel lblTemp2; private final transient boolean isAnte; @@ -472,15 +471,16 @@ public class QuestWinLose extends ControlWinLose { qData.getAssets().addCredits(credTotal); // Generate Swing components and attach. - this.icoTemp = QuestWinLose.getResizedIcon(FSkin.getIcon(FSkin.QuestIcons.ICO_GOLD), 0.5); + this.icoTemp = FSkin.getIcon(FSkin.QuestIcons.ICO_GOLD).scale(0.5); this.lblTemp1 = new TitleLabel("Gameplay Results"); this.lblTemp2 = new JLabel(sb.toString()); + FSkin.JLabelSkin labelSkin = FSkin.get(this.lblTemp2); this.lblTemp2.setHorizontalAlignment(SwingConstants.CENTER); - this.lblTemp2.setFont(FSkin.getFont(14)); + labelSkin.setFont(FSkin.getFont(14)); this.lblTemp2.setForeground(Color.white); - this.lblTemp2.setIcon(this.icoTemp); + labelSkin.setIcon(this.icoTemp); this.lblTemp2.setIconTextGap(50); this.getView().getPnlCustom().add(this.lblTemp1, QuestWinLose.CONSTRAINTS_TITLE); @@ -624,15 +624,16 @@ public class QuestWinLose extends ControlWinLose { qData.getAssets().addCredits(questRewardCredits); // Generate Swing components and attach. - this.icoTemp = QuestWinLose.getResizedIcon(FSkin.getIcon(FSkin.QuestIcons.ICO_BOX), 0.5); + this.icoTemp = FSkin.getIcon(FSkin.QuestIcons.ICO_BOX).scale(0.5); this.lblTemp1 = new TitleLabel("Challenge Rewards for \"" + ((QuestEventChallenge) qEvent).getTitle() + "\""); this.lblTemp2 = new JLabel(sb.toString()); - this.lblTemp2.setFont(FSkin.getFont(14)); + FSkin.JLabelSkin labelSkin = FSkin.get(this.lblTemp2); + labelSkin.setFont(FSkin.getFont(14)); this.lblTemp2.setForeground(Color.white); this.lblTemp2.setHorizontalAlignment(SwingConstants.CENTER); this.lblTemp2.setIconTextGap(50); - this.lblTemp2.setIcon(this.icoTemp); + labelSkin.setIcon(this.icoTemp); this.getView().getPnlCustom().add(this.lblTemp1, QuestWinLose.CONSTRAINTS_TITLE); this.getView().getPnlCustom().add(this.lblTemp2, QuestWinLose.CONSTRAINTS_TEXT); @@ -697,16 +698,17 @@ public class QuestWinLose extends ControlWinLose { private void penalizeLoss() { final int x = Singletons.getModel().getQuestPreferences().getPrefInt(QPref.PENALTY_LOSS); - this.icoTemp = QuestWinLose.getResizedIcon(FSkin.getIcon(FSkin.QuestIcons.ICO_HEART), 0.5); + this.icoTemp = FSkin.getIcon(FSkin.QuestIcons.ICO_HEART).scale(0.5); this.lblTemp1 = new TitleLabel("Gameplay Results"); this.lblTemp2 = new JLabel("You lose! You have lost " + x + " credits."); - this.lblTemp2.setFont(FSkin.getFont(14)); + FSkin.JLabelSkin labelSkin = FSkin.get(this.lblTemp2); + labelSkin.setFont(FSkin.getFont(14)); this.lblTemp2.setForeground(Color.white); this.lblTemp2.setHorizontalAlignment(SwingConstants.CENTER); this.lblTemp2.setIconTextGap(50); - this.lblTemp2.setIcon(this.icoTemp); + labelSkin.setIcon(this.icoTemp); this.getView().getPnlCustom().add(this.lblTemp1, QuestWinLose.CONSTRAINTS_TITLE); this.getView().getPnlCustom().add(this.lblTemp2, QuestWinLose.CONSTRAINTS_TEXT); @@ -783,24 +785,6 @@ public class QuestWinLose extends ControlWinLose { return credits; } - /** - *

- * getResizedIcon. - *

- * - * @param icon - * ImageIcon - * @param scale - * Double - * @return {@link javax.swing.ImageIcon} object - */ - public static ImageIcon getResizedIcon(final ImageIcon icon, final double scale) { - final int w = (int) (icon.getIconWidth() * scale); - final int h = (int) (icon.getIconHeight() * scale); - - return new ImageIcon(icon.getImage().getScaledInstance(w, h, Image.SCALE_SMOOTH)); - } - /** * JLabel header between reward sections. * @@ -809,7 +793,7 @@ public class QuestWinLose extends ControlWinLose { private class TitleLabel extends JLabel { TitleLabel(final String msg) { super(msg); - this.setFont(FSkin.getFont(16)); + FSkin.get(this).setFont(FSkin.getFont(16)); this.setPreferredSize(new Dimension(200, 40)); this.setHorizontalAlignment(SwingConstants.CENTER); this.setForeground(Color.white); diff --git a/src/main/java/forge/gui/match/QuestWinLoseCardViewer.java b/src/main/java/forge/gui/match/QuestWinLoseCardViewer.java index 78d34c8cf0e..4245bbbca66 100644 --- a/src/main/java/forge/gui/match/QuestWinLoseCardViewer.java +++ b/src/main/java/forge/gui/match/QuestWinLoseCardViewer.java @@ -67,7 +67,7 @@ public class QuestWinLoseCardViewer extends FPanel { this.setCornerDiameter(20); this.setBorderToggle(false); - this.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); + FSkin.get(this).setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); picture.setOpaque(false); scroller.setBorder(null); diff --git a/src/main/java/forge/gui/match/TargetingOverlay.java b/src/main/java/forge/gui/match/TargetingOverlay.java index 21783c71a5c..c2972568501 100644 --- a/src/main/java/forge/gui/match/TargetingOverlay.java +++ b/src/main/java/forge/gui/match/TargetingOverlay.java @@ -66,7 +66,7 @@ public enum TargetingOverlay { pnl.setOpaque(false); pnl.setVisible(false); pnl.setFocusTraversalKeysEnabled(false); - pnl.setBackground(FSkin.getColor(FSkin.Colors.CLR_ZEBRA)); + FSkin.get(pnl).setBackground(FSkin.getColor(FSkin.Colors.CLR_ZEBRA)); } /** @return {@link javax.swing.JPanel} */ @@ -300,7 +300,7 @@ public enum TargetingOverlay { return area; } - private void drawArrow(Graphics2D g2d, int startX, int startY, int endX, int endY, Color color) { + private void drawArrow(Graphics2D g2d, int startX, int startY, int endX, int endY, FSkin.SkinColor skinColor) { float ex = endX - startX; float ey = endY - startY; if (ex == 0 && ey == 0) { return; } @@ -318,7 +318,7 @@ public enum TargetingOverlay { g2d.translate(startX, startY); g2d.rotate(Math.atan2(ey, ex)); g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.75f)); - g2d.setColor(color); + FSkin.get(this).setGraphicsColor(g2d, skinColor); g2d.fill(arrow); g2d.setColor(Color.BLACK); g2d.draw(arrow); @@ -347,7 +347,7 @@ public enum TargetingOverlay { Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - Color color = FSkin.getColor(FSkin.Colors.CLR_ACTIVE); + FSkin.SkinColor skinColor = FSkin.getColor(FSkin.Colors.CLR_ACTIVE); for (Point[] p : arcs) { if (p[0] == null || p[1] == null) { @@ -359,7 +359,7 @@ public enum TargetingOverlay { int startX = (int) p[1].getX(); int startY = (int) p[1].getY(); - drawArrow(g2d, startX, startY, endX, endY, color); + drawArrow(g2d, startX, startY, endX, endY, skinColor); } FView.SINGLETON_INSTANCE.getFrame().repaint(); // repaint the match UI diff --git a/src/main/java/forge/gui/match/VAssignDamage.java b/src/main/java/forge/gui/match/VAssignDamage.java index eefbb009084..b6dbf45811e 100644 --- a/src/main/java/forge/gui/match/VAssignDamage.java +++ b/src/main/java/forge/gui/match/VAssignDamage.java @@ -33,8 +33,6 @@ import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.SwingConstants; import javax.swing.SwingUtilities; -import javax.swing.border.LineBorder; - import net.miginfocom.swing.MigLayout; import forge.Card; import forge.CounterType; @@ -113,7 +111,7 @@ public class VAssignDamage { if (!damage.containsKey(source)) source = null; // to get player instead of fake card FSkin.Colors brdrColor = VAssignDamage.this.canAssignTo(source) ? FSkin.Colors.CLR_ACTIVE : FSkin.Colors.CLR_INACTIVE; - ((CardPanel) evt.getSource()).setBorder(new LineBorder(FSkin.getColor(brdrColor), 2)); + FSkin.get((CardPanel) evt.getSource()).setLineBorder(FSkin.getColor(brdrColor), 2); } @Override @@ -155,7 +153,7 @@ public class VAssignDamage { // Top-level UI stuff final JPanel overlay = SOverlayUtils.genericOverlay(); final JPanel pnlMain = new JPanel(); - pnlMain.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); + FSkin.get(pnlMain).setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); // Attacker area final CardPanel pnlAttacker = new CardPanel(attacker0); diff --git a/src/main/java/forge/gui/match/ViewWinLose.java b/src/main/java/forge/gui/match/ViewWinLose.java index 2521cd66ca9..addcca37796 100644 --- a/src/main/java/forge/gui/match/ViewWinLose.java +++ b/src/main/java/forge/gui/match/ViewWinLose.java @@ -91,24 +91,24 @@ public class ViewWinLose { lblTitle.setForeground(Color.white); lblTitle.setHorizontalAlignment(SwingConstants.CENTER); - lblTitle.setFont(FSkin.getFont().deriveFont(Font.BOLD, 30)); + FSkin.get(lblTitle).setFont(FSkin.getBoldFont(30)); lblStats.setForeground(Color.white); lblStats.setHorizontalAlignment(SwingConstants.CENTER); - lblStats.setFont(FSkin.getFont().deriveFont(Font.PLAIN, 26)); + FSkin.get(lblStats).setFont(FSkin.getFont(26)); btnContinue.setText("Continue"); - btnContinue.setFont(FSkin.getFont(22)); + FSkin.get(btnContinue).setFont(FSkin.getFont(22)); btnRestart.setText("Restart"); - btnRestart.setFont(FSkin.getFont(22)); + FSkin.get(btnRestart).setFont(FSkin.getFont(22)); btnQuit.setText("Quit"); - btnQuit.setFont(FSkin.getFont(22)); + FSkin.get(btnQuit).setFont(FSkin.getFont(22)); btnContinue.setEnabled(!game.getMatch().isMatchOver()); // Assemble game log scroller. final FTextArea txtLog = new FTextArea(); txtLog.setText(game.getGameLog().getLogText(null)); - txtLog.setFont(FSkin.getFont(14)); + FSkin.get(txtLog).setFont(FSkin.getFont(14)); txtLog.setFocusable(true); // allow highlighting and copying of log FLabel btnCopyLog = new FLabel.ButtonBuilder().text("Copy to clipboard").build(); diff --git a/src/main/java/forge/gui/match/menus/GameMenu.java b/src/main/java/forge/gui/match/menus/GameMenu.java index 638075a8ba1..f15169dea70 100644 --- a/src/main/java/forge/gui/match/menus/GameMenu.java +++ b/src/main/java/forge/gui/match/menus/GameMenu.java @@ -5,7 +5,6 @@ import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import javax.swing.ButtonGroup; -import javax.swing.ImageIcon; import javax.swing.JCheckBoxMenuItem; import javax.swing.JMenu; import javax.swing.JMenuItem; @@ -16,6 +15,7 @@ import forge.Singletons; import forge.gui.match.controllers.CDock; import forge.gui.menubar.MenuUtil; import forge.gui.toolbox.FSkin; +import forge.gui.toolbox.FSkin.SkinIcon; import forge.gui.toolbox.FSkin.SkinProp; import forge.properties.ForgePreferences; import forge.properties.ForgePreferences.FPref; @@ -70,7 +70,7 @@ public final class GameMenu { private static JMenuItem getMenuItem_Concede() { JMenuItem menuItem = new JMenuItem("Concede"); - menuItem.setIcon((showIcons ? MenuUtil.getMenuIcon(FSkin.DockIcons.ICO_CONCEDE) : null)); + FSkin.get(menuItem).setIcon((showIcons ? MenuUtil.getMenuIcon(FSkin.DockIcons.ICO_CONCEDE) : null)); menuItem.setAccelerator(MenuUtil.getAcceleratorKey(KeyEvent.VK_Q)); menuItem.addActionListener(getConcedeAction()); return menuItem; @@ -92,7 +92,7 @@ public final class GameMenu { private static JMenuItem getMenuItem_AlphaStrike() { JMenuItem menuItem = new JMenuItem("Alpha Strike"); - menuItem.setIcon((showIcons ? MenuUtil.getMenuIcon(FSkin.DockIcons.ICO_ALPHASTRIKE) : null)); + FSkin.get(menuItem).setIcon((showIcons ? MenuUtil.getMenuIcon(FSkin.DockIcons.ICO_ALPHASTRIKE) : null)); menuItem.setAccelerator(MenuUtil.getAcceleratorKey(KeyEvent.VK_A)); menuItem.addActionListener(getAlphaStrikeAction()); return menuItem; @@ -109,7 +109,7 @@ public final class GameMenu { private static JMenuItem getMenuItem_EndTurn() { JMenuItem menuItem = new JMenuItem("End Turn"); - menuItem.setIcon((showIcons ? MenuUtil.getMenuIcon(FSkin.DockIcons.ICO_ENDTURN) : null)); + FSkin.get(menuItem).setIcon((showIcons ? MenuUtil.getMenuIcon(FSkin.DockIcons.ICO_ENDTURN) : null)); menuItem.setAccelerator(MenuUtil.getAcceleratorKey(KeyEvent.VK_E)); menuItem.addActionListener(getEndTurnAction()); return menuItem; @@ -129,7 +129,7 @@ public final class GameMenu { JMenu menu = new JMenu("Targeting Arcs"); ButtonGroup group = new ButtonGroup(); - ImageIcon menuIcon = MenuUtil.getMenuIcon(FSkin.DockIcons.ICO_ARCSOFF); + SkinIcon menuIcon = MenuUtil.getMenuIcon(FSkin.DockIcons.ICO_ARCSOFF); JRadioButtonMenuItem menuItem; menuItem = getTargetingArcRadioButton("Off", FSkin.DockIcons.ICO_ARCSOFF, 0); @@ -144,7 +144,7 @@ public final class GameMenu { if (menuItem.isSelected()) { menuIcon = MenuUtil.getMenuIcon(FSkin.DockIcons.ICO_ARCSON); } group.add(menuItem); - menu.setIcon((showIcons ? menuIcon : null)); + FSkin.get(menu).setIcon((showIcons ? menuIcon : null)); menu.add(menuItem); return menu; @@ -152,7 +152,7 @@ public final class GameMenu { private static JRadioButtonMenuItem getTargetingArcRadioButton(String caption, SkinProp icon, final int arcState) { final JRadioButtonMenuItem menuItem = new JRadioButtonMenuItem(caption); - menuItem.setIcon((showIcons ? MenuUtil.getMenuIcon(icon) : null)); + FSkin.get(menuItem).setIcon((showIcons ? MenuUtil.getMenuIcon(icon) : null)); menuItem.setSelected(arcState == controller.getArcState()); menuItem.addActionListener(getTargetingRadioButtonAction(arcState)); return menuItem; @@ -178,7 +178,7 @@ public final class GameMenu { private static JMenuItem getMenuItem_ViewDeckList() { JMenuItem menuItem = new JMenuItem("Deck List"); - menuItem.setIcon((showIcons ? MenuUtil.getMenuIcon(FSkin.DockIcons.ICO_DECKLIST) : null)); + FSkin.get(menuItem).setIcon((showIcons ? MenuUtil.getMenuIcon(FSkin.DockIcons.ICO_DECKLIST) : null)); menuItem.addActionListener(getViewDeckListAction()); return menuItem; } diff --git a/src/main/java/forge/gui/match/nonsingleton/VCommand.java b/src/main/java/forge/gui/match/nonsingleton/VCommand.java index 17711a00c6c..fee0fde087e 100644 --- a/src/main/java/forge/gui/match/nonsingleton/VCommand.java +++ b/src/main/java/forge/gui/match/nonsingleton/VCommand.java @@ -19,8 +19,6 @@ package forge.gui.match.nonsingleton; import javax.swing.JPanel; import javax.swing.JScrollPane; -import javax.swing.border.MatteBorder; - import net.miginfocom.swing.MigLayout; import forge.game.player.Player; import forge.game.zone.ZoneType; @@ -71,8 +69,7 @@ public class VCommand implements IVDoc { control = new CCommand(player, this); - tabletop.setBorder(new MatteBorder(0, 1, 0, 0, - FSkin.getColor(FSkin.Colors.CLR_BORDERS))); + FSkin.get(tabletop).setMatteBorder(0, 1, 0, 0, FSkin.getColor(FSkin.Colors.CLR_BORDERS)); tabletop.setOpaque(false); scroller.setViewportView(this.tabletop); diff --git a/src/main/java/forge/gui/match/nonsingleton/VField.java b/src/main/java/forge/gui/match/nonsingleton/VField.java index 03d0815a42f..941823e662d 100644 --- a/src/main/java/forge/gui/match/nonsingleton/VField.java +++ b/src/main/java/forge/gui/match/nonsingleton/VField.java @@ -26,8 +26,6 @@ import javax.swing.JScrollPane; import javax.swing.SwingConstants; import javax.swing.border.Border; import javax.swing.border.LineBorder; -import javax.swing.border.MatteBorder; - import net.miginfocom.swing.MigLayout; import forge.game.player.LobbyPlayer; import forge.game.player.Player; @@ -73,7 +71,6 @@ public class VField implements IVDoc { private final PhaseIndicator phaseInidicator = new PhaseIndicator(); private final Border borderAvatarSimple = new LineBorder(new Color(0, 0, 0, 0), 1); - private final Border borderAvatarHover = new LineBorder(FSkin.getColor(FSkin.Colors.CLR_BORDERS), 1); private final Border borderAvatarHighlited = new LineBorder(Color.red, 2); @@ -102,7 +99,7 @@ public class VField implements IVDoc { control = new CField(player, this, playerViewer); avatarArea.setOpaque(false); - avatarArea.setBackground(FSkin.getColor(FSkin.Colors.CLR_HOVER)); + FSkin.get(avatarArea).setBackground(FSkin.getColor(FSkin.Colors.CLR_HOVER)); avatarArea.setLayout(new MigLayout("insets 0, gap 0")); avatarArea.add(lblAvatar, "w 100%!, h 70%!, wrap, gaptop 4%"); avatarArea.add(lblLife, "w 100%!, h 30%!, gaptop 4%"); @@ -113,7 +110,7 @@ public class VField implements IVDoc { public void mouseEntered(final MouseEvent e) { avatarArea.setOpaque(true); if (!isHighlited()) - avatarArea.setBorder(borderAvatarHover); + FSkin.get(avatarArea).setLineBorder(FSkin.getColor(FSkin.Colors.CLR_BORDERS)); } @Override @@ -124,8 +121,7 @@ public class VField implements IVDoc { } }); - tabletop.setBorder(new MatteBorder(0, 1, 0, 0, - FSkin.getColor(FSkin.Colors.CLR_BORDERS))); + FSkin.get(tabletop).setMatteBorder(0, 1, 0, 0, FSkin.getColor(FSkin.Colors.CLR_BORDERS)); tabletop.setOpaque(false); scroller.setViewportView(this.tabletop); @@ -261,9 +257,12 @@ public class VField implements IVDoc { detailsPanel.updateDetails(); this.getLblLife().setText("" + player.getLife()); - Color lifeFg = player.getLife() <= 5 ? Color.red : FSkin.getColor(FSkin.Colors.CLR_TEXT); - this.getLblLife().setForeground(lifeFg); - + if (player.getLife() > 5) { + FSkin.get(this.getLblLife()).setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); + } + else { + FSkin.get(this.getLblLife()).setForeground(Color.red); + } boolean highlited = isHighlited(); this.avatarArea.setBorder(highlited ? borderAvatarHighlited : borderAvatarSimple ); diff --git a/src/main/java/forge/gui/match/views/VCombat.java b/src/main/java/forge/gui/match/views/VCombat.java index f54116e8e96..eaf56494317 100644 --- a/src/main/java/forge/gui/match/views/VCombat.java +++ b/src/main/java/forge/gui/match/views/VCombat.java @@ -18,8 +18,6 @@ package forge.gui.match.views; import javax.swing.JTextArea; -import javax.swing.border.MatteBorder; - import net.miginfocom.swing.MigLayout; import forge.gui.framework.DragCell; import forge.gui.framework.DragTab; @@ -44,9 +42,10 @@ public enum VCombat implements IVDoc { final JTextArea tar = new JTextArea(); private VCombat() { + FSkin.JTextComponentSkin tarSkin = FSkin.get(tar); tar.setOpaque(false); - tar.setBorder(new MatteBorder(0, 0, 0, 0, FSkin.getColor(FSkin.Colors.CLR_BORDERS))); - tar.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); + tarSkin.setMatteBorder(0, 0, 0, 0, FSkin.getColor(FSkin.Colors.CLR_BORDERS)); + tarSkin.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); tar.setFocusable(false); tar.setLineWrap(true); } diff --git a/src/main/java/forge/gui/match/views/VDetail.java b/src/main/java/forge/gui/match/views/VDetail.java index c9a6b66ede4..2d0502c810e 100644 --- a/src/main/java/forge/gui/match/views/VDetail.java +++ b/src/main/java/forge/gui/match/views/VDetail.java @@ -43,11 +43,11 @@ public enum VDetail implements IVDoc { // Top-level containers private final CardDetailPanel pnlDetail = new CardDetailPanel(null); - private final JLabel lblFlipcard = new JLabel( - FSkin.getIcon(FSkin.InterfaceIcons.ICO_FLIPCARD)); + private final JLabel lblFlipcard = new JLabel(); //========= Constructor private VDetail() { + FSkin.get(lblFlipcard).setIcon(FSkin.getIcon(FSkin.InterfaceIcons.ICO_FLIPCARD)); lblFlipcard.setVisible(false); } diff --git a/src/main/java/forge/gui/match/views/VDev.java b/src/main/java/forge/gui/match/views/VDev.java index d6b938c69a4..d6bef4d8b24 100644 --- a/src/main/java/forge/gui/match/views/VDev.java +++ b/src/main/java/forge/gui/match/views/VDev.java @@ -17,7 +17,6 @@ */ package forge.gui.match.views; -import java.awt.Color; import java.awt.Graphics; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; @@ -239,9 +238,9 @@ public enum VDev implements IVDoc { public class DevLabel extends JLabel { private static final long serialVersionUID = 7917311680519060700L; - private Color defaultBG = FSkin.getColor(FSkin.Colors.CLR_ACTIVE); - private final Color hoverBG = FSkin.getColor(FSkin.Colors.CLR_HOVER); - private final Color pressedBG = FSkin.getColor(FSkin.Colors.CLR_INACTIVE); + private FSkin.SkinColor defaultBG = FSkin.getColor(FSkin.Colors.CLR_ACTIVE); + private final FSkin.SkinColor hoverBG = FSkin.getColor(FSkin.Colors.CLR_HOVER); + private final FSkin.SkinColor pressedBG = FSkin.getColor(FSkin.Colors.CLR_INACTIVE); private boolean enabled; private final String enabledText, disabledText; private int w, h; // Width, height, radius, insets (for paintComponent) @@ -285,27 +284,27 @@ public enum VDev implements IVDoc { this.r = 6; // Radius (for paintComponent) this.i = 2; // Insets (for paintComponent) this.setEnabled(true); - this.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); + FSkin.get(this).setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); this.addMouseListener(new MouseAdapter() { @Override public void mousePressed(final MouseEvent e) { - DevLabel.this.setBackground(DevLabel.this.pressedBG); + FSkin.get(DevLabel.this).setBackground(DevLabel.this.pressedBG); } @Override public void mouseReleased(final MouseEvent e) { - DevLabel.this.setBackground(DevLabel.this.defaultBG); + FSkin.get(DevLabel.this).setBackground(DevLabel.this.defaultBG); } @Override public void mouseEntered(final MouseEvent e) { - DevLabel.this.setBackground(DevLabel.this.hoverBG); + FSkin.get(DevLabel.this).setBackground(DevLabel.this.hoverBG); } @Override public void mouseExited(final MouseEvent e) { - DevLabel.this.setBackground(DevLabel.this.defaultBG); + FSkin.get(DevLabel.this).setBackground(DevLabel.this.defaultBG); } }); } @@ -330,7 +329,7 @@ public enum VDev implements IVDoc { this.enabled = b; this.setText(s); this.setToolTipText(s); - this.setBackground(this.defaultBG); + FSkin.get(this).setBackground(this.defaultBG); } /** diff --git a/src/main/java/forge/gui/match/views/VDock.java b/src/main/java/forge/gui/match/views/VDock.java index 4e39734a644..eaa5948d113 100644 --- a/src/main/java/forge/gui/match/views/VDock.java +++ b/src/main/java/forge/gui/match/views/VDock.java @@ -21,11 +21,9 @@ import java.awt.Color; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.Graphics; -import java.awt.Image; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; -import javax.swing.ImageIcon; import javax.swing.JLabel; import javax.swing.JPanel; @@ -36,6 +34,9 @@ import forge.gui.framework.IVDoc; import forge.gui.match.controllers.CDock; import forge.gui.toolbox.FLabel; import forge.gui.toolbox.FSkin; +import forge.gui.toolbox.FSkin.JLabelSkin; +import forge.gui.toolbox.FSkin.SkinColor; +import forge.gui.toolbox.FSkin.SkinImage; /** * Assembles Swing components of button dock area. @@ -193,10 +194,11 @@ public enum VDock implements IVDoc { */ @SuppressWarnings("serial") private class DockButton extends JLabel { - private final Image img; - private final Color hoverBG = FSkin.getColor(FSkin.Colors.CLR_HOVER); + private final SkinImage img; + private final JLabelSkin skin; + private final SkinColor hoverBG = FSkin.getColor(FSkin.Colors.CLR_HOVER); private final Color defaultBG = new Color(0, 0, 0, 0); - private Color clrBorders = new Color(0, 0, 0, 0); + private final Color defaultBorderColor = new Color(0, 0, 0, 0); private int w, h; /** @@ -207,12 +209,13 @@ public enum VDock implements IVDoc { * @param s0 *   Tooltip string */ - public DockButton(final ImageIcon i0, final String s0) { + public DockButton(final SkinImage i0, final String s0) { super(); + this.skin = FSkin.get(this); this.setToolTipText(s0); this.setOpaque(false); this.setBackground(this.defaultBG); - this.img = i0.getImage(); + this.img = i0; Dimension size = new Dimension(30, 30); this.setMinimumSize(size); @@ -222,13 +225,11 @@ public enum VDock implements IVDoc { this.addMouseListener(new MouseAdapter() { @Override public void mouseEntered(final MouseEvent e) { - DockButton.this.clrBorders = FSkin.getColor(FSkin.Colors.CLR_BORDERS); - DockButton.this.setBackground(DockButton.this.hoverBG); + DockButton.this.skin.setBackground(DockButton.this.hoverBG); } @Override public void mouseExited(final MouseEvent e) { - DockButton.this.clrBorders = new Color(0, 0, 0, 0); DockButton.this.setBackground(DockButton.this.defaultBG); } }); @@ -245,9 +246,14 @@ public enum VDock implements IVDoc { this.h = this.getHeight(); g.setColor(this.getBackground()); g.fillRect(0, 0, this.w, this.h); - g.setColor(this.clrBorders); + if (skin.getBackground() == this.hoverBG) { + skin.setGraphicsColor(g, FSkin.getColor(FSkin.Colors.CLR_BORDERS)); + } + else { + g.setColor(this.defaultBorderColor); + } g.drawRect(0, 0, this.w - 1, this.h - 1); - g.drawImage(this.img, 0, 0, this.w, this.h, null); + skin.drawImage(g, this.img, 0, 0, this.w, this.h); super.paintComponent(g); } } diff --git a/src/main/java/forge/gui/match/views/VLog.java b/src/main/java/forge/gui/match/views/VLog.java index c122b45f82d..0aeb387957b 100644 --- a/src/main/java/forge/gui/match/views/VLog.java +++ b/src/main/java/forge/gui/match/views/VLog.java @@ -17,7 +17,6 @@ */ package forge.gui.match.views; -import java.awt.Font; import java.util.ArrayList; import java.util.List; @@ -37,6 +36,7 @@ import forge.gui.framework.IVDoc; import forge.gui.match.GameLogPanel; import forge.gui.match.controllers.CLog; import forge.gui.toolbox.FSkin; +import forge.gui.toolbox.FSkin.SkinFont; /** * Assembles Swing components of game log report. @@ -186,9 +186,8 @@ public enum VLog implements IVDoc { } } - private Font getJTextAreaFont(GameLogEntryType logEntryType) { + private SkinFont getJTextAreaFont(GameLogEntryType logEntryType) { boolean isNewTurn = (logEntryType == GameLogEntryType.TURN); return (isNewTurn ? FSkin.getBoldFont() : FSkin.getFont()); } - } diff --git a/src/main/java/forge/gui/match/views/VMessage.java b/src/main/java/forge/gui/match/views/VMessage.java index 6fa7c294f9a..0f93c27de10 100644 --- a/src/main/java/forge/gui/match/views/VMessage.java +++ b/src/main/java/forge/gui/match/views/VMessage.java @@ -38,6 +38,7 @@ import forge.gui.match.controllers.CMessage; import forge.gui.toolbox.FButton; import forge.gui.toolbox.FLabel; import forge.gui.toolbox.FSkin; +import forge.gui.toolbox.FSkin.JTextComponentSkin; import forge.properties.ForgePreferences.FPref; /** @@ -69,13 +70,14 @@ public enum VMessage implements IVDoc { .opaque() .build(); + JTextComponentSkin tarMessageSkin = FSkin.get(tarMessage); tarMessage.setOpaque(false); tarMessage.setFocusable(false); tarMessage.setEditable(false); tarMessage.setLineWrap(true); tarMessage.setWrapStyleWord(true); - tarMessage.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); - tarMessage.setFont(FSkin.getFont(14)); + tarMessageSkin.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); + tarMessageSkin.setFont(FSkin.getFont(14)); tarMessage.setMargin(new Insets(5, 5, 5, 5)); // Prevent scroll-bar from automatically scrolling to bottom of JTextArea. diff --git a/src/main/java/forge/gui/match/views/VPicture.java b/src/main/java/forge/gui/match/views/VPicture.java index 858ea99b81e..dee721b7df7 100644 --- a/src/main/java/forge/gui/match/views/VPicture.java +++ b/src/main/java/forge/gui/match/views/VPicture.java @@ -43,11 +43,11 @@ public enum VPicture implements IVDoc { // Top-level containers private final CardPicturePanel pnlPicture = new CardPicturePanel(); - private final JLabel lblFlipcard = new JLabel( - FSkin.getIcon(FSkin.InterfaceIcons.ICO_FLIPCARD)); + private final JLabel lblFlipcard = new JLabel(); //========= Constructor private VPicture() { + FSkin.get(lblFlipcard).setIcon(FSkin.getIcon(FSkin.InterfaceIcons.ICO_FLIPCARD)); pnlPicture.setOpaque(false); lblFlipcard.setVisible(false); } diff --git a/src/main/java/forge/gui/match/views/VPlayers.java b/src/main/java/forge/gui/match/views/VPlayers.java index babfcad7738..d5893f77212 100644 --- a/src/main/java/forge/gui/match/views/VPlayers.java +++ b/src/main/java/forge/gui/match/views/VPlayers.java @@ -24,8 +24,6 @@ import java.util.Map.Entry; import javax.swing.JLabel; import javax.swing.JPanel; -import javax.swing.border.MatteBorder; - import net.miginfocom.swing.MigLayout; import forge.Card; import forge.Singletons; @@ -96,7 +94,7 @@ public enum VPlayers implements IVDoc { this.infoLBLs.put(p, new JLabel[] { name, life, hand, draw, prevention, keywords, antes, cmd }); // Set border on bottom label, and larger font on player name - cmd.setBorder(new MatteBorder(0, 0, 1, 0, FSkin.getColor(FSkin.Colors.CLR_BORDERS))); + FSkin.get(cmd).setMatteBorder(0, 0, 1, 0, FSkin.getColor(FSkin.Colors.CLR_BORDERS)); name.setText(p.getName()); } } @@ -195,7 +193,7 @@ public enum VPlayers implements IVDoc { private class InfoLabel extends JLabel { public InfoLabel() { super(); - this.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); + FSkin.get(this).setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); } } } diff --git a/src/main/java/forge/gui/match/views/VStack.java b/src/main/java/forge/gui/match/views/VStack.java index 417314e1e22..a1b0c980f92 100644 --- a/src/main/java/forge/gui/match/views/VStack.java +++ b/src/main/java/forge/gui/match/views/VStack.java @@ -131,13 +131,10 @@ public enum VStack implements IVDoc { tab.setText("Stack : " + stack.size()); final Border border = new EmptyBorder(5, 5, 5, 5); - Color[] scheme; stackTARs.clear(); boolean isFirst = true; for (final SpellAbilityStackInstance spell : stack) { - scheme = getSpellColor(spell); - String isOptional = spell.getSpellAbility().isOptionalTrigger() && spell.getSourceCard().getController().getController().getLobbyPlayer().equals(viewer) ? "(OPTIONAL) " : ""; String txt = (count++) + ". " + isOptional + spell.getStackDescription(); @@ -145,8 +142,7 @@ public enum VStack implements IVDoc { tar.setToolTipText(txt); tar.setOpaque(true); tar.setBorder(border); - tar.setForeground(scheme[1]); - tar.setBackground(scheme[0]); + this.setSpellColor(tar, spell); tar.setFocusable(false); tar.setEditable(false); @@ -203,23 +199,43 @@ public enum VStack implements IVDoc { parentCell.getBody().repaint(); } - /** Returns array with [background, foreground] colors. */ - private Color[] getSpellColor(SpellAbilityStackInstance s0) { - if (s0.getStackDescription().startsWith("Morph ")) - return new Color[] { new Color(0, 0, 0, 0), FSkin.getColor(FSkin.Colors.CLR_TEXT) }; - if (CardUtil.getColors(s0.getSourceCard()).isMulticolor()) - return new Color[] { new Color(253, 175, 63), Color.black }; - - if (s0.getSourceCard().isBlack()) return new Color[] { Color.black, Color.white }; - if (s0.getSourceCard().isBlue()) return new Color[] { new Color(71, 108, 191), Color.white }; - if (s0.getSourceCard().isGreen()) return new Color[] { new Color(23, 95, 30), Color.white }; - if (s0.getSourceCard().isRed()) return new Color[] { new Color(214, 8, 8), Color.white }; - if (s0.getSourceCard().isWhite()) return new Color[] { Color.white, Color.black }; - - if (s0.getSourceCard().isArtifact() || s0.getSourceCard().isLand()) - return new Color[] { new Color(111, 75, 43), Color.white }; - - return new Color[] { new Color(0, 0, 0, 0), FSkin.getColor(FSkin.Colors.CLR_TEXT) }; + private void setSpellColor(JTextArea tar, SpellAbilityStackInstance s0) { + if (s0.getStackDescription().startsWith("Morph ")) { + tar.setBackground(new Color(0, 0, 0, 0)); + FSkin.get(tar).setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); + } + else if (CardUtil.getColors(s0.getSourceCard()).isMulticolor()) { + tar.setBackground(new Color(253, 175, 63)); + tar.setForeground(Color.black); + } + else if (s0.getSourceCard().isBlack()) { + tar.setBackground(Color.black); + tar.setForeground(Color.white); + } + else if (s0.getSourceCard().isBlue()) { + tar.setBackground(new Color(71, 108, 191)); + tar.setForeground(Color.white); + } + else if (s0.getSourceCard().isGreen()) { + tar.setBackground(new Color(23, 95, 30)); + tar.setForeground(Color.white); + } + else if (s0.getSourceCard().isRed()) { + tar.setBackground(new Color(214, 8, 8)); + tar.setForeground(Color.white); + } + else if (s0.getSourceCard().isWhite()) { + tar.setBackground(Color.white); + tar.setForeground(Color.black); + } + else if (s0.getSourceCard().isArtifact() || s0.getSourceCard().isLand()) { + tar.setBackground(new Color(111, 75, 43)); + tar.setForeground(Color.white); + } + else { + tar.setBackground(new Color(0, 0, 0, 0)); + FSkin.get(tar).setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); + } } //========= Custom class handling diff --git a/src/main/java/forge/gui/menubar/FMenuBar.java b/src/main/java/forge/gui/menubar/FMenuBar.java index 797d2531546..117c1270f01 100644 --- a/src/main/java/forge/gui/menubar/FMenuBar.java +++ b/src/main/java/forge/gui/menubar/FMenuBar.java @@ -2,6 +2,7 @@ package forge.gui.menubar; import java.awt.Component; import java.awt.Dimension; +import java.util.List; import javax.swing.Box; import javax.swing.JFrame; @@ -13,50 +14,73 @@ import forge.gui.menus.ForgeMenu; import forge.gui.menus.HelpMenu; import forge.gui.menus.LayoutMenu; import forge.gui.toolbox.FSkin; +import forge.gui.toolbox.FSkin.JLabelSkin; @SuppressWarnings("serial") public class FMenuBar extends JMenuBar { - JLabel statusCaption; + private String statusText; + private JLabel lblStatus; + private IMenuProvider provider; public FMenuBar(JFrame f) { f.setJMenuBar(this); setPreferredSize(new Dimension(f.getWidth(), 26)); - setupMenuBar(null); + refresh(); + setStatusText(""); //set default status text } - public void setupMenuBar(IMenuProvider provider) { + public void setupMenuBar(IMenuProvider provider0) { + provider = provider0; + refresh(); + } + + public void refresh() { removeAll(); add(ForgeMenu.getMenu()); - addProviderMenus(provider); + addProviderMenus(); add(LayoutMenu.getMenu()); add(HelpMenu.getMenu()); - setStatusCaption(); - repaint(); + addStatusLabel(); + revalidate(); } /** * Adds a label to the right-hand side of the MenuBar which can * be used to show hints or status information. */ - private void setStatusCaption() { + private void addStatusLabel() { add(Box.createHorizontalGlue()); // align right hack/patch. - statusCaption = new JLabel(); - statusCaption.setForeground(getForeground()); - statusCaption.setFont(FSkin.getItalicFont(11)); - statusCaption.setOpaque(false); - add(statusCaption); + lblStatus = new JLabel(statusText); + JLabelSkin labelSkin = FSkin.get(lblStatus); + if (FSkin.isLookAndFeelSet()) { + labelSkin.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); + } + else { //ensure status is visible on default menu bar + labelSkin.setForeground(getForeground()); + } + labelSkin.setFont(FSkin.getItalicFont(11)); + lblStatus.setOpaque(false); + add(lblStatus); } public void setStatusText(String text) { - statusCaption.setText(text.trim() + " "); + statusText = text.trim(); + if (statusText.isEmpty()) { + statusText = "F1 : hide menu"; //show shortcut to hide menu if no other status to show + } + statusText += " "; //add padding from right edge of menu bar + lblStatus.setText(statusText); } - private void addProviderMenus(IMenuProvider provider) { - if (provider != null && provider.getMenus() != null) { - for (JMenu m : provider.getMenus()) { - m.setBorderPainted(false); - add(m); + private void addProviderMenus() { + if (provider != null) { + List menus = provider.getMenus(); + if (menus != null) { + for (JMenu m : menus) { + m.setBorderPainted(false); + add(m); + } } } } diff --git a/src/main/java/forge/gui/menubar/MenuUtil.java b/src/main/java/forge/gui/menubar/MenuUtil.java index 35912930709..cb897062405 100644 --- a/src/main/java/forge/gui/menubar/MenuUtil.java +++ b/src/main/java/forge/gui/menubar/MenuUtil.java @@ -3,7 +3,6 @@ package forge.gui.menubar; import java.awt.Toolkit; import java.io.IOException; -import javax.swing.ImageIcon; import javax.swing.JOptionPane; import javax.swing.KeyStroke; @@ -36,7 +35,7 @@ public final class MenuUtil { } } - public static ImageIcon getMenuIcon(SkinProp ico) { + public static FSkin.SkinIcon getMenuIcon(SkinProp ico) { return ImageUtil.getMenuIcon(FSkin.getIcon(ico)); } diff --git a/src/main/java/forge/gui/menus/LayoutMenu.java b/src/main/java/forge/gui/menus/LayoutMenu.java index bd9fc211a33..40086eadef2 100644 --- a/src/main/java/forge/gui/menus/LayoutMenu.java +++ b/src/main/java/forge/gui/menus/LayoutMenu.java @@ -9,7 +9,6 @@ import javax.swing.ButtonGroup; import javax.swing.JCheckBoxMenuItem; import javax.swing.JMenu; import javax.swing.JMenuItem; -import javax.swing.JOptionPane; import javax.swing.JRadioButtonMenuItem; import forge.Singletons; @@ -92,25 +91,7 @@ public final class LayoutMenu { private static final ActionListener changeSkin = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - String skin = e.getActionCommand(); - if (!skin.equals(prefs.getPref(FPref.UI_SKIN))) { - prefs.setPref(FPref.UI_SKIN, skin); - prefs.save(); - - Object[] options = {"Restart Now", "Restart Later"}; - int reply = JOptionPane.showOptionDialog( - null, - "You must restart Forge for " + skin + " theme to take effect.", - "Change Theme", - JOptionPane.YES_NO_OPTION, - JOptionPane.INFORMATION_MESSAGE, - null, - options, - options[0]); - if (reply == JOptionPane.YES_OPTION) { - RestartUtil.restartApplication(null); - } - } + FSkin.changeSkin(e.getActionCommand()); } }; @@ -156,7 +137,7 @@ public final class LayoutMenu { } private static JMenuItem getMenuItem_SaveLayout() { JMenuItem menuItem = new JMenuItem("Save Current Layout"); - menuItem.setIcon((showIcons ? MenuUtil.getMenuIcon(FSkin.DockIcons.ICO_SAVELAYOUT) : null)); + FSkin.get(menuItem).setIcon((showIcons ? MenuUtil.getMenuIcon(FSkin.DockIcons.ICO_SAVELAYOUT) : null)); menuItem.addActionListener(getSaveLayoutAction()); return menuItem; } @@ -172,7 +153,7 @@ public final class LayoutMenu { private static JMenuItem getMenuItem_OpenLayout() { JMenuItem menuItem = new JMenuItem("Open..."); - menuItem.setIcon((showIcons ? MenuUtil.getMenuIcon(FSkin.DockIcons.ICO_OPENLAYOUT) : null)); + FSkin.get(menuItem).setIcon((showIcons ? MenuUtil.getMenuIcon(FSkin.DockIcons.ICO_OPENLAYOUT) : null)); menuItem.addActionListener(getOpenLayoutAction()); return menuItem; } @@ -188,7 +169,7 @@ public final class LayoutMenu { private static JMenuItem getMenuItem_RevertLayout() { JMenuItem menuItem = new JMenuItem("Refresh"); - menuItem.setIcon((showIcons ? MenuUtil.getMenuIcon(FSkin.DockIcons.ICO_REVERTLAYOUT) : null)); + FSkin.get(menuItem).setIcon((showIcons ? MenuUtil.getMenuIcon(FSkin.DockIcons.ICO_REVERTLAYOUT) : null)); menuItem.addActionListener(getRevertLayoutAction()); return menuItem; } diff --git a/src/main/java/forge/gui/toolbox/CardFaceSymbols.java b/src/main/java/forge/gui/toolbox/CardFaceSymbols.java index 8390420b579..f12eb506b8b 100644 --- a/src/main/java/forge/gui/toolbox/CardFaceSymbols.java +++ b/src/main/java/forge/gui/toolbox/CardFaceSymbols.java @@ -18,7 +18,6 @@ package forge.gui.toolbox; import java.awt.Graphics; -import java.awt.Image; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -28,6 +27,8 @@ import com.esotericsoftware.minlog.Log; import forge.card.mana.ManaCost; import forge.card.mana.ManaCostShard; +import forge.gui.toolbox.FSkin.ComponentSkin; +import forge.gui.toolbox.FSkin.SkinImage; /** *

@@ -39,7 +40,7 @@ import forge.card.mana.ManaCostShard; */ public class CardFaceSymbols { /** Constant manaImages. */ - private static final Map MANA_IMAGES = new HashMap(); + private static final Map MANA_IMAGES = new HashMap(); /** *

@@ -143,7 +144,7 @@ public class CardFaceSymbols { * @param y * a int. */ - public static void draw(Graphics g, ManaCost manaCost, int x, int y) { + public static void draw(final ComponentSkin skin, Graphics g, ManaCost manaCost, int x, int y) { if (manaCost.isNoCost()) { return; } @@ -156,12 +157,12 @@ public class CardFaceSymbols { final int offset = 14; if (hasGeneric) { final String sGeneric = Integer.toString(genericManaCost); - CardFaceSymbols.drawSymbol(sGeneric, g, xpos, y); + CardFaceSymbols.drawSymbol(sGeneric, skin, g, xpos, y); xpos += offset; } for (final ManaCostShard s : shards) { - CardFaceSymbols.drawSymbol(s.getImageKey(), g, xpos, y); + CardFaceSymbols.drawSymbol(s.getImageKey(), skin, g, xpos, y); xpos += offset; } } @@ -176,7 +177,7 @@ public class CardFaceSymbols { * @param w an int * @param h and int */ - public static void drawOther(final Graphics g, String s, int x, final int y, final int w, final int h) { + public static void drawOther(final ComponentSkin skin, final Graphics g, String s, int x, final int y, final int w, final int h) { if (s.length() == 0) { return; } @@ -184,13 +185,12 @@ public class CardFaceSymbols { StringTokenizer tok = new StringTokenizer(s, " "); while (tok.hasMoreTokens()) { String symbol = tok.nextToken(); - Image image = MANA_IMAGES.get(symbol); + SkinImage image = MANA_IMAGES.get(symbol); if (image == null) { Log.info("Symbol not recognized \"" + symbol + "\" in string: " + s); continue; } - // g.drawImage(image, x, y, null); - g.drawImage(image, x, y, w, h, null); + skin.drawImage(g, image, x, y, w, h); x += symbol.length() > 2 ? 10 : 14; // slash.png is only 10 pixels // wide. } @@ -208,9 +208,8 @@ public class CardFaceSymbols { * @param y * a int. */ - public static void drawAttack(final Graphics g, final int x, final int y) { - Image image = MANA_IMAGES.get("attack"); - g.drawImage(image, x, y, null); + public static void drawAttack(final ComponentSkin skin, final Graphics g, final int x, final int y) { + skin.drawImage(g, MANA_IMAGES.get("attack"), x, y); } /** @@ -227,9 +226,8 @@ public class CardFaceSymbols { * @param y * a int. */ - public static void drawSymbol(final String imageName, final Graphics g, final int x, final int y) { - Image image = MANA_IMAGES.get(imageName); - g.drawImage(image, x, y, null); + public static void drawSymbol(final String imageName, final ComponentSkin skin, final Graphics g, final int x, final int y) { + skin.drawImage(g, MANA_IMAGES.get(imageName), x, y); } diff --git a/src/main/java/forge/gui/toolbox/FButton.java b/src/main/java/forge/gui/toolbox/FButton.java index 77c46f61d77..da599b8c8e5 100644 --- a/src/main/java/forge/gui/toolbox/FButton.java +++ b/src/main/java/forge/gui/toolbox/FButton.java @@ -22,7 +22,6 @@ import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; -import java.awt.Image; import java.awt.Insets; import java.awt.RenderingHints; import java.awt.event.FocusAdapter; @@ -35,6 +34,8 @@ import javax.swing.BorderFactory; import javax.swing.JButton; import forge.gui.framework.ILocalRepaint; +import forge.gui.toolbox.FSkin.JComponentSkin; +import forge.gui.toolbox.FSkin.SkinImage; /** * The core JButton used throughout the Forge project. Follows skin font and @@ -45,9 +46,10 @@ import forge.gui.framework.ILocalRepaint; public class FButton extends JButton implements ILocalRepaint { /** The img r. */ - private Image imgL; - private Image imgM; - private Image imgR; + private final JComponentSkin skin; + private SkinImage imgL; + private SkinImage imgM; + private SkinImage imgR; private int w, h = 0; private boolean allImagesPresent = false; private boolean toggle = false; @@ -65,16 +67,17 @@ public class FButton extends JButton implements ILocalRepaint { public FButton(final String label) { super(label); this.setOpaque(false); - this.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); - this.setBackground(Color.red); + skin = FSkin.get(this); + skin.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); + skin.setBackground(Color.red); this.setFocusPainted(false); this.setBorder(BorderFactory.createEmptyBorder()); this.setContentAreaFilled(false); this.setMargin(new Insets(0, 25, 0, 25)); - this.setFont(FSkin.getBoldFont(14)); - this.imgL = FSkin.getIcon(FSkin.ButtonImages.IMG_BTN_UP_LEFT).getImage(); - this.imgM = FSkin.getIcon(FSkin.ButtonImages.IMG_BTN_UP_CENTER).getImage(); - this.imgR = FSkin.getIcon(FSkin.ButtonImages.IMG_BTN_UP_RIGHT).getImage(); + skin.setFont(FSkin.getBoldFont(14)); + this.imgL = FSkin.getIcon(FSkin.ButtonImages.IMG_BTN_UP_LEFT); + this.imgM = FSkin.getIcon(FSkin.ButtonImages.IMG_BTN_UP_CENTER); + this.imgR = FSkin.getIcon(FSkin.ButtonImages.IMG_BTN_UP_RIGHT); if ((this.imgL != null) && (this.imgM != null) && (this.imgR != null)) { this.allImagesPresent = true; @@ -110,9 +113,9 @@ public class FButton extends JButton implements ILocalRepaint { @Override public void mousePressed(MouseEvent evt) { if (isToggled() || !isEnabled()) { return; } - imgL = FSkin.getIcon(FSkin.ButtonImages.IMG_BTN_DOWN_LEFT).getImage(); - imgM = FSkin.getIcon(FSkin.ButtonImages.IMG_BTN_DOWN_CENTER).getImage(); - imgR = FSkin.getIcon(FSkin.ButtonImages.IMG_BTN_DOWN_RIGHT).getImage(); + imgL = FSkin.getIcon(FSkin.ButtonImages.IMG_BTN_DOWN_LEFT); + imgM = FSkin.getIcon(FSkin.ButtonImages.IMG_BTN_DOWN_CENTER); + imgR = FSkin.getIcon(FSkin.ButtonImages.IMG_BTN_DOWN_RIGHT); repaintSelf(); } @@ -146,27 +149,27 @@ public class FButton extends JButton implements ILocalRepaint { private void resetImg() { if (hovered) { - imgL = FSkin.getIcon(FSkin.ButtonImages.IMG_BTN_OVER_LEFT).getImage(); - imgM = FSkin.getIcon(FSkin.ButtonImages.IMG_BTN_OVER_CENTER).getImage(); - imgR = FSkin.getIcon(FSkin.ButtonImages.IMG_BTN_OVER_RIGHT).getImage(); + imgL = FSkin.getIcon(FSkin.ButtonImages.IMG_BTN_OVER_LEFT); + imgM = FSkin.getIcon(FSkin.ButtonImages.IMG_BTN_OVER_CENTER); + imgR = FSkin.getIcon(FSkin.ButtonImages.IMG_BTN_OVER_RIGHT); } else if (isFocusOwner()) { - imgL = FSkin.getIcon(FSkin.ButtonImages.IMG_BTN_FOCUS_LEFT).getImage(); - imgM = FSkin.getIcon(FSkin.ButtonImages.IMG_BTN_FOCUS_CENTER).getImage(); - imgR = FSkin.getIcon(FSkin.ButtonImages.IMG_BTN_FOCUS_RIGHT).getImage(); + imgL = FSkin.getIcon(FSkin.ButtonImages.IMG_BTN_FOCUS_LEFT); + imgM = FSkin.getIcon(FSkin.ButtonImages.IMG_BTN_FOCUS_CENTER); + imgR = FSkin.getIcon(FSkin.ButtonImages.IMG_BTN_FOCUS_RIGHT); } else { - imgL = FSkin.getIcon(FSkin.ButtonImages.IMG_BTN_UP_LEFT).getImage(); - imgM = FSkin.getIcon(FSkin.ButtonImages.IMG_BTN_UP_CENTER).getImage(); - imgR = FSkin.getIcon(FSkin.ButtonImages.IMG_BTN_UP_RIGHT).getImage(); + imgL = FSkin.getIcon(FSkin.ButtonImages.IMG_BTN_UP_LEFT); + imgM = FSkin.getIcon(FSkin.ButtonImages.IMG_BTN_UP_CENTER); + imgR = FSkin.getIcon(FSkin.ButtonImages.IMG_BTN_UP_RIGHT); } } @Override public void setEnabled(boolean b0) { if (!b0) { - imgL = FSkin.getIcon(FSkin.ButtonImages.IMG_BTN_DISABLED_LEFT).getImage(); - imgM = FSkin.getIcon(FSkin.ButtonImages.IMG_BTN_DISABLED_CENTER).getImage(); - imgR = FSkin.getIcon(FSkin.ButtonImages.IMG_BTN_DISABLED_RIGHT).getImage(); + imgL = FSkin.getIcon(FSkin.ButtonImages.IMG_BTN_DISABLED_LEFT); + imgM = FSkin.getIcon(FSkin.ButtonImages.IMG_BTN_DISABLED_CENTER); + imgR = FSkin.getIcon(FSkin.ButtonImages.IMG_BTN_DISABLED_RIGHT); } else { resetImg(); @@ -188,17 +191,17 @@ public class FButton extends JButton implements ILocalRepaint { /** @param b0   boolean. */ public void setToggled(boolean b0) { if (b0) { - imgL = FSkin.getIcon(FSkin.ButtonImages.IMG_BTN_TOGGLE_LEFT).getImage(); - imgM = FSkin.getIcon(FSkin.ButtonImages.IMG_BTN_TOGGLE_CENTER).getImage(); - imgR = FSkin.getIcon(FSkin.ButtonImages.IMG_BTN_TOGGLE_RIGHT).getImage(); + imgL = FSkin.getIcon(FSkin.ButtonImages.IMG_BTN_TOGGLE_LEFT); + imgM = FSkin.getIcon(FSkin.ButtonImages.IMG_BTN_TOGGLE_CENTER); + imgR = FSkin.getIcon(FSkin.ButtonImages.IMG_BTN_TOGGLE_RIGHT); } else if (isEnabled()) { resetImg(); } else { - imgL = FSkin.getIcon(FSkin.ButtonImages.IMG_BTN_DISABLED_LEFT).getImage(); - imgM = FSkin.getIcon(FSkin.ButtonImages.IMG_BTN_DISABLED_CENTER).getImage(); - imgR = FSkin.getIcon(FSkin.ButtonImages.IMG_BTN_DISABLED_RIGHT).getImage(); + imgL = FSkin.getIcon(FSkin.ButtonImages.IMG_BTN_DISABLED_LEFT); + imgM = FSkin.getIcon(FSkin.ButtonImages.IMG_BTN_DISABLED_CENTER); + imgR = FSkin.getIcon(FSkin.ButtonImages.IMG_BTN_DISABLED_RIGHT); } this.toggle = b0; repaintSelf(); @@ -230,9 +233,9 @@ public class FButton extends JButton implements ILocalRepaint { w = getWidth(); h = getHeight(); - g2d.drawImage(imgL, 0, 0, this.h, this.h, null); - g2d.drawImage(imgM, this.h, 0, this.w - (2 * this.h), this.h, null); - g2d.drawImage(imgR, this.w - this.h, 0, this.h, this.h, null); + skin.drawImage(g2d, imgL, 0, 0, this.h, this.h); + skin.drawImage(g2d, imgM, this.h, 0, this.w - (2 * this.h), this.h); + skin.drawImage(g2d, imgR, this.w - this.h, 0, this.h, this.h); super.paintComponent(g); } diff --git a/src/main/java/forge/gui/toolbox/FCheckBox.java b/src/main/java/forge/gui/toolbox/FCheckBox.java index b25ba7615d9..9bd54aef1a5 100644 --- a/src/main/java/forge/gui/toolbox/FCheckBox.java +++ b/src/main/java/forge/gui/toolbox/FCheckBox.java @@ -2,6 +2,8 @@ package forge.gui.toolbox; import javax.swing.JCheckBox; +import forge.gui.toolbox.FSkin.JComponentSkin; + /** * A custom instance of JCheckBox using Forge skin properties. */ @@ -13,8 +15,9 @@ public class FCheckBox extends JCheckBox { public FCheckBox(final String s0) { super(s0); - this.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); - this.setFont(FSkin.getFont(14)); + JComponentSkin skin = FSkin.get(this); + skin.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); + skin.setFont(FSkin.getFont(14)); this.setOpaque(false); } } diff --git a/src/main/java/forge/gui/toolbox/FComboBoxPanel.java b/src/main/java/forge/gui/toolbox/FComboBoxPanel.java index 938686f5ea4..fa13f390951 100644 --- a/src/main/java/forge/gui/toolbox/FComboBoxPanel.java +++ b/src/main/java/forge/gui/toolbox/FComboBoxPanel.java @@ -2,6 +2,8 @@ package forge.gui.toolbox; import java.awt.Component; import java.awt.FlowLayout; +import java.util.ArrayList; + import javax.swing.DefaultListCellRenderer; import javax.swing.JComboBox; import javax.swing.JLabel; @@ -11,22 +13,32 @@ import javax.swing.ListCellRenderer; import javax.swing.border.EmptyBorder; import forge.Singletons; +import forge.gui.toolbox.FSkin.JLabelSkin; import forge.properties.ForgePreferences.FPref; /** - * TODO: Write javadoc for this type. + * Panel with combo box and caption (either FComboBoxWrapper or FComboBoxPanel should be used instead of JComboBox so skinning works) * */ @SuppressWarnings("serial") public class FComboBoxPanel extends JPanel { - + + private static ArrayList> allPanels = new ArrayList>(); + + public static void refreshAllSkins() { + for (FComboBoxPanel panel : allPanels) { + panel.refreshSkin(); + } + } + private String comboBoxCaption = ""; private JComboBox comboBox = null; public FComboBoxPanel(String comboBoxCaption) { super(); this.comboBoxCaption = comboBoxCaption; - applyLayoutAndSkin(); + applyLayoutAndSkin(); + allPanels.add(this); } public void setComboBox(JComboBox comboBox, E selectedItem) { @@ -58,10 +70,10 @@ public class FComboBoxPanel extends JPanel { private void setLabelLayout() { if (this.comboBoxCaption != null && !this.comboBoxCaption.isEmpty()) { - JLabel comboLabel; - comboLabel = new JLabel(this.comboBoxCaption); - comboLabel.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); - comboLabel.setFont(FSkin.getBoldFont(12)); + JLabel comboLabel = new JLabel(this.comboBoxCaption); + JLabelSkin labelSkin = FSkin.get(comboLabel); + labelSkin.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); + labelSkin.setFont(FSkin.getBoldFont(12)); this.add(comboLabel); } } @@ -69,9 +81,10 @@ public class FComboBoxPanel extends JPanel { private void setComboBoxLayout() { if (this.comboBox != null) { if (Singletons.getModel().getPreferences().getPrefBoolean(FPref.UI_THEMED_COMBOBOX)) { - this.comboBox.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); - this.comboBox.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); - this.comboBox.setFont(FSkin.getFont(12)); + FSkin.JComponentSkin> comboBoxSkin = FSkin.get(this.comboBox); + comboBoxSkin.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); + comboBoxSkin.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); + comboBoxSkin.setFont(FSkin.getFont(12)); this.comboBox.setRenderer(new ComplexCellRenderer()); } this.comboBox.setEditable(false); @@ -80,6 +93,18 @@ public class FComboBoxPanel extends JPanel { this.add(this.comboBox); } } + + public void setSelectedItem(Object item) { + this.comboBox.setSelectedItem(item); + } + + public Object getSelectedItem() { + return this.comboBox.getSelectedItem(); + } + + private void refreshSkin() { + this.comboBox = FComboBoxWrapper.refreshComboBoxSkin(this.comboBox); + } private class ComplexCellRenderer implements ListCellRenderer { @@ -96,12 +121,9 @@ public class FComboBoxPanel extends JPanel { lst0, val0, i0, isSelected, cellHasFocus); lblItem.setBorder(new EmptyBorder(4, 3, 4, 3)); - lblItem.setFont(FSkin.getFont(12)); + FSkin.get(lblItem).setFont(FSkin.getFont(12)); lblItem.setOpaque(isSelected); return lblItem; - } - } - } diff --git a/src/main/java/forge/gui/toolbox/FComboBoxWrapper.java b/src/main/java/forge/gui/toolbox/FComboBoxWrapper.java new file mode 100644 index 00000000000..baef7012ec2 --- /dev/null +++ b/src/main/java/forge/gui/toolbox/FComboBoxWrapper.java @@ -0,0 +1,186 @@ +package forge.gui.toolbox; + +import java.awt.Container; +import java.awt.event.ActionListener; +import java.awt.event.ItemListener; +import java.awt.event.KeyListener; +import java.util.ArrayList; +import java.util.Vector; + +import javax.swing.ComboBoxModel; +import javax.swing.JComboBox; +import javax.swing.ListCellRenderer; + +/** + * Wrapper for combo box with extra logic (either FComboBoxWrapper or FComboBoxPanel should be used instead of JComboBox so skinning works) + * + */ +public class FComboBoxWrapper { + + private static ArrayList> allWrappers = new ArrayList>(); + + public static void refreshAllSkins() { + for (FComboBoxWrapper wrapper : allWrappers) { + wrapper.refreshSkin(); + } + } + + private JComboBox comboBox; + private Object constraints; + + public FComboBoxWrapper() { + super(); + this.comboBox = new JComboBox(); + allWrappers.add(this); + } + + public FComboBoxWrapper(E[] items) { + super(); + this.comboBox = new JComboBox(items); + allWrappers.add(this); + } + + public FComboBoxWrapper(Vector items) { + super(); + this.comboBox = new JComboBox(items); + allWrappers.add(this); + } + + public FComboBoxWrapper(ComboBoxModel aModel) { + super(); + this.comboBox = new JComboBox(aModel); + allWrappers.add(this); + } + + public void addItem(E item) { + this.comboBox.addItem(item); + } + + public void removeItem(E item) { + this.comboBox.removeItem(item); + } + + public void removeAllItems() { + this.comboBox.removeAllItems(); + } + + public Object getSelectedItem() { + return this.comboBox.getSelectedItem(); + } + + public void setSelectedItem(Object item) { + this.comboBox.setSelectedItem(item); + } + + public int getSelectedIndex() { + return this.comboBox.getSelectedIndex(); + } + + public void setSelectedIndex(int index) { + this.comboBox.setSelectedIndex(index); + } + + public int getItemCount() { + return this.comboBox.getItemCount(); + } + + public E getItemAt(int index) { + return this.comboBox.getItemAt(index); + } + + public void addActionListener(ActionListener l) { + this.comboBox.addActionListener(l); + } + + public void addItemListener(ItemListener l) { + this.comboBox.addItemListener(l); + } + + public void addKeyListener(KeyListener l) { + this.comboBox.addKeyListener(l); + } + + public void setRenderer(ListCellRenderer aRenderer) { + this.comboBox.setRenderer(aRenderer); + } + + public void setVisible(boolean aFlag) { + this.comboBox.setVisible(aFlag); + } + + public void setEnabled(boolean aFlag) { + this.comboBox.setVisible(aFlag); + } + + public void addTo(Container container) { + addTo(container, null); + } + + public void addTo(Container container, Object constraints0) { + container.add(this.comboBox, constraints0); + this.constraints = constraints0; + } + + private void refreshSkin() { + this.comboBox = refreshComboBoxSkin(this.comboBox, this.constraints); + } + + //refresh combo box skin by replacing it with a copy of itself + //TODO: Figure out if there's a better way, as calling updateUI doesn't seem to work + public static JComboBox refreshComboBoxSkin(JComboBox comboBox) { + return refreshComboBoxSkin(comboBox, null); + } + public static JComboBox refreshComboBoxSkin(JComboBox comboBox, Object constraints) { + //find index of combo box within parent + Container parent = comboBox.getParent(); + if (parent == null) { return comboBox; } + + int index; + for (index = 0; index < parent.getComponentCount(); index++) { + if (parent.getComponent(index) == comboBox) { + break; + } + } + + //create copy of combo box + JComboBox newComboBox = new JComboBox(); + for (int i = 0; i < comboBox.getItemCount(); i++) { + newComboBox.addItem(comboBox.getItemAt(i)); + } + newComboBox.setSelectedIndex(comboBox.getSelectedIndex()); + + ActionListener[] actionListeners = newComboBox.getActionListeners(); + for (ActionListener l : actionListeners) { + newComboBox.removeActionListener(l); //remove default action listeners to prevent duplicates + } + actionListeners = comboBox.getActionListeners(); + for (ActionListener l : actionListeners) { + newComboBox.addActionListener(l); + } + + ItemListener[] itemListeners = newComboBox.getItemListeners(); + for (ItemListener l : itemListeners) { + newComboBox.removeItemListener(l); //remove default item listener to prevent duplicates + } + itemListeners = comboBox.getItemListeners(); + for (ItemListener l : itemListeners) { + newComboBox.addItemListener(l); + } + + KeyListener[] keyListeners = newComboBox.getKeyListeners(); + for (KeyListener l : keyListeners) { + newComboBox.removeKeyListener(l); //remove default key listeners to prevent duplicates + } + keyListeners = comboBox.getKeyListeners(); + for (KeyListener l : keyListeners) { + newComboBox.addKeyListener(l); + } + + newComboBox.setRenderer(comboBox.getRenderer()); + + //replace combo box with its copy so skin updated + parent.remove(index); + parent.add(newComboBox, constraints, index); + return newComboBox; + } +} \ No newline at end of file diff --git a/src/main/java/forge/gui/toolbox/FLabel.java b/src/main/java/forge/gui/toolbox/FLabel.java index bdf255cbe69..a7f554d3422 100644 --- a/src/main/java/forge/gui/toolbox/FLabel.java +++ b/src/main/java/forge/gui/toolbox/FLabel.java @@ -1,11 +1,9 @@ package forge.gui.toolbox; import java.awt.AlphaComposite; -import java.awt.Color; import java.awt.Composite; import java.awt.Dimension; import java.awt.Font; -import java.awt.GradientPaint; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Image; @@ -31,6 +29,9 @@ import javax.swing.event.AncestorListener; import forge.Command; import forge.gui.framework.ILocalRepaint; +import forge.gui.toolbox.FSkin.JLabelSkin; +import forge.gui.toolbox.FSkin.SkinColor; +import forge.gui.toolbox.FSkin.SkinImage; /** * Uses the Builder pattern to facilitate/encourage inline styling. @@ -76,7 +77,7 @@ public class FLabel extends JLabel implements ILocalRepaint { private boolean bldEnabled = true; protected String bldText, bldToolTip; - private ImageIcon bldIcon; + private SkinImage bldIcon; private int bldFontAlign; protected Command bldCmd; @@ -93,9 +94,9 @@ public class FLabel extends JLabel implements ILocalRepaint { * @return {@link forge.gui.toolbox.Builder} */ public Builder tooltip(final String s0) { this.bldToolTip = s0; return this; } - /**@param i0   {@link javax.swing.ImageIcon} + /**@param i0   {@link forge.gui.toolbox.FSkin.SkinIcon} * @return {@link forge.gui.toolbox.Builder} */ - public Builder icon(final ImageIcon i0) { this.bldIcon = i0; return this; } + public Builder icon(final SkinImage i0) { this.bldIcon = i0; return this; } /**@param i0   SwingConstants.CENTER, .LEFT, or .RIGHT * @return {@link forge.gui.toolbox.Builder} */ @@ -186,6 +187,8 @@ public class FLabel extends JLabel implements ILocalRepaint { // Call this using FLabel.Builder()... protected FLabel(final Builder b0) { super(b0.bldText); + + this.skin = FSkin.get(this); // Init fields from builder this.iconScaleFactor = b0.bldIconScaleFactor; @@ -230,8 +233,8 @@ public class FLabel extends JLabel implements ILocalRepaint { if (b0.bldUseSkinColors) { // Non-custom display properties - this.setForeground(clrText); - this.setBackground(clrMain); + this.skin.setForeground(clrText); + this.skin.setBackground(clrMain); } // Resize adapter @@ -245,15 +248,16 @@ public class FLabel extends JLabel implements ILocalRepaint { //========== Variable initialization // Final inits - private final Color clrHover = FSkin.getColor(FSkin.Colors.CLR_HOVER); - private final Color clrText = FSkin.getColor(FSkin.Colors.CLR_TEXT); - private final Color clrMain = FSkin.getColor(FSkin.Colors.CLR_INACTIVE); - private final Color d50 = FSkin.stepColor(clrMain, -50); - private final Color d30 = FSkin.stepColor(clrMain, -30); - private final Color d10 = FSkin.stepColor(clrMain, -10); - private final Color l10 = FSkin.stepColor(clrMain, 10); - private final Color l20 = FSkin.stepColor(clrMain, 20); - private final Color l30 = FSkin.stepColor(clrMain, 30); + private final JLabelSkin skin; + private final SkinColor clrHover = FSkin.getColor(FSkin.Colors.CLR_HOVER); + private final SkinColor clrText = FSkin.getColor(FSkin.Colors.CLR_TEXT); + private final SkinColor clrMain = FSkin.getColor(FSkin.Colors.CLR_INACTIVE); + private final SkinColor d50 = clrMain.stepColor(-50); + private final SkinColor d30 = clrMain.stepColor(-30); + private final SkinColor d10 = clrMain.stepColor(-10); + private final SkinColor l10 = clrMain.stepColor(10); + private final SkinColor l20 = clrMain.stepColor(20); + private final SkinColor l30 = clrMain.stepColor(30); // Custom properties, assigned either at realization (using builder) // or dynamically (using methods below). @@ -391,9 +395,9 @@ public class FLabel extends JLabel implements ILocalRepaint { private void setFontSize(final int i0) { switch(this.fontStyle) { - case Font.BOLD: this.setFont(FSkin.getBoldFont(i0)); break; - case Font.ITALIC: this.setFont(FSkin.getItalicFont(i0)); break; - default: this.setFont(FSkin.getFont(i0)); + case Font.BOLD: skin.setFont(FSkin.getBoldFont(i0)); break; + case Font.ITALIC: skin.setFont(FSkin.getItalicFont(i0)); break; + default: skin.setFont(FSkin.getFont(i0)); } } @@ -439,21 +443,31 @@ public class FLabel extends JLabel implements ILocalRepaint { return this.cmdRightClick; } + public void setIcon(FSkin.SkinImage icon) { + this.skin.setIcon(icon); + } + @Override // Must be public. public void setIcon(final Icon i0) { - if (i0 == null) { this.img = null; return; } // Will need image (not icon) for scaled and non-scaled. - if (iconInBackground) { this.img = ((ImageIcon) i0).getImage(); } // Will need image if not in background, but scaled. - else if (iconScaleAuto) { this.img = ((ImageIcon) i0).getImage(); } - // If not in background, not scaled, can use original icon. - else { super.setIcon(i0); } - - if (img != null) { - iw = img.getWidth(null); - ih = img.getHeight(null); - iar = ((double) iw) / ((double) ih); + if (iconInBackground || iconScaleAuto) { + if (i0 != null) { + img = ((ImageIcon) i0).getImage(); + iw = img.getWidth(null); + ih = img.getHeight(null); + iar = ((double) iw) / ((double) ih); + } + else { + img = null; + iw = 0; + ih = 0; + iar = 0; + } + } + else { // If not in background, not scaled, can use original icon. + super.setIcon(i0); } } @@ -538,38 +552,36 @@ public class FLabel extends JLabel implements ILocalRepaint { } private void paintFocus(final Graphics2D g, int w, int h) { - g.setColor(clrHover); + skin.setGraphicsColor(g, clrHover); g.drawRect(0, 0, w - 2, h - 2); - g.setColor(l30); + skin.setGraphicsColor(g, l30); g.drawRect(1, 1, w - 4, h - 4); } private void paintUp(final Graphics2D g, int w, int h) { - GradientPaint gradient = new GradientPaint(0, h, d10, 0, 0, l20); - g.setPaint(gradient); + skin.setGraphicsGradientPaint(g, 0, h, d10, 0, 0, l20); g.fillRect(0, 0, w, h); - g.setColor(d50); + skin.setGraphicsColor(g, d50); g.drawRect(0, 0, w - 2, h - 2); - g.setColor(l10); + skin.setGraphicsColor(g, l10); g.drawRect(1, 1, w - 4, h - 4); } private void paintBorder(final Graphics2D g, int w, int h) { - g.setColor(l10); + skin.setGraphicsColor(g, l10); g.drawRect(0, 0, w - 2, h - 2); - g.setColor(l30); + skin.setGraphicsColor(g, l30); g.drawRect(1, 1, w - 4, h - 4); } private void paintDown(final Graphics2D g, int w, int h) { - GradientPaint gradient = new GradientPaint(0, h, d30, 0, 0, l10); - g.setPaint(gradient); + skin.setGraphicsGradientPaint(g, 0, h, d30, 0, 0, l10); g.fillRect(0, 0, w - 1, h - 1); - g.setColor(d30); + skin.setGraphicsColor(g, d30); g.drawRect(0, 0, w - 2, h - 2); - g.setColor(l10); + skin.setGraphicsColor(g, l10); g.drawRect(1, 1, w - 4, h - 4); } diff --git a/src/main/java/forge/gui/toolbox/FList.java b/src/main/java/forge/gui/toolbox/FList.java index 9c461d85a0d..fad559dd476 100644 --- a/src/main/java/forge/gui/toolbox/FList.java +++ b/src/main/java/forge/gui/toolbox/FList.java @@ -45,7 +45,7 @@ public class FList extends JList { * TODO: Write javadoc for this method. */ private void applySkin() { - setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); + FSkin.get(this).setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); ListCellRenderer renderer = new ComplexCellRenderer(); setCellRenderer(renderer); @@ -61,10 +61,11 @@ public class FList extends JList { JLabel lblItem = (JLabel) defaultRenderer.getListCellRendererComponent( lst0, val0, i0, isSelected, cellHasFocus); + FSkin.JLabelSkin lblItemSkin = FSkin.get(lblItem); lblItem.setBorder(new EmptyBorder(4, 3, 4, 3)); - lblItem.setBackground(FSkin.getColor(hasFocus() ? FSkin.Colors.CLR_ACTIVE : FSkin.Colors.CLR_INACTIVE)); - lblItem.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); - lblItem.setFont(FSkin.getFont(13)); + lblItemSkin.setBackground(FSkin.getColor(hasFocus() ? FSkin.Colors.CLR_ACTIVE : FSkin.Colors.CLR_INACTIVE)); + lblItemSkin.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); + lblItemSkin.setFont(FSkin.getFont(13)); lblItem.setOpaque(isSelected); return lblItem; } diff --git a/src/main/java/forge/gui/toolbox/FPanel.java b/src/main/java/forge/gui/toolbox/FPanel.java index 0413bfdf8ef..c5cd84b03b7 100644 --- a/src/main/java/forge/gui/toolbox/FPanel.java +++ b/src/main/java/forge/gui/toolbox/FPanel.java @@ -17,7 +17,6 @@ */ package forge.gui.toolbox; -import java.awt.Color; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.Graphics; @@ -36,6 +35,7 @@ import javax.swing.SwingConstants; import forge.Command; import forge.gui.framework.ILocalRepaint; +import forge.gui.toolbox.FSkin.SkinImage; /** * Core panel used in UI. @@ -51,13 +51,14 @@ import forge.gui.framework.ILocalRepaint; @SuppressWarnings("serial") public class FPanel extends JPanel implements ILocalRepaint { //========== Variable initialization + protected final FSkin.FPanelSkin skin; // Defaults for adjustable values private boolean selectable = false; private boolean hoverable = false; private boolean foregroundStretch = false; private Image foregroundImage = null; private Image backgroundTexture = null; - private Color borderColor = FSkin.getColor(FSkin.Colors.CLR_BORDERS); + private FSkin.SkinColor borderColor = FSkin.getColor(FSkin.Colors.CLR_BORDERS); private boolean borderToggle = true; private int cornerDiameter = 20; private int foregroundAlign = SwingConstants.CENTER; @@ -85,7 +86,8 @@ public class FPanel extends JPanel implements ILocalRepaint { this.setOpaque(false); // Background will follow skin theme. - this.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME)); + skin = FSkin.get(this); + skin.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME)); } // Mouse event handler @@ -138,13 +140,15 @@ public class FPanel extends JPanel implements ILocalRepaint { /** @param bool0   boolean */ public void setSelected(final boolean bool0) { selected = bool0; - if (bool0) { this.setBackground(FSkin.getColor(FSkin.Colors.CLR_ACTIVE)); } - else { this.setBackground(FSkin.getColor(FSkin.Colors.CLR_INACTIVE)); } + if (bool0) { skin.setBackground(FSkin.getColor(FSkin.Colors.CLR_ACTIVE)); } + else { skin.setBackground(FSkin.getColor(FSkin.Colors.CLR_INACTIVE)); } repaintSelf(); } /** @param img0   {@link java.awt.Image} */ public void setForegroundImage(final Image img0) { + skin.resetForegroundImage(); //must reset if non-skin image set + if (img0 == null) { this.foregroundImage = null; return; @@ -161,6 +165,11 @@ public class FPanel extends JPanel implements ILocalRepaint { setForegroundImage(ii0.getImage()); } + /** @param ii0   {@link javax.swing.ImageIcon} */ + public void setForegroundImage(final SkinImage skinImage) { + skin.setForegroundImage(skinImage); + } + /** Aligns NON-STRETCHED foreground image. * Must use SwingConstants. * @param i0   int @@ -186,6 +195,8 @@ public class FPanel extends JPanel implements ILocalRepaint { /** @param img0   {@link java.awt.Image} */ public void setBackgroundTexture(final Image img0) { + skin.resetBackgroundTexture(); //must reset if non-skin image set + if (img0 == null) { return; } this.backgroundTexture = img0; @@ -197,14 +208,19 @@ public class FPanel extends JPanel implements ILocalRepaint { public void setBackgroundTexture(final ImageIcon ii0) { setBackgroundTexture(ii0.getImage()); } + + /** @param ii0   {@link javax.swing.ImageIcon} */ + public void setBackgroundTexture(final SkinImage skinImage) { + skin.setBackgroundTexture(skinImage); + } /** @param bool0   boolean */ public void setBorderToggle(final boolean bool0) { this.borderToggle = bool0; } - /** @param clr0   {@link java.awt.Color} */ - public void setBorderColor(final Color clr0) { + /** @param clr0   {@link forge.gui.toolbox.FSkin.SkinColor} */ + public void setBorderColor(final FSkin.SkinColor clr0) { this.borderColor = clr0; } @@ -260,10 +276,10 @@ public class FPanel extends JPanel implements ILocalRepaint { //========== Special draw methods private void drawBackgroundColor(final Graphics2D g2d0) { // Color background as appropriate - if (selected) { g2d0.setColor(FSkin.getColor(FSkin.Colors.CLR_ACTIVE)); } - else if (hovered) { g2d0.setColor(FSkin.getColor(FSkin.Colors.CLR_HOVER)); } - else if (selectable) { g2d0.setColor(FSkin.getColor(FSkin.Colors.CLR_INACTIVE)); } - else { g2d0.setColor(getBackground()); } + if (selected) { skin.setGraphicsColor(g2d0, FSkin.getColor(FSkin.Colors.CLR_ACTIVE)); } + else if (hovered) { skin.setGraphicsColor(g2d0, FSkin.getColor(FSkin.Colors.CLR_HOVER)); } + else if (selectable) { skin.setGraphicsColor(g2d0, FSkin.getColor(FSkin.Colors.CLR_INACTIVE)); } + else { skin.setGraphicsColor(g2d0, skin.getBackground()); } g2d0.fillRoundRect(0, 0, pnlW, pnlH, cornerDiameter, cornerDiameter); } @@ -327,7 +343,7 @@ public class FPanel extends JPanel implements ILocalRepaint { } private void drawBorder(final Graphics2D g2d0) { - g2d0.setColor(borderColor); + skin.setGraphicsColor(g2d0, borderColor); g2d0.drawRoundRect(0, 0, pnlW - 1, pnlH - 1, cornerDiameter, cornerDiameter); } diff --git a/src/main/java/forge/gui/toolbox/FRadioButton.java b/src/main/java/forge/gui/toolbox/FRadioButton.java index da9764e7788..1f9da18c3ec 100644 --- a/src/main/java/forge/gui/toolbox/FRadioButton.java +++ b/src/main/java/forge/gui/toolbox/FRadioButton.java @@ -2,6 +2,8 @@ package forge.gui.toolbox; import javax.swing.JRadioButton; +import forge.gui.toolbox.FSkin.JComponentSkin; + /** * A custom instance of JRadioButton using Forge skin properties. */ @@ -16,8 +18,9 @@ public class FRadioButton extends JRadioButton { public FRadioButton(String s0) { super(); this.setText(s0); - this.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); - this.setFont(FSkin.getFont(14)); + JComponentSkin skin = FSkin.get(this); + skin.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); + skin.setFont(FSkin.getFont(14)); this.setOpaque(false); } } diff --git a/src/main/java/forge/gui/toolbox/FScrollPane.java b/src/main/java/forge/gui/toolbox/FScrollPane.java index a4847dd3577..8bd21f92e9b 100644 --- a/src/main/java/forge/gui/toolbox/FScrollPane.java +++ b/src/main/java/forge/gui/toolbox/FScrollPane.java @@ -4,7 +4,6 @@ import java.awt.Component; import javax.swing.JScrollPane; import javax.swing.ScrollPaneConstants; -import javax.swing.border.LineBorder; /** * A very basic extension of JScrollPane to centralize common styling changes. @@ -33,7 +32,7 @@ public class FScrollPane extends JScrollPane { super(c0, vertical0, horizontal0); getVerticalScrollBar().setUnitIncrement(16); getViewport().setOpaque(false); - setBorder(new LineBorder(FSkin.getColor(FSkin.Colors.CLR_BORDERS), 1)); + FSkin.get(this).setLineBorder(FSkin.getColor(FSkin.Colors.CLR_BORDERS)); setOpaque(false); } } diff --git a/src/main/java/forge/gui/toolbox/FScrollPanel.java b/src/main/java/forge/gui/toolbox/FScrollPanel.java index 51be78e9ad3..4b2860349f2 100644 --- a/src/main/java/forge/gui/toolbox/FScrollPanel.java +++ b/src/main/java/forge/gui/toolbox/FScrollPanel.java @@ -22,7 +22,6 @@ import java.awt.Color; import java.awt.Component; import java.awt.Composite; import java.awt.Dimension; -import java.awt.GradientPaint; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.LayoutManager; @@ -40,6 +39,8 @@ import javax.swing.ScrollPaneConstants; import javax.swing.Timer; import forge.gui.framework.ILocalRepaint; +import forge.gui.toolbox.FSkin.JLabelSkin; +import forge.gui.toolbox.FSkin.SkinColor; /** * An extension of JScrollPane that can be used as a panel and supports using arrow buttons to scroll instead of scrollbars @@ -195,12 +196,13 @@ public class FScrollPanel extends JScrollPane { } private abstract class ArrowButton extends JLabel implements ILocalRepaint { - private final Color clrFore = FSkin.getColor(FSkin.Colors.CLR_TEXT); - private final Color clrBack = FSkin.getColor(FSkin.Colors.CLR_INACTIVE); - private final Color d50 = FSkin.stepColor(clrBack, -50); - private final Color d10 = FSkin.stepColor(clrBack, -10); - private final Color l10 = FSkin.stepColor(clrBack, 10); - private final Color l20 = FSkin.stepColor(clrBack, 20); + private final JLabelSkin skin; + private final SkinColor clrFore = FSkin.getColor(FSkin.Colors.CLR_TEXT); + private final SkinColor clrBack = FSkin.getColor(FSkin.Colors.CLR_INACTIVE); + private final SkinColor d50 = clrBack.stepColor(-50); + private final SkinColor d10 = clrBack.stepColor(-10); + private final SkinColor l10 = clrBack.stepColor(10); + private final SkinColor l20 = clrBack.stepColor(20); private final AlphaComposite alphaDefault = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f); private final AlphaComposite alphaHovered = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.9f); protected final int arrowSize = 6; @@ -210,6 +212,7 @@ public class FScrollPanel extends JScrollPane { protected ArrowButton(final JScrollBar scrollBar0, final int incrementDirection0) { super(""); + skin = FSkin.get(this); scrollBar = scrollBar0; incrementDirection = incrementDirection0; timer.setInitialDelay(500); //wait half a second after mouse down before starting timer @@ -235,16 +238,15 @@ public class FScrollPanel extends JScrollPane { Composite oldComp = g2d.getComposite(); g2d.setComposite(hovered ? alphaHovered : alphaDefault); - GradientPaint gradient = new GradientPaint(0, h, d10, 0, 0, l20); - g2d.setPaint(gradient); + skin.setGraphicsGradientPaint(g2d, 0, h, d10, 0, 0, l20); g.fillRect(0, 0, w, h); - g.setColor(d50); + skin.setGraphicsColor(g, d50); g.drawRect(0, 0, w - 1, h - 1); - g.setColor(l10); + skin.setGraphicsColor(g, l10); g.drawRect(1, 1, w - 3, h - 3); - g.setColor(clrFore); + skin.setGraphicsColor(g, clrFore); drawArrow(g); super.paintComponent(g); diff --git a/src/main/java/forge/gui/toolbox/FSkin.java b/src/main/java/forge/gui/toolbox/FSkin.java index 532e5654ee0..db5768837b8 100644 --- a/src/main/java/forge/gui/toolbox/FSkin.java +++ b/src/main/java/forge/gui/toolbox/FSkin.java @@ -18,27 +18,49 @@ package forge.gui.toolbox; import java.awt.Color; +import java.awt.Component; +import java.awt.Cursor; +import java.awt.Dimension; import java.awt.Font; +import java.awt.GradientPaint; +import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Image; +import java.awt.Point; import java.awt.RenderingHints; +import java.awt.Toolkit; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; +import java.util.Map.Entry; import javax.imageio.ImageIO; +import javax.swing.AbstractButton; +import javax.swing.BorderFactory; import javax.swing.ImageIcon; +import javax.swing.JComponent; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JTable; import javax.swing.SwingUtilities; import javax.swing.UIManager; +import javax.swing.UnsupportedLookAndFeelException; +import javax.swing.border.Border; import javax.swing.border.LineBorder; +import javax.swing.text.JTextComponent; import org.apache.commons.lang.WordUtils; import forge.FThreads; +import forge.Singletons; import forge.gui.GuiUtils; +import forge.gui.home.settings.CSubmenuPreferences; +import forge.properties.ForgePreferences; +import forge.properties.ForgePreferences.FPref; +import forge.util.TypeUtil; import forge.view.FView; /** @@ -50,6 +72,463 @@ import forge.view.FView; public enum FSkin { /** Singleton instance of skin. */ SINGLETON_INSTANCE; + + public static class ComponentSkin { + protected T comp; + private SkinColor foreground, background; + private SkinFont font; + private SkinCursor cursor; + protected boolean needRepaintOnReapply; + + private ComponentSkin(T comp0) { + this.comp = comp0; + } + + public SkinColor getForeground() { + return this.foreground; + } + + public void setForeground(SkinColor skinColor) { + this.foreground = skinColor; + this.comp.setForeground(skinColor.color); + } + public void setForeground(Color color) { + this.foreground = null; //ensure this field is reset when static color set + this.comp.setForeground(color); + } + + public SkinColor getBackground() { + return this.background; + } + + public void setBackground(SkinColor skinColor) { + this.background = skinColor; + this.comp.setBackground(skinColor.color); + } + public void setBackground(Color color) { + this.background = null; //ensure this field is reset when static color set + this.comp.setBackground(color); + } + + public void setFont(SkinFont skinFont) { + this.font = skinFont; + this.comp.setFont(skinFont.font); + } + public void setFont(Font font) { + this.font = null; //ensure this field is reset when static font set + this.comp.setFont(font); + } + + public void setCursor(SkinCursor skinCursor) { + this.cursor = skinCursor; + this.comp.setCursor(skinCursor != null ? skinCursor.cursor : null); + } + public void setCursor(Cursor cursor0) { + this.cursor = null; //ensure this field is reset when static cursor set + this.comp.setCursor(cursor0); + } + public void resetCursor() { + this.cursor = null; + } + + public void setGraphicsColor(Graphics g, SkinColor skinColor) { + this.needRepaintOnReapply = true; + g.setColor(skinColor.color); + } + + public void setGraphicsGradientPaint(Graphics2D g2d, float x1, float y1, SkinColor skinColor1, float x2, float y2, SkinColor skinColor2) { + this.needRepaintOnReapply = true; + g2d.setPaint(new GradientPaint(x1, y1, skinColor1.color, x2, y2, skinColor2.color)); + } + public void setGraphicsGradientPaint(Graphics2D g2d, float x1, float y1, Color color1, float x2, float y2, SkinColor skinColor2) { + this.needRepaintOnReapply = true; + g2d.setPaint(new GradientPaint(x1, y1, color1, x2, y2, skinColor2.color)); + } + public void setGraphicsGradientPaint(Graphics2D g2d, float x1, float y1, SkinColor skinColor1, float x2, float y2, Color color2) { + this.needRepaintOnReapply = true; + g2d.setPaint(new GradientPaint(x1, y1, skinColor1.color, x2, y2, color2)); + } + + public void drawImage(Graphics g, SkinImage skinImage, int x, int y) { + this.needRepaintOnReapply = true; + g.drawImage(skinImage.image, x, y, null); + } + public void drawImage(Graphics g, SkinImage skinImage, int x, int y, int w, int h) { + this.needRepaintOnReapply = true; + g.drawImage(skinImage.image, x, y, w, h, null); + } + public void drawImage(Graphics g, SkinImage skinImage, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2) { + this.needRepaintOnReapply = true; + g.drawImage(skinImage.image, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, null); + } + + protected void reapply() { + if (this.foreground != null) { + comp.setForeground(this.foreground.color); + } + if (this.background != null) { + comp.setBackground(this.background.color); + } + if (this.font != null) { + comp.setFont(this.font.font); + } + if (this.cursor != null) { + comp.setCursor(this.cursor.cursor); + } + if (this.needRepaintOnReapply) { + comp.repaint(); + } + } + } + public static class JFrameSkin extends ComponentSkin { + private SkinImage iconImage; + + private JFrameSkin(T comp0) { + super(comp0); + } + + public void setIconImage(SkinImage skinImage) { + this.iconImage = skinImage; + this.comp.setIconImage(skinImage.image); + } + public void setIcon(Image image) { + this.iconImage = null; //ensure this field is reset when static image set + this.comp.setIconImage(image); + } + + @Override + protected void reapply() { + if (this.iconImage != null) { + this.comp.setIconImage(this.iconImage.image); + } + super.reapply(); + } + } + public static class JComponentSkin extends ComponentSkin { + private class LineBorder { + private final SkinColor skinColor; + private final int thickness; + private final boolean rounded; + + private LineBorder(SkinColor skinColor0, int thickness0, boolean rounded0) { + this.skinColor = skinColor0; + this.thickness = thickness0; + this.rounded = rounded0; + } + + private void apply() { + JComponentSkin.this.comp.setBorder(BorderFactory.createLineBorder(this.skinColor.color, this.thickness, this.rounded)); + } + } + private LineBorder lineBorder; + + private class MatteBorder { + private final int top, left, bottom, right; + private final SkinColor skinColor; + + private MatteBorder(int top0, int left0, int bottom0, int right0, SkinColor skinColor0) { + this.top = top0; + this.left = left0; + this.bottom = bottom0; + this.right = right0; + this.skinColor = skinColor0; + } + + private void apply() { + JComponentSkin.this.comp.setBorder(BorderFactory.createMatteBorder(this.top, this.left, this.bottom, this.right, this.skinColor.color)); + } + } + private MatteBorder matteBorder; + + private JComponentSkin(T comp0) { + super(comp0); + } + + public void setLineBorder(SkinColor skinColor) { + setLineBorder(skinColor, 1, false); + } + public void setLineBorder(SkinColor skinColor, int thickness) { + setLineBorder(skinColor, thickness, false); + } + public void setLineBorder(SkinColor skinColor, int thickness, boolean rounded) { + this.lineBorder = new LineBorder(skinColor, thickness, rounded); + this.lineBorder.apply(); + } + + public void setMatteBorder(int top, int left, int bottom, int right, SkinColor skinColor) { + this.matteBorder = new MatteBorder(top, left, bottom, right, skinColor); + this.matteBorder.apply(); + } + + @Override + protected void reapply() { + if (this.lineBorder != null) { + this.lineBorder.apply(); + } + if (this.matteBorder != null) { + this.matteBorder.apply(); + } + super.reapply(); + } + } + public static class JLabelSkin extends JComponentSkin { + private SkinImage icon; + + private JLabelSkin(T comp0) { + super(comp0); + } + + public void setIcon(SkinImage skinImage) { + this.icon = skinImage; + this.comp.setIcon(skinImage != null ? skinImage.getIcon() : null); + } + public void setIcon(ImageIcon imageIcon) { + this.icon = null; //ensure this field is reset when static icon set + this.comp.setIcon(imageIcon); + } + + @Override + protected void reapply() { + if (this.icon != null) { + this.comp.setIcon(this.icon.getIcon()); + } + super.reapply(); + } + } + public static class AbstractButtonSkin extends JComponentSkin { + private SkinImage icon, pressedIcon, rolloverIcon; + + private AbstractButtonSkin(T comp0) { + super(comp0); + } + + public void setIcon(SkinImage skinImage) { + this.icon = skinImage; + this.comp.setIcon(skinImage != null ? skinImage.getIcon() : null); + } + public void setIcon(ImageIcon imageIcon) { + this.icon = null; //ensure this field is reset when static icon set + this.comp.setIcon(imageIcon); + } + + public void setPressedIcon(SkinImage skinImage) { + this.pressedIcon = skinImage; + this.comp.setPressedIcon(skinImage != null ? skinImage.getIcon() : null); + } + public void setPressedIcon(ImageIcon imageIcon) { + this.pressedIcon = null; //ensure this field is reset when static icon set + this.comp.setPressedIcon(imageIcon); + } + + public void setRolloverIcon(SkinImage skinImage) { + this.rolloverIcon = skinImage; + this.comp.setRolloverIcon(skinImage != null ? skinImage.getIcon() : null); + } + public void setRolloverIcon(ImageIcon imageIcon) { + this.rolloverIcon = null; //ensure this field is reset when static icon set + this.comp.setRolloverIcon(imageIcon); + } + + @Override + protected void reapply() { + if (this.icon != null) { + this.comp.setIcon(this.icon.getIcon()); + } + if (this.pressedIcon != null) { + this.comp.setPressedIcon(this.pressedIcon.getIcon()); + } + if (this.rolloverIcon != null) { + this.comp.setRolloverIcon(this.rolloverIcon.getIcon()); + } + super.reapply(); + } + } + public static class JTextComponentSkin extends JComponentSkin { + private SkinColor caretColor; + + private JTextComponentSkin(T comp0) { + super(comp0); + } + + public SkinColor getCaretColor() { + return this.caretColor; + } + + public void setCaretColor(SkinColor skinColor) { + this.caretColor = skinColor; + this.comp.setCaretColor(skinColor.color); + } + public void setCaretColor(Color color) { + this.caretColor = null; //ensure this field is reset when static color set + this.comp.setCaretColor(color); + } + + @Override + protected void reapply() { + if (this.caretColor != null) { + this.comp.setCaretColor(this.caretColor.color); + } + super.reapply(); + } + } + public static class JTableSkin extends JComponentSkin { + private SkinColor selectionForeground, selectionBackground; + + private JTableSkin(T comp0) { + super(comp0); + } + + public SkinColor getSelectionForeground() { + return this.selectionForeground; + } + + public void setSelectionForeground(SkinColor skinColor) { + this.selectionForeground = skinColor; + this.comp.setSelectionForeground(skinColor.color); + } + public void setSelectionForeground(Color color) { + this.selectionForeground = null; //ensure this field is reset when static color set + this.comp.setSelectionForeground(color); + } + + public SkinColor getSelectionBackground() { + return this.selectionBackground; + } + + public void setSelectionBackground(SkinColor skinColor) { + this.selectionBackground = skinColor; + this.comp.setSelectionBackground(skinColor.color); + } + public void setSelectionBackground(Color color) { + this.selectionBackground = null; //ensure this field is reset when static color set + this.comp.setSelectionBackground(color); + } + + @Override + protected void reapply() { + if (this.selectionForeground != null) { + this.comp.setSelectionForeground(this.selectionForeground.color); + } + if (this.selectionBackground != null) { + this.comp.setSelectionBackground(this.selectionBackground.color); + } + super.reapply(); + } + } + public static class FPanelSkin extends JComponentSkin { + private SkinImage foregroundImage, backgroundTexture; + + private FPanelSkin(T comp0) { + super(comp0); + } + + public void setForegroundImage(SkinImage skinIcon) { + this.comp.setForegroundImage(skinIcon.image); //must call this first since it will call resetForegroundImage + this.foregroundImage = skinIcon; + this.needRepaintOnReapply = true; //foreground image draw during paint + } + + public void resetForegroundImage() { + this.foregroundImage = null; + } + + public void setBackgroundTexture(SkinImage skinIcon) { + this.comp.setBackgroundTexture(skinIcon.image); //must call this first since it will call resetBackgroundTexture + this.backgroundTexture = skinIcon; + this.needRepaintOnReapply = true; //background texture drawn during paint + } + + public void resetBackgroundTexture() { + this.backgroundTexture = null; + } + + @Override + protected void reapply() { + if (this.foregroundImage != null) { + this.setForegroundImage(this.foregroundImage); //use skin function so foregroundImage field retained + } + if (this.backgroundTexture != null) { + this.setBackgroundTexture(this.backgroundTexture); //use skin function so backgroundTexture field retained + } + super.reapply(); + } + } + + @SuppressWarnings("rawtypes") + private static HashMap compSkins = new HashMap(); + + @SuppressWarnings("unchecked") + public static ComponentSkin get(T comp) { + ComponentSkin skinnedComp = compSkins.get(comp); + if (skinnedComp == null) { + skinnedComp = new ComponentSkin(comp); + compSkins.put(comp, skinnedComp); + } + return skinnedComp; + } + @SuppressWarnings("unchecked") + public static JFrameSkin get(T comp) { + JFrameSkin skinnedComp = TypeUtil.safeCast(compSkins.get(comp), JFrameSkin.class); + if (skinnedComp == null) { + skinnedComp = new JFrameSkin(comp); + compSkins.put(comp, skinnedComp); + } + return skinnedComp; + } + @SuppressWarnings("unchecked") + public static JComponentSkin get(T comp) { + JComponentSkin skinnedComp = TypeUtil.safeCast(compSkins.get(comp), JComponentSkin.class); + if (skinnedComp == null) { + skinnedComp = new JComponentSkin(comp); + compSkins.put(comp, skinnedComp); + } + return skinnedComp; + } + @SuppressWarnings("unchecked") + public static JLabelSkin get(T comp) { + JLabelSkin skinnedComp = TypeUtil.safeCast(compSkins.get(comp), JLabelSkin.class); + if (skinnedComp == null) { + skinnedComp = new JLabelSkin(comp); + compSkins.put(comp, skinnedComp); + } + return skinnedComp; + } + @SuppressWarnings("unchecked") + public static AbstractButtonSkin get(T comp) { + AbstractButtonSkin skinnedComp = TypeUtil.safeCast(compSkins.get(comp), AbstractButtonSkin.class); + if (skinnedComp == null) { + skinnedComp = new AbstractButtonSkin(comp); + compSkins.put(comp, skinnedComp); + } + return skinnedComp; + } + @SuppressWarnings("unchecked") + public static JTextComponentSkin get(T comp) { + JTextComponentSkin skinnedComp = TypeUtil.safeCast(compSkins.get(comp), JTextComponentSkin.class); + if (skinnedComp == null) { + skinnedComp = new JTextComponentSkin(comp); + compSkins.put(comp, skinnedComp); + } + return skinnedComp; + } + @SuppressWarnings("unchecked") + public static JTableSkin get(T comp) { + JTableSkin skinnedComp = TypeUtil.safeCast(compSkins.get(comp), JTableSkin.class); + if (skinnedComp == null) { + skinnedComp = new JTableSkin(comp); + compSkins.put(comp, skinnedComp); + } + return skinnedComp; + } + @SuppressWarnings("unchecked") + public static FPanelSkin get(T comp) { + FPanelSkin skinnedComp = TypeUtil.safeCast(compSkins.get(comp), FPanelSkin.class); + if (skinnedComp == null) { + skinnedComp = new FPanelSkin(comp); + compSkins.put(comp, skinnedComp); + } + return skinnedComp; + } /** */ public enum Backgrounds implements SkinProp { /** */ @@ -64,6 +543,129 @@ public enum FSkin { @Override public int[] getCoords() { return coords; } } + + /** + * Retrieves a color from this skin's color map. + * + * @param c0   Colors property (from enum) + * @return {@link forge.gui.toolbox.FSkin.SkinColor} + */ + public static SkinColor getColor(final Colors c0) { + return SkinColor.baseColors.get(c0); + } + + /** Steps RGB components of a color up or down. + * Returns opaque (non-alpha) stepped color. + * Plus for lighter, minus for darker. + * + * @param clr0 {@link java.awt.Color} + * @param step int + * @return {@link java.awt.Color} + */ + public static Color stepColor(Color clr0, int step) { + int r = clr0.getRed(); + int g = clr0.getGreen(); + int b = clr0.getBlue(); + + // Darker + if (step < 0) { + r = ((r + step > 0) ? r + step : 0); + g = ((g + step > 0) ? g + step : 0); + b = ((b + step > 0) ? b + step : 0); + } + else { + r = ((r + step < 255) ? r + step : 255); + g = ((g + step < 255) ? g + step : 255); + b = ((b + step < 255) ? b + step : 255); + } + + return new Color(r, g, b); + } + + /** Returns RGB components of a color, with a new + * value for alpha. 0 = transparent, 255 = opaque. + * + * @param clr0 {@link java.awt.Color} + * @param alpha int + * @return {@link java.awt.Color} + */ + public static Color alphaColor(Color clr0, int alpha) { + return new Color(clr0.getRed(), clr0.getGreen(), clr0.getBlue(), alpha); + } + + public static class SkinColor { + private static final HashMap baseColors = new HashMap(); + private static final HashMap derivedColors = new HashMap(); + private static final int NO_BRIGHTNESS_DELTA = 0; + private static final int NO_STEP = -999; //needs to be large negative since small negative values are valid + private static final int NO_ALPHA = -1; + + private final Colors baseColor; + private final int brightnessDelta; + private final int step; + private final int alpha; + private Color color; + + //private constructors for color that changes with skin (use FSkin.getColor()) + private SkinColor(Colors baseColor0) { + this(baseColor0, NO_BRIGHTNESS_DELTA, NO_STEP, NO_ALPHA); + } + private SkinColor(Colors baseColor0, int brightnessDelta0, int step0, int alpha0) { + this.baseColor = baseColor0; + this.brightnessDelta = brightnessDelta0; + this.step = step0; + this.alpha = alpha0; + this.updateColor(); + } + + private SkinColor getDerivedColor(int brightnessDelta0, int step0, int alpha0) { + String key = this.baseColor.name() + "|" + brightnessDelta0 + "|" + step0 + "|" + alpha0; + SkinColor derivedColor = derivedColors.get(key); + if (derivedColor == null) { + derivedColor = new SkinColor(this.baseColor, brightnessDelta0, step0, alpha0); + derivedColors.put(key, derivedColor); + } + return derivedColor; + } + + public SkinColor brighter() { + return getDerivedColor(this.brightnessDelta + 1, this.step, this.alpha); + } + + public SkinColor darker() { + return getDerivedColor(this.brightnessDelta - 1, this.step, this.alpha); + } + + public SkinColor stepColor(int step0) { + return getDerivedColor(this.brightnessDelta, step0, this.alpha); + } + + public SkinColor alphaColor(int alpha0) { + return getDerivedColor(this.brightnessDelta, this.step, alpha0); + } + + private void updateColor() { + this.color = this.baseColor.color; + if (this.brightnessDelta != NO_BRIGHTNESS_DELTA) { + if (this.brightnessDelta < 0) { + for (int i = 0; i > this.brightnessDelta; i--) { + this.color = this.color.darker(); + } + } + else { + for (int i = 0; i < this.brightnessDelta; i++) { + this.color = this.color.brighter(); + } + } + } + if (this.step != NO_STEP) { + this.color = FSkin.stepColor(this.color, this.step); + } + if (this.alpha != NO_ALPHA) { + this.color = FSkin.alphaColor(this.color, this.alpha); + } + } + } /** */ public enum Colors implements SkinProp { /** */ @@ -81,12 +683,410 @@ public enum FSkin { CLR_THEME2 (new int[] {70, 230}), /** */ CLR_OVERLAY (new int[] {70, 250}); + private Color color; private int[] coords; + /** @param xy   int[] coordinates */ Colors(final int[] xy) { this.coords = xy; } + /** @return int[] */ @Override public int[] getCoords() { return coords; } + + public static void updateAll() { + for (final Colors c : Colors.values()) { + c.updateColor(); + } + if (SkinColor.baseColors.size() == 0) { //initialize base skin colors if needed + for (final Colors c : Colors.values()) { + SkinColor.baseColors.put(c, new SkinColor(c)); + } + } + else { //update existing SkinColors if baseColors already initialized + for (final SkinColor c : SkinColor.baseColors.values()) { + c.updateColor(); + } + for (final SkinColor c : SkinColor.derivedColors.values()) { + c.updateColor(); + } + } + } + + private void updateColor() { + tempCoords = this.getCoords(); + x0 = tempCoords[0]; + y0 = tempCoords[1]; + + color = FSkin.getColorFromPixel(bimPreferredSprite.getRGB(x0, y0)); + } + } + + /** + * Gets an image. + * + * @param s0   SkinProp enum + * @return {@link forge.gui.toolbox.FSkin.SkinImage} + */ + public static SkinImage getImage(final SkinProp s0) { + SkinImage image = SkinImage.images.get(s0); + if (image == null) { + throw new NullPointerException("Can't find an image for SkinProp " + s0); + } + return image; + } + + /** + * Gets a scaled version of an image from this skin's image map. + * + * @param s0 + * String image enum + * @param w0 + * int new width + * @param h0 + * int new height + * @return {@link forge.gui.toolbox.FSkin.SkinImage} + */ + public static SkinImage getImage(final SkinProp s0, int w0, int h0) { + w0 = (w0 < 1) ? 1 : w0; + h0 = (h0 < 1) ? 1 : h0; + return getImage(s0).resize(w0, h0); + } + + public static class SkinImage { + private static final Map images = new HashMap(); + + private static void setImage(final SkinProp s0, Image image0) { + SkinImage skinImage = images.get(s0); + if (skinImage == null) { + skinImage = new SkinImage(image0); + images.put(s0, skinImage); + } + else { + skinImage.changeImage(image0, null); + } + } + + /** + * setImage, with auto-scaling assumed true. + * + * @param s0 + */ + private static void setImage(final SkinProp s0) { + setImage(s0, true); + } + + /** + * Checks the preferred sprite for existence of a sub-image + * defined by X, Y, W, H. + * + * If an image is not present at those coordinates, default + * icon is substituted. + * + * The result is saved in a HashMap. + * + * @param s0   An address in the hashmap, derived from SkinProp enum + */ + private static void setImage(final SkinProp s0, final boolean scale) { + tempCoords = s0.getCoords(); + x0 = tempCoords[0]; + y0 = tempCoords[1]; + w0 = tempCoords[2]; + h0 = tempCoords[3]; + newW = (tempCoords.length == 6 ? tempCoords[4] : 0); + newH = (tempCoords.length == 6 ? tempCoords[5] : 0); + + final BufferedImage img = FSkin.testPreferredSprite(s0); + final BufferedImage bi0 = img.getSubimage(x0, y0, w0, h0); + + if (scale && newW != 0) { + setImage(s0, bi0.getScaledInstance(newW, newH, Image.SCALE_AREA_AVERAGING)); + } + else { + setImage(s0, bi0); + } + } + + protected Image image; + protected ImageIcon imageIcon; + protected HashMap scaledImages; + private HashMap cursors; + + private SkinImage(Image image0) { + this.image = image0; + } + + protected void changeImage(Image image0, ImageIcon imageIcon0) { + this.image = image0; + this.imageIcon = imageIcon0; + this.updateScaledImages(); + this.updateCursors(); + } + + protected SkinImage clone() { + return new SkinImage(this.image); + } + + public SkinImage resize(int w, int h) { + if (this.scaledImages == null) { + this.scaledImages = new HashMap(); + } + String key = w + "x" + h; + SkinImage scaledImage = this.scaledImages.get(key); + if (scaledImage == null) { + scaledImage = this.clone(); + scaledImage.createResizedImage(this, w, h); + this.scaledImages.put(key, scaledImage); + } + return scaledImage; + } + + public SkinImage scale(double scale) { + return scale(scale, scale); + } + public SkinImage scale(double scaleX, double scaleY) { + if (this.scaledImages == null) { + this.scaledImages = new HashMap(); + } + String key = scaleX + "|" + scaleY; + SkinImage scaledImage = this.scaledImages.get(key); + if (scaledImage == null) { + scaledImage = this.clone(); + scaledImage.createScaledImage(this, scaleX, scaleY); + this.scaledImages.put(key, scaledImage); + } + return scaledImage; + } + + protected void updateScaledImages() { + if (this.scaledImages == null) { return; } + + for (Entry i : this.scaledImages.entrySet()) { + String[] dims = i.getKey().split("x"); + if (dims.length == 2) { //static scale + i.getValue().createResizedImage(this, Integer.parseInt(dims[0]), Integer.parseInt(dims[1])); + } + else { //dynamic scale + dims = i.getKey().split("\\|"); //must escape since "|" is regex operator + i.getValue().createScaledImage(this, Double.parseDouble(dims[0]), Double.parseDouble(dims[1])); + } + } + } + + protected void createResizedImage(SkinImage baseImage, int w, int h) { + final BufferedImage resizedImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); + + final Graphics2D g2d = resizedImage.createGraphics(); + g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); + g2d.drawImage(baseImage.image, 0, 0, w, h, 0, 0, baseImage.getWidth(), baseImage.getHeight(), null); + g2d.dispose(); + + this.changeImage(resizedImage, null); + } + + private void createScaledImage(SkinImage baseImage, double scaleX, double scaleY) { + createResizedImage(baseImage, (int)(baseImage.getWidth() * scaleX), (int)(baseImage.getHeight() * scaleY)); + } + + private SkinCursor toCursor(int hotSpotX, int hotSpotY, String name) { + if (this.cursors == null) { + this.cursors = new HashMap(); + } + String key = hotSpotX + "|" + hotSpotY + "|" + name; + SkinCursor cursor = this.cursors.get(key); + if (cursor == null) { + cursor = new SkinCursor(new Point(hotSpotX, hotSpotY), name); + cursor.updateCursor(this.image); + this.cursors.put(key, cursor); + } + return cursor; + } + + private void updateCursors() { + if (this.cursors == null) { return; } + + for (SkinCursor cursor : this.cursors.values()) { + cursor.updateCursor(this.image); + } + } + + public Dimension getSizeForPaint(Graphics g) { + if (g == null) { + throw new NullPointerException("Must pass Graphics to get size for paint"); + } + return new Dimension(this.getWidth(), this.getHeight()); + } + + protected int getWidth() { + return this.image.getWidth(null); + } + + protected int getHeight() { + return this.image.getHeight(null); + } + + protected ImageIcon getIcon() { + if (this.imageIcon == null) { + this.imageIcon = new ImageIcon(this.image); + } + return this.imageIcon; + } + } + + /** + * Gets an image. + * + * @param s0   SkinProp enum + * @return {@link forge.gui.toolbox.FSkin.SkinCursor} + */ + public static SkinCursor getCursor(final SkinProp s0, int hotSpotX, int hotSpotY, String name) { + return getImage(s0).toCursor(hotSpotX, hotSpotY, name); + } + + public static class SkinCursor { + private static final Toolkit TOOLS = Toolkit.getDefaultToolkit(); + + private final Point hotSpot; + private final String name; + private Cursor cursor; + + private SkinCursor(Point hotSpot0, String name0) { + this.hotSpot = hotSpot0; + this.name = name0; + } + + private void updateCursor(Image image) { + this.cursor = TOOLS.createCustomCursor(image, this.hotSpot, this.name); + } + } + + /** + * Gets an icon. + * + * @param s0   SkinProp enum + * @return {@link forge.gui.toolbox.FSkin.SkinImage} + */ + public static SkinIcon getIcon(final SkinProp s0) { + SkinIcon icon = SkinIcon.icons.get(s0); + if (icon == null) { + throw new NullPointerException("Can't find an icon for SkinProp " + s0); + } + return icon; + } + + public static class SkinIcon extends SkinImage { + private static final Map icons = new HashMap(); + + private static void setIcon(final SkinProp s0, ImageIcon imageIcon0) { + SkinIcon skinIcon = icons.get(s0); + if (skinIcon == null) { + skinIcon = new SkinIcon(imageIcon0); + icons.put(s0, skinIcon); + } + else { + skinIcon.changeImage(imageIcon0.getImage(), imageIcon0); + } + } + + private static void setIcon(final SkinProp s0) { + tempCoords = s0.getCoords(); + x0 = tempCoords[0]; + y0 = tempCoords[1]; + w0 = tempCoords[2]; + h0 = tempCoords[3]; + + final BufferedImage img = testPreferredSprite(s0); + + setIcon(s0, new ImageIcon(img.getSubimage(x0, y0, w0, h0))); + } + + /** + * Sets an icon in this skin's icon map from a file address. + * Throws IO exception for debugging if needed. + * + * @param s0 + *   Skin property (from enum) + * @param s1 + *   File address + */ + private static void setIcon(final SkinProp s0, final String s1) { + try { + final File file = new File(s1); + ImageIO.read(file); + } catch (final IOException e) { + e.printStackTrace(); + } + setIcon(s0, new ImageIcon(s1)); + } + + /** + * Sets an icon in this skin's icon map from a buffered image. + * + * @param s0   Skin property (from enum) + * @param bi0   BufferedImage + */ + private static void setIcon(final SkinProp s0, final BufferedImage bi0) { + setIcon(s0, new ImageIcon(bi0)); + } + + private SkinIcon(ImageIcon imageIcon0) { + super(imageIcon0.getImage()); + this.imageIcon = imageIcon0; + } + + @Override + protected SkinIcon clone() { + return new SkinIcon(this.imageIcon); + } + + @Override + public SkinIcon resize(int w, int h) { + return (SkinIcon)super.resize(w, h); + } + + @Override + public SkinIcon scale(double scale) { + return scale(scale, scale); + } + @Override + public SkinIcon scale(double scaleX, double scaleY) { + return (SkinIcon)super.scale(scaleX, scaleY); + } + + @Override + protected void createResizedImage(SkinImage baseImage, int w, int h) { + Image image0 = baseImage.image.getScaledInstance(w, h, java.awt.Image.SCALE_SMOOTH); + this.changeImage(image0, new ImageIcon(image0)); + } + + @Override + protected int getWidth() { + return this.imageIcon.getIconWidth(); + } + + @Override + protected int getHeight() { + return this.imageIcon.getIconHeight(); + } + + @Override + protected ImageIcon getIcon() { //can skip null check since imageIcon will always be set + return this.imageIcon; + } + } + + //allow creating dynamic icons that can be used in place of skin icons + public static class UnskinnedIcon extends SkinIcon { + public UnskinnedIcon(String path0) { + super(new ImageIcon(path0)); + } + public UnskinnedIcon(BufferedImage i0) { + super(new ImageIcon(i0)); + } + + @Override + public ImageIcon getIcon() { + return super.getIcon(); + } } /** int[] can hold [xcoord, ycoord, width, height, newwidth, newheight]. */ @@ -402,15 +1402,104 @@ public enum FSkin { int[] getCoords(); } - private static Map icons; - private static Map images; - private static Map colors; + private static Map avatars; + private static Map fixedFonts = new HashMap(); + + /** @return {@link java.awt.font} */ + public static Font getFixedFont(final int size) { + Font fixedFont = fixedFonts.get(size); + if (fixedFont == null) { + fixedFont = new Font("Monospaced", Font.PLAIN, size); + fixedFonts.put(size, fixedFont); + } + return fixedFont; + } - private static Map fixedFonts; - private static Map plainFonts; - private static Map boldFonts; - private static Map italicFonts; - private static Map avatars; + /** + * @return {@link forge.gui.toolbox.FSkin.SkinFont} + */ + public static SkinFont getFont() { + return FSkin.getFont(FSkin.defaultFontSize); + } + + /** + * @param size - integer, pixel size + * @return {@link forge.gui.toolbox.FSkin.SkinFont} + */ + public static SkinFont getFont(final int size) { + return SkinFont.get(Font.PLAIN, size); + } + + /** + * @return {@link forge.gui.toolbox.FSkin.SkinFont} + */ + public static SkinFont getBoldFont() { + return FSkin.getBoldFont(FSkin.defaultFontSize); + } + + /** + * @param size - integer, pixel size + * @return {@link forge.gui.toolbox.FSkin.SkinFont} + */ + public static SkinFont getBoldFont(final int size) { + return SkinFont.get(Font.BOLD, size); + } + + /** + * @return {@link forge.gui.toolbox.FSkin.SkinFont} + */ + public static SkinFont getItalicFont() { + return FSkin.getItalicFont(FSkin.defaultFontSize); + } + + /** + * @param size - integer, pixel size + * @return {@link forge.gui.toolbox.FSkin.SkinFont} + */ + public static SkinFont getItalicFont(final int size) { + return SkinFont.get(Font.ITALIC, size); + } + + public static class SkinFont { + private static Font baseFont; + private static Map fonts = new HashMap(); + + private static SkinFont get(final int style0, final int size0) { + String key = style0 + "|" + size0; + SkinFont skinFont = fonts.get(key); + if (skinFont == null) { + skinFont = new SkinFont(style0, size0); + fonts.put(key, skinFont); + } + return skinFont; + } + + private static void setBaseFont(Font baseFont0) { + baseFont = baseFont0; + + //update all cached skin fonts + for (SkinFont skinFont : fonts.values()) { + skinFont.updateFont(); + } + } + + private final int style, size; + private Font font; + + private SkinFont(final int style0, final int size0) { + this.style = style0; + this.size = size0; + this.updateFont(); + } + + public int getSize() { + return this.font.getSize(); + } + + private void updateFont() { + this.font = baseFont.deriveFont(this.style, this.size); + } + } private static final String FILE_SKINS_DIR = "res/skins/", @@ -426,13 +1515,38 @@ public enum FSkin { private static String preferredDir; private static String preferredName; - private static Font font; private static BufferedImage bimDefaultSprite, bimPreferredSprite, bimFoils, bimOldFoils, bimDefaultAvatars, bimPreferredAvatars; private static int x0, y0, w0, h0, newW, newH, preferredW, preferredH; private static int[] tempCoords; private static int defaultFontSize = 12; private static boolean loaded = false; + + @SuppressWarnings("rawtypes") + public static void changeSkin(final String skinName) { + final ForgePreferences prefs = Singletons.getModel().getPreferences(); + if (skinName.equals(prefs.getPref(FPref.UI_SKIN))) { return; } + + //save skin preference + prefs.setPref(FPref.UI_SKIN, skinName); + prefs.save(); + + //load skin + loaded = false; //reset this temporarily until end of loadFull() + loadLight(skinName, false); + loadFull(false); + + //reapply skin to all skinned components + for (ComponentSkin compSkin : compSkins.values()) { + compSkin.reapply(); + } + + //refresh certain components skinned via look and feel + Singletons.getControl().getMenuBar().refresh(); + FComboBoxWrapper.refreshAllSkins(); + FComboBoxPanel.refreshAllSkins(); + CSubmenuPreferences.SINGLETON_INSTANCE.updateCurrentSkin(); + } /** * Loads a "light" version of FSkin, just enough for the splash screen: @@ -442,66 +1556,42 @@ public enum FSkin { * @param skinName * the skin name */ - public static void loadLight(final String skinName) { - // No need for this method to be loaded while on the EDT. - FThreads.assertExecutedByEdt(false); + public static void loadLight(final String skinName, final boolean onInit) { + if (onInit) { + // No need for this method to be loaded while on the EDT. + FThreads.assertExecutedByEdt(false); + } // Non-default (preferred) skin name and dir. FSkin.preferredName = skinName.toLowerCase().replace(' ', '_'); FSkin.preferredDir = FILE_SKINS_DIR + preferredName + "/"; - if (FSkin.icons != null) { FSkin.icons.clear(); } - if (FSkin.images != null) { FSkin.images.clear(); } - if (FSkin.colors != null) { FSkin.colors.clear(); } - - FSkin.icons = new HashMap(); - FSkin.images = new HashMap(); - FSkin.colors = new HashMap(); - - final File f = new File(preferredDir + FILE_SPLASH); - if (!f.exists()) { - FSkin.loadLight("default"); - } - else { - final BufferedImage img; - try { - img = ImageIO.read(f); - - final int h = img.getHeight(); - final int w = img.getWidth(); - - FSkin.setIcon(Backgrounds.BG_SPLASH, img.getSubimage(0, 0, w, h - 100)); - - UIManager.put("ProgressBar.background", FSkin.getColorFromPixel(img.getRGB(25, h - 75))); - UIManager.put("ProgressBar.selectionBackground", FSkin.getColorFromPixel(img.getRGB(75, h - 75))); - UIManager.put("ProgressBar.foreground", FSkin.getColorFromPixel(img.getRGB(25, h - 25))); - UIManager.put("ProgressBar.selectionForeground", FSkin.getColorFromPixel(img.getRGB(75, h - 25))); - UIManager.put("ProgressBar.border", new LineBorder(Color.BLACK, 0)); - } catch (final IOException e) { - e.printStackTrace(); + if (onInit) { + final File f = new File(preferredDir + FILE_SPLASH); + if (!f.exists()) { + FSkin.loadLight("default", onInit); } - } - loaded = true; - } + else { + final BufferedImage img; + try { + img = ImageIO.read(f); - public static void setProgessBarMessage(final String message) { - setProgessBarMessage(message, 0); - } - public static void setProgessBarMessage(final String message, final int cnt) { - final FProgressBar barProgress = FView.SINGLETON_INSTANCE.getSplash().getProgressBar(); - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - if ( cnt > 0 ) { - barProgress.reset(); - barProgress.setMaximum(cnt); + final int h = img.getHeight(); + final int w = img.getWidth(); + + SkinIcon.setIcon(Backgrounds.BG_SPLASH, img.getSubimage(0, 0, w, h - 100)); + + UIManager.put("ProgressBar.background", FSkin.getColorFromPixel(img.getRGB(25, h - 75))); + UIManager.put("ProgressBar.selectionBackground", FSkin.getColorFromPixel(img.getRGB(75, h - 75))); + UIManager.put("ProgressBar.foreground", FSkin.getColorFromPixel(img.getRGB(25, h - 25))); + UIManager.put("ProgressBar.selectionForeground", FSkin.getColorFromPixel(img.getRGB(75, h - 25))); + UIManager.put("ProgressBar.border", new LineBorder(Color.BLACK, 0)); + } catch (final IOException e) { + e.printStackTrace(); } - barProgress.setShowETA(false); - barProgress.setShowCount(cnt > 0); - barProgress.setDescription(message); - } - }); + loaded = true; + } } /** @@ -523,19 +1613,17 @@ public enum FSkin { * preferred takes precedence over default, but if something is * missing, the default picture is retrieved. */ - public static void loadFull() { - // No need for this method to be loaded while on the EDT. - FThreads.assertExecutedByEdt(false); + public static void loadFull(final boolean onInit) { + if (onInit) { + // No need for this method to be loaded while on the EDT. + FThreads.assertExecutedByEdt(false); - // Preferred skin name must be called via loadLight() method, - // which does some cleanup and init work. - if (FSkin.preferredName.isEmpty()) { FSkin.loadLight("default"); } - - // Everything OK? - - final FProgressBar barProgress = FView.SINGLETON_INSTANCE.getSplash().getProgressBar(); - setProgessBarMessage("Processing image sprites: ", 5); + // Preferred skin name must be called via loadLight() method, + // which does some cleanup and init work. + if (FSkin.preferredName.isEmpty()) { FSkin.loadLight("default", onInit); } + } + FView.SINGLETON_INSTANCE.setSplashProgessBarMessage("Processing image sprites: ", 5); // Grab and test various sprite files. final File f1 = new File(DEFAULT_DIR + FILE_ICON_SPRITE); @@ -547,18 +1635,18 @@ public enum FSkin { try { bimDefaultSprite = ImageIO.read(f1); - barProgress.increment(); + FView.SINGLETON_INSTANCE.incrementSplashProgessBar(); bimPreferredSprite = ImageIO.read(f2); - barProgress.increment(); + FView.SINGLETON_INSTANCE.incrementSplashProgessBar(); bimFoils = ImageIO.read(f3); - barProgress.increment(); + FView.SINGLETON_INSTANCE.incrementSplashProgessBar(); bimOldFoils = f6.exists() ? ImageIO.read(f6) : ImageIO.read(f3); - barProgress.increment(); + FView.SINGLETON_INSTANCE.incrementSplashProgessBar(); bimDefaultAvatars = ImageIO.read(f4); if (f5.exists()) { bimPreferredAvatars = ImageIO.read(f5); } - barProgress.increment(); + FView.SINGLETON_INSTANCE.incrementSplashProgessBar(); preferredH = bimPreferredSprite.getHeight(); preferredW = bimPreferredSprite.getWidth(); @@ -569,36 +1657,33 @@ public enum FSkin { e.printStackTrace(); } - // Pre-derive most fonts (plain, bold, and italic). - // Exceptions handled inside method. - FSkin.setDefaultFontSize(); - FSkin.font = GuiUtils.newFont(FILE_SKINS_DIR + preferredName + "/" + FILE_FONT); - fixedFonts = new HashMap(); - plainFonts = new HashMap(); - boldFonts = new HashMap(); - italicFonts = new HashMap(); - for (int i = 10; i <= 22; i++) { setFont(i); } - for (int i = 10; i <= 20; i += 2) { setBoldFont(i); } - for (int i = 12; i <= 14; i += 2) { setItalicFont(i); } + // Initialize fonts + if (onInit) { //set default font size only once onInit + Font f = UIManager.getDefaults().getFont("Label.font"); + if (f != null) { + FSkin.defaultFontSize = f.getSize(); + } + } + SkinFont.setBaseFont(GuiUtils.newFont(FILE_SKINS_DIR + preferredName + "/" + FILE_FONT)); // Put various images into map (except sprite and splash). // Exceptions handled inside method. - FSkin.setIcon(Backgrounds.BG_TEXTURE, preferredDir + FILE_TEXTURE_BG); - FSkin.setIcon(Backgrounds.BG_MATCH, preferredDir + FILE_MATCH_BG); + SkinIcon.setIcon(Backgrounds.BG_TEXTURE, preferredDir + FILE_TEXTURE_BG); + SkinIcon.setIcon(Backgrounds.BG_MATCH, preferredDir + FILE_MATCH_BG); // Run through enums and load their coords. - for (final Colors e : Colors.values()) { FSkin.setColor(e); } - for (final ZoneImages e : ZoneImages.values()) { FSkin.setImage(e); } - for (final DockIcons e : DockIcons.values()) { FSkin.setIcon(e); } - for (final InterfaceIcons e : InterfaceIcons.values()) { FSkin.setIcon(e); } - for (final ButtonImages e : ButtonImages.values()) { FSkin.setIcon(e); } - for (final QuestIcons e : QuestIcons.values()) { FSkin.setIcon(e); } + Colors.updateAll(); + for (final ZoneImages e : ZoneImages.values()) { SkinImage.setImage(e); } + for (final DockIcons e : DockIcons.values()) { SkinIcon.setIcon(e); } + for (final InterfaceIcons e : InterfaceIcons.values()) { SkinIcon.setIcon(e); } + for (final ButtonImages e : ButtonImages.values()) { SkinIcon.setIcon(e); } + for (final QuestIcons e : QuestIcons.values()) { SkinIcon.setIcon(e); } - for (final EditorImages e : EditorImages.values()) { FSkin.setImage(e); } - for (final ManaImages e : ManaImages.values()) { FSkin.setImage(e); } - for (final ColorlessManaImages e : ColorlessManaImages.values()) { FSkin.setImage(e); } - for (final GameplayImages e : GameplayImages.values()) { FSkin.setImage(e); } - for (final LayoutImages e : LayoutImages.values()) { FSkin.setImage(e); } + for (final EditorImages e : EditorImages.values()) { SkinImage.setImage(e); } + for (final ManaImages e : ManaImages.values()) { SkinImage.setImage(e); } + for (final ColorlessManaImages e : ColorlessManaImages.values()) { SkinImage.setImage(e); } + for (final GameplayImages e : GameplayImages.values()) { SkinImage.setImage(e); } + for (final LayoutImages e : LayoutImages.values()) { SkinImage.setImage(e); } // Foils have a separate sprite, so uses a specific method. for (final Foils e : Foils.values()) { FSkin.setFoil(e, false); } @@ -611,7 +1696,7 @@ public enum FSkin { UIManager.put("Table.alternateRowColor", new Color(240, 240, 240)); // Images loaded; can start UI init. - setProgessBarMessage("Creating display components."); + FView.SINGLETON_INSTANCE.setSplashProgessBarMessage("Creating display components."); loaded = true; // Clear references to buffered images @@ -629,66 +1714,11 @@ public enum FSkin { FSkin.bimPreferredSprite = null; FSkin.bimDefaultAvatars = null; FSkin.bimPreferredAvatars = null; - } - - private static void setDefaultFontSize() { - Font f = UIManager.getDefaults().getFont("Label.font"); - if (f != null) { - FSkin.defaultFontSize = f.getSize(); - } - } - /** @return {@link java.awt.font} font */ - public static Font getFont() { - return FSkin.getFont(FSkin.defaultFontSize); - } - - /** - * @param size - integer, pixel size - * @return {@link java.awt.font} font1 - */ - public static Font getFont(final int size) { - if (plainFonts.get(size) == null) { - plainFonts.put(size, getFont().deriveFont(Font.PLAIN, size)); - } - return plainFonts.get(size); - } - - public static Font getFixedFont(final int size) { - if (fixedFonts.get(size) == null) { - fixedFonts.put(size, new Font("Monospaced", Font.PLAIN, size)); - } - return fixedFonts.get(size); - } - - public static Font getBoldFont() { - return FSkin.getBoldFont(FSkin.defaultFontSize); - } - - /** - * @param size - integer, pixel size - * @return {@link java.awt.font} font1 - */ - public static Font getBoldFont(final int size) { - if (boldFonts.get(size) == null) { - boldFonts.put(size, getFont().deriveFont(Font.BOLD, size)); - } - return boldFonts.get(size); - } - - public static Font getItalicFont() { - return FSkin.getItalicFont(FSkin.defaultFontSize); - } - - /** - * @param size - integer, pixel size - * @return {@link java.awt.font} font1 - */ - public static Font getItalicFont(final int size) { - if (boldFonts.get(size) == null) { - italicFonts.put(size, getFont().deriveFont(Font.ITALIC, size)); - } - return italicFonts.get(size); + // Set look and feel after skin loaded + FView.SINGLETON_INSTANCE.setSplashProgessBarMessage("Setting look and feel..."); + ForgeLookAndFeel laf = new ForgeLookAndFeel(); + laf.setForgeLookAndFeel(Singletons.getView().getFrame()); } /** @@ -700,69 +1730,6 @@ public enum FSkin { return FSkin.preferredName; } - /** - * Gets an image. - * - * @param s0   SkinProp enum - * @return {@link java.awt.Image} - */ - public static Image getImage(final SkinProp s0) { - if (FSkin.images.get(s0) == null) { - throw new NullPointerException("Can't find an image for SkinProp " + s0); - } - return FSkin.images.get(s0); - } - - /** - * Gets an icon. - * - * @param s0   SkinProp enum - * @return {@link javax.swing.ImageIcon} - */ - public static ImageIcon getIcon(final SkinProp s0) { - if (FSkin.icons.get(s0) == null) { - throw new NullPointerException("Can't find an icon for SkinProp " + s0); - } - return FSkin.icons.get(s0); - } - - /** - * Gets a scaled version of an image from this skin's image map. - * - * @param s0 - * String image enum - * @param w0 - * int new width - * @param h0 - * int new height - * @return {@link java.awt.Image} - */ - public static Image getImage(final SkinProp s0, int w0, int h0) { - w0 = (w0 < 1) ? 1 : w0; - h0 = (h0 < 1) ? 1 : h0; - - final Image original = FSkin.images.get(s0); - - final BufferedImage scaled = new BufferedImage(w0, h0, BufferedImage.TYPE_INT_ARGB); - - final Graphics2D g2d = scaled.createGraphics(); - g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); - g2d.drawImage(original, 0, 0, w0, h0, 0, 0, original.getWidth(null), original.getHeight(null), null); - g2d.dispose(); - - return scaled; - } - - /** - * Retrieves a color from this skin's color map. - * - * @param s0   Skin property (from enum) - * @return Color - */ - public static Color getColor(final SkinProp s0) { - return colors.get(s0); - } - /** * Gets the skins. * @@ -799,51 +1766,12 @@ public enum FSkin { } /** @return Map */ - public static Map getAvatars() { + public static Map getAvatars() { return avatars; } - - /** Steps RGB components of a color up or down. - * Returns opaque (non-alpha) stepped color. - * Plus for lighter, minus for darker. - * - * @param clr0 {@link java.awt.Color} - * @param step int - * @return {@link java.awt.Color} - */ - public static Color stepColor(Color clr0, int step) { - int r = clr0.getRed(); - int g = clr0.getGreen(); - int b = clr0.getBlue(); - - // Darker - if (step < 0) { - r = ((r + step > 0) ? r + step : 0); - g = ((g + step > 0) ? g + step : 0); - b = ((b + step > 0) ? b + step : 0); - } - else { - r = ((r + step < 255) ? r + step : 255); - g = ((g + step < 255) ? g + step : 255); - b = ((b + step < 255) ? b + step : 255); - } - - return new Color(r, g, b); - } public static boolean isLoaded() { return loaded; } - /** Returns RGB components of a color, with a new - * value for alpha. 0 = transparent, 255 = opaque. - * - * @param clr0 {@link java.awt.Color} - * @param alpha int - * @return {@link java.awt.Color} - */ - public static Color alphaColor(Color clr0, int alpha) { - return new Color(clr0.getRed(), clr0.getGreen(), clr0.getBlue(), alpha); - } - /** *

* getColorFromPixel. @@ -906,7 +1834,7 @@ public enum FSkin { } private static void assembleAvatars() { - FSkin.avatars = new HashMap(); + FSkin.avatars = new HashMap(); int counter = 0; Color pxTest; @@ -919,7 +1847,7 @@ public enum FSkin { if (i == 0 && j == 0) { continue; } pxTest = FSkin.getColorFromPixel(bimPreferredAvatars.getRGB(i + 50, j + 50)); if (pxTest.getAlpha() == 0) { continue; } - FSkin.avatars.put(counter++, bimPreferredAvatars.getSubimage(i, j, 100, 100)); + FSkin.avatars.put(counter++, new SkinImage(bimPreferredAvatars.getSubimage(i, j, 100, 100))); } } } @@ -932,7 +1860,7 @@ public enum FSkin { if (i == 0 && j == 0) { continue; } pxTest = FSkin.getColorFromPixel(bimDefaultAvatars.getRGB(i + 50, j + 50)); if (pxTest.getAlpha() == 0) { continue; } - FSkin.avatars.put(counter++, bimDefaultAvatars.getSubimage(i, j, 100, 100)); + FSkin.avatars.put(counter++, new SkinImage(bimDefaultAvatars.getSubimage(i, j, 100, 100))); } } } @@ -944,107 +1872,164 @@ public enum FSkin { w0 = tempCoords[2]; h0 = tempCoords[3]; - FSkin.images.put(s0, isOldStyle ? bimOldFoils.getSubimage(x0, y0, w0, h0) : bimFoils.getSubimage(x0, y0, w0, h0)); + SkinImage.setImage(s0, isOldStyle ? bimOldFoils.getSubimage(x0, y0, w0, h0) : bimFoils.getSubimage(x0, y0, w0, h0)); } - - private static void setColor(final SkinProp s0) { - tempCoords = s0.getCoords(); - x0 = tempCoords[0]; - y0 = tempCoords[1]; - - FSkin.colors.put(s0, FSkin.getColorFromPixel(bimPreferredSprite.getRGB(x0, y0))); + + public static boolean isLookAndFeelSet() { + return ForgeLookAndFeel.isMetalLafSet; } - - private static void setFont(final int size) { - plainFonts.put(size, font.deriveFont(Font.PLAIN, size)); - } - - private static void setBoldFont(final int size) { - boldFonts.put(size, font.deriveFont(Font.BOLD, size)); - } - - private static void setItalicFont(final int size) { - italicFonts.put(size, FSkin.font.deriveFont(Font.ITALIC, size)); - } - - private static void setIcon(final SkinProp s0) { - tempCoords = s0.getCoords(); - x0 = tempCoords[0]; - y0 = tempCoords[1]; - w0 = tempCoords[2]; - h0 = tempCoords[3]; - - final BufferedImage img = testPreferredSprite(s0); - - FSkin.icons.put(s0, new ImageIcon(img.getSubimage(x0, y0, w0, h0))); - } - - /** - * Sets an icon in this skin's icon map from a file address. - * Throws IO exception for debugging if needed. - * - * @param s0 - *   Skin property (from enum) - * @param s1 - *   File address + + /** + * Sets the look and feel of the GUI based on the selected Forge theme. + * + * @see UIManager Defaults */ - private static void setIcon(final SkinProp s0, final String s1) { - try { - final File file = new File(s1); - ImageIO.read(file); - } catch (final IOException e) { - e.printStackTrace(); + private static class ForgeLookAndFeel { //needs to live in FSkin for access to skin colors + + private static boolean onInit = true; + private static boolean isMetalLafSet = false; + + private final Color FORE_COLOR = FSkin.getColor(FSkin.Colors.CLR_TEXT).color; + private final Color BACK_COLOR = FSkin.getColor(FSkin.Colors.CLR_THEME2).color; + private final Color HIGHLIGHT_COLOR = BACK_COLOR.brighter(); + private final Border LINE_BORDER = BorderFactory.createLineBorder(FORE_COLOR.darker(), 1); + private final Border EMPTY_BORDER = BorderFactory.createEmptyBorder(2, 2, 2, 2); + + /** + * Sets the look and feel of the GUI based on the selected Forge theme. + */ + private void setForgeLookAndFeel(final JFrame appFrame) { + if (isUIManagerEnabled()) { + if (setMetalLookAndFeel(appFrame)) { + setMenusLookAndFeel(); + setComboBoxLookAndFeel(); + setTabbedPaneLookAndFeel(); + setButtonLookAndFeel(); + } + } + onInit = false; } - FSkin.icons.put(s0, new ImageIcon(s1)); - } - - /** - * Sets an icon in this skin's icon map from a buffered image. - * - * @param s0   Skin property (from enum) - * @param bi0   BufferedImage - */ - private static void setIcon(final SkinProp s0, final BufferedImage bi0) { - FSkin.icons.put(s0, new ImageIcon(bi0)); - } - - /** - * setImage, with auto-scaling assumed true. - * - * @param s0 - */ - private static void setImage(final SkinProp s0) { - FSkin.setImage(s0, true); - } - - /** - * Checks the preferred sprite for existence of a sub-image - * defined by X, Y, W, H. - * - * If an image is not present at those coordinates, default - * icon is substituted. - * - * The result is saved in a HashMap. - * - * @param s0   An address in the hashmap, derived from SkinProp enum - */ - private static void setImage(final SkinProp s0, final boolean scale) { - tempCoords = s0.getCoords(); - x0 = tempCoords[0]; - y0 = tempCoords[1]; - w0 = tempCoords[2]; - h0 = tempCoords[3]; - newW = (tempCoords.length == 6 ? tempCoords[4] : 0); - newH = (tempCoords.length == 6 ? tempCoords[5] : 0); - - final BufferedImage img = FSkin.testPreferredSprite(s0); - final BufferedImage bi0 = img.getSubimage(x0, y0, w0, h0); - - if (scale && newW != 0) { - FSkin.images.put(s0, bi0.getScaledInstance(newW, newH, Image.SCALE_AREA_AVERAGING)); + + /** + * Sets the standard "Java L&F" (also called "Metal") that looks the same on all platforms. + *

+ * If not explicitly set then the Mac uses its native L&F which does + * not support various settings (eg. combobox background color). + */ + private boolean setMetalLookAndFeel(JFrame appFrame) { + if (onInit) { //only attempt to set Metal Look and Feel the first time + try { + UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel"); + SwingUtilities.updateComponentTreeUI(appFrame); + isMetalLafSet = true; + } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) { + // Auto-generated catch block ignores the exception, but sends it to System.err and probably forge.log. + e.printStackTrace(); + } + } + return isMetalLafSet; } - else { - FSkin.images.put(s0, bi0); + + /** + * Sets the look and feel for a JMenuBar, JMenu, JMenuItem & variations. + */ + private void setMenusLookAndFeel() { + // JMenuBar + Color clrTheme = FSkin.getColor(FSkin.Colors.CLR_THEME).color; + Color backgroundColor = FSkin.stepColor(clrTheme, 0); + Color menuBarEdgeColor = FSkin.stepColor(clrTheme, -80); + UIManager.put("MenuBar.foreground", FORE_COLOR); + UIManager.put("MenuBar.gradient", getColorGradients(backgroundColor.darker(), backgroundColor)); + UIManager.put("MenuBar.border", BorderFactory.createMatteBorder(0, 0, 1, 0, menuBarEdgeColor)); + // JMenu + UIManager.put("Menu.foreground", FORE_COLOR); + UIManager.put("Menu.background", BACK_COLOR); + UIManager.put("Menu.borderPainted", false); + UIManager.put("Menu.selectionBackground", HIGHLIGHT_COLOR); + UIManager.put("Menu.selectionForeground", FORE_COLOR); + UIManager.put("Menu.border", EMPTY_BORDER); + UIManager.put("Menu.opaque", false); + // JPopupMenu + UIManager.put("PopupMenu.border", LINE_BORDER); + UIManager.put("PopupMenu.background", BACK_COLOR); + UIManager.put("PopupMenu.foreground", FORE_COLOR); + // JMenuItem + UIManager.put("MenuItem.foreground", FORE_COLOR); + UIManager.put("MenuItem.background", BACK_COLOR); + UIManager.put("MenuItem.border", EMPTY_BORDER); + UIManager.put("MenuItem.selectionBackground", HIGHLIGHT_COLOR); + UIManager.put("MenuItem.selectionForeground", FORE_COLOR); + UIManager.put("MenuItem.acceleratorForeground", FORE_COLOR.darker()); + UIManager.put("MenuItem.opaque", true); + // JSeparator (needs to be opaque!). + UIManager.put("Separator.foreground", FORE_COLOR.darker()); + UIManager.put("Separator.background", BACK_COLOR); + // JRadioButtonMenuItem + UIManager.put("RadioButtonMenuItem.foreground", FORE_COLOR); + UIManager.put("RadioButtonMenuItem.background", BACK_COLOR); + UIManager.put("RadioButtonMenuItem.selectionBackground", HIGHLIGHT_COLOR); + UIManager.put("RadioButtonMenuItem.selectionForeground", FORE_COLOR); + UIManager.put("RadioButtonMenuItem.border", EMPTY_BORDER); + UIManager.put("RadioButtonMenuItem.acceleratorForeground", FORE_COLOR.darker()); + // JCheckboxMenuItem + UIManager.put("CheckBoxMenuItem.foreground", FORE_COLOR); + UIManager.put("CheckBoxMenuItem.background", BACK_COLOR); + UIManager.put("CheckBoxMenuItem.selectionBackground", HIGHLIGHT_COLOR); + UIManager.put("CheckBoxMenuItem.selectionForeground", FORE_COLOR); + UIManager.put("CheckBoxMenuItem.border", EMPTY_BORDER); + UIManager.put("CheckBoxMenuItem.acceleratorForeground", FORE_COLOR.darker()); + } + + private void setTabbedPaneLookAndFeel() { + UIManager.put("TabbedPane.selected", HIGHLIGHT_COLOR); + UIManager.put("TabbedPane.contentOpaque", FSkin.getColor(FSkin.Colors.CLR_THEME)); + UIManager.put("TabbedPane.unselectedBackground", BACK_COLOR); + } + + /** + * Sets the look and feel for a non-editable JComboBox. + */ + private void setComboBoxLookAndFeel() { + UIManager.put("ComboBox.background", BACK_COLOR); + UIManager.put("ComboBox.foreground", FORE_COLOR); + UIManager.put("ComboBox.selectionBackground", HIGHLIGHT_COLOR); + UIManager.put("ComboBox.selectionForeground", FORE_COLOR); + UIManager.put("ComboBox.disabledBackground", BACK_COLOR); + UIManager.put("ComboBox.disabledForeground", BACK_COLOR.darker()); + UIManager.put("ComboBox.font", getDefaultFont("ComboBox.font")); + UIManager.put("Button.select", HIGHLIGHT_COLOR); + } + + private void setButtonLookAndFeel() { + UIManager.put("Button.foreground", FORE_COLOR); + UIManager.put("Button.background", BACK_COLOR); + UIManager.put("Button.select", HIGHLIGHT_COLOR); + UIManager.put("Button.focus", FORE_COLOR.darker()); + UIManager.put("Button.rollover", false); + } + + /** + * Determines whether theme styles should be applied to GUI. + *

+ * TODO: Currently is using UI_THEMED_COMBOBOX setting but will + * eventually want to rename for clarity. + */ + private boolean isUIManagerEnabled() { + return Singletons.getModel().getPreferences().getPrefBoolean(FPref.UI_THEMED_COMBOBOX); + } + + private Font getDefaultFont(String component) { + return FSkin.getFont(UIManager.getFont(component).getSize()).font; + } + + private ArrayList getColorGradients(Color bottom, Color top) { + ArrayList gradients = new ArrayList<>(); + gradients.add(0.0); + gradients.add(0.0); + gradients.add(top); + gradients.add(bottom); + gradients.add(bottom); + return gradients; } } } diff --git a/src/main/java/forge/gui/toolbox/FSpinner.java b/src/main/java/forge/gui/toolbox/FSpinner.java index 177dc439820..df2c142b8e3 100644 --- a/src/main/java/forge/gui/toolbox/FSpinner.java +++ b/src/main/java/forge/gui/toolbox/FSpinner.java @@ -37,9 +37,10 @@ public class FSpinner extends JSpinner { this.setEditor(new JSpinner.NumberEditor(this, "##")); JFormattedTextField txt = ((JSpinner.NumberEditor)this.getEditor()).getTextField(); ((NumberFormatter)txt.getFormatter()).setAllowsInvalid(false); - txt.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); - txt.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); - txt.setCaretColor(FSkin.getColor(FSkin.Colors.CLR_TEXT)); + FSkin.JTextComponentSkin txtSkin = FSkin.get(txt); + txtSkin.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); + txtSkin.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); + txtSkin.setCaretColor(FSkin.getColor(FSkin.Colors.CLR_TEXT)); txt.setMargin(new Insets(5, 5, 5, 5)); txt.setOpaque(true); diff --git a/src/main/java/forge/gui/toolbox/FTabbedPane.java b/src/main/java/forge/gui/toolbox/FTabbedPane.java index a881b3bbc5b..4db08be9082 100644 --- a/src/main/java/forge/gui/toolbox/FTabbedPane.java +++ b/src/main/java/forge/gui/toolbox/FTabbedPane.java @@ -11,7 +11,8 @@ public class FTabbedPane extends JTabbedPane { private static final long serialVersionUID = 2207172560817790885L; public FTabbedPane() { - this.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME)); - this.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); + FSkin.JComponentSkin skin = FSkin.get(this); + skin.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME)); + skin.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); } } diff --git a/src/main/java/forge/gui/toolbox/FTextArea.java b/src/main/java/forge/gui/toolbox/FTextArea.java index 22ff4696920..5c480cc3782 100644 --- a/src/main/java/forge/gui/toolbox/FTextArea.java +++ b/src/main/java/forge/gui/toolbox/FTextArea.java @@ -11,8 +11,9 @@ public class FTextArea extends JTextArea { /** */ public FTextArea() { super(); - this.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); - this.setCaretColor(FSkin.getColor(FSkin.Colors.CLR_TEXT)); + FSkin.JTextComponentSkin skin = FSkin.get(this); + skin.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); + skin.setCaretColor(FSkin.getColor(FSkin.Colors.CLR_TEXT)); this.setOpaque(false); this.setWrapStyleWord(true); this.setLineWrap(true); diff --git a/src/main/java/forge/gui/toolbox/FTextField.java b/src/main/java/forge/gui/toolbox/FTextField.java index d99a5e926eb..2c943240dfd 100644 --- a/src/main/java/forge/gui/toolbox/FTextField.java +++ b/src/main/java/forge/gui/toolbox/FTextField.java @@ -49,14 +49,16 @@ public class FTextField extends JTextField { } public static final int HEIGHT = 25; //TODO: calculate this somehow instead of hard-coding it - + + private final FSkin.JTextComponentSkin skin; private String ghostText; private boolean showGhostTextWithFocus; private FTextField(Builder builder) { - this.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); - this.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); - this.setCaretColor(FSkin.getColor(FSkin.Colors.CLR_TEXT)); + skin = FSkin.get(this); + skin.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); + skin.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); + skin.setCaretColor(FSkin.getColor(FSkin.Colors.CLR_TEXT)); this.setMargin(new Insets(3, 3, 2, 3)); this.setOpaque(true); @@ -115,7 +117,7 @@ public class FTextField extends JTextField { final Insets margin = this.getMargin(); final Graphics2D g2d = (Graphics2D)g.create(); g2d.setFont(this.getFont()); - g2d.setColor(FSkin.stepColor(this.getForeground(), 20)); + skin.setGraphicsColor(g2d, skin.getForeground().stepColor(20)); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.drawString(this.ghostText, margin.left + 2, margin.top + 15); //account for borders (TODO: why +15?) g2d.dispose(); diff --git a/src/main/java/forge/gui/toolbox/imaging/FImageUtil.java b/src/main/java/forge/gui/toolbox/imaging/FImageUtil.java index 55920772d13..250d7f20747 100644 --- a/src/main/java/forge/gui/toolbox/imaging/FImageUtil.java +++ b/src/main/java/forge/gui/toolbox/imaging/FImageUtil.java @@ -25,6 +25,7 @@ import forge.Card; import forge.CardCharacteristicName; import forge.ImageCache; import forge.gui.toolbox.CardFaceSymbols; +import forge.gui.toolbox.FSkin.ComponentSkin; /** * Common image-related routines specific to Forge images. @@ -35,11 +36,11 @@ import forge.gui.toolbox.CardFaceSymbols; public final class FImageUtil { private FImageUtil() {} - public static BufferedImage getImage(Card card, CardCharacteristicName state) { + public static BufferedImage getImage(Card card, CardCharacteristicName state, ComponentSkin skin) { BufferedImage image = ImageCache.getOriginalImage(card.getImageKey(state), true); int foilIndex = card.getFoil(); if (image != null && foilIndex > 0) { - image = getImageWithFoilEffect(image, foilIndex); + image = getImageWithFoilEffect(image, foilIndex, skin); } return image; } @@ -52,11 +53,11 @@ public final class FImageUtil { * For double-sided cards, returns the front-side image.
* For flip cards, returns the un-flipped image. */ - public static BufferedImage getImage(Card card) { + public static BufferedImage getImage(Card card, ComponentSkin skin) { BufferedImage image = ImageCache.getOriginalImage(card.getImageKey(), true); int foilIndex = card.getFoil(); if (image != null && foilIndex > 0) { - image = getImageWithFoilEffect(image, foilIndex); + image = getImageWithFoilEffect(image, foilIndex, skin); } return image; } @@ -64,11 +65,11 @@ public final class FImageUtil { /** * Applies a foil effect to a card image. */ - private static BufferedImage getImageWithFoilEffect(BufferedImage plainImage, int foilIndex) { + private static BufferedImage getImageWithFoilEffect(BufferedImage plainImage, int foilIndex, ComponentSkin skin) { ColorModel cm = plainImage.getColorModel(); BufferedImage foilImage = new BufferedImage(cm, plainImage.copyData(null), cm.isAlphaPremultiplied(), null); final String fl = String.format("foil%02d", foilIndex); - CardFaceSymbols.drawOther(foilImage.getGraphics(), fl, 0, 0, foilImage.getWidth(), foilImage.getHeight()); + CardFaceSymbols.drawOther(skin, foilImage.getGraphics(), fl, 0, 0, foilImage.getWidth(), foilImage.getHeight()); return foilImage; } } diff --git a/src/main/java/forge/gui/toolbox/imaging/ImageUtil.java b/src/main/java/forge/gui/toolbox/imaging/ImageUtil.java index a943521e6fc..3fda5b2a354 100644 --- a/src/main/java/forge/gui/toolbox/imaging/ImageUtil.java +++ b/src/main/java/forge/gui/toolbox/imaging/ImageUtil.java @@ -19,9 +19,7 @@ package forge.gui.toolbox.imaging; import java.awt.Dimension; -import java.awt.Image; - -import javax.swing.ImageIcon; +import forge.gui.toolbox.FSkin.SkinIcon; /** * Useful general imaging routines. @@ -32,10 +30,8 @@ import javax.swing.ImageIcon; public final class ImageUtil { private ImageUtil() {} - public static ImageIcon getMenuIcon(ImageIcon sourceIcon) { - Image img = sourceIcon.getImage(); - Image newimg = img.getScaledInstance(16, 16, java.awt.Image.SCALE_SMOOTH); - return new ImageIcon(newimg); + public static SkinIcon getMenuIcon(SkinIcon sourceIcon) { + return sourceIcon.resize(16, 16); } /** diff --git a/src/main/java/forge/gui/toolbox/itemmanager/SItemManagerUtil.java b/src/main/java/forge/gui/toolbox/itemmanager/SItemManagerUtil.java index 17d98967eb1..29a70585b3e 100644 --- a/src/main/java/forge/gui/toolbox/itemmanager/SItemManagerUtil.java +++ b/src/main/java/forge/gui/toolbox/itemmanager/SItemManagerUtil.java @@ -1,7 +1,5 @@ package forge.gui.toolbox.itemmanager; -import javax.swing.ImageIcon; - import com.google.common.base.Predicate; import com.google.common.base.Predicates; import com.google.common.collect.Iterables; @@ -11,6 +9,7 @@ import forge.card.CardRulesPredicates; import forge.gui.deckeditor.views.VCardCatalog; import forge.gui.deckeditor.views.VCurrentDeck; import forge.gui.toolbox.FSkin; +import forge.gui.toolbox.FSkin.SkinImage; import forge.item.PaperCard; import forge.item.InventoryItem; import forge.item.ItemPoolView; @@ -48,12 +47,12 @@ public final class SItemManagerUtil { INSTANT (FSkin.EditorImages.IMG_INSTANT, CardRulesPredicates.Presets.IS_INSTANT, 2), SORCERY (FSkin.EditorImages.IMG_SORCERY, CardRulesPredicates.Presets.IS_SORCERY, 2); - public final ImageIcon img; + public final SkinImage img; public final Predicate predicate; public final int group; StatTypes(FSkin.SkinProp prop, Predicate pred, int grp) { - img = new ImageIcon(FSkin.getImage(prop, 18, 18)); + img = FSkin.getImage(prop, 18, 18); predicate = pred; group = grp; } diff --git a/src/main/java/forge/gui/toolbox/itemmanager/filters/ItemFilter.java b/src/main/java/forge/gui/toolbox/itemmanager/filters/ItemFilter.java index cc89a3ff12f..e7392c7508b 100644 --- a/src/main/java/forge/gui/toolbox/itemmanager/filters/ItemFilter.java +++ b/src/main/java/forge/gui/toolbox/itemmanager/filters/ItemFilter.java @@ -1,6 +1,5 @@ package forge.gui.toolbox.itemmanager.filters; -import javax.swing.BorderFactory; import javax.swing.JLabel; import javax.swing.JPanel; @@ -31,7 +30,7 @@ public abstract class ItemFilter { if (this.panel == null) { this.panel = new JPanel(new MigLayout("insets 0, gap 2")); this.panel.setOpaque(false); - this.panel.setBorder(BorderFactory.createMatteBorder(1, 2, 1, 2, FSkin.getColor(FSkin.Colors.CLR_TEXT))); + FSkin.get(this.panel).setMatteBorder(1, 2, 1, 2, FSkin.getColor(FSkin.Colors.CLR_TEXT)); this.lblPanelTitle = new FLabel.Builder().fontSize(10).build(); this.panel.add(this.lblPanelTitle, "top"); diff --git a/src/main/java/forge/gui/toolbox/itemmanager/filters/ToggleButtonsFilter.java b/src/main/java/forge/gui/toolbox/itemmanager/filters/ToggleButtonsFilter.java index 5ca5adec5fb..4b0ada69152 100644 --- a/src/main/java/forge/gui/toolbox/itemmanager/filters/ToggleButtonsFilter.java +++ b/src/main/java/forge/gui/toolbox/itemmanager/filters/ToggleButtonsFilter.java @@ -3,11 +3,11 @@ package forge.gui.toolbox.itemmanager.filters; import java.awt.Dimension; import java.util.ArrayList; -import javax.swing.ImageIcon; import javax.swing.JPanel; import forge.Command; import forge.gui.toolbox.FLabel; +import forge.gui.toolbox.FSkin.SkinImage; import forge.gui.toolbox.itemmanager.ItemManager; import forge.gui.toolbox.itemmanager.SItemManagerUtil.StatTypes; import forge.item.InventoryItem; @@ -30,7 +30,7 @@ public abstract class ToggleButtonsFilter extends ItemF addToggleButton(panel, s.toLabelString(), s.img); } - protected void addToggleButton(JPanel panel, String filterName, ImageIcon icon) { + protected void addToggleButton(JPanel panel, String filterName, SkinImage icon) { final FLabel button = new FLabel.Builder() .icon(icon).iconScaleAuto(false) .fontSize(11) diff --git a/src/main/java/forge/gui/toolbox/itemmanager/table/ItemTable.java b/src/main/java/forge/gui/toolbox/itemmanager/table/ItemTable.java index f0e15a57b9a..974b6f580d5 100644 --- a/src/main/java/forge/gui/toolbox/itemmanager/table/ItemTable.java +++ b/src/main/java/forge/gui/toolbox/itemmanager/table/ItemTable.java @@ -53,6 +53,7 @@ import forge.item.InventoryItem; */ @SuppressWarnings("serial") public final class ItemTable extends JTable { + private final FSkin.JTableSkin> skin; private final ItemManager itemManager; private final ItemTableModel tableModel; @@ -71,19 +72,20 @@ public final class ItemTable extends JTable { this.tableModel = new ItemTableModel(this, model0); // use different selection highlight colors for focused vs. unfocused tables - setSelectionBackground(FSkin.getColor(FSkin.Colors.CLR_INACTIVE)); - setSelectionForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); + skin = FSkin.get(this); + skin.setSelectionBackground(FSkin.getColor(FSkin.Colors.CLR_INACTIVE)); + skin.setSelectionForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); addFocusListener(new FocusListener() { @Override public void focusLost(FocusEvent e) { if (!e.isTemporary()) { - setSelectionBackground(FSkin.getColor(FSkin.Colors.CLR_INACTIVE)); + skin.setSelectionBackground(FSkin.getColor(FSkin.Colors.CLR_INACTIVE)); } } @Override public void focusGained(FocusEvent e) { - setSelectionBackground(FSkin.getColor(FSkin.Colors.CLR_ACTIVE)); + skin.setSelectionBackground(FSkin.getColor(FSkin.Colors.CLR_ACTIVE)); // if nothing selected when we gain focus, select the first row (if exists) if (-1 == getSelectedRow() && 0 < getRowCount()) { setRowSelectionInterval(0, 0); @@ -91,7 +93,7 @@ public final class ItemTable extends JTable { } }); - setFont(FSkin.getFont(12)); + skin.setFont(FSkin.getFont(12)); setBorder(null); getTableHeader().setBorder(null); setRowHeight(18); diff --git a/src/main/java/forge/gui/toolbox/itemmanager/table/ManaCostRenderer.java b/src/main/java/forge/gui/toolbox/itemmanager/table/ManaCostRenderer.java index f674536ef27..926d5029af1 100644 --- a/src/main/java/forge/gui/toolbox/itemmanager/table/ManaCostRenderer.java +++ b/src/main/java/forge/gui/toolbox/itemmanager/table/ManaCostRenderer.java @@ -29,6 +29,8 @@ import forge.card.CardSplitType; import forge.card.mana.ManaCost; import forge.card.mana.ManaCostShard; import forge.gui.toolbox.CardFaceSymbols; +import forge.gui.toolbox.FSkin; +import forge.gui.toolbox.FSkin.JLabelSkin; /** * Displays mana cost as symbols. @@ -41,6 +43,7 @@ public class ManaCostRenderer extends DefaultTableCellRenderer { static final int padding0 = 1; static final int spaceBetweenSplitCosts = 3; + private final JLabelSkin skin = FSkin.get(this); private ManaCost v1; private ManaCost v2; @@ -110,7 +113,7 @@ public class ManaCostRenderer extends DefaultTableCellRenderer { // Display X Mana before any other type of mana if (xManaCosts > 0) { for (int i = 0; i < xManaCosts; i++) { - CardFaceSymbols.drawSymbol(ManaCostShard.X.getImageKey(), g, (int) xpos, 1); + CardFaceSymbols.drawSymbol(ManaCostShard.X.getImageKey(), skin, g, (int) xpos, 1); xpos += offset; } } @@ -118,7 +121,7 @@ public class ManaCostRenderer extends DefaultTableCellRenderer { // Display colorless mana before colored mana if (hasGeneric) { final String sGeneric = Integer.toString(genericManaCost); - CardFaceSymbols.drawSymbol(sGeneric, g, (int) xpos, 1); + CardFaceSymbols.drawSymbol(sGeneric, skin, g, (int) xpos, 1); xpos += offset; } @@ -127,7 +130,7 @@ public class ManaCostRenderer extends DefaultTableCellRenderer { // X costs already drawn up above continue; } - CardFaceSymbols.drawSymbol(s.getImageKey(), g, (int) xpos, 1); + CardFaceSymbols.drawSymbol(s.getImageKey(), skin, g, (int) xpos, 1); xpos += offset; } } diff --git a/src/main/java/forge/gui/toolbox/special/CardZoomer.java b/src/main/java/forge/gui/toolbox/special/CardZoomer.java index 5b18e6cd83e..24d43417ab7 100644 --- a/src/main/java/forge/gui/toolbox/special/CardZoomer.java +++ b/src/main/java/forge/gui/toolbox/special/CardZoomer.java @@ -26,8 +26,6 @@ import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.MouseWheelEvent; import java.awt.event.MouseWheelListener; -import java.awt.image.BufferedImage; - import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.Timer; @@ -59,7 +57,7 @@ public enum CardZoomer { private final JPanel overlay = FOverlay.SINGLETON_INSTANCE.getPanel(); private JPanel pnlMain; private FImagePanel imagePanel; - private JLabel lblFlipcard = new JLabel(FSkin.getIcon(FSkin.InterfaceIcons.ICO_FLIPCARD)); + private JLabel lblFlipcard = new JLabel(); // Details about the current card being displayed. private Card thisCard; @@ -78,7 +76,8 @@ public enum CardZoomer { private boolean isMouseWheelEnabled = false; // ctr - private CardZoomer() { + private CardZoomer() { + FSkin.get(lblFlipcard).setIcon(FSkin.getIcon(FSkin.InterfaceIcons.ICO_FLIPCARD)); setMouseButtonListener(); setMouseWheelListener(); setKeyListeners(); @@ -236,15 +235,11 @@ public enum CardZoomer { */ private void setImage() { imagePanel = new FImagePanel(); - imagePanel.setImage(getImageFromCache(), getInitialRotation(), AutoSizeImageMode.SOURCE); + imagePanel.setImage(FImageUtil.getImage(thisCard, cardState, FSkin.get(imagePanel)), getInitialRotation(), AutoSizeImageMode.SOURCE); pnlMain.removeAll(); - pnlMain.add(imagePanel, "w 80%!, h 80%!"); + pnlMain.add(imagePanel, "w 80%!, h 80%!"); pnlMain.validate(); - setFlipIndicator(); - } - - private BufferedImage getImageFromCache() { - return FImageUtil.getImage(thisCard, cardState); + setFlipIndicator(); } private int getInitialRotation() { diff --git a/src/main/java/forge/gui/toolbox/special/DeckLister.java b/src/main/java/forge/gui/toolbox/special/DeckLister.java index db2991dded9..148c41335d7 100644 --- a/src/main/java/forge/gui/toolbox/special/DeckLister.java +++ b/src/main/java/forge/gui/toolbox/special/DeckLister.java @@ -27,13 +27,11 @@ import java.awt.event.MouseEvent; import java.util.ArrayList; import java.util.List; -import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.SwingConstants; -import javax.swing.border.MatteBorder; import net.miginfocom.swing.MigLayout; import forge.Command; @@ -52,6 +50,7 @@ import forge.gui.deckeditor.controllers.CEditorQuest; import forge.gui.framework.ILocalRepaint; import forge.gui.toolbox.FLabel; import forge.gui.toolbox.FSkin; +import forge.gui.toolbox.FSkin.JLabelSkin; import forge.item.InventoryItem; /** @@ -61,15 +60,13 @@ import forge.item.InventoryItem; */ @SuppressWarnings("serial") public class DeckLister extends JPanel implements ILocalRepaint { - private final ImageIcon icoDelete; - private final ImageIcon icoDeleteOver; - private final ImageIcon icoEdit; - private final ImageIcon icoEditOver; private RowPanel previousSelect; private RowPanel[] rows; private final GameType gametype; private Command cmdDelete, cmdRowSelect; - private final Color clrDefault, clrHover, clrActive, clrBorders; + private final Color clrDefault; + private final FSkin.SkinIcon icoDelete, icoDeleteOver, icoEdit, icoEditOver; + private final FSkin.SkinColor clrHover, clrActive, clrBorders; /** * Creates deck list for selected decks for quick deleting, editing, and @@ -125,7 +122,7 @@ public class DeckLister extends JPanel implements ILocalRepaint { // scroll panes will have difficulty dynamically resizing if 100% width // is set. final JPanel rowTitle = new TitlePanel(); - rowTitle.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); + FSkin.get(rowTitle).setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); rowTitle.setLayout(new MigLayout("insets 0, gap 0")); rowTitle.add(new FLabel.Builder().text("Delete").fontAlign(SwingConstants.CENTER).build(), @@ -189,10 +186,11 @@ public class DeckLister extends JPanel implements ILocalRepaint { private class DeleteButton extends JButton { public DeleteButton(final RowPanel r0) { super(); + FSkin.AbstractButtonSkin skin = FSkin.get(this); this.setRolloverEnabled(true); - this.setPressedIcon(DeckLister.this.icoDeleteOver); - this.setRolloverIcon(DeckLister.this.icoDeleteOver); - this.setIcon(DeckLister.this.icoDelete); + skin.setPressedIcon(DeckLister.this.icoDeleteOver); + skin.setRolloverIcon(DeckLister.this.icoDeleteOver); + skin.setIcon(DeckLister.this.icoDelete); this.setOpaque(false); this.setContentAreaFilled(false); this.setBorder(null); @@ -203,7 +201,7 @@ public class DeckLister extends JPanel implements ILocalRepaint { @Override public void mouseEntered(final MouseEvent e) { if (!r0.selected) { - r0.setBackground(DeckLister.this.clrHover); + FSkin.get(r0).setBackground(DeckLister.this.clrHover); r0.setOpaque(true); } } @@ -211,7 +209,7 @@ public class DeckLister extends JPanel implements ILocalRepaint { @Override public void mouseExited(final MouseEvent e) { if (!r0.selected) { - r0.setBackground(DeckLister.this.clrDefault); + FSkin.get(r0).setBackground(DeckLister.this.clrDefault); r0.setOpaque(false); } } @@ -227,10 +225,11 @@ public class DeckLister extends JPanel implements ILocalRepaint { private class EditButton extends JButton { public EditButton(final RowPanel r0) { super(); + FSkin.AbstractButtonSkin skin = FSkin.get(this); this.setRolloverEnabled(true); - this.setPressedIcon(DeckLister.this.icoEditOver); - this.setRolloverIcon(DeckLister.this.icoEditOver); - this.setIcon(DeckLister.this.icoEdit); + skin.setPressedIcon(DeckLister.this.icoEditOver); + skin.setRolloverIcon(DeckLister.this.icoEditOver); + skin.setIcon(DeckLister.this.icoEdit); this.setOpaque(false); this.setContentAreaFilled(false); this.setBorder(null); @@ -241,7 +240,7 @@ public class DeckLister extends JPanel implements ILocalRepaint { @Override public void mouseEntered(final MouseEvent e) { if (!r0.selected) { - r0.setBackground(DeckLister.this.clrHover); + FSkin.get(r0).setBackground(DeckLister.this.clrHover); r0.setOpaque(true); } } @@ -249,7 +248,7 @@ public class DeckLister extends JPanel implements ILocalRepaint { @Override public void mouseExited(final MouseEvent e) { if (!r0.selected) { - r0.setBackground(DeckLister.this.clrDefault); + FSkin.get(r0).setBackground(DeckLister.this.clrDefault); r0.setOpaque(false); } } @@ -284,7 +283,7 @@ public class DeckLister extends JPanel implements ILocalRepaint { this.setOpaque(false); this.setBackground(new Color(0, 0, 0, 0)); this.setLayout(new MigLayout("insets 0, gap 0")); - this.setBorder(new MatteBorder(0, 0, 1, 0, DeckLister.this.clrBorders)); + FSkin.get(this).setMatteBorder(0, 0, 1, 0, DeckLister.this.clrBorders); this.deck = d0; this.addMouseListener(new MouseAdapter() { @@ -292,7 +291,7 @@ public class DeckLister extends JPanel implements ILocalRepaint { public void mouseEntered(final MouseEvent e) { RowPanel.this.hovered = true; if (!RowPanel.this.selected) { - ((RowPanel) e.getSource()).setBackground(DeckLister.this.clrHover); + FSkin.get(((RowPanel) e.getSource())).setBackground(DeckLister.this.clrHover); ((RowPanel) e.getSource()).setOpaque(true); } } @@ -301,7 +300,7 @@ public class DeckLister extends JPanel implements ILocalRepaint { public void mouseExited(final MouseEvent e) { RowPanel.this.hovered = false; if (!RowPanel.this.selected) { - ((RowPanel) e.getSource()).setBackground(DeckLister.this.clrDefault); + FSkin.get(((RowPanel) e.getSource())).setBackground(DeckLister.this.clrDefault); ((RowPanel) e.getSource()).setOpaque(false); } } @@ -321,7 +320,9 @@ public class DeckLister extends JPanel implements ILocalRepaint { public void setSelected(final boolean b0) { this.selected = b0; this.setOpaque(b0); - this.setBackground(b0 ? DeckLister.this.clrActive : (this.hovered ? DeckLister.this.clrHover : DeckLister.this.clrDefault)); + if (b0) { FSkin.get(this).setBackground(DeckLister.this.clrActive); } + else if (this.hovered) { FSkin.get(this).setBackground(DeckLister.this.clrHover); } + else { FSkin.get(this).setBackground(DeckLister.this.clrDefault); } } public boolean isSelected() { @@ -343,7 +344,7 @@ public class DeckLister extends JPanel implements ILocalRepaint { this.setBackground(Color.GREEN); } this.setHorizontalAlignment(SwingConstants.CENTER); - this.setFont(FSkin.getBoldFont(12)); + FSkin.get(this).setFont(FSkin.getBoldFont(12)); this.setHorizontalAlignment(SwingConstants.CENTER); } } @@ -352,8 +353,9 @@ public class DeckLister extends JPanel implements ILocalRepaint { public GenericLabel(final String txt0) { super(txt0); this.setHorizontalAlignment(SwingConstants.CENTER); - this.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); - this.setFont(FSkin.getBoldFont(12)); + JLabelSkin skin = FSkin.get(this); + skin.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); + skin.setFont(FSkin.getBoldFont(12)); } } diff --git a/src/main/java/forge/gui/toolbox/special/PhaseLabel.java b/src/main/java/forge/gui/toolbox/special/PhaseLabel.java index cece1f6efc2..c65592da83f 100644 --- a/src/main/java/forge/gui/toolbox/special/PhaseLabel.java +++ b/src/main/java/forge/gui/toolbox/special/PhaseLabel.java @@ -1,6 +1,5 @@ package forge.gui.toolbox.special; -import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.event.MouseAdapter; @@ -115,7 +114,7 @@ public class PhaseLabel extends JLabel { public void paintComponent(final Graphics g) { final int w = this.getWidth(); final int h = this.getHeight(); - Color c; + FSkin.SkinColor c; // Set color according to skip or active or hover state of label if (this.hover) { @@ -131,7 +130,7 @@ public class PhaseLabel extends JLabel { } // Center vertically and horizontally. Show border if active. - g.setColor(c); + FSkin.get(this).setGraphicsColor(g, c); g.fillRoundRect(1, 1, w - 2, h - 2, 5, 5); super.paintComponent(g); } diff --git a/src/main/java/forge/gui/toolbox/special/PlayerDetailsPanel.java b/src/main/java/forge/gui/toolbox/special/PlayerDetailsPanel.java index 725ff41a9a3..0ea47c11f75 100644 --- a/src/main/java/forge/gui/toolbox/special/PlayerDetailsPanel.java +++ b/src/main/java/forge/gui/toolbox/special/PlayerDetailsPanel.java @@ -7,7 +7,6 @@ import java.awt.event.MouseEvent; import java.util.ArrayList; import java.util.List; -import javax.swing.ImageIcon; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.SwingConstants; @@ -48,7 +47,7 @@ public class PlayerDetailsPanel extends JPanel { private final List> manaLabels = new ArrayList>(); private FLabel getBuiltFLabel(SkinProp p0, String s0, String s1) { - return new FLabel.Builder().icon(new ImageIcon(FSkin.getImage(p0))) + return new FLabel.Builder().icon(FSkin.getImage(p0)) .opaque(false).fontSize(14) .fontStyle(Font.BOLD).iconInBackground() .text(s0).tooltip(s1).fontAlign(SwingConstants.RIGHT).build(); @@ -85,11 +84,11 @@ public class PlayerDetailsPanel extends JPanel { final JPanel row5 = new JPanel(new MigLayout("insets 0, gap 0")); final JPanel row6 = new JPanel(new MigLayout("insets 0, gap 0")); - row1.setBackground(FSkin.getColor(FSkin.Colors.CLR_ZEBRA)); + FSkin.get(row1).setBackground(FSkin.getColor(FSkin.Colors.CLR_ZEBRA)); row2.setOpaque(false); - row3.setBackground(FSkin.getColor(FSkin.Colors.CLR_ZEBRA)); + FSkin.get(row3).setBackground(FSkin.getColor(FSkin.Colors.CLR_ZEBRA)); row4.setOpaque(false); - row5.setBackground(FSkin.getColor(FSkin.Colors.CLR_ZEBRA)); + FSkin.get(row5).setBackground(FSkin.getColor(FSkin.Colors.CLR_ZEBRA)); row6.setOpaque(false); // Hand, library, graveyard, exile, flashback, poison labels @@ -151,8 +150,12 @@ public class PlayerDetailsPanel extends JPanel { // Poison/life this.getLblPoison().setText("" + player.getPoisonCounters()); - Color poisonFg = player.getPoisonCounters() >= 8 ? Color.red : FSkin.getColor(FSkin.Colors.CLR_TEXT); - this.getLblPoison().setForeground(poisonFg); + if (player.getPoisonCounters() < 8) { + FSkin.get(this.getLblPoison()).setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); + } + else { + FSkin.get(this.getLblPoison()).setForeground(Color.red); + } } /** diff --git a/src/main/java/forge/model/FModel.java b/src/main/java/forge/model/FModel.java index 764a512f1e6..710dba9e9a3 100644 --- a/src/main/java/forge/model/FModel.java +++ b/src/main/java/forge/model/FModel.java @@ -40,7 +40,6 @@ import forge.error.ExceptionHandler; import forge.game.ai.AiProfileUtil; import forge.game.limited.GauntletMini; import forge.gauntlet.GauntletData; -import forge.gui.toolbox.FSkin; import forge.item.PrintSheet; import forge.properties.ForgePreferences; import forge.properties.ForgePreferences.FPref; @@ -172,8 +171,9 @@ public class FModel { this.loadDynamicGamedata(); - if(initWithUi) - FSkin.setProgessBarMessage("Loading decks"); + if (initWithUi) { + FView.SINGLETON_INSTANCE.setSplashProgessBarMessage("Loading decks"); + } this.decks = new CardCollections(); this.quest = new QuestController(); diff --git a/src/main/java/forge/properties/ForgeLookAndFeel.java b/src/main/java/forge/properties/ForgeLookAndFeel.java deleted file mode 100644 index 9d2e51ea9e3..00000000000 --- a/src/main/java/forge/properties/ForgeLookAndFeel.java +++ /dev/null @@ -1,166 +0,0 @@ -package forge.properties; - -import java.awt.Color; -import java.awt.Font; -import java.util.ArrayList; - -import javax.swing.BorderFactory; -import javax.swing.JFrame; -import javax.swing.SwingUtilities; -import javax.swing.UIManager; -import javax.swing.UnsupportedLookAndFeelException; -import javax.swing.border.Border; - -import forge.Singletons; -import forge.gui.toolbox.FSkin; -import forge.properties.ForgePreferences.FPref; - -/** - * Sets the look and feel of the GUI based on the selected Forge theme. - * - * @see UIManager Defaults - */ -public final class ForgeLookAndFeel { - - private Color FORE_COLOR = FSkin.getColor(FSkin.Colors.CLR_TEXT); - private Color BACK_COLOR = FSkin.getColor(FSkin.Colors.CLR_THEME2); - private Color HIGHLIGHT_COLOR = BACK_COLOR.brighter(); - private Border LINE_BORDER = BorderFactory.createLineBorder(FORE_COLOR.darker(), 1); - private Border EMPTY_BORDER = BorderFactory.createEmptyBorder(2,2,2,2); - - /** - * Sets the look and feel of the GUI based on the selected Forge theme. - */ - public void setForgeLookAndFeel(JFrame appFrame) { - if (isUIManagerEnabled()) { - if (setMetalLookAndFeel(appFrame)) { - setMenusLookAndFeel(); - setComboBoxLookAndFeel(); - setTabbedPaneLookAndFeel(); - setButtonLookAndFeel(); - } - } - } - - /** - * Sets the standard "Java L&F" (also called "Metal") that looks the same on all platforms. - *

- * If not explicitly set then the Mac uses its native L&F which does - * not support various settings (eg. combobox background color). - */ - private boolean setMetalLookAndFeel(JFrame appFrame) { - boolean isMetalLafSet = false; - try { - UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel"); - SwingUtilities.updateComponentTreeUI(appFrame); - isMetalLafSet = true; - } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) { - // Auto-generated catch block ignores the exception, but sends it to System.err and probably forge.log. - e.printStackTrace(); - } - return isMetalLafSet; - } - - /** - * Sets the look and feel for a JMenuBar, JMenu, JMenuItem & variations. - */ - private void setMenusLookAndFeel() { - // JMenuBar - Color clrTheme = FSkin.getColor(FSkin.Colors.CLR_THEME); - Color backgroundColor = FSkin.stepColor(clrTheme, 0); - Color menuBarEdgeColor = FSkin.stepColor(clrTheme, -80); - UIManager.put("MenuBar.foreground", FORE_COLOR); - UIManager.put("MenuBar.gradient", getColorGradients(backgroundColor.darker(), backgroundColor)); - UIManager.put("MenuBar.border", BorderFactory.createMatteBorder(0, 0, 1, 0, menuBarEdgeColor)); - // JMenu - UIManager.put("Menu.foreground", FORE_COLOR); - UIManager.put("Menu.background", BACK_COLOR); - UIManager.put("Menu.borderPainted", false); - UIManager.put("Menu.selectionBackground", HIGHLIGHT_COLOR); - UIManager.put("Menu.selectionForeground", FORE_COLOR); - UIManager.put("Menu.border", EMPTY_BORDER); - UIManager.put("Menu.opaque", false); - // JPopupMenu - UIManager.put("PopupMenu.border", LINE_BORDER); - UIManager.put("PopupMenu.background", BACK_COLOR); - UIManager.put("PopupMenu.foreground", FORE_COLOR); - // JMenuItem - UIManager.put("MenuItem.foreground", FORE_COLOR); - UIManager.put("MenuItem.background", BACK_COLOR); - UIManager.put("MenuItem.border", EMPTY_BORDER); - UIManager.put("MenuItem.selectionBackground", HIGHLIGHT_COLOR); - UIManager.put("MenuItem.selectionForeground", FORE_COLOR); - UIManager.put("MenuItem.acceleratorForeground", FORE_COLOR.darker()); - UIManager.put("MenuItem.opaque", true); - // JSeparator (needs to be opaque!). - UIManager.put("Separator.foreground", FORE_COLOR.darker()); - UIManager.put("Separator.background", BACK_COLOR); - // JRadioButtonMenuItem - UIManager.put("RadioButtonMenuItem.foreground", FORE_COLOR); - UIManager.put("RadioButtonMenuItem.background", BACK_COLOR); - UIManager.put("RadioButtonMenuItem.selectionBackground", HIGHLIGHT_COLOR); - UIManager.put("RadioButtonMenuItem.selectionForeground", FORE_COLOR); - UIManager.put("RadioButtonMenuItem.border", EMPTY_BORDER); - UIManager.put("RadioButtonMenuItem.acceleratorForeground", FORE_COLOR.darker()); - // JCheckboxMenuItem - UIManager.put("CheckBoxMenuItem.foreground", FORE_COLOR); - UIManager.put("CheckBoxMenuItem.background", BACK_COLOR); - UIManager.put("CheckBoxMenuItem.selectionBackground", HIGHLIGHT_COLOR); - UIManager.put("CheckBoxMenuItem.selectionForeground", FORE_COLOR); - UIManager.put("CheckBoxMenuItem.border", EMPTY_BORDER); - UIManager.put("CheckBoxMenuItem.acceleratorForeground", FORE_COLOR.darker()); - } - - private void setTabbedPaneLookAndFeel() { - UIManager.put("TabbedPane.selected", HIGHLIGHT_COLOR); - UIManager.put("TabbedPane.contentOpaque", FSkin.getColor(FSkin.Colors.CLR_THEME)); - UIManager.put("TabbedPane.unselectedBackground", BACK_COLOR); - } - - /** - * Sets the look and feel for a non-editable JComboBox. - */ - private void setComboBoxLookAndFeel() { - UIManager.put("ComboBox.background", BACK_COLOR); - UIManager.put("ComboBox.foreground", FORE_COLOR); - UIManager.put("ComboBox.selectionBackground", HIGHLIGHT_COLOR); - UIManager.put("ComboBox.selectionForeground", FORE_COLOR); - UIManager.put("ComboBox.disabledBackground", BACK_COLOR); - UIManager.put("ComboBox.disabledForeground", BACK_COLOR.darker()); - UIManager.put("ComboBox.font", getDefaultFont("ComboBox.font")); - UIManager.put("Button.select", HIGHLIGHT_COLOR); - } - - private void setButtonLookAndFeel() { - UIManager.put("Button.foreground", FORE_COLOR); - UIManager.put("Button.background", BACK_COLOR); - UIManager.put("Button.select", HIGHLIGHT_COLOR); - UIManager.put("Button.focus", FORE_COLOR.darker()); - UIManager.put("Button.rollover", false); - } - - /** - * Determines whether theme styles should be applied to GUI. - *

- * TODO: Currently is using UI_THEMED_COMBOBOX setting but will - * eventually want to rename for clarity. - */ - private boolean isUIManagerEnabled() { - return Singletons.getModel().getPreferences().getPrefBoolean(FPref.UI_THEMED_COMBOBOX); - } - - private Font getDefaultFont(String component) { - return FSkin.getFont(UIManager.getFont(component).getSize()); - } - - private ArrayList getColorGradients(Color bottom, Color top) { - ArrayList gradients = new ArrayList<>(); - gradients.add(0.0); - gradients.add(0.0); - gradients.add(top); - gradients.add(bottom); - gradients.add(bottom); - return gradients; - } - -} diff --git a/src/main/java/forge/quest/bazaar/IQuestBazaarItem.java b/src/main/java/forge/quest/bazaar/IQuestBazaarItem.java index 97a052900f1..e8d5ded75b5 100644 --- a/src/main/java/forge/quest/bazaar/IQuestBazaarItem.java +++ b/src/main/java/forge/quest/bazaar/IQuestBazaarItem.java @@ -17,8 +17,7 @@ */ package forge.quest.bazaar; -import javax.swing.ImageIcon; - +import forge.gui.toolbox.FSkin.SkinIcon; import forge.quest.data.QuestAssets; /** @@ -53,7 +52,7 @@ public interface IQuestBazaarItem extends Comparable { * * @return the name of the image that is displayed in the bazaar */ - ImageIcon getIcon(QuestAssets qA); + SkinIcon getIcon(QuestAssets qA); /** *

diff --git a/src/main/java/forge/quest/bazaar/QuestItemBasic.java b/src/main/java/forge/quest/bazaar/QuestItemBasic.java index 00f57fb352c..c257e774470 100644 --- a/src/main/java/forge/quest/bazaar/QuestItemBasic.java +++ b/src/main/java/forge/quest/bazaar/QuestItemBasic.java @@ -17,14 +17,13 @@ */ package forge.quest.bazaar; -import javax.swing.ImageIcon; - import org.apache.commons.lang3.StringUtils; import com.thoughtworks.xstream.annotations.XStreamAsAttribute; import forge.gui.toolbox.FSkin; import forge.gui.toolbox.FSkin.QuestIcons; +import forge.gui.toolbox.FSkin.SkinIcon; import forge.quest.data.QuestAssets; /** @@ -169,7 +168,7 @@ public class QuestItemBasic implements IQuestBazaarItem { * @return a {@link java.lang.String} object. */ @Override - public ImageIcon getIcon(QuestAssets qA) { + public SkinIcon getIcon(QuestAssets qA) { return FSkin.getIcon(this.icon); } diff --git a/src/main/java/forge/quest/bazaar/QuestPetController.java b/src/main/java/forge/quest/bazaar/QuestPetController.java index c262997b08d..4f1bc1b492a 100644 --- a/src/main/java/forge/quest/bazaar/QuestPetController.java +++ b/src/main/java/forge/quest/bazaar/QuestPetController.java @@ -20,11 +20,11 @@ package forge.quest.bazaar; import java.util.ArrayList; import java.util.List; -import javax.swing.ImageIcon; - import com.thoughtworks.xstream.annotations.XStreamAlias; import com.thoughtworks.xstream.annotations.XStreamAsAttribute; +import forge.gui.toolbox.FSkin; +import forge.gui.toolbox.FSkin.SkinIcon; import forge.item.PaperToken; import forge.properties.NewConstants; import forge.quest.data.QuestAssets; @@ -119,10 +119,10 @@ public class QuestPetController implements IQuestBazaarItem { * @return a {@link java.lang.String} object. */ @Override - public final ImageIcon getIcon(final QuestAssets qA) { + public final SkinIcon getIcon(final QuestAssets qA) { final String path = NewConstants.CACHE_TOKEN_PICS_DIR; final int level = this.getPetLevel(qA); - return new ImageIcon(path + this.levels.get(level < this.maxLevel ? level + 1 : level).getPicture() + ".jpg"); + return new FSkin.UnskinnedIcon(path + this.levels.get(level < this.maxLevel ? level + 1 : level).getPicture() + ".jpg"); } /** diff --git a/src/main/java/forge/quest/gui/ViewItem.java b/src/main/java/forge/quest/gui/ViewItem.java index 8d2d9402705..d747b059c38 100644 --- a/src/main/java/forge/quest/gui/ViewItem.java +++ b/src/main/java/forge/quest/gui/ViewItem.java @@ -30,7 +30,7 @@ public class ViewItem extends FPanel { this.tarDesc = new FTextArea(); this.btnPurchase = new FLabel.Builder().text("Buy").opaque(true).fontSize(20).hoverable(true).build(); - this.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); + FSkin.get(this).setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); // Layout this.setLayout(new MigLayout("insets 0, gap 0")); diff --git a/src/main/java/forge/quest/gui/ViewStall.java b/src/main/java/forge/quest/gui/ViewStall.java index 7ec41d8dd95..a069c7ee4d2 100644 --- a/src/main/java/forge/quest/gui/ViewStall.java +++ b/src/main/java/forge/quest/gui/ViewStall.java @@ -34,6 +34,7 @@ import forge.Singletons; import forge.gui.toolbox.FLabel; import forge.gui.toolbox.FScrollPane; import forge.gui.toolbox.FSkin; +import forge.gui.toolbox.FSkin.JTextComponentSkin; import forge.quest.QuestController; import forge.quest.bazaar.IQuestBazaarItem; import forge.quest.bazaar.QuestStallDefinition; @@ -78,9 +79,10 @@ public class ViewStall extends JPanel { // Component styling this.setOpaque(false); + JTextComponentSkin tpnFluffSkin = FSkin.get(this.tpnFluff); this.tpnFluff.setOpaque(false); - this.tpnFluff.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); - this.tpnFluff.setFont(FSkin.getItalicFont(15)); + tpnFluffSkin.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); + tpnFluffSkin.setFont(FSkin.getItalicFont(15)); this.tpnFluff.setFocusable(false); this.tpnFluff.setEditable(false); this.tpnFluff.setBorder(null); diff --git a/src/main/java/forge/util/TypeUtil.java b/src/main/java/forge/util/TypeUtil.java index ba92f20105f..e969d5c3cd4 100644 --- a/src/main/java/forge/util/TypeUtil.java +++ b/src/main/java/forge/util/TypeUtil.java @@ -1,9 +1,9 @@ package forge.util; -/** - * TODO: Write javadoc for this type. - * - */ +import java.awt.Component; +import java.awt.Container; +import java.util.ArrayList; + public class TypeUtil { /** @@ -18,4 +18,30 @@ public class TypeUtil { } return null; } + + /** + * Find all components of the given type at or under the given component + * @param compType + * @param searchComp + */ + public static ArrayList findAllComponents(Class compType, Component searchComp) { + ArrayList comps = new ArrayList(); + searchForComponents(compType, searchComp, comps); + return comps; + } + + private static void searchForComponents(Class compType, Component searchComp, ArrayList comps) { + T comp = safeCast(searchComp, compType); + if (comp != null) { + comps.add(comp); + } + + Container container = safeCast(searchComp, Container.class); + if (container != null) { + //search child components + for (Component c : container.getComponents()) { + searchForComponents(compType, c, comps); + } + } + } } diff --git a/src/main/java/forge/view/FView.java b/src/main/java/forge/view/FView.java index b1e35913062..123408f29b7 100644 --- a/src/main/java/forge/view/FView.java +++ b/src/main/java/forge/view/FView.java @@ -2,6 +2,7 @@ package forge.view; import java.awt.BorderLayout; import java.awt.Color; +import java.awt.Cursor; import java.awt.Dimension; import java.awt.Font; import java.awt.Graphics; @@ -51,7 +52,10 @@ import forge.gui.toolbox.FButton; import forge.gui.toolbox.FLabel; import forge.gui.toolbox.FOverlay; import forge.gui.toolbox.FPanel; +import forge.gui.toolbox.FProgressBar; import forge.gui.toolbox.FSkin; +import forge.gui.toolbox.FSkin.JComponentSkin; +import forge.gui.toolbox.FSkin.SkinCursor; import forge.model.BuildInfo; import forge.properties.NewConstants; @@ -71,7 +75,7 @@ public enum FView { // Top-level UI components; all have getters. private final JFrame frmDocument = new JFrame(); // A layered pane is the frame's viewport, allowing overlay effects. - private final JLayeredPane lpnDocument = new JLayeredPane(); + private final DocumentPane lpnDocument = new DocumentPane(); // The content panel is placed in the layered pane. private final JPanel pnlContent = new JPanel(); // An insets panel neatly maintains a space from the edges of the window and @@ -84,19 +88,20 @@ public enum FView { private FView() { frmSplash = new SplashFrame(); - - // Insets panel has background image / texture, which - // must be instantiated after the skin is loaded. - pnlInsets = new FPanel(new BorderLayout()); } /** */ public void initialize() { + // Insets panel has background image / texture, which + // must be instantiated after the skin is loaded. + pnlInsets = new FPanel(new BorderLayout()); + pnlInsets.setBorderToggle(false); + // Frame styling frmDocument.setMinimumSize(new Dimension(800, 600)); frmDocument.setLocationRelativeTo(null); frmDocument.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); - frmDocument.setIconImage(FSkin.getIcon(FSkin.InterfaceIcons.ICO_FAVICON).getImage()); + FSkin.get(frmDocument).setIconImage(FSkin.getIcon(FSkin.InterfaceIcons.ICO_FAVICON)); frmDocument.setTitle("Forge: " + BuildInfo.getVersionString()); // Frame components @@ -121,7 +126,7 @@ public enum FView { pnlContent.setOpaque(false); pnlContent.setLayout(null); - FOverlay.SINGLETON_INSTANCE.getPanel().setBackground(FSkin.getColor(FSkin.Colors.CLR_OVERLAY)); + FSkin.get(FOverlay.SINGLETON_INSTANCE.getPanel()).setBackground(FSkin.getColor(FSkin.Colors.CLR_OVERLAY)); // Populate all drag tab components. this.cacheUIStates(); @@ -158,7 +163,7 @@ public enum FView { resDirs.add(new File("res", resDir)); } - final Set doNotDeleteDirs = new HashSet(); + final Set doNotDeleteDirs = new HashSet(); for (String dir : Lists.newArrayList("decks", "decks/constructed", "decks/draft", "decks/plane", "decks/scheme", "decks/sealed", "gauntlet", "layouts", "pics", "preferences", "quest/data")) { doNotDeleteDirs.add(new File("res", dir)); } @@ -295,7 +300,7 @@ public enum FView { } /** @return {@link javax.swing.JLayeredPane} */ - public JLayeredPane getLpnDocument() { + public DocumentPane getLpnDocument() { return lpnDocument; } @@ -366,6 +371,26 @@ public enum FView { g.fillRect(0, 0, getWidth(), getHeight()); } } + + @SuppressWarnings("serial") + public class DocumentPane extends JLayeredPane { + private final JComponentSkin skin; + + public DocumentPane() { + super(); + this.skin = FSkin.get(this); + } + + public void setCursor(SkinCursor skinCursor) { + this.skin.setCursor(skinCursor); + } + + @Override + public void setCursor(Cursor cursor) { + this.skin.resetCursor(); //ensure skin cursor reset if needed + super.setCursor(cursor); + } + } /** @return {@link forge.view.ViewBazaarUI} */ public ViewBazaarUI getViewBazaar() { @@ -384,6 +409,32 @@ public enum FView { VHomeUI.SINGLETON_INSTANCE.instantiate(); VDeckEditorUI.SINGLETON_INSTANCE.instantiate(); } + + public void incrementSplashProgessBar() { + if (this.frmSplash == null) { return; } + this.frmSplash.getProgressBar().increment(); + } + + public void setSplashProgessBarMessage(final String message) { + setSplashProgessBarMessage(message, 0); + } + public void setSplashProgessBarMessage(final String message, final int cnt) { + if (this.frmSplash == null) { return; } + + final FProgressBar progressBar = this.frmSplash.getProgressBar(); //must cache for sake of runnable below + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + if ( cnt > 0 ) { + progressBar.reset(); + progressBar.setMaximum(cnt); + } + progressBar.setShowETA(false); + progressBar.setShowCount(cnt > 0); + progressBar.setDescription(message); + } + }); + } public void refreshAllCellLayouts(boolean showTabs) { for (DragCell cell : allCells) { diff --git a/src/main/java/forge/view/SplashFrame.java b/src/main/java/forge/view/SplashFrame.java index 3ab1f219f42..c395ee44016 100644 --- a/src/main/java/forge/view/SplashFrame.java +++ b/src/main/java/forge/view/SplashFrame.java @@ -26,7 +26,6 @@ import java.awt.event.MouseAdapter; import javax.swing.AbstractAction; import javax.swing.Action; import javax.swing.BorderFactory; -import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; @@ -38,6 +37,7 @@ import javax.swing.UIManager; import forge.gui.toolbox.FProgressBar; import forge.gui.toolbox.FSkin; +import forge.gui.toolbox.FSkin.SkinIcon; import forge.properties.ForgePreferences; import forge.properties.ForgePreferences.FPref; @@ -77,7 +77,7 @@ public class SplashFrame extends JFrame { public SplashFrame() { super(); final ForgePreferences prefs = new ForgePreferences(); - FSkin.loadLight(prefs.getPref(FPref.UI_SKIN)); + FSkin.loadLight(prefs.getPref(FPref.UI_SKIN), true); try { SwingUtilities.invokeAndWait(new Runnable() { @@ -92,7 +92,7 @@ public class SplashFrame extends JFrame { } private void init() { - final ImageIcon bgIcon = FSkin.getIcon(FSkin.Backgrounds.BG_SPLASH); + final SkinIcon bgIcon = FSkin.getIcon(FSkin.Backgrounds.BG_SPLASH); barProgress = new FProgressBar(); this.setUndecorated(true); @@ -138,7 +138,8 @@ public class SplashFrame extends JFrame { barProgress.setBounds(20, 373, 410, 57); pnlContent.add(barProgress); - final JLabel bgLabel = new JLabel(bgIcon); + final JLabel bgLabel = new JLabel(); + FSkin.get(bgLabel).setIcon(bgIcon); bgLabel.setBounds(0, 0, 450, 450); pnlContent.add(bgLabel); diff --git a/src/main/java/forge/view/ViewBazaarUI.java b/src/main/java/forge/view/ViewBazaarUI.java index c66c867afe3..ea4070f9b14 100644 --- a/src/main/java/forge/view/ViewBazaarUI.java +++ b/src/main/java/forge/view/ViewBazaarUI.java @@ -38,7 +38,7 @@ public class ViewBazaarUI extends FPanel { // Component styling this.setCornerDiameter(0); this.setBorderToggle(false); - this.setBackgroundTexture(FSkin.getIcon(FSkin.Backgrounds.BG_TEXTURE)); + this.skin.setBackgroundTexture(FSkin.getIcon(FSkin.Backgrounds.BG_TEXTURE)); this.setLayout(new MigLayout("insets 0, gap 0")); pnlAllStalls.setOpaque(false); pnlAllStalls.setLayout(new MigLayout("insets 0, gap 0, wrap, align center")); diff --git a/src/main/java/forge/view/arcane/CardPanel.java b/src/main/java/forge/view/arcane/CardPanel.java index ea18f5d858e..c02fc602021 100644 --- a/src/main/java/forge/view/arcane/CardPanel.java +++ b/src/main/java/forge/view/arcane/CardPanel.java @@ -46,6 +46,7 @@ import forge.game.combat.Combat; import forge.gui.CardContainer; import forge.gui.match.CMatchUI; import forge.gui.toolbox.CardFaceSymbols; +import forge.gui.toolbox.FSkin; import forge.properties.ForgePreferences.FPref; import forge.view.arcane.util.OutlinedLabel; @@ -92,31 +93,14 @@ public class CardPanel extends JPanel implements CardContainer { */ private static final float ROT_CENTER_TO_BOTTOM_CORNER = 0.7071067811865475244008443621048f; - /** - * - */ private Card gameCard; - /** - * - */ private CardPanel attachedToPanel; - /** - * - */ private List attachedPanels = new ArrayList(); - /** - * - */ private boolean tapped; - /** - * - */ private double tappedAngle = 0; - /** - * - */ private ScaledImagePanel imagePanel; + private final FSkin.JComponentSkin skin; private OutlinedLabel titleText; private OutlinedLabel ptText; private OutlinedLabel damageText; @@ -138,6 +122,7 @@ public class CardPanel extends JPanel implements CardContainer { public CardPanel(final Card newGameCard) { this.gameCard = newGameCard; + this.skin = FSkin.get(this); this.setBackground(Color.black); this.setOpaque(false); @@ -365,7 +350,7 @@ public class CardPanel extends JPanel implements CardContainer { private void drawManaCost(final Graphics g, ManaCost cost, int deltaY ) { int width = CardFaceSymbols.getWidth(cost); int height = CardFaceSymbols.getHeight(); - CardFaceSymbols.draw(g, cost, (this.cardXOffset + (this.cardWidth / 2)) - (width / 2), deltaY + this.cardYOffset + (this.cardHeight / 2) - height/2); + CardFaceSymbols.draw(skin, g, cost, (this.cardXOffset + (this.cardWidth / 2)) - (width / 2), deltaY + this.cardYOffset + (this.cardHeight / 2) - height/2); } /** {@inheritDoc} */ @@ -402,13 +387,13 @@ public class CardPanel extends JPanel implements CardContainer { final int yCounters = (this.cardYOffset + this.cardHeight) - (this.cardHeight / 3) - 40; if (counters == 1) { - CardFaceSymbols.drawSymbol("counters1", g, this.cardXOffset - 15, yCounters); + CardFaceSymbols.drawSymbol("counters1", skin, g, this.cardXOffset - 15, yCounters); } else if (counters == 2) { - CardFaceSymbols.drawSymbol("counters2", g, this.cardXOffset - 15, yCounters); + CardFaceSymbols.drawSymbol("counters2", skin, g, this.cardXOffset - 15, yCounters); } else if (counters == 3) { - CardFaceSymbols.drawSymbol("counters3", g, this.cardXOffset - 15, yCounters); + CardFaceSymbols.drawSymbol("counters3", skin, g, this.cardXOffset - 15, yCounters); } else if (counters > 3) { - CardFaceSymbols.drawSymbol("countersMulti", g, this.cardXOffset - 15, yCounters); + CardFaceSymbols.drawSymbol("countersMulti", skin, g, this.cardXOffset - 15, yCounters); } final int combatXSymbols = (this.cardXOffset + (this.cardWidth / 4)) - 16; @@ -418,28 +403,28 @@ public class CardPanel extends JPanel implements CardContainer { Combat combat = card.getGame().getCombat(); if( combat != null ) { if ( combat.isAttacking(card)) - CardFaceSymbols.drawSymbol("attack", g, combatXSymbols, ySymbols); + CardFaceSymbols.drawSymbol("attack", skin, g, combatXSymbols, ySymbols); if ( combat.isBlocking(card)) - CardFaceSymbols.drawSymbol("defend", g, combatXSymbols, ySymbols); + CardFaceSymbols.drawSymbol("defend", skin, g, combatXSymbols, ySymbols); } if (card.isSick() && card.isInPlay()) { - CardFaceSymbols.drawSymbol("summonsick", g, stateXSymbols, ySymbols); + CardFaceSymbols.drawSymbol("summonsick", skin, g, stateXSymbols, ySymbols); } if (card.isPhasedOut()) { - CardFaceSymbols.drawSymbol("phasing", g, stateXSymbols, ySymbols); + CardFaceSymbols.drawSymbol("phasing", skin, g, stateXSymbols, ySymbols); } if (CMatchUI.SINGLETON_INSTANCE.isUsedToPay(card)) { - CardFaceSymbols.drawSymbol("sacrifice", g, (this.cardXOffset + (this.cardWidth / 2)) - 20, + CardFaceSymbols.drawSymbol("sacrifice", skin, g, (this.cardXOffset + (this.cardWidth / 2)) - 20, (this.cardYOffset + (this.cardHeight / 2)) - 20); } if (card.getFoil() > 0) { final String fl = String.format("foil%02d", card.getFoil()); final int z = Math.round(this.cardWidth * CardPanel.BLACK_BORDER_SIZE); - CardFaceSymbols.drawOther(g, fl, this.cardXOffset + z, this.cardYOffset + z, this.cardWidth - (2 * z), + CardFaceSymbols.drawOther(skin, g, fl, this.cardXOffset + z, this.cardYOffset + z, this.cardWidth - (2 * z), this.cardHeight - (2 * z)); } }