jdk/src/windows/classes/sun/print/Win32PrintService.java
author ohair
Wed, 06 Apr 2011 22:06:11 -0700
changeset 9035 1255eb81cc2f
parent 8408 e3dac3bc81d1
child 18116 f26d5963f5cb
child 18522 d4b867568c74
permissions -rw-r--r--
7033660: Update copyright year to 2011 on any files changed in 2011 Reviewed-by: dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
9035
1255eb81cc2f 7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents: 8408
diff changeset
     2
 * Copyright (c) 2000, 2011, 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: 715
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: 715
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: 715
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
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.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.net.URI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.net.URISyntaxException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.net.URL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.Vector;
8363
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
    34
import java.util.HashMap;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.print.DocFlavor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import javax.print.DocPrintJob;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import javax.print.PrintService;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import javax.print.ServiceUIFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import javax.print.attribute.Attribute;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import javax.print.attribute.AttributeSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import javax.print.attribute.AttributeSetUtilities;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import javax.print.attribute.EnumSyntax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import javax.print.attribute.HashAttributeSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import javax.print.attribute.PrintServiceAttribute;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import javax.print.attribute.PrintServiceAttributeSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import javax.print.attribute.HashPrintServiceAttributeSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import javax.print.attribute.standard.PrinterName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import javax.print.attribute.standard.PrinterIsAcceptingJobs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import javax.print.attribute.standard.QueuedJobCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import javax.print.attribute.standard.JobName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import javax.print.attribute.standard.RequestingUserName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import javax.print.attribute.standard.Chromaticity;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import javax.print.attribute.standard.Copies;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
import javax.print.attribute.standard.CopiesSupported;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
import javax.print.attribute.standard.Destination;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
import javax.print.attribute.standard.Fidelity;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
import javax.print.attribute.standard.Media;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
import javax.print.attribute.standard.MediaSizeName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
import javax.print.attribute.standard.MediaSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
import javax.print.attribute.standard.MediaTray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
import javax.print.attribute.standard.MediaPrintableArea;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
import javax.print.attribute.standard.OrientationRequested;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
import javax.print.attribute.standard.PageRanges;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
import javax.print.attribute.standard.PrinterState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
import javax.print.attribute.standard.PrinterStateReason;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
import javax.print.attribute.standard.PrinterStateReasons;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
import javax.print.attribute.standard.Severity;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
import javax.print.attribute.standard.Sides;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
import javax.print.attribute.standard.ColorSupported;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
import javax.print.attribute.standard.PrintQuality;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
import javax.print.attribute.ResolutionSyntax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
import javax.print.attribute.standard.PrinterResolution;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
import javax.print.attribute.standard.SheetCollate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
import javax.print.event.PrintServiceAttributeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
import sun.print.SunPrinterJobService;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
public class Win32PrintService implements PrintService, AttributeUpdater,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                                          SunPrinterJobService {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    public static MediaSize[] predefMedia;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        Class c = Win32MediaSize.class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    private static final DocFlavor[] supportedFlavors = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        DocFlavor.BYTE_ARRAY.GIF,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        DocFlavor.INPUT_STREAM.GIF,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        DocFlavor.URL.GIF,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        DocFlavor.BYTE_ARRAY.JPEG,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        DocFlavor.INPUT_STREAM.JPEG,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        DocFlavor.URL.JPEG,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        DocFlavor.BYTE_ARRAY.PNG,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        DocFlavor.INPUT_STREAM.PNG,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        DocFlavor.URL.PNG,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        DocFlavor.SERVICE_FORMATTED.PAGEABLE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        DocFlavor.SERVICE_FORMATTED.PRINTABLE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        DocFlavor.BYTE_ARRAY.AUTOSENSE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        DocFlavor.URL.AUTOSENSE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        DocFlavor.INPUT_STREAM.AUTOSENSE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    /* let's try to support a few of these */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    private static final Class[] serviceAttrCats = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        PrinterName.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        PrinterIsAcceptingJobs.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        QueuedJobCount.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        ColorSupported.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    /*  it turns out to be inconvenient to store the other categories
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     *  separately because many attributes are in multiple categories.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    private static Class[] otherAttrCats = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        JobName.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        RequestingUserName.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        Copies.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        Destination.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        OrientationRequested.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        PageRanges.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        Media.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        MediaPrintableArea.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        Fidelity.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        // We support collation on 2D printer jobs, even if the driver can't.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        SheetCollate.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        SunAlternateMedia.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        Chromaticity.class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * This table together with methods findWin32Media and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * findMatchingMediaSizeNameMM are declared public as these are also
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * used in WPrinterJob.java.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    public static final MediaSizeName[] dmPaperToPrintService = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
      MediaSizeName.NA_LETTER, MediaSizeName.NA_LETTER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
      MediaSizeName.TABLOID, MediaSizeName.LEDGER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
      MediaSizeName.NA_LEGAL, MediaSizeName.INVOICE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
      MediaSizeName.EXECUTIVE, MediaSizeName.ISO_A3,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
      MediaSizeName.ISO_A4, MediaSizeName.ISO_A4,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
      MediaSizeName.ISO_A5, MediaSizeName.JIS_B4,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
      MediaSizeName.JIS_B5, MediaSizeName.FOLIO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
      MediaSizeName.QUARTO, MediaSizeName.NA_10X14_ENVELOPE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
      MediaSizeName.B, MediaSizeName.NA_LETTER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
      MediaSizeName.NA_NUMBER_9_ENVELOPE, MediaSizeName.NA_NUMBER_10_ENVELOPE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
      MediaSizeName.NA_NUMBER_11_ENVELOPE, MediaSizeName.NA_NUMBER_12_ENVELOPE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
      MediaSizeName.NA_NUMBER_14_ENVELOPE, MediaSizeName.C,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
      MediaSizeName.D, MediaSizeName.E,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
      MediaSizeName.ISO_DESIGNATED_LONG, MediaSizeName.ISO_C5,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
      MediaSizeName.ISO_C3, MediaSizeName.ISO_C4,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
      MediaSizeName.ISO_C6, MediaSizeName.ITALY_ENVELOPE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
      MediaSizeName.ISO_B4, MediaSizeName.ISO_B5,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
      MediaSizeName.ISO_B6, MediaSizeName.ITALY_ENVELOPE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
      MediaSizeName.MONARCH_ENVELOPE, MediaSizeName.PERSONAL_ENVELOPE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
      MediaSizeName.NA_10X15_ENVELOPE, MediaSizeName.NA_9X12_ENVELOPE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
      MediaSizeName.FOLIO, MediaSizeName.ISO_B4,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
      MediaSizeName.JAPANESE_POSTCARD, MediaSizeName.NA_9X11_ENVELOPE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    private static final MediaTray[] dmPaperBinToPrintService = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
      MediaTray.TOP, MediaTray.BOTTOM, MediaTray.MIDDLE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
      MediaTray.MANUAL, MediaTray.ENVELOPE, Win32MediaTray.ENVELOPE_MANUAL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
      Win32MediaTray.AUTO, Win32MediaTray.TRACTOR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
      Win32MediaTray.SMALL_FORMAT, Win32MediaTray.LARGE_FORMAT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
      MediaTray.LARGE_CAPACITY, null, null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
      MediaTray.MAIN, Win32MediaTray.FORMSOURCE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    // from wingdi.h
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    private static int DM_PAPERSIZE = 0x2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    private static int DM_PRINTQUALITY = 0x400;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    private static int DM_YRESOLUTION = 0x2000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    private static final int DMRES_MEDIUM = -3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    private static final int DMRES_HIGH = -4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    private static final int DMORIENT_LANDSCAPE = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    private static final int DMDUP_VERTICAL = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    private static final int DMDUP_HORIZONTAL = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    private static final int DMCOLLATE_TRUE = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    // media sizes with indices above dmPaperToPrintService' length
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    private static final int DMPAPER_A2 = 66;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    private static final int DMPAPER_A6 = 70;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    private static final int DMPAPER_B6_JIS = 88;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    // Bit settings for getPrinterCapabilities which matches that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    // of native getCapabilities in WPrinterJob.cpp
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    private static final int DEVCAP_COLOR = 0x0001;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    private static final int DEVCAP_DUPLEX = 0x0002;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    private static final int DEVCAP_COLLATE = 0x0004;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    private static final int DEVCAP_QUALITY = 0x0008;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    private static final int DEVCAP_POSTSCRIPT = 0x0010;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    private String printer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    private PrinterName name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    private String port;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    transient private PrintServiceAttributeSet lastSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    transient private ServiceNotifier notifier = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    private MediaSizeName[] mediaSizeNames;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    private MediaPrintableArea[] mediaPrintables;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    private MediaTray[] mediaTrays;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    private PrinterResolution[] printRes;
8363
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   209
    private HashMap mpaMap;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    private int nCopies;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    private int prnCaps;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    private int[] defaultSettings;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    private boolean gotTrays;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    private boolean gotCopies;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    private boolean mediaInitialized;
8363
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   217
    private boolean mpaListInitialized;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    private ArrayList idList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    private MediaSize[] mediaSizes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    private boolean isInvalid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    Win32PrintService(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        if (name == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            throw new IllegalArgumentException("null printer name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        printer = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        // initialize flags
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        mediaInitialized = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        gotTrays = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        gotCopies = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        isInvalid = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        printRes = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        prnCaps = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        defaultSettings = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        port = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    public void invalidateService() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        isInvalid = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    public String getName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        return printer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    private PrinterName getPrinterName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        if (name == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            name = new PrinterName(printer, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    public int findPaperID(MediaSizeName msn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        if (msn instanceof Win32MediaSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            Win32MediaSize winMedia = (Win32MediaSize)msn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            return winMedia.getDMPaper();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            for (int id=0; id<dmPaperToPrintService.length;id++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                if (dmPaperToPrintService[id].equals(msn)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                    return id+1; // DMPAPER_LETTER == 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            if (msn.equals(MediaSizeName.ISO_A2)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                return DMPAPER_A2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            else if (msn.equals(MediaSizeName.ISO_A6)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                return DMPAPER_A6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            else if (msn.equals(MediaSizeName.JIS_B6)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                return DMPAPER_B6_JIS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        }
8408
e3dac3bc81d1 7022228: JPRT failure: RuntimeException in SupportedMedia regression test
jgodinez
parents: 8365
diff changeset
   276
e3dac3bc81d1 7022228: JPRT failure: RuntimeException in SupportedMedia regression test
jgodinez
parents: 8365
diff changeset
   277
        // If not found in predefined Windows ID, then we search through
e3dac3bc81d1 7022228: JPRT failure: RuntimeException in SupportedMedia regression test
jgodinez
parents: 8365
diff changeset
   278
        // the returned IDs of the driver because they can define their own
e3dac3bc81d1 7022228: JPRT failure: RuntimeException in SupportedMedia regression test
jgodinez
parents: 8365
diff changeset
   279
        // unique IDs.
e3dac3bc81d1 7022228: JPRT failure: RuntimeException in SupportedMedia regression test
jgodinez
parents: 8365
diff changeset
   280
        initMedia();
e3dac3bc81d1 7022228: JPRT failure: RuntimeException in SupportedMedia regression test
jgodinez
parents: 8365
diff changeset
   281
e3dac3bc81d1 7022228: JPRT failure: RuntimeException in SupportedMedia regression test
jgodinez
parents: 8365
diff changeset
   282
        if ((idList != null) && (mediaSizes != null) &&
e3dac3bc81d1 7022228: JPRT failure: RuntimeException in SupportedMedia regression test
jgodinez
parents: 8365
diff changeset
   283
            (idList.size() == mediaSizes.length)) {
e3dac3bc81d1 7022228: JPRT failure: RuntimeException in SupportedMedia regression test
jgodinez
parents: 8365
diff changeset
   284
            for (int i=0; i< idList.size(); i++) {
e3dac3bc81d1 7022228: JPRT failure: RuntimeException in SupportedMedia regression test
jgodinez
parents: 8365
diff changeset
   285
                if (mediaSizes[i].getMediaSizeName() == msn) {
e3dac3bc81d1 7022228: JPRT failure: RuntimeException in SupportedMedia regression test
jgodinez
parents: 8365
diff changeset
   286
                    return ((Integer)idList.get(i)).intValue();
e3dac3bc81d1 7022228: JPRT failure: RuntimeException in SupportedMedia regression test
jgodinez
parents: 8365
diff changeset
   287
                }
e3dac3bc81d1 7022228: JPRT failure: RuntimeException in SupportedMedia regression test
jgodinez
parents: 8365
diff changeset
   288
            }
e3dac3bc81d1 7022228: JPRT failure: RuntimeException in SupportedMedia regression test
jgodinez
parents: 8365
diff changeset
   289
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    public MediaTray findMediaTray(int dmBin) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        if (dmBin >= 1 && dmBin <= dmPaperBinToPrintService.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            return dmPaperBinToPrintService[dmBin-1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        MediaTray[] trays = getMediaTrays();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        if (trays != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            for (int i=0;i<trays.length;i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                if(trays[i] instanceof Win32MediaTray) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                    Win32MediaTray win32Tray = (Win32MediaTray)trays[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                    if (win32Tray.winID == dmBin) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                        return win32Tray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                    }
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
        return Win32MediaTray.AUTO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    public MediaSizeName findWin32Media(int dmIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        if (dmIndex >= 1 && dmIndex <= dmPaperToPrintService.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
           switch(dmIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            /* matching media sizes with indices beyond
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
               dmPaperToPrintService's length */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            case DMPAPER_A2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                return MediaSizeName.ISO_A2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            case DMPAPER_A6:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                return MediaSizeName.ISO_A6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            case DMPAPER_B6_JIS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                return MediaSizeName.JIS_B6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                return dmPaperToPrintService[dmIndex - 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    private boolean addToUniqueList(ArrayList msnList, MediaSizeName mediaName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        MediaSizeName msn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        for (int i=0; i< msnList.size(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            msn = (MediaSizeName)msnList.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            if (msn == mediaName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        msnList.add(mediaName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    private synchronized void initMedia() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        if (mediaInitialized == true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        mediaInitialized = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        int[] media = getAllMediaIDs(printer, getPort());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        if (media == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        ArrayList msnList = new ArrayList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        ArrayList printableList = new ArrayList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        MediaSizeName mediaName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        boolean added;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        boolean queryFailure = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        float[] prnArea;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        // Get all mediaSizes supported by the printer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        // We convert media to ArrayList idList and pass this to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        // function for getting mediaSizes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        // This is to ensure that mediaSizes and media IDs have 1-1 correspondence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        // We remove from ID list any invalid mediaSize.  Though this is rare,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        // it happens in HP 4050 German driver.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        idList = new ArrayList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        for (int i=0; i < media.length; i++) {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   368
            idList.add(Integer.valueOf(media[i]));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        mediaSizes = getMediaSizes(idList, media);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        for (int i = 0; i < idList.size(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            // match Win ID with our predefined ID using table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            mediaName = findWin32Media(((Integer)idList.get(i)).intValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            // Verify that this standard size is the same size as that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            // reported by the driver. This should be the case except when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            // the driver is mis-using a standard windows paper ID.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            if (mediaName != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                idList.size() == mediaSizes.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                MediaSize win32Size = MediaSize.getMediaSizeForName(mediaName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                MediaSize driverSize = mediaSizes[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                int error = 2540; // == 1/10"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                if (Math.abs(win32Size.getX(1)-driverSize.getX(1)) > error ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                    Math.abs(win32Size.getY(1)-driverSize.getY(1)) > error)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                   mediaName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            // No match found, then we get the MediaSizeName out of the MediaSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            // This requires 1-1 correspondence, lengths must be checked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            if ((mediaName == null) && (idList.size() == mediaSizes.length)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                mediaName = mediaSizes[i].getMediaSizeName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            // Add mediaName to the msnList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            if (mediaName != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                added = addToUniqueList(msnList, mediaName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        // init mediaSizeNames
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        mediaSizeNames = new MediaSizeName[msnList.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        msnList.toArray(mediaSizeNames);
8363
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   406
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
8363
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   408
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   409
    /*
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   410
     * Gets a list of MediaPrintableAreas using a call to native function.
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   411
     *  msn is MediaSizeName used to get a specific printable area.  If null,
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   412
     *  it will get all the supported MediPrintableAreas.
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   413
     */
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   414
    private synchronized MediaPrintableArea[] getMediaPrintables(MediaSizeName msn)
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   415
    {
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   416
        if (msn == null)  {
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   417
            if (mpaListInitialized == true) {
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   418
                return mediaPrintables;
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   419
            }
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   420
        } else {
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   421
            // get from cached mapping of MPAs
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   422
            if (mpaMap != null && (mpaMap.get(msn) != null)) {
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   423
                MediaPrintableArea[] mpaArr = new MediaPrintableArea[1];
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   424
                mpaArr[0] = (MediaPrintableArea)mpaMap.get(msn);
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   425
                return mpaArr;
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   426
            }
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   427
        }
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   428
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   429
        initMedia();
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   430
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   431
        if ((mediaSizeNames == null) && (mediaSizeNames.length == 0)) {
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   432
            return null;
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   433
        }
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   434
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   435
        MediaSizeName[] loopNames;
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   436
        if (msn != null) {
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   437
            loopNames = new MediaSizeName[1];
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   438
            loopNames[0] = msn;
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   439
        } else {
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   440
            loopNames = mediaSizeNames;
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   441
        }
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   442
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   443
        if (mpaMap == null) {
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   444
            mpaMap = new HashMap();
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   445
        }
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   446
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   447
        for (int i=0; i < loopNames.length; i++) {
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   448
            MediaSizeName mediaName = loopNames[i];
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   449
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   450
            if (mpaMap.get(mediaName) != null) {
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   451
                continue;
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   452
             }
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   453
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   454
            if (mediaName != null) {
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   455
                int defPaper = findPaperID(mediaName);
8408
e3dac3bc81d1 7022228: JPRT failure: RuntimeException in SupportedMedia regression test
jgodinez
parents: 8365
diff changeset
   456
                float[] prnArea = (defPaper != 0) ? getMediaPrintableArea(printer, defPaper) : null;
8363
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   457
                MediaPrintableArea printableArea = null;
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   458
                if (prnArea != null) {
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   459
                    try {
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   460
                        printableArea = new MediaPrintableArea(prnArea[0],
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   461
                                                               prnArea[1],
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   462
                                                               prnArea[2],
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   463
                                                               prnArea[3],
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   464
                                                 MediaPrintableArea.INCH);
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   465
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   466
                        mpaMap.put(mediaName, printableArea);
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   467
                    }
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   468
                    catch (IllegalArgumentException e) {
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   469
                    }
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   470
                } else {
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   471
                    // if getting  MPA failed, we use MediaSize
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   472
                    MediaSize ms =
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   473
                        MediaSize.getMediaSizeForName((MediaSizeName)mediaName);
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   474
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   475
                    if (ms != null) {
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   476
                        try {
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   477
                            printableArea = new MediaPrintableArea(0, 0,
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   478
                                                     ms.getX(MediaSize.INCH),
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   479
                                                     ms.getY(MediaSize.INCH),
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   480
                                                     MediaPrintableArea.INCH);
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   481
                            mpaMap.put(mediaName, printableArea);
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   482
                        } catch (IllegalArgumentException e) {
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   483
                        }
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   484
                    }
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   485
                }
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   486
            } //mediaName != null
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   487
        }
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   488
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   489
       if (mpaMap.size() == 0) {
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   490
           return null;
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   491
       }
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   492
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   493
       if (msn != null) {
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   494
           if (mpaMap.get(msn) == null) {
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   495
               return null;
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   496
           }
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   497
           MediaPrintableArea[] mpaArr = new MediaPrintableArea[1];
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   498
           // by this time, we've already gotten the desired MPA
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   499
           mpaArr[0] = (MediaPrintableArea)mpaMap.get(msn);
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   500
           return mpaArr;
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   501
       } else {
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   502
           mediaPrintables = (MediaPrintableArea[])mpaMap.values().toArray(new MediaPrintableArea[0]);
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   503
           mpaListInitialized = true;
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   504
           return mediaPrintables;
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   505
       }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
8363
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   508
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    private synchronized MediaTray[] getMediaTrays() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        if (gotTrays == true && mediaTrays != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
            return mediaTrays;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        String prnPort = getPort();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        int[] mediaTr = getAllMediaTrays(printer, prnPort);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        String[] winMediaTrayNames = getAllMediaTrayNames(printer, prnPort);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        if ((mediaTr == null) || (winMediaTrayNames == null)){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        /* first count how many valid bins there are so we can allocate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
         * an array of the correct size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        int nTray = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        for (int i=0; i < mediaTr.length ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
            if (mediaTr[i] > 0) nTray++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        MediaTray[] arr = new MediaTray[nTray];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        int dmBin;
7939
4b122be94252 6939417: ArrayIndexOutOfBoundsException in Win 7 on selected printers
jgodinez
parents: 5506
diff changeset
   531
4b122be94252 6939417: ArrayIndexOutOfBoundsException in Win 7 on selected printers
jgodinez
parents: 5506
diff changeset
   532
        /* Some drivers in Win 7 don't have the same length for DC_BINS and
4b122be94252 6939417: ArrayIndexOutOfBoundsException in Win 7 on selected printers
jgodinez
parents: 5506
diff changeset
   533
         * DC_BINNAMES so there is no guarantee that lengths of mediaTr and
4b122be94252 6939417: ArrayIndexOutOfBoundsException in Win 7 on selected printers
jgodinez
parents: 5506
diff changeset
   534
         * winMediaTrayNames are equal. To avoid getting ArrayIndexOutOfBounds,
4b122be94252 6939417: ArrayIndexOutOfBoundsException in Win 7 on selected printers
jgodinez
parents: 5506
diff changeset
   535
         * we need to make sure we get the minimum of the two.
4b122be94252 6939417: ArrayIndexOutOfBoundsException in Win 7 on selected printers
jgodinez
parents: 5506
diff changeset
   536
         */
4b122be94252 6939417: ArrayIndexOutOfBoundsException in Win 7 on selected printers
jgodinez
parents: 5506
diff changeset
   537
4b122be94252 6939417: ArrayIndexOutOfBoundsException in Win 7 on selected printers
jgodinez
parents: 5506
diff changeset
   538
        for (int i = 0, j=0; i < Math.min(mediaTr.length, winMediaTrayNames.length); i++) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
            dmBin = mediaTr[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            if (dmBin > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                // check for unsupported DMBINs and create new Win32MediaTray
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                if ((dmBin > dmPaperBinToPrintService.length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                    || (dmPaperBinToPrintService[dmBin-1] == null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                    arr[j++] = new Win32MediaTray(dmBin, winMediaTrayNames[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                    arr[j++] = dmPaperBinToPrintService[dmBin-1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
            // no else - For invalid ids, just ignore it because assigning a "default"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            // value may result in duplicate trays.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        mediaTrays = arr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        gotTrays = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        return mediaTrays;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
    private boolean isSameSize(float w1, float h1, float w2, float h2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        float diffX = w1 - w2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        float diffY = h1 - h2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        // Get diff of reverse dimensions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        // EPSON Stylus COLOR 860 reverses envelope's width & height
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        float diffXrev = w1 - h2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        float diffYrev = h1 - w2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        if (((Math.abs(diffX)<=1) && (Math.abs(diffY)<=1)) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
            ((Math.abs(diffXrev)<=1) && (Math.abs(diffYrev)<=1))){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
          return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
          return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    public MediaSizeName findMatchingMediaSizeNameMM (float w, float h){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        if (predefMedia != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
            for (int k=0; k<predefMedia.length;k++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                if (predefMedia[k] == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
                if (isSameSize(predefMedia[k].getX(MediaSize.MM),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
                               predefMedia[k].getY(MediaSize.MM),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                               w, h)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                  return predefMedia[k].getMediaSizeName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
    private MediaSize[] getMediaSizes(ArrayList idList, int[] media) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        String prnPort = getPort();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        int[] mediaSz = getAllMediaSizes(printer, prnPort);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        String[] winMediaNames = getAllMediaNames(printer, prnPort);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        MediaSizeName msn = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        MediaSize ms = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        float wid, ht;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        if ((mediaSz == null) || (winMediaNames == null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        int nMedia = mediaSz.length/2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        ArrayList msList = new ArrayList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        for (int i = 0; i < nMedia; i++, ms=null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
            wid = mediaSz[i*2]/10f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
            ht = mediaSz[i*2+1]/10f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
          // Make sure to validate wid & ht.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
          // HP LJ 4050 (german) causes IAE in Sonderformat paper, wid & ht
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
          // returned is not constant.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
          if ((wid <= 0) || (ht <= 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
            //Remove corresponding ID from list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
            if (nMedia == media.length) {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   616
                Integer remObj = Integer.valueOf(media[i]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
              idList.remove(idList.indexOf(remObj));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
            continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
          // Find matching media using dimensions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
          // This call matches only with our own predefined sizes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
          msn = findMatchingMediaSizeNameMM(wid, ht);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
          if (msn != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
            ms = MediaSize.getMediaSizeForName(msn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
          if (ms != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
            msList.add(ms);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
          } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
              Win32MediaSize wms =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
                new Win32MediaSize(winMediaNames[i], media[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
              ms = new MediaSize(wid, ht, MediaSize.MM, wms);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
              msList.add(ms);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
            } catch(IllegalArgumentException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
              if (nMedia == media.length) {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   638
                  Integer remObj = Integer.valueOf(media[i]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
                idList.remove(idList.indexOf(remObj));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
            }
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        MediaSize[] arr2 = new MediaSize[msList.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        msList.toArray(arr2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        return arr2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
    private PrinterIsAcceptingJobs getPrinterIsAcceptingJobs() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        if (getJobStatus(printer, 2) != 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
            return PrinterIsAcceptingJobs.NOT_ACCEPTING_JOBS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
            return PrinterIsAcceptingJobs.ACCEPTING_JOBS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
    private PrinterState getPrinterState() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        if (isInvalid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
            return PrinterState.STOPPED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
    private PrinterStateReasons getPrinterStateReasons() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        if (isInvalid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
            PrinterStateReasons psr = new PrinterStateReasons();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
            psr.put(PrinterStateReason.SHUTDOWN, Severity.ERROR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
            return psr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
    private QueuedJobCount getQueuedJobCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        int count = getJobStatus(printer, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
        if (count != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
            return new QueuedJobCount(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
            return new QueuedJobCount(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
    private boolean isSupportedCopies(Copies copies) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
            if (gotCopies == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
                nCopies = getCopiesSupported(printer, getPort());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
                gotCopies = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        int numCopies = copies.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        return (numCopies > 0 && numCopies <= nCopies);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
    private boolean isSupportedMedia(MediaSizeName msn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        initMedia();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
        if (mediaSizeNames != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
            for (int i=0; i<mediaSizeNames.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
                if (msn.equals(mediaSizeNames[i])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
    private boolean isSupportedMediaPrintableArea(MediaPrintableArea mpa) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
8363
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
   718
        getMediaPrintables(null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
        if (mediaPrintables != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
            for (int i=0; i<mediaPrintables.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
                if (mpa.equals(mediaPrintables[i])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
    private boolean isSupportedMediaTray(MediaTray msn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        MediaTray[] trays = getMediaTrays();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
        if (trays != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
            for (int i=0; i<trays.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
                if (msn.equals(trays[i])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
    private int getPrinterCapabilities() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        if (prnCaps == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
            prnCaps = getCapabilities(printer, getPort());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
        return prnCaps;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
    private String getPort() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
        if (port == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
            port = getPrinterPort(printer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
        return port;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
   /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
    * NOTE: defaults indices must match those in WPrinterJob.cpp
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
    private int[] getDefaultPrinterSettings() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
        if (defaultSettings == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
            defaultSettings = getDefaultSettings(printer, getPort());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
        return defaultSettings;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
    private PrinterResolution[] getPrintResolutions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
        if (printRes == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
            int[] prnRes = getAllResolutions(printer, getPort());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
            if (prnRes == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
                printRes = new PrinterResolution[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
                int nRes = prnRes.length/2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
                ArrayList arrList = new ArrayList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
                PrinterResolution pr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
                for (int i=0; i<nRes; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
                  try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
                        pr = new PrinterResolution(prnRes[i*2],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
                                       prnRes[i*2+1], PrinterResolution.DPI);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
                        arrList.add(pr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
                    } catch (IllegalArgumentException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
                printRes = (PrinterResolution[])arrList.toArray(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
                                        new PrinterResolution[arrList.size()]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
        return printRes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
    private boolean isSupportedResolution(PrinterResolution res) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
        PrinterResolution[] supportedRes = getPrintResolutions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
        if (supportedRes != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
            for (int i=0; i<supportedRes.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
                if (res.equals(supportedRes[i])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
    public DocPrintJob createPrintJob() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
      SecurityManager security = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
      if (security != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
        security.checkPrintJobAccess();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
        return new Win32PrintJob(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
    private PrintServiceAttributeSet getDynamicAttributes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
        PrintServiceAttributeSet attrs = new HashPrintServiceAttributeSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
        attrs.add(getPrinterIsAcceptingJobs());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
        attrs.add(getQueuedJobCount());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
        return attrs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
    public PrintServiceAttributeSet getUpdatedAttributes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
        PrintServiceAttributeSet currSet = getDynamicAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
        if (lastSet == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
            lastSet = currSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
            return AttributeSetUtilities.unmodifiableView(currSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
            PrintServiceAttributeSet updates =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
                new HashPrintServiceAttributeSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
            Attribute []attrs =  currSet.toArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
            for (int i=0; i<attrs.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
                Attribute attr = attrs[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
                if (!lastSet.containsValue(attr)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
                    updates.add(attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
            lastSet = currSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
            return AttributeSetUtilities.unmodifiableView(updates);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
    public void wakeNotifier() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
            if (notifier != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
                notifier.wake();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
    public void addPrintServiceAttributeListener(PrintServiceAttributeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
                                                 listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
            if (listener == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
            if (notifier == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
                notifier = new ServiceNotifier(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
            notifier.addListener(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
    public void removePrintServiceAttributeListener(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
                                      PrintServiceAttributeListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
            if (listener == null || notifier == null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
            notifier.removeListener(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
            if (notifier.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
                notifier.stopNotifier();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
                notifier = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
    public <T extends PrintServiceAttribute> T
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
        getAttribute(Class<T> category)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
        if (category == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
            throw new NullPointerException("category");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
        if (!(PrintServiceAttribute.class.isAssignableFrom(category))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
            throw new IllegalArgumentException("Not a PrintServiceAttribute");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
        if (category == ColorSupported.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
            int caps = getPrinterCapabilities();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
            if ((caps & DEVCAP_COLOR) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
                return (T)ColorSupported.SUPPORTED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
                return (T)ColorSupported.NOT_SUPPORTED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
        } else if (category == PrinterName.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
            return (T)getPrinterName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
        } else if (category == PrinterState.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
            return (T)getPrinterState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
        } else if (category == PrinterStateReasons.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
            return (T)getPrinterStateReasons();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
        } else if (category == QueuedJobCount.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
            return (T)getQueuedJobCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
        } else if (category == PrinterIsAcceptingJobs.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
            return (T)getPrinterIsAcceptingJobs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
    public PrintServiceAttributeSet getAttributes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
        PrintServiceAttributeSet attrs = new  HashPrintServiceAttributeSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
        attrs.add(getPrinterName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
        attrs.add(getPrinterIsAcceptingJobs());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
        PrinterState prnState = getPrinterState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
        if (prnState != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
            attrs.add(prnState);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
        PrinterStateReasons prnStateReasons = getPrinterStateReasons();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
        if (prnStateReasons != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
            attrs.add(prnStateReasons);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
        attrs.add(getQueuedJobCount());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
        int caps = getPrinterCapabilities();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
        if ((caps & DEVCAP_COLOR) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
            attrs.add(ColorSupported.SUPPORTED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
            attrs.add(ColorSupported.NOT_SUPPORTED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
        return AttributeSetUtilities.unmodifiableView(attrs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
    public DocFlavor[] getSupportedDocFlavors() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
        int len = supportedFlavors.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
        DocFlavor[] supportedDocFlavors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
        int caps = getPrinterCapabilities();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
        // doc flavors supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
        // if PostScript is supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
        if ((caps & DEVCAP_POSTSCRIPT) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
            supportedDocFlavors = new DocFlavor[len+3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
            System.arraycopy(supportedFlavors, 0, supportedDocFlavors, 0, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
            supportedDocFlavors[len] = DocFlavor.BYTE_ARRAY.POSTSCRIPT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
            supportedDocFlavors[len+1] = DocFlavor.INPUT_STREAM.POSTSCRIPT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
            supportedDocFlavors[len+2] = DocFlavor.URL.POSTSCRIPT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
            supportedDocFlavors = new DocFlavor[len];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
            System.arraycopy(supportedFlavors, 0, supportedDocFlavors, 0, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
        return supportedDocFlavors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
    public boolean isDocFlavorSupported(DocFlavor flavor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
        /* To avoid a native query which may be time-consuming
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
         * do not invoke native unless postscript support is being queried.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
         * Instead just check the ones we 'always' support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
        DocFlavor[] supportedDocFlavors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
        if (isPostScriptFlavor(flavor)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
            supportedDocFlavors = getSupportedDocFlavors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
            supportedDocFlavors = supportedFlavors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
        for (int f=0; f<supportedDocFlavors.length; f++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
            if (flavor.equals(supportedDocFlavors[f])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
    public Class<?>[] getSupportedAttributeCategories() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
        ArrayList categList = new ArrayList(otherAttrCats.length+3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
        for (int i=0; i < otherAttrCats.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
            categList.add(otherAttrCats[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
        int caps = getPrinterCapabilities();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
        if ((caps & DEVCAP_DUPLEX) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
            categList.add(Sides.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
        if ((caps & DEVCAP_QUALITY) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
            int[] defaults = getDefaultPrinterSettings();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
            // Added check: if supported, we should be able to get the default.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
            if ((defaults[3] >= DMRES_HIGH) && (defaults[3] < 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
                categList.add(PrintQuality.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
        PrinterResolution[] supportedRes = getPrintResolutions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
        if ((supportedRes!=null) && (supportedRes.length>0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
            categList.add(PrinterResolution.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
        return (Class[])categList.toArray(new Class[categList.size()]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
    public boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
        isAttributeCategorySupported(Class<? extends Attribute> category)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
        if (category == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
            throw new NullPointerException("null category");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
        if (!(Attribute.class.isAssignableFrom(category))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
            throw new IllegalArgumentException(category +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
                                               " is not an Attribute");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
        Class[] classList = getSupportedAttributeCategories();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
        for (int i = 0; i < classList.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
            if (category.equals(classList[i])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
    public Object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
        getDefaultAttributeValue(Class<? extends Attribute> category)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
        if (category == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
            throw new NullPointerException("null category");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
        if (!Attribute.class.isAssignableFrom(category)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
            throw new IllegalArgumentException(category +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
                                               " is not an Attribute");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
        if (!isAttributeCategorySupported(category)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
        int[] defaults = getDefaultPrinterSettings();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
        // indices must match those in WPrinterJob.cpp
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
        int defPaper = defaults[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
        int defYRes = defaults[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
        int defQuality = defaults[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
        int defCopies = defaults[4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
        int defOrient = defaults[5];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
        int defSides = defaults[6];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
        int defCollate = defaults[7];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
        if (category == Copies.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
            if (defCopies > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
                return new Copies(defCopies);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
                return new Copies(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
        } else if (category == Chromaticity.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
            int caps = getPrinterCapabilities();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
            if ((caps & DEVCAP_COLOR) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
                return Chromaticity.MONOCHROME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
                return Chromaticity.COLOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
        } else if (category == JobName.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
            return new JobName("Java Printing", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
        } else if (category == OrientationRequested.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
            if (defOrient == DMORIENT_LANDSCAPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
                return OrientationRequested.LANDSCAPE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
                return OrientationRequested.PORTRAIT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
        } else if (category == PageRanges.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
            return new PageRanges(1, Integer.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
        } else if (category == Media.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
            MediaSizeName msn = findWin32Media(defPaper);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
            if (msn != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
                if (!isSupportedMedia(msn) && mediaSizeNames != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
                    msn = mediaSizeNames[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
                    defPaper = findPaperID(msn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
                return msn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
             } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
                 initMedia();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
                 if ((mediaSizeNames != null) && (mediaSizeNames.length > 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
                     // if 'mediaSizeNames' is not null, idList and mediaSizes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
                     // cannot be null but to be safe, add a check
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
                     if ((idList != null) && (mediaSizes != null) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
                         (idList.size() == mediaSizes.length)) {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
  1083
                         Integer defIdObj = Integer.valueOf(defPaper);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
                         int index = idList.indexOf(defIdObj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
                         if (index>=0 && index<mediaSizes.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
                             return mediaSizes[index].getMediaSizeName();
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
                     return mediaSizeNames[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
                 }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
        } else if (category == MediaPrintableArea.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
            /* Verify defPaper */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
            MediaSizeName msn = findWin32Media(defPaper);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
            if (msn != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
                !isSupportedMedia(msn) && mediaSizeNames != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
                defPaper = findPaperID(mediaSizeNames[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
            float[] prnArea = getMediaPrintableArea(printer, defPaper);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
            if (prnArea != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
                MediaPrintableArea printableArea = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
                    printableArea = new MediaPrintableArea(prnArea[0],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
                                                           prnArea[1],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
                                                           prnArea[2],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
                                                           prnArea[3],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
                                                           MediaPrintableArea.INCH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
                } catch (IllegalArgumentException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
                return printableArea;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
        } else if (category == SunAlternateMedia.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
        } else if (category == Destination.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
                return new Destination((new File("out.prn")).toURI());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
            } catch (SecurityException se) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
                    return new Destination(new URI("file:out.prn"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
                } catch (URISyntaxException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
        } else if (category == Sides.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
            switch(defSides) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
            case DMDUP_VERTICAL :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
                return Sides.TWO_SIDED_LONG_EDGE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
            case DMDUP_HORIZONTAL :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
                return Sides.TWO_SIDED_SHORT_EDGE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
            default :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
                return Sides.ONE_SIDED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
        } else if (category == PrinterResolution.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
            int yRes = defYRes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
            int xRes = defQuality;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
            if ((xRes < 0) || (yRes < 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
                int res = (yRes > xRes) ? yRes : xRes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
                if (res > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
                 return new PrinterResolution(res, res, PrinterResolution.DPI);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
               return new PrinterResolution(xRes, yRes, PrinterResolution.DPI);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
        } else if (category == ColorSupported.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
            int caps = getPrinterCapabilities();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
            if ((caps & DEVCAP_COLOR) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
                return ColorSupported.SUPPORTED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
                return ColorSupported.NOT_SUPPORTED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
        } else if (category == PrintQuality.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
            if ((defQuality < 0) && (defQuality >= DMRES_HIGH)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
                switch (defQuality) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
                case DMRES_HIGH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
                    return PrintQuality.HIGH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
                case DMRES_MEDIUM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
                    return PrintQuality.NORMAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
                default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
                    return PrintQuality.DRAFT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
        } else if (category == RequestingUserName.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
            String userName = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
              userName = System.getProperty("user.name", "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
            } catch (SecurityException se) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
            return new RequestingUserName(userName, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
        } else if (category == SheetCollate.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
            if (defCollate == DMCOLLATE_TRUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
                return SheetCollate.COLLATED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
                return SheetCollate.UNCOLLATED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
        } else if (category == Fidelity.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
            return Fidelity.FIDELITY_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
    private boolean isPostScriptFlavor(DocFlavor flavor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
        if (flavor.equals(DocFlavor.BYTE_ARRAY.POSTSCRIPT) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
            flavor.equals(DocFlavor.INPUT_STREAM.POSTSCRIPT) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
            flavor.equals(DocFlavor.URL.POSTSCRIPT)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
    private boolean isPSDocAttr(Class category) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
        if (category == OrientationRequested.class || category == Copies.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
    private boolean isAutoSense(DocFlavor flavor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
        if (flavor.equals(DocFlavor.BYTE_ARRAY.AUTOSENSE) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
            flavor.equals(DocFlavor.INPUT_STREAM.AUTOSENSE) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
            flavor.equals(DocFlavor.URL.AUTOSENSE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
    public Object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
        getSupportedAttributeValues(Class<? extends Attribute> category,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
                                    DocFlavor flavor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
                                    AttributeSet attributes)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
        if (category == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
            throw new NullPointerException("null category");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
        if (!Attribute.class.isAssignableFrom(category)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
            throw new IllegalArgumentException(category +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
                                             " does not implement Attribute");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
        if (flavor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
            if (!isDocFlavorSupported(flavor)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
                throw new IllegalArgumentException(flavor +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
                                                  " is an unsupported flavor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
                // if postscript & category is already specified within the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
                //  PostScript data we return null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
            } else if (isAutoSense(flavor) ||(isPostScriptFlavor(flavor) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
                       (isPSDocAttr(category)))){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
        if (!isAttributeCategorySupported(category)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
        if (category == JobName.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
            return new JobName("Java Printing", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
        } else if (category == RequestingUserName.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
          String userName = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
          try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
            userName = System.getProperty("user.name", "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
          } catch (SecurityException se) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
            return new RequestingUserName(userName, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
        } else if (category == ColorSupported.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
            int caps = getPrinterCapabilities();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
            if ((caps & DEVCAP_COLOR) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
                return ColorSupported.SUPPORTED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
                return ColorSupported.NOT_SUPPORTED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
        } else if (category == Chromaticity.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
            if (flavor == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
                flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
                flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
                flavor.equals(DocFlavor.BYTE_ARRAY.GIF) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
                flavor.equals(DocFlavor.INPUT_STREAM.GIF) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
                flavor.equals(DocFlavor.URL.GIF) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
                flavor.equals(DocFlavor.BYTE_ARRAY.JPEG) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
                flavor.equals(DocFlavor.INPUT_STREAM.JPEG) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
                flavor.equals(DocFlavor.URL.JPEG) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
                flavor.equals(DocFlavor.BYTE_ARRAY.PNG) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
                flavor.equals(DocFlavor.INPUT_STREAM.PNG) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
                flavor.equals(DocFlavor.URL.PNG)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
                int caps = getPrinterCapabilities();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
                if ((caps & DEVCAP_COLOR) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
                    Chromaticity []arr = new Chromaticity[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
                    arr[0] = Chromaticity.MONOCHROME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
                    return (arr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
                    Chromaticity []arr = new Chromaticity[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
                    arr[0] = Chromaticity.MONOCHROME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
                    arr[1] = Chromaticity.COLOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
                    return (arr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
        } else if (category == Destination.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
                return new Destination((new File("out.prn")).toURI());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
            } catch (SecurityException se) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
                    return new Destination(new URI("file:out.prn"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
                } catch (URISyntaxException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
        } else if (category == OrientationRequested.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
            if (flavor == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
                flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
                flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
                flavor.equals(DocFlavor.INPUT_STREAM.GIF) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
                flavor.equals(DocFlavor.INPUT_STREAM.JPEG) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
                flavor.equals(DocFlavor.INPUT_STREAM.PNG) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
                flavor.equals(DocFlavor.BYTE_ARRAY.GIF) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
                flavor.equals(DocFlavor.BYTE_ARRAY.JPEG) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
                flavor.equals(DocFlavor.BYTE_ARRAY.PNG) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
                flavor.equals(DocFlavor.URL.GIF) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
                flavor.equals(DocFlavor.URL.JPEG) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
                flavor.equals(DocFlavor.URL.PNG)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
                OrientationRequested []arr = new OrientationRequested[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
                arr[0] = OrientationRequested.PORTRAIT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
                arr[1] = OrientationRequested.LANDSCAPE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
                arr[2] = OrientationRequested.REVERSE_LANDSCAPE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
                return arr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
        } else if ((category == Copies.class) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
                   (category == CopiesSupported.class)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
            synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
                if (gotCopies == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
                    nCopies = getCopiesSupported(printer, getPort());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
                    gotCopies = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
            return new CopiesSupported(1, nCopies);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
        } else if (category == Media.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
            initMedia();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
            int len = (mediaSizeNames == null) ? 0 : mediaSizeNames.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
            MediaTray[] trays = getMediaTrays();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
            len += (trays == null) ? 0 : trays.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
            Media []arr = new Media[len];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
            if (mediaSizeNames != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
                System.arraycopy(mediaSizeNames, 0, arr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
                                 0, mediaSizeNames.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
            if (trays != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
                System.arraycopy(trays, 0, arr,
8365
803a1fd60835 6850806: NPE exception throws in PrintServce.getSupportedAttributeValues
jgodinez
parents: 8363
diff changeset
  1342
                                 len - trays.length, trays.length);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
            return arr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
        } else if (category == MediaPrintableArea.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
            // if getting printable area for a specific media size
8363
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
  1347
            Media mediaName = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
            if ((attributes != null) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
                ((mediaName =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
                  (Media)attributes.get(Media.class)) != null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
8363
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
  1352
                if (!(mediaName instanceof MediaSizeName)) {
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
  1353
                    // if an instance of MediaTray, fall thru returning
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
  1354
                    // all MediaPrintableAreas
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
  1355
                    mediaName = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
8363
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
  1359
            MediaPrintableArea[] mpas =
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
  1360
                                  getMediaPrintables((MediaSizeName)mediaName);
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
  1361
            if (mpas != null) {
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
  1362
                MediaPrintableArea[] arr = new MediaPrintableArea[mpas.length];
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
  1363
                System.arraycopy(mpas, 0, arr, 0, mpas.length);
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
  1364
                return arr;
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
  1365
            } else {
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
  1366
                return null;
63664c9ccde0 6722351: sun.print.Win32PrintService.initMedia() is slow
jgodinez
parents: 7939
diff changeset
  1367
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
        } else if (category == SunAlternateMedia.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
            return new SunAlternateMedia(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
                              (Media)getDefaultAttributeValue(Media.class));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
        } else if (category == PageRanges.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
            if (flavor == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
                flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
                flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
                PageRanges []arr = new PageRanges[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
                arr[0] = new PageRanges(1, Integer.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
                return arr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
        } else if (category == PrinterResolution.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
            PrinterResolution[] supportedRes = getPrintResolutions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
            if (supportedRes == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
            PrinterResolution []arr =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
                new PrinterResolution[supportedRes.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
            System.arraycopy(supportedRes, 0, arr, 0, supportedRes.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
            return arr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
        } else if (category == Sides.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
            if (flavor == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
                flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
                flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
                Sides []arr = new Sides[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
                arr[0] = Sides.ONE_SIDED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
                arr[1] = Sides.TWO_SIDED_LONG_EDGE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
                arr[2] = Sides.TWO_SIDED_SHORT_EDGE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
                return arr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
        } else if (category == PrintQuality.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
            PrintQuality []arr = new PrintQuality[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
            arr[0] = PrintQuality.DRAFT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
            arr[1] = PrintQuality.HIGH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
            arr[2] = PrintQuality.NORMAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
            return arr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
        } else if (category == SheetCollate.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
            if (flavor == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
                (flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
                 flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
                SheetCollate []arr = new SheetCollate[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
                arr[0] = SheetCollate.COLLATED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
                arr[1] = SheetCollate.UNCOLLATED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
                return arr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
        } else if (category == Fidelity.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
            Fidelity []arr = new Fidelity[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
            arr[0] = Fidelity.FIDELITY_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
            arr[1] = Fidelity.FIDELITY_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
            return arr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
    public boolean isAttributeValueSupported(Attribute attr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
                                             DocFlavor flavor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
                                             AttributeSet attributes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
        if (attr == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
            throw new NullPointerException("null attribute");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
        Class category = attr.getCategory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
        if (flavor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
            if (!isDocFlavorSupported(flavor)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
                throw new IllegalArgumentException(flavor +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
                                                   " is an unsupported flavor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
                // if postscript & category is already specified within the PostScript data
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
                // we return false
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
            } else if (isAutoSense(flavor) || (isPostScriptFlavor(flavor) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
                       (isPSDocAttr(category)))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
        if (!isAttributeCategorySupported(category)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
        else if (category == Chromaticity.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
            if ((flavor == null) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
                flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
                flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
                flavor.equals(DocFlavor.BYTE_ARRAY.GIF) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
                flavor.equals(DocFlavor.INPUT_STREAM.GIF) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
                flavor.equals(DocFlavor.URL.GIF) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
                flavor.equals(DocFlavor.BYTE_ARRAY.JPEG) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
                flavor.equals(DocFlavor.INPUT_STREAM.JPEG) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
                flavor.equals(DocFlavor.URL.JPEG) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
                flavor.equals(DocFlavor.BYTE_ARRAY.PNG) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
                flavor.equals(DocFlavor.INPUT_STREAM.PNG) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
                flavor.equals(DocFlavor.URL.PNG)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
                int caps = getPrinterCapabilities();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
                if ((caps & DEVCAP_COLOR) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
                    return attr == Chromaticity.MONOCHROME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
        } else if (category == Copies.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
            return isSupportedCopies((Copies)attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
        } else if (category == Destination.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
            URI uri = ((Destination)attr).getURI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
            if ("file".equals(uri.getScheme()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
                !(uri.getSchemeSpecificPart().equals(""))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
        } else if (category == Media.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
            if (attr instanceof MediaSizeName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
                return isSupportedMedia((MediaSizeName)attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
            if (attr instanceof MediaTray) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
                return isSupportedMediaTray((MediaTray)attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
        } else if (category == MediaPrintableArea.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
            return isSupportedMediaPrintableArea((MediaPrintableArea)attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
        } else if (category == SunAlternateMedia.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
            Media media = ((SunAlternateMedia)attr).getMedia();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
            return isAttributeValueSupported(media, flavor, attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
        } else if (category == PageRanges.class ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
                   category == SheetCollate.class ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
                   category == Sides.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
            if (flavor != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
                !(flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
                flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
        } else if (category == PrinterResolution.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
            if (attr instanceof PrinterResolution) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
                return isSupportedResolution((PrinterResolution)attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
        } else if (category == OrientationRequested.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
            if (attr == OrientationRequested.REVERSE_PORTRAIT ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
                (flavor != null) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
                !(flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
                flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
                flavor.equals(DocFlavor.INPUT_STREAM.GIF) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
                flavor.equals(DocFlavor.INPUT_STREAM.JPEG) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
                flavor.equals(DocFlavor.INPUT_STREAM.PNG) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
                flavor.equals(DocFlavor.BYTE_ARRAY.GIF) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
                flavor.equals(DocFlavor.BYTE_ARRAY.JPEG) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
                flavor.equals(DocFlavor.BYTE_ARRAY.PNG) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
                flavor.equals(DocFlavor.URL.GIF) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
                flavor.equals(DocFlavor.URL.JPEG) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
                flavor.equals(DocFlavor.URL.PNG))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
        } else if (category == ColorSupported.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
            int caps = getPrinterCapabilities();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
            boolean isColorSup = ((caps & DEVCAP_COLOR) != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
            if  ((!isColorSup && (attr == ColorSupported.SUPPORTED)) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
                (isColorSup && (attr == ColorSupported.NOT_SUPPORTED))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
    public AttributeSet getUnsupportedAttributes(DocFlavor flavor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
                                                 AttributeSet attributes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
        if (flavor != null && !isDocFlavorSupported(flavor)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
            throw new IllegalArgumentException("flavor " + flavor +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
                                               "is not supported");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
        if (attributes == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
        Attribute attr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
        AttributeSet unsupp = new HashAttributeSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
        Attribute []attrs = attributes.toArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
        for (int i=0; i<attrs.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
                attr = attrs[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
                if (!isAttributeCategorySupported(attr.getCategory())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
                    unsupp.add(attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
                else if (!isAttributeValueSupported(attr, flavor, attributes)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
                    unsupp.add(attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
            } catch (ClassCastException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
        if (unsupp.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
            return unsupp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
    public ServiceUIFactory getServiceUIFactory() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
        return "Win32 Printer : " + getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
        return  (obj == this ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
                 (obj instanceof Win32PrintService &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
                  ((Win32PrintService)obj).getName().equals(getName())));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
   public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
        return this.getClass().hashCode()+getName().hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
    public boolean usesClass(Class c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
        return (c == sun.awt.windows.WPrinterJob.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
    private native int[] getAllMediaIDs(String printerName, String port);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
    private native int[] getAllMediaSizes(String printerName, String port);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
    private native int[] getAllMediaTrays(String printerName, String port);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
    private native float[] getMediaPrintableArea(String printerName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
                                                 int paperSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
    private native String[] getAllMediaNames(String printerName, String port);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
    private native String[] getAllMediaTrayNames(String printerName, String port);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
    private native int getCopiesSupported(String printerName, String port);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
    private native int[] getAllResolutions(String printerName, String port);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
    private native int getCapabilities(String printerName, String port);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
    private native int[] getDefaultSettings(String printerName, String port);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
    private native int getJobStatus(String printerName, int type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
    private native String getPrinterPort(String printerName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
class Win32MediaSize extends MediaSizeName {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
    private static ArrayList winStringTable = new ArrayList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
    private static ArrayList winEnumTable = new ArrayList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
    private int dmPaperID; // driver ID for this paper.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
    private Win32MediaSize(int x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
        super(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
    private synchronized static int nextValue(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
      winStringTable.add(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
      return (winStringTable.size()-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
    public Win32MediaSize(String name, int dmPaper) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
        super(nextValue(name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
        dmPaperID = dmPaper;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
        winEnumTable.add(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
    private MediaSizeName[] getSuperEnumTable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
      return (MediaSizeName[])super.getEnumValueTable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
         /* initialize Win32PrintService.predefMedia */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
            Win32MediaSize winMedia = new Win32MediaSize(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
            // cannot call getSuperEnumTable directly because of static context
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
            MediaSizeName[] enumMedia = winMedia.getSuperEnumTable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
            if (enumMedia != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
                Win32PrintService.predefMedia = new MediaSize[enumMedia.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
                for (int i=0; i<enumMedia.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
                    Win32PrintService.predefMedia[i] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
                        MediaSize.getMediaSizeForName(enumMedia[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
    int getDMPaper() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
        return dmPaperID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
    protected String[] getStringTable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
      String[] nameTable = new String[winStringTable.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
      return (String[])winStringTable.toArray(nameTable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
    protected EnumSyntax[] getEnumValueTable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
      MediaSizeName[] enumTable = new MediaSizeName[winEnumTable.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
      return (MediaSizeName[])winEnumTable.toArray(enumTable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
}