Big update to FLabel, allowing auto icon resize, font resizing per axis, resize toggling, hover toggle, select toggle, and command execution ability.

This commit is contained in:
Doublestrike
2012-02-02 08:54:55 +00:00
parent c23ff8d8f2
commit 6a11e12bc0
12 changed files with 284 additions and 175 deletions

4
.gitattributes vendored
View File

@@ -11201,8 +11201,6 @@ src/main/java/forge/view/home/QuestFileLister.java -text
src/main/java/forge/view/home/QuestPreferencesHandler.java -text src/main/java/forge/view/home/QuestPreferencesHandler.java -text
src/main/java/forge/view/home/SplashFrame.java -text src/main/java/forge/view/home/SplashFrame.java -text
src/main/java/forge/view/home/StartButton.java -text src/main/java/forge/view/home/StartButton.java -text
src/main/java/forge/view/home/SubButton.java -text
src/main/java/forge/view/home/SubTab.java -text
src/main/java/forge/view/home/ViewConstructed.java -text src/main/java/forge/view/home/ViewConstructed.java -text
src/main/java/forge/view/home/ViewDraft.java -text src/main/java/forge/view/home/ViewDraft.java -text
src/main/java/forge/view/home/ViewQuest.java -text src/main/java/forge/view/home/ViewQuest.java -text
@@ -11238,6 +11236,8 @@ src/main/java/forge/view/toolbox/FScrollPane.java -text
src/main/java/forge/view/toolbox/FSkin.java -text src/main/java/forge/view/toolbox/FSkin.java -text
src/main/java/forge/view/toolbox/FTextArea.java -text src/main/java/forge/view/toolbox/FTextArea.java -text
src/main/java/forge/view/toolbox/FVerticalTabPanel.java -text src/main/java/forge/view/toolbox/FVerticalTabPanel.java -text
src/main/java/forge/view/toolbox/SubButton.java -text
src/main/java/forge/view/toolbox/SubTab.java -text
src/main/java/forge/view/toolbox/package-info.java svneol=native#text/plain src/main/java/forge/view/toolbox/package-info.java svneol=native#text/plain
src/main/java/net/slightlymagic/braids/LICENSE.txt svneol=native#text/plain src/main/java/net/slightlymagic/braids/LICENSE.txt svneol=native#text/plain
src/main/java/net/slightlymagic/braids/util/ClumsyRunnable.java svneol=native#text/plain src/main/java/net/slightlymagic/braids/util/ClumsyRunnable.java svneol=native#text/plain

View File

