Ejemplo n.º 1
0
  private BufferedImage createGrid() {
    if (transformCells.getScaleY() < SHOW_GRID_MIN_SCALE) {
      return null;
    }

    Point2D cellSize = getCellSizeAfterScale();
    cellWidth = round(cellSize.getX());
    cellHeight = round(cellSize.getY());

    BufferedImage image =
        new BufferedImage(
            getWidth() + 2 * (cellWidth),
            getHeight() + 2 * (cellHeight),
            BufferedImage.TYPE_INT_ARGB);
    Graphics2D graphics2D = image.createGraphics();
    graphics2D.setColor(new Color(0, true));
    graphics2D.fillRect(0, 0, image.getWidth(), image.getHeight());

    graphics2D.setPaint(Color.YELLOW);
    graphics2D.setStroke(new BasicStroke(1));

    for (int x = 0; x < image.getWidth(); x += cellWidth) {
      graphics2D.drawLine(x, 0, x, image.getHeight());
    }
    for (int y = 0; y < image.getHeight(); y += cellHeight) {
      graphics2D.drawLine(0, y, image.getWidth(), y);
    }
    transformGrid.setToIdentity();
    calculateGridTranslation();

    graphics2D.dispose();
    return image;
  }
  /**
   * Paint a background for all groups and a round blue border and background when a cell is
   * selected.
   *
   * @param g2 the <tt>Graphics2D</tt> object through which we paint
   */
  private void internalPaintComponent(Graphics2D g2) {
    Color borderColor = Color.GRAY;

    if (isSelected) {
      g2.setPaint(
          new GradientPaint(
              0, 0, Constants.SELECTED_COLOR, 0, getHeight(), Constants.SELECTED_GRADIENT_COLOR));

      borderColor = Constants.SELECTED_COLOR;
    } else if (treeNode instanceof GroupNode) {
      g2.setPaint(
          new GradientPaint(
              0,
              0,
              Constants.CONTACT_LIST_GROUP_BG_GRADIENT_COLOR,
              0,
              getHeight(),
              Constants.CONTACT_LIST_GROUP_BG_COLOR));

      borderColor = Constants.CONTACT_LIST_GROUP_BG_COLOR;
    }

    g2.fillRect(0, 0, getWidth(), getHeight());
    g2.setColor(borderColor);
    g2.drawLine(0, 0, getWidth(), 0);
    g2.drawLine(0, getHeight() - 1, getWidth(), getHeight() - 1);
  }
Ejemplo n.º 3
0
  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;
    }
  }
Ejemplo n.º 4
0
  public void drawAxes(Graphics2D g) {

    // create x and y axes
    g.setColor(ALIZARIN);
    g.drawLine(0, height / 2, 0, -height / 2);
    g.drawLine(width / 2, 0, -width / 2, 0);

    // create arrows
    g.drawLine(0, -height / 2, 5, -height / 2 + 5);
    g.drawLine(0, -height / 2, -5, -height / 2 + 5);
    g.drawLine(width / 2, 0, width / 2 - 5, 5);
    g.drawLine(width / 2, 0, width / 2 - 5, -5);

    // create hatch marks and coordinate numbers for x and y axis.
    int interval = (int) (zoom / 2);

    double coordinateNumber;
    String numberMark;

    for (int i = 0; i <= height / 2 - interval; i += zoom) {
      g.drawLine(-HATCH_LENGTH, i, HATCH_LENGTH, i);
      g.drawLine(-HATCH_LENGTH, -i, HATCH_LENGTH, -i);

      coordinateNumber = i / zoom;

      if (i != 0) {

        numberMark = String.format("%2.0f", -coordinateNumber);

        if (i % 2 == 0) g2.drawString(numberMark, 0 - HATCH_LENGTH - 18, i + 5);

        numberMark = String.format("%2.0f", coordinateNumber);

        g2.drawString(numberMark, 0 - HATCH_LENGTH - 18, -i + 5);
      }
    }

    for (int i = 0; i < width / 2 - interval; i += zoom) {
      g.drawLine(i, HATCH_LENGTH, i, -HATCH_LENGTH);
      g.drawLine(-i, HATCH_LENGTH, -i, -HATCH_LENGTH);

      coordinateNumber = i / zoom;

      if (i != 0) {

        numberMark = String.format("%2.0f", coordinateNumber);

        g2.drawString(numberMark, i - 6, 0 - HATCH_LENGTH - 5);

        numberMark = String.format("%2.0f", -coordinateNumber);

        g2.drawString(numberMark, -i - 6, 0 - HATCH_LENGTH - 3);
      }
    }
  }
  private static void drawSierpinskyTriangle(int level, int x, int y, int size, Graphics2D g) {
    if (level <= 0) return;

    g.drawLine(x, y, x + size, y);
    g.drawLine(x, y, x, y + size);
    g.drawLine(x + size, y, x, y + size);

    drawSierpinskyTriangle(level - 1, x, y, size / 2, g);
    drawSierpinskyTriangle(level - 1, x + size / 2, y, size / 2, g);
    drawSierpinskyTriangle(level - 1, x, y + size / 2, size / 2, g);
  }
