2839 lines · 102.4 KB · Java
RawDownload
                updateRangeAttribute();                select = SunPageSelection.RANGE;            }             if (isAWT) {                asCurrent.add(select);            }        }         public void focusLost(FocusEvent e) {            Object source = e.getSource();             if ((source == tfRangeFrom) || (source == tfRangeTo)) {                updateRangeAttribute();            }        }         public void focusGained(FocusEvent e) {}         private void setupRangeWidgets() {            boolean rangeEnabled = (rbPages.isSelected() && prSupported);            tfRangeFrom.setEnabled(rangeEnabled);            tfRangeTo.setEnabled(rangeEnabled);            lblRangeTo.setEnabled(rangeEnabled);        }         private void updateRangeAttribute() {            String strFrom = tfRangeFrom.getText();            String strTo = tfRangeTo.getText();             int min;            int max;             try {                min = Integer.parseInt(strFrom);            } catch (NumberFormatException e) {                min = 1;            }             try {                max = Integer.parseInt(strTo);            } catch (NumberFormatException e) {                max = min;            }             if (min < 1) {                min = 1;                tfRangeFrom.setValue(new Integer(1));            }             if (max < min) {                max = min;                tfRangeTo.setValue(new Integer(min));            }             PageRanges pr = new PageRanges(min, max);            asCurrent.add(pr);        }         public void updateInfo() {            Class prCategory = PageRanges.class;            prSupported = false;             if (psCurrent.isAttributeCategorySupported(prCategory) ||                   isAWT) {                prSupported = true;            }             SunPageSelection select = SunPageSelection.ALL;            int min = 1;            int max = 1;             PageRanges pr = (PageRanges)asCurrent.get(prCategory);            if (pr != null) {                if (!pr.equals(prAll)) {                    select = SunPageSelection.RANGE;                     int[][] members = pr.getMembers();                    if ((members.length > 0) &&                        (members[0].length > 1)) {                        min = members[0][0];                        max = members[0][1];                    }                }            }             if (isAWT) {                select = (SunPageSelection)asCurrent.get(                                                SunPageSelection.class);            }             if (select == SunPageSelection.ALL) {                rbAll.setSelected(true);            } else if (select == SunPageSelection.SELECTION) {                // Comment this for now -  rbSelect is not initialized                // because Selection button is not added.                // See PrintRangePanel above.                 //rbSelect.setSelected(true);            } else { // RANGE                rbPages.setSelected(true);            }            tfRangeFrom.setValue(new Integer(min));            tfRangeTo.setValue(new Integer(max));            rbAll.setEnabled(prSupported);            rbPages.setEnabled(prSupported);            setupRangeWidgets();        }    }     private class CopiesPanel extends JPanel        implements ActionListener, ChangeListener    {        private final String strTitle = getMsg("border.copies");        private SpinnerNumberModel snModel;        private JSpinner spinCopies;        private JLabel lblCopies;        private JCheckBox cbCollate;        private boolean scSupported;         public CopiesPanel() {            super();             GridBagLayout gridbag = new GridBagLayout();            GridBagConstraints c = new GridBagConstraints();             setLayout(gridbag);            setBorder(BorderFactory.createTitledBorder(strTitle));             c.fill = GridBagConstraints.HORIZONTAL;            c.insets = compInsets;             lblCopies = new JLabel(getMsg("label.numcopies"), JLabel.TRAILING);            lblCopies.setDisplayedMnemonic(getMnemonic("label.numcopies"));            lblCopies.getAccessibleContext().setAccessibleName(                                             getMsg("label.numcopies"));            addToGB(lblCopies, this, gridbag, c);             snModel = new SpinnerNumberModel(1, 1, 999, 1);            spinCopies = new JSpinner(snModel);            lblCopies.setLabelFor(spinCopies);            // REMIND            ((JSpinner.NumberEditor)spinCopies.getEditor()).getTextField().setColumns(3);            spinCopies.addChangeListener(this);            c.gridwidth = GridBagConstraints.REMAINDER;            addToGB(spinCopies, this, gridbag, c);             cbCollate = createCheckBox("checkbox.collate", this);            cbCollate.setEnabled(false);            addToGB(cbCollate, this, gridbag, c);        }         public void actionPerformed(ActionEvent e) {            if (cbCollate.isSelected()) {                asCurrent.add(SheetCollate.COLLATED);            } else {                asCurrent.add(SheetCollate.UNCOLLATED);            }        }         public void stateChanged(ChangeEvent e) {            updateCollateCB();             asCurrent.add(new Copies(snModel.getNumber().intValue()));        }         private void updateCollateCB() {            int num = snModel.getNumber().intValue();            if (isAWT) {                cbCollate.setEnabled(true);            } else {                cbCollate.setEnabled((num > 1) && scSupported);            }        }         public void updateInfo() {            Class cpCategory = Copies.class;            Class csCategory = CopiesSupported.class;            Class scCategory = SheetCollate.class;            boolean cpSupported = false;            scSupported = false;             // setup Copies spinner            if (psCurrent.isAttributeCategorySupported(cpCategory)) {                cpSupported = true;            }            CopiesSupported cs =                (CopiesSupported)psCurrent.getSupportedAttributeValues(                                                       cpCategory, null, null);            if (cs == null) {                cs = new CopiesSupported(1, 999);            }            Copies cp = (Copies)asCurrent.get(cpCategory);            if (cp == null) {                cp = (Copies)psCurrent.getDefaultAttributeValue(cpCategory);                if (cp == null) {                    cp = new Copies(1);                }            }            spinCopies.setEnabled(cpSupported);            lblCopies.setEnabled(cpSupported);             int[][] members = cs.getMembers();            int min, max;            if ((members.length > 0) && (members[0].length > 0)) {                min = members[0][0];                max = members[0][1];            } else {                min = 1;                max = Integer.MAX_VALUE;            }            snModel.setMinimum(new Integer(min));            snModel.setMaximum(new Integer(max));             int value = cp.getValue();            if ((value < min) || (value > max)) {                value = min;            }            snModel.setValue(new Integer(value));             // setup Collate checkbox            if (psCurrent.isAttributeCategorySupported(scCategory)) {                scSupported = true;            }            SheetCollate sc = (SheetCollate)asCurrent.get(scCategory);            if (sc == null) {                sc = (SheetCollate)psCurrent.getDefaultAttributeValue(scCategory);                if (sc == null) {                    sc = SheetCollate.UNCOLLATED;                }            }            cbCollate.setSelected(sc == SheetCollate.COLLATED);            updateCollateCB();        }    }        /**     * The "Page Setup" tab.  Includes the controls for MediaSource/MediaTray,     * OrientationRequested, and Sides.     */    private class PageSetupPanel extends JPanel {         private MediaPanel pnlMedia;        private OrientationPanel pnlOrientation;        private MarginsPanel pnlMargins;         public PageSetupPanel() {            super();             GridBagLayout gridbag = new GridBagLayout();            GridBagConstraints c = new GridBagConstraints();             setLayout(gridbag);             c.fill = GridBagConstraints.BOTH;            c.insets = panelInsets;            c.weightx = 1.0;            c.weighty = 1.0;             c.gridwidth = GridBagConstraints.REMAINDER;            pnlMedia = new MediaPanel();            addToGB(pnlMedia, this, gridbag, c);             pnlOrientation = new OrientationPanel();            c.gridwidth = GridBagConstraints.RELATIVE;            addToGB(pnlOrientation, this, gridbag, c);             pnlMargins = new MarginsPanel();            pnlOrientation.addOrientationListener(pnlMargins);            pnlMedia.addMediaListener(pnlMargins);            c.gridwidth = GridBagConstraints.REMAINDER;            addToGB(pnlMargins, this, gridbag, c);        }         public void updateInfo() {            pnlMedia.updateInfo();            pnlOrientation.updateInfo();            pnlMargins.updateInfo();        }    }     private class MarginsPanel extends JPanel                               implements ActionListener, FocusListener {         private final String strTitle = getMsg("border.margins");        private JFormattedTextField leftMargin, rightMargin,                                    topMargin, bottomMargin;        private JLabel lblLeft, lblRight, lblTop, lblBottom;        private int units = MediaPrintableArea.MM;        // storage for the last margin values calculated, -ve is uninitialised        private float lmVal = -1f,rmVal = -1f, tmVal = -1f, bmVal = -1f;        // storage for margins as objects mapped into orientation for display        private Float lmObj,rmObj,tmObj,bmObj;         public MarginsPanel() {            super();             GridBagLayout gridbag = new GridBagLayout();            GridBagConstraints c = new GridBagConstraints();            c.fill = GridBagConstraints.HORIZONTAL;            c.weightx = 1.0;            c.weighty = 0.0;            c.insets = compInsets;             setLayout(gridbag);            setBorder(BorderFactory.createTitledBorder(strTitle));             String unitsKey = "label.millimetres";            String defaultCountry = Locale.getDefault().getCountry();            if (defaultCountry != null &&                (defaultCountry.equals("") ||                 defaultCountry.equals(Locale.US.getCountry()) ||                 defaultCountry.equals(Locale.CANADA.getCountry()))) {                unitsKey = "label.inches";                units = MediaPrintableArea.INCH;            }            String unitsMsg = getMsg(unitsKey);             DecimalFormat format;            if (units == MediaPrintableArea.MM) {                format = new DecimalFormat("###.##");                format.setMaximumIntegerDigits(3);            } else {                format = new DecimalFormat("##.##");                format.setMaximumIntegerDigits(2);            }             format.setMinimumFractionDigits(1);            format.setMaximumFractionDigits(2);            format.setMinimumIntegerDigits(1);            format.setParseIntegerOnly(false);            format.setDecimalSeparatorAlwaysShown(true);            NumberFormatter nf = new NumberFormatter(format);            nf.setMinimum(new Float(0.0f));            nf.setMaximum(new Float(999.0f));            nf.setAllowsInvalid(true);            nf.setCommitsOnValidEdit(true);             leftMargin = new JFormattedTextField(nf);            leftMargin.addFocusListener(this);            leftMargin.addActionListener(this);            leftMargin.getAccessibleContext().setAccessibleName(                                              getMsg("label.leftmargin"));            rightMargin = new JFormattedTextField(nf);            rightMargin.addFocusListener(this);            rightMargin.addActionListener(this);            rightMargin.getAccessibleContext().setAccessibleName(                                              getMsg("label.rightmargin"));            topMargin = new JFormattedTextField(nf);            topMargin.addFocusListener(this);            topMargin.addActionListener(this);            topMargin.getAccessibleContext().setAccessibleName(                                              getMsg("label.topmargin"));            topMargin = new JFormattedTextField(nf);            bottomMargin = new JFormattedTextField(nf);            bottomMargin.addFocusListener(this);            bottomMargin.addActionListener(this);            bottomMargin.getAccessibleContext().setAccessibleName(                                              getMsg("label.bottommargin"));            topMargin = new JFormattedTextField(nf);            c.gridwidth = GridBagConstraints.RELATIVE;            lblLeft = new JLabel(getMsg("label.leftmargin") + " " + unitsMsg,                                 JLabel.LEADING);            lblLeft.setDisplayedMnemonic(getMnemonic("label.leftmargin"));            lblLeft.setLabelFor(leftMargin);            addToGB(lblLeft, this, gridbag, c);             c.gridwidth = GridBagConstraints.REMAINDER;            lblRight = new JLabel(getMsg("label.rightmargin") + " " + unitsMsg,                                  JLabel.LEADING);            lblRight.setDisplayedMnemonic(getMnemonic("label.rightmargin"));            lblRight.setLabelFor(rightMargin);            addToGB(lblRight, this, gridbag, c);             c.gridwidth = GridBagConstraints.RELATIVE;            addToGB(leftMargin, this, gridbag, c);             c.gridwidth = GridBagConstraints.REMAINDER;            addToGB(rightMargin, this, gridbag, c);             // add an invisible spacing component.            addToGB(new JPanel(), this, gridbag, c);             c.gridwidth = GridBagConstraints.RELATIVE;            lblTop = new JLabel(getMsg("label.topmargin") + " " + unitsMsg,                                JLabel.LEADING);            lblTop.setDisplayedMnemonic(getMnemonic("label.topmargin"));            lblTop.setLabelFor(topMargin);            addToGB(lblTop, this, gridbag, c);             c.gridwidth = GridBagConstraints.REMAINDER;            lblBottom = new JLabel(getMsg("label.bottommargin") +                                   " " + unitsMsg, JLabel.LEADING);            lblBottom.setDisplayedMnemonic(getMnemonic("label.bottommargin"));            lblBottom.setLabelFor(bottomMargin);            addToGB(lblBottom, this, gridbag, c);             c.gridwidth = GridBagConstraints.RELATIVE;            addToGB(topMargin, this, gridbag, c);             c.gridwidth = GridBagConstraints.REMAINDER;            addToGB(bottomMargin, this, gridbag, c);         }         public void actionPerformed(ActionEvent e) {            Object source = e.getSource();            updateMargins(source);        }         public void focusLost(FocusEvent e) {            Object source = e.getSource();            updateMargins(source);        }         public void focusGained(FocusEvent e) {}         /* Get the numbers, use to create a MPA.         * If its valid, accept it and update the attribute set.         * If its not valid, then reject it and call updateInfo()         * to re-establish the previous entries.         */        public void updateMargins(Object source) {            if (!(source instanceof JFormattedTextField)) {                return;            } else {                JFormattedTextField tf = (JFormattedTextField)source;                Float val = (Float)tf.getValue();                if (val == null) {                    return;                }                if (tf == leftMargin && val.equals(lmObj)) {                    return;                }                if (tf == rightMargin && val.equals(rmObj)) {                    return;                }                if (tf == topMargin && val.equals(tmObj)) {                    return;                }                if (tf == bottomMargin && val.equals(bmObj)) {                    return;                }            }             Float lmTmpObj = (Float)leftMargin.getValue();            Float rmTmpObj = (Float)rightMargin.getValue();            Float tmTmpObj = (Float)topMargin.getValue();            Float bmTmpObj = (Float)bottomMargin.getValue();             float lm = lmTmpObj.floatValue();            float rm = rmTmpObj.floatValue();            float tm = tmTmpObj.floatValue();            float bm = bmTmpObj.floatValue();             /* adjust for orientation */            Class orCategory = OrientationRequested.class;            OrientationRequested or =                (OrientationRequested)asCurrent.get(orCategory);             if (or == null) {                or = (OrientationRequested)                     psCurrent.getDefaultAttributeValue(orCategory);            }             float tmp;            if (or == OrientationRequested.REVERSE_PORTRAIT) {                tmp = lm; lm = rm; rm = tmp;                tmp = tm; tm = bm; bm = tmp;            } else if (or == OrientationRequested.LANDSCAPE) {                tmp = lm;                lm = tm;                tm = rm;                rm = bm;                bm = tmp;            } else if (or == OrientationRequested.REVERSE_LANDSCAPE) {                tmp = lm;                lm = bm;                bm = rm;                rm = tm;                tm = tmp;            }            MediaPrintableArea mpa;            if ((mpa = validateMargins(lm, rm, tm, bm)) != null) {                asCurrent.add(mpa);                lmVal = lm;                rmVal = rm;                tmVal = tm;                bmVal = bm;                lmObj = lmTmpObj;                rmObj = rmTmpObj;                tmObj = tmTmpObj;                bmObj = bmTmpObj;            } else {                if (lmObj == null || rmObj == null ||                    tmObj == null || rmObj == null) {                    return;

Lines 1001–1500 of 2839. Previous lines