Esempio n. 1
0
  @Override
  // TODO Auto-generated method stub
  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D) g;

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

    // Alters and prints the text on the screen
    g2.setColor(Color.BLACK);
    g2.setFont(font);
    g2.drawString("Score", 700, 25);
    g2.drawString(Integer.toString(points), 700, 75);
    g2.drawString("Misses", 800, 25);
    g2.drawString(Integer.toString(misses), 800, 75);
    g2.drawString("Time Left", 700, 110);
    timeDisplay = timeLeft / 100.0;
    g2.drawString(timeDisplay.toString(), 700, 160);
  }
Esempio n. 2
0
  public void paint(Graphics g) {
    super.paint(g);

    Graphics2D g2 = (Graphics2D) g;
    int size =
        Math.min(
            MAX_SIZE,
            Math.min(
                getWidth() - imagePadding.left - imagePadding.right,
                getHeight() - imagePadding.top - imagePadding.bottom));

    g2.translate(getWidth() / 2 - size / 2, getHeight() / 2 - size / 2);
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    Shape shape;

    if (mode == ColorPicker.SAT || mode == ColorPicker.BRI) {
      shape = new Ellipse2D.Float(0, 0, size, size);
    } else {
      Rectangle r = new Rectangle(0, 0, size, size);
      shape = r;
    }

    if (hasFocus()) {
      PaintUtils.paintFocus(g2, shape, 5);
    }

    if (!(shape instanceof Rectangle)) {
      // paint a circular shadow
      g2.translate(2, 2);
      g2.setColor(new Color(0, 0, 0, 20));
      g2.fill(new Ellipse2D.Float(-2, -2, size + 4, size + 4));
      g2.setColor(new Color(0, 0, 0, 40));
      g2.fill(new Ellipse2D.Float(-1, -1, size + 2, size + 2));
      g2.setColor(new Color(0, 0, 0, 80));
      g2.fill(new Ellipse2D.Float(0, 0, size, size));
      g2.translate(-2, -2);
    }

    g2.drawImage(image, 0, 0, size, size, 0, 0, size, size, null);

    if (shape instanceof Rectangle) {
      Rectangle r = (Rectangle) shape;
      PaintUtils.drawBevel(g2, r);
    } else {
      g2.setColor(new Color(0, 0, 0, 120));
      g2.draw(shape);
    }

    g2.setColor(Color.white);
    g2.setStroke(new BasicStroke(1));
    g2.draw(new Ellipse2D.Float(point.x - 3, point.y - 3, 6, 6));
    g2.setColor(Color.black);
    g2.draw(new Ellipse2D.Float(point.x - 4, point.y - 4, 8, 8));

    g.translate(-imagePadding.left, -imagePadding.top);
  }
Esempio n. 3
0
 @Override
 protected void drawFill(Graphics2D g) {
   if (isClosed() || get(UNCLOSED_PATH_FILLED)) {
     double grow = AttributeKeys.getPerpendicularFillGrowth(this);
     if (grow == 0d) {
       g.fill(path);
     } else {
       GrowStroke gs =
           new GrowStroke(grow, AttributeKeys.getStrokeTotalWidth(this) * get(STROKE_MITER_LIMIT));
       g.fill(gs.createStrokedShape(path));
     }
   }
 }
Esempio n. 4
0
 /** the paintComponent -- paints the board every repaint() call. */
 public void paintComponent(Graphics g) {
   super.paintComponent(g);
   Graphics2D g2 = (Graphics2D) g;
   for (int i = 0; i < B_WIDTH; i++) {
     for (int j = 0; j < B_HEIGHT; j++) {
       Rectangle2D rect = new Rectangle2D.Double((i * 40) + 1, (j * 40) + 1, 38, 38);
       g2.setPaint(balls[i][j].getColor());
       g2.fill(rect);
       Ellipse2D circle = new Ellipse2D.Double();
       circle.setFrame(rect);
       g2.setPaint(balls[i][j].getcColor());
       g2.fill(circle);
     }
   }
 }
