jdk/src/windows/classes/sun/awt/windows/WPrinterJob.java
author ohair
Wed, 06 Apr 2011 22:06:11 -0700
changeset 9035 1255eb81cc2f
parent 8352 956b231fed62
child 18116 f26d5963f5cb
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: 8352
diff changeset
     2
 * Copyright (c) 1997, 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: 3928
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: 3928
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: 3928
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3928
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3928
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.awt.windows;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.Color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.Font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.Graphics2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.GraphicsEnvironment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.HeadlessException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.KeyboardFocusManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.Toolkit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.BasicStroke;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.awt.Button;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.awt.Component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.awt.Dimension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.awt.Event;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.awt.event.ActionEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.awt.event.ActionListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.awt.FileDialog;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.awt.Dialog;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.awt.Label;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.awt.Panel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.awt.Rectangle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.awt.Window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import java.awt.image.BufferedImage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import java.awt.image.IndexColorModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import java.awt.print.Pageable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import java.awt.print.PageFormat;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import java.awt.print.Paper;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
import java.awt.print.Printable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
import java.awt.print.PrinterJob;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
import java.awt.print.PrinterException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
import javax.print.PrintService;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
import java.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
import java.util.Hashtable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
import java.util.Properties;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
import java.util.MissingResourceException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
import java.util.ResourceBundle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
import sun.awt.Win32GraphicsEnvironment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
import sun.print.PeekGraphics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
import sun.print.PeekMetrics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
import java.net.URL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
import java.net.URI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
import java.net.URISyntaxException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
import javax.print.PrintServiceLookup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
import javax.print.attribute.PrintRequestAttributeSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
import javax.print.attribute.HashPrintServiceAttributeSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
import javax.print.attribute.HashPrintRequestAttributeSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
import javax.print.attribute.Attribute;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
import javax.print.attribute.standard.Sides;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
import javax.print.attribute.standard.Chromaticity;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
import javax.print.attribute.standard.PrintQuality;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
import javax.print.attribute.standard.PrinterResolution;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
import javax.print.attribute.standard.SheetCollate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
import javax.print.attribute.IntegerSyntax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
import javax.print.attribute.standard.Copies;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
import javax.print.attribute.standard.Destination;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
import javax.print.attribute.standard.OrientationRequested;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
import javax.print.attribute.standard.Media;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
import javax.print.attribute.standard.MediaSizeName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
import javax.print.attribute.standard.MediaSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
import javax.print.attribute.standard.MediaTray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
import javax.print.attribute.standard.PrinterName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
import javax.print.attribute.standard.JobMediaSheetsSupported;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
import javax.print.attribute.standard.PageRanges;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
import javax.print.attribute.Size2DSyntax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
import javax.print.StreamPrintService;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   101
import sun.awt.Win32FontManager;
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   102
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
import sun.print.RasterPrinterJob;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
import sun.print.SunAlternateMedia;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
import sun.print.SunPageSelection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
import sun.print.SunMinMaxPage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
import sun.print.Win32MediaTray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
import sun.print.Win32PrintService;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
import sun.print.Win32PrintServiceLookup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
import sun.print.ServiceDialog;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
import sun.print.DialogOwner;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
import java.awt.Frame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
import java.io.FilePermission;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
import sun.java2d.Disposer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
import sun.java2d.DisposerRecord;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
import sun.java2d.DisposerTarget;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 * A class which initiates and executes a Win32 printer job.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 * @author Richard Blanchard
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
public class WPrinterJob extends RasterPrinterJob implements DisposerTarget {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 /* Class Constants */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
/* Instance Variables */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * These are Windows' ExtCreatePen End Cap Styles
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * and must match the values in <WINGDI.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    protected static final long PS_ENDCAP_ROUND  = 0x00000000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    protected static final long PS_ENDCAP_SQUARE   = 0x00000100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    protected static final long PS_ENDCAP_FLAT   =   0x00000200;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * These are Windows' ExtCreatePen Line Join Styles
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * and must match the values in <WINGDI.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    protected static final long PS_JOIN_ROUND   =    0x00000000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    protected static final long PS_JOIN_BEVEL   =    0x00001000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    protected static final long PS_JOIN_MITER   =    0x00002000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * This is the Window's Polygon fill rule which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * Selects alternate mode (fills the area between odd-numbered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * and even-numbered polygon sides on each scan line).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * It must match the value in <WINGDI.h> It can be passed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * to setPolyFillMode().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    protected static final int POLYFILL_ALTERNATE = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * This is the Window's Polygon fill rule which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * Selects winding mode which fills any region
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * with a nonzero winding value). It must match
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * the value in <WINGDI.h> It can be passed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * to setPolyFillMode().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    protected static final int POLYFILL_WINDING = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * The maximum value for a Window's color component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * as passed to selectSolidBrush.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    private static final int MAX_WCOLOR = 255;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * Flags for setting values from devmode in native code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * Values must match those defined in awt_PrintControl.cpp
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    private static final int SET_DUP_VERTICAL = 0x00000010;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    private static final int SET_DUP_HORIZONTAL = 0x00000020;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    private static final int SET_RES_HIGH = 0x00000040;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    private static final int SET_RES_LOW = 0x00000080;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    private static final int SET_COLOR = 0x00000200;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    private static final int SET_ORIENTATION = 0x00004000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * Values must match those defined in wingdi.h & commdlg.h
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    private static final int PD_ALLPAGES = 0x00000000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    private static final int PD_SELECTION = 0x00000001;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    private static final int PD_PAGENUMS = 0x00000002;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    private static final int PD_NOSELECTION = 0x00000004;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    private static final int PD_COLLATE = 0x00000010;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    private static final int PD_PRINTTOFILE = 0x00000020;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    private static final int DM_ORIENTATION = 0x00000001;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    private static final int DM_PRINTQUALITY = 0x00000400;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    private static final int DM_COLOR = 0x00000800;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    private static final int DM_DUPLEX = 0x00001000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * Pageable MAX pages
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    private static final int MAX_UNKNOWN_PAGES = 9999;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    /* Collation and copy flags.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * The Windows PRINTDLG struct has a nCopies field which on return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * indicates how many copies of a print job an application must render.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * There is also a PD_COLLATE member of the flags field which if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * set on return indicates the application generated copies should be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * collated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * Windows printer drivers typically - but not always - support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * generating multiple copies themselves, but uncollated is more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * universal than collated copies.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * When they do, they read the initial values from the PRINTDLG structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * and set them into the driver's DEVMODE structure and intialise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * the printer DC based on that, so that when printed those settings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * will be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * For drivers supporting both these capabilities via DEVMODE, then on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * return from the Print Dialog, nCopies is set to 1 and the PD_COLLATE is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * cleared, so that the application will only render 1 copy and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * driver takes care of the rest.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * Applications which want to know what's going on have to be DEVMODE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * savvy and peek at that.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * DM_COPIES flag indicates support for multiple driver copies
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * and dmCopies is the number of copies the driver will print
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * DM_COLLATE flag indicates support for collated driver copies and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * dmCollate == DMCOLLATE_TRUE indicates the option is in effect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * Multiple copies from Java applications:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * We provide API to get & set the number of copies as well as allowing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * user to choose it, so we need to be savvy about DEVMODE, so that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * we can accurately report back the number of copies selected by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * the user, as well as make use of the driver to render multiple copies.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * Collation and Java applications:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * We presently provide no API for specifying collation, but its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * present on the Windows Print Dialog, and when a user checks it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * they expect it to be obeyed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * The best thing to do is to detect exactly the cases where the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * driver doesn't support this and render multiple copies ourselves.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * To support all this we need several flags which signal the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * printer's capabilities and the user's requests.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * Its questionable if we (yet) need to make a distinction between
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * the user requesting collation and the driver supporting it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * Since for now we only need to know whether we need to render the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * copies. However it allows the logic to be clearer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * These fields are changed by native code which detects the driver's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * capabilities and the user's choices.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    //initialize to false because the Flags that we initialized in PRINTDLG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    // tells GDI that we can handle our own collation and multiple copies
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     private boolean driverDoesMultipleCopies = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     private boolean driverDoesCollation = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     private boolean userRequestedCollation = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     private boolean noDefaultPrinter = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    /* The HandleRecord holds the native resources that need to be freed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * when this WPrinterJob is GC'd.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    static class HandleRecord implements DisposerRecord {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
         * The Windows device context we will print into.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
         * This variable is set after the Print dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
         * is okayed by the user. If the user cancels
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
         * the print dialog, then this variable is 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
         * Much of the configuration information for a printer is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
         * obtained through printer device specific handles.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
         * We need to associate these with, and free with, the mPrintDC.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        private long mPrintDC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        private long mPrintHDevMode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        private long mPrintHDevNames;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        public void dispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            WPrinterJob.deleteDC(mPrintDC, mPrintHDevMode, mPrintHDevNames);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    private HandleRecord handleRecord = new HandleRecord();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    private int mPrintPaperSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    /* These fields are directly set in upcalls from the values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * obtained from calling DeviceCapabilities()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    private int mPrintXRes;   // pixels per inch in x direction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    private int mPrintYRes;   // pixels per inch in y direction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    private int mPrintPhysX;  // x offset in pixels of printable area
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    private int mPrintPhysY;  // y offset in pixels of printable area
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    private int mPrintWidth;  // width in pixels of printable area
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    private int mPrintHeight; // height in pixels of printable area
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    private int mPageWidth;   // width in pixels of entire page
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    private int mPageHeight;  // height in pixels of entire page
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    /* The values of the following variables are pulled directly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * into native code (even bypassing getter methods) when starting a doc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * So these need to be synced up from any resulting native changes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * by a user dialog.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * But the native changes call up to into the attributeset, and that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * should be sufficient, since before heading down to native either
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * to (re-)display a dialog, or to print the doc, these are all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * re-populated from the AttributeSet,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * Nonetheless having them in sync with the attributeset and native
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * state is probably safer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * Also whereas the startDoc native code pulls the variables directly,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * the dialog code does use getter to pull some of these values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * That's an inconsistency we should fix if it causes problems.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    private int mAttSides;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    private int mAttChromaticity;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    private int mAttXRes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    private int mAttYRes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    private int mAttQuality;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    private int mAttCollate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    private int mAttCopies;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    private int mAttMediaSizeName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    private int mAttMediaTray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    private String mDestination = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * The last color set into the print device context or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * <code>null</code> if no color has been set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    private Color mLastColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * The last text color set into the print device context or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * <code>null</code> if no color has been set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    private Color mLastTextColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * Define the most recent java font set as a GDI font in the printer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * device context. mLastFontFamily will be NULL if no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * GDI font has been set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    private String mLastFontFamily;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    private float mLastFontSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    private int mLastFontStyle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    private int mLastRotation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    private float mLastAwScale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    // for AwtPrintControl::InitPrintDialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    private PrinterJob pjob;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    private java.awt.peer.ComponentPeer dialogOwnerPeer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
 /* Static Initializations */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        // AWT has to be initialized for the native code to function correctly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        Toolkit.getDefaultToolkit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   364
        Win32FontManager.registerJREFontsForPrinting();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    /* Constructors */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    public WPrinterJob()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        Disposer.addRecord(disposerReferent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                           handleRecord = new HandleRecord());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        initAttributeMembers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    /* Implement DisposerTarget. Weak references to an Object can delay
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * its storage reclaimation marginally.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * It won't make the native resources be release any more quickly, but
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * by pointing the reference held by Disposer at an object which becomes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * no longer strongly reachable when this WPrinterJob is no longer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * strongly reachable, we allow the WPrinterJob to be freed more promptly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * than if it were the referenced object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    private Object disposerReferent = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    public Object getDisposerReferent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        return disposerReferent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
/* Instance Methods */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * Display a dialog to the user allowing the modification of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * PageFormat instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * The <code>page</code> argument is used to initialize controls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * in the page setup dialog.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * If the user cancels the dialog, then the method returns the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * original <code>page</code> object unmodified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * If the user okays the dialog then the method returns a new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * PageFormat object with the indicated changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * In either case the original <code>page</code> object will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * not be modified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * @param     page    the default PageFormat presented to the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     *                    for modification
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * @return    the original <code>page</code> object if the dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     *            is cancelled, or a new PageFormat object containing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     *            the format indicated by the user if the dialog is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     *            acknowledged
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * @exception HeadlessException if GraphicsEnvironment.isHeadless()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * returns true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * @since     JDK1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    public PageFormat pageDialog(PageFormat page) throws HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        if (GraphicsEnvironment.isHeadless()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            throw new HeadlessException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        if (getPrintService() instanceof StreamPrintService) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
            return super.pageDialog(page);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        PageFormat pageClone = (PageFormat) page.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        boolean result = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
         * Fix for 4507585: show the native modal dialog the same way printDialog() does so
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
         * that it won't block event dispatching when called on EventDispatchThread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        WPageDialog dialog = new WPageDialog((Frame)null, this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                                     pageClone, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        dialog.setRetVal(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        dialog.setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        result = dialog.getRetVal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        dialog.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        // myService => current PrintService
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        if (result && (myService != null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            // It's possible that current printer is changed through
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            // the "Printer..." button so we query again from native.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            String printerName = getNativePrintService();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            if (!myService.getName().equals(printerName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                // native printer is different !
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                // we update the current PrintService
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                    setPrintService(Win32PrintServiceLookup.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                                    getWin32PrintLUS().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                                    getPrintServiceByName(printerName));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                } catch (PrinterException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            // Update attributes, this will preserve the page settings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            //  - same code as in RasterPrinterJob.java
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            updatePageAttributes(myService, pageClone);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
            return pageClone;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
            return page;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    private boolean displayNativeDialog() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        // "attributes" is required for getting the updated attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        if (attributes == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        DialogOwner dlgOwner = (DialogOwner)attributes.get(DialogOwner.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        Frame ownerFrame = (dlgOwner != null) ? dlgOwner.getOwner() : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        WPrintDialog dialog = new WPrintDialog(ownerFrame, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        dialog.setRetVal(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        dialog.setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        boolean prv = dialog.getRetVal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        dialog.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        Destination dest =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                (Destination)attributes.get(Destination.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        if ((dest == null) || !prv){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                return prv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
            String title = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            String strBundle = "sun.print.resources.serviceui";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
            ResourceBundle rb = ResourceBundle.getBundle(strBundle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                title = rb.getString("dialog.printtofile");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            } catch (MissingResourceException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            FileDialog fileDialog = new FileDialog(ownerFrame, title,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                                                   FileDialog.SAVE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            URI destURI = dest.getURI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            // Old code destURI.getPath() would return null for "file:out.prn"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            // so we use getSchemeSpecificPart instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
            String pathName = (destURI != null) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                destURI.getSchemeSpecificPart() : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
            if (pathName != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
               File file = new File(pathName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
               fileDialog.setFile(file.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
               File parent = file.getParentFile();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
               if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
                   fileDialog.setDirectory(parent.getPath());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                fileDialog.setFile("out.prn");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
            fileDialog.setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
            String fileName = fileDialog.getFile();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
            if (fileName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                fileDialog.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
            String fullName = fileDialog.getDirectory() + fileName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
            File f = new File(fullName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            File pFile = f.getParentFile();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            while ((f.exists() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
                      (!f.isFile() || !f.canWrite())) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                   ((pFile != null) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                      (!pFile.exists() || (pFile.exists() && !pFile.canWrite())))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                (new PrintToFileErrorDialog(ownerFrame,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                                ServiceDialog.getMsg("dialog.owtitle"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                                ServiceDialog.getMsg("dialog.writeerror")+" "+fullName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                                ServiceDialog.getMsg("button.ok"))).setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                fileDialog.setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                fileName = fileDialog.getFile();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                if (fileName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                    fileDialog.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                fullName = fileDialog.getDirectory() + fileName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                f = new File(fullName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                pFile = f.getParentFile();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
            fileDialog.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
            attributes.add(new Destination(f.toURI()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     * Presents the user a dialog for changing properties of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     * print job interactively.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     * @returns false if the user cancels the dialog and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     *          true otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     * @exception HeadlessException if GraphicsEnvironment.isHeadless()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     * returns true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
    public boolean printDialog() throws HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        if (GraphicsEnvironment.isHeadless()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
            throw new HeadlessException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        // current request attribute set should be reflected to the print dialog.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        // If null, create new instance of HashPrintRequestAttributeSet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        if (attributes == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
            attributes = new HashPrintRequestAttributeSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        if (getPrintService() instanceof StreamPrintService) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
            return super.printDialog(attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        if (noDefaultPrinter == true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
            return displayNativeDialog();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     * Associate this PrinterJob with a new PrintService.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     * Throws <code>PrinterException</code> if the specified service
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     * cannot support the <code>Pageable</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     * </code>Printable</code> interfaces necessary to support 2D printing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     * @param a print service which supports 2D printing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     * @throws PrinterException if the specified service does not support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     * 2D printing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    public void setPrintService(PrintService service)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        throws PrinterException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        super.setPrintService(service);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        if (service instanceof StreamPrintService) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        driverDoesMultipleCopies = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        driverDoesCollation = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        setNativePrintService(service.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
    /* associates this job with the specified native service */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
    private native void setNativePrintService(String name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        throws PrinterException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
    public PrintService getPrintService() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        if (myService == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
            String printerName = getNativePrintService();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
            if (printerName != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                myService = Win32PrintServiceLookup.getWin32PrintLUS().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                    getPrintServiceByName(printerName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                // no need to call setNativePrintService as this name is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
                // currently set in native
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                if (myService != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                    return myService;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
            myService = PrintServiceLookup.lookupDefaultPrintService();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
            if (myService != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
                    setNativePrintService(myService.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
                } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
                    myService = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
          return myService;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
    private native String getNativePrintService();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
    private void initAttributeMembers() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
            mAttSides = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
            mAttChromaticity = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
            mAttXRes = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
            mAttYRes = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
            mAttQuality = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
            mAttCollate = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
            mAttCopies = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
            mAttMediaTray = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
            mAttMediaSizeName = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
            mDestination = null;
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
     * copy the attributes to the native print job
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     * Note that this method, and hence the re-initialisation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     * of the GDI values is done on each entry to the print dialog since
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     * an app could redisplay the print dialog for the same job and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     * 1) the application may have changed attribute settings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     * 2) the application may have changed the printer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
     * In the event that the user changes the printer using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
      dialog, then it is up to GDI to report back all changed values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
    protected void setAttributes(PrintRequestAttributeSet attributes)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        throws PrinterException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        // initialize attribute values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        initAttributeMembers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        super.setAttributes(attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        mAttCopies = getCopiesInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        mDestination = destinationAttr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        if (attributes == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
            return; // now always use attributes, so this shouldn't happen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
        Attribute[] attrs = attributes.toArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
        for (int i=0; i< attrs.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
            Attribute attr = attrs[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
                 if (attr.getCategory() == Sides.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
                    setSidesAttrib(attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
                else if (attr.getCategory() == Chromaticity.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
                    setColorAttrib(attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
                else if (attr.getCategory() == PrinterResolution.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
                    setResolutionAttrib(attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
                else if (attr.getCategory() == PrintQuality.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
                    setQualityAttrib(attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
                else if (attr.getCategory() == SheetCollate.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                    setCollateAttrib(attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                }  else if (attr.getCategory() == Media.class ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                            attr.getCategory() == SunAlternateMedia.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
                    /* SunAlternateMedia is used if its a tray, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
                     * any Media that is specified is not a tray.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
                     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
                    if (attr.getCategory() == SunAlternateMedia.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
                        Media media = (Media)attributes.get(Media.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
                        if (media == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
                            !(media instanceof MediaTray)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
                            attr = ((SunAlternateMedia)attr).getMedia();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
                    if (attr instanceof MediaSizeName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
                        setWin32MediaAttrib(attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
                    if (attr instanceof MediaTray) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
                        setMediaTrayAttrib(attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
            } catch (ClassCastException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
     * Alters the orientation and Paper to match defaults obtained
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
     * from a printer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
    private native void getDefaultPage(PageFormat page);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
     * The passed in PageFormat will be copied and altered to describe
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
     * the default page size and orientation of the PrinterJob's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
     * current printer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
     * Note: PageFormat.getPaper() returns a clone and getDefaultPage()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
     * gets that clone so it won't overwrite the original paper.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
    public PageFormat defaultPage(PageFormat page) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        PageFormat newPage = (PageFormat)page.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
        getDefaultPage(newPage);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        return newPage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
     * validate the paper size against the current printer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
    protected native void validatePaper(Paper origPaper, Paper newPaper );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
     * Examine the metrics captured by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
     * <code>PeekGraphics</code> instance and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
     * if capable of directly converting this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
     * print job to the printer's control language
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     * or the native OS's graphics primitives, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
     * return a <code>PathGraphics</code> to perform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
     * that conversion. If there is not an object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
     * capable of the conversion then return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
     * <code>null</code>. Returning <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
     * causes the print job to be rasterized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
    protected Graphics2D createPathGraphics(PeekGraphics peekGraphics,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
                                            PrinterJob printerJob,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
                                            Printable painter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
                                            PageFormat pageFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
                                            int pageIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
        WPathGraphics pathGraphics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
        PeekMetrics metrics = peekGraphics.getMetrics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
        /* If the application has drawn anything that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
         * out PathGraphics class can not handle then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
         * return a null PathGraphics. If the property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
         * to force the raster pipeline has been set then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
         * we also want to avoid the path (pdl) pipeline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
         * and return null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
       if (forcePDL == false && (forceRaster == true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
                                  || metrics.hasNonSolidColors()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
                                  || metrics.hasCompositing()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
                                  )) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
            pathGraphics = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
            BufferedImage bufferedImage = new BufferedImage(8, 8,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
                                            BufferedImage.TYPE_INT_RGB);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
            Graphics2D bufferedGraphics = bufferedImage.createGraphics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
            boolean canRedraw = peekGraphics.getAWTDrawingOnly() == false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
            pathGraphics =  new WPathGraphics(bufferedGraphics, printerJob,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
                                              painter, pageFormat, pageIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
                                              canRedraw);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
        return pathGraphics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
    protected double getXRes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        if (mAttXRes != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
            return mAttXRes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
            return mPrintXRes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
    protected double getYRes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
        if (mAttYRes != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
            return mAttYRes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
            return mPrintYRes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
    protected double getPhysicalPrintableX(Paper p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
        return mPrintPhysX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
    protected double getPhysicalPrintableY(Paper p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        return mPrintPhysY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
    protected double getPhysicalPrintableWidth(Paper p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
        return mPrintWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
    protected double getPhysicalPrintableHeight(Paper p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
        return mPrintHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
    protected double getPhysicalPageWidth(Paper p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
        return mPageWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
    protected double getPhysicalPageHeight(Paper p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
        return mPageHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
     * We don't (yet) provide API to support collation, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
     * when we do the logic here will require adjustment, but
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
     * this method is currently necessary to honour user-originated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
     * collation requests - which can only originate from the print dialog.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
     * REMIND: check if this can be deleted already.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
    protected boolean isCollated() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
        return userRequestedCollation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
     * Returns how many times the entire book should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
     * be printed by the PrintJob. If the printer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
     * itself supports collation then this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
     * should return 1 indicating that the entire
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
     * book need only be printed once and the copies
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
     * will be collated and made in the printer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
    protected int getCollatedCopies() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
        debug_println("driverDoesMultipleCopies="+driverDoesMultipleCopies
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
                      +" driverDoesCollation="+driverDoesCollation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
        if  (super.isCollated() && !driverDoesCollation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
            // we will do our own collation so we need to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
            // tell the printer to not collate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
            mAttCollate = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
            mAttCopies = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
            return getCopies();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
        return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
     * Returns how many times each page in the book
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
     * should be consecutively printed by PrinterJob.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
     * If the underlying Window's driver will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
     * generate the copies, rather than having RasterPrinterJob
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
     * iterate over the number of copies, this method always returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
     * 1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
    protected int getNoncollatedCopies() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
        if (driverDoesMultipleCopies || super.isCollated()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
            return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
            return getCopies();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
    /* These getter/setters are called from native code */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
     * Return the Window's device context that we are printing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
     * into.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
    private long getPrintDC() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
        return handleRecord.mPrintDC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
    private void setPrintDC(long mPrintDC) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
        handleRecord.mPrintDC = mPrintDC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
    private long getDevMode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
        return handleRecord.mPrintHDevMode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
    private void setDevMode(long mPrintHDevMode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
        handleRecord.mPrintHDevMode = mPrintHDevMode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
    private long getDevNames() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
        return handleRecord.mPrintHDevNames;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
    private void setDevNames(long mPrintHDevNames) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
        handleRecord.mPrintHDevNames = mPrintHDevNames;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
    protected void beginPath() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
        beginPath(getPrintDC());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
    protected void endPath() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
        endPath(getPrintDC());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
    protected void closeFigure() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
        closeFigure(getPrintDC());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
    protected void fillPath() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
        fillPath(getPrintDC());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
    protected void moveTo(float x, float y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
        moveTo(getPrintDC(), x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
    protected void lineTo(float x, float y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
        lineTo(getPrintDC(), x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
    protected void polyBezierTo(float control1x, float control1y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
                                float control2x, float control2y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
                                float endX, float endY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
        polyBezierTo(getPrintDC(), control1x, control1y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
                               control2x, control2y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
                               endX, endY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
     * Set the current polgon fill rule into the printer device context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
     * The <code>fillRule</code> should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
     * be one of the following Windows constants:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
     * <code>ALTERNATE</code> or <code>WINDING</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
    protected void setPolyFillMode(int fillRule) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
        setPolyFillMode(getPrintDC(), fillRule);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
     * Create a Window's solid brush for the color specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
     * by <code>(red, green, blue)</code>. Once the brush
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
     * is created, select it in the current printing device
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
     * context and free the old brush.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
    protected void selectSolidBrush(Color color) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
        /* We only need to select a brush if the color has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
        if (color.equals(mLastColor) == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
            mLastColor = color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
            float[] rgb = color.getRGBColorComponents(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
            selectSolidBrush(getPrintDC(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
                             (int) (rgb[0] * MAX_WCOLOR),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
                             (int) (rgb[1] * MAX_WCOLOR),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
                             (int) (rgb[2] * MAX_WCOLOR));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
     * Return the x coordinate of the current pen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
     * position in the print device context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
    protected int getPenX() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
        return getPenX(getPrintDC());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
     * Return the y coordinate of the current pen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
     * position in the print device context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
    protected int getPenY() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
        return getPenY(getPrintDC());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
     * Set the current path in the printer device's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
     * context to be clipping path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
    protected void selectClipPath() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
        selectClipPath(getPrintDC());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
    protected void frameRect(float x, float y, float width, float height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
        frameRect(getPrintDC(), x, y, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
    protected void fillRect(float x, float y, float width, float height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
                            Color color) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
        float[] rgb = color.getRGBColorComponents(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
        fillRect(getPrintDC(), x, y, width, height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
                 (int) (rgb[0] * MAX_WCOLOR),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
                 (int) (rgb[1] * MAX_WCOLOR),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
                 (int) (rgb[2] * MAX_WCOLOR));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
    protected void selectPen(float width, Color color) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
        float[] rgb = color.getRGBColorComponents(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
        selectPen(getPrintDC(), width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
                  (int) (rgb[0] * MAX_WCOLOR),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
                  (int) (rgb[1] * MAX_WCOLOR),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
                  (int) (rgb[2] * MAX_WCOLOR));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
    protected boolean selectStylePen(int cap, int join, float width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
                                     Color color) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
        long endCap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
        long lineJoin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
        float[] rgb = color.getRGBColorComponents(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
        switch(cap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
        case BasicStroke.CAP_BUTT: endCap = PS_ENDCAP_FLAT; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
        case BasicStroke.CAP_ROUND: endCap = PS_ENDCAP_ROUND; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
        case BasicStroke.CAP_SQUARE: endCap = PS_ENDCAP_SQUARE; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
        switch(join) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
        case BasicStroke.JOIN_BEVEL:lineJoin = PS_JOIN_BEVEL; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
        case BasicStroke.JOIN_MITER:lineJoin = PS_JOIN_MITER; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
        case BasicStroke.JOIN_ROUND:lineJoin = PS_JOIN_ROUND; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
        return (selectStylePen(getPrintDC(), endCap, lineJoin, width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
                               (int) (rgb[0] * MAX_WCOLOR),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
                               (int) (rgb[1] * MAX_WCOLOR),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
                               (int) (rgb[2] * MAX_WCOLOR)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
     * Set a GDI font capable of drawing the java Font
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
     * passed in.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
    protected boolean setFont(String family, float size, int style,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
                              int rotation, float awScale) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
        boolean didSetFont = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
        if (!family.equals(mLastFontFamily) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
            size     != mLastFontSize       ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
            style    != mLastFontStyle      ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
            rotation != mLastRotation       ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
            awScale  != mLastAwScale) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
            didSetFont = setFont(getPrintDC(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
                                 family,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
                                 size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
                                 (style & Font.BOLD) != 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
                                 (style & Font.ITALIC) != 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
                                 rotation, awScale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
            if (didSetFont) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
                mLastFontFamily   = family;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
                mLastFontSize     = size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
                mLastFontStyle    = style;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
                mLastRotation     = rotation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
                mLastAwScale      = awScale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
        return didSetFont;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
     * Set the GDI color for text drawing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
    protected void setTextColor(Color color) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
        /* We only need to select a brush if the color has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
        if (color.equals(mLastTextColor) == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
            mLastTextColor = color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
            float[] rgb = color.getRGBColorComponents(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
            setTextColor(getPrintDC(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
                         (int) (rgb[0] * MAX_WCOLOR),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
                         (int) (rgb[1] * MAX_WCOLOR),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
                         (int) (rgb[2] * MAX_WCOLOR));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
     * Remove control characters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
    protected String removeControlChars(String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
        return super.removeControlChars(str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
     * Draw the string <code>text</code> to the printer's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
     * device context at the specified position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
    protected void textOut(String str, float x, float y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
                           float[] positions) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
        /* Don't leave handling of control chars to GDI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
         * If control chars are removed,  'positions' isn't valid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
         * This means the caller needs to be aware of this and remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
         * control chars up front if supplying positions. Since the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
         * caller is tightly integrated here, that's acceptable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
        String text = removeControlChars(str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
        assert (positions == null) || (text.length() == str.length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
        if (text.length() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
        textOut(getPrintDC(), text, text.length(), false, x, y, positions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
     * Draw the glyphs <code>glyphs</code> to the printer's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
     * device context at the specified position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
    protected void glyphsOut(int []glyphs, float x, float y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
                             float[] positions) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
        /* TrueType glyph codes are 16 bit values, so can be packed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
         * in a unicode string, and that's how GDI expects them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
         * A flag bit is set to indicate to GDI that these are glyphs,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
         * not characters. The positions array must always be non-null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
         * here for our purposes, although if not supplied, GDI should
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
         * just use the default advances for the glyphs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
         * Mask out upper 16 bits to remove any slot from a composite.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
        char[] glyphCharArray = new char[glyphs.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
        for (int i=0;i<glyphs.length;i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
            glyphCharArray[i] = (char)(glyphs[i] & 0xffff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
        String glyphStr = new String(glyphCharArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
        textOut(getPrintDC(), glyphStr, glyphs.length, true, x, y, positions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
     * Get the advance of this text that GDI returns for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
     * font currently selected into the GDI device context for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
     * this job. Note that the removed control characters are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
     * interpreted as zero-width by JDK and we remove them for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
     * rendering so also remove them for measurement so that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
     * this measurement can be properly compared with JDK measurement.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
    protected int getGDIAdvance(String text) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
        /* Don't leave handling of control chars to GDI. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
        text = removeControlChars(text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
        if (text.length() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
        return getGDIAdvance(getPrintDC(), text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
     * Draw the 24 bit BGR image buffer represented by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
     * <code>image</code> to the GDI device context
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
     * <code>printDC</code>. The image is drawn at
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
     * <code>(destX, destY)</code> in device coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
     * The image is scaled into a square of size
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
     * specified by <code>destWidth</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
     * <code>destHeight</code>. The portion of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
     * source image copied into that square is specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
     * by <code>srcX</code>, <code>srcY</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
     * <code>srcWidth</code>, and srcHeight.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
    protected void drawImage3ByteBGR(byte[] image,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
                                     float destX, float destY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
                                     float destWidth, float destHeight,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
                                     float srcX, float srcY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
                                     float srcWidth, float srcHeight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
        drawDIBImage(getPrintDC(), image,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
                     destX, destY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
                     destWidth, destHeight,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
                     srcX, srcY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
                     srcWidth, srcHeight,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
                     24, null);
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
    /* If 'icm' is null we expect its 24 bit (ie 3BYTE_BGR).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
     * If 'icm' is non-null we expect its no more than 8 bpp and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
     * specifically must be a valid DIB sizes : 1, 4 or 8 bpp.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
     * Then we need to extract the colours into a byte array of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
     * format required by GDI which is an array of 'RGBQUAD'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
     * RGBQUAD looks like :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
     * typedef struct tagRGBQUAD {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
     *    BYTE    rgbBlue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
     *    BYTE    rgbGreen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
     *    BYTE    rgbRed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
     *    BYTE    rgbReserved; // must be zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
     * } RGBQUAD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
     * There's no alignment problem as GDI expects this to be packed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
     * and each struct will start on a 4 byte boundary anyway.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
    protected void drawDIBImage(byte[] image,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
                                float destX, float destY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
                                float destWidth, float destHeight,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
                                float srcX, float srcY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
                                float srcWidth, float srcHeight,
8352
956b231fed62 7006865: Regression: Corrupted output when printing images with bit depth of 4
prr
parents: 5506
diff changeset
  1215
                                int sampleBitsPerPixel,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
                                IndexColorModel icm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
        int bitCount = 24;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
        byte[] bmiColors = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
        if (icm != null) {
8352
956b231fed62 7006865: Regression: Corrupted output when printing images with bit depth of 4
prr
parents: 5506
diff changeset
  1221
            bitCount = sampleBitsPerPixel;
956b231fed62 7006865: Regression: Corrupted output when printing images with bit depth of 4
prr
parents: 5506
diff changeset
  1222
            bmiColors = new byte[(1<<icm.getPixelSize())*4];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
            for (int i=0;i<icm.getMapSize(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
                bmiColors[i*4+0]=(byte)(icm.getBlue(i)&0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
                bmiColors[i*4+1]=(byte)(icm.getGreen(i)&0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
                bmiColors[i*4+2]=(byte)(icm.getRed(i)&0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
        drawDIBImage(getPrintDC(), image,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
                     destX, destY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
                     destWidth, destHeight,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
                     srcX, srcY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
                     srcWidth, srcHeight,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
                     bitCount, bmiColors);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
     * Begin a new page.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
    protected void startPage(PageFormat format, Printable painter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
                             int index, boolean paperChanged) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
        /* Invalidate any device state caches we are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
         * maintaining. Win95/98 resets the device
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
         * context attributes to default values at
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
         * the start of each page.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
        invalidateCachedState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
        deviceStartPage(format, painter, index, paperChanged);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
     * End a page.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
    protected void endPage(PageFormat format, Printable painter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
                           int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
        deviceEndPage(format, painter, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
     * Forget any device state we may have cached.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
    private void invalidateCachedState() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
        mLastColor = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
        mLastTextColor = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
        mLastFontFamily = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
     * Set the number of copies to be printed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
    public void setCopies(int copies) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
        super.setCopies(copies);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
        mAttCopies = copies;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
        setNativeCopies(copies);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
 /* Native Methods */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
     * Set copies in device.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
    public native void setNativeCopies(int copies);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
     * Displays the print dialog and records the user's settings
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
     * into this object. Return false if the user cancels the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
     * dialog.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
     * If the dialog is to use a set of attributes, useAttributes is true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
    private native boolean jobSetup(Pageable doc, boolean allowPrintToFile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
    /* Make sure printer DC is intialised and that info about the printer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
     * is reflected back up to Java code
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
    protected native void initPrinter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
     * Call Window's StartDoc routine to begin a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
     * print job. The DC from the print dialog is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
     * used. If the print dialog was not displayed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
     * then a DC for the default printer is created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
     * The native StartDoc returns false if the end-user cancelled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
     * printing. This is possible if the printer is connected to FILE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
     * in which case windows queries the user for a destination and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
     * user may cancel out of it. Note that the implementation of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
     * cancel() throws PrinterAbortException to indicate the user cancelled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
    private native boolean _startDoc(String dest, String jobName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
                                     throws PrinterException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
    protected void startDoc() throws PrinterException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
        if (!_startDoc(mDestination, getJobName())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
            cancel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
     * Call Window's EndDoc routine to end a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
     * print job.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
    protected native void endDoc();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
     * Call Window's AbortDoc routine to abort a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
     * print job.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
    protected native void abortDoc();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
     * Call Windows native resource freeing APIs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
    private static native void deleteDC(long dc, long devmode, long devnames);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
     * Begin a new page. This call's Window's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
     * StartPage routine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
    protected native void deviceStartPage(PageFormat format, Printable painter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
                                          int index, boolean paperChanged);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
     * End a page. This call's Window's EndPage
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
     * routine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
    protected native void deviceEndPage(PageFormat format, Printable painter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
                                        int index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
     * Prints the contents of the array of ints, 'data'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
     * to the current page. The band is placed at the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
     * location (x, y) in device coordinates on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
     * page. The width and height of the band is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
     * specified by the caller.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
    protected native void printBand(byte[] data, int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
                                    int width, int height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
     * Begin a Window's rendering path in the device
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
     * context <code>printDC</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
    protected native void beginPath(long printDC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
     * End a Window's rendering path in the device
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
     * context <code>printDC</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
    protected native void endPath(long printDC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
     * Close a subpath in a Window's rendering path in the device
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
     * context <code>printDC</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
    protected native void closeFigure(long printDC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
     * Fill a defined Window's rendering path in the device
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
     * context <code>printDC</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
    protected native void fillPath(long printDC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
     * Move the Window's pen position to <code>(x,y)</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
     * in the device context <code>printDC</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
    protected native void moveTo(long printDC, float x, float y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
     * Draw a line from the current pen position to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
     * <code>(x,y)</code> in the device context <code>printDC</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
    protected native void lineTo(long printDC, float x, float y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
    protected native void polyBezierTo(long printDC,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
                                       float control1x, float control1y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
                                       float control2x, float control2y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
                                       float endX, float endY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
     * Set the current polgon fill rule into the device context
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
     * <code>printDC</code>. The <code>fillRule</code> should
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
     * be one of the following Windows constants:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
     * <code>ALTERNATE</code> or <code>WINDING</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
    protected native void setPolyFillMode(long printDC, int fillRule);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
     * Create a Window's solid brush for the color specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
     * by <code>(red, green, blue)</code>. Once the brush
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
     * is created, select it in the device
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
     * context <code>printDC</code> and free the old brush.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
    protected native void selectSolidBrush(long printDC,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
                                           int red, int green, int blue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
     * Return the x coordinate of the current pen
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
     * position in the device context
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
     * <code>printDC</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
    protected native int getPenX(long printDC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
     * Return the y coordinate of the current pen
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
     * position in the device context
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
     * <code>printDC</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
    protected native int getPenY(long printDC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
     * Select the device context's current path
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
     * to be the clipping path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
    protected native void selectClipPath(long printDC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
     * Draw a rectangle using specified brush.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
    protected native void frameRect(long printDC, float x, float y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
                                    float width, float height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
     * Fill a rectangle specified by the coordinates using
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
     * specified brush.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
    protected native void fillRect(long printDC, float x, float y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
                                   float width, float height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
                                   int red, int green, int blue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
     * Create a solid brush using the RG & B colors and width.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
     * Select this brush and delete the old one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
    protected native void selectPen(long printDC, float width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
                                    int red, int green, int blue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
     * Create a solid brush using the RG & B colors and specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
     * pen styles.  Select this created brush and delete the old one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
    protected native boolean selectStylePen(long printDC, long cap,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
                                            long join, float width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
                                            int red, int green, int blue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
     * Set a GDI font capable of drawing the java Font
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
     * passed in.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
    protected native boolean setFont(long printDC, String familyName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
                                     float fontSize,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
                                     boolean bold,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
                                     boolean italic,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
                                     int rotation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
                                     float awScale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
     * Set the GDI color for text drawing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
    protected native void setTextColor(long printDC,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
                                       int red, int green, int blue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
     * Draw the string <code>text</code> into the device
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
     * context <code>printDC</code> at the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
     * position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
    protected native void textOut(long printDC, String text,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
                                  int strlen, boolean glyphs,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
                                  float x, float y, float[] positions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
    private native int getGDIAdvance(long printDC, String text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
     * Draw the DIB compatible image buffer represented by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
     * <code>image</code> to the GDI device context
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
     * <code>printDC</code>. The image is drawn at
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
     * <code>(destX, destY)</code> in device coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
     * The image is scaled into a square of size
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
     * specified by <code>destWidth</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
     * <code>destHeight</code>. The portion of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
     * source image copied into that square is specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
     * by <code>srcX</code>, <code>srcY</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
     * <code>srcWidth</code>, and srcHeight.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
     * Note that the image isn't completely compatible with DIB format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
     * At the very least it needs to be padded so each scanline is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
     * DWORD aligned. Also we "flip" the image to make it a bottom-up DIB.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
    private native void drawDIBImage(long printDC, byte[] image,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
                                     float destX, float destY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
                                     float destWidth, float destHeight,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
                                     float srcX, float srcY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
                                     float srcWidth, float srcHeight,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
                                     int bitCount, byte[] bmiColors);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
    //** BEGIN Functions called by native code for querying/updating attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
    private final String getPrinterAttrib() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
        // getPrintService will get current print service or default if none
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
        PrintService service = this.getPrintService();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
        String name = (service != null) ? service.getName() : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
        return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
    /* SheetCollate */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
    private final boolean getCollateAttrib() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
        return (mAttCollate == 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
    private void setCollateAttrib(Attribute attr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
        if (attr == SheetCollate.COLLATED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
            mAttCollate = 1; // DMCOLLATE_TRUE
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
            mAttCollate = 0; // DMCOLLATE_FALSE
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
    private void setCollateAttrib(Attribute attr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
                                  PrintRequestAttributeSet set) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
        setCollateAttrib(attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
        set.add(attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
    /* Orientation */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
    private final int getOrientAttrib() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
        int orient = PageFormat.PORTRAIT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
        OrientationRequested orientReq = (attributes == null) ? null :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
            (OrientationRequested)attributes.get(OrientationRequested.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
        if (orientReq != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
            if (orientReq == OrientationRequested.REVERSE_LANDSCAPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
                orient = PageFormat.REVERSE_LANDSCAPE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
            } else if (orientReq == OrientationRequested.LANDSCAPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
                orient = PageFormat.LANDSCAPE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
        return orient;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
    private void setOrientAttrib(Attribute attr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
                                 PrintRequestAttributeSet set) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
        if (set != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
            set.add(attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
    /* Copies and Page Range. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
    private final int getCopiesAttrib() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
        return getCopiesInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
    private final void setRangeCopiesAttribute(int from, int to,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
                                               boolean isRangeSet,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
                                               int copies) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
        if (attributes != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
            if (isRangeSet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
                attributes.add(new PageRanges(from, to));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
                setPageRange(from, to);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
            attributes.add(new Copies(copies));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
            /* Since this is called from native to tell Java to sync
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
             * up with native, we don't call this class's own setCopies()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
             * method which is mainly to send the value down to native
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
            super.setCopies(copies);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
            mAttCopies = copies;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
    //returns 1-based index for "From" page
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
    private final int getFromPageAttrib() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
        if (attributes != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
            PageRanges pageRangesAttr =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
                (PageRanges)attributes.get(PageRanges.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
            if (pageRangesAttr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
                int[][] range = pageRangesAttr.getMembers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
                return range[0][0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
        return getMinPageAttrib();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
    //returns 1-based index for "To" page
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
    private final int getToPageAttrib() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
        if (attributes != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
            PageRanges pageRangesAttr =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
                (PageRanges)attributes.get(PageRanges.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
            if (pageRangesAttr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
                int[][] range = pageRangesAttr.getMembers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
                return range[range.length-1][1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
        return getMaxPageAttrib();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
    private final int getMinPageAttrib() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
        if (attributes != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
            SunMinMaxPage s =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
                (SunMinMaxPage)attributes.get(SunMinMaxPage.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
            if (s != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
                return s.getMin();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
        return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
    private final int getMaxPageAttrib() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
        if (attributes != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
            SunMinMaxPage s =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
                (SunMinMaxPage)attributes.get(SunMinMaxPage.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
            if (s != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
                return s.getMax();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
        Pageable pageable = getPageable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
        if (pageable != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
            int numPages = pageable.getNumberOfPages();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
            if (numPages <= Pageable.UNKNOWN_NUMBER_OF_PAGES) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
                numPages = MAX_UNKNOWN_PAGES;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
            return  ((numPages == 0) ? 1 : numPages);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
        return Integer.MAX_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
    private final boolean getDestAttrib() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
        return (mDestination != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
    /* Quality */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
    private final int getQualityAttrib() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
        return mAttQuality;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
    private void setQualityAttrib(Attribute attr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
        if (attr == PrintQuality.HIGH) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
            mAttQuality = -4; // DMRES_HIGH
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
        } else if (attr == PrintQuality.NORMAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
            mAttQuality = -3; // DMRES_MEDIUM
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
            mAttQuality = -2; // DMRES_LOW
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
    private void setQualityAttrib(Attribute attr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
                                  PrintRequestAttributeSet set) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
        setQualityAttrib(attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
        set.add(attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
    /* Color/Chromaticity */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
    private final int getColorAttrib() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
        return mAttChromaticity;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
    private void setColorAttrib(Attribute attr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
        if (attr == Chromaticity.COLOR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
            mAttChromaticity = 2; // DMCOLOR_COLOR
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
            mAttChromaticity = 1; // DMCOLOR_MONOCHROME
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
    private void setColorAttrib(Attribute attr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
                                  PrintRequestAttributeSet set) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
        setColorAttrib(attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
        set.add(attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
    /* Sides */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
    private final int getSidesAttrib() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
        return mAttSides;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
    private void setSidesAttrib(Attribute attr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
        if (attr == Sides.TWO_SIDED_LONG_EDGE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
            mAttSides = 2; // DMDUP_VERTICAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
        } else if (attr == Sides.TWO_SIDED_SHORT_EDGE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
            mAttSides = 3; // DMDUP_HORIZONTAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
        } else { // Sides.ONE_SIDED
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
            mAttSides = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
    private void setSidesAttrib(Attribute attr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
                                PrintRequestAttributeSet set) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
        setSidesAttrib(attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
        set.add(attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
    /** MediaSizeName / dmPaper */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
    private final int[] getWin32MediaAttrib() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
        int wid_ht[] = {0, 0};
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
        if (attributes != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
            Media media = (Media)attributes.get(Media.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
            if (media instanceof MediaSizeName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
                MediaSizeName msn = (MediaSizeName)media;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
                MediaSize ms = MediaSize.getMediaSizeForName(msn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
                if (ms != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
                    wid_ht[0] = (int)(ms.getX(MediaSize.INCH) * 72.0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
                    wid_ht[1] = (int)(ms.getY(MediaSize.INCH) * 72.0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
        return wid_ht;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
    private void setWin32MediaAttrib(Attribute attr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
        if (!(attr instanceof MediaSizeName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
        MediaSizeName msn = (MediaSizeName)attr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
        mAttMediaSizeName = ((Win32PrintService)myService).findPaperID(msn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
    private void setWin32MediaAttrib(int dmIndex, int width, int length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
       MediaSizeName msn =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
           ((Win32PrintService)myService).findWin32Media(dmIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
        if (msn == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
            msn = ((Win32PrintService)myService).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
                findMatchingMediaSizeNameMM((float)width, (float)length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
        if (msn != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
            if (attributes != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
                attributes.add(msn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
        mAttMediaSizeName = dmIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
    /* MediaTray / dmTray */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
    private void setMediaTrayAttrib(Attribute attr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
        if (attr == MediaTray.BOTTOM) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
            mAttMediaTray = 2;    // DMBIN_LOWER
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
        } else if (attr == MediaTray.ENVELOPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
            mAttMediaTray = 5;    // DMBIN_ENVELOPE
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
        } else if (attr == MediaTray.LARGE_CAPACITY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
            mAttMediaTray = 11;      // DMBIN_LARGECAPACITY
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
        } else if (attr == MediaTray.MAIN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
            mAttMediaTray =1;               // DMBIN_UPPER
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
        } else if (attr == MediaTray.MANUAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
            mAttMediaTray = 4;              // DMBIN_MANUAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
        } else if (attr == MediaTray.MIDDLE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
            mAttMediaTray = 3;              // DMBIN_MIDDLE
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
        } else if (attr == MediaTray.SIDE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
            // no equivalent predefined value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
            mAttMediaTray = 7;              // DMBIN_AUTO
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
        } else if (attr == MediaTray.TOP) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
            mAttMediaTray =1;               // DMBIN_UPPER
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
            if (attr instanceof Win32MediaTray) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
                mAttMediaTray = ((Win32MediaTray)attr).winID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
                mAttMediaTray = 1;  // default
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
    private void setMediaTrayAttrib(int dmBinID) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
        mAttMediaTray = dmBinID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
        MediaTray tray = ((Win32PrintService)myService).findMediaTray(dmBinID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
    private int getMediaTrayAttrib() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
        return mAttMediaTray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
    private final int getSelectAttrib() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
        if (attributes != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
            SunPageSelection pages =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
                (SunPageSelection)attributes.get(SunPageSelection.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
            if (pages == SunPageSelection.RANGE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
                return PD_PAGENUMS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
            } else if (pages == SunPageSelection.SELECTION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
                return PD_SELECTION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
            } else if (pages ==  SunPageSelection.ALL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
                return PD_ALLPAGES;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
        return PD_NOSELECTION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
    private final boolean getPrintToFileEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
        SecurityManager security = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
        if (security != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
            FilePermission printToFilePermission =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
                new FilePermission("<<ALL FILES>>", "read,write");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
                security.checkPermission(printToFilePermission);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
            } catch (SecurityException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
    private final void setNativeAttributes(int flags, int fields, int values) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
        if (attributes == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
        if ((flags & PD_PRINTTOFILE) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
            Destination destPrn = (Destination)attributes.get(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
                                                 Destination.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
            if (destPrn == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
                    attributes.add(new Destination(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
                                               new File("./out.prn").toURI()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
                } catch (SecurityException se) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
                        attributes.add(new Destination(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
                                                new URI("file:out.prn")));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
                    } catch (URISyntaxException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1846
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
            attributes.remove(Destination.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
        if ((flags & PD_COLLATE) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
            setCollateAttrib(SheetCollate.COLLATED, attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
            setCollateAttrib(SheetCollate.UNCOLLATED, attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1855
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
        if ((flags & PD_PAGENUMS) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
            attributes.add(SunPageSelection.RANGE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
        } else if ((flags & PD_SELECTION) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
            attributes.add(SunPageSelection.SELECTION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
            attributes.add(SunPageSelection.ALL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1863
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1864
        if ((fields & DM_ORIENTATION) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1865
            if ((values & SET_ORIENTATION) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1866
                setOrientAttrib(OrientationRequested.LANDSCAPE, attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1867
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
                setOrientAttrib(OrientationRequested.PORTRAIT, attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
        if ((fields & DM_COLOR) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1873
            if ((values & SET_COLOR) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
                setColorAttrib(Chromaticity.COLOR, attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
                setColorAttrib(Chromaticity.MONOCHROME, attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1879
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1880
        if ((fields & DM_PRINTQUALITY) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1881
            PrintQuality quality;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
            if ((values & SET_RES_LOW) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1883
                quality = PrintQuality.DRAFT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
            } else if ((fields & SET_RES_HIGH) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1885
                quality = PrintQuality.HIGH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1886
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
                quality = PrintQuality.NORMAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1888
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1889
            setQualityAttrib(quality, attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1891
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
        if ((fields & DM_DUPLEX) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1893
            Sides sides;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1894
            if ((values & SET_DUP_VERTICAL) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
                sides = Sides.TWO_SIDED_LONG_EDGE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
            } else if ((values & SET_DUP_HORIZONTAL) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1897
                sides = Sides.TWO_SIDED_SHORT_EDGE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1898
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1899
                sides = Sides.ONE_SIDED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1900
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1901
            setSidesAttrib(sides, attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1902
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1903
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1904
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1905
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1906
    /* Printer Resolution. See also getXRes() and getYRes() */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1907
    private final void setResolutionDPI(int xres, int yres) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1908
        if (attributes != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1909
            PrinterResolution res =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1910
                new PrinterResolution(xres, yres, PrinterResolution.DPI);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1911
            attributes.add(res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1912
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
        mAttXRes = xres;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1914
        mAttYRes = yres;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1915
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1916
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
    private void setResolutionAttrib(Attribute attr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1918
        PrinterResolution pr = (PrinterResolution)attr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1919
        mAttXRes = pr.getCrossFeedResolution(PrinterResolution.DPI);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1920
        mAttYRes = pr.getFeedResolution(PrinterResolution.DPI);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1921
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1922
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1923
    private void setPrinterNameAttrib(String printerName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1924
        PrintService service = this.getPrintService();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1925
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1926
        if (printerName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1927
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1928
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1929
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1930
        if (service != null && printerName.equals(service.getName())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1931
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1932
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1933
            PrintService []services = PrinterJob.lookupPrintServices();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1934
            for (int i=0; i<services.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1935
                if (printerName.equals(services[i].getName())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1936
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1937
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1938
                        this.setPrintService(services[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1939
                    } catch (PrinterException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1940
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1941
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1942
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1943
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1944
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1945
    //** END Functions called by native code for querying/updating attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1946
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1947
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1948
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1949
class PrintToFileErrorDialog extends Dialog implements ActionListener{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1950
    public PrintToFileErrorDialog(Frame parent, String title, String message,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1951
                           String buttonText) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1952
        super(parent, title, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1953
        init (parent, title, message, buttonText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1954
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1955
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1956
    public PrintToFileErrorDialog(Dialog parent, String title, String message,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
                           String buttonText) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1958
        super(parent, title, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1959
        init (parent, title, message, buttonText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1960
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1961
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
    private void init(Component parent, String  title, String message,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1963
                      String buttonText) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1964
        Panel p = new Panel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1965
        add("Center", new Label(message));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1966
        Button btn = new Button(buttonText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
        btn.addActionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
        p.add(btn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1969
        add("South", p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1970
        pack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1971
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1972
        Dimension dDim = getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1973
        if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
            Rectangle fRect = parent.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
            setLocation(fRect.x + ((fRect.width - dDim.width) / 2),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1976
                        fRect.y + ((fRect.height - dDim.height) / 2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1977
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1978
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1980
    public void actionPerformed(ActionEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1981
        setVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1982
        dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1983
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1984
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1985
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1986
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1987
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1988
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1989
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1990
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1991
     * Initialize JNI field and method ids
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1992
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1993
    private static native void initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1994
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1995
}