예제 #1
0
  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
 private static Image getImage(ResizableIcon icon, int size) {
   icon.setDimension(new Dimension(size, size));
   if (icon instanceof AsynchronousLoading) {
     AsynchronousLoading async = (AsynchronousLoading) icon;
     if (async.isLoading()) {
       final CountDownLatch latch = new CountDownLatch(1);
       final boolean[] status = new boolean[1];
       AsynchronousLoadListener all =
           new AsynchronousLoadListener() {
             @Override
             public void completed(boolean success) {
               status[0] = success;
               latch.countDown();
             }
           };
       async.addAsynchronousLoadListener(all);
       try {
         latch.await();
       } catch (InterruptedException ignored) {
       }
       async.removeAsynchronousLoadListener(all);
       if (!status[0]) {
         return null;
       }
       if (async.isLoading()) {
         return null;
       }
     }
   }
   Image result = FlamingoUtilities.getBlankImage(size, size);
   Graphics2D g2d = (Graphics2D) result.getGraphics().create();
   icon.paintIcon(null, g2d, 0, 0);
   g2d.dispose();
   return result;
 }
예제 #3
0
  /**
   * Adds the componentType buttons to the Panel of Main Window.
   *
   * @param pkg_name whose componentType buttons will be added
   * @param a needed for the addition of the ActionListener of respective buttons and calling method
   *     of Pad_Draw
   */
  public void add_componentType_buttons(package_cls pkg_name, final counts a) {
    int i;
    JLabel pkg_hdng = new JLabel(pkg_name.getName());
    panel.add(pkg_hdng);
    for (i = 0; i < pkg_name.getComponentType_list().size(); i++) {
      final componentType cmp_Types = pkg_name.getComponentType_list().get(i);
      int btnHeight, btnWidth;
      double scale = 0.5;
      btnWidth = (int) (scale * (double) cmp_Types.getWidth());
      btnHeight = (int) (scale * (double) cmp_Types.getHeight());
      ImageIcon myIcon = new ImageIcon(cmp_Types.getType_Img());

      BufferedImage bi = new BufferedImage(btnWidth, btnHeight, BufferedImage.TYPE_INT_ARGB);
      Graphics2D g = bi.createGraphics();
      g.scale(scale, scale);
      myIcon.paintIcon(null, g, 0, 0);
      g.dispose();

      JButton strctButton = new JButton(new ImageIcon(bi));
      strctButton.addActionListener(
          new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
              drawPad.add_componentType(cmp_Types, a);
              taskbar.setText("Click to add a component");
            }
          });
      panel.add(strctButton);
    }
    panel.validate(); // Updates the Panel
  }
예제 #4
0
 private static BufferedImage makeBufferedImage(Icon icon, int w, int h) {
   BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
   Graphics2D g = image.createGraphics();
   icon.paintIcon(null, g, (w - icon.getIconWidth()) / 2, (h - icon.getIconWidth()) / 2);
   g.dispose();
   return image;
 }
예제 #5
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();
  }
예제 #6
0
  public void drawScreen() {
    Graphics2D g = (Graphics2D) this.getGraphics();

    g.drawImage(buffer, 0, 0, this);
    Toolkit.getDefaultToolkit().sync();
    g.dispose();
  }
예제 #7
0
 public static BufferedImage convertToARGB(BufferedImage image) {
   BufferedImage newImage =
       new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB);
   Graphics2D g = newImage.createGraphics();
   g.drawImage(image, 0, 0, null);
   g.dispose();
   return newImage;
 }
예제 #8
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();
 }
 public static BufferedImage resize(BufferedImage image, int width, int height) {
   BufferedImage bi = new BufferedImage(width, height, BufferedImage.TRANSLUCENT);
   Graphics2D g2d = (Graphics2D) bi.createGraphics();
   g2d.addRenderingHints(
       new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY));
   g2d.drawImage(image, 0, 0, width, height, null);
   g2d.dispose();
   return bi;
 }
  // Takes resource name and returns button
  public JButton createButton(String name, String toolTip) {

    // load the image
    String imagePath = "./resources/" + name + ".png";
    ImageIcon iconRollover = new ImageIcon(imagePath);
    int w = iconRollover.getIconWidth();
    int h = iconRollover.getIconHeight();

    // get the cursor for this button
    Cursor cursor = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);

    // make translucent default image
    Image image = createCompatibleImage(w, h, Transparency.TRANSLUCENT);
    Graphics2D g = (Graphics2D) image.getGraphics();
    Composite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .5f);
    g.setComposite(alpha);
    g.drawImage(iconRollover.getImage(), 0, 0, null);
    g.dispose();
    ImageIcon iconDefault = new ImageIcon(image);

    // make a pressed image
    image = createCompatibleImage(w, h, Transparency.TRANSLUCENT);
    g = (Graphics2D) image.getGraphics();
    g.drawImage(iconRollover.getImage(), 2, 2, null);
    g.dispose();
    ImageIcon iconPressed = new ImageIcon(image);

    // create the button
    JButton button = new JButton();
    button.addActionListener(this);
    button.setIgnoreRepaint(true);
    button.setFocusable(false);
    button.setToolTipText(toolTip);
    button.setBorder(null);
    button.setContentAreaFilled(false);
    button.setCursor(cursor);
    button.setIcon(iconDefault);
    button.setRolloverIcon(iconRollover);
    button.setPressedIcon(iconPressed);

    return button;
  }