Esempio n. 5
0
  //	public void savePDF(){
  //		 Rectangle suggestedPageSize = getITextPageSize(page1.getPageSize());
  //		  Rectangle pageSize = rotatePageIfNecessary(suggestedPageSize);
  //		  //rotate if we need landscape
  //		  Document document = new Document(pageSize);
  //
  //		  PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(outputFile));
  //		  document.open();
  //		  Graphics2D graphics = cb.createGraphics(pageSize.getWidth(), pageSize.getHeight());
  //
  //		  // call your GTRenderer here
  //		  GTRenderer draw = new StreamingRenderer();
  //		  draw.setMapContent(mapContent);
  //
  //		  draw.paint(graphics, outputArea, mapContent.getLayerBounds() );
  //
  //		  // cleanup
  //		  graphics.dispose();
  //
  //		  //cleanup
  //		  document.close();
  //		  writer.close();
  //	}
  public void saveImage(final MapContent map, final String file, final int imageWidth) {

    GTRenderer renderer = new StreamingRenderer();
    renderer.setMapContent(map);

    Rectangle imageBounds = null;
    ReferencedEnvelope mapBounds = null;
    try {
      mapBounds = map.getMaxBounds();
      double heightToWidth = mapBounds.getSpan(1) / mapBounds.getSpan(0);
      imageBounds = new Rectangle(0, 0, imageWidth, (int) Math.round(imageWidth * heightToWidth));

    } catch (Exception e) {
      // failed to access mapContent layers
      throw new RuntimeException(e);
    }

    BufferedImage image =
        new BufferedImage(imageBounds.width, imageBounds.height, BufferedImage.TYPE_INT_RGB);

    Graphics2D gr = image.createGraphics();
    gr.setPaint(Color.WHITE);
    gr.fill(imageBounds);

    try {
      renderer.paint(gr, imageBounds, mapBounds);
      File fileToSave = new File(file);
      ImageIO.write(image, "jpeg", fileToSave);

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Esempio n. 6
0
 void draw(Graphics2D g) {
   g.setColor(darkColor);
   int x = (int) (center_x + distance * Math.sin(-unit * current / num));
   int y = (int) (center_y + distance * Math.cos(-unit * current / num));
   Area area = new Area(new Ellipse2D.Double(x, y, ball_r, ball_r));
   g.fill(area);
 }
  protected void paintComponent(Graphics g2) {
    super.paintComponent(g2);

    Graphics2D g = (Graphics2D) g2;
    test.draw(g2, 0, 0);
    // Shape triangle = new Polygon(new int[] {15, 20, 10}, new int[] {0, 10, 10}, 3);

    Shape square = new Rectangle2D.Double(0, 0, 30, 30);

    g.setColor(Color.white);

    g.translate(20, 20);
    // g.rotate(theta, 10, 10);
    // g.fill(star);

    // g.setColor(new Color(0, 86, 141));
    // g.fill(square);
    if (star2 != null) g.fill(star2);

    // Graphics2D g3 = (Graphics2D) g;
    // 3.fill(star);

    // g.setStroke(new BasicStroke(1));
    // g.translate(x, y);
    // g.draw(line);
    // g.draw(line2);

  }
Esempio n. 8
0
 public void drawTo(Graphics g, Line line) {
   if (!calc.tileOnMap(t1) || !calc.tileOnMap(t2)) return;
   if (calc.tileOnMap(line.getTile1()) && calc.tileOnMap(line.getTile2())) {
     Point p1 = calc.tileToMinimap(t1);
     Point p2 = calc.tileToMinimap(t2);
     Point p3 = calc.tileToMinimap(line.getTile2());
     Point p4 = calc.tileToMinimap(line.getTile1());
     GeneralPath path = new GeneralPath();
     path.moveTo(p1.x, p1.y);
     path.lineTo(p2.x, p2.y);
     path.lineTo(p3.x, p3.y);
     path.lineTo(p4.x, p4.y);
     path.closePath();
     g.setColor(POLY_FILL);
     ((Graphics2D) g).fill(path);
     ((Graphics2D) g).draw(path);
   }
   Point last = null, p;
   g.setColor(Color.ORANGE);
   for (RSTile t : pathList) {
     if (calc.tileOnMap(t)) {
       p = calc.tileToMinimap(t);
       g.fillOval(p.x - 2, p.y - 2, 5, 5);
       if (last != null) g.drawLine(p.x, p.y, last.x, last.y);
       last = p;
     } else last = null;
   }
 }
Esempio n. 9
0
 public void paintComponent(Graphics g) {
   Graphics2D g2 = (Graphics2D) g;
   Rectangle2D rect = new Rectangle2D.Double(0, 0, getWidth() - 1, getHeight() - 1);
   g2.setPaint(Color.YELLOW);
   g2.fill(rect);
   g2.setPaint(Color.BLUE);
   g2.draw(rect);
 }
Esempio n. 10
0
 private void fill(Graphics2D g, Rectangle2D.Float rect, RoadDirection dir) {
   if (Globals.roadDirection == dir) {
     g.setColor(Color.green);
   } else {
     g.setColor(Color.red);
   }
   g.fill(rect);
 }
Esempio n. 11
0
 @Override
 public void paintIcon(Component c, Graphics g, int x, int y) {
   Graphics2D g2 = (Graphics2D) g.create();
   g2.translate(x, y);
   g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
   g2.setPaint(Color.ORANGE);
   g2.fill(star);
   g2.dispose();
 }
Esempio n. 12
0
  public void paintBackground(Graphics2D g, ButtonInfo info) {
    if (info.button.isContentAreaFilled()) {
      g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

      Paint fillPaint = fill.getFill(info.button, info.fillBounds);
      g.setPaint(fillPaint);
      g.fill(info.fill);
    }
  }
Esempio n. 13
0
 /**
  * Draw a filled polygon with the given (x[i], y[i]) coordinates.
  *
  * @param x an array of all the x-coordindates of the polygon
  * @param y an array of all the y-coordindates of the polygon
  */
 public static void filledPolygon(double[] x, double[] y) {
   int N = x.length;
   GeneralPath path = new GeneralPath();
   path.moveTo((float) scaleX(x[0]), (float) scaleY(y[0]));
   for (int i = 0; i < N; i++) path.lineTo((float) scaleX(x[i]), (float) scaleY(y[i]));
   path.closePath();
   offscreen.fill(path);
   draw();
 }
Esempio n. 14
0
    public void draw(Graphics2D g2) {
      g2.setPaint(selected ? selColor : bgColor);
      g2.fill(rect);
      // g2.fill(new Rectangle2D.Double(row,col,10,10));
      // g2.fill(new Rectangle2D.Double(rect.x,rect.y,rect.height, rect.width));
      g2.setPaint(color);

      g2.draw(rect);
    }
Esempio n. 15
0
 public void paint(Graphics g) {
   Graphics2D g2 = (Graphics2D) g;
   g2.setPaint(BACKGROUND);
   g2.fill(
       new Rectangle2D.Float(
           0f, 0f, (float) g2.getClipBounds().width, (float) g2.getClipBounds().height));
   g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
   canvas.paint(g2);
 }
Esempio n. 16
0
 /**
  * Draw a filled square of side length 2r, centered on (x, y).
  *
  * @param x the x-coordinate of the center of the square
  * @param y the y-coordinate of the center of the square
  * @param r radius is half the length of any side of the square
  * @throws RuntimeException if r is negative
  */
 public static void filledSquare(double x, double y, double r) {
   if (r < 0) throw new RuntimeException("square side length can't be negative");
   double xs = scaleX(x);
   double ys = scaleY(y);
   double ws = factorX(2 * r);
   double hs = factorY(2 * r);
   if (ws <= 1 && hs <= 1) pixel(x, y);
   else offscreen.fill(new Rectangle2D.Double(xs - ws / 2, ys - hs / 2, ws, hs));
   draw();
 }
Esempio n. 17
0
 /**
  * Draw filled circle of radius r, centered on (x, y).
  *
  * @param x the x-coordinate of the center of the circle
  * @param y the y-coordinate of the center of the circle
  * @param r the radius of the circle
  * @throws RuntimeException if the radius of the circle is negative
  */
 public static void filledCircle(double x, double y, double r) {
   if (r < 0) throw new RuntimeException("circle radius can't be negative");
   double xs = scaleX(x);
   double ys = scaleY(y);
   double ws = factorX(2 * r);
   double hs = factorY(2 * r);
   if (ws <= 1 && hs <= 1) pixel(x, y);
   else offscreen.fill(new Ellipse2D.Double(xs - ws / 2, ys - hs / 2, ws, hs));
   draw();
 }
Esempio n. 18
0
 /**
  * Draw a filled rectangle of given half width and half height, centered on (x, y).
  *
  * @param x the x-coordinate of the center of the rectangle
  * @param y the y-coordinate of the center of the rectangle
  * @param halfWidth is half the width of the rectangle
  * @param halfHeight is half the height of the rectangle
  * @throws RuntimeException if halfWidth or halfHeight is negative
  */
 public static void filledRectangle(double x, double y, double halfWidth, double halfHeight) {
   if (halfWidth < 0) throw new RuntimeException("half width can't be negative");
   if (halfHeight < 0) throw new RuntimeException("half height can't be negative");
   double xs = scaleX(x);
   double ys = scaleY(y);
   double ws = factorX(2 * halfWidth);
   double hs = factorY(2 * halfHeight);
   if (ws <= 1 && hs <= 1) pixel(x, y);
   else offscreen.fill(new Rectangle2D.Double(xs - ws / 2, ys - hs / 2, ws, hs));
   draw();
 }
Esempio n. 19
0
 /**
  * Draw an ellipse with given semimajor and semiminor axes, centered on (x, y).
  *
  * @param x the x-coordinate of the center of the ellipse
  * @param y the y-coordinate of the center of the ellipse
  * @param semiMajorAxis is the semimajor axis of the ellipse
  * @param semiMinorAxis is the semiminor axis of the ellipse
  * @throws RuntimeException if either of the axes are negative
  */
 public static void filledEllipse(double x, double y, double semiMajorAxis, double semiMinorAxis) {
   if (semiMajorAxis < 0) throw new RuntimeException("ellipse semimajor axis can't be negative");
   if (semiMinorAxis < 0) throw new RuntimeException("ellipse semiminor axis can't be negative");
   double xs = scaleX(x);
   double ys = scaleY(y);
   double ws = factorX(2 * semiMajorAxis);
   double hs = factorY(2 * semiMinorAxis);
   if (ws <= 1 && hs <= 1) pixel(x, y);
   else offscreen.fill(new Ellipse2D.Double(xs - ws / 2, ys - hs / 2, ws, hs));
   draw();
 }
Esempio n. 20
0
 /**
  * Draw a point at (x, y).
  *
  * @param x the x-coordinate of the point
  * @param y the y-coordinate of the point
  */
 public static void point(double x, double y) {
   double xs = scaleX(x);
   double ys = scaleY(y);
   double r = penRadius;
   // double ws = factorX(2*r);
   // double hs = factorY(2*r);
   // if (ws <= 1 && hs <= 1) pixel(x, y);
   if (r <= 1) pixel(x, y);
   else offscreen.fill(new Ellipse2D.Double(xs - r / 2, ys - r / 2, r, r));
   draw();
 }
Esempio n. 21
0
  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D) g;
    int i, j, k;
    System.out.println("Starting painting");
    // draw sets

    if (firstTimeAround) {
      drawSet(g2);
      render();
      viewer.save("final_product_full.png");
      firstTimeAround = false;
    }
    // render();
    /* for(i=0;i<viewer.getWidth();i++){
        for(j=0;j<viewer.getHeight();j++){
            viewer.setPixel(i,j,Color3.BLACK);
        }
    }
    */

    g2.setBackground(Color.BLACK);

    //        if(newRender){
    for (i = minX; i < maxX; i++) {
      // System.out.println("line "+i);
      for (j = minY; j < maxY; j++) {

        g2.setColor(
            new Color(
                (float) viewer.getPixel(i, j).getR(),
                (float) viewer.getPixel(i, j).getG(),
                (float) viewer.getPixel(i, j).getB()));
        // g2.drawLine(i,j,1,1);
        Ellipse2D.Double node_circ = new Ellipse2D.Double(i, j, 1, 1);
        g2.fill(node_circ);

        g2.setColor(Color.BLACK);

        // if(j*scale<viewer.getHeight()){
        //       j=0;//viewer.getHeight();
        // }

      }
      // if(i*scale<viewer.getWidth()){
      //    i=0;//viewer.getWidth();
      //  }
    }

    //  g2.drawImage(viewer.1)
    newRender = false;
    // }
    System.out.println("end painting");
  }
