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;
    }
  }
Example #2
0
      @Override
      public void paintComponent(Graphics g) {
        super.paintComponent(g);
        Graphics2D g2d = (Graphics2D) g;
        g2d.setStroke(new BasicStroke(3.0f));
        g2d.setColor(getForeground());

        Rectangle r = getBounds();

        if (!dir) {
          Ellipse2D c1 = new Ellipse2D.Double(0, 0, 10, 10);
          g2d.draw(c1);

          Ellipse2D c2 = new Ellipse2D.Double(r.width - 10, r.height - 10, 10, 10);
          g2d.draw(c2);

          g2d.drawLine(5, 5, r.width - 5, r.height - 5);
        } else {
          Ellipse2D c1 = new Ellipse2D.Double(0, r.height - 10, 10, 10);
          g2d.draw(c1);

          Ellipse2D c2 = new Ellipse2D.Double(r.width - 10, 0, 10, 10);
          g2d.draw(c2);

          g2d.drawLine(5, r.height - 5, r.width - 5, 5);
        }
      }
Example #3
0
  public void draw(Graphics2D graphics, DrawingProperties properties) {
    Color startingcol = graphics.getColor();
    Font startingfont = graphics.getFont();
    graphics.setColor(Constants.COLOR_ERROR);
    graphics.setFont(Constants.FONT_CANVAS_SMALL);

    int w = cmptodraw.getWidth();
    int h = cmptodraw.getHeight();
    if (componentName == null) componentName = cmptodraw.getTypeName().toString();

    // draw a rectangle
    graphics.setColor(Color.WHITE);
    graphics.fillRect(EDGE_OFFSET, EDGE_OFFSET, w - 2 * EDGE_OFFSET, h - 2 * EDGE_OFFSET);
    graphics.setColor(Constants.COLOR_ERROR);
    graphics.drawRect(EDGE_OFFSET, EDGE_OFFSET, w - 2 * EDGE_OFFSET, h - 2 * EDGE_OFFSET);

    // draw invalidated sign
    graphics.drawLine(EDGE_OFFSET, EDGE_OFFSET, w - EDGE_OFFSET, h - EDGE_OFFSET);
    graphics.drawLine(EDGE_OFFSET, h - EDGE_OFFSET, w - EDGE_OFFSET, EDGE_OFFSET);

    // draw border
    int wmeo = w - EDGE_OFFSET;
    int hmeo = h - EDGE_OFFSET;
    for (int j = BORDER_LINES_STEP * 2; j <= hmeo; j += BORDER_LINES_STEP) {
      graphics.drawLine(0, j, EDGE_OFFSET, j - BORDER_LINES_STEP);
      graphics.drawLine(wmeo, j, w, j - BORDER_LINES_STEP);
    }
    for (int i = 0; i <= wmeo; i += BORDER_LINES_STEP) {
      graphics.drawLine(i, EDGE_OFFSET, i + BORDER_LINES_STEP, 0);
      graphics.drawLine(i, h, i + BORDER_LINES_STEP, hmeo);
    }

    // draw component type name and instance name
    if (properties.drawingComponentNames) {
      Font oldf = graphics.getFont();
      Color oldc = graphics.getColor();

      Font f = new Font(Constants.TEXT_FONT_CANVAS, Font.PLAIN, Constants.TEXT_NORMAL_FONT_SIZE);
      graphics.setFont(f);
      graphics.drawString(
          cmptodraw.getName().toString(), 0, -Constants.TEXT_NORMAL_FONT_SIZE * 1.5f);

      f = new Font(Constants.TEXT_FONT_CANVAS, Font.PLAIN, Constants.TEXT_SMALL_FONT_SIZE);
      int r = oldc.getRed() + 140;
      r = (r > 230) ? (230) : (r);
      int g = oldc.getGreen() + 140;
      g = (g > 230) ? (230) : (g);
      int b = oldc.getBlue() + 140;
      b = (b > 230) ? (230) : (b);
      graphics.setColor(new Color(r, g, b));
      graphics.setFont(f);
      graphics.drawString(componentName, 0, -Constants.TEXT_NORMAL_FONT_SIZE * 0.5f);

      graphics.setFont(oldf);
      graphics.setColor(oldc);
    }

    graphics.setColor(startingcol);
    graphics.setFont(startingfont);
  }
  /**
   * Draw the icon at the specified location. Icon implementations may use the Component argument to
   * get properties useful for painting, e.g. the foreground or background color.
   *
   * @param c the component which the icon belongs to
   * @param gorg the graphic object to draw on
   * @param x the upper left point of the icon in the x direction
   * @param y the upper left point of the icon in the y direction
   */
  public void paintIcon(final Component c, final Graphics gorg, final int x, final int y) {
    final Graphics2D g = (Graphics2D) gorg.create();
    if (!mousepressed) {
      g.translate(-1, -1);
    }

    if (mousepressed && mouseover) {
      g.setColor(Color.WHITE);
      g.fillRect(x + 1, y + 1, 14, 14);
    }

    g.setColor(Color.black);
    g.drawRect(x + 1, y + 1, 14, 14);
    if (mouseover) {
      g.setColor(Color.GRAY);
    }

    g.setStroke(new BasicStroke(2));
    // from top left to bottom right
    g.drawLine(x + 5, y + 5, x + 12, y + 12);
    // from bottom left to top right
    g.drawLine(x + 12, y + 5, x + 5, y + 12);

    g.dispose();
  }
  @Override
  public void onPaint(Graphics2D graphics2D) {
    this.runtimeMillis = System.currentTimeMillis() - this.startTimeMillis;
    graphics2D.setColor(new Color(0, 0, 100, 120));
    graphics2D.fillRect(25, 240, 350, 82);

    graphics2D.setColor(Color.GREEN);
    graphics2D.fillRect(25, 240, 3 * this.expTracker.getPercentageToNextLevel(Skill.HERBLORE), 9);

    graphics2D.setColor(Color.WHITE);
    graphics2D.drawRect(25, 240, 350, 9);
    graphics2D.drawRect(25, 240, 350, 82);

    int cleanedPerHour =
        (int)
            (3600000.0
                / (double) (System.currentTimeMillis() - this.startTimeMillis)
                * (double) this.herbsCleaned);
    String profitsPerHour =
        String.valueOf(cleanedPerHour * this.profitPerClean)
            .replaceAll("(\\d)(?=(\\d{3})+$)", "$1,");

    graphics2D.setFont(new Font("Monospaced", 0, 12));
    graphics2D.drawString(
        "Herbs cleaned: " + this.herbsCleaned + " | (" + cleanedPerHour + ")", 28, 260);
    graphics2D.drawString("Current State: " + this.textualState, 28, 270);
    graphics2D.drawString("Time running: " + Core.formatElapsedTime(this.runtimeMillis), 28, 280);
    graphics2D.drawString(
        "XP Gained: "
            + this.expTracker.getExperienceGained(Skill.HERBLORE)
            + (" | (" + this.expTracker.getLevelsGained(Skill.HERBLORE) + ")"),
        28,
        290);
    graphics2D.drawString(
        "XP/hr: "
            + this.expTracker.gainedPerHour(Skill.HERBLORE)
            + " | Profit/hr: "
            + profitsPerHour,
        28,
        300);
    graphics2D.drawString(
        "Time till next level: "
            + Core.formatElapsedTime(this.expTracker.timeUntilNextLevel(Skill.HERBLORE)),
        28,
        310);

    graphics2D.drawLine(
        (int) this.getMouse().getPosition().getX(),
        (int) this.getMouse().getPosition().getY() + 10,
        (int) this.getMouse().getPosition().getX(),
        (int) this.getMouse().getPosition().getY() - 10);
    graphics2D.drawLine(
        (int) this.getMouse().getPosition().getX() + 10,
        (int) this.getMouse().getPosition().getY(),
        (int) this.getMouse().getPosition().getX() - 10,
        (int) this.getMouse().getPosition().getY());

    graphics2D.setColor(Color.RED);
    graphics2D.drawString("by Chicken Wing      v1.0", 70, 320);
  }
