Beispiel #1
0
  public void paintText(Graphics2D g, ButtonInfo info) {
    ButtonModel model = info.button.getModel();
    FontMetrics fm = info.button.getFontMetrics(info.button.getFont());
    int mnemonicIndex = info.button.getDisplayedMnemonicIndex();
    String text = info.button.getText();
    int textShiftOffset = 0;

    g.setComposite(AlphaComposite.SrcOver);
    /* Draw the Text */
    if (isEnabled(info.button)) {
      /** * paint the text normally */
      g.setColor(info.button.getForeground());
      BasicGraphicsUtils.drawStringUnderlineCharAt(
          g,
          text,
          mnemonicIndex,
          info.textRect.x + textShiftOffset,
          info.textRect.y + fm.getAscent() + textShiftOffset);
    } else {
      /** * paint the text disabled ** */
      g.setColor(info.button.getBackground().brighter());
      BasicGraphicsUtils.drawStringUnderlineCharAt(
          g, text, mnemonicIndex, info.textRect.x, info.textRect.y + fm.getAscent());
      g.setColor(info.button.getBackground().darker());
      BasicGraphicsUtils.drawStringUnderlineCharAt(
          g, text, mnemonicIndex, info.textRect.x - 1, info.textRect.y + fm.getAscent() - 1);
    }
  }
Beispiel #2
0
  @Override
  public void setBounds(int x, int y, int width, int height) {
    super.setBounds(x, y, width, height);
    int w = getWidth() - (SHADOW_SIZE - 2) * 2;
    int h = getHeight() - (SHADOW_SIZE - 2) * 2;
    int arc = 15;
    int shadowSize = SHADOW_SIZE;
    shadow = GraphicsUtilities.createCompatibleTranslucentImage(w, h);
    Graphics2D g2 = shadow.createGraphics();

    if (active) {
      g2.setColor(new Color(243, 238, 39, 150));
    } else {
      g2.setColor(Color.WHITE);
    }

    g2.setColor(Color.WHITE);
    g2.fillOval(0, 0, w, h);
    g2.dispose();
    ShadowRenderer renderer = new ShadowRenderer(shadowSize, 0.5f, Color.BLACK);
    shadow = renderer.createShadow(shadow);
    g2 = shadow.createGraphics();
    g2.setColor(Color.GRAY);
    g2.setComposite(AlphaComposite.Clear);
    g2.fillOval(shadowSize, shadowSize, w, h);
    g2.dispose();
  }
Beispiel #3
0
 /**
  * Erases a given shape's outline on the screen.
  *
  * @param shape the shape object to be erased
  */
 public void eraseOutline(Shape shape) {
   Color original = graphic.getColor();
   graphic.setColor(backgroundColour);
   graphic.draw(shape); // erase by drawing background colour
   graphic.setColor(original);
   canvas.repaint();
 }
 /** Erase the whole canvas. (Does not repaint.) */
 private void erase() {
   Color original = graphic.getColor();
   graphic.setColor(backgroundColor);
   Dimension size = canvas.getSize();
   graphic.fill(new Rectangle(0, 0, size.width, size.height));
   graphic.setColor(original);
 }
  public void drawFunctionToGraphic(Graphics2D g, int x, int y, int UNITYX, int UNITYY) {
    int _x, _y;

    g.setColor(Color.red);
    g.drawString("f(x) = " + F.toString(), 15, 20);

    g.setColor(Color.blue);
    for (double i = 0; ; i += EPSILON) {
      _x = (int) (i * UNITYX) + x / 2;
      _y = -(int) (F.evaluate(i) * UNITYY) + y / 2;

      g.drawLine(
          _x,
          _y,
          (int) ((i + EPSILON) * UNITYX) + x / 2,
          -(int) (F.evaluate(i + EPSILON) * UNITYY) + y / 2);

      if (_x < 0 || _x > x || _y < 0 || _y > y) break;
    }

    for (double i = 0; ; i -= EPSILON) {
      _x = (int) (i * UNITYX) + x / 2;
      _y = -(int) (F.evaluate(i) * UNITYY) + y / 2;

      g.drawLine(
          _x,
          _y,
          (int) ((i + EPSILON) * UNITYX) + x / 2,
          -(int) (F.evaluate(i + EPSILON) * UNITYY) + y / 2);

      if (_x < 0 || _x > x || _y < 0 || _y > y) break;
    }
  }
