001: /*
002: * @(#)X11GraphicsDevice.java 1.10 06/10/10
003: *
004: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: *
026: */
027:
028: package java.awt;
029:
030: import java.util.Vector;
031:
032: /**
033: * This is an implementation of a GraphicsDevice object for a single
034: * X11 screen.
035: *
036: * @see GraphicsEnvironment
037: * @see GraphicsConfiguration
038: * @version 10 Feb 1997
039: */
040: class X11GraphicsDevice extends GraphicsDevice {
041: private int screen;
042: X11GraphicsConfig[] configs;
043: X11GraphicsConfig defaultConfig;
044:
045: public X11GraphicsDevice(int screennum) {
046: this .screen = screennum;
047: }
048:
049: /**
050: * Returns the X11 screen of the device.
051: */
052: public int getScreen() {
053: return screen;
054: }
055:
056: /**
057: * Returns the X11 Display of this device.
058: */
059: public native int getDisplay();
060:
061: /**
062: * Returns the type of the graphics device.
063: * @see #TYPE_RASTER_SCREEN
064: * @see #TYPE_PRINTER
065: * @see #TYPE_IMAGE_BUFFER
066: */
067: public int getType() {
068: return TYPE_RASTER_SCREEN;
069: }
070:
071: /**
072: * Returns the identification string associated with this graphics
073: * device.
074: */
075: public native String getIDstring();
076:
077: private native int[] getDepths(int screen);
078:
079: private native int[] getVisualIDs(int screen, int depth);
080:
081: private native int getDefaultVisual();
082:
083: /**
084: * Returns all of the graphics
085: * configurations associated with this graphics device.
086: */
087: public GraphicsConfiguration[] getConfigurations() {
088: X11GraphicsConfig[] ret = configs;
089: if (ret == null) {
090: int[] Xdepths = getDepths(screen);
091: Vector Xconfigs = new Vector();
092: if (defaultConfig != null)
093: Xconfigs.add(defaultConfig);
094: for (int i = 0; i < Xdepths.length; i++) {
095: int[] Xvisuals = getVisualIDs(screen, Xdepths[i]);
096: if (Xvisuals != null)
097: for (int j = 0; j < Xvisuals.length; j++)
098: Xconfigs.add(new X11GraphicsConfig(this ,
099: Xvisuals[j]));
100: }
101: ret = configs = new X11GraphicsConfig[Xconfigs.size()];
102: System.arraycopy(Xconfigs.toArray(), 0, configs, 0,
103: Xconfigs.size());
104: }
105: return ret;
106: }
107:
108: /**
109: * Returns the default graphics configuration
110: * associated with this graphics device.
111: */
112: public GraphicsConfiguration getDefaultConfiguration() {
113: if (defaultConfig == null) {
114: /* FIXME: I should get my defaults here */
115: // defaultConfig = X11GraphicsConfig(this, /* visual number */);
116: getConfigurations();
117: int defaultVis = getDefaultVisual();
118: for (int i = 0; i < configs.length; i++)
119: if (configs[i].visual == defaultVis) {
120: defaultConfig = configs[i];
121: break;
122: }
123: System.out.println("GCLen=" + configs.length + " GC="
124: + configs);
125: defaultConfig.getColorModel();
126: }
127: return defaultConfig;
128: }
129:
130: public String toString() {
131: return ("X11GraphicsDevice[screen=" + screen + "]");
132: }
133: }
|