Ejemplo n.º 6
0
  public void drawGrid(Graphics2D g) {

    g.setColor(WET_ASPHALT);
    for (int i = 0; i < height; i += zoom) {
      g.drawLine(i, -height / 2, i, height / 2);
      g.drawLine(-i, -height / 2, -i, height / 2);
    }

    for (int i = 0; i < width; i += zoom) {
      g.drawLine(-width / 2, i, width / 2, i);
      g.drawLine(-width / 2, -i, width / 2, -i);
    }
  }
Ejemplo n.º 7
0
  public static void paintButtonGroupLines(
      RadRootContainer rootContainer, RadButtonGroup group, Graphics g) {
    List<RadComponent> components = rootContainer.getGroupContents(group);
    if (components.size() < 2) return;
    Rectangle[] allBounds = new Rectangle[components.size()];
    int lastTop = -1;
    int minLeft = Integer.MAX_VALUE;
    for (int i = 0; i < components.size(); i++) {
      final Rectangle rc =
          SwingUtilities.convertRectangle(
              components.get(i).getParent().getDelegee(),
              components.get(i).getBounds(),
              rootContainer.getDelegee());
      allBounds[i] = rc;

      minLeft = Math.min(minLeft, rc.x);
      if (i == 0) {
        lastTop = rc.y;
      } else if (lastTop != rc.y) {
        lastTop = Integer.MIN_VALUE;
      }
    }

    Graphics2D g2d = (Graphics2D) g;
    Stroke oldStroke = g2d.getStroke();
    g2d.setStroke(new BasicStroke(2.0f));
    g2d.setColor(new Color(104, 107, 130));
    if (lastTop != Integer.MIN_VALUE) {
      // all items in group have same Y
      int left = Integer.MAX_VALUE;
      int right = Integer.MIN_VALUE;
      for (Rectangle rc : allBounds) {
        final int midX = (int) rc.getCenterX();
        left = Math.min(left, midX);
        right = Math.max(right, midX);
        g2d.drawLine(midX, lastTop - 8, midX, lastTop);
      }
      g2d.drawLine(left, lastTop - 8, right, lastTop - 8);
    } else {
      int top = Integer.MAX_VALUE;
      int bottom = Integer.MIN_VALUE;
      for (Rectangle rc : allBounds) {
        final int midY = (int) rc.getCenterY();
        top = Math.min(top, midY);
        bottom = Math.max(bottom, midY);
        g2d.drawLine(minLeft - 8, midY, rc.x, midY);
      }
      g2d.drawLine(minLeft - 8, top, minLeft - 8, bottom);
    }
    g2d.setStroke(oldStroke);
  }
Ejemplo n.º 8
0
  protected void paintHorizontalPartOfLeg(
      Graphics g,
      Rectangle clipBounds,
      Insets insets,
      Rectangle bounds,
      TreePath path,
      int param,
      boolean param6,
      boolean param7,
      boolean param8) {

    boolean selected = treeSelectionModel.isPathSelected(path);

    if (selected) {
      Graphics2D g2d = (Graphics2D) g;

      Color c1 = new Color(146, 163, 179);
      Color c2 = new Color(82, 108, 133);

      GradientPaint gradient =
          new GradientPaint(0, bounds.y, c1, 0, bounds.y + bounds.height, c2, true);
      g2d.setPaint(gradient);
      g2d.fillRect(0, bounds.y, tree.getWidth(), bounds.height);

      Color lineColor = new Color(123, 139, 157);
      g2d.setColor(lineColor);
      g2d.drawLine(0, bounds.y, tree.getWidth(), bounds.y);
    }
    // Do not call super. We dont want the lines.
  }
