diff --git a/src/main/java/forge/view/match/ViewTopLevel.java b/src/main/java/forge/view/match/ViewTopLevel.java
index 38c9d677396..7f50d8d98f7 100644
--- a/src/main/java/forge/view/match/ViewTopLevel.java
+++ b/src/main/java/forge/view/match/ViewTopLevel.java
@@ -54,8 +54,7 @@ import forge.properties.ForgePreferences;
import forge.view.toolbox.FPanel;
/**
- * - Lays out battle, sidebar, user areas in locked % vals and repaints as
- * necessary.
+ * - Lays out containers and borders for resizeable layout.
* - Instantiates top-level controller for match UI.
* - Has access methods for all child controllers
* - Implements Display interface used in singleton pattern
@@ -77,13 +76,14 @@ public class ViewTopLevel extends FPanel implements CardContainer, Display {
private double delta;
// Default layout parameters (all in percent!)
- private static final int BOUNDARY_THICKNESS_PX = 6;
- private double rightbarWpct = 0.16;
- private double pictureHpct = 0.5;
+ private double dockWpct = 0.15;
+ private double dockHpct = 0.2;
+ private double tabberHpct = 0.55;
private double battleWpct = 0.68;
private double battleHpct = 0.73;
- private double dockHpct = 0.2;
- private double inputHpct = 0.2;
+ private double pictureHpct = 0.5;
+
+ private static final int BOUNDARY_THICKNESS_PX = 6;
// Boundary rectangles for all components, and boundary panel objects.
private Rectangle pictureBounds, detailBounds, battleBounds,
@@ -112,6 +112,7 @@ public class ViewTopLevel extends FPanel implements CardContainer, Display {
this.setLayout(null);
b = (int) Math.ceil(BOUNDARY_THICKNESS_PX / 2);
+ // Declare and add containers and resizers for various regions in layout
pnlPicture = new RegionPanel();
pnlDetail = new RegionPanel();
pnlBattlefield = new RegionPanel();
@@ -121,10 +122,10 @@ public class ViewTopLevel extends FPanel implements CardContainer, Display {
pnlTabber = new RegionPanel();
pnlB1 = new BoundaryPanel(true);
- pnlB2 = new BoundaryPanel();
- pnlB3 = new BoundaryPanel(true);
- pnlB4 = new BoundaryPanel();
- pnlB5 = new BoundaryPanel(true);
+ pnlB2 = new BoundaryPanel(true);
+ pnlB3 = new BoundaryPanel();
+ pnlB4 = new BoundaryPanel(true);
+ pnlB5 = new BoundaryPanel();
pnlB6 = new BoundaryPanel(true);
add(pnlPicture);
@@ -142,6 +143,7 @@ public class ViewTopLevel extends FPanel implements CardContainer, Display {
add(pnlB5);
add(pnlB6);
+ // Declare and add various view components
input = new ViewInput();
hand = new ViewHand();
dock = new ViewDock();
@@ -168,13 +170,19 @@ public class ViewTopLevel extends FPanel implements CardContainer, Display {
* Panel resizing algorithms. Basically, find the change in % per
* drag event, then add that to an appropriate parameter. In some
* cases, also remove the delta from an appropriate parameter.
+ *
*/
+
+ // Formulas here SHOULD NOT BE VERY COMPLICATED at all. If they're
+ // complicated, you're doing it wrong. The complicated part should
+ // be in calculateBounds().
private void addDragListeners() {
pnlB1.addMouseMotionListener(new MouseMotionAdapter() {
@Override
public void mouseDragged(final MouseEvent e) {
delta = e.getY() / (double) h;
- pictureHpct += delta;
+ dockHpct += delta;
+ tabberHpct -= delta;
repaint();
}
});
@@ -182,14 +190,23 @@ public class ViewTopLevel extends FPanel implements CardContainer, Display {
pnlB2.addMouseMotionListener(new MouseMotionAdapter() {
@Override
public void mouseDragged(final MouseEvent e) {
- delta = e.getX() / (double) w;
- rightbarWpct += delta;
- battleWpct -= delta;
+ delta = e.getY() / (double) h;
+ tabberHpct += delta;
repaint();
}
});
pnlB3.addMouseMotionListener(new MouseMotionAdapter() {
+ @Override
+ public void mouseDragged(final MouseEvent e) {
+ delta = e.getX() / (double) w;
+ battleWpct -= delta;
+ dockWpct += delta;
+ repaint();
+ }
+ });
+
+ pnlB4.addMouseMotionListener(new MouseMotionAdapter() {
@Override
public void mouseDragged(final MouseEvent e) {
delta = e.getY() / (double) h;
@@ -198,7 +215,7 @@ public class ViewTopLevel extends FPanel implements CardContainer, Display {
}
});
- pnlB4.addMouseMotionListener(new MouseMotionAdapter() {
+ pnlB5.addMouseMotionListener(new MouseMotionAdapter() {
@Override
public void mouseDragged(final MouseEvent e) {
delta = e.getX() / (double) w;
@@ -207,21 +224,11 @@ public class ViewTopLevel extends FPanel implements CardContainer, Display {
}
});
- pnlB5.addMouseMotionListener(new MouseMotionAdapter() {
- @Override
- public void mouseDragged(final MouseEvent e) {
- delta = e.getY() / (double) h;
- dockHpct += delta;
- inputHpct -= delta;
- repaint();
- }
- });
-
pnlB6.addMouseMotionListener(new MouseMotionAdapter() {
@Override
public void mouseDragged(final MouseEvent e) {
delta = e.getY() / (double) h;
- inputHpct += delta;
+ pictureHpct += delta;
repaint();
}
});
@@ -230,46 +237,37 @@ public class ViewTopLevel extends FPanel implements CardContainer, Display {
/**
* Put together default layout; most values are dependent
* on sibling component dimensions. The whole layout can be
- * defined from six parameters:
- *
- * rightbarWpct = % width of the right sidebar
- * pictureHpct = % height of card art
- *
- * battleWpct = % width of the battlefield
- * battleHpct = % height of the battlefield
- *
- * dockHpct = % height of the dock
- * inputHpct = % height of the input
+ * defined from six parameters.
*
*/
private void calculateBounds() {
- pictureBounds = new Rectangle(
+ dockBounds = new Rectangle(
b, b,
- (int) (w * rightbarWpct), (int) (h * pictureHpct - 2 * b));
+ (int) (dockWpct * w), (int) (dockHpct * h));
- detailBounds = new Rectangle(
- b, pictureBounds.height + 3 * b,
- pictureBounds.width, h - pictureBounds.height - 4 * b);
+ tabberBounds = new Rectangle(
+ dockBounds.x, dockBounds.height + 3 * b,
+ dockBounds.width, (int) (tabberHpct * h));
+
+ inputBounds = new Rectangle(
+ dockBounds.x, tabberBounds.y + tabberBounds.height + 2 * b,
+ dockBounds.width, h - tabberBounds.y - tabberBounds.height - 3 * b);
battleBounds = new Rectangle(
- pictureBounds.width + 3 * b, b,
+ dockBounds.width + 3 * b, b,
(int) (w * battleWpct), (int) (h * battleHpct));
handBounds = new Rectangle(
battleBounds.x, battleBounds.height + 3 * b,
battleBounds.width, h - battleBounds.height - 4 * b);
- dockBounds = new Rectangle(
- pictureBounds.width + battleBounds.width + 5 * b, b,
- w - pictureBounds.width - battleBounds.width - 6 * b, (int) (h * dockHpct - 2 * b));
+ pictureBounds = new Rectangle(
+ battleBounds.x + battleBounds.width + 2 * b, b,
+ w - battleBounds.x - battleBounds.width - 3 * b, (int) (h * pictureHpct));
- inputBounds = new Rectangle(
- dockBounds.x, dockBounds.height + 2 * b,
- dockBounds.width, (int) (h * inputHpct - b));
-
- tabberBounds = new Rectangle(
- dockBounds.x, inputBounds.y + inputBounds.height + 2 * b,
- dockBounds.width, h - inputBounds.y - inputBounds.height - 3 * b);
+ detailBounds = new Rectangle(
+ pictureBounds.x, pictureBounds.height + 3 * b,
+ pictureBounds.width, h - pictureBounds.height - 4 * b);
// Apply bounds to regions.
pnlPicture.setBounds(pictureBounds);
@@ -282,28 +280,28 @@ public class ViewTopLevel extends FPanel implements CardContainer, Display {
// Apply bounds to boundaries.
pnlB1.setBounds(new Rectangle(
- 0, pictureBounds.height + b,
- pictureBounds.width + b, 2 * b));
+ b, dockBounds.height + b,
+ dockBounds.width, 2 * b));
pnlB2.setBounds(new Rectangle(
- pictureBounds.width + b, 0,
- 2 * b, h));
+ b, dockBounds.height + tabberBounds.height + 3 * b,
+ dockBounds.width, 2 * b));
pnlB3.setBounds(new Rectangle(
- pictureBounds.width + 3 * b, battleBounds.height + b,
- battleBounds.width, 2 * b));
+ dockBounds.width + b, b,
+ 2 * b, h - 2 * b));
pnlB4.setBounds(new Rectangle(
- dockBounds.x - 2 * b, 0,
- 2 * b, h));
+ dockBounds.width + 3 * b, battleBounds.height + b,
+ battleBounds.width, 2 * b));
pnlB5.setBounds(new Rectangle(
- dockBounds.x, dockBounds.height,
- dockBounds.width, 2 * b));
+ battleBounds.width + dockBounds.width + 3 * b, b,
+ 2 * b, h - 2 * b));
pnlB6.setBounds(new Rectangle(
- dockBounds.x, tabberBounds.y - 2 * b,
- dockBounds.width, 2 * b));
+ pictureBounds.x, pictureBounds.height + b,
+ pictureBounds.width, 2 * b));
this.revalidate();
} // End calculateBounds()
@@ -334,7 +332,8 @@ public class ViewTopLevel extends FPanel implements CardContainer, Display {
private class RegionPanel extends JPanel {
public RegionPanel() {
super();
- // For testing, comment this opaque setter. A border helps too.
+ // For testing, comment this opaque setter, uncomment the border.
+ //setBorder(new LineBorder(Color.green, 1));
setOpaque(false);
setLayout(new MigLayout("insets 0, gap 0"));
}
@@ -754,7 +753,7 @@ public class ViewTopLevel extends FPanel implements CardContainer, Display {
if (damage <= 0) {
return;
}
-
+
new GuiMultipleBlockers(attacker, blockers, damage, this);
}
diff --git a/src/main/java/forge/view/toolbox/FVerticalTabPanel.java b/src/main/java/forge/view/toolbox/FVerticalTabPanel.java
index 44a6ccf62ff..60a8a3642f3 100644
--- a/src/main/java/forge/view/toolbox/FVerticalTabPanel.java
+++ b/src/main/java/forge/view/toolbox/FVerticalTabPanel.java
@@ -44,12 +44,23 @@ public class FVerticalTabPanel extends FPanel {
private final CardLayout cards;
private final JPanel pnlContent;
private final List allVTabs;
+ private int w, h;
private final FSkin skin;
private int active;
private final Color activeColor, inactiveColor, hoverColor;
private final Border inactiveBorder, hoverBorder;
+ private boolean tabsOnRightSide;
+
+ /** Constructor, will automatically place tabs on left side.
+ *
+ * @param childPanels JPanels to be placed in tabber
+ */
+ public FVerticalTabPanel(final List childPanels) {
+ this(childPanels, false);
+ }
+
/**
* Assembles vertical tab panel from list of child panels. Tooltip on tab is
* same as tooltip on child panel. Title of tab is same as name of child
@@ -57,10 +68,12 @@ public class FVerticalTabPanel extends FPanel {
*
* @param childPanels
* JPanels to be placed in tabber
+ * @param b boolean, true if tabs are on right side, false for left side.
*/
- public FVerticalTabPanel(final List childPanels) {
+ public FVerticalTabPanel(final List childPanels, boolean b) {
// General inits and skin settings
super();
+ tabsOnRightSide = b;
this.setLayout(new MigLayout("insets 0, gap 0, wrap 2"));
this.setOpaque(false);
final int size = childPanels.size();
@@ -81,14 +94,26 @@ public class FVerticalTabPanel extends FPanel {
this.pnlContent = new JPanel();
this.pnlContent.setOpaque(false);
this.pnlContent.setLayout(this.cards);
- this.pnlContent.setBorder(new MatteBorder(0, 0, 0, 1, this.skin.getClrBorders()));
- this.add(this.pnlContent, "span 1 " + (size + 2) + ", w " + (100 - pctTabW) + "%!, h 100%!");
+ // If tabs are on the left side, content panel is added
+ // immediately to define grid.
+ if (tabsOnRightSide) {
+ this.add(this.pnlContent, "span 1 " + (size + 2) + ", w " + (100 - pctTabW) + "%!, h 100%!");
+ this.pnlContent.setBorder(new MatteBorder(0, 0, 0, 1, this.skin.getClrBorders()));
+ }
+ // Add top spacer in any case.
final JPanel topSpacer = new JPanel();
topSpacer.setOpaque(false);
this.add(topSpacer, "w " + pctTabW + "%!, h " + pctInsetH + "%!");
+ // If tabs are on right side, content panel
+ // must be added after spacer, which then defines the grid.
+ if (!tabsOnRightSide) {
+ this.add(this.pnlContent, "span 1 " + (size + 2) + ", w " + (100 - pctTabW) + "%!, h 100%!");
+ this.pnlContent.setBorder(new MatteBorder(0, 1, 0, 0, this.skin.getClrBorders()));
+ }
+
// Add all tabs
VTab tab;
this.allVTabs = new ArrayList();
@@ -151,9 +176,14 @@ public class FVerticalTabPanel extends FPanel {
public class VTab extends JPanel {
private String msg;
private int id;
- private int w;
// ID is used to retrieve this tab from the list of allVTabs.
+ /**
+ * Creates the actual clickable tab.
+ *
+ * @param txt String text in tab
+ * @param i int index
+ */
VTab(final String txt, final int i) {
super();
this.setLayout(new MigLayout("insets 0, gap 0"));
@@ -192,23 +222,39 @@ public class FVerticalTabPanel extends FPanel {
@Override
protected void paintComponent(final Graphics g) {
super.paintComponent(g);
- this.w = this.getWidth();
+ w = this.getWidth();
+ h = this.getHeight();
// Careful with this font scale factor; the vertical tabs will be
// unreadable
// if small window, too big if large window.
- g.setFont(FVerticalTabPanel.this.skin.getFont1().deriveFont(Font.PLAIN, (int) (this.w * 0.68)));
+ g.setFont(FVerticalTabPanel.this.skin.getFont1().deriveFont(Font.PLAIN, (int) (h * 0.2)));
// Rotate, draw string, rotate back (to allow hover border to be
// painted properly)
final Graphics2D g2d = (Graphics2D) g;
final AffineTransform at = g2d.getTransform();
- at.rotate(Math.toRadians(90), 0, 0);
- g2d.setTransform(at);
- g2d.setColor(AllZone.getSkin().getClrText());
- g2d.drawString(this.msg, 5, -4);
- at.rotate(Math.toRadians(-90), 0, 0);
+ if (tabsOnRightSide) {
+ at.rotate(Math.toRadians(90), 0, 0);
+ g2d.setTransform(at);
+ g2d.setColor(AllZone.getSkin().getClrText());
+ g2d.drawString(this.msg, 5, -4);
+ }
+ else {
+ at.rotate(Math.toRadians(-90), 0, 0);
+ g2d.setTransform(at);
+ g2d.setColor(AllZone.getSkin().getClrText());
+ g2d.drawString(this.msg, 5 - h, w - 4);
+ }
+
+ if (tabsOnRightSide) {
+ at.rotate(Math.toRadians(-90), 0, 0);
+ }
+ else {
+ at.rotate(Math.toRadians(90), 0, 0);
+ }
+
g2d.setTransform(at);
}
@@ -218,6 +264,7 @@ public class FVerticalTabPanel extends FPanel {
}
}
+ /** @return List */
public List getAllVTabs() {
return allVTabs;
}