1.1 --- a/visidor/src/main/java/cz/xelfi/quoridor/visidor/Viewer.java Sat Jun 06 15:13:04 2009 +0200
1.2 +++ b/visidor/src/main/java/cz/xelfi/quoridor/visidor/Viewer.java Wed Sep 16 22:28:11 2009 +0200
1.3 @@ -1,8 +1,3 @@
1.4 -/*
1.5 - * To change this template, choose Tools | Templates
1.6 - * and open the template in the editor.
1.7 - */
1.8 -
1.9 package cz.xelfi.quoridor.visidor;
1.10
1.11 import cz.xelfi.quoridor.Board;
1.12 @@ -17,13 +12,9 @@
1.13 import java.awt.Rectangle;
1.14 import javax.swing.JFrame;
1.15 import javax.swing.JPanel;
1.16 -import org.netbeans.api.visual.action.ActionFactory;
1.17 import org.netbeans.api.visual.action.MoveProvider;
1.18 -import org.netbeans.api.visual.anchor.AnchorFactory;
1.19 import org.netbeans.api.visual.border.BorderFactory;
1.20 -import org.netbeans.api.visual.widget.ConnectionWidget;
1.21 import org.netbeans.api.visual.widget.ImageWidget;
1.22 -import org.netbeans.api.visual.widget.LabelWidget;
1.23 import org.netbeans.api.visual.widget.LayerWidget;
1.24 import org.netbeans.api.visual.widget.Scene;
1.25 import org.netbeans.api.visual.widget.Widget;
1.26 @@ -70,41 +61,29 @@
1.27
1.28 private void view(Scene scene, Board b) {
1.29 scene.removeChildren();
1.30 + drawBoard(scene, b);
1.31 + }
1.32 +
1.33 + static void drawBoard(Scene scene, Board b) {
1.34 // Scene layerBoard = scene;
1.35 + scene.setPreferredLocation(new Point(0, 0));
1.36 final LayerWidget layerLines = new LayerWidget(scene);
1.37 scene.addChild(layerLines);
1.38 final LayerWidget layerBoard = new LayerWidget(scene);
1.39 layerLines.addChild(layerBoard);
1.40 final int WDTH = 50;
1.41 final int HGHT = 50;
1.42 -// conn.setSourceAnchor(ahoj);
1.43 - Widget[][] fields = new Widget[10][];
1.44 - for (int i = 0; i < fields.length; i++) {
1.45 - fields[i] = new Widget[10];
1.46 - for (int j = 0; j < fields[i].length; j++) {
1.47 - LabelWidget w = new LabelWidget(scene);
1.48 +
1.49 +
1.50 + for (int i = 0; i < 9; i++) {
1.51 + for (int j = 0; j < 9; j++) {
1.52 + Widget w = new FieldWidget(scene);
1.53 w.setPreferredBounds(new Rectangle(i * WDTH, j * HGHT, WDTH, HGHT));
1.54 layerBoard.addChild(w);
1.55 - fields[i][j] = w;
1.56 - }
1.57 - }
1.58 - for (int i = 0; i < fields.length; i++) {
1.59 - for (int j = 0; j < fields[i].length; j++) {
1.60 - if (i > 0) {
1.61 - ConnectionWidget horiz = new ConnectionWidget(scene);
1.62 - horiz.setSourceAnchor(AnchorFactory.createCenterAnchor(fields[i - 1][j]));
1.63 - horiz.setTargetAnchor(AnchorFactory.createCenterAnchor(fields[i][j]));
1.64 - scene.addChild(horiz);
1.65 - }
1.66 - if (j > 0) {
1.67 - ConnectionWidget vert = new ConnectionWidget(scene);
1.68 - vert.setSourceAnchor(AnchorFactory.createCenterAnchor(fields[i][j - 1]));
1.69 - vert.setTargetAnchor(AnchorFactory.createCenterAnchor(fields[i][j]));
1.70 - scene.addChild(vert);
1.71 - }
1.72 }
1.73 }
1.74
1.75 +/*
1.76 ImageWidget horizontalWall = new ImageWidget(scene);
1.77 horizontalWall.setPreferredBounds(new Rectangle(550, 300, 90, 10));
1.78 horizontalWall.setBackground(Color.BLACK);
1.79 @@ -120,7 +99,7 @@
1.80 verticalWall.setBorder(BorderFactory.createLineBorder());
1.81 verticalWall.setOpaque(true);
1.82 layerBoard.addChild(verticalWall);
1.83 -
1.84 +*/
1.85 for (Fence f : b.getFences()) {
1.86 Rectangle r = fenceRectangle(f.getColumn(), f.getRow(), f.getOrientation());
1.87 ImageWidget fenceWall = new ImageWidget(scene);
1.88 @@ -132,19 +111,10 @@
1.89 }
1.90
1.91 int cnt = 0;
1.92 + Color[] colors = { Color.WHITE, Color.BLACK, Color.ORANGE, Color.MAGENTA };
1.93 for (Player p : b.getPlayers()) {
1.94 - LabelWidget lw = new LabelWidget(scene);
1.95 - lw.setLabel("" + p.getFences());
1.96 - if (cnt == 0) {
1.97 - lw.setPreferredBounds(new Rectangle(550, 200, 50, 50));
1.98 - } else {
1.99 - lw.setPreferredBounds(new Rectangle(550, 450, 50, 50));
1.100 - }
1.101 - layerBoard.addChild(lw);
1.102 -
1.103 - PlayerWidget pw = new PlayerWidget(scene);
1.104 - System.err.println("p: " + p);
1.105 - pw.setPreferredBounds(new Rectangle(p.getColumn() * 50 + 25, p.getRow() * 50 + 25, 50, 50));
1.106 + PlayerWidget pw = new PlayerWidget(scene, colors[cnt]);
1.107 + pw.setPreferredBounds(new Rectangle(p.getColumn() * WDTH, p.getRow() * HGHT, WDTH, HGHT));
1.108 layerBoard.addChild(pw);
1.109
1.110 cnt++;
1.111 @@ -160,7 +130,7 @@
1.112 }
1.113
1.114 return new Rectangle(
1.115 - (column - 'A' + 1) * 50 + 25 - w, row * 50 + 25 - h, 2 * w, 2 * h
1.116 + (column - 'A' + 1) * 50 - w, row * 50 - h, 2 * w, 2 * h
1.117 );
1.118 }
1.119
1.120 @@ -259,7 +229,28 @@
1.121 }
1.122
1.123 private static final class PlayerWidget extends Widget {
1.124 - public PlayerWidget(Scene s) {
1.125 + private final Color color;
1.126 +
1.127 + public PlayerWidget(Scene s, Color color) {
1.128 + super(s);
1.129 + this.color = color;
1.130 + }
1.131 +
1.132 + @Override
1.133 + protected Rectangle calculateClientArea() {
1.134 + return getBounds();
1.135 + }
1.136 +
1.137 + @Override
1.138 + protected void paintWidget() {
1.139 + Graphics2D g = getGraphics();
1.140 + Rectangle b = getBounds();
1.141 + g.setColor(color);
1.142 + g.fillOval(b.x + 8, b.y + 8, b.width - 16, b.height - 16);
1.143 + }
1.144 + }
1.145 + private static final class FieldWidget extends Widget {
1.146 + public FieldWidget(Scene s) {
1.147 super(s);
1.148 }
1.149
1.150 @@ -272,7 +263,8 @@
1.151 protected void paintWidget() {
1.152 Graphics2D g = getGraphics();
1.153 Rectangle b = getBounds();
1.154 - g.drawOval(b.x + 5, b.y + 5, b.width - 10, b.height - 10);
1.155 + g.setColor(Color.lightGray);
1.156 + g.fillRect(b.x + 5, b.y + 5, b.width - 10, b.height - 10);
1.157 }
1.158 }
1.159 }