Exemple #1
0
 private boolean paintSimpleRobot(Dimension d, Graphics2D g2d) {
   if (null == jointvals || jointvals.length < SimulatedKinematicsSimple.NUM_JOINTS) {
     return true;
   }
   maxSimpleJv0 = Math.max(maxSimpleJv0, jointvals[0]);
   double sfactor =
       Math.min(d.width / 2.0, d.height / 2.0)
           / (Math.abs(maxSimpleJv0) + SimulatedKinematicsSimple.DEFAULT_SEGLENGTHS[0]);
   g2d.scale(sfactor, -1.0 * sfactor);
   g2d.setColor(Color.gray);
   g2d.fill(j1circle);
   l0rect.width = jointvals[0];
   g2d.rotate(Math.toRadians(jointvals[2]));
   g2d.setColor(Color.yellow);
   g2d.fill(l0rect);
   g2d.translate(l0rect.width, 0.0);
   g2d.setColor(Color.gray);
   g2d.fill(j1circle);
   l1rect.width =
       Math.cos(Math.toRadians(jointvals[5] - jointvals[2]))
           * SimulatedKinematicsSimple.DEFAULT_SEGLENGTHS[0];
   g2d.rotate(Math.toRadians(jointvals[4] - jointvals[2]));
   g2d.setColor(Color.yellow);
   g2d.fill(l1rect);
   return false;
 }
  @Override
  public void paint(Graphics g) {
    onResize();
    double speed = this.speed;
    float rotation = 0;
    Graphics2D g2d = (Graphics2D) g;

    drawBackground(g2d);

    // needle
    g2d.translate(getNeedleLocation().x, getNeedleLocation().y); // translate begin middle
    drawFrom00Center(g2d);
    g2d.rotate(getNeedleStartRotation()); // rotate begin needle
    rotation += getNeedleStartRotation();
    drawBackgroundWithNeedleStartRotation(g2d);

    g2d.rotate(step1Speed * speed); // rotate begin speed
    rotation += step1Speed * speed;

    drawNeedle(g2d);
    drawOnNeedleSpeedRotation(g2d);

    g2d.rotate(-rotation); // rotate end,rotate end
    g2d.translate(-getNeedleLocation().x, -getNeedleLocation().y); // //translate end
    rotation = 0;

    super.paint(g2d);
  }
Exemple #3
0
  public void draw(Graphics2D g, boolean bVertical, boolean bRight) {
    if (!bValid) return;
    int tx = pX;
    int ty = pY;

    g.setColor(fgColor);

    if (bVertical) {
      if (bRight) {
        tx = pX + pWidth;
        ty = pY;
        g.translate(tx, ty);
        g.rotate(deg90);
      } else {
        tx = pX;
        ty = pY + pHeight;
        g.translate(tx, ty);
        g.rotate(-deg90);
      }
    } else {
      if (tx != 0 || ty != 0) g.translate(tx, ty);
    }

    g.drawLine(x, y, x2, y2);

    if (bVertical) {
      if (bRight) g.rotate(-deg90);
      else g.rotate(deg90);
    }
    if (tx != 0 || ty != 0) g.translate(-tx, -ty);
  }
Exemple #4
0
  private void paintBase(InstancePainter painter) {
    Graphics g = painter.getGraphics();
    Direction facing = painter.getAttributeValue(StdAttr.FACING);
    Location loc = painter.getLocation();
    int x = loc.getX();
    int y = loc.getY();
    g.translate(x, y);
    double rotate = 0.0;
    if (facing != null && facing != Direction.EAST && g instanceof Graphics2D) {
      rotate = -facing.toRadians();
      ((Graphics2D) g).rotate(rotate);
    }

    Object shape = painter.getGateShape();
    if (shape == AppPreferences.SHAPE_RECTANGULAR) {
      paintRectangularBase(g, painter);
    } else if (shape == AppPreferences.SHAPE_DIN40700) {
      int width = painter.getAttributeValue(ATTR_SIZE) == SIZE_NARROW ? 20 : 30;
      PainterDin.paintAnd(painter, width, 18, true);
    } else {
      PainterShaped.paintNot(painter);
    }

    if (rotate != 0.0) {
      ((Graphics2D) g).rotate(-rotate);
    }
    g.translate(-x, -y);
  }
