Example #1
0
  /**
   * Main Sudoku Paint. Paints everything for the sudoku board.
   *
   * @param m
   * @param g
   * @param w
   * @param oh
   */
  @Override
  public void paint(SudokuModel m, Graphics g, int w, int oh) {
    this.oh = oh;
    this.w = w;
    int h = oh - 100;
    this.h = h;
    g.setFont(new Font(SANS_SERIF, PLAIN, 50));

    m.checkConflict();

    for (int i = 0; i < 3; ++i)
      for (int j = 0; j < 3; ++j) paintSmallGrid(g, i * w / 3, j * h / 3, w / 3, h / 3);

    m.updateSelection();
    for (int i = 0; i < 9; ++i)
      for (int j = 0; j < 9; ++j) paintBox(g, i * w / 9, j * h / 9, m.get(j, i), w / 9, h / 9);
    paintGrid(g, w, h);

    if (m.gameOver()) {
      g.setColor(Color.BLACK);
      g.fillRect(w / 2 - 200, h / 2 - 100, 400, 200);
      g.setColor(Color.RED);
      drawStringBox(g, w / 2 - 200, h / 2 - 200, "GAME OVER", 400, 400);
    }
  }
Example #2
0
 /**
  * Paints a box.
  *
  * @param g usable graphics object
  * @param tlx x-coordinate of the top left corner of the box
  * @param tly y-coordinate of the top left corner of the box
  * @param b the Box object
  * @param w
  * @param h
  */
 public void paintBox(Graphics g, int tlx, int tly, Box b, int w, int h) {
   if (b.clue) g.setColor(Color.BLACK);
   else if (b.conflict) g.setColor(Color.RED);
   else g.setColor(Color.BLUE);
   drawStringBox(g, tlx, tly, (b.number == 0) ? "" : (b.number + ""), w, h);
   Graphics2D g2 = (Graphics2D) g;
   g2.setStroke(new BasicStroke(5));
   g2.setColor(Color.GRAY);
   if (b.selected) g2.drawRect(tlx + 5, tly + 5, w - 10, h - 10);
   g2.setStroke(new BasicStroke(1));
 }
Example #3
0
  /**
   * Paints the 3x3 outer grid.
   *
   * @param g
   * @param w
   * @param h
   */
  public void paintGrid(Graphics g, int w, int h) {
    g.setColor(Color.BLACK);

    Graphics2D g2 = (Graphics2D) g;
    g2.setStroke(new BasicStroke(3));
    g2.drawRect(0, 0, w, h);
    g2.drawRect(0, h / 3, w, h / 3);
    g2.drawRect(w / 3, 0, w / 3, h);
    g2.setStroke(new BasicStroke(1));
  }
 /**
  * Paint the glyphs for the given view. This is implemented to only render if the Graphics is of
  * type Graphics2D which is required by TextLayout (and this should be the case if running on the
  * JDK).
  */
 public void paint(GlyphView v, Graphics g, Shape a, int p0, int p1) {
   if (g instanceof Graphics2D) {
     Rectangle2D alloc = a.getBounds2D();
     Graphics2D g2d = (Graphics2D) g;
     float y = (float) alloc.getY() + layout.getAscent() + layout.getLeading();
     float x = (float) alloc.getX();
     if (p0 > v.getStartOffset() || p1 < v.getEndOffset()) {
       try {
         // TextLayout can't render only part of it's range, so if a
         // partial range is required, add a clip region.
         Shape s = v.modelToView(p0, Position.Bias.Forward, p1, Position.Bias.Backward, a);
         Shape savedClip = g.getClip();
         g2d.clip(s);
         layout.draw(g2d, x, y);
         g.setClip(savedClip);
       } catch (BadLocationException e) {
       }
     } else {
       layout.draw(g2d, x, y);
     }
   }
 }