Example #6
0
  private void drawInstance(InstancePainter painter, boolean isGhost) {
    Graphics2D g = (Graphics2D) painter.getGraphics().create();
    Location loc = painter.getLocation();
    g.translate(loc.getX(), loc.getY());

    Direction from = painter.getAttributeValue(StdAttr.FACING);
    int degrees = Direction.EAST.toDegrees() - from.toDegrees();
    double radians = Math.toRadians((degrees + 360) % 360);
    g.rotate(radians);

    GraphicsUtil.switchToWidth(g, Wire.WIDTH);
    if (!isGhost && painter.getShowState()) {
      g.setColor(painter.getPort(0).getColor());
    }
    g.drawLine(0, 0, 5, 0);

    GraphicsUtil.switchToWidth(g, 1);
    if (!isGhost && painter.shouldDrawColor()) {
      BitWidth width = painter.getAttributeValue(StdAttr.WIDTH);
      g.setColor(Value.repeat(Value.FALSE, width.getWidth()).getColor());
    }
    g.drawLine(6, -8, 6, 8);
    g.drawLine(9, -5, 9, 5);
    g.drawLine(12, -2, 12, 2);

    g.dispose();
  }
  protected void drawCoords(
      Graphics2D g,
      Color coordcolor,
      int offx,
      int cols,
      int COORDDELTA,
      int maxy,
      int offy,
      int rows,
      int maxx) {
    g.setColor(coordcolor);
    for (int c = offx; c <= offx + cols * BUCKET; c++) {
      int startx = (int) (BORDER + ((c - offx) / BUCKET * pixpercol));
      if (c % COORDDELTA == 0) {

        g.drawLine(startx, BORDER + (int) pixpercol, startx, maxy + (int) pixpercol);
        int value = c * coordscale;
        g.drawString("" + value, startx - 3, maxy + this.fontsize + 6);
      }
    }
    for (int r = offy; r <= offy + rows * BUCKET; r++) {
      int starty = (int) ((((r - offy) / BUCKET - 1) * pixperrow));
      if (r % COORDDELTA == 0) {
        g.drawLine(BORDER, maxy - starty, maxx, maxy - starty);
        int x = Math.max(1, BORDER - 10 - (int) (10 * (int) Math.log10(r + 1)));
        x = Math.min(x, BORDER - 15);
        int value = r * coordscale;
        g.drawString("" + value, x, maxy - starty + 3);
      }
    }
  }
  /**
   * 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);
  }
Example #9
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;
  }
  private void plot(Graphics2D g, Material material, Shape shape, boolean subdued) {
    final Stroke savedStroke = g.getStroke();
    g.setStroke(plotStroke);
    double yTensile = Inventory.tensileStrength(material, shape);
    final int iy = yPlotAreaBottom - (int) Math.round((yTensile / yMax) * heightPlotArea);
    g.setColor(subdued ? subduedBlue : Color.BLUE);
    g.drawLine(xPlotAreaLeft, iy, xPlotAreaRight, iy);

    final int nPlotPoints = 32;
    double yCompressive = Inventory.compressiveStrength(material, shape, 0.0);
    int iy0 = yPlotAreaBottom - (int) Math.round((yCompressive / yMax) * heightPlotArea);
    int ix0 = xPlotAreaLeft;
    g.setColor(subdued ? subduedRed : Color.RED);
    for (int i = 1; i <= nPlotPoints; i++) {
      double t = (double) i / nPlotPoints;
      double x = t * xMax;
      int ix1 = xPlotAreaLeft + (int) Math.round(t * widthPlotArea);
      yCompressive = Inventory.compressiveStrength(material, shape, x);
      int iy1 = yPlotAreaBottom - (int) Math.round((yCompressive / yMax) * heightPlotArea);
      g.drawLine(ix0, iy0, ix1, iy1);
      ix0 = ix1;
      iy0 = iy1;
    }
    g.setStroke(savedStroke);
    g.setColor(Color.BLACK);
  }
Example #11
0
  private void updateLevels() {
    Graphics2D g2 = (Graphics2D) panel.getGraphics();
    if (g2 == null) return;
    if (xPos < 10) {
      g2.setColor(Color.BLACK);
      g2.fillRect(0, 0, panel.getWidth(), panel.getHeight());
    }

    int newL = (int) sampleToDB(maxL);
    int newR = (int) sampleToDB(maxR);
    if (newL < -96) newL = -96;
    if (newR < -96) newR = -96;

    //		double db = sampleToDB(maxL);
    //		System.out.println("dB - L: " + newL + " - R: " + newR);
    //		System.out.println("height: " + heightL);
    //		g2.setColor(Color.BLACK);
    //		g2.fillRect(0, 0, panel.getWidth(), panel.getHeight());

    g2.setColor(Color.MAGENTA);
    g2.drawLine(xPos, -(oldL * 2), xPos + 1, -(newL * 2));
    g2.setColor(Color.CYAN);
    g2.drawLine(xPos, -(oldR * 2), xPos + 1, -(newR * 2));
    oldL = newL;
    oldR = newR;
    xPos++;
    if (xPos == panel.getWidth()) {
      xPos = 0;
    }
  }
Example #12
0
  public static final void drawAxes(final Canvas canvas, final OrbiterMouseHandler orbiter) {
    final int bottom = canvas.getHeight() - 1;
    final double s = 10.0;
    final double[] axes = {0.0, 0.0, 0.0, s, 0.0, 0.0, 0.0, s, 0.0, 0.0, 0.0, s};

    orbiter.transform(axes, 0.0, 0.0, 0.0);

    final Graphics2D g = canvas.getGraphics();

    g.setColor(RED);
    g.drawLine(
        (int) round(s + axes[0 + 0]),
        bottom - (int) round(s + axes[0 + 1]),
        (int) round(s + axes[3 + 0]),
        bottom - (int) round(s + axes[3 + 1]));
    g.setColor(GREEN);
    g.drawLine(
        (int) round(s + axes[0 + 0]),
        bottom - (int) round(s + axes[0 + 1]),
        (int) round(s + axes[6 + 0]),
        bottom - (int) round(s + axes[6 + 1]));
    g.setColor(BLUE);
    g.drawLine(
        (int) round(s + axes[0 + 0]),
        bottom - (int) round(s + axes[0 + 1]),
        (int) round(s + axes[9 + 0]),
        bottom - (int) round(s + axes[9 + 1]));
  }
Example #13
0
 public void paintComponent(Graphics g) {
   Graphics2D gs = (Graphics2D) g;
   // draw the background
   gs.setColor(Color.lightGray);
   gs.fillRect(0, 0, 48, 48);
   for (int i = 0; i < 4; i++) {
     for (int j = 0; j < 4; j++) {
       if (cTetrisBlock.m_blockGrid[i][j] == 1) {
         //// System.out.println(cTetrisBlock.getTetrisCoordinateX() + "  " +
         // cTetrisBlock.getTetrisCoordinateY() );
         // draw the block
         int corX = cTetrisBlock.getTetrisCoordinateX() + 10 * j;
         int corY = cTetrisBlock.getTetrisCoordinateY() + 10 * i;
         gs.setColor(new Color(100, 10, 30));
         gs.fillRect(corX, corY, 10, 10);
         // draw the outline
         gs.setColor(new Color(230, 230, 200));
         gs.drawLine(corX, corY, corX, corY + 10);
         gs.drawLine(corX, corY, corX + 10, corY);
         gs.drawLine(corX + 10, corY + 10, corX, corY + 10);
         gs.drawLine(corX + 10, corY + 10, corX + 10, corY);
       }
     }
   }
 }
Example #14
0
  /**
   * Draw the gridlines for the grid. We only draw the portion of the lines that intersect the
   * current clipping bounds.
   *
   * @param g2 the Graphics2 object to use to render
   */
  private void drawGridlines(Graphics2D g2) {
    Rectangle curClip = g2.getClip().getBounds();
    int top = getInsets().top, left = getInsets().left;

    int miny = Math.max(0, (curClip.y - top) / (cellSize + 1)) * (cellSize + 1) + top;
    int minx = Math.max(0, (curClip.x - left) / (cellSize + 1)) * (cellSize + 1) + left;
    int maxy =
        Math.min(numRows, (curClip.y + curClip.height - top + cellSize) / (cellSize + 1))
                * (cellSize + 1)
            + top;
    int maxx =
        Math.min(numCols, (curClip.x + curClip.width - left + cellSize) / (cellSize + 1))
                * (cellSize + 1)
            + left;

    g2.setColor(Color.GRAY);
    for (int y = miny; y <= maxy; y += cellSize + 1)
      for (int x = minx; x <= maxx; x += cellSize + 1) {
        Location loc = locationForPoint(new Point(x + cellSize / 2, y + cellSize / 2));
        if (loc != null && !grid.isValid(loc)) g2.fillRect(x + 1, y + 1, cellSize, cellSize);
      }

    g2.setColor(Color.BLACK);
    for (int y = miny; y <= maxy; y += cellSize + 1)
      // draw horizontal lines
      g2.drawLine(minx, y, maxx, y);

    for (int x = minx; x <= maxx; x += cellSize + 1)
      // draw vertical lines
      g2.drawLine(x, miny, x, maxy);
  }
