コード例 #1
0
ファイル: AutomatonPanel.java プロジェクト: Yozer/Automaton
  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;
  }
コード例 #2
0
  /**
   * 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);
  }
コード例 #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;
    }
  }
コード例 #4
0
ファイル: DrawTool.java プロジェクト: tstamler/linAlg
  // 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);
  }
コード例 #5
0
  private void drawSelection(Graphics2D g2d) {
    if (srcx != destx || srcy != desty) {
      int x1 = (srcx < destx) ? srcx : destx;
      int y1 = (srcy < desty) ? srcy : desty;
      int x2 = (srcx > destx) ? srcx : destx;
      int y2 = (srcy > desty) ? srcy : desty;

      rectSelection.x = x1;
      rectSelection.y = y1;
      rectSelection.width = (x2 - x1) + 1;
      rectSelection.height = (y2 - y1) + 1;
      if (rectSelection.width > 0 && rectSelection.height > 0) {
        g2d.drawImage(scr_img.getSubimage(x1, y1, x2 - x1 + 1, y2 - y1 + 1), null, x1, y1);
      }

      g2d.setColor(selFrameColor);
      g2d.setStroke(bs);
      g2d.draw(rectSelection);
      int cx = (x1 + x2) / 2;
      int cy = (y1 + y2) / 2;
      g2d.setColor(selCrossColor);
      g2d.setStroke(_StrokeCross);
      g2d.drawLine(cx, y1, cx, y2);
      g2d.drawLine(x1, cy, x2, cy);

      if (Screen.getNumberScreens() > 1) {
        drawScreenFrame(g2d, srcScreenId);
      }
    }
  }
コード例 #6
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);
      }
    }
  }
コード例 #7
0
ファイル: ATCUI_impl.java プロジェクト: sts44b/cs3330
  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);
  }
コード例 #8
0
ファイル: TicTac.java プロジェクト: Sykess/Eastwood
  /** 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!");
    }
  }
コード例 #9
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);
 }
コード例 #10
0
ファイル: graphPanel.java プロジェクト: TUDelftNAS/graphGEAR
  @Override
  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    if (nodes.get(0) == null) {
      return;
    }
    Graphics2D g2 = (Graphics2D) g;
    g2.setColor(Color.blue);
    int x = 0;
    int y = 0;
    double xs = (double) (this.getWidth() - b - (nodes.get(0).r * nodeScaling));
    double ys = (double) (this.getHeight() - b - (nodes.get(0).r * nodeScaling) - noticeBorder);
    g2.setColor(Color.black);
    g2.fillRect(0, 0, this.getWidth(), this.getHeight());
    g2.setColor(Color.blue);
    drawNode s;
    drawNode d;
    RenderingHints rh =
        new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setRenderingHints(rh);
    g2.setColor(Color.white);
    if (!ignoreLinks) {
      for (drawLink L : links.values()) {
        g2.setColor(L.color);
        s = nodes.get(L.sid);
        d = nodes.get(L.eid);
        if (s != null && d != null) {
          g2.drawLine(
              (int) ((s.x * xs) + (s.r * nodeScaling) / 2d),
              (int) ((s.y * ys) + (s.r * nodeScaling) / 2d),
              (int) ((d.x * xs) + (d.r * nodeScaling) / 2d),
              (int) ((d.y * ys) + (d.r * nodeScaling) / 2d));
        }
      }
    }
    for (drawNode N : nodes.values()) {
      g2.setColor(N.color);
      g2.fill(new Ellipse2D.Double(N.x * xs, N.y * ys, N.r * nodeScaling, N.r * nodeScaling));
      g2.setColor(Color.black);
      g2.draw(new Ellipse2D.Double(N.x * xs, N.y * ys, N.r * nodeScaling, N.r * nodeScaling));
    }
    if (showInfoForNode != -1 && nodeInfo.containsKey(showInfoForNode)) {
      drawNode N = nodes.get(showInfoForNode);

      x = (int) (N.x * xs + N.r * nodeScaling) + 3;
      y = (int) (N.y * ys);
      CTB.flipShift = (int) (N.r * nodeScaling) + 5;
      CTB.draw(g2, x, y, this.getWidth(), this.getHeight(), nodeInfo.get(showInfoForNode));
    }
    g2.setColor(Color.white);
    g2.setFont(new Font("Arial", Font.PLAIN, 10));
    g2.drawString("Ruud van de Bovenkamp - NAS", b, this.getHeight() - b);
    doneDrawing = true;
  }
コード例 #11
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);
   }
 }
コード例 #12
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();
  }
コード例 #13
0
ファイル: TabbedPane.java プロジェクト: neurolit/javascool
 @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();
 }
コード例 #14
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());
       }
     }
   }
 }
コード例 #15
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);
     }
   }
 }
コード例 #16
0
ファイル: Canvas.java プロジェクト: davidozhang/cs349
 public void paintComponent(Graphics g) {
   super.paintComponent(g);
   this.setBackground(Color.WHITE);
   Graphics2D g2d = (Graphics2D) g;
   RenderingHints rh =
       new RenderingHints(
           RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
   g2d.setRenderingHints(rh);
   for (int i = 0; i < strokes.size(); i++) {
     Stroke currentStroke = strokes.get(i);
     g2d.setPaint(currentStroke.getColor());
     g2d.setStroke(new BasicStroke(currentStroke.getThickness()));
     ArrayList<Point2D> currentStrokePoints = currentStroke.getPoints();
     for (int j = 1; j < currentStrokePoints.size(); j++) {
       g2d.drawLine(
           (int) (currentStrokePoints.get(j - 1).getX() * this.getSize().getWidth()),
           (int) (currentStrokePoints.get(j - 1).getY() * this.getSize().getHeight()),
           (int) (currentStrokePoints.get(j).getX() * this.getSize().getWidth()),
           (int) (currentStrokePoints.get(j).getY() * this.getSize().getHeight()));
     }
   }
 }
コード例 #17
0
ファイル: TerminalPanel.java プロジェクト: bitekas/jediterm
  private void drawCharacters(int x, int y, TextStyle style, CharBuffer buf, Graphics2D gfx) {
    int xCoord = x * myCharSize.width;
    int yCoord = y * myCharSize.height;

    if (xCoord < 0 || xCoord > getWidth() || yCoord < 0 || yCoord > getHeight()) {
      return;
    }

    gfx.setColor(getPalette().getColor(myStyleState.getBackground(style.getBackgroundForRun())));
    int textLength =
        CharUtils.getTextLengthDoubleWidthAware(
            buf.getBuf(),
            buf.getStart(),
            buf.length(),
            mySettingsProvider.ambiguousCharsAreDoubleWidth());

    gfx.fillRect(
        xCoord,
        yCoord,
        Math.min(textLength * myCharSize.width, getWidth() - xCoord),
        Math.min(myCharSize.height, getHeight() - yCoord));

    if (buf.isNul()) {
      return; // nothing more to do
    }

    drawChars(x, y, buf, style, gfx);

    gfx.setColor(getPalette().getColor(myStyleState.getForeground(style.getForegroundForRun())));

    int baseLine = (y + 1) * myCharSize.height - myDescent;

    if (style.hasOption(TextStyle.Option.UNDERLINED)) {
      gfx.drawLine(xCoord, baseLine + 1, (x + textLength) * myCharSize.width, baseLine + 1);
    }
  }
コード例 #18
0
ファイル: TerminalPanel.java プロジェクト: bitekas/jediterm
  private void drawInputMethodUncommitedChars(Graphics2D gfx) {
    if (myInputMethodUncommitedChars != null && myInputMethodUncommitedChars.length() > 0) {
      int x = myCursor.getCoordX() * myCharSize.width;
      int y = (myCursor.getCoordY()) * myCharSize.height - 2;

      int len = (myInputMethodUncommitedChars.length()) * myCharSize.width;

      gfx.setColor(getBackground());
      gfx.fillRect(x, (myCursor.getCoordY() - 1) * myCharSize.height, len, myCharSize.height);

      gfx.setColor(getForeground());
      gfx.setFont(myNormalFont);

      gfx.drawString(myInputMethodUncommitedChars, x, y);
      Stroke saved = gfx.getStroke();
      BasicStroke dotted =
          new BasicStroke(
              1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0, new float[] {0, 2, 0, 2}, 0);
      gfx.setStroke(dotted);

      gfx.drawLine(x, y, x + len, y);
      gfx.setStroke(saved);
    }
  }
コード例 #19
0
  /**
   * All purpose paint method that should do the right thing for almost all linear, determinate
   * progress bars. By setting a few values in the defaults table, things should work just fine to
   * paint your progress bar. Naturally, override this if you are making a circular or semi-circular
   * progress bar.
   *
   * @see #paintIndeterminate
   * @since 1.4
   */
  protected void paintDeterminate(Graphics g, JComponent c) {
    if (!(g instanceof Graphics2D)) {
      return;
    }

    Insets b = progressBar.getInsets(); // area for border
    int barRectWidth = progressBar.getWidth() - (b.right + b.left);
    int barRectHeight = progressBar.getHeight() - (b.top + b.bottom);

    if (barRectWidth <= 0 || barRectHeight <= 0) {
      return;
    }

    int cellLength = getCellLength();
    int cellSpacing = getCellSpacing();
    // amount of progress to draw
    int amountFull = getAmountFull(b, barRectWidth, barRectHeight);

    Graphics2D g2 = (Graphics2D) g;
    g2.setColor(progressBar.getForeground());

    if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) {
      // draw the cells
      if (cellSpacing == 0 && amountFull > 0) {
        // draw one big Rect because there is no space between cells
        g2.setStroke(
            new BasicStroke((float) barRectHeight, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
      } else {
        // draw each individual cell
        g2.setStroke(
            new BasicStroke(
                (float) barRectHeight,
                BasicStroke.CAP_BUTT,
                BasicStroke.JOIN_BEVEL,
                0.f,
                new float[] {cellLength, cellSpacing},
                0.f));
      }

      if (BasicGraphicsUtils.isLeftToRight(c)) {
        g2.drawLine(
            b.left, (barRectHeight / 2) + b.top, amountFull + b.left, (barRectHeight / 2) + b.top);
      } else {
        g2.drawLine(
            (barRectWidth + b.left),
            (barRectHeight / 2) + b.top,
            barRectWidth + b.left - amountFull,
            (barRectHeight / 2) + b.top);
      }

    } else { // VERTICAL
      // draw the cells
      if (cellSpacing == 0 && amountFull > 0) {
        // draw one big Rect because there is no space between cells
        g2.setStroke(
            new BasicStroke((float) barRectWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
      } else {
        // draw each individual cell
        g2.setStroke(
            new BasicStroke(
                (float) barRectWidth,
                BasicStroke.CAP_BUTT,
                BasicStroke.JOIN_BEVEL,
                0f,
                new float[] {cellLength, cellSpacing},
                0f));
      }

      g2.drawLine(
          barRectWidth / 2 + b.left,
          b.top + barRectHeight,
          barRectWidth / 2 + b.left,
          b.top + barRectHeight - amountFull);
    }

    // Deal with possible text painting
    if (progressBar.isStringPainted()) {
      paintString(g, b.left, b.top, barRectWidth, barRectHeight, amountFull, b);
    }
  }
コード例 #20
0
  private void drawPlot(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    g2d.setRenderingHint(
        RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    g2d.setColor(Color.white);
    g2d.fillRect(0, 0, getWidth(), getHeight());

    double activeWidth = getWidth() - leftMargin - rightMargin;
    double activeHeight = getHeight() - topMargin - bottomMargin;
    int bottomY = getHeight() - bottomMargin;
    int rightX = getWidth() - rightMargin;

    // draw data line
    int x1, x2, y1, y2;
    g2d.setColor(Color.red);
    for (int i = 1; i < numComponents; i++) {
      x1 = (int) (leftMargin + ((double) (i - 1) / (numComponents - 1)) * activeWidth);
      y1 = (int) (bottomY - (plotData[i - 1][plotIndex] * 10.0) / 1000 * activeHeight);
      x2 = (int) (leftMargin + ((double) (i) / (numComponents - 1)) * activeWidth);
      y2 = (int) (bottomY - (plotData[i][plotIndex] * 10) / 1000 * activeHeight);
      g2d.drawLine(x1, y1, x2, y2);
    }

    // draw data points
    int radius = 2;
    for (int i = 0; i < numComponents; i++) {
      x1 = (int) (leftMargin + ((double) (i) / (numComponents - 1)) * activeWidth);
      y1 = (int) (bottomY - (plotData[i][plotIndex] * 10.0) / 1000 * activeHeight);
      g2d.drawOval(x1 - radius - 1, y1 - radius - 1, 2 * radius + 2, 2 * radius + 2);
    }

    // draw axes
    g2d.setColor(Color.black);
    g2d.drawLine(leftMargin, bottomY, rightX, bottomY);
    g2d.drawLine(leftMargin, bottomY, leftMargin, topMargin);
    g2d.drawLine(leftMargin, topMargin, rightX, topMargin);
    g2d.drawLine(rightX, bottomY, rightX, topMargin);

    // draw ticks
    int tickSize = 4;
    for (int i = 1; i <= numComponents; i++) {
      x1 = (int) (leftMargin + ((double) (i - 1) / (numComponents - 1)) * activeWidth);
      g2d.drawLine(x1, bottomY, x1, bottomY + tickSize);
    }

    for (int i = 0; i <= 1000; i += 100) {
      y1 = (int) (bottomY - i / 1000.0 * activeHeight);
      g2d.drawLine(leftMargin, y1, leftMargin - tickSize, y1);
    }

    // labels
    DecimalFormat df = new DecimalFormat("#,###,###.###");
    Font font = new Font("SanSerif", Font.PLAIN, 11);
    FontMetrics metrics = g.getFontMetrics(font);
    int hgt, adv;
    hgt = metrics.getHeight();

    // x-axis labels
    String label;
    for (int i = 1; i <= numComponents; i++) {
      label = String.valueOf(i);
      x1 = (int) (leftMargin + ((double) (i - 1) / (numComponents - 1)) * activeWidth);
      adv = metrics.stringWidth(label) / 2;
      g2d.drawString(label, x1 - adv, bottomY + hgt + 4);
    }
    label = "Component";
    adv = metrics.stringWidth(label);
    int xAxisMidPoint = (int) (leftMargin + activeWidth / 2);
    g2d.drawString(label, xAxisMidPoint - adv / 2, bottomY + 2 * hgt + 6);

    // y-axis labels

    // rotate the font
    Font oldFont = g.getFont();
    Font f = oldFont.deriveFont(AffineTransform.getRotateInstance(-Math.PI / 2.0));
    g2d.setFont(f);

    int yAxisMidPoint = (int) (topMargin + activeHeight / 2);
    int offset;
    label = "Explained Variance (%)";
    offset = metrics.stringWidth("100.0") + 12 + hgt;
    adv = metrics.stringWidth(label);
    g2d.drawString(label, leftMargin - offset, yAxisMidPoint + adv / 2);

    // replace the rotated font.
    g2d.setFont(oldFont);

    df = new DecimalFormat("0.0");
    for (int i = 0; i <= 1000; i += 100) {
      label = df.format(i / 10);
      y1 = (int) (bottomY - i / 1000.0 * activeHeight);
      adv = metrics.stringWidth(label);
      g2d.drawString(label, leftMargin - adv - 12, y1 + hgt / 2);
    }

    // title

    // bold font
    oldFont = g.getFont();
    font = font = new Font("SanSerif", Font.BOLD, 12);
    g2d.setFont(font);

    label = "PCA Scree Plot";
    adv = metrics.stringWidth(label);
    g2d.drawString(label, getWidth() / 2 - adv / 2, topMargin - hgt - 5);

    g2d.setFont(oldFont);
  }
コード例 #21
0
ファイル: JCanvas.java プロジェクト: xaleth09/Connect4-AI
 // also clip, transform, composite,
 // public boolean isOpaque(){return false;}//theOpaque!=null&&theOpaque;}
 // ---------------------------------------------------------
 private void doPaint(Graphics2D g, int s, Object o) {
   // process an operation from the buffer
   // System.out.println(s);
   Object o1 = null,
       o2 = null,
       o3 = null,
       o4 = null,
       o5 = null,
       o6 = null,
       o7 = null,
       o8 = null,
       o9 = null,
       o10 = null,
       o11 = null;
   if (o instanceof Object[]) {
     Object[] a = (Object[]) o;
     if (a.length > 0) o1 = a[0];
     if (a.length > 1) o2 = a[1];
     if (a.length > 2) o3 = a[2];
     if (a.length > 3) o4 = a[3];
     if (a.length > 4) o5 = a[4];
     if (a.length > 5) o6 = a[5];
     if (a.length > 6) o7 = a[6];
     if (a.length > 7) o8 = a[7];
     if (a.length > 8) o9 = a[8];
     if (a.length > 9) o10 = a[9];
     if (a.length > 10) o11 = a[10];
   }
   switch (s) {
     case clear:
       paintBackground(g, theBackground);
       break;
       // public void addRenderingHints(Map<?,?> hints)
       // {toBuffer("addRenderingHints",hints );}
     case addRenderingHints:
       g.addRenderingHints((Map<?, ?>) o);
       break;
     case clip1:
       g.clip((Shape) o);
       break;
     case draw1:
       g.draw((Shape) o);
       break;
     case draw3DRect:
       g.draw3DRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Boolean) o5);
       break;
     case drawGlyphVector:
       g.drawGlyphVector((GlyphVector) o1, (Float) o2, (Float) o3);
       break;
     case drawImage1:
       g.drawImage((BufferedImage) o1, (BufferedImageOp) o2, (Integer) o3, (Integer) o4);
       break;
     case drawImage2:
       g.drawImage((Image) o1, (AffineTransform) o2, (ImageObserver) o3);
       break;
     case drawRenderableImage:
       g.drawRenderableImage((RenderableImage) o1, (AffineTransform) o2);
       break;
     case drawRenderedImage:
       g.drawRenderedImage((RenderedImage) o1, (AffineTransform) o2);
       break;
     case drawString1:
       g.drawString((AttributedCharacterIterator) o1, (Float) o2, (Float) o3);
       break;
     case drawString2:
       g.drawString((AttributedCharacterIterator) o1, (Integer) o2, (Integer) o3);
       break;
     case drawString3:
       g.drawString((String) o1, (Float) o2, (Float) o3);
       break;
     case drawString4:
       g.drawString((String) o1, (Integer) o2, (Integer) o3);
       break;
     case fill:
       g.fill((Shape) o);
       break;
     case fill3DRect:
       g.fill3DRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Boolean) o5);
       break;
     case rotate1:
       g.rotate((Double) o);
       break;
     case rotate2:
       g.rotate((Double) o1, (Double) o2, (Double) o3);
       break;
     case scale1:
       g.scale((Double) o1, (Double) o2);
       break;
     case setBackground:
       g.setBackground(
           (Color) o); // paintBackground(g,(Color)o); /*super.setBackground((Color)o) ;*/
       break;
     case setComposite:
       g.setComposite((Composite) o);
       break;
     case setPaint:
       g.setPaint((Paint) o);
       break;
     case setRenderingHint:
       g.setRenderingHint((RenderingHints.Key) o1, o2);
       break;
     case setRenderingHints:
       g.setRenderingHints((Map<?, ?>) o);
       break;
     case setStroke:
       g.setStroke((Stroke) o);
       break;
     case setTransform:
       g.setTransform(makeTransform(o));
       break;
     case shear:
       g.shear((Double) o1, (Double) o2);
       break;
     case transform1:
       g.transform(makeTransform(o));
       break;
     case translate1:
       g.translate((Double) o1, (Double) o2);
       break;
     case translate2:
       g.translate((Integer) o1, (Integer) o2);
       break;
     case clearRect:
       g.clearRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4);
       break;
     case copyArea:
       g.copyArea(
           (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6);
       break;
     case drawArc:
       g.drawArc(
           (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6);
       break;
     case drawBytes:
       g.drawBytes((byte[]) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5);
       break;
     case drawChars:
       g.drawChars((char[]) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5);
       break;
     case drawImage4:
       g.drawImage((Image) o1, (Integer) o2, (Integer) o3, (Color) o4, (ImageObserver) o5);
       break;
     case drawImage5:
       g.drawImage((Image) o1, (Integer) o2, (Integer) o3, (ImageObserver) o4);
       break;
     case drawImage6:
       g.drawImage(
           (Image) o1,
           (Integer) o2,
           (Integer) o3,
           (Integer) o4,
           (Integer) o5,
           (Color) o6,
           (ImageObserver) o7);
       break;
     case drawImage7:
       g.drawImage(
           (Image) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (ImageObserver) o6);
       break;
     case drawImage8:
       g.drawImage(
           (Image) o1,
           (Integer) o2,
           (Integer) o3,
           (Integer) o4,
           (Integer) o5,
           (Integer) o6,
           (Integer) o7,
           (Integer) o8,
           (Integer) o9,
           (Color) o10,
           (ImageObserver) o11);
       break;
     case drawImage9:
       g.drawImage(
           (Image) o1,
           (Integer) o2,
           (Integer) o3,
           (Integer) o4,
           (Integer) o5,
           (Integer) o6,
           (Integer) o7,
           (Integer) o8,
           (Integer) o9,
           (ImageObserver) o10);
       break;
     case drawLine:
       g.drawLine((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4);
       break;
     case drawOval:
       g.drawOval((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4);
       break;
     case drawPolygon1:
       g.drawPolygon((int[]) o1, (int[]) o2, (Integer) o3);
       break;
     case drawPolygon2:
       g.drawPolygon((Polygon) o);
       break;
     case drawPolyline:
       g.drawPolyline((int[]) o1, (int[]) o2, (Integer) o3);
       break;
     case drawRect:
       g.drawRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4);
       break;
     case drawRoundRect:
       g.drawRoundRect(
           (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6);
       break;
     case fillArc:
       g.fillArc(
           (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6);
       break;
     case fillOval:
       g.fillOval((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4);
       break;
       // {toBuffer("fillPolygon",mkArg(xPoints,  yPoints, nPoints) );}
     case fillPolygon1:
       g.fillPolygon((int[]) o1, (int[]) o2, (Integer) o3);
       break;
     case fillPolygon2:
       g.fillPolygon((Polygon) o);
       break;
     case fillRect:
       g.fillRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4);
       break;
     case fillRoundRect:
       g.fillRoundRect(
           (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6);
       break;
     case setClip1:
       g.setClip((Shape) o);
       break;
     case setColor:
       g.setColor((Color) o);
       break;
     case setFont:
       g.setFont((Font) o);
       break;
     case setPaintMode:
       g.setPaintMode();
       break;
     case setXORMode:
       g.setXORMode((Color) o);
       break;
     case opaque:
       super.setOpaque((Boolean) o);
       break;
     case drawOutline: // g.drawString((String)o1, (Integer)o2, (Integer)o3) ;break;
       {
         FontRenderContext frc = g.getFontRenderContext();
         TextLayout tl = new TextLayout((String) o1, g.getFont(), frc);
         Shape s1 = tl.getOutline(null);
         AffineTransform af = g.getTransform();
         g.translate((Integer) o2, (Integer) o3);
         g.draw(s1);
         g.setTransform(af);
       }
       ;
       break;
     default:
       System.out.println("Unknown image operation " + s);
   }
 }
コード例 #22
0
  public void paintComponent(java.awt.Graphics g) {
    if (offer == null || g == null) return;

    Graphics2D g2d = (Graphics2D) g;
    AffineTransform origTx = g2d.getTransform();
    AffineTransform at = new AffineTransform();

    int x = getSize().width;
    int y = getSize().height;

    int xGap = 25;
    int yGap = 35;

    int xPaint = x - xGap;
    int yPaint = y - yGap;

    int maxRows = offer.maxRows;
    int maxCols = offer.maxCols;

    g2d.setColor(Color.lightGray);
    g2d.clearRect(0, 0, x, y);

    double xDist = ((double) xPaint) / maxCols, yDist = ((double) yPaint) / maxRows;

    // I = resourcen
    for (int i = 0; i < maxCols; i++) {
      // J= farben
      for (int j = 0; j < maxRows; j++) {
        if (offer.history[i][j] != 0) {
          g2d.setColor(color[offer.history[i][j]]);
          g2d.fillRect(
              xGap + (int) (xDist * i),
              yGap + yPaint - (int) (yDist * (j + 1)),
              (int) (xDist + 1),
              (int) (yDist + 1));
        }
      }
    }

    g2d.setColor(Color.black);
    // Rotate 90 degrees clockwise about the position (x, y)
    at.rotate(-Math.PI / 2, y / 2, y / 2);
    g2d.transform(at);

    // Draw the string at the position (x, y)
    g2d.setFont(new Font("Arial", Font.ITALIC, 15));
    g2d.drawString("Capacity of resource", 20, 14);

    // Rotate back
    g2d.setTransform(origTx);

    for (int i = 0; i < maxRows; i++) {
      g2d.drawLine(xGap, yGap + (int) (yDist * i), xGap + xPaint, yGap + (int) (yDist * i));
      g2d.drawLine(xGap, yGap + (int) (yDist * i + 1), xGap + xPaint, yGap + (int) (yDist * i + 1));
    }
    g2d.drawLine(
        xGap,
        yGap + (int) (yDist * maxRows) - 1,
        xGap + xPaint,
        yGap + (int) (yDist * maxRows) - 1);
    g2d.drawLine(
        xGap,
        yGap + (int) (yDist * maxRows) - 2,
        xGap + xPaint,
        yGap + (int) (yDist * maxRows) - 2);

    g2d.setFont(new Font("Dialog", Font.BOLD, 12));
    g2d.drawString("t = ", 10, 16);
    for (int i = 0; i < maxCols; i++) {
      g2d.drawLine(xGap + (int) (xDist * i), yGap, xGap + (int) (xDist * i), y);
      g2d.drawLine(xGap + (int) (xDist * i + 1), yGap, xGap + (int) (xDist * i + 1), y);
      g2d.drawString(String.valueOf(i + 1), xGap + (int) (xDist * i) + (i < 9 ? 8 : 4), 16);
    }
    g2d.drawLine(xGap + (int) (xDist * maxCols) - 1, yGap, xGap + (int) (xDist * maxCols) - 1, y);
    g2d.drawLine(xGap + (int) (xDist * maxCols) - 2, yGap, xGap + (int) (xDist * maxCols) - 2, y);
  }
コード例 #23
0
  public void onRepaint(Graphics g1) {
    Graphics2D g = (Graphics2D) g1;
    String paintText = "Hide Paint";

    if (hidePaint) {
      paintText = "Show Paint";
      g.setColor(color1);
      g.fillRoundRect(closePaint.x, closePaint.y, closePaint.width, closePaint.height, 16, 16);
      g.setColor(color3);
      g.drawString(paintText, 435, 27);
    } else {
      g.setColor(color2);
      g.fillRoundRect(closePaint.x, closePaint.y, closePaint.width, closePaint.height, 16, 16);
      g.setColor(color3);
      g.drawString(paintText, 438, 27);

      final int skillPercent = skills.getPercentToNextLevel(Skills.FARMING);
      final int skillXP = skills.getExpToNextLevel(Skills.FARMING);
      final String xpToLevel;
      if (skillXP >= 1000) xpToLevel = Integer.toString(skillXP / 1000) + "k";
      else xpToLevel = Integer.toString(skillXP);
      final int nextLevel = skills.getRealLevel(Skills.FARMING) + 1;
      final int profit = marketPriceOfHerbs * numHerbsFarmed - marketPriceOfSeeds * numSeedsPlanted;
      final String profitMade;
      if (profit >= 100000) profitMade = Integer.toString(profit / 1000) + "k";
      else profitMade = Integer.toString(profit);

      String displayStatus = status;
      if (displayStatus == "Breaking while herbs grow: ")
        displayStatus += breakTimer.toRemainingString();

      int mouseX, mouseY;
      mouseX = (int) mouse.getLocation().getX();
      mouseY = (int) mouse.getLocation().getY();

      g.setColor(color1);
      g.drawLine(mouseX - 1000, mouseY, mouseX + 1000, mouseY);
      g.drawLine(mouseX, mouseY - 1000, mouseX, mouseY + 1000);
      g.fillRect(69, 320, 450, 21);
      g.setColor(color2);
      g.fillRect(69, 320, 450 * skillPercent / 100, 21);
      g.drawImage(img1, 0, 243, null);
      g.setFont(font1);
      g.drawString("Version: " + scriptVersion, 431, 471);
      g.setColor(color3);
      g.drawString(skillPercent + "% to level " + nextLevel + " (" + xpToLevel + " xp)", 216, 334);
      g.setColor(color1);
      g.drawString("Time Running: " + runTime.toElapsedString(), 102, 398);
      g.drawString("Herbs Farmed: " + numHerbsFarmed, 319, 399);
      g.drawString("Profit Made: " + profitMade, 319, 416);
      g.drawString("Seeds Planted: " + numSeedsPlanted, 102, 415);
      g.drawString("Seed Type: " + seedType, 102, 431);
      g.drawString("Status: " + displayStatus, 102, 449);

      if (currentLocation == Location.ARDOUGNE)
        for (int i = 1; i < camelotPath.length; i++) camelotPath[i].drawTo(g1, camelotPath[i - 1]);
      if (currentLocation == Location.CAMELOT)
        for (int i = 1; i < faladorPath.length; i++) faladorPath[i].drawTo(g1, faladorPath[i - 1]);
      if (currentLocation == Location.FALADOR)
        for (int i = 1; i < ardougnePath.length; i++)
          ardougnePath[i].drawTo(g1, ardougnePath[i - 1]);
    }
  }
コード例 #24
0
  public void paint(Graphics g) {
    Graphics2D graph = (Graphics2D) g;
    graph.setStroke(drawingStroke);
    graph.setPaint(Color.red);
    graph.draw(xAxis);
    graph.setPaint(Color.BLACK);
    graph.drawString("X", xStopHoriz + 10, yOnxAxis + 4);
    graph.setPaint(Color.red);
    graph.draw(yAxis);
    graph.setPaint(Color.BLACK);
    graph.drawString("Y", xOnyAxis - 4, yStartVert - 10);
    graph.setColor(Color.BLACK);
    graph.drawString("Graph for y= " + function, 150, 50);
    graph.drawString("Hold down the mouse click to read a corresponding curve y-value ", 15, 12);

    int xBump = (int) xAxisLength / (numberOfXs - 1);
    int xOffset = xStartHoriz;
    int[] xOffsets = new int[numberOfXs];

    int yBump = (int) yAxisLength / (numberOfExpressions - 1);
    int yOffset = yStopVert;
    int[] yOffsets = new int[numberOfExpressions];

    float[] yScaleValues = new float[numberOfExpressions];
    String[] yScaleStrings = new String[numberOfExpressions];

    float smallestYvalue = ordinates[0];
    float biggestYvalue = ordinates[0];

    for (int i = 0; i < numberOfXs; i++) {
      xOffsets[i] = xOffset;
      graph.drawString("|", xOffset - 2, yOnxAxis + 5);
      graph.drawString(abscissaeStrings[i], xOffset - 5, yOnxAxis + 25);
      xOffset += xBump;
    }

    // Determinate the biggest and the smallest y value
    for (float yValue : ordinates) {
      if (yValue > biggestYvalue) biggestYvalue = yValue;
      if (yValue < smallestYvalue) smallestYvalue = yValue;
    }

    yScaleValues[0] = smallestYvalue;
    yScaleStrings[0] = String.valueOf(smallestYvalue);

    float yScaleIncrement = (biggestYvalue - smallestYvalue) / numberOfExpressions;

    for (int i = 1;
        i < yScaleValues.length;
        i++) // Start at [1] because [0] contains the smallest value
    {
      yScaleValues[i] = (yScaleValues[(i - 1)] + yScaleIncrement);
      yScaleStrings[i] =
          String.format("%.01f", yScaleValues[i]); // To make the labels look neat by...
      // ...limiting the values to 2 decimal points
    }

    for (int i = 0; i < numberOfExpressions; i++) {
      yOffsets[i] = yOffset;
      graph.drawString("--", xOnyAxis - 5, yOffset + 2);

      if (!functionIsNotConstant)
        graph.drawString(yScaleStrings[0], 30, yOffset + 2); // Label only one y coordinate
      else {
        graph.drawString(yScaleStrings[i], 30, yOffset + 2); // Label all applicable y coordinates
        yOffset -= yBump;
      }
    }
    // ==================Drawing the curve======================
    int[] yPixelRelatives = new int[numberOfExpressions];
    double yValueRange = biggestYvalue - smallestYvalue;
    int yPixelRange = (int) yAxisLength;

    // Converting expression values into pixel values
    for (int i = 0; i < numberOfExpressions; i++) {
      double yValuePercent = (double) ((ordinates[i] - smallestYvalue) / yValueRange);
      int yPixelAbsolute = (int) (yPixelRange * yValuePercent);
      yPixelRelatives[i] = (yStopVert - yPixelAbsolute);
    }
    graph.setColor(Color.BLUE);
    for (int i = 0; i < yPixelRelatives.length; i++) {
      graph.drawOval(xOffsets[i] - 2, yPixelRelatives[i] - 2, 4, 4);

      if (i > 0)
        graph.drawLine(
            xOffsets[(i - 1)], yPixelRelatives[(i - 1)], xOffsets[i], yPixelRelatives[i]);
    }
  }
コード例 #25
0
    public void paint(Graphics g) {

      if (big == null) {
        return;
      }

      big.setBackground(getBackground());
      big.clearRect(0, 0, w, h);

      float freeMemory = (float) r.freeMemory();
      float totalMemory = (float) r.totalMemory();

      // .. Draw allocated and used strings ..
      big.setColor(GREEN);
      big.drawString(
          String.valueOf((int) totalMemory / 1024) + "K allocated", 4.0f, (float) ascent + 0.5f);
      usedStr = String.valueOf(((int) (totalMemory - freeMemory)) / 1024) + "K used";
      big.drawString(usedStr, 4, h - descent);

      // Calculate remaining size
      float ssH = ascent + descent;
      float remainingHeight = (float) (h - (ssH * 2) - 0.5f);
      float blockHeight = remainingHeight / 10;
      float blockWidth = 20.0f;
      float remainingWidth = (float) (w - blockWidth - 10);

      // .. Memory Free ..
      big.setColor(mfColor);
      int MemUsage = (int) ((freeMemory / totalMemory) * 10);
      int i = 0;
      for (; i < MemUsage; i++) {
        mfRect.setRect(5, (float) ssH + i * blockHeight, blockWidth, (float) blockHeight - 1);
        big.fill(mfRect);
      }

      // .. Memory Used ..
      big.setColor(GREEN);
      for (; i < 10; i++) {
        muRect.setRect(5, (float) ssH + i * blockHeight, blockWidth, (float) blockHeight - 1);
        big.fill(muRect);
      }

      // .. Draw History Graph ..
      big.setColor(graphColor);
      int graphX = 30;
      int graphY = (int) ssH;
      int graphW = w - graphX - 5;
      int graphH = (int) remainingHeight;
      graphOutlineRect.setRect(graphX, graphY, graphW, graphH);
      big.draw(graphOutlineRect);

      int graphRow = graphH / 10;

      // .. Draw row ..
      for (int j = graphY; j <= graphH + graphY; j += graphRow) {
        graphLine.setLine(graphX, j, graphX + graphW, j);
        big.draw(graphLine);
      }

      // .. Draw animated column movement ..
      int graphColumn = graphW / 15;

      if (columnInc == 0) {
        columnInc = graphColumn;
      }

      for (int j = graphX + columnInc; j < graphW + graphX; j += graphColumn) {
        graphLine.setLine(j, graphY, j, graphY + graphH);
        big.draw(graphLine);
      }

      --columnInc;

      if (pts == null) {
        pts = new int[graphW];
        ptNum = 0;
      } else if (pts.length != graphW) {
        int tmp[] = null;
        if (ptNum < graphW) {
          tmp = new int[ptNum];
          System.arraycopy(pts, 0, tmp, 0, tmp.length);
        } else {
          tmp = new int[graphW];
          System.arraycopy(pts, pts.length - tmp.length, tmp, 0, tmp.length);
          ptNum = tmp.length - 2;
        }
        pts = new int[graphW];
        System.arraycopy(tmp, 0, pts, 0, tmp.length);
      } else {
        big.setColor(YELLOW);
        pts[ptNum] = (int) (graphY + graphH * (freeMemory / totalMemory));
        for (int j = graphX + graphW - ptNum, k = 0; k < ptNum; k++, j++) {
          if (k != 0) {
            if (pts[k] != pts[k - 1]) {
              big.drawLine(j - 1, pts[k - 1], j, pts[k]);
            } else {
              big.fillRect(j, pts[k], 1, 1);
            }
          }
        }
        if (ptNum + 2 == pts.length) {
          // throw out oldest point
          for (int j = 1; j < ptNum; j++) {
            pts[j - 1] = pts[j];
          }
          --ptNum;
        } else {
          ptNum++;
        }
      }
      g.drawImage(bimg, 0, 0, this);
    }
コード例 #26
0
ファイル: GMap.java プロジェクト: joshuasm/gmap-viewer
  /** Get an image based on index numbers */
  public BufferedImage getIndexedImage(
      int x, int y, int zoom, int cacheZoom, GMapListener listener) {

    if (listener != null) {
      if (!getGDataSource().isCached(x, y, zoom)) {
        listener.updateGMapPainting();
        listener.updateGMapMessage(GMap.MESSAGE_DOWNLOADING);
      } else {
        listener.updateGMapMessage(GMap.MESSAGE_PAINTING);
      }
    }

    BufferedImage thumbImage = getGDataSource().getImage(x, y, zoom, true);

    if (thumbImage == null) return defaultImage;

    // if we dont have to paint cache, return here
    if (cacheZoom == (GPhysicalPoint.MIN_ZOOM - 1) || cacheZoom >= zoom) return thumbImage;

    BufferedImage paintedImage =
        new BufferedImage(
            GDataSource.sourceSize.width,
            GDataSource.sourceSize.height,
            BufferedImage.TYPE_INT_ARGB);
    Graphics2D graphics2D = paintedImage.createGraphics();
    graphics2D.drawImage(
        thumbImage, 0, 0, GDataSource.sourceSize.width, GDataSource.sourceSize.height, null);

    // now lets move to painting the cache
    double imageNum = Math.pow(2, zoom - cacheZoom);

    // draw cache lines
    int startX = (int) (imageNum * x);
    int startY = (int) (imageNum * y);

    // get composite to restore later, set new transparent composite
    Composite originalComposite = graphics2D.getComposite();
    graphics2D.setComposite(opacity40);

    // draw grid
    for (int i = 0; i < imageNum; i++) {
      for (int j = 0; j < imageNum; j++) {
        // points
        Point upperLeft =
            new Point(
                (int) (GDataSource.sourceSize.width / imageNum) * i,
                (int) (GDataSource.sourceSize.height / imageNum) * j);
        Dimension size =
            new Dimension(
                (int) (GDataSource.sourceSize.width / imageNum),
                (int) (GDataSource.sourceSize.height / imageNum));

        // draw lines
        graphics2D.setColor(new Color(100, 100, 100));
        graphics2D.drawLine(upperLeft.x, upperLeft.y, upperLeft.x + size.width, upperLeft.y);
        graphics2D.drawLine(upperLeft.x, upperLeft.y, upperLeft.x, upperLeft.y + size.height);

        // check if file exists
        if (getGDataSource().isCached(startX + i, startY + j, cacheZoom))
          graphics2D.setColor(Color.RED);
        else graphics2D.setColor(new Color(155, 155, 155));

        // shade rectangle
        graphics2D.fillRect(upperLeft.x, upperLeft.y, size.width, size.height);
      }
    }

    // restore composite
    graphics2D.setComposite(originalComposite);

    return paintedImage;
  }
コード例 #27
0
ファイル: FTACanvas.java プロジェクト: jandcmoore/OpenFTA
 public void drawLine(int x1, int y1, int x2, int y2) {
   gRef.drawLine(x1, y1, x2, y2);
 }
コード例 #28
0
    public void paint(Graphics g) {
      path = findOptimizedPath(srcID, dstID, type);

      /// Create the drawing board
      Dimension d = getSize();
      g.setColor(Color.white);
      g.fillRect(1, 1, d.width - 2, d.height - 2);

      g.setColor(Color.black);
      g.drawRect(1, 1, d.width - 2, d.height - 2);
      g.setFont(serifFont);

      /// Draw the whole network, including all routers with
      ///     delay and flow level, sources and destinations.
      int numR = 1;
      int w = 95;
      int h = d.height / 5;
      int pos = -1;

      for (int i = 0; i < 3; i++) {
        g.drawOval(w, h + 100 * i, 40, 40);
        g.drawString("S" + String.valueOf(i + 1), w + 13, h + 100 * i - 5);
      }

      for (int i = 0; i < 3; i++) {
        pos++;
        Router temp = statMux.getRouter(pos);
        g.drawOval(w + 110, h + 100 * i, 40, 40);
        g.drawString("R" + String.valueOf(numR++), w + 123, h + 100 * i - 5);
        g.drawString(
            String.valueOf(temp.getDelay() * temp.getPriority(type) + temp.getFlowLevel()),
            w + 125,
            h + 100 * i + 15);
        g.drawString(String.valueOf(temp.getFlowLevel()), w + 125, h + 100 * i + 35);
      }

      h = d.height / 11;
      for (int i = 0; i < 4; i++) {
        pos++;
        Router temp = statMux.getRouter(pos);
        g.drawOval(w + 210, h + 100 * i, 40, 40);
        g.drawString("R" + String.valueOf(numR++), w + 223, h + 100 * i - 5);
        g.drawString(
            String.valueOf(temp.getDelay() * temp.getPriority(type) + temp.getFlowLevel()),
            w + 225,
            h + 100 * i + 15);
        g.drawString(String.valueOf(temp.getFlowLevel()), w + 225, h + 100 * i + 35);
      }

      h = 20;
      for (int i = 0; i < 6; i++) {
        pos++;
        Router temp = statMux.getRouter(pos);
        g.drawOval(w + 310, h + 80 * i, 40, 40);
        g.drawString("R" + String.valueOf(numR++), w + 320, h + 80 * i - 5);
        g.drawString(
            String.valueOf(temp.getDelay() * temp.getPriority(type) + temp.getFlowLevel()),
            w + 325,
            h + 80 * i + 15);
        g.drawString(String.valueOf(temp.getFlowLevel()), w + 325, h + 80 * i + 35);
      }

      for (int i = 0; i < 4; i++) {
        g.drawOval(w + 410, d.height / 11 + 100 * i, 40, 40);
        g.drawString("D" + String.valueOf(i + 1), w + 423, d.height / 11 + 100 * i - 5);
      }

      g.setColor(Color.black);
      int[][] connection = statMux.getConnections();

      /// Check buffer for connections at each step and draw links at layer1
      for (int i = 0; i < connection[path[0] - 1].length; i++) {
        int temp = connection[path[0] - 1][i] - 3;
        g.drawLine(w + 40, (path[0]) * d.height / 5 + 20, w + 110, temp * d.height / 5 + 20);
      }

      /// Check buffer for connections at each step and draw links at layer2
      for (int i = 0; i < connection[path[1] - 1].length; i++) {
        int temp = connection[path[1] - 1][i] - 7;
        g.drawLine(
            w + 150, (path[1] - 3) * d.height / 5 + 20, w + 210, (d.height / 11) + 100 * temp + 20);
      }

      /// Check buffer for connections at each step and draw links at layer3
      for (int i = 0; i < connection[path[2] - 1].length; i++) {
        int temp = connection[path[2] - 1][i] - 11;
        g.drawLine(w + 250, (d.height / 11) + 100 * (path[2] - 7) + 20, w + 310, 80 * temp + 40);
      }

      /// Draw optimized path for packets traveling between source
      /// and destination
      h = d.height / 5;
      Graphics2D g2 = (Graphics2D) g;
      g2.setStroke(new BasicStroke(2));
      g2.setColor(Color.red);

      g2.drawLine(w + 40, h * (path[0]) + 20, w + 110, h * (path[1] - 3) + 20);
      g2.drawLine(
          w + 150, h * (path[1] - 3) + 20, w + 210, (d.height / 11) + 100 * (path[2] - 7) + 20);
      g2.drawLine(
          w + 250, (d.height / 11) + 100 * (path[2] - 7) + 20, w + 310, 80 * (path[3] - 11) + 40);
      g2.drawLine(
          w + 350, 80 * (path[3] - 11) + 40, w + 410, (d.height / 11) + 100 * (path[4] - 17) + 20);

      /// Calculate and display loss, delay, and throughput
      delayTime = getDelay(path, type);
      throughPut = getThroughput(path);

      int numPackLost = getLossRate(numTransfer);

      lossRate = numPackLost / 100000.0 + 0.0005 * delayTime;
      delayVal.setText(String.format("%.2f", delayTime));
      throuVal.setText(String.valueOf(throughPut));
      lossVal.setText(String.format("%.4f", lossRate));
    }
コード例 #29
0
  public void paintComponent(Graphics g) {
    // clear(g);
    Graphics2D g2d = (Graphics2D) g;

    RenderingHints rh =
        new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    g2d.setRenderingHints(rh);

    g.setColor(new Color(0, 0, 0));
    g.fillRect(0, 0, getWidth(), getHeight());

    // draw the connectors
    for (int i = 1; i < connections.length; i++) {

      NetworkButton b1 = this.nodeList.get(connections[i][0]);
      NetworkButton b2 = this.nodeList.get(connections[i][1]);

      g2d.setStroke(new BasicStroke(2));

      // grey line
      g2d.setPaint(new Color(50, 50, 50));
      g2d.drawLine(
          b1.x + b1.width / 2, b1.y + b1.height / 2, b2.x + b2.width / 2, b2.y + b2.height / 2);

      g2d.setStroke(new BasicStroke(1));

      // b1 line
      g2d.setPaint(b1.baseColor);
      g2d.drawLine(
          b1.x + b1.width / 2 - 2,
          b1.y - 2 + b1.height / 2,
          b2.x - 2 + b2.width / 2,
          b2.y - 2 + b2.height / 2);
      // b2 line
      g2d.setPaint(b2.baseColor);
      g2d.drawLine(
          b1.x + 2 + b1.width / 2,
          b1.y + 2 + b1.height / 2,
          b2.x + 2 + b2.width / 2,
          b2.y + 2 + b2.height / 2);

      // draw crosshairs around current

      String currentNode = mapPanel.networkPanel.getName();

      NetworkButton current = this.nodeList.get(currentNode);
      int x = current.x;
      int y = current.y;
      int height = current.height;
      int width = current.width;
      int l = (int) (height * 0.2);
      g2d.setStroke(new BasicStroke(6));
      g2d.setPaint(new Color(200, 200, 200));
      g2d.drawLine((int) (x + width * 0.5), y, (int) (x + width * 0.5), y - l);
      g2d.drawLine(x, (int) (y + height * 0.5), x - l, (int) (y + height * 0.5));
      g2d.drawLine((int) (x + width * 0.5), y + height, (int) (x + width * 0.5), y + height + l);
      g2d.drawLine(x + width, (int) (y + height * 0.5), x + width + l, (int) (y + height * 0.5));

      g2d.setStroke(new BasicStroke(4));
      g2d.setPaint(current.baseColor);
      g2d.drawLine((int) (x + width * 0.5), y, (int) (x + width * 0.5), y - l);
      g2d.drawLine(x, (int) (y + height * 0.5), x - l, (int) (y + height * 0.5));
      g2d.drawLine((int) (x + width * 0.5), y + height, (int) (x + width * 0.5), y + height + l);
      g2d.drawLine(x + width, (int) (y + height * 0.5), x + width + l, (int) (y + height * 0.5));
    }
  }
コード例 #30
0
ファイル: Arrow.java プロジェクト: simonhjsong/drawfbp
  void draw(Graphics2D g) {

    int endX, endY;
    Block from = null;
    if (fromId > -1) from = diag.blocks.get(new Integer(fromId));
    Block to = null;
    if (!endsAtLine && toId > -1) to = diag.blocks.get(new Integer(toId));

    if (toX == -1) endX = diag.xa;
    else endX = toX;

    if (toY == -1) endY = diag.ya;
    else endY = toY;

    g.setColor(Color.GRAY);

    Stroke stroke = g.getStroke();
    ZigzagStroke zzstroke = new ZigzagStroke(stroke, 2, 4);

    if (toX == -1) {
      g.drawRect(fromX - 3, fromY - 3, 6, 6);
      return;
    }

    if (from != null) {
      if (fromSide == Side.TOP) fromY = from.cy - from.height / 2;
      else if (fromSide == Side.BOTTOM) fromY = from.cy + from.height / 2;
      else if (fromSide == Side.LEFT) fromX = from.cx - from.width / 2;
      else if (fromSide == Side.RIGHT) fromX = from.cx + from.width / 2;
    }

    if (to != null) {
      if (toSide == Side.TOP) toY = to.cy - to.height / 2;
      else if (toSide == Side.BOTTOM) toY = to.cy + to.height / 2;
      else if (toSide == Side.LEFT) toX = to.cx - to.width / 2;
      else if (toSide == Side.RIGHT) toX = to.cx + to.width / 2;
    }

    if (driver.selArrowP == this) g.setColor(Color.BLUE);
    else if ((from instanceof ComponentBlock
            || from instanceof ExtPortBlock
            || from instanceof Enclosure)
        && (to instanceof ComponentBlock
            || to instanceof ExtPortBlock
            || to instanceof Enclosure
            || endsAtLine))
      if (checkStatus == Status.UNCHECKED) g.setColor(Color.BLACK);
      else if (checkStatus == Status.COMPATIBLE) g.setColor(FOREST_GREEN);
      else g.setColor(ORANGE_RED);
    else if (from instanceof LegendBlock || to instanceof LegendBlock) g.setColor(Color.GRAY);

    int fx, fy, tx, ty;
    fx = fromX;
    fy = fromY;
    // tx = toX;
    // ty = toY;
    // int autoX = -1, autoY = -1;  // only used for automatic ports
    if (bends != null) {
      for (Bend bend : bends) {
        tx = bend.x;
        ty = bend.y;
        if (!dropOldest) g.drawLine(fx, fy, tx, ty);
        else {
          Shape shape = new Line2D.Double(fx, fy, tx, ty);
          shape = zzstroke.createStrokedShape(shape);
          g.draw(shape);
          // g.setStroke(stroke);
        }

        if (bend.marked) {
          Color col = g.getColor();
          g.setColor(Color.RED);
          g.drawOval(tx - 5, ty - 5, 10, 10);
          g.setColor(col);
        }
        calcLimits(fx, tx, fy, ty);
        fx = tx;
        fy = ty;
      }
    }
    tx = endX;
    ty = endY;

    int x = endX;
    if (to != null && endsAtBlock && to.multiplex) {
      String s = to.mpxfactor;
      if (s == null) s = " ";
      int i = s.length() * driver.fontWidth + 10;
      x -= i;
    }

    if (headMarked) {
      Color col = g.getColor();
      g.setColor(Color.RED);
      g.drawOval(x - 5, toY - 5, 10, 10);
      g.setColor(col);
    }

    if (!dropOldest) g.drawLine(fx, fy, tx, ty);
    else {
      Shape shape = new Line2D.Double(fx, fy, tx, ty);
      shape = zzstroke.createStrokedShape(shape);
      g.draw(shape);
      // g.setStroke(stroke);
    }

    if (tailMarked) {
      Color col = g.getColor();
      g.setColor(Color.RED);
      g.drawOval(fromX - 5, fromY - 5, 10, 10);
      g.setColor(col);
    }

    calcLimits(fx, x, fy, toY);

    if (!endsAtBlock && !endsAtLine) {
      g.drawRect(fromX - 3, fromY - 3, 6, 6);
      g.drawRect(x - 3, toY - 3, 6, 6);
    } else if (endsAtBlock) {
      if ((from instanceof ComponentBlock
              || from instanceof ExtPortBlock
              || from instanceof Enclosure)
          && (to instanceof ComponentBlock
              || to instanceof ExtPortBlock
              || to instanceof Enclosure)) {
        Arrowhead ah = new Arrowhead(fx, fy, toX, toY);
        ah.draw(g);
      }

    } else if (endsAtLine) {
      drawCircleTo(g, fx, fy, x, toY, Color.BLACK, 4);
      // g.drawOval(toX - 2, toY - 2, 4, 4);
      // g.fillOval(toX - 2, toY - 2, 4, 4);
    }

    if (toX != -1 && (endsAtBlock || endsAtLine)) {
      if (upStreamPort != null && (from instanceof ComponentBlock || from instanceof Enclosure)) {
        if (upStreamPort.equals("*")) {
          drawCircleFrom(g, fromX, fromY, endX, endY, Color.BLUE, 8);
          // g.setColor(Color.BLUE);
          // g.drawOval(fromX, fromY - 4, 8, 8);
          // g.fillOval(fromX, fromY - 4, 8, 8);
        } else if (from.visible) {
          g.setColor(Color.BLUE);
          int y = fromY + driver.fontHeight;
          int x2 = fromX + driver.fontWidth;
          g.drawString(upStreamPort, x2, y);
        }
        g.setColor(Color.BLACK);
      }
      if (downStreamPort != null
          && !endsAtLine
          && to != null
          && (to instanceof ComponentBlock || to instanceof Enclosure)) {
        if (downStreamPort.equals("*")) {
          drawCircleTo(g, fx, fy, toX, toY, Color.BLUE, 8);
          // g.setColor(Color.BLUE);
          // g.drawOval(x - 8, toY - 4, 8, 8);
          // g.fillOval(x - 8, toY - 4, 8, 8);
        } else if (to.visible) {
          g.setColor(Color.BLUE);
          int y = toY - driver.fontHeight / 2;
          x = toX - driver.fontWidth * (downStreamPort.length() + 1);
          if (!endsAtLine && to != null && to.multiplex) x -= 20;
          g.drawString(downStreamPort, x, y);
        }
        g.setColor(Color.BLACK);
      }
    }
    if (extraArrowhead != null) extraArrowhead.draw(g);
  }