@@ -153,29 +153,31 @@ public class ControlField {
*/ */
private void addZoneListeners() { private void addZoneListeners() {
// Graveyard card list button // Graveyard card list button
this.view.getLblGraveyard().enableHover(); this.view.getLblGraveyard().setHoverable(true);
this.view.getLblGraveyard().removeMouseListener(maGraveyard); this.view.getLblGraveyard().removeMouseListener(maGraveyard);
this.view.getLblGraveyard().addMouseListener(maGraveyard); this.view.getLblGraveyard().addMouseListener(maGraveyard);
// Exile card list button // Exile card list button
this.view.getLblExile().enableHover(); this.view.getLblExile().setHoverable(true);
this.view.getLblExile().removeMouseListener(maExiled); this.view.getLblExile().removeMouseListener(maExiled);
this.view.getLblExile().addMouseListener(maExiled); this.view.getLblExile().addMouseListener(maExiled);
// Library card list button // Library card list button
if (Constant.Runtime.DEV_MODE[0]) { if (Constant.Runtime.DEV_MODE[0]) {
this.view.getLblLibrary().enableHover();
this.view.getLblLibrary().removeMouseListener(maLibrary); this.view.getLblLibrary().removeMouseListener(maLibrary);
this.view.getLblLibrary().addMouseListener(maLibrary); this.view.getLblLibrary().addMouseListener(maLibrary);
// Hand button // Hand button
this.view.getLblHand().enableHover(); this.view.getLblHand().setHoverable(true);
}
else {
this.view.getLblLibrary().setHoverable(false);
} }
this.view.getLblHand().removeMouseListener(maHand); this.view.getLblHand().removeMouseListener(maHand);
this.view.getLblHand().addMouseListener(maHand); this.view.getLblHand().addMouseListener(maHand);
// Flashback card list button // Flashback card list button
this.view.getLblFlashback().enableHover(); this.view.getLblFlashback().setHoverable(true);
this.view.getLblFlashback().removeMouseListener(maFlashback); this.view.getLblFlashback().removeMouseListener(maFlashback);
this.view.getLblFlashback().addMouseListener(maFlashback); this.view.getLblFlashback().addMouseListener(maFlashback);
} }
@@ -184,22 +186,22 @@ public class ControlField {
* Adds listeners to mana "pool" labels, for paying mana. * Adds listeners to mana "pool" labels, for paying mana.
*/ */
private void addPoolListeners() { private void addPoolListeners() {
this.view.getLblBlack().enableHover(); this.view.getLblBlack().setHoverable(true);
this.view.getLblBlack().removeMouseListener(maBlack); this.view.getLblBlack().removeMouseListener(maBlack);
this.view.getLblBlack().addMouseListener(maBlack); this.view.getLblBlack().addMouseListener(maBlack);
this.view.getLblBlue().enableHover(); this.view.getLblBlue().setHoverable(true);
this.view.getLblBlue().removeMouseListener(maBlue); this.view.getLblBlue().removeMouseListener(maBlue);
this.view.getLblBlue().addMouseListener(maBlue); this.view.getLblBlue().addMouseListener(maBlue);
this.view.getLblGreen().enableHover(); this.view.getLblGreen().setHoverable(true);
this.view.getLblGreen().removeMouseListener(maGreen); this.view.getLblGreen().removeMouseListener(maGreen);
this.view.getLblGreen().addMouseListener(maGreen); this.view.getLblGreen().addMouseListener(maGreen);
this.view.getLblRed().enableHover(); this.view.getLblRed().setHoverable(true);
this.view.getLblRed().removeMouseListener(maRed); this.view.getLblRed().removeMouseListener(maRed);
this.view.getLblRed().addMouseListener(maRed); this.view.getLblRed().addMouseListener(maRed);
this.view.getLblWhite().enableHover(); this.view.getLblWhite().setHoverable(true);
this.view.getLblWhite().removeMouseListener(maWhite); this.view.getLblWhite().removeMouseListener(maWhite);
this.view.getLblWhite().addMouseListener(maWhite); this.view.getLblWhite().addMouseListener(maWhite);
this.view.getLblColorless().enableHover(); this.view.getLblColorless().setHoverable(true);
this.view.getLblColorless().removeMouseListener(maColorless); this.view.getLblColorless().removeMouseListener(maColorless);
this.view.getLblColorless().addMouseListener(maColorless); this.view.getLblColorless().addMouseListener(maColorless);
} }

View File

@@ -15,6 +15,7 @@ import forge.view.toolbox.FList;
import forge.view.toolbox.FProgressBar; import forge.view.toolbox.FProgressBar;
import forge.view.toolbox.FScrollPane; import forge.view.toolbox.FScrollPane;
import forge.view.toolbox.FSkin; import forge.view.toolbox.FSkin;
import forge.view.toolbox.SubButton;
/** /**
* Assembles swing components for "Constructed" mode menu. * Assembles swing components for "Constructed" mode menu.

View File

@@ -29,6 +29,7 @@ import forge.view.toolbox.FPanel;
import forge.view.toolbox.FProgressBar; import forge.view.toolbox.FProgressBar;
import forge.view.toolbox.FScrollPane; import forge.view.toolbox.FScrollPane;
import forge.view.toolbox.FSkin; import forge.view.toolbox.FSkin;
import forge.view.toolbox.SubButton;
/** /**
* Assembles swing components for "Draft" mode menu. * Assembles swing components for "Draft" mode menu.

View File

@@ -38,6 +38,8 @@ import forge.view.toolbox.FRoundedPanel;
import forge.view.toolbox.FScrollPane; import forge.view.toolbox.FScrollPane;
import forge.view.toolbox.FSkin; import forge.view.toolbox.FSkin;
import forge.view.toolbox.FTextArea; import forge.view.toolbox.FTextArea;
import forge.view.toolbox.SubButton;
import forge.view.toolbox.SubTab;
/** /**
* Populates Swing components of Quest mode in home screen. * Populates Swing components of Quest mode in home screen.
@@ -106,7 +108,7 @@ public class ViewQuest extends JScrollPane {
pnlLoadQuest = new JPanel(); pnlLoadQuest = new JPanel();
pnlPrefs = new JPanel(); pnlPrefs = new JPanel();
lblTitle = new FLabel("New Quest"); lblTitle = new FLabel("New Quest", SwingConstants.CENTER);
lblLife = new FLabel(); lblLife = new FLabel();
lblCredits = new FLabel(); lblCredits = new FLabel();
lblWins = new FLabel(); lblWins = new FLabel();
@@ -144,7 +146,7 @@ public class ViewQuest extends JScrollPane {
final String constraints = "w 90%!, gap 0 0 0 20px, alignx center"; final String constraints = "w 90%!, gap 0 0 0 20px, alignx center";
pnlViewport.add(pnlTabber, constraints + ", h 20px!"); pnlViewport.add(pnlTabber, constraints + ", h 20px!");
pnlViewport.add(pnlTitle, constraints + ", h 60px!"); pnlViewport.add(pnlTitle, constraints + ", h 7%:7%:60px");
pnlViewport.add(pnlStats, constraints); pnlViewport.add(pnlStats, constraints);
pnlViewport.add(pnlDuels, constraints); pnlViewport.add(pnlDuels, constraints);
pnlViewport.add(pnlChallenges, constraints); pnlViewport.add(pnlChallenges, constraints);
@@ -205,7 +207,10 @@ public class ViewQuest extends JScrollPane {
pnlTitle.setLayout(new MigLayout("insets 0, gap 0, align center")); pnlTitle.setLayout(new MigLayout("insets 0, gap 0, align center"));
pnlTitle.setBackground(skin.getColor(FSkin.Colors.CLR_THEME).darker()); pnlTitle.setBackground(skin.getColor(FSkin.Colors.CLR_THEME).darker());
((FRoundedPanel) pnlTitle).setBorderColor(clrBorders); ((FRoundedPanel) pnlTitle).setBorderColor(clrBorders);
pnlTitle.add(lblTitle, "h 70%!, gap 0 0 0 10%!");
((FLabel) lblTitle).setFontScaleBy(SwingConstants.HORIZONTAL);
((FLabel) lblTitle).setFontScaleFactor(0.035);
pnlTitle.add(lblTitle, "w 98%!, h 70%!, gap 0 0 15%! 15%!");
} }
/** Layout permanent parts of stats panel. */ /** Layout permanent parts of stats panel. */
@@ -415,8 +420,11 @@ public class ViewQuest extends JScrollPane {
//========= TAB SHOW METHODS //========= TAB SHOW METHODS
/** Display handler for duel tab click. */ /** Display handler for duel tab click. */
public void showDuelsTab() { public void showDuelsTab() {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
control.updateTabber(tabDuels); control.updateTabber(tabDuels);
this.hideAllPanels(); hideAllPanels();
pnlTitle.setVisible(true); pnlTitle.setVisible(true);
if (AllZone.getQuestData() == null) { if (AllZone.getQuestData() == null) {
@@ -437,9 +445,6 @@ public class ViewQuest extends JScrollPane {
selectedOpponent.setBackground(skin.getColor(FSkin.Colors.CLR_ACTIVE)); selectedOpponent.setBackground(skin.getColor(FSkin.Colors.CLR_ACTIVE));
} }
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
pnlStats.setVisible(true); pnlStats.setVisible(true);
pnlDuels.setVisible(true); pnlDuels.setVisible(true);
} }
@@ -449,7 +454,7 @@ public class ViewQuest extends JScrollPane {
/** Display handler for duel tab click. */ /** Display handler for duel tab click. */
public void showChallengesTab() { public void showChallengesTab() {
control.updateTabber(tabChallenges); control.updateTabber(tabChallenges);
this.hideAllPanels(); hideAllPanels();
pnlTitle.setVisible(true); pnlTitle.setVisible(true);
if (AllZone.getQuestData() == null) { if (AllZone.getQuestData() == null) {
@@ -547,7 +552,6 @@ public class ViewQuest extends JScrollPane {
FLabel lblIcon = new FLabel(); FLabel lblIcon = new FLabel();
lblIcon.setIconScaleFactor(1); lblIcon.setIconScaleFactor(1);
lblIcon.setForeground(skin.getColor(FSkin.Colors.CLR_TEXT));
if (!file.exists()) { if (!file.exists()) {
lblIcon.setIcon(skin.getIcon(FSkin.ForgeIcons.ICO_UNKNOWN)); lblIcon.setIcon(skin.getIcon(FSkin.ForgeIcons.ICO_UNKNOWN));
} }
@@ -556,22 +560,6 @@ public class ViewQuest extends JScrollPane {
} }
this.add(lblIcon, "h 60px!, w 60px!, gap 10px 10px 10px 0, span 1 2"); this.add(lblIcon, "h 60px!, w 60px!, gap 10px 10px 10px 0, span 1 2");
// Name
final FLabel lblName = new FLabel(event.getTitle() + ": " + event.getDifficulty());
lblName.setFontScaleFactor(0.6);
this.add(lblName, "h 31px!, gap 0 0 10px 5px, wrap");
// Description
final FTextArea tarDesc = new FTextArea();
tarDesc.setText(event.getDescription());
tarDesc.setFont(skin.getItalicFont(12));
this.add(tarDesc, "w 80%!, h 30px!");
this.setToolTipText("<html>" + event.getTitle()
+ ": " + event.getDifficulty()
+ "<br>" + event.getDescription()
+ "</html>");
this.addMouseListener(new MouseAdapter() { this.addMouseListener(new MouseAdapter() {
@Override @Override
public void mouseReleased(MouseEvent e) { public void mouseReleased(MouseEvent e) {
@@ -599,6 +587,18 @@ public class ViewQuest extends JScrollPane {
} }
} }
}); });
// Name
final FLabel lblName = new FLabel(event.getTitle() + ": " + event.getDifficulty());
lblName.setFontScaleFactor(0.6);
lblName.setHoverable(false);
this.add(lblName, "h 31px!, gap 0 0 10px 5px, wrap");
// Description
final FTextArea tarDesc = new FTextArea();
tarDesc.setText(event.getDescription());
tarDesc.setFont(skin.getItalicFont(12));
this.add(tarDesc, "w 80%!, h 30px!");
} }
/** @return QuestEvent */ /** @return QuestEvent */

View File

@@ -13,6 +13,7 @@ import forge.view.toolbox.DeckLister;
import forge.view.toolbox.FProgressBar; import forge.view.toolbox.FProgressBar;
import forge.view.toolbox.FScrollPane; import forge.view.toolbox.FScrollPane;
import forge.view.toolbox.FSkin; import forge.view.toolbox.FSkin;
import forge.view.toolbox.SubButton;
/** /**
* Assembles swing components for "Sealed" mode menu. * Assembles swing components for "Sealed" mode menu.

View File

@@ -43,6 +43,7 @@ import forge.view.toolbox.FLabel;
import forge.view.toolbox.FList; import forge.view.toolbox.FList;
import forge.view.toolbox.FScrollPane; import forge.view.toolbox.FScrollPane;
import forge.view.toolbox.FSkin; import forge.view.toolbox.FSkin;
import forge.view.toolbox.SubButton;
/** /**
* Assembles swing components for "Settings" mode menu. * Assembles swing components for "Settings" mode menu.

View File

@@ -20,6 +20,7 @@ import forge.view.toolbox.FButton;
import forge.view.toolbox.FOverlay; import forge.view.toolbox.FOverlay;
import forge.view.toolbox.FPanel; import forge.view.toolbox.FPanel;
import forge.view.toolbox.FSkin; import forge.view.toolbox.FSkin;
import forge.view.toolbox.SubButton;
/** /**
* Assembles swing components for "Utilities" mode menu. * Assembles swing components for "Utilities" mode menu.

View File

@@ -19,7 +19,6 @@ package forge.view.match;
import java.awt.Color; import java.awt.Color;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image; import java.awt.Image;
import java.awt.event.ComponentAdapter; import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent; import java.awt.event.ComponentEvent;
@@ -672,12 +671,6 @@ public class ViewField extends FRoundedPanel {
// difficulties in displaying the desired "flat" background and // difficulties in displaying the desired "flat" background and
// also strange icon/action behavior. // also strange icon/action behavior.
public class DetailLabel extends FLabel { public class DetailLabel extends FLabel {
private boolean hover = false;
private final MouseAdapter madHover;
private int w, h, iw, ih;
private final Image img;
private Graphics2D g2d;
/** /**
* Instance of JLabel detailing info about field: has icon and optional * Instance of JLabel detailing info about field: has icon and optional
* hover effect. * hover effect.
@@ -692,53 +685,11 @@ public class ViewField extends FRoundedPanel {
this.setOpaque(false); this.setOpaque(false);
this.setFontScaleFactor(0.5); this.setFontScaleFactor(0.5);
this.setBackground(clrHover); this.setIconScaleFactor(0.8);
img = skin.getImage(s0); this.setIconInBackground(true);
iw = img.getWidth(null); this.setIcon(new ImageIcon(skin.getImage(s0)));
ih = img.getHeight(null);
// Hover effect this.setHoverable(true);
this.madHover = new MouseAdapter() {
@Override
public void mouseEntered(final MouseEvent e) { hover = true; repaint(); }
@Override
public void mouseExited(final MouseEvent e) { hover = false; repaint(); }
};
this.enableHover();
//this.clrBorders = ViewField.this.transparent;
}
/** Enable hover effects for this label. */
public void enableHover() {
this.disableHover();
this.addMouseListener(this.madHover);
}
/** Disable hover effects for this label. */
public void disableHover() {
this.removeMouseListener(this.madHover);
}
/*
* (non-Javadoc)
*
* @see javax.swing.JComponent#paintComponent(java.awt.Graphics)
*/
@Override
protected void paintComponent(final Graphics g) {
this.h = this.getHeight();
this.w = this.getWidth();
this.g2d = (Graphics2D) g.create();
if (hover) {
g2d.setColor(clrHover);
g2d.fillRect(0, 0, w, h);
}
g2d.drawImage(img, 3, 5, h - 12, h - 10, 0, 0, iw, ih, null);
super.paintComponent(g);
} }
} }

View File

@@ -1,15 +1,21 @@
package forge.view.toolbox; package forge.view.toolbox;
import java.awt.Color;
import java.awt.Font; import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image; import java.awt.Image;
import java.awt.event.ComponentAdapter; import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent; import java.awt.event.ComponentEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.Icon; import javax.swing.Icon;
import javax.swing.ImageIcon; import javax.swing.ImageIcon;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.SwingConstants; import javax.swing.SwingConstants;
import forge.Command;
import forge.Singletons; import forge.Singletons;
/** /**
@@ -23,13 +29,32 @@ import forge.Singletons;
public class FLabel extends JLabel { public class FLabel extends JLabel {
private final FSkin skin; private final FSkin skin;
private final ComponentAdapter cadResize; private final ComponentAdapter cadResize;
private boolean scaleAuto; private final MouseAdapter madEvents;
private double fontScaleFactor = 0.6; private final Color clrText, clrBorders, clrHover, clrInactive, clrActive;
private double iconScaleFactor = 0.8;
private double aspectRatio; private boolean fontScaleAuto;
private Image img = null; private boolean iconScaleAuto;
private int w, h;
private int fontStyle = Font.PLAIN; private int fontScaleBy;
private boolean iconInBackground;
private boolean opaque;
private boolean selectable;
private boolean selected;
private boolean hoverable;
private boolean hovered;
private double fontScaleFactor;
private double iconScaleFactor;
private Image img;
private Graphics2D g2d;
private Command cmdClick;
private int x, y, w, h, iw, ih, sw, sh, ref;
private double iar;
private int fontStyle;
/** */ /** */
public FLabel() { public FLabel() {
@@ -64,60 +89,98 @@ public class FLabel extends JLabel {
public FLabel(final String s0) { public FLabel(final String s0) {
super(s0); super(s0);
this.skin = Singletons.getView().getSkin(); this.skin = Singletons.getView().getSkin();
this.setForeground(skin.getColor(FSkin.Colors.CLR_TEXT)); // Final inits
this.clrText = skin.getColor(FSkin.Colors.CLR_TEXT);
this.clrBorders = skin.getColor(FSkin.Colors.CLR_BORDERS);
this.clrHover = skin.getColor(FSkin.Colors.CLR_HOVER);
this.clrActive = skin.getColor(FSkin.Colors.CLR_ACTIVE);
this.clrInactive = skin.getColor(FSkin.Colors.CLR_INACTIVE);
// Custom properties
this.fontScaleAuto = true;
this.fontScaleFactor = 0.6;
this.iconScaleAuto = true;
this.iconScaleFactor = 0.8;
this.selectable = false;
this.selected = false;
this.hoverable = false;
this.hovered = false;
this.fontScaleBy = SwingConstants.VERTICAL;
this.fontStyle = Font.PLAIN;
this.iconInBackground = false;
// Default properties
this.setForeground(clrText);
this.setBackground(clrInactive);
this.setVerticalTextPosition(SwingConstants.CENTER); this.setVerticalTextPosition(SwingConstants.CENTER);
this.setVerticalAlignment(SwingConstants.CENTER); this.setVerticalAlignment(SwingConstants.CENTER);
// Resize adapter
this.cadResize = new ComponentAdapter() { this.cadResize = new ComponentAdapter() {
@Override @Override
public void componentResized(ComponentEvent e) { public void componentResized(ComponentEvent e) {
if (fontScaleAuto) {
ref = (fontScaleBy == SwingConstants.VERTICAL ? getHeight() : getWidth());
switch (fontStyle) { switch (fontStyle) {
case Font.BOLD: case Font.BOLD:
setFont(skin.getBoldFont((int) (getHeight() * fontScaleFactor))); setFont(skin.getBoldFont((int) (ref * fontScaleFactor)));
repaint();
break; break;
case Font.ITALIC: case Font.ITALIC:
setFont(skin.getItalicFont((int) (getHeight() * fontScaleFactor))); setFont(skin.getItalicFont((int) (ref * fontScaleFactor)));
break; break;
default: default:
setFont(skin.getFont((int) (getHeight() * fontScaleFactor))); setFont(skin.getFont((int) (ref * fontScaleFactor)));
}
} }
if (img == null) { return; } // Non-background icon
aspectRatio = img.getWidth(null) / img.getHeight(null); if (img != null && iconScaleAuto && !iconInBackground) {
h = (int) (getHeight() * iconScaleFactor); h = (int) (getHeight() * iconScaleFactor);
w = (int) (h * aspectRatio * iconScaleFactor); w = (int) (h * iar * iconScaleFactor);
if (w == 0 || h == 0) { return; } if (w == 0 || h == 0) { return; }
FLabel.super.setIcon(new ImageIcon(img.getScaledInstance(w, h, Image.SCALE_SMOOTH))); FLabel.super.setIcon(new ImageIcon(img.getScaledInstance(w, h, Image.SCALE_SMOOTH)));
} }
}
}; };
this.removeComponentListener(cadResize);
this.addComponentListener(cadResize);
this.setScaleAuto(true); this.madEvents = new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent e) { hovered = true; repaint(); }
@Override
public void mouseExited(MouseEvent e) { hovered = false; repaint(); }
@Override
public void mouseClicked(MouseEvent e) {
if (!selectable) { return; }
selected = (selected ? false : true); repaint();
cmdClick.execute();
}
};
}
/** @param b0 &emsp; boolean */
public void setHoverable(boolean b0) {
if (!b0) { this.removeMouseListener(madEvents); }
else { this.addMouseListener(madEvents); }
}
/** @param b0 &emsp; boolean */
public void setSelectable(boolean b0) {
this.selectable = b0;
}
/** @param d0 &emsp; Scale factor for font size relative to label height, percent.
* If your font is "blowing up", try setting an explicity height/width for this label. */
public void setFontScaleFactor(final double d0) {
this.fontScaleFactor = d0;
} }
/** @param b0 &emsp; {@link java.lang.boolean} */ /** @param b0 &emsp; {@link java.lang.boolean} */
public void setScaleAuto(final boolean b0) { public void setFontScaleAuto(final boolean b0) {
this.scaleAuto = b0; this.fontScaleAuto = b0;
if (scaleAuto) {
this.addComponentListener(cadResize);
}
else {
this.removeComponentListener(cadResize);
}
}
/**
* Sets whether bold or italic font should be used for this label.
*
* @param i0 &emsp; Font.BOLD or Font.ITALIC
*/
public void setFontStyle(int i0) {
this.fontStyle = i0;
}
/** @param d0 &emsp; Scale factor for font size relative to label height, percent. */
public void setFontScaleFactor(final double d0) {
this.fontScaleFactor = d0;
} }
/** @param d0 &emsp; Scale factor for icon size relative to label height, percent. */ /** @param d0 &emsp; Scale factor for icon size relative to label height, percent. */
@@ -125,22 +188,102 @@ public class FLabel extends JLabel {
this.iconScaleFactor = d0; this.iconScaleFactor = d0;
} }
/** @return {@link java.lang.boolean} */ /** @param b0 &emsp; Font drawn in background, or positioned by default. */
public boolean isScaleAuto() { public void setIconInBackground(final boolean b0) {
return this.scaleAuto; this.iconInBackground = b0;
// Reset icon in case this method has been called after setIcon().
if (b0 && img != null) { setIcon(new ImageIcon(img)); }
}
/** @param b0 &emsp; {@link java.lang.boolean} */
public void setIconScaleAuto(final boolean b0) {
this.iconScaleAuto = b0;
// Reset icon in case this method has been called after setIcon().
if (!b0 && img != null) { setIcon(new ImageIcon(img)); }
}
/** @param i0 &emsp; int, must be SwingConstants.HORIZONTAL or VERTICAL */
public void setFontScaleBy(int i0) {
if (i0 != SwingConstants.HORIZONTAL && i0 != SwingConstants.VERTICAL) {
throw new IllegalArgumentException("FLabel$setScaleBy "
+ "must be passed either SwingConstants.HORIZONTAL "
+ "or SwingConstants.VERTICAL.");
}
this.fontScaleBy = i0;
}
/** @param i0 &emsp; must be Font.PLAIN, Font.BOLD, Font.ITALIC */
public void setFontStyle(int i0) {
if (i0 != Font.PLAIN && i0 != Font.BOLD && i0 != Font.ITALIC) {
throw new IllegalArgumentException("FLabel$setFontStyle "
+ "must be passed either Font.PLAIN, Font.BOLD, or Font.ITALIC.");
}
this.fontStyle = i0;
} }
@Override @Override
public void setIcon(final Icon i0) { public void setIcon(final Icon i0) {
if (scaleAuto) {
// Setting the icon in the usual way leads to scaling problems.
// So, only the image is saved, and scaled along with the font
// in the resize adapter.
if (i0 == null) { return; } if (i0 == null) { return; }
this.img = ((ImageIcon) i0).getImage(); // 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);
} }
else {
super.setIcon(i0);
} }
/** @param c0 &emsp; {@link forge.Command} on click */
public void setCommand(Command c0) {
this.cmdClick = c0;
}
@Override
public void setOpaque(final boolean b0) {
// Must be overridden to allow drawing order of background, icon, string
this.opaque = b0;
super.setOpaque(false);
}
@Override
public void paintComponent(Graphics g) {
g2d = (Graphics2D) g.create();
w = getWidth();
h = getHeight();
// Opacity, select
if (this.opaque && !selected) {
g2d.setColor(clrInactive);
g2d.fillRect(0, 0, w, h);
}
else if (selectable && selected) {
g2d.setColor(clrActive);
g2d.fillRect(0, 0, w, h);
}
// Hover
if (hoverable && hovered && !selected) {
g2d.setColor(clrHover);
g2d.fillRect(0, 0, w, h);
g2d.setColor(clrBorders);
g2d.drawRect(0, 0, w - 1, h - 1);
}
// Icon in background
if (iconInBackground) {
x = 3;
sh = (int) ((h - 2 * x) * iconScaleFactor);
sw = (int) (sh * iar);
y = (int) ((h - sh) / 2);
g2d.drawImage(img, x, y, sw + x, sh + y, 0, 0, iw, ih, null);
}
super.paintComponent(g);
} }
} }

