diff -r 6a6d1dbea99e -r 786df32c496b visidor/src/main/java/cz/xelfi/quoridor/visidor/Viewer.java --- a/visidor/src/main/java/cz/xelfi/quoridor/visidor/Viewer.java Sat Jun 06 15:13:04 2009 +0200 +++ b/visidor/src/main/java/cz/xelfi/quoridor/visidor/Viewer.java Wed Sep 16 22:28:11 2009 +0200 @@ -1,8 +1,3 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - package cz.xelfi.quoridor.visidor; import cz.xelfi.quoridor.Board; @@ -17,13 +12,9 @@ import java.awt.Rectangle; import javax.swing.JFrame; import javax.swing.JPanel; -import org.netbeans.api.visual.action.ActionFactory; import org.netbeans.api.visual.action.MoveProvider; -import org.netbeans.api.visual.anchor.AnchorFactory; import org.netbeans.api.visual.border.BorderFactory; -import org.netbeans.api.visual.widget.ConnectionWidget; import org.netbeans.api.visual.widget.ImageWidget; -import org.netbeans.api.visual.widget.LabelWidget; import org.netbeans.api.visual.widget.LayerWidget; import org.netbeans.api.visual.widget.Scene; import org.netbeans.api.visual.widget.Widget; @@ -70,41 +61,29 @@ private void view(Scene scene, Board b) { scene.removeChildren(); + drawBoard(scene, b); + } + + static void drawBoard(Scene scene, Board b) { // Scene layerBoard = scene; + scene.setPreferredLocation(new Point(0, 0)); final LayerWidget layerLines = new LayerWidget(scene); scene.addChild(layerLines); final LayerWidget layerBoard = new LayerWidget(scene); layerLines.addChild(layerBoard); final int WDTH = 50; final int HGHT = 50; -// conn.setSourceAnchor(ahoj); - Widget[][] fields = new Widget[10][]; - for (int i = 0; i < fields.length; i++) { - fields[i] = new Widget[10]; - for (int j = 0; j < fields[i].length; j++) { - LabelWidget w = new LabelWidget(scene); + + + for (int i = 0; i < 9; i++) { + for (int j = 0; j < 9; j++) { + Widget w = new FieldWidget(scene); w.setPreferredBounds(new Rectangle(i * WDTH, j * HGHT, WDTH, HGHT)); layerBoard.addChild(w); - fields[i][j] = w; - } - } - for (int i = 0; i < fields.length; i++) { - for (int j = 0; j < fields[i].length; j++) { - if (i > 0) { - ConnectionWidget horiz = new ConnectionWidget(scene); - horiz.setSourceAnchor(AnchorFactory.createCenterAnchor(fields[i - 1][j])); - horiz.setTargetAnchor(AnchorFactory.createCenterAnchor(fields[i][j])); - scene.addChild(horiz); - } - if (j > 0) { - ConnectionWidget vert = new ConnectionWidget(scene); - vert.setSourceAnchor(AnchorFactory.createCenterAnchor(fields[i][j - 1])); - vert.setTargetAnchor(AnchorFactory.createCenterAnchor(fields[i][j])); - scene.addChild(vert); - } } } +/* ImageWidget horizontalWall = new ImageWidget(scene); horizontalWall.setPreferredBounds(new Rectangle(550, 300, 90, 10)); horizontalWall.setBackground(Color.BLACK); @@ -120,7 +99,7 @@ verticalWall.setBorder(BorderFactory.createLineBorder()); verticalWall.setOpaque(true); layerBoard.addChild(verticalWall); - +*/ for (Fence f : b.getFences()) { Rectangle r = fenceRectangle(f.getColumn(), f.getRow(), f.getOrientation()); ImageWidget fenceWall = new ImageWidget(scene); @@ -132,19 +111,10 @@ } int cnt = 0; + Color[] colors = { Color.WHITE, Color.BLACK, Color.ORANGE, Color.MAGENTA }; for (Player p : b.getPlayers()) { - LabelWidget lw = new LabelWidget(scene); - lw.setLabel("" + p.getFences()); - if (cnt == 0) { - lw.setPreferredBounds(new Rectangle(550, 200, 50, 50)); - } else { - lw.setPreferredBounds(new Rectangle(550, 450, 50, 50)); - } - layerBoard.addChild(lw); - - PlayerWidget pw = new PlayerWidget(scene); - System.err.println("p: " + p); - pw.setPreferredBounds(new Rectangle(p.getColumn() * 50 + 25, p.getRow() * 50 + 25, 50, 50)); + PlayerWidget pw = new PlayerWidget(scene, colors[cnt]); + pw.setPreferredBounds(new Rectangle(p.getColumn() * WDTH, p.getRow() * HGHT, WDTH, HGHT)); layerBoard.addChild(pw); cnt++; @@ -160,7 +130,7 @@ } return new Rectangle( - (column - 'A' + 1) * 50 + 25 - w, row * 50 + 25 - h, 2 * w, 2 * h + (column - 'A' + 1) * 50 - w, row * 50 - h, 2 * w, 2 * h ); } @@ -259,7 +229,28 @@ } private static final class PlayerWidget extends Widget { - public PlayerWidget(Scene s) { + private final Color color; + + public PlayerWidget(Scene s, Color color) { + super(s); + this.color = color; + } + + @Override + protected Rectangle calculateClientArea() { + return getBounds(); + } + + @Override + protected void paintWidget() { + Graphics2D g = getGraphics(); + Rectangle b = getBounds(); + g.setColor(color); + g.fillOval(b.x + 8, b.y + 8, b.width - 16, b.height - 16); + } + } + private static final class FieldWidget extends Widget { + public FieldWidget(Scene s) { super(s); } @@ -272,7 +263,8 @@ protected void paintWidget() { Graphics2D g = getGraphics(); Rectangle b = getBounds(); - g.drawOval(b.x + 5, b.y + 5, b.width - 10, b.height - 10); + g.setColor(Color.lightGray); + g.fillRect(b.x + 5, b.y + 5, b.width - 10, b.height - 10); } } }