Beispiel #6
0
    @Override
    public void paint(Graphics g) {
      super.paint(g);
      if (g instanceof Graphics2D) {
        Graphics2D g2d = (Graphics2D) g;

        if (blackOutEnabled) {
          // background
          g2d.setColor(Color.BLACK);
          g2d.fillRect(0, 0, this.getWidth(), this.getHeight());
        } else if (whiteOutEnabled) {
          // background
          g2d.setColor(Color.WHITE);
          g2d.fillRect(0, 0, this.getWidth(), this.getHeight());
        } else {
          // background
          g2d.setColor(backgroundColor);
          g2d.fillRect(0, 0, this.getWidth(), this.getHeight());

          // text
          if (font == null)
            font = GuiHelper.maxFontSize(frame.getWidth(), frame.getHeight(), fontName, timeFormat);
          if (textY == -1) textY = GuiHelper.getTextYForCenter(timeFormat, font, frame.getHeight());
          g2d.setRenderingHint(
              RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
          g2d.setFont(font);
          g2d.setColor(textColor);
          g2d.drawString(timeToString(time), 0, textY);
        }
      }
    }
Beispiel #7
0
 // draw on screen
 public synchronized void draw(Graphics2D g) {
   Window w = s.getFullScreenWindow();
   g.setColor(w.getBackground());
   g.fillRect(0, 0, s.getWidth(), s.getHeight());
   g.setColor(w.getForeground());
   g.drawString(mess, 100, 100);
 }
Beispiel #8
0
 /**
  * icon is painted with correct number of stones in the pit/mancala
  *
  * @param c properties for painting
  * @param g graphics object
  * @param x x location of icon
  * @param y y location of icon
  */
 public void paintIcon(Component c, Graphics g, int x, int y) {
   int iterateNum = data[pitNum];
   if (iterateNum > 5) {
     iterateNum = 5;
   }
   Graphics2D g2 = (Graphics2D) g;
   if (pitNum == 6 || pitNum == 13) {
     pitShape = s.getMancalaShape();
     g2.setColor(s.getPitColor());
     g2.fill(pitShape);
     for (int i = 0; i < data[pitNum]; i++) {
       RectangularShape temp = s.getStoneShape(i, data[pitNum], true);
       g2.setColor(s.getStoneColor());
       g2.draw(temp);
       g2.fill(temp);
     }
   } else {
     pitShape = s.getPitShape();
     g2.setColor(s.getPitColor());
     g2.fill(pitShape);
     for (int i = 0; i < data[pitNum]; i++) {
       RectangularShape temp = s.getStoneShape(i, data[pitNum], false);
       g2.setColor(s.getStoneColor());
       g2.draw(temp);
       g2.fill(temp);
     }
   }
 }
  public void paintComponent(Graphics g) {
    Graphics2D g2d = (Graphics2D) g.create();
    g2d.setStroke(new BasicStroke(1.0f));

    if (isOpaque()) {
      g2d.setColor(getBackground());
      g2d.fillRect(0, 0, getWidth(), getHeight());
    }

    g2d.setColor(Color.black);
    g2d.drawLine(0, frameHeight / 2, frameWidth, frameHeight / 2);
    g2d.drawLine(frameWidth / 2, 0, frameWidth / 2, frameHeight);

    for (int i = unityX; i < frameWidth / 2; i += unityX) {
      g2d.drawLine(
          frameWidth / 2 + i, frameHeight / 2 - 3, frameWidth / 2 + i, frameHeight / 2 + 3);
      g2d.drawLine(
          frameWidth / 2 - i, frameHeight / 2 - 3, frameWidth / 2 - i, frameHeight / 2 + 3);
    }

    for (int i = unityY; i < frameHeight / 2; i += unityY) {
      g2d.drawLine(
          frameWidth / 2 - 3, frameHeight / 2 + i, frameWidth / 2 + 3, frameHeight / 2 + i);
      g2d.drawLine(
          frameWidth / 2 - 3, frameHeight / 2 - i, frameWidth / 2 + 3, frameHeight / 2 - i);
    }

    g2d.setColor(Color.blue);
    function.drawFunctionToGraphic(g2d, frameWidth, frameHeight, unityX, unityY);

    paintCurrentMethodState(g2d);

    g2d.dispose();
  }
Beispiel #10
0
  public void paint(Graphics g) {
    gRef = (Graphics2D) g;

    // change size of font
    gRef.setFont(gRef.getFont().deriveFont(9.0f));

    fmRef = g.getFontMetrics();

    // Clear background

    if (Preferences.monochrome) {
      gRef.setColor(Preferences.whiteColor);
    } else {
      gRef.setColor(Preferences.backgroundColor);
    }
    gRef.fillRect(0, 0, getWidth(), getHeight());

    // set colour to correct drawing colour
    if (Preferences.monochrome) {
      gRef.setColor(Preferences.blackColor);
    } else {
      gRef.setColor(Preferences.penColor);
    }

    gRef.translate(0, margin);

    // Call c code to draw tree
    gRef.scale(scale, scale);
    nativeDrawTree();
  }
  @Override
  protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D gfx = (Graphics2D) g;
    gfx.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    // Clear screen
    gfx.setColor(Constants.BACKGROUND_COLOR);
    gfx.fillRect(0, 0, getWidth(), getHeight());
    // Render next frame
    grid.draw(gfx);
    // Trace path line
    if (tracing) {
      gfx.setColor(Constants.PATH_COLOR);
      gfx.setStroke(new BasicStroke(2));
      for (int i = 1; i < pathLine.size(); i++) {
        Coordinate p = pathLine.get(i - 1);
        Coordinate n = pathLine.get(i);
        gfx.drawLine(
            (Constants.TILESIZE + Constants.MARGIN) * p.x
                + (Constants.TILESIZE / 2)
                + Constants.MARGIN,
            (Constants.TILESIZE + Constants.MARGIN) * p.y
                + (Constants.TILESIZE / 2)
                + Constants.MARGIN,
            (Constants.TILESIZE + Constants.MARGIN) * n.x
                + (Constants.TILESIZE / 2)
                + Constants.MARGIN,
            (Constants.TILESIZE + Constants.MARGIN) * n.y
                + (Constants.TILESIZE / 2)
                + Constants.MARGIN);
      }
    }
  }
  /** Paints selection for the specified <code>component</code>. */
  public static void paintSelectionDecoration(
      @NotNull RadComponent component, Graphics g, boolean focused) {
    if (component.isSelected()) {
      if (focused) {
        g.setColor(PlatformColors.BLUE);
      } else {
        g.setColor(Color.GRAY);
      }
      final Point[] points = getPoints(component.getWidth(), component.getHeight());
      for (final Point point : points) {
        g.fillRect(point.x - R, point.y - R, 2 * R + 1, 2 * R + 1);
      }
    } else if (component.getWidth() < FormEditingUtil.EMPTY_COMPONENT_SIZE
        || component.getHeight() < FormEditingUtil.EMPTY_COMPONENT_SIZE) {
      Graphics2D g2d = (Graphics2D) g;
      Composite oldComposite = g2d.getComposite();
      Stroke oldStroke = g2d.getStroke();
      Color oldColor = g2d.getColor();

      g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 0.5f));
      g2d.setStroke(new BasicStroke(0.7f));
      g2d.setColor(Color.black);
      g2d.drawRect(
          0,
          0,
          Math.max(component.getWidth(), FormEditingUtil.EMPTY_COMPONENT_SIZE),
          Math.max(component.getHeight(), FormEditingUtil.EMPTY_COMPONENT_SIZE));

      g2d.setComposite(oldComposite);
      g2d.setStroke(oldStroke);
      g2d.setColor(oldColor);
    }
  }
