Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4045174

RFE: provide a Java wrapper for printing on Win95

    XMLWordPrintable

Details

    • beta
    • x86
    • windows_95

    Description

      Requesting a Java wrapper for printing as get.Property()
      does not return the selected options on Win95 platform.

      Currently on Win95, we need to know which options the user has selected in
      the PrintDialog called up by Toolkit.getPrintJob. For example,
      we need to know whether the user has selected Portrait or Landscape.
      Right now he has no way of telling what was selected and therefore have no way of determining how to print to the page.

      In bugid 4036938, which was closed as not a bug, we know the PrintDialog
      on Win32 or MacOS uses the system dialogs, ie. Print Dialog is
      platform specific.

      The user know how to control this dialog with native Windows code, so
      implementing a Java wrapper would not be complicated to add to the JDK.

      Here is a code sample which does not return the Properties
      selected in the PrintDialog (get results "unk").
      The props.getProperty() returns the property
      "awt.print.orientation" on Solaris however.


      import java.awt.*;
      import java.awt.event.*;
      import java.util.*;

      public class PrintingTest extends Frame implements ActionListener {

          PrintCanvas canvas;

          public PrintingTest() {
              super("Printing Test");
              canvas = new PrintCanvas();
              add("Center", canvas);

              Button b = new Button("Print");
              b.setActionCommand("print");
              b.addActionListener(this);
              add("South", b);

              pack();
          }

          public void actionPerformed(ActionEvent e) {
              String cmd = e.getActionCommand();
              Properties props = new Properties();
              props.put("awt.print.printer", "pegah8");
              if (cmd.equals("print")) {
                  PrintJob pjob = getToolkit().getPrintJob(this,
                                     "Mei Printing Test", props);

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

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

                  }
              }
              System.out.println(props.getProperty("awt.print.orientation", "unk"));
          }

          public static void main(String args[]) {
              PrintingTest test = new PrintingTest();
              test.show();
          }
      }

      class PrintCanvas extends Canvas {

          public Dimension getPreferredSize() {
              return new Dimension(100, 100);
          }

          public void paint(Graphics g) {
              Rectangle r = getBounds();

              g.setColor(Color.yellow);
              g.fillRect(0, 0, r.width, r.height);

              g.setColor(Color.blue);
              g.drawLine(0, 0, r.width, r.height);

              g.setColor(Color.red);
              g.drawLine(0, r.height, r.width, 0);
          }
      }

      Attachments

        Issue Links

          Activity

            People

              dmendenhsunw David Mendenhall (Inactive)
              mchansunw Mei Chan (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: