]> git.gag.com Git - debian/openrocket/commitdiff
DGP - Partial workaround for systems with no print services; simplification of the...
authorrodinia814 <rodinia814@180e2498-e6e9-4542-8430-84ac67f01cd8>
Thu, 10 Mar 2011 05:21:09 +0000 (05:21 +0000)
committerrodinia814 <rodinia814@180e2498-e6e9-4542-8430-84ac67f01cd8>
Thu, 10 Mar 2011 05:21:09 +0000 (05:21 +0000)
git-svn-id: https://openrocket.svn.sourceforge.net/svnroot/openrocket/trunk@118 180e2498-e6e9-4542-8430-84ac67f01cd8

src/net/sf/openrocket/gui/dialogs/PrintDialog.java
src/net/sf/openrocket/gui/dialogs/PrintPanel.java
src/net/sf/openrocket/gui/print/PrintController.java
src/net/sf/openrocket/gui/print/PrintServiceDialog.java

index f8ffed70f32366b875a78cb8451e043134400e62..cfd36be394dc5ee84f288a1e7af129d05047ee76 100644 (file)
@@ -8,15 +8,20 @@ import net.sf.openrocket.gui.print.PDFPrintStreamDoc;
 import net.sf.openrocket.gui.print.PrintServiceDialog;
 import net.sf.openrocket.gui.print.PrintUtilities;
 
-import javax.print.*;
+import javax.print.DocFlavor;
+import javax.print.DocPrintJob;
+import javax.print.PrintService;
+import javax.print.PrintServiceLookup;
 import javax.print.attribute.Attribute;
 import javax.print.attribute.AttributeSet;
 import javax.print.attribute.HashPrintRequestAttributeSet;
 import javax.print.attribute.PrintRequestAttributeSet;
 import javax.print.attribute.standard.Destination;
 import javax.print.attribute.standard.Fidelity;
-import javax.swing.*;
-import java.awt.*;
+import javax.swing.JDialog;
+import java.awt.Dialog;
+import java.awt.GraphicsEnvironment;
+import java.awt.HeadlessException;
 import java.io.ByteArrayOutputStream;
 
 /**
@@ -41,24 +46,23 @@ public class PrintDialog {
      *
      * @param orDocument the rocket container
      */