Ejemplo n.º 9
0
  /**
   * Draws a double headed arrow with arrow heads of a given width and height.
   *
   * @param aG the canvas to draw on;
   * @param aX1 the starting X position of the arrow;
   * @param aY1 the starting Y position of the arrow;
   * @param aX2 the ending X position of the arrow;
   * @param aY2 the ending Y position of the arrow;
   * @param aArrowWidth the total width of the arrow head;
   * @param aArrowHeight the total height of the arrow head.
   */
  public static final void drawDoubleHeadedArrow(
      final Graphics aG,
      final int aX1,
      final int aY1,
      final int aX2,
      final int aY2,
      final int aArrowWidth,
      final int aArrowHeight) {
    final Graphics2D g2d = (Graphics2D) aG.create();

    final int lineWidth = Math.abs(aX2 - aX1);
    final int threshold = (2 * aArrowWidth) + 2;
    try {
      int x1 = aX1;
      int x2 = aX2;

      if (lineWidth > threshold) {
        drawArrowHead(g2d, aX1, aY1, LEFT_FACING, aArrowWidth, aArrowHeight);
        // why x2 needs to be shifted by one pixel is beyond me...
        drawArrowHead(g2d, aX2 + 1, aY2, RIGHT_FACING, aArrowWidth, aArrowHeight);

        x1 += aArrowWidth - 1;
        x2 -= aArrowWidth + 1;
      }

      g2d.drawLine(x1, aY1, x2, aY2);
    } finally {
      g2d.dispose();
    }
  }
Ejemplo n.º 10
0
  // From: http://forum.java.sun.com/thread.jspa?threadID=378460&tstart=135
  void drawArrow(
      Graphics2D g2d,
      int xCenter,
      int yCenter,
      int x,
      int y,
      float stroke,
      BasicStroke drawStroke) {
    double aDir = Math.atan2(xCenter - x, yCenter - y);
    // Line can be dashed.
    g2d.setStroke(drawStroke);
    g2d.drawLine(x, y, xCenter, yCenter);
    // make the arrow head solid even if dash pattern has been specified
    g2d.setStroke(lineStroke);
    Polygon tmpPoly = new Polygon();
    int i1 = 12 + (int) (stroke * 2);
    // make the arrow head the same size regardless of the length length
    int i2 = 6 + (int) stroke;
    tmpPoly.addPoint(x, y);
    tmpPoly.addPoint(x + xCor(i1, aDir + .5), y + yCor(i1, aDir + .5));
    tmpPoly.addPoint(x + xCor(i2, aDir), y + yCor(i2, aDir));
    tmpPoly.addPoint(x + xCor(i1, aDir - .5), y + yCor(i1, aDir - .5));
    tmpPoly.addPoint(x, y); // arrow tip
    g2d.drawPolygon(tmpPoly);

    // Remove this line to leave arrow head unpainted:
    g2d.fillPolygon(tmpPoly);
  }
Ejemplo n.º 11
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);
        }
      }
    }
  }
Ejemplo n.º 12
0
  @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);
      }
    }
  }
Ejemplo n.º 13
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
  protected void paintCheckSign(Graphics2D g, boolean enabled, int w, int h) {
    g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
    g.setStroke(
        new BasicStroke(JBUI.scale(1) * 2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));

    g.setPaint(getShadowColor(enabled, true));
    final int x1 = JBUI.scale(5);
    final int y1 = JBUI.scale(9);
    final int x2 = JBUI.scale(7);
    final int y2 = JBUI.scale(11);
    g.drawLine(x1, y1, x2, y2);
    g.drawLine(x2, y2, w - JBUI.scale(2) - 1, JBUI.scale(5));
    g.setPaint(getCheckSignColor(enabled, true));
    g.drawLine(x1, y1 - 2, x2, y2 - 2);
    g.drawLine(x2, y2 - 2, w - JBUI.scale(2) - 1, JBUI.scale(5) - 2);
  }
Ejemplo n.º 15
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!");
    }
  }
Ejemplo n.º 16
0
 public void plot(Color c, int x0, int y0, int z0) {
   Graphics2D g = bi.createGraphics();
   g.setColor(c);
   if (x0 >= XRES || y0 >= YRES || x0 < 0 || y0 < 0) return;
   if (z0 > zbuffer[x0][y0]) {
     g.drawLine(x0, y0, x0, y0);
     zbuffer[x0][y0] = z0;
   }
 }
