Exemplo n.º 1
0
  /** paint the canvas into a image file of given width and height */
  public void writeToImage(String s, int w, int h) {
    String ext;
    File f;
    try {
      ext = s.substring(s.lastIndexOf(".") + 1);
      f = new File(s);
    } catch (Exception e) {
      System.out.println(e);
      return;
    }
    if (!ext.equals("jpg") && !ext.equals("png")) {
      System.out.println("Cannot write to file: Illegal extension " + ext);
      return;
    }
    boolean opq = true;
    if (theOpaque != null) opq = theOpaque;

    BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = image.createGraphics();
    g2.setBackground(Color.white);
    g2.setPaint(Color.black);
    g2.setStroke(new BasicStroke(1));
    g2.setRenderingHint(
        RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
    doBuffer(g2, true, new Rectangle(0, 0, w, h));
    try {
      ImageIO.write(image, ext, f);
    } catch (Exception e) {
      System.out.println(e);
    }
  }
Exemplo n.º 2
0
  public void paint(Graphics g) {
    super.paint(g);
    Graphics2D g2D = (Graphics2D) g;
    int x = this.getWidth();
    int y = this.getHeight();
    int z = 4;

    if (orientation.equals(DesktopBar.WEST)) {
      int[] X = {x - z, x - z, 2 * x / 5, x / 2, z, x / 2, 2 * x / 5};
      int[] Y = {2 * y / 5, 3 * y / 5, 3 * y / 5, y - z, y / 2, z, 2 * y / 5};
      g2D.draw(new Polygon(X, Y, 7));
    }
    if (orientation.equals(DesktopBar.EAST)) {
      int[] X = {z, z, 2 * x / 3, x / 2, x - z, x / 2, 2 * x / 3};
      int[] Y = {2 * y / 5, 3 * y / 5, 3 * y / 5, y - z, y / 2, z, 2 * y / 5};
      g2D.draw(new Polygon(X, Y, 7));
    }
    if (orientation.equals(DesktopBar.NORTH)) {
      int[] X = {2 * x / 5, 3 * x / 5, 3 * x / 5, x - z, x / 2, z, 2 * x / 5};
      int[] Y = {y - z, y - z, 2 * y / 5, y / 2, z, y / 2, 2 * y / 5};
      g2D.draw(new Polygon(X, Y, 7));
    }
    if (orientation.equals(DesktopBar.SOUTH)) {
      int[] X = {2 * x / 5, 3 * x / 5, 3 * x / 5, x - z, x / 2, z, 2 * x / 5};
      int[] Y = {z, z, 2 * y / 3, y / 2, y - z, y / 2, 2 * y / 3};
      g2D.draw(new Polygon(X, Y, 7));
    }
  }
Exemplo n.º 3
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);
    }
  }
Exemplo n.º 4
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;
    }
  }
  /**
   * All purpose paint method that should do the right thing for all linear bouncing-box progress
   * bars. Override this if you are making another kind of progress bar.
   *
   * @see #paintDeterminate
   * @since 1.4
   */
  protected void paintIndeterminate(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;
    }

    Graphics2D g2 = (Graphics2D) g;

    // Paint the bouncing box.
    boxRect = getBox(boxRect);
    if (boxRect != null) {
      g2.setColor(progressBar.getForeground());
      g2.fillRect(boxRect.x, boxRect.y, boxRect.width, boxRect.height);
    }

    // Deal with possible text painting
    if (progressBar.isStringPainted()) {
      if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) {
        paintString(g2, b.left, b.top, barRectWidth, barRectHeight, boxRect.x, boxRect.width, b);
      } else {
        paintString(g2, b.left, b.top, barRectWidth, barRectHeight, boxRect.y, boxRect.height, b);
      }
    }
  }