Esempio n. 22
0
  @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;
  }
Esempio n. 23
0
  public void drawModel(Graphics2D g2d) {
    for (OriFace face : ORIPA.doc.sortedFaces) {
      if (Globals.modelDispMode == Constants.ModelDispMode.FILL_COLOR) {
        if (face.faceFront) {
          g2d.setColor(new Color(255, 200, 200));
        } else {
          g2d.setColor(new Color(200, 200, 255));
        }
        g2d.fill(face.outline);
      } else if (Globals.modelDispMode == Constants.ModelDispMode.FILL_WHITE) {
        g2d.setColor(Color.WHITE);
        g2d.fill(face.outline);
      } else if (Globals.modelDispMode == Constants.ModelDispMode.FILL_ALPHA) {
        g2d.setColor(new Color(100, 100, 100));
        g2d.fill(face.outline);
      }

      g2d.setColor(Color.BLACK);
      for (OriHalfedge he : face.halfedges) {
        if (he.pair == null) {
          g2d.setStroke(Config.MODEL_STROKE_CUT);
        } else {
          g2d.setStroke(Config.STROKE_CUT);
        }
        g2d.draw(
            new Line2D.Double(
                he.positionForDisplay.x,
                he.positionForDisplay.y,
                he.next.positionForDisplay.x,
                he.next.positionForDisplay.y));
      }
    }

    if (Globals.bDispCrossLine) {
      g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f));
      g2d.setStroke(Config.MODEL_STROKE_CUT);
      g2d.setColor(Color.RED);

      g2d.draw(new Line2D.Double(crossLine.p0.x, crossLine.p0.y, crossLine.p1.x, crossLine.p1.y));
    }
  }
