2839 lines · 102.4 KB · Java
RawDownload
            if (psCurrent.isAttributeCategorySupported(sdCategory)) {                Object values =                    psCurrent.getSupportedAttributeValues(sdCategory,                                                          docFlavor,                                                          asCurrent);                 if (values instanceof Sides[]) {                    Sides[] svalues = (Sides[])values;                     for (int i = 0; i < svalues.length; i++) {                        Sides value = svalues[i];                         if (value == Sides.ONE_SIDED) {                            osSupported = true;                        } else if (value == Sides.TUMBLE) {                            tSupported = true;                        } else if (value == Sides.DUPLEX) {                            dSupported = true;                        }                    }                }            }            rbOneSide.setEnabled(osSupported);            rbTumble.setEnabled(tSupported);            rbDuplex.setEnabled(dSupported);             Sides sd = (Sides)asCurrent.get(sdCategory);            if (sd == null) {                sd = (Sides)psCurrent.getDefaultAttributeValue(sdCategory);                if (sd == null) {                    sd = Sides.ONE_SIDED;                }            }             if (sd == Sides.ONE_SIDED) {                rbOneSide.setSelected(true);            } else if (sd == Sides.TUMBLE) {                rbTumble.setSelected(true);            } else { // if (sd == Sides.DUPLEX)                rbDuplex.setSelected(true);            }        }    }       private class JobAttributesPanel extends JPanel        implements ActionListener, ChangeListener, FocusListener    {        private final String strTitle = getMsg("border.jobattributes");        private JLabel lblPriority, lblJobName, lblUserName;        private JSpinner spinPriority;        private SpinnerNumberModel snModel;        private JCheckBox cbJobSheets;        private JTextField tfJobName, tfUserName;         public JobAttributesPanel() {            super();             GridBagLayout gridbag = new GridBagLayout();            GridBagConstraints c = new GridBagConstraints();             setLayout(gridbag);            setBorder(BorderFactory.createTitledBorder(strTitle));             c.fill = GridBagConstraints.NONE;            c.insets = compInsets;            c.weighty = 1.0;             cbJobSheets = createCheckBox("checkbox.jobsheets", this);            c.anchor = GridBagConstraints.LINE_START;            addToGB(cbJobSheets, this, gridbag, c);             JPanel pnlTop = new JPanel();            lblPriority = new JLabel(getMsg("label.priority"), JLabel.TRAILING);            lblPriority.setDisplayedMnemonic(getMnemonic("label.priority"));             pnlTop.add(lblPriority);            snModel = new SpinnerNumberModel(1, 1, 100, 1);            spinPriority = new JSpinner(snModel);            lblPriority.setLabelFor(spinPriority);            // REMIND            ((JSpinner.NumberEditor)spinPriority.getEditor()).getTextField().setColumns(3);            spinPriority.addChangeListener(this);            pnlTop.add(spinPriority);            c.anchor = GridBagConstraints.LINE_END;            c.gridwidth = GridBagConstraints.REMAINDER;            pnlTop.getAccessibleContext().setAccessibleName(                                       getMsg("label.priority"));            addToGB(pnlTop, this, gridbag, c);             c.fill = GridBagConstraints.HORIZONTAL;            c.anchor = GridBagConstraints.CENTER;            c.weightx = 0.0;            c.gridwidth = 1;            char jmnemonic = getMnemonic("label.jobname");            lblJobName = new JLabel(getMsg("label.jobname"), JLabel.TRAILING);            lblJobName.setDisplayedMnemonic(jmnemonic);            addToGB(lblJobName, this, gridbag, c);            c.weightx = 1.0;            c.gridwidth = GridBagConstraints.REMAINDER;            tfJobName = new JTextField();            lblJobName.setLabelFor(tfJobName);            tfJobName.addFocusListener(this);            tfJobName.setFocusAccelerator(jmnemonic);            tfJobName.getAccessibleContext().setAccessibleName(                                             getMsg("label.jobname"));            addToGB(tfJobName, this, gridbag, c);             c.weightx = 0.0;            c.gridwidth = 1;            char umnemonic = getMnemonic("label.username");            lblUserName = new JLabel(getMsg("label.username"), JLabel.TRAILING);            lblUserName.setDisplayedMnemonic(umnemonic);            addToGB(lblUserName, this, gridbag, c);            c.gridwidth = GridBagConstraints.REMAINDER;            tfUserName = new JTextField();            lblUserName.setLabelFor(tfUserName);            tfUserName.addFocusListener(this);            tfUserName.setFocusAccelerator(umnemonic);            tfUserName.getAccessibleContext().setAccessibleName(                                             getMsg("label.username"));            addToGB(tfUserName, this, gridbag, c);        }         public void actionPerformed(ActionEvent e) {            if (cbJobSheets.isSelected()) {                asCurrent.add(JobSheets.STANDARD);            } else {                asCurrent.add(JobSheets.NONE);            }        }         public void stateChanged(ChangeEvent e) {            asCurrent.add(new JobPriority(snModel.getNumber().intValue()));        }         public void focusLost(FocusEvent e) {            Object source = e.getSource();             if (source == tfJobName) {                asCurrent.add(new JobName(tfJobName.getText(),                                          Locale.getDefault()));            } else if (source == tfUserName) {                asCurrent.add(new RequestingUserName(tfUserName.getText(),                                                     Locale.getDefault()));            }        }         public void focusGained(FocusEvent e) {}         public void updateInfo() {            Class jsCategory = JobSheets.class;            Class jpCategory = JobPriority.class;            Class jnCategory = JobName.class;            Class unCategory = RequestingUserName.class;            boolean jsSupported = false;            boolean jpSupported = false;            boolean jnSupported = false;            boolean unSupported = false;             // setup JobSheets checkbox            if (psCurrent.isAttributeCategorySupported(jsCategory)) {                jsSupported = true;            }            JobSheets js = (JobSheets)asCurrent.get(jsCategory);            if (js == null) {                js = (JobSheets)psCurrent.getDefaultAttributeValue(jsCategory);                if (js == null) {                    js = JobSheets.NONE;                }            }            cbJobSheets.setSelected(js != JobSheets.NONE);            cbJobSheets.setEnabled(jsSupported);             // setup JobPriority spinner            if (!isAWT && psCurrent.isAttributeCategorySupported(jpCategory)) {                jpSupported = true;            }            JobPriority jp = (JobPriority)asCurrent.get(jpCategory);            if (jp == null) {                jp = (JobPriority)psCurrent.getDefaultAttributeValue(jpCategory);                if (jp == null) {                    jp = new JobPriority(1);                }            }            int value = jp.getValue();            if ((value < 1) || (value > 100)) {                value = 1;            }            snModel.setValue(new Integer(value));            lblPriority.setEnabled(jpSupported);            spinPriority.setEnabled(jpSupported);             // setup JobName text field            if (psCurrent.isAttributeCategorySupported(jnCategory)) {                jnSupported = true;            }            JobName jn = (JobName)asCurrent.get(jnCategory);            if (jn == null) {                jn = (JobName)psCurrent.getDefaultAttributeValue(jnCategory);                if (jn == null) {                    jn = new JobName("", Locale.getDefault());                }            }            tfJobName.setText(jn.getValue());            tfJobName.setEnabled(jnSupported);            lblJobName.setEnabled(jnSupported);             // setup RequestingUserName text field            if (!isAWT && psCurrent.isAttributeCategorySupported(unCategory)) {                unSupported = true;            }            RequestingUserName un = (RequestingUserName)asCurrent.get(unCategory);            if (un == null) {                un = (RequestingUserName)psCurrent.getDefaultAttributeValue(unCategory);                if (un == null) {                    un = new RequestingUserName("", Locale.getDefault());                }            }            tfUserName.setText(un.getValue());            tfUserName.setEnabled(unSupported);            lblUserName.setEnabled(unSupported);        }    }        /**     * A special widget that groups a JRadioButton with an associated icon,     * placed to the left of the radio button.     */    private class IconRadioButton extends JPanel {         private JRadioButton rb;        private JLabel lbl;         public IconRadioButton(String key, String img, boolean selected,                               ButtonGroup bg, ActionListener al)        {            super(new FlowLayout(FlowLayout.LEADING));            final URL imgURL = getImageResource(img);            Icon icon = (Icon)java.security.AccessController.doPrivileged(                                 new java.security.PrivilegedAction() {                public Object run() {                    Icon icon = new ImageIcon(imgURL);                    return icon;                }            });            lbl = new JLabel(icon);            add(lbl);             rb = createRadioButton(key, al);            rb.setSelected(selected);            addToBG(rb, this, bg);        }         public void addActionListener(ActionListener al) {            rb.addActionListener(al);        }         public boolean isSameAs(Object source) {            return (rb == source);        }         public void setEnabled(boolean enabled) {            rb.setEnabled(enabled);            lbl.setEnabled(enabled);        }         public boolean isSelected() {            return rb.isSelected();        }         public void setSelected(boolean selected) {            rb.setSelected(selected);        }    }     /**     * Similar in functionality to the default JFileChooser, except this     * chooser will pop up a "Do you want to overwrite..." dialog if the     * user selects a file that already exists.     */    private class ValidatingFileChooser extends JFileChooser {        public void approveSelection() {            File selected = getSelectedFile();            boolean exists;             try {                exists = selected.exists();            } catch (SecurityException e) {                exists = false;            }             if (exists) {                int val;                val = JOptionPane.showConfirmDialog(this,                                                    getMsg("dialog.overwrite"),                                                    getMsg("dialog.owtitle"),                                                    JOptionPane.YES_NO_OPTION);                if (val != JOptionPane.YES_OPTION) {                    return;                }            }             try {                if (selected.createNewFile()) {                    selected.delete();                }            }  catch (IOException ioe) {                JOptionPane.showMessageDialog(this,                                   getMsg("dialog.writeerror")+" "+selected,                                   getMsg("dialog.owtitle"),                                   JOptionPane.WARNING_MESSAGE);                return;            } catch (SecurityException se) {                //There is already file read/write access so at this point                // only delete access is denied.  Just ignore it because in                // most cases the file created in createNewFile gets                // overwritten anyway.            }            File pFile = selected.getParentFile();            if ((selected.exists() &&                      (!selected.isFile() || !selected.canWrite())) ||                     ((pFile != null) &&                      (!pFile.exists() || (pFile.exists() && !pFile.canWrite())))) {                JOptionPane.showMessageDialog(this,                                   getMsg("dialog.writeerror")+" "+selected,                                   getMsg("dialog.owtitle"),                                   JOptionPane.WARNING_MESSAGE);                return;            }             super.approveSelection();        }    }}

Lines 2501–2839 of 2839. Previous lines