Example #1
0
  /**
   * Override the pain method do draw the axis lines
   *
   * @param g The graphics to paint to
   */
  public void paint(Graphics g) {
    Rectangle b = getBounds();
    g.setColor(canvasBg);
    g.fillRect(0, 0, b.width, b.height);
    paintGrid(g);

    Point center = getCenter();
    if (g instanceof Graphics2D) {
      ((Graphics2D) g).translate(center.x, center.y);
    }
    super.paint(g);
    if (g instanceof Graphics2D) {
      ((Graphics2D) g).scale(1.0, 1.0);
    }
    g.setColor(Color.gray);
    g.drawLine(0, -10 * b.height, 0, 10 * b.height);
    g.drawLine(-10 * b.width, 0, 10 * b.width, 0);

    MetSymbol tmp = highlightedMetSymbol;
    if (tmp != null) {
      Rectangle tb = tmp.getBounds();
      g.setColor(Color.red);
      g.drawRect(tb.x - 2, tb.y - 2, tb.width + 4, tb.height + 4);
    }
  }
Example #2
0
  /**
   * Draws an filled paddle with an extra outline around it in the current position
   *
   * @param pict is Picture object to draw the paddle outline in
   */
  public void drawPaddleXtr(JFrame pict) {
    Graphics g = pict.getGraphics();

    g.setColor(this.color);
    g.fillRect(this.x, this.y, this.width, this.height);
    g.setColor(Color.black);
    g.drawRect(this.x, this.y, this.width, this.height);
  }
 void drawZoomIndicator(Graphics g) {
   int x1 = 10;
   int y1 = 10;
   double aspectRatio = (double) imageHeight / imageWidth;
   int w1 = 64;
   if (aspectRatio > 1.0) w1 = (int) (w1 / aspectRatio);
   int h1 = (int) (w1 * aspectRatio);
   if (w1 < 4) w1 = 4;
   if (h1 < 4) h1 = 4;
   int w2 = (int) (w1 * ((double) srcRect.width / imageWidth));
   int h2 = (int) (h1 * ((double) srcRect.height / imageHeight));
   if (w2 < 1) w2 = 1;
   if (h2 < 1) h2 = 1;
   int x2 = (int) (w1 * ((double) srcRect.x / imageWidth));
   int y2 = (int) (h1 * ((double) srcRect.y / imageHeight));
   if (zoomIndicatorColor == null) zoomIndicatorColor = new Color(128, 128, 255);
   g.setColor(zoomIndicatorColor);
   ((Graphics2D) g).setStroke(Roi.onePixelWide);
   g.drawRect(x1, y1, w1, h1);
   if (w2 * h2 <= 200 || w2 < 10 || h2 < 10) g.fillRect(x1 + x2, y1 + y2, w2, h2);
   else g.drawRect(x1 + x2, y1 + y2, w2, h2);
 }
Example #4
0
  static void paintFocus(
      Graphics g, int x, int y, int width, int height, int r1, int r2, float grosor, Color color) {
    Graphics2D g2d = (Graphics2D) g;
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    Stroke oldStroke = g2d.getStroke();

    g2d.setColor(color);
    g2d.setStroke(new BasicStroke(grosor));
    if (r1 == 0 && r2 == 0) {
      g.drawRect(x, y, width, height);
    } else {
      g.drawRoundRect(x, y, width - 1, height - 1, r1, r2);
    }

    g2d.setStroke(oldStroke);

    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_DEFAULT);
  }
Example #5
0
 void drawOvalOrRectangle(Graphics g, DrawObject R, boolean isRect) {
   if (R == null) {
     return;
   }
   if ((sequencingOn) && (R.sequenceNum != currentSequenceNumDisplay)) {
     return;
   }
   Graphics2D g2 = (Graphics2D) g;
   g2.setStroke(R.drawStroke);
   int x1 = (int) ((R.x - minX) / (maxX - minX) * (D.width - 2 * inset));
   int y1 = (int) ((R.y - minY) / (maxY - minY) * (D.height - 2.0 * inset));
   double x = R.x + R.width;
   double y = R.y - R.height;
   int x2 = (int) ((x - minX) / (maxX - minX) * (D.width - 2 * inset));
   int y2 = (int) ((y - minY) / (maxY - minY) * (D.height - 2.0 * inset));
   if (isRect) {
     g.drawRect(inset + x1, D.height - y1 - inset, x2 - x1, y1 - y2);
   } else {
     g.drawOval(inset + x1, D.height - y1 - inset, x2 - x1, y1 - y2);
   }
 }