Exemple #5
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);
  }
  @Override
  public void paintComponent(Graphics g) {
    super.paintComponent(g);

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

    // Draw each space
    for (int i = 0, degrees = 0; i < imageNames.size() / 2; ++i) {
      g2D.setColor(
          WHEEL_COLORS.get(imageNames.get(i).substring(0, imageNames.get(i).indexOf('.'))));
      g2D.fillArc(150, 45, 480, 480, degrees, DEGREES_EACH);
      degrees += DEGREES_EACH;
    }

    // Set the origin and rotate before drawing the images
    g2D.translate(390, 285);
    g2D.rotate(Math.toRadians(-100));

    // Draw wheel spaces
    for (int i = 0; i < imageNames.size() / 2; ++i) {
      g2D.drawImage(IMAGES.get(imageNames.get(i)), -42, 0, this);
      g2D.rotate(Math.toRadians(-DEGREES_EACH));
    }

    // Reset origin
    g2D.translate(-390, -285);

    // Draw the arrow to indicate where the wheel stopped
    g.drawImage(IMAGES.get("arrow.png"), 370, 10, this);
  }
 @Override
 public void paint(Graphics g) {
   Graphics2D g2 = (Graphics2D) g;
   Stroke initialStroke = g2.getStroke();
   Color initialColor = g2.getColor();
   if (drawConcrete) {
     g2.setColor(Color.LIGHT_GRAY);
     g2.fill(getBounds());
   }
   g2.translate(loc.getX(), loc.getY());
   g2.rotate(rot);
   if (picture != null) {
     g2.drawImage(picture, -picture.getWidth(null) / 2, -picture.getHeight(null) / 2, null);
   }
   g2.setStroke(stroke);
   for (int i = 0; i < complexity; i++) {
     g2.translate(rLoc[i].getX(), rLoc[i].getY());
     g2.rotate(rRot[i]);
     g2.setColor(rCol[i]);
     if (rFill[i]) {
       g2.fill(rShape[i]);
     } else {
       g2.draw(rShape[i]);
     }
     g2.rotate(-rRot[i]);
     g2.translate(-rLoc[i].getX(), -rLoc[i].getY());
   }
   g2.setColor(initialColor);
   g2.setStroke(initialStroke);
   g2.rotate(-rot);
   g2.translate(-loc.getX(), -loc.getY());
 }
Exemple #8
0
  public void draw(Graphics2D g, boolean bVertical, boolean bRight) {
    if (!bValid || dataSize < 1) return;
    int tx = pX;
    int ty = pY;

    g.setColor(fgColor);
    if (bVertical) {
      if (bRight) {
        tx = pX + pWidth;
        ty = pY;
        g.translate(tx, ty);
        g.rotate(deg90);
      } else {
        tx = pX;
        ty = pY + pHeight;
        g.translate(tx, ty);
        g.rotate(-deg90);
      }
    } else {
      if (tx != 0 || ty != 0) g.translate(tx, ty);
    }

    if (dataSize > 1) g.drawPolyline(xPoints, yPoints, dataSize);
    else g.drawLine(xPoints[0], yPoints[0], xPoints[0], yPoints[0]);

    if (bVertical) {
      if (bRight) {
        g.rotate(-deg90);
      } else g.rotate(deg90);
    }
    if (tx != 0 || ty != 0) g.translate(-tx, -ty);
  }
Exemple #9
0
 /**
  * Write the given text string in the current font, centered on (x, y) and rotated by the
  * specified number of degrees.
  *
  * @param x the center x-coordinate of the text
  * @param y the center y-coordinate of the text
  * @param s the text
  * @param degrees is the number of degrees to rotate counterclockwise
  */
 public static void text(double x, double y, String s, double degrees) {
   double xs = scaleX(x);
   double ys = scaleY(y);
   offscreen.rotate(Math.toRadians(-degrees), xs, ys);
   text(x, y, s);
   offscreen.rotate(Math.toRadians(+degrees), xs, ys);
 }
 /** Transforms the Graphics for vertical rendering and invokes the super method. */
 @Override
 public void paint(Graphics g, JComponent c) {
   Graphics2D g2 = (Graphics2D) g.create();
   if (clockwise) {
     g2.rotate(Math.PI / 2, c.getSize().width / 2, c.getSize().width / 2);
   } else {
     g2.rotate(-Math.PI / 2, c.getSize().height / 2, c.getSize().height / 2);
   }
   super.paint(g2, c);
 }
Exemple #11
0
  public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    float val;
    int i, x[] = new int[17];
    Dimension dim = this.getSize();
    Stroke defaultStroke = g2.getStroke();
    BasicStroke dashed =
        new BasicStroke(
            1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 5.0f, new float[] {5.0f}, 0.0f);

    for (i = 0; i <= 16; i++) x[i] = (int) ((dim.width - 1) * i / (double) 16.0);

    // draw brain structure bars, with colours depending on selected-subject values
    g2.setColor(Color.black);
    for (i = 0; i < 16; i++) {
      if (selectedSubjectVolumes[0] != 0) {
        val = (float) ((selectedSubjectVolumes[i] - mean[i]) / (2.0 * std[i]));
        // System.out.println("val= "+val);
        if (val >= 0 && val <= 1) g2.setColor(new Color(val, 1.0f - val, 0.0f));
        else if (val >= -1 && val < 0) g2.setColor(new Color(0.0f, 1.0f + val, -val));
        else g2.setColor(Color.white);
      } else g2.setColor(Color.white);
      g2.fillRect(x[i], 0, x[i + 1], dim.height);
      g2.setColor(Color.black);
      g2.drawRect(x[i], 0, x[i + 1], dim.height);
    }

    // draw dots for selected subject values
    g2.setColor(Color.black);
    if (selectedSubjectVolumes[0] != 0)
      for (i = 0; i < 16; i++) {
        val = (float) (0.5f + (selectedSubjectVolumes[i] - mean[i]) / (2.0 * std[i]) / 2.0);
        if (val < 0) val = 0;
        if (val > 1) val = 1;
        // fillOval(int x, int y, int width, int height) avec la couleur definit par
        // g2.setColor(Color.black)
        g2.fillOval((x[i] + x[i + 1]) / 2 - 5, (int) (dim.height * (1 - val)) - 5, 11, 11);
      }

    // draw mean and +/- 1 std values
    g2.setColor(Color.black);
    g2.drawLine(0, dim.height / 2, dim.width, dim.height / 2);
    g2.setStroke(dashed);
    g2.drawLine(0, dim.height / 4, dim.width, dim.height / 4);
    g2.drawLine(0, dim.height * 3 / 4, dim.width, dim.height * 3 / 4);

    // draw brain structure names
    for (i = 0; i < 16; i++) {
      g2.translate((x[i] + x[i + 1]) / 2, 2);
      g2.rotate(Math.PI / 2.0);
      g2.drawString(regions[i], 0, 0);
      g2.rotate(-Math.PI / 2.0);
      g2.translate(-(x[i] + x[i + 1]) / 2, -2);
    }
  }
Exemple #12
0
  @Override
  public void paint(Graphics g, JComponent c) {
    JButton button = (JButton) c;
    String text = button.getText();
    Icon icon = (button.isEnabled()) ? button.getIcon() : button.getDisabledIcon();

    if ((icon == null) && (text == null)) {
      return;
    }

    FontMetrics fm = g.getFontMetrics();
    paintViewInsets = c.getInsets(paintViewInsets);

    paintViewR.x = paintViewInsets.left;
    paintViewR.y = paintViewInsets.top;

    // Use inverted height &amp; width
    paintViewR.height = c.getWidth() - (paintViewInsets.left + paintViewInsets.right);
    paintViewR.width = c.getHeight() - (paintViewInsets.top + paintViewInsets.bottom);

    paintIconR.x = paintIconR.y = paintIconR.width = paintIconR.height = 0;
    paintTextR.x = paintTextR.y = paintTextR.width = paintTextR.height = 0;

    Graphics2D g2 = (Graphics2D) g;
    AffineTransform tr = g2.getTransform();

    if (angle == 90) {
      g2.rotate(Math.PI / 2);
      g2.translate(0, -c.getWidth());
      paintViewR.x = c.getHeight() / 2 - (int) fm.getStringBounds(text, g).getWidth() / 2;
      paintViewR.y = c.getWidth() / 2 - (int) fm.getStringBounds(text, g).getHeight() / 2;
    } else if (angle == 270) {
      g2.rotate(-Math.PI / 2);
      g2.translate(-c.getHeight(), 0);
      paintViewR.x = c.getHeight() / 2 - (int) fm.getStringBounds(text, g).getWidth() / 2;
      paintViewR.y = c.getWidth() / 2 - (int) fm.getStringBounds(text, g).getHeight() / 2;
    }

    if (icon != null) {
      icon.paintIcon(c, g, paintIconR.x, paintIconR.y);
    }

    if (text != null) {
      int textX = paintTextR.x;
      int textY = paintTextR.y + fm.getAscent();

      if (button.isEnabled()) {
        paintText(g, c, new Rectangle(paintViewR.x, paintViewR.y, textX, textY), text);
      } else {
        paintText(g, c, new Rectangle(paintViewR.x, paintViewR.y, textX, textY), text);
      }
    }

    g2.setTransform(tr);
  }
Exemple #13
0
  public void drawStar(int xpos, int ypos, double rot, double xscale, double yscale) {
    g.translate(xpos, ypos);
    g.rotate(rot * Math.PI / 180.0);
    g.scale(xscale, yscale);

    g.fillOval(-10, -10, 20, 20);

    g.scale(1.0 / xscale, 1.0 / yscale);
    g.rotate(-rot * Math.PI / 180.0);
    g.translate(-xpos, -ypos);
  }
Exemple #14
0
  public void drawCircle(int xpos, int ypos, double rot, double xscale, double yscale, int width) {
    g.translate(xpos, ypos);
    g.rotate(rot * Math.PI / 180.0);
    g.scale(xscale, yscale);

    g.fillOval(-width / 2, -width / 2, width, width);

    g.scale(1.0 / xscale, 1.0 / yscale);
    g.rotate(-rot * Math.PI / 180.0);
    g.translate(-xpos, -ypos);
  }
Exemple #15
0
 void drawCenteredString(Graphics2D g2d, String string, int x0, int y0, float angle) {
   FontRenderContext frc = g2d.getFontRenderContext();
   Rectangle2D bounds = g2d.getFont().getStringBounds(string, frc);
   LineMetrics metrics = g2d.getFont().getLineMetrics(string, frc);
   if (angle == 0) {
     g2d.drawString(string, x0 - (float) bounds.getWidth() / 2, y0 + metrics.getHeight() / 2);
   } else {
     g2d.rotate(angle, x0, y0);
     g2d.drawString(string, x0 - (float) bounds.getWidth() / 2, y0 + metrics.getHeight() / 2);
     g2d.rotate(-angle, x0, y0);
   }
 }
Exemple #16
0
  public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    if (!(g instanceof Graphics2D)) {
      return;
    }

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

    int[] widths = getWidths();

    // Position and size of the border interior.
    int intX = x + widths[LEFT];
    int intY = y + widths[TOP];
    int intWidth = width - (widths[RIGHT] + widths[LEFT]);
    int intHeight = height - (widths[TOP] + widths[BOTTOM]);

    // Coordinates of the interior corners, from NW clockwise.
    int[][] intCorners = {
      {intX, intY},
      {intX + intWidth, intY},
      {intX + intWidth, intY + intHeight},
      {
        intX, intY + intHeight,
      },
    };

    // Draw the borders for all sides.
    for (int i = 0; i < 4; i++) {
      Value style = getBorderStyle(i);
      Polygon shape = getBorderShape(i);
      if ((style != Value.NONE) && (shape != null)) {
        int sideLength = (i % 2 == 0 ? intWidth : intHeight);

        // "stretch" the border shape by the interior area dimension
        shape.xpoints[2] += sideLength;
        shape.xpoints[3] += sideLength;
        Color color = getBorderColor(i);
        BorderPainter painter = getBorderPainter(i);

        double angle = i * Math.PI / 2;
        g2.setClip(g.getClip()); // Restore initial clip
        g2.translate(intCorners[i][0], intCorners[i][1]);
        g2.rotate(angle);
        g2.clip(shape);
        painter.paint(shape, g2, color, i);
        g2.rotate(-angle);
        g2.translate(-intCorners[i][0], -intCorners[i][1]);
      }
    }
    g2.dispose();
  }
