Author: allain.lalonde
Date: Sat Jul 18 16:50:14 2009
New Revision: 514
Modified:
piccolo2d.java/trunk/examples/src/main/java/edu/umd/cs/piccolo/examples/PrintExample.java
Log:
Removing buried PrintException, replacing it with a
JOptionPane.showMessageDialog call
Modified:
piccolo2d.java/trunk/examples/src/main/java/edu/umd/cs/piccolo/examples/PrintExample.java
==============================================================================
---
piccolo2d.java/trunk/examples/src/main/java/edu/umd/cs/piccolo/examples/PrintExample.java
(original)
+++
piccolo2d.java/trunk/examples/src/main/java/edu/umd/cs/piccolo/examples/PrintExample.java
Sat Jul 18 16:50:14 2009
@@ -45,6 +45,7 @@
import javax.swing.ButtonGroup;
import javax.swing.JButton;
+import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JToggleButton;
import javax.swing.JToolBar;
@@ -133,7 +134,12 @@
});
print.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
- print();
+ try {
+ print();
+ }
+ catch (PrinterException e) {
+ JOptionPane.showMessageDialog(PrintExample.this, "An
error occured while printing");
+ }
}
});
JPanel contentPane = new JPanel();
@@ -258,15 +264,17 @@
/**
* Print the canvas.
+ *
+ * @throws PrinterException
*/
- private void print()
- {
+ private void print() throws PrinterException {
PrinterJob printJob = PrinterJob.getPrinterJob();
printJob.setPrintable(new Printable() {
public int print(Graphics graphics, PageFormat pageFormat, int
pageIndex) throws PrinterException {
if (pageIndex > 0) {
return (NO_SUCH_PAGE);
- } else {
+ }
+ else {
Graphics2D g2 = (Graphics2D) graphics;
g2.translate(pageFormat.getImageableX(),
pageFormat.getImageableY());
getCanvas().printAll(g2);
@@ -275,11 +283,7 @@
}
});
if (printJob.printDialog()) {
- try {
- printJob.print();
- } catch (PrinterException e) {
- e.printStackTrace();
- }
+ printJob.print();
}
}
--~--~---------~--~----~------------~-------~--~----~
Piccolo2D Developers Group: http://groups.google.com/group/piccolo2d-dev?hl=en
-~----------~----~----~----~------~----~------~--~---