001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Oleg V. Khaschansky
019: * @version $Revision$
020: */package java.awt;
021:
022: import java.awt.image.BufferedImage;
023: import java.util.Locale;
024:
025: import org.apache.harmony.awt.ContextStorage;
026: import org.apache.harmony.awt.gl.CommonGraphics2DFactory;
027:
028: public abstract class GraphicsEnvironment {
029: protected GraphicsEnvironment() {
030: }
031:
032: public static GraphicsEnvironment getLocalGraphicsEnvironment() {
033: synchronized (ContextStorage.getContextLock()) {
034: if (ContextStorage.getGraphicsEnvironment() == null) {
035: if (isHeadless()) {
036: ContextStorage
037: .setGraphicsEnvironment(new HeadlessGraphicsEnvironment());
038: } else {
039: CommonGraphics2DFactory g2df = (CommonGraphics2DFactory) Toolkit
040: .getDefaultToolkit().getGraphicsFactory();
041:
042: ContextStorage.setGraphicsEnvironment(g2df
043: .createGraphicsEnvironment(ContextStorage
044: .getWindowFactory()));
045: }
046: }
047:
048: return ContextStorage.getGraphicsEnvironment();
049: }
050: }
051:
052: public boolean isHeadlessInstance() {
053: return false;
054: }
055:
056: public static boolean isHeadless() {
057: return "true".equals(System.getProperty("java.awt.headless"));
058: }
059:
060: public Rectangle getMaximumWindowBounds() throws HeadlessException {
061: return getDefaultScreenDevice().getDefaultConfiguration()
062: .getBounds();
063: }
064:
065: public Point getCenterPoint() throws HeadlessException {
066: Rectangle mwb = getMaximumWindowBounds();
067: return new Point(mwb.width >> 1, mwb.height >> 1);
068: }
069:
070: public void preferLocaleFonts() {
071: // Note: API specification says following:
072: // "The actual change in font rendering behavior resulting
073: // from a call to this method is implementation dependent;
074: // it may have no effect at all." So, doing nothing is an
075: // acceptable behavior for this method.
076:
077: // For now FontManager uses 1.4 font.properties scheme for font mapping, so
078: // this method doesn't make any sense. The implementation of this method
079: // which will influence font mapping is postponed until
080: // 1.5 mapping scheme not implemented.
081:
082: // todo - Implement non-default behavior with 1.5 font mapping scheme
083: }
084:
085: public void preferProportionalFonts() {
086: // Note: API specification says following:
087: // "The actual change in font rendering behavior resulting
088: // from a call to this method is implementation dependent;
089: // it may have no effect at all." So, doing nothing is an
090: // acceptable behavior for this method.
091:
092: // For now FontManager uses 1.4 font.properties scheme for font mapping, so
093: // this method doesn't make any sense. The implementation of this method
094: // which will influence font mapping is postponed until
095: // 1.5 mapping scheme not implemented.
096:
097: // todo - Implement non-default behavior with 1.5 font mapping scheme
098: }
099:
100: public abstract Graphics2D createGraphics(
101: BufferedImage bufferedImage);
102:
103: public abstract Font[] getAllFonts();
104:
105: public abstract String[] getAvailableFontFamilyNames();
106:
107: public abstract String[] getAvailableFontFamilyNames(Locale locale);
108:
109: public abstract GraphicsDevice getDefaultScreenDevice()
110: throws HeadlessException;
111:
112: public abstract GraphicsDevice[] getScreenDevices()
113: throws HeadlessException;
114: }
|