1 /* XGraphicsConfiguration.java -- GraphicsConfiguration for X
2 Copyright (C) 2006 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
38 package gnu
.java
.awt
.peer
.x
;
40 import gnu
.x11
.Display
;
41 import gnu
.x11
.Screen
;
43 import java
.awt
.Dimension
;
44 import java
.awt
.GraphicsConfiguration
;
45 import java
.awt
.GraphicsDevice
;
46 import java
.awt
.Point
;
47 import java
.awt
.Rectangle
;
48 import java
.awt
.Transparency
;
49 import java
.awt
.color
.ColorSpace
;
50 import java
.awt
.geom
.AffineTransform
;
51 import java
.awt
.image
.BufferedImage
;
52 import java
.awt
.image
.ColorModel
;
53 import java
.awt
.image
.ComponentColorModel
;
54 import java
.awt
.image
.ComponentSampleModel
;
55 import java
.awt
.image
.DataBuffer
;
56 import java
.awt
.image
.Raster
;
57 import java
.awt
.image
.SampleModel
;
58 import java
.awt
.image
.VolatileImage
;
59 import java
.awt
.image
.WritableRaster
;
61 public class XGraphicsConfiguration
62 extends GraphicsConfiguration
65 XGraphicsDevice device
;
67 XGraphicsConfiguration(XGraphicsDevice dev
)
72 public GraphicsDevice
getDevice()
77 public BufferedImage
createCompatibleImage(int w
, int h
)
79 return createCompatibleImage(w
, h
, Transparency
.OPAQUE
);
82 public BufferedImage
createCompatibleImage(int w
, int h
, int transparency
)
87 case Transparency
.OPAQUE
:
88 DataBuffer buffer
= new ZPixmapDataBuffer(w
, h
);
89 SampleModel sm
= new ComponentSampleModel(DataBuffer
.TYPE_BYTE
, w
, h
,
91 new int[]{0, 1, 2, 3 });
92 ColorSpace cs
= ColorSpace
.getInstance(ColorSpace
.CS_LINEAR_RGB
);
93 ColorModel cm
= new ComponentColorModel(cs
, true, false,
95 DataBuffer
.TYPE_BYTE
);
96 WritableRaster raster
= Raster
.createWritableRaster(sm
, buffer
,
98 bi
= new BufferedImage(cm
, raster
, false, null);
100 case Transparency
.BITMASK
:
101 case Transparency
.TRANSLUCENT
:
102 bi
= new BufferedImage(w
, h
, BufferedImage
.TYPE_INT_ARGB
);
105 throw new IllegalArgumentException("Illegal transparency: "
111 public VolatileImage
createCompatibleVolatileImage(int w
, int h
)
113 return createCompatibleVolatileImage(w
, h
, Transparency
.OPAQUE
);
116 public VolatileImage
createCompatibleVolatileImage(int width
, int height
,
120 switch (transparency
)
122 case Transparency
.OPAQUE
:
123 im
= new PixmapVolatileImage(width
, height
);
125 case Transparency
.BITMASK
:
126 case Transparency
.TRANSLUCENT
:
127 throw new UnsupportedOperationException("Not yet implemented");
129 throw new IllegalArgumentException("Unknown transparency type: "
135 public ColorModel
getColorModel()
137 // TODO: Implement this.
138 throw new UnsupportedOperationException("Not yet implemented.");
141 public ColorModel
getColorModel(int transparency
)
143 // TODO: Implement this.
144 throw new UnsupportedOperationException("Not yet implemented.");
147 public AffineTransform
getDefaultTransform()
149 // TODO: Implement this.
150 throw new UnsupportedOperationException("Not yet implemented.");
153 public AffineTransform
getNormalizingTransform()
155 // TODO: Implement this.
156 throw new UnsupportedOperationException("Not yet implemented.");
159 public Rectangle
getBounds()
161 // TODO: Implement this.
162 throw new UnsupportedOperationException("Not yet implemented.");
166 * Determines the size of the primary screen.
168 * @return the size of the primary screen
172 // TODO: A GraphicsConfiguration should correspond to a Screen instance.
173 Display d
= device
.getDisplay();
174 Screen screen
= d
.default_screen
;
175 int w
= screen
.width
;
176 int h
= screen
.height
;
177 return new Dimension(w
, h
);
181 * Determines the resolution of the primary screen in pixel-per-inch.
183 * @returnthe resolution of the primary screen in pixel-per-inch
187 Display d
= device
.getDisplay();
188 Screen screen
= d
.default_screen
;
189 int w
= screen
.width
* 254;
190 int h
= screen
.height
* 254;
191 int wmm
= screen
.width_in_mm
* 10;
192 int hmm
= screen
.height_in_mm
* 10;
195 int dpi
= (xdpi
+ ydpi
) / 2;