Beispiel #13
0
  @Override
  protected void paintWidget() {
    Graphics2D g = getGraphics();
    g.setStroke(Util.STROKE_2);
    g.setFont(getFont());
    Rectangle bounds = getBounds();

    String text = Util.node(this).toString();
    if (text.length() == 0) {
      g.setColor((Color) getBackground());
      g.fillOval(bounds.x, bounds.y, bounds.width - 1, bounds.height - 1);
      g.setColor(getForeground());
      g.drawOval(bounds.x, bounds.y, bounds.width - 1, bounds.height - 1);
    } else {
      g.setColor((Color) getBackground());
      int arc = (bounds.height - 1);
      g.fillRoundRect(bounds.x, bounds.y, bounds.width - 1, bounds.height - 1, arc, arc);
      g.setColor(getForeground());
      g.drawString(
          text,
          bounds.x + (bounds.height - 1) / 2,
          bounds.y + bounds.height - vborder - 1 - g.getFontMetrics().getMaxDescent());
      g.drawRoundRect(bounds.x, bounds.y, bounds.width - 1, bounds.height - 1, arc, arc);
    }
  }
Beispiel #14
0
  @Override
  // TODO Auto-generated method stub
  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D) g;

    // Draws the two initial two YinYang symbols on the frame
    g2.setColor(color1);
    if (timeLeft < 6000) {
      g2.rotate(degrees, yin1X + (yin1Width / 2), yin1Y + (yin1Height / 2));
    }
    g2.fill(new MyYinYang(yin1X, yin1Y, yin1Width, yin1Height));
    if (timeLeft < 6000) {
      g2.rotate(-degrees, yin1X + (yin1Width / 2), yin1Y + (yin1Height / 2));
    }
    g2.setColor(color2);
    if (timeLeft < 6000) {
      g2.rotate(degrees, yin2X + (yin2Width / 2), yin2Y + (yin2Height / 2));
    }
    g2.fill(new MyYinYang(yin2X, yin2Y, yin2Width, yin2Height));
    if (timeLeft < 6000) {
      g2.rotate(-degrees, yin2X + (yin2Width / 2), yin2Y + (yin2Height / 2));
    }

    // Alters and prints the text on the screen
    g2.setColor(Color.BLACK);
    g2.setFont(font);
    g2.drawString("Score", 700, 25);
    g2.drawString(Integer.toString(points), 700, 75);
    g2.drawString("Misses", 800, 25);
    g2.drawString(Integer.toString(misses), 800, 75);
    g2.drawString("Time Left", 700, 110);
    timeDisplay = timeLeft / 100.0;
    g2.drawString(timeDisplay.toString(), 700, 160);
  }