예제 #11
0
  /**
   * Overrides the <code>paintComponent</code> method of <tt>JButton</tt> to paint the button
   * background and icon, and all additional effects of this configurable button.
   *
   * @param g The Graphics object.
   */
  @Override
  protected void paintComponent(Graphics g) {
    Graphics2D g1 = (Graphics2D) g.create();
    try {
      internalPaintComponent(g1);
    } finally {
      g1.dispose();
    }

    super.paintComponent(g);
  }
예제 #12
0
 @Override
 public void dispose() {
   myTimer.stop();
   super.dispose();
   if (myGraphics != null) {
     myGraphics.dispose();
   }
   myImage = null;
   myPipetteImage = null;
   myMaskImage = null;
 }
예제 #13
0
 public static BufferedImage cropImage(BufferedImage bi, int x, int y, int w, int h) {
   BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
   Graphics2D g2 = image.createGraphics();
   g2.setRenderingHint(
       RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
   g2.setPaint(Color.white);
   g2.fillRect(0, 0, w, h);
   g2.drawImage(bi, -x, -y, null); // this);
   g2.dispose();
   return image;
 }
예제 #14
0
  public void drawBuffer() {
    Graphics2D b = buffer.createGraphics();

    b.setColor(Color.black);
    b.fillRect(0, 0, 800, 600);

    if (hast.collision == false) {
      b.setColor(Color.red);
      b.fillRect(hast.getX(), hast.getY(), hast.getWidth(), hast.getHeight());

      for (int i = 0; i < 20; i++) {
        b.setColor(Color.blue);
        b.fillRect(box[i].getX(), box[i].getY(), box[i].getWidth(), box[i].getHeight());
      }

      b.dispose();
    } else b.setColor(Color.white);
    b.drawString("Horsie is DEAD!!!!", 350, 300);
    b.dispose();
  }
 private void doPaintStatusText(Graphics g, Rectangle textComponentBounds) {
   myComponent.setBounds(0, 0, textComponentBounds.width, textComponentBounds.height);
   Graphics2D g2 =
       (Graphics2D)
           g.create(
               textComponentBounds.x,
               textComponentBounds.y,
               textComponentBounds.width,
               textComponentBounds.height);
   myComponent.paint(g2);
   g2.dispose();
 }
예제 #16
0
 public static BufferedImage scaleImage(BufferedImage bi, double scale) {
   int w1 = (int) (Math.round(scale * bi.getWidth()));
   int h1 = (int) (Math.round(scale * bi.getHeight()));
   BufferedImage image = new BufferedImage(w1, h1, BufferedImage.TYPE_INT_RGB);
   Graphics2D g2 = image.createGraphics();
   g2.setRenderingHint(
       RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
   g2.setPaint(Color.white);
   g2.fillRect(0, 0, w1, h1);
   g2.drawImage(bi, 0, 0, w1, h1, null); // this);
   g2.dispose();
   return image;
 }
예제 #17
0
      public Example(BufferedImage image) {
        // copy image
        int width = image.getWidth();
        int height = image.getHeight();
        this.image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = this.image.createGraphics();
        g2.drawImage(image, 0, 0, null);
        g2.dispose();

        // create icon
        if (Math.max(width, height) > ICON_SIZE) {
          double scale = Math.min((double) ICON_SIZE / width, (double) ICON_SIZE / height);
          width *= scale;
          height *= scale;
        }
        BufferedImage buf = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        g2 = buf.createGraphics();
        g2.setRenderingHint(
            RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
        g2.drawImage(image, 0, 0, width, height, null);
        g2.dispose();
        this.icon = new ImageIcon(buf);
      }
예제 #18
0
 /*
  *  Create a BufferedImage for Swing components.
  *  All or part of the component can be captured to an image.
  *
  *  @param	 component Swing component to create image from
  *  @param	 region The region of the component to be captured to an image
  *  @param	 fileName name of file to be created or null
  *  @return	image the image for the given region
  *  @exception IOException if an error occurs during writing
  */
 public static BufferedImage createImage(JComponent component, Rectangle region, String fileName)
     throws IOException {
   boolean opaqueValue = component.isOpaque();
   component.setOpaque(true);
   BufferedImage image =
       new BufferedImage(region.width, region.height, BufferedImage.TYPE_INT_RGB);
   Graphics2D g2d = image.createGraphics();
   g2d.setClip(region);
   component.paint(g2d);
   g2d.dispose();
   component.setOpaque(opaqueValue);
   ScreenCapture.writeImage(image, fileName);
   return image;
 }
예제 #19
0
 public static BufferedImage rotateImage(BufferedImage bi) {
   int w = bi.getWidth();
   int h = bi.getHeight();
   BufferedImage image = new BufferedImage(h, w, BufferedImage.TYPE_INT_RGB);
   Graphics2D g2 = image.createGraphics();
   g2.setRenderingHint(
       RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
   g2.setPaint(Color.white); // getBackground());
   g2.fillRect(0, 0, h, w);
   g2.rotate(90 * Math.PI / 180);
   g2.drawImage(bi, 0, -h, w, h, null); // this);
   g2.dispose();
   return image;
 }
예제 #20
0
 private BufferedImage cropSelection() {
   int w = rectSelection.width, h = rectSelection.height;
   if (w <= 0 || h <= 0) {
     return null;
   }
   BufferedImage crop = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
   Graphics2D crop_g2d = crop.createGraphics();
   try {
     crop_g2d.drawImage(scr_img.getSubimage(rectSelection.x, rectSelection.y, w, h), null, 0, 0);
   } catch (RasterFormatException e) {
     Debug.error(e.getMessage());
   }
   crop_g2d.dispose();
   return crop;
 }
예제 #21
0
  /**
   * Internal utility method that creates a new icon. Called after the user selects a new color, or
   * when the size of the icon changes.
   */
  private void updateIcon() {
    BufferedImage image = new BufferedImage(iconWidth, iconHeight, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2d = (Graphics2D) image.getGraphics();

    g2d.setColor(this.color);
    // turn antialiasing off
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
    // we want fast rendering
    g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);

    g2d.fillRect(0, 0, iconWidth, iconHeight);
    ImageIcon imageIcon = new ImageIcon(image);
    this.setIcon(imageIcon);
    g2d.dispose();
  }
예제 #22
0
 @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();
 }
예제 #23
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();
 }
예제 #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);
  }
예제 #25
0
  public void paint(Graphics g) {
    // repaint the whole transformer in case the view component was repainted
    Rectangle clipBounds = g.getClipBounds();
    if (clipBounds != null && !clipBounds.equals(visibleRect)) {
      repaint();
    }
    // clear the background
    g.setColor(getBackground());
    g.fillRect(0, 0, getWidth(), getHeight());

    if (view != null && at.getDeterminant() != 0) {
      Graphics2D g2 = (Graphics2D) g.create();
      Insets insets = getInsets();
      Rectangle bounds = getBounds();

      // don't forget about insets
      bounds.x += insets.left;
      bounds.y += insets.top;
      bounds.width -= insets.left + insets.right;
      bounds.height -= insets.top + insets.bottom;
      double centerX1 = bounds.getCenterX();
      double centerY1 = bounds.getCenterY();

      Rectangle tb = getTransformedSize();
      double centerX2 = tb.getCenterX();
      double centerY2 = tb.getCenterY();

      // set antialiasing by default
      g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      if (renderingHints != null) {
        g2.addRenderingHints(renderingHints);
      }
      // translate it to the center of the view component again
      double tx = centerX1 - centerX2 - getX();
      double ty = centerY1 - centerY2 - getY();
      g2.translate((int) tx, (int) ty);
      g2.transform(at);
      view.paint(g2);
      g2.dispose();
    }
    // paint the border
    paintBorder(g);
  }
예제 #26
0
  @Override
  public void draw(Graphics2D g) {
    double opacity = get(OPACITY);
    opacity = Math.min(Math.max(0d, opacity), 1d);
    if (opacity != 0d) {
      if (opacity != 1d) {
        Rectangle2D.Double drawingArea = getDrawingArea();

        Rectangle2D clipBounds = g.getClipBounds();
        if (clipBounds != null) {
          Rectangle2D.intersect(drawingArea, clipBounds, drawingArea);
        }

        if (!drawingArea.isEmpty()) {

          BufferedImage buf =
              new BufferedImage(
                  (int) ((2 + drawingArea.width) * g.getTransform().getScaleX()),
                  (int) ((2 + drawingArea.height) * g.getTransform().getScaleY()),
                  BufferedImage.TYPE_INT_ARGB);
          Graphics2D gr = buf.createGraphics();
          gr.scale(g.getTransform().getScaleX(), g.getTransform().getScaleY());
          gr.translate((int) -drawingArea.x, (int) -drawingArea.y);
          gr.setRenderingHints(g.getRenderingHints());
          drawFigure(gr);
          gr.dispose();
          Composite savedComposite = g.getComposite();
          g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float) opacity));
          g.drawImage(
              buf,
              (int) drawingArea.x,
              (int) drawingArea.y,
              2 + (int) drawingArea.width,
              2 + (int) drawingArea.height,
              null);
          g.setComposite(savedComposite);
        }
      } else {
        drawFigure(g);
      }
    }
  }
    void paintSkin(Skin skin, Graphics _g, int dx, int dy, int dw, int dh, State state) {
      assert SwingUtilities.isEventDispatchThread();

      updateProgress();
      if (!isDone()) {
        Graphics2D g = (Graphics2D) _g.create();
        skin.paintSkinRaw(g, dx, dy, dw, dh, startState);
        float alpha;
        if (isForward) {
          alpha = progress;
        } else {
          alpha = 1 - progress;
        }
        g.setComposite(AlphaComposite.SrcOver.derive(alpha));
        skin.paintSkinRaw(g, dx, dy, dw, dh, state);
        g.dispose();
      } else {
        skin.paintSkinRaw(_g, dx, dy, dw, dh, state);
      }
    }