Example #15
0
  @Override
  protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    int width = this.getBounds().width;
    int height = this.getBounds().height;

    Graphics2D g2 = (Graphics2D) g;

    g2.setStroke(new BasicStroke(3.0f));
    g2.drawOval(width / 3, height / 5, width / 3, height / 2);

    int x1 = width / 2;
    int y1 = height * 3 / 10;
    int x2 = x1 + (int) (height / 5 * Math.sin(anguloVela));
    int y2 = y1 + (int) (height / 5 * Math.cos(anguloVela));
    if (focusVela) {
      g2.setColor(Color.RED);
      g2.drawLine(x1, y1, x2, y2);
      g2.setColor(Color.BLACK);
    } else {
      g2.drawLine(x1, y1, x2, y2);
    }

    y1 = height * 7 / 10;
    x2 = x1 + (int) (height / 10 * Math.sin(anguloTimon));
    y2 = y1 + (int) (height / 10 * Math.cos(anguloTimon));
    if (focusTimon) {
      g2.setColor(Color.RED);
      g2.drawLine(x1, y1, x2, y2);
      g2.setColor(Color.BLACK);
    } else {
      g2.drawLine(x1, y1, x2, y2);
    }
  }
  public static void renderSurface(
      Graphics g,
      Container c,
      Rectangle rect,
      boolean toSimulateRollover,
      boolean hasTopBorder,
      boolean hasBottomBorder) {
    CellRendererPane buttonRendererPane = new CellRendererPane();
    JButton rendererButton = new JButton("");
    rendererButton.getModel().setRollover(toSimulateRollover);

    buttonRendererPane.setBounds(rect.x, rect.y, rect.width, rect.height);
    Graphics2D g2d = (Graphics2D) g.create();
    g2d.clipRect(rect.x, rect.y, rect.width, rect.height);
    buttonRendererPane.paintComponent(
        g2d,
        rendererButton,
        c,
        rect.x - rect.width / 2,
        rect.y - rect.height / 2,
        2 * rect.width,
        2 * rect.height,
        true);

    g2d.setColor(FlamingoUtilities.getBorderColor());
    if (hasTopBorder) {
      g2d.drawLine(rect.x, rect.y, rect.x + rect.width - 1, rect.y);
    }
    if (hasBottomBorder) {
      g2d.drawLine(
          rect.x, rect.y + rect.height - 1, rect.x + rect.width - 1, rect.y + rect.height - 1);
    }
    g2d.dispose();
  }
  private void showScale(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    g2d.setColor(Color.lightGray);
    int y_step = 20;
    float[] dash1 = {2f, 0f, 2f};

    Stroke strk = g2d.getStroke();

    g2d.setStroke(
        new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 1.0f, dash1, 2f));
    for (int y = m_y_offset - y_step; y > m_y_offset - (int) (m_height * 0.5); y -= y_step)
      g2d.drawLine(m_x_offset, y, m_width - m_x_offset, y);
    for (int y = m_y_offset + y_step; y < m_y_offset + (int) (m_height * 0.5); y += y_step)
      g2d.drawLine(m_x_offset, y, m_width - m_x_offset, y);

    for (int x = m_x_offset + y_step; x < m_width - m_x_offset; x += y_step)
      g2d.drawLine(x, m_y_offset - (int) (m_height * 0.5), x, m_y_offset + (int) (m_height * 0.5));

    Font cur_Font = new Font("Arial", Font.BOLD, 8);
    g.setFont(cur_Font);

    int i = y_step;
    for (int y = m_y_offset - y_step;
        y > m_y_offset - (int) (m_height * 0.5);
        y -= y_step, i += y_step) g.drawString(i + "", m_width - m_x_offset, y);
    i = -y_step;
    for (int y = m_y_offset + y_step;
        y < m_y_offset + (int) (m_height * 0.5);
        y += y_step, i -= y_step) g.drawString(i + "", m_width - m_x_offset, y);

    g2d.setStroke(strk);
  }