Ejemplo n.º 17
0
  public static void drawRound3DBorder(Graphics g, Color c1, Color c2, int x, int y, int w, int h) {
    Graphics2D g2D = (Graphics2D) g;
    int x2 = x + w;
    int y2 = y + h;
    int d = h;
    int r = h / 2;
    Color cm = ColorHelper.median(c1, c2);
    Color c1m = ColorHelper.median(c1, cm);
    Color c2m = ColorHelper.median(c2, cm);

    Object savedRederingHint = g2D.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
    g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    // oben
    g2D.setColor(c1);
    g2D.drawLine(x + r, y, x2 - r, y);
    // rechts
    g2D.drawLine(x, y + r, x, y2 - r);
    // unten
    g2D.setColor(c2);
    g2D.drawLine(x + r, y2, x2 - r, y2);
    // links
    g2D.drawLine(x2, y + r, x2, y2 - r);

    // links
    g2D.setColor(c1);
    g2D.drawArc(x, y, d, d, 90, 45);
    g2D.setColor(c1m);
    g2D.drawArc(x, y, d, d, 135, 45);
    g2D.setColor(cm);
    g2D.drawArc(x, y, d, d, 180, 45);
    g2D.setColor(c2m);
    g2D.drawArc(x, y, d, d, 225, 45);
    // rechts
    g2D.setColor(c1m);
    g2D.drawArc(x2 - d, y, d, d, 45, 45);
    g2D.setColor(cm);
    g2D.drawArc(x2 - d, y, d, d, 0, 45);
    g2D.setColor(c2m);
    g2D.drawArc(x2 - d, y, d, d, -45, 45);
    g2D.setColor(c2);
    g2D.drawArc(x2 - d, y, d, d, -90, 45);
    g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, savedRederingHint);
  }
Ejemplo n.º 18
0
 @Override
 protected void paintComponent(Graphics g) {
   super.paintComponent(g);
   Graphics2D g2 = (Graphics2D) g;
   Insets i = getInsets();
   // int y = g2.getFontMetrics().getHeight()*getLineAtCaret(this)+i.top;
   int y = caret.y + caret.height - 1;
   g2.setPaint(cfc);
   g2.drawLine(i.left, y, getSize().width - i.left - i.right, y);
 }
Ejemplo n.º 19
0
 private void quadriller(Graphics2D g) {
   float dash[] = {2f, 0f, 2f};
   BasicStroke pointilles =
       new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 1.0f, dash, 2f);
   g.setStroke(pointilles);
   for (int i = 1; i <= Parametres.NB_TRAVEES - 1; i++) {
     g.drawLine(
         Parametres.LARGEUR_TRAVEE * i,
         0,
         Parametres.LARGEUR_TRAVEE * i,
         Parametres.NB_RANGEES * Parametres.HAUTEUR_RANGEE - 1);
   }
   for (int i = 1; i <= Parametres.NB_RANGEES - 1; i++) {
     g.drawLine(
         0,
         Parametres.HAUTEUR_RANGEE * i,
         Parametres.NB_TRAVEES * Parametres.LARGEUR_TRAVEE - 1,
         Parametres.HAUTEUR_RANGEE * i);
   }
 }
Ejemplo n.º 20
0
  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();
  }