View File

@@ -1,4 +1,4 @@
package forge.view.home; package forge.view.toolbox;
import java.awt.Color; import java.awt.Color;
import java.awt.Graphics; import java.awt.Graphics;
@@ -12,7 +12,6 @@ import javax.swing.SwingConstants;
import javax.swing.border.LineBorder; import javax.swing.border.LineBorder;
import forge.Singletons; import forge.Singletons;
import forge.view.toolbox.FSkin;
/** /**
* Standard button used for for submenus on the home screen. * Standard button used for for submenus on the home screen.
@@ -21,6 +20,8 @@ import forge.view.toolbox.FSkin;
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class SubButton extends JButton { public class SubButton extends JButton {
private FSkin skin; private FSkin skin;
private final Color clrHover, clrInactive;
/** */ /** */
public SubButton() { public SubButton() {
this(""); this("");
@@ -34,20 +35,23 @@ public class SubButton extends JButton {
*/ */
public SubButton(String txt0) { public SubButton(String txt0) {
super(txt0); super(txt0);
skin = Singletons.getView().getSkin(); this.skin = Singletons.getView().getSkin();
this.clrHover = skin.getColor(FSkin.Colors.CLR_HOVER);
this.clrInactive = skin.getColor(FSkin.Colors.CLR_INACTIVE);
setBorder(new LineBorder(skin.getColor(FSkin.Colors.CLR_BORDERS), 1)); setBorder(new LineBorder(skin.getColor(FSkin.Colors.CLR_BORDERS), 1));
setBackground(skin.getColor(FSkin.Colors.CLR_INACTIVE)); setBackground(clrInactive);
setForeground(skin.getColor(FSkin.Colors.CLR_TEXT)); setForeground(skin.getColor(FSkin.Colors.CLR_TEXT));
setVerticalTextPosition(SwingConstants.CENTER); setVerticalTextPosition(SwingConstants.CENTER);
setFocusPainted(false); setFocusPainted(false);
this.addMouseListener(new MouseAdapter() { this.addMouseListener(new MouseAdapter() {
public void mouseEntered(MouseEvent e) { public void mouseEntered(MouseEvent e) {
if (isEnabled()) { setBackground(skin.getColor(FSkin.Colors.CLR_HOVER)); } if (isEnabled() && !isSelected()) { setBackground(clrHover); }
} }
public void mouseExited(MouseEvent e) { public void mouseExited(MouseEvent e) {
if (isEnabled()) { setBackground(skin.getColor(FSkin.Colors.CLR_INACTIVE)); } if (isEnabled() && !isSelected()) { setBackground(clrInactive); }
} }
}); });
@@ -70,6 +74,11 @@ public class SubButton extends JButton {
else { setBackground(new Color(220, 220, 220)); } else { setBackground(new Color(220, 220, 220)); }
} }
@Override
public void setSelected(boolean b0) {
super.setSelected(b0);
}
@Override @Override
public void paintComponent(Graphics g) { public void paintComponent(Graphics g) {
g.setColor(getBackground()); g.setColor(getBackground());

View File

@@ -1,4 +1,4 @@
package forge.view.home; package forge.view.toolbox;
import java.awt.Color; import java.awt.Color;
import java.awt.Cursor; import java.awt.Cursor;
@@ -10,7 +10,6 @@ import javax.swing.JLabel;
import javax.swing.JPanel; import javax.swing.JPanel;
import forge.Singletons; import forge.Singletons;
import forge.view.toolbox.FSkin;
/** Standardized tab for submenus in home screen. */ /** Standardized tab for submenus in home screen. */
public class SubTab extends JPanel { public class SubTab extends JPanel {