Example #18
0
  @Override
  public void paint(int x, int y, Graphics2D g) {

    // paint lines above, the first note that needs a line is 7 positions above a1, which has
    // position 0
    if (positionY <= -7) //
    {
      int numLines = ((positionY + 7) / -2) + 1;
      int finalY = (int) (y + positionSpacing + ((-positionY + 1) % 2) * positionSpacing);
      for (int i = 0; i < numLines; i++) {
        g.drawLine(x - 5, finalY, x + getSymbolWidth() + 5, finalY);
        finalY += (int) (2 * positionSpacing);
      }
    }
    // paint lines below, the first note that needs a line is 5 positions below a1, which has
    // position 0
    else if (positionY >= 5) {
      int numLines = ((positionY - 5) / 2) + 1;
      int finalY = (int) (y + (positionY % 2) * positionSpacing) + (positionY % 2);
      for (int i = 0; i < numLines; i++) {
        g.drawLine(x - 5, finalY, x + getSymbolWidth() + 5, finalY);
        finalY -= (int) (2 * positionSpacing);
      }
    }
  }
Example #19
0
 @Override
 public void paintComponent(Graphics g) {
   super.paintComponent(g);
   Graphics2D copy = (Graphics2D) g.create();
   if (dragging) {
     copy.drawImage(imageBuffer, 0, 0, null);
     if (objectDragging == SelectedForm.LINE) {
       Line l = (Line) objectDragged;
       copy.setColor(l.getColor());
       copy.drawLine(l.getP1().x, l.getP1().y, l.getP2().x, l.getP2().y);
     } else if (objectDragging == SelectedForm.SQUARE) {
       Square sq = (Square) objectDragged;
       copy.setColor(sq.getColor());
       copy.drawRect(
           sq.adjustRendering().x, sq.adjustRendering().y, sq.getWidth(), sq.getHeight());
     } else if (objectDragging == SelectedForm.CIRCLE) {
       Circle c = (Circle) objectDragged;
       copy.setColor(c.getColor());
       copy.drawOval(c.adjustRendering().x, c.adjustRendering().y, c.getWidth(), c.getHeight());
     } else if (objectDragging == SelectedForm.POLYLINE) {
       Polyline poly = (Polyline) objectDragged;
       copy.setColor(poly.getColor());
       poly.fill();
       int[] XIS = poly.getX();
       int[] YSP = poly.getY();
       copy.drawPolyline(XIS, YSP, poly.getN());
       copy.drawLine(
           XIS[poly.getN() - 1], YSP[poly.getN() - 1], poly.getActualX(), poly.getActualY());
     }
   } else {
     copy.drawImage(imageBuffer, 0, 0, null);
   }
   copy.dispose();
 }
  @Override
  public void paintComponent(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    super.paintComponent(g);

    /*TODO solution pas terrible pour les GLiens qui servent un peu ˆ rienÉ*/
    for (int i = 0; i < gLiens.size(); i++) {
      g2d.setStroke(new BasicStroke(2));
      g2d.drawLine(
          (int) gLiens.get(i).getA().getCentreX(),
          (int) gLiens.get(i).getA().getCentreY(),
          (int) gLiens.get(i).getB().getCentreX(),
          (int) gLiens.get(i).getB().getCentreY());
    }

    for (int i = 0; i < gLiensConditionnels.size(); i++) {
      g2d.setColor(Color.RED);
      g2d.setStroke(new BasicStroke(2));
      g2d.drawLine(
          (int) gLiensConditionnels.get(i).getA().getCentreX() - 2,
          (int) gLiensConditionnels.get(i).getA().getCentreY() - 2,
          (int) gLiensConditionnels.get(i).getB().getCentreX() - 2,
          (int) gLiensConditionnels.get(i).getB().getCentreY() - 2);
    }

    for (int i = 0; i < this.gLinksTrigger.size(); i++) {
      g2d.setColor(Color.ORANGE);
      g2d.setStroke(new BasicStroke(3));
      g2d.drawLine(
          (int) gLinksTrigger.get(i).getA().getCentreX() - 2,
          (int) gLinksTrigger.get(i).getA().getCentreY() - 2,
          (int) gLinksTrigger.get(i).getB().getCentreX() - 2,
          (int) gLinksTrigger.get(i).getB().getCentreY() - 2);
    }
  }