Beispiel #15
0
  /** {@inheritDoc} */
  @Override
  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2d = (Graphics2D) g.create();
    g2d.setBackground(Color.white);
    int xDim = (int) (getWidth() / 56);
    int yDim = (int) (getHeight() / 66);
    g2d.drawLine(0, (agent[0].length) * yDim, Slope.getWidth() * xDim, (agent[0].length) * yDim);
    g2d.drawRect((Slope.getWidth() - 3) * xDim, 0, 15, Slope.getHeight() * yDim);

    for (int k = 0; k < Slope.getHeight(); k++)
      for (int l = 0; l < Slope.getWidth(); l++) {

        g2d.setColor(new Color(0, 0, 0, 1));
        g2d.drawRect(k * getWidth() / 56, l * getHeight() / 66, 30, 30);
      }

    for (int i = 0; i < agent.length; i++) {
      for (int j = 0; j < agent[0].length; j++) {
        g2d.setColor(Color.blue);
        if (agent[i][j]) {
          //					 g2d.drawString("*", i*getWidth()/56, j*getHeight()/66);
          g2d.drawImage(image, i * getWidth() / 56, j * getHeight() / 66, null);
        }
      }
    }
  }
 private void placerPostes(Graphics2D g) {
   g.setStroke(new BasicStroke());
   for (PlanSalle.Poste poste : modele.listerPostes()) {
     g.setColor(Color.gray);
     int xPoste = Parametres.posteX(poste.getPosition().getTravee(), poste.getOrientation());
     int yPoste = Parametres.posteY(poste.getPosition().getRangee(), poste.getOrientation());
     int xPersonne =
         Parametres.personneX(poste.getPosition().getTravee(), poste.getOrientation());
     int yPersonne =
         Parametres.personneY(poste.getPosition().getRangee(), poste.getOrientation());
     if (poste.getOrientation() == Orientation.NORD
         || poste.getOrientation() == Orientation.SUD) {
       g.fill3DRect(xPoste, yPoste, Parametres.LONGUEUR_POSTE, Parametres.LARGEUR_POSTE, true);
     } else {
       g.fill3DRect(xPoste, yPoste, Parametres.LARGEUR_POSTE, Parametres.LONGUEUR_POSTE, true);
     }
     g.drawOval(xPersonne, yPersonne, Parametres.LARGEUR_PERSONNE, Parametres.LARGEUR_PERSONNE);
     if (poste.peutVoir()) {
       g.setColor(Color.red);
     } else {
       g.setColor(Color.blue);
     }
     g.fillOval(xPersonne, yPersonne, 20, 20);
   }
 }
Beispiel #17
0
 /** [Internal] */
 private void paintBackground(Graphics2D g2, Color theBackground) {
   Color color1 = g2.getColor();
   if (theBackground == null) theBackground = Color.white;
   g2.setColor(theBackground);
   g2.fillRect(0, 0, 30000, 30000);
   g2.setColor(color1);
 }
Beispiel #18
0
 /**
  * Erases a String on the Canvas.
  *
  * @param text the String to be displayed
  * @param x x co-ordinate for text placement
  * @param y y co-ordinate for text placement
  */
 public void eraseString(String text, int x, int y) {
   Color original = graphic.getColor();
   graphic.setColor(backgroundColour);
   graphic.drawString(text, x, y);
   graphic.setColor(original);
   canvas.repaint();
 }
  @Override
  public void paint(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    Color old = g2d.getColor();
    // Draw box
    g2d.setColor(
        clicked
            ? this.clickedBackColor
            : (hovering ? this.hoverBackColor : this.unclickedBackColor));
    g2d.fillRect(0, 0, getWidth(), getHeight());
    // Draw label
    g2d.setColor(
        clicked
            ? this.clickedForeColor
            : (hovering ? this.hoverForeColor : this.unclickedForeColor));
    g2d.setFont(getFont());
    int width = g2d.getFontMetrics().stringWidth(getText());
    int textHeight = getFont().getSize();
    int otherTextHeight = getFontMetrics(getFont()).getHeight();

    textHeight = textHeight - (otherTextHeight - textHeight);
    int height = textHeight + (getHeight() - textHeight) / 2;
    g2d.drawString(getText(), (getWidth() - width) / 2, height);

    g2d.setColor(old);
  }
