⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 printerdialog.java

📁 linux下建立JAVA虚拟机的源码KAFFE
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
/* PrinterDialog.java --   Copyright (C)  2006  Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING.  If not, write to theFree Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library.  Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule.  An independent module is a module which is not derived fromor based on this library.  If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so.  If you do not wish to do so, delete thisexception statement from your version. */package gnu.javax.print;import java.awt.BorderLayout;import java.awt.Dimension;import java.awt.Frame;import java.awt.GraphicsConfiguration;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.HeadlessException;import java.awt.Insets;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.FocusEvent;import java.awt.event.FocusListener;import java.util.ArrayList;import java.util.ResourceBundle;import javax.print.DocFlavor;import javax.print.PrintService;import javax.print.attribute.Attribute;import javax.print.attribute.HashPrintRequestAttributeSet;import javax.print.attribute.PrintRequestAttributeSet;import javax.print.attribute.standard.Chromaticity;import javax.print.attribute.standard.Copies;import javax.print.attribute.standard.Destination;import javax.print.attribute.standard.JobName;import javax.print.attribute.standard.JobPriority;import javax.print.attribute.standard.JobSheets;import javax.print.attribute.standard.Media;import javax.print.attribute.standard.MediaPrintableArea;import javax.print.attribute.standard.OrientationRequested;import javax.print.attribute.standard.PageRanges;import javax.print.attribute.standard.PrintQuality;import javax.print.attribute.standard.PrinterInfo;import javax.print.attribute.standard.PrinterIsAcceptingJobs;import javax.print.attribute.standard.PrinterMakeAndModel;import javax.print.attribute.standard.PrinterState;import javax.print.attribute.standard.RequestingUserName;import javax.print.attribute.standard.SheetCollate;import javax.print.attribute.standard.Sides;import javax.swing.BorderFactory;import javax.swing.Box;import javax.swing.BoxLayout;import javax.swing.ButtonGroup;import javax.swing.JButton;import javax.swing.JCheckBox;import javax.swing.JComboBox;import javax.swing.JDialog;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JRadioButton;import javax.swing.JSpinner;import javax.swing.JTabbedPane;import javax.swing.JTextField;import javax.swing.SpinnerNumberModel;import javax.swing.border.TitledBorder;import javax.swing.event.ChangeEvent;import javax.swing.event.ChangeListener;/** * Implementation of the PrinterDialog used by * {@link javax.print.ServiceUI} for visual selection * of print services and its attributes. *  * @author Wolfgang Baer (WBaer@gmx.de) */public final class PrinterDialog extends JDialog implements ActionListener{    /**   * The General Panel used in the printing dialog.   * @author Wolfgang Baer (WBaer@gmx.de)   */  final class GeneralPanel extends JPanel  {    /**     * Handles the copies attribute.     * @author Wolfgang Baer (WBaer@gmx.de)     */    final class CopiesAndSorted extends JPanel       implements ChangeListener, ActionListener    {            private JCheckBox sort;          private JSpinner copies;      private JLabel copies_lb;      private SpinnerNumberModel copiesModel;          CopiesAndSorted()      {        copies_lb = new JLabel(getLocalizedString("lb.copies"));                sort = new JCheckBox(getLocalizedString("cb.sort"));        sort.addActionListener(this);            copiesModel = new SpinnerNumberModel(1, 1, 9999, 1);        copies = new JSpinner(copiesModel);        copies.addChangeListener(this);                GridBagLayout layout = new GridBagLayout();        GridBagConstraints c = new GridBagConstraints();        c.fill = GridBagConstraints.BOTH;        c.insets = new Insets(5, 5, 5, 5);            setLayout(layout);        setBorder(new TitledBorder(getLocalizedString("title.copies")));            c.anchor = GridBagConstraints.WEST;            c.gridx = 0;        c.gridy = 0;        add(copies_lb, c);            c.gridx = 1;        c.gridy = 0;        add(copies, c);            c.gridx = 0;        c.gridy = 1;        add(sort, c);      }            // copies jspinner state      public void stateChanged(ChangeEvent event)      {        int value = ((Integer) copies.getValue()).intValue();        atts.add(new Copies(value));                    if (value > 1 && categorySupported(SheetCollate.class))          sort.setEnabled(true);        else          sort.setEnabled(false);                      }      // sorted checkbox state      public void actionPerformed(ActionEvent event)      {        if (sort.isSelected())          atts.add(SheetCollate.COLLATED);      }      /**       * Called to update for new selected       * print service. Tests if currently       * selected attributes are supported.       */      void updateForSelectedService()      {                if (categorySupported(Copies.class))          {            copies.setEnabled(true);            copies_lb.setEnabled(true);                        Copies copies = (Copies) attribute(Copies.class);            if (copies != null)              copiesModel.setValue(new Integer(copies.getValue()));                        if (((Integer)copiesModel.getValue()).intValue() > 1                            && categorySupported(SheetCollate.class))              {                sort.setEnabled(true);                Attribute collate = attribute(SheetCollate.class);                if (collate != null && collate.equals(SheetCollate.COLLATED))                  sort.setSelected(true);               }            else              sort.setEnabled(false);          }        else          {            copies.setEnabled(false);                        copies_lb.setEnabled(false);          }      }    }    /**     * Handles the print ranges attribute.     * @author Wolfgang Baer (WBaer@gmx.de)     */    final class PrintRange extends JPanel       implements ActionListener, FocusListener    {          private JLabel to;          private JRadioButton all_rb, pages_rb;         private JTextField from_tf, to_tf;                PrintRange()      {                to = new JLabel(getLocalizedString("lb.to"));        to.setEnabled(false);            all_rb = new JRadioButton(getLocalizedString("rbt.all"));        all_rb.setSelected(true);        all_rb.setActionCommand("ALL");        all_rb.addActionListener(this);        pages_rb = new JRadioButton(getLocalizedString("rbt.pages"));        pages_rb.setActionCommand("PAGES");        pages_rb.setEnabled(false);        pages_rb.addActionListener(this);            ButtonGroup group = new ButtonGroup();        group.add(all_rb);        group.add(pages_rb);            from_tf = new JTextField("1", 4);        from_tf.setEnabled(false);        from_tf.addFocusListener(this);        to_tf = new JTextField("1", 4);        to_tf.setEnabled(false);        to_tf.addFocusListener(this);            GridBagLayout layout = new GridBagLayout();        GridBagConstraints c = new GridBagConstraints();        c.fill = GridBagConstraints.BOTH;            setLayout(layout);        setBorder(new TitledBorder(getLocalizedString("title.printrange")));            c.insets = new Insets(15, 5, 5, 5);        c.gridx = 0;        c.gridy = 0;        add(all_rb, c);            c.insets = new Insets(5, 5, 15, 5);        c.gridx = 0;        c.gridy = 1;        add(pages_rb, c);            c.gridx = 1;        c.gridy = 1;        add(from_tf, c);            c.gridx = 2;        c.gridy = 1;        add(to, c);            c.insets = new Insets(5, 5, 15, 15);        c.gridx = 3;        c.gridy = 1;        add(to_tf, c);      }                  // focus pagerange      public void focusGained(FocusEvent event)      {        updatePageRanges();      }        public void focusLost(FocusEvent event)      {        updatePageRanges();      }            // updates the range after user changed it      private void updatePageRanges()      {        int lower = Integer.parseInt(from_tf.getText());        int upper = Integer.parseInt(to_tf.getText());                if (lower > upper)          {            upper = lower;            to_tf.setText("" + lower);                          }                PageRanges range = new PageRanges(lower, upper);        atts.add(range);      }      // page range change      public void actionPerformed(ActionEvent e)      {         // if ALL is selected we must use a full-range object        if (e.getActionCommand().equals("ALL"))          {            from_tf.setEnabled(false);            to.setEnabled(false);            to_tf.setEnabled(false);                        atts.add(new PageRanges(1, Integer.MAX_VALUE));          }        else          {            from_tf.setEnabled(true);            to.setEnabled(true);            to_tf.setEnabled(true);            all_rb.setSelected(false);          }             }          /**       * Called to update for new selected       * print service. Tests if currently       * selected attributes are supported.       */      void updateForSelectedService()      {        if (categorySupported(PageRanges.class))          {            pages_rb.setEnabled(true);            PageRanges range = (PageRanges) attribute(PageRanges.class);            if (range != null)              {                from_tf.setEnabled(true);                to.setEnabled(true);                to_tf.setEnabled(true);                   all_rb.setSelected(false);                pages_rb.setSelected(true);                                int[][] members = range.getMembers();                // Although passed in attributes may contain more than one                 // range we only take the first one                from_tf.setText("" + members[0][0]);                to_tf.setText("" + members[0][1]);              }          }        else          {            from_tf.setEnabled(false);            to.setEnabled(false);            to_tf.setEnabled(false);            all_rb.setSelected(true);          }       }    }    /**     * Handles the selection of the print services     * and its location and description attributes.     * @author Wolfgang Baer (WBaer@gmx.de)     */    final class PrintServices extends JPanel       implements ActionListener    {          private JLabel name, status, typ, info;      private JLabel statusValue, typValue, infoValue;         private JButton attributes;          private JComboBox services_cob;          private JCheckBox fileRedirection_cb;          PrintServices()      {        name = new JLabel(getLocalizedString("lb.name"));        status = new JLabel(getLocalizedString("lb.status"));        typ = new JLabel(getLocalizedString("lb.typ"));        info = new JLabel(getLocalizedString("lb.info"));        typValue = new JLabel();        infoValue = new JLabel();        statusValue = new JLabel();            attributes = new JButton(getLocalizedString("bt.attributes"));        attributes.setEnabled(false);        attributes.setActionCommand("ATTRIBUTES");        attributes.addActionListener(this);            services_cob = new JComboBox(getPrintServices());        services_cob.setActionCommand("SERVICE");        services_cob.addActionListener(this);            fileRedirection_cb = new JCheckBox(getLocalizedString("cb.output"));        fileRedirection_cb.setEnabled(false);            GridBagLayout layout = new GridBagLayout();        GridBagConstraints c = new GridBagConstraints();            setLayout(layout);        setBorder(new TitledBorder(getLocalizedString("title.printservice")));            c.insets = new Insets(5, 5, 5, 5);        c.anchor = GridBagConstraints.LINE_END;        c.gridx = 0;        c.gridy = 0;        add(name, c);            c.gridx = 0;        c.gridy = 1;        add(status, c);            c.gridx = 0;        c.gridy = 2;        add(typ, c);            c.gridx = 0;        c.gridy = 3;        add(info, c);            c.gridx = 2;        c.gridy = 3;        c.weightx = 1;        add(fileRedirection_cb, c);            c.anchor = GridBagConstraints.LINE_START;        c.fill = GridBagConstraints.HORIZONTAL;        c.gridx = 1;        c.gridy = 0;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -