1 /* XGraphicsEnvironment.java -- Represents the X environment
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. */
39 package gnu
.java
.awt
.peer
.x
;
41 import gnu
.java
.awt
.font
.OpenTypeFontPeer
;
42 import gnu
.java
.awt
.java2d
.RasterGraphics
;
43 import gnu
.x11
.Display
;
46 import java
.awt
.Graphics2D
;
47 import java
.awt
.GraphicsDevice
;
48 import java
.awt
.GraphicsEnvironment
;
49 import java
.awt
.image
.BufferedImage
;
51 import java
.io
.FileInputStream
;
52 import java
.io
.FileNotFoundException
;
53 import java
.io
.IOException
;
54 import java
.util
.ArrayList
;
55 import java
.util
.Locale
;
56 import java
.util
.Properties
;
59 * Represents the X environment for AWT.
61 * @author Roman Kennke (kennke@aicas.com)
63 public class XGraphicsEnvironment
64 extends GraphicsEnvironment
68 * The default graphics device. This is normally the local main X
69 * Display, but can be configured to be any X connection.
71 private XGraphicsDevice defaultDevice
;
74 * All configured devices.
76 private XGraphicsDevice
[] devices
;
79 * Creates a new XGraphicsEnvironment. This loads the configuration if
80 * there is one present and initializes the XGraphicsDevices in the
81 * environment. If there is no configuration, then there is one
82 * default device initialized with the local main X device.
84 public XGraphicsEnvironment()
86 // Initiliaze the devices.
87 Properties props
= new Properties();
88 File config
= new File(System
.getProperty("user.home"),
93 FileInputStream configIn
= new FileInputStream(config
);
96 ArrayList deviceList
= new ArrayList();
99 String propName
= "display." + dev
;
100 String propValue
= props
.getProperty(propName
);
101 if (propValue
!= null)
103 Display
.Name displayName
= new Display
.Name(propValue
);
104 XGraphicsDevice device
= new XGraphicsDevice(displayName
);
106 defaultDevice
= device
;
107 deviceList
.add(device
);
114 defaultDevice
= initDefaultDevice();
115 deviceList
.add(defaultDevice
);
120 devices
= (XGraphicsDevice
[]) deviceList
.toArray
121 (new XGraphicsDevice
[deviceList
.size()]);
123 catch (FileNotFoundException ex
)
125 defaultDevice
= initDefaultDevice();
126 devices
= new XGraphicsDevice
[]{ defaultDevice
};
128 catch (IOException ex
)
130 defaultDevice
= initDefaultDevice();
131 devices
= new XGraphicsDevice
[]{ defaultDevice
};
137 * Helper method that initializes the default device in the case when there
138 * is no configuration for the default.
140 private XGraphicsDevice
initDefaultDevice()
142 String display
= System
.getenv("DISPLAY");
145 Display
.Name displayName
= new Display
.Name(display
);
146 return new XGraphicsDevice(displayName
);
150 * Returns all configured screen devices.
152 * @return all configured screen devices
154 public GraphicsDevice
[] getScreenDevices()
156 // We return a copy so that nobody can fiddle with our devices.
157 XGraphicsDevice
[] copy
= new XGraphicsDevice
[devices
.length
];
158 System
.arraycopy(devices
, 0, copy
, 0, devices
.length
);
163 * Returns the default screen device.
165 * @return the default screen device
167 public GraphicsDevice
getDefaultScreenDevice()
169 return defaultDevice
;
173 * Returns a Graphics instance suitable for drawing on top of the
176 * @param image the buffered image to create a graphics for
178 * @return a Graphics2D instance for drawing on the BufferedImage
180 public Graphics2D
createGraphics(BufferedImage image
)
182 return new RasterGraphics(image
.getRaster(), image
.getColorModel());
185 public Font
[] getAllFonts()
187 // TODO: Implement this.
188 throw new UnsupportedOperationException("Not yet implemented.");
191 public String
[] getAvailableFontFamilyNames()
193 return getAvailableFontFamilyNames(Locale
.getDefault());
196 public String
[] getAvailableFontFamilyNames(Locale l
)
198 // TODO: This doesn't work when we are using X fonts.
200 return OpenTypeFontPeer
.getAvailableFontFamilyNames(l
);