Exemplo n.º 6
0
 /** [Internal] */
 private void paintBackground(Graphics2D g2, Color theBackground) {
   Color color1 = g2.getColor();
   if (theBackground == null) theBackground = Color.white;
   g2.setColor(theBackground);
   g2.fillRect(0, 0, 30000, 30000);
   g2.setColor(color1);
 }
Exemplo n.º 7
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);
 }
Exemplo n.º 8
0
    /**
     * Paint a background for all groups and a round blue border and background when a cell is
     * selected.
     *
     * @param g the <tt>Graphics</tt> object
     */
    private void internalPaintComponent(Graphics g) {
      AntialiasingManager.activateAntialiasing(g);

      Graphics2D g2 = (Graphics2D) g;

      if (isSelected) {
        g2.setColor(selectedColor);
        g2.fillRect(0, 0, this.getWidth(), this.getHeight());
      }
    }
Exemplo n.º 9
0
  public void paint(Graphics g) {
    gRef = (Graphics2D) g;

    // change size of font
    gRef.setFont(gRef.getFont().deriveFont(9.0f));

    fmRef = g.getFontMetrics();

    // Clear background

    if (Preferences.monochrome) {
      gRef.setColor(Preferences.whiteColor);
    } else {
      gRef.setColor(Preferences.backgroundColor);
    }
    gRef.fillRect(0, 0, getWidth(), getHeight());

    // set colour to correct drawing colour
    if (Preferences.monochrome) {
      gRef.setColor(Preferences.blackColor);
    } else {
      gRef.setColor(Preferences.penColor);
    }

    gRef.translate(0, margin);

    // Call c code to draw tree
    gRef.scale(scale, scale);
    nativeDrawTree();
  }
 @Override
 public void paintIcon(Component c, Graphics g, int x, int y) {
   icon.paintIcon(c, g, x, y);
   int w = getIconWidth();
   int h = getIconHeight();
   Graphics2D g2 = (Graphics2D) g;
   g2.setPaint(FOREGROUND);
   g2.translate(x, y);
   g2.fillRect(a, (h - b) / 2, w - a - a, b);
   g2.translate(-x, -y);
 }
Exemplo n.º 11
0
 public void paint(Graphics g) {
   synchronized (this) {
     Graphics2D g2d = (Graphics2D) g;
     if (img != null) {
       int imgw = img.getWidth();
       int imgh = img.getHeight();
       g2d.setComposite(AlphaComposite.Src);
       g2d.drawImage(img, null, 0, 0);
     }
   }
 }
Exemplo n.º 12
0
 public static BufferedImage tileImage(BufferedImage im, int width, int height) {
   GraphicsConfiguration gc =
       GraphicsEnvironment.getLocalGraphicsEnvironment()
           .getDefaultScreenDevice()
           .getDefaultConfiguration();
   int transparency = Transparency.OPAQUE; // Transparency.BITMASK;
   BufferedImage compatible = gc.createCompatibleImage(width, height, transparency);
   Graphics2D g = (Graphics2D) compatible.getGraphics();
   g.setPaint(new TexturePaint(im, new Rectangle(0, 0, im.getWidth(), im.getHeight())));
   g.fillRect(0, 0, width, height);
   return compatible;
 }
Exemplo n.º 13
0
  public void setPenColour(int colour) {

    if (Preferences.monochrome) {
      gRef.setColor(Preferences.blackColor);
    } else {
      if (colour == 0) {
        gRef.setColor(Preferences.penColor);
      }
      if (colour == 1) {
        gRef.setColor(Preferences.highlightColor);
      }
    }
  }
Exemplo n.º 14
0
 /** [Internal] */
 public int print(Graphics g, PageFormat pf, int pi) throws PrinterException {
   if (pi >= 1) {
     return Printable.NO_SUCH_PAGE;
   }
   RepaintManager currentManager = RepaintManager.currentManager(this);
   currentManager.setDoubleBufferingEnabled(false);
   Graphics2D g2 = (Graphics2D) g;
   initState(g2, true);
   g2.translate((int) (pf.getImageableX() + 1), (int) (pf.getImageableY() + 1));
   g2.scale(printScale, printScale);
   doBuffer(g2, true, null);
   currentManager.setDoubleBufferingEnabled(true);
   return Printable.PAGE_EXISTS;
 }
