示例#1
0
  public void paintComponent(Graphics g) throws RuntimeException {
    int squarewidth = getSquareWidth();
    int squareheight = getSquareHeight();

    int hoffset = getHorizontalOffset();
    int voffset = getVerticalOffset();

    for (int x = 0; x < grid.maxX(); x++) {
      for (int y = 0; y < grid.maxY(); y++) {
        Cell tmp = grid.grabObjectAt(x, y);

        if (tmp == null) {
          g.setColor(Color.gray.darker());
        } else {
          g.setColor(tmp.getColor());
        }

        g.fillRect(
            hoffset + x * squarewidth,
            voffset + ((grid.maxY() - y) * squareheight),
            squarewidth - 1,
            squareheight - 1);
      }
    }
  }
示例#2
0
  protected int getSquareHeight() {
    int sheight = getRealHeight() / (grid.maxY() + 1);

    if (sheight > 0) {
      return sheight;
    } else {
      return 1;
    }
  }
示例#3
0
  public Cell getObjectAt(int x, int y) {
    int grid_x = (x - getHorizontalOffset()) / getSquareWidth();
    int grid_y = Math.abs(((y - getVerticalOffset()) / getSquareHeight()) - grid.maxY());

    return grid.getObjectAt(grid_x, grid_y);
  }
示例#4
0
 protected int getVerticalOffset() {
   int offset = (getRealHeight() - (getSquareHeight() * (grid.maxY() + 2))) / 2;
   return offset;
 }