From 9ced7cf9530cb1cc7446dbbae4b5c6a607de01d5 Mon Sep 17 00:00:00 2001 From: Ida Massow Date: Wed, 22 Jun 2011 04:02:38 +0200 Subject: View Methoden-Sichtbarkeit korrigiert git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@574 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/view/impl/StonePainter.java | 112 ++++++++++++++++-------------- 1 file changed, 60 insertions(+), 52 deletions(-) (limited to 'src/jrummikub/view/impl/StonePainter.java') diff --git a/src/jrummikub/view/impl/StonePainter.java b/src/jrummikub/view/impl/StonePainter.java index 143ef86..56a41bf 100644 --- a/src/jrummikub/view/impl/StonePainter.java +++ b/src/jrummikub/view/impl/StonePainter.java @@ -46,11 +46,11 @@ class StonePainter { /** * The width of one pixel in the scale of 1.0 */ - public static final double WIDTH_SCALE = 1 / DEFAULT_WIDTH; + static final double WIDTH_SCALE = 1 / DEFAULT_WIDTH; /** * The height of one pixel in the scale of 1.0 */ - public static final double HEIGHT_SCALE = ASPECT_RATIO / DEFAULT_WIDTH; + static final double HEIGHT_SCALE = ASPECT_RATIO / DEFAULT_WIDTH; private double scale; @@ -63,7 +63,8 @@ class StonePainter { int g = (int) (color.getGreen() * BRIGHTER_SCALE); int b = (int) (color.getBlue() * BRIGHTER_SCALE); - return new Color(r > 255 ? 255 : r, g > 255 ? 255 : g, b > 255 ? 255 : b); + return new Color(r > 255 ? 255 : r, g > 255 ? 255 : g, b > 255 ? 255 + : b); } private static Color hover(Color color) { @@ -71,7 +72,8 @@ class StonePainter { int g = (int) (color.getGreen() * HOVER_RATIO + 255 * (1 - HOVER_RATIO)); int b = (int) (color.getBlue() * HOVER_RATIO + 255 * (1 - HOVER_RATIO)); - return new Color(r > 255 ? 255 : r, g > 255 ? 255 : g, b > 255 ? 255 : b); + return new Color(r > 255 ? 255 : r, g > 255 ? 255 : g, b > 255 ? 255 + : b); } private static Color redden(Color color) { @@ -79,27 +81,28 @@ class StonePainter { int g = (int) (color.getGreen() * REDDEN_RATIO + 128 * (1 - REDDEN_RATIO)); int b = (int) (color.getBlue() * REDDEN_RATIO + 128 * (1 - REDDEN_RATIO)); - return new Color(r > 255 ? 255 : r, g > 255 ? 255 : g, b > 255 ? 255 : b); + return new Color(r > 255 ? 255 : r, g > 255 ? 255 : g, b > 255 ? 255 + : b); } - public static Color getColor(StoneColor color) { + static Color getColor(StoneColor color) { switch (color) { - case BLACK: - return new Color(0.0f, 0.0f, 0.0f); - case BLUE: - return new Color(0.0f, 0.0f, 1.0f); - case ORANGE: - return new Color(1.0f, 0.4f, 0.0f); - case RED: - return new Color(0.9f, 0.0f, 0.25f); - case AQUA: - return new Color(0.0f, 0.85f, 0.75f); - case GREEN: - return new Color(0.0f, 0.65f, 0.0f); - case VIOLET: - return new Color(0.75f, 0.325f, 0.75f); - case GRAY: - return new Color(0.5f, 0.5f, 0.5f); + case BLACK: + return new Color(0.0f, 0.0f, 0.0f); + case BLUE: + return new Color(0.0f, 0.0f, 1.0f); + case ORANGE: + return new Color(1.0f, 0.4f, 0.0f); + case RED: + return new Color(0.9f, 0.0f, 0.25f); + case AQUA: + return new Color(0.0f, 0.85f, 0.75f); + case GREEN: + return new Color(0.0f, 0.65f, 0.0f); + case VIOLET: + return new Color(0.75f, 0.325f, 0.75f); + case GRAY: + return new Color(0.5f, 0.5f, 0.5f); } return null; @@ -109,9 +112,9 @@ class StonePainter { * Sets the new grid scale * * @param scale - * the new scale + * the new scale */ - public void setScale(double scale) { + void setScale(double scale) { this.scale = scale; if (this.scale == 0) { @@ -123,12 +126,12 @@ class StonePainter { /** * @param x - * x position in screen coordinates + * x position in screen coordinates * @param y - * y position in screen coordinates + * y position in screen coordinates * @return position in grid coordinates */ - public Position calculatePosition(int x, int y) { + Position calculatePosition(int x, int y) { double width = getStoneWidth(); double height = getStoneHeight(); @@ -138,14 +141,14 @@ class StonePainter { /** * @return the width of a stone in the current scale in pixels */ - public int getStoneWidth() { + int getStoneWidth() { return Math.max(even(DEFAULT_WIDTH * scale), 1); } /** * @return the height of a stone in the current scale in pixels */ - public int getStoneHeight() { + int getStoneHeight() { return Math.max((int) (DEFAULT_WIDTH * scale / ASPECT_RATIO), 1); } @@ -219,21 +222,24 @@ class StonePainter { hoveredStones.put(state, hoveredStateStones); for (StoneColor color : StoneColor.values()) { - defaultStateStones.put(color, new HashMap()); - hoveredStateStones.put(color, new HashMap()); + defaultStateStones.put(color, + new HashMap()); + hoveredStateStones.put(color, + new HashMap()); } } } /** * @param scale - * the scaling factor for the grid coordinates + * the scaling factor for the grid coordinates */ StonePainter(double scale) { setScale(scale); } - private void paintStoneBackground(Graphics2D g, Rectangle r, Color background) { + private void paintStoneBackground(Graphics2D g, Rectangle r, + Color background) { // Paint background g.setColor(background); g.fillRect(r.x, r.y, r.width, r.height); @@ -334,8 +340,9 @@ class StonePainter { pos + (fm.getAscent() - fm.getDescent()) / 2 + 1); } g.setColor(color); - g.drawString(value, (int) (r.x + r.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, Rectangle r, Color background) { @@ -344,42 +351,43 @@ class StonePainter { // Paint circle g.setColor(background.darker()); - g.drawArc(r.x + r.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) (r.x + r.width / 2 - size / 2), pos - size / 2, size, size, - -130, 170); + g.drawArc((int) (r.x + r.width / 2 - size / 2), pos - size / 2, size, + size, -130, 170); } /** * Paints a stone * * @param g - * the graphics context to paint the stone on + * the graphics context to paint the stone on * @param stone - * the stone to paint + * the stone to paint * @param p - * the position of the stone + * the position of the stone * @param state - * if the stone is selected the stone will be painted darker, if it - * is invalid it will be painted in red + * if the stone is selected the stone will be painted darker, if + * it is invalid it will be painted in red * @param hovered - * if hovered is true the stone will be painted brighter + * if hovered is true the stone will be painted brighter */ - public void paintStone(Graphics2D g, Stone stone, Position p, - StoneState state, boolean hovered) { + void paintStone(Graphics2D g, Stone stone, Position p, StoneState state, + boolean hovered) { int width = getStoneWidth(); int height = getStoneHeight(); - int x = (int) Math.round(p.getX() * width), y = (int) Math.round(p.getY() - * height); + int x = (int) Math.round(p.getX() * width), y = (int) Math.round(p + .getY() * height); if (stone.isJoker()) { - g.drawImage(getStoneImage(stone.getColor(), 0, state, hovered), x, y, - null); + g.drawImage(getStoneImage(stone.getColor(), 0, state, hovered), x, + y, null); } else { g.drawImage( - getStoneImage(stone.getColor(), stone.getValue(), state, hovered), x, - y, null); + getStoneImage(stone.getColor(), stone.getValue(), state, + hovered), x, y, null); } } } -- cgit v1.2.3