Esempio n. 24
0
 public synchronized void paintComponent(Graphics g) // Called on the event dispatch thread
     {
   if (values == null) return;
   Graphics2D g2 = (Graphics2D) g;
   int width = getWidth() / values.length;
   for (int i = 0; i < values.length; i++) {
     double height = values[i] * getHeight();
     Rectangle2D bar = new Rectangle2D.Double(width * i, 0, width, height);
     if (values[i] == marked1 || values[i] == marked2) g2.fill(bar);
     else g2.draw(bar);
   }
 }
Esempio n. 25
0
    void draw(Graphics2D g) {

      // toX/toY is tip of arrow and fx/fy is a point on the line -
      // fx/fy is used to determine direction & angle

      AffineTransform at = AffineTransform.getTranslateInstance(toX, toY);
      int b = 9;
      double theta = Math.toRadians(20);
      // The idea of using a GeneralPath is so we can
      // create the (three lines that make up the) arrow
      // (only) one time and then use AffineTransform to
      // place it anywhere we want.
      GeneralPath path = new GeneralPath();

      // distance between line and the arrow mark <** not **
      // Start a new line segment from the position of (0,0).
      path.moveTo(0, 0);
      // Create one of the two arrow head lines.
      int x = (int) (-b * Math.cos(theta));
      int y = (int) (b * Math.sin(theta));
      path.lineTo(x, y);

      // distance between line and the arrow mark <** not **
      // Make the other arrow head line.
      int x2 = (int) (-b * Math.cos(-theta));
      int y2 = (int) (b * Math.sin(-theta));
      // path.moveTo(0,0);
      path.lineTo(x2, y2);
      path.closePath();

      // theta is in radians
      double s, t;
      s = toY - fy; // calculate slopes.
      t = toX - fx;
      if (t != 0) {
        s = s / t;
        theta = Math.atan(s);
        if (t < 0) theta += Math.PI;
      } else if (s < 0) theta = -(Math.PI / 2);
      else theta = Math.PI / 2;

      at.rotate(theta);
      // at.rotate(theta,toX,toY);
      Shape shape = at.createTransformedShape(path);
      if (checkStatus == Status.UNCHECKED) g.setColor(Color.BLACK);
      else if (checkStatus == Status.COMPATIBLE) g.setColor(FOREST_GREEN);
      else g.setColor(ORANGE_RED);
      g.fill(shape);
      g.draw(shape);
    }
