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/FTitleBar.java -text
forge-gui/src/main/java/forge/view/FTitleBarBase.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/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/Main.java -text
forge-gui/src/main/java/forge/view/SplashFrame.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 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.Point;
import java.awt.RenderingHints; import java.awt.RenderingHints;
import java.awt.Toolkit; import java.awt.Toolkit;
import java.awt.Window;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@@ -82,7 +83,7 @@ public enum FSkin {
for (ComponentSkin compSkin : ComponentSkin.skins.values()) { for (ComponentSkin compSkin : ComponentSkin.skins.values()) {
compSkin.reapply(); compSkin.reapply();
} }
for (JFrameSkin compSkin : JFrameSkin.skins.values()) { for (WindowSkin compSkin : WindowSkin.skins.values()) {
compSkin.reapply(); compSkin.reapply();
} }
for (JComponentSkin compSkin : JComponentSkin.skins.values()) { 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") @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 SkinImage iconImage;
private JFrameSkin(T comp0) { private WindowSkin(T comp0) {
super(comp0); super(comp0);
} }
@@ -490,11 +491,11 @@ public enum FSkin {
return compSkin; return compSkin;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static <T extends JFrame> JFrameSkin<T> get(T comp) { public static <T extends Window> WindowSkin<T> get(T comp) {
JFrameSkin<T> compSkin = JFrameSkin.skins.get(comp); WindowSkin<T> compSkin = WindowSkin.skins.get(comp);
if (compSkin == null) { if (compSkin == null) {
compSkin = new JFrameSkin<T>(comp); compSkin = new WindowSkin<T>(comp);
JFrameSkin.skins.put(comp, compSkin); WindowSkin.skins.put(comp, compSkin);
} }
return compSkin; return compSkin;
} }

View File

@@ -1,10 +1,28 @@
package forge.view; 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.JDialog;
import javax.swing.JOptionPane; 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") @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() { public FDialog() {
this(true); this(true);
@@ -12,6 +30,14 @@ public class FDialog extends JDialog {
public FDialog(boolean modal0) { public FDialog(boolean modal0) {
super(JOptionPane.getRootFrame(), 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 @Override
@@ -21,4 +47,93 @@ public class FDialog extends JDialog {
} }
super.setVisible(visible); 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; import forge.properties.ForgePreferences.FPref;
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class FFrame extends JFrame { public class FFrame extends JFrame implements ITitleBarOwner {
private static final int borderThickness = 3; private static final int borderThickness = 3;
private Point locBeforeMove; private Point locBeforeMove;
private Dimension sizeBeforeResize; private Dimension sizeBeforeResize;

View File

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

View File

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

View File

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