コード例 #1
0
  @Override
  protected void paintComponent(Graphics graphics) {
    // Fill in the background:
    Graphics2D g = (Graphics2D) graphics;
    Shape clip = g.getClip();
    g.setColor(LightZoneSkin.Colors.NeutralGray);
    g.fill(clip);

    if (preview == null) {
      PlanarImage image = currentImage.get();
      if (image == null) {
        engine.update(null, false);
      } else if (visibleRect != null && getHeight() > 1 && getWidth() > 1) {
        preview = cropScaleGrayscale(visibleRect, image);
      }
    }
    if (preview != null) {
      int dx, dy;
      AffineTransform transform = new AffineTransform();
      if (getSize().width > preview.getWidth()) dx = (getSize().width - preview.getWidth()) / 2;
      else dx = 0;
      if (getSize().height > preview.getHeight()) dy = (getSize().height - preview.getHeight()) / 2;
      else dy = 0;
      transform.setToTranslation(dx, dy);
      try {
        g.drawRenderedImage(preview, transform);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
コード例 #2
0
 @Override
 public void addNotify() {
   // This method gets called when this Preview is added.
   engine.update(null, false);
   super.addNotify();
 }