summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/view
diff options
context:
space:
mode:
Diffstat (limited to 'src/jrummikub/view')
-rw-r--r--src/jrummikub/view/impl/PlayerPanel.java123
-rw-r--r--src/jrummikub/view/impl/StonePainter.java111
2 files changed, 117 insertions, 117 deletions
diff --git a/src/jrummikub/view/impl/PlayerPanel.java b/src/jrummikub/view/impl/PlayerPanel.java
index 6bc3d09..1d62aab 100644
--- a/src/jrummikub/view/impl/PlayerPanel.java
+++ b/src/jrummikub/view/impl/PlayerPanel.java
@@ -107,40 +107,7 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
});
leftPanel.add(sortByColorButton);
- leftPanel.addComponentListener(new ComponentAdapter() {
- @Override
- public void componentResized(ComponentEvent e) {
- Insets insets = leftPanel.getInsets();
- int x = insets.left, y = insets.top, width = leftPanel.getWidth()
- - insets.left - insets.right, height = leftPanel.getHeight()
- - insets.top - insets.bottom;
-
- if (width > SIDE_PANEL_MAX_WIDTH) {
- x += (width - SIDE_PANEL_MAX_WIDTH) / 4;
- width = width / 2 + SIDE_PANEL_MAX_WIDTH / 2;
- }
-
- int firstLineHeight = (int) ((height - SIDE_PANEL_SEPARATOR) * SIDE_PANEL_FIRST_LINE_HEIGHT);
- int buttonWidth = (width - SIDE_PANEL_SEPARATOR) / 2;
- int buttonHeight = height - SIDE_PANEL_SEPARATOR - firstLineHeight;
- float fontSize = (float) Math.sqrt(buttonWidth * buttonHeight) / 5;
- if (fontSize > MAX_BUTTON_FONT_SIZE)
- fontSize = MAX_BUTTON_FONT_SIZE;
-
- currentPlayerNameLabel.setBounds(x, y, width, firstLineHeight);
- sortByNumberButton.setBounds(x, y + firstLineHeight
- + SIDE_PANEL_SEPARATOR, buttonWidth, buttonHeight);
- sortByColorButton
- .setBounds(x + buttonWidth + SIDE_PANEL_SEPARATOR, y
- + firstLineHeight + SIDE_PANEL_SEPARATOR, buttonWidth,
- buttonHeight);
-
- sortByNumberButton.setFont(sortByNumberButton.getFont().deriveFont(
- fontSize));
- sortByColorButton.setFont(sortByColorButton.getFont().deriveFont(
- fontSize));
- }
- });
+ leftPanel.addComponentListener(new LeftPanelResizeListener());
}
private void createRightPanel() {
@@ -164,33 +131,7 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
rightPanel.add(endTurnButton);
- rightPanel.addComponentListener(new ComponentAdapter() {
- @Override
- public void componentResized(ComponentEvent e) {
- Insets insets = rightPanel.getInsets();
- int x = insets.left, y = insets.top, width = rightPanel.getWidth()
- - insets.left - insets.right, height = rightPanel.getHeight()
- - insets.top - insets.bottom;
-
- if (width > SIDE_PANEL_MAX_WIDTH) {
- x += (width - SIDE_PANEL_MAX_WIDTH) / 4;
- width = width / 2 + SIDE_PANEL_MAX_WIDTH / 2;
- }
-
- int firstLineHeight = (int) ((height - SIDE_PANEL_SEPARATOR) * SIDE_PANEL_FIRST_LINE_HEIGHT);
- int buttonWidth = width;
- int buttonHeight = height - SIDE_PANEL_SEPARATOR - firstLineHeight;
- float fontSize = (float) Math.sqrt(buttonWidth * buttonHeight) / 5;
- if (fontSize > MAX_BUTTON_FONT_SIZE)
- fontSize = MAX_BUTTON_FONT_SIZE;
-
- timeBar.setBounds(x, y, width, firstLineHeight);
- endTurnButton.setBounds(x, y + firstLineHeight + SIDE_PANEL_SEPARATOR,
- buttonWidth, buttonHeight);
- endTurnButton.setFont(endTurnButton.getFont().deriveFont(
- fontSize));
- }
- });
+ rightPanel.addComponentListener(new RightPanelResizeListener());
}
private void rescale() {
@@ -232,4 +173,64 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
addComponentListener(rescaleListener);
board.addComponentListener(rescaleListener);
}
+
+ private class LeftPanelResizeListener extends ComponentAdapter {
+ @Override
+ public void componentResized(ComponentEvent e) {
+ Insets insets = leftPanel.getInsets();
+ int x = insets.left, y = insets.top, width = leftPanel.getWidth()
+ - insets.left - insets.right, height = leftPanel.getHeight()
+ - insets.top - insets.bottom;
+
+ if (width > SIDE_PANEL_MAX_WIDTH) {
+ x += (width - SIDE_PANEL_MAX_WIDTH) / 4;
+ width = width / 2 + SIDE_PANEL_MAX_WIDTH / 2;
+ }
+
+ int firstLineHeight = (int) ((height - SIDE_PANEL_SEPARATOR) * SIDE_PANEL_FIRST_LINE_HEIGHT);
+ int buttonWidth = (width - SIDE_PANEL_SEPARATOR) / 2;
+ int buttonHeight = height - SIDE_PANEL_SEPARATOR - firstLineHeight;
+ float fontSize = (float) Math.sqrt(buttonWidth * buttonHeight) / 5;
+ if (fontSize > MAX_BUTTON_FONT_SIZE)
+ fontSize = MAX_BUTTON_FONT_SIZE;
+
+ currentPlayerNameLabel.setBounds(x, y, width, firstLineHeight);
+ sortByNumberButton.setBounds(x, y + firstLineHeight
+ + SIDE_PANEL_SEPARATOR, buttonWidth, buttonHeight);
+ sortByColorButton.setBounds(x + buttonWidth + SIDE_PANEL_SEPARATOR, y
+ + firstLineHeight + SIDE_PANEL_SEPARATOR, buttonWidth, buttonHeight);
+
+ sortByNumberButton.setFont(sortByNumberButton.getFont().deriveFont(
+ fontSize));
+ sortByColorButton.setFont(sortByColorButton.getFont()
+ .deriveFont(fontSize));
+ }
+ }
+
+ private class RightPanelResizeListener extends ComponentAdapter {
+ @Override
+ public void componentResized(ComponentEvent e) {
+ Insets insets = rightPanel.getInsets();
+ int x = insets.left, y = insets.top, width = rightPanel.getWidth()
+ - insets.left - insets.right, height = rightPanel.getHeight()
+ - insets.top - insets.bottom;
+
+ if (width > SIDE_PANEL_MAX_WIDTH) {
+ x += (width - SIDE_PANEL_MAX_WIDTH) / 4;
+ width = width / 2 + SIDE_PANEL_MAX_WIDTH / 2;
+ }
+
+ int firstLineHeight = (int) ((height - SIDE_PANEL_SEPARATOR) * SIDE_PANEL_FIRST_LINE_HEIGHT);
+ int buttonWidth = width;
+ int buttonHeight = height - SIDE_PANEL_SEPARATOR - firstLineHeight;
+ float fontSize = (float) Math.sqrt(buttonWidth * buttonHeight) / 5;
+ if (fontSize > MAX_BUTTON_FONT_SIZE)
+ fontSize = MAX_BUTTON_FONT_SIZE;
+
+ timeBar.setBounds(x, y, width, firstLineHeight);
+ endTurnButton.setBounds(x, y + firstLineHeight + SIDE_PANEL_SEPARATOR,
+ buttonWidth, buttonHeight);
+ endTurnButton.setFont(endTurnButton.getFont().deriveFont(fontSize));
+ }
+ }
}
diff --git a/src/jrummikub/view/impl/StonePainter.java b/src/jrummikub/view/impl/StonePainter.java
index f873f2d..ab523a7 100644
--- a/src/jrummikub/view/impl/StonePainter.java
+++ b/src/jrummikub/view/impl/StonePainter.java
@@ -5,6 +5,7 @@ import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
+import java.awt.Rectangle;
import java.awt.Stroke;
import java.awt.geom.GeneralPath;
import java.awt.geom.Rectangle2D;
@@ -26,6 +27,7 @@ class StonePainter {
private static final float BRIGHTER_SCALE = 1.15f;
+ public static final float WIDTH_SCALE = 1 / DEFAULT_WIDTH;
public static final float HEIGHT_SCALE = ASPECT_RATIO / DEFAULT_WIDTH;
private float scale;
@@ -91,121 +93,118 @@ class StonePainter {
this.scale = scale;
}
- private void paintStoneBackground(Graphics2D g, int x, int y, int width,
- int height, Color background) {
+ private void paintStoneBackground(Graphics2D g, Rectangle r, Color background) {
// Paint background
g.setColor(background);
- g.fillRect(x, y, width, height);
+ g.fillRect(r.x, r.y, r.width, r.height);
// Paint bevel border
g.setColor(brighter(brighter(background)));
- g.fillRect(x, y, 1, height);
+ g.fillRect(r.x, r.y, 1, r.height);
g.setColor(brighter(background));
- g.fillRect(x + 1, y + 1, 1, height - 2);
+ g.fillRect(r.x + 1, r.y + 1, 1, r.height - 2);
g.setColor(brighter(brighter(background)));
- g.fillRect(x, y, width, 1);
+ g.fillRect(r.x, r.y, r.width, 1);
g.setColor(brighter(background));
- g.fillRect(x + 1, y + 1, width - 2, 1);
+ g.fillRect(r.x + 1, r.y + 1, r.width - 2, 1);
g.setColor(background.darker().darker());
- g.fillRect(x + width - 1, y, 1, height);
+ g.fillRect(r.x + r.width - 1, r.y, 1, r.height);
g.setColor(background.darker());
- g.fillRect(x + width - 2, y + 1, 1, height - 2);
+ g.fillRect(r.x + r.width - 2, r.y + 1, 1, r.height - 2);
g.setColor(background.darker().darker());
- g.fillRect(x, y + height - 1, width, 1);
+ g.fillRect(r.x, r.y + r.height - 1, r.width, 1);
g.setColor(background.darker());
- g.fillRect(x + 1, y + height - 2, width - 2, 1);
+ g.fillRect(r.x + 1, r.y + r.height - 2, r.width - 2, 1);
}
- private void paintJokerFace(Graphics2D g, int x, int y, int width, int height) {
+ private void paintJokerFace(Graphics2D g, Rectangle r) {
Stroke oldStroke = g.getStroke();
g.setStroke(new BasicStroke(2));
- g.drawOval(x, y, width, height);
+ g.drawOval(r.x, r.y, r.width, r.height);
g.setStroke(new BasicStroke(1));
GeneralPath path = new GeneralPath();
// nose
- path.moveTo(x + 0.5f * width, y + 0.45f * height);
- path.lineTo(x + 0.53f * width, y + 0.6f * height);
- path.lineTo(x + 0.47f * width, y + 0.6f * height);
+ path.moveTo(r.x + 0.5f * r.width, r.y + 0.45f * r.height);
+ path.lineTo(r.x + 0.53f * r.width, r.y + 0.6f * r.height);
+ path.lineTo(r.x + 0.47f * r.width, r.y + 0.6f * r.height);
path.closePath();
g.fill(path);
path.reset();
// mouth, left
- path.moveTo(x + 0.23f * width, y + 0.75f * width);
- path.lineTo(x + 0.27f * width, y + 0.65f * width);
+ path.moveTo(r.x + 0.23f * r.width, r.y + 0.75f * r.width);
+ path.lineTo(r.x + 0.27f * r.width, r.y + 0.65f * r.width);
// mouth, middle
- path.moveTo(x + 0.25f * width, y + 0.7f * width);
- path.lineTo(x + 0.5f * width, y + 0.8f * width);
- path.lineTo(x + 0.75f * width, y + 0.7f * width);
+ path.moveTo(r.x + 0.25f * r.width, r.y + 0.7f * r.width);
+ path.lineTo(r.x + 0.5f * r.width, r.y + 0.8f * r.width);
+ path.lineTo(r.x + 0.75f * r.width, r.y + 0.7f * r.width);
// mouth, right
- path.moveTo(x + 0.77f * width, y + 0.75f * width);
- path.lineTo(x + 0.73f * width, y + 0.65f * width);
+ path.moveTo(r.x + 0.77f * r.width, r.y + 0.75f * r.width);
+ path.lineTo(r.x + 0.73f * r.width, r.y + 0.65f * r.width);
g.draw(path);
path.reset();
// left eye
- path.moveTo(x + 0.3f * width, y + 0.41f * height);
- path.lineTo(x + 0.375f * width, y + 0.375f * height);
- path.lineTo(x + 0.3f * width, y + 0.34f * height);
- path.lineTo(x + 0.225f * width, y + 0.375f * height);
+ path.moveTo(r.x + 0.3f * r.width, r.y + 0.41f * r.height);
+ path.lineTo(r.x + 0.375f * r.width, r.y + 0.375f * r.height);
+ path.lineTo(r.x + 0.3f * r.width, r.y + 0.34f * r.height);
+ path.lineTo(r.x + 0.225f * r.width, r.y + 0.375f * r.height);
path.closePath();
g.draw(path);
path.reset();
// right eye
- path.moveTo(x + 0.7f * width, y + 0.41f * height);
- path.lineTo(x + 0.625f * width, y + 0.375f * height);
- path.lineTo(x + 0.7f * width, y + 0.34f * height);
- path.lineTo(x + 0.775f * width, y + 0.375f * height);
+ path.moveTo(r.x + 0.7f * r.width, r.y + 0.41f * r.height);
+ path.lineTo(r.x + 0.625f * r.width, r.y + 0.375f * r.height);
+ path.lineTo(r.x + 0.7f * r.width, r.y + 0.34f * r.height);
+ path.lineTo(r.x + 0.775f * r.width, r.y + 0.375f * r.height);
path.closePath();
g.draw(path);
g.setStroke(oldStroke);
}
- private void paintJoker(Graphics2D g, int x, int y, int width, int height,
- Color color) {
- int faceSize = even(FACE_WIDTH * width);
- int pos = y + (int) (TEXT_POS * height);
+ private void paintJoker(Graphics2D g, Rectangle r, Color color) {
+ int faceSize = even(FACE_WIDTH * r.width);
+ int pos = r.y + (int) (TEXT_POS * r.height);
g.setColor(color);
- paintJokerFace(g, x + width / 2 - faceSize / 2, pos - faceSize / 2,
- faceSize, faceSize);
+ paintJokerFace(g, new Rectangle(r.x + r.width / 2 - faceSize / 2, pos
+ - faceSize / 2, faceSize, faceSize));
}
- private void paintStoneNumber(Graphics2D g, int x, int y, int width,
- int height, Color color, int v) {
- int pos = y + (int) (TEXT_POS * height);
+ private void paintStoneNumber(Graphics2D g, Rectangle r, Color color, int v) {
+ int pos = r.y + (int) (TEXT_POS * r.height);
- g.setFont(new Font("SansSerif", Font.BOLD, height / 4));
+ g.setFont(new Font("SansSerif", Font.BOLD, r.height / 4));
FontMetrics fm = g.getFontMetrics();
String value = Integer.toString(v);
Rectangle2D stringRect = fm.getStringBounds(value, g);
g.setColor(color.darker());
- g.drawString(value, (int) (x + width / 2 - stringRect.getWidth() / 2) + 1,
+ g.drawString(value,
+ (int) (r.x + r.width / 2 - stringRect.getWidth() / 2) + 1,
pos + (fm.getAscent() - fm.getDescent()) / 2 + 1);
g.setColor(color);
- g.drawString(value, (int) (x + width / 2 - stringRect.getWidth() / 2), pos
- + (fm.getAscent() - fm.getDescent()) / 2);
+ g.drawString(value, (int) (r.x + r.width / 2 - stringRect.getWidth() / 2),
+ pos + (fm.getAscent() - fm.getDescent()) / 2);
}
- private void paintCircle(Graphics2D g, int x, int y, int width, int height,
- Color background) {
- int size = even(width * CIRCLE_WIDTH);
- int pos = y + (int) (CIRCLE_POS * height);
+ private void paintCircle(Graphics2D g, Rectangle r, Color background) {
+ int size = even(r.width * CIRCLE_WIDTH);
+ int pos = r.y + (int) (CIRCLE_POS * r.height);
// Paint circle
g.setColor(background.darker());
- g.drawArc(x + width / 2 - size / 2, pos - size / 2, size, size, 50, 170);
+ g.drawArc(r.x + r.width / 2 - size / 2, pos - size / 2, size, size, 50, 170);
g.setColor(brighter(background));
- g.drawArc((int) (x + width / 2 - size / 2), pos - size / 2, size, size,
+ g.drawArc((int) (r.x + r.width / 2 - size / 2), pos - size / 2, size, size,
-130, 170);
}
@@ -214,21 +213,21 @@ class StonePainter {
int width = getStoneWidth();
int height = getStoneHeight();
- int x = (int) (p.getX() * width);
- int y = (int) (p.getY() * height);
+ Rectangle rect = new Rectangle((int) (p.getX() * width),
+ (int) (p.getY() * height), width, height);
- paintStoneBackground(g, x, y, width, height, background);
+ paintStoneBackground(g, rect, background);
Color color = getColor(stone.getColor());
if (selected)
color = color.darker();
if (stone.isJoker()) {
- paintJoker(g, x, y, width, height, color);
+ paintJoker(g, rect, color);
} else {
- paintStoneNumber(g, x, y, width, height, color, stone.getValue());
+ paintStoneNumber(g, rect, color, stone.getValue());
}
- paintCircle(g, x, y, width, height, background);
+ paintCircle(g, rect, background);
}
}