public synchronized void paintIcon(Component c, Graphics g, int x, int y) {
   g.setColor(Color.white);
   g.fillRect(0, 0, c.getWidth(), c.getHeight());
   if (getImageObserver() == null) {
     g.drawImage(
         getImage(),
         c.getWidth() / 2 - getIconWidth() / 2,
         c.getHeight() / 2 - getIconHeight() / 2,
         c);
   } else {
     g.drawImage(
         getImage(),
         c.getWidth() / 2 - getIconWidth() / 2,
         c.getHeight() / 2 - getIconHeight() / 2,
         getImageObserver());
   }
 }
示例#2
0
 public void paint(Graphics g) {
   if (comp != null) {
     width = comp.getWidth() / 6;
     height = comp.getHeight() * 2 / 3;
   }
   g.setColor(bgColor);
   g.fillRect(x, y, width, height);
   g.setColor(fgColor);
   g.setFont(font);
   g.drawString(strTray, x / 2 + width / 2, y + height + 10);
   super.paint(g);
 }
示例#3
0
 public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
   if (image != null && showimage) {
     // TODO: add ability to scale maintaining aspect ratio fitting to size of parent
     // TODO: Need to add not zoom all the way, but zoom to a box of aspect ratio 4/3
     Graphics2D g2 = (Graphics2D) g;
     AffineTransform tran = new AffineTransform(1f, 0f, 0f, 1f, 0, 0);
     float widthscale = (float) c.getWidth() / image.getWidth();
     float heightscale = (float) c.getHeight() / image.getHeight();
     switch (drawmode) {
       case DRAW_MODE_ASPECT:
         float scale;
         if (widthscale < heightscale) {
           scale = widthscale;
         } else {
           scale = heightscale;
         }
         tran.scale(scale, scale);
         g2.drawImage(
             image,
             new AffineTransformOp(tran, AffineTransformOp.TYPE_BILINEAR),
             (int) (c.getWidth() - image.getWidth() * scale) / 2,
             (int) (c.getHeight() - image.getHeight() * scale) / 2);
         break;
       case DRAW_MODE_WIDTH:
         tran.scale(widthscale, widthscale);
         g2.drawImage(image, tran, null);
         break;
       case DRAW_MODE_HEIGHT:
         tran.scale(heightscale, heightscale);
         g2.drawImage(image, tran, null);
         break;
       default:
         tran.scale(widthscale, heightscale);
         g2.drawImage(image, tran, null);
         break;
     }
   }
 }
示例#4
0
  private static void exportScreenshotEpsGraphics(
      Component target, File selectedFile, boolean paintOffscreen) throws IOException {

    if (!SnapshotUtilities.canExportScreenshotEps()) {
      String msg =
          "ERROR: EPS output requires EPSGraphics library. See https://www.broadinstitute.org/software/igv/third_party_tools#epsgraphics";
      log.error(msg);
      return;
    }

    Graphics2D g = null;
    FileOutputStream fos = null;
    try {
      Class colorModeClass = RuntimeUtils.loadClassForName(EPSColorModeClassName, null);
      Class graphicsClass = RuntimeUtils.loadClassForName(EPSClassName, null);

      Constructor constructor =
          graphicsClass.getConstructor(
              String.class,
              OutputStream.class,
              int.class,
              int.class,
              int.class,
              int.class,
              colorModeClass);

      Object colorModeValue = Enum.valueOf(colorModeClass, "COLOR_RGB");

      // EpsGraphics stores directly in a file
      fos = new FileOutputStream(selectedFile);
      g =
          (Graphics2D)
              constructor.newInstance(
                  "eps", fos, 0, 0, target.getWidth(), target.getHeight(), colorModeValue);

      choosePaint(target, g, paintOffscreen);

      graphicsClass.getMethod("close").invoke(g);

    } catch (Exception e) {
      log.error(e.getMessage(), e);
    } finally {
      if (fos != null) {
        fos.flush();
        fos.close();
      }
    }
  }
示例#5
0
  public static String doComponentSnapshot(
      Component component,
      File file,
      SnapshotFileChooser.SnapshotFileType type,
      boolean paintOffscreen)
      throws IOException {

    // TODO Should really make this work for more components
    if (paintOffscreen && !(component instanceof Paintable)) {
      log.error("Component cannot be painted offscreen. Performing onscreen paint");
      paintOffscreen = false;
    }

    if (paintOffscreen) {

      Rectangle rect = component.getBounds();

      if (component instanceof MainPanel) {
        rect.height = ((MainPanel) component).getOffscreenImageHeight();
      } else {
        rect.height = Math.min(component.getHeight(), getMaxPanelHeight());
      }

      // translate to (0, 0) if necessary
      int dx = rect.x;
      int dy = rect.y;
      rect.x = 0;
      rect.y = 0;
      rect.width -= dx;
      rect.height -= dy;

      component.setBounds(rect);
    }

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

    // Call appropriate converter
    String format = null;
    String[] exts = null;
    switch (type) {
      case SVG:
        // log.debug("Exporting svg screenshot");
        exportScreenshotSVG(component, file, paintOffscreen);
        // exportScreenshotVector2D(component, file, paintOffscreen);
        break;
      case JPEG:
        format = "jpeg";
        exts = new String[] {".jpg", ".jpeg"};
        break;
      case PNG:
        format = "png";
        exts = new String[] {"." + format};
        break;
      case EPS:
        exportScreenshotEpsGraphics(component, file, paintOffscreen);
        // exportScreenshotEpsGraphicsNoRef(component, file, paintOffscreen);
        break;
    }
    if (format != null && exts != null) {
      exportScreenShotBufferedImage(component, file, width, height, exts, format, paintOffscreen);
    }
    return "OK";
  }