Example #21
0
 public void drawCluster(Cluster cluster) {
   int index = clusters.indexOf(cluster);
   if (index != -1) {
     cluster.y = maxY;
     cluster.x = minX + index * factor;
     if (cluster.size() > 1) g.setColor(Color.RED);
     else g.setColor(Color.BLACK);
     g.drawRect(cluster.x - 1, cluster.y - cluster.size(), 2, 1 + cluster.size());
   } else {
     Cluster left = cluster.getLeft();
     Cluster right = cluster.getRight();
     drawCluster(left);
     drawCluster(right);
     int yBar = minY + (int) ((maxY - minY) * (cluster.getSimilarity() / threshold));
     g.setColor(Color.DARK_GRAY);
     if (left.y > yBar) {
       g.drawLine(left.x, left.y - 1, left.x, yBar);
       writeMap(left, yBar);
     }
     if (right.y > yBar) {
       g.drawLine(right.x, right.y - 1, right.x, yBar);
       writeMap(right, yBar);
     }
     g.setColor(Color.BLACK);
     g.drawLine(left.x, yBar, right.x, yBar);
     cluster.x = (right.x + left.x) / 2;
     cluster.y = yBar;
   }
 }
Example #22
0
  @Override
  protected void fillTitleBar(Graphics2D g2) {
    Paint oldPaint = g2.getPaint();
    Stroke oldStroke = g2.getStroke();

    g2.setColor(new Color(241, 241, 241));
    g2.setStroke(new BasicStroke(1));
    g2.drawLine(0, 0, getWidth(), 0);

    LinearGradientPaint p =
        new LinearGradientPaint(
            1f,
            1f,
            1f,
            getHeight() - 1,
            new float[] {0.0f, 0.499f, 0.5f, 1.0f},
            new Color[] {
              new Color(230, 230, 230),
              new Color(202, 202, 202),
              new Color(202, 202, 202),
              new Color(178, 178, 178)
            });
    g2.setPaint(p);
    g2.fillRect(0, 0, getWidth(), this.getHeight() - 1);

    g2.setPaint(oldPaint);
    g2.setColor(new Color(104, 104, 104));
    g2.setStroke(new BasicStroke(1));
    g2.drawLine(getX(), getHeight() - 1, getWidth(), getHeight() - 1);

    g2.setStroke(oldStroke);
  }
 @Override
 public void drawItem(
     Graphics2D g2,
     CategoryItemRendererState state,
     Rectangle2D dataArea,
     CategoryPlot plot,
     CategoryAxis domainAxis,
     ValueAxis rangeAxis,
     CategoryDataset dataset,
     int row,
     int column,
     int pass) {
   drawItemInternal(
       g2, state, dataArea, plot, domainAxis, rangeAxis, dataset, row, column, pass);
   //            System.out.println(String.format("row %s, column %s, pass %s", row, column,
   // pass));
   if ((pass == 0) && (row == 1) && (column == 3)) {
     // Workaround: because the dataArea sits on the the Axis the 0% gridline gets drawn
     // over the category axis making it gray. To fix this as we draw another black line
     // to restore the black axis.
     g2.setColor(Color.black);
     g2.setStroke(new BasicStroke(2));
     g2.drawLine(
         (int) dataArea.getMinX(),
         (int) dataArea.getMaxY(),
         (int) dataArea.getMaxX(),
         (int) dataArea.getMaxY());
     g2.drawLine(
         (int) dataArea.getMinX(),
         (int) dataArea.getMinY(),
         (int) dataArea.getMinX(),
         (int) dataArea.getMaxY());
   }
 }
