コード例 #1
0
  /** Prints the drawing. */
  public void print() {
    tool().deactivate();
    PrintJob printJob = getToolkit().getPrintJob(this, "Print Drawing", null);

    if (printJob != null) {
      Graphics pg = printJob.getGraphics();

      if (pg != null) {
        ((StandardDrawingView) view()).printAll(pg);
        pg.dispose(); // flush page
      }
      printJob.end();
    }
    tool().activate();
  }
コード例 #2
0
  public void actionPerformed(ActionEvent e) {
    String cmd = e.getActionCommand();
    if (cmd.equals("print")) {
      PrintJob pjob = getToolkit().getPrintJob(this, "RoundedRectTest", null);
      if (pjob != null) {
        Graphics pg = pjob.getGraphics();

        if (pg != null) {
          canvas.printAll(pg);
          pg.dispose(); // flush page
        }

        pjob.end();
      }
    }
  }
コード例 #3
0
 // If all is true, loop through all selections in chart, asking it to
 // grab the data and print each one.
 public void print(boolean all) {
   Toolkit tk = getToolkit();
   PrintJob pj =
       tk.getPrintJob(chart, all ? "All charts" : chart.current_tradable(), print_properties);
   if (pj != null) {
     if (all) {
       Vector selections = chart.tradable_selections().selections();
       for (int i = 0; i < selections.size(); ++i) {
         chart.request_data((String) selections.elementAt(i));
         if (chart.request_result_id() == Ok) {
           print_current_chart(pj);
         }
       }
     } else {
       print_current_chart(pj);
     }
     pj.end();
   }
 }
コード例 #4
0
 private void print_current_chart(PrintJob pj) {
   Graphics page = pj.getGraphics();
   Dimension size = graph_panel.getSize();
   Dimension pagesize = pj.getPageDimension();
   main_graph.set_symbol(chart.current_tradable().toUpperCase());
   if (size.width <= pagesize.width) {
     // Center the output on the page.
     page.translate((pagesize.width - size.width) / 2, (pagesize.height - size.height) / 2);
   } else {
     // The graph size is wider than a page, so print first
     // the left side, then the right side.  Assumption - it is
     // not larger than two pages.
     page.translate(15, (pagesize.height - size.height) / 2);
     graph_panel.printAll(page);
     page.dispose();
     page = pj.getGraphics();
     page.translate(pagesize.width - size.width - 13, (pagesize.height - size.height) / 2);
   }
   graph_panel.printAll(page);
   page.dispose();
   main_graph.set_symbol(null);
 }
コード例 #5
0
 public void actionPerformed(ActionEvent e) {
   PrintJob pjob = getToolkit().getPrintJob(textViewerFrame, "Printing Nslm", null);
   if (pjob != null) {
     Graphics pg = pjob.getGraphics();
     if (pg != null) {
       // todo: this should print from
       // the file not from the screen.
       // if (editor1!=null) {
       //    editor1.print(pg); //print crashes, must use printAll
       // }
       // if (scroller1!=null) {
       //    scroller1.printAll(pg); //is clipping on left
       // }
       if (scroller1 != null) {
         JViewport jvp = scroller1.getViewport();
         jvp.printAll(pg);
       }
       pg.dispose();
     }
     pjob.end();
   }
 }
コード例 #6
0
ファイル: HardcopyWriter.java プロジェクト: olexy/RealJava
  /** This internal method begins a new page and prints the header. */
  protected void newpage() {
    page = job.getGraphics(); // Begin the new page
    linenum = 0;
    charnum = 0; // Reset line and char number
    pagenum++; // Increment page number
    page.setFont(headerfont); // Set the header font.
    page.drawString(jobname, x0, headery); // Print job name left justified

    String s = "- " + pagenum + " -"; // Print the page number centered.
    int w = headermetrics.stringWidth(s);
    page.drawString(s, x0 + (this.width - w) / 2, headery);
    w = headermetrics.stringWidth(time); // Print date right justified
    page.drawString(time, x0 + width - w, headery);

    // Draw a line beneath the header
    int y = headery + headermetrics.getDescent() + 1;
    page.drawLine(x0, y, x0 + width, y);

    // Set the basic monospaced font for the rest of the page.
    page.setFont(font);
  }
