jdk/src/java.desktop/share/classes/sun/print/ServiceDialog.java
author psadhukhan
Tue, 23 Aug 2016 10:27:47 +0530
changeset 40714 b25cd91f5dd2
parent 40431 50d30cb5c70b
child 44348 dbf9b2624dfa
permissions -rw-r--r--
8163922: Print-to-file is disabled for SERVICE_FORMATTED docflavor in linux Reviewed-by: prr, jdv
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23648
a95041026433 8037139: Fix serial lint warnings in sun.print
darcy
parents: 23010
diff changeset
     2
 * Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2389
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2389
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2389
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2389
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2389
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.print;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.BorderLayout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.Color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.Component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.Container;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.Dialog;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.FlowLayout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.Frame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.GraphicsConfiguration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.awt.GridBagLayout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.awt.GridBagConstraints;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.awt.GridLayout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.awt.Insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.awt.Toolkit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.awt.event.ActionEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.awt.event.ActionListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.awt.event.FocusEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.awt.event.FocusListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.awt.event.ItemEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.awt.event.ItemListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.awt.event.WindowEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.awt.event.WindowAdapter;
19781
91b06f016821 4673406: RFE: Java Printing: Provide a way to display win32 printer driver's dialog
prr
parents: 14342
diff changeset
    49
import java.awt.print.PrinterJob;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import java.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import java.io.FilePermission;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import java.net.URI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import java.net.URL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
import java.text.DecimalFormat;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
import java.util.Locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
import java.util.ResourceBundle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
import javax.print.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
import javax.print.attribute.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
import javax.print.attribute.standard.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
import javax.swing.border.Border;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
import javax.swing.border.EmptyBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
import javax.swing.border.TitledBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
import javax.swing.event.ChangeEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
import javax.swing.event.ChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
import javax.swing.event.DocumentEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
import javax.swing.event.DocumentListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
import javax.swing.event.PopupMenuEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
import javax.swing.event.PopupMenuListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
import javax.swing.text.NumberFormatter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
import sun.print.SunPageSelection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
import java.awt.event.KeyEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
import java.net.URISyntaxException;
12520
9d6777f588d4 7013850: Please change the mnemonic assignment system to avoid translation issue
jgodinez
parents: 5506
diff changeset
    76
import java.lang.reflect.Field;
39847
8d41728f649b 5049012: PrintToFile option is not disabled for flavors that do not support destination
psadhukhan
parents: 38983
diff changeset
    77
import java.net.MalformedURLException;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * A class which implements a cross-platform print dialog.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * @author  Chris Campbell
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 */
23648
a95041026433 8037139: Fix serial lint warnings in sun.print
darcy
parents: 23010
diff changeset
    84
@SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
public class ServiceDialog extends JDialog implements ActionListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * Waiting print status (user response pending).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     */
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 29008
diff changeset
    90
    public static final int WAITING = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * Approve print status (user activated "Print" or "OK").
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     */
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 29008
diff changeset
    95
    public static final int APPROVE = 1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * Cancel print status (user activated "Cancel");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     */
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 29008
diff changeset
   100
    public static final int CANCEL = 2;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    private static final String strBundle = "sun.print.resources.serviceui";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    private static final Insets panelInsets = new Insets(6, 6, 6, 6);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    private static final Insets compInsets = new Insets(3, 6, 3, 6);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    private static ResourceBundle messageRB;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    private JTabbedPane tpTabs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    private JButton btnCancel, btnApprove;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    private PrintService[] services;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    private int defaultServiceIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    private PrintRequestAttributeSet asOriginal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    private HashPrintRequestAttributeSet asCurrent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    private PrintService psCurrent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    private DocFlavor docFlavor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    private int status;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    private ValidatingFileChooser jfc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    private GeneralPanel pnlGeneral;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    private PageSetupPanel pnlPageSetup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    private AppearancePanel pnlAppearance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    private boolean isAWT = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        initResource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * Constructor for the "standard" print dialog (containing all relevant
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * tabs)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    public ServiceDialog(GraphicsConfiguration gc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                         int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                         PrintService[] services,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                         int defaultServiceIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                         DocFlavor flavor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                         PrintRequestAttributeSet attributes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                         Dialog dialog)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        super(dialog, getMsg("dialog.printtitle"), true, gc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        initPrintDialog(x, y, services, defaultServiceIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                        flavor, attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * Constructor for the "standard" print dialog (containing all relevant
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * tabs)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    public ServiceDialog(GraphicsConfiguration gc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                         int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                         PrintService[] services,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                         int defaultServiceIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                         DocFlavor flavor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                         PrintRequestAttributeSet attributes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                         Frame frame)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        super(frame, getMsg("dialog.printtitle"), true, gc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        initPrintDialog(x, y, services, defaultServiceIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                        flavor, attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * Initialize print dialog.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    void initPrintDialog(int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                         PrintService[] services,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                         int defaultServiceIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                         DocFlavor flavor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                         PrintRequestAttributeSet attributes)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        this.services = services;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        this.defaultServiceIndex = defaultServiceIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        this.asOriginal = attributes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        this.asCurrent = new HashPrintRequestAttributeSet(attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        this.psCurrent = services[defaultServiceIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        this.docFlavor = flavor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        SunPageSelection pages =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            (SunPageSelection)attributes.get(SunPageSelection.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        if (pages != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            isAWT = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        Container c = getContentPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        c.setLayout(new BorderLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        tpTabs = new JTabbedPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        tpTabs.setBorder(new EmptyBorder(5, 5, 5, 5));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        String gkey = getMsg("tab.general");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        int gmnemonic = getVKMnemonic("tab.general");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        pnlGeneral = new GeneralPanel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        tpTabs.add(gkey, pnlGeneral);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        tpTabs.setMnemonicAt(0, gmnemonic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        String pkey = getMsg("tab.pagesetup");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        int pmnemonic = getVKMnemonic("tab.pagesetup");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        pnlPageSetup = new PageSetupPanel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        tpTabs.add(pkey, pnlPageSetup);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        tpTabs.setMnemonicAt(1, pmnemonic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        String akey = getMsg("tab.appearance");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        int amnemonic = getVKMnemonic("tab.appearance");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        pnlAppearance = new AppearancePanel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        tpTabs.add(akey, pnlAppearance);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        tpTabs.setMnemonicAt(2, amnemonic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        c.add(tpTabs, BorderLayout.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        updatePanels();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        JPanel pnlSouth = new JPanel(new FlowLayout(FlowLayout.TRAILING));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        btnApprove = createExitButton("button.print", this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        pnlSouth.add(btnApprove);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        getRootPane().setDefaultButton(btnApprove);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        btnCancel = createExitButton("button.cancel", this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        handleEscKey(btnCancel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        pnlSouth.add(btnCancel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        c.add(pnlSouth, BorderLayout.SOUTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        addWindowListener(new WindowAdapter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            public void windowClosing(WindowEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                dispose(CANCEL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        getAccessibleContext().setAccessibleDescription(getMsg("dialog.printtitle"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        setResizable(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        setLocation(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        pack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * Constructor for the solitary "page setup" dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    public ServiceDialog(GraphicsConfiguration gc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                         int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                         PrintService ps,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                         DocFlavor flavor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                         PrintRequestAttributeSet attributes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                         Dialog dialog)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        super(dialog, getMsg("dialog.pstitle"), true, gc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        initPageDialog(x, y, ps, flavor, attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * Constructor for the solitary "page setup" dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    public ServiceDialog(GraphicsConfiguration gc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                         int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                         PrintService ps,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                         DocFlavor flavor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                         PrintRequestAttributeSet attributes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                         Frame frame)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        super(frame, getMsg("dialog.pstitle"), true, gc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        initPageDialog(x, y, ps, flavor, attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * Initialize "page setup" dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    void initPageDialog(int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                         PrintService ps,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                         DocFlavor flavor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                         PrintRequestAttributeSet attributes)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        this.psCurrent = ps;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        this.docFlavor = flavor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        this.asOriginal = attributes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        this.asCurrent = new HashPrintRequestAttributeSet(attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        Container c = getContentPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        c.setLayout(new BorderLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        pnlPageSetup = new PageSetupPanel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        c.add(pnlPageSetup, BorderLayout.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        pnlPageSetup.updateInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        JPanel pnlSouth = new JPanel(new FlowLayout(FlowLayout.TRAILING));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        btnApprove = createExitButton("button.ok", this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        pnlSouth.add(btnApprove);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        getRootPane().setDefaultButton(btnApprove);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        btnCancel = createExitButton("button.cancel", this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        handleEscKey(btnCancel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        pnlSouth.add(btnCancel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        c.add(pnlSouth, BorderLayout.SOUTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        addWindowListener(new WindowAdapter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            public void windowClosing(WindowEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                dispose(CANCEL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        getAccessibleContext().setAccessibleDescription(getMsg("dialog.pstitle"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        setResizable(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        setLocation(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        pack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * Performs Cancel when Esc key is pressed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    private void handleEscKey(JButton btnCancel) {
23648
a95041026433 8037139: Fix serial lint warnings in sun.print
darcy
parents: 23010
diff changeset
   311
        @SuppressWarnings("serial") // anonymous class
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        Action cancelKeyAction = new AbstractAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                dispose(CANCEL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        KeyStroke cancelKeyStroke =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            KeyStroke.getKeyStroke((char)KeyEvent.VK_ESCAPE, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        InputMap inputMap =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            btnCancel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        ActionMap actionMap = btnCancel.getActionMap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        if (inputMap != null && actionMap != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            inputMap.put(cancelKeyStroke, "cancel");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            actionMap.put("cancel", cancelKeyAction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * Returns the current status of the dialog (whether the user has selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * the "Print" or "Cancel" button)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    public int getStatus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        return status;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * Returns an AttributeSet based on whether or not the user cancelled the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * dialog.  If the user selected "Print" we return their new selections,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * otherwise we return the attributes that were passed in initially.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    public PrintRequestAttributeSet getAttributes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        if (status == APPROVE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            return asCurrent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            return asOriginal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * Returns a PrintService based on whether or not the user cancelled the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * dialog.  If the user selected "Print" we return the user's selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * for the PrintService, otherwise we return null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    public PrintService getPrintService() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        if (status == APPROVE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            return psCurrent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * Sets the current status flag for the dialog and disposes it (thus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * returning control of the parent frame back to the user)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    public void dispose(int status) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        this.status = status;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        super.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        Object source = e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        boolean approved = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        if (source == btnApprove) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            approved = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            if (pnlGeneral != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                if (pnlGeneral.isPrintToFileRequested()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                    approved = showFileChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                    asCurrent.remove(Destination.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        dispose(approved ? APPROVE : CANCEL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * Displays a JFileChooser that allows the user to select the destination
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * for "Print To File"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    private boolean showFileChooser() {
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
   398
        Class<Destination> dstCategory = Destination.class;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        Destination dst = (Destination)asCurrent.get(dstCategory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        if (dst == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            dst = (Destination)asOriginal.get(dstCategory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            if (dst == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                dst = (Destination)psCurrent.getDefaultAttributeValue(dstCategory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                // "dst" should not be null. The following code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                // is only added to safeguard against a possible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                // buggy implementation of a PrintService having a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
                // null default Destination.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
                if (dst == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                        dst = new Destination(new URI("file:out.prn"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                    } catch (URISyntaxException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        File fileDest;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        if (dst != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                fileDest = new File(dst.getURI());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                // all manner of runtime exceptions possible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                fileDest = new File("out.prn");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            fileDest = new File("out.prn");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        ValidatingFileChooser jfc = new ValidatingFileChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        jfc.setApproveButtonText(getMsg("button.ok"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        jfc.setDialogTitle(getMsg("dialog.printtofile"));
12995
0a91fe123fa2 7158366: [macosx] Print-to-file dialog doesn't have an entry field for a name
prr
parents: 12520
diff changeset
   433
        jfc.setDialogType(JFileChooser.SAVE_DIALOG);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        jfc.setSelectedFile(fileDest);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        int returnVal = jfc.showDialog(this, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        if (returnVal == JFileChooser.APPROVE_OPTION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            fileDest = jfc.getSelectedFile();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                asCurrent.add(new Destination(fileDest.toURI()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                asCurrent.remove(dstCategory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            asCurrent.remove(dstCategory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        return (returnVal == JFileChooser.APPROVE_OPTION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * Updates each of the top level panels
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    private void updatePanels() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        pnlGeneral.updateInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        pnlPageSetup.updateInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        pnlAppearance.updateInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * Initialize ResourceBundle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    public static void initResource() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        java.security.AccessController.doPrivileged(
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
   466
            new java.security.PrivilegedAction<Object>() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                public Object run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                        messageRB = ResourceBundle.getBundle(strBundle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                    } catch (java.util.MissingResourceException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                        throw new Error("Fatal: Resource for ServiceUI " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                                        "is missing");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * Returns message string from resource
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    public static String getMsg(String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        try {
12520
9d6777f588d4 7013850: Please change the mnemonic assignment system to avoid translation issue
jgodinez
parents: 5506
diff changeset
   485
            return removeMnemonics(messageRB.getString(key));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        } catch (java.util.MissingResourceException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
            throw new Error("Fatal: Resource for ServiceUI is broken; " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                            "there is no " + key + " key in resource");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
12520
9d6777f588d4 7013850: Please change the mnemonic assignment system to avoid translation issue
jgodinez
parents: 5506
diff changeset
   492
    private static String removeMnemonics(String s) {
9d6777f588d4 7013850: Please change the mnemonic assignment system to avoid translation issue
jgodinez
parents: 5506
diff changeset
   493
        int i = s.indexOf('&');
9d6777f588d4 7013850: Please change the mnemonic assignment system to avoid translation issue
jgodinez
parents: 5506
diff changeset
   494
        int len = s.length();
9d6777f588d4 7013850: Please change the mnemonic assignment system to avoid translation issue
jgodinez
parents: 5506
diff changeset
   495
        if (i < 0 || i == (len - 1)) {
9d6777f588d4 7013850: Please change the mnemonic assignment system to avoid translation issue
jgodinez
parents: 5506
diff changeset
   496
            return s;
9d6777f588d4 7013850: Please change the mnemonic assignment system to avoid translation issue
jgodinez
parents: 5506
diff changeset
   497
        }
9d6777f588d4 7013850: Please change the mnemonic assignment system to avoid translation issue
jgodinez
parents: 5506
diff changeset
   498
        int j = s.indexOf('&', i+1);
9d6777f588d4 7013850: Please change the mnemonic assignment system to avoid translation issue
jgodinez
parents: 5506
diff changeset
   499
        if (j == i+1) {
9d6777f588d4 7013850: Please change the mnemonic assignment system to avoid translation issue
jgodinez
parents: 5506
diff changeset
   500
            if (j+1 == len) {
9d6777f588d4 7013850: Please change the mnemonic assignment system to avoid translation issue
jgodinez
parents: 5506
diff changeset
   501
                return s.substring(0, i+1);  // string ends with &&
9d6777f588d4 7013850: Please change the mnemonic assignment system to avoid translation issue
jgodinez
parents: 5506
diff changeset
   502
            } else {
9d6777f588d4 7013850: Please change the mnemonic assignment system to avoid translation issue
jgodinez
parents: 5506
diff changeset
   503
                return s.substring(0, i+1) + removeMnemonics(s.substring(j+1));
9d6777f588d4 7013850: Please change the mnemonic assignment system to avoid translation issue
jgodinez
parents: 5506
diff changeset
   504
            }
9d6777f588d4 7013850: Please change the mnemonic assignment system to avoid translation issue
jgodinez
parents: 5506
diff changeset
   505
        }
9d6777f588d4 7013850: Please change the mnemonic assignment system to avoid translation issue
jgodinez
parents: 5506
diff changeset
   506
        // ok first & not double &&
9d6777f588d4 7013850: Please change the mnemonic assignment system to avoid translation issue
jgodinez
parents: 5506
diff changeset
   507
        if (i == 0) {
9d6777f588d4 7013850: Please change the mnemonic assignment system to avoid translation issue
jgodinez
parents: 5506
diff changeset
   508
            return removeMnemonics(s.substring(1));
9d6777f588d4 7013850: Please change the mnemonic assignment system to avoid translation issue
jgodinez
parents: 5506
diff changeset
   509
        } else {
9d6777f588d4 7013850: Please change the mnemonic assignment system to avoid translation issue
jgodinez
parents: 5506
diff changeset
   510
            return (s.substring(0, i) + removeMnemonics(s.substring(i+1)));
9d6777f588d4 7013850: Please change the mnemonic assignment system to avoid translation issue
jgodinez
parents: 5506
diff changeset
   511
        }
9d6777f588d4 7013850: Please change the mnemonic assignment system to avoid translation issue
jgodinez
parents: 5506
diff changeset
   512
    }
9d6777f588d4 7013850: Please change the mnemonic assignment system to avoid translation issue
jgodinez
parents: 5506
diff changeset
   513
9d6777f588d4 7013850: Please change the mnemonic assignment system to avoid translation issue
jgodinez
parents: 5506
diff changeset
   514
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     * Returns mnemonic character from resource
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    private static char getMnemonic(String key) {
12520
9d6777f588d4 7013850: Please change the mnemonic assignment system to avoid translation issue
jgodinez
parents: 5506
diff changeset
   519
        String str = messageRB.getString(key).replace("&&", "");
9d6777f588d4 7013850: Please change the mnemonic assignment system to avoid translation issue
jgodinez
parents: 5506
diff changeset
   520
        int index = str.indexOf('&');
9d6777f588d4 7013850: Please change the mnemonic assignment system to avoid translation issue
jgodinez
parents: 5506
diff changeset
   521
        if (0 <= index && index < str.length() - 1) {
9d6777f588d4 7013850: Please change the mnemonic assignment system to avoid translation issue
jgodinez
parents: 5506
diff changeset
   522
            char c = str.charAt(index + 1);
9d6777f588d4 7013850: Please change the mnemonic assignment system to avoid translation issue
jgodinez
parents: 5506
diff changeset
   523
            return Character.toUpperCase(c);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
            return (char)0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     * Returns the mnemonic as a KeyEvent.VK constant from the resource.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     */
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
   532
    static Class<?> _keyEventClazz = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    private static int getVKMnemonic(String key) {
12520
9d6777f588d4 7013850: Please change the mnemonic assignment system to avoid translation issue
jgodinez
parents: 5506
diff changeset
   534
        String s = String.valueOf(getMnemonic(key));
9d6777f588d4 7013850: Please change the mnemonic assignment system to avoid translation issue
jgodinez
parents: 5506
diff changeset
   535
        if ( s == null || s.length() != 1) {
9d6777f588d4 7013850: Please change the mnemonic assignment system to avoid translation issue
jgodinez
parents: 5506
diff changeset
   536
            return 0;
9d6777f588d4 7013850: Please change the mnemonic assignment system to avoid translation issue
jgodinez
parents: 5506
diff changeset
   537
        }
9d6777f588d4 7013850: Please change the mnemonic assignment system to avoid translation issue
jgodinez
parents: 5506
diff changeset
   538
        String vkString = "VK_" + s.toUpperCase();
9d6777f588d4 7013850: Please change the mnemonic assignment system to avoid translation issue
jgodinez
parents: 5506
diff changeset
   539
9d6777f588d4 7013850: Please change the mnemonic assignment system to avoid translation issue
jgodinez
parents: 5506
diff changeset
   540
        try {
9d6777f588d4 7013850: Please change the mnemonic assignment system to avoid translation issue
jgodinez
parents: 5506
diff changeset
   541
            if (_keyEventClazz == null) {
9d6777f588d4 7013850: Please change the mnemonic assignment system to avoid translation issue
jgodinez
parents: 5506
diff changeset
   542
                _keyEventClazz= Class.forName("java.awt.event.KeyEvent",
9d6777f588d4 7013850: Please change the mnemonic assignment system to avoid translation issue
jgodinez
parents: 5506
diff changeset
   543
                                 true, (ServiceDialog.class).getClassLoader());
9d6777f588d4 7013850: Please change the mnemonic assignment system to avoid translation issue
jgodinez
parents: 5506
diff changeset
   544
            }
9d6777f588d4 7013850: Please change the mnemonic assignment system to avoid translation issue
jgodinez
parents: 5506
diff changeset
   545
            Field field = _keyEventClazz.getDeclaredField(vkString);
9d6777f588d4 7013850: Please change the mnemonic assignment system to avoid translation issue
jgodinez
parents: 5506
diff changeset
   546
            int value = field.getInt(null);
9d6777f588d4 7013850: Please change the mnemonic assignment system to avoid translation issue
jgodinez
parents: 5506
diff changeset
   547
            return value;
9d6777f588d4 7013850: Please change the mnemonic assignment system to avoid translation issue
jgodinez
parents: 5506
diff changeset
   548
        } catch (Exception e) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     * Returns URL for image resource
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    private static URL getImageResource(final String key) {
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
   557
        URL url = java.security.AccessController.doPrivileged(
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
   558
                       new java.security.PrivilegedAction<URL>() {
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
   559
                public URL run() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                    URL url = ServiceDialog.class.getResource(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                                                  "resources/" + key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                    return url;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        if (url == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
            throw new Error("Fatal: Resource for ServiceUI is broken; " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                            "there is no " + key + " key in resource");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        return url;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     * Creates a new JButton and sets its text, mnemonic, and ActionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    private static JButton createButton(String key, ActionListener al) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        JButton btn = new JButton(getMsg(key));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        btn.setMnemonic(getMnemonic(key));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        btn.addActionListener(al);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        return btn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     * Creates a new JButton and sets its text, and ActionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    private static JButton createExitButton(String key, ActionListener al) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        String str = getMsg(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        JButton btn = new JButton(str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        btn.addActionListener(al);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        btn.getAccessibleContext().setAccessibleDescription(str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        return btn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     * Creates a new JCheckBox and sets its text, mnemonic, and ActionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
    private static JCheckBox createCheckBox(String key, ActionListener al) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        JCheckBox cb = new JCheckBox(getMsg(key));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        cb.setMnemonic(getMnemonic(key));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        cb.addActionListener(al);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        return cb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * Creates a new JRadioButton and sets its text, mnemonic,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     * and ActionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
    private static JRadioButton createRadioButton(String key,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                                                  ActionListener al)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        JRadioButton rb = new JRadioButton(getMsg(key));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        rb.setMnemonic(getMnemonic(key));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        rb.addActionListener(al);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        return rb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
  /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
   * Creates a  pop-up dialog for "no print service"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    public static void showNoPrintService(GraphicsConfiguration gc)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        Frame dlgFrame = new Frame(gc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        JOptionPane.showMessageDialog(dlgFrame,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
                                      getMsg("dialog.noprintermsg"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        dlgFrame.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     * Sets the constraints for the GridBagLayout and adds the Component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     * to the given Container
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
    private static void addToGB(Component comp, Container cont,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
                                GridBagLayout gridbag,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
                                GridBagConstraints constraints)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        gridbag.setConstraints(comp, constraints);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        cont.add(comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     * Adds the AbstractButton to both the given ButtonGroup and Container
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
    private static void addToBG(AbstractButton button, Container cont,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
                                ButtonGroup bg)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
        bg.add(button);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        cont.add(button);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     * The "General" tab.  Includes the controls for PrintService,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     * PageRange, and Copies/Collate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     */
23648
a95041026433 8037139: Fix serial lint warnings in sun.print
darcy
parents: 23010
diff changeset
   661
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
    private class GeneralPanel extends JPanel {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        private PrintServicePanel pnlPrintService;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        private PrintRangePanel pnlPrintRange;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
        private CopiesPanel pnlCopies;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
        public GeneralPanel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
            super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
            GridBagLayout gridbag = new GridBagLayout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
            GridBagConstraints c = new GridBagConstraints();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
            setLayout(gridbag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
            c.fill = GridBagConstraints.BOTH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
            c.insets = panelInsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
            c.weightx = 1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
            c.weighty = 1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
            c.gridwidth = GridBagConstraints.REMAINDER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
            pnlPrintService = new PrintServicePanel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
            addToGB(pnlPrintService, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
            c.gridwidth = GridBagConstraints.RELATIVE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
            pnlPrintRange = new PrintRangePanel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
            addToGB(pnlPrintRange, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
            c.gridwidth = GridBagConstraints.REMAINDER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
            pnlCopies = new CopiesPanel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
            addToGB(pnlCopies, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
        public boolean isPrintToFileRequested() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
            return (pnlPrintService.isPrintToFileSelected());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        public void updateInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
            pnlPrintService.updateInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
            pnlPrintRange.updateInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
            pnlCopies.updateInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
23648
a95041026433 8037139: Fix serial lint warnings in sun.print
darcy
parents: 23010
diff changeset
   705
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
    private class PrintServicePanel extends JPanel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
        implements ActionListener, ItemListener, PopupMenuListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        private final String strTitle = getMsg("border.printservice");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        private FilePermission printToFilePermission;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        private JButton btnProperties;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
        private JCheckBox cbPrintToFile;
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
   713
        private JComboBox<String> cbName;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        private JLabel lblType, lblStatus, lblInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
        private ServiceUIFactory uiFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        private boolean changedService = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        private boolean filePermission;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
        public PrintServicePanel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
            super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
            uiFactory = psCurrent.getServiceUIFactory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
            GridBagLayout gridbag = new GridBagLayout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
            GridBagConstraints c = new GridBagConstraints();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
            setLayout(gridbag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
            setBorder(BorderFactory.createTitledBorder(strTitle));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
            String[] psnames = new String[services.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
            for (int i = 0; i < psnames.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
                psnames[i] = services[i].getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
            }
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
   734
            cbName = new JComboBox<>(psnames);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
            cbName.setSelectedIndex(defaultServiceIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
            cbName.addItemListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
            cbName.addPopupMenuListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
            c.fill = GridBagConstraints.BOTH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
            c.insets = compInsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
            c.weightx = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
            JLabel lblName = new JLabel(getMsg("label.psname"), JLabel.TRAILING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
            lblName.setDisplayedMnemonic(getMnemonic("label.psname"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
            lblName.setLabelFor(cbName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
            addToGB(lblName, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
            c.weightx = 1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
            c.gridwidth = GridBagConstraints.RELATIVE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
            addToGB(cbName, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
            c.weightx = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
            c.gridwidth = GridBagConstraints.REMAINDER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
            btnProperties = createButton("button.properties", this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
            addToGB(btnProperties, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
            c.weighty = 1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
            lblStatus = addLabel(getMsg("label.status"), gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
            lblStatus.setLabelFor(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
            lblType = addLabel(getMsg("label.pstype"), gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
            lblType.setLabelFor(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
            c.gridwidth = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
            addToGB(new JLabel(getMsg("label.info"), JLabel.TRAILING),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
                    this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
            c.gridwidth = GridBagConstraints.RELATIVE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
            lblInfo = new JLabel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
            lblInfo.setLabelFor(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
            addToGB(lblInfo, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
            c.gridwidth = GridBagConstraints.REMAINDER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
            cbPrintToFile = createCheckBox("checkbox.printtofile", this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
            addToGB(cbPrintToFile, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
            filePermission = allowedToPrintToFile();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
        public boolean isPrintToFileSelected() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
            return cbPrintToFile.isSelected();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
        private JLabel addLabel(String text,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
                                GridBagLayout gridbag, GridBagConstraints c)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
            c.gridwidth = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
            addToGB(new JLabel(text, JLabel.TRAILING), this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
            c.gridwidth = GridBagConstraints.REMAINDER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
            JLabel label = new JLabel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
            addToGB(label, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
            return label;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
28231
b608ffcaed74 8066621: Suppress deprecation warnings in java.desktop module
darcy
parents: 25859
diff changeset
   795
        @SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
            Object source = e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
            if (source == btnProperties) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
                if (uiFactory != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
                    JDialog dialog = (JDialog)uiFactory.getUI(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
                                               ServiceUIFactory.MAIN_UIROLE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
                                               ServiceUIFactory.JDIALOG_UI);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
                    if (dialog != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
                        dialog.show();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
                    } else {
19781
91b06f016821 4673406: RFE: Java Printing: Provide a way to display win32 printer driver's dialog
prr
parents: 14342
diff changeset
   808
                        DocumentPropertiesUI docPropertiesUI = null;
91b06f016821 4673406: RFE: Java Printing: Provide a way to display win32 printer driver's dialog
prr
parents: 14342
diff changeset
   809
                        try {
91b06f016821 4673406: RFE: Java Printing: Provide a way to display win32 printer driver's dialog
prr
parents: 14342
diff changeset
   810
                            docPropertiesUI =
91b06f016821 4673406: RFE: Java Printing: Provide a way to display win32 printer driver's dialog
prr
parents: 14342
diff changeset
   811
                                (DocumentPropertiesUI)uiFactory.getUI
91b06f016821 4673406: RFE: Java Printing: Provide a way to display win32 printer driver's dialog
prr
parents: 14342
diff changeset
   812
                                (DocumentPropertiesUI.DOCUMENTPROPERTIES_ROLE,
91b06f016821 4673406: RFE: Java Printing: Provide a way to display win32 printer driver's dialog
prr
parents: 14342
diff changeset
   813
                                 DocumentPropertiesUI.DOCPROPERTIESCLASSNAME);
91b06f016821 4673406: RFE: Java Printing: Provide a way to display win32 printer driver's dialog
prr
parents: 14342
diff changeset
   814
                        } catch (Exception ex) {
91b06f016821 4673406: RFE: Java Printing: Provide a way to display win32 printer driver's dialog
prr
parents: 14342
diff changeset
   815
                        }
91b06f016821 4673406: RFE: Java Printing: Provide a way to display win32 printer driver's dialog
prr
parents: 14342
diff changeset
   816
                        if (docPropertiesUI != null) {
91b06f016821 4673406: RFE: Java Printing: Provide a way to display win32 printer driver's dialog
prr
parents: 14342
diff changeset
   817
                            PrinterJobWrapper wrapper = (PrinterJobWrapper)
91b06f016821 4673406: RFE: Java Printing: Provide a way to display win32 printer driver's dialog
prr
parents: 14342
diff changeset
   818
                                asCurrent.get(PrinterJobWrapper.class);
91b06f016821 4673406: RFE: Java Printing: Provide a way to display win32 printer driver's dialog
prr
parents: 14342
diff changeset
   819
                            if (wrapper == null) {
91b06f016821 4673406: RFE: Java Printing: Provide a way to display win32 printer driver's dialog
prr
parents: 14342
diff changeset
   820
                                return; // should not happen, defensive only.
91b06f016821 4673406: RFE: Java Printing: Provide a way to display win32 printer driver's dialog
prr
parents: 14342
diff changeset
   821
                            }
91b06f016821 4673406: RFE: Java Printing: Provide a way to display win32 printer driver's dialog
prr
parents: 14342
diff changeset
   822
                            PrinterJob job = wrapper.getPrinterJob();
91b06f016821 4673406: RFE: Java Printing: Provide a way to display win32 printer driver's dialog
prr
parents: 14342
diff changeset
   823
                            if (job == null) {
91b06f016821 4673406: RFE: Java Printing: Provide a way to display win32 printer driver's dialog
prr
parents: 14342
diff changeset
   824
                                return;  // should not happen, defensive only.
91b06f016821 4673406: RFE: Java Printing: Provide a way to display win32 printer driver's dialog
prr
parents: 14342
diff changeset
   825
                            }
91b06f016821 4673406: RFE: Java Printing: Provide a way to display win32 printer driver's dialog
prr
parents: 14342
diff changeset
   826
                            PrintRequestAttributeSet newAttrs =
91b06f016821 4673406: RFE: Java Printing: Provide a way to display win32 printer driver's dialog
prr
parents: 14342
diff changeset
   827
                               docPropertiesUI.showDocumentProperties
91b06f016821 4673406: RFE: Java Printing: Provide a way to display win32 printer driver's dialog
prr
parents: 14342
diff changeset
   828
                               (job, ServiceDialog.this, psCurrent, asCurrent);
91b06f016821 4673406: RFE: Java Printing: Provide a way to display win32 printer driver's dialog
prr
parents: 14342
diff changeset
   829
                            if (newAttrs != null) {
91b06f016821 4673406: RFE: Java Printing: Provide a way to display win32 printer driver's dialog
prr
parents: 14342
diff changeset
   830
                                asCurrent.addAll(newAttrs);
91b06f016821 4673406: RFE: Java Printing: Provide a way to display win32 printer driver's dialog
prr
parents: 14342
diff changeset
   831
                                updatePanels();
91b06f016821 4673406: RFE: Java Printing: Provide a way to display win32 printer driver's dialog
prr
parents: 14342
diff changeset
   832
                            }
91b06f016821 4673406: RFE: Java Printing: Provide a way to display win32 printer driver's dialog
prr
parents: 14342
diff changeset
   833
                        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
        public void itemStateChanged(ItemEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
            if (e.getStateChange() == ItemEvent.SELECTED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
                int index = cbName.getSelectedIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
                if ((index >= 0) && (index < services.length)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
                    if (!services[index].equals(psCurrent)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
                        psCurrent = services[index];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
                        uiFactory = psCurrent.getServiceUIFactory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
                        changedService = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
                        Destination dest =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
                            (Destination)asOriginal.get(Destination.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
                        // to preserve the state of Print To File
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
                        if ((dest != null || isPrintToFileSelected())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
                            && psCurrent.isAttributeCategorySupported(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
                                                        Destination.class)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
                            if (dest != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
                                asCurrent.add(dest);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
                            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
                                dest = (Destination)psCurrent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
                                    getDefaultAttributeValue(Destination.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
                                // "dest" should not be null. The following code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
                                // is only added to safeguard against a possible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
                                // buggy implementation of a PrintService having a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
                                // null default Destination.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
                                if (dest == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
                                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
                                        dest =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
                                            new Destination(new URI("file:out.prn"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
                                    } catch (URISyntaxException ue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
                                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
                                if (dest != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
                                    asCurrent.add(dest);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
                            asCurrent.remove(Destination.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
        public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
            changedService = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
        public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
            if (changedService) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
                changedService = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
                updatePanels();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
        public void popupMenuCanceled(PopupMenuEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
         * We disable the "Print To File" checkbox if this returns false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
        private boolean allowedToPrintToFile() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
                throwPrintToFile();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
            } catch (SecurityException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
         * Break this out as it may be useful when we allow API to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
         * specify printing to a file. In that case its probably right
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
         * to throw a SecurityException if the permission is not granted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
        private void throwPrintToFile() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
            SecurityManager security = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
            if (security != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
                if (printToFilePermission == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
                    printToFilePermission =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
                        new FilePermission("<<ALL FILES>>", "read,write");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
                security.checkPermission(printToFilePermission);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
        public void updateInfo() {
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
   928
            Class<Destination> dstCategory = Destination.class;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
            boolean dstSupported = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
            boolean dstSelected = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
            boolean dstAllowed = filePermission ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
                allowedToPrintToFile() : false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
            // setup Destination (print-to-file) widgets
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
            Destination dst = (Destination)asCurrent.get(dstCategory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
            if (dst != null) {
39847
8d41728f649b 5049012: PrintToFile option is not disabled for flavors that do not support destination
psadhukhan
parents: 38983
diff changeset
   937
                try {
8d41728f649b 5049012: PrintToFile option is not disabled for flavors that do not support destination
psadhukhan
parents: 38983
diff changeset
   938
                     dst.getURI().toURL();
8d41728f649b 5049012: PrintToFile option is not disabled for flavors that do not support destination
psadhukhan
parents: 38983
diff changeset
   939
                     if (psCurrent.isAttributeValueSupported(dst, docFlavor,
8d41728f649b 5049012: PrintToFile option is not disabled for flavors that do not support destination
psadhukhan
parents: 38983
diff changeset
   940
                                                             asCurrent)) {
8d41728f649b 5049012: PrintToFile option is not disabled for flavors that do not support destination
psadhukhan
parents: 38983
diff changeset
   941
                         dstSupported = true;
8d41728f649b 5049012: PrintToFile option is not disabled for flavors that do not support destination
psadhukhan
parents: 38983
diff changeset
   942
                         dstSelected = true;
8d41728f649b 5049012: PrintToFile option is not disabled for flavors that do not support destination
psadhukhan
parents: 38983
diff changeset
   943
                     }
8d41728f649b 5049012: PrintToFile option is not disabled for flavors that do not support destination
psadhukhan
parents: 38983
diff changeset
   944
                 } catch (MalformedURLException ex) {
8d41728f649b 5049012: PrintToFile option is not disabled for flavors that do not support destination
psadhukhan
parents: 38983
diff changeset
   945
                     dstSupported = true;
8d41728f649b 5049012: PrintToFile option is not disabled for flavors that do not support destination
psadhukhan
parents: 38983
diff changeset
   946
                 }
40714
b25cd91f5dd2 8163922: Print-to-file is disabled for SERVICE_FORMATTED docflavor in linux
psadhukhan
parents: 40431
diff changeset
   947
            } else {
b25cd91f5dd2 8163922: Print-to-file is disabled for SERVICE_FORMATTED docflavor in linux
psadhukhan
parents: 40431
diff changeset
   948
                if (psCurrent.isAttributeCategorySupported(dstCategory)) {
b25cd91f5dd2 8163922: Print-to-file is disabled for SERVICE_FORMATTED docflavor in linux
psadhukhan
parents: 40431
diff changeset
   949
                    dstSupported = true;
b25cd91f5dd2 8163922: Print-to-file is disabled for SERVICE_FORMATTED docflavor in linux
psadhukhan
parents: 40431
diff changeset
   950
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
            cbPrintToFile.setEnabled(dstSupported && dstAllowed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
            cbPrintToFile.setSelected(dstSelected && dstAllowed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
                                      && dstSupported);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
            // setup PrintService information widgets
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
            Attribute type = psCurrent.getAttribute(PrinterMakeAndModel.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
            if (type != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
                lblType.setText(type.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
            Attribute status =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
                psCurrent.getAttribute(PrinterIsAcceptingJobs.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
            if (status != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
                lblStatus.setText(getMsg(status.toString()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
            Attribute info = psCurrent.getAttribute(PrinterInfo.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
            if (info != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
                lblInfo.setText(info.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
            btnProperties.setEnabled(uiFactory != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
23648
a95041026433 8037139: Fix serial lint warnings in sun.print
darcy
parents: 23010
diff changeset
   974
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
    private class PrintRangePanel extends JPanel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
        implements ActionListener, FocusListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
        private final String strTitle = getMsg("border.printrange");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
        private final PageRanges prAll = new PageRanges(1, Integer.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
        private JRadioButton rbAll, rbPages, rbSelect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
        private JFormattedTextField tfRangeFrom, tfRangeTo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
        private JLabel lblRangeTo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
        private boolean prSupported;
40431
50d30cb5c70b 5080098: Page Range must be disabled on the common print dlg for Non serv-formatted flvrs
psadhukhan
parents: 40172
diff changeset
   984
        private boolean prPgRngSupported;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
        public PrintRangePanel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
            super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
            GridBagLayout gridbag = new GridBagLayout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
            GridBagConstraints c = new GridBagConstraints();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
            setLayout(gridbag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
            setBorder(BorderFactory.createTitledBorder(strTitle));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
            c.fill = GridBagConstraints.BOTH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
            c.insets = compInsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
            c.gridwidth = GridBagConstraints.REMAINDER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
            ButtonGroup bg = new ButtonGroup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
            JPanel pnlTop = new JPanel(new FlowLayout(FlowLayout.LEADING));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
            rbAll = createRadioButton("radiobutton.rangeall", this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
            rbAll.setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
            bg.add(rbAll);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
            pnlTop.add(rbAll);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
            addToGB(pnlTop, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
            // Selection never seemed to work so I'm commenting this part.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
            if (isAWT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
                JPanel pnlMiddle  =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
                    new JPanel(new FlowLayout(FlowLayout.LEADING));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
                rbSelect =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
                    createRadioButton("radiobutton.selection", this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
                bg.add(rbSelect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
                pnlMiddle.add(rbSelect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
                addToGB(pnlMiddle, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
            */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
            JPanel pnlBottom = new JPanel(new FlowLayout(FlowLayout.LEADING));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
            rbPages = createRadioButton("radiobutton.rangepages", this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
            bg.add(rbPages);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
            pnlBottom.add(rbPages);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
            DecimalFormat format = new DecimalFormat("####0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
            format.setMinimumFractionDigits(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
            format.setMaximumFractionDigits(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
            format.setMinimumIntegerDigits(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
            format.setMaximumIntegerDigits(5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
            format.setParseIntegerOnly(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
            format.setDecimalSeparatorAlwaysShown(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
            NumberFormatter nf = new NumberFormatter(format);
25777
bb88947b6766 8049893: Replace uses of 'new Integer()' with appropriate alternative across client classes
prr
parents: 25140
diff changeset
  1032
            nf.setMinimum(1);
bb88947b6766 8049893: Replace uses of 'new Integer()' with appropriate alternative across client classes
prr
parents: 25140
diff changeset
  1033
            nf.setMaximum(Integer.MAX_VALUE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
            nf.setAllowsInvalid(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
            nf.setCommitsOnValidEdit(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
            tfRangeFrom = new JFormattedTextField(nf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
            tfRangeFrom.setColumns(4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
            tfRangeFrom.setEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
            tfRangeFrom.addActionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
            tfRangeFrom.addFocusListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
            tfRangeFrom.setFocusLostBehavior(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
                JFormattedTextField.PERSIST);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
            tfRangeFrom.getAccessibleContext().setAccessibleName(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
                                          getMsg("radiobutton.rangepages"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
            pnlBottom.add(tfRangeFrom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
            lblRangeTo = new JLabel(getMsg("label.rangeto"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
            lblRangeTo.setEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
            pnlBottom.add(lblRangeTo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
            NumberFormatter nfto;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
                nfto = (NumberFormatter)nf.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
            } catch (CloneNotSupportedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
                nfto = new NumberFormatter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
            tfRangeTo = new JFormattedTextField(nfto);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
            tfRangeTo.setColumns(4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
            tfRangeTo.setEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
            tfRangeTo.addFocusListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
            tfRangeTo.getAccessibleContext().setAccessibleName(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
                                          getMsg("label.rangeto"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
            pnlBottom.add(tfRangeTo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
            addToGB(pnlBottom, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
            Object source = e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
            SunPageSelection select = SunPageSelection.ALL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
            setupRangeWidgets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
            if (source == rbAll) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
                asCurrent.add(prAll);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
            } else if (source == rbSelect) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
                select = SunPageSelection.SELECTION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
            } else if (source == rbPages ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
                       source == tfRangeFrom ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
                       source == tfRangeTo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
                updateRangeAttribute();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
                select = SunPageSelection.RANGE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
            if (isAWT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
                asCurrent.add(select);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
        public void focusLost(FocusEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
            Object source = e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
            if ((source == tfRangeFrom) || (source == tfRangeTo)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
                updateRangeAttribute();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
        public void focusGained(FocusEvent e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
        private void setupRangeWidgets() {
40431
50d30cb5c70b 5080098: Page Range must be disabled on the common print dlg for Non serv-formatted flvrs
psadhukhan
parents: 40172
diff changeset
  1098
            boolean rangeEnabled = (rbPages.isSelected() && prPgRngSupported);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
            tfRangeFrom.setEnabled(rangeEnabled);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
            tfRangeTo.setEnabled(rangeEnabled);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
            lblRangeTo.setEnabled(rangeEnabled);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
        private void updateRangeAttribute() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
            String strFrom = tfRangeFrom.getText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
            String strTo = tfRangeTo.getText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
            int min;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
            int max;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
                min = Integer.parseInt(strFrom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
            } catch (NumberFormatException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
                min = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
                max = Integer.parseInt(strTo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
            } catch (NumberFormatException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
                max = min;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
            if (min < 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
                min = 1;
25777
bb88947b6766 8049893: Replace uses of 'new Integer()' with appropriate alternative across client classes
prr
parents: 25140
diff changeset
  1125
                tfRangeFrom.setValue(1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
            if (max < min) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
                max = min;
25777
bb88947b6766 8049893: Replace uses of 'new Integer()' with appropriate alternative across client classes
prr
parents: 25140
diff changeset
  1130
                tfRangeTo.setValue(min);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
            PageRanges pr = new PageRanges(min, max);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
            asCurrent.add(pr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
        public void updateInfo() {
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  1138
            Class<PageRanges> prCategory = PageRanges.class;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
            prSupported = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
            if (psCurrent.isAttributeCategorySupported(prCategory) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
                   isAWT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
                prSupported = true;
40431
50d30cb5c70b 5080098: Page Range must be disabled on the common print dlg for Non serv-formatted flvrs
psadhukhan
parents: 40172
diff changeset
  1144
                prPgRngSupported = psCurrent.isAttributeValueSupported(prAll,
50d30cb5c70b 5080098: Page Range must be disabled on the common print dlg for Non serv-formatted flvrs
psadhukhan
parents: 40172
diff changeset
  1145
                                                                     docFlavor,
50d30cb5c70b 5080098: Page Range must be disabled on the common print dlg for Non serv-formatted flvrs
psadhukhan
parents: 40172
diff changeset
  1146
                                                                     asCurrent);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
            SunPageSelection select = SunPageSelection.ALL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
            int min = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
            int max = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
            PageRanges pr = (PageRanges)asCurrent.get(prCategory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
            if (pr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
                if (!pr.equals(prAll)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
                    select = SunPageSelection.RANGE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
                    int[][] members = pr.getMembers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
                    if ((members.length > 0) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
                        (members[0].length > 1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
                        min = members[0][0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
                        max = members[0][1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
            if (isAWT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
                select = (SunPageSelection)asCurrent.get(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
                                                SunPageSelection.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
            if (select == SunPageSelection.ALL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
                rbAll.setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
            } else if (select == SunPageSelection.SELECTION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
                // Comment this for now -  rbSelect is not initialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
                // because Selection button is not added.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
                // See PrintRangePanel above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
                //rbSelect.setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
            } else { // RANGE
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
                rbPages.setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
            }
25777
bb88947b6766 8049893: Replace uses of 'new Integer()' with appropriate alternative across client classes
prr
parents: 25140
diff changeset
  1183
            tfRangeFrom.setValue(min);
bb88947b6766 8049893: Replace uses of 'new Integer()' with appropriate alternative across client classes
prr
parents: 25140
diff changeset
  1184
            tfRangeTo.setValue(max);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
            rbAll.setEnabled(prSupported);
40431
50d30cb5c70b 5080098: Page Range must be disabled on the common print dlg for Non serv-formatted flvrs
psadhukhan
parents: 40172
diff changeset
  1186
            rbPages.setEnabled(prPgRngSupported);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
            setupRangeWidgets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
23648
a95041026433 8037139: Fix serial lint warnings in sun.print
darcy
parents: 23010
diff changeset
  1191
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
    private class CopiesPanel extends JPanel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
        implements ActionListener, ChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
        private final String strTitle = getMsg("border.copies");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
        private SpinnerNumberModel snModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
        private JSpinner spinCopies;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
        private JLabel lblCopies;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
        private JCheckBox cbCollate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
        private boolean scSupported;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
        public CopiesPanel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
            super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
            GridBagLayout gridbag = new GridBagLayout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
            GridBagConstraints c = new GridBagConstraints();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
            setLayout(gridbag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
            setBorder(BorderFactory.createTitledBorder(strTitle));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
            c.fill = GridBagConstraints.HORIZONTAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
            c.insets = compInsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
            lblCopies = new JLabel(getMsg("label.numcopies"), JLabel.TRAILING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
            lblCopies.setDisplayedMnemonic(getMnemonic("label.numcopies"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
            lblCopies.getAccessibleContext().setAccessibleName(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
                                             getMsg("label.numcopies"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
            addToGB(lblCopies, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
            snModel = new SpinnerNumberModel(1, 1, 999, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
            spinCopies = new JSpinner(snModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
            lblCopies.setLabelFor(spinCopies);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
            // REMIND
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
            ((JSpinner.NumberEditor)spinCopies.getEditor()).getTextField().setColumns(3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
            spinCopies.addChangeListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
            c.gridwidth = GridBagConstraints.REMAINDER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
            addToGB(spinCopies, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
            cbCollate = createCheckBox("checkbox.collate", this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
            cbCollate.setEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
            addToGB(cbCollate, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
            if (cbCollate.isSelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
                asCurrent.add(SheetCollate.COLLATED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
                asCurrent.add(SheetCollate.UNCOLLATED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
        public void stateChanged(ChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
            updateCollateCB();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
            asCurrent.add(new Copies(snModel.getNumber().intValue()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
        private void updateCollateCB() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
            int num = snModel.getNumber().intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
            if (isAWT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
                cbCollate.setEnabled(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
                cbCollate.setEnabled((num > 1) && scSupported);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
        public void updateInfo() {
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  1258
            Class<Copies> cpCategory = Copies.class;
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  1259
            Class<SheetCollate> scCategory = SheetCollate.class;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
            boolean cpSupported = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
            scSupported = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
            // setup Copies spinner
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
            if (psCurrent.isAttributeCategorySupported(cpCategory)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
                cpSupported = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
            CopiesSupported cs =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
                (CopiesSupported)psCurrent.getSupportedAttributeValues(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
                                                       cpCategory, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
            if (cs == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
                cs = new CopiesSupported(1, 999);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
            Copies cp = (Copies)asCurrent.get(cpCategory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
            if (cp == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
                cp = (Copies)psCurrent.getDefaultAttributeValue(cpCategory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
                if (cp == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
                    cp = new Copies(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
            spinCopies.setEnabled(cpSupported);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
            lblCopies.setEnabled(cpSupported);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
            int[][] members = cs.getMembers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
            int min, max;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
            if ((members.length > 0) && (members[0].length > 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
                min = members[0][0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
                max = members[0][1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
                min = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
                max = Integer.MAX_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
            }
25777
bb88947b6766 8049893: Replace uses of 'new Integer()' with appropriate alternative across client classes
prr
parents: 25140
diff changeset
  1292
            snModel.setMinimum(min);
bb88947b6766 8049893: Replace uses of 'new Integer()' with appropriate alternative across client classes
prr
parents: 25140
diff changeset
  1293
            snModel.setMaximum(max);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
            int value = cp.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
            if ((value < min) || (value > max)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
                value = min;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
            }
25777
bb88947b6766 8049893: Replace uses of 'new Integer()' with appropriate alternative across client classes
prr
parents: 25140
diff changeset
  1299
            snModel.setValue(value);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
            // setup Collate checkbox
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
            if (psCurrent.isAttributeCategorySupported(scCategory)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
                scSupported = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
            SheetCollate sc = (SheetCollate)asCurrent.get(scCategory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
            if (sc == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
                sc = (SheetCollate)psCurrent.getDefaultAttributeValue(scCategory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
                if (sc == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
                    sc = SheetCollate.UNCOLLATED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
                }
39865
62db9aaff554 5080830: SheetCollate is not handled properly by the cross platform print dlg
psadhukhan
parents: 39847
diff changeset
  1311
                if (sc != null &&
62db9aaff554 5080830: SheetCollate is not handled properly by the cross platform print dlg
psadhukhan
parents: 39847
diff changeset
  1312
                    !psCurrent.isAttributeValueSupported(sc, docFlavor, asCurrent)) {
62db9aaff554 5080830: SheetCollate is not handled properly by the cross platform print dlg
psadhukhan
parents: 39847
diff changeset
  1313
                    scSupported = false;
62db9aaff554 5080830: SheetCollate is not handled properly by the cross platform print dlg
psadhukhan
parents: 39847
diff changeset
  1314
                }
62db9aaff554 5080830: SheetCollate is not handled properly by the cross platform print dlg
psadhukhan
parents: 39847
diff changeset
  1315
            } else {
62db9aaff554 5080830: SheetCollate is not handled properly by the cross platform print dlg
psadhukhan
parents: 39847
diff changeset
  1316
                if (!psCurrent.isAttributeValueSupported(sc, docFlavor, asCurrent)) {
62db9aaff554 5080830: SheetCollate is not handled properly by the cross platform print dlg
psadhukhan
parents: 39847
diff changeset
  1317
                    scSupported = false;
62db9aaff554 5080830: SheetCollate is not handled properly by the cross platform print dlg
psadhukhan
parents: 39847
diff changeset
  1318
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
            }
39865
62db9aaff554 5080830: SheetCollate is not handled properly by the cross platform print dlg
psadhukhan
parents: 39847
diff changeset
  1320
            cbCollate.setSelected(sc == SheetCollate.COLLATED && scSupported);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
            updateCollateCB();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
     * The "Page Setup" tab.  Includes the controls for MediaSource/MediaTray,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
     * OrientationRequested, and Sides.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
     */
23648
a95041026433 8037139: Fix serial lint warnings in sun.print
darcy
parents: 23010
diff changeset
  1332
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
    private class PageSetupPanel extends JPanel {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
        private MediaPanel pnlMedia;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
        private OrientationPanel pnlOrientation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
        private MarginsPanel pnlMargins;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
        public PageSetupPanel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
            super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
            GridBagLayout gridbag = new GridBagLayout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
            GridBagConstraints c = new GridBagConstraints();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
            setLayout(gridbag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
            c.fill = GridBagConstraints.BOTH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
            c.insets = panelInsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
            c.weightx = 1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
            c.weighty = 1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
            c.gridwidth = GridBagConstraints.REMAINDER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
            pnlMedia = new MediaPanel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
            addToGB(pnlMedia, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
            pnlOrientation = new OrientationPanel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
            c.gridwidth = GridBagConstraints.RELATIVE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
            addToGB(pnlOrientation, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
            pnlMargins = new MarginsPanel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
            pnlOrientation.addOrientationListener(pnlMargins);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
            pnlMedia.addMediaListener(pnlMargins);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
            c.gridwidth = GridBagConstraints.REMAINDER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
            addToGB(pnlMargins, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
        public void updateInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
            pnlMedia.updateInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
            pnlOrientation.updateInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
            pnlMargins.updateInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
23648
a95041026433 8037139: Fix serial lint warnings in sun.print
darcy
parents: 23010
diff changeset
  1374
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
    private class MarginsPanel extends JPanel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
                               implements ActionListener, FocusListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
        private final String strTitle = getMsg("border.margins");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
        private JFormattedTextField leftMargin, rightMargin,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
                                    topMargin, bottomMargin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
        private JLabel lblLeft, lblRight, lblTop, lblBottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
        private int units = MediaPrintableArea.MM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
        // storage for the last margin values calculated, -ve is uninitialised
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
        private float lmVal = -1f,rmVal = -1f, tmVal = -1f, bmVal = -1f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
        // storage for margins as objects mapped into orientation for display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
        private Float lmObj,rmObj,tmObj,bmObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
        public MarginsPanel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
            super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
            GridBagLayout gridbag = new GridBagLayout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
            GridBagConstraints c = new GridBagConstraints();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
            c.fill = GridBagConstraints.HORIZONTAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
            c.weightx = 1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
            c.weighty = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
            c.insets = compInsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
            setLayout(gridbag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
            setBorder(BorderFactory.createTitledBorder(strTitle));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
            String unitsKey = "label.millimetres";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
            String defaultCountry = Locale.getDefault().getCountry();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
            if (defaultCountry != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
                (defaultCountry.equals("") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
                 defaultCountry.equals(Locale.US.getCountry()) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
                 defaultCountry.equals(Locale.CANADA.getCountry()))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
                unitsKey = "label.inches";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
                units = MediaPrintableArea.INCH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
            String unitsMsg = getMsg(unitsKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
            DecimalFormat format;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
            if (units == MediaPrintableArea.MM) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
                format = new DecimalFormat("###.##");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
                format.setMaximumIntegerDigits(3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
                format = new DecimalFormat("##.##");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
                format.setMaximumIntegerDigits(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
            format.setMinimumFractionDigits(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
            format.setMaximumFractionDigits(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
            format.setMinimumIntegerDigits(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
            format.setParseIntegerOnly(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
            format.setDecimalSeparatorAlwaysShown(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
            NumberFormatter nf = new NumberFormatter(format);
37714
7a0b1c7e7054 8154213: clean up uses of boxed primitive constructors in the java.desktop module
prr
parents: 37691
diff changeset
  1427
            nf.setMinimum(Float.valueOf(0.0f));
7a0b1c7e7054 8154213: clean up uses of boxed primitive constructors in the java.desktop module
prr
parents: 37691
diff changeset
  1428
            nf.setMaximum(Float.valueOf(999.0f));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
            nf.setAllowsInvalid(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
            nf.setCommitsOnValidEdit(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
            leftMargin = new JFormattedTextField(nf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
            leftMargin.addFocusListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
            leftMargin.addActionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
            leftMargin.getAccessibleContext().setAccessibleName(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
                                              getMsg("label.leftmargin"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
            rightMargin = new JFormattedTextField(nf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
            rightMargin.addFocusListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
            rightMargin.addActionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
            rightMargin.getAccessibleContext().setAccessibleName(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
                                              getMsg("label.rightmargin"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
            topMargin = new JFormattedTextField(nf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
            topMargin.addFocusListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
            topMargin.addActionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
            topMargin.getAccessibleContext().setAccessibleName(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
                                              getMsg("label.topmargin"));
37691
8cd8bdd9280c 6801613: Cross-platform pageDialog and printDialog top margin entry broken
psadhukhan
parents: 32865
diff changeset
  1447
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
            bottomMargin = new JFormattedTextField(nf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
            bottomMargin.addFocusListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
            bottomMargin.addActionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
            bottomMargin.getAccessibleContext().setAccessibleName(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
                                              getMsg("label.bottommargin"));
37691
8cd8bdd9280c 6801613: Cross-platform pageDialog and printDialog top margin entry broken
psadhukhan
parents: 32865
diff changeset
  1453
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
            c.gridwidth = GridBagConstraints.RELATIVE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
            lblLeft = new JLabel(getMsg("label.leftmargin") + " " + unitsMsg,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
                                 JLabel.LEADING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
            lblLeft.setDisplayedMnemonic(getMnemonic("label.leftmargin"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
            lblLeft.setLabelFor(leftMargin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
            addToGB(lblLeft, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
            c.gridwidth = GridBagConstraints.REMAINDER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
            lblRight = new JLabel(getMsg("label.rightmargin") + " " + unitsMsg,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
                                  JLabel.LEADING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
            lblRight.setDisplayedMnemonic(getMnemonic("label.rightmargin"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
            lblRight.setLabelFor(rightMargin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
            addToGB(lblRight, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
            c.gridwidth = GridBagConstraints.RELATIVE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
            addToGB(leftMargin, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
            c.gridwidth = GridBagConstraints.REMAINDER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
            addToGB(rightMargin, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
            // add an invisible spacing component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
            addToGB(new JPanel(), this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
            c.gridwidth = GridBagConstraints.RELATIVE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
            lblTop = new JLabel(getMsg("label.topmargin") + " " + unitsMsg,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
                                JLabel.LEADING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
            lblTop.setDisplayedMnemonic(getMnemonic("label.topmargin"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
            lblTop.setLabelFor(topMargin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
            addToGB(lblTop, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
            c.gridwidth = GridBagConstraints.REMAINDER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
            lblBottom = new JLabel(getMsg("label.bottommargin") +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
                                   " " + unitsMsg, JLabel.LEADING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
            lblBottom.setDisplayedMnemonic(getMnemonic("label.bottommargin"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
            lblBottom.setLabelFor(bottomMargin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
            addToGB(lblBottom, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
            c.gridwidth = GridBagConstraints.RELATIVE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
            addToGB(topMargin, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
            c.gridwidth = GridBagConstraints.REMAINDER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
            addToGB(bottomMargin, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
            Object source = e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
            updateMargins(source);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
        public void focusLost(FocusEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
            Object source = e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
            updateMargins(source);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
        public void focusGained(FocusEvent e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
        /* Get the numbers, use to create a MPA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
         * If its valid, accept it and update the attribute set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
         * If its not valid, then reject it and call updateInfo()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
         * to re-establish the previous entries.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
        public void updateMargins(Object source) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
            if (!(source instanceof JFormattedTextField)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
                JFormattedTextField tf = (JFormattedTextField)source;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
                Float val = (Float)tf.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
                if (val == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
                if (tf == leftMargin && val.equals(lmObj)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
                if (tf == rightMargin && val.equals(rmObj)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
                if (tf == topMargin && val.equals(tmObj)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
                if (tf == bottomMargin && val.equals(bmObj)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
            Float lmTmpObj = (Float)leftMargin.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
            Float rmTmpObj = (Float)rightMargin.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
            Float tmTmpObj = (Float)topMargin.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
            Float bmTmpObj = (Float)bottomMargin.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
            float lm = lmTmpObj.floatValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
            float rm = rmTmpObj.floatValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
            float tm = tmTmpObj.floatValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
            float bm = bmTmpObj.floatValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
            /* adjust for orientation */
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  1550
            Class<OrientationRequested> orCategory = OrientationRequested.class;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
            OrientationRequested or =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
                (OrientationRequested)asCurrent.get(orCategory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
            if (or == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
                or = (OrientationRequested)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
                     psCurrent.getDefaultAttributeValue(orCategory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
            float tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
            if (or == OrientationRequested.REVERSE_PORTRAIT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
                tmp = lm; lm = rm; rm = tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
                tmp = tm; tm = bm; bm = tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
            } else if (or == OrientationRequested.LANDSCAPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
                tmp = lm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
                lm = tm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
                tm = rm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
                rm = bm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
                bm = tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
            } else if (or == OrientationRequested.REVERSE_LANDSCAPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
                tmp = lm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
                lm = bm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
                bm = rm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
                rm = tm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
                tm = tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
            MediaPrintableArea mpa;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
            if ((mpa = validateMargins(lm, rm, tm, bm)) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
                asCurrent.add(mpa);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
                lmVal = lm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
                rmVal = rm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
                tmVal = tm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
                bmVal = bm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
                lmObj = lmTmpObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
                rmObj = rmTmpObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
                tmObj = tmTmpObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
                bmObj = bmTmpObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
                if (lmObj == null || rmObj == null ||
29008
e368342daf04 8072433: copy/paste duplicated tests in some condition statements
prr
parents: 28231
diff changeset
  1589
                    tmObj == null || bmObj == null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
                    leftMargin.setValue(lmObj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
                    rightMargin.setValue(rmObj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
                    topMargin.setValue(tmObj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
                    bottomMargin.setValue(bmObj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
         * This method either accepts the values and creates a new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
         * MediaPrintableArea, or does nothing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
         * It should not attempt to create a printable area from anything
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
         * other than the exact values passed in.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
         * But REMIND/TBD: it would be user friendly to replace margins the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
         * user entered but are out of bounds with the minimum.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
         * At that point this method will need to take responsibility for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
         * updating the "stored" values and the UI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
        private MediaPrintableArea validateMargins(float lm, float rm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
                                                   float tm, float bm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  1614
            Class<MediaPrintableArea> mpaCategory = MediaPrintableArea.class;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
            MediaPrintableArea mpa;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
            MediaPrintableArea mpaMax = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
            MediaSize mediaSize = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
            Media media = (Media)asCurrent.get(Media.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
            if (media == null || !(media instanceof MediaSizeName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
                media = (Media)psCurrent.getDefaultAttributeValue(Media.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
            if (media != null && (media instanceof MediaSizeName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
                MediaSizeName msn = (MediaSizeName)media;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
                mediaSize = MediaSize.getMediaSizeForName(msn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
            if (mediaSize == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
                mediaSize = new MediaSize(8.5f, 11f, Size2DSyntax.INCH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
            if (media != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
                PrintRequestAttributeSet tmpASet =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
                    new HashPrintRequestAttributeSet(asCurrent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
                tmpASet.add(media);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
                Object values =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
                    psCurrent.getSupportedAttributeValues(mpaCategory,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
                                                          docFlavor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
                                                          tmpASet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
                if (values instanceof MediaPrintableArea[] &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
                    ((MediaPrintableArea[])values).length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
                    mpaMax = ((MediaPrintableArea[])values)[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
            if (mpaMax == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
                mpaMax = new MediaPrintableArea(0f, 0f,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
                                                mediaSize.getX(units),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
                                                mediaSize.getY(units),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
                                                units);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
            float wid = mediaSize.getX(units);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
            float hgt = mediaSize.getY(units);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
            float pax = lm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
            float pay = tm;
38983
3cc67a01654b 6509729: javax.print.ServiceUI.printDialog Border/Margin Evaluation is bugged
psadhukhan
parents: 37714
diff changeset
  1657
            float par = rm;
3cc67a01654b 6509729: javax.print.ServiceUI.printDialog Border/Margin Evaluation is bugged
psadhukhan
parents: 37714
diff changeset
  1658
            float pab = bm;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
            float paw = wid - lm - rm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
            float pah = hgt - tm - bm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
            if (paw <= 0f || pah <= 0f || pax < 0f || pay < 0f ||
38983
3cc67a01654b 6509729: javax.print.ServiceUI.printDialog Border/Margin Evaluation is bugged
psadhukhan
parents: 37714
diff changeset
  1663
                par <= 0f || pab <= 0f ||
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
                pax < mpaMax.getX(units) || paw > mpaMax.getWidth(units) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
                pay < mpaMax.getY(units) || pah > mpaMax.getHeight(units)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
                return new MediaPrintableArea(lm, tm, paw, pah, units);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
        /* This is complex as a MediaPrintableArea is valid only within
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
         * a particular context of media size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
         * So we need a MediaSize as well as a MediaPrintableArea.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
         * MediaSize can be obtained from MediaSizeName.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
         * If the application specifies a MediaPrintableArea, we accept it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
         * to the extent its valid for the Media they specify. If they
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
         * don't specify a Media, then the default is assumed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
         * If an application doesn't define a MediaPrintableArea, we need to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
         * create a suitable one, this is created using the specified (or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
         * default) Media and default 1 inch margins. This is validated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
         * against the paper in case this is too large for tiny media.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
        public void updateInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
            if (isAWT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
                leftMargin.setEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
                rightMargin.setEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
                topMargin.setEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
                bottomMargin.setEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
                lblLeft.setEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
                lblRight.setEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
                lblTop.setEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
                lblBottom.setEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  1699
            Class<MediaPrintableArea> mpaCategory = MediaPrintableArea.class;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
            MediaPrintableArea mpa =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
                 (MediaPrintableArea)asCurrent.get(mpaCategory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
            MediaPrintableArea mpaMax = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
            MediaSize mediaSize = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
            Media media = (Media)asCurrent.get(Media.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
            if (media == null || !(media instanceof MediaSizeName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
                media = (Media)psCurrent.getDefaultAttributeValue(Media.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
            if (media != null && (media instanceof MediaSizeName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
                MediaSizeName msn = (MediaSizeName)media;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
                mediaSize = MediaSize.getMediaSizeForName(msn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
            if (mediaSize == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
                mediaSize = new MediaSize(8.5f, 11f, Size2DSyntax.INCH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
            if (media != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
                PrintRequestAttributeSet tmpASet =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
                    new HashPrintRequestAttributeSet(asCurrent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
                tmpASet.add(media);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
                Object values =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
                    psCurrent.getSupportedAttributeValues(mpaCategory,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
                                                          docFlavor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
                                                          tmpASet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
                if (values instanceof MediaPrintableArea[] &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
                    ((MediaPrintableArea[])values).length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
                    mpaMax = ((MediaPrintableArea[])values)[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
                } else if (values instanceof MediaPrintableArea) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
                    mpaMax = (MediaPrintableArea)values;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
            if (mpaMax == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
                mpaMax = new MediaPrintableArea(0f, 0f,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
                                                mediaSize.getX(units),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
                                                mediaSize.getY(units),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
                                                units);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
             * At this point we now know as best we can :-
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
             * - the media size
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
             * - the maximum corresponding printable area
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
             * - the media printable area specified by the client, if any.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
             * The next step is to create a default MPA if none was specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
             * 1" margins are used unless they are disproportionately
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
             * large compared to the size of the media.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
            float wid = mediaSize.getX(MediaPrintableArea.INCH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
            float hgt = mediaSize.getY(MediaPrintableArea.INCH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
            float maxMarginRatio = 5f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
            float xMgn, yMgn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
            if (wid > maxMarginRatio) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
                xMgn = 1f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
                xMgn = wid / maxMarginRatio;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
            if (hgt > maxMarginRatio) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
                yMgn = 1f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
                yMgn = hgt / maxMarginRatio;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
            if (mpa == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
                mpa = new MediaPrintableArea(xMgn, yMgn,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
                                             wid-(2*xMgn), hgt-(2*yMgn),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
                                             MediaPrintableArea.INCH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
                asCurrent.add(mpa);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
            float pax = mpa.getX(units);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
            float pay = mpa.getY(units);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
            float paw = mpa.getWidth(units);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
            float pah = mpa.getHeight(units);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
            float paxMax = mpaMax.getX(units);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
            float payMax = mpaMax.getY(units);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
            float pawMax = mpaMax.getWidth(units);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
            float pahMax = mpaMax.getHeight(units);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
            boolean invalid = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
            // If the paper is set to something which is too small to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
            // accommodate a specified printable area, perhaps carried
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
            // over from a larger paper, the adjustment that needs to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
            // performed should seem the most natural from a user's viewpoint.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
            // Since the user is specifying margins, then we are biased
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
            // towards keeping the margins as close to what is specified as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
            // possible, shrinking or growing the printable area.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
            // But the API uses printable area, so you need to know the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
            // media size in which the margins were previously interpreted,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
            // or at least have a record of the margins.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
            // In the case that this is the creation of this UI we do not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
            // have this record, so we are somewhat reliant on the client
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
            // to supply a reasonable default
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
            wid = mediaSize.getX(units);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
            hgt = mediaSize.getY(units);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
            if (lmVal >= 0f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
                invalid = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
                if (lmVal + rmVal > wid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
                    // margins impossible, but maintain P.A if can
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
                    if (paw > pawMax) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
                        paw = pawMax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
                    // try to centre the printable area.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
                    pax = (wid - paw)/2f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
                    pax = (lmVal >= paxMax) ? lmVal : paxMax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
                    paw = wid - pax - rmVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
                if (tmVal + bmVal > hgt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
                    if (pah > pahMax) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
                        pah = pahMax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
                    pay = (hgt - pah)/2f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
                    pay = (tmVal >= payMax) ? tmVal : payMax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
                    pah = hgt - pay - bmVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
            if (pax < paxMax) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
                invalid = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
                pax = paxMax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
            if (pay < payMax) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
                invalid = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
                pay = payMax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
            if (paw > pawMax) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
                invalid = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
                paw = pawMax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
            if (pah > pahMax) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
                invalid = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
                pah = pahMax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
            if ((pax + paw > paxMax + pawMax) || (paw <= 0f)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
                invalid = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
                pax = paxMax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
                paw = pawMax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
            if ((pay + pah > payMax + pahMax) || (pah <= 0f)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1846
                invalid = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
                pay = payMax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
                pah = pahMax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
            if (invalid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
                mpa = new MediaPrintableArea(pax, pay, paw, pah, units);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
                asCurrent.add(mpa);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1855
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
            /* We now have a valid printable area.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
             * Turn it into margins, using the mediaSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
            lmVal = pax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
            tmVal = pay;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
            rmVal = mediaSize.getX(units) - pax - paw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
            bmVal = mediaSize.getY(units) - pay - pah;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1863
37714
7a0b1c7e7054 8154213: clean up uses of boxed primitive constructors in the java.desktop module
prr
parents: 37691
diff changeset
  1864
            lmObj = lmVal;
7a0b1c7e7054 8154213: clean up uses of boxed primitive constructors in the java.desktop module
prr
parents: 37691
diff changeset
  1865
            rmObj = rmVal;
7a0b1c7e7054 8154213: clean up uses of boxed primitive constructors in the java.desktop module
prr
parents: 37691
diff changeset
  1866
            tmObj = tmVal;
7a0b1c7e7054 8154213: clean up uses of boxed primitive constructors in the java.desktop module
prr
parents: 37691
diff changeset
  1867
            bmObj = bmVal;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
            /* Now we know the values to use, we need to assign them
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
             * to the fields appropriate for the orientation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
             * Note: if orientation changes this method must be called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
             */
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  1873
            Class<OrientationRequested> orCategory = OrientationRequested.class;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
            OrientationRequested or =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
                (OrientationRequested)asCurrent.get(orCategory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
            if (or == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
                or = (OrientationRequested)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1879
                     psCurrent.getDefaultAttributeValue(orCategory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1880
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1881
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
            Float tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1883
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
            if (or == OrientationRequested.REVERSE_PORTRAIT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1885
                tmp = lmObj; lmObj = rmObj; rmObj = tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1886
                tmp = tmObj; tmObj = bmObj; bmObj = tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
            }  else if (or == OrientationRequested.LANDSCAPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1888
                tmp = lmObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1889
                lmObj = bmObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
                bmObj = rmObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1891
                rmObj = tmObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
                tmObj = tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1893
            }  else if (or == OrientationRequested.REVERSE_LANDSCAPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1894
                tmp = lmObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
                lmObj = tmObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
                tmObj = rmObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1897
                rmObj = bmObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1898
                bmObj = tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1899
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1900
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1901
            leftMargin.setValue(lmObj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1902
            rightMargin.setValue(rmObj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1903
            topMargin.setValue(tmObj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1904
            bottomMargin.setValue(bmObj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1905
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1906
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1907
23648
a95041026433 8037139: Fix serial lint warnings in sun.print
darcy
parents: 23010
diff changeset
  1908
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1909
    private class MediaPanel extends JPanel implements ItemListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1910
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1911
        private final String strTitle = getMsg("border.media");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1912
        private JLabel lblSize, lblSource;
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  1913
        private JComboBox<Object> cbSize, cbSource;
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  1914
        private Vector<MediaSizeName> sizes = new Vector<>();
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  1915
        private Vector<MediaTray> sources = new Vector<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1916
        private MarginsPanel pnlMargins = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1918
        public MediaPanel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1919
            super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1920
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1921
            GridBagLayout gridbag = new GridBagLayout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1922
            GridBagConstraints c = new GridBagConstraints();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1923
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1924
            setLayout(gridbag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1925
            setBorder(BorderFactory.createTitledBorder(strTitle));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1926
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  1927
            cbSize = new JComboBox<>();
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  1928
            cbSource = new JComboBox<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1929
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1930
            c.fill = GridBagConstraints.BOTH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1931
            c.insets = compInsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1932
            c.weighty = 1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1933
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1934
            c.weightx = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1935
            lblSize = new JLabel(getMsg("label.size"), JLabel.TRAILING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1936
            lblSize.setDisplayedMnemonic(getMnemonic("label.size"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1937
            lblSize.setLabelFor(cbSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1938
            addToGB(lblSize, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1939
            c.weightx = 1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1940
            c.gridwidth = GridBagConstraints.REMAINDER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1941
            addToGB(cbSize, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1942
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1943
            c.weightx = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1944
            c.gridwidth = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1945
            lblSource = new JLabel(getMsg("label.source"), JLabel.TRAILING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1946
            lblSource.setDisplayedMnemonic(getMnemonic("label.source"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1947
            lblSource.setLabelFor(cbSource);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1948
            addToGB(lblSource, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1949
            c.gridwidth = GridBagConstraints.REMAINDER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1950
            addToGB(cbSource, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1951
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1952
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1953
        private String getMediaName(String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1954
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1955
                // replace characters that would be invalid in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1956
                // a resource key with valid characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
                String newkey = key.replace(' ', '-');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1958
                newkey = newkey.replace('#', 'n');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1959
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1960
                return messageRB.getString(newkey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1961
            } catch (java.util.MissingResourceException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
                return key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1963
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1964
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1965
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1966
        public void itemStateChanged(ItemEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
            Object source = e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1969
            if (e.getStateChange() == ItemEvent.SELECTED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1970
                if (source == cbSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1971
                    int index = cbSize.getSelectedIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1972
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1973
                    if ((index >= 0) && (index < sizes.size())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
                        if ((cbSource.getItemCount() > 1) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
                            (cbSource.getSelectedIndex() >= 1))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1976
                        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1977
                            int src = cbSource.getSelectedIndex() - 1;
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  1978
                            MediaTray mt = sources.get(src);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
                            asCurrent.add(new SunAlternateMedia(mt));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1980
                        }
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  1981
                        asCurrent.add(sizes.get(index));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1982
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1983
                } else if (source == cbSource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1984
                    int index = cbSource.getSelectedIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1985
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1986
                    if ((index >= 1) && (index < (sources.size() + 1))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1987
                       asCurrent.remove(SunAlternateMedia.class);
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  1988
                       MediaTray newTray = sources.get(index - 1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1989
                       Media m = (Media)asCurrent.get(Media.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1990
                       if (m == null || m instanceof MediaTray) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1991
                           asCurrent.add(newTray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1992
                       } else if (m instanceof MediaSizeName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1993
                           MediaSizeName msn = (MediaSizeName)m;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1994
                           Media def = (Media)psCurrent.getDefaultAttributeValue(Media.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1995
                           if (def instanceof MediaSizeName && def.equals(msn)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1996
                               asCurrent.add(newTray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1997
                           } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1998
                               /* Non-default paper size, so need to store tray
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1999
                                * as SunAlternateMedia
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2000
                                */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2001
                               asCurrent.add(new SunAlternateMedia(newTray));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2002
                           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2003
                       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2004
                    } else if (index == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2005
                        asCurrent.remove(SunAlternateMedia.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2006
                        if (cbSize.getItemCount() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2007
                            int size = cbSize.getSelectedIndex();
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  2008
                            asCurrent.add(sizes.get(size));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2009
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2010
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2011
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2012
            // orientation affects display of margins.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2013
                if (pnlMargins != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2014
                    pnlMargins.updateInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2015
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2016
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2017
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2018
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2019
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2020
        /* this is ad hoc to keep things simple */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2021
        public void addMediaListener(MarginsPanel pnl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2022
            pnlMargins = pnl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2023
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2024
        public void updateInfo() {
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  2025
            Class<Media> mdCategory = Media.class;
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  2026
            Class<SunAlternateMedia> amCategory = SunAlternateMedia.class;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2027
            boolean mediaSupported = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2028
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2029
            cbSize.removeItemListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2030
            cbSize.removeAllItems();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2031
            cbSource.removeItemListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2032
            cbSource.removeAllItems();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2033
            cbSource.addItem(getMediaName("auto-select"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2034
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2035
            sizes.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2036
            sources.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2037
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2038
            if (psCurrent.isAttributeCategorySupported(mdCategory)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2039
                mediaSupported = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2040
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2041
                Object values =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2042
                    psCurrent.getSupportedAttributeValues(mdCategory,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2043
                                                          docFlavor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2044
                                                          asCurrent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2045
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2046
                if (values instanceof Media[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2047
                    Media[] media = (Media[])values;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2048
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2049
                    for (int i = 0; i < media.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2050
                        Media medium = media[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2051
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2052
                        if (medium instanceof MediaSizeName) {
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  2053
                            sizes.add((MediaSizeName)medium);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2054
                            cbSize.addItem(getMediaName(medium.toString()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2055
                        } else if (medium instanceof MediaTray) {
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  2056
                            sources.add((MediaTray)medium);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2057
                            cbSource.addItem(getMediaName(medium.toString()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2058
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2059
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2060
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2061
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2062
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2063
            boolean msSupported = (mediaSupported && (sizes.size() > 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2064
            lblSize.setEnabled(msSupported);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2065
            cbSize.setEnabled(msSupported);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2066
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2067
            if (isAWT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2068
                cbSource.setEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2069
                lblSource.setEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2070
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2071
                cbSource.setEnabled(mediaSupported);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2072
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2073
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2074
            if (mediaSupported) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2075
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2076
                Media medium = (Media)asCurrent.get(mdCategory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2077
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2078
               // initialize size selection to default
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2079
                Media defMedia = (Media)psCurrent.getDefaultAttributeValue(mdCategory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2080
                if (defMedia instanceof MediaSizeName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2081
                    cbSize.setSelectedIndex(sizes.size() > 0 ? sizes.indexOf(defMedia) : -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2082
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2083
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2084
                if (medium == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2085
                    !psCurrent.isAttributeValueSupported(medium,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2086
                                                         docFlavor, asCurrent)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2087
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2088
                    medium = defMedia;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2089
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2090
                    if (medium == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2091
                        if (sizes.size() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2092
                            medium = (Media)sizes.get(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2093
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2094
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2095
                    if (medium != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2096
                        asCurrent.add(medium);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2097
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2098
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2099
                if (medium != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2100
                    if (medium instanceof MediaSizeName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2101
                        MediaSizeName ms = (MediaSizeName)medium;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2102
                        cbSize.setSelectedIndex(sizes.indexOf(ms));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2103
                    } else if (medium instanceof MediaTray) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2104
                        MediaTray mt = (MediaTray)medium;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2105
                        cbSource.setSelectedIndex(sources.indexOf(mt) + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2106
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2107
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2108
                    cbSize.setSelectedIndex(sizes.size() > 0 ? 0 : -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2109
                    cbSource.setSelectedIndex(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2110
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2111
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2112
                SunAlternateMedia alt = (SunAlternateMedia)asCurrent.get(amCategory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2113
                if (alt != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2114
                    Media md = alt.getMedia();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2115
                    if (md instanceof MediaTray) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2116
                        MediaTray mt = (MediaTray)md;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2117
                        cbSource.setSelectedIndex(sources.indexOf(mt) + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2118
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2119
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2120
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2121
                int selIndex = cbSize.getSelectedIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2122
                if ((selIndex >= 0) && (selIndex < sizes.size())) {
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  2123
                  asCurrent.add(sizes.get(selIndex));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2124
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2125
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2126
                selIndex = cbSource.getSelectedIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2127
                if ((selIndex >= 1) && (selIndex < (sources.size()+1))) {
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  2128
                    MediaTray mt = sources.get(selIndex-1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2129
                    if (medium instanceof MediaTray) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2130
                        asCurrent.add(mt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2131
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2132
                        asCurrent.add(new SunAlternateMedia(mt));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2133
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2134
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2135
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2136
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2137
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2138
            cbSize.addItemListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2139
            cbSource.addItemListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2140
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2141
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2142
23648
a95041026433 8037139: Fix serial lint warnings in sun.print
darcy
parents: 23010
diff changeset
  2143
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2144
    private class OrientationPanel extends JPanel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2145
        implements ActionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2146
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2147
        private final String strTitle = getMsg("border.orientation");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2148
        private IconRadioButton rbPortrait, rbLandscape,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2149
                                rbRevPortrait, rbRevLandscape;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2150
        private MarginsPanel pnlMargins = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2151
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2152
        public OrientationPanel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2153
            super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2154
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2155
            GridBagLayout gridbag = new GridBagLayout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2156
            GridBagConstraints c = new GridBagConstraints();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2157
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2158
            setLayout(gridbag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2159
            setBorder(BorderFactory.createTitledBorder(strTitle));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2160
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2161
            c.fill = GridBagConstraints.BOTH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2162
            c.insets = compInsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2163
            c.weighty = 1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2164
            c.gridwidth = GridBagConstraints.REMAINDER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2165
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2166
            ButtonGroup bg = new ButtonGroup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2167
            rbPortrait = new IconRadioButton("radiobutton.portrait",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2168
                                             "orientPortrait.png", true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2169
                                             bg, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2170
            rbPortrait.addActionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2171
            addToGB(rbPortrait, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2172
            rbLandscape = new IconRadioButton("radiobutton.landscape",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2173
                                              "orientLandscape.png", false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2174
                                              bg, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2175
            rbLandscape.addActionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2176
            addToGB(rbLandscape, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2177
            rbRevPortrait = new IconRadioButton("radiobutton.revportrait",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2178
                                                "orientRevPortrait.png", false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2179
                                                bg, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2180
            rbRevPortrait.addActionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2181
            addToGB(rbRevPortrait, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2182
            rbRevLandscape = new IconRadioButton("radiobutton.revlandscape",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2183
                                                 "orientRevLandscape.png", false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2184
                                                 bg, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2185
            rbRevLandscape.addActionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2186
            addToGB(rbRevLandscape, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2187
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2188
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2189
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2190
            Object source = e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2191
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2192
            if (rbPortrait.isSameAs(source)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2193
                asCurrent.add(OrientationRequested.PORTRAIT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2194
            } else if (rbLandscape.isSameAs(source)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2195
                asCurrent.add(OrientationRequested.LANDSCAPE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2196
            } else if (rbRevPortrait.isSameAs(source)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2197
                asCurrent.add(OrientationRequested.REVERSE_PORTRAIT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2198
            } else if (rbRevLandscape.isSameAs(source)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2199
                asCurrent.add(OrientationRequested.REVERSE_LANDSCAPE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2200
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2201
            // orientation affects display of margins.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2202
            if (pnlMargins != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2203
                pnlMargins.updateInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2204
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2205
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2206
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2207
        /* This is ad hoc to keep things simple */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2208
        void addOrientationListener(MarginsPanel pnl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2209
            pnlMargins = pnl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2210
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2211
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2212
        public void updateInfo() {
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  2213
            Class<OrientationRequested> orCategory = OrientationRequested.class;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2214
            boolean pSupported = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2215
            boolean lSupported = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2216
            boolean rpSupported = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2217
            boolean rlSupported = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2218
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2219
            if (isAWT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2220
                pSupported = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2221
                lSupported = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2222
            } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2223
            if (psCurrent.isAttributeCategorySupported(orCategory)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2224
                Object values =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2225
                    psCurrent.getSupportedAttributeValues(orCategory,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2226
                                                          docFlavor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2227
                                                          asCurrent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2228
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2229
                if (values instanceof OrientationRequested[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2230
                    OrientationRequested[] ovalues =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2231
                        (OrientationRequested[])values;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2232
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2233
                    for (int i = 0; i < ovalues.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2234
                        OrientationRequested value = ovalues[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2235
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2236
                        if (value == OrientationRequested.PORTRAIT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2237
                            pSupported = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2238
                        } else if (value == OrientationRequested.LANDSCAPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2239
                            lSupported = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2240
                        } else if (value == OrientationRequested.REVERSE_PORTRAIT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2241
                            rpSupported = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2242
                        } else if (value == OrientationRequested.REVERSE_LANDSCAPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2243
                            rlSupported = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2244
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2245
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2246
                }
2389
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2247
            }
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2248
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2249
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2250
            rbPortrait.setEnabled(pSupported);
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2251
            rbLandscape.setEnabled(lSupported);
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2252
            rbRevPortrait.setEnabled(rpSupported);
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2253
            rbRevLandscape.setEnabled(rlSupported);
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2254
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2255
            OrientationRequested or = (OrientationRequested)asCurrent.get(orCategory);
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2256
            if (or == null ||
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2257
                !psCurrent.isAttributeValueSupported(or, docFlavor, asCurrent)) {
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2258
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2259
                or = (OrientationRequested)psCurrent.getDefaultAttributeValue(orCategory);
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2260
                // need to validate if default is not supported
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2261
                if ((or != null) &&
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2262
                   !psCurrent.isAttributeValueSupported(or, docFlavor, asCurrent)) {
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2263
                    or = null;
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2264
                    Object values =
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2265
                        psCurrent.getSupportedAttributeValues(orCategory,
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2266
                                                              docFlavor,
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2267
                                                              asCurrent);
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2268
                    if (values instanceof OrientationRequested[]) {
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2269
                        OrientationRequested[] orValues =
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2270
                                            (OrientationRequested[])values;
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2271
                        if (orValues.length > 1) {
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2272
                            // get the first in the list
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2273
                            or = orValues[0];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2274
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2275
                    }
2389
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2276
                }
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2277
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2278
                if (or == null) {
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2279
                    or = OrientationRequested.PORTRAIT;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2280
                }
2389
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2281
                asCurrent.add(or);
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2282
            }
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2283
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2284
            if (or == OrientationRequested.PORTRAIT) {
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2285
                rbPortrait.setSelected(true);
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2286
            } else if (or == OrientationRequested.LANDSCAPE) {
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2287
                rbLandscape.setSelected(true);
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2288
            } else if (or == OrientationRequested.REVERSE_PORTRAIT) {
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2289
                rbRevPortrait.setSelected(true);
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2290
            } else { // if (or == OrientationRequested.REVERSE_LANDSCAPE)
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2291
                rbRevLandscape.setSelected(true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2292
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2293
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2294
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2295
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2296
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2297
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2298
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2299
     * The "Appearance" tab.  Includes the controls for Chromaticity,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2300
     * PrintQuality, JobPriority, JobName, and other related job attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2301
     */
23648
a95041026433 8037139: Fix serial lint warnings in sun.print
darcy
parents: 23010
diff changeset
  2302
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2303
    private class AppearancePanel extends JPanel {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2304
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2305
        private ChromaticityPanel pnlChromaticity;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2306
        private QualityPanel pnlQuality;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2307
        private JobAttributesPanel pnlJobAttributes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2308
        private SidesPanel pnlSides;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2309
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2310
        public AppearancePanel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2311
            super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2312
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2313
            GridBagLayout gridbag = new GridBagLayout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2314
            GridBagConstraints c = new GridBagConstraints();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2315
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2316
            setLayout(gridbag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2317
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2318
            c.fill = GridBagConstraints.BOTH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2319
            c.insets = panelInsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2320
            c.weightx = 1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2321
            c.weighty = 1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2322
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2323
            c.gridwidth = GridBagConstraints.RELATIVE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2324
            pnlChromaticity = new ChromaticityPanel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2325
            addToGB(pnlChromaticity, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2326
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2327
            c.gridwidth = GridBagConstraints.REMAINDER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2328
            pnlQuality = new QualityPanel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2329
            addToGB(pnlQuality, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2330
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2331
            c.gridwidth = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2332
            pnlSides = new SidesPanel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2333
            addToGB(pnlSides, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2334
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2335
            c.gridwidth = GridBagConstraints.REMAINDER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2336
            pnlJobAttributes = new JobAttributesPanel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2337
            addToGB(pnlJobAttributes, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2338
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2339
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2340
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2341
        public void updateInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2342
            pnlChromaticity.updateInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2343
            pnlQuality.updateInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2344
            pnlSides.updateInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2345
            pnlJobAttributes.updateInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2346
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2347
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2348
23648
a95041026433 8037139: Fix serial lint warnings in sun.print
darcy
parents: 23010
diff changeset
  2349
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2350
    private class ChromaticityPanel extends JPanel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2351
        implements ActionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2352
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2353
        private final String strTitle = getMsg("border.chromaticity");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2354
        private JRadioButton rbMonochrome, rbColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2355
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2356
        public ChromaticityPanel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2357
            super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2358
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2359
            GridBagLayout gridbag = new GridBagLayout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2360
            GridBagConstraints c = new GridBagConstraints();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2361
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2362
            setLayout(gridbag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2363
            setBorder(BorderFactory.createTitledBorder(strTitle));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2364
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2365
            c.fill = GridBagConstraints.BOTH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2366
            c.gridwidth = GridBagConstraints.REMAINDER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2367
            c.weighty = 1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2368
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2369
            ButtonGroup bg = new ButtonGroup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2370
            rbMonochrome = createRadioButton("radiobutton.monochrome", this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2371
            rbMonochrome.setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2372
            bg.add(rbMonochrome);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2373
            addToGB(rbMonochrome, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2374
            rbColor = createRadioButton("radiobutton.color", this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2375
            bg.add(rbColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2376
            addToGB(rbColor, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2377
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2378
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2379
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2380
            Object source = e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2381
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2382
            // REMIND: use isSameAs if we move to a IconRB in the future
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2383
            if (source == rbMonochrome) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2384
                asCurrent.add(Chromaticity.MONOCHROME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2385
            } else if (source == rbColor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2386
                asCurrent.add(Chromaticity.COLOR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2387
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2388
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2389
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2390
        public void updateInfo() {
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  2391
            Class<Chromaticity> chCategory = Chromaticity.class;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2392
            boolean monoSupported = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2393
            boolean colorSupported = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2394
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2395
            if (isAWT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2396
                monoSupported = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2397
                colorSupported = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2398
            } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2399
            if (psCurrent.isAttributeCategorySupported(chCategory)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2400
                Object values =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2401
                    psCurrent.getSupportedAttributeValues(chCategory,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2402
                                                          docFlavor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2403
                                                          asCurrent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2404
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2405
                if (values instanceof Chromaticity[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2406
                    Chromaticity[] cvalues = (Chromaticity[])values;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2407
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2408
                    for (int i = 0; i < cvalues.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2409
                        Chromaticity value = cvalues[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2410
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2411
                        if (value == Chromaticity.MONOCHROME) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2412
                            monoSupported = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2413
                        } else if (value == Chromaticity.COLOR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2414
                            colorSupported = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2415
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2416
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2417
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2418
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2419
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2420
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2421
            rbMonochrome.setEnabled(monoSupported);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2422
            rbColor.setEnabled(colorSupported);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2423
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2424
            Chromaticity ch = (Chromaticity)asCurrent.get(chCategory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2425
            if (ch == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2426
                ch = (Chromaticity)psCurrent.getDefaultAttributeValue(chCategory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2427
                if (ch == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2428
                    ch = Chromaticity.MONOCHROME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2429
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2430
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2431
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2432
            if (ch == Chromaticity.MONOCHROME) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2433
                rbMonochrome.setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2434
            } else { // if (ch == Chromaticity.COLOR)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2435
                rbColor.setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2436
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2437
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2438
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2439
23648
a95041026433 8037139: Fix serial lint warnings in sun.print
darcy
parents: 23010
diff changeset
  2440
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2441
    private class QualityPanel extends JPanel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2442
        implements ActionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2443
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2444
        private final String strTitle = getMsg("border.quality");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2445
        private JRadioButton rbDraft, rbNormal, rbHigh;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2446
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2447
        public QualityPanel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2448
            super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2449
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2450
            GridBagLayout gridbag = new GridBagLayout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2451
            GridBagConstraints c = new GridBagConstraints();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2452
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2453
            setLayout(gridbag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2454
            setBorder(BorderFactory.createTitledBorder(strTitle));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2455
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2456
            c.fill = GridBagConstraints.BOTH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2457
            c.gridwidth = GridBagConstraints.REMAINDER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2458
            c.weighty = 1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2459
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2460
            ButtonGroup bg = new ButtonGroup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2461
            rbDraft = createRadioButton("radiobutton.draftq", this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2462
            bg.add(rbDraft);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2463
            addToGB(rbDraft, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2464
            rbNormal = createRadioButton("radiobutton.normalq", this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2465
            rbNormal.setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2466
            bg.add(rbNormal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2467
            addToGB(rbNormal, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2468
            rbHigh = createRadioButton("radiobutton.highq", this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2469
            bg.add(rbHigh);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2470
            addToGB(rbHigh, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2471
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2472
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2473
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2474
            Object source = e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2475
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2476
            if (source == rbDraft) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2477
                asCurrent.add(PrintQuality.DRAFT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2478
            } else if (source == rbNormal) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2479
                asCurrent.add(PrintQuality.NORMAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2480
            } else if (source == rbHigh) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2481
                asCurrent.add(PrintQuality.HIGH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2482
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2483
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2484
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2485
        public void updateInfo() {
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  2486
            Class<PrintQuality> pqCategory = PrintQuality.class;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2487
            boolean draftSupported = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2488
            boolean normalSupported = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2489
            boolean highSupported = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2490
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2491
            if (isAWT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2492
                draftSupported = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2493
                normalSupported = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2494
                highSupported = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2495
            } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2496
            if (psCurrent.isAttributeCategorySupported(pqCategory)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2497
                Object values =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2498
                    psCurrent.getSupportedAttributeValues(pqCategory,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2499
                                                          docFlavor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2500
                                                          asCurrent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2501
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2502
                if (values instanceof PrintQuality[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2503
                    PrintQuality[] qvalues = (PrintQuality[])values;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2504
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2505
                    for (int i = 0; i < qvalues.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2506
                        PrintQuality value = qvalues[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2507
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2508
                        if (value == PrintQuality.DRAFT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2509
                            draftSupported = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2510
                        } else if (value == PrintQuality.NORMAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2511
                            normalSupported = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2512
                        } else if (value == PrintQuality.HIGH) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2513
                            highSupported = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2514
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2515
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2516
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2517
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2518
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2519
            rbDraft.setEnabled(draftSupported);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2520
            rbNormal.setEnabled(normalSupported);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2521
            rbHigh.setEnabled(highSupported);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2522
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2523
            PrintQuality pq = (PrintQuality)asCurrent.get(pqCategory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2524
            if (pq == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2525
                pq = (PrintQuality)psCurrent.getDefaultAttributeValue(pqCategory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2526
                if (pq == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2527
                    pq = PrintQuality.NORMAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2528
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2529
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2530
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2531
            if (pq == PrintQuality.DRAFT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2532
                rbDraft.setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2533
            } else if (pq == PrintQuality.NORMAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2534
                rbNormal.setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2535
            } else { // if (pq == PrintQuality.HIGH)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2536
                rbHigh.setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2537
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2538
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2539
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2540
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2541
    }
23648
a95041026433 8037139: Fix serial lint warnings in sun.print
darcy
parents: 23010
diff changeset
  2542
a95041026433 8037139: Fix serial lint warnings in sun.print
darcy
parents: 23010
diff changeset
  2543
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2544
    private class SidesPanel extends JPanel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2545
        implements ActionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2546
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2547
        private final String strTitle = getMsg("border.sides");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2548
        private IconRadioButton rbOneSide, rbTumble, rbDuplex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2549
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2550
        public SidesPanel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2551
            super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2552
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2553
            GridBagLayout gridbag = new GridBagLayout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2554
            GridBagConstraints c = new GridBagConstraints();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2555
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2556
            setLayout(gridbag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2557
            setBorder(BorderFactory.createTitledBorder(strTitle));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2558
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2559
            c.fill = GridBagConstraints.BOTH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2560
            c.insets = compInsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2561
            c.weighty = 1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2562
            c.gridwidth = GridBagConstraints.REMAINDER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2563
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2564
            ButtonGroup bg = new ButtonGroup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2565
            rbOneSide = new IconRadioButton("radiobutton.oneside",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2566
                                            "oneside.png", true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2567
                                            bg, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2568
            rbOneSide.addActionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2569
            addToGB(rbOneSide, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2570
            rbTumble = new IconRadioButton("radiobutton.tumble",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2571
                                           "tumble.png", false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2572
                                           bg, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2573
            rbTumble.addActionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2574
            addToGB(rbTumble, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2575
            rbDuplex = new IconRadioButton("radiobutton.duplex",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2576
                                           "duplex.png", false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2577
                                           bg, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2578
            rbDuplex.addActionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2579
            c.gridwidth = GridBagConstraints.REMAINDER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2580
            addToGB(rbDuplex, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2581
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2582
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2583
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2584
            Object source = e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2585
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2586
            if (rbOneSide.isSameAs(source)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2587
                asCurrent.add(Sides.ONE_SIDED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2588
            } else if (rbTumble.isSameAs(source)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2589
                asCurrent.add(Sides.TUMBLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2590
            } else if (rbDuplex.isSameAs(source)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2591
                asCurrent.add(Sides.DUPLEX);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2592
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2593
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2594
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2595
        public void updateInfo() {
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  2596
            Class<Sides> sdCategory = Sides.class;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2597
            boolean osSupported = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2598
            boolean tSupported = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2599
            boolean dSupported = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2600
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2601
            if (psCurrent.isAttributeCategorySupported(sdCategory)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2602
                Object values =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2603
                    psCurrent.getSupportedAttributeValues(sdCategory,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2604
                                                          docFlavor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2605
                                                          asCurrent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2606
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2607
                if (values instanceof Sides[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2608
                    Sides[] svalues = (Sides[])values;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2609
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2610
                    for (int i = 0; i < svalues.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2611
                        Sides value = svalues[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2612
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2613
                        if (value == Sides.ONE_SIDED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2614
                            osSupported = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2615
                        } else if (value == Sides.TUMBLE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2616
                            tSupported = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2617
                        } else if (value == Sides.DUPLEX) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2618
                            dSupported = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2619
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2620
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2621
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2622
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2623
            rbOneSide.setEnabled(osSupported);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2624
            rbTumble.setEnabled(tSupported);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2625
            rbDuplex.setEnabled(dSupported);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2626
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2627
            Sides sd = (Sides)asCurrent.get(sdCategory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2628
            if (sd == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2629
                sd = (Sides)psCurrent.getDefaultAttributeValue(sdCategory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2630
                if (sd == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2631
                    sd = Sides.ONE_SIDED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2632
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2633
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2634
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2635
            if (sd == Sides.ONE_SIDED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2636
                rbOneSide.setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2637
            } else if (sd == Sides.TUMBLE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2638
                rbTumble.setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2639
            } else { // if (sd == Sides.DUPLEX)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2640
                rbDuplex.setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2641
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2642
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2643
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2644
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2645
23648
a95041026433 8037139: Fix serial lint warnings in sun.print
darcy
parents: 23010
diff changeset
  2646
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2647
    private class JobAttributesPanel extends JPanel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2648
        implements ActionListener, ChangeListener, FocusListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2649
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2650
        private final String strTitle = getMsg("border.jobattributes");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2651
        private JLabel lblPriority, lblJobName, lblUserName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2652
        private JSpinner spinPriority;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2653
        private SpinnerNumberModel snModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2654
        private JCheckBox cbJobSheets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2655
        private JTextField tfJobName, tfUserName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2656
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2657
        public JobAttributesPanel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2658
            super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2659
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2660
            GridBagLayout gridbag = new GridBagLayout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2661
            GridBagConstraints c = new GridBagConstraints();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2662
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2663
            setLayout(gridbag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2664
            setBorder(BorderFactory.createTitledBorder(strTitle));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2665
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2666
            c.fill = GridBagConstraints.NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2667
            c.insets = compInsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2668
            c.weighty = 1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2669
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2670
            cbJobSheets = createCheckBox("checkbox.jobsheets", this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2671
            c.anchor = GridBagConstraints.LINE_START;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2672
            addToGB(cbJobSheets, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2673
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2674
            JPanel pnlTop = new JPanel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2675
            lblPriority = new JLabel(getMsg("label.priority"), JLabel.TRAILING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2676
            lblPriority.setDisplayedMnemonic(getMnemonic("label.priority"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2677
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2678
            pnlTop.add(lblPriority);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2679
            snModel = new SpinnerNumberModel(1, 1, 100, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2680
            spinPriority = new JSpinner(snModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2681
            lblPriority.setLabelFor(spinPriority);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2682
            // REMIND
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2683
            ((JSpinner.NumberEditor)spinPriority.getEditor()).getTextField().setColumns(3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2684
            spinPriority.addChangeListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2685
            pnlTop.add(spinPriority);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2686
            c.anchor = GridBagConstraints.LINE_END;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2687
            c.gridwidth = GridBagConstraints.REMAINDER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2688
            pnlTop.getAccessibleContext().setAccessibleName(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2689
                                       getMsg("label.priority"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2690
            addToGB(pnlTop, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2691
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2692
            c.fill = GridBagConstraints.HORIZONTAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2693
            c.anchor = GridBagConstraints.CENTER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2694
            c.weightx = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2695
            c.gridwidth = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2696
            char jmnemonic = getMnemonic("label.jobname");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2697
            lblJobName = new JLabel(getMsg("label.jobname"), JLabel.TRAILING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2698
            lblJobName.setDisplayedMnemonic(jmnemonic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2699
            addToGB(lblJobName, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2700
            c.weightx = 1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2701
            c.gridwidth = GridBagConstraints.REMAINDER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2702
            tfJobName = new JTextField();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2703
            lblJobName.setLabelFor(tfJobName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2704
            tfJobName.addFocusListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2705
            tfJobName.setFocusAccelerator(jmnemonic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2706
            tfJobName.getAccessibleContext().setAccessibleName(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2707
                                             getMsg("label.jobname"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2708
            addToGB(tfJobName, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2709
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2710
            c.weightx = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2711
            c.gridwidth = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2712
            char umnemonic = getMnemonic("label.username");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2713
            lblUserName = new JLabel(getMsg("label.username"), JLabel.TRAILING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2714
            lblUserName.setDisplayedMnemonic(umnemonic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2715
            addToGB(lblUserName, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2716
            c.gridwidth = GridBagConstraints.REMAINDER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2717
            tfUserName = new JTextField();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2718
            lblUserName.setLabelFor(tfUserName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2719
            tfUserName.addFocusListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2720
            tfUserName.setFocusAccelerator(umnemonic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2721
            tfUserName.getAccessibleContext().setAccessibleName(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2722
                                             getMsg("label.username"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2723
            addToGB(tfUserName, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2724
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2725
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2726
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2727
            if (cbJobSheets.isSelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2728
                asCurrent.add(JobSheets.STANDARD);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2729
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2730
                asCurrent.add(JobSheets.NONE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2731
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2732
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2733
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2734
        public void stateChanged(ChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2735
            asCurrent.add(new JobPriority(snModel.getNumber().intValue()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2736
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2737
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2738
        public void focusLost(FocusEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2739
            Object source = e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2740
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2741
            if (source == tfJobName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2742
                asCurrent.add(new JobName(tfJobName.getText(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2743
                                          Locale.getDefault()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2744
            } else if (source == tfUserName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2745
                asCurrent.add(new RequestingUserName(tfUserName.getText(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2746
                                                     Locale.getDefault()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2747
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2748
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2749
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2750
        public void focusGained(FocusEvent e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2751
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2752
        public void updateInfo() {
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  2753
            Class<JobSheets>          jsCategory = JobSheets.class;
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  2754
            Class<JobPriority>        jpCategory = JobPriority.class;
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  2755
            Class<JobName>            jnCategory = JobName.class;
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  2756
            Class<RequestingUserName> unCategory = RequestingUserName.class;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2757
            boolean jsSupported = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2758
            boolean jpSupported = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2759
            boolean jnSupported = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2760
            boolean unSupported = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2761
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2762
            // setup JobSheets checkbox
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2763
            if (psCurrent.isAttributeCategorySupported(jsCategory)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2764
                jsSupported = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2765
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2766
            JobSheets js = (JobSheets)asCurrent.get(jsCategory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2767
            if (js == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2768
                js = (JobSheets)psCurrent.getDefaultAttributeValue(jsCategory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2769
                if (js == null) {
40172
87175987096e 6575247: Banner checkbox in PrinterJob print dialog doesn't work
psadhukhan
parents: 39865
diff changeset
  2770
                    js = JobSheets.STANDARD;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2771
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2772
            }
40172
87175987096e 6575247: Banner checkbox in PrinterJob print dialog doesn't work
psadhukhan
parents: 39865
diff changeset
  2773
            cbJobSheets.setSelected(js != JobSheets.NONE && jsSupported);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2774
            cbJobSheets.setEnabled(jsSupported);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2775
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2776
            // setup JobPriority spinner
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2777
            if (!isAWT && psCurrent.isAttributeCategorySupported(jpCategory)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2778
                jpSupported = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2779
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2780
            JobPriority jp = (JobPriority)asCurrent.get(jpCategory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2781
            if (jp == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2782
                jp = (JobPriority)psCurrent.getDefaultAttributeValue(jpCategory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2783
                if (jp == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2784
                    jp = new JobPriority(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2785
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2786
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2787
            int value = jp.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2788
            if ((value < 1) || (value > 100)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2789
                value = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2790
            }
25777
bb88947b6766 8049893: Replace uses of 'new Integer()' with appropriate alternative across client classes
prr
parents: 25140
diff changeset
  2791
            snModel.setValue(value);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2792
            lblPriority.setEnabled(jpSupported);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2793
            spinPriority.setEnabled(jpSupported);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2794
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2795
            // setup JobName text field
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2796
            if (psCurrent.isAttributeCategorySupported(jnCategory)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2797
                jnSupported = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2798
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2799
            JobName jn = (JobName)asCurrent.get(jnCategory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2800
            if (jn == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2801
                jn = (JobName)psCurrent.getDefaultAttributeValue(jnCategory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2802
                if (jn == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2803
                    jn = new JobName("", Locale.getDefault());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2804
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2805
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2806
            tfJobName.setText(jn.getValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2807
            tfJobName.setEnabled(jnSupported);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2808
            lblJobName.setEnabled(jnSupported);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2809
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2810
            // setup RequestingUserName text field
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2811
            if (!isAWT && psCurrent.isAttributeCategorySupported(unCategory)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2812
                unSupported = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2813
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2814
            RequestingUserName un = (RequestingUserName)asCurrent.get(unCategory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2815
            if (un == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2816
                un = (RequestingUserName)psCurrent.getDefaultAttributeValue(unCategory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2817
                if (un == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2818
                    un = new RequestingUserName("", Locale.getDefault());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2819
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2820
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2821
            tfUserName.setText(un.getValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2822
            tfUserName.setEnabled(unSupported);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2823
            lblUserName.setEnabled(unSupported);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2824
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2825
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2826
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2827
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2828
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2829
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2830
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2831
     * A special widget that groups a JRadioButton with an associated icon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2832
     * placed to the left of the radio button.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2833
     */
23648
a95041026433 8037139: Fix serial lint warnings in sun.print
darcy
parents: 23010
diff changeset
  2834
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2835
    private class IconRadioButton extends JPanel {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2836
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2837
        private JRadioButton rb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2838
        private JLabel lbl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2839
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2840
        public IconRadioButton(String key, String img, boolean selected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2841
                               ButtonGroup bg, ActionListener al)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2842
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2843
            super(new FlowLayout(FlowLayout.LEADING));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2844
            final URL imgURL = getImageResource(img);
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  2845
            Icon icon = java.security.AccessController.doPrivileged(
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  2846
                                 new java.security.PrivilegedAction<Icon>() {
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  2847
                public Icon run() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2848
                    Icon icon = new ImageIcon(imgURL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2849
                    return icon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2850
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2851
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2852
            lbl = new JLabel(icon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2853
            add(lbl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2854
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2855
            rb = createRadioButton(key, al);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2856
            rb.setSelected(selected);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2857
            addToBG(rb, this, bg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2858
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2859
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2860
        public void addActionListener(ActionListener al) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2861
            rb.addActionListener(al);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2862
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2863
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2864
        public boolean isSameAs(Object source) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2865
            return (rb == source);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2866
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2867
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2868
        public void setEnabled(boolean enabled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2869
            rb.setEnabled(enabled);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2870
            lbl.setEnabled(enabled);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2871
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2872
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2873
        public boolean isSelected() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2874
            return rb.isSelected();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2875
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2876
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2877
        public void setSelected(boolean selected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2878
            rb.setSelected(selected);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2879
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2880
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2881
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2882
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2883
     * Similar in functionality to the default JFileChooser, except this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2884
     * chooser will pop up a "Do you want to overwrite..." dialog if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2885
     * user selects a file that already exists.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2886
     */
23648
a95041026433 8037139: Fix serial lint warnings in sun.print
darcy
parents: 23010
diff changeset
  2887
    @SuppressWarnings("serial") // JDK implementation class
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2888
    private class ValidatingFileChooser extends JFileChooser {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2889
        public void approveSelection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2890
            File selected = getSelectedFile();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2891
            boolean exists;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2892
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2893
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2894
                exists = selected.exists();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2895
            } catch (SecurityException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2896
                exists = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2897
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2898
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2899
            if (exists) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2900
                int val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2901
                val = JOptionPane.showConfirmDialog(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2902
                                                    getMsg("dialog.overwrite"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2903
                                                    getMsg("dialog.owtitle"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2904
                                                    JOptionPane.YES_NO_OPTION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2905
                if (val != JOptionPane.YES_OPTION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2906
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2907
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2908
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2909
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2910
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2911
                if (selected.createNewFile()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2912
                    selected.delete();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2913
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2914
            }  catch (IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2915
                JOptionPane.showMessageDialog(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2916
                                   getMsg("dialog.writeerror")+" "+selected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2917
                                   getMsg("dialog.owtitle"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2918
                                   JOptionPane.WARNING_MESSAGE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2919
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2920
            } catch (SecurityException se) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2921
                //There is already file read/write access so at this point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2922
                // only delete access is denied.  Just ignore it because in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2923
                // most cases the file created in createNewFile gets
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2924
                // overwritten anyway.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2925
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2926
            File pFile = selected.getParentFile();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2927
            if ((selected.exists() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2928
                      (!selected.isFile() || !selected.canWrite())) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2929
                     ((pFile != null) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2930
                      (!pFile.exists() || (pFile.exists() && !pFile.canWrite())))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2931
                JOptionPane.showMessageDialog(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2932
                                   getMsg("dialog.writeerror")+" "+selected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2933
                                   getMsg("dialog.owtitle"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2934
                                   JOptionPane.WARNING_MESSAGE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2935
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2936
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2937
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2938
            super.approveSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2939
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2940
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2941
}