Example #24
0
  @Override
  public void draw(Graphics2D g2d, Surface s) {

    g2d.setPaint(getColor());
    g2d.fill(getSurface());

    if (getHover() && !selected) {
      Stroke outl = new BasicStroke(2f);
      g2d.setStroke(outl);
      if (getColor() != Color.red) g2d.setPaint(Color.red);
      else g2d.setPaint(Color.BLACK);
      g2d.drawPolygon(getSurface());
    } else if (selected) {
      float[] dash = {4f, 0f, 2f};
      BasicStroke outl =
          new BasicStroke(
              2f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 1.0f, dash, getFramesAlive() * .2f);
      g2d.setStroke(outl);

      if (ownedby.equals(Player.NONE)) {
        g2d.setPaint(Color.black);
      } else if (ownedby.equals(Player.COMPUTER)) {
        g2d.setPaint(Color.RED);
      } else if (ownedby.equals(Player.PLAYER)) {
        g2d.setPaint(Color.BLUE);
      }

      g2d.drawPolygon(getSurface());
    }

    g2d.setPaint(Color.BLUE.brighter());
    for (Territory t : neighbors) {
      double distance;
      if (CalculateDistance(this.capital.x, this.capital.y, t.GetCapital().x, t.GetCapital().y)
          < 800) g2d.drawLine(this.capital.x, this.capital.y, t.GetCapital().x, t.GetCapital().y);
      else {
        if (CalculateDistance(this.capital.x, this.capital.y, 0, 0) < 500) {
          g2d.drawLine(this.capital.x, this.capital.y, 0, 70);
        } else if (CalculateDistance(this.capital.x, this.capital.y, 0, 0) > 500) {
          g2d.drawLine(this.capital.x, this.capital.y, 1280, 70);
        }
      }
    }

    if (ownedby.equals(Player.NONE)) {
      g2d.setPaint(Color.black);
    } else if (ownedby.equals(Player.COMPUTER)) {
      g2d.setPaint(Color.RED);
    } else if (ownedby.equals(Player.PLAYER)) {
      g2d.setPaint(Color.BLUE);
    }

    g2d.setFont(new Font("TimesRoman", Font.PLAIN, 18));
    g2d.setStroke(new BasicStroke(1f));
    g2d.fillOval(capital.x - 10, capital.y - 10, 20, 20);
    g2d.setPaint(Color.BLACK);
    g2d.drawOval(capital.x - 10, capital.y - 10, 20, 20);
    g2d.setPaint(Color.WHITE);
    g2d.drawString("" + armies, capital.x - 5, capital.y + 5);
  }