Ejemplo n.º 21
0
    /**
     * @param points
     * @param color
     * @param g
     */
    private void paintSequence(
        Slot type, List<List<ValuePointColored>> points, Color color, Graphics2D g) {
      int i = 0;
      int size = points.size();

      if (size > 0) {
        double increment = 200 / size;

        for (List<ValuePointColored> valuePoints : points) {
          int alpha = (int) (i * increment) + 55;
          Color c = new Color(color.getRed(), color.getGreen(), color.getBlue(), alpha);
          for (ValuePointColored valuePoint : valuePoints) {
            double[] coordinates = valuePoint.getPoint().toArray();
            int x = xToPix(coordinates[0]);
            int y = yToPix(coordinates[1]);
            // if minimum then red, else black
            if (valuePoint.getBest() == true) {
              g.setColor(Color.red);
            } else {
              g.setColor(c);
            }
            g.setStroke(LINE);

            switch (type) {
              case CIRCLE:
                g.drawOval(x - RADIUS / 2 - 3, y - RADIUS / 2 - 3, RADIUS * 2, RADIUS * 2);
                break;
              case SQUARE:
                g.drawRect(x - RADIUS / 2 - 2, y - RADIUS / 2 - 2, RADIUS * 2 - 2, RADIUS * 2 - 2);
                break;
              case TRIANGLE:
                GeneralPath polyline = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 3);
                polyline.moveTo(x, y - RADIUS / 2 - 4);
                polyline.lineTo(x + RADIUS / 2 + 3, y + RADIUS / 2 + 1);
                polyline.lineTo(x - RADIUS / 2 - 3, y + RADIUS / 2 + 1);
                polyline.closePath();
                g.draw(polyline);
                break;
              case CROSS:
                int xLow = x - RADIUS / 2 - 1;
                int xHigh = x + RADIUS / 2 + 1;
                int yLow = y - RADIUS / 2 - 1;
                int yHigh = y + RADIUS / 2 + 1;
                g.drawLine(xLow, yLow, xHigh, yHigh);
                g.drawLine(xHigh, yLow, xLow, yHigh);
                break;
            }
          }
          i++;
        }
      }
    }
Ejemplo n.º 22
0
  @Override
  public void paintBorder(Component component, Graphics g, int x, int y, int width, int height) {
    Graphics2D g2 = (Graphics2D) g;

    g2.setPaint(getBoundsColor());
    int horMargin = myOuterMargin.left + myOuterMargin.right;
    int vertMargin = myOuterMargin.top + myOuterMargin.bottom;

    g2.drawRect(
        x + myOuterMargin.left,
        y + myOuterMargin.top,
        x + width - 3 - horMargin,
        y + height - 3 - vertMargin);
    g2.setPaint(myShade1);

    g2.drawLine(
        x + 1 + myOuterMargin.left,
        y + height - 2 - myOuterMargin.bottom,
        x + width - 2 - myOuterMargin.right,
        y + height - 2 - myOuterMargin.bottom);
    g2.drawLine(
        x + width - 2 - myOuterMargin.right,
        y + 1 + myOuterMargin.bottom,
        x + width - 2 - myOuterMargin.right,
        y + height - 2 - myOuterMargin.bottom);

    g2.setPaint(myShade2);
    g2.drawLine(
        x + 2 + myOuterMargin.left,
        y + height - 1 - myOuterMargin.bottom,
        x + width - 1 - myOuterMargin.right,
        y + height - 1 - myOuterMargin.bottom);
    g2.drawLine(
        x + width - 1 - myOuterMargin.right,
        y + 2 + myOuterMargin.top,
        x + width - 1 - myOuterMargin.right,
        y + height - 1 - myOuterMargin.bottom);
  }
Ejemplo n.º 23
0
  @Override
  public void paintComponent(Graphics g) {
    final JLabel lbl = CHomeUI.SINGLETON_INSTANCE.getLblSelected();
    int yTop = (lbl.getY() + lbl.getParent().getY());

    // super.paintComponent(g);
    final Graphics2D g2d = (Graphics2D) g.create();
    final int w = getWidth();
    final int h = getHeight();

    FSkin.setGraphicsColor(g2d, d20);

    // Selected in this group, don't draw background under selected label.
    if (getY() < yTop && yTop < getY() + h) {
      g2d.fillRect(0, 0, w, lbl.getY());
      g2d.fillRect(0, lbl.getY() + lbl.getHeight(), w, h);

      FSkin.setGraphicsGradientPaint(g2d, w - 8, 0, l00, w, 0, d80);
      g2d.fillRect(w - 6, 0, w, lbl.getY());
      g2d.fillRect(w - 6, lbl.getY() + lbl.getHeight(), w, h);
    }
    // Selected not in this group; draw full background.
    else {
      g2d.fillRect(0, 0, w, h);

      FSkin.setGraphicsGradientPaint(g2d, w - 8, 0, l00, w, 0, d80);
      g2d.fillRect(w - 6, 0, w, h);
    }

    FSkin.setGraphicsColor(g2d, l10);
    g2d.drawLine(0, h - 1, w - 1, h - 1);

    FSkin.setGraphicsColor(g2d, d60);
    g2d.drawLine(0, 0, w - 1, 0);

    g2d.dispose();
  }
