Example #1
0
    private void runDialogsAndPrint() throws java.awt.print.PrinterException {
      out("job starting for " + this.map);
      PrinterJob job = getPrinterJob();
      out("got OS job: " + tufts.Util.tags(job));
      if (job.printDialog()) {
        out("printDialog ran, waiting for format...");
        // PageFormat format = getPageFormat(job, bounds);
        PageFormat format = getPageFormatInteractive(job, bounds);
        out("format: " + outpf(format));
        if (format != null) {
          job.setJobName(jobName);
          job.setPrintable(this, format);
          // try setting pageable to see if it then
          // skips system dialog (we'd like a no-dialog option)
          // job.setPrintService(job.getPrintService());

          // this only *sometimes* works as a workaround
          // for the vue ap mysteriously being raised above
          // the system print dialog...
          // VUE.frame.toBack();

          out("printing...");
          job.print();
        }
      }
      out("job complete.");
    }
Example #2
0
  private void displayImage(Image image) {
    if (DEBUG.RESOURCE || DEBUG.IMAGE) out("displayImage " + Util.tag(image));

    mImage = image;
    if (mImage != null) {
      mImageWidth = mImage.getWidth(null);
      mImageHeight = mImage.getHeight(null);
      if (DEBUG.IMAGE) out("displayImage " + mImageWidth + "x" + mImageHeight);
    }

    clearStatus();
    repaint();
  }
Example #3
0
  synchronized void loadResource(Resource r) {

    if (DEBUG.RESOURCE || DEBUG.IMAGE) out("loadResource: " + Util.tag(r) + " " + r);

    mResource = r;
    if (r != null) mPreviewData = r.getPreview();
    else mPreviewData = null;
    mImage = null;

    // URLResource decides this
    // if (mPreviewData == null && mResource.isImage())
    //    mPreviewData = mResource;

    loadPreview(mPreviewData);
  }
Example #4
0
  /*@Override*/ public void paintIcon(Component c, Graphics g, int x, int y) {
    final boolean expandToFit = (mWidth < 1);

    if (DEBUG.IMAGE && DEBUG.META)
      out(
          "paintIcon; onto="
              + GUI.name(c)
              + " painter="
              + GUI.name(mPainter)
              + "@"
              + Integer.toHexString((mPainter.hashCode())));

    if (mPainter == null) {
      // note this means repaint updates would stop in a new parent,
      // tho assuming it's loaded by then, regular paints would work fine.
      mPainter = c;
    }

    if (DrawBorder && !expandToFit) {
      g.setColor(Color.gray);
      g.drawRect(x, y, mWidth - 1, mHeight - 1);
    }

    if (mImage == null) {

      if (!isLoading /*&& mPreviewData != null*/) {
        synchronized (this) {
          if (!isLoading /*&& mPreviewData != null*/)
            VUE.invokeAfterAWT(ResourceIcon.this); // load the preview
        }
      }
      g.setColor(Color.gray);
      g.drawRect(x, y, mWidth - 1, mHeight - 1);
      return;
    }

    int fitWidth, fitHeight;
    final Dimension maxImageSize;

    if (expandToFit) {
      // fill the given component
      fitWidth = c.getWidth();
      fitHeight = c.getHeight();
      maxImageSize = c.getSize();
    } else {
      // paint at our fixed size
      fitWidth = mWidth;
      fitHeight = mHeight;

      if (DrawBorder)
        maxImageSize = new Dimension(fitWidth - BorderSpace * 2, fitHeight - BorderSpace * 2);
      else maxImageSize = new Dimension(fitWidth, fitHeight);

      if (DEBUG.IMAGE && DEBUG.META) out("paintIcon; into " + GUI.name(maxImageSize));
    }

    double zoomFit;
    if (mImage == NoImage && expandToFit) {
      zoomFit = 1;
    } else {
      Rectangle2D imageBounds;
      if (CropToSquare) {
        // square off image, then fit in icon (todo: better; crop to icon)
        int smallestAxis = mImageWidth > mImageHeight ? mImageHeight : mImageWidth;
        imageBounds = new Rectangle2D.Float(0, 0, smallestAxis, smallestAxis);
      } else {
        // fit entire image in icon
        imageBounds = new Rectangle2D.Float(0, 0, mImageWidth, mImageHeight);
      }
      zoomFit = ZoomTool.computeZoomFit(maxImageSize, 0, imageBounds, null, false);
      if (zoomFit > MaxZoom) zoomFit = MaxZoom;
    }

    final int drawW = (int) (mImageWidth * zoomFit + 0.5);
    final int drawH = (int) (mImageHeight * zoomFit + 0.5);

    int xoff = x;
    int yoff = y;

    // center if drawable area is bigger than image
    if (drawW != fitWidth) xoff += (fitWidth - drawW) / 2;
    if (drawH != fitHeight) yoff += (fitHeight - drawH) / 2;

    Shape oldClip = null;
    if (CropToSquare && !expandToFit) {
      oldClip = g.getClip();
      g.clipRect(x, y, mWidth, mHeight);
    }

    if (DEBUG.IMAGE && DEBUG.META)
      out("paintIcon; " + Util.tag(mImage) + " as " + drawW + "x" + drawH);
    g.drawImage(mImage, xoff, yoff, drawW, drawH, null);

    if (DEBUG.BOXES) {
      g.setColor(Color.green);
      ((Graphics2D) g)
          .setComposite(
              java.awt.AlphaComposite.getInstance(java.awt.AlphaComposite.SRC_OVER, 0.2f));
      g.drawRect(x, y, mWidth - 1, mHeight - 1);
      ((Graphics2D) g).setComposite(java.awt.AlphaComposite.SrcOver);
    }

    if (CropToSquare && !expandToFit) g.setClip(oldClip);
  }
Example #5
0
 public static void main(String[] args) {
   for (Field f : Fields) {
     System.out.format("%-26s %s\n", tufts.Util.tags(f.getName()), f);
   }
 }