Return-Path: Delivered-To: apmail-incubator-harmony-commits-archive@www.apache.org Received: (qmail 47574 invoked from network); 10 Nov 2006 17:01:08 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 10 Nov 2006 17:01:08 -0000 Received: (qmail 51024 invoked by uid 500); 10 Nov 2006 17:01:18 -0000 Delivered-To: apmail-incubator-harmony-commits-archive@incubator.apache.org Received: (qmail 50996 invoked by uid 500); 10 Nov 2006 17:01:18 -0000 Mailing-List: contact harmony-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: harmony-dev@incubator.apache.org Delivered-To: mailing list harmony-commits@incubator.apache.org Received: (qmail 50985 invoked by uid 99); 10 Nov 2006 17:01:18 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 10 Nov 2006 09:01:18 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 10 Nov 2006 09:01:02 -0800 Received: by eris.apache.org (Postfix, from userid 65534) id 1976D1A984D; Fri, 10 Nov 2006 09:00:34 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r473392 [2/3] - in /incubator/harmony/enhanced/classlib/trunk/modules: beans/src/main/java/java/beans/beancontext/ print/src/main/java/common/javax/print/attribute/ print/src/main/java/common/org/apache/harmony/x/print/ print/src/main/java/... Date: Fri, 10 Nov 2006 17:00:33 -0000 To: harmony-commits@incubator.apache.org From: ayza@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20061110170034.1976D1A984D@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Modified: incubator/harmony/enhanced/classlib/trunk/modules/print/src/main/java/common/org/apache/harmony/x/print/ServiceUIDialog.java URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/print/src/main/java/common/org/apache/harmony/x/print/ServiceUIDialog.java?view=diff&rev=473392&r1=473391&r2=473392 ============================================================================== --- incubator/harmony/enhanced/classlib/trunk/modules/print/src/main/java/common/org/apache/harmony/x/print/ServiceUIDialog.java (original) +++ incubator/harmony/enhanced/classlib/trunk/modules/print/src/main/java/common/org/apache/harmony/x/print/ServiceUIDialog.java Fri Nov 10 09:00:32 2006 @@ -14,10 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/** - * @author Irina A. Arkhipets - * @version $Revision: 1.3 $ - */ /* * ServiceUIDialog class - the class for the PrintService selecting @@ -168,1889 +164,1892 @@ public class ServiceUIDialog extends ServiceUIDialogTemplate { -// State of dialog: -public static int APPROVE_PRINT = 1; // OK button was pressed -public static int CANSEL_PRINT = -1; // Cancel button was pressed -public static int SETUP_ERROR = 2; // Dialog Setup was finished with - // error, dialog can not be shown -public static int SETUP_OK = 3; // Dialog setup was OK, - // you can show the dialog -int dialogResult = 0; // Current dialog status - -// Dialog type: -public static int PRINT_DIALOG = 1; // Dialog for PrintService selecting, - // all dialog tabs are visible -public static int PAGE_DIALOG = 2; // Page setup dialog: - // only PageSetup dialog tab is visible -private int dialogType = PRINT_DIALOG; // dialog type - -PrintService [] services = null; // Print services array for the choice - -private DocFlavor flavor = null; // DocFlavor for the dialog - -private PrintRequestAttributeSet attrs = null; - // AttributeSet for the dialog creation -private PrintRequestAttributeSet newAttrs = null; - // Result AttributeSet - -PrintService myService = null; // Last selected PrintService - -// Button groups: -ButtonGroup prnRngGrp = null; -ButtonGroup orientGrp = null; -ButtonGroup colorGrp = null; -ButtonGroup sidesGrp = null; -ButtonGroup qualGrp = null; - -// Last selected Orientation -OrientationRequested lastOrient = null; - -// True means that dialog fields were not initialized yet. -boolean firstUse = true; - -// Do we have permitions for the Destination attribute using? -private Permission destPermission = - new FilePermission("<>", "read,write"); - -//--------------------------------------------------------------------- -/* - * Constructor for the PRINT_DIALOG dialog type. - * The dialog is modal. - * It can be called from javax.print.ServiceUI.printDialog(...) and from - * printDialog(), printDialog(PrintRequestAttributeSet) methods of default - * java.awt.print.PrinterJob class implementation. - * - * Parameters: - * gc - GraphicsConfiguration to select screen. If gc is null, default screen - * is used. - * x - x location of the dialog in screen coordinates - * y - y location of the dialog in screen coordinates - * services - PrintServices array to be browsable (should be non-null) - * defPrintService - initially selected PrintService index in services array - * (should be more then 0 and less then services array - * length) - * flavor - printed DocFlavor (may be null) - * attrs - Initial print request attribute set. It can not be null, but may be - * empty. On output this attribute set reflects changes made by user. - * owner - dialog owner, should be Frame or Dialog. - * - * Throws: - * HeadlessException if current graphics environment is headless - * - * Set dialogResult to SETUP_ERROR if HeadlessException was thrown, owner is - * not Frame or Dialog object, services array is null or empty, defServiceIndex - * is incorrect or attrs is null; set dialogResult to SETUP_OK otherwise. -*/ -public ServiceUIDialog(GraphicsConfiguration gc, - int x, - int y, - PrintService[] dialogServices, - int defServiceIndex, - DocFlavor dialogFlavor, - PrintRequestAttributeSet dialogAttrs, - Window owner) -{ - if (GraphicsEnvironment.isHeadless()) { - dialogResult = SETUP_ERROR; - throw new HeadlessException(); - } - - if (owner instanceof Frame) { - printDialog = new JDialog((Frame)owner, "Print", true, gc); - } else if(owner instanceof Dialog) { - printDialog=new JDialog((Dialog)owner, "Print", true, gc); - } else { - dialogResult = SETUP_ERROR; - } - - if (printDialog != null) { - printDialog.setSize(542, 444); - printDialog.setLocation(x, y); - printDialog.setContentPane(getPanel()); - printDialog.setResizable(false); - dialogResult = setup(dialogServices, - defServiceIndex, - dialogFlavor, - dialogAttrs); - } -} - -/* - * Constructor for the PAGE_DIALOG dialog type. - * The dialog is modal. - * It can be called from pageDialog(), pageDialog(PageFormat) methods of - * default java.awt.print.PrinterJob class implementation. - * - * Parameters: - * gc - GraphicsConfiguration to select screen. If gc is null, default screen - * is used. - * x - x location of the dialog in screen coordinates - * y - y location of the dialog in screen coordinates - * aService - print service for this page dialog - * attrs - initial print request attribute set. It can not be null, but may be - * empty. On output this attribute set reflects changes made by user. - * Attributes not related with page foemat settings are ignored. - * owner - dialog owner, should be Frame or Dialog. - * - * Throws: - * HeadlessException if current graphics environment is headless - * - * Set dialogResult to SETUP_ERROR if HeadlessException was thrown, owner is - * not Frame or Dialog object, aService or attrs is null. -*/ -public ServiceUIDialog(GraphicsConfiguration gc, - int x, - int y, - PrintService aService, - PrintRequestAttributeSet dialogAttrs, - Window owner) { - - dialogType = PAGE_DIALOG; - - if (GraphicsEnvironment.isHeadless()) { - dialogResult = SETUP_ERROR; - throw new HeadlessException(); + // State of dialog: + public static int APPROVE_PRINT = 1; // OK button was pressed + public static int CANSEL_PRINT = -1; // Cancel button was pressed + public static int SETUP_ERROR = 2; // Dialog Setup was finished with + // error, dialog can not be shown + public static int SETUP_OK = 3; // Dialog setup was OK, + // you can show the dialog + int dialogResult = 0; // Current dialog status + + // Dialog type: + public static int PRINT_DIALOG = 1; // Dialog for PrintService selecting, + // all dialog tabs are visible + public static int PAGE_DIALOG = 2; // Page setup dialog: + // only PageSetup dialog tab is visible + private int dialogType = PRINT_DIALOG; // dialog type + + PrintService [] services = null; // Print services array for the choice + + private DocFlavor flavor = null; // DocFlavor for the dialog + + private PrintRequestAttributeSet attrs = null; + // AttributeSet for the dialog creation + private PrintRequestAttributeSet newAttrs = null; + // Result AttributeSet + + PrintService myService = null; // Last selected PrintService + + // Button groups: + ButtonGroup prnRngGrp = null; + ButtonGroup orientGrp = null; + ButtonGroup colorGrp = null; + ButtonGroup sidesGrp = null; + ButtonGroup qualGrp = null; + + // Last selected Orientation + OrientationRequested lastOrient = null; + + // True means that dialog fields were not initialized yet. + boolean firstUse = true; + + // Do we have permitions for the Destination attribute using? + private Permission destPermission = + new FilePermission("<>", "read,write"); + + //--------------------------------------------------------------------- + /* + * Constructor for the PRINT_DIALOG dialog type. + * The dialog is modal. + * It can be called from javax.print.ServiceUI.printDialog(...) and from + * printDialog(), printDialog(PrintRequestAttributeSet) methods of default + * java.awt.print.PrinterJob class implementation. + * + * Parameters: + * gc - GraphicsConfiguration to select screen. If gc is null, default screen + * is used. + * x - x location of the dialog in screen coordinates + * y - y location of the dialog in screen coordinates + * services - PrintServices array to be browsable (should be non-null) + * defPrintService - initially selected PrintService index in services array + * (should be more then 0 and less then services array + * length) + * flavor - printed DocFlavor (may be null) + * attrs - Initial print request attribute set. It can not be null, but may be + * empty. On output this attribute set reflects changes made by user. + * owner - dialog owner, should be Frame or Dialog. + * + * Throws: + * HeadlessException if current graphics environment is headless + * + * Set dialogResult to SETUP_ERROR if HeadlessException was thrown, owner is + * not Frame or Dialog object, services array is null or empty, defServiceIndex + * is incorrect or attrs is null; set dialogResult to SETUP_OK otherwise. + */ + public ServiceUIDialog(GraphicsConfiguration gc, + int x, + int y, + PrintService[] dialogServices, + int defServiceIndex, + DocFlavor dialogFlavor, + PrintRequestAttributeSet dialogAttrs, + Window owner) + { + if (GraphicsEnvironment.isHeadless()) { + dialogResult = SETUP_ERROR; + throw new HeadlessException(); + } + + if (owner instanceof Frame) { + printDialog = new JDialog((Frame)owner, "Print", true, gc); + } else if(owner instanceof Dialog) { + printDialog=new JDialog((Dialog)owner, "Print", true, gc); + } else { + dialogResult = SETUP_ERROR; + } + + if (printDialog != null) { + printDialog.setSize(542, 444); + printDialog.setLocation(x, y); + printDialog.setContentPane(getPanel()); + printDialog.setResizable(false); + dialogResult = setup(dialogServices, + defServiceIndex, + dialogFlavor, + dialogAttrs); + } } - - if (owner instanceof Frame) { - printDialog = new JDialog((Frame)owner, "Print", true, gc); - } else if (owner instanceof Dialog) { - printDialog=new JDialog((Dialog)owner, "Print", true, gc); - } else { - dialogResult = SETUP_ERROR; + + /* + * Constructor for the PAGE_DIALOG dialog type. + * The dialog is modal. + * It can be called from pageDialog(), pageDialog(PageFormat) methods of + * default java.awt.print.PrinterJob class implementation. + * + * Parameters: + * gc - GraphicsConfiguration to select screen. If gc is null, default screen + * is used. + * x - x location of the dialog in screen coordinates + * y - y location of the dialog in screen coordinates + * aService - print service for this page dialog + * attrs - initial print request attribute set. It can not be null, but may be + * empty. On output this attribute set reflects changes made by user. + * Attributes not related with page foemat settings are ignored. + * owner - dialog owner, should be Frame or Dialog. + * + * Throws: + * HeadlessException if current graphics environment is headless + * + * Set dialogResult to SETUP_ERROR if HeadlessException was thrown, owner is + * not Frame or Dialog object, aService or attrs is null. + */ + public ServiceUIDialog(GraphicsConfiguration gc, + int x, + int y, + PrintService aService, + PrintRequestAttributeSet dialogAttrs, + Window owner) { + + dialogType = PAGE_DIALOG; + + if (GraphicsEnvironment.isHeadless()) { + dialogResult = SETUP_ERROR; + throw new HeadlessException(); + } + + if (owner instanceof Frame) { + printDialog = new JDialog((Frame)owner, "Print", true, gc); + } else if (owner instanceof Dialog) { + printDialog=new JDialog((Dialog)owner, "Print", true, gc); + } else { + dialogResult = SETUP_ERROR; + } + + if (printDialog != null) { + printDialog.setSize(530, 400); + printDialog.setLocation(x, y); + printDialog.setContentPane(getPageDialogPanel()); + printDialog.setResizable(false); + dialogResult = pageSetup(aService, dialogAttrs); + } } - - if (printDialog != null) { - printDialog.setSize(530, 400); - printDialog.setLocation(x, y); - printDialog.setContentPane(getPageDialogPanel()); - printDialog.setResizable(false); - dialogResult = pageSetup(aService, dialogAttrs); + + // --------------------------------------------------------------------- + /* + * Shows the dialog if the dialog fields were successfully initialized before + */ + public void show() { + if (dialogResult == SETUP_OK) { + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + printDialog.show(); + return null; + } + }); + } } -} - -// --------------------------------------------------------------------- -/* - * Shows the dialog if the dialog fields were successfully initialized before -*/ -public void show() { - if (dialogResult == SETUP_OK) { - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - printDialog.show(); - return null; + + //--------------------------------------------------------------------- + /* + * Initialization for PRINT_DIALOG dialog + * + * Parameters: + * services - PrintServices array to be browsable + * defPrintService - initially selected PrintService index in services array + * flavor - printed DocFlavor (may be null) + * attrs - Initial print request attribute set. + * + * Set dialogResult to SETUP_ERROR services array is null or empty, + * defServiceIndex is incorrect or attrs is null; set dialogResult to SETUP_OK + * otherwise. + */ + private int setup(PrintService[] dialogServices, + int defServiceIndex, + DocFlavor dialogFlavor, + PrintRequestAttributeSet dialogAttrs) + { + if ((dialogServices == null) + || (dialogServices.length <= 0) + || (defServiceIndex < 0) + || (defServiceIndex >= dialogServices.length) + || (dialogAttrs == null)) { + return SETUP_ERROR; + } + + services = dialogServices; + flavor = dialogFlavor; + attrs = dialogAttrs; + this.myService = services[defServiceIndex]; + if (servicesBox.getItemCount() <= 0) { + for (int i = 0; i < services.length; i++) { + servicesBox.addItem(services[i].getName()); } - }); - } -} - -//--------------------------------------------------------------------- -/* - * Initialization for PRINT_DIALOG dialog - * - * Parameters: - * services - PrintServices array to be browsable - * defPrintService - initially selected PrintService index in services array - * flavor - printed DocFlavor (may be null) - * attrs - Initial print request attribute set. - * - * Set dialogResult to SETUP_ERROR services array is null or empty, - * defServiceIndex is incorrect or attrs is null; set dialogResult to SETUP_OK - * otherwise. -*/ -private int setup(PrintService[] dialogServices, - int defServiceIndex, - DocFlavor dialogFlavor, - PrintRequestAttributeSet dialogAttrs) -{ - if ((dialogServices == null) - || (dialogServices.length <= 0) - || (defServiceIndex < 0) - || (defServiceIndex >= dialogServices.length) - || (dialogAttrs == null)) { - return SETUP_ERROR; - } - - services = dialogServices; - flavor = dialogFlavor; - attrs = dialogAttrs; - this.myService = services[defServiceIndex]; - if (servicesBox.getItemCount() <= 0) { - for (int i = 0; i < services.length; i++) { - servicesBox.addItem(services[i].getName()); } + newAttrs = new HashPrintRequestAttributeSet(attrs); + + prepareDialog(); // Prepare dialog + servicesBox.setSelectedIndex(defServiceIndex); + // Select default PrintService and + // initialize dialog fields + firstUse = false; + return SETUP_OK; } - newAttrs = new HashPrintRequestAttributeSet(attrs); - - prepareDialog(); // Prepare dialog - servicesBox.setSelectedIndex(defServiceIndex); - // Select default PrintService and - // initialize dialog fields - firstUse = false; - return SETUP_OK; -} - -/* - * Initialization for PAGE_DIALOG dialog - * - * Parameters: - * aService - print service for this page dialog - * attrs - initial print request attribute set. - * - * Set dialogResult to SETUP_ERROR if aService or attrs is null. -*/ -private int pageSetup(PrintService aService, - PrintRequestAttributeSet requestAttrs) -{ - myService = (aService == null) - ? PrintServiceLookup.lookupDefaultPrintService() - : aService; - - if ((requestAttrs == null) || (aService == null)) { - return SETUP_ERROR; - } - - attrs = requestAttrs; - newAttrs = new HashPrintRequestAttributeSet(attrs); - myService = aService; - - prepareDialog(); // prepare dialog - fillPageSetupFields(); // Initialize dialog fields - firstUse = false; - return SETUP_OK; -} - -/* - * Dialog preparing: create button groups, add listeners to components, etc. - * This method logically should belong to the ServiceUIDialogTemplate class, - * however I place it in ServiceUIDialog because ServiceUIDialogTemplated was - * generated automatically by Eclipse Visual Editor -*/ -private void prepareDialog() { - JRadioButton [] orientArr = new JRadioButton [] { - portraitBtn, landscapeBtn, rvportraitBtn, rvlandscapeBtn }; - organizeButtonGroup(orientGrp, orientArr); - - sourceBox.setVisible(false); - sourceLabel.setVisible(false); - if (dialogType == PRINT_DIALOG) { - JRadioButton [] rangesArr = new JRadioButton[] { - allRngBtn, pageRngBtn }; - JRadioButton [] colorsArr = new JRadioButton[] { monoBtn, colorBtn }; - JRadioButton [] sidesArr = new JRadioButton[] { - oneSideBtn, tumbleBtn, duplexBtn }; - JRadioButton [] qualityArr = new JRadioButton[] { - draftBtn, normalBtn, highBtn }; - - organizeButtonGroup(prnRngGrp, rangesArr); - organizeButtonGroup(colorGrp, colorsArr); - organizeButtonGroup(sidesGrp,sidesArr); - organizeButtonGroup(qualGrp, qualityArr); + /* + * Initialization for PAGE_DIALOG dialog + * + * Parameters: + * aService - print service for this page dialog + * attrs - initial print request attribute set. + * + * Set dialogResult to SETUP_ERROR if aService or attrs is null. + */ + private int pageSetup(PrintService aService, + PrintRequestAttributeSet requestAttrs) + { + myService = (aService == null) + ? PrintServiceLookup.lookupDefaultPrintService() + : aService; - propertiesBtn.setVisible(false); - - prtSpinner.setModel(new SpinnerNumberModel(1, 1, 100, 1)); + if ((requestAttrs == null) || (aService == null)) { + return SETUP_ERROR; + } - cpSpinner.addChangeListener(new CopiesChangeListener()); - allRngBtn.addChangeListener(new PagesButtonChangeListener()); - pageRngBtn.addChangeListener(new PagesButtonChangeListener()); - servicesBox.addActionListener(new ServicesActionListener()); + attrs = requestAttrs; + newAttrs = new HashPrintRequestAttributeSet(attrs); + myService = aService; + + prepareDialog(); // prepare dialog + fillPageSetupFields(); // Initialize dialog fields + firstUse = false; + return SETUP_OK; } - - portraitBtn.addChangeListener(new OrientationChangeListener()); - landscapeBtn.addChangeListener(new OrientationChangeListener()); - rvportraitBtn.addChangeListener(new OrientationChangeListener()); - rvlandscapeBtn.addChangeListener(new OrientationChangeListener()); - printBtn.addActionListener(new OKButtonListener()); - cancelBtn.addActionListener(new cancelButtonListener()); - printDialog.addWindowListener(new WindowAdapter() { - public void windowClosing(WindowEvent event) { - dialogResult = CANSEL_PRINT; + /* + * Dialog preparing: create button groups, add listeners to components, etc. + * This method logically should belong to the ServiceUIDialogTemplate class, + * however I place it in ServiceUIDialog because ServiceUIDialogTemplated was + * generated automatically by Eclipse Visual Editor + */ + private void prepareDialog() { + JRadioButton [] orientArr = new JRadioButton [] { + portraitBtn, landscapeBtn, rvportraitBtn, rvlandscapeBtn }; + organizeButtonGroup(orientGrp, orientArr); + + sourceBox.setVisible(false); + sourceLabel.setVisible(false); + + if (dialogType == PRINT_DIALOG) { + JRadioButton [] rangesArr = new JRadioButton[] { + allRngBtn, pageRngBtn }; + JRadioButton [] colorsArr = new JRadioButton[] { monoBtn, colorBtn }; + JRadioButton [] sidesArr = new JRadioButton[] { + oneSideBtn, tumbleBtn, duplexBtn }; + JRadioButton [] qualityArr = new JRadioButton[] { + draftBtn, normalBtn, highBtn }; + + organizeButtonGroup(prnRngGrp, rangesArr); + organizeButtonGroup(colorGrp, colorsArr); + organizeButtonGroup(sidesGrp,sidesArr); + organizeButtonGroup(qualGrp, qualityArr); + + propertiesBtn.setVisible(false); + + prtSpinner.setModel(new SpinnerNumberModel(1, 1, 100, 1)); + + cpSpinner.addChangeListener(new CopiesChangeListener()); + allRngBtn.addChangeListener(new PagesButtonChangeListener()); + pageRngBtn.addChangeListener(new PagesButtonChangeListener()); + servicesBox.addActionListener(new ServicesActionListener()); } - }); -} - -/* - * Adds all JRadioButtons from "buttons" array to "group" ButtonGroup - */ -private void organizeButtonGroup(ButtonGroup group, JRadioButton[] buttons) { - group = new ButtonGroup(); - for (int i = 0; i< buttons.length; i++) { - group.add(buttons[i]); - } -} - -//--------------------------------------------------------------------- - -/* - * ActionListener for the PrintServices combo box: - * Update all dialog fields if new print service is selected. - * As the user browses print services, attributes and values are copied to new - * display. If user select a print service which does not support particular - * attribute value, default attribute for this print service is used instead. - * Unsupported attributes fields are disabled for the selected print service. -*/ -class ServicesActionListener implements ActionListener { -public void actionPerformed(ActionEvent e) { - if (firstUse - || (myService != services[servicesBox.getSelectedIndex()])) { - myService = services[servicesBox.getSelectedIndex()]; - - fillGeneralFields(); // General standard tab - fillPageSetupFields(); // Page Setup standard tab - fillAppearanceFields(); // Appearance standard tab - fillVendorSuppliedTab(); // vendor supplied tab (if exists) - } -} -} /* End of ServiceActionListener class */ - -//--------------------------------------------------------------------- -/* - *General tab fields filling after PrintService selecting -*/ -void fillGeneralFields() { - fillStatusField(); - fillTypeField(); - fillInfoField(); - filltoFileBox(); - fillCopiesFields(); - fillPrintRangeFields(); -} - -/* - * "Status" field from "General" tab: - * If selected print service does not support PrinterIsAcceptingJobs attribute, - * "Status" field is empty. Otherwise, it is "Accepting jobs" if - * PrinterIsAcceptingJob attribute for this print service is ACCEPTING_JOBS; or - * "Not accepting jobs" if PrinterIsAcceptingJobs is NOT_ACCEPTING_JOBS. -*/ -void fillStatusField() { - String text; - PrinterIsAcceptingJobs job = (PrinterIsAcceptingJobs) - myService.getAttribute(PrinterIsAcceptingJobs.class); - if (job != null) { - text = job.equals(PrinterIsAcceptingJobs.ACCEPTING_JOBS) - ? "Accepting jobs" - : "Not accepting jobs"; - } else { - text = ""; + + portraitBtn.addChangeListener(new OrientationChangeListener()); + landscapeBtn.addChangeListener(new OrientationChangeListener()); + rvportraitBtn.addChangeListener(new OrientationChangeListener()); + rvlandscapeBtn.addChangeListener(new OrientationChangeListener()); + printBtn.addActionListener(new OKButtonListener()); + cancelBtn.addActionListener(new cancelButtonListener()); + + printDialog.addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent event) { + dialogResult = CANSEL_PRINT; + } + }); } - - statusText.setText(text); -} - -/* - * "Type" field from "General" tab: - * This field contains PrinterMakeAndModel attribute of selected print service - * or is empty if service does not support PrinterMakeAndModel. -*/ -void fillTypeField() { - PrinterMakeAndModel type = (PrinterMakeAndModel) - myService.getAttribute(PrinterMakeAndModel.class); - typeText.setText(type == null ? "" : type.getValue()); -} - -/* - * "Info" field from "General" tab: - * This field contains PrinterInfo attribute of selected print service - * or is empty if service does not support PrinterInfo. -*/ -void fillInfoField() { - PrinterInfo info = (PrinterInfo) myService.getAttribute(PrinterInfo.class); - infoText.setText(info == null ? "" : info.getValue()); -} - -/* - * "Print to file" combobox from "General" tab: - * This combobox will be enabled if Destination attribute is supported by - * selected print service and user can write to file. -*/ -void filltoFileBox() { - if (firstUse && attrs.containsKey(Destination.class)) { - toFileBox.setSelected(true); - } - toFileBox.setEnabled(checkFilePermission(destPermission) - && myService.isAttributeCategorySupported(Destination.class)); -} - -/* - * Checks if the user has given permission - */ -boolean checkFilePermission(Permission permission) { - SecurityManager manager = System.getSecurityManager(); - if (manager != null) { - try { - manager.checkPermission(permission); - return true; - } - catch(SecurityException e) { - return false; + + /* + * Adds all JRadioButtons from "buttons" array to "group" ButtonGroup + */ + private void organizeButtonGroup(ButtonGroup group, JRadioButton[] buttons) { + group = new ButtonGroup(); + for (int i = 0; i< buttons.length; i++) { + group.add(buttons[i]); } } - return true; -} - -/* - * Copies and Collate fields -*/ -void fillCopiesFields() { - fillCopiesSpinner(); - fillCollateBox(); -} - -/* - * "Number of copies" spinner from "General" tab: - * It is enabled if selected printer supports Copies attribute. Maximum and - * minimum values of the spinner are minimum and maximum supported Copies - * values for selected print service. -*/ -void fillCopiesSpinner() { - boolean isEnabled = myService.isAttributeCategorySupported(Copies.class); - copiesLabel.setEnabled(isEnabled); - cpSpinner.setEnabled(isEnabled); - - if (firstUse && !isEnabled) { - int value = (attrs.containsKey(Copies.class) - ? ((Copies)(attrs.get(Copies.class))).getValue() : 1); - cpSpinner.setModel(new SpinnerNumberModel(value, value, value, 1)); + //--------------------------------------------------------------------- + + /* + * ActionListener for the PrintServices combo box: + * Update all dialog fields if new print service is selected. + * As the user browses print services, attributes and values are copied to new + * display. If user select a print service which does not support particular + * attribute value, default attribute for this print service is used instead. + * Unsupported attributes fields are disabled for the selected print service. + */ + class ServicesActionListener implements ActionListener { + public void actionPerformed(ActionEvent e) { + if (firstUse + || (myService != services[servicesBox.getSelectedIndex()])) { + myService = services[servicesBox.getSelectedIndex()]; + + fillGeneralFields(); // General standard tab + fillPageSetupFields(); // Page Setup standard tab + fillAppearanceFields(); // Appearance standard tab + fillVendorSuppliedTab(); // vendor supplied tab (if exists) + } + } + } /* End of ServiceActionListener class */ + + //--------------------------------------------------------------------- + /* + *General tab fields filling after PrintService selecting + */ + void fillGeneralFields() { + fillStatusField(); + fillTypeField(); + fillInfoField(); + filltoFileBox(); + fillCopiesFields(); + fillPrintRangeFields(); } - - if (isEnabled) { - int value = (firstUse && attrs.containsKey(Copies.class) - ? ((Copies) (attrs.get(Copies.class))).getValue() - : ((Integer) cpSpinner.getValue()).intValue()); - CopiesSupported supported = (CopiesSupported) myService - .getSupportedAttributeValues(Copies.class, flavor, attrs); - Copies defaul = (Copies) - myService.getDefaultAttributeValue(Copies.class); - - if(supported == null) { - /* - * It is incorrect situation, however it is possible: Copies - * category is supported, but there are no supported values. I - * suppose that only default Copies value is supported in this - * case. If default Copies value is null - I suppose that default - * and supported value is 1 Copy only. - */ - supported = new CopiesSupported( (defaul == null) - ? defaul.getValue() - : 1); - } - - int [][] range = supported.getMembers(); - - if (!supported.contains(value)) { - value = (((defaul == null) - || (!supported.contains(defaul.getValue()))) - ? range[0][0] - : defaul.getValue()); + + /* + * "Status" field from "General" tab: + * If selected print service does not support PrinterIsAcceptingJobs attribute, + * "Status" field is empty. Otherwise, it is "Accepting jobs" if + * PrinterIsAcceptingJob attribute for this print service is ACCEPTING_JOBS; or + * "Not accepting jobs" if PrinterIsAcceptingJobs is NOT_ACCEPTING_JOBS. + */ + void fillStatusField() { + String text; + PrinterIsAcceptingJobs job = (PrinterIsAcceptingJobs) + myService.getAttribute(PrinterIsAcceptingJobs.class); + if (job != null) { + text = job.equals(PrinterIsAcceptingJobs.ACCEPTING_JOBS) + ? "Accepting jobs" + : "Not accepting jobs"; + } else { + text = ""; } - - cpSpinner.setModel( - new SpinnerNumberModel(value, range[0][0], range[0][1], 1)); + + statusText.setText(text); } -} - -/* - * Change listener for "Number of copies" spinner. - * "Collate" combobox is enabled if Copies > 1 only -*/ -class CopiesChangeListener implements ChangeListener { - public void stateChanged(ChangeEvent e) { - fillCollateBox(); + + /* + * "Type" field from "General" tab: + * This field contains PrinterMakeAndModel attribute of selected print service + * or is empty if service does not support PrinterMakeAndModel. + */ + void fillTypeField() { + PrinterMakeAndModel type = (PrinterMakeAndModel) + myService.getAttribute(PrinterMakeAndModel.class); + typeText.setText(type == null ? "" : type.getValue()); } -} - -/* - * "Collate" combobox from "General" tab. - * This box will be enabled if more then one SheetCollate attribute - * is supported by selected print service and "Number of copies" value > 1 -*/ -void fillCollateBox() { - boolean isSupported = - myService.isAttributeCategorySupported(SheetCollate.class); - SheetCollate [] supported = (SheetCollate []) (myService - .getSupportedAttributeValues(SheetCollate.class, flavor, attrs)); - Attribute attr = attrs.get(SheetCollate.class); - int spinnerValue = ((Integer) cpSpinner.getValue()).intValue(); - - if ((supported == null) || !isSupported) { - if (attrs.containsKey(SheetCollate.class)) { - collateBox.setSelected(attr.equals(SheetCollate.COLLATED)); - } - } else { - boolean isValueSupported = myService.isAttributeValueSupported( - SheetCollate.COLLATED, flavor, attrs); - if (attrs.containsKey(SheetCollate.class) && isValueSupported) { - collateBox.setSelected(attr.equals(SheetCollate.COLLATED)); - } else { - Object defaul = - myService.getDefaultAttributeValue(SheetCollate.class); - collateBox.setSelected(defaul != null - ? defaul.equals(SheetCollate.COLLATED) - : true); + + /* + * "Info" field from "General" tab: + * This field contains PrinterInfo attribute of selected print service + * or is empty if service does not support PrinterInfo. + */ + void fillInfoField() { + PrinterInfo info = (PrinterInfo) myService.getAttribute(PrinterInfo.class); + infoText.setText(info == null ? "" : info.getValue()); + } + + /* + * "Print to file" combobox from "General" tab: + * This combobox will be enabled if Destination attribute is supported by + * selected print service and user can write to file. + */ + void filltoFileBox() { + if (firstUse && attrs.containsKey(Destination.class)) { + toFileBox.setSelected(true); } + toFileBox.setEnabled(checkFilePermission(destPermission) + && myService.isAttributeCategorySupported(Destination.class)); } - - collateBox.setEnabled(isSupported - && (spinnerValue > 1) - && (!(supported == null || supported.length <= 1))); -} - -/* - * "Print ranges" fields from "General" tab. - * "From" and "to" text fields are enabled only if "Pages" radiobutton is - * selected. If attr set does not contain PageRanges attribute, default value - * is always "All". -*/ -void fillPrintRangeFields() { - if (firstUse) { - if (attrs.containsKey(PageRanges.class)) { - PageRanges aRange = (PageRanges) (attrs.get(PageRanges.class)); - int [][] range = aRange.getMembers(); - fromTxt.setText(range.length > 0 - ? Integer.toString(range[0][0]) : "1"); - toTxt.setText(range.length > 0 - ? Integer.toString(range[0][1]) : "1"); - pageRngBtn.setSelected(true); - } else { - allRngBtn.setSelected(true); - fromTxt.setEnabled(false); - toTxt.setEnabled(false); - fromTxt.setText("1"); - toTxt.setText("1"); - toLabel.setEnabled(false); + + /* + * Checks if the user has given permission + */ + boolean checkFilePermission(Permission permission) { + SecurityManager manager = System.getSecurityManager(); + if (manager != null) { + try { + manager.checkPermission(permission); + return true; + } + catch(SecurityException e) { + return false; + } } + return true; } -} - -/* - * Change listener for "Print Ranges" fields: - * Range fields are enabled only if not all the pages should be printed, i.e. - * if "Pages" button is selected. - */ -class PagesButtonChangeListener implements ChangeListener { -public void stateChanged(ChangeEvent e) { - fromTxt.setEnabled(pageRngBtn.isSelected()); - toTxt.setEnabled(pageRngBtn.isSelected()); - toLabel.setEnabled(pageRngBtn.isSelected()); -} -} /* End of PagesButtonChangeListener class */ - -//--------------------------------------------------------------------- -/* - * Page Setup fields filling after PrintService selecting -*/ -void fillPageSetupFields() { - fillMediaFields(); - fillOrientationFields(); - fillMarginsFields(); -} - -/* - * "Size" and "Source" comboboxes from "Page Setup" tab. - * - * I made "Source" combobox invisible because it is unclear how to work with - * two different Media comboboxes in one dialog (please, see comments in the - * beginning of the ServiceUIDialog class for more details). - * Probably, we will need to change it in the future. - * - * "Size" combobox contains all medias supported by the selected print service. - * It is disabled if given service does not support Media attribute or - * supported media list is empty. -*/ -void fillMediaFields() { - if (myService.isAttributeCategorySupported(Media.class)) { - Media [] mediaList = (Media []) myService - .getSupportedAttributeValues(Media.class, flavor, attrs); - Media oldMedia = (sizeBox.getItemCount() <= 0) - ? null - : (Media)sizeBox.getSelectedItem(); - - sizeBox.removeAllItems(); - if ((mediaList != null) && (mediaList.length > 0)) { - for(int i = 0; i < mediaList.length; i++) { - sizeBox.addItem(mediaList[i]); - } - selectMedia(oldMedia); - } - sizeBox.setEnabled((mediaList != null) && (mediaList.length > 0)); - sizeLabel.setEnabled((mediaList != null) && (mediaList.length > 0)); - } else { - sizeBox.setEnabled(false); - sizeLabel.setEnabled(false); + + /* + * Copies and Collate fields + */ + void fillCopiesFields() { + fillCopiesSpinner(); + fillCollateBox(); } - sizeBox.updateUI(); -} - -/* - * Selects media in "Sizes" combobox. Selected media is previously - * selected Media if it is supported by current print service. - * Otherwise selected media Media from attrs (if it is supported) or default - * Media for selected service. -*/ -void selectMedia(Media oldMedia) { - if (sizeBox.getItemCount() > 0) { + + /* + * "Number of copies" spinner from "General" tab: + * It is enabled if selected printer supports Copies attribute. Maximum and + * minimum values of the spinner are minimum and maximum supported Copies + * values for selected print service. + */ + void fillCopiesSpinner() { + boolean isEnabled = myService.isAttributeCategorySupported(Copies.class); - /* if media was not set - get it from attribites */ - if ((oldMedia == null) && attrs.containsKey(Media.class)) { - oldMedia = (Media) attrs.get(Media.class); + copiesLabel.setEnabled(isEnabled); + cpSpinner.setEnabled(isEnabled); + + if (firstUse && !isEnabled) { + int value = (attrs.containsKey(Copies.class) + ? ((Copies)(attrs.get(Copies.class))).getValue() : 1); + cpSpinner.setModel(new SpinnerNumberModel(value, value, value, 1)); } - sizeBox.setSelectedItem(oldMedia); - if ((sizeBox.getSelectedIndex() < 0) - || (!sizeBox.getSelectedItem().equals(oldMedia))) { - Object media = myService.getDefaultAttributeValue(Media.class); - if (media != null) { - sizeBox.setSelectedItem(media); + if (isEnabled) { + int value = (firstUse && attrs.containsKey(Copies.class) + ? ((Copies) (attrs.get(Copies.class))).getValue() + : ((Integer) cpSpinner.getValue()).intValue()); + CopiesSupported supported = (CopiesSupported) myService + .getSupportedAttributeValues(Copies.class, flavor, attrs); + Copies defaul = (Copies) + myService.getDefaultAttributeValue(Copies.class); + + if(supported == null) { + /* + * It is incorrect situation, however it is possible: Copies + * category is supported, but there are no supported values. I + * suppose that only default Copies value is supported in this + * case. If default Copies value is null - I suppose that default + * and supported value is 1 Copy only. + */ + supported = new CopiesSupported( (defaul == null) + ? defaul.getValue() + : 1); } + + int [][] range = supported.getMembers(); + + if (!supported.contains(value)) { + value = (((defaul == null) + || (!supported.contains(defaul.getValue()))) + ? range[0][0] + : defaul.getValue()); + } + + cpSpinner.setModel( + new SpinnerNumberModel(value, range[0][0], range[0][1], 1)); + } + } + + /* + * Change listener for "Number of copies" spinner. + * "Collate" combobox is enabled if Copies > 1 only + */ + class CopiesChangeListener implements ChangeListener { + public void stateChanged(ChangeEvent e) { + fillCollateBox(); } + } + + /* + * "Collate" combobox from "General" tab. + * This box will be enabled if more then one SheetCollate attribute + * is supported by selected print service and "Number of copies" value > 1 + */ + void fillCollateBox() { + boolean isSupported = + myService.isAttributeCategorySupported(SheetCollate.class); + SheetCollate [] supported = (SheetCollate []) (myService + .getSupportedAttributeValues(SheetCollate.class, flavor, attrs)); + Attribute attr = attrs.get(SheetCollate.class); + int spinnerValue = ((Integer) cpSpinner.getValue()).intValue(); - /* select first media if there is still no selection */ - if (sizeBox.getSelectedIndex() < 0) { - sizeBox.setSelectedIndex(0); + if ((supported == null) || !isSupported) { + if (attrs.containsKey(SheetCollate.class)) { + collateBox.setSelected(attr.equals(SheetCollate.COLLATED)); + } + } else { + boolean isValueSupported = myService.isAttributeValueSupported( + SheetCollate.COLLATED, flavor, attrs); + if (attrs.containsKey(SheetCollate.class) && isValueSupported) { + collateBox.setSelected(attr.equals(SheetCollate.COLLATED)); + } else { + Object defaul = + myService.getDefaultAttributeValue(SheetCollate.class); + collateBox.setSelected(defaul != null + ? defaul.equals(SheetCollate.COLLATED) + : true); + } } + + collateBox.setEnabled(isSupported + && (spinnerValue > 1) + && (!(supported == null || supported.length <= 1))); } -} - -/* - * "Orientation" radiobuttons from "Page Setup" tab. - * All these buttons are disabled if selected print service does not support - * OrientationRequested attribute. Only supported by service orientations - * are enabled. -*/ -void fillOrientationFields() { - - OrientationRequested orient = - (OrientationRequested) attrs.get(OrientationRequested.class); - boolean isSupported = - myService.isAttributeCategorySupported(OrientationRequested.class); - - OrientationRequested [] supportedList = (isSupported - ? (OrientationRequested []) myService.getSupportedAttributeValues( - OrientationRequested.class, flavor, attrs) - : null); - - enableOrient(supportedList); - - /* Select orientation at first time (orientation from attributes set or - default orientation for this Print Service) */ - if (firstUse) { - if (orient != null) { - selectOrient(orient); - } else { - OrientationRequested defaul = (OrientationRequested) - myService.getDefaultAttributeValue(OrientationRequested.class); - selectOrient(isSupported ? defaul : null); + + /* + * "Print ranges" fields from "General" tab. + * "From" and "to" text fields are enabled only if "Pages" radiobutton is + * selected. If attr set does not contain PageRanges attribute, default value + * is always "All". + */ + void fillPrintRangeFields() { + if (firstUse) { + if (attrs.containsKey(PageRanges.class)) { + PageRanges aRange = (PageRanges) (attrs.get(PageRanges.class)); + int [][] range = aRange.getMembers(); + fromTxt.setText(range.length > 0 + ? Integer.toString(range[0][0]) : "1"); + toTxt.setText(range.length > 0 + ? Integer.toString(range[0][1]) : "1"); + pageRngBtn.setSelected(true); + } else { + allRngBtn.setSelected(true); + fromTxt.setEnabled(false); + toTxt.setEnabled(false); + fromTxt.setText("1"); + toTxt.setText("1"); + toLabel.setEnabled(false); + } } } - - /* Select orientation if previosly selected button is disabled now */ - if (supportedList != null) { - OrientationRequested oldValue = getOrient(); - if (!orientEnabled(oldValue)) { - selectOrient(orientEnabled(orient) ? orient : supportedList[0]); + + /* + * Change listener for "Print Ranges" fields: + * Range fields are enabled only if not all the pages should be printed, i.e. + * if "Pages" button is selected. + */ + class PagesButtonChangeListener implements ChangeListener { + public void stateChanged(ChangeEvent e) { + fromTxt.setEnabled(pageRngBtn.isSelected()); + toTxt.setEnabled(pageRngBtn.isSelected()); + toLabel.setEnabled(pageRngBtn.isSelected()); } + } /* End of PagesButtonChangeListener class */ + + //--------------------------------------------------------------------- + /* + * Page Setup fields filling after PrintService selecting + */ + void fillPageSetupFields() { + fillMediaFields(); + fillOrientationFields(); + fillMarginsFields(); } -} - -/* - * Select "Orientation" button corresponding to the given orientation -*/ -private void selectOrient(OrientationRequested par) { - if (par == null) { - par = OrientationRequested.PORTRAIT; - } - if (par.equals(OrientationRequested.LANDSCAPE)) { - landscapeBtn.setSelected(true); - } else if (par.equals(OrientationRequested.REVERSE_LANDSCAPE)) { - rvlandscapeBtn.setSelected(true); - } else if (par.equals(OrientationRequested.REVERSE_PORTRAIT)) { - rvportraitBtn.setSelected(true); - } else { - portraitBtn.setSelected(true); + + /* + * "Size" and "Source" comboboxes from "Page Setup" tab. + * + * I made "Source" combobox invisible because it is unclear how to work with + * two different Media comboboxes in one dialog (please, see comments in the + * beginning of the ServiceUIDialog class for more details). + * Probably, we will need to change it in the future. + * + * "Size" combobox contains all medias supported by the selected print service. + * It is disabled if given service does not support Media attribute or + * supported media list is empty. + */ + void fillMediaFields() { + if (myService.isAttributeCategorySupported(Media.class)) { + Media [] mediaList = (Media []) myService + .getSupportedAttributeValues(Media.class, flavor, attrs); + Media oldMedia = (sizeBox.getItemCount() <= 0) + ? null + : (Media)sizeBox.getSelectedItem(); + + sizeBox.removeAllItems(); + if ((mediaList != null) && (mediaList.length > 0)) { + for(int i = 0; i < mediaList.length; i++) { + sizeBox.addItem(mediaList[i]); + } + selectMedia(oldMedia); + } + sizeBox.setEnabled((mediaList != null) && (mediaList.length > 0)); + sizeLabel.setEnabled((mediaList != null) && (mediaList.length > 0)); + } else { + sizeBox.setEnabled(false); + sizeLabel.setEnabled(false); + } + sizeBox.updateUI(); } -} - -/* - enable/disable corresponding "Orientation" buttons -*/ -private void enableOrient(OrientationRequested[] list) { - portraitBtn.setEnabled(false); - landscapeBtn.setEnabled(false); - rvportraitBtn.setEnabled(false); - rvlandscapeBtn.setEnabled(false); - - if (list != null) { - for (int i = 0; i < list.length; i++) { - if (list[i].equals(OrientationRequested.LANDSCAPE)) { - landscapeBtn.setEnabled(true); - } else if (list[i].equals(OrientationRequested.PORTRAIT)) { - portraitBtn.setEnabled(true); - } else if (list[i].equals(OrientationRequested.REVERSE_LANDSCAPE)) { - rvlandscapeBtn.setEnabled(true); - } else if (list[i].equals(OrientationRequested.REVERSE_PORTRAIT)) { - rvportraitBtn.setEnabled(true); + + /* + * Selects media in "Sizes" combobox. Selected media is previously + * selected Media if it is supported by current print service. + * Otherwise selected media Media from attrs (if it is supported) or default + * Media for selected service. + */ + void selectMedia(Media oldMedia) { + if (sizeBox.getItemCount() > 0) { + + /* if media was not set - get it from attribites */ + if ((oldMedia == null) && attrs.containsKey(Media.class)) { + oldMedia = (Media) attrs.get(Media.class); + } + sizeBox.setSelectedItem(oldMedia); + + if ((sizeBox.getSelectedIndex() < 0) + || (!sizeBox.getSelectedItem().equals(oldMedia))) { + Object media = myService.getDefaultAttributeValue(Media.class); + if (media != null) { + sizeBox.setSelectedItem(media); + } + } + + /* select first media if there is still no selection */ + if (sizeBox.getSelectedIndex() < 0) { + sizeBox.setSelectedIndex(0); } } } -} - -/* - * get selected orientation -*/ -OrientationRequested getOrient() { - if (portraitBtn.isSelected()) { - return OrientationRequested.PORTRAIT; - } else if (landscapeBtn.isSelected()) { - return OrientationRequested.LANDSCAPE; - } else if (rvportraitBtn.isSelected()) { - return OrientationRequested.REVERSE_PORTRAIT; - } else if (rvlandscapeBtn.isSelected()) { - return OrientationRequested.REVERSE_LANDSCAPE; - } else { - return null; + + /* + * "Orientation" radiobuttons from "Page Setup" tab. + * All these buttons are disabled if selected print service does not support + * OrientationRequested attribute. Only supported by service orientations + * are enabled. + */ + void fillOrientationFields() { + + OrientationRequested orient = + (OrientationRequested) attrs.get(OrientationRequested.class); + boolean isSupported = + myService.isAttributeCategorySupported(OrientationRequested.class); + + OrientationRequested [] supportedList = (isSupported + ? (OrientationRequested []) myService.getSupportedAttributeValues( + OrientationRequested.class, flavor, attrs) + : null); + + enableOrient(supportedList); + + /* Select orientation at first time (orientation from attributes set or + default orientation for this Print Service) */ + if (firstUse) { + if (orient != null) { + selectOrient(orient); + } else { + OrientationRequested defaul = (OrientationRequested) + myService.getDefaultAttributeValue(OrientationRequested.class); + selectOrient(isSupported ? defaul : null); + } + } + + /* Select orientation if previosly selected button is disabled now */ + if (supportedList != null) { + OrientationRequested oldValue = getOrient(); + if (!orientEnabled(oldValue)) { + selectOrient(orientEnabled(orient) ? orient : supportedList[0]); + } + } } -} - -/* - * returns true if button for the given orientation is enabled -*/ -private boolean orientEnabled(OrientationRequested par) { - if (par == null) { - return false; - } else if (par.equals(OrientationRequested.LANDSCAPE)) { - return landscapeBtn.isEnabled(); - } else if (par.equals(OrientationRequested.PORTRAIT)) { - return portraitBtn.isEnabled(); - } else if (par.equals(OrientationRequested.REVERSE_LANDSCAPE)) { - return rvlandscapeBtn.isEnabled(); - } else if (par.equals(OrientationRequested.REVERSE_PORTRAIT)) { - return rvportraitBtn.isEnabled(); - } else { - return false; + + /* + * Select "Orientation" button corresponding to the given orientation + */ + private void selectOrient(OrientationRequested par) { + if (par == null) { + par = OrientationRequested.PORTRAIT; + } + if (par.equals(OrientationRequested.LANDSCAPE)) { + landscapeBtn.setSelected(true); + } else if (par.equals(OrientationRequested.REVERSE_LANDSCAPE)) { + rvlandscapeBtn.setSelected(true); + } else if (par.equals(OrientationRequested.REVERSE_PORTRAIT)) { + rvportraitBtn.setSelected(true); + } else { + portraitBtn.setSelected(true); + } } -} - -/* - * return true if at least one orientation button is enabled, - * i.e. at least one OrientationRequested attribute is supported. -*/ -private boolean isOrientSupported() { - return landscapeBtn.isEnabled() - || portraitBtn.isEnabled() - || rvlandscapeBtn.isEnabled() - || rvportraitBtn.isEnabled(); -} - -/* - * Change listener for "Orientation" buttons: - * "Margins" fields should be updated after the orientation is changed. -*/ -class OrientationChangeListener implements ChangeListener { - -public void stateChanged(ChangeEvent e) { - OrientationRequested now = getOrient(); - - if ((lastOrient != null) && (now != null) && (!lastOrient.equals(now))) { - /* if orientation was really changed */ + + /* + enable/disable corresponding "Orientation" buttons + */ + private void enableOrient(OrientationRequested[] list) { + portraitBtn.setEnabled(false); + landscapeBtn.setEnabled(false); + rvportraitBtn.setEnabled(false); + rvlandscapeBtn.setEnabled(false); - String txt = leftTxt.getText(); - - if ((lastOrient.equals(OrientationRequested.PORTRAIT) - && now.equals(OrientationRequested.LANDSCAPE)) - || (lastOrient.equals(OrientationRequested.LANDSCAPE) - && now.equals(OrientationRequested.REVERSE_PORTRAIT)) - || (lastOrient.equals(OrientationRequested.REVERSE_PORTRAIT) - && now.equals(OrientationRequested.REVERSE_LANDSCAPE)) - || (lastOrient.equals(OrientationRequested.REVERSE_LANDSCAPE) - && now.equals(OrientationRequested.PORTRAIT))) { - leftTxt.setText(bottomTxt.getText()); - bottomTxt.setText(rightTxt.getText()); - rightTxt.setText(topTxt.getText()); - topTxt.setText(txt); - - } else if ((lastOrient.equals(OrientationRequested.PORTRAIT) - && now.equals(OrientationRequested.REVERSE_PORTRAIT)) - || (lastOrient.equals(OrientationRequested.LANDSCAPE) - && now.equals(OrientationRequested.REVERSE_LANDSCAPE)) - || (lastOrient.equals(OrientationRequested.REVERSE_PORTRAIT) - && now.equals(OrientationRequested.PORTRAIT)) - || (lastOrient.equals(OrientationRequested.REVERSE_LANDSCAPE) - && now.equals(OrientationRequested.LANDSCAPE))) { - leftTxt.setText(rightTxt.getText()); - rightTxt.setText(txt); - txt = topTxt.getText(); - topTxt.setText(bottomTxt.getText()); - bottomTxt.setText(txt); - - } else { - leftTxt.setText(topTxt.getText()); - topTxt.setText(rightTxt.getText()); - rightTxt.setText(bottomTxt.getText()); - bottomTxt.setText(txt); + if (list != null) { + for (int i = 0; i < list.length; i++) { + if (list[i].equals(OrientationRequested.LANDSCAPE)) { + landscapeBtn.setEnabled(true); + } else if (list[i].equals(OrientationRequested.PORTRAIT)) { + portraitBtn.setEnabled(true); + } else if (list[i].equals(OrientationRequested.REVERSE_LANDSCAPE)) { + rvlandscapeBtn.setEnabled(true); + } else if (list[i].equals(OrientationRequested.REVERSE_PORTRAIT)) { + rvportraitBtn.setEnabled(true); + } + } } } - if (now != null) { - lastOrient = now; + /* + * get selected orientation + */ + OrientationRequested getOrient() { + if (portraitBtn.isSelected()) { + return OrientationRequested.PORTRAIT; + } else if (landscapeBtn.isSelected()) { + return OrientationRequested.LANDSCAPE; + } else if (rvportraitBtn.isSelected()) { + return OrientationRequested.REVERSE_PORTRAIT; + } else if (rvlandscapeBtn.isSelected()) { + return OrientationRequested.REVERSE_LANDSCAPE; + } else { + return null; + } } -} -} /* End of OrientationChangeListener class */ - -/* - * "Margins" fields from "Page Setup" tab. - * - * These fields are related with Media, MediaPrintableArea and MediaMargins - * attributes. - * These fields are enabled if selected print service supports MediaMargins - * attribute, or service supports Media + MediaPrintebleArea attributes and at - * lease one Media is supported. They are also always enabled if this is a - * PAGE_DIALOG. - * - * Meaning of this fields should be updated if Orientation is changed. - * - * When we initialize the dialog at first time, "Margins" values are - * calculated using the following algorythm: - * - * * 1. If MediaPrintableArea + Media attributes are supported, attrs set - * contains MediaPrintableArea and Media, Media attibute from attrs is - * supported by selected print service and this is MediaSizeName object - * (i.e. we can get size of this Media) and margins may be correctly - * calculated using these Media and MediaMargins attributes - we get - * margins from these Media and MediaPrintableArea. - * 2. If margins fields are not defined yet and MediaMargins is supported by - * selected service or this is a page setup dialog, we get MediaMargins from - * attribute set (if it is present) or default MediaMargins for selected - * print service (if service has default MediaMargins) - * 3. If margins fields are not defined yet, try to obtain MediaMargins from - * selected Media and default MediaPrintebleArea (if it is present) for - * selected print service. If margins can be calculated - fill "Margins" - * fields with these meanings. - * 4. If margins fields are not defined yet, we set them just to some default - * meanings (25.4 mm). - * - * Please, see also comments in the beginning of the ServiceUIDialog class. -*/ -void fillMarginsFields() { - boolean isMediaSupported = - myService.isAttributeCategorySupported(Media.class); - boolean isPaSupported = myService - .isAttributeCategorySupported(MediaPrintableArea.class); - boolean isMarginsSupported = myService - .isAttributeCategorySupported(MediaMargins.class); - - /* We enable margins fields if this is a PAGE_DIALOG or Media and - MediaPrintableArea attributes are supported or MediaMargins attribute is - supported by selected PrintService */ - boolean isMarginsEnabled = ((dialogType == PAGE_DIALOG) - || isMarginsSupported - || (isMediaSupported - && isPaSupported - && (sizeBox.getSelectedItem() != null))); - enableMargins(isMarginsEnabled); - - if (firstUse) { - /* set margins at first time */ - MediaMargins margins = null; // Margins for the dialog Margins fields - - if (isMarginsEnabled) { // Margins fields are enabled and can be edited - - Media selectedMedia = (Media) sizeBox.getSelectedItem(); - boolean isMediaSizeSelected = (selectedMedia == null) - ? false : - selectedMedia.getClass().isAssignableFrom(MediaSizeName.class); - MediaSize selectedSize = isMediaSizeSelected - ? MediaSize.getMediaSizeForName((MediaSizeName) selectedMedia) - : null; - - if (isMediaSupported - && isPaSupported - && attrs.containsKey(Media.class) - && attrs.containsKey(MediaPrintableArea.class) - && attrs.get(Media.class).equals(selectedMedia) - && isMediaSizeSelected) { - /* p.1 - see fillMarginsFields() comments above*/ - try { - MediaPrintableArea attrsPA = (MediaPrintableArea) - attrs.get(MediaPrintableArea.class); - margins = new MediaMargins(selectedSize, attrsPA); - } catch(IllegalArgumentException e) { - /* - * If we are unable to get correct margins values from the - * given MediaPrintableArea (attrsPA) and MediaSize - * (selectedSize), we just ignore this case - */ + /* + * returns true if button for the given orientation is enabled + */ + private boolean orientEnabled(OrientationRequested par) { + if (par == null) { + return false; + } else if (par.equals(OrientationRequested.LANDSCAPE)) { + return landscapeBtn.isEnabled(); + } else if (par.equals(OrientationRequested.PORTRAIT)) { + return portraitBtn.isEnabled(); + } else if (par.equals(OrientationRequested.REVERSE_LANDSCAPE)) { + return rvlandscapeBtn.isEnabled(); + } else if (par.equals(OrientationRequested.REVERSE_PORTRAIT)) { + return rvportraitBtn.isEnabled(); + } else { + return false; + } + } + + /* + * return true if at least one orientation button is enabled, + * i.e. at least one OrientationRequested attribute is supported. + */ + private boolean isOrientSupported() { + return landscapeBtn.isEnabled() + || portraitBtn.isEnabled() + || rvlandscapeBtn.isEnabled() + || rvportraitBtn.isEnabled(); + } + + /* + * Change listener for "Orientation" buttons: + * "Margins" fields should be updated after the orientation is changed. + */ + class OrientationChangeListener implements ChangeListener { + + public void stateChanged(ChangeEvent e) { + OrientationRequested now = getOrient(); + + if ((lastOrient != null) && (now != null) && (!lastOrient.equals(now))) { + /* if orientation was really changed */ + + String txt = leftTxt.getText(); + + if ((lastOrient.equals(OrientationRequested.PORTRAIT) + && now.equals(OrientationRequested.LANDSCAPE)) + || (lastOrient.equals(OrientationRequested.LANDSCAPE) + && now.equals(OrientationRequested.REVERSE_PORTRAIT)) + || (lastOrient.equals(OrientationRequested.REVERSE_PORTRAIT) + && now.equals(OrientationRequested.REVERSE_LANDSCAPE)) + || (lastOrient.equals(OrientationRequested.REVERSE_LANDSCAPE) + && now.equals(OrientationRequested.PORTRAIT))) { + leftTxt.setText(bottomTxt.getText()); + bottomTxt.setText(rightTxt.getText()); + rightTxt.setText(topTxt.getText()); + topTxt.setText(txt); + + } else if ((lastOrient.equals(OrientationRequested.PORTRAIT) + && now.equals(OrientationRequested.REVERSE_PORTRAIT)) + || (lastOrient.equals(OrientationRequested.LANDSCAPE) + && now.equals(OrientationRequested.REVERSE_LANDSCAPE)) + || (lastOrient.equals(OrientationRequested.REVERSE_PORTRAIT) + && now.equals(OrientationRequested.PORTRAIT)) + || (lastOrient.equals(OrientationRequested.REVERSE_LANDSCAPE) + && now.equals(OrientationRequested.LANDSCAPE))) { + leftTxt.setText(rightTxt.getText()); + rightTxt.setText(txt); + txt = topTxt.getText(); + topTxt.setText(bottomTxt.getText()); + bottomTxt.setText(txt); + + } else { + leftTxt.setText(topTxt.getText()); + topTxt.setText(rightTxt.getText()); + rightTxt.setText(bottomTxt.getText()); + bottomTxt.setText(txt); } } - - if ((margins == null) - && (isMarginsSupported || (dialogType == PAGE_DIALOG))) { - /* p.2 - see fillMarginsFields() comments above*/ - margins = (MediaMargins) (attrs.containsKey(MediaMargins.class) - ? attrs.get(MediaMargins.class) - : myService.getDefaultAttributeValue(MediaMargins.class)); + + if (now != null) { + lastOrient = now; } - - if ((margins == null) - && isPaSupported - && isMediaSupported - && isMediaSizeSelected) { - /* p.3 - see fillMarginsFields() comments above*/ - try { - MediaPrintableArea defaultPA = (MediaPrintableArea) - myService.getDefaultAttributeValue( - MediaPrintableArea.class); - if ((defaultPA != null) && (selectedSize != null)) { - margins = new MediaMargins(selectedSize, defaultPA); + } + } /* End of OrientationChangeListener class */ + + /* + * "Margins" fields from "Page Setup" tab. + * + * These fields are related with Media, MediaPrintableArea and MediaMargins + * attributes. + * These fields are enabled if selected print service supports MediaMargins + * attribute, or service supports Media + MediaPrintebleArea attributes and at + * lease one Media is supported. They are also always enabled if this is a + * PAGE_DIALOG. + * + * Meaning of this fields should be updated if Orientation is changed. + * + * When we initialize the dialog at first time, "Margins" values are + * calculated using the following algorythm: + * + * * 1. If MediaPrintableArea + Media attributes are supported, attrs set + * contains MediaPrintableArea and Media, Media attibute from attrs is + * supported by selected print service and this is MediaSizeName object + * (i.e. we can get size of this Media) and margins may be correctly + * calculated using these Media and MediaMargins attributes - we get + * margins from these Media and MediaPrintableArea. + * 2. If margins fields are not defined yet and MediaMargins is supported by + * selected service or this is a page setup dialog, we get MediaMargins from + * attribute set (if it is present) or default MediaMargins for selected + * print service (if service has default MediaMargins) + * 3. If margins fields are not defined yet, try to obtain MediaMargins from + * selected Media and default MediaPrintebleArea (if it is present) for + * selected print service. If margins can be calculated - fill "Margins" + * fields with these meanings. + * 4. If margins fields are not defined yet, we set them just to some default + * meanings (25.4 mm). + * + * Please, see also comments in the beginning of the ServiceUIDialog class. + */ + void fillMarginsFields() { + boolean isMediaSupported = + myService.isAttributeCategorySupported(Media.class); + boolean isPaSupported = myService + .isAttributeCategorySupported(MediaPrintableArea.class); + boolean isMarginsSupported = myService + .isAttributeCategorySupported(MediaMargins.class); + + /* We enable margins fields if this is a PAGE_DIALOG or Media and + MediaPrintableArea attributes are supported or MediaMargins attribute is + supported by selected PrintService */ + boolean isMarginsEnabled = ((dialogType == PAGE_DIALOG) + || isMarginsSupported + || (isMediaSupported + && isPaSupported + && (sizeBox.getSelectedItem() != null))); + + enableMargins(isMarginsEnabled); + + if (firstUse) { + /* set margins at first time */ + MediaMargins margins = null; // Margins for the dialog Margins fields + + if (isMarginsEnabled) { // Margins fields are enabled and can be edited + + Media selectedMedia = (Media) sizeBox.getSelectedItem(); + boolean isMediaSizeSelected = (selectedMedia == null) + ? false : + selectedMedia.getClass().isAssignableFrom(MediaSizeName.class); + MediaSize selectedSize = isMediaSizeSelected + ? MediaSize.getMediaSizeForName((MediaSizeName) selectedMedia) + : null; + + if (isMediaSupported + && isPaSupported + && attrs.containsKey(Media.class) + && attrs.containsKey(MediaPrintableArea.class) + && attrs.get(Media.class).equals(selectedMedia) + && isMediaSizeSelected) { + /* p.1 - see fillMarginsFields() comments above*/ + try { + MediaPrintableArea attrsPA = (MediaPrintableArea) + attrs.get(MediaPrintableArea.class); + margins = new MediaMargins(selectedSize, attrsPA); + } catch(IllegalArgumentException e) { + /* + * If we are unable to get correct margins values from the + * given MediaPrintableArea (attrsPA) and MediaSize + * (selectedSize), we just ignore this case + */ + } + } + + if ((margins == null) + && (isMarginsSupported || (dialogType == PAGE_DIALOG))) { + /* p.2 - see fillMarginsFields() comments above*/ + margins = (MediaMargins) (attrs.containsKey(MediaMargins.class) + ? attrs.get(MediaMargins.class) + : myService.getDefaultAttributeValue(MediaMargins.class)); + } + + if ((margins == null) + && isPaSupported + && isMediaSupported + && isMediaSizeSelected) { + /* p.3 - see fillMarginsFields() comments above*/ + try { + MediaPrintableArea defaultPA = (MediaPrintableArea) + myService.getDefaultAttributeValue( + MediaPrintableArea.class); + if ((defaultPA != null) && (selectedSize != null)) { + margins = new MediaMargins(selectedSize, defaultPA); + } + } catch (IllegalArgumentException e) { + /* + * If we are unable to get correct margins value from the + * default MediaPrintableArea (defPA) for this service and + * MediaSize (selectedSize), we just ignoew this case. + */ } - } catch (IllegalArgumentException e) { - /* - * If we are unable to get correct margins value from the - * default MediaPrintableArea (defPA) for this service and - * MediaSize (selectedSize), we just ignoew this case. - */ } + + if (margins == null) { + /* Just 25.4 mm margins! */ + margins = new MediaMargins(25.4F, 25.4F, 25.4F, 25.4F, + MediaMargins.MM); + } + + } else { + /* Margins fields are disabled, but we always set them to some + default meanings (25.4 mm) */ + margins = (attrs.containsKey(MediaMargins.class) + ? (MediaMargins) attrs.get(MediaMargins.class) + : new MediaMargins(25.4F, 25.4F, 25.4F, 25.4F, + MediaMargins.MM)); } - - if (margins == null) { - /* Just 25.4 mm margins! */ - margins = new MediaMargins(25.4F, 25.4F, 25.4F, 25.4F, - MediaMargins.MM); + setMargins(margins); + } + } + + /* + * Enable/disable all Margins fields + */ + private void enableMargins(boolean flg) { + leftLabel.setEnabled(flg); + rightLabel.setEnabled(flg); + topLabel.setEnabled(flg); + bottomLabel.setEnabled(flg); + leftTxt.setEnabled(flg); + rightTxt.setEnabled(flg); + topTxt.setEnabled(flg); + bottomTxt.setEnabled(flg); + } + + /* + * Set Margins dialog fields in accordance with the given MediaMargins object + */ + private void setMargins(MediaMargins margins) { + NumberFormatter fmt = getFloatFormatter(); + try { + leftTxt.setText(fmt.valueToString( + new Float(margins.getX1(MediaMargins.MM)))); + rightTxt.setText(fmt.valueToString( + new Float(margins.getX2(MediaMargins.MM)))); + topTxt.setText(fmt.valueToString( + new Float(margins.getY1(MediaMargins.MM)))); + bottomTxt.setText(fmt.valueToString( + new Float(margins.getY2(MediaMargins.MM)))); + } catch (ParseException e) { + /* Ignore incorrect float format */ + } + } + + //--------------------------------------------------------------------- + /* + * "Apparance" tab fields filling after new PrintService selecting + */ + void fillAppearanceFields() { + fillColorFields(); + fillQualityFields(); + fillSidesFields(); + fillJobAttributesFields(); + } + + /* + * "Color" panel radiobuttons from "Appearance" tab. + * The buttons are enabled only if selected service supports both COLOR and + * MONOCHROME Chromaticity attributes. + */ + void fillColorFields() { + boolean lastIsMonochrome = getLastColor(); + + monoBtn.setEnabled(false); + colorBtn.setEnabled(false); + + if (myService.isAttributeCategorySupported(Chromaticity.class)) { + Chromaticity [] supported = (Chromaticity []) (myService + .getSupportedAttributeValues(Chromaticity.class, flavor, attrs)); + if (supported != null) { + if (supported.length == 1) { + lastIsMonochrome = setMonochrome( + (supported[0]).equals(Chromaticity.MONOCHROME)); + } else if (supported.length > 1) { + monoBtn.setEnabled(true); + colorBtn.setEnabled(true); + } } - - } else { - /* Margins fields are disabled, but we always set them to some - default meanings (25.4 mm) */ - margins = (attrs.containsKey(MediaMargins.class) - ? (MediaMargins) attrs.get(MediaMargins.class) - : new MediaMargins(25.4F, 25.4F, 25.4F, 25.4F, - MediaMargins.MM)); } - setMargins(margins); + + if (lastIsMonochrome) { + monoBtn.setSelected(true); + } else { + colorBtn.setSelected(true); + } } -} - -/* - * Enable/disable all Margins fields - */ -private void enableMargins(boolean flg) { - leftLabel.setEnabled(flg); - rightLabel.setEnabled(flg); - topLabel.setEnabled(flg); - bottomLabel.setEnabled(flg); - leftTxt.setEnabled(flg); - rightTxt.setEnabled(flg); - topTxt.setEnabled(flg); - bottomTxt.setEnabled(flg); -} - -/* - * Set Margins dialog fields in accordance with the given MediaMargins object -*/ -private void setMargins(MediaMargins margins) { - NumberFormatter fmt = getFloatFormatter(); - try { - leftTxt.setText(fmt.valueToString( - new Float(margins.getX1(MediaMargins.MM)))); - rightTxt.setText(fmt.valueToString( - new Float(margins.getX2(MediaMargins.MM)))); - topTxt.setText(fmt.valueToString( - new Float(margins.getY1(MediaMargins.MM)))); - bottomTxt.setText(fmt.valueToString( - new Float(margins.getY2(MediaMargins.MM)))); - } catch (ParseException e) { - /* Ignore incorrect float format */ + + /* + * get last selected Chromaticity button + */ + private boolean getLastColor() { + if (firstUse) { + if (attrs.containsKey(Chromaticity.class)) { + Attribute value = attrs.get(Chromaticity.class); + return value.equals(Chromaticity.MONOCHROME); + } + + Object defaul = myService.getDefaultAttributeValue(Chromaticity.class); + return (myService.isAttributeCategorySupported(Chromaticity.class) + && (defaul != null)) + ? defaul.equals(Chromaticity.MONOCHROME) + : true; + } + + return monoBtn.isSelected(); } -} - -//--------------------------------------------------------------------- -/* - * "Apparance" tab fields filling after new PrintService selecting -*/ -void fillAppearanceFields() { - fillColorFields(); - fillQualityFields(); - fillSidesFields(); - fillJobAttributesFields(); -} - -/* - * "Color" panel radiobuttons from "Appearance" tab. - * The buttons are enabled only if selected service supports both COLOR and - * MONOCHROME Chromaticity attributes. -*/ -void fillColorFields() { - boolean lastIsMonochrome = getLastColor(); - - monoBtn.setEnabled(false); - colorBtn.setEnabled(false); - - if (myService.isAttributeCategorySupported(Chromaticity.class)) { - Chromaticity [] supported = (Chromaticity []) (myService - .getSupportedAttributeValues(Chromaticity.class, flavor, attrs)); - if (supported != null) { - if (supported.length == 1) { - lastIsMonochrome = setMonochrome( - (supported[0]).equals(Chromaticity.MONOCHROME)); - } else if (supported.length > 1) { - monoBtn.setEnabled(true); - colorBtn.setEnabled(true); + + private boolean setMonochrome(boolean flg) { + monoBtn.setEnabled(flg); + colorBtn.setEnabled(!flg); + return flg; + } + + /* + * "Quality" panel radiobuttons from "Appearance" tab + * Only supported by selected print service PrintQualities are enabled. + */ + void fillQualityFields() { + PrintQuality quality = (PrintQuality) attrs.get(PrintQuality.class); + if (firstUse) { + selectQualityButton(quality); + } + + PrintQuality [] aList = ( + myService.isAttributeCategorySupported(PrintQuality.class) + ? (PrintQuality []) myService + .getSupportedAttributeValues(PrintQuality.class, flavor, attrs) + : null); + enableQualityButtons(aList); /* enable qualities which are supported */ + + /* select quality */ + if ((aList != null) && (!qualityIsEnabled(getSelectedQuality()))) { + selectQualityButton(qualityIsEnabled(quality) + ? quality + : (PrintQuality) (myService + .getDefaultAttributeValue(PrintQuality.class))); + } + } + + /* + * select "Quality" button for the given PrintQuality attribute + */ + private void selectQualityButton(PrintQuality par) { + if (par == null) { + par = PrintQuality.NORMAL; + } + if (par.equals(PrintQuality.DRAFT)) { + draftBtn.setSelected(true); + } else if (par.equals(PrintQuality.HIGH)) { + highBtn.setSelected(true); + } else { + normalBtn.setSelected(true); + } + } + + /* + * enable "Quality" buttons for the PrintQuality attributes from the given list + */ + private void enableQualityButtons(PrintQuality [] list) { + normalBtn.setEnabled(false); + draftBtn.setEnabled(false); + highBtn.setEnabled(false); + + if (list != null) { + for (int i = 0; i < list.length; i++) { + if (list[i].equals(PrintQuality.DRAFT)) { + draftBtn.setEnabled(true); + } else if (list[i].equals(PrintQuality.NORMAL)) { + normalBtn.setEnabled(true); + } else if (list[i].equals(PrintQuality.HIGH)) { + highBtn.setEnabled(true); + } } } } - - if (lastIsMonochrome) { - monoBtn.setSelected(true); - } else { - colorBtn.setSelected(true); + + /* + * return PrintQuality attribute for the selected "Quality" button + */ + private PrintQuality getSelectedQuality() { + if (normalBtn.isSelected()) { + return PrintQuality.NORMAL; + } else if (draftBtn.isSelected()) { + return PrintQuality.DRAFT; + } else if (highBtn.isSelected()) { + return PrintQuality.HIGH; + } else { + return null; + } } -} - -/* - * get last selected Chromaticity button - */ -private boolean getLastColor() { - if (firstUse) { - if (attrs.containsKey(Chromaticity.class)) { - Attribute value = attrs.get(Chromaticity.class); - return value.equals(Chromaticity.MONOCHROME); - } - - Object defaul = myService.getDefaultAttributeValue(Chromaticity.class); - return (myService.isAttributeCategorySupported(Chromaticity.class) - && (defaul != null)) - ? defaul.equals(Chromaticity.MONOCHROME) - : true; - } - - return monoBtn.isSelected(); -} - -private boolean setMonochrome(boolean flg) { - monoBtn.setEnabled(flg); - colorBtn.setEnabled(!flg); - return flg; -} - -/* - * "Quality" panel radiobuttons from "Appearance" tab - * Only supported by selected print service PrintQualities are enabled. -*/ -void fillQualityFields() { - PrintQuality quality = (PrintQuality) attrs.get(PrintQuality.class); - if (firstUse) { - selectQualityButton(quality); + + /* + * returns true if "Quality" button for the given PrintQuality attribute + * enabled + */ + private boolean qualityIsEnabled(PrintQuality par) { + if (par == null) { + return false; + } else if (par.equals(PrintQuality.NORMAL)) { + return normalBtn.isEnabled(); + } else if (par.equals(PrintQuality.DRAFT)) { + return draftBtn.isEnabled(); + } else if (par.equals(PrintQuality.HIGH)) { + return highBtn.isEnabled(); + } else { + return false; + } } - - PrintQuality [] aList = ( - myService.isAttributeCategorySupported(PrintQuality.class) - ? (PrintQuality []) myService - .getSupportedAttributeValues(PrintQuality.class, flavor, attrs) [... 1468 lines stripped ...]