Ejemplo n.º 24
0
 @Override
 protected void paintComponent(Graphics g) {
   super.paintComponent(g);
   Graphics2D g2 = (Graphics2D) g.create();
   if (getModel().isPressed()) {
     g2.translate(1, 1);
   }
   g2.setStroke(new BasicStroke(2));
   g2.setColor(Color.BLACK);
   if (getModel().isRollover()) {
     g2.setColor(Color.WHITE);
   }
   int delta = 6;
   g2.drawLine(delta, delta, getWidth() - delta - 1, getHeight() - delta - 1);
   g2.drawLine(getWidth() - delta - 1, delta, delta, getHeight() - delta - 1);
   g2.dispose();
 }
Ejemplo n.º 25
0
 public void paint(Graphics g) {
   Graphics2D g2 = (Graphics2D) g;
   bg.paintIcon(this, g2, 0, 0);
   TreeMap<Integer, FactoryObject> to = (TreeMap<Integer, FactoryObject>) fos.clone();
   for (Integer i : to.keySet()) {
     FactoryObject t = to.get(i);
     if (t.getIsLine()) {
       g2.setColor(Color.WHITE);
       g2.drawLine(t.getPositionX(), t.getPositionY(), t.getPositionXF(), t.getPositionYF());
     } else {
       if (t.getImageIndex() >= 0) {
         ImageIcon tmp = images.getIcon(t.getImageIndex());
         tmp.paintIcon(this, g2, t.getPositionX(), t.getPositionY());
       }
     }
   }
 }
Ejemplo n.º 26
0
      /**
       * A paint class that will draw the needle, dots, and TO/FROM RenderingHints is IMPORTANT. It
       * will make sure that everything stays focused and not blurry whenever the image rotates. I
       * added an empty line between the 8 fillArcs, just so its easier to see that four of them
       * draw on the left side and four draw on the right side.
       */
      public void paintComponent(Graphics g) {
        Graphics2D g2 = (Graphics2D) g;
        RenderingHints hints = new RenderingHints(null);
        hints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        hints.put(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
        hints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
        g2.setRenderingHints(hints);
        g2.setStroke(new BasicStroke(3));
        // g2.drawString("TO", 190, 200);
        if (vor.isTo() == true) {
          if (vor.isAbeamed() == true) {
            // g2.setFont(new Font("default", Font.BOLD, 16));
            // g2.setColor(Color.red);
            // g2.drawString("BAD", 190, 200);
          } else {
            // g2.setFont(new Font("default", Font.BOLD, 16));
            g2.drawString("TO", 190, 200);
          }
        } else if (vor.isFrom() == true) {
          if (vor.isAbeamed() == true) {
            // g2.setFont(new Font("default", Font.BOLD, 16));
            // g2.setColor(Color.red);
            // g2.drawString("BAD", 190, 300);
          } else {
            // g2.setFont(new Font("default", Font.BOLD, 13));
            g2.drawString("FROM", 190, 300);
          }
        } else if (vor.isFrom() == false || vor.isTo() == false) {
          // is above the vor station no to or from
        }

        g2.fillArc(140, 240, 7, 7, 0, 360);
        g2.fillArc(125, 240, 7, 7, 0, 360);
        g2.fillArc(110, 240, 7, 7, 0, 360);
        g2.fillArc(95, 240, 7, 7, 0, 360);

        g2.fillArc(195, 240, 7, 7, 0, 360);
        g2.fillArc(210, 240, 7, 7, 0, 360);
        g2.fillArc(225, 240, 7, 7, 0, 360);
        g2.fillArc(240, 240, 7, 7, 0, 360);

        // g2.drawString("FROM",190, 300);
        g2.drawLine(x, y1, x, y2);
        super.paintComponent(g);
        g2.dispose();
      }
Ejemplo n.º 27
0
  private void renderClusters() {

    Graphics2D g2 = workImage.createGraphics();

    FastQueue<Polygon2D_F64> squares = alg.getFindSeeds().getDetectorSquare().getFound();

    for (int i = 0; i < squares.size(); i++) {
      Polygon2D_F64 p = squares.get(i);
      g2.setColor(Color.black);
      g2.setStroke(new BasicStroke(4));
      VisualizeShapes.drawPolygon(p, true, g2, true);
      g2.setColor(Color.white);
      g2.setStroke(new BasicStroke(2));
      VisualizeShapes.drawPolygon(p, true, g2, true);
    }

    List<SquareGrid> grids = alg.getFindSeeds().getGrids().getGrids();

    for (int i = 0; i < grids.size(); i++) {
      SquareGrid g = grids.get(i);
      int a = grids.size() == 1 ? 0 : 255 * i / (grids.size() - 1);

      int rgb = a << 16 | (255 - a) << 8;

      g2.setStroke(new BasicStroke(3));

      for (int j = 0; j < g.nodes.size() - 1; j++) {
        double fraction = j / ((double) g.nodes.size() - 1);
        fraction = fraction * 0.6 + 0.4;

        int lineRGB = (int) (fraction * a) << 16 | (int) (fraction * (255 - a)) << 8;

        g2.setColor(new Color(lineRGB));
        SquareNode p0 = g.nodes.get(j);
        SquareNode p1 = g.nodes.get(j + 1);
        g2.drawLine((int) p0.center.x, (int) p0.center.y, (int) p1.center.x, (int) p1.center.y);
      }

      g2.setColor(new Color(rgb));
      for (int j = 0; j < g.nodes.size(); j++) {
        SquareNode n = g.nodes.get(j);
        VisualizeShapes.drawPolygon(n.corners, true, g2, true);
      }
    }
  }
Ejemplo n.º 28
0
 private void tracerVisualisations(Graphics2D g) {
   float dash[] = {2f, 0f, 2f};
   BasicStroke pointilles =
       new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 1.0f, dash, 2f);
   g.setStroke(pointilles);
   g.setColor(Color.red);
   for (PlanSalle.Poste poste : modele.listerPostes()) {
     int centreX =
         Parametres.centrePersonneX(poste.getPosition().getTravee(), poste.getOrientation());
     int centreY =
         Parametres.centrePersonneY(poste.getPosition().getRangee(), poste.getOrientation());
     for (PlanSalle.Poste posteVisible : poste.getPostesVisibles()) {
       int visibleX = Parametres.centrePositionX(posteVisible.getPosition().getTravee());
       int visibleY = Parametres.centrePositionY(posteVisible.getPosition().getRangee());
       g.drawLine(centreX, centreY, visibleX, visibleY);
     }
   }
 }
