Skin FDialog

This commit is contained in:
drdev
2013-12-13 07:29:55 +00:00
parent 5b18ba9058
commit a04e5c1da2
8 changed files with 227 additions and 76 deletions

1
.gitattributes vendored
View File

@@ -15646,6 +15646,7 @@ forge-gui/src/main/java/forge/view/FNavigationBar.java -text
forge-gui/src/main/java/forge/view/FTitleBar.java -text
forge-gui/src/main/java/forge/view/FTitleBarBase.java -text
forge-gui/src/main/java/forge/view/FView.java -text
forge-gui/src/main/java/forge/view/ITitleBarOwner.java -text
forge-gui/src/main/java/forge/view/Main.java -text
forge-gui/src/main/java/forge/view/SplashFrame.java -text
forge-gui/src/main/java/forge/view/arcane/CardArea.java svneol=native#text/plain

View File

@@ -29,6 +29,7 @@ import java.awt.Image;
import java.awt.Point;
import java.awt.RenderingHints;
import java.awt.Toolkit;
import java.awt.Window;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
@@ -82,7 +83,7 @@ public enum FSkin {
for (ComponentSkin compSkin : ComponentSkin.skins.values()) {
compSkin.reapply();
}
for (JFrameSkin compSkin : JFrameSkin.skins.values()) {
for (WindowSkin compSkin : WindowSkin.skins.values()) {
compSkin.reapply();
}
for (JComponentSkin compSkin : JComponentSkin.skins.values()) {
@@ -211,13 +212,13 @@ public enum FSkin {
}
}
}
public static class JFrameSkin<T extends JFrame> extends ComponentSkin<T> {
public static class WindowSkin<T extends Window> extends ComponentSkin<T> {
@SuppressWarnings("rawtypes")
private static HashMap<JFrame, JFrameSkin> skins = new HashMap<JFrame, JFrameSkin>();
private static HashMap<Window, WindowSkin> skins = new HashMap<Window, WindowSkin>();
private SkinImage iconImage;
private JFrameSkin(T comp0) {
private WindowSkin(T comp0) {
super(comp0);
}
@@ -490,11 +491,11 @@ public enum FSkin {
return compSkin;
}
@SuppressWarnings("unchecked")
public static <T extends JFrame> JFrameSkin<T> get(T comp) {
JFrameSkin<T> compSkin = JFrameSkin.skins.get(comp);
public static <T extends Window> WindowSkin<T> get(T comp) {
WindowSkin<T> compSkin = WindowSkin.skins.get(comp);
if (compSkin == null) {
compSkin = new JFrameSkin<T>(comp);
JFrameSkin.skins.put(comp, compSkin);
compSkin = new WindowSkin<T>(comp);
WindowSkin.skins.put(comp, compSkin);
}
return compSkin;
}

View File

@@ -1,19 +1,45 @@
package forge.view;
import java.awt.Color;
import java.awt.Image;
import java.awt.Point;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import javax.swing.BorderFactory;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import forge.gui.toolbox.FSkin;
import forge.gui.toolbox.FSkin.Colors;
import forge.gui.toolbox.FSkin.CompoundSkinBorder;
import forge.gui.toolbox.FSkin.LineSkinBorder;
@SuppressWarnings("serial")
public class FDialog extends JDialog {
public class FDialog extends JDialog implements ITitleBarOwner {
private static final int borderThickness = 3;
private Point locBeforeMove;
private Point mouseDownLoc;
private final FTitleBar titleBar;
public FDialog() {
this(true);
}
public FDialog(boolean modal0) {
super(JOptionPane.getRootFrame(), modal0);
this.setUndecorated(true);
FSkin.get(this).setIconImage(FSkin.getIcon(FSkin.InterfaceIcons.ICO_FAVICON)); //use Forge icon by default
titleBar = new FTitleBar(this);
titleBar.setVisible(true);
addMoveSupport();
FSkin.get(getRootPane()).setBorder(new CompoundSkinBorder(
BorderFactory.createLineBorder(Color.BLACK, 1),
new LineSkinBorder(FSkin.getColor(Colors.CLR_BORDERS), borderThickness - 1)));
}
@Override
public void setVisible(boolean visible) {
if (visible) {
@@ -21,4 +47,93 @@ public class FDialog extends JDialog {
}
super.setVisible(visible);
}
@Override
public void setTitle(String title) {
super.setTitle(title);
if (this.titleBar != null) {
this.titleBar.setTitle(title);
}
}
@Override
public void setIconImage(Image image) {
super.setIconImage(image);
if (this.titleBar != null) {
this.titleBar.setIconImage(image);
}
}
private void addMoveSupport() {
this.titleBar.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
if (SwingUtilities.isLeftMouseButton(e)) {
if (e.getClickCount() == 1) {
locBeforeMove = getLocation();
mouseDownLoc = e.getLocationOnScreen();
}
}
}
@Override
public void mouseReleased(MouseEvent e) {
if (SwingUtilities.isLeftMouseButton(e)) {
locBeforeMove = null;
mouseDownLoc = null;
}
}
});
this.titleBar.addMouseMotionListener(new MouseMotionAdapter() {
@Override
public void mouseDragged(MouseEvent e) {
if (mouseDownLoc != null) {
final Point loc = e.getLocationOnScreen();
final int dx = loc.x - mouseDownLoc.x;
final int dy = loc.y - mouseDownLoc.y;
setLocation(locBeforeMove.x + dx, locBeforeMove.y + dy);
}
}
});
}
@Override
public boolean isMinimized() {
return false;
}
@Override
public void setMinimized(boolean b) {
}
@Override
public boolean isMaximized() {
return false;
}
@Override
public void setMaximized(boolean b) {
}
@Override
public boolean isFullScreen() {
return false;
}
@Override
public void setFullScreen(boolean b) {
}
@Override
public boolean getLockTitleBar() {
return false;
}
@Override
public void setLockTitleBar(boolean b) {
}
@Override
public Image getIconImage() {
return getIconImages().isEmpty() ? null : getIconImages().get(0);
}
}

View File

@@ -30,7 +30,7 @@ import forge.properties.ForgePreferences;
import forge.properties.ForgePreferences.FPref;
@SuppressWarnings("serial")
public class FFrame extends JFrame {
public class FFrame extends JFrame implements ITitleBarOwner {
private static final int borderThickness = 3;
private Point locBeforeMove;
private Dimension sizeBeforeResize;
@@ -43,11 +43,11 @@ public class FFrame extends JFrame {
public FFrame() {
setUndecorated(true);
}
public void initialize() {
initialize(new FTitleBar(this));
}
public void initialize(FTitleBarBase titleBar0) {
this.isMainFrame = (FView.SINGLETON_INSTANCE.getFrame() == this);
@@ -79,11 +79,11 @@ public class FFrame extends JFrame {
public FTitleBarBase getTitleBar() {
return this.titleBar;
}
public boolean getLockTitleBar() {
return this.lockTitleBar;
}
public void setLockTitleBar(boolean lockTitleBar0) {
if (this.lockTitleBar == lockTitleBar0) { return; }
this.lockTitleBar = lockTitleBar0;
@@ -94,11 +94,11 @@ public class FFrame extends JFrame {
}
updateTitleBar();
}
public boolean isTitleBarHidden() {
return this.hideTitleBar;
}
private void updateTitleBar() {
this.titleBar.updateButtons();
if (this.hideTitleBar == (this.fullScreen && !this.lockTitleBar)) {
@@ -110,7 +110,7 @@ public class FFrame extends JFrame {
SResizingUtil.resizeWindow(); //ensure window layout updated to account for titlebar visibility change
}
}
@Override
public void setTitle(String title) {
super.setTitle(title);
@@ -118,7 +118,7 @@ public class FFrame extends JFrame {
this.titleBar.setTitle(title);
}
}
@Override
public void setIconImage(Image image) {
super.setIconImage(image);
@@ -126,7 +126,7 @@ public class FFrame extends JFrame {
this.titleBar.setIconImage(image);
}
}
//ensure un-maximized if location or size changed
@Override
public void setLocation(Point point) {
@@ -148,7 +148,7 @@ public class FFrame extends JFrame {
resetState();
super.setSize(width, height);
}
private void resetState() {
if (this.minimized || this.maximized || this.fullScreen) {
this.minimized = false;
@@ -160,25 +160,25 @@ public class FFrame extends JFrame {
updateState();
}
}
public void setWindowLayout(int x, int y, int width, int height, boolean maximized0, boolean fullScreen0) {
this.normalBounds = new Rectangle(x, y, width, height);
this.maximized = maximized0;
this.fullScreen = fullScreen0;
updateState();
}
public Rectangle getNormalBounds() {
return this.normalBounds;
}
public void updateNormalBounds() {
if (this.minimized || this.maximized || this.fullScreen) {
return;
}
this.normalBounds = this.getBounds();
}
public boolean isMinimized() {
return this.minimized;
}
@@ -188,7 +188,7 @@ public class FFrame extends JFrame {
this.minimized = minimized0;
updateState();
}
public boolean isMaximized() {
return this.maximized;
}
@@ -198,7 +198,7 @@ public class FFrame extends JFrame {
this.maximized = maximized0;
updateState();
}
public boolean isFullScreen() {
return this.fullScreen;
}
@@ -211,7 +211,7 @@ public class FFrame extends JFrame {
}
updateState();
}
private void updateState() {
if (this.minimized) {
super.setExtendedState(Frame.ICONIFIED);
@@ -238,7 +238,7 @@ public class FFrame extends JFrame {
this.setBounds(this.normalBounds);
}
}
private void updateBorder() {
if (this.minimized || this.hideBorder == (this.maximized || this.fullScreen)) {
return; //don't update border if minimized or border visibility wouldn't change
@@ -249,11 +249,11 @@ public class FFrame extends JFrame {
}
else {
FSkin.get(getRootPane()).setBorder(new CompoundSkinBorder(
BorderFactory.createLineBorder(Color.BLACK, 1),
BorderFactory.createLineBorder(Color.BLACK, 1),
new LineSkinBorder(FSkin.getColor(Colors.CLR_BORDERS), borderThickness - 1)));
}
}
//override normal state behavior
@Override
public void setState(int state) {
@@ -272,7 +272,7 @@ public class FFrame extends JFrame {
updateState();
}
}
private void addMoveSupport() {
this.titleBar.addMouseListener(new MouseAdapter() {
@Override
@@ -307,12 +307,12 @@ public class FFrame extends JFrame {
}
});
}
private void setResizeCursor(int resizeCursor0) {
this.resizeCursor = resizeCursor0;
this.getRootPane().setCursor(Cursor.getPredefinedCursor(resizeCursor0));
}
private void addResizeSupport() {
final JRootPane resizeBorders = getRootPane();
resizeBorders.addMouseListener(new MouseAdapter() {
@@ -386,7 +386,7 @@ public class FFrame extends JFrame {
final Point loc = e.getLocationOnScreen();
int dx = loc.x - mouseDownLoc.x;
int dy = loc.y - mouseDownLoc.y;
//determine new size based on resize direction
int width = sizeBeforeResize.width;
int height = sizeBeforeResize.height;
@@ -420,7 +420,7 @@ public class FFrame extends JFrame {
height -= dy;
break;
}
//ensure new size in bounds
Dimension minSize = getMinimumSize();
Dimension maxSize = getMaximumSize();
@@ -440,7 +440,7 @@ public class FFrame extends JFrame {
dy -= (height - maxSize.height);
height = maxSize.height;
}
//determine new location based on resize direction
int x = locBeforeMove.x;
int y = locBeforeMove.y;
@@ -458,7 +458,7 @@ public class FFrame extends JFrame {
y += dy;
break;
}
//set bounds based on new size and location
setBounds(x, y, width, height);
}

View File

@@ -57,7 +57,7 @@ public class FNavigationBar extends FTitleBarBase {
public FNavigationBar(FFrame f) {
super(f);
this.setLocation(0, -visibleHeight); //hide by default
this.setPreferredSize(new Dimension(this.frame.getWidth(), visibleHeight));
this.setPreferredSize(new Dimension(this.owner.getWidth(), visibleHeight));
btnForge.setFocusable(false);
btnForge.setPreferredSize(new Dimension(100, 23));
FSkin.get(btnForge).setForeground(foreColor);
@@ -190,7 +190,7 @@ public class FNavigationBar extends FTitleBarBase {
//only show clock if Full Screen
private void updateClockVisibility() {
clock.setVisible(this.frame.isFullScreen());
clock.setVisible(this.owner.isFullScreen());
}
private void addForgeButtonListeners() {

View File

@@ -10,11 +10,11 @@ import forge.gui.toolbox.FSkin;
public class FTitleBar extends FTitleBarBase {
private final JLabel lblTitle = new JLabel();
public FTitleBar(FFrame f) {
super(f);
f.setJMenuBar(this);
setTitle(f.getTitle()); //set default title based on frame title
setIconImage(f.getIconImage()); //set default icon image based on frame icon image
public FTitleBar(ITitleBarOwner owner0) {
super(owner0);
owner0.setJMenuBar(this);
setTitle(owner0.getTitle()); //set default title based on frame title
setIconImage(owner0.getIconImage()); //set default icon image based on frame icon image
FSkin.get(lblTitle).setForeground(foreColor);
addControls();
}

View File

@@ -7,6 +7,7 @@ import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.RenderingHints;
import java.awt.Toolkit;
import java.awt.Window;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowEvent;
@@ -34,7 +35,7 @@ public abstract class FTitleBarBase extends JMenuBar {
protected static final SkinColor buttonDownColor = backColor.stepColor(-40);
protected static final SkinColor buttonToggleColor = backColor.stepColor(-30);
protected final FFrame frame;
protected final ITitleBarOwner owner;
protected final JComponentSkin<FTitleBarBase> skin = FSkin.get(this);
protected final SpringLayout layout = new SpringLayout();
protected final LockTitleBarButton btnLockTitleBar = new LockTitleBarButton();
@@ -43,8 +44,8 @@ public abstract class FTitleBarBase extends JMenuBar {
protected final MaximizeButton btnMaximize = new MaximizeButton();
protected final CloseButton btnClose = new CloseButton();
protected FTitleBarBase(FFrame f) {
this.frame = f;
protected FTitleBarBase(ITitleBarOwner owner0) {
this.owner = owner0;
setVisible(false); //start out hidden unless frame chooses to show title bar
setLayout(this.layout);
skin.setBackground(backColor);
@@ -56,35 +57,37 @@ public abstract class FTitleBarBase extends JMenuBar {
layout.putConstraint(SpringLayout.EAST, btnClose, 0, SpringLayout.EAST, this);
layout.putConstraint(SpringLayout.SOUTH, btnClose, 0, SpringLayout.SOUTH, this);
add(btnMaximize);
layout.putConstraint(SpringLayout.EAST, btnMaximize, 0, SpringLayout.WEST, btnClose);
layout.putConstraint(SpringLayout.SOUTH, btnMaximize, 0, SpringLayout.SOUTH, btnClose);
add(btnFullScreen);
layout.putConstraint(SpringLayout.EAST, btnFullScreen, 0, SpringLayout.WEST, btnMaximize);
layout.putConstraint(SpringLayout.SOUTH, btnFullScreen, 0, SpringLayout.SOUTH, btnMaximize);
add(btnMinimize);
layout.putConstraint(SpringLayout.EAST, btnMinimize, 0, SpringLayout.WEST, btnFullScreen);
layout.putConstraint(SpringLayout.SOUTH, btnMinimize, 0, SpringLayout.SOUTH, btnFullScreen);
add(btnLockTitleBar);
layout.putConstraint(SpringLayout.EAST, btnLockTitleBar, 0, SpringLayout.WEST, btnMinimize);
layout.putConstraint(SpringLayout.SOUTH, btnLockTitleBar, 0, SpringLayout.SOUTH, btnMinimize);
if (owner instanceof FFrame) { //only support buttons besides Close for frames
add(btnMaximize);
layout.putConstraint(SpringLayout.EAST, btnMaximize, 0, SpringLayout.WEST, btnClose);
layout.putConstraint(SpringLayout.SOUTH, btnMaximize, 0, SpringLayout.SOUTH, btnClose);
add(btnFullScreen);
layout.putConstraint(SpringLayout.EAST, btnFullScreen, 0, SpringLayout.WEST, btnMaximize);
layout.putConstraint(SpringLayout.SOUTH, btnFullScreen, 0, SpringLayout.SOUTH, btnMaximize);
add(btnMinimize);
layout.putConstraint(SpringLayout.EAST, btnMinimize, 0, SpringLayout.WEST, btnFullScreen);
layout.putConstraint(SpringLayout.SOUTH, btnMinimize, 0, SpringLayout.SOUTH, btnFullScreen);
add(btnLockTitleBar);
layout.putConstraint(SpringLayout.EAST, btnLockTitleBar, 0, SpringLayout.WEST, btnMinimize);
layout.putConstraint(SpringLayout.SOUTH, btnLockTitleBar, 0, SpringLayout.SOUTH, btnMinimize);
}
}
public abstract void setTitle(String title);
public abstract void setIconImage(Image image);
public void updateButtons() {
boolean fullScreen = frame.isFullScreen();
boolean fullScreen = owner.isFullScreen();
btnLockTitleBar.setVisible(fullScreen);
btnMaximize.setVisible(!fullScreen);
if (fullScreen) {
layout.putConstraint(SpringLayout.EAST, btnFullScreen, 0, SpringLayout.WEST, btnClose);
btnFullScreen.setToolTipText("Exit Full Screen (F11)");
if (frame.getLockTitleBar()) {
if (owner.getLockTitleBar()) {
btnLockTitleBar.setToolTipText("Unlock Title Bar");
}
else {
@@ -95,7 +98,7 @@ public abstract class FTitleBarBase extends JMenuBar {
else {
layout.putConstraint(SpringLayout.EAST, btnFullScreen, 0, SpringLayout.WEST, btnMaximize);
btnFullScreen.setToolTipText("Full Screen (F11)");
if (frame.isMaximized()) {
if (owner.isMaximized()) {
btnMaximize.setToolTipText("Restore Down");
}
else {
@@ -112,7 +115,7 @@ public abstract class FTitleBarBase extends JMenuBar {
@Override
public void setVisible(boolean visible) {
//use height 0 to hide rather than setting visible to false to allow menu item accelerators to work
setPreferredSize(new Dimension(this.frame.getWidth(), visible ? visibleHeight : 0));
setPreferredSize(new Dimension(this.owner.getWidth(), visible ? visibleHeight : 0));
revalidate();
}
@@ -207,11 +210,11 @@ public abstract class FTitleBarBase extends JMenuBar {
}
@Override
protected void onClick() {
frame.setLockTitleBar(!frame.getLockTitleBar());
owner.setLockTitleBar(!owner.getLockTitleBar());
}
@Override
protected boolean isToggled() {
return frame.getLockTitleBar();
return owner.getLockTitleBar();
}
@Override
public void paintComponent(Graphics g) {
@@ -241,7 +244,7 @@ public abstract class FTitleBarBase extends JMenuBar {
}
@Override
protected void onClick() {
frame.setMinimized(true);
owner.setMinimized(true);
}
@Override
public void paintComponent(Graphics g) {
@@ -267,7 +270,7 @@ public abstract class FTitleBarBase extends JMenuBar {
}
@Override
protected void onClick() {
frame.setFullScreen(!frame.isFullScreen());
owner.setFullScreen(!owner.isFullScreen());
}
@Override
public void paintComponent(Graphics g) {
@@ -284,7 +287,7 @@ public abstract class FTitleBarBase extends JMenuBar {
Graphics2D g2d = (Graphics2D) g;
skin.setGraphicsColor(g2d, foreColor);
if (frame.isFullScreen()) { //draw arrows facing inward
if (owner.isFullScreen()) { //draw arrows facing inward
g2d.drawLine(x1 + arrowLength, y1, x1 + arrowLength, y1 + arrowLength);
g2d.drawLine(x1, y1 + arrowLength, x1 + arrowLength, y1 + arrowLength);
g2d.drawLine(x2 - arrowLength, y1, x2 - arrowLength, y1 + arrowLength);
@@ -325,7 +328,7 @@ public abstract class FTitleBarBase extends JMenuBar {
}
@Override
protected void onClick() {
frame.setMaximized(!frame.isMaximized());
owner.setMaximized(!owner.isMaximized());
}
@Override
public void paintComponent(Graphics g) {
@@ -343,7 +346,7 @@ public abstract class FTitleBarBase extends JMenuBar {
skin.setGraphicsColor(g2d, foreColor);
g2d.setStroke(new BasicStroke(thickness));
if (frame.isMaximized()) { //draw 2 rectangles offset if icon to restore window
if (owner.isMaximized()) { //draw 2 rectangles offset if icon to restore window
x -= 1;
y += 2;
width -= 1;
@@ -371,7 +374,7 @@ public abstract class FTitleBarBase extends JMenuBar {
}
@Override
protected void onClick() {
WindowEvent wev = new WindowEvent(frame, WindowEvent.WINDOW_CLOSING);
WindowEvent wev = new WindowEvent((Window)owner, WindowEvent.WINDOW_CLOSING);
Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(wev);
}
@Override

View File

@@ -0,0 +1,31 @@
package forge.view;
import java.awt.Image;
import javax.swing.JMenuBar;
public interface ITitleBarOwner {
boolean isMinimized();
void setMinimized(boolean b);
boolean isMaximized();
void setMaximized(boolean b);
boolean isFullScreen();
void setFullScreen(boolean b);
boolean getLockTitleBar();
void setLockTitleBar(boolean b);
int getWidth();
void setJMenuBar(JMenuBar menuBar);
String getTitle();
Image getIconImage();
}