Example #6
0
  /*@Override*/ public void paintIcon(Component c, Graphics g, int x, int y) {
    final boolean expandToFit = (mWidth < 1);

    if (DEBUG.IMAGE && DEBUG.META)
      out(
          "paintIcon; onto="
              + GUI.name(c)
              + " painter="
              + GUI.name(mPainter)
              + "@"
              + Integer.toHexString((mPainter.hashCode())));

    if (mPainter == null) {
      // note this means repaint updates would stop in a new parent,
      // tho assuming it's loaded by then, regular paints would work fine.
      mPainter = c;
    }

    if (DrawBorder && !expandToFit) {
      g.setColor(Color.gray);
      g.drawRect(x, y, mWidth - 1, mHeight - 1);
    }

    if (mImage == null) {

      if (!isLoading /*&& mPreviewData != null*/) {
        synchronized (this) {
          if (!isLoading /*&& mPreviewData != null*/)
            VUE.invokeAfterAWT(ResourceIcon.this); // load the preview
        }
      }
      g.setColor(Color.gray);
      g.drawRect(x, y, mWidth - 1, mHeight - 1);
      return;
    }

    int fitWidth, fitHeight;
    final Dimension maxImageSize;

    if (expandToFit) {
      // fill the given component
      fitWidth = c.getWidth();
      fitHeight = c.getHeight();
      maxImageSize = c.getSize();
    } else {
      // paint at our fixed size
      fitWidth = mWidth;
      fitHeight = mHeight;

      if (DrawBorder)
        maxImageSize = new Dimension(fitWidth - BorderSpace * 2, fitHeight - BorderSpace * 2);
      else maxImageSize = new Dimension(fitWidth, fitHeight);

      if (DEBUG.IMAGE && DEBUG.META) out("paintIcon; into " + GUI.name(maxImageSize));
    }

    double zoomFit;
    if (mImage == NoImage && expandToFit) {
      zoomFit = 1;
    } else {
      Rectangle2D imageBounds;
      if (CropToSquare) {
        // square off image, then fit in icon (todo: better; crop to icon)
        int smallestAxis = mImageWidth > mImageHeight ? mImageHeight : mImageWidth;
        imageBounds = new Rectangle2D.Float(0, 0, smallestAxis, smallestAxis);
      } else {
        // fit entire image in icon
        imageBounds = new Rectangle2D.Float(0, 0, mImageWidth, mImageHeight);
      }
      zoomFit = ZoomTool.computeZoomFit(maxImageSize, 0, imageBounds, null, false);
      if (zoomFit > MaxZoom) zoomFit = MaxZoom;
    }

    final int drawW = (int) (mImageWidth * zoomFit + 0.5);
    final int drawH = (int) (mImageHeight * zoomFit + 0.5);

    int xoff = x;
    int yoff = y;

    // center if drawable area is bigger than image
    if (drawW != fitWidth) xoff += (fitWidth - drawW) / 2;
    if (drawH != fitHeight) yoff += (fitHeight - drawH) / 2;

    Shape oldClip = null;
    if (CropToSquare && !expandToFit) {
      oldClip = g.getClip();
      g.clipRect(x, y, mWidth, mHeight);
    }

    if (DEBUG.IMAGE && DEBUG.META)
      out("paintIcon; " + Util.tag(mImage) + " as " + drawW + "x" + drawH);
    g.drawImage(mImage, xoff, yoff, drawW, drawH, null);

    if (DEBUG.BOXES) {
      g.setColor(Color.green);
      ((Graphics2D) g)
          .setComposite(
              java.awt.AlphaComposite.getInstance(java.awt.AlphaComposite.SRC_OVER, 0.2f));
      g.drawRect(x, y, mWidth - 1, mHeight - 1);
      ((Graphics2D) g).setComposite(java.awt.AlphaComposite.SrcOver);
    }

    if (CropToSquare && !expandToFit) g.setClip(oldClip);
  }
Example #7
0
 private void drawStartBox(Graphics g) {
   if (type != ANGLE) {
     double offset = getOffset(0.5);
     g.drawRect(ic.screenXD(startXD + offset) - 4, ic.screenYD(startYD + offset) - 4, 8, 8);
   }
 }
Example #8
0
  /**
   * Draws an outline of the paddle in the current position
   *
   * @param pict is Picture object to draw the paddle outline in
   */
  public void drawPaddleOutline(JFrame pict) {
    Graphics g = pict.getGraphics();

    g.setColor(this.color);
    g.drawRect(this.x, this.y, this.width, this.height);
  }