Exemple #17
0
  public void drawRocket(
      Image image, int xpos, int ypos, double rot, double xscale, double yscale) {
    int width = rocketImage.getWidth(this);
    int height = rocketImage.getHeight(this);
    g.translate(xpos, ypos);
    g.rotate(rot * Math.PI / 180.0);
    g.scale(xscale, yscale);

    g.drawImage(image, -width / 2, -height / 2, width, height, this);

    g.scale(1.0 / xscale, 1.0 / yscale);
    g.rotate(-rot * Math.PI / 180.0);
    g.translate(-xpos, -ypos);
  }
Exemple #18
0
 /**
  * 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.
  */
 public void paintIcon(Component c, Graphics g, int x, int y) {
   Graphics2D g2 = (Graphics2D) g;
   Toolkit tk = Toolkit.getDefaultToolkit();
   Map<?, ?> map = (Map<?, ?>) (tk.getDesktopProperty("awt.font.desktophints"));
   if (map != null) {
     g2.addRenderingHints(map);
   }
   // We don't insist that it be on the same Component
   g2.setColor(c.getForeground());
   g2.setFont(c.getFont());
   if (fRotation == ROTATE_NONE) {
     int yPos = y + fCharHeight;
     for (int i = 0; i < fCharStrings.length; i++) {
       // Special rules for Japanese - "half-height" characters (like ya, yu, yo in combinations)
       // should draw in the top-right quadrant when drawn vertically
       // - they draw in the bottom-left normally
       int tweak;
       switch (fPosition[i]) {
         case POSITION_NORMAL:
           // Roman fonts should be centered. Japanese fonts are always monospaced.
           g2.drawString(fCharStrings[i], x + ((fWidth - fCharWidths[i]) / 2), yPos);
           break;
         case POSITION_TOP_RIGHT:
           tweak = fCharHeight / 3; // Should be 2, but they aren't actually half-height
           g2.drawString(fCharStrings[i], x + (tweak / 2), yPos - tweak);
           break;
         case POSITION_FAR_TOP_RIGHT:
           tweak = fCharHeight - fCharHeight / 3;
           g2.drawString(fCharStrings[i], x + (tweak / 2), yPos - tweak);
           break;
         default:
           throw new Error();
       }
       yPos += fCharHeight;
     }
   } else if (fRotation == ROTATE_LEFT) {
     g2.translate(x + fWidth, y + fHeight);
     g2.rotate(-NINETY_DEGREES);
     g2.drawString(fLabel, K_BUFFER_SPACE, -fDescent);
     g2.rotate(NINETY_DEGREES);
     g2.translate(-(x + fWidth), -(y + fHeight));
   } else if (fRotation == ROTATE_RIGHT) {
     g2.translate(x, y);
     g2.rotate(NINETY_DEGREES);
     g2.drawString(fLabel, K_BUFFER_SPACE, -fDescent);
     g2.rotate(-NINETY_DEGREES);
     g2.translate(-x, -y);
   }
 }
Exemple #19
0
  @Override
  public void paint(Graphics g) {
    // TODO Auto-generated method stub
    BufferedImage im = new BufferedImage(1000, 1000, BufferedImage.TYPE_INT_RGB);

    Graphics2D g2d = (Graphics2D) im.getGraphics();
    g2d.setBackground(Color.white);
    g2d.clearRect(0, 0, 1000, 1000);
    g2d.translate(frame.x, frame.y);
    g2d.rotate(frame.ug);
    g2d.drawImage(frame.image, -50, -50, 100, 100, frame);
    g2d.rotate(frame.ug2);
    g2d.drawImage(frame.image2, -50, -50, 100, 100, frame);
    g.drawImage(im, 0, 0, 1000, 1000, frame);
  }