Esempio n. 26
0
  public void paint(Graphics g) {
    Graphics2D gr = (Graphics2D) g;
    super.paint(g);
    Rectangle bounds = scene.getBounds();
    Dimension size = getSize();

    double sx = bounds.width > 0 ? (double) size.width / bounds.width : 0.0;
    double sy = bounds.width > 0 ? (double) size.height / bounds.height : 0.0;
    double scale = Math.min(sx, sy);

    int vw = (int) (scale * bounds.width);
    int vh = (int) (scale * bounds.height);
    int vx = (size.width - vw) / 2;
    int vy = (size.height - vh) / 2;

    if (image == null || vw != imageWidth || vh != imageHeight) {

      imageWidth = vw;
      imageHeight = vh;
      image = this.createImage(imageWidth, imageHeight);
      Graphics2D ig = (Graphics2D) image.getGraphics();
      ig.scale(scale, scale);
      scene.setRealZoomFactor(scale);
      scene.paint(ig);
      scene.setRealZoomFactor(0.0);
    }

    gr.drawImage(image, vx, vy, this);

    JComponent component = scene.getView();
    double zoomFactor = scene.getZoomFactor();
    Rectangle viewRectangle = component != null ? component.getVisibleRect() : null;
    if (viewRectangle != null) {
      Rectangle window =
          new Rectangle(
              (int) ((double) viewRectangle.x * scale / zoomFactor),
              (int) ((double) viewRectangle.y * scale / zoomFactor),
              (int) ((double) viewRectangle.width * scale / zoomFactor),
              (int) ((double) viewRectangle.height * scale / zoomFactor));
      window.translate(vx, vy);
      gr.setColor(new Color(200, 200, 200, 128));
      gr.fill(window);
      gr.setColor(Color.BLACK);
      gr.drawRect(window.x, window.y, window.width - 1, window.height - 1);
    }
  }