Beispiel #20
0
  public void paint(java.awt.Graphics g) {
    if (element != null) {
      Rectangle bounds = element.jGetBounds();
      Graphics2D g2 = (Graphics2D) g;

      g2.setFont(font);

      int mitteX = bounds.x + (bounds.width) / 2;
      int mitteY = bounds.y + (bounds.height) / 2;

      int distanceY = 10;

      g2.setColor(new Color(204, 204, 255));
      g2.fillRect(bounds.x, mitteY - distanceY, bounds.width, 2 * distanceY);
      g2.setColor(Color.BLACK);
      g2.drawRect(bounds.x, mitteY - distanceY, bounds.width, 2 * distanceY);

      String caption = "dec(" + variable.getValue() + ")";

      FontMetrics fm = g2.getFontMetrics();
      Rectangle2D r = fm.getStringBounds(caption, g2);

      g2.setColor(Color.BLACK);
      g.drawString(
          caption, mitteX - (int) (r.getWidth() / 2), (int) (mitteY + fm.getHeight() / 2) - 3);
    }
    super.paint(g);
  }
Beispiel #21
0
  public void paintComponent(Graphics g) {
    super.paintComponent(g);

    int centerX = getWidth() / 2;
    int centerY = getHeight() / 2;

    Graphics2D g2d = (Graphics2D) g.create();

    g2d.translate(centerX, centerY); // Set Graphics2D transform origin to center of panel

    g2d.setColor(fgColor);
    bar.setFrame(-barWidth / 2, -barHeight / 2 + barHeight * barPosition, barWidth, barHeight);
    g2d.fill(bar);
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    for (Spike spike : spikes) {
      if (spike != null) {
        double opacity = 255;
        if (spike.getDirection() == 0) {
          opacity = getWidth() * 0.5 - 70 - spike.getPosition().getX();
        } else {
          opacity = spike.getPosition().getX() + getWidth() * 0.5 - 70;
        }
        g2d.setColor(new Color(0, 0, 0, (int) clamp(opacity * 10, 0, 255)));
        g2d.fill(spike);
      }
    }
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
    g2d.setColor(Color.BLACK);
    g2d.draw(barCross);
    g2d.setStroke(new BasicStroke(2));
    g2d.draw(barFrame);
    g2d.dispose();
  }
Beispiel #22
0
  public VolatileImage renderBackgroundLayer(int LayerNumber) {
    // create hardware accellerated background layer (Volatile Image)
    backgroundLayer[LayerNumber] =
        this.getGraphicsConfiguration()
            .createCompatibleVolatileImage(
                loadedLevel.getWidth() * 16,
                loadedLevel.getHeight() * 16,
                Transparency.TRANSLUCENT);
    Graphics2D g2d = backgroundLayer[LayerNumber].createGraphics();
    g2d.setComposite(AlphaComposite.Src);

    // Clear the image.
    g2d.setColor(new Color(0, 0, 0, 0));
    g2d.fillRect(
        0, 0, backgroundLayer[LayerNumber].getWidth(), backgroundLayer[LayerNumber].getHeight());
    g2d.setBackground(new Color(0, 0, 0, 0));

    g2d.setColor(new Color(1f, 1f, 1f, 1f));
    for (int i = 0;
        i
            < backgroundLayer[LayerNumber].getWidth(this)
                / backgroundImage[LayerNumber].getWidth(this);
        i++) {
      g2d.drawImage(
          backgroundImage[LayerNumber], i * backgroundImage[LayerNumber].getWidth(this), 0, this);
    }
    return backgroundLayer[LayerNumber];
  }