Example #25
0
 protected void paint1Break(Graphics2D g2d) {
   if (lineStart == LINE_START_HORIZONTAL) {
     g2d.drawLine(p1.x, p1.y, p2.x, p1.y);
     g2d.drawLine(p2.x, p1.y, p2.x, p2.y);
     switch (lineArrow) {
       case LINE_ARROW_DEST:
         paintArrow(g2d, new Point(p2.x, p1.y), p2);
         break;
       case LINE_ARROW_SOURCE:
         paintArrow(g2d, new Point(p2.x, p1.y), p1);
         break;
       case LINE_ARROW_BOTH:
         paintArrow(g2d, new Point(p2.x, p1.y), p2);
         paintArrow(g2d, new Point(p2.x, p1.y), p1);
         break;
     }
   } else if (lineStart == LINE_START_VERTICAL) {
     g2d.drawLine(p1.x, p1.y, p1.x, p2.y);
     g2d.drawLine(p1.x, p2.y, p2.x, p2.y);
     switch (lineArrow) {
       case LINE_ARROW_DEST:
         paintArrow(g2d, new Point(p1.x, p2.y), p2);
         break;
       case LINE_ARROW_SOURCE:
         paintArrow(g2d, new Point(p1.x, p2.y), p1);
         break;
       case LINE_ARROW_BOTH:
         paintArrow(g2d, new Point(p1.x, p2.y), p2);
         paintArrow(g2d, new Point(p1.x, p2.y), p1);
         break;
     }
   }
 }
Example #26
0
    public final StickMan draw(
        final double[] locations,
        final Canvas canvas,
        final Canvas ids,
        final AtomicInteger idUnderMouse,
        final OrbiterMouseHandler orbiter) {
      final Graphics2D g = canvas.getGraphics();
      final int bottom = canvas.getHeight() - 1;

      {
        g.setColor(Color.CYAN);

        final int n = this.segments.length;

        for (int i = 0; i < n; i += 2) {
          final int v0 = this.offset + 3 * this.segments[i + 0];
          final int v1 = this.offset + 3 * this.segments[i + 1];

          g.drawLine(
              iround(locations[v0 + 0]),
              bottom - iround(locations[v0 + 1]),
              iround(locations[v1 + 0]),
              bottom - iround(locations[v1 + 1]));
        }
      }

      {
        g.setColor(Color.YELLOW);

        final int n = this.muscles.length;

        for (int i = 0; i < n; i += 2) {
          final int v0 = this.offset + 3 * this.muscles[i + 0];
          final int v1 = this.offset + 3 * this.muscles[i + 1];

          g.drawLine(
              iround(locations[v0 + 0]),
              bottom - iround(locations[v0 + 1]),
              iround(locations[v1 + 0]),
              bottom - iround(locations[v1 + 1]));
        }
      }

      for (int i = this.offset; i < this.nextOffset; i += 3) {
        final int r = 3;
        final int left = iround(locations[i + 0]) - r;
        final int top = bottom - iround(locations[i + 1]) - r;
        final int d = 2 * r;
        final int id = i / 3;

        g.setColor(id != idUnderMouse.get() ? RED : YELLOW);
        g.fillOval(left, top, d, d);

        ids.getGraphics().setColor(new Color(id + 1));
        ids.getGraphics().fillOval(left, top, d, d);
      }

      return this;
    }
  private void paintGridBoard(Graphics2D g2) {
    g2.setColor(Color.WHITE);
    g2.fillRect(
        columns[0].getStart(),
        rows[0].getStart(),
        columns[columns.length - 1].getEnd() - 1,
        rows[rows.length - 1].getEnd() - 1);

    g2.setColor(new Color(0xEEEEEE));
    g2.fillRect(
        columns[3].getStart(),
        rows[0].getStart(),
        columns[5].getEnd() - columns[3].getStart(),
        rows[rows.length - 1].getEnd());
    g2.fillRect(
        columns[0].getStart(),
        rows[3].getStart(),
        columns[columns.length - 1].getEnd(),
        rows[5].getEnd() - rows[3].getStart());
    g2.setColor(Color.WHITE);
    g2.fillRect(
        columns[3].getStart(),
        rows[3].getStart(),
        columns[5].getEnd() - columns[3].getStart(),
        rows[5].getEnd() - rows[3].getStart());

    g2.setColor(Color.BLACK);
    for (int li = 0; li < 9; li++) {
      g2.drawLine(
          columns[0].getStart(),
          rows[li].getStart(),
          columns[columns.length - 1].getEnd(),
          rows[li].getStart());
      g2.drawLine(
          columns[0].getStart(),
          rows[li].getEnd(),
          columns[columns.length - 1].getEnd(),
          rows[li].getEnd());
    }
    for (int co = 0; co < 9; co++) {
      g2.drawLine(
          columns[co].getStart(),
          rows[0].getStart(),
          columns[co].getStart(),
          rows[rows.length - 1].getEnd());
      g2.drawLine(
          columns[co].getEnd(),
          rows[0].getStart(),
          columns[co].getEnd(),
          rows[rows.length - 1].getEnd());
    }
    g2.setColor(Color.BLACK);
    g2.drawRect(
        columns[0].getStart() - 1,
        rows[0].getStart() - 1,
        columns[columns.length - 1].getEnd() - columns[0].getStart() + 2,
        rows[rows.length - 1].getEnd() - rows[0].getStart() + 2);
  }