コード例 #7
0
  // Esta metodo permite realizar el proceso
  // de imprimir los resultados del modelo Cocomo
  public void imprimir() {
    int posY = 200; // la posicion Y vertical
    int posx = 100; // la posicion X horizontal
    try {
      pagina = pj.getGraphics();
      pagina.setFont(fuente);
      pagina.setColor(Color.black);
      pagina.drawString("     DIAGNOSTICO DE LA HEPATITIS  " + "", 60, 100);
      pagina.drawString("-------------------------------" + "", 60, 200);
      pagina.drawString("ENFERMEDAD" + "", 60, 100);
      pagina.drawString("                                   " + "", 60, 100);
      pagina.drawString("Paciente que:     " + enfermedad, 60, 110);
      pagina.drawString("                                   " + "", 60, 100);
      pagina.drawString("TRATAMIENTO" + "", 60, 100);
      pagina.drawString("                                   " + "", 60, 100);
      pagina.drawString("Su tratamiento es:     " + tratamiento, 60, 110);
      pagina.drawString("-------------------------------" + "", 60, 200);

    } catch (Exception e) {
      JOptionPane.showMessageDialog(
          null, "LA IMPRESION HA SIDO CANCELADA" + e, "Informacion", JOptionPane.ERROR_MESSAGE);
      System.out.println("LA IMPRESION HA SIDO CANCELADA...");
    }
  }
コード例 #8
0
ファイル: HardcopyWriter.java プロジェクト: olexy/RealJava
  /**
   * The constructor for this class has a bunch of arguments: The frame argument is required for all
   * printing in Java. The jobname appears left justified at the top of each printed page. The font
   * size is specified in points, as on-screen font sizes are. The margins are specified in inches
   * (or fractions of inches).
   */
  public HardcopyWriter(
      Frame frame,
      String jobname,
      int fontsize,
      double leftmargin,
      double rightmargin,
      double topmargin,
      double bottommargin)
      throws HardcopyWriter.PrintCanceledException {
    // Get the PrintJob object with which we'll do all the printing.
    // The call is synchronized on the static printprops object, which
    // means that only one print dialog can be popped up at a time.
    // If the user clicks Cancel in the print dialog, throw an exception.
    Toolkit toolkit = frame.getToolkit(); // get Toolkit from Frame
    synchronized (printprops) {
      job = toolkit.getPrintJob(frame, jobname, printprops);
    }
    if (job == null) throw new PrintCanceledException("User cancelled print request");

    pagesize = job.getPageDimension(); // query the page size
    pagedpi = job.getPageResolution(); // query the page resolution

    // Bug Workaround:
    // On windows, getPageDimension() and getPageResolution don't work, so
    // we've got to fake them.
    if (System.getProperty("os.name").regionMatches(true, 0, "windows", 0, 7)) {
      // Use screen dpi, which is what the PrintJob tries to emulate, anyway
      pagedpi = toolkit.getScreenResolution();
      System.out.println(pagedpi);
      // Assume a 8.5" x 11" page size.  A4 paper users have to change this.
      pagesize = new Dimension((int) (8.5 * pagedpi), 11 * pagedpi);
      System.out.println(pagesize);
      // We also have to adjust the fontsize.  It is specified in points,
      // (1 point = 1/72 of an inch) but Windows measures it in pixels.
      fontsize = fontsize * pagedpi / 72;
      System.out.println(fontsize);
      System.out.flush();
    }

    // Compute coordinates of the upper-left corner of the page.
    // I.e. the coordinates of (leftmargin, topmargin).  Also compute
    // the width and height inside of the margins.
    x0 = (int) (leftmargin * pagedpi);
    y0 = (int) (topmargin * pagedpi);
    width = pagesize.width - (int) ((leftmargin + rightmargin) * pagedpi);
    height = pagesize.height - (int) ((topmargin + bottommargin) * pagedpi);

    // Get body font and font size
    font = new Font("Monospaced", Font.PLAIN, fontsize);
    metrics = toolkit.getFontMetrics(font);
    lineheight = metrics.getHeight();
    lineascent = metrics.getAscent();
    charwidth = metrics.charWidth('0'); // Assumes a monospaced font!

    // Now compute columns and lines will fit inside the margins
    chars_per_line = width / charwidth;
    lines_per_page = height / lineheight;

    // Get header font information
    // And compute baseline of page header: 1/8" above the top margin
    headerfont = new Font("SansSerif", Font.ITALIC, fontsize);
    headermetrics = toolkit.getFontMetrics(headerfont);
    headery = y0 - (int) (0.125 * pagedpi) - headermetrics.getHeight() + headermetrics.getAscent();

    // Compute the date/time string to display in the page header
    DateFormat df = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT);
    df.setTimeZone(TimeZone.getDefault());
    time = df.format(new Date());

    this.jobname = jobname; // save name
    this.fontsize = fontsize; // save font size
  }