예제 #28
0
  private void establishFontMetrics() {
    final BufferedImage img = createBufferedImage(1, 1);
    final Graphics2D graphics = img.createGraphics();
    graphics.setFont(myNormalFont);

    final float lineSpace = mySettingsProvider.getLineSpace();
    final FontMetrics fo = graphics.getFontMetrics();

    myDescent = fo.getDescent();
    myCharSize.width = fo.charWidth('W');
    myCharSize.height = fo.getHeight() + (int) (lineSpace * 2);
    myDescent += lineSpace;

    myMonospaced = isMonospaced(fo);
    if (!myMonospaced) {
      LOG.info("WARNING: Font " + myNormalFont.getName() + " is non-monospaced");
    }

    img.flush();
    graphics.dispose();
  }
예제 #29
0
  private static int[] makeGradientPallet() {
    BufferedImage image = new BufferedImage(100, 1, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = image.createGraphics();
    Point2D start = new Point2D.Float(0f, 0f);
    Point2D end = new Point2D.Float(99f, 0f);
    float[] dist = {0f, .5f, 1f};
    Color[] colors = {Color.RED, Color.YELLOW, Color.GREEN};
    g2.setPaint(new LinearGradientPaint(start, end, dist, colors));
    g2.fillRect(0, 0, 100, 1);
    g2.dispose();

    int width = image.getWidth(null);
    int[] pallet = new int[width];
    PixelGrabber pg = new PixelGrabber(image, 0, 0, width, 1, pallet, 0, width);
    try {
      pg.grabPixels();
    } catch (InterruptedException ex) {
      ex.printStackTrace();
    }
    return pallet;
  }
예제 #30
0
    protected BufferedImage makeImage() {
      BufferedImage image =
          new BufferedImage(IMAGE_SIZE, IMAGE_SIZE, BufferedImage.TYPE_4BYTE_ABGR);
      Graphics2D g = image.createGraphics();

      g.setPaint(Color.WHITE);
      g.fill3DRect(0, 0, IMAGE_SIZE, IMAGE_SIZE, false);

      g.setPaint(Color.RED);
      g.setFont(Font.decode("ARIAL-BOLD-50"));

      g.drawString(Long.toString(++this.counter) + " frames", 10, IMAGE_SIZE / 4);
      g.drawString(
          Long.toString((System.currentTimeMillis() - start) / 1000) + " sec", 10, IMAGE_SIZE / 2);
      g.drawString(
          "Heap:" + Long.toString(Runtime.getRuntime().totalMemory()), 10, 3 * IMAGE_SIZE / 4);

      g.dispose();

      return image;
    }