Example #5
0
  @Override
  public void paintIcon(Component c, Graphics g, int x, int y) {
    Graphics2D g2 = (Graphics2D) g.create();
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.translate(x, y);

    g2.setStroke(new BasicStroke(BORDER_WIDTH));
    g2.setPaint(LINE_COLOR);
    g2.draw(BORDER);

    g2.setStroke(new BasicStroke(SLIT_WIDTH));
    g2.setColor(UIManager.getColor("Panel.background"));

    int n = SLIT_NUM + 1;
    int v = ICON_SIZE / n;
    int m = n * v;
    for (int i = 1; i < n; i++) {
      int a = i * v;
      g2.drawLine(a, 0, a, m);
      g2.drawLine(0, a, m, a);
    }

    // g2.drawLine(1 * v, 0 * v, 1 * v, 4 * v);
    // g2.drawLine(2 * v, 0 * v, 2 * v, 4 * v);
    // g2.drawLine(3 * v, 0 * v, 3 * v, 4 * v);
    // g2.drawLine(0 * v, 1 * v, 4 * v, 1 * v);
    // g2.drawLine(0 * v, 2 * v, 4 * v, 2 * v);
    // g2.drawLine(0 * v, 3 * v, 4 * v, 3 * v);

    g2.setPaint(LINE_COLOR);
    Rectangle2D b = ARROW.getBounds();
    Point2D p = new Point2D.Double(b.getX() + b.getWidth() / 2d, b.getY() + b.getHeight() / 2d);
    AffineTransform toCenterAT =
        AffineTransform.getTranslateInstance(ICON_SIZE / 2d - p.getX(), ICON_SIZE / 2d - p.getY());
    g2.fill(toCenterAT.createTransformedShape(ARROW));
    g2.dispose();
  }
  public void paintComponent(Graphics screen) {
    if (inactive == null) {
      inactive = new Image[BUTTON_COUNT];
      rollover = new Image[BUTTON_COUNT];
      active = new Image[BUTTON_COUNT];

      int IMAGE_SIZE = 33;

      for (int i = 0; i < BUTTON_COUNT; i++) {
        inactive[i] = createImage(BUTTON_WIDTH, BUTTON_HEIGHT);
        Graphics g = inactive[i].getGraphics();
        g.drawImage(buttons, -(i * IMAGE_SIZE) - 3, -2 * IMAGE_SIZE, null);

        rollover[i] = createImage(BUTTON_WIDTH, BUTTON_HEIGHT);
        g = rollover[i].getGraphics();
        g.drawImage(buttons, -(i * IMAGE_SIZE) - 3, -1 * IMAGE_SIZE, null);

        active[i] = createImage(BUTTON_WIDTH, BUTTON_HEIGHT);
        g = active[i].getGraphics();
        g.drawImage(buttons, -(i * IMAGE_SIZE) - 3, -0 * IMAGE_SIZE, null);
      }

      state = new int[buttonCount];
      stateImage = new Image[buttonCount];
      for (int i = 0; i < buttonCount; i++) {
        setState(i, INACTIVE, false);
      }
    }
    Dimension size = getSize();
    if ((offscreen == null) || (size.width != width) || (size.height != height)) {
      offscreen = createImage(size.width, size.height);
      width = size.width;
      height = size.height;

      y1 = 0;
      y2 = BUTTON_HEIGHT;

      x1 = new int[buttonCount];
      x2 = new int[buttonCount];

      int offsetX = 3;
      for (int i = 0; i < buttonCount; i++) {
        x1[i] = offsetX;
        if (i == 2) x1[i] += BUTTON_GAP;
        x2[i] = x1[i] + BUTTON_WIDTH;
        offsetX = x2[i];
      }
    }
    Graphics g = offscreen.getGraphics();
    g.setColor(bgcolor); // getBackground());
    g.fillRect(0, 0, width, height);

    for (int i = 0; i < buttonCount; i++) {
      g.drawImage(stateImage[i], x1[i], y1, null);
    }

    g.setColor(statusColor);
    g.setFont(statusFont);

    /*
    // if i ever find the guy who wrote the java2d api, i will hurt him.
    Graphics2D g2 = (Graphics2D) g;
    FontRenderContext frc = g2.getFontRenderContext();
    float statusW = (float) statusFont.getStringBounds(status, frc).getWidth();
    float statusX = (getSize().width - statusW) / 2;
    g2.drawString(status, statusX, statusY);
    */
    // int statusY = (BUTTON_HEIGHT + statusFont.getAscent()) / 2;
    int statusY = (BUTTON_HEIGHT + g.getFontMetrics().getAscent()) / 2;
    g.drawString(status, buttonCount * BUTTON_WIDTH + 2 * BUTTON_GAP, statusY);

    screen.drawImage(offscreen, 0, 0, null);
  }
Example #7
0
 /**
  * @param g graphics object
  * @param tlx top left x coordinate
  * @param tly top left y coordinate
  * @param s painted string
  * @param w width of outlying box
  * @param h height of outlying box
  */
 public void drawStringBox(Graphics g, int tlx, int tly, String s, int w, int h) {
   GraphicsUtilityFunctions.drawStringWithFontInRectangle(g, s, g.getFont(), tlx, tly, w, h);
 }
Example #8
0
 /**
  * Paints the inner, smaller grids.
  *
  * @param g
  * @param tlx
  * @param tly
  * @param w
  * @param h
  */
 public void paintSmallGrid(Graphics g, int tlx, int tly, int w, int h) {
   g.setColor(Color.BLACK);
   g.drawRect(tlx + w / 3, tly, w / 3, h);
   g.drawRect(tlx, tly + h / 3, w, h / 3);
 }
Example #9
0
 public void paintIcon(Component c, Graphics g, int x, int y) {
   Color oldColor = g.getColor();
   g.setColor(color);
   g.fill3DRect(x, y, getIconWidth(), getIconHeight(), true);
   g.setColor(oldColor);
 }