コード例 #9
0
ファイル: HardcopyWriter.java プロジェクト: olexy/RealJava
 /**
  * This is the close() method that all Writer subclasses must implement. Print the pending page
  * (if any) and terminate the PrintJob.
  */
 public void close() {
   synchronized (this.lock) {
     if (page != null) page.dispose(); // Send page to the printer
     job.end(); // Terminate the job
   }
 }
コード例 #10
0
ファイル: HighResTest.java プロジェクト: FauxFaux/jdk9-jdk
  private static void init() {
    String[] instructions = {
      "To be able to run this test it is required to have a default",
      "printer configured in your user environment.",
      "If no default printer exists, then test passes.",
      " ",
      "There will be 2 print dialogs.  The first dialog should show",
      "portrait as the selected orientation.  The 2nd dialog should show",
      "landscape as the selected orientation.",
      " ",
      "Visual inspection of the printed pages is needed. A passing",
      "test will print 2 pages in portrait and 2 pages in landscape.",
      "The pages have on the center of the page the text \"Center\"",
      "2 rectangles will appear above and below it, the one below is",
      "filled."
    };
    Sysout.createDialog();
    Sysout.printInstructions(instructions);

    PrintJob job = null;
    Dimension dim = null;
    JobAttributes jobAttributes = new JobAttributes();
    PageAttributes pageAttributes = new PageAttributes();
    String center = "Center";
    Font font = new Font("SansSerif", Font.PLAIN, 200);
    FontMetrics metrics = null;
    int width = 0;
    Graphics g = null;

    jobAttributes.setDialog(DialogType.NATIVE);
    pageAttributes.setOrigin(OriginType.PRINTABLE);
    pageAttributes.setPrinterResolution(new int[] {1200, 1200, 3});
    pageAttributes.setOrientationRequested(OrientationRequestedType.PORTRAIT);
    jobAttributes.setSides(SidesType.TWO_SIDED_LONG_EDGE);

    job = f.getToolkit().getPrintJob(f, "Portrait Test", jobAttributes, pageAttributes);
    if (job != null) {
      dim = job.getPageDimension();
      for (int i = 0; i < 2; i++) {
        g = job.getGraphics();

        g.drawLine(0, 0, dim.width, 0);
        g.drawLine(dim.width, 0, dim.width, dim.height);
        g.drawLine(dim.width, dim.height, 0, dim.height);
        g.drawLine(0, dim.height, 0, 0);

        g.drawRect(dim.width / 2 - 200, dim.height / 3 - 300, 400, 600);
        g.fillRect(dim.width / 2 - 200, 2 * dim.height / 3 - 300, 400, 600);

        g.setFont(font);
        metrics = g.getFontMetrics();
        width = metrics.stringWidth(center);
        g.setColor(Color.black);
        g.drawString(center, (dim.width / 2) - (width / 2), dim.height / 2);

        g.dispose();
      }
      job.end();
      job = null;
    }

    pageAttributes.setOrientationRequested(OrientationRequestedType.LANDSCAPE);

    job = f.getToolkit().getPrintJob(f, "Landscape Test", jobAttributes, pageAttributes);
    if (job != null) {
      dim = job.getPageDimension();
      for (int i = 0; i < 2; i++) {
        g = job.getGraphics();
        g.drawLine(0, 0, dim.width, 0);
        g.drawLine(dim.width, 0, dim.width, dim.height);
        g.drawLine(dim.width, dim.height, 0, dim.height);
        g.drawLine(0, dim.height, 0, 0);

        g.drawRect(dim.width / 2 - 200, dim.height / 3 - 300, 400, 600);
        g.fillRect(dim.width / 2 - 200, 2 * dim.height / 3 - 300, 400, 600);

        g.setFont(font);
        metrics = g.getFontMetrics();
        width = metrics.stringWidth(center);
        g.setColor(Color.black);
        g.drawString(center, (dim.width / 2) - (width / 2), dim.height / 2);

        g.dispose();
      }
      job.end();
      job = null;
    }
    System.out.println("done");
  }