webidor/src/main/java/cz/xelfi/quoridor/webidor/resources/BoardImage.java
changeset 105 6e55d5c85d3c
parent 104 e37b229e238b
child 106 7d090f2c5b91
     1.1 --- a/webidor/src/main/java/cz/xelfi/quoridor/webidor/resources/BoardImage.java	Sun Sep 20 11:00:36 2009 +0200
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,109 +0,0 @@
     1.4 -/*
     1.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     1.6 - *
     1.7 - * The contents of this file are subject to the terms of either the GNU
     1.8 - * General Public License Version 2 only ("GPL") or the Common
     1.9 - * Development and Distribution License("CDDL") (collectively, the
    1.10 - * "License"). You may not use this file except in compliance with the
    1.11 - * License. You can obtain a copy of the License at
    1.12 - * http://www.netbeans.org/cddl-gplv2.html
    1.13 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
    1.14 - * specific language governing permissions and limitations under the
    1.15 - * License.  When distributing the software, include this License Header
    1.16 - * Notice in each file and include the License file at
    1.17 - * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
    1.18 - * particular file as subject to the "Classpath" exception as provided
    1.19 - * by Sun in the GPL Version 2 section of the License file that
    1.20 - * accompanied this code. If applicable, add the following below the
    1.21 - * License Header, with the fields enclosed by brackets [] replaced by
    1.22 - * your own identifying information:
    1.23 - * "Portions Copyrighted [year] [name of copyright owner]"
    1.24 - *
    1.25 - * Contributor(s):
    1.26 - *
    1.27 - * Portions Copyrighted 2009 Jaroslav Tulach
    1.28 - */
    1.29 -
    1.30 -package cz.xelfi.quoridor.webidor.resources;
    1.31 -
    1.32 -import cz.xelfi.quoridor.Board;
    1.33 -import cz.xelfi.quoridor.Fence;
    1.34 -import cz.xelfi.quoridor.Player;
    1.35 -import java.awt.Color;
    1.36 -import java.awt.Font;
    1.37 -import java.awt.Graphics2D;
    1.38 -import java.awt.Image;
    1.39 -import java.awt.Rectangle;
    1.40 -import java.awt.image.BufferedImage;
    1.41 -
    1.42 -/** Convertor of a board to Image.
    1.43 - *
    1.44 - * @author Jaroslav Tulach <jtulach@netbeans.org>
    1.45 - */
    1.46 -final class BoardImage  {
    1.47 -    static Image draw(Board b, int fieldSize) {
    1.48 -        int fifth = fieldSize / 10;
    1.49 -
    1.50 -        BufferedImage img = new BufferedImage(fieldSize * 9, fieldSize * 9, BufferedImage.TYPE_INT_ARGB);
    1.51 -        Graphics2D g = (Graphics2D) img.getGraphics();
    1.52 -
    1.53 -        g.setColor(Color.lightGray);
    1.54 -        for (int i = 0; i < 9; i++) {
    1.55 -            for (int j = 0; j < 9; j++) {
    1.56 -                final Rectangle r = new Rectangle(i * fieldSize, j * fieldSize, fieldSize, fieldSize);
    1.57 -                g.fillRect(r.x + fifth, r.y + fifth, r.width - fifth * 2, r.height - fifth * 2);
    1.58 -            }
    1.59 -        }
    1.60 -
    1.61 -
    1.62 -        g.setColor(Color.BLACK);
    1.63 -        for (Fence f : b.getFences()) {
    1.64 -            int w, h;
    1.65 -            switch (f.getOrientation()) {
    1.66 -                case HORIZONTAL: w = fieldSize - fifth; h = fifth; break;
    1.67 -                case VERTICAL: w = fifth; h = fieldSize - fifth; break;
    1.68 -                default: throw new IllegalStateException();
    1.69 -            }
    1.70 -            int column = (f.getColumn() - 'A') + 1;
    1.71 -            int row = 9 - f.getRow();
    1.72 -            Rectangle r = new Rectangle(
    1.73 -                column * fieldSize - w,
    1.74 -                row * fieldSize - h,
    1.75 -                2 * w,
    1.76 -                2 * h
    1.77 -            );
    1.78 -            g.fill(r);
    1.79 -        }
    1.80 -
    1.81 -        int cnt = 0;
    1.82 -        Color[] colors = { Color.WHITE, Color.BLACK, Color.ORANGE, Color.MAGENTA };
    1.83 -        int diametr = fieldSize - fifth * 4;
    1.84 -        for (Player p : b.getPlayers()) {
    1.85 -            int column = p.getColumn();
    1.86 -            int row = 8 - p.getRow();
    1.87 -            final Rectangle r = new Rectangle(
    1.88 -                column * fieldSize + 2 * fifth,
    1.89 -                row * fieldSize + 2 * fifth,
    1.90 -                diametr,
    1.91 -                diametr
    1.92 -            );
    1.93 -            g.setColor(colors[cnt]);
    1.94 -            g.fillOval(r.x, r.y, r.width, r.height);
    1.95 -            cnt++;
    1.96 -        }
    1.97 -
    1.98 -        g.setColor(Color.BLACK);
    1.99 -        final Font f = new Font("Monospace", Font.BOLD, fifth * 2);
   1.100 -        g.setFont(f);
   1.101 -        for (int i = 0; i < 8; i++) {
   1.102 -            final char ch = (char) ('A' + i);
   1.103 -            g.drawString(Character.toString(ch), i * fieldSize + fieldSize - fifth, fifth + f.getSize() - f.getBaselineFor(ch));
   1.104 -        }
   1.105 -        for (int i = 0; i < 8; i++) {
   1.106 -            String s = "" + (8 - i);
   1.107 -            g.drawString(s, fifth, i * fieldSize + fieldSize - fifth + f.getSize() - f.getBaselineFor(s.charAt(0)));
   1.108 -        }
   1.109 -
   1.110 -        return img;
   1.111 -    }
   1.112 -}