-    public PrintDialog (OpenRocketDocument orDocument) {
+    public PrintDialog(OpenRocketDocument orDocument) {
         PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);
         PrintService svc = PrintServiceLookup.lookupDefaultPrintService();
         PrintRequestAttributeSet attrs = new HashPrintRequestAttributeSet();
         attrs.add(PrintUtilities.getDefaultMedia().getMediaSizeName());
 
         final PrintPanel panel = new PrintPanel(orDocument, this);
-        PrintService ps = printDialog(null, 100, 100, services, svc, PDF, attrs, panel);
-        if (ps != null) {
-            DocPrintJob dpj = ps.createPrintJob();
-            try {
+        try {
+            PrintService ps = printDialog(100, 100, services, svc, PDF, attrs, panel);
+            if (ps != null) {
+                DocPrintJob dpj = ps.createPrintJob();
                 ByteArrayOutputStream baos = panel.generateReport();
                 dpj.print(new PDFPrintStreamDoc(baos, null), attrs);
             }
-            catch (PrintException e) {
-                e.printStackTrace();
-                //dgp
-            }
+        }
+        catch (Exception e) {
+            e.printStackTrace();
         }
     }
 
@@ -67,7 +71,7 @@ public class PrintDialog {
      *
      * @return a set of print attributes
      */
-    PrintRequestAttributeSet getAttributes () {
+    PrintRequestAttributeSet getAttributes() {
         return dialog.getAttributes();
     }
 
@@ -77,14 +81,13 @@ public class PrintDialog {
      *
      * @return the Java service ui print dialog
      */
-    JDialog getDialog () {
+    JDialog getDialog() {
         return dialog;
     }
 
     /**
      * Mimics the ServiceUI.printDialog method, but with enhancements for our own print settings tab.
      *
-     * @param gc             used to select screen. null means primary or default screen.
      * @param x              location of dialog including border in screen coordinates
      * @param y              location of dialog including border in screen coordinates
      * @param services       to be browsable, must be non-null.
@@ -93,35 +96,28 @@ public class PrintDialog {
      * @param attributes     on input is the initial application supplied preferences. This cannot be null but may be
      *                       empty. On output the attributes reflect changes made by the user.
      * @param addnl          a panel to be added, as a tab, to the internal tabbed pane of the resulting print dialog
-     *
      * @return print service selected by the user, or null if the user cancelled the dialog.
-     *
      * @throws HeadlessException        if GraphicsEnvironment.isHeadless() returns true.
      * @throws IllegalArgumentException if services is null or empty, or attributes is null, or the initial PrintService
      *                                  is not in the list of browsable services.
      */
-    private PrintService printDialog (GraphicsConfiguration gc,
-                                      int x, int y,
-                                      PrintService[] services,
-                                      PrintService defaultService,
-                                      DocFlavor flavor,
-                                      PrintRequestAttributeSet attributes,
-                                      PrintPanel addnl)
-            throws HeadlessException {
+    private PrintService printDialog(int x, int y,
+                                     PrintService[] services,
+                                     PrintService defaultService,
+                                     DocFlavor flavor,
+                                     PrintRequestAttributeSet attributes,
+                                     PrintPanel addnl)
+            throws HeadlessException, IllegalArgumentException {
         int defaultIndex = -1;
 
         if (GraphicsEnvironment.isHeadless()) {
             throw new HeadlessException();
         }
-        else if ((services == null) || (services.length == 0)) {
-            throw new IllegalArgumentException("services must be non-null " +
-                                               "and non-empty");
-        }
         else if (attributes == null) {
             throw new IllegalArgumentException("attributes must be non-null");
         }
 
-        if (defaultService != null) {
+        if (defaultService != null && services != null) {
             for (int i = 0; i < services.length; i++) {
                 if (services[i].equals(defaultService)) {
                     defaultIndex = i;
@@ -129,45 +125,21 @@ public class PrintDialog {
                 }
             }
 
+            //If the default service is not found just go with the first in the list
             if (defaultIndex < 0) {
-                throw new IllegalArgumentException("services must contain " +
-                                                   "defaultService");
+                defaultIndex = 0;
             }
         }
         else {
-            defaultIndex = 0;
-        }
-
-        Rectangle gcBounds = (gc == null) ? GraphicsEnvironment.
-                getLocalGraphicsEnvironment().getDefaultScreenDevice().
-                getDefaultConfiguration().getBounds() : gc.getBounds();
-
-        dialog = new PrintServiceDialog(gc,
-                                   x + gcBounds.x,
-                                   y + gcBounds.y,
-                                   services, defaultIndex,
-                                   flavor, attributes,
-                                   (Dialog) null);
-        Rectangle dlgBounds = dialog.getBounds();
-
-        // get union of all GC bounds
-        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
-        GraphicsDevice[] gs = ge.getScreenDevices();
-        for (GraphicsDevice g : gs) {
-            gcBounds = gcBounds.union(g.getDefaultConfiguration().getBounds());
-        }
-
-        // if portion of dialog is not within the gc boundary
-        if (!gcBounds.contains(dlgBounds)) {
-            // put in the center relative to parent frame/dialog
-            dialog.setLocationRelativeTo(null);
-        }
-        if (addnl != null && addnl.getTitle() != null) {
-            JTabbedPane tp = (JTabbedPane) getDescendantOfClass(JTabbedPane.class, dialog);
-            tp.add(addnl, addnl.getTitle(), 0);
-            tp.setSelectedIndex(0);
+            defaultIndex = -1;
         }
 
+        dialog = new PrintServiceDialog(
+                                        x,
+                                        y,
+                                        services, defaultIndex,
+                                        flavor, attributes,
+                                        (Dialog) null, addnl);
         dialog.setVisible(true);
 
         if (dialog.getStatus() == PrintServiceDialog.APPROVE) {
@@ -176,7 +148,7 @@ public class PrintDialog {
             Class fdCategory = Fidelity.class;
 
             if (attributes.containsKey(dstCategory) &&
-                !newas.containsKey(dstCategory)) {
+                    !newas.containsKey(dstCategory)) {
                 attributes.remove(dstCategory);
             }
 
@@ -196,37 +168,17 @@ public class PrintDialog {
         }
     }
 
-    private Component getDescendantOfClass (Class c, Container cont) {
-        if (c == null || cont == null) {
-            return null;
-        }
-        Component[] children = (cont instanceof JMenu)
-                               ? ((JMenu) cont).getMenuComponents()
-                               : cont.getComponents();
-        for (int i = 0, n = children.length; i < n; i++) {
-            Component comp = children[i];
-            if (c.isInstance(comp)) {
-                return comp;
-            }
-            comp = getDescendantOfClass(c, (Container) comp);
-            if (comp != null) {
-                return comp;
-            }
-        }
-        return null;
-    }
-
     /**
      * Removes any attributes from the given AttributeSet that are unsupported by the given PrintService/DocFlavor
      * combination.
      *
-     * @param ps      the print service for which unsupported attributes will be determined
-     * @param flavor  the document flavor; PDF in our case
-     * @param aset    the set of attributes requested
+     * @param ps     the print service for which unsupported attributes will be determined
+     * @param flavor the document flavor; PDF in our case
+     * @param aset   the set of attributes requested
      */
-    private static void removeUnsupportedAttributes (PrintService ps,
-                                                     DocFlavor flavor,
-                                                     AttributeSet aset) {
+    private static void removeUnsupportedAttributes(PrintService ps,
+                                                    DocFlavor flavor,
+                                                    AttributeSet aset) {
         AttributeSet asUnsupported = ps.getUnsupportedAttributes(flavor,
                                                                  aset);
 
index 73aefd42f5d114ef0939a4f84909c0eb26c4cefd..4bc748cd032886930b43f3842075436343d84452 100644 (file)
@@ -18,13 +18,23 @@ import net.sf.openrocket.startup.Application;
 
 import javax.print.attribute.PrintRequestAttributeSet;
 import javax.print.attribute.standard.MediaSizeName;
-import javax.swing.*;
+import javax.swing.JButton;
+import javax.swing.JCheckBox;
+import javax.swing.JColorChooser;
+import javax.swing.JComponent;
+import javax.swing.JDialog;
+import javax.swing.JFileChooser;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.UIManager;
 import javax.swing.event.TreeSelectionEvent;
 import javax.swing.event.TreeSelectionListener;
 import javax.swing.filechooser.FileFilter;
 import javax.swing.tree.TreeNode;
 import javax.swing.tree.TreePath;
-import java.awt.*;
+import java.awt.Color;
+import java.awt.Desktop;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.io.ByteArrayOutputStream;
@@ -165,6 +175,11 @@ public class PrintPanel extends JPanel implements TreeSelectionListener {
         return TAB_TITLE;
     }
 
+    @Override
+    public String getName() {
+        return getTitle();
+    }
+
     @Override
     public void valueChanged (final TreeSelectionEvent e) {
         final TreePath path = e.getNewLeadSelectionPath();
index 000288710099088f90bd31e1141da0f3921f021c..31c5d4d7951d9df9b6c2bae291bfaa3984db392c 100644 (file)
@@ -12,6 +12,7 @@ import com.itextpdf.text.pdf.PdfBoolean;
 import com.itextpdf.text.pdf.PdfName;
 import com.itextpdf.text.pdf.PdfWriter;
 import net.sf.openrocket.document.OpenRocketDocument;
+import net.sf.openrocket.gui.main.ExceptionHandler;
 import net.sf.openrocket.gui.print.visitor.FinSetVisitorStrategy;
 import net.sf.openrocket.gui.print.visitor.PartsDetailVisitorStrategy;
 
@@ -35,7 +36,8 @@ public class PrintController {
      * @param outputFile  the file being written to
      * @param msn         the paper size
      */
-    public void print (OpenRocketDocument doc, Iterator<PrintableContext> toBePrinted, OutputStream outputFile, MediaSizeName msn) {
+    public void print(OpenRocketDocument doc, Iterator<PrintableContext> toBePrinted, OutputStream outputFile,
+                      MediaSizeName msn) {
 
         Document idoc = new Document(convertWithDefault(msn));
         PdfWriter writer = null;
@@ -64,8 +66,8 @@ public class PrintController {
                         break;
                     case FIN_TEMPLATE:
                         final FinSetVisitorStrategy finWriter = new FinSetVisitorStrategy(idoc,
-                                                                                           writer,
-                                                                                           stages);
+                                                                                          writer,
+                                                                                          stages);
                         finWriter.writeToDocument(doc.getRocket());
                         break;
                     case PARTS_DETAIL:
@@ -86,8 +88,10 @@ public class PrintController {
             idoc.close();
         }
         catch (DocumentException e) {
+            ExceptionHandler.handleErrorCondition("Could not create document.", e);
         }
         catch (ExceptionConverter ec) {
+            ExceptionHandler.handleErrorCondition("Could not create document.", ec);
         }
         finally {
             if (outputFile != null) {
@@ -98,15 +102,19 @@ public class PrintController {
                 }
             }
         }
-
     }
 
-    private Rectangle convertWithDefault (final MediaSizeName msn) {
+    /**
+     * Convert a media size name to a rectangle that defines the bounds of the corresponding paper size.
+     *
+     * @param msn the MediaSizeName to convert
+     * @return the corresponding Rectangle
+     */
+    private Rectangle convertWithDefault(final MediaSizeName msn) {
         Rectangle result = PaperSize.convert(msn);
         if (result == null) {
             result = PaperSize.convert(PrintUtilities.getDefaultMedia().getMediaSizeName());
         }
         return result;
     }
-
 }
index 98045f88a1fdd121d56793e24df960e3a807d089..4aedabac5de668cefc99cc23521aff640a9d0eec 100644 (file)
@@ -12,14 +12,32 @@ import javax.print.ServiceUIFactory;
 import javax.print.attribute.HashPrintRequestAttributeSet;\r
 import javax.print.attribute.PrintRequestAttribute;\r
 import javax.print.attribute.PrintRequestAttributeSet;\r
-import javax.print.attribute.PrintServiceAttribute;\r
-import javax.print.attribute.standard.*;\r
-import javax.swing.*;\r
+import javax.print.attribute.standard.Destination;\r
+import javax.print.attribute.standard.Media;\r
+import javax.print.attribute.standard.MediaSizeName;\r
+import javax.print.attribute.standard.MediaTray;\r
+import javax.swing.AbstractAction;\r
+import javax.swing.ActionMap;\r
+import javax.swing.BorderFactory;\r
+import javax.swing.InputMap;\r
+import javax.swing.JButton;\r
+import javax.swing.JComboBox;\r
+import javax.swing.JDialog;\r
+import javax.swing.JLabel;\r
+import javax.swing.JPanel;\r
+import javax.swing.JTabbedPane;\r
+import javax.swing.KeyStroke;\r
 import javax.swing.border.EmptyBorder;\r
 import javax.swing.event.PopupMenuEvent;\r
 import javax.swing.event.PopupMenuListener;\r
-import java.awt.*;\r
-import java.awt.event.*;\r
+import java.awt.Container;\r
+import java.awt.Dialog;\r
+import java.awt.event.ActionEvent;\r
+import java.awt.event.ActionListener;\r
+import java.awt.event.ItemEvent;\r
+import java.awt.event.ItemListener;\r
+import java.awt.event.WindowAdapter;\r
+import java.awt.event.WindowEvent;\r
 import java.util.ArrayList;\r
 import java.util.Iterator;\r
 import java.util.Set;\r
@@ -31,7 +49,8 @@ public class PrintServiceDialog extends JDialog implements ActionListener {
     private JButton btnCancel, btnPrint;\r
     private boolean pdfFlavorSupported = true;\r
     private PrintService services[];\r
-    private int defaultServiceIndex, status;\r
+    private int defaultServiceIndex = -1;\r
+    private int status;\r
     private PrintRequestAttributeSet asOriginal;\r
     private HashPrintRequestAttributeSet asCurrent;\r
     private PrintService psCurrent;\r
@@ -53,15 +72,15 @@ public class PrintServiceDialog extends JDialog implements ActionListener {
         private ArrayList<MediaSizeName> sizes;\r
         private ArrayList sources;\r
 \r
-        private String getMediaName (String s) {\r
+        private String getMediaName(String s) {\r
             String s1 = s.replace(' ', '-');\r
             s1 = s1.replace('#', 'n');\r
             return PaperSize.toDisplayable(s1);\r
         }\r
 \r
-        public void itemStateChanged (ItemEvent itemevent) {\r
+        public void itemStateChanged(ItemEvent itemevent) {\r
             Object obj = itemevent.getSource();\r
-            if (itemevent.getStateChange() == 1) {\r
+            if (itemevent.getStateChange() == ItemEvent.SELECTED) {\r
                 if (obj == cbSize) {\r
                     int i = cbSize.getSelectedIndex();\r
                     if (i >= 0 && i < sizes.size()) {\r
@@ -91,7 +110,7 @@ public class PrintServiceDialog extends JDialog implements ActionListener {
         }\r
 \r
 \r
-        public void updateInfo () {\r
+        public void updateInfo() {\r
             boolean flag = false;\r
             cbSize.removeItemListener(this);\r
             cbSize.removeAllItems();\r
@@ -100,7 +119,7 @@ public class PrintServiceDialog extends JDialog implements ActionListener {
             cbSource.addItem(getMediaName("auto-select"));\r
             sizes.clear();\r
             sources.clear();\r
-            if (psCurrent.isAttributeCategorySupported(Media.class)) {\r
+            if (psCurrent != null && psCurrent.isAttributeCategorySupported(Media.class)) {\r
                 flag = true;\r
                 Object obj = null;\r
                 try {\r
@@ -108,7 +127,7 @@ public class PrintServiceDialog extends JDialog implements ActionListener {
                 }\r
                 catch (IllegalArgumentException iae) {\r
                     pdfFlavorSupported = false;\r
-                                             //dgp\r
+                    //dgp\r
                 }\r
                 if (obj instanceof Media[]) {\r
                     Media amedia[] = (Media[]) obj;\r
@@ -141,15 +160,16 @@ public class PrintServiceDialog extends JDialog implements ActionListener {
             cbSize.setEnabled(flag1);\r
             cbSource.setEnabled(false);\r
             lblSource.setEnabled(false);\r
-            if (flag) {\r
+            if (flag && psCurrent != null) {\r
                 Media media = (Media) asCurrent.get(Media.class);\r
                 boolean attributeValueSupported = false;\r
                 try {\r
-                    attributeValueSupported = psCurrent.isAttributeValueSupported(media, docFlavor, asCurrent);\r
+                    attributeValueSupported = media == null ? false : psCurrent.isAttributeValueSupported(media,\r
+                                                                                                          docFlavor,\r
+                                                                                                          asCurrent);\r
                 }\r
                 catch (IllegalArgumentException iae) {\r
                     pdfFlavorSupported = false;\r
-                    //dgp\r
                 }\r
                 if (media == null || !attributeValueSupported) {\r
                     media = (Media) psCurrent.getDefaultAttributeValue(Media.class);\r
@@ -187,7 +207,7 @@ public class PrintServiceDialog extends JDialog implements ActionListener {
             cbSource.addItemListener(this);\r
         }\r
 \r
-        public MediaPanel () {\r
+        public MediaPanel() {\r
             super(new MigLayout("fill, gap rel unrel"));\r
             sizes = new ArrayList<MediaSizeName>();\r
             sources = new ArrayList();\r
@@ -223,12 +243,12 @@ public class PrintServiceDialog extends JDialog implements ActionListener {
              * Returns a string value corresponding to this enumeration value.\r
              */\r
             @Override\r
-            public String toString () {\r
+            public String toString() {\r
                 return displayableName;\r
             }\r
 \r
             @Override\r
-            public int compareTo (final Object o) {\r
+            public int compareTo(final Object o) {\r
                 String name = displayableName;\r
                 if (name != null) {\r
                     return name.compareTo(o.toString());\r
@@ -237,7 +257,7 @@ public class PrintServiceDialog extends JDialog implements ActionListener {
             }\r
 \r
             @Override\r
-            public boolean equals (final Object o) {\r
+            public boolean equals(final Object o) {\r
                 if (this == o) {\r
                     return true;\r
                 }\r
@@ -251,7 +271,7 @@ public class PrintServiceDialog extends JDialog implements ActionListener {
             }\r
 \r
             @Override\r
-            public int hashCode () {\r
+            public int hashCode() {\r
                 return displayableName.hashCode();\r
             }\r
 \r
@@ -267,15 +287,15 @@ public class PrintServiceDialog extends JDialog implements ActionListener {
         private final String strTitle = "Print Service";\r
         private JButton btnProperties;\r
         private JComboBox cbName;\r
-        private JLabel lblType, lblStatus, lblInfo;\r
-        private JLabel vType, vStatus, vInfo;\r
         private ServiceUIFactory uiFactory;\r
         private boolean changedService;\r
 \r
-        public PrintServicePanel () {\r
+        public PrintServicePanel() {\r
             super(new MigLayout("fill, gap rel unrel"));\r
             changedService = false;\r
-            uiFactory = psCurrent.getServiceUIFactory();\r
+            if (psCurrent != null) {\r
+                uiFactory = psCurrent.getServiceUIFactory();\r
+            }\r
             setBorder(BorderFactory.createTitledBorder(strTitle));\r
             String as[] = new String[services.length];\r
             for (int i = 0; i < as.length; i++) {\r
@@ -283,7 +303,9 @@ public class PrintServiceDialog extends JDialog implements ActionListener {
             }\r
 \r
             cbName = new JComboBox(as);\r
-            cbName.setSelectedIndex(defaultServiceIndex);\r
+            if (defaultServiceIndex != -1 && defaultServiceIndex < services.length) {\r
+                cbName.setSelectedIndex(defaultServiceIndex);\r
+            }\r
             cbName.addItemListener(this);\r
             cbName.addPopupMenuListener(this);\r
             JLabel jlabel = new JLabel(("Name:"), 11);\r
@@ -293,24 +315,12 @@ public class PrintServiceDialog extends JDialog implements ActionListener {
             add(cbName);\r
             btnProperties = PrintServiceDialog.createButton("Properties...", this);\r
             add(btnProperties, "wrap");\r
-            lblStatus = new JLabel("Status:", 11);\r
-            add(lblStatus);\r
-            vStatus = new JLabel();\r
-            add(vStatus, "wrap");\r
-            lblType = new JLabel("Type:", 11);\r
-            vType = new JLabel();\r
-            add(lblType);\r
-            add(vType, "wrap");\r
-            lblInfo = new JLabel("Info:", 11);\r
-            vInfo = new JLabel();\r
-            add(lblInfo);\r
-            add(vInfo, "wrap");\r
-        }\r
-\r
-        public void actionPerformed (ActionEvent actionevent) {\r
+        }\r
+\r
+        public void actionPerformed(ActionEvent actionevent) {\r
             Object obj = actionevent.getSource();\r
             if (obj == btnProperties && uiFactory != null) {\r
-                JDialog jdialog = (JDialog) uiFactory.getUI(3, "javax.swing.JDialog");\r
+                JDialog jdialog = (JDialog) uiFactory.getUI(ServiceUIFactory.MAIN_UIROLE, "javax.swing.JDialog");\r
                 if (jdialog != null) {\r
                     jdialog.show();\r
                 }\r
@@ -320,96 +330,128 @@ public class PrintServiceDialog extends JDialog implements ActionListener {
             }\r
         }\r
 \r
-        public void itemStateChanged (ItemEvent itemevent) {\r
-            if (itemevent.getStateChange() == 1) {\r
+        /**\r
+         * {@inheritDoc}\r
+         *\r
+         * @param itemevent  the event that indicates what changed\r
+         */\r
+        @Override\r
+        public void itemStateChanged(ItemEvent itemevent) {\r
+            if (itemevent.getStateChange() == ItemEvent.SELECTED) {\r
                 int i = cbName.getSelectedIndex();\r
-                if (i >= 0 && i < services.length && !services[i].equals(psCurrent)) {\r
+                if (services != null && i >= 0 && i < services.length && !services[i].equals(psCurrent)) {\r
                     psCurrent = services[i];\r
                     uiFactory = psCurrent.getServiceUIFactory();\r
                     changedService = true;\r
-                    Destination destination = (Destination) asOriginal.get(\r
-                            Destination.class);\r
-                    if ((destination != null) && psCurrent.isAttributeCategorySupported(\r
-                            Destination.class)) {\r
-                        asCurrent.add(destination);\r
-                    }\r
-                    else {\r
-                        asCurrent.remove(Destination.class);\r
+                    if (asOriginal != null) {\r
+                        Destination destination = (Destination) asOriginal.get(\r
+                                Destination.class);\r
+                        if ((destination != null) && psCurrent.isAttributeCategorySupported(\r
+                                Destination.class)) {\r
+                            asCurrent.add(destination);\r
+                        }\r
+                        else {\r
+                            asCurrent.remove(Destination.class);\r
+                        }\r
                     }\r
                 }\r
             }\r
         }\r
 \r
-        public void popupMenuWillBecomeVisible (PopupMenuEvent popupmenuevent) {\r
+        /**\r
+         * {@inheritDoc}\r
+         *\r
+         * @param popupmenuevent\r
+         */\r
+        @Override\r
+        public void popupMenuWillBecomeVisible(PopupMenuEvent popupmenuevent) {\r
             changedService = false;\r
         }\r
 \r
-        public void popupMenuWillBecomeInvisible (PopupMenuEvent popupmenuevent) {\r
+        /**\r
+         * {@inheritDoc}\r
+         *\r
+         * @param popupmenuevent\r
+         */\r
+        @Override\r
+        public void popupMenuWillBecomeInvisible(PopupMenuEvent popupmenuevent) {\r
             if (changedService) {\r
                 changedService = false;\r
                 updatePanels();\r
             }\r
         }\r
 \r
-        public void popupMenuCanceled (PopupMenuEvent popupmenuevent) {\r
+        /**\r
+         * {@inheritDoc}\r
+         *\r
+         * @param popupmenuevent\r
+         */\r
+        @Override\r
+        public void popupMenuCanceled(PopupMenuEvent popupmenuevent) {\r
         }\r
 \r
-        public void updateInfo () {\r
-            PrintServiceAttribute psa = psCurrent.getAttribute(PrinterMakeAndModel.class);\r
-            if (psa != null) {\r
-                vType.setText(psa.toString());\r
-            }\r
-            psa = psCurrent.getAttribute(PrinterIsAcceptingJobs.class);\r
-            if (psa != null) {\r
-                vStatus.setText((psa.toString()));\r
-            }\r
-            psa = psCurrent.getAttribute(PrinterInfo.class);\r
-            if (psa != null) {\r
-                vInfo.setText(psa.toString());\r
-            }\r
+        /**\r
+         * Modify the enablement of the properties button.\r
+         */\r
+        public void updateInfo() {\r
             btnProperties.setEnabled(uiFactory != null);\r
         }\r
 \r
     }\r
 \r
+    /**\r
+     * The panel for general print services info.\r
+     */\r
     private class GeneralPanel extends JPanel {\r
 \r
-        public void updateInfo () {\r
-            pnlPrintService.updateInfo();\r
-            pnlMedia.updateInfo();\r
-        }\r
-\r
         private PrintServicePanel pnlPrintService;\r
         private MediaPanel pnlMedia;\r
 \r
-        public GeneralPanel () {\r
+        public GeneralPanel() {\r
             super(new MigLayout("fill, gap rel unrel"));\r
             pnlPrintService = new PrintServicePanel();\r
             add(pnlPrintService, "wrap");\r
             pnlMedia = new MediaPanel();\r
             add(pnlMedia, "wrap");\r
         }\r
-    }\r
-\r
 \r
-    public PrintServiceDialog (GraphicsConfiguration graphicsconfiguration, int i, int j, PrintService aprintservice[],\r
-                               int k, DocFlavor docflavor, PrintRequestAttributeSet printrequestattributeset,\r
-                               Dialog dialog, JPanel... additional) {\r
-        super(dialog, PRINT_BUTTON_LABEL, true, graphicsconfiguration);\r
-        initPrintDialog(i, j, aprintservice, k, docflavor, printrequestattributeset, additional);\r
+        public void updateInfo() {\r
+            pnlPrintService.updateInfo();\r
+            pnlMedia.updateInfo();\r
+        }\r
     }\r
 \r
-    void initPrintDialog (int i, int j, PrintService aprintservice[], int k, DocFlavor docflavor,\r
-                          PrintRequestAttributeSet printrequestattributeset,\r
-                          JPanel... additional) {\r
-        services = aprintservice;\r
-        defaultServiceIndex = k;\r
-        asOriginal = printrequestattributeset;\r
-        asCurrent = new HashPrintRequestAttributeSet(printrequestattributeset);\r
-        psCurrent = aprintservice[k];\r
+    /**\r
+     * Constructor.\r
+     *\r
+     * @param x the <i>x</i>-coordinate of the new location's\r
+     *          top-left corner in the parent's coordinate space\r
+     * @param y the <i>y</i>-coordinate of the new location's\r
+     *          top-left corner in the parent's coordinate space\r
+     * @param aPrintService  the array of installed print services\r
+     * @param defaultServiceIndex  the default service index (index into aPrintService)\r
+     * @param docflavor  the document flavor (i.e. PDF)\r
+     * @param attributeSet  the set of required attributes\r
+     * @param dialog  the parent\r
+     * @param additional  other panels to add in tabs\r
+     */\r
+    public PrintServiceDialog(int x, int y, PrintService[] aPrintService,\r
+                              int defaultServiceIndex, DocFlavor docflavor, PrintRequestAttributeSet attributeSet,\r
+                              Dialog dialog, JPanel... additional) {\r
+        super(dialog, PRINT_BUTTON_LABEL, true);\r
+        setLayout(new MigLayout("fill, gap rel unrel"));\r
+        services = aPrintService;\r
+        this.defaultServiceIndex = defaultServiceIndex;\r
+        asOriginal = attributeSet;\r
+        asCurrent = new HashPrintRequestAttributeSet(attributeSet);\r
+\r
+        if (services != null && defaultServiceIndex < services.length && defaultServiceIndex >= 0) {\r
+            psCurrent = services[defaultServiceIndex];\r
+        }\r
         docFlavor = docflavor;\r
         Container container = getContentPane();\r
-        container.setLayout(new BorderLayout());\r
+        container.setLayout(new MigLayout("fill, gap rel unrel"));\r
+//        container.setLayout(new BorderLayout());\r
         final JTabbedPane tpTabs = new JTabbedPane();\r
         tpTabs.setBorder(new EmptyBorder(5, 5, 5, 5));\r
 \r
@@ -418,36 +460,39 @@ public class PrintServiceDialog extends JDialog implements ActionListener {
                 tpTabs.add(anAdditional, anAdditional.getName(), 0);\r
             }\r
         }\r
-        pnlGeneral = new GeneralPanel();\r
-        tpTabs.add(GENERAL_TAB_TITLE, pnlGeneral);\r
+        if (psCurrent != null) {\r
+            pnlGeneral = new GeneralPanel();\r
+            tpTabs.add(GENERAL_TAB_TITLE, pnlGeneral);\r
+        }\r
 \r
-        container.add(tpTabs, "Center");\r
+        container.add(tpTabs, "growx");\r
         updatePanels();\r
+\r
         JPanel jpanel = new JPanel(new MigLayout());\r
         btnPrint = createExitButton(PRINT_BUTTON_LABEL, this);\r
         jpanel.add(btnPrint, "x 300");\r
         getRootPane().setDefaultButton(btnPrint);\r
-        btnPrint.setEnabled(pdfFlavorSupported);\r
+        btnPrint.setEnabled(pdfFlavorSupported && psCurrent != null);\r
 \r
         btnCancel = createExitButton(CANCEL_BUTTON_LABEL, this);\r
         handleEscKey(btnCancel);\r
         jpanel.add(btnCancel, "x 380");\r
         container.add(jpanel, "South");\r
         addWindowListener(new WindowAdapter() {\r
-            public void windowClosing (WindowEvent windowevent) {\r
+            public void windowClosing(WindowEvent windowevent) {\r
                 dispose(2);\r
             }\r
         }\r
         );\r
         setResizable(false);\r
-        setLocation(i, j);\r
+        setLocation(x, y);\r
         pack();\r
     }\r
 \r
-    private void handleEscKey (JButton jbutton) {\r
+    private void handleEscKey(JButton jbutton) {\r
         AbstractAction abstractaction = new AbstractAction() {\r
 \r
-            public void actionPerformed (ActionEvent actionevent) {\r
+            public void actionPerformed(ActionEvent actionevent) {\r
                 dispose(2);\r
             }\r
 \r
@@ -461,11 +506,11 @@ public class PrintServiceDialog extends JDialog implements ActionListener {
         }\r
     }\r
 \r
-    public int getStatus () {\r
+    public int getStatus() {\r
         return status;\r
     }\r
 \r
-    public PrintRequestAttributeSet getAttributes () {\r
+    public PrintRequestAttributeSet getAttributes() {\r
         if (status == 1) {\r
             return asCurrent;\r
         }\r
@@ -474,7 +519,7 @@ public class PrintServiceDialog extends JDialog implements ActionListener {
         }\r
     }\r
 \r
-    public PrintService getPrintService () {\r
+    public PrintService getPrintService() {\r
         if (status == 1) {\r
             return psCurrent;\r
         }\r
@@ -483,12 +528,12 @@ public class PrintServiceDialog extends JDialog implements ActionListener {
         }\r
     }\r
 \r
-    public void dispose (int i) {\r
+    public void dispose(int i) {\r
         status = i;\r
         super.dispose();\r
     }\r
 \r
-    public void actionPerformed (ActionEvent actionevent) {\r
+    public void actionPerformed(ActionEvent actionevent) {\r
         Object obj = actionevent.getSource();\r
         boolean flag = false;\r
         if (obj == btnPrint) {\r
@@ -501,11 +546,13 @@ public class PrintServiceDialog extends JDialog implements ActionListener {
     }\r
 \r
 \r
-    private void updatePanels () {\r
-        pnlGeneral.updateInfo();\r
+    private void updatePanels() {\r
+        if (pnlGeneral != null) {\r
+            pnlGeneral.updateInfo();\r
+        }\r
     }\r
 \r
-    private static char getMnemonic (String s) {\r
+    private static char getMnemonic(String s) {\r
         if (s != null && s.length() > 0) {\r
             return s.charAt(0);\r
         }\r
@@ -514,14 +561,14 @@ public class PrintServiceDialog extends JDialog implements ActionListener {
         }\r
     }\r
 \r
-    private static JButton createButton (String s, ActionListener actionlistener) {\r
+    private static JButton createButton(String s, ActionListener actionlistener) {\r
         JButton jbutton = new JButton(s);\r
         jbutton.setMnemonic(getMnemonic(s));\r
         jbutton.addActionListener(actionlistener);\r
         return jbutton;\r
     }\r
 \r
-    private static JButton createExitButton (String s, ActionListener actionlistener) {\r
+    private static JButton createExitButton(String s, ActionListener actionlistener) {\r
         JButton jbutton = new JButton(s);\r
         jbutton.addActionListener(actionlistener);\r
         jbutton.getAccessibleContext().setAccessibleDescription(s);\r
@@ -533,27 +580,27 @@ public class PrintServiceDialog extends JDialog implements ActionListener {
 \r
         private Media media;\r
 \r
-        MediaWrapper (Media theMedia) {\r
+        MediaWrapper(Media theMedia) {\r
             media = theMedia;\r
         }\r
 \r
-        Media getMedia () {\r
+        Media getMedia() {\r
             return media;\r
         }\r
 \r
-        public final Class getCategory () {\r
+        public final Class getCategory() {\r
             return this.getClass();\r
         }\r
 \r
-        public final String getName () {\r
+        public final String getName() {\r
             return "mw";\r
         }\r
 \r
-        public String toString () {\r
+        public String toString() {\r
             return media.toString();\r
         }\r
 \r
-        public int hashCode () {\r
+        public int hashCode() {\r
             return media.hashCode();\r
         }\r
 \r