Beispiel #23
0
  private void paintString(
      Graphics g, int x, int y, int width, int height, int fillStart, int amountFull, Insets b) {
    if (!(g instanceof Graphics2D)) {
      return;
    }

    Graphics2D g2D = (Graphics2D) g;
    String progressString = progressBar.getString();
    g2D.setFont(progressBar.getFont());
    Point renderLocation = getStringPlacement(g2D, progressString, x, y, width, height);
    Rectangle savedClip = g2D.getClipBounds();

    if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) {
      g2D.setColor(getSelectionBackground());
      Utilities.drawString(progressBar, g2D, progressString, renderLocation.x, renderLocation.y);
      g2D.setColor(getSelectionForeground());
      g2D.clipRect(fillStart, y, amountFull, height);
      Utilities.drawString(progressBar, g2D, progressString, renderLocation.x, renderLocation.y);
    } else { // VERTICAL
      g2D.setColor(getSelectionBackground());
      AffineTransform rotate = AffineTransform.getRotateInstance(Math.PI / 2);
      g2D.setFont(progressBar.getFont().deriveFont(rotate));
      renderLocation = getStringPlacement(g2D, progressString, x, y, width, height);
      Utilities.drawString(progressBar, g2D, progressString, renderLocation.x, renderLocation.y);
      g2D.setColor(getSelectionForeground());
      g2D.clipRect(x, fillStart, width, amountFull);
      Utilities.drawString(progressBar, g2D, progressString, renderLocation.x, renderLocation.y);
    }
    g2D.setClip(savedClip);
  }
Beispiel #24
0
  public void StaticObjNew(StaticObj so) {
    Graphics2D g = radarArea.backImage.createGraphics();
    g.setColor(so_color);

    if (so instanceof Beacon) {
      g.drawOval(
          convPos(so.pos.x) - grid_size / 6,
          convPos(so.pos.y) - grid_size / 6,
          grid_size / 3,
          grid_size / 3);
      JLabel sol = new JLabel(Integer.toString(so.id));
      sol.setForeground(so_text_color);
      sol.setBounds(
          convPos(so.pos.x) + grid_size / 6, convPos(so.pos.y), grid_size / 3, grid_size / 2);
      radarArea.add(sol, new Integer(1));
    }

    if (so instanceof Airfield) {
      int xa[] = new int[3], ya[] = new int[3];
      int l1 = grid_size / 2, l2 = grid_size / 6;
      xa[0] = convPos(so.pos.x);
      ya[0] = convPos(so.pos.y);
      xa[1] = convPos(so.pos.x) - l1 * so.dir.x - l2 * so.dir.y;
      ya[1] = convPos(so.pos.y) - l1 * so.dir.y + l2 * so.dir.x;
      xa[2] = convPos(so.pos.x) - l1 * so.dir.x + l2 * so.dir.y;
      ya[2] = convPos(so.pos.y) - l1 * so.dir.y - l2 * so.dir.x;
      g.drawPolygon(xa, ya, 3);
      JLabel sol = new JLabel(Integer.toString(so.id));
      sol.setForeground(so_text_color);
      sol.setBounds(
          convPos(so.pos.x) + grid_size / 6, convPos(so.pos.y), grid_size / 3, grid_size / 2);
      radarArea.add(sol, new Integer(1));
    }

    if (so instanceof Exit) {
      g.drawRect(
          convPos(so.pos.x) - grid_size / 6,
          convPos(so.pos.y) - grid_size / 6,
          grid_size / 3,
          grid_size / 3);
      JLabel sol = new JLabel(Integer.toString(so.id));
      sol.setForeground(so_text_color);
      sol.setBounds(
          convPos(so.pos.x) + grid_size / 6, convPos(so.pos.y), grid_size / 3, grid_size / 2);
      radarArea.add(sol, new Integer(1));
    }

    if (so instanceof Line) {
      g.setColor(line_color);
      g.drawLine(
          convPos(((Line) so).pos.x),
          convPos(((Line) so).pos.y),
          convPos(((Line) so).second_end.x),
          convPos(((Line) so).second_end.y));
    }

    radarArea.backIcon = new ImageIcon(radarArea.backImage);
    radarArea.back.setIcon(radarArea.backIcon);
  }
 @Override
 public void draw(Graphics2D g2) {
   int w = toolInterface.getStrokeWidth() * 4;
   Color c = g2.getColor();
   g2.setColor(Color.GRAY);
   g2.drawRect(mouseX - w / 2, mouseY - w / 2, w, w);
   g2.setColor(c);
 }
