From 682357b5841f7853212e354199d1a46589663364 Mon Sep 17 00:00:00 2001 From: Ida Massow Date: Mon, 6 Jun 2011 19:53:45 +0200 Subject: Double ist das neue float git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@377 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/view/impl/TablePanel.java | 88 ++++++++++++++++++--------------- 1 file changed, 47 insertions(+), 41 deletions(-) (limited to 'src/jrummikub/view/impl/TablePanel.java') diff --git a/src/jrummikub/view/impl/TablePanel.java b/src/jrummikub/view/impl/TablePanel.java index 7c53d28..93509a6 100644 --- a/src/jrummikub/view/impl/TablePanel.java +++ b/src/jrummikub/view/impl/TablePanel.java @@ -39,17 +39,18 @@ class TablePanel extends AbstractStonePanel implements ITablePanel { private final static ImageIcon BRIGHT_BACKGROUND = new ImageIcon( HandPanel.class.getResource("/jrummikub/resource/bright_felt.png")); - private final static float MIN_VISIBLE_WIDTH = 15; - private final static float MIN_VISIBLE_HEIGHT = 7.5f; - private final static float HORIZONTAL_MARGIN = 1; - private final static float VERTICAL_MARGIN = 0.7f; - private final static float CONNECTOR_WIDTH = 0.25f; - private final float COLLECTION_RATIO = 0.12f; + private final static double MIN_VISIBLE_WIDTH = 15; + private final static double MIN_VISIBLE_HEIGHT = 7.5f; + private final static double HORIZONTAL_MARGIN = 1; + private final static double VERTICAL_MARGIN = 0.7f; + private final static double CONNECTOR_WIDTH = 0.25f; + private final double COLLECTION_RATIO = 0.12f; private final int COLLECTION_GAP = 5; private StoneCollectionPanel stoneCollection; - private Iterable> stoneSets = Collections.emptySet(); + private Iterable> stoneSets = Collections + .emptySet(); private Collection selectedStones = Collections.emptyList(); private Event1 leftConnectorClickEvent = new Event1(); @@ -73,7 +74,7 @@ class TablePanel extends AbstractStonePanel implements ITablePanel { List> stones = new ArrayList>(); for (Pair entry : stoneSets) { - float x = entry.getSecond().getX(), y = entry.getSecond().getY(); + double x = entry.getSecond().getX(), y = entry.getSecond().getY(); for (Stone stone : entry.getFirst()) { stones.add(new Pair(stone, new Position(x, y))); @@ -98,7 +99,7 @@ class TablePanel extends AbstractStonePanel implements ITablePanel { * Sets the currently selected stones * * @param stones - * the selected stones + * the selected stones */ void setSelectedStones(Collection stones) { selectedStones = stones; @@ -134,8 +135,8 @@ class TablePanel extends AbstractStonePanel implements ITablePanel { } private Rectangle2D calculateTableExtent() { - float minx = -MIN_VISIBLE_WIDTH / 2, maxx = MIN_VISIBLE_WIDTH / 2; - float miny = -MIN_VISIBLE_HEIGHT / 2, maxy = MIN_VISIBLE_HEIGHT / 2; + double minx = -MIN_VISIBLE_WIDTH / 2, maxx = MIN_VISIBLE_WIDTH / 2; + double miny = -MIN_VISIBLE_HEIGHT / 2, maxy = MIN_VISIBLE_HEIGHT / 2; for (Pair entry : stoneSets) { Position p = entry.getSecond(); @@ -154,20 +155,20 @@ class TablePanel extends AbstractStonePanel implements ITablePanel { maxy = p.getY() + 1; } - return new Rectangle2D.Float(minx - HORIZONTAL_MARGIN, miny - - VERTICAL_MARGIN, maxx - minx + 2 * HORIZONTAL_MARGIN, maxy - miny + 2 - * VERTICAL_MARGIN); + return new Rectangle2D.Double(minx - HORIZONTAL_MARGIN, miny + - VERTICAL_MARGIN, maxx - minx + 2 * HORIZONTAL_MARGIN, maxy + - miny + 2 * VERTICAL_MARGIN); } private void rescale() { Insets insets = getInsets(); int x = insets.left, y = insets.top, width = getWidth() - insets.left - - insets.right, height = getHeight() - insets.top - insets.bottom; + - insets.right, height = getHeight() - insets.top + - insets.bottom; int collectionHeight = (int) (height * COLLECTION_RATIO); - stoneCollection - .setBounds(x, y + height - collectionHeight - COLLECTION_GAP, width, - collectionHeight); + stoneCollection.setBounds(x, y + height - collectionHeight + - COLLECTION_GAP, width, collectionHeight); setScale(); @@ -180,10 +181,10 @@ class TablePanel extends AbstractStonePanel implements ITablePanel { - insets.top - insets.bottom; Rectangle2D extent = calculateTableExtent(); - float widthScale = width / (float) extent.getWidth() + double widthScale = width / (double) extent.getWidth() * StonePainter.WIDTH_SCALE; - float heightScale = height * (1 - COLLECTION_RATIO) - / (float) extent.getHeight() * StonePainter.HEIGHT_SCALE; + double heightScale = height * (1 - COLLECTION_RATIO) + / (double) extent.getHeight() * StonePainter.HEIGHT_SCALE; getStonePainter().setScale(Math.min(widthScale, heightScale)); } @@ -193,10 +194,10 @@ class TablePanel extends AbstractStonePanel implements ITablePanel { for (Pair entry : stoneSets) { Position p = entry.getSecond(); StoneSet stoneSet = entry.getFirst(); - float x = p.getX(), y = p.getY(); + double x = p.getX(), y = p.getY(); // left connector - Rectangle2D rect = new Rectangle2D.Float(x - CONNECTOR_WIDTH, y, + Rectangle2D rect = new Rectangle2D.Double(x - CONNECTOR_WIDTH, y, CONNECTOR_WIDTH, 1); if (rect.contains(pos.getX(), pos.getY())) { leftConnectorClickEvent.emit(stoneSet); @@ -204,7 +205,8 @@ class TablePanel extends AbstractStonePanel implements ITablePanel { } // right connector - rect = new Rectangle2D.Float(x + stoneSet.getSize(), y, CONNECTOR_WIDTH, 1); + rect = new Rectangle2D.Double(x + stoneSet.getSize(), y, + CONNECTOR_WIDTH, 1); if (rect.contains(pos.getX(), pos.getY())) { rightConnectorClickEvent.emit(stoneSet); return true; @@ -224,10 +226,10 @@ class TablePanel extends AbstractStonePanel implements ITablePanel { for (Pair entry : stoneSets) { Position p = entry.getSecond(); StoneSet stoneSet = entry.getFirst(); - float x = p.getX(), y = p.getY(); + double x = p.getX(), y = p.getY(); // left connector - Rectangle2D rect = new Rectangle2D.Float(x - CONNECTOR_WIDTH, y, + Rectangle2D rect = new Rectangle2D.Double(x - CONNECTOR_WIDTH, y, CONNECTOR_WIDTH, 1); if (rect.contains(pos.getX(), pos.getY())) { leftHoveredConnector = stoneSet; @@ -235,7 +237,8 @@ class TablePanel extends AbstractStonePanel implements ITablePanel { } // right connector - rect = new Rectangle2D.Float(x + stoneSet.getSize(), y, CONNECTOR_WIDTH, 1); + rect = new Rectangle2D.Double(x + stoneSet.getSize(), y, + CONNECTOR_WIDTH, 1); if (rect.contains(pos.getX(), pos.getY())) { rightHoveredConnector = stoneSet; break; @@ -257,15 +260,15 @@ class TablePanel extends AbstractStonePanel implements ITablePanel { .getStoneHeight(); Rectangle2D extent = calculateTableExtent(); - return new Pair((int) (width / 2 - extent.getCenterX() - * stoneWidth), - (int) ((height * (1 - COLLECTION_RATIO)) / 2 - extent.getCenterY() - * stoneHeight)); + return new Pair( + (int) (width / 2 - extent.getCenterX() * stoneWidth), + (int) ((height * (1 - COLLECTION_RATIO)) / 2 - extent + .getCenterY() * stoneHeight)); } private void paintStoneSet(Graphics2D g, StoneSet stoneSet, Position pos, Area connectorArea, Area hoveredConnectorArea) { - float x = pos.getX(); + double x = pos.getX(); int width = getStonePainter().getStoneWidth(), height = getStonePainter() .getStoneHeight(); Area leftConnectorArea = (stoneSet == leftHoveredConnector ? hoveredConnectorArea @@ -275,9 +278,10 @@ class TablePanel extends AbstractStonePanel implements ITablePanel { // Left connector - leftConnectorArea.add(new Area(new Rectangle2D.Float(Math.round(x * width) - - (int) width * CONNECTOR_WIDTH + 1, Math.round(pos.getY() * height), - (int) (width * CONNECTOR_WIDTH), height))); + leftConnectorArea.add(new Area(new Rectangle2D.Double(Math.round(x + * width) + - (int) width * CONNECTOR_WIDTH + 1, Math.round(pos.getY() + * height), (int) (width * CONNECTOR_WIDTH), height))); for (Stone stone : stoneSet) { getStonePainter().paintStone(g, stone, new Position(x, pos.getY()), @@ -286,8 +290,8 @@ class TablePanel extends AbstractStonePanel implements ITablePanel { } // Right connector - rightConnectorArea.add(new Area(new Rectangle2D.Float( - Math.round(x * width), Math.round(pos.getY() * height), + rightConnectorArea.add(new Area(new Rectangle2D.Double(Math.round(x + * width), Math.round(pos.getY() * height), (int) (width * CONNECTOR_WIDTH), height))); } @@ -311,15 +315,16 @@ class TablePanel extends AbstractStonePanel implements ITablePanel { Area hoveredConnectorArea = new Area(); for (Pair entry : stoneSets) { - paintStoneSet(g, entry.getFirst(), entry.getSecond(), connectorArea, - hoveredConnectorArea); + paintStoneSet(g, entry.getFirst(), entry.getSecond(), + connectorArea, hoveredConnectorArea); } g.setClip(connectorArea); g.setTransform(oldTransform); for (int x = 0; x < getWidth(); x += DARK_BACKGROUND.getIconWidth()) { - for (int y = 0; y < getHeight(); y += DARK_BACKGROUND.getIconHeight()) { + for (int y = 0; y < getHeight(); y += DARK_BACKGROUND + .getIconHeight()) { DARK_BACKGROUND.paintIcon(this, g, x, y); } } @@ -335,7 +340,8 @@ class TablePanel extends AbstractStonePanel implements ITablePanel { g.setTransform(oldTransform); for (int x = 0; x < getWidth(); x += BRIGHT_BACKGROUND.getIconWidth()) { - for (int y = 0; y < getHeight(); y += BRIGHT_BACKGROUND.getIconHeight()) { + for (int y = 0; y < getHeight(); y += BRIGHT_BACKGROUND + .getIconHeight()) { BRIGHT_BACKGROUND.paintIcon(this, g, x, y); } } -- cgit v1.2.3