Esempio n. 27
0
 protected float drawBoxedString(Graphics2D g2, String s, Color c1, Color c2, double x) {
   // Calculate the width of the string.
   FontRenderContext frc = g2.getFontRenderContext();
   TextLayout subLayout = new TextLayout(s, mFont, frc);
   float advance = subLayout.getAdvance();
   // Fill the background rectangle with a gradient.
   GradientPaint gradient = new GradientPaint((float) x, 0, c1, (float) (x + advance), 0, c2);
   g2.setPaint(gradient);
   Rectangle2D bounds = mLayout.getBounds();
   Rectangle2D back = new Rectangle2D.Double(x, 0, advance, bounds.getHeight());
   g2.fill(back);
   // Draw the string over the gradient rectangle.
   g2.setPaint(Color.white);
   g2.setFont(mFont);
   g2.drawString(s, (float) x, (float) -bounds.getY());
   return advance;
 }
Esempio n. 28
0
 protected void drawBackground(Graphics2D g2) {
   // Draw circles of different colors.
   int side = 45;
   int width = getSize().width;
   int height = getSize().height;
   Color[] colors = {
     Color.yellow, Color.cyan, Color.orange, Color.pink, Color.magenta, Color.lightGray
   };
   for (int y = 0; y < height; y += side) {
     for (int x = 0; x < width; x += side) {
       Ellipse2D ellipse = new Ellipse2D.Float(x, y, side, side);
       int index = (x + y) / side % colors.length;
       g2.setPaint(colors[index]);
       g2.fill(ellipse);
     }
   }
 }