Exemplo n.º 15
0
 private synchronized void doBuffer(Graphics2D g2, boolean opq, Rectangle rt) {
   origTransform = g2.getTransform();
   if (opq && rt != null) g2.clearRect(rt.x, rt.y, rt.width, rt.height);
   g2.setPaint(origPaint);
   g2.setFont(origFont);
   g2.setStroke(origStroke);
   if (inBuffer) { // System.out.println("upps");
     for (int i = 0; i < a1x.size(); i++) doPaint(g2, a1x.get(i), a2x.get(i));
     origTransform = null;
     return;
   }
   for (int i = 0; i < a1.size(); i++) doPaint(g2, a1.get(i), a2.get(i));
   origTransform = null;
 }
Exemplo n.º 16
0
  public void generarFondo(Component componente) {
    Rectangle areaDibujo = this.getBounds();
    BufferedImage tmp;
    GraphicsConfiguration gc =
        GraphicsEnvironment.getLocalGraphicsEnvironment()
            .getDefaultScreenDevice()
            .getDefaultConfiguration();

    tmp = gc.createCompatibleImage(areaDibujo.width, areaDibujo.height, BufferedImage.TRANSLUCENT);
    Graphics2D g2d = (Graphics2D) tmp.getGraphics();
    g2d.setColor(new Color(55, 55, 255, 165));
    g2d.fillRect(0, 0, areaDibujo.width, areaDibujo.height);
    fondo = tmp;
  }
Exemplo n.º 17
0
  private void drawString(String str, int x, int y) {

    // text does not work correctly for very small scales.
    if (textEnabled && scale > 0.05) {
      gRef.drawString(str, x, y);
    }
  }
Exemplo n.º 18
0
 private void drawPoint(PointDP point, Graphics2D g) {
   g.fillOval(
       frameWidth / 2 + (int) (point.x * unityX) - 3,
       frameHeight / 2 - (int) (point.y * unityY) - 3,
       6,
       6);
 }
Exemplo n.º 19
0
 public void render(int w, int h, Graphics2D g2) {
   int iw = img[imgIndex].getWidth(null);
   int ih = img[imgIndex].getHeight(null);
   BufferedImage bi = new BufferedImage(iw, ih, BufferedImage.TYPE_INT_RGB);
   biop[opsIndex].filter(img[imgIndex], bi);
   g2.drawImage(bi, 0, 0, w, h, null);
 }
Exemplo n.º 20
0
 private void fillPolyline(int x[], int y[], int length, int symbolType) {
   if (!Preferences.monochrome) {
     setFillColor(symbolType);
     gRef.fillPolygon(x, y, length);
     restoreColor();
   }
 }
Exemplo n.º 21
0
 private void fillRectangle(int x, int y, int width, int height, int symbolType) {
   if (!Preferences.monochrome) {
     setFillColor(symbolType);
     gRef.fillRect(x, y, width, height);
     restoreColor();
   }
 }
