author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 38986 | jdk/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPrinterGraphicsConfig.java@5b96e2b155eb |
child 53673 | e04d39094915 |
permissions | -rw-r--r-- |
12047 | 1 |
/* |
23010
6dadb192ad81
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents:
12047
diff
changeset
|
2 |
* Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. |
12047 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
package sun.lwawt.macosx; |
|
27 |
||
28 |
import java.awt.*; |
|
29 |
import java.awt.geom.*; |
|
30 |
import java.awt.image.*; |
|
31 |
import java.awt.print.*; |
|
32 |
||
33 |
public class CPrinterGraphicsConfig extends GraphicsConfiguration { |
|
34 |
public static CPrinterGraphicsConfig getConfig(PageFormat pf) { |
|
35 |
return new CPrinterGraphicsConfig(pf); |
|
36 |
} |
|
37 |
||
38 |
GraphicsDevice gd; |
|
39 |
PageFormat pf; |
|
40 |
||
41 |
public CPrinterGraphicsConfig(PageFormat pf) { |
|
42 |
this.gd = new CPrinterDevice(this); |
|
43 |
this.pf = pf; |
|
44 |
} |
|
45 |
||
46 |
public PageFormat getPageFormat() { |
|
47 |
return pf; |
|
48 |
} |
|
49 |
||
50 |
/** |
|
51 |
* Returns the {@link GraphicsDevice} associated with this |
|
35667 | 52 |
* {@code GraphicsConfiguration}. |
53 |
* @return a {@code GraphicsDevice} object that is |
|
54 |
* associated with this {@code GraphicsConfiguration}. |
|
12047 | 55 |
*/ |
56 |
public GraphicsDevice getDevice() { |
|
57 |
return gd; |
|
58 |
} |
|
59 |
||
60 |
/** |
|
61 |
* Returns a {@link BufferedImage} with a data layout and color model |
|
35667 | 62 |
* compatible with this {@code GraphicsConfiguration}. This |
12047 | 63 |
* method has nothing to do with memory-mapping |
35667 | 64 |
* a device. The returned {@code BufferedImage} has |
12047 | 65 |
* a layout and color model that is closest to this native device |
66 |
* configuration and can therefore be optimally blitted to this |
|
67 |
* device. |
|
35667 | 68 |
* @param width the width of the returned {@code BufferedImage} |
69 |
* @param height the height of the returned {@code BufferedImage} |
|
70 |
* @return a {@code BufferedImage} whose data layout and color |
|
71 |
* model is compatible with this {@code GraphicsConfiguration}. |
|
12047 | 72 |
*/ |
73 |
public BufferedImage createCompatibleImage(int width, int height) { |
|
74 |
return createCompatibleImage(width, height, Transparency.OPAQUE); |
|
75 |
} |
|
76 |
||
77 |
/** |
|
78 |
* Returns a {@link VolatileImage} with a data layout and color model |
|
35667 | 79 |
* compatible with this {@code GraphicsConfiguration}. |
80 |
* The returned {@code VolatileImage} |
|
12047 | 81 |
* may have data that is stored optimally for the underlying graphics |
82 |
* device and may therefore benefit from platform-specific rendering |
|
83 |
* acceleration. |
|
35667 | 84 |
* @param width the width of the returned {@code VolatileImage} |
85 |
* @param height the height of the returned {@code VolatileImage} |
|
86 |
* @return a {@code VolatileImage} whose data layout and color |
|
87 |
* model is compatible with this {@code GraphicsConfiguration}. |
|
12047 | 88 |
* @see Component#createVolatileImage(int, int) |
89 |
*/ |
|
90 |
public VolatileImage createCompatibleVolatileImage(int width, int height) { |
|
91 |
return createCompatibleVolatileImage(width, height, Transparency.OPAQUE); |
|
92 |
} |
|
93 |
||
94 |
// empty implementation (this should not be called) |
|
95 |
public VolatileImage createCompatibleVolatileImage(int width, int height, int transparency) { |
|
96 |
return null; |
|
97 |
} |
|
98 |
||
99 |
/** |
|
35667 | 100 |
* Returns a {@code BufferedImage} that supports the specified |
12047 | 101 |
* transparency and has a data layout and color model |
35667 | 102 |
* compatible with this {@code GraphicsConfiguration}. This |
12047 | 103 |
* method has nothing to do with memory-mapping |
35667 | 104 |
* a device. The returned {@code BufferedImage} has a layout and |
12047 | 105 |
* color model that can be optimally blitted to a device |
35667 | 106 |
* with this {@code GraphicsConfiguration}. |
107 |
* @param width the width of the returned {@code BufferedImage} |
|
108 |
* @param height the height of the returned {@code BufferedImage} |
|
12047 | 109 |
* @param transparency the specified transparency mode |
35667 | 110 |
* @return a {@code BufferedImage} whose data layout and color |
111 |
* model is compatible with this {@code GraphicsConfiguration} |
|
12047 | 112 |
* and also supports the specified transparency. |
113 |
* @see Transparency#OPAQUE |
|
114 |
* @see Transparency#BITMASK |
|
115 |
* @see Transparency#TRANSLUCENT |
|
116 |
*/ |
|
117 |
public BufferedImage createCompatibleImage(int width, int height, int transparency) { |
|
118 |
//+++gdb what to do? |
|
119 |
return null; |
|
120 |
} |
|
121 |
||
122 |
/** |
|
123 |
* Returns the {@link ColorModel} associated with this |
|
35667 | 124 |
* {@code GraphicsConfiguration}. |
125 |
* @return a {@code ColorModel} object that is associated with |
|
126 |
* this {@code GraphicsConfiguration}. |
|
12047 | 127 |
*/ |
128 |
public ColorModel getColorModel() { |
|
129 |
return getColorModel(Transparency.OPAQUE); |
|
130 |
} |
|
131 |
||
132 |
/** |
|
35667 | 133 |
* Returns the {@code ColorModel} associated with this |
134 |
* {@code GraphicsConfiguration} that supports the specified |
|
12047 | 135 |
* transparency. |
136 |
* @param transparency the specified transparency mode |
|
35667 | 137 |
* @return a {@code ColorModel} object that is associated with |
138 |
* this {@code GraphicsConfiguration} and supports the |
|
12047 | 139 |
* specified transparency. |
140 |
*/ |
|
141 |
public ColorModel getColorModel(int transparency) { |
|
142 |
return ColorModel.getRGBdefault(); |
|
143 |
} |
|
144 |
||
145 |
/** |
|
146 |
* Returns the default {@link AffineTransform} for this |
|
35667 | 147 |
* {@code GraphicsConfiguration}. This |
148 |
* {@code AffineTransform} is typically the Identity transform |
|
149 |
* for most normal screens. The default {@code AffineTransform} |
|
12047 | 150 |
* maps coordinates onto the device such that 72 user space |
151 |
* coordinate units measure approximately 1 inch in device |
|
152 |
* space. The normalizing transform can be used to make |
|
153 |
* this mapping more exact. Coordinates in the coordinate space |
|
35667 | 154 |
* defined by the default {@code AffineTransform} for screen and |
12047 | 155 |
* printer devices have the origin in the upper left-hand corner of |
156 |
* the target region of the device, with X coordinates |
|
157 |
* increasing to the right and Y coordinates increasing downwards. |
|
158 |
* For image buffers not associated with a device, such as those not |
|
35667 | 159 |
* created by {@code createCompatibleImage}, |
160 |
* this {@code AffineTransform} is the Identity transform. |
|
161 |
* @return the default {@code AffineTransform} for this |
|
162 |
* {@code GraphicsConfiguration}. |
|
12047 | 163 |
*/ |
164 |
public AffineTransform getDefaultTransform() { |
|
165 |
return new AffineTransform(); |
|
166 |
} |
|
167 |
||
168 |
/** |
|
38986 | 169 |
* Returns an {@code AffineTransform} that can be concatenated |
35667 | 170 |
* with the default {@code AffineTransform} |
171 |
* of a {@code GraphicsConfiguration} so that 72 units in user |
|
12047 | 172 |
* space equals 1 inch in device space. |
173 |
* <p> |
|
174 |
* For a particular {@link Graphics2D}, g, one |
|
175 |
* can reset the transformation to create |
|
176 |
* such a mapping by using the following pseudocode: |
|
177 |
* <pre> |
|
178 |
* GraphicsConfiguration gc = g.getGraphicsConfiguration(); |
|
179 |
* |
|
180 |
* g.setTransform(gc.getDefaultTransform()); |
|
181 |
* g.transform(gc.getNormalizingTransform()); |
|
182 |
* </pre> |
|
35667 | 183 |
* Note that sometimes this {@code AffineTransform} is identity, |
12047 | 184 |
* such as for printers or metafile output, and that this |
35667 | 185 |
* {@code AffineTransform} is only as accurate as the information |
12047 | 186 |
* supplied by the underlying system. For image buffers not |
187 |
* associated with a device, such as those not created by |
|
35667 | 188 |
* {@code createCompatibleImage}, this |
189 |
* {@code AffineTransform} is the Identity transform |
|
12047 | 190 |
* since there is no valid distance measurement. |
35667 | 191 |
* @return an {@code AffineTransform} to concatenate to the |
192 |
* default {@code AffineTransform} so that 72 units in user |
|
12047 | 193 |
* space is mapped to 1 inch in device space. |
194 |
*/ |
|
195 |
public AffineTransform getNormalizingTransform() { |
|
196 |
return new AffineTransform(); |
|
197 |
} |
|
198 |
||
199 |
/** |
|
35667 | 200 |
* Returns the bounds of the {@code GraphicsConfiguration} |
12047 | 201 |
* in the device coordinates. In a multi-screen environment |
202 |
* with a virtual device, the bounds can have negative X |
|
203 |
* or Y origins. |
|
204 |
* @return the bounds of the area covered by this |
|
35667 | 205 |
* {@code GraphicsConfiguration}. |
12047 | 206 |
* @since 1.3 |
207 |
*/ |
|
208 |
public Rectangle getBounds() { |
|
209 |
return new Rectangle(0, 0, (int)pf.getWidth(), (int)pf.getHeight()); |
|
210 |
} |
|
211 |
} |