Ejemplo n.º 29
0
  /**
   * Paints a custom gradient background for selected cells.
   *
   * @param g the <tt>Graphics</tt> object used for painting
   */
  private void internalPaintComponent(Graphics g) {
    AntialiasingManager.activateAntialiasing(g);

    Graphics2D g2 = (Graphics2D) g;
    int width = getWidth();
    int height = getHeight();

    if (this.isSelected) {
      GradientPaint p =
          new GradientPaint(
              width / 2, 0, SELECTED_START_COLOR, width / 2, height, SELECTED_END_COLOR);

      g2.setPaint(p);
      g2.fillRoundRect(1, 1, width, height - 1, 7, 7);
    }

    g2.setColor(SELECTED_START_COLOR);
    g2.drawLine(0, height - 1, width, height - 1);
  }
Ejemplo n.º 30
0
  @Override
  public void paintComponent(Graphics g) {
    super.paintComponent(g);

    Graphics2D g2 = (Graphics2D) g;

    if (images == null || selectedImage >= images.size()) return;

    BufferedImage image = images.get(selectedImage);

    double scaleX = getWidth() / (double) image.getWidth();
    double scaleY = getHeight() / (double) image.getHeight();
    double scale = Math.min(1, Math.min(scaleX, scaleY));

    AffineTransform tranOrig = g2.getTransform();
    AffineTransform tran = g2.getTransform();
    tran.concatenate(AffineTransform.getScaleInstance(scale, scale));

    g2.setTransform(tran);

    if (showUndistorted) {
      if (undoRadial != null && !isUndistorted) {
        undoRadialDistortion(image);
        isUndistorted = true;
      }
      g2.drawImage(undistorted, 0, 0, null);
    } else g2.drawImage(image, 0, 0, null);

    g2.setTransform(tranOrig);

    if (features.size() > selectedImage) {
      drawFeatures(g2, scale);
    }

    if (lineY > -1) {
      g2.setColor(Color.RED);
      g2.setStroke(new BasicStroke(3));
      g2.drawLine(0, lineY, getWidth(), lineY);
    }
  }