📄 printerdialog.java
字号:
c.weightx = 1.5; add(services_cob, c); c.gridx = 1; c.gridy = 1; c.gridwidth = 2; c.weightx = 1; add(statusValue, c); c.gridx = 1; c.gridy = 2; c.gridwidth = 2; c.weightx = 1; add(typValue, c); c.gridx = 1; c.gridy = 3; c.gridwidth = 2; c.weightx = 1; add(infoValue, c); c.gridx = 2; c.gridy = 0; c.weightx = 1.5; add(attributes, c); } public void actionPerformed(ActionEvent e) { if (e.getActionCommand().equals("SERVICE")) { setSelectedPrintService((PrintService) services_cob.getSelectedItem()); updateAll(); } else if (e.getActionCommand().equals("ATTRIBUTES")) { // TODO LowPriority-Enhancement: As tests have shown this button // is even gray and not enabled under Windows - Its a good place // to provide a classpath specific browsing dialog for all // attributes not in the default printing dialog. } } /** * Called to update for new selected * print service. Tests if currently * selected attributes are supported. */ void updateForSelectedService() { PrinterMakeAndModel att1 = (PrinterMakeAndModel) getSelectedPrintService().getAttribute(PrinterMakeAndModel.class); typValue.setText(att1 == null ? "" : att1.getValue()); PrinterInfo att2 = (PrinterInfo) getSelectedPrintService().getAttribute(PrinterInfo.class); infoValue.setText(att2 == null ? "" : att2.getValue()); PrinterIsAcceptingJobs att3 = (PrinterIsAcceptingJobs) getSelectedPrintService().getAttribute(PrinterIsAcceptingJobs.class); PrinterState att4 = (PrinterState) getSelectedPrintService().getAttribute(PrinterState.class); String status = att4.toString(); if (att3 == PrinterIsAcceptingJobs.ACCEPTING_JOBS) status += " - " + getLocalizedString("lb.acceptingjobs"); else if (att3 == PrinterIsAcceptingJobs.NOT_ACCEPTING_JOBS) status += " - " + getLocalizedString("lb.notacceptingjobs"); statusValue.setText(status); if (categorySupported(Destination.class)) { fileRedirection_cb.setEnabled(false); } } } private PrintServices printserv_panel; private PrintRange printrange_panel; private CopiesAndSorted copies; /** * Constructs the General Panel. */ public GeneralPanel() { setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); printserv_panel = new PrintServices(); printrange_panel = new PrintRange(); copies = new CopiesAndSorted(); JPanel layout_panel = new JPanel(); layout_panel.setLayout(new BoxLayout(layout_panel, BoxLayout.LINE_AXIS)); layout_panel.add(printrange_panel); layout_panel.add(Box.createRigidArea(new Dimension(10, 0))); layout_panel.add(copies); setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS)); add(printserv_panel); add(Box.createRigidArea(new Dimension(0, 12))); add(layout_panel); } /** * Calls update on all internal panels to adjust * for a new selected print service. */ void update() { printserv_panel.updateForSelectedService(); printrange_panel.updateForSelectedService(); copies.updateForSelectedService(); } } /** * The Page setup Panel. * @author Wolfgang Baer (WBaer@gmx.de) */ final class PageSetupPanel extends JPanel { /** * Handles the orientation attribute. * @author Wolfgang Baer (WBaer@gmx.de) */ final class Orientation extends JPanel implements ActionListener { private JRadioButton portrait, landscape, rev_portrait, rev_landscape; Orientation() { portrait = new JRadioButton(getLocalizedString("rbt.portrait")); portrait.addActionListener(this); landscape = new JRadioButton(getLocalizedString("rbt.landscape")); landscape.addActionListener(this); rev_portrait = new JRadioButton(getLocalizedString("rbt.revportrait")); rev_portrait.addActionListener(this); rev_landscape = new JRadioButton(getLocalizedString("rbt.revlandscape")); rev_landscape.addActionListener(this); ButtonGroup group = new ButtonGroup(); group.add(portrait); group.add(landscape); group.add(rev_portrait); group.add(rev_landscape); GridBagLayout layout = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.BOTH; setLayout(layout); setBorder(new TitledBorder(getLocalizedString("title.orientation"))); c.insets = new Insets(5, 5, 5, 5); c.gridx = 0; c.gridy = 0; add(portrait, c); c.gridx = 0; c.gridy = 1; add(landscape, c); c.gridx = 0; c.gridy = 2; add(rev_portrait, c); c.gridx = 0; c.gridy = 3; add(rev_landscape, c); } // event handling orientation public void actionPerformed(ActionEvent e) { if (e.getSource() == portrait) atts.add(OrientationRequested.PORTRAIT); else if (e.getSource() == landscape) atts.add(OrientationRequested.LANDSCAPE); else if (e.getSource() == rev_portrait) atts.add(OrientationRequested.REVERSE_PORTRAIT); else atts.add(OrientationRequested.REVERSE_LANDSCAPE); } /** * Called to update for new selected * print service. Tests if currently * selected attributes are supported. */ void updateForSelectedService() { if (categorySupported(OrientationRequested.class)) { portrait.setEnabled(true); landscape.setEnabled(true); rev_landscape.setEnabled(true); rev_portrait.setEnabled(true); Attribute orientation = attribute(OrientationRequested.class); if (orientation != null) { if (orientation.equals(OrientationRequested.LANDSCAPE)) landscape.setSelected(true); else if (orientation.equals(OrientationRequested.PORTRAIT)) portrait.setSelected(true); else if (orientation.equals(OrientationRequested.REVERSE_PORTRAIT)) rev_portrait.setSelected(true); else rev_landscape.setSelected(true); } else { Object defaultValue = defaultValue(OrientationRequested.class); if (defaultValue.equals(OrientationRequested.LANDSCAPE)) landscape.setSelected(true); else if (defaultValue.equals(OrientationRequested.PORTRAIT)) portrait.setSelected(true); else if (defaultValue.equals(OrientationRequested.REVERSE_PORTRAIT)) rev_portrait.setSelected(true); else rev_landscape.setSelected(true); } } else { portrait.setEnabled(false); landscape.setEnabled(false); rev_landscape.setEnabled(false); rev_portrait.setEnabled(false); } } } /** * Handles the media attribute. * @author Wolfgang Baer (WBaer@gmx.de) */ final class MediaTypes extends JPanel implements ActionListener { private JLabel size_lb, source_lb; private JComboBox size, source; MediaTypes() { size_lb = new JLabel(getLocalizedString("lb.size")); source_lb = new JLabel(getLocalizedString("lb.source")); size = new JComboBox(); size.setEditable(false); size.addActionListener(this); source = new JComboBox(); source.setEditable(false); size.addActionListener(this); GridBagLayout layout = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); setLayout(layout); setBorder(new TitledBorder(getLocalizedString("title.medias"))); c.insets = new Insets(5, 5, 5, 5); c.anchor = GridBagConstraints.LINE_END; c.gridx = 0; c.gridy = 0; add(size_lb, c); c.gridx = 0; c.gridy = 1; add(source_lb, c); c.anchor = GridBagConstraints.LINE_START; c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 1; c.gridy = 0; c.weightx = 1.5; add(size, c); c.gridx = 1; c.gridy = 1; c.weightx = 1.5; add(source, c); } public void actionPerformed(ActionEvent event) { if (event.getSource() == size) { Object obj = size.getSelectedItem(); if (obj instanceof Media) atts.add((Media) obj); } // we ignore source events currently // as only the automatic selection is used. } /** * Called to update for new selected * print service. Tests if currently * selected attributes are supported. */ void updateForSelectedService() { if (categorySupported(Media.class)) { Media[] medias = (Media[]) getSelectedPrintService() .getSupportedAttributeValues(Media.class, flavor, null); size.removeAllItems(); if (medias.length == 0) size.addItem(getLocalizedString("lb.automatically")); else for (int i=0; i < medias.length; i++) size.addItem(medias[i]); Media media = (Media) attribute(Media.class); if (media != null) size.setSelectedItem(media); // this is currently ignored source.removeAllItems(); source.addItem(getLocalizedString("lb.automatically")); } else { size.removeAllItems(); source.removeAllItems(); size.addItem(getLocalizedString("lb.automatically")); source.addItem(getLocalizedString("lb.automatically")); } } } /** * Handles the media printable area attribute. * @author Wolfgang Baer (WBaer@gmx.de) */ final class Margins extends JPanel implements FocusListener { private JLabel left, right, top, bottom; private JTextField left_tf, right_tf, top_tf, bottom_tf; Margins() { left = new JLabel(getLocalizedString("lb.left")); right = new JLabel(getLocalizedString("lb.right")); top = new JLabel(getLocalizedString("lb.top")); bottom = new JLabel(getLocalizedString("lb.bottom")); left_tf = new JTextField(7); left_tf.addFocusListener(this); right_tf = new JTextField(7); right_tf.addFocusListener(this); top_tf = new JTextField(7); top_tf.addFocusListener(this); bottom_tf = new JTextField(7); bottom_tf.addFocusListener(this); GridBagLayout layout = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); setLayout(layout); setBorder(new TitledBorder(getLocalizedString("title.margins"))); c.insets = new Insets(5, 5, 5, 5); c.gridx = 0; c.gridy = 0; add(left, c); c.gridx = 1; c.gridy = 0; add(right, c); c.insets = new Insets(5, 5, 5, 5); c.gridx = 0; c.gridy = 1; add(left_tf, c); c.gridx = 1; c.gridy = 1; add(right_tf, c); c.insets = new Insets(10, 5, 5, 5); c.gridx = 0; c.gridy = 2; add(top, c); c.gridx = 1; c.gridy = 2; add(bottom, c); c.insets = new Insets(0, 5, 5, 5); c.gridx = 0; c.gridy = 3; add(top_tf, c); c.gridx = 1; c.gridy = 3; add(bottom_tf, c); } public void focusGained(FocusEvent event) { updateMargins(); } public void focusLost(FocusEvent event) { updateMargins(); } // updates the margins after user changed it private void updateMargins() { // We currently do not support this attribute // as it is not in the IPP spec and therefore not in CUPS } /** * Called to update for new selected * print service. Tests if currently * selected attributes are supported. */ void updateForSelectedService() { if (categorySupported(MediaPrintableArea.class)) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -