author | serb |
Mon, 28 Jan 2019 17:19:54 -0800 | |
changeset 53673 | e04d39094915 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
12047 | 1 |
/* |
53673
e04d39094915
8214076: Cleanup the code related to GraphicsEnvironment/Device/Configuration
serb
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2011, 2019, 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 |
||
53673
e04d39094915
8214076: Cleanup the code related to GraphicsEnvironment/Device/Configuration
serb
parents:
47216
diff
changeset
|
28 |
import java.awt.Component; |
e04d39094915
8214076: Cleanup the code related to GraphicsEnvironment/Device/Configuration
serb
parents:
47216
diff
changeset
|
29 |
import java.awt.Graphics2D; |
e04d39094915
8214076: Cleanup the code related to GraphicsEnvironment/Device/Configuration
serb
parents:
47216
diff
changeset
|
30 |
import java.awt.GraphicsConfiguration; |
e04d39094915
8214076: Cleanup the code related to GraphicsEnvironment/Device/Configuration
serb
parents:
47216
diff
changeset
|
31 |
import java.awt.GraphicsDevice; |
e04d39094915
8214076: Cleanup the code related to GraphicsEnvironment/Device/Configuration
serb
parents:
47216
diff
changeset
|
32 |
import java.awt.Rectangle; |
e04d39094915
8214076: Cleanup the code related to GraphicsEnvironment/Device/Configuration
serb
parents:
47216
diff
changeset
|
33 |
import java.awt.Transparency; |
e04d39094915
8214076: Cleanup the code related to GraphicsEnvironment/Device/Configuration
serb
parents:
47216
diff
changeset
|
34 |
import java.awt.geom.AffineTransform; |
e04d39094915
8214076: Cleanup the code related to GraphicsEnvironment/Device/Configuration
serb
parents:
47216
diff
changeset
|
35 |
import java.awt.image.BufferedImage; |
e04d39094915
8214076: Cleanup the code related to GraphicsEnvironment/Device/Configuration
serb
parents:
47216
diff
changeset
|
36 |
import java.awt.image.ColorModel; |
e04d39094915
8214076: Cleanup the code related to GraphicsEnvironment/Device/Configuration
serb
parents:
47216
diff
changeset
|
37 |
import java.awt.image.VolatileImage; |
e04d39094915
8214076: Cleanup the code related to GraphicsEnvironment/Device/Configuration
serb
parents:
47216
diff
changeset
|
38 |
import java.awt.print.PageFormat; |
12047 | 39 |
|
53673
e04d39094915
8214076: Cleanup the code related to GraphicsEnvironment/Device/Configuration
serb
parents:
47216
diff
changeset
|
40 |
public final class CPrinterGraphicsConfig extends GraphicsConfiguration { |
e04d39094915
8214076: Cleanup the code related to GraphicsEnvironment/Device/Configuration
serb
parents:
47216
diff
changeset
|
41 |
|
12047 | 42 |
public static CPrinterGraphicsConfig getConfig(PageFormat pf) { |
43 |
return new CPrinterGraphicsConfig(pf); |
|
44 |
} |
|
45 |
||
53673
e04d39094915
8214076: Cleanup the code related to GraphicsEnvironment/Device/Configuration
serb
parents:
47216
diff
changeset
|
46 |
private final GraphicsDevice device; |
e04d39094915
8214076: Cleanup the code related to GraphicsEnvironment/Device/Configuration
serb
parents:
47216
diff
changeset
|
47 |
private final PageFormat pf; |
12047 | 48 |
|
49 |
public CPrinterGraphicsConfig(PageFormat pf) { |
|
53673
e04d39094915
8214076: Cleanup the code related to GraphicsEnvironment/Device/Configuration
serb
parents:
47216
diff
changeset
|
50 |
this.device = new CPrinterDevice(this); |
12047 | 51 |
this.pf = pf; |
52 |
} |
|
53 |
||
54 |
public PageFormat getPageFormat() { |
|
55 |
return pf; |
|
56 |
} |
|
57 |
||
58 |
/** |
|
59 |
* Returns the {@link GraphicsDevice} associated with this |
|
35667 | 60 |
* {@code GraphicsConfiguration}. |
61 |
* @return a {@code GraphicsDevice} object that is |
|
62 |
* associated with this {@code GraphicsConfiguration}. |
|
12047 | 63 |
*/ |
53673
e04d39094915
8214076: Cleanup the code related to GraphicsEnvironment/Device/Configuration
serb
parents:
47216
diff
changeset
|
64 |
@Override |
12047 | 65 |
public GraphicsDevice getDevice() { |
53673
e04d39094915
8214076: Cleanup the code related to GraphicsEnvironment/Device/Configuration
serb
parents:
47216
diff
changeset
|
66 |
return device; |
12047 | 67 |
} |
68 |
||
69 |
/** |
|
70 |
* Returns a {@link BufferedImage} with a data layout and color model |
|
35667 | 71 |
* compatible with this {@code GraphicsConfiguration}. This |
12047 | 72 |
* method has nothing to do with memory-mapping |
35667 | 73 |
* a device. The returned {@code BufferedImage} has |
12047 | 74 |
* a layout and color model that is closest to this native device |
75 |
* configuration and can therefore be optimally blitted to this |
|
76 |
* device. |
|
35667 | 77 |
* @param width the width of the returned {@code BufferedImage} |
78 |
* @param height the height of the returned {@code BufferedImage} |
|
79 |
* @return a {@code BufferedImage} whose data layout and color |
|
80 |
* model is compatible with this {@code GraphicsConfiguration}. |
|
12047 | 81 |
*/ |
53673
e04d39094915
8214076: Cleanup the code related to GraphicsEnvironment/Device/Configuration
serb
parents:
47216
diff
changeset
|
82 |
@Override |
12047 | 83 |
public BufferedImage createCompatibleImage(int width, int height) { |
84 |
return createCompatibleImage(width, height, Transparency.OPAQUE); |
|
85 |
} |
|
86 |
||
87 |
/** |
|
88 |
* Returns a {@link VolatileImage} with a data layout and color model |
|
35667 | 89 |
* compatible with this {@code GraphicsConfiguration}. |
90 |
* The returned {@code VolatileImage} |
|
12047 | 91 |
* may have data that is stored optimally for the underlying graphics |
92 |
* device and may therefore benefit from platform-specific rendering |
|
93 |
* acceleration. |
|
35667 | 94 |
* @param width the width of the returned {@code VolatileImage} |
95 |
* @param height the height of the returned {@code VolatileImage} |
|
96 |
* @return a {@code VolatileImage} whose data layout and color |
|
97 |
* model is compatible with this {@code GraphicsConfiguration}. |
|
12047 | 98 |
* @see Component#createVolatileImage(int, int) |
99 |
*/ |
|
53673
e04d39094915
8214076: Cleanup the code related to GraphicsEnvironment/Device/Configuration
serb
parents:
47216
diff
changeset
|
100 |
@Override |
12047 | 101 |
public VolatileImage createCompatibleVolatileImage(int width, int height) { |
102 |
return createCompatibleVolatileImage(width, height, Transparency.OPAQUE); |
|
103 |
} |
|
104 |
||
105 |
// empty implementation (this should not be called) |
|
53673
e04d39094915
8214076: Cleanup the code related to GraphicsEnvironment/Device/Configuration
serb
parents:
47216
diff
changeset
|
106 |
@Override |
12047 | 107 |
public VolatileImage createCompatibleVolatileImage(int width, int height, int transparency) { |
108 |
return null; |
|
109 |
} |
|
110 |
||
111 |
/** |
|
35667 | 112 |
* Returns a {@code BufferedImage} that supports the specified |
12047 | 113 |
* transparency and has a data layout and color model |
35667 | 114 |
* compatible with this {@code GraphicsConfiguration}. This |
12047 | 115 |
* method has nothing to do with memory-mapping |
35667 | 116 |
* a device. The returned {@code BufferedImage} has a layout and |
12047 | 117 |
* color model that can be optimally blitted to a device |
35667 | 118 |
* with this {@code GraphicsConfiguration}. |
119 |
* @param width the width of the returned {@code BufferedImage} |
|
120 |
* @param height the height of the returned {@code BufferedImage} |
|
12047 | 121 |
* @param transparency the specified transparency mode |
35667 | 122 |
* @return a {@code BufferedImage} whose data layout and color |
123 |
* model is compatible with this {@code GraphicsConfiguration} |
|
12047 | 124 |
* and also supports the specified transparency. |
125 |
* @see Transparency#OPAQUE |
|
126 |
* @see Transparency#BITMASK |
|
127 |
* @see Transparency#TRANSLUCENT |
|
128 |
*/ |
|
53673
e04d39094915
8214076: Cleanup the code related to GraphicsEnvironment/Device/Configuration
serb
parents:
47216
diff
changeset
|
129 |
@Override |
12047 | 130 |
public BufferedImage createCompatibleImage(int width, int height, int transparency) { |
131 |
//+++gdb what to do? |
|
132 |
return null; |
|
133 |
} |
|
134 |
||
135 |
/** |
|
136 |
* Returns the {@link ColorModel} associated with this |
|
35667 | 137 |
* {@code GraphicsConfiguration}. |
138 |
* @return a {@code ColorModel} object that is associated with |
|
139 |
* this {@code GraphicsConfiguration}. |
|
12047 | 140 |
*/ |
53673
e04d39094915
8214076: Cleanup the code related to GraphicsEnvironment/Device/Configuration
serb
parents:
47216
diff
changeset
|
141 |
@Override |
12047 | 142 |
public ColorModel getColorModel() { |
143 |
return getColorModel(Transparency.OPAQUE); |
|
144 |
} |
|
145 |
||
146 |
/** |
|
35667 | 147 |
* Returns the {@code ColorModel} associated with this |
148 |
* {@code GraphicsConfiguration} that supports the specified |
|
12047 | 149 |
* transparency. |
150 |
* @param transparency the specified transparency mode |
|
35667 | 151 |
* @return a {@code ColorModel} object that is associated with |
152 |
* this {@code GraphicsConfiguration} and supports the |
|
12047 | 153 |
* specified transparency. |
154 |
*/ |
|
53673
e04d39094915
8214076: Cleanup the code related to GraphicsEnvironment/Device/Configuration
serb
parents:
47216
diff
changeset
|
155 |
@Override |
12047 | 156 |
public ColorModel getColorModel(int transparency) { |
157 |
return ColorModel.getRGBdefault(); |
|
158 |
} |
|
159 |
||
160 |
/** |
|
161 |
* Returns the default {@link AffineTransform} for this |
|
35667 | 162 |
* {@code GraphicsConfiguration}. This |
163 |
* {@code AffineTransform} is typically the Identity transform |
|
164 |
* for most normal screens. The default {@code AffineTransform} |
|
12047 | 165 |
* maps coordinates onto the device such that 72 user space |
166 |
* coordinate units measure approximately 1 inch in device |
|
167 |
* space. The normalizing transform can be used to make |
|
168 |
* this mapping more exact. Coordinates in the coordinate space |
|
35667 | 169 |
* defined by the default {@code AffineTransform} for screen and |
12047 | 170 |
* printer devices have the origin in the upper left-hand corner of |
171 |
* the target region of the device, with X coordinates |
|
172 |
* increasing to the right and Y coordinates increasing downwards. |
|
173 |
* For image buffers not associated with a device, such as those not |
|
35667 | 174 |
* created by {@code createCompatibleImage}, |
175 |
* this {@code AffineTransform} is the Identity transform. |
|
176 |
* @return the default {@code AffineTransform} for this |
|
177 |
* {@code GraphicsConfiguration}. |
|
12047 | 178 |
*/ |
53673
e04d39094915
8214076: Cleanup the code related to GraphicsEnvironment/Device/Configuration
serb
parents:
47216
diff
changeset
|
179 |
@Override |
12047 | 180 |
public AffineTransform getDefaultTransform() { |
181 |
return new AffineTransform(); |
|
182 |
} |
|
183 |
||
184 |
/** |
|
38986 | 185 |
* Returns an {@code AffineTransform} that can be concatenated |
35667 | 186 |
* with the default {@code AffineTransform} |
187 |
* of a {@code GraphicsConfiguration} so that 72 units in user |
|
12047 | 188 |
* space equals 1 inch in device space. |
189 |
* <p> |
|
190 |
* For a particular {@link Graphics2D}, g, one |
|
191 |
* can reset the transformation to create |
|
192 |
* such a mapping by using the following pseudocode: |
|
193 |
* <pre> |
|
194 |
* GraphicsConfiguration gc = g.getGraphicsConfiguration(); |
|
195 |
* |
|
196 |
* g.setTransform(gc.getDefaultTransform()); |
|
197 |
* g.transform(gc.getNormalizingTransform()); |
|
198 |
* </pre> |
|
35667 | 199 |
* Note that sometimes this {@code AffineTransform} is identity, |
12047 | 200 |
* such as for printers or metafile output, and that this |
35667 | 201 |
* {@code AffineTransform} is only as accurate as the information |
12047 | 202 |
* supplied by the underlying system. For image buffers not |
203 |
* associated with a device, such as those not created by |
|
35667 | 204 |
* {@code createCompatibleImage}, this |
205 |
* {@code AffineTransform} is the Identity transform |
|
12047 | 206 |
* since there is no valid distance measurement. |
35667 | 207 |
* @return an {@code AffineTransform} to concatenate to the |
208 |
* default {@code AffineTransform} so that 72 units in user |
|
12047 | 209 |
* space is mapped to 1 inch in device space. |
210 |
*/ |
|
53673
e04d39094915
8214076: Cleanup the code related to GraphicsEnvironment/Device/Configuration
serb
parents:
47216
diff
changeset
|
211 |
@Override |
12047 | 212 |
public AffineTransform getNormalizingTransform() { |
213 |
return new AffineTransform(); |
|
214 |
} |
|
215 |
||
216 |
/** |
|
35667 | 217 |
* Returns the bounds of the {@code GraphicsConfiguration} |
12047 | 218 |
* in the device coordinates. In a multi-screen environment |
219 |
* with a virtual device, the bounds can have negative X |
|
220 |
* or Y origins. |
|
221 |
* @return the bounds of the area covered by this |
|
35667 | 222 |
* {@code GraphicsConfiguration}. |
12047 | 223 |
* @since 1.3 |
224 |
*/ |
|
53673
e04d39094915
8214076: Cleanup the code related to GraphicsEnvironment/Device/Configuration
serb
parents:
47216
diff
changeset
|
225 |
@Override |
12047 | 226 |
public Rectangle getBounds() { |
227 |
return new Rectangle(0, 0, (int)pf.getWidth(), (int)pf.getHeight()); |
|
228 |
} |
|
229 |
} |