jdk/src/share/classes/javax/print/ServiceUI.java
author never
Mon, 12 Jul 2010 22:27:18 -0700
changeset 5926 a36f90d986b6
parent 5506 202f599c92aa
child 19166 e6cd1eb44237
permissions -rw-r--r--
6968385: malformed xml in sweeper logging Reviewed-by: kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2000, 2005, 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: 2
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: 2
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: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
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 javax.print;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.GraphicsConfiguration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.GraphicsDevice;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.GraphicsEnvironment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.HeadlessException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.Dialog;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.Frame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.Point;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.Rectangle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.awt.Window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.awt.KeyboardFocusManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import javax.print.attribute.Attribute;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import javax.print.attribute.AttributeSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import javax.print.attribute.PrintRequestAttributeSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import javax.print.attribute.standard.Destination;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import javax.print.attribute.standard.Fidelity;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import sun.print.ServiceDialog;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import sun.print.SunAlternateMedia;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
/** This class is a collection of UI convenience methods which provide a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * graphical user dialog for browsing print services looked up through the Java
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * Print Service API.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * The dialogs follow a standard pattern of acting as a continue/cancel option
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *for a user as well as allowing the user to select the print service to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *and specify choices such as paper size and number of copies.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * The dialogs are designed to work with pluggable print services though the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * public APIs of those print services.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * If a print service provides any vendor extensions these may be made
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * accessible to the user through a vendor supplied tab panel Component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * Such a vendor extension is encouraged to use Swing! and to support its
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * accessibility APIs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * The vendor extensions should return the settings as part of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * AttributeSet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * Applications which want to preserve the user settings should use those
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * settings to specify the print job.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * Note that this class is not referenced by any other part of the Java
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * Print Service and may not be included in profiles which cannot depend
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * on the presence of the AWT packages.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
public class ServiceUI {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * Presents a dialog to the user for selecting a print service (printer).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * It is displayed at the location specified by the application and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * is modal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * If the specification is invalid or would make the dialog not visible it
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * will be displayed at a location determined by the implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * The dialog blocks its calling thread and is application modal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * The dialog may include a tab panel with custom UI lazily obtained from
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * the PrintService's ServiceUIFactory when the PrintService is browsed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * The dialog will attempt to locate a MAIN_UIROLE first as a JComponent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * then as a Panel. If there is no ServiceUIFactory or no matching role
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * the custom tab will be empty or not visible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * The dialog returns the print service selected by the user if the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * OK's the dialog and null if the user cancels the dialog.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * An application must pass in an array of print services to browse.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * The array must be non-null and non-empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * Typically an application will pass in only PrintServices capable
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * of printing a particular document flavor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * An application may pass in a PrintService to be initially displayed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * A non-null parameter must be included in the array of browsable
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * services.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * If this parameter is null a service is chosen by the implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * An application may optionally pass in the flavor to be printed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * If this is non-null choices presented to the user can be better
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * validated against those supported by the services.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * An application must pass in a PrintRequestAttributeSet for returning
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * user choices.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * On calling the PrintRequestAttributeSet may be empty, or may contain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * application-specified values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * These are used to set the initial settings for the initially
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * displayed print service. Values which are not supported by the print
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * service are ignored. As the user browses print services, attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * and values are copied to the new display. If a user browses a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * print service which does not support a particular attribute-value, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * default for that service is used as the new value to be copied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * If the user cancels the dialog, the returned attributes will not reflect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * any changes made by the user.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * A typical basic usage of this method may be :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * PrintService[] services = PrintServiceLookup.lookupPrintServices(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     *                            DocFlavor.INPUT_STREAM.JPEG, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * if (services.length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     *    PrintService service =  ServiceUI.printDialog(null, 50, 50,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     *                                               services, services[0],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     *                                               null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     *                                               attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     *    if (service != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     *     ... print ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     *    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * @param gc used to select screen. null means primary or default screen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * @param x location of dialog including border in screen coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * @param y location of dialog including border in screen coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * @param services to be browsable, must be non-null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * @param defaultService - initial PrintService to display.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * @param flavor - the flavor to be printed, or null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * @param attributes on input is the initial application supplied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * preferences. This cannot be null but may be empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * On output the attributes reflect changes made by the user.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * @return print service selected by the user, or null if the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * cancelled the dialog.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * @throws HeadlessException if GraphicsEnvironment.isHeadless()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * returns true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * @throws IllegalArgumentException if services is null or empty,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * or attributes is null, or the initial PrintService is not in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * list of browsable services.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    public static PrintService printDialog(GraphicsConfiguration gc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                                           int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                                           PrintService[] services,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                                           PrintService defaultService,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                                           DocFlavor flavor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                                           PrintRequestAttributeSet attributes)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        throws HeadlessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        int defaultIndex = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        if (GraphicsEnvironment.isHeadless()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            throw new HeadlessException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        } else if ((services == null) || (services.length == 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            throw new IllegalArgumentException("services must be non-null " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                                               "and non-empty");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        } else if (attributes == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            throw new IllegalArgumentException("attributes must be non-null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        if (defaultService != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            for (int i = 0; i < services.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                if (services[i].equals(defaultService)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                    defaultIndex = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            if (defaultIndex < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                throw new IllegalArgumentException("services must contain " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                                                   "defaultService");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            defaultIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        // For now we set owner to null. In the future, it may be passed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        // as an argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        Window owner = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        Rectangle gcBounds = (gc == null) ?  GraphicsEnvironment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            getLocalGraphicsEnvironment().getDefaultScreenDevice().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            getDefaultConfiguration().getBounds() : gc.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        ServiceDialog dialog;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        if (owner instanceof Frame) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            dialog = new ServiceDialog(gc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                                       x + gcBounds.x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                                       y + gcBounds.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                                       services, defaultIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                                       flavor, attributes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                                       (Frame)owner);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            dialog = new ServiceDialog(gc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                                       x + gcBounds.x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                                       y + gcBounds.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                                       services, defaultIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                                       flavor, attributes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                                       (Dialog)owner);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        Rectangle dlgBounds = dialog.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        // get union of all GC bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        GraphicsDevice[] gs = ge.getScreenDevices();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        for (int j=0; j<gs.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            gcBounds =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                gcBounds.union(gs[j].getDefaultConfiguration().getBounds());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        // if portion of dialog is not within the gc boundary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        if (!gcBounds.contains(dlgBounds)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            // put in the center relative to parent frame/dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            dialog.setLocationRelativeTo(owner);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        dialog.show();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        if (dialog.getStatus() == ServiceDialog.APPROVE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            PrintRequestAttributeSet newas = dialog.getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            Class dstCategory = Destination.class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            Class amCategory = SunAlternateMedia.class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            Class fdCategory = Fidelity.class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            if (attributes.containsKey(dstCategory) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                !newas.containsKey(dstCategory))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                attributes.remove(dstCategory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            if (attributes.containsKey(amCategory) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                !newas.containsKey(amCategory))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                attributes.remove(amCategory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            attributes.addAll(newas);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            Fidelity fd = (Fidelity)attributes.get(fdCategory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            if (fd != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                if (fd == Fidelity.FIDELITY_TRUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                    removeUnsupportedAttributes(dialog.getPrintService(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                                                flavor, attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        return dialog.getPrintService();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * POSSIBLE FUTURE API: This method may be used down the road if we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * decide to allow developers to explicitly display a "page setup" dialog.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * Currently we use that functionality internally for the AWT print model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    public static void pageDialog(GraphicsConfiguration gc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                                  int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                                  PrintService service,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                                  DocFlavor flavor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                                  PrintRequestAttributeSet attributes)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        throws HeadlessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        if (GraphicsEnvironment.isHeadless()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            throw new HeadlessException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        } else if (service == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            throw new IllegalArgumentException("service must be non-null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        } else if (attributes == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            throw new IllegalArgumentException("attributes must be non-null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        ServiceDialog dialog = new ServiceDialog(gc, x, y, service,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                                                 flavor, attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        dialog.show();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        if (dialog.getStatus() == ServiceDialog.APPROVE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            PrintRequestAttributeSet newas = dialog.getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            Class amCategory = SunAlternateMedia.class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            if (attributes.containsKey(amCategory) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                !newas.containsKey(amCategory))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                attributes.remove(amCategory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            attributes.addAll(newas.values());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        dialog.getOwner().dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * Removes any attributes from the given AttributeSet that are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * unsupported by the given PrintService/DocFlavor combination.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    private static void removeUnsupportedAttributes(PrintService ps,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                                                    DocFlavor flavor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                                                    AttributeSet aset)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        AttributeSet asUnsupported = ps.getUnsupportedAttributes(flavor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                                                                 aset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        if (asUnsupported != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            Attribute[] usAttrs = asUnsupported.toArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            for (int i=0; i<usAttrs.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                Class category = usAttrs[i].getCategory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                if (ps.isAttributeCategorySupported(category)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                    Attribute attr =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                        (Attribute)ps.getDefaultAttributeValue(category);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                    if (attr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                        aset.add(attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                        aset.remove(category);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                    aset.remove(category);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
}