jdk/src/java.desktop/share/classes/sun/print/ServiceDialog.java
author psadhukhan
Fri, 15 Jul 2016 15:30:15 +0530
changeset 39865 62db9aaff554
parent 39847 8d41728f649b
child 40172 87175987096e
permissions -rw-r--r--
5080830: SheetCollate is not handled properly by the cross platform print dlg 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
                 }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
            cbPrintToFile.setEnabled(dstSupported && dstAllowed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
            cbPrintToFile.setSelected(dstSelected && dstAllowed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
                                      && dstSupported);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
            // setup PrintService information widgets
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
            Attribute type = psCurrent.getAttribute(PrinterMakeAndModel.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
            if (type != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
                lblType.setText(type.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
            Attribute status =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
                psCurrent.getAttribute(PrinterIsAcceptingJobs.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
            if (status != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
                lblStatus.setText(getMsg(status.toString()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
            Attribute info = psCurrent.getAttribute(PrinterInfo.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
            if (info != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
                lblInfo.setText(info.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
            btnProperties.setEnabled(uiFactory != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
23648
a95041026433 8037139: Fix serial lint warnings in sun.print
darcy
parents: 23010
diff changeset
   970
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
    private class PrintRangePanel extends JPanel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
        implements ActionListener, FocusListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
        private final String strTitle = getMsg("border.printrange");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
        private final PageRanges prAll = new PageRanges(1, Integer.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
        private JRadioButton rbAll, rbPages, rbSelect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
        private JFormattedTextField tfRangeFrom, tfRangeTo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
        private JLabel lblRangeTo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
        private boolean prSupported;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
        public PrintRangePanel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
            super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
            GridBagLayout gridbag = new GridBagLayout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
            GridBagConstraints c = new GridBagConstraints();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
            setLayout(gridbag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
            setBorder(BorderFactory.createTitledBorder(strTitle));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
            c.fill = GridBagConstraints.BOTH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
            c.insets = compInsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
            c.gridwidth = GridBagConstraints.REMAINDER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
            ButtonGroup bg = new ButtonGroup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
            JPanel pnlTop = new JPanel(new FlowLayout(FlowLayout.LEADING));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
            rbAll = createRadioButton("radiobutton.rangeall", this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
            rbAll.setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
            bg.add(rbAll);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
            pnlTop.add(rbAll);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
            addToGB(pnlTop, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
            // Selection never seemed to work so I'm commenting this part.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
            if (isAWT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
                JPanel pnlMiddle  =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
                    new JPanel(new FlowLayout(FlowLayout.LEADING));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
                rbSelect =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
                    createRadioButton("radiobutton.selection", this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
                bg.add(rbSelect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
                pnlMiddle.add(rbSelect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
                addToGB(pnlMiddle, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
            */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
            JPanel pnlBottom = new JPanel(new FlowLayout(FlowLayout.LEADING));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
            rbPages = createRadioButton("radiobutton.rangepages", this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
            bg.add(rbPages);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
            pnlBottom.add(rbPages);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
            DecimalFormat format = new DecimalFormat("####0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
            format.setMinimumFractionDigits(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
            format.setMaximumFractionDigits(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
            format.setMinimumIntegerDigits(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
            format.setMaximumIntegerDigits(5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
            format.setParseIntegerOnly(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
            format.setDecimalSeparatorAlwaysShown(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
            NumberFormatter nf = new NumberFormatter(format);
25777
bb88947b6766 8049893: Replace uses of 'new Integer()' with appropriate alternative across client classes
prr
parents: 25140
diff changeset
  1027
            nf.setMinimum(1);
bb88947b6766 8049893: Replace uses of 'new Integer()' with appropriate alternative across client classes
prr
parents: 25140
diff changeset
  1028
            nf.setMaximum(Integer.MAX_VALUE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
            nf.setAllowsInvalid(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
            nf.setCommitsOnValidEdit(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
            tfRangeFrom = new JFormattedTextField(nf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
            tfRangeFrom.setColumns(4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
            tfRangeFrom.setEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
            tfRangeFrom.addActionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
            tfRangeFrom.addFocusListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
            tfRangeFrom.setFocusLostBehavior(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
                JFormattedTextField.PERSIST);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
            tfRangeFrom.getAccessibleContext().setAccessibleName(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
                                          getMsg("radiobutton.rangepages"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
            pnlBottom.add(tfRangeFrom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
            lblRangeTo = new JLabel(getMsg("label.rangeto"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
            lblRangeTo.setEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
            pnlBottom.add(lblRangeTo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
            NumberFormatter nfto;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
                nfto = (NumberFormatter)nf.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
            } catch (CloneNotSupportedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
                nfto = new NumberFormatter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
            tfRangeTo = new JFormattedTextField(nfto);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
            tfRangeTo.setColumns(4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
            tfRangeTo.setEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
            tfRangeTo.addFocusListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
            tfRangeTo.getAccessibleContext().setAccessibleName(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
                                          getMsg("label.rangeto"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
            pnlBottom.add(tfRangeTo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
            addToGB(pnlBottom, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
            Object source = e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
            SunPageSelection select = SunPageSelection.ALL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
            setupRangeWidgets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
            if (source == rbAll) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
                asCurrent.add(prAll);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
            } else if (source == rbSelect) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
                select = SunPageSelection.SELECTION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
            } else if (source == rbPages ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
                       source == tfRangeFrom ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
                       source == tfRangeTo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
                updateRangeAttribute();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
                select = SunPageSelection.RANGE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
            if (isAWT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
                asCurrent.add(select);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
        public void focusLost(FocusEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
            Object source = e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
            if ((source == tfRangeFrom) || (source == tfRangeTo)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
                updateRangeAttribute();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
        public void focusGained(FocusEvent e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
        private void setupRangeWidgets() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
            boolean rangeEnabled = (rbPages.isSelected() && prSupported);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
            tfRangeFrom.setEnabled(rangeEnabled);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
            tfRangeTo.setEnabled(rangeEnabled);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
            lblRangeTo.setEnabled(rangeEnabled);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
        private void updateRangeAttribute() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
            String strFrom = tfRangeFrom.getText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
            String strTo = tfRangeTo.getText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
            int min;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
            int max;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
                min = Integer.parseInt(strFrom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
            } catch (NumberFormatException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
                min = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
                max = Integer.parseInt(strTo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
            } catch (NumberFormatException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
                max = min;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
            if (min < 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
                min = 1;
25777
bb88947b6766 8049893: Replace uses of 'new Integer()' with appropriate alternative across client classes
prr
parents: 25140
diff changeset
  1120
                tfRangeFrom.setValue(1);
2
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 (max < min) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
                max = min;
25777
bb88947b6766 8049893: Replace uses of 'new Integer()' with appropriate alternative across client classes
prr
parents: 25140
diff changeset
  1125
                tfRangeTo.setValue(min);
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
            PageRanges pr = new PageRanges(min, max);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
            asCurrent.add(pr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
        public void updateInfo() {
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  1133
            Class<PageRanges> prCategory = PageRanges.class;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
            prSupported = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
            if (psCurrent.isAttributeCategorySupported(prCategory) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
                   isAWT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
                prSupported = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
            SunPageSelection select = SunPageSelection.ALL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
            int min = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
            int max = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
            PageRanges pr = (PageRanges)asCurrent.get(prCategory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
            if (pr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
                if (!pr.equals(prAll)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
                    select = SunPageSelection.RANGE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
                    int[][] members = pr.getMembers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
                    if ((members.length > 0) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
                        (members[0].length > 1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
                        min = members[0][0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
                        max = members[0][1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
            if (isAWT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
                select = (SunPageSelection)asCurrent.get(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
                                                SunPageSelection.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
            if (select == SunPageSelection.ALL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
                rbAll.setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
            } else if (select == SunPageSelection.SELECTION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
                // Comment this for now -  rbSelect is not initialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
                // because Selection button is not added.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
                // See PrintRangePanel above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
                //rbSelect.setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
            } else { // RANGE
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
                rbPages.setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
            }
25777
bb88947b6766 8049893: Replace uses of 'new Integer()' with appropriate alternative across client classes
prr
parents: 25140
diff changeset
  1175
            tfRangeFrom.setValue(min);
bb88947b6766 8049893: Replace uses of 'new Integer()' with appropriate alternative across client classes
prr
parents: 25140
diff changeset
  1176
            tfRangeTo.setValue(max);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
            rbAll.setEnabled(prSupported);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
            rbPages.setEnabled(prSupported);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
            setupRangeWidgets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
23648
a95041026433 8037139: Fix serial lint warnings in sun.print
darcy
parents: 23010
diff changeset
  1183
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
    private class CopiesPanel extends JPanel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
        implements ActionListener, ChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
        private final String strTitle = getMsg("border.copies");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
        private SpinnerNumberModel snModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
        private JSpinner spinCopies;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
        private JLabel lblCopies;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
        private JCheckBox cbCollate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
        private boolean scSupported;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
        public CopiesPanel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
            super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
            GridBagLayout gridbag = new GridBagLayout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
            GridBagConstraints c = new GridBagConstraints();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
            setLayout(gridbag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
            setBorder(BorderFactory.createTitledBorder(strTitle));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
            c.fill = GridBagConstraints.HORIZONTAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
            c.insets = compInsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
            lblCopies = new JLabel(getMsg("label.numcopies"), JLabel.TRAILING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
            lblCopies.setDisplayedMnemonic(getMnemonic("label.numcopies"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
            lblCopies.getAccessibleContext().setAccessibleName(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
                                             getMsg("label.numcopies"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
            addToGB(lblCopies, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
            snModel = new SpinnerNumberModel(1, 1, 999, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
            spinCopies = new JSpinner(snModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
            lblCopies.setLabelFor(spinCopies);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
            // REMIND
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
            ((JSpinner.NumberEditor)spinCopies.getEditor()).getTextField().setColumns(3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
            spinCopies.addChangeListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
            c.gridwidth = GridBagConstraints.REMAINDER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
            addToGB(spinCopies, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
            cbCollate = createCheckBox("checkbox.collate", this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
            cbCollate.setEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
            addToGB(cbCollate, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
            if (cbCollate.isSelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
                asCurrent.add(SheetCollate.COLLATED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
                asCurrent.add(SheetCollate.UNCOLLATED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
            }
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 stateChanged(ChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
            updateCollateCB();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
            asCurrent.add(new Copies(snModel.getNumber().intValue()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
        private void updateCollateCB() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
            int num = snModel.getNumber().intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
            if (isAWT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
                cbCollate.setEnabled(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
                cbCollate.setEnabled((num > 1) && scSupported);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
        public void updateInfo() {
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  1250
            Class<Copies> cpCategory = Copies.class;
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  1251
            Class<SheetCollate> scCategory = SheetCollate.class;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
            boolean cpSupported = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
            scSupported = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
            // setup Copies spinner
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
            if (psCurrent.isAttributeCategorySupported(cpCategory)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
                cpSupported = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
            CopiesSupported cs =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
                (CopiesSupported)psCurrent.getSupportedAttributeValues(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
                                                       cpCategory, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
            if (cs == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
                cs = new CopiesSupported(1, 999);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
            Copies cp = (Copies)asCurrent.get(cpCategory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
            if (cp == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
                cp = (Copies)psCurrent.getDefaultAttributeValue(cpCategory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
                if (cp == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
                    cp = new Copies(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
            spinCopies.setEnabled(cpSupported);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
            lblCopies.setEnabled(cpSupported);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
            int[][] members = cs.getMembers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
            int min, max;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
            if ((members.length > 0) && (members[0].length > 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
                min = members[0][0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
                max = members[0][1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
                min = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
                max = Integer.MAX_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
            }
25777
bb88947b6766 8049893: Replace uses of 'new Integer()' with appropriate alternative across client classes
prr
parents: 25140
diff changeset
  1284
            snModel.setMinimum(min);
bb88947b6766 8049893: Replace uses of 'new Integer()' with appropriate alternative across client classes
prr
parents: 25140
diff changeset
  1285
            snModel.setMaximum(max);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
            int value = cp.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
            if ((value < min) || (value > max)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
                value = min;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
            }
25777
bb88947b6766 8049893: Replace uses of 'new Integer()' with appropriate alternative across client classes
prr
parents: 25140
diff changeset
  1291
            snModel.setValue(value);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
            // setup Collate checkbox
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
            if (psCurrent.isAttributeCategorySupported(scCategory)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
                scSupported = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
            SheetCollate sc = (SheetCollate)asCurrent.get(scCategory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
            if (sc == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
                sc = (SheetCollate)psCurrent.getDefaultAttributeValue(scCategory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
                if (sc == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
                    sc = SheetCollate.UNCOLLATED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
                }
39865
62db9aaff554 5080830: SheetCollate is not handled properly by the cross platform print dlg
psadhukhan
parents: 39847
diff changeset
  1303
                if (sc != null &&
62db9aaff554 5080830: SheetCollate is not handled properly by the cross platform print dlg
psadhukhan
parents: 39847
diff changeset
  1304
                    !psCurrent.isAttributeValueSupported(sc, docFlavor, asCurrent)) {
62db9aaff554 5080830: SheetCollate is not handled properly by the cross platform print dlg
psadhukhan
parents: 39847
diff changeset
  1305
                    scSupported = false;
62db9aaff554 5080830: SheetCollate is not handled properly by the cross platform print dlg
psadhukhan
parents: 39847
diff changeset
  1306
                }
62db9aaff554 5080830: SheetCollate is not handled properly by the cross platform print dlg
psadhukhan
parents: 39847
diff changeset
  1307
            } else {
62db9aaff554 5080830: SheetCollate is not handled properly by the cross platform print dlg
psadhukhan
parents: 39847
diff changeset
  1308
                if (!psCurrent.isAttributeValueSupported(sc, docFlavor, asCurrent)) {
62db9aaff554 5080830: SheetCollate is not handled properly by the cross platform print dlg
psadhukhan
parents: 39847
diff changeset
  1309
                    scSupported = false;
62db9aaff554 5080830: SheetCollate is not handled properly by the cross platform print dlg
psadhukhan
parents: 39847
diff changeset
  1310
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
            }
39865
62db9aaff554 5080830: SheetCollate is not handled properly by the cross platform print dlg
psadhukhan
parents: 39847
diff changeset
  1312
            cbCollate.setSelected(sc == SheetCollate.COLLATED && scSupported);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
            updateCollateCB();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
     * The "Page Setup" tab.  Includes the controls for MediaSource/MediaTray,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
     * OrientationRequested, and Sides.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
     */
23648
a95041026433 8037139: Fix serial lint warnings in sun.print
darcy
parents: 23010
diff changeset
  1324
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
    private class PageSetupPanel extends JPanel {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
        private MediaPanel pnlMedia;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
        private OrientationPanel pnlOrientation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
        private MarginsPanel pnlMargins;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
        public PageSetupPanel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
            super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
            GridBagLayout gridbag = new GridBagLayout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
            GridBagConstraints c = new GridBagConstraints();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
            setLayout(gridbag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
            c.fill = GridBagConstraints.BOTH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
            c.insets = panelInsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
            c.weightx = 1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
            c.weighty = 1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
            c.gridwidth = GridBagConstraints.REMAINDER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
            pnlMedia = new MediaPanel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
            addToGB(pnlMedia, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
            pnlOrientation = new OrientationPanel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
            c.gridwidth = GridBagConstraints.RELATIVE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
            addToGB(pnlOrientation, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
            pnlMargins = new MarginsPanel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
            pnlOrientation.addOrientationListener(pnlMargins);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
            pnlMedia.addMediaListener(pnlMargins);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
            c.gridwidth = GridBagConstraints.REMAINDER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
            addToGB(pnlMargins, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
        public void updateInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
            pnlMedia.updateInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
            pnlOrientation.updateInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
            pnlMargins.updateInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
23648
a95041026433 8037139: Fix serial lint warnings in sun.print
darcy
parents: 23010
diff changeset
  1366
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
    private class MarginsPanel extends JPanel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
                               implements ActionListener, FocusListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
        private final String strTitle = getMsg("border.margins");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
        private JFormattedTextField leftMargin, rightMargin,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
                                    topMargin, bottomMargin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
        private JLabel lblLeft, lblRight, lblTop, lblBottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
        private int units = MediaPrintableArea.MM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
        // storage for the last margin values calculated, -ve is uninitialised
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
        private float lmVal = -1f,rmVal = -1f, tmVal = -1f, bmVal = -1f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
        // storage for margins as objects mapped into orientation for display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
        private Float lmObj,rmObj,tmObj,bmObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
        public MarginsPanel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
            super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
            GridBagLayout gridbag = new GridBagLayout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
            GridBagConstraints c = new GridBagConstraints();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
            c.fill = GridBagConstraints.HORIZONTAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
            c.weightx = 1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
            c.weighty = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
            c.insets = compInsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
            setLayout(gridbag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
            setBorder(BorderFactory.createTitledBorder(strTitle));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
            String unitsKey = "label.millimetres";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
            String defaultCountry = Locale.getDefault().getCountry();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
            if (defaultCountry != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
                (defaultCountry.equals("") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
                 defaultCountry.equals(Locale.US.getCountry()) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
                 defaultCountry.equals(Locale.CANADA.getCountry()))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
                unitsKey = "label.inches";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
                units = MediaPrintableArea.INCH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
            String unitsMsg = getMsg(unitsKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
            DecimalFormat format;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
            if (units == MediaPrintableArea.MM) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
                format = new DecimalFormat("###.##");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
                format.setMaximumIntegerDigits(3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
                format = new DecimalFormat("##.##");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
                format.setMaximumIntegerDigits(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
            format.setMinimumFractionDigits(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
            format.setMaximumFractionDigits(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
            format.setMinimumIntegerDigits(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
            format.setParseIntegerOnly(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
            format.setDecimalSeparatorAlwaysShown(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
            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
  1419
            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
  1420
            nf.setMaximum(Float.valueOf(999.0f));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
            nf.setAllowsInvalid(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
            nf.setCommitsOnValidEdit(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
            leftMargin = new JFormattedTextField(nf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
            leftMargin.addFocusListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
            leftMargin.addActionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
            leftMargin.getAccessibleContext().setAccessibleName(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
                                              getMsg("label.leftmargin"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
            rightMargin = new JFormattedTextField(nf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
            rightMargin.addFocusListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
            rightMargin.addActionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
            rightMargin.getAccessibleContext().setAccessibleName(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
                                              getMsg("label.rightmargin"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
            topMargin = new JFormattedTextField(nf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
            topMargin.addFocusListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
            topMargin.addActionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
            topMargin.getAccessibleContext().setAccessibleName(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
                                              getMsg("label.topmargin"));
37691
8cd8bdd9280c 6801613: Cross-platform pageDialog and printDialog top margin entry broken
psadhukhan
parents: 32865
diff changeset
  1439
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
            bottomMargin = new JFormattedTextField(nf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
            bottomMargin.addFocusListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
            bottomMargin.addActionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
            bottomMargin.getAccessibleContext().setAccessibleName(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
                                              getMsg("label.bottommargin"));
37691
8cd8bdd9280c 6801613: Cross-platform pageDialog and printDialog top margin entry broken
psadhukhan
parents: 32865
diff changeset
  1445
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
            c.gridwidth = GridBagConstraints.RELATIVE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
            lblLeft = new JLabel(getMsg("label.leftmargin") + " " + unitsMsg,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
                                 JLabel.LEADING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
            lblLeft.setDisplayedMnemonic(getMnemonic("label.leftmargin"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
            lblLeft.setLabelFor(leftMargin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
            addToGB(lblLeft, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
            c.gridwidth = GridBagConstraints.REMAINDER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
            lblRight = new JLabel(getMsg("label.rightmargin") + " " + unitsMsg,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
                                  JLabel.LEADING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
            lblRight.setDisplayedMnemonic(getMnemonic("label.rightmargin"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
            lblRight.setLabelFor(rightMargin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
            addToGB(lblRight, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
            c.gridwidth = GridBagConstraints.RELATIVE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
            addToGB(leftMargin, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
            c.gridwidth = GridBagConstraints.REMAINDER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
            addToGB(rightMargin, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
            // add an invisible spacing component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
            addToGB(new JPanel(), this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
            c.gridwidth = GridBagConstraints.RELATIVE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
            lblTop = new JLabel(getMsg("label.topmargin") + " " + unitsMsg,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
                                JLabel.LEADING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
            lblTop.setDisplayedMnemonic(getMnemonic("label.topmargin"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
            lblTop.setLabelFor(topMargin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
            addToGB(lblTop, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
            c.gridwidth = GridBagConstraints.REMAINDER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
            lblBottom = new JLabel(getMsg("label.bottommargin") +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
                                   " " + unitsMsg, JLabel.LEADING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
            lblBottom.setDisplayedMnemonic(getMnemonic("label.bottommargin"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
            lblBottom.setLabelFor(bottomMargin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
            addToGB(lblBottom, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
            c.gridwidth = GridBagConstraints.RELATIVE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
            addToGB(topMargin, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
            c.gridwidth = GridBagConstraints.REMAINDER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
            addToGB(bottomMargin, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
            Object source = e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
            updateMargins(source);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
        public void focusLost(FocusEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
            Object source = e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
            updateMargins(source);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
        public void focusGained(FocusEvent e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
        /* Get the numbers, use to create a MPA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
         * If its valid, accept it and update the attribute set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
         * If its not valid, then reject it and call updateInfo()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
         * to re-establish the previous entries.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
        public void updateMargins(Object source) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
            if (!(source instanceof JFormattedTextField)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
                JFormattedTextField tf = (JFormattedTextField)source;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
                Float val = (Float)tf.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
                if (val == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
                if (tf == leftMargin && val.equals(lmObj)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
                if (tf == rightMargin && val.equals(rmObj)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
                if (tf == topMargin && val.equals(tmObj)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
                if (tf == bottomMargin && val.equals(bmObj)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
            Float lmTmpObj = (Float)leftMargin.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
            Float rmTmpObj = (Float)rightMargin.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
            Float tmTmpObj = (Float)topMargin.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
            Float bmTmpObj = (Float)bottomMargin.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
            float lm = lmTmpObj.floatValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
            float rm = rmTmpObj.floatValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
            float tm = tmTmpObj.floatValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
            float bm = bmTmpObj.floatValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
            /* adjust for orientation */
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  1542
            Class<OrientationRequested> orCategory = OrientationRequested.class;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
            OrientationRequested or =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
                (OrientationRequested)asCurrent.get(orCategory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
            if (or == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
                or = (OrientationRequested)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
                     psCurrent.getDefaultAttributeValue(orCategory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
            float tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
            if (or == OrientationRequested.REVERSE_PORTRAIT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
                tmp = lm; lm = rm; rm = tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
                tmp = tm; tm = bm; bm = tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
            } else if (or == OrientationRequested.LANDSCAPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
                tmp = lm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
                lm = tm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
                tm = rm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
                rm = bm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
                bm = tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
            } else if (or == OrientationRequested.REVERSE_LANDSCAPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
                tmp = lm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
                lm = bm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
                bm = rm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
                rm = tm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
                tm = tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
            MediaPrintableArea mpa;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
            if ((mpa = validateMargins(lm, rm, tm, bm)) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
                asCurrent.add(mpa);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
                lmVal = lm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
                rmVal = rm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
                tmVal = tm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
                bmVal = bm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
                lmObj = lmTmpObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
                rmObj = rmTmpObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
                tmObj = tmTmpObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
                bmObj = bmTmpObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
                if (lmObj == null || rmObj == null ||
29008
e368342daf04 8072433: copy/paste duplicated tests in some condition statements
prr
parents: 28231
diff changeset
  1581
                    tmObj == null || bmObj == null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
                    leftMargin.setValue(lmObj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
                    rightMargin.setValue(rmObj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
                    topMargin.setValue(tmObj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
                    bottomMargin.setValue(bmObj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
         * This method either accepts the values and creates a new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
         * MediaPrintableArea, or does nothing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
         * It should not attempt to create a printable area from anything
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
         * other than the exact values passed in.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
         * But REMIND/TBD: it would be user friendly to replace margins the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
         * user entered but are out of bounds with the minimum.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
         * At that point this method will need to take responsibility for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
         * updating the "stored" values and the UI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
        private MediaPrintableArea validateMargins(float lm, float rm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
                                                   float tm, float bm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  1606
            Class<MediaPrintableArea> mpaCategory = MediaPrintableArea.class;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
            MediaPrintableArea mpa;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
            MediaPrintableArea mpaMax = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
            MediaSize mediaSize = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
            Media media = (Media)asCurrent.get(Media.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
            if (media == null || !(media instanceof MediaSizeName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
                media = (Media)psCurrent.getDefaultAttributeValue(Media.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
            if (media != null && (media instanceof MediaSizeName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
                MediaSizeName msn = (MediaSizeName)media;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
                mediaSize = MediaSize.getMediaSizeForName(msn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
            if (mediaSize == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
                mediaSize = new MediaSize(8.5f, 11f, Size2DSyntax.INCH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
            if (media != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
                PrintRequestAttributeSet tmpASet =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
                    new HashPrintRequestAttributeSet(asCurrent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
                tmpASet.add(media);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
                Object values =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
                    psCurrent.getSupportedAttributeValues(mpaCategory,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
                                                          docFlavor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
                                                          tmpASet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
                if (values instanceof MediaPrintableArea[] &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
                    ((MediaPrintableArea[])values).length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
                    mpaMax = ((MediaPrintableArea[])values)[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
            if (mpaMax == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
                mpaMax = new MediaPrintableArea(0f, 0f,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
                                                mediaSize.getX(units),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
                                                mediaSize.getY(units),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
                                                units);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
            float wid = mediaSize.getX(units);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
            float hgt = mediaSize.getY(units);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
            float pax = lm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
            float pay = tm;
38983
3cc67a01654b 6509729: javax.print.ServiceUI.printDialog Border/Margin Evaluation is bugged
psadhukhan
parents: 37714
diff changeset
  1649
            float par = rm;
3cc67a01654b 6509729: javax.print.ServiceUI.printDialog Border/Margin Evaluation is bugged
psadhukhan
parents: 37714
diff changeset
  1650
            float pab = bm;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
            float paw = wid - lm - rm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
            float pah = hgt - tm - bm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
            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
  1655
                par <= 0f || pab <= 0f ||
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
                pax < mpaMax.getX(units) || paw > mpaMax.getWidth(units) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
                pay < mpaMax.getY(units) || pah > mpaMax.getHeight(units)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
                return new MediaPrintableArea(lm, tm, paw, pah, units);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
        /* This is complex as a MediaPrintableArea is valid only within
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
         * a particular context of media size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
         * So we need a MediaSize as well as a MediaPrintableArea.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
         * MediaSize can be obtained from MediaSizeName.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
         * If the application specifies a MediaPrintableArea, we accept it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
         * to the extent its valid for the Media they specify. If they
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
         * don't specify a Media, then the default is assumed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
         * If an application doesn't define a MediaPrintableArea, we need to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
         * create a suitable one, this is created using the specified (or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
         * default) Media and default 1 inch margins. This is validated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
         * against the paper in case this is too large for tiny media.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
        public void updateInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
            if (isAWT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
                leftMargin.setEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
                rightMargin.setEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
                topMargin.setEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
                bottomMargin.setEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
                lblLeft.setEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
                lblRight.setEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
                lblTop.setEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
                lblBottom.setEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  1691
            Class<MediaPrintableArea> mpaCategory = MediaPrintableArea.class;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
            MediaPrintableArea mpa =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
                 (MediaPrintableArea)asCurrent.get(mpaCategory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
            MediaPrintableArea mpaMax = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
            MediaSize mediaSize = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
            Media media = (Media)asCurrent.get(Media.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
            if (media == null || !(media instanceof MediaSizeName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
                media = (Media)psCurrent.getDefaultAttributeValue(Media.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
            if (media != null && (media instanceof MediaSizeName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
                MediaSizeName msn = (MediaSizeName)media;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
                mediaSize = MediaSize.getMediaSizeForName(msn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
            if (mediaSize == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
                mediaSize = new MediaSize(8.5f, 11f, Size2DSyntax.INCH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
            if (media != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
                PrintRequestAttributeSet tmpASet =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
                    new HashPrintRequestAttributeSet(asCurrent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
                tmpASet.add(media);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
                Object values =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
                    psCurrent.getSupportedAttributeValues(mpaCategory,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
                                                          docFlavor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
                                                          tmpASet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
                if (values instanceof MediaPrintableArea[] &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
                    ((MediaPrintableArea[])values).length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
                    mpaMax = ((MediaPrintableArea[])values)[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
                } else if (values instanceof MediaPrintableArea) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
                    mpaMax = (MediaPrintableArea)values;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
            if (mpaMax == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
                mpaMax = new MediaPrintableArea(0f, 0f,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
                                                mediaSize.getX(units),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
                                                mediaSize.getY(units),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
                                                units);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
             * At this point we now know as best we can :-
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
             * - the media size
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
             * - the maximum corresponding printable area
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
             * - the media printable area specified by the client, if any.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
             * The next step is to create a default MPA if none was specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
             * 1" margins are used unless they are disproportionately
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
             * large compared to the size of the media.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
            float wid = mediaSize.getX(MediaPrintableArea.INCH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
            float hgt = mediaSize.getY(MediaPrintableArea.INCH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
            float maxMarginRatio = 5f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
            float xMgn, yMgn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
            if (wid > maxMarginRatio) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
                xMgn = 1f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
                xMgn = wid / maxMarginRatio;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
            if (hgt > maxMarginRatio) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
                yMgn = 1f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
                yMgn = hgt / maxMarginRatio;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
            if (mpa == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
                mpa = new MediaPrintableArea(xMgn, yMgn,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
                                             wid-(2*xMgn), hgt-(2*yMgn),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
                                             MediaPrintableArea.INCH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
                asCurrent.add(mpa);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
            float pax = mpa.getX(units);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
            float pay = mpa.getY(units);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
            float paw = mpa.getWidth(units);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
            float pah = mpa.getHeight(units);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
            float paxMax = mpaMax.getX(units);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
            float payMax = mpaMax.getY(units);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
            float pawMax = mpaMax.getWidth(units);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
            float pahMax = mpaMax.getHeight(units);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
            boolean invalid = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
            // If the paper is set to something which is too small to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
            // accommodate a specified printable area, perhaps carried
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
            // over from a larger paper, the adjustment that needs to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
            // performed should seem the most natural from a user's viewpoint.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
            // Since the user is specifying margins, then we are biased
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
            // towards keeping the margins as close to what is specified as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
            // possible, shrinking or growing the printable area.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
            // But the API uses printable area, so you need to know the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
            // media size in which the margins were previously interpreted,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
            // or at least have a record of the margins.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
            // In the case that this is the creation of this UI we do not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
            // have this record, so we are somewhat reliant on the client
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
            // to supply a reasonable default
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
            wid = mediaSize.getX(units);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
            hgt = mediaSize.getY(units);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
            if (lmVal >= 0f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
                invalid = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
                if (lmVal + rmVal > wid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
                    // margins impossible, but maintain P.A if can
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
                    if (paw > pawMax) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
                        paw = pawMax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
                    // try to centre the printable area.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
                    pax = (wid - paw)/2f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
                    pax = (lmVal >= paxMax) ? lmVal : paxMax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
                    paw = wid - pax - rmVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
                if (tmVal + bmVal > hgt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
                    if (pah > pahMax) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
                        pah = pahMax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
                    pay = (hgt - pah)/2f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
                    pay = (tmVal >= payMax) ? tmVal : payMax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
                    pah = hgt - pay - bmVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
            if (pax < paxMax) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
                invalid = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
                pax = paxMax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
            if (pay < payMax) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
                invalid = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
                pay = payMax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
            if (paw > pawMax) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
                invalid = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
                paw = pawMax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
            if (pah > pahMax) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
                invalid = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
                pah = pahMax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
            if ((pax + paw > paxMax + pawMax) || (paw <= 0f)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
                invalid = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
                pax = paxMax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
                paw = pawMax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
            if ((pay + pah > payMax + pahMax) || (pah <= 0f)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
                invalid = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
                pay = payMax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
                pah = pahMax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
            if (invalid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
                mpa = new MediaPrintableArea(pax, pay, paw, pah, units);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
                asCurrent.add(mpa);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1846
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
            /* We now have a valid printable area.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
             * Turn it into margins, using the mediaSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
            lmVal = pax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
            tmVal = pay;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
            rmVal = mediaSize.getX(units) - pax - paw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
            bmVal = mediaSize.getY(units) - pay - pah;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1855
37714
7a0b1c7e7054 8154213: clean up uses of boxed primitive constructors in the java.desktop module
prr
parents: 37691
diff changeset
  1856
            lmObj = lmVal;
7a0b1c7e7054 8154213: clean up uses of boxed primitive constructors in the java.desktop module
prr
parents: 37691
diff changeset
  1857
            rmObj = rmVal;
7a0b1c7e7054 8154213: clean up uses of boxed primitive constructors in the java.desktop module
prr
parents: 37691
diff changeset
  1858
            tmObj = tmVal;
7a0b1c7e7054 8154213: clean up uses of boxed primitive constructors in the java.desktop module
prr
parents: 37691
diff changeset
  1859
            bmObj = bmVal;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
            /* Now we know the values to use, we need to assign them
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
             * to the fields appropriate for the orientation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1863
             * Note: if orientation changes this method must be called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1864
             */
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  1865
            Class<OrientationRequested> orCategory = OrientationRequested.class;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1866
            OrientationRequested or =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1867
                (OrientationRequested)asCurrent.get(orCategory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
            if (or == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
                or = (OrientationRequested)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
                     psCurrent.getDefaultAttributeValue(orCategory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1873
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
            Float tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
            if (or == OrientationRequested.REVERSE_PORTRAIT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
                tmp = lmObj; lmObj = rmObj; rmObj = tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
                tmp = tmObj; tmObj = bmObj; bmObj = tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1879
            }  else if (or == OrientationRequested.LANDSCAPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1880
                tmp = lmObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1881
                lmObj = bmObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
                bmObj = rmObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1883
                rmObj = tmObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
                tmObj = tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1885
            }  else if (or == OrientationRequested.REVERSE_LANDSCAPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1886
                tmp = lmObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
                lmObj = tmObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1888
                tmObj = rmObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1889
                rmObj = bmObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
                bmObj = tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1891
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1893
            leftMargin.setValue(lmObj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1894
            rightMargin.setValue(rmObj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
            topMargin.setValue(tmObj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
            bottomMargin.setValue(bmObj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1897
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1898
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1899
23648
a95041026433 8037139: Fix serial lint warnings in sun.print
darcy
parents: 23010
diff changeset
  1900
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1901
    private class MediaPanel extends JPanel implements ItemListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1902
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1903
        private final String strTitle = getMsg("border.media");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1904
        private JLabel lblSize, lblSource;
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  1905
        private JComboBox<Object> cbSize, cbSource;
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  1906
        private Vector<MediaSizeName> sizes = new Vector<>();
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  1907
        private Vector<MediaTray> sources = new Vector<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1908
        private MarginsPanel pnlMargins = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1909
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1910
        public MediaPanel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1911
            super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1912
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
            GridBagLayout gridbag = new GridBagLayout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1914
            GridBagConstraints c = new GridBagConstraints();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1915
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1916
            setLayout(gridbag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
            setBorder(BorderFactory.createTitledBorder(strTitle));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1918
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  1919
            cbSize = new JComboBox<>();
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  1920
            cbSource = new JComboBox<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1921
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1922
            c.fill = GridBagConstraints.BOTH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1923
            c.insets = compInsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1924
            c.weighty = 1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1925
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1926
            c.weightx = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1927
            lblSize = new JLabel(getMsg("label.size"), JLabel.TRAILING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1928
            lblSize.setDisplayedMnemonic(getMnemonic("label.size"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1929
            lblSize.setLabelFor(cbSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1930
            addToGB(lblSize, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1931
            c.weightx = 1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1932
            c.gridwidth = GridBagConstraints.REMAINDER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1933
            addToGB(cbSize, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1934
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1935
            c.weightx = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1936
            c.gridwidth = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1937
            lblSource = new JLabel(getMsg("label.source"), JLabel.TRAILING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1938
            lblSource.setDisplayedMnemonic(getMnemonic("label.source"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1939
            lblSource.setLabelFor(cbSource);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1940
            addToGB(lblSource, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1941
            c.gridwidth = GridBagConstraints.REMAINDER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1942
            addToGB(cbSource, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1943
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1944
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1945
        private String getMediaName(String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1946
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1947
                // replace characters that would be invalid in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1948
                // a resource key with valid characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1949
                String newkey = key.replace(' ', '-');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1950
                newkey = newkey.replace('#', 'n');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1951
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1952
                return messageRB.getString(newkey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1953
            } catch (java.util.MissingResourceException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1954
                return key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1955
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1956
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1958
        public void itemStateChanged(ItemEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1959
            Object source = e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1960
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1961
            if (e.getStateChange() == ItemEvent.SELECTED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
                if (source == cbSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1963
                    int index = cbSize.getSelectedIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1964
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1965
                    if ((index >= 0) && (index < sizes.size())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1966
                        if ((cbSource.getItemCount() > 1) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
                            (cbSource.getSelectedIndex() >= 1))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
                        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1969
                            int src = cbSource.getSelectedIndex() - 1;
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  1970
                            MediaTray mt = sources.get(src);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1971
                            asCurrent.add(new SunAlternateMedia(mt));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1972
                        }
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  1973
                        asCurrent.add(sizes.get(index));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
                } else if (source == cbSource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1976
                    int index = cbSource.getSelectedIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1977
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1978
                    if ((index >= 1) && (index < (sources.size() + 1))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
                       asCurrent.remove(SunAlternateMedia.class);
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  1980
                       MediaTray newTray = sources.get(index - 1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1981
                       Media m = (Media)asCurrent.get(Media.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1982
                       if (m == null || m instanceof MediaTray) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1983
                           asCurrent.add(newTray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1984
                       } else if (m instanceof MediaSizeName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1985
                           MediaSizeName msn = (MediaSizeName)m;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1986
                           Media def = (Media)psCurrent.getDefaultAttributeValue(Media.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1987
                           if (def instanceof MediaSizeName && def.equals(msn)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1988
                               asCurrent.add(newTray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1989
                           } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1990
                               /* Non-default paper size, so need to store tray
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1991
                                * as SunAlternateMedia
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1992
                                */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1993
                               asCurrent.add(new SunAlternateMedia(newTray));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1994
                           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1995
                       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1996
                    } else if (index == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1997
                        asCurrent.remove(SunAlternateMedia.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1998
                        if (cbSize.getItemCount() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1999
                            int size = cbSize.getSelectedIndex();
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  2000
                            asCurrent.add(sizes.get(size));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2001
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2002
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2003
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2004
            // orientation affects display of margins.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2005
                if (pnlMargins != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2006
                    pnlMargins.updateInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2007
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2008
            }
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
        /* this is ad hoc to keep things simple */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2013
        public void addMediaListener(MarginsPanel pnl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2014
            pnlMargins = pnl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2015
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2016
        public void updateInfo() {
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  2017
            Class<Media> mdCategory = Media.class;
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  2018
            Class<SunAlternateMedia> amCategory = SunAlternateMedia.class;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2019
            boolean mediaSupported = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2020
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2021
            cbSize.removeItemListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2022
            cbSize.removeAllItems();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2023
            cbSource.removeItemListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2024
            cbSource.removeAllItems();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2025
            cbSource.addItem(getMediaName("auto-select"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2026
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2027
            sizes.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2028
            sources.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2029
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2030
            if (psCurrent.isAttributeCategorySupported(mdCategory)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2031
                mediaSupported = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2032
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2033
                Object values =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2034
                    psCurrent.getSupportedAttributeValues(mdCategory,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2035
                                                          docFlavor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2036
                                                          asCurrent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2037
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2038
                if (values instanceof Media[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2039
                    Media[] media = (Media[])values;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2040
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2041
                    for (int i = 0; i < media.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2042
                        Media medium = media[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2043
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2044
                        if (medium instanceof MediaSizeName) {
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  2045
                            sizes.add((MediaSizeName)medium);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2046
                            cbSize.addItem(getMediaName(medium.toString()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2047
                        } else if (medium instanceof MediaTray) {
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  2048
                            sources.add((MediaTray)medium);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2049
                            cbSource.addItem(getMediaName(medium.toString()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2050
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2051
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2052
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2053
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2054
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2055
            boolean msSupported = (mediaSupported && (sizes.size() > 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2056
            lblSize.setEnabled(msSupported);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2057
            cbSize.setEnabled(msSupported);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2058
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2059
            if (isAWT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2060
                cbSource.setEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2061
                lblSource.setEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2062
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2063
                cbSource.setEnabled(mediaSupported);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2064
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2065
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2066
            if (mediaSupported) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2067
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2068
                Media medium = (Media)asCurrent.get(mdCategory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2069
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2070
               // initialize size selection to default
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2071
                Media defMedia = (Media)psCurrent.getDefaultAttributeValue(mdCategory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2072
                if (defMedia instanceof MediaSizeName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2073
                    cbSize.setSelectedIndex(sizes.size() > 0 ? sizes.indexOf(defMedia) : -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2074
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2075
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2076
                if (medium == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2077
                    !psCurrent.isAttributeValueSupported(medium,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2078
                                                         docFlavor, asCurrent)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2079
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2080
                    medium = defMedia;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2081
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2082
                    if (medium == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2083
                        if (sizes.size() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2084
                            medium = (Media)sizes.get(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2085
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2086
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2087
                    if (medium != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2088
                        asCurrent.add(medium);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2089
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2090
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2091
                if (medium != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2092
                    if (medium instanceof MediaSizeName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2093
                        MediaSizeName ms = (MediaSizeName)medium;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2094
                        cbSize.setSelectedIndex(sizes.indexOf(ms));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2095
                    } else if (medium instanceof MediaTray) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2096
                        MediaTray mt = (MediaTray)medium;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2097
                        cbSource.setSelectedIndex(sources.indexOf(mt) + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2098
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2099
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2100
                    cbSize.setSelectedIndex(sizes.size() > 0 ? 0 : -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2101
                    cbSource.setSelectedIndex(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2102
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2103
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2104
                SunAlternateMedia alt = (SunAlternateMedia)asCurrent.get(amCategory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2105
                if (alt != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2106
                    Media md = alt.getMedia();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2107
                    if (md instanceof MediaTray) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2108
                        MediaTray mt = (MediaTray)md;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2109
                        cbSource.setSelectedIndex(sources.indexOf(mt) + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2110
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2111
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2112
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2113
                int selIndex = cbSize.getSelectedIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2114
                if ((selIndex >= 0) && (selIndex < sizes.size())) {
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  2115
                  asCurrent.add(sizes.get(selIndex));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2116
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2117
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2118
                selIndex = cbSource.getSelectedIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2119
                if ((selIndex >= 1) && (selIndex < (sources.size()+1))) {
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  2120
                    MediaTray mt = sources.get(selIndex-1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2121
                    if (medium instanceof MediaTray) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2122
                        asCurrent.add(mt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2123
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2124
                        asCurrent.add(new SunAlternateMedia(mt));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2125
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2126
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2127
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2128
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2129
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2130
            cbSize.addItemListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2131
            cbSource.addItemListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2132
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2134
23648
a95041026433 8037139: Fix serial lint warnings in sun.print
darcy
parents: 23010
diff changeset
  2135
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2136
    private class OrientationPanel extends JPanel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2137
        implements ActionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2138
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2139
        private final String strTitle = getMsg("border.orientation");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2140
        private IconRadioButton rbPortrait, rbLandscape,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2141
                                rbRevPortrait, rbRevLandscape;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2142
        private MarginsPanel pnlMargins = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2143
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2144
        public OrientationPanel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2145
            super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2146
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2147
            GridBagLayout gridbag = new GridBagLayout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2148
            GridBagConstraints c = new GridBagConstraints();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2149
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2150
            setLayout(gridbag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2151
            setBorder(BorderFactory.createTitledBorder(strTitle));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2152
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2153
            c.fill = GridBagConstraints.BOTH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2154
            c.insets = compInsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2155
            c.weighty = 1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2156
            c.gridwidth = GridBagConstraints.REMAINDER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2157
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2158
            ButtonGroup bg = new ButtonGroup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2159
            rbPortrait = new IconRadioButton("radiobutton.portrait",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2160
                                             "orientPortrait.png", true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2161
                                             bg, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2162
            rbPortrait.addActionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2163
            addToGB(rbPortrait, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2164
            rbLandscape = new IconRadioButton("radiobutton.landscape",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2165
                                              "orientLandscape.png", false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2166
                                              bg, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2167
            rbLandscape.addActionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2168
            addToGB(rbLandscape, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2169
            rbRevPortrait = new IconRadioButton("radiobutton.revportrait",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2170
                                                "orientRevPortrait.png", false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2171
                                                bg, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2172
            rbRevPortrait.addActionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2173
            addToGB(rbRevPortrait, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2174
            rbRevLandscape = new IconRadioButton("radiobutton.revlandscape",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2175
                                                 "orientRevLandscape.png", false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2176
                                                 bg, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2177
            rbRevLandscape.addActionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2178
            addToGB(rbRevLandscape, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2179
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2180
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2181
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2182
            Object source = e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2183
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2184
            if (rbPortrait.isSameAs(source)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2185
                asCurrent.add(OrientationRequested.PORTRAIT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2186
            } else if (rbLandscape.isSameAs(source)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2187
                asCurrent.add(OrientationRequested.LANDSCAPE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2188
            } else if (rbRevPortrait.isSameAs(source)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2189
                asCurrent.add(OrientationRequested.REVERSE_PORTRAIT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2190
            } else if (rbRevLandscape.isSameAs(source)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2191
                asCurrent.add(OrientationRequested.REVERSE_LANDSCAPE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2192
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2193
            // orientation affects display of margins.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2194
            if (pnlMargins != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2195
                pnlMargins.updateInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2196
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2197
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2198
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2199
        /* This is ad hoc to keep things simple */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2200
        void addOrientationListener(MarginsPanel pnl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2201
            pnlMargins = pnl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2202
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2203
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2204
        public void updateInfo() {
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  2205
            Class<OrientationRequested> orCategory = OrientationRequested.class;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2206
            boolean pSupported = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2207
            boolean lSupported = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2208
            boolean rpSupported = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2209
            boolean rlSupported = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2210
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2211
            if (isAWT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2212
                pSupported = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2213
                lSupported = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2214
            } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2215
            if (psCurrent.isAttributeCategorySupported(orCategory)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2216
                Object values =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2217
                    psCurrent.getSupportedAttributeValues(orCategory,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2218
                                                          docFlavor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2219
                                                          asCurrent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2220
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2221
                if (values instanceof OrientationRequested[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2222
                    OrientationRequested[] ovalues =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2223
                        (OrientationRequested[])values;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2224
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2225
                    for (int i = 0; i < ovalues.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2226
                        OrientationRequested value = ovalues[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2227
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2228
                        if (value == OrientationRequested.PORTRAIT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2229
                            pSupported = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2230
                        } else if (value == OrientationRequested.LANDSCAPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2231
                            lSupported = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2232
                        } else if (value == OrientationRequested.REVERSE_PORTRAIT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2233
                            rpSupported = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2234
                        } else if (value == OrientationRequested.REVERSE_LANDSCAPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2235
                            rlSupported = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2236
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2237
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2238
                }
2389
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2239
            }
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2240
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2241
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2242
            rbPortrait.setEnabled(pSupported);
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2243
            rbLandscape.setEnabled(lSupported);
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2244
            rbRevPortrait.setEnabled(rpSupported);
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2245
            rbRevLandscape.setEnabled(rlSupported);
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2246
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2247
            OrientationRequested or = (OrientationRequested)asCurrent.get(orCategory);
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2248
            if (or == null ||
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2249
                !psCurrent.isAttributeValueSupported(or, docFlavor, asCurrent)) {
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2250
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2251
                or = (OrientationRequested)psCurrent.getDefaultAttributeValue(orCategory);
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2252
                // 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
  2253
                if ((or != null) &&
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2254
                   !psCurrent.isAttributeValueSupported(or, docFlavor, asCurrent)) {
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2255
                    or = null;
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2256
                    Object values =
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2257
                        psCurrent.getSupportedAttributeValues(orCategory,
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2258
                                                              docFlavor,
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2259
                                                              asCurrent);
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2260
                    if (values instanceof OrientationRequested[]) {
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2261
                        OrientationRequested[] orValues =
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2262
                                            (OrientationRequested[])values;
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2263
                        if (orValues.length > 1) {
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2264
                            // get the first in the list
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2265
                            or = orValues[0];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2266
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2267
                    }
2389
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2268
                }
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2269
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2270
                if (or == null) {
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2271
                    or = OrientationRequested.PORTRAIT;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2272
                }
2389
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2273
                asCurrent.add(or);
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2274
            }
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2275
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2276
            if (or == OrientationRequested.PORTRAIT) {
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2277
                rbPortrait.setSelected(true);
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2278
            } else if (or == OrientationRequested.LANDSCAPE) {
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2279
                rbLandscape.setSelected(true);
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2280
            } else if (or == OrientationRequested.REVERSE_PORTRAIT) {
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2281
                rbRevPortrait.setSelected(true);
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2282
            } else { // if (or == OrientationRequested.REVERSE_LANDSCAPE)
62115d5c2ed3 6735296: Regression: Common print dialog does not show the correct page orientation
jgodinez
parents: 715
diff changeset
  2283
                rbRevLandscape.setSelected(true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2284
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2285
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2286
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2287
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2288
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2289
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2290
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2291
     * The "Appearance" tab.  Includes the controls for Chromaticity,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2292
     * PrintQuality, JobPriority, JobName, and other related job attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2293
     */
23648
a95041026433 8037139: Fix serial lint warnings in sun.print
darcy
parents: 23010
diff changeset
  2294
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2295
    private class AppearancePanel extends JPanel {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2296
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2297
        private ChromaticityPanel pnlChromaticity;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2298
        private QualityPanel pnlQuality;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2299
        private JobAttributesPanel pnlJobAttributes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2300
        private SidesPanel pnlSides;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2301
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2302
        public AppearancePanel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2303
            super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2304
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2305
            GridBagLayout gridbag = new GridBagLayout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2306
            GridBagConstraints c = new GridBagConstraints();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2307
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2308
            setLayout(gridbag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2309
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2310
            c.fill = GridBagConstraints.BOTH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2311
            c.insets = panelInsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2312
            c.weightx = 1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2313
            c.weighty = 1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2314
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2315
            c.gridwidth = GridBagConstraints.RELATIVE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2316
            pnlChromaticity = new ChromaticityPanel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2317
            addToGB(pnlChromaticity, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2318
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2319
            c.gridwidth = GridBagConstraints.REMAINDER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2320
            pnlQuality = new QualityPanel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2321
            addToGB(pnlQuality, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2322
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2323
            c.gridwidth = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2324
            pnlSides = new SidesPanel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2325
            addToGB(pnlSides, 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
            pnlJobAttributes = new JobAttributesPanel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2329
            addToGB(pnlJobAttributes, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2330
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2331
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2332
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2333
        public void updateInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2334
            pnlChromaticity.updateInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2335
            pnlQuality.updateInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2336
            pnlSides.updateInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2337
            pnlJobAttributes.updateInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2338
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2339
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2340
23648
a95041026433 8037139: Fix serial lint warnings in sun.print
darcy
parents: 23010
diff changeset
  2341
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2342
    private class ChromaticityPanel extends JPanel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2343
        implements ActionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2344
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2345
        private final String strTitle = getMsg("border.chromaticity");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2346
        private JRadioButton rbMonochrome, rbColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2347
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2348
        public ChromaticityPanel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2349
            super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2350
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2351
            GridBagLayout gridbag = new GridBagLayout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2352
            GridBagConstraints c = new GridBagConstraints();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2353
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2354
            setLayout(gridbag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2355
            setBorder(BorderFactory.createTitledBorder(strTitle));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2356
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2357
            c.fill = GridBagConstraints.BOTH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2358
            c.gridwidth = GridBagConstraints.REMAINDER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2359
            c.weighty = 1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2360
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2361
            ButtonGroup bg = new ButtonGroup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2362
            rbMonochrome = createRadioButton("radiobutton.monochrome", this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2363
            rbMonochrome.setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2364
            bg.add(rbMonochrome);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2365
            addToGB(rbMonochrome, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2366
            rbColor = createRadioButton("radiobutton.color", this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2367
            bg.add(rbColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2368
            addToGB(rbColor, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2369
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2370
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2371
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2372
            Object source = e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2373
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2374
            // REMIND: use isSameAs if we move to a IconRB in the future
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2375
            if (source == rbMonochrome) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2376
                asCurrent.add(Chromaticity.MONOCHROME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2377
            } else if (source == rbColor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2378
                asCurrent.add(Chromaticity.COLOR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2379
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2380
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2381
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2382
        public void updateInfo() {
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  2383
            Class<Chromaticity> chCategory = Chromaticity.class;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2384
            boolean monoSupported = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2385
            boolean colorSupported = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2386
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2387
            if (isAWT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2388
                monoSupported = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2389
                colorSupported = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2390
            } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2391
            if (psCurrent.isAttributeCategorySupported(chCategory)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2392
                Object values =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2393
                    psCurrent.getSupportedAttributeValues(chCategory,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2394
                                                          docFlavor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2395
                                                          asCurrent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2396
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2397
                if (values instanceof Chromaticity[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2398
                    Chromaticity[] cvalues = (Chromaticity[])values;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2399
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2400
                    for (int i = 0; i < cvalues.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2401
                        Chromaticity value = cvalues[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2402
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2403
                        if (value == Chromaticity.MONOCHROME) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2404
                            monoSupported = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2405
                        } else if (value == Chromaticity.COLOR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2406
                            colorSupported = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2407
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2408
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2409
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2410
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2411
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2412
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2413
            rbMonochrome.setEnabled(monoSupported);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2414
            rbColor.setEnabled(colorSupported);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2415
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2416
            Chromaticity ch = (Chromaticity)asCurrent.get(chCategory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2417
            if (ch == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2418
                ch = (Chromaticity)psCurrent.getDefaultAttributeValue(chCategory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2419
                if (ch == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2420
                    ch = Chromaticity.MONOCHROME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2421
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2422
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2423
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2424
            if (ch == Chromaticity.MONOCHROME) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2425
                rbMonochrome.setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2426
            } else { // if (ch == Chromaticity.COLOR)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2427
                rbColor.setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2428
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2429
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2430
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2431
23648
a95041026433 8037139: Fix serial lint warnings in sun.print
darcy
parents: 23010
diff changeset
  2432
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2433
    private class QualityPanel extends JPanel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2434
        implements ActionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2435
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2436
        private final String strTitle = getMsg("border.quality");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2437
        private JRadioButton rbDraft, rbNormal, rbHigh;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2438
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2439
        public QualityPanel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2440
            super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2441
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2442
            GridBagLayout gridbag = new GridBagLayout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2443
            GridBagConstraints c = new GridBagConstraints();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2444
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2445
            setLayout(gridbag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2446
            setBorder(BorderFactory.createTitledBorder(strTitle));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2447
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2448
            c.fill = GridBagConstraints.BOTH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2449
            c.gridwidth = GridBagConstraints.REMAINDER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2450
            c.weighty = 1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2451
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2452
            ButtonGroup bg = new ButtonGroup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2453
            rbDraft = createRadioButton("radiobutton.draftq", this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2454
            bg.add(rbDraft);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2455
            addToGB(rbDraft, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2456
            rbNormal = createRadioButton("radiobutton.normalq", this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2457
            rbNormal.setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2458
            bg.add(rbNormal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2459
            addToGB(rbNormal, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2460
            rbHigh = createRadioButton("radiobutton.highq", this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2461
            bg.add(rbHigh);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2462
            addToGB(rbHigh, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2463
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2464
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2465
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2466
            Object source = e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2467
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2468
            if (source == rbDraft) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2469
                asCurrent.add(PrintQuality.DRAFT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2470
            } else if (source == rbNormal) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2471
                asCurrent.add(PrintQuality.NORMAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2472
            } else if (source == rbHigh) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2473
                asCurrent.add(PrintQuality.HIGH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2474
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2475
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2476
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2477
        public void updateInfo() {
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  2478
            Class<PrintQuality> pqCategory = PrintQuality.class;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2479
            boolean draftSupported = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2480
            boolean normalSupported = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2481
            boolean highSupported = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2482
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2483
            if (isAWT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2484
                draftSupported = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2485
                normalSupported = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2486
                highSupported = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2487
            } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2488
            if (psCurrent.isAttributeCategorySupported(pqCategory)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2489
                Object values =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2490
                    psCurrent.getSupportedAttributeValues(pqCategory,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2491
                                                          docFlavor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2492
                                                          asCurrent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2493
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2494
                if (values instanceof PrintQuality[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2495
                    PrintQuality[] qvalues = (PrintQuality[])values;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2496
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2497
                    for (int i = 0; i < qvalues.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2498
                        PrintQuality value = qvalues[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2499
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2500
                        if (value == PrintQuality.DRAFT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2501
                            draftSupported = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2502
                        } else if (value == PrintQuality.NORMAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2503
                            normalSupported = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2504
                        } else if (value == PrintQuality.HIGH) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2505
                            highSupported = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2506
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2507
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2508
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2509
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2510
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2511
            rbDraft.setEnabled(draftSupported);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2512
            rbNormal.setEnabled(normalSupported);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2513
            rbHigh.setEnabled(highSupported);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2514
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2515
            PrintQuality pq = (PrintQuality)asCurrent.get(pqCategory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2516
            if (pq == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2517
                pq = (PrintQuality)psCurrent.getDefaultAttributeValue(pqCategory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2518
                if (pq == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2519
                    pq = PrintQuality.NORMAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2520
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2521
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2522
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2523
            if (pq == PrintQuality.DRAFT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2524
                rbDraft.setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2525
            } else if (pq == PrintQuality.NORMAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2526
                rbNormal.setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2527
            } else { // if (pq == PrintQuality.HIGH)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2528
                rbHigh.setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2529
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2530
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2531
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2532
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2533
    }
23648
a95041026433 8037139: Fix serial lint warnings in sun.print
darcy
parents: 23010
diff changeset
  2534
a95041026433 8037139: Fix serial lint warnings in sun.print
darcy
parents: 23010
diff changeset
  2535
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2536
    private class SidesPanel extends JPanel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2537
        implements ActionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2538
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2539
        private final String strTitle = getMsg("border.sides");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2540
        private IconRadioButton rbOneSide, rbTumble, rbDuplex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2541
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2542
        public SidesPanel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2543
            super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2544
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2545
            GridBagLayout gridbag = new GridBagLayout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2546
            GridBagConstraints c = new GridBagConstraints();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2547
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2548
            setLayout(gridbag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2549
            setBorder(BorderFactory.createTitledBorder(strTitle));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2550
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2551
            c.fill = GridBagConstraints.BOTH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2552
            c.insets = compInsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2553
            c.weighty = 1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2554
            c.gridwidth = GridBagConstraints.REMAINDER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2555
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2556
            ButtonGroup bg = new ButtonGroup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2557
            rbOneSide = new IconRadioButton("radiobutton.oneside",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2558
                                            "oneside.png", true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2559
                                            bg, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2560
            rbOneSide.addActionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2561
            addToGB(rbOneSide, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2562
            rbTumble = new IconRadioButton("radiobutton.tumble",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2563
                                           "tumble.png", false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2564
                                           bg, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2565
            rbTumble.addActionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2566
            addToGB(rbTumble, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2567
            rbDuplex = new IconRadioButton("radiobutton.duplex",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2568
                                           "duplex.png", false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2569
                                           bg, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2570
            rbDuplex.addActionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2571
            c.gridwidth = GridBagConstraints.REMAINDER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2572
            addToGB(rbDuplex, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2573
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2574
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2575
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2576
            Object source = e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2577
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2578
            if (rbOneSide.isSameAs(source)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2579
                asCurrent.add(Sides.ONE_SIDED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2580
            } else if (rbTumble.isSameAs(source)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2581
                asCurrent.add(Sides.TUMBLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2582
            } else if (rbDuplex.isSameAs(source)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2583
                asCurrent.add(Sides.DUPLEX);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2584
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2585
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2586
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2587
        public void updateInfo() {
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  2588
            Class<Sides> sdCategory = Sides.class;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2589
            boolean osSupported = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2590
            boolean tSupported = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2591
            boolean dSupported = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2592
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2593
            if (psCurrent.isAttributeCategorySupported(sdCategory)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2594
                Object values =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2595
                    psCurrent.getSupportedAttributeValues(sdCategory,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2596
                                                          docFlavor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2597
                                                          asCurrent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2598
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2599
                if (values instanceof Sides[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2600
                    Sides[] svalues = (Sides[])values;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2601
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2602
                    for (int i = 0; i < svalues.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2603
                        Sides value = svalues[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2604
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2605
                        if (value == Sides.ONE_SIDED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2606
                            osSupported = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2607
                        } else if (value == Sides.TUMBLE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2608
                            tSupported = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2609
                        } else if (value == Sides.DUPLEX) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2610
                            dSupported = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2611
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2612
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2613
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2614
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2615
            rbOneSide.setEnabled(osSupported);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2616
            rbTumble.setEnabled(tSupported);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2617
            rbDuplex.setEnabled(dSupported);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2618
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2619
            Sides sd = (Sides)asCurrent.get(sdCategory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2620
            if (sd == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2621
                sd = (Sides)psCurrent.getDefaultAttributeValue(sdCategory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2622
                if (sd == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2623
                    sd = Sides.ONE_SIDED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2624
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2625
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2626
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2627
            if (sd == Sides.ONE_SIDED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2628
                rbOneSide.setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2629
            } else if (sd == Sides.TUMBLE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2630
                rbTumble.setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2631
            } else { // if (sd == Sides.DUPLEX)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2632
                rbDuplex.setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2633
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2634
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2635
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2636
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2637
23648
a95041026433 8037139: Fix serial lint warnings in sun.print
darcy
parents: 23010
diff changeset
  2638
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2639
    private class JobAttributesPanel extends JPanel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2640
        implements ActionListener, ChangeListener, FocusListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2641
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2642
        private final String strTitle = getMsg("border.jobattributes");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2643
        private JLabel lblPriority, lblJobName, lblUserName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2644
        private JSpinner spinPriority;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2645
        private SpinnerNumberModel snModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2646
        private JCheckBox cbJobSheets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2647
        private JTextField tfJobName, tfUserName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2648
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2649
        public JobAttributesPanel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2650
            super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2651
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2652
            GridBagLayout gridbag = new GridBagLayout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2653
            GridBagConstraints c = new GridBagConstraints();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2654
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2655
            setLayout(gridbag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2656
            setBorder(BorderFactory.createTitledBorder(strTitle));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2657
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2658
            c.fill = GridBagConstraints.NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2659
            c.insets = compInsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2660
            c.weighty = 1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2661
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2662
            cbJobSheets = createCheckBox("checkbox.jobsheets", this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2663
            c.anchor = GridBagConstraints.LINE_START;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2664
            addToGB(cbJobSheets, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2665
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2666
            JPanel pnlTop = new JPanel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2667
            lblPriority = new JLabel(getMsg("label.priority"), JLabel.TRAILING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2668
            lblPriority.setDisplayedMnemonic(getMnemonic("label.priority"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2669
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2670
            pnlTop.add(lblPriority);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2671
            snModel = new SpinnerNumberModel(1, 1, 100, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2672
            spinPriority = new JSpinner(snModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2673
            lblPriority.setLabelFor(spinPriority);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2674
            // REMIND
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2675
            ((JSpinner.NumberEditor)spinPriority.getEditor()).getTextField().setColumns(3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2676
            spinPriority.addChangeListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2677
            pnlTop.add(spinPriority);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2678
            c.anchor = GridBagConstraints.LINE_END;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2679
            c.gridwidth = GridBagConstraints.REMAINDER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2680
            pnlTop.getAccessibleContext().setAccessibleName(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2681
                                       getMsg("label.priority"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2682
            addToGB(pnlTop, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2683
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2684
            c.fill = GridBagConstraints.HORIZONTAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2685
            c.anchor = GridBagConstraints.CENTER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2686
            c.weightx = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2687
            c.gridwidth = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2688
            char jmnemonic = getMnemonic("label.jobname");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2689
            lblJobName = new JLabel(getMsg("label.jobname"), JLabel.TRAILING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2690
            lblJobName.setDisplayedMnemonic(jmnemonic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2691
            addToGB(lblJobName, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2692
            c.weightx = 1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2693
            c.gridwidth = GridBagConstraints.REMAINDER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2694
            tfJobName = new JTextField();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2695
            lblJobName.setLabelFor(tfJobName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2696
            tfJobName.addFocusListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2697
            tfJobName.setFocusAccelerator(jmnemonic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2698
            tfJobName.getAccessibleContext().setAccessibleName(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2699
                                             getMsg("label.jobname"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2700
            addToGB(tfJobName, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2701
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2702
            c.weightx = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2703
            c.gridwidth = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2704
            char umnemonic = getMnemonic("label.username");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2705
            lblUserName = new JLabel(getMsg("label.username"), JLabel.TRAILING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2706
            lblUserName.setDisplayedMnemonic(umnemonic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2707
            addToGB(lblUserName, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2708
            c.gridwidth = GridBagConstraints.REMAINDER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2709
            tfUserName = new JTextField();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2710
            lblUserName.setLabelFor(tfUserName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2711
            tfUserName.addFocusListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2712
            tfUserName.setFocusAccelerator(umnemonic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2713
            tfUserName.getAccessibleContext().setAccessibleName(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2714
                                             getMsg("label.username"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2715
            addToGB(tfUserName, this, gridbag, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2716
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2717
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2718
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2719
            if (cbJobSheets.isSelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2720
                asCurrent.add(JobSheets.STANDARD);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2721
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2722
                asCurrent.add(JobSheets.NONE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2723
            }
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 stateChanged(ChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2727
            asCurrent.add(new JobPriority(snModel.getNumber().intValue()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2728
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2729
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2730
        public void focusLost(FocusEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2731
            Object source = e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2732
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2733
            if (source == tfJobName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2734
                asCurrent.add(new JobName(tfJobName.getText(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2735
                                          Locale.getDefault()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2736
            } else if (source == tfUserName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2737
                asCurrent.add(new RequestingUserName(tfUserName.getText(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2738
                                                     Locale.getDefault()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2739
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2740
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2741
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2742
        public void focusGained(FocusEvent e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2743
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2744
        public void updateInfo() {
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  2745
            Class<JobSheets>          jsCategory = JobSheets.class;
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  2746
            Class<JobPriority>        jpCategory = JobPriority.class;
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  2747
            Class<JobName>            jnCategory = JobName.class;
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  2748
            Class<RequestingUserName> unCategory = RequestingUserName.class;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2749
            boolean jsSupported = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2750
            boolean jpSupported = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2751
            boolean jnSupported = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2752
            boolean unSupported = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2753
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2754
            // setup JobSheets checkbox
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2755
            if (psCurrent.isAttributeCategorySupported(jsCategory)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2756
                jsSupported = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2757
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2758
            JobSheets js = (JobSheets)asCurrent.get(jsCategory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2759
            if (js == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2760
                js = (JobSheets)psCurrent.getDefaultAttributeValue(jsCategory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2761
                if (js == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2762
                    js = JobSheets.NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2763
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2764
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2765
            cbJobSheets.setSelected(js != JobSheets.NONE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2766
            cbJobSheets.setEnabled(jsSupported);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2767
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2768
            // setup JobPriority spinner
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2769
            if (!isAWT && psCurrent.isAttributeCategorySupported(jpCategory)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2770
                jpSupported = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2771
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2772
            JobPriority jp = (JobPriority)asCurrent.get(jpCategory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2773
            if (jp == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2774
                jp = (JobPriority)psCurrent.getDefaultAttributeValue(jpCategory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2775
                if (jp == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2776
                    jp = new JobPriority(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2777
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2778
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2779
            int value = jp.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2780
            if ((value < 1) || (value > 100)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2781
                value = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2782
            }
25777
bb88947b6766 8049893: Replace uses of 'new Integer()' with appropriate alternative across client classes
prr
parents: 25140
diff changeset
  2783
            snModel.setValue(value);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2784
            lblPriority.setEnabled(jpSupported);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2785
            spinPriority.setEnabled(jpSupported);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2786
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2787
            // setup JobName text field
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2788
            if (psCurrent.isAttributeCategorySupported(jnCategory)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2789
                jnSupported = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2790
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2791
            JobName jn = (JobName)asCurrent.get(jnCategory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2792
            if (jn == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2793
                jn = (JobName)psCurrent.getDefaultAttributeValue(jnCategory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2794
                if (jn == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2795
                    jn = new JobName("", Locale.getDefault());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2796
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2797
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2798
            tfJobName.setText(jn.getValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2799
            tfJobName.setEnabled(jnSupported);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2800
            lblJobName.setEnabled(jnSupported);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2801
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2802
            // setup RequestingUserName text field
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2803
            if (!isAWT && psCurrent.isAttributeCategorySupported(unCategory)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2804
                unSupported = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2805
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2806
            RequestingUserName un = (RequestingUserName)asCurrent.get(unCategory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2807
            if (un == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2808
                un = (RequestingUserName)psCurrent.getDefaultAttributeValue(unCategory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2809
                if (un == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2810
                    un = new RequestingUserName("", Locale.getDefault());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2811
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2812
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2813
            tfUserName.setText(un.getValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2814
            tfUserName.setEnabled(unSupported);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2815
            lblUserName.setEnabled(unSupported);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2816
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2817
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2818
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2819
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2820
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2821
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2822
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2823
     * A special widget that groups a JRadioButton with an associated icon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2824
     * placed to the left of the radio button.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2825
     */
23648
a95041026433 8037139: Fix serial lint warnings in sun.print
darcy
parents: 23010
diff changeset
  2826
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2827
    private class IconRadioButton extends JPanel {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2828
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2829
        private JRadioButton rb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2830
        private JLabel lbl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2831
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2832
        public IconRadioButton(String key, String img, boolean selected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2833
                               ButtonGroup bg, ActionListener al)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2834
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2835
            super(new FlowLayout(FlowLayout.LEADING));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2836
            final URL imgURL = getImageResource(img);
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  2837
            Icon icon = java.security.AccessController.doPrivileged(
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  2838
                                 new java.security.PrivilegedAction<Icon>() {
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 23648
diff changeset
  2839
                public Icon run() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2840
                    Icon icon = new ImageIcon(imgURL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2841
                    return icon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2842
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2843
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2844
            lbl = new JLabel(icon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2845
            add(lbl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2846
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2847
            rb = createRadioButton(key, al);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2848
            rb.setSelected(selected);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2849
            addToBG(rb, this, bg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2850
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2851
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2852
        public void addActionListener(ActionListener al) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2853
            rb.addActionListener(al);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2854
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2855
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2856
        public boolean isSameAs(Object source) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2857
            return (rb == source);
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 setEnabled(boolean enabled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2861
            rb.setEnabled(enabled);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2862
            lbl.setEnabled(enabled);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2863
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2864
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2865
        public boolean isSelected() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2866
            return rb.isSelected();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2867
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2868
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2869
        public void setSelected(boolean selected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2870
            rb.setSelected(selected);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2871
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2872
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2873
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2874
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2875
     * Similar in functionality to the default JFileChooser, except this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2876
     * chooser will pop up a "Do you want to overwrite..." dialog if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2877
     * user selects a file that already exists.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2878
     */
23648
a95041026433 8037139: Fix serial lint warnings in sun.print
darcy
parents: 23010
diff changeset
  2879
    @SuppressWarnings("serial") // JDK implementation class
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2880
    private class ValidatingFileChooser extends JFileChooser {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2881
        public void approveSelection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2882
            File selected = getSelectedFile();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2883
            boolean exists;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2884
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2885
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2886
                exists = selected.exists();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2887
            } catch (SecurityException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2888
                exists = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2889
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2890
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2891
            if (exists) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2892
                int val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2893
                val = JOptionPane.showConfirmDialog(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2894
                                                    getMsg("dialog.overwrite"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2895
                                                    getMsg("dialog.owtitle"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2896
                                                    JOptionPane.YES_NO_OPTION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2897
                if (val != JOptionPane.YES_OPTION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2898
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2899
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2900
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2901
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2902
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2903
                if (selected.createNewFile()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2904
                    selected.delete();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2905
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2906
            }  catch (IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2907
                JOptionPane.showMessageDialog(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2908
                                   getMsg("dialog.writeerror")+" "+selected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2909
                                   getMsg("dialog.owtitle"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2910
                                   JOptionPane.WARNING_MESSAGE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2911
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2912
            } catch (SecurityException se) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2913
                //There is already file read/write access so at this point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2914
                // only delete access is denied.  Just ignore it because in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2915
                // most cases the file created in createNewFile gets
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2916
                // overwritten anyway.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2917
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2918
            File pFile = selected.getParentFile();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2919
            if ((selected.exists() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2920
                      (!selected.isFile() || !selected.canWrite())) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2921
                     ((pFile != null) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2922
                      (!pFile.exists() || (pFile.exists() && !pFile.canWrite())))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2923
                JOptionPane.showMessageDialog(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2924
                                   getMsg("dialog.writeerror")+" "+selected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2925
                                   getMsg("dialog.owtitle"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2926
                                   JOptionPane.WARNING_MESSAGE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2927
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2928
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2929
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2930
            super.approveSelection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2931
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2932
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2933
}