Exemplo n.º 22
0
  public synchronized void paint(Graphics gin) {
    Graphics2D g = (Graphics2D) gin;

    if (im == null) return;

    int height = getHeight();
    int width = getWidth();

    if (fit) {
      t = new AffineTransform();
      double scale = Math.min(((double) width) / im.getWidth(), ((double) height) / im.getHeight());
      // we'll re-center the transform in a moment.
      t.scale(scale, scale);
    }

    // if the image (in either X or Y) is smaller than the view port, then center
    // the image with respect to that axis.
    double mwidth = im.getWidth() * t.getScaleX();
    double mheight = im.getHeight() * t.getScaleY();
    if (mwidth < width)
      t.preConcatenate(
          AffineTransform.getTranslateInstance((width - mwidth) / 2.0 - t.getTranslateX(), 0));
    if (mheight < height)
      t.preConcatenate(
          AffineTransform.getTranslateInstance(0, (height - mheight) / 2.0 - t.getTranslateY()));

    // if we're allowing panning (because only a portion of the image is visible),
    // don't allow translations that show less information that is possible.
    Point2D topleft = t.transform(new Point2D.Double(0, 0), null);
    Point2D bottomright = t.transform(new Point2D.Double(im.getWidth(), im.getHeight()), null);

    if (mwidth > width) {
      if (topleft.getX() > 0)
        t.preConcatenate(AffineTransform.getTranslateInstance(-topleft.getX(), 0));
      if (bottomright.getX() < width)
        t.preConcatenate(AffineTransform.getTranslateInstance(width - bottomright.getX(), 0));
      //		    t.translate(width-bottomright.getX(), 0);
    }
    if (mheight > height) {
      if (topleft.getY() > 0)
        t.preConcatenate(AffineTransform.getTranslateInstance(0, -topleft.getY()));
      if (bottomright.getY() < height)
        t.preConcatenate(AffineTransform.getTranslateInstance(0, height - bottomright.getY()));
    }

    g.drawImage(im, t, null);
  }
Exemplo n.º 23
0
 private void fillArc(
     int x, int y, int width, int height, int startAngle, int arcAngle, int symbolType) {
   if (!Preferences.monochrome) {
     setFillColor(symbolType);
     gRef.fillArc(x, y, width, height, startAngle, arcAngle);
     restoreColor();
   }
 }
Exemplo n.º 24
0
  private void buildAccumulator(int r) {
    accImage = new BufferedImage(width, height, greyScale.getType());
    Graphics2D g = accImage.createGraphics();
    g.setColor(new Color(0, 0, 0, 0));
    g.fillRect(0, 0, width, height);
    g.dispose();
    int max = 0;

    double[] a = new double[1];
    for (int y = 0; y < height; ++y)
      for (int x = 0; x < width; ++x) {
        a[0] = acc[y * width + x][r - rmin] & 0xFF;
        accImage.getRaster().setPixel(x, y, a);
      }
    ImageIcon icon2 = new ImageIcon(accImage);
    lbl2.setIcon(icon2);
  }
Exemplo n.º 25
0
 public void draw(Graphics2D g) {
   Rectangle2D clipBounds = g.getClipBounds();
   if (clipBounds != null) {
     Collection<Figure> c = quadTree.findIntersects(clipBounds);
     Collection<Figure> toDraw = sort(c);
     draw(g, toDraw);
   } else {
     draw(g, children);
   }
 }
Exemplo n.º 26
0
 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()));
     }
   }
 }
Exemplo n.º 27
0
  /**
   * Draws the passed-in text using syntax highlighting for the current language. It is assumed that
   * the entire line is either not in a selected region, or painting with a selection-foreground
   * color is turned off.
   *
   * @param painter The painter to render the tokens.
   * @param token The list of tokens to draw.
   * @param g The graphics context in which to draw.
   * @param x The x-coordinate at which to draw.
   * @param y The y-coordinate at which to draw.
   * @return The x-coordinate representing the end of the painted text.
   */
  private float drawLine(
      TokenPainter painter, Token token, Graphics2D g, float x, float y, int line) {

    float nextX = x; // The x-value at the end of our text.
    boolean paintBG = host.getPaintTokenBackgrounds(line, y);

    while (token != null && token.isPaintable() && nextX < clipEnd) {
      nextX = painter.paint(token, g, nextX, y, host, this, clipStart, paintBG);
      token = token.getNextToken();
    }

    // NOTE: We should re-use code from Token (paintBackground()) here,
    // but don't because I'm just too lazy.
    if (host.getEOLMarkersVisible()) {
      g.setColor(host.getForegroundForTokenType(Token.WHITESPACE));
      g.setFont(host.getFontForTokenType(Token.WHITESPACE));
      g.drawString("\u00B6", nextX, y);
    }

    // Return the x-coordinate at the end of the painted text.
    return nextX;
  }