Esempio n. 29
0
  public void paintComponent(Graphics g) {
    // необходиом чтобы текст коректно отрисовывался в окне
    super.paintComponent(g);
    // рисуем текст в окне
    Graphics2D g2 = (Graphics2D) g;
    AffineTransform t = g2.getTransform();
    g.drawString("It is text", 5, 5);
    // создание шрифта
    Font f = new Font("SanasSerif", Font.ITALIC, 20);
    g2.setFont(f);
    g2.drawString("It is new text", 5, 33);
    String[] fontNames =
        GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
    for (int i = 5; i < 20; i++) {
      g2.rotate(-0.05);
      g2.setColor(
          new Color(
              (int) (Math.random() * 255),
              (int) (Math.random() * 255),
              (int) (Math.random() * 255)));
      Font f1 = new Font(fontNames[i], Font.BOLD, 20);
      g2.setFont(f1);
      g2.drawString(fontNames[i], 5, 20 * i);
    }
    // текст в центре

    g2.setTransform(t); // возращение к кординатам, которые запонилив начале
    Font f2 = new Font("SanasSerif", Font.ITALIC, 20);
    g2.setFont(f2);
    String s = "It is center!";
    FontRenderContext context = g2.getFontRenderContext();
    Rectangle2D r = f2.getStringBounds(s, context);
    double x1 = (getWidth() - r.getWidth()) / 2;
    double y1 = (getHeight() - r.getHeight()) / 2;
    double ascent = -r.getY(); // узнаем высоту текста
    double y2 = y1 + ascent;
    Rectangle2D rect = new Rectangle2D.Double(x1, y1, r.getWidth(), r.getHeight());
    g2.setColor(Color.YELLOW);
    g2.fill(rect);
    g2.setColor(Color.red);
    g2.drawString(s, (int) x1, (int) y2);
    g2.setColor(Color.blue);
    g2.draw(new Line2D.Double(x1, y2, x1 + r.getWidth(), y2));

    g2.draw(rect);
  }
Esempio n. 30
0
 @Override
 public void paintIcon(Component c, Graphics g, int x, int y) {
   Graphics2D g2 = (Graphics2D) g.create();
   g2.setPaint(Objects.nonNull(c) ? c.getBackground() : Color.WHITE);
   g2.fillRect(x, y, getIconWidth(), getIconHeight());
   g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
   g2.setColor(ELLIPSE_COLOR);
   g2.translate(x, y);
   int size = list.size();
   for (int i = 0; i < size; i++) {
     float alpha = isRunning ? (i + 1) / (float) size : .5f;
     g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
     g2.fill(list.get(i));
   }
   // g2.translate(-x, -y);
   g2.dispose();
 }