< prev index next >

src/java.desktop/share/classes/sun/swing/PrintingStatus.java

Print this page




  73                 abortDialog.setTitle(
  74                     UIManager.getString("PrintingDialog.titleAbortingText"));
  75                 statusLabel.setText(
  76                     UIManager.getString("PrintingDialog.contentAbortingText"));
  77 
  78                 // cancel the PrinterJob
  79                 job.cancel();
  80             }
  81         }
  82     };
  83 
  84     private final WindowAdapter closeListener = new WindowAdapter() {
  85         public void windowClosing(WindowEvent we) {
  86             abortAction.actionPerformed(null);
  87         }
  88     };
  89 
  90     /**
  91      * Creates PrintingStatus instance
  92      *
  93      * @param parent a <code>Component</code> object to be used
  94      *               as parent component for PrintingStatus dialog
  95      * @param job    a <code>PrinterJob</code> object to be cancelled
  96      *               using this <code>PrintingStatus</code> dialog
  97      * @return a <code>PrintingStatus</code> object
  98      */
  99     public static PrintingStatus
 100             createPrintingStatus(Component parent, PrinterJob job) {
 101         return new PrintingStatus(parent, job);
 102     }
 103 
 104     protected PrintingStatus(Component parent, PrinterJob job) {
 105         this.job = job;
 106         this.parent = parent;
 107     }
 108 
 109     private void init() {
 110         // prepare the status JOptionPane
 111         String progressTitle =
 112             UIManager.getString("PrintingDialog.titleProgressText");
 113 
 114         String dialogInitialContent =
 115             UIManager.getString("PrintingDialog.contentInitialText");
 116 
 117         // this one's a MessageFormat since it must include the page


 144             JOptionPane.DEFAULT_OPTION,
 145             null, new Object[]{abortButton},
 146             abortButton);
 147         abortPane.getActionMap().put("close", abortAction);
 148 
 149         // The dialog should be centered over the viewport if the table is in one
 150         if (parent != null && parent.getParent() instanceof JViewport) {
 151             abortDialog =
 152                     abortPane.createDialog(parent.getParent(), progressTitle);
 153         } else {
 154             abortDialog = abortPane.createDialog(parent, progressTitle);
 155         }
 156         // clicking the X button should not hide the dialog
 157         abortDialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
 158         abortDialog.addWindowListener(closeListener);
 159     }
 160 
 161     /**
 162      * Shows PrintingStatus dialog.
 163      * if dialog is modal this method returns only
 164      * after <code>dispose()</code> was called otherwise returns immediately
 165      *
 166      * @param isModal <code>true</code> this dialog should be modal;
 167      *                <code>false</code> otherwise.
 168      * @see #dispose
 169      */
 170     public void showModal(final boolean isModal) {
 171         if (SwingUtilities.isEventDispatchThread()) {
 172             showModalOnEDT(isModal);
 173         } else {
 174             try {
 175                 SwingUtilities.invokeAndWait(new Runnable() {
 176                     public void run() {
 177                         showModalOnEDT(isModal);
 178                     }
 179                 });
 180             } catch(InterruptedException e) {
 181                 throw new RuntimeException(e);
 182             } catch(InvocationTargetException e) {
 183                 Throwable cause = e.getCause();
 184                 if (cause instanceof RuntimeException) {
 185                    throw (RuntimeException) cause;
 186                 } else if (cause instanceof Error) {
 187                    throw (Error) cause;


 234             abortDialog = null;
 235         }
 236     }
 237 
 238     /**
 239      * Returns whether the printng was aborted using this PrintingStatus
 240      *
 241      * @return whether the printng was aborted using this PrintingStatus
 242      */
 243     public boolean isAborted() {
 244         return isAborted.get();
 245     }
 246 
 247     /**
 248      * Returns printable which is used to track the current page being
 249      * printed in this PrintingStatus
 250      *
 251      * @param printable to be used to create notification printable
 252      * @return printable which is used to track the current page being
 253      *         printed in this PrintingStatus
 254      * @throws NullPointerException if <code>printable</code> is <code>null</code>
 255      */
 256     public Printable createNotificationPrintable(Printable printable) {
 257         return new NotificationPrintable(printable);
 258     }
 259 
 260     private class NotificationPrintable implements Printable {
 261         private final Printable printDelegatee;
 262 
 263         public NotificationPrintable(Printable delegatee) {
 264             if (delegatee == null) {
 265                 throw new NullPointerException("Printable is null");
 266             }
 267             this.printDelegatee = delegatee;
 268         }
 269 
 270         public int print(final Graphics graphics,
 271                          final PageFormat pageFormat, final int pageIndex)
 272                 throws PrinterException {
 273 
 274             final int retVal =




  73                 abortDialog.setTitle(
  74                     UIManager.getString("PrintingDialog.titleAbortingText"));
  75                 statusLabel.setText(
  76                     UIManager.getString("PrintingDialog.contentAbortingText"));
  77 
  78                 // cancel the PrinterJob
  79                 job.cancel();
  80             }
  81         }
  82     };
  83 
  84     private final WindowAdapter closeListener = new WindowAdapter() {
  85         public void windowClosing(WindowEvent we) {
  86             abortAction.actionPerformed(null);
  87         }
  88     };
  89 
  90     /**
  91      * Creates PrintingStatus instance
  92      *
  93      * @param parent a {@code Component} object to be used
  94      *               as parent component for PrintingStatus dialog
  95      * @param job    a {@code PrinterJob} object to be cancelled
  96      *               using this {@code PrintingStatus} dialog
  97      * @return a {@code PrintingStatus} object
  98      */
  99     public static PrintingStatus
 100             createPrintingStatus(Component parent, PrinterJob job) {
 101         return new PrintingStatus(parent, job);
 102     }
 103 
 104     protected PrintingStatus(Component parent, PrinterJob job) {
 105         this.job = job;
 106         this.parent = parent;
 107     }
 108 
 109     private void init() {
 110         // prepare the status JOptionPane
 111         String progressTitle =
 112             UIManager.getString("PrintingDialog.titleProgressText");
 113 
 114         String dialogInitialContent =
 115             UIManager.getString("PrintingDialog.contentInitialText");
 116 
 117         // this one's a MessageFormat since it must include the page


 144             JOptionPane.DEFAULT_OPTION,
 145             null, new Object[]{abortButton},
 146             abortButton);
 147         abortPane.getActionMap().put("close", abortAction);
 148 
 149         // The dialog should be centered over the viewport if the table is in one
 150         if (parent != null && parent.getParent() instanceof JViewport) {
 151             abortDialog =
 152                     abortPane.createDialog(parent.getParent(), progressTitle);
 153         } else {
 154             abortDialog = abortPane.createDialog(parent, progressTitle);
 155         }
 156         // clicking the X button should not hide the dialog
 157         abortDialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
 158         abortDialog.addWindowListener(closeListener);
 159     }
 160 
 161     /**
 162      * Shows PrintingStatus dialog.
 163      * if dialog is modal this method returns only
 164      * after {@code dispose()} was called otherwise returns immediately
 165      *
 166      * @param isModal {@code true} this dialog should be modal;
 167      *                {@code false} otherwise.
 168      * @see #dispose
 169      */
 170     public void showModal(final boolean isModal) {
 171         if (SwingUtilities.isEventDispatchThread()) {
 172             showModalOnEDT(isModal);
 173         } else {
 174             try {
 175                 SwingUtilities.invokeAndWait(new Runnable() {
 176                     public void run() {
 177                         showModalOnEDT(isModal);
 178                     }
 179                 });
 180             } catch(InterruptedException e) {
 181                 throw new RuntimeException(e);
 182             } catch(InvocationTargetException e) {
 183                 Throwable cause = e.getCause();
 184                 if (cause instanceof RuntimeException) {
 185                    throw (RuntimeException) cause;
 186                 } else if (cause instanceof Error) {
 187                    throw (Error) cause;


 234             abortDialog = null;
 235         }
 236     }
 237 
 238     /**
 239      * Returns whether the printng was aborted using this PrintingStatus
 240      *
 241      * @return whether the printng was aborted using this PrintingStatus
 242      */
 243     public boolean isAborted() {
 244         return isAborted.get();
 245     }
 246 
 247     /**
 248      * Returns printable which is used to track the current page being
 249      * printed in this PrintingStatus
 250      *
 251      * @param printable to be used to create notification printable
 252      * @return printable which is used to track the current page being
 253      *         printed in this PrintingStatus
 254      * @throws NullPointerException if {@code printable} is {@code null}
 255      */
 256     public Printable createNotificationPrintable(Printable printable) {
 257         return new NotificationPrintable(printable);
 258     }
 259 
 260     private class NotificationPrintable implements Printable {
 261         private final Printable printDelegatee;
 262 
 263         public NotificationPrintable(Printable delegatee) {
 264             if (delegatee == null) {
 265                 throw new NullPointerException("Printable is null");
 266             }
 267             this.printDelegatee = delegatee;
 268         }
 269 
 270         public int print(final Graphics graphics,
 271                          final PageFormat pageFormat, final int pageIndex)
 272                 throws PrinterException {
 273 
 274             final int retVal =


< prev index next >