Index: modules/swing/src/main/java/common/javax/swing/RepaintManager.java =================================================================== --- modules/swing/src/main/java/common/javax/swing/RepaintManager.java (revision 506408) +++ modules/swing/src/main/java/common/javax/swing/RepaintManager.java (working copy) @@ -27,6 +27,7 @@ import java.awt.Dimension; import java.awt.EventQueue; import java.awt.Graphics; +import java.awt.GraphicsEnvironment; import java.awt.Image; import java.awt.Rectangle; import java.awt.Toolkit; @@ -51,7 +52,7 @@ private Image offscreenImage; private VolatileImage volatileOffscreenImage; - private Dimension maximumSize = Toolkit.getDefaultToolkit().getScreenSize(); + private Dimension maximumSize; private boolean doubleBufferingEnabled = true; private Map dirtyRegions = new Hashtable(); private Map optimizedDirtyRegions = new HashMap(); @@ -60,6 +61,12 @@ private static final Rectangle COMPLETELY_DIRTY_RECT = new Rectangle(0, 0, Integer.MAX_VALUE, Integer.MAX_VALUE); private static RepaintManager instance; + + RepaintManager() { + maximumSize = GraphicsEnvironment.getLocalGraphicsEnvironment().isHeadlessInstance() ? + new Dimension(0,0) + : Toolkit.getDefaultToolkit().getScreenSize(); + } private final Runnable paintEvent = new Runnable() { public void run() { Index: modules/awt/src/main/java/common/java/awt/Panel.java =================================================================== --- modules/awt/src/main/java/common/java/awt/Panel.java (revision 506408) +++ modules/awt/src/main/java/common/java/awt/Panel.java (working copy) @@ -88,8 +88,10 @@ } @Override - ComponentBehavior createBehavior() { - return new HWBehavior(this); + ComponentBehavior createBehavior() { + return GraphicsEnvironment.getLocalGraphicsEnvironment().isHeadlessInstance() ? + new LWBehavior(this) : + new HWBehavior(this) ; } @Override Index: modules/awt/src/main/java/common/java/awt/EventQueueCore.java =================================================================== --- modules/awt/src/main/java/common/java/awt/EventQueueCore.java (revision 506408) +++ modules/awt/src/main/java/common/java/awt/EventQueueCore.java (working copy) @@ -88,7 +88,9 @@ // TODO: add event coalescing if (toolkit != null) { toolkit.shutdownWatchdog.setAwtQueueEmpty(false); - notifyEventMonitor(toolkit); + if (!GraphicsEnvironment.getLocalGraphicsEnvironment().isHeadlessInstance()) { + notifyEventMonitor(toolkit); + } } notifyAll(); } Index: modules/awt/src/main/java/common/java/awt/EventDispatchThread.java =================================================================== --- modules/awt/src/main/java/common/java/awt/EventDispatchThread.java (revision 506408) +++ modules/awt/src/main/java/common/java/awt/EventDispatchThread.java (working copy) @@ -23,7 +23,7 @@ import org.apache.harmony.awt.wtk.NativeEvent; import org.apache.harmony.awt.wtk.NativeEventQueue; -final class EventDispatchThread extends Thread { +class EventDispatchThread extends Thread { private static final class MarkerEvent extends AWTEvent { MarkerEvent(Object source, int id) { @@ -35,7 +35,7 @@ final Toolkit toolkit; private NativeEventQueue nativeQueue; - private volatile boolean shutdownPending = false; + protected volatile boolean shutdownPending = false; /** * Initialise and run the main event loop Index: modules/awt/src/main/java/common/java/awt/Toolkit.java =================================================================== --- modules/awt/src/main/java/common/java/awt/Toolkit.java (revision 506408) +++ modules/awt/src/main/java/common/java/awt/Toolkit.java (working copy) @@ -71,6 +71,7 @@ import java.util.MissingResourceException; import java.util.Properties; import java.util.ResourceBundle; + import org.apache.harmony.awt.ChoiceStyle; import org.apache.harmony.awt.ComponentInternals; import org.apache.harmony.awt.ContextStorage; @@ -100,15 +101,15 @@ private static final ResourceBundle properties = loadResources(RECOURCE_PATH); - final Dispatcher dispatcher; + Dispatcher dispatcher; private EventQueueCore systemEventQueueCore; - final EventDispatchThread dispatchThread; + EventDispatchThread dispatchThread; NativeEventThread nativeThread; - private final AWTEventsManager awtEventsManager; + protected AWTEventsManager awtEventsManager; /* key = nativeWindow, value = Component, should be Map */ private final Map windowComponentMap = new HashMap(); @@ -150,9 +151,9 @@ */ private final HashSet userPropSet = new HashSet(); - protected final Map desktopProperties; + protected Map desktopProperties; - protected final PropertyChangeSupport desktopPropsSupport; + protected PropertyChangeSupport desktopPropsSupport; /** * For this component the native window is being created @@ -167,9 +168,9 @@ private WTK wtk; - final DTK dtk; + DTK dtk; - private final class ComponentInternalsImpl extends ComponentInternals { + protected final class ComponentInternalsImpl extends ComponentInternals { @Override public NativeWindow getNativeWindow(Component component) { lockAWT(); @@ -382,9 +383,8 @@ * if GraphicsEnvironment.isHeadless() returns true. */ static void checkHeadless() throws HeadlessException { - if (GraphicsEnvironment.isHeadless()) { + if (GraphicsEnvironment.getLocalGraphicsEnvironment().isHeadlessInstance()) throw new HeadlessException(); - } } final void lockAWT() { @@ -401,7 +401,7 @@ static final void staticUnlockAWT() { ContextStorage.getSynchronizer().unlock(); - } + } /** * InvokeAndWait under AWT lock. W/o this method system can hang up. @@ -467,7 +467,8 @@ } staticLockAWT(); try { - defToolkit = new ToolkitImpl(); + defToolkit = GraphicsEnvironment.isHeadless() ? + new HeadlessToolkit() : new ToolkitImpl(); ContextStorage.setDefaultToolkit(defToolkit); return defToolkit; } finally { @@ -524,15 +525,19 @@ return windowFocusProxyMap.get(getWindowFactory().getWindowById(id)); } - final WindowFactory getWindowFactory() { + WindowFactory getWindowFactory() { return wtk.getWindowFactory(); } - final GraphicsFactory getGraphicsFactory() { + GraphicsFactory getGraphicsFactory() { return wtk.getGraphicsFactory(); } + + public Toolkit() { + init(); + } - public Toolkit() { + protected void init() { lockAWT(); try { ComponentInternals.setComponentInternals(new ComponentInternalsImpl()); @@ -662,7 +667,6 @@ Map mapInputMethodHighlightImpl( InputMethodHighlight highlight) throws HeadlessException { - checkHeadless(); HashMap map = new HashMap(); wtk.getSystemProperties().mapInputMethodHighlight(highlight, map); return Collections. unmodifiableMap(map); @@ -729,7 +733,6 @@ throws IndexOutOfBoundsException, HeadlessException { lockAWT(); try { - checkHeadless(); int w = img.getWidth(null), x = hotSpot.x; int h = img.getHeight(null), y = hotSpot.y; if (x < 0 || x >= w || y < 0 || y >= h) { @@ -758,7 +761,6 @@ public Dimension getBestCursorSize(int prefWidth, int prefHeight) throws HeadlessException { lockAWT(); try { - checkHeadless(); return wtk.getCursorFactory().getBestCursorSize(prefWidth, prefHeight); } finally { unlockAWT(); @@ -802,7 +804,6 @@ public int getMaximumCursorColors() throws HeadlessException { lockAWT(); try { - checkHeadless(); return wtk.getCursorFactory().getMaximumCursorColors(); } finally { unlockAWT(); @@ -812,7 +813,6 @@ public int getMenuShortcutKeyMask() throws HeadlessException { lockAWT(); try { - checkHeadless(); return InputEvent.CTRL_MASK; } finally { unlockAWT(); @@ -862,7 +862,6 @@ public Clipboard getSystemSelection() throws HeadlessException { lockAWT(); try { - checkHeadless(); SecurityManager security = System.getSecurityManager(); if (security != null) { security.checkSystemClipboardAccess(); @@ -888,7 +887,6 @@ public boolean isDynamicLayoutActive() throws HeadlessException { lockAWT(); try { - checkHeadless(); // always return true return true; } finally { @@ -899,7 +897,6 @@ protected boolean isDynamicLayoutSet() throws HeadlessException { lockAWT(); try { - checkHeadless(); return bDynamicLayoutSet; } finally { unlockAWT(); @@ -909,7 +906,6 @@ public boolean isFrameStateSupported(int state) throws HeadlessException { lockAWT(); try { - checkHeadless(); return wtk.getWindowFactory().isWindowStateSupported(state); } finally { unlockAWT(); @@ -944,7 +940,6 @@ public void setDynamicLayout(boolean dynamic) throws HeadlessException { lockAWT(); try { - checkHeadless(); bDynamicLayoutSet = dynamic; } finally { unlockAWT(); Index: modules/awt/src/main/java/common/java/awt/HeadlessToolkit.java =================================================================== --- modules/awt/src/main/java/common/java/awt/HeadlessToolkit.java (revision 0) +++ modules/awt/src/main/java/common/java/awt/HeadlessToolkit.java (revision 0) @@ -0,0 +1,290 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package java.awt; + +import java.awt.datatransfer.Clipboard; +import java.awt.dnd.DragGestureEvent; +import java.awt.dnd.DragGestureListener; +import java.awt.dnd.DragGestureRecognizer; +import java.awt.dnd.DragSource; +import java.awt.dnd.InvalidDnDOperationException; +import java.awt.dnd.peer.DragSourceContextPeer; +import java.awt.im.InputMethodHighlight; +import java.awt.image.ColorModel; +import java.awt.peer.*; +import java.beans.PropertyChangeSupport; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; + +import org.apache.harmony.awt.ComponentInternals; +import org.apache.harmony.awt.datatransfer.DTK; +import org.apache.harmony.awt.wtk.GraphicsFactory; +import org.apache.harmony.awt.wtk.NativeEventQueue; +import org.apache.harmony.awt.wtk.WindowFactory; + +public final class HeadlessToolkit extends ToolkitImpl { + + @Override + protected ButtonPeer createButton(Button a0) throws HeadlessException { + throw new HeadlessException(); + } + + @Override + protected CheckboxPeer createCheckbox(Checkbox a0) throws HeadlessException { + throw new HeadlessException(); + } + + @Override + protected CheckboxMenuItemPeer createCheckboxMenuItem(CheckboxMenuItem a0) throws HeadlessException { + throw new HeadlessException(); + } + + @Override + protected ChoicePeer createChoice(Choice a0) throws HeadlessException { + throw new HeadlessException(); + } + + public Cursor createCustomCursor(Image img, Point hotSpot, String name) + throws HeadlessException { + throw new HeadlessException(); + } + + @Override + protected DialogPeer createDialog(Dialog a0) throws HeadlessException { + throw new HeadlessException(); + } + + @Override + public T createDragGestureRecognizer( + Class recognizerAbstractClass, DragSource ds, Component c, int srcActions, + DragGestureListener dgl) { + return null; + } + + @Override + public DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge) + throws InvalidDnDOperationException { + throw new InvalidDnDOperationException(); + } + + @Override + protected FileDialogPeer createFileDialog(FileDialog a0) throws HeadlessException { + throw new HeadlessException(); + } + + @Override + protected FramePeer createFrame(Frame a0) throws HeadlessException { + throw new HeadlessException(); + } + + @Override + protected LabelPeer createLabel(Label a0) throws HeadlessException { + throw new HeadlessException(); + } + + @Override + protected ListPeer createList(List a0) throws HeadlessException { + throw new HeadlessException(); + } + + @Override + protected MenuPeer createMenu(Menu a0) throws HeadlessException { + throw new HeadlessException(); + } + + @Override + protected MenuBarPeer createMenuBar(MenuBar a0) throws HeadlessException { + throw new HeadlessException(); + } + + @Override + protected MenuItemPeer createMenuItem(MenuItem a0) throws HeadlessException { + throw new HeadlessException(); + } + + @Override + protected PopupMenuPeer createPopupMenu(PopupMenu a0) throws HeadlessException { + throw new HeadlessException(); + } + + @Override + protected ScrollbarPeer createScrollbar(Scrollbar a0) throws HeadlessException { + throw new HeadlessException(); + } + + @Override + protected ScrollPanePeer createScrollPane(ScrollPane a0) throws HeadlessException { + throw new HeadlessException(); + } + + @Override + protected TextAreaPeer createTextArea(TextArea a0) throws HeadlessException { + throw new HeadlessException(); + } + + @Override + protected TextFieldPeer createTextField(TextField a0) throws HeadlessException { + throw new HeadlessException(); + } + + @Override + protected WindowPeer createWindow(Window a0) throws HeadlessException { + throw new HeadlessException(); + } + + @Override + public Dimension getBestCursorSize(int prefWidth, int prefHeight) throws HeadlessException { + throw new HeadlessException(); + } + + @Override + public ColorModel getColorModel() throws HeadlessException { + throw new HeadlessException(); + } + + @Override + GraphicsFactory getGraphicsFactory() throws HeadlessException { + throw new HeadlessException(); + } + + @Override + public boolean getLockingKeyState(int keyCode) throws UnsupportedOperationException { + throw new HeadlessException(); + } + + @Override + public int getMaximumCursorColors() throws HeadlessException { + throw new HeadlessException(); + } + + @Override + public int getMenuShortcutKeyMask() throws HeadlessException { + throw new HeadlessException(); + } + + @Override + NativeEventQueue getNativeEventQueue() throws HeadlessException { + throw new HeadlessException(); + } + + @Override + public PrintJob getPrintJob(Frame frame, String jobtitle, JobAttributes jobAttributes, + PageAttributes pageAttributes) throws IllegalArgumentException { + throw new IllegalArgumentException(); + } + + @Override + public PrintJob getPrintJob(Frame frame, String jobtitle, Properties props) throws NullPointerException { + throw new NullPointerException(); + } + + @Override + public Insets getScreenInsets(GraphicsConfiguration gc) throws HeadlessException { + throw new HeadlessException(); + } + + @Override + public int getScreenResolution() throws HeadlessException { + throw new HeadlessException(); + } + + @Override + public Dimension getScreenSize() throws HeadlessException { + throw new HeadlessException(); + } + + @Override + public Clipboard getSystemClipboard() throws HeadlessException { + throw new HeadlessException(); + } + + @Override + public Clipboard getSystemSelection() throws HeadlessException { + throw new HeadlessException(); + } + + @Override + WindowFactory getWindowFactory() throws HeadlessException { + throw new HeadlessException(); + } + + @Override + protected void init() { + lockAWT(); + try { + ComponentInternals.setComponentInternals(new ComponentInternalsImpl()); + new EventQueue(this); // create the system EventQueue + dispatcher = new Dispatcher(this); + desktopProperties = new HashMap(); + desktopPropsSupport = new PropertyChangeSupport(this); + awtEventsManager = new AWTEventsManager(); + dispatchThread = new HeadlessEventDispatchThread(this, dispatcher); + dtk = DTK.getDTK(); + dispatchThread.start(); + } finally { + unlockAWT(); + } + } + + @Override + public boolean isDynamicLayoutActive() throws HeadlessException { + throw new HeadlessException(); + } + + @Override + protected boolean isDynamicLayoutSet() throws HeadlessException { + throw new HeadlessException(); + } + + @Override + public boolean isFrameStateSupported(int state) throws HeadlessException { + throw new HeadlessException(); + } + + @Override + protected void loadSystemColors(int[] systemColors) throws HeadlessException { + throw new HeadlessException(); + } + + @Override + public Map mapInputMethodHighlight( + InputMethodHighlight highlight) throws HeadlessException { + throw new HeadlessException(); + } + + @Override + Map mapInputMethodHighlightImpl( + InputMethodHighlight highlight) throws HeadlessException { + throw new HeadlessException(); + } + + @Override + public void setDynamicLayout(boolean dynamic) throws HeadlessException { + throw new HeadlessException(); + } + + @Override + public void setLockingKeyState(int keyCode, boolean on) throws UnsupportedOperationException { + throw new HeadlessException(); + } +} Index: modules/awt/src/main/java/common/java/awt/HeadlessGraphicsEnvironment.java =================================================================== --- modules/awt/src/main/java/common/java/awt/HeadlessGraphicsEnvironment.java (revision 0) +++ modules/awt/src/main/java/common/java/awt/HeadlessGraphicsEnvironment.java (revision 0) @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package java.awt; + +import java.awt.GraphicsDevice; +import java.awt.HeadlessException; + +import org.apache.harmony.awt.gl.CommonGraphicsEnvironment; + +public class HeadlessGraphicsEnvironment extends CommonGraphicsEnvironment { + + @Override + public boolean isHeadlessInstance() { + return true; + } + + @Override + public GraphicsDevice getDefaultScreenDevice() throws HeadlessException { + throw new HeadlessException(); + } + + @Override + public GraphicsDevice[] getScreenDevices() throws HeadlessException { + throw new HeadlessException(); + } + +} Index: modules/awt/src/main/java/common/java/awt/Canvas.java =================================================================== --- modules/awt/src/main/java/common/java/awt/Canvas.java (revision 506408) +++ modules/awt/src/main/java/common/java/awt/Canvas.java (working copy) @@ -126,8 +126,10 @@ } @Override - ComponentBehavior createBehavior() { - return new HWBehavior(this); + ComponentBehavior createBehavior() { + return GraphicsEnvironment.getLocalGraphicsEnvironment().isHeadlessInstance() ? + new LWBehavior(this) : + new HWBehavior(this) ; } @Override Index: modules/awt/src/main/java/common/java/awt/HeadlessEventDispatchThread.java =================================================================== --- modules/awt/src/main/java/common/java/awt/HeadlessEventDispatchThread.java (revision 0) +++ modules/awt/src/main/java/common/java/awt/HeadlessEventDispatchThread.java (revision 0) @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package java.awt; + +final class HeadlessEventDispatchThread extends EventDispatchThread { + + HeadlessEventDispatchThread(Toolkit toolkit, Dispatcher dispatcher ) { + super(toolkit, dispatcher); + } + + /** + * Initialise and run the main event loop + */ + @Override + public void run() { + try { + runModalLoop(null); + } finally { + toolkit.shutdownWatchdog.forceShutdown(); + } + } + + void runModalLoop(ModalContext context) { + long lastPaintTime = System.currentTimeMillis(); + while (!shutdownPending && (context == null || context.isModalLoopRunning())) { + try { + EventQueue eventQueue = toolkit.getSystemEventQueueImpl(); + + toolkit.shutdownWatchdog.setNativeQueueEmpty(true); + AWTEvent ae = eventQueue.getNextEventNoWait(); + if (ae != null) { + eventQueue.dispatchEvent(ae); + long curTime = System.currentTimeMillis(); + if (curTime - lastPaintTime > 10) { + toolkit.onQueueEmpty(); + lastPaintTime = System.currentTimeMillis(); + } + } else { + toolkit.shutdownWatchdog.setAwtQueueEmpty(true); + toolkit.onQueueEmpty(); + lastPaintTime = System.currentTimeMillis(); + } + } catch (Throwable t) { + t.printStackTrace(); + } + } + } + +} Index: modules/awt/src/main/java/common/java/awt/Component.java =================================================================== --- modules/awt/src/main/java/common/java/awt/Component.java (revision 506408) +++ modules/awt/src/main/java/common/java/awt/Component.java (working copy) @@ -69,12 +69,14 @@ import java.util.Locale; import java.util.Map; import java.util.Set; + import javax.accessibility.Accessible; import javax.accessibility.AccessibleComponent; import javax.accessibility.AccessibleContext; import javax.accessibility.AccessibleRole; import javax.accessibility.AccessibleState; import javax.accessibility.AccessibleStateSet; + import org.apache.harmony.awt.ClipRegion; import org.apache.harmony.awt.FieldsAccessor; import org.apache.harmony.awt.gl.MultiRectArea; @@ -4058,7 +4060,6 @@ } public Point getMousePosition() throws HeadlessException { - Toolkit.checkHeadless(); Point absPointerPos = MouseInfo.getPointerInfo().getLocation(); Window winUnderPtr = toolkit.dispatcher.mouseDispatcher.findWindowAt(absPointerPos); Point pointerPos = MouseDispatcher.convertPoint(null, absPointerPos, winUnderPtr); Index: modules/awt/src/main/java/common/java/awt/SystemColor.java =================================================================== --- modules/awt/src/main/java/common/java/awt/SystemColor.java (revision 506408) +++ modules/awt/src/main/java/common/java/awt/SystemColor.java (working copy) @@ -141,6 +141,88 @@ public static final SystemColor infoText = new SystemColor(INFO_TEXT); private final transient Toolkit toolkit = Toolkit.getDefaultToolkit(); + + private int getHeadlessSystemColorARGB(int index) { + switch(index) { + // Grey-blue + case SystemColor.ACTIVE_CAPTION: + return 0xff336699; + case SystemColor.ACTIVE_CAPTION_BORDER: + return 0xffcccccc; + case SystemColor.ACTIVE_CAPTION_TEXT: + return 0xffffffff; + // Light grey + case SystemColor.CONTROL: + return 0xffdddddd; + // Dark grey + case SystemColor.CONTROL_DK_SHADOW: + return 0xff777777; + // Almost white + case SystemColor.CONTROL_HIGHLIGHT: + return 0xffeeeeee; + // White + case SystemColor.CONTROL_LT_HIGHLIGHT: + return 0xffffffff; + // Grey + case SystemColor.CONTROL_SHADOW: + return 0xff999999; + // Black + case SystemColor.CONTROL_TEXT: + return 0xff000000; + // Dark blue + case SystemColor.DESKTOP: + return 0xff224466; + // Another grey + case SystemColor.INACTIVE_CAPTION: + return 0xff888888; + // Grey + case SystemColor.INACTIVE_CAPTION_BORDER: + return 0xffcccccc; + // Light grey + case SystemColor.INACTIVE_CAPTION_TEXT: + return 0xffdddddd; + // Almost white + case SystemColor.INFO: + return 0xffeeeeee; + case SystemColor.INFO_TEXT: + return 0xff222222; + // Light grey + case SystemColor.MENU: + return 0xffdddddd; + // Black + case SystemColor.MENU_TEXT: + return 0xff000000; + // Grey + case SystemColor.SCROLLBAR: + return 0xffcccccc; + // White + case SystemColor.TEXT: + return 0xffffffff; + // Grey blue + case SystemColor.TEXT_HIGHLIGHT: + return 0xff336699; + // White + case SystemColor.TEXT_HIGHLIGHT_TEXT: + return 0xffffffff; + // Almost white + case SystemColor.TEXT_INACTIVE_TEXT: + return 0xffdddddd; + // Black + case SystemColor.TEXT_TEXT: + return 0xff000000; + // White + case SystemColor.WINDOW: + return 0xffffffff; + // Black + case SystemColor.WINDOW_BORDER: + return 0xff000000; + // Black + case SystemColor.WINDOW_TEXT: + return 0xff000000; + } + // Black + return 0xFF000000; + } private final int index; @Override @@ -159,8 +241,10 @@ value = getRGB(); } - private int getARGB() { - return toolkit.getWTK().getSystemProperties().getSystemColorARGB(index); + private int getARGB() { + return GraphicsEnvironment.getLocalGraphicsEnvironment().isHeadlessInstance() ? + getHeadlessSystemColorARGB(index) : + toolkit.getWTK().getSystemProperties().getSystemColorARGB(index); } @Override Index: modules/awt/src/main/java/common/java/awt/ToolkitImpl.java =================================================================== --- modules/awt/src/main/java/common/java/awt/ToolkitImpl.java (revision 506408) +++ modules/awt/src/main/java/common/java/awt/ToolkitImpl.java (working copy) @@ -48,10 +48,9 @@ } @Override - protected TextAreaPeer createTextArea(TextArea a0) throws HeadlessException { + protected TextAreaPeer createTextArea(TextArea a0) { lockAWT(); try { - checkHeadless(); return null; } finally { unlockAWT(); @@ -117,7 +116,7 @@ } @Override - public ColorModel getColorModel() throws HeadlessException { + public ColorModel getColorModel() { lockAWT(); try { return GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice() @@ -166,10 +165,9 @@ } @Override - protected ButtonPeer createButton(Button a0) throws HeadlessException { + protected ButtonPeer createButton(Button a0) { lockAWT(); try { - checkHeadless(); return null; } finally { unlockAWT(); @@ -187,10 +185,9 @@ } @Override - protected CheckboxPeer createCheckbox(Checkbox a0) throws HeadlessException { + protected CheckboxPeer createCheckbox(Checkbox a0) { lockAWT(); try { - checkHeadless(); return null; } finally { unlockAWT(); @@ -202,7 +199,6 @@ throws HeadlessException { lockAWT(); try { - checkHeadless(); return null; } finally { unlockAWT(); @@ -210,10 +206,9 @@ } @Override - protected ChoicePeer createChoice(Choice a0) throws HeadlessException { + protected ChoicePeer createChoice(Choice a0) { lockAWT(); try { - checkHeadless(); return null; } finally { unlockAWT(); @@ -221,10 +216,9 @@ } @Override - protected DialogPeer createDialog(Dialog a0) throws HeadlessException { + protected DialogPeer createDialog(Dialog a0) { lockAWT(); try { - checkHeadless(); return null; } finally { unlockAWT(); @@ -238,10 +232,9 @@ } @Override - protected FileDialogPeer createFileDialog(FileDialog a0) throws HeadlessException { + protected FileDialogPeer createFileDialog(FileDialog a0) { lockAWT(); try { - checkHeadless(); return null; } finally { unlockAWT(); @@ -249,10 +242,9 @@ } @Override - protected FramePeer createFrame(Frame a0) throws HeadlessException { + protected FramePeer createFrame(Frame a0) { lockAWT(); try { - checkHeadless(); return null; } finally { unlockAWT(); @@ -260,10 +252,9 @@ } @Override - protected LabelPeer createLabel(Label a0) throws HeadlessException { + protected LabelPeer createLabel(Label a0) { lockAWT(); try { - checkHeadless(); return null; } finally { unlockAWT(); @@ -271,10 +262,9 @@ } @Override - protected ListPeer createList(List a0) throws HeadlessException { + protected ListPeer createList(List a0) { lockAWT(); try { - checkHeadless(); return null; } finally { unlockAWT(); @@ -282,10 +272,9 @@ } @Override - protected MenuPeer createMenu(Menu a0) throws HeadlessException { + protected MenuPeer createMenu(Menu a0) { lockAWT(); try { - checkHeadless(); return null; } finally { unlockAWT(); @@ -293,10 +282,9 @@ } @Override - protected MenuBarPeer createMenuBar(MenuBar a0) throws HeadlessException { + protected MenuBarPeer createMenuBar(MenuBar a0) { lockAWT(); try { - checkHeadless(); return null; } finally { unlockAWT(); @@ -304,10 +292,9 @@ } @Override - protected MenuItemPeer createMenuItem(MenuItem a0) throws HeadlessException { + protected MenuItemPeer createMenuItem(MenuItem a0) { lockAWT(); try { - checkHeadless(); return null; } finally { unlockAWT(); @@ -325,10 +312,9 @@ } @Override - protected PopupMenuPeer createPopupMenu(PopupMenu a0) throws HeadlessException { + protected PopupMenuPeer createPopupMenu(PopupMenu a0) { lockAWT(); try { - checkHeadless(); return null; } finally { unlockAWT(); @@ -336,10 +322,9 @@ } @Override - protected ScrollPanePeer createScrollPane(ScrollPane a0) throws HeadlessException { + protected ScrollPanePeer createScrollPane(ScrollPane a0) { lockAWT(); try { - checkHeadless(); return null; } finally { unlockAWT(); @@ -347,10 +332,9 @@ } @Override - protected ScrollbarPeer createScrollbar(Scrollbar a0) throws HeadlessException { + protected ScrollbarPeer createScrollbar(Scrollbar a0) { lockAWT(); try { - checkHeadless(); return null; } finally { unlockAWT(); @@ -358,10 +342,9 @@ } @Override - protected TextFieldPeer createTextField(TextField a0) throws HeadlessException { + protected TextFieldPeer createTextField(TextField a0) { lockAWT(); try { - checkHeadless(); return null; } finally { unlockAWT(); @@ -369,10 +352,9 @@ } @Override - protected WindowPeer createWindow(Window a0) throws HeadlessException { + protected WindowPeer createWindow(Window a0) { lockAWT(); try { - checkHeadless(); return null; } finally { unlockAWT(); @@ -465,7 +447,7 @@ } @Override - public Dimension getScreenSize() throws HeadlessException { + public Dimension getScreenSize() { lockAWT(); try { DisplayMode dm = GraphicsEnvironment.getLocalGraphicsEnvironment() @@ -477,10 +459,9 @@ } @Override - public Clipboard getSystemClipboard() throws HeadlessException { + public Clipboard getSystemClipboard() { lockAWT(); try { - checkHeadless(); SecurityManager security = System.getSecurityManager(); if (security != null) { security.checkSystemClipboardAccess(); Index: modules/awt/src/main/java/common/java/awt/GraphicsEnvironment.java =================================================================== --- modules/awt/src/main/java/common/java/awt/GraphicsEnvironment.java (revision 506408) +++ modules/awt/src/main/java/common/java/awt/GraphicsEnvironment.java (working copy) @@ -24,8 +24,8 @@ import java.awt.image.BufferedImage; import java.util.Locale; -import org.apache.harmony.awt.*; -import org.apache.harmony.awt.gl.*; +import org.apache.harmony.awt.ContextStorage; +import org.apache.harmony.awt.gl.CommonGraphics2DFactory; public abstract class GraphicsEnvironment { @@ -34,11 +34,16 @@ public static GraphicsEnvironment getLocalGraphicsEnvironment() { synchronized(ContextStorage.getContextLock()) { if (ContextStorage.getGraphicsEnvironment() == null) { - CommonGraphics2DFactory g2df = - (CommonGraphics2DFactory) Toolkit.getDefaultToolkit().getGraphicsFactory(); - ContextStorage.setGraphicsEnvironment( - g2df.createGraphicsEnvironment(ContextStorage.getWindowFactory()) - ); + if (isHeadless()) { + ContextStorage.setGraphicsEnvironment(new HeadlessGraphicsEnvironment()); + } else { + CommonGraphics2DFactory g2df = + (CommonGraphics2DFactory) Toolkit.getDefaultToolkit().getGraphicsFactory(); + + ContextStorage.setGraphicsEnvironment( + g2df.createGraphicsEnvironment(ContextStorage.getWindowFactory()) + ); + } } return ContextStorage.getGraphicsEnvironment(); @@ -46,18 +51,11 @@ } public boolean isHeadlessInstance() { - // At present headless mode not supported, HeadlessException will never be thrown - try { - getDefaultScreenDevice(); - } catch (HeadlessException e) { - return true; - } - return false; } public static boolean isHeadless() { - return getLocalGraphicsEnvironment().isHeadlessInstance(); + return "true".equals(System.getProperty("java.awt.headless")); } public Rectangle getMaximumWindowBounds() throws HeadlessException {