Example #28
0
  @Override
  public void paintComponent(Graphics g) {
    super.paintComponent(g);

    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);

    g2.setFont(new Font("Arial", Font.BOLD, 10));

    // draw line
    int hBase = 16;
    g2.drawLine(0, getHeight() - hBase, getWidth() - 1, getHeight() - hBase);

    // draw line ticks
    double wBar = (double) getWidth() / (this.bins.length + 1);
    for (int i = 0; i < this.bins.length + 1; i++) {
      int x = (int) ((i + 0.5) * wBar);
      int y = getHeight() - hBase;

      g2.drawLine(x, y - 2, x, y + 2);
    }

    // draw labels
    double binInterval = (double) (this.intervalEnd - this.intervalStart) / this.bins.length;
    for (int i = 0; i < this.bins.length + 1; i++) {
      long value = (long) (this.intervalStart + i * binInterval);
      String label =
          SolutionUtils.format(
              value, this.configurationManager.getConfiguration("TIMER-PRECISION"), false);

      FontMetrics fontMetrics = g2.getFontMetrics();
      int width = fontMetrics.stringWidth(label);
      int height = fontMetrics.getAscent();
      int x = (int) ((i + 0.5) * wBar - width / 2);
      int y = getHeight() - (hBase - height) / 2;

      g2.drawString(label, x, y);
    }

    // draw bars
    long maxValue = 0L;
    for (int i = 0; i < this.bins.length; i++) {
      if (this.bins[i] > maxValue) {
        maxValue = this.bins[i];
      }
    }

    if (maxValue > 0) {
      for (int i = 0; i < this.bins.length; i++) {
        int x1 = (int) ((i + 0.5) * wBar);
        int x2 = (int) ((i + 1.5) * wBar);
        int y = getHeight() - hBase;
        int height = (int) (this.bins[i] * (getHeight() - hBase - 4) / maxValue);

        g2.drawRect(x1, y - height, x2 - x1, height);
      }
    }
  }
 private void doPaint(Graphics2D g, Rectangle r) {
   Color old = g.getColor();
   g.setColor(getForeground());
   g.drawLine(r.x, r.y, r.x + r.width, r.y + r.height);
   g.drawLine(r.x + 1, r.y, r.x + r.width + 1, r.y + r.height);
   g.drawLine(r.x + r.width, r.y, r.x, r.y + r.height);
   g.drawLine(r.x + r.width - 1, r.y, r.x - 1, r.y + r.height);
   g.setColor(old);
 }
Example #30
0
  protected void paintArrow(Graphics2D g2d, Point p1, Point p2, int width) {
    Point2D.Float pp1 = new Point2D.Float(p1.x, p1.y);
    Point2D.Float pp2 = new Point2D.Float(p2.x, p2.y);
    Point2D.Float left = getLeftArrowPoint(pp1, pp2, width);
    Point2D.Float right = getRightArrowPoint(pp1, pp2, width);

    g2d.drawLine(p2.x, p2.y, Math.round(left.x), Math.round(left.y));
    g2d.drawLine(p2.x, p2.y, Math.round(right.x), Math.round(right.y));
  }