Exemple #20
0
  /**
   * Draw picture (gif, jpg, or png) centered on (x, y), rotated given number of degrees.
   *
   * @param x the center x-coordinate of the image
   * @param y the center y-coordinate of the image
   * @param s the name of the image/picture, e.g., "ball.gif"
   * @param degrees is the number of degrees to rotate counterclockwise
   * @throws IllegalArgumentException if the image is corrupt
   */
  public static void picture(double x, double y, String s, double degrees) {
    Image image = getImage(s);
    double xs = scaleX(x);
    double ys = scaleY(y);
    int ws = image.getWidth(null);
    int hs = image.getHeight(null);
    if (ws < 0 || hs < 0) throw new IllegalArgumentException("image " + s + " is corrupt");

    offscreen.rotate(Math.toRadians(-degrees), xs, ys);
    offscreen.drawImage(
        image, (int) Math.round(xs - ws / 2.0), (int) Math.round(ys - hs / 2.0), null);
    offscreen.rotate(Math.toRadians(+degrees), xs, ys);

    draw();
  }
 protected void drawString(Graphics2D g2, double x, double y, double theta) {
   // Transform to the requested location.
   g2.translate(x, y);
   // Rotate by the requested angle.
   g2.rotate(theta);
   // Draw the first part of the string.
   String first = mMessage.substring(0, mSplit);
   float width = drawBoxedString(g2, first, Color.white, Color.red, 0);
   // Draw the second part of the string.
   String second = mMessage.substring(mSplit);
   drawBoxedString(g2, second, Color.blue, Color.white, width);
   // Undo the transformations.
   g2.rotate(-theta);
   g2.translate(-x, -y);
 }
Exemple #22
0
  public void paintComponent(Graphics g) {
    clear(g);
    Graphics2D g2d = (Graphics2D) g;

    g2d.setRenderingHint(
        RenderingHints.KEY_ANTIALIASING, // Anti-alias!
        RenderingHints.VALUE_ANTIALIAS_ON);

    g2d.translate(getWidth() / 2, getHeight() / 2);

    double scale = 1.5;
    paintChart(g2d, scale);

    // Elevation (0-90), Azimuth (0-359), Signal to noise ration in dBHZ (0-99)
    //        double[][] satelliteList  = new double[][] {
    //            {45,0+adjust,50}, {90,90+adjust,0}
    //        };

    double radius = 5.0 * scale;
    Ellipse2D ellipse =
        new Ellipse2D.Double(
            -radius * scale, -radius * scale, radius * scale * 2, radius * scale * 2);

    for (RelativeSatellitePosition satellitePos : this.satelliteList) {
      double elevation = satellitePos.getElevation();
      double azimuth = satellitePos.getAzimuth();
      int satelliteId = satellitePos.getSatelliteId();

      g2d.rotate(Math.toRadians(azimuth));
      g2d.translate(0, elevation * scale);
      g2d.setColor(getSNRColor((int) satellitePos.getSignalToNoiseRatio()));
      g2d.fill(ellipse);
      g2d.setColor(Color.BLACK);
      g2d.draw(ellipse);

      g2d.rotate(-Math.toRadians(azimuth));
      String text = satelliteId + "";
      Rectangle2D bounds = g2d.getFontMetrics().getStringBounds(text, g2d);
      g2d.drawString(
          text, (float) (-bounds.getWidth() / 2.0f), (float) (bounds.getHeight() / 2.0f));
      g2d.rotate(Math.toRadians(azimuth));

      g2d.translate(0, -elevation * scale);
      g2d.rotate(-Math.toRadians(azimuth));
    }

    adjust++;
  }
  public byte[] rotateImage(byte[] imageByte, String extension) throws IOException {

    byte[] transformedImageBytes;
    ByteArrayInputStream input = new ByteArrayInputStream(imageByte);
    ByteArrayOutputStream output = new ByteArrayOutputStream();

    BufferedImage image = null;
    image = ImageIO.read(input);
    if (image == null) {
      throw new RuntimeException();
    }

    int w = image.getWidth();
    int h = image.getHeight();
    BufferedImage imageTransformed =
        new BufferedImage(w, h, image.getColorModel().getTransparency());
    Graphics2D g = imageTransformed.createGraphics();
    g.rotate(Math.toRadians(180), w / 2.0, h / 2.0);
    g.drawImage(image, 0, 0, null);
    g.dispose();

    ImageIO.write(imageTransformed, extension, output);

    transformedImageBytes = output.toByteArray();

    return transformedImageBytes;
  }
Exemple #24
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();
  }