Beispiel #26
0
  /** PaintComponent to draw everything. */
  @Override
  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    setBackground(Color.WHITE);
    // If using images, use cool dragon background
    if (useImages) g.drawImage(background, 0, 0, 310, 300, null);

    // Use light gray to not overpower the background image
    g.setColor(Color.LIGHT_GRAY);
    for (int y = 1; y < ROWS; ++y)
      g.fillRoundRect(0, cellSize * y - 4, (cellSize * COLS) - 1, 8, 8, 8);
    for (int x = 1; x < COLS; ++x)
      g.fillRoundRect(cellSize * x - 4, 0, 8, (cellSize * ROWS) - 1, 8, 8);

    // Use graphics2d for when not using the images
    Graphics2D g2d = (Graphics2D) g;
    g2d.setStroke(new BasicStroke(4, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
    for (int y = 0; y < ROWS; ++y) {
      for (int x = 0; x < COLS; ++x) {
        int x1 = x * cellSize + 16;
        int y1 = y * cellSize + 16;
        if (board[y][x] == Symbol.X) {
          // use image if set to true, otherwise use g2d
          // for thicker, better looking X's and O's
          if (useImages) g.drawImage(imageX, x1, y1, 75, 75, null);
          else {
            g2d.setColor(PURPLE);
            int x2 = (x + 1) * cellSize - 16;
            int y2 = (y + 1) * cellSize - 16;
            g2d.drawLine(x1, y1, x2, y2);
            g2d.drawLine(x2, y1, x1, y2);
          }
        } else if (board[y][x] == Symbol.O) {
          if (useImages) g.drawImage(imageO, x1, y1, 75, 75, null);
          else {
            g2d.setColor(Color.BLUE);
            g2d.drawOval(x1, y1, 70, 70);
          }
        }
      } // end for
    }

    // Set status bar based on gamestate.  If CONTINUE, show whose turn it is
    if (gameStatus == GameStatus.CONTINUE) {
      statusBar.setForeground(Color.BLACK);
      if (currentPlayer == Symbol.X) statusBar.setText("X's Turn");
      else statusBar.setText("O's Turn");
    } else if (gameStatus == GameStatus.DRAW) {
      statusBar.setForeground(Color.RED);
      statusBar.setText("Draw! Click to play again!");
    } else if (gameStatus == GameStatus.X_WIN) {
      statusBar.setForeground(Color.RED);
      statusBar.setText("X has won! Click to play again!");
    } else if (gameStatus == GameStatus.O_WIN) {
      statusBar.setForeground(Color.RED);
      statusBar.setText("O has won! Click to play again!");
    }
  }
Beispiel #27
0
  private void paintFirms(Graphics2D g2d) {

    Rectangle2D rec = new Rectangle2D.Double();
    ArrayList<Firm> firms = SleepStoneTest.firms;

    Stroke normalStroke = new BasicStroke();
    Stroke boldStroke = new BasicStroke(4f);

    g2d.setStroke(boldStroke);
    for (Firm x : firms) {
      rec.setRect(firmsPlace.get(x));
      FirmStatus status = x.getStatus();

      g2d.setColor(Color.black);

      g2d.drawString(x.getFirmName(), Math.round(rec.getMinX()), Math.round(rec.getMaxY() + 15d));

      g2d.drawString(
          Integer.toString(x.getWorkers().size()),
          Math.round(rec.getMinX()),
          Math.round(rec.getMinY() - 15d));
      // g2d.setColor(Color.RED);
      g2d.drawImage(
          firmIcon.getImage(),
          (int) rec.getX(),
          (int) rec.getY(),
          (int) rec.getWidth(),
          (int) rec.getHeight(),
          FirmStatus.getStatusColor(status),
          null);

      // draw the jobs done indicator
      if (status == FirmStatus.PRODUCING) {
        g2d.setColor(Color.black);
        g2d.setStroke(boldStroke);
        Rectangle jobsIndicator =
            new Rectangle(
                (int) rec.getMaxX() + 5,
                (int) rec.getMinY(),
                (int) (firmSpacing / 2d),
                (int) rec.getHeight());
        g2d.draw(jobsIndicator);
        float jobsToDo = x.getJobsToDo();
        float jobsDone = x.getJobsDone().availablePermits();
        float percentComplete = jobsDone / jobsToDo;
        g2d.setColor(Color.BLUE);
        jobsIndicator.setBounds(
            (int) rec.getMaxX() + 5,
            (int) rec.getMinY(),
            (int) (firmSpacing / 2d),
            (int) (((float) (rec.getHeight())) * percentComplete));
        g2d.fill(jobsIndicator);
        g2d.setStroke(normalStroke);
      }
      // index++;
    }
  }
Beispiel #28
0
 // initialize default image
 private BufferedImage getDefaultImage(int w, int h) {
   BufferedImage defaultImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
   Graphics2D graphics2D = defaultImage.createGraphics();
   graphics2D.setColor(new Color(200, 200, 200));
   graphics2D.fillRect(0, 0, w, h);
   graphics2D.setColor(new Color(130, 130, 130));
   graphics2D.drawRect(0, 0, w - 1, h - 1);
   return defaultImage;
 }
  private void paintCaret(Graphics2D g_) {
    EditorImpl.CaretRectangle[] locations = myEditor.getCaretLocations(true);
    if (locations == null) return;

    Graphics2D g = IdeBackgroundUtil.getOriginalGraphics(g_);
    int lineHeight = myView.getLineHeight();
    EditorSettings settings = myEditor.getSettings();
    Color caretColor = myEditor.getColorsScheme().getColor(EditorColors.CARET_COLOR);
    if (caretColor == null) caretColor = new JBColor(CARET_DARK, CARET_LIGHT);
    g.setColor(caretColor);
    for (EditorImpl.CaretRectangle location : locations) {
      int x = location.myPoint.x;
      int y = location.myPoint.y;
      Caret caret = location.myCaret;
      boolean isRtl = location.myIsRtl;
      if (myEditor.isInsertMode() != settings.isBlockCursor()) {
        int lineWidth = JBUI.scale(settings.getLineCursorWidth());
        g.fillRect(x, y, lineWidth, lineHeight);
        if (myDocument.getTextLength() > 0
            && caret != null
            && !myView.getLineLayout(caret.getLogicalPosition().line).isLtr()) {
          g.fillPolygon(
              new int[] {
                isRtl ? x + lineWidth : x,
                isRtl ? x + lineWidth - CARET_DIRECTION_MARK_SIZE : x + CARET_DIRECTION_MARK_SIZE,
                isRtl ? x + lineWidth : x
              },
              new int[] {y, y, y + CARET_DIRECTION_MARK_SIZE},
              3);
        }
      } else {
        int width = location.myWidth;
        int startX = Math.max(0, isRtl ? x - width : x);
        g.fillRect(startX, y, width, lineHeight - 1);
        if (myDocument.getTextLength() > 0 && caret != null) {
          int targetVisualColumn = caret.getVisualPosition().column;
          for (VisualLineFragmentsIterator.Fragment fragment :
              VisualLineFragmentsIterator.create(myView, caret.getVisualLineStart(), false)) {
            int startVisualColumn = fragment.getStartVisualColumn();
            int endVisualColumn = fragment.getEndVisualColumn();
            if (startVisualColumn < targetVisualColumn && endVisualColumn > targetVisualColumn
                || startVisualColumn == targetVisualColumn && !isRtl
                || endVisualColumn == targetVisualColumn && isRtl) {
              g.setColor(ColorUtil.isDark(caretColor) ? CARET_LIGHT : CARET_DARK);
              fragment.draw(
                  g,
                  startX,
                  y + myView.getAscent(),
                  targetVisualColumn - startVisualColumn - (isRtl ? 1 : 0),
                  targetVisualColumn - startVisualColumn + (isRtl ? 0 : 1));
              break;
            }
          }
        }
      }
    }
  }
Beispiel #30
0
  @Override
  public void paintComponent(Graphics g) {
    super.paintComponent(g);

    Graphics2D g2d = ((Graphics2D) g);
    g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
    g2d.setRenderingHint(
        RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
    g2d.setRenderingHint(
        RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_OFF);
    g2d.setRenderingHint(
        RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_SPEED);
    g2d.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DISABLE);
    g2d.setColor(Color.BLACK);
    g2d.fillRect(0, 0, getWidth(), getHeight());

    if (bufferedImage != null) {
      synchronized (LOCKER) {
        g2d.drawImage(bufferedImage, transformCells, null);
      }
    }
    // draw struct preview
    if (structurePreview != null) {
      Composite composite = g2d.getComposite();
      g2d.setComposite(compositeStructPreview);
      g2d.drawImage(structurePreview, previewTransform, null);
      g2d.setComposite(composite);
    }
    // draw grid
    if (transformCells.getScaleX() > SHOW_GRID_MIN_SCALE) {
      Composite composite = g2d.getComposite();
      g2d.setComposite(compositeGrid);
      g2d.drawImage(bufferedImageGrid, transformGrid, null);
      g2d.setComposite(composite);
    }
    // draw border for preview
    if (structurePreview != null && Math.abs(transformCells.getScaleX()) >= 0.95) {
      Shape shape = new Rectangle(0, 0, structurePreview.getWidth(), structurePreview.getHeight());
      shape = previewTransform.createTransformedShape(shape);
      g2d.setColor(Color.RED);
      g2d.draw(shape);
    }

    // draw border
    double x = transformCells.getTranslateX();
    double y = transformCells.getTranslateY();

    g2d.setColor(BORDER_COLOR);
    g2d.setStroke(new BasicStroke(BORDER_WIDTH));
    g2d.drawRect(
        round(x - BORDER_WIDTH),
        round(y - BORDER_WIDTH),
        round(getAutomatonWidth() * transformCells.getScaleX() + 2 * BORDER_WIDTH),
        round(getAutomatonHeight() * transformCells.getScaleY() + 2 * BORDER_WIDTH));
  }