예제 #1
0
 /**
  * Extracts the buffered image of some component
  *
  * @param myComponent the component for which the BufferedImage is required
  * @param region region to be captured
  * @return the BufferedImage which has the current condition of component
  * @throws IOException
  */
 public static BufferedImage Get_Component_Image(Component myComponent, Rectangle region)
     throws IOException {
   BufferedImage img =
       new BufferedImage(
           myComponent.getWidth(), myComponent.getHeight(), BufferedImage.TYPE_INT_RGB);
   Graphics g = img.getGraphics();
   myComponent.paint(g);
   g.dispose();
   return img;
 }
예제 #2
0
 public void paint(Graphics g1) {
   Graphics2D g = (Graphics2D) g1;
   Component c;
   Point p;
   paintComponent(g);
   for (int i = 0; i < getComponentCount(); i++) {
     AffineTransform save = g.getTransform();
     c = getComponent(i);
     p = c.getLocation();
     g.translate((int) p.getX(), (int) p.getY());
     c.paint(g);
     g.setTransform(save);
   }
 }
  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);
  }