Exemple #25
0
 /** {@inheritDoc} */
 @Override
 protected void paintTrack(Graphics g, JComponent c, Rectangle trackBounds) {
   BufferedImage decImg =
       decBtnMousePressed
           ? SCROLL_DEC_PRESSED
           : decBtnMouseOver ? SCROLL_DEC_OVER : SCROLL_DEC_NORMAL;
   BufferedImage incImg =
       incBtnMousePressed
           ? SCROLL_INC_PRESSED
           : incBtnMouseOver ? SCROLL_INC_OVER : SCROLL_INC_NORMAL;
   Graphics2D g2 = (Graphics2D) g;
   AffineTransform origTransform = g2.getTransform();
   int scrollWidth = scrollbar.getWidth();
   if (scrollbar.getOrientation() == JScrollBar.VERTICAL) {
     scrollWidth = scrollbar.getHeight();
     g2.scale(1, -1);
     g2.rotate(-Math.PI / 2, 0, 0);
   }
   // draw track & bottons
   if (scrollbar.isEnabled()) {
     g.drawImage(decImg, 0, 0, scrollbar);
     // g.drawImage(BACKGROUND_ENABLED, 15, 0, scrollWidth - 15, 15, 0, 0, 1, 15, scrollbar);
     g.drawImage(incImg, scrollWidth - 15, 0, scrollbar);
   } else {
     // g.drawImage(BACKGROUND_DISABLED, 0, 0, scrollWidth, 15, 0, 0, 1, 15, scrollbar);
   }
   // undo any transform
   g2.setTransform(origTransform);
 }
Exemple #26
0
  private void drawYLabel(Graphics g) {
    g.setFont(fontBold);

    // # radians to rotate.
    double theta = -Math.PI / 2;

    Rectangle plotRect = getPlotRect();
    /*
     The y axis laabel.
    */
    String yLabel = "True Positive Fraction";
    int stringWidth = fm.stringWidth(yLabel);

    // where to begin drawing (the rotated image)
    Point translate =
        new Point(fm.getAscent(), plotRect.y + (plotRect.height / 2 + stringWidth / 2));

    Graphics2D g2 = (Graphics2D) g;
    AffineTransform save = g2.getTransform();

    g2.translate(translate.x, translate.y);
    g2.rotate(theta);

    g2.setColor(boundaryColor);
    g2.drawString(yLabel, 0, 0);

    g2.setTransform(save);
  }
Exemple #27
0
 @Override
 public void drawTextAxis(
     Graphics2D g2d, Dimension dim, boolean isHorizontal, String text, double coordinate) {
   if (!this.showAxisFonts) return;
   g2d.setFont(this.axisFont);
   int width = g2d.getFontMetrics().stringWidth(text) + this.axisFontMargin;
   int height = g2d.getFontMetrics().getHeight();
   /*if (isHorizontal)
   	g2d.fillRect(0, (int) dim.getHeight()-width,
   			(int) dim.getWidth(), (int) dim.getHeight());
   else
   	g2d.fillRect(0, 0, width, (int) dim.getHeight());*/
   g2d.setFont(axisFont);
   AffineTransform orig = g2d.getTransform();
   double angle = Math.toRadians(90);
   if (this.showAxisFonts)
     if (!isHorizontal) {
       g2d.setColor(this.axisBackgroundColor);
       g2d.fillRect(axisFontMargin, (int) coordinate - height, width, height);
       g2d.setColor(this.axisFontColor);
       g2d.drawString(text, this.axisFontMargin, (int) coordinate - axisFontMargin);
     } else {
       g2d.rotate(
           -angle, (int) coordinate - this.axisFontMargin, (int) dim.getHeight() - axisFontMargin);
       g2d.setColor(this.axisBackgroundColor);
       g2d.fillRect(
           (int) coordinate - this.axisFontMargin, (int) dim.getHeight() - height, width, height);
       g2d.setColor(this.axisFontColor);
       g2d.drawString(
           text, (int) coordinate - this.axisFontMargin, (int) dim.getHeight() - axisFontMargin);
       g2d.setTransform(orig);
     }
 }
  /**
   * Draw a string with given reference point and rotation angle. (0.5, 0.5) is center, (0, 0) is
   * lower left, (1, 0) is upper left, etc. The angle of rotation is in radians. The logical are
   * proportional to the base coordinates.
   */
  public void drawTextBaseRatio(
      String label,
      double horizontalReference,
      double verticalReference,
      double rotation,
      double[] coord) {
    int[] sc = projection.screenProjectionBaseRatio(coord);
    int x = sc[0];
    int y = sc[1];

    AffineTransform transform = g2d.getTransform();

    // Corner offset adjustment : Text Offset is used Here
    FontRenderContext frc = g2d.getFontRenderContext();
    Font font = g2d.getFont();
    double w = font.getStringBounds(label, frc).getWidth();
    double h = font.getSize2D();

    if (rotation != 0) {
      g2d.rotate(rotation, x, y);
    }

    x -= (int) (w * horizontalReference);
    y += (int) (h * verticalReference);

    g2d.drawString(label, x, y);

    g2d.setTransform(transform);
  }