Exemplo n.º 28
0
  public void sobel() {
    sobel = new BufferedImage(width, height, filtered.getType());
    Graphics2D g = sobel.createGraphics();
    g.setColor(new Color(0, 0, 0, 0));
    g.fillRect(0, 0, width, height);
    g.dispose();

    int[] tmp = new int[1];
    sX = new double[height][width];
    sY = new double[height][width];
    double maxX = 0;
    double maxY = 0;
    for (int y = 1; y < height - 1; ++y)
      for (int x = 1; x < width - 1; ++x) {
        double Xvalue = 0;
        double Yvalue = 0;
        for (int j = -1; j <= 1; ++j)
          for (int i = -1; i <= 1; ++i) {

            Xvalue += GX[1 + j][1 + i] * filtered.getRaster().getPixel(x + i, y + j, tmp)[0];
            Yvalue += GY[1 + j][1 + i] * filtered.getRaster().getPixel(x + i, y + j, tmp)[0];
          }
        if (Xvalue > maxX) maxX = Xvalue;
        if (Yvalue > maxY) maxY = Yvalue;
        sX[y][x] = Xvalue;
        sY[y][x] = Yvalue;
      }

    for (int y = 1; y < height - 1; ++y)
      for (int x = 1; x < width - 1; ++x) {
        double[] a = {(Math.abs((sX[y][x] / maxX * 255)) + Math.abs((sY[y][x] / maxY) * 255))};
        // if (a[0] > 0) binary[y][x] = 1;
        // if (a[0] <= 0) binary[y][x] = 0;

        sobel.getRaster().setPixel(x, y, a);
      }
    ImageIcon icon2 = new ImageIcon(sobel);
    lbl2.setIcon(icon2);
  }
 public void drawPolylines(Graphics2D g2) {
   int i, ipol, npoints, noffs;
   // draw GeneralPath (polyline)
   for (ipol = 0; ipol < numpolys; ipol++) {
     noffs = bufpol[ipol];
     npoints = bufpts[noffs + 1];
     if (npoints > 1) { // was 0, TS on 20.08.'12
       polyline.moveTo(bufpts[noffs + 2], bufpts[noffs + 3]);
       for (i = 1; i < npoints; i++) {
         polyline.lineTo(bufpts[noffs + 2 * i + 2], bufpts[noffs + 2 * i + 3]);
       }
       /* //TS on 20.08.'12
                       if (npoints == 1) {
                           polyline.lineTo(bufpts[noffs+2], bufpts[noffs+3]);
                       }
       */
       g2.setStroke(DatanGraphics.strokes[bufpts[noffs] - 1]);
       g2.setPaint(DatanGraphics.ct[bufpts[noffs]]);
       g2.draw(polyline);
       polyline.reset();
     }
   }
 }
Exemplo n.º 30
0
 private synchronized void toBuffer(int s, Object a) {
   a1.add(s);
   a2.add(a);
   if (s == clear) {
     clearBuffer();
   }
   if (s == opaque) theOpaque = (Boolean) a;
   if (s == setBackground) theBackground = (Color) a;
   if (inBuffer) return;
   if (isSetter(s)) return;
   Graphics g = getGraphics();
   if (g == null) return;
   Graphics2D g2 = (Graphics2D) g;
   g2.setPaint(origPaint);
   g2.setFont(origFont);
   g2.setStroke(origStroke);
   for (int i = 0; i < a1.size() - 1; i++) {
     int s1 = a1.get(i);
     Object s2 = a2.get(i);
     if (isSetter(s1)) doPaint(g2, s1, s2);
   }
   doPaint((Graphics2D) g, s, a);
 }