Ejemplo n.º 1
0
        @Override
        public void run() {
          PrintDialog dialog = new PrintDialog(getViewSite().getShell(), SWT.NONE);
          PrinterData data = dialog.open();
          if (data == null) {
            return;
          }
          if (data.printToFile) {
            data.fileName =
                "print.out"; // TODO you probably want to ask the user for a filename //$NON-NLS-1$
          }

          Printer printer = new Printer(data);
          try {
            Rectangle printerBounds = printer.getClientArea();
            Rectangle trimBounds =
                printer.computeTrim(
                    printerBounds.x, printerBounds.y, printerBounds.width, printerBounds.height);
            System.out.println(printerBounds + ", " + trimBounds); // $NON-NLS-1$

            if (printer.startJob(getPartName())) {
              viewer.print(printer);
              printer.endJob();
            }
          } catch (Throwable e) {
            e.printStackTrace();
          } finally {
            printer.dispose();
          }
        }
Ejemplo n.º 2
0
  public void dispose() {
    if (shell != null) {
      shell.dispose();
      shell = null;
    }
    if (printer != null) {
      if (!printer.isDisposed()) {
        printer.endJob();
      }
      printer.dispose();
      printer = null;
    }
    jobStarted = false;

    //        if (providers != null) {
    //            for (Object o : providers.toArray()) {
    //                ((MindMapExportContentProvider) o).dispose();
    //            }
    //            providers = null;
    //        }
  }
Ejemplo n.º 3
0
  public boolean performPrint(Shell shell, Image image) {
    GC gc = null;
    boolean success = true;

    PrintDialog dialog = new PrintDialog(shell);
    PrinterData pd = dialog.open();

    if (pd != null) {
      Printer printer = new Printer(pd);

      Rectangle bounds = image.getBounds();
      Rectangle area = printer.getClientArea();
      Point dpi = printer.getDPI();
      int xScale = dpi.x / 96;
      int yScale = dpi.y / 96;
      int width = bounds.width * xScale;
      int height = bounds.height * yScale;
      int pWidth = area.width - 5 * dpi.x / 4;
      int pHeight = area.height - 5 * dpi.x / 4;
      float factor =
          Math.min(
              1.0F, Math.min((float) pWidth / (float) width, (float) pHeight / (float) height));
      int aWidth = (int) (factor * width);
      int aHeight = (int) (factor * height);
      int xoff = (area.width - aWidth) / 2;
      int yoff = (area.height - aHeight) / 2;

      String jobName = ScreenshotMessages.getString("ScreenshotPlugin.Screenshot");

      if (printer.startJob(jobName)) {
        System.out.println(" Job gestartet\n");

        if (printer.startPage()) {
          System.out.println(" Seite gestartet\n");

          System.out.println(
              image.toString()
                  + ", "
                  + bounds.x
                  + ", "
                  + bounds.y
                  + ", "
                  + bounds.width
                  + ", "
                  + bounds.height
                  + ", "
                  + xoff
                  + ", "
                  + yoff
                  + ", "
                  + aWidth
                  + ", "
                  + aHeight);

          gc = new GC(printer);

          System.out.println(gc.toString());

          gc.drawImage(
              image, bounds.x, bounds.y, bounds.width, bounds.height, xoff, yoff, aWidth, aHeight);

          printer.endPage();
        }

        printer.endJob();
      } else {
        success = false;
      }

      if (gc != null) {
        gc.dispose();
      }

      printer.dispose();
    }

    return success;
  }