Exemple #29
0
    protected void paintComponent(Graphics g) {
      super.paintComponent(g);
      Graphics2D g2 = (Graphics2D) g;
      g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      int w = getWidth();
      int h = getHeight();
      int pointSize = Math.max(Math.min(w, h) / 80, 4);

      double xInc = (double) (w - 2 * PAD) / (MAX_X - 1);
      double scale = (double) (h - 2 * PAD) / MAX_Y;
      // Draw abcissa.
      int tickInc = MAX_X / 10;
      for (int i = 0; i <= MAX_X; i += tickInc) {
        int x = PAD + (int) (i * xInc);
        int y = h - PAD;
        g.drawString(Integer.toString(i), x - 5, y + 20);
        g2.draw(new Line2D.Double(x, y - 5, x, y + 5));
      }
      g2.draw(new Line2D.Double(PAD, h - PAD, w - PAD / 2, h - PAD));
      AffineTransform orig = g2.getTransform();
      g2.rotate(-Math.PI / 2);
      g2.setColor(Color.black);
      g2.drawString("Number of comparisons", -((h + PAD) / 2), PAD / 3);
      g2.setTransform(orig);

      // Draw ordinate.
      tickInc = (h - PAD) / 10;

      for (int i = tickInc; i < h - PAD; i += tickInc) {
        int x = PAD;
        int closest_10 = ((int) (i / scale) / 10) * 10;

        int y = h - PAD - (int) (closest_10 * scale);
        if (y < PAD) break;
        String tickMark = Integer.toString(closest_10);
        int stringLen = (int) g2.getFontMetrics().getStringBounds(tickMark, g2).getWidth();
        g.drawString(tickMark, x - stringLen - 8, y + 5);
        g2.draw(new Line2D.Double(x - 5, y, x + 5, y));
      }
      g2.draw(new Line2D.Double(PAD, PAD / 2, PAD, h - PAD));
      g.drawString("Array Size", (w - PAD) / 2, h - PAD + 40);

      for (int index = 0; index < plot_data.size(); index++) {
        int[] data = plot_data.get(index);

        // Mark data points.
        g2.setPaint(plot_colors.get(index));

        for (int i = 0; i < data.length; i++) {
          double x = PAD + i * xInc;
          double y = h - PAD - scale * data[i];
          g2.fill(new Ellipse2D.Double(x - pointSize / 2, y - pointSize / 2, pointSize, pointSize));
        }

        g2.setFont(textFont);
        int stringHeight =
            (int) g2.getFontMetrics().getStringBounds(plot_names.get(index), g2).getHeight();
        g.drawString(plot_names.get(index), PAD + 20, PAD + (index + 1) * stringHeight);
      }
    }
Exemple #30
-1
  // renders a page to the given graphics
  private void renderPage(
      PDPage page, Graphics2D graphics, int width, int height, float scaleX, float scaleY)
      throws IOException {
    graphics.clearRect(0, 0, width, height);

    graphics.scale(scaleX, scaleY);
    // TODO should we be passing the scale to PageDrawer rather than messing with Graphics?

    PDRectangle cropBox = page.getCropBox();
    int rotationAngle = page.getRotation();

    if (rotationAngle != 0) {
      float translateX = 0;
      float translateY = 0;
      switch (rotationAngle) {
        case 90:
          translateX = cropBox.getHeight();
          break;
        case 270:
          translateY = cropBox.getWidth();
          break;
        case 180:
          translateX = cropBox.getWidth();
          translateY = cropBox.getHeight();
          break;
      }
      graphics.translate(translateX, translateY);
      graphics.rotate((float) Math.toRadians(rotationAngle));
    }

    // the end-user may provide a custom PageDrawer
    PageDrawerParameters parameters = new PageDrawerParameters(this, page);
    PageDrawer drawer = createPageDrawer(parameters);
    drawer.drawPage(graphics, cropBox);
  }