From: <ls...@us...> - 2007-01-28 21:36:50
|
Revision: 3097 http://jnode.svn.sourceforge.net/jnode/?rev=3097&view=rev Author: lsantha Date: 2007-01-28 13:36:49 -0800 (Sun, 28 Jan 2007) Log Message: ----------- Classpath patches. Modified Paths: -------------- trunk/core/src/classpath/java/java/awt/Button.java trunk/core/src/classpath/java/java/awt/Component.java trunk/core/src/classpath/java/java/awt/MenuBar.java Modified: trunk/core/src/classpath/java/java/awt/Button.java =================================================================== --- trunk/core/src/classpath/java/java/awt/Button.java 2007-01-28 20:52:02 UTC (rev 3096) +++ trunk/core/src/classpath/java/java/awt/Button.java 2007-01-28 21:36:49 UTC (rev 3097) @@ -352,11 +352,11 @@ * * @since 1.3 */ - public EventListener[] getListeners(Class listenerType) + public <T extends EventListener> T[] getListeners(Class<T> listenerType) { if (listenerType == ActionListener.class) - return getActionListeners(); - return (EventListener[]) Array.newInstance(listenerType, 0); + return (T[]) getActionListeners(); + return (T[]) Array.newInstance(listenerType, 0); } /*************************************************************************/ Modified: trunk/core/src/classpath/java/java/awt/Component.java =================================================================== --- trunk/core/src/classpath/java/java/awt/Component.java 2007-01-28 20:52:02 UTC (rev 3096) +++ trunk/core/src/classpath/java/java/awt/Component.java 2007-01-28 21:36:49 UTC (rev 3097) @@ -2847,29 +2847,29 @@ * @see #getPropertyChangeListeners() * @since 1.3 */ - public EventListener[] getListeners(Class listenerType) + public <T extends EventListener> T[] getListeners(Class<T> listenerType) { if (listenerType == ComponentListener.class) - return getComponentListeners(); + return (T[]) getComponentListeners(); if (listenerType == FocusListener.class) - return getFocusListeners(); + return (T[]) getFocusListeners(); if (listenerType == HierarchyListener.class) - return getHierarchyListeners(); + return (T[]) getHierarchyListeners(); if (listenerType == HierarchyBoundsListener.class) - return getHierarchyBoundsListeners(); + return (T[]) getHierarchyBoundsListeners(); if (listenerType == KeyListener.class) - return getKeyListeners(); + return (T[]) getKeyListeners(); if (listenerType == MouseListener.class) - return getMouseListeners(); + return (T[]) getMouseListeners(); if (listenerType == MouseMotionListener.class) - return getMouseMotionListeners(); + return (T[]) getMouseMotionListeners(); if (listenerType == MouseWheelListener.class) - return getMouseWheelListeners(); + return (T[]) getMouseWheelListeners(); if (listenerType == InputMethodListener.class) - return getInputMethodListeners(); + return (T[]) getInputMethodListeners(); if (listenerType == PropertyChangeListener.class) - return getPropertyChangeListeners(); - return (EventListener[]) Array.newInstance(listenerType, 0); + return (T[]) getPropertyChangeListeners(); + return (T[]) Array.newInstance(listenerType, 0); } /** Modified: trunk/core/src/classpath/java/java/awt/MenuBar.java =================================================================== --- trunk/core/src/classpath/java/java/awt/MenuBar.java 2007-01-28 20:52:02 UTC (rev 3096) +++ trunk/core/src/classpath/java/java/awt/MenuBar.java 2007-01-28 21:36:49 UTC (rev 3097) @@ -272,7 +272,7 @@ * * @return a list of all shortcuts for the menus in this menu bar */ - public synchronized Enumeration shortcuts() + public synchronized Enumeration<MenuShortcut> shortcuts() { Vector shortcuts = new Vector(); Enumeration e = menus.elements(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ls...@us...> - 2007-01-31 19:02:54
|
Revision: 3098 http://jnode.svn.sourceforge.net/jnode/?rev=3098&view=rev Author: lsantha Date: 2007-01-31 11:02:43 -0800 (Wed, 31 Jan 2007) Log Message: ----------- Classpath patches. Modified Paths: -------------- trunk/core/src/classpath/java/java/awt/Choice.java trunk/core/src/classpath/java/java/awt/Component.java trunk/core/src/classpath/java/java/awt/Container.java trunk/core/src/classpath/java/java/awt/Frame.java trunk/core/src/classpath/java/java/awt/Label.java trunk/core/src/classpath/java/java/awt/List.java trunk/core/src/classpath/java/java/awt/Menu.java trunk/core/src/classpath/java/java/awt/ScrollPane.java trunk/core/src/classpath/java/java/awt/ScrollPaneAdjustable.java trunk/core/src/classpath/java/java/awt/Scrollbar.java trunk/core/src/classpath/java/java/awt/Window.java Modified: trunk/core/src/classpath/java/java/awt/Choice.java =================================================================== --- trunk/core/src/classpath/java/java/awt/Choice.java 2007-01-28 21:36:49 UTC (rev 3097) +++ trunk/core/src/classpath/java/java/awt/Choice.java 2007-01-31 19:02:43 UTC (rev 3098) @@ -1,5 +1,5 @@ /* Choice.java -- Java choice button widget. - Copyright (C) 1999, 2000, 2001, 2002, 2004 Free Software Foundation, Inc. + Copyright (C) 1999, 2000, 2001, 2002, 2004, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -58,35 +58,31 @@ public class Choice extends Component implements ItemSelectable, Serializable, Accessible { - -/* - * Static Variables + /** + * The number used to generate the name returned by getName. */ + private static transient long next_choice_number; -// Serialization constant -private static final long serialVersionUID = -4075310674757313071L; + // Serialization constant + private static final long serialVersionUID = -4075310674757313071L; -/*************************************************************************/ - -/* - * Instance Variables - */ - -/** + /** * @serial A list of items for the choice box, which can be <code>null</code>. * This is package-private to avoid an accessor method. */ -Vector pItems = new Vector(); + Vector pItems = new Vector(); -/** + /** * @serial The index of the selected item in the choice box. */ -private int selectedIndex = -1; + private int selectedIndex = -1; -// Listener chain -private ItemListener item_listeners; + /** + * ItemListener chain + */ + private ItemListener item_listeners; -/** + /** * This class provides accessibility support for the * combo box. * @@ -181,19 +177,12 @@ if (i < 0 || i >= pItems.size()) return false; - Choice.this.processItemEvent(new ItemEvent(Choice.this, - ItemEvent.ITEM_STATE_CHANGED, - this, ItemEvent.SELECTED)); + Choice.this.select( i ); + return true; } } -/*************************************************************************/ - -/* - * Constructors - */ - /** * Initializes a new instance of <code>Choice</code>. * @@ -206,56 +195,41 @@ throw new HeadlessException (); } -/*************************************************************************/ - -/* - * Instance Methods - */ - -/** + /** * Returns the number of items in the list. * * @return The number of items in the list. */ -public int -getItemCount() -{ + public int getItemCount() + { return countItems (); -} + } -/*************************************************************************/ - -/** + /** * Returns the number of items in the list. * * @return The number of items in the list. * * @deprecated This method is deprecated in favor of <code>getItemCount</code>. */ -public int -countItems() -{ - return(pItems.size()); -} + public int countItems() + { + return pItems.size(); + } -/*************************************************************************/ - -/** + /** * Returns the item at the specified index in the list. * * @param index The index into the list to return the item from. * * @exception ArrayIndexOutOfBoundsException If the index is invalid. */ -public String -getItem(int index) -{ - return((String)pItems.elementAt(index)); -} + public String getItem(int index) + { + return (String)pItems.elementAt(index); + } -/*************************************************************************/ - -/** + /** * Adds the specified item to this choice box. * * @param item The item to add. @@ -264,45 +238,36 @@ * * @since 1.1 */ -public synchronized void -add(String item) -{ + public synchronized void add(String item) + { if (item == null) throw new NullPointerException ("item must be non-null"); pItems.addElement(item); - int i = pItems.size () - 1; if (peer != null) - { - ChoicePeer cp = (ChoicePeer) peer; - cp.add (item, i); - } - else if (selectedIndex == -1) - select(0); -} + ((ChoicePeer) peer).add(item, getItemCount() - 1); -/*************************************************************************/ + if (selectedIndex == -1) + select( 0 ); + } -/** + /** * Adds the specified item to this choice box. * - * This method is oboslete since Java 2 platform 1.1. Please use @see add - * instead. + * This method is oboslete since Java 2 platform 1.1. Please use + * {@link #add(String)} instead. * * @param item The item to add. * * @exception NullPointerException If the item's value is equal to null */ -public synchronized void -addItem(String item) -{ + public synchronized void addItem(String item) + { add(item); -} + } -/*************************************************************************/ - -/** Inserts an item into this Choice. Existing items are shifted + /** Inserts an item into this Choice. Existing items are shifted * upwards. If the new item is the only item, then it is selected. * If the currently selected item is shifted, then the first item is * selected. If the currently selected item is not shifted, then it @@ -313,9 +278,8 @@ * * @exception IllegalArgumentException If index is less than 0 */ -public synchronized void -insert(String item, int index) -{ + public synchronized void insert(String item, int index) + { if (index < 0) throw new IllegalArgumentException ("index may not be less then 0"); @@ -325,75 +289,61 @@ pItems.insertElementAt(item, index); if (peer != null) - { - ChoicePeer cp = (ChoicePeer) peer; - cp.add (item, index); - } - else if (selectedIndex == -1 || selectedIndex >= index) + ((ChoicePeer) peer).add (item, index); + + if (selectedIndex == -1 || selectedIndex >= index) select(0); -} + } -/*************************************************************************/ - -/** + /** * Removes the specified item from the choice box. * * @param item The item to remove. * * @exception IllegalArgumentException If the specified item doesn't exist. */ -public synchronized void -remove(String item) -{ + public synchronized void remove(String item) + { int index = pItems.indexOf(item); if (index == -1) throw new IllegalArgumentException ("item \"" + item + "\" not found in Choice"); remove(index); -} + } -/*************************************************************************/ - -/** + /** * Removes the item at the specified index from the choice box. * * @param index The index of the item to remove. * * @exception IndexOutOfBoundsException If the index is not valid. */ -public synchronized void -remove(int index) -{ - if ((index < 0) || (index > getItemCount())) - throw new IllegalArgumentException("Bad index: " + index); - + public synchronized void remove(int index) + { pItems.removeElementAt(index); if (peer != null) - { - ChoicePeer cp = (ChoicePeer) peer; - cp.remove (index); - } - else - { - if (getItemCount() == 0) + ((ChoicePeer) peer).remove( index ); + + if( getItemCount() == 0 ) selectedIndex = -1; - else if (index == selectedIndex) - select(0); - } + else + { + if( selectedIndex > index ) + selectedIndex--; + else if( selectedIndex == index ) + selectedIndex = 0; - if (selectedIndex > index) - --selectedIndex; -} + if( peer != null ) + ((ChoicePeer)peer).select( selectedIndex ); + } + } -/*************************************************************************/ - -/** + /** * Removes all of the objects from this choice box. */ -public synchronized void -removeAll() -{ + public synchronized void removeAll() + { if (getItemCount() <= 0) return; @@ -406,197 +356,159 @@ } selectedIndex = -1; -} + } -/*************************************************************************/ - -/** + /** * Returns the currently selected item, or null if no item is * selected. * * @return The currently selected item. */ -public synchronized String -getSelectedItem() -{ + public synchronized String getSelectedItem() + { return (selectedIndex == -1 ? null : ((String)pItems.elementAt(selectedIndex))); -} + } -/*************************************************************************/ - -/** + /** * Returns an array with one row containing the selected item. * * @return An array containing the selected item. */ -public synchronized Object[] -getSelectedObjects() -{ + public synchronized Object[] getSelectedObjects() + { if (selectedIndex == -1) return null; Object[] objs = new Object[1]; objs[0] = pItems.elementAt(selectedIndex); - return(objs); -} + return objs; + } -/*************************************************************************/ - -/** + /** * Returns the index of the selected item. * * @return The index of the selected item. */ -public int -getSelectedIndex() -{ - return(selectedIndex); -} + public int getSelectedIndex() + { + return selectedIndex; + } -/*************************************************************************/ - -/** + /** * Forces the item at the specified index to be selected. * * @param index The index of the row to make selected. * * @exception IllegalArgumentException If the specified index is invalid. */ -public synchronized void -select(int index) -{ + public synchronized void select(int index) + { if ((index < 0) || (index >= getItemCount())) throw new IllegalArgumentException("Bad index: " + index); - if (pItems.size() > 0) { + if( selectedIndex == index ) + return; + selectedIndex = index; - ChoicePeer cp = (ChoicePeer) peer; - if (cp != null) { - cp.select(index); + if( peer != null ) + ((ChoicePeer)peer).select( index ); } - } -} -/*************************************************************************/ - -/** + /** * Forces the named item to be selected. * * @param item The item to be selected. * * @exception IllegalArgumentException If the specified item does not exist. */ -public synchronized void -select(String item) -{ + public synchronized void select(String item) + { int index = pItems.indexOf(item); - if (index >= 0) - select(index); -} + if( index >= 0 ) + select( index ); + } -/*************************************************************************/ - -/** + /** * Creates the native peer for this object. */ -public void -addNotify() -{ + public void addNotify() + { if (peer == null) peer = getToolkit ().createChoice (this); super.addNotify (); -} + } -/*************************************************************************/ - -/** + /** * Adds the specified listener to the list of registered listeners for * this object. * * @param listener The listener to add. */ -public synchronized void -addItemListener(ItemListener listener) -{ + public synchronized void addItemListener(ItemListener listener) + { item_listeners = AWTEventMulticaster.add(item_listeners, listener); -} + } -/*************************************************************************/ - -/** + /** * Removes the specified listener from the list of registered listeners for * this object. * * @param listener The listener to remove. */ -public synchronized void -removeItemListener(ItemListener listener) -{ + public synchronized void removeItemListener(ItemListener listener) + { item_listeners = AWTEventMulticaster.remove(item_listeners, listener); -} + } -/*************************************************************************/ - -/** + /** * Processes this event by invoking <code>processItemEvent()</code> if the * event is an instance of <code>ItemEvent</code>, otherwise the event * is passed to the superclass. * * @param event The event to process. */ -protected void -processEvent(AWTEvent event) -{ + protected void processEvent(AWTEvent event) + { if (event instanceof ItemEvent) processItemEvent((ItemEvent)event); else super.processEvent(event); -} + } -void -dispatchEventImpl(AWTEvent e) -{ - if (e.id <= ItemEvent.ITEM_LAST - && e.id >= ItemEvent.ITEM_FIRST - && (item_listeners != null || (eventMask & AWTEvent.ITEM_EVENT_MASK) != 0)) - processEvent(e); - else + void dispatchEventImpl(AWTEvent e) + { super.dispatchEventImpl(e); -} -/*************************************************************************/ + if( e.id <= ItemEvent.ITEM_LAST && e.id >= ItemEvent.ITEM_FIRST && + ( item_listeners != null || + ( eventMask & AWTEvent.ITEM_EVENT_MASK ) != 0 ) ) + processEvent(e); + } -/** + /** * Processes item event by dispatching to any registered listeners. * * @param event The event to process. */ -protected void -processItemEvent(ItemEvent event) -{ + protected void processItemEvent(ItemEvent event) + { int index = pItems.indexOf((String) event.getItem()); - // Don't call back into the peers when selecting index here - if (event.getStateChange() == ItemEvent.SELECTED) - this.selectedIndex = index; if (item_listeners != null) item_listeners.itemStateChanged(event); -} + } -/*************************************************************************/ - -/** + /** * Returns a debugging string for this object. * * @return A debugging string for this object. */ -protected String -paramString() -{ - return ("selectedIndex=" + selectedIndex + "," + super.paramString()); -} + protected String paramString() + { + return "selectedIndex=" + selectedIndex + "," + super.paramString(); + } /** * Returns an array of all the objects currently registered as FooListeners @@ -608,7 +520,7 @@ * * @since 1.3 */ - public EventListener[] getListeners (Class listenerType) + public <T extends EventListener> T[] getListeners (Class<T> listenerType) { if (listenerType == ItemListener.class) return AWTEventMulticaster.getListeners (item_listeners, listenerType); @@ -639,4 +551,19 @@ accessibleContext = new AccessibleAWTChoice(); return accessibleContext; } -} // class Choice + + /** + * Generate a unique name for this <code>Choice</code>. + * + * @return A unique name for this <code>Choice</code>. + */ + String generateName() + { + return "choice" + getUniqueLong(); + } + + private static synchronized long getUniqueLong() + { + return next_choice_number++; + } +} // class Choice Modified: trunk/core/src/classpath/java/java/awt/Component.java =================================================================== --- trunk/core/src/classpath/java/java/awt/Component.java 2007-01-28 21:36:49 UTC (rev 3097) +++ trunk/core/src/classpath/java/java/awt/Component.java 2007-01-31 19:02:43 UTC (rev 3098) @@ -39,6 +39,10 @@ package java.awt; +//import gnu.java.awt.dnd.peer.gtk.GtkDropTargetContextPeer; + +import gnu.java.awt.ComponentReshapeEvent; + import java.awt.dnd.DropTarget; import java.awt.event.ActionEvent; import java.awt.event.AdjustmentEvent; @@ -70,6 +74,7 @@ import java.awt.image.VolatileImage; import java.awt.peer.ComponentPeer; import java.awt.peer.LightweightPeer; +import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; import java.io.IOException; @@ -213,6 +218,12 @@ */ static final Object treeLock = new String("AWT_TREE_LOCK"); + /** + * The default maximum size. + */ + private static final Dimension DEFAULT_MAX_SIZE + = new Dimension(Short.MAX_VALUE, Short.MAX_VALUE); + // Serialized fields from the serialization spec. /** @@ -427,6 +438,24 @@ Dimension minSize; /** + * Flag indicating whether the minimum size for the component has been set + * by a call to {@link #setMinimumSize(Dimension)} with a non-null value. + */ + boolean minSizeSet; + + /** + * The maximum size for the component. + * @see #setMaximumSize(Dimension) + */ + Dimension maxSize; + + /** + * A flag indicating whether the maximum size for the component has been set + * by a call to {@link #setMaximumSize(Dimension)} with a non-null value. + */ + boolean maxSizeSet; + + /** * Cached information on the preferred size. Should have been transient. * * @serial ignore @@ -569,6 +598,17 @@ transient BufferStrategy bufferStrategy; /** + * The number of hierarchy listeners of this container plus all of its + * children. This is needed for efficient handling of HierarchyEvents. + * These must be propagated to all child components with HierarchyListeners + * attached. To avoid traversal of the whole subtree, we keep track of + * the number of HierarchyListeners here and only walk the paths that + * actually have listeners. + */ + int numHierarchyListeners; + int numHierarchyBoundsListeners; + + /** * true if requestFocus was called on this component when its * top-level ancestor was not focusable. */ @@ -613,16 +653,19 @@ } /** - * Sets the name of this component to the specified name. + * Sets the name of this component to the specified name (this is a bound + * property with the name 'name'). * - * @param name the new name of this component + * @param name the new name (<code>null</code> permitted). * @see #getName() * @since 1.1 */ public void setName(String name) { nameExplicitlySet = true; + String old = this.name; this.name = name; + firePropertyChange("name", old, name); } /** @@ -659,6 +702,9 @@ public void setDropTarget(DropTarget dt) { this.dropTarget = dt; + + if (peer != null) + dropTarget.addNotify(peer); } /** @@ -1590,6 +1636,7 @@ * * @return the component's preferred size * @see #getMinimumSize() + * @see #setPreferredSize(Dimension) * @see LayoutManager */ public Dimension getPreferredSize() @@ -1600,7 +1647,7 @@ /** * Sets the preferred size that will be returned by * {@link #getPreferredSize()} always, and sends a - * {@link java.beans.PropertyChangeEvent} (with the property name 'preferredSize') to + * {@link PropertyChangeEvent} (with the property name 'preferredSize') to * all registered listeners. * * @param size the preferred size (<code>null</code> permitted). @@ -1662,6 +1709,39 @@ } /** + * Sets the minimum size that will be returned by {@link #getMinimumSize()} + * always, and sends a {@link PropertyChangeEvent} (with the property name + * 'minimumSize') to all registered listeners. + * + * @param size the minimum size (<code>null</code> permitted). + * + * @since 1.5 + * + * @see #getMinimumSize() + */ + public void setMinimumSize(Dimension size) + { + Dimension old = minSizeSet ? minSize : null; + minSize = size; + minSizeSet = (size != null); + firePropertyChange("minimumSize", old, size); + } + + /** + * Returns <code>true</code> if the current minimum size is not + * <code>null</code> and was set by a call to + * {@link #setMinimumSize(Dimension)}, otherwise returns <code>false</code>. + * + * @return A boolean. + * + * @since 1.5 + */ + public boolean isMinimumSizeSet() + { + return minSizeSet; + } + + /** * Returns the component's minimum size. * * @return the component's minimum size @@ -1676,10 +1756,38 @@ } /** + * The actual calculation is pulled out of minimumSize() so that + * we can call it from Container.preferredSize() and + * Component.preferredSizeImpl and avoid creating a + * new intermediate Dimension object. + * + * @return the minimum size of the component + */ + Dimension minimumSizeImpl() + { + Dimension size = minSize; + if (size == null || !(valid || minSizeSet)) + { + // We need to lock here, because the calculation depends on the + // component structure not changing. + synchronized (getTreeLock()) + { + ComponentPeer p = peer; + if (p != null) + size = peer.minimumSize(); + else + size = size(); + } + } + return size; + } + + /** * Returns the component's maximum size. * * @return the component's maximum size * @see #getMinimumSize() + * @see #setMaximumSize(Dimension) * @see #getPreferredSize() * @see LayoutManager */ @@ -1689,6 +1797,56 @@ } /** + * This is pulled out from getMaximumSize(), so that we can access it + * from Container.getMaximumSize() without creating an additional + * intermediate Dimension object. + * + * @return the maximum size of the component + */ + Dimension maximumSizeImpl() + { + Dimension size; + if (maxSizeSet) + size = maxSize; + else + size = DEFAULT_MAX_SIZE; + return size; + } + + /** + * Sets the maximum size that will be returned by {@link #getMaximumSize()} + * always, and sends a {@link PropertyChangeEvent} (with the property name + * 'maximumSize') to all registered listeners. + * + * @param size the maximum size (<code>null</code> permitted). + * + * @since 1.5 + * + * @see #getMaximumSize() + */ + public void setMaximumSize(Dimension size) + { + Dimension old = maxSizeSet ? maxSize : null; + maxSize = size; + maxSizeSet = (size != null); + firePropertyChange("maximumSize", old, size); + } + + /** + * Returns <code>true</code> if the current maximum size is not + * <code>null</code> and was set by a call to + * {@link #setMaximumSize(Dimension)}, otherwise returns <code>false</code>. + * + * @return A boolean. + * + * @since 1.5 + */ + public boolean isMaximumSizeSet() + { + return maxSizeSet; + } + + /** * Returns the preferred horizontal alignment of this component. The value * returned will be between {@link #LEFT_ALIGNMENT} and * {@link #RIGHT_ALIGNMENT}, inclusive. @@ -1873,11 +2031,9 @@ } /** - * Updates this component. This is called in response to - * <code>repaint</code>. This method fills the component with the - * background color, then sets the foreground color of the specified - * graphics context to the foreground color of this component and calls - * the <code>paint()</code> method. The coordinates of the graphics are + * Updates this component. This is called for heavyweight components in + * response to {@link #repaint()}. The default implementation simply forwards + * to {@link #paint(Graphics)}. The coordinates of the graphics are * relative to this component. Subclasses should call either * <code>super.update(g)</code> or <code>paint(g)</code>. * @@ -1885,11 +2041,6 @@ * * @see #paint(Graphics) * @see #repaint() - * - * @specnote In contrast to what the spec says, tests show that the exact - * behaviour is to clear the background on lightweight and - * top-level components only. Heavyweight components are not - * affected by this method and only call paint(). */ public void update(Graphics g) { @@ -2004,10 +2155,7 @@ } /** - * Prints this component, including all sub-components. This method is - * provided so that printing can be done in a different manner from - * painting. However, the implementation in this class simply calls the - * <code>paintAll()</code> method. + * Prints this component, including all sub-components. * * @param g the graphics context of the print device * @@ -2365,6 +2513,17 @@ } /** + * By default, no old mouse events should be ignored. + * This can be overridden by subclasses. + * + * @return false, no mouse events are ignored. + */ + static boolean ignoreOldMouseEvents() + { + return false; + } + + /** * AWT 1.0 event handler. * * This method simply calls handleEvent and returns the result. @@ -2581,6 +2740,40 @@ } /** + * Fires a HierarchyEvent or HierarchyChangeEvent on this component. + * + * @param id the event id + * @param changed the changed component + * @param parent the parent + * @param flags the event flags + */ + void fireHierarchyEvent(int id, Component changed, Container parent, + long flags) + { + boolean enabled = false; + switch (id) + { + case HierarchyEvent.HIERARCHY_CHANGED: + enabled = hierarchyListener != null + || (eventMask & AWTEvent.HIERARCHY_EVENT_MASK) != 0; + break; + case HierarchyEvent.ANCESTOR_MOVED: + case HierarchyEvent.ANCESTOR_RESIZED: + enabled = hierarchyBoundsListener != null + || (eventMask & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) != 0; + break; + default: + assert false : "Should not reach here"; + } + if (enabled) + { + HierarchyEvent ev = new HierarchyEvent(this, id, changed, parent, + flags); + dispatchEvent(ev); + } + } + + /** * Adds the specified listener to this component. This is harmless if the * listener is null, but if the listener has already been registered, it * will now be registered twice. @@ -3636,7 +3829,8 @@ * @see KeyboardFocusManager#UP_CYCLE_TRAVERSAL_KEYS * @since 1.4 */ - public void setFocusTraversalKeys(int id, Set keystrokes) + public void setFocusTraversalKeys(int id, + Set<? extends AWTKeyStroke> keystrokes) { if (keystrokes == null) { @@ -3728,14 +3922,14 @@ * * @since 1.4 */ - public Set getFocusTraversalKeys (int id) + public Set<AWTKeyStroke> getFocusTraversalKeys (int id) { if (id != KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS && id != KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS && id != KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS) throw new IllegalArgumentException(); - Set s = null; + Set<AWTKeyStroke> s = null; if (focusTraversalKeys != null) s = focusTraversalKeys[id]; @@ -4740,8 +4934,7 @@ * {@link #applyComponentOrientation(ComponentOrientation)} affects the * entire hierarchy. * - * @param o the new orientation - * @throws NullPointerException if o is null + * @param o the new orientation (<code>null</code> is accepted) * @see #getComponentOrientation() */ public void setComponentOrientation(ComponentOrientation o) @@ -4756,7 +4949,7 @@ /** * Determines the text layout orientation used by this component. * - * @return the component orientation + * @return the component orientation (this can be <code>null</code>) * @see #setComponentOrientation(ComponentOrientation) */ public ComponentOrientation getComponentOrientation() @@ -5046,7 +5239,7 @@ oldKey = Event.UP; break; default: - oldKey = (int) ((KeyEvent) e).getKeyChar(); + oldKey = ((KeyEvent) e).getKeyChar(); } translated = new Event (target, when, oldID, @@ -5089,11 +5282,10 @@ * * @param e the event to dispatch */ - void dispatchEventImpl(AWTEvent e) { - // This boolean tells us not to process focus events when the focus - // opposite component is the same as the focus component. + // Update the component's knowledge about the size. + // Important: Please look at the big comment in ComponentReshapeEvent boolean ignoreFocus = (e instanceof FocusEvent && ((FocusEvent)e).getComponent() == ((FocusEvent)e).getOppositeComponent()); @@ -5385,7 +5577,7 @@ */ public void componentHidden(ComponentEvent event) { - if (!isShowing()) + if (isShowing()) peer.hide(); } } Modified: trunk/core/src/classpath/java/java/awt/Container.java =================================================================== --- trunk/core/src/classpath/java/java/awt/Container.java 2007-01-28 21:36:49 UTC (rev 3097) +++ trunk/core/src/classpath/java/java/awt/Container.java 2007-01-31 19:02:43 UTC (rev 3098) @@ -42,7 +42,9 @@ import java.awt.event.ComponentListener; import java.awt.event.ContainerEvent; import java.awt.event.ContainerListener; +import java.awt.event.HierarchyEvent; import java.awt.event.KeyEvent; +import java.awt.event.MouseEvent; import java.awt.peer.ComponentPeer; import java.awt.peer.ContainerPeer; import java.awt.peer.LightweightPeer; @@ -68,10 +70,11 @@ * * @author original author unknown * @author Eric Blake (eb...@em...) + * @author Andrew John Hughes (gnu...@me...) * * @since 1.0 * - * @status still missing 1.4 support + * @status still missing 1.4 support, some generics from 1.5 */ public class Container extends Component { @@ -97,6 +100,13 @@ */ boolean focusCycleRoot; + /** + * Indicates if this container provides a focus traversal policy. + * + * @since 1.5 + */ + private boolean focusTraversalPolicyProvider; + int containerSerializedDataVersion; /* Anything else is non-serializable, and should be declared "transient". */ @@ -927,10 +937,10 @@ * * @since 1.3 */ - public EventListener[] getListeners(Class listenerType) + public <T extends EventListener> T[] getListeners(Class<T> listenerType) { if (listenerType == ContainerListener.class) - return getContainerListeners(); + return (T[]) getContainerListeners(); return super.getListeners(listenerType); } @@ -1549,6 +1559,42 @@ } /** + * Set to <code>true</code> if this container provides a focus traversal + * policy, <code>false</code> when the root container's focus + * traversal policy should be used. + * + * @return <code>true</code> if this container provides a focus traversal + * policy, <code>false</code> when the root container's focus + * traversal policy should be used + * + * @see #setFocusTraversalPolicyProvider(boolean) + * + * @since 1.5 + */ + public final boolean isFocusTraversalPolicyProvider() + { + return focusTraversalPolicyProvider; + } + + /** + * Set to <code>true</code> if this container provides a focus traversal + * policy, <code>false</code> when the root container's focus + * traversal policy should be used. + * + * @param b <code>true</code> if this container provides a focus traversal + * policy, <code>false</code> when the root container's focus + * traversal policy should be used + * + * @see #isFocusTraversalPolicyProvider() + * + * @since 1.5 + */ + public final void setFocusTraversalPolicyProvider(boolean b) + { + focusTraversalPolicyProvider = b; + } + + /** * Check whether this Container is a focus cycle root. * * @return true if this is a focus cycle root, false otherwise @@ -1850,6 +1896,48 @@ } } + /** + * Fires hierarchy events to the children of this container and this + * container itself. This overrides {@link Component#fireHierarchyEvent} + * in order to forward this event to all children. + */ + void fireHierarchyEvent(int id, Component changed, Container parent, + long flags) + { + // Only propagate event if there is actually a listener waiting for it. + if ((id == HierarchyEvent.HIERARCHY_CHANGED && numHierarchyListeners > 0) + || ((id == HierarchyEvent.ANCESTOR_MOVED + || id == HierarchyEvent.ANCESTOR_RESIZED) + && numHierarchyBoundsListeners > 0)) + { + for (int i = 0; i < ncomponents; i++) + component[i].fireHierarchyEvent(id, changed, parent, flags); + super.fireHierarchyEvent(id, changed, parent, flags); + } + } + + /** + * Adjusts the number of hierarchy listeners of this container and all of + * its parents. This is called by the add/remove listener methods and + * structure changing methods in Container. + * + * @param type the type, either {@link AWTEvent#HIERARCHY_BOUNDS_EVENT_MASK} + * or {@link AWTEvent#HIERARCHY_EVENT_MASK} + * @param delta the number of listeners added or removed + */ + void updateHierarchyListenerCount(long type, int delta) + { + if (type == AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) + numHierarchyBoundsListeners += delta; + else if (type == AWTEvent.HIERARCHY_EVENT_MASK) + numHierarchyListeners += delta; + else + assert false : "Should not reach here"; + + if (parent != null) + parent.updateHierarchyListenerCount(type, delta); + } + private void addNotifyContainerChildren() { synchronized (getTreeLock ()) Modified: trunk/core/src/classpath/java/java/awt/Frame.java =================================================================== --- trunk/core/src/classpath/java/java/awt/Frame.java 2007-01-28 21:36:49 UTC (rev 3097) +++ trunk/core/src/classpath/java/java/awt/Frame.java 2007-01-31 19:02:43 UTC (rev 3098) @@ -340,12 +340,15 @@ parent.remove(menuBar); menuBar.setParent(this); - if (peer != null) + // Create local copy for thread safety. + FramePeer p = (FramePeer) peer; + if (p != null) { if (menuBar != null) menuBar.addNotify(); - invalidateTree(); - ((FramePeer) peer).setMenuBar(menuBar); + if (valid) + invalidate(); + p.setMenuBar(menuBar); } } } @@ -485,8 +488,11 @@ private static void noteFrame(Frame f) { + synchronized (weakFrames) + { weakFrames.add(new WeakReference(f)); } + } public static Frame[] getFrames() { @@ -533,8 +539,7 @@ public int getState() { - // FIXME: State might have changed in the peer... Must check. - return (state & ICONIFIED) != 0 ? ICONIFIED : NORMAL; + return (getExtendedState() & ICONIFIED) != 0 ? ICONIFIED : NORMAL; } /** @@ -542,14 +547,23 @@ */ public void setExtendedState(int state) { + if (getToolkit().isFrameStateSupported(state)) + { this.state = state; + FramePeer p = (FramePeer) peer; + if (p != null) + p.setState(state); } + } /** * @since 1.4 */ public int getExtendedState() { + FramePeer p = (FramePeer) peer; + if (p != null) + state = p.getState(); return state; } Modified: trunk/core/src/classpath/java/java/awt/Label.java =================================================================== --- trunk/core/src/classpath/java/java/awt/Label.java 2007-01-28 21:36:49 UTC (rev 3097) +++ trunk/core/src/classpath/java/java/awt/Label.java 2007-01-31 19:02:43 UTC (rev 3098) @@ -1,5 +1,6 @@ /* Label.java -- Java label widget - Copyright (C) 1999, 2000, 2002, 2004, 2005 Free Software Foundation, Inc. + Copyright (C) 1999, 2000, 2002, 2004, 2005, 2006, Free Software + Foundation, Inc. This file is part of GNU Classpath. @@ -55,66 +56,47 @@ public class Label extends Component implements Accessible { -/* - * Static Variables - */ - -/** + /** * Alignment constant aligning the text to the left of its window. */ -public static final int LEFT = 0; + public static final int LEFT = 0; -/** + /** * Alignment constant aligning the text in the center of its window. */ -public static final int CENTER = 1; + public static final int CENTER = 1; -/** + /** * Alignment constant aligning the text to the right of its window. */ -public static final int RIGHT = 2; + public static final int RIGHT = 2; -// Serialization version constant: -private static final long serialVersionUID = 3094126758329070636L; + // Serialization version constant: + private static final long serialVersionUID = 3094126758329070636L; -/*************************************************************************/ - -/* - * Instance Variables - */ - -/** + /** * @serial Indicates the alignment of the text within this label's window. * This is one of the constants in this class. The default value is * <code>LEFT</code>. */ -private int alignment; + private int alignment; -/** + /** * @serial The text displayed in the label */ -private String text; + private String text; -/*************************************************************************/ - -/* - * Constructors - */ - -/** + /** * Initializes a new instance of <code>Label</code> with no text. * * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. */ -public -Label() -{ + public Label() + { this("", LEFT); -} + } -/*************************************************************************/ - -/** + /** * Initializes a new instance of <code>Label</code> with the specified * text that is aligned to the left. * @@ -122,15 +104,12 @@ * * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. */ -public -Label(String text) -{ + public Label(String text) + { this(text, LEFT); -} + } -/*************************************************************************/ - -/** + /** * Initializes a new instance of <code>Label</code> with the specified * text and alignment. * @@ -141,80 +120,63 @@ * * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. */ -public -Label(String text, int alignment) -{ - setAlignment (alignment); - setText (text); + public Label(String text, int alignment) + { + setAlignment(alignment); + setText(text); if (GraphicsEnvironment.isHeadless()) - throw new HeadlessException (); -} + throw new HeadlessException(); + } -/*************************************************************************/ - -/* - * Instance Variables - */ - -/** + /** * Returns the constant indicating the alignment of the text in this * label. The value returned will be one of the alignment constants * from this class. * * @return The alignment of the text in the label. */ -public int -getAlignment() -{ + public int getAlignment() + { return(alignment); -} + } -/*************************************************************************/ - -/** + /** * Sets the text alignment of this label to the specified value. * * @param alignment The desired alignment for the text in this label, * which must be one of <code>LEFT</code>, <code>CENTER</code>, or * <code>RIGHT</code>. */ -public synchronized void -setAlignment(int alignment) -{ + public synchronized void setAlignment(int alignment) + { if (alignment != CENTER && alignment != LEFT && alignment != RIGHT) - throw new IllegalArgumentException ("invalid alignment: " + alignment); + throw new IllegalArgumentException("invalid alignment: " + alignment); this.alignment = alignment; if (peer != null) { LabelPeer lp = (LabelPeer) peer; - lp.setAlignment (alignment); + lp.setAlignment(alignment); + } } -} -/*************************************************************************/ - -/** + /** * Returns the text displayed in this label. * * @return The text for this label. */ -public String -getText() -{ - return(text); -} + public String getText() + { + return text; + } -/*************************************************************************/ - -/** + /** * Sets the text in this label to the specified value. * * @param text The new text for this label. */ -public synchronized void -setText(String text) -{ + public synchronized void setText(String text) + { if ((this.text == null && text != null) || (this.text != null && ! this.text.equals(text))) { @@ -223,47 +185,41 @@ if (peer != null) { LabelPeer lp = (LabelPeer) peer; - lp.setText (text); + lp.setText(text); } invalidate(); } -} + } -/*************************************************************************/ - -/** + /** * Notifies this label that it has been added to a container, causing * the peer to be created. This method is called internally by the AWT * system. */ -public void -addNotify() -{ + public void addNotify() + { if (peer == null) - peer = getToolkit ().createLabel (this); - super.addNotify (); -} + peer = getToolkit().createLabel(this); + super.addNotify(); + } -/*************************************************************************/ - -/** + /** * Returns a parameter string useful for debugging. * * @return A debugging string. */ -protected String -paramString() -{ + protected String paramString() + { return ("text=" + getText() + ",alignment=" + getAlignment() + "," + super.paramString()); -} + } -/** + /** * This class provides accessibility support for the label. */ -protected class AccessibleAWTLabel + protected class AccessibleAWTLabel extends AccessibleAWTComponent -{ + { /** * For compatability with Sun's JDK 1.4.2 rev. 5 */ @@ -299,21 +255,41 @@ return AccessibleRole.LABEL; } -} + } -/** + /** * Gets the AccessibleContext associated with this <code>Label</code>. * The context is created, if necessary. * * @return the associated context */ -public AccessibleContext getAccessibleContext() -{ + public AccessibleContext getAccessibleContext() + { /* Create the context if this is the first request */ if (accessibleContext == null) accessibleContext = new AccessibleAWTLabel(); return accessibleContext; -} + } -} // class Label + /** + * Generate a unique name for this button. + * + * @return A unique name for this button. + */ + String generateName() + { + return "label" + getUniqueLong(); + } + /** + * The number used to generate the name returned by getName. + */ + private static transient long nextLabelNumber; + + private static synchronized long getUniqueLong() + { + return nextLabelNumber++; + } + +} + Modified: trunk/core/src/classpath/java/java/awt/List.java =================================================================== --- trunk/core/src/classpath/java/java/awt/List.java 2007-01-28 21:36:49 UTC (rev 3097) +++ trunk/core/src/classpath/java/java/awt/List.java 2007-01-31 19:02:43 UTC (rev 3098) @@ -1,5 +1,5 @@ /* List.java -- A listbox widget - Copyright (C) 1999, 2002, 2004 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2004, 2006, Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -62,77 +62,63 @@ implements ItemSelectable, Accessible { -/* - * Static Variables + /** + * The number used to generate the name returned by getName. */ + private static transient long next_list_number; -// Serialization constant -private static final long serialVersionUID = -3304312411574666869L; + // Serialization constant + private static final long serialVersionUID = -3304312411574666869L; -/*************************************************************************/ + // FIXME: Need read/writeObject -/* - * Instance Variables - */ - -// FIXME: Need read/writeObject - -/** + /** * @serial The items in the list. */ -private Vector items = new Vector(); + private Vector items = new Vector(); -/** + /** * @serial Indicates whether or not multiple items can be selected * simultaneously. */ -private boolean multipleMode; + private boolean multipleMode; -/** + /** * @serial The number of rows in the list. This is set on creation * only and cannot be modified. */ -private int rows; + private int rows; -/** + /** * @serial An array of the item indices that are selected. */ -private int[] selected; + private int[] selected; -/** + /** * @serial An index value used by <code>makeVisible()</code> and * <code>getVisibleIndex</code>. */ -private int visibleIndex; + private int visibleIndex = -1; -// The list of ItemListeners for this object. -private ItemListener item_listeners; + // The list of ItemListeners for this object. + private ItemListener item_listeners; -// The list of ActionListeners for this object. -private ActionListener action_listeners; + // The list of ActionListeners for this object. + private ActionListener action_listeners; - -/*************************************************************************/ - -/* - * Constructors - */ - -/** + /** * Initializes a new instance of <code>List</code> with no visible lines * and multi-select disabled. * * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. + * @since 1.1 */ -public -List() -{ + public List() + { this(4, false); -} + } -/*************************************************************************/ - -/** + /** * Initializes a new instance of <code>List</code> with the specified * number of visible lines and multi-select disabled. * @@ -140,15 +126,12 @@ * * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. */ -public -List(int rows) -{ + public List(int rows) + { this(rows, false); -} + } -/*************************************************************************/ - -/** + /** * Initializes a new instance of <code>List</code> with the specified * number of lines and the specified multi-select setting. * @@ -158,37 +141,34 @@ * * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true. */ -public -List(int rows, boolean multipleMode) -{ + public List(int rows, boolean multipleMode) + { + if (rows == 0) + this.rows = 4; + else this.rows = rows; + this.multipleMode = multipleMode; selected = new int[0]; if (GraphicsEnvironment.isHeadless()) - throw new HeadlessException (); -} + throw new HeadlessException(); -/*************************************************************************/ + } -/* - * Instance Variables - */ - -/** + /** * Returns the number of items in this list. * * @return The number of items in this list. + * + * @since 1.1 */ -public int -getItemCount() -{ - return countItems (); -} + public int getItemCount() + { + return countItems(); + } -/*************************************************************************/ - -/** + /** * Returns the number of items in this list. * * @return The number of items in this list. @@ -196,73 +176,62 @@ * @deprecated This method is deprecated in favor of * <code>getItemCount()</code> */ -public int -countItems() -{ - return items.size (); -} + public int countItems() + { + return items.size(); + } -/*************************************************************************/ - -/** + /** * Returns the complete list of items. * * @return The complete list of items in the list. + * + * @since 1.1 */ -public synchronized String[] -getItems() -{ + public synchronized String[] getItems() + { String[] l_items = new String[getItemCount()]; items.copyInto(l_items); return(l_items); -} + } -/*************************************************************************/ - -/** + /** * Returns the item at the specified index. * * @param index The index of the item to retrieve. * * @exception IndexOutOfBoundsException If the index value is not valid. */ -public String -getItem(int index) -{ - return((String)items.elementAt(index)); -} + public String getItem(int index) + { + return((String) items.elementAt(index)); + } -/*************************************************************************/ - -/** + /** * Returns the number of visible rows in the list. * * @return The number of visible rows in the list. */ -public int -getRows() -{ + public int getRows() + { return(rows); -} + } -/*************************************************************************/ - -/** + /** * Tests whether or not multi-select mode is enabled. * * @return <code>true</code> if multi-select mode is enabled, * <code>false</code> otherwise. + * + * @since 1.1 */ -public boolean -isMultipleMode() -{ + public boolean isMultipleMode() + { return allowsMultipleSelections (); -} + } -/*************************************************************************/ - -/** + /** * Tests whether or not multi-select mode is enabled. * * @return <code>true</code> if multi-select mode is enabled, @@ -271,30 +240,26 @@ * @deprecated This method is deprecated in favor of * <code>isMultipleMode()</code>. */ -public boolean -allowsMultipleSelections() -{ + public boolean allowsMultipleSelections() + { return multipleMode; -} + } -/*************************************************************************/ - -/** + /** * This method enables or disables multiple selection mode for this * list. * * @param multipleMode <code>true</code> to enable multiple mode, * <code>false</code> otherwise. + * + * @since 1.1 */ -public void -setMultipleMode(boolean multipleMode) -{ + public void setMultipleMode(boolean multipleMode) + { setMultipleSelections (multipleMode); -} + } -/*************************************************************************/ - -/** + /** * This method enables or disables multiple selection mode for this * list. * @@ -303,32 +268,29 @@ * * @deprecated */ -public void -setMultipleSelections(boolean multipleMode) -{ + public void setMultipleSelections(boolean multipleMode) + { this.multipleMode = multipleMode; - ListPeer peer = (ListPeer) getPeer (); + ListPeer peer = (ListPeer) getPeer(); if (peer != null) - peer.setMultipleMode (multipleMode); -} + peer.setMultipleMode(multipleMode); -/*************************************************************************/ + } -/** + /** * Returns the minimum size of this component. * * @return The minimum size of this component. + * + * @since 1.1 */ -public Dimension -getMinimumSize() -{ - return getMinimumSize (getRows ()); -} + public Dimension getMinimumSize() + { + return getMinimumSize(getRows()); + } -/*************************************************************************/ - -/** + /** * Returns the minimum size of this component. * * @return The minimum size of this component. @@ -336,31 +298,27 @@ * @deprecated This method is deprecated in favor of * <code>getMinimumSize</code>. */ -public Dimension -minimumSize() -{ - return minimumSize (getRows ()); -} + public Dimension minimumSize() + { + return minimumSize(getRows()); + } -/*************************************************************************/ - -/** + /** * Returns the minimum size of this component assuming it had the specified * number of rows. * * @param rows The number of rows to size for. * * @return The minimum size of this component. + * + * @since 1.1 */ -public Dimension -getMinimumSize(int rows) -{ - return minimumSize (rows); -} + public Dimension getMinimumSize(int rows) + { + return minimumSize(rows); + } -/*************************************************************************/ - -/** + /** * Returns the minimum size of this component assuming it had the specified * number of rows. * @@ -371,32 +329,28 @@ * @deprecated This method is deprecated in favor of * <code>getMinimumSize(int)</code>> */ -public Dimension -minimumSize(int rows) -{ - ListPeer peer = (ListPeer) getPeer (); + public Dimension minimumSize(int rows) + { + ListPeer peer = (ListPeer) getPeer(); if (peer != null) - return peer.minimumSize (rows); + return peer.minimumSize(rows); else - return new Dimension (0, 0); -} + return new Dimension(0, 0); + } -/*************************************************************************/ - -/** + /** * Returns the preferred size of this component. * * @return The preferred size of this component. + * + * @since 1.1 */ -public Dimension -getPreferredSize() -{ - return getPreferredSize (getRows ()); -} + public Dimension getPreferredSize() + { + return getPreferredSize(getRows()); + } -/*************************************************************************/ - -/** + /** * Returns the preferred size of this component. * * @return The preferred size of this component. @@ -404,31 +358,27 @@ * @deprecated This method is deprecated in favor of * <code>getPreferredSize</code>. */ -public Dimension -preferredSize() -{ - return preferredSize (getRows ()); -} + public Dimension preferredSize() + { + return preferredSize(getRows()); + } -/*************************************************************************/ - -/** + /** * Returns the preferred size of this component assuming it had the specified * number of rows. * * @param rows The number of rows to size for. * * @return The preferred size of this component. + * + * @since 1.1 */ -public Dimension -getPreferredSize(int rows) -{ - return preferredSize (rows); -} + public Dimension getPreferredSize(int rows) + { + return preferredSize(rows); + } -/*************************************************************************/ - -/** + /** * Returns the preferred size of this component assuming it had the specified * number of rows. * @@ -439,47 +389,40 @@ * @deprecated This method is deprecated in favor of * <code>getPreferredSize(int)</code>> */ -public Dimension -preferredSize(int rows) -{ - ListPeer peer = (ListPeer) getPeer (); + public Dimension preferredSize(int rows) + { + ListPeer peer = (ListPeer)getPeer(); if (peer != null) - return peer.preferredSize (rows); + return peer.preferredSize(rows); else return getSize(); -} + } -/*************************************************************************/ - -/** + /** * This method adds the specified item to the end of the list. * * @param item The item to add to the list. + * + * @since 1.1 */ -public void -add(String item) -{ + public void add(String item) + { add (item, -1); -} + } -/*************************************************************************/ - -/** + /** * This method adds the specified item to the end of the list. * * @param item The item to add to the list. * * @deprecated Use add() instead. */ -public void -addItem(String item) -{ - addItem (item, -1); -} + public void addItem(String item) + { + addItem(item, -1); + } -/*************************************************************************/ - -/** + /** * Adds the specified item to the specified location in the list. * If the desired index is -1 or greater than the number of rows * in the list, then the item is added to the end. @@ -487,16 +430,15 @@ * @param item The item to add to the list. * @param index The location in the list to add the item, or -1 to add * to the end. + * + * @since 1.1 */ -public void -add(String item, int index) -{ - addItem (item, index); -} + public void add(String item, int index) + { + addItem(item, index); + } -/*************************************************************************/ - -/** + /** * Adds the specified item to the specified location in the list. * If the desired index is -1 or greater than the number of rows * in the list, then the item is added to the end. @@ -507,22 +449,25 @@ * * @deprecated Use add() instead. */ -public void -addItem(String item, int index) -{ + public void addItem(String item, int index) + { + if (item == null) + item = ""; + + if (index < -1) + index = -1; + if ((index == -1) || (index >= items.size ())) items.addElement (item); else - items.insertElementAt (item, index); + items.insertElementAt(item, index); - ListPeer peer = (ListPeer) getPeer (); + ListPeer peer = (ListPeer) getPeer(); if (peer != null) peer.add (item, index); -} + } -/*************************************************************************/ - -/** + /** * Deletes the item at the specified index. * * @param index The index of the item to delete. @@ -531,34 +476,40 @@ * * @deprecated */ -public void -delItem(int index) throws IllegalArgumentException -{ + public void delItem(int index) throws IllegalArgumentException + { + boolean selected = false; + if (isSelected(index)) + { + selected = true; + deselect(index); + } + items.removeElementAt (index); - ListPeer peer = (ListPeer) getPeer (); + if (selected) + select(index); + + ListPeer peer = (ListPeer) getPeer(); if (peer != null) peer.delItems (index, index); -} + } -/*************************************************************************/ - -/** + /** * Deletes the item at the specified index. * * @param index The index of the item to delete. * * @exception IllegalArgumentException If the index is not valid + * + * @since 1.1 */ -public void -remove(int index) throws IllegalArgumentException -{ - delItem (index); -} + public void remove(int index) throws IllegalArgumentException + { + delItem(index); + } -/*************************************************************************/ - -/** + /** * Deletes all items in the specified index range. * * @param start The beginning index of the range to delete. @@ -568,18 +519,9 @@ * * @deprecated This method is deprecated for some unknown reason. */ -public synchronized void -delItems(int start, int end) throws IllegalArgumentException -{ - if ((start < 0) || (start >= items.size())) - throw new IllegalArgumentException("Bad list start index value: " + start); - - if ((start < 0) || (start >= items.size())) - throw new IllegalArgumentException("Bad list start index value: " + start); - - if (start > end) - throw new IllegalArgumentException("Start is greater than end!"); - + public synchronized void delItems(int start, int end) + throws IllegalArgumentException + { // We must run the loop in reverse direction. for (int i = end; i >= start; --i) items.removeElementAt (i); @@ -588,70 +530,65 @@ ListPeer l = (ListPeer) peer; l.delItems (start, end); } -} + } -/*************************************************************************/ - -/** + /** * Deletes the first occurrence of the specified item from the list. * * @param item The item to delete. * * @exception IllegalArgumentException If the specified item does not exist. + * + * @since 1.1 */ -public synchronized void -remove(String item) throws IllegalArgumentException -{ + public synchronized void remove(String item) throws IllegalArgumentException + { int index = items.indexOf(item); if (index == -1) throw new IllegalArgumentException("List element to delete not found"); remove(index); -} + } -/*************************************************************************/ - -/** + /** * Deletes all of the items from the list. + * + * @since 1.1 */ -public synchronized void -removeAll() -{ - clear (); -} + public synchronized void removeAll() + { + clear(); + } -/*************************************************************************/ - -/** + /** * Deletes all of the items from the list. * * @deprecated This method is deprecated in favor of <code>removeAll()</code>. */ -public... [truncated message content] |
From: <ls...@us...> - 2007-01-31 20:25:36
|
Revision: 3099 http://jnode.svn.sourceforge.net/jnode/?rev=3099&view=rev Author: lsantha Date: 2007-01-31 12:25:09 -0800 (Wed, 31 Jan 2007) Log Message: ----------- Classpath patches. Modified Paths: -------------- trunk/core/src/classpath/java/java/awt/Component.java trunk/core/src/classpath/java/java/awt/Container.java trunk/core/src/classpath/java/java/awt/ContainerOrderFocusTraversalPolicy.java trunk/core/src/classpath/java/java/awt/EventDispatchThread.java trunk/core/src/classpath/java/java/awt/EventQueue.java trunk/core/src/classpath/java/java/awt/LightweightDispatcher.java trunk/core/src/classpath/java/java/awt/Window.java Modified: trunk/core/src/classpath/java/java/awt/Component.java =================================================================== --- trunk/core/src/classpath/java/java/awt/Component.java 2007-01-31 19:02:43 UTC (rev 3098) +++ trunk/core/src/classpath/java/java/awt/Component.java 2007-01-31 20:25:09 UTC (rev 3099) @@ -1486,7 +1486,40 @@ } } - /** + /** + * Sends notification to interested listeners about resizing and/or moving + * the component. If this component has interested + * component listeners or the corresponding event mask enabled, then + * COMPONENT_MOVED and/or COMPONENT_RESIZED events are posted to the event + * queue. + * + * @param resized true if the component has been resized, false otherwise + * @param moved true if the component has been moved, false otherwise + */ + void notifyReshape(boolean resized, boolean moved) + { + // Only post an event if this component actually has a listener + // or has this event explicitly enabled. + if (componentListener != null + || (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0) + { + // Fire component event on this component. + if (moved) + { + ComponentEvent ce = new ComponentEvent(this, + ComponentEvent.COMPONENT_MOVED); + getToolkit().getSystemEventQueue().postEvent(ce); + } + if (resized) + { + ComponentEvent ce = new ComponentEvent(this, + ComponentEvent.COMPONENT_RESIZED); + getToolkit().getSystemEventQueue().postEvent(ce); + } + } + } + + /** * Sets the bounding rectangle for this component to the specified * rectangle. Note that these coordinates are relative to the parent, not * to the screen. Modified: trunk/core/src/classpath/java/java/awt/Container.java =================================================================== --- trunk/core/src/classpath/java/java/awt/Container.java 2007-01-31 19:02:43 UTC (rev 3098) +++ trunk/core/src/classpath/java/java/awt/Container.java 2007-01-31 20:25:09 UTC (rev 3099) @@ -1808,6 +1808,11 @@ } } + /** + * Overridden to dispatch events to lightweight descendents. + * + * @param e the event to dispatch. + */ void dispatchEventImpl(AWTEvent e) { boolean dispatched = @@ -1825,6 +1830,19 @@ } /** + * This is called by the lightweight dispatcher to avoid recursivly + * calling into the lightweight dispatcher. + * + * @param e the event to dispatch + * + * @see LightweightDispatcher#redispatch(MouseEvent, Component, int) + */ + void dispatchNoLightweight(AWTEvent e) + { + super.dispatchEventImpl(e); + } + + /** * Tests if this container has an interest in the given event id. * * @param eventId The event id to check. @@ -1938,6 +1956,43 @@ parent.updateHierarchyListenerCount(type, delta); } + /** + * Notifies interested listeners about resizing or moving the container. + * This performs the super behaviour (sending component events) and + * additionally notifies any hierarchy bounds listeners on child components. + * + * @param resized true if the component has been resized, false otherwise + * @param moved true if the component has been moved, false otherwise + */ + void notifyReshape(boolean resized, boolean moved) + { + // Notify component listeners. + super.notifyReshape(resized, moved); + + if (ncomponents > 0) + { + // Notify hierarchy bounds listeners. + if (resized) + { + for (int i = 0; i < getComponentCount(); i++) + { + Component child = getComponent(i); + child.fireHierarchyEvent(HierarchyEvent.ANCESTOR_RESIZED, + this, parent, 0); + } + } + if (moved) + { + for (int i = 0; i < getComponentCount(); i++) + { + Component child = getComponent(i); + child.fireHierarchyEvent(HierarchyEvent.ANCESTOR_MOVED, + this, parent, 0); + } + } + } + } + private void addNotifyContainerChildren() { synchronized (getTreeLock ()) Modified: trunk/core/src/classpath/java/java/awt/ContainerOrderFocusTraversalPolicy.java =================================================================== --- trunk/core/src/classpath/java/java/awt/ContainerOrderFocusTraversalPolicy.java 2007-01-31 19:02:43 UTC (rev 3098) +++ trunk/core/src/classpath/java/java/awt/ContainerOrderFocusTraversalPolicy.java 2007-01-31 20:25:09 UTC (rev 3099) @@ -346,29 +346,31 @@ || !root.isDisplayable ()) return null; - if (root.visible && root.isDisplayable() && root.enabled - && root.focusable) + if (accept(root)) return root; - Component[] componentArray = root.getComponents (); - - for (int i = 0; i < componentArray.length; i++) + int ncomponents = root.getComponentCount(); + for (int i = 0; i < ncomponents; i++) { - Component component = componentArray [i]; - - if (component.visible && component.isDisplayable() && component.enabled - && component.focusable) - return component; - - if (component instanceof Container) + Component component = root.getComponent(i); + if (component instanceof Container + && !((Container) component).isFocusCycleRoot()) { - Component result = getFirstComponent ((Container) component); - - if (result != null - && (result.visible && result.isDisplayable() && result.enabled && result.focusable)) - return result; + Component first = null; + Container cont = (Container) component; + if (cont.isFocusTraversalPolicyProvider()) + { + FocusTraversalPolicy childPol = cont.getFocusTraversalPolicy(); + first = childPol.getFirstComponent(cont); } + else + first = getFirstComponent(cont); + if (first != null) + return first; } + else if (accept(component)) + return component; + } return null; } Modified: trunk/core/src/classpath/java/java/awt/EventDispatchThread.java =================================================================== --- trunk/core/src/classpath/java/java/awt/EventDispatchThread.java 2007-01-31 19:02:43 UTC (rev 3098) +++ trunk/core/src/classpath/java/java/awt/EventDispatchThread.java 2007-01-31 20:25:09 UTC (rev 3099) @@ -73,6 +73,9 @@ // Ignore and use default. } setPriority(priority); + + // Make sure that an event dispatch thread is never a daemon thread. + setDaemon(false); } public void run() Modified: trunk/core/src/classpath/java/java/awt/EventQueue.java =================================================================== --- trunk/core/src/classpath/java/java/awt/EventQueue.java 2007-01-31 19:02:43 UTC (rev 3098) +++ trunk/core/src/classpath/java/java/awt/EventQueue.java 2007-01-31 20:25:09 UTC (rev 3099) @@ -39,6 +39,7 @@ package java.awt; import gnu.java.awt.LowPriorityEvent; +import gnu.java.awt.peer.NativeEventLoopRunningEvent; import java.awt.event.ActionEvent; import java.awt.event.InputEvent; @@ -114,6 +115,7 @@ private long lastWhen = System.currentTimeMillis(); private EventDispatchThread dispatchThread = new EventDispatchThread(this); + private boolean nativeLoopRunning = false; private boolean shutdown = false; // @vm-specific allow JNode access from VMAwtAPI @@ -130,17 +132,19 @@ // This is the exact self-shutdown condition specified in J2SE: // http://java.sun.com/j2se/1.4.2/docs/api/java/awt/doc-files/AWTThreadIssues.html - - // FIXME: check somewhere that the native queue is empty - if (peekEvent() == null) - { - Frame[] frames = Frame.getFrames(); - for (int i = 0; i < frames.length; ++i) - if (frames[i].isDisplayable()) - return false; - return true; - } + + if (nativeLoopRunning) return false; + + if (peekEvent() != null) + return false; + + Frame[] frames = Frame.getFrames(); + for (int i = 0; i < frames.length; ++i) + if (frames[i].isDisplayable()) + return false; + + return true; } /** @@ -169,22 +173,26 @@ return next.getNextEvent(); AWTEvent res = getNextEventImpl(true); + while (res == null) { - // We are not allowed to return null from this method, yet it - // is possible that we actually have run out of native events - // in the enclosing while() loop, and none of the native events - // happened to cause AWT events. We therefore ought to check - // the isShutdown() condition here, before risking a "native - // wait". If we check it before entering this function we may - // wait forever for events after the shutdown condition has - // arisen. + if (isShutdown()) + { + // Explicitly set dispathThread to null. If we don't do + // this, there is a race condition where dispatchThread + // can be != null even after the event dispatch thread has + // stopped running. If that happens, then the + // dispatchThread == null check in postEventImpl will + // fail, and a new event dispatch thread will not be + // created, leaving invokeAndWaits waiting indefinitely. + dispatchThread = null; - if (isShutdown()) + // Interrupt the event dispatch thread. throw new InterruptedException(); + } wait(); - res = getNextEventImpl(true); + res = getNextEventImpl(true); } return res; @@ -298,6 +306,12 @@ priority = LOW_PRIORITY; // TODO: Maybe let Swing RepaintManager events also be processed with // low priority. + if (evt instanceof NativeEventLoopRunningEvent) + { + nativeLoopRunning = ((NativeEventLoopRunningEvent) evt).isRunning(); + notify(); + return; + } postEventImpl(evt, priority); } Modified: trunk/core/src/classpath/java/java/awt/LightweightDispatcher.java =================================================================== --- trunk/core/src/classpath/java/java/awt/LightweightDispatcher.java 2007-01-31 19:02:43 UTC (rev 3098) +++ trunk/core/src/classpath/java/java/awt/LightweightDispatcher.java 2007-01-31 20:25:09 UTC (rev 3099) @@ -38,7 +38,10 @@ package java.awt; +import java.awt.event.InputEvent; import java.awt.event.MouseEvent; +import java.awt.event.MouseWheelEvent; +import java.awt.peer.LightweightPeer; import java.util.WeakHashMap; /** @@ -49,7 +52,7 @@ * * @author Roman Kennke (ke...@ai...) */ -class LightweightDispatcher +final class LightweightDispatcher { /** @@ -80,6 +83,11 @@ private Component lastTarget; /** + * The current mouseEventTarget. + */ + private Component mouseEventTarget; + + /** * Returns an instance of LightweightDispatcher for the current thread's * thread group. * @@ -113,7 +121,7 @@ * * @param event the event */ - public boolean dispatchEvent(AWTEvent event) + public boolean dispatchEvent(final AWTEvent event) { if (event instanceof MouseEvent && event.getSource() instanceof Window) { @@ -336,4 +344,138 @@ p.y -= offY; return p; } + + /** + * Checks if the specified component would be interested in a mouse event. + * + * @param c the component to check + * + * @return <code>true</code> if the component has mouse listeners installed, + * <code>false</code> otherwise + */ + private boolean isMouseListening(final Component c) + { + // Note: It is important to NOT check if the component is listening + // for a specific event (for instance, mouse motion events). The event + // gets dispatched to the component if the component is listening + // for ANY mouse event, even when the component is not listening for the + // specific type of event. There are applications that depend on this + // (sadly). + return c.mouseListener != null + || c.mouseMotionListener != null + || c.mouseWheelListener != null + || (c.eventMask & AWTEvent.MOUSE_EVENT_MASK) != 0 + || (c.eventMask & AWTEvent.MOUSE_MOTION_EVENT_MASK) != 0 + || (c.eventMask & AWTEvent.MOUSE_WHEEL_EVENT_MASK) != 0; + } + + /** + * Tracks MOUSE_ENTERED and MOUSE_EXIT as well as MOUSE_MOVED and + * MOUSE_DRAGGED and creates synthetic MOUSE_ENTERED and MOUSE_EXITED for + * lightweight component.s + * + * @param target the current mouse event target + * @param ev the mouse event + */ + private void trackEnterExit(final Component target, final MouseEvent ev) + { + int id = ev.getID(); + if (target != lastTarget) + { + if (lastTarget != null) + redispatch(ev, lastTarget, MouseEvent.MOUSE_EXITED); + if (id == MouseEvent.MOUSE_EXITED) + ev.consume(); + if (target != null) + redispatch(ev, target, MouseEvent.MOUSE_ENTERED); + if (id == MouseEvent.MOUSE_ENTERED) + ev.consume(); + lastTarget = target; + } + + } + + /** + * Redispatches the specified mouse event to the specified target with the + * specified id. + * + * @param ev the mouse event + * @param target the new target + * @param id the new id + */ + private void redispatch(MouseEvent ev, Component target, int id) + { + Component source = ev.getComponent(); + if (target != null) + { + // Translate coordinates. + int x = ev.getX(); + int y = ev.getY(); + for (Component c = target; c != null && c != source; c = c.getParent()) + { + x -= c.x; + y -= c.y; + } + + // Retarget event. + MouseEvent retargeted; + if (id == MouseEvent.MOUSE_WHEEL) + { + MouseWheelEvent mwe = (MouseWheelEvent) ev; + retargeted = new MouseWheelEvent(target, id, ev.getWhen(), + ev.getModifiers() + | ev.getModifiersEx(), x, y, + ev.getClickCount(), + ev.isPopupTrigger(), + mwe.getScrollType(), + mwe.getScrollAmount(), + mwe.getWheelRotation()); + } + else + { + retargeted = new MouseEvent(target, id, ev.getWhen(), + ev.getModifiers() | ev.getModifiersEx(), + x, y, ev.getClickCount(), + ev.isPopupTrigger(), ev.getButton()); + } + + if (target == source) + ((Container) target).dispatchNoLightweight(retargeted); + else + target.dispatchEvent(retargeted); + } + } + + /** + * Determines if we are in the middle of a drag operation, that is, if + * any of the buttons is held down. + * + * @param ev the mouse event to check + * + * @return <code>true</code> if we are in the middle of a drag operation, + * <code>false</code> otherwise + */ + private boolean isDragging(MouseEvent ev) + { + int mods = ev.getModifiersEx(); + int id = ev.getID(); + if (id == MouseEvent.MOUSE_PRESSED || id == MouseEvent.MOUSE_RELEASED) + { + switch (ev.getButton()) + { + case MouseEvent.BUTTON1: + mods ^= InputEvent.BUTTON1_DOWN_MASK; + break; + case MouseEvent.BUTTON2: + mods ^= InputEvent.BUTTON2_DOWN_MASK; + break; + case MouseEvent.BUTTON3: + mods ^= InputEvent.BUTTON3_DOWN_MASK; + break; + } + } + return (mods & (InputEvent.BUTTON1_DOWN_MASK + | InputEvent.BUTTON2_DOWN_MASK + | InputEvent.BUTTON3_DOWN_MASK)) != 0; + } } Modified: trunk/core/src/classpath/java/java/awt/Window.java =================================================================== --- trunk/core/src/classpath/java/java/awt/Window.java 2007-01-31 19:02:43 UTC (rev 3098) +++ trunk/core/src/classpath/java/java/awt/Window.java 2007-01-31 20:25:09 UTC (rev 3099) @@ -329,6 +329,15 @@ if (initialFocusOwner != null) initialFocusOwner.requestFocusInWindow(); + // Post WINDOW_OPENED from here. + if (windowListener != null + || (eventMask & AWTEvent.WINDOW_EVENT_MASK) != 0) + { + WindowEvent ev = new WindowEvent(this, + WindowEvent.WINDOW_OPENED); + Toolkit tk = Toolkit.getDefaultToolkit(); + tk.getSystemEventQueue().postEvent(ev); + } shown = true; } } @@ -413,11 +422,8 @@ public void toFront() { if (peer != null) - { - WindowPeer wp = (WindowPeer) peer; - wp.toFront(); + ( (WindowPeer) peer ).toFront(); } - } /** * Returns the toolkit used to create this window. @@ -1146,6 +1152,47 @@ this.focusableWindowState = focusableWindowState; } + /** + * Check whether this Container is a focus cycle root. + * Returns always <code>true</code> as Windows are the + * root of the focus cycle. + * + * @return Always <code>true</code>. + * + * @since 1.4 + */ + public final boolean isFocusCycleRoot() + { + return true; + } + + /** + * Set whether or not this Container is the root of a focus + * traversal cycle. Windows are the root of the focus cycle + * and therefore this method does nothing. + * + * @param focusCycleRoot ignored. + * + * @since 1.4 + */ + public final void setFocusCycleRoot(boolean focusCycleRoot) + { + // calls to the method are ignored + } + + /** + * Returns the root container that owns the focus cycle where this + * component resides. Windows have no ancestors and this method + * returns always <code>null</code>. + * + * @return Always <code>null</code>. + * @since 1.4 + */ + public final Container getFocusCycleRootAncestor() + { + return null; + } + // setBoundsCallback is needed so that when a user moves a window, // the Window's location can be updated without calling the peer's // setBounds method. When a user moves a window the peer window's This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ls...@us...> - 2007-01-31 21:51:51
|
Revision: 3100 http://jnode.svn.sourceforge.net/jnode/?rev=3100&view=rev Author: lsantha Date: 2007-01-31 13:51:44 -0800 (Wed, 31 Jan 2007) Log Message: ----------- Classpath patches. Modified Paths: -------------- trunk/core/src/classpath/java/java/awt/DefaultKeyboardFocusManager.java trunk/core/src/classpath/java/java/awt/KeyboardFocusManager.java trunk/core/src/classpath/java/java/awt/TextArea.java trunk/core/src/classpath/java/java/awt/TextComponent.java trunk/core/src/classpath/java/java/awt/TextField.java trunk/core/src/classpath/java/java/awt/Toolkit.java Modified: trunk/core/src/classpath/java/java/awt/DefaultKeyboardFocusManager.java =================================================================== --- trunk/core/src/classpath/java/java/awt/DefaultKeyboardFocusManager.java 2007-01-31 20:25:09 UTC (rev 3099) +++ trunk/core/src/classpath/java/java/awt/DefaultKeyboardFocusManager.java 2007-01-31 21:51:44 UTC (rev 3100) @@ -256,6 +256,95 @@ return false; } + /** + * Handles FOCUS_GAINED events in {@link #dispatchEvent(AWTEvent)}. + * + * @param fe the focus event + */ + private boolean handleFocusGained(FocusEvent fe) + { + Component target = fe.getComponent (); + + // If old focus owner != new focus owner, notify old focus + // owner that it has lost focus. + Component oldFocusOwner = getGlobalFocusOwner(); + if (oldFocusOwner != null && oldFocusOwner != target) + { + FocusEvent lost = new FocusEvent(oldFocusOwner, + FocusEvent.FOCUS_LOST, + fe.isTemporary(), target); + oldFocusOwner.dispatchEvent(lost); + } + + setGlobalFocusOwner (target); + if (target != getGlobalFocusOwner()) + { + // Focus transfer was rejected, like when the target is not + // focusable. + dequeueKeyEvents(-1, target); + // FIXME: Restore focus somehow. + } + else + { + if (! fe.isTemporary()) + { + setGlobalPermanentFocusOwner (target); + if (target != getGlobalPermanentFocusOwner()) + { + // Focus transfer was rejected, like when the target is not + // focusable. + dequeueKeyEvents(-1, target); + // FIXME: Restore focus somehow. + } + else + { + redispatchEvent(target, fe); + } + } + } + + return true; + } + + /** + * Handles FOCUS_LOST events for {@link #dispatchEvent(AWTEvent)}. + * + * @param fe the focus event + * + * @return if the event has been handled + */ + private boolean handleFocusLost(FocusEvent fe) + { + Component currentFocus = getGlobalFocusOwner(); + if (currentFocus != fe.getOppositeComponent()) + { + setGlobalFocusOwner(null); + if (getGlobalFocusOwner() != null) + { + // TODO: Is this possible? If so, then we should try to restore + // the focus. + } + else + { + if (! fe.isTemporary()) + { + setGlobalPermanentFocusOwner(null); + if (getGlobalPermanentFocusOwner() != null) + { + // TODO: Is this possible? If so, then we should try to + // restore the focus. + } + else + { + fe.setSource(currentFocus); + redispatchEvent(currentFocus, fe); + } + } + } + } + return true; + } + private boolean enqueueKeyEvent (KeyEvent e) { Iterator i = delayRequests.iterator (); Modified: trunk/core/src/classpath/java/java/awt/KeyboardFocusManager.java =================================================================== --- trunk/core/src/classpath/java/java/awt/KeyboardFocusManager.java 2007-01-31 20:25:09 UTC (rev 3099) +++ trunk/core/src/classpath/java/java/awt/KeyboardFocusManager.java 2007-01-31 21:51:44 UTC (rev 3100) @@ -561,7 +561,9 @@ * @see #UP_CYCLE_TRAVERSAL_KEYS * @see #DOWN_CYCLE_TRAVERSAL_KEYS */ - public void setDefaultFocusTraversalKeys (int id, Set keystrokes) + public void setDefaultFocusTraversalKeys (int id, + Set<? extends AWTKeyStroke> + keystrokes) { if (id != KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS && id != KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS && @@ -633,7 +635,7 @@ * @see #UP_CYCLE_TRAVERSAL_KEYS * @see #DOWN_CYCLE_TRAVERSAL_KEYS */ - public Set getDefaultFocusTraversalKeys (int id) + public Set<AWTKeyStroke> getDefaultFocusTraversalKeys (int id) { if (id < FORWARD_TRAVERSAL_KEYS || id > DOWN_CYCLE_TRAVERSAL_KEYS) throw new IllegalArgumentException (); @@ -995,9 +997,9 @@ * @return A list of explicitly registered key event dispatchers. * @see KeyboardFocusManager#addKeyEventDispatcher(java.awt.KeyEventDispatcher) */ - protected List getKeyEventDispatchers () + protected List<KeyEventDispatcher> getKeyEventDispatchers () { - return (List) keyEventDispatchers.clone (); + return (List<KeyEventDispatcher>) keyEventDispatchers.clone (); } /** @@ -1052,9 +1054,9 @@ * @return A list of explicitly registered key event post processors. * @see KeyboardFocusManager#addKeyEventPostProcessor(java.awt.KeyEventPostProcessor) */ - protected List getKeyEventPostProcessors () + protected List<KeyEventPostProcessor> getKeyEventPostProcessors () { - return (List) keyEventPostProcessors.clone (); + return (List<KeyEventPostProcessor>) keyEventPostProcessors.clone (); } /** @@ -1436,4 +1438,48 @@ } } } + + + /** + * Maps focus requests from heavyweight to lightweight components. + */ + private static HashMap focusRequests = new HashMap(); + + /** + * Retargets focus events that come from the peer (which only know about + * heavyweight components) to go to the correct lightweight component + * if appropriate. + * + * @param ev the event to check + * + * @return the retargetted event + */ + static AWTEvent retargetFocusEvent(AWTEvent ev) + { + if (ev instanceof FocusEvent) + { + FocusEvent fe = (FocusEvent) ev; + Component target = fe.getComponent(); + if (focusRequests.containsKey(target)) + { + Component lightweight = (Component) focusRequests.get(target); + ev = new FocusEvent(lightweight, fe.id, fe.isTemporary()); + focusRequests.remove(target); } + } + return ev; + } + + /** + * Adds a lightweight focus request for a heavyweight component. + * + * @param heavyweight the heavyweight from which we will receive a focus + * event soon + * @param lightweight the lightweight that ultimately receives the request + */ + static void addLightweightFocusRequest(Component heavyweight, + Component lightweight) + { + focusRequests.put(heavyweight, lightweight); + } +} Modified: trunk/core/src/classpath/java/java/awt/TextArea.java =================================================================== --- trunk/core/src/classpath/java/java/awt/TextArea.java 2007-01-31 20:25:09 UTC (rev 3099) +++ trunk/core/src/classpath/java/java/awt/TextArea.java 2007-01-31 21:51:44 UTC (rev 3100) @@ -125,9 +125,11 @@ * the specified text. Conceptually the <code>TextArea</code> has 0 * rows and 0 columns but its initial bounds are defined by its peer * or by the container in which it is packed. Both horizontal and - * veritcal scrollbars will be displayed. + * veritcal scrollbars will be displayed. The TextArea initially contains + * the specified text. If text specified as <code>null<code>, it will + * be set to "". * - * @param text The text to display in this text area. + * @param text The text to display in this text area (<code>null</code> permitted). * * @exception HeadlessException if GraphicsEnvironment.isHeadless () is true */ @@ -156,9 +158,10 @@ * Initialize a new instance of <code>TextArea</code> that can * display the specified number of rows and columns of text, without * the need to scroll. The TextArea initially contains the - * specified text. + * specified text. If text specified as <code>null<code>, it will + * be set to "". * - * @param text The text to display in this text area. + * @param text The text to display in this text area (<code>null</code> permitted). * @param rows The number of rows in this text area. * @param columns The number of columns in this text area. * @@ -174,9 +177,10 @@ * contains the specified text. The TextArea can display the * specified number of rows and columns of text, without the need to * scroll. This constructor allows specification of the scroll bar - * display policy. + * display policy. The TextArea initially contains the specified text. + * If text specified as <code>null<code>, it will be set to "". * - * @param text The text to display in this text area. + * @param text The text to display in this text area (<code>null</code> permitted). * @param rows The number of rows in this text area. * @param columns The number of columns in this text area. * @param scrollbarVisibility The scroll bar display policy. One of @@ -192,17 +196,19 @@ if (GraphicsEnvironment.isHeadless ()) throw new HeadlessException (); - if (rows < 0 || columns < 0) - throw new IllegalArgumentException ("Bad row or column value"); + if (rows < 0) + this.rows = 0; + else + this.rows = rows; - if (scrollbarVisibility != SCROLLBARS_BOTH - && scrollbarVisibility != SCROLLBARS_VERTICAL_ONLY - && scrollbarVisibility != SCROLLBARS_HORIZONTAL_ONLY - && scrollbarVisibility != SCROLLBARS_NONE) - throw new IllegalArgumentException ("Bad scrollbar visibility value"); + if (columns < 0) + this.columns = 0; + else + this.columns = columns; - this.rows = rows; - this.columns = columns; + if (scrollbarVisibility < 0 || scrollbarVisibility > 4) + this.scrollbarVisibility = SCROLLBARS_BOTH; + else this.scrollbarVisibility = scrollbarVisibility; // TextAreas need to receive tab key events so we override the @@ -278,11 +284,7 @@ } /** - * Retrieve the minimum size for this text area, considering the - * text area's current row and column values. A text area's minimum - * size depends on the number of rows and columns of text it would - * prefer to display, and on the size of the font in which the text - * would be displayed. + * Retrieve the minimum size for this text area. * * @return The minimum size for this text field. */ @@ -292,11 +294,8 @@ } /** - * Retrieve the minimum size that this text area would have if its - * row and column values were equal to those specified. A text - * area's minimum size depends on the number of rows and columns of - * text it would prefer to display, and on the size of the font in - * which the text would be displayed. + * Retrieve the minimum size for this text area. If the minimum + * size has been set, then rows and columns are used in the calculation. * * @param rows The number of rows to use in the minimum size * calculation. @@ -311,11 +310,7 @@ } /** - * Retrieve the minimum size for this text area, considering the - * text area's current row and column values. A text area's minimum - * size depends on the number of rows and columns of text it would - * prefer to display, and on the size of the font in which the text - * would be displayed. + * Retrieve the minimum size for this text area. * * @return The minimum size for this text area. * @@ -328,11 +323,8 @@ } /** - * Retrieve the minimum size that this text area would have if its - * row and column values were equal to those specified. A text - * area's minimum size depends on the number of rows and columns of - * text it would prefer to display, and on the size of the font in - * which the text would be displayed. + * Retrieve the minimum size for this text area. If the minimum + * size has been set, then rows and columns are used in the calculation. * * @param rows The number of rows to use in the minimum size * calculation. @@ -346,21 +338,18 @@ */ public Dimension minimumSize (int rows, int columns) { + if (isMinimumSizeSet()) + return new Dimension(minSize); + TextAreaPeer peer = (TextAreaPeer) getPeer (); - - // Sun returns Dimension (0,0) in this case. if (peer == null) - return new Dimension (0, 0); + return new Dimension (getWidth(), getHeight()); return peer.getMinimumSize (rows, columns); } /** - * Retrieve the preferred size for this text area, considering the - * text area's current row and column values. A text area's preferred - * size depends on the number of rows and columns of text it would - * prefer to display, and on the size of the font in which the text - * would be displayed. + * Retrieve the preferred size for this text area. * * @return The preferred size for this text field. */ @@ -370,11 +359,8 @@ } /** - * Retrieve the preferred size that this text area would have if its - * row and column values were equal to those specified. A text - * area's preferred size depends on the number of rows and columns - * of text it would prefer to display, and on the size of the font - * in which the text would be displayed. + * Retrieve the preferred size for this text area. If the preferred + * size has been set, then rows and columns are used in the calculation. * * @param rows The number of rows to use in the preferred size * calculation. @@ -389,11 +375,7 @@ } /** - * Retrieve the preferred size for this text area, considering the - * text area's current row and column values. A text area's preferred - * size depends on the number of rows and columns of text it would - * prefer to display, and on the size of the font in which the text - * would be displayed. + * Retrieve the preferred size for this text area. * * @return The preferred size for this text field. * @@ -406,11 +388,8 @@ } /** - * Retrieve the preferred size that this text area would have if its - * row and column values were equal to those specified. A text - * area's preferred size depends on the number of rows and columns - * of text it would prefer to display, and on the size of the font - * in which the text would be displayed. + * Retrieve the preferred size for this text area. If the preferred + * size has been set, then rows and columns are used in the calculation. * * @param rows The number of rows to use in the preferred size * calculation. @@ -424,11 +403,12 @@ */ public Dimension preferredSize (int rows, int columns) { + if (isPreferredSizeSet()) + return new Dimension(prefSize); + TextAreaPeer peer = (TextAreaPeer) getPeer (); - - // Sun returns Dimension (0,0) in this case. if (peer == null) - return new Dimension (0, 0); + return new Dimension (getWidth(), getHeight()); return peer.getPreferredSize (rows, columns); } @@ -478,6 +458,8 @@ if (peer != null) peer.insert (str, peer.getText().length ()); + else + setText(getText() + str); } /** @@ -504,11 +486,20 @@ */ public void insertText (String str, int pos) { + String tmp1 = null; + String tmp2 = null; + TextAreaPeer peer = (TextAreaPeer) getPeer (); if (peer != null) peer.insert (str, pos); + else + { + tmp1 = getText().substring(0, pos); + tmp2 = getText().substring(pos, getText().length()); + setText(tmp1 + str + tmp2); } + } /** * Replace a range of characters with the specified text. The @@ -544,11 +535,20 @@ */ public void replaceText (String str, int start, int end) { - TextAreaPeer peer = (TextAreaPeer) getPeer (); + String tmp1 = null; + String tmp2 = null; + TextAreaPeer peer = (TextAreaPeer) getPeer(); + if (peer != null) - peer.replaceRange (str, start, end); + peer.replaceRange(str, start, end); + else + { + tmp1 = getText().substring(0, start); + tmp2 = getText().substring(end, getText().length()); + setText(tmp1 + str + tmp2); } + } /** * Retrieve a debugging string for this text area. Modified: trunk/core/src/classpath/java/java/awt/TextComponent.java =================================================================== --- trunk/core/src/classpath/java/java/awt/TextComponent.java 2007-01-31 20:25:09 UTC (rev 3099) +++ trunk/core/src/classpath/java/java/awt/TextComponent.java 2007-01-31 21:51:44 UTC (rev 3100) @@ -1,5 +1,5 @@ /* TextComponent.java -- Widgets for entering text - Copyright (C) 1999, 2002, 2003 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2003, 2006, Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -63,45 +63,36 @@ implements Serializable, Accessible { -/* - * Static Variables - */ + private static final long serialVersionUID = -2214773872412987419L; -// Constant for serialization -private static final long serialVersionUID = -2214773872412987419L; - -/* - * Instance Variables - */ - -/** + /** * @serial Indicates whether or not this component is editable. * This is package-private to avoid an accessor method. */ -boolean editable; + boolean editable; -/** + /** * @serial The starting position of the selected text region. * This is package-private to avoid an accessor method. */ -int selectionStart; + int selectionStart; -/** + /** * @serial The ending position of the selected text region. * This is package-private to avoid an accessor method. */ -int selectionEnd; + int selectionEnd; -/** + /** * @serial The text in the component * This is package-private to avoid an accessor method. */ -String text; + String text; -/** + /** * A list of listeners that will receive events from this object. */ -protected transient TextListener textListener; + protected transient TextListener textListener; protected class AccessibleAWTTextComponent extends AccessibleAWTComponent @@ -318,146 +309,121 @@ } -/*************************************************************************/ -/* - * Constructors - */ - -TextComponent(String text) -{ + TextComponent(String text) + { + if (text == null) + this.text = ""; + else this.text = text; + this.editable = true; -} + } -/*************************************************************************/ -/* - * Instance Methods - */ - -/** + /** * Returns the text in this component * * @return The text in this component. */ -public synchronized String -getText() -{ - TextComponentPeer tcp = (TextComponentPeer)getPeer(); + public synchronized String getText() + { + TextComponentPeer tcp = (TextComponentPeer) getPeer(); if (tcp != null) text = tcp.getText(); return(text); -} + } -/*************************************************************************/ - -/** + /** * Sets the text in this component to the specified string. * * @param text The new text for this component. */ -public synchronized void -setText(String text) -{ + public synchronized void setText(String text) + { if (text == null) text = ""; this.text = text; - TextComponentPeer tcp = (TextComponentPeer)getPeer(); + TextComponentPeer tcp = (TextComponentPeer) getPeer(); if (tcp != null) tcp.setText(text); setCaretPosition(0); -} + } -/*************************************************************************/ - -/** + /** * Returns a string that contains the text that is currently selected. * * @return The currently selected text region. */ -public synchronized String -getSelectedText() -{ + public synchronized String getSelectedText() + { String alltext = getText(); int start = getSelectionStart(); int end = getSelectionEnd(); return(alltext.substring(start, end)); -} + } -/*************************************************************************/ - -/** + /** * Returns the starting position of the selected text region. * If the text is not selected then caret position is returned. * * @return The starting position of the selected text region. */ -public synchronized int -getSelectionStart() -{ - TextComponentPeer tcp = (TextComponentPeer)getPeer(); + public synchronized int getSelectionStart() + { + TextComponentPeer tcp = (TextComponentPeer) getPeer(); if (tcp != null) selectionStart = tcp.getSelectionStart(); return(selectionStart); -} + } -/*************************************************************************/ - -/** + /** * Sets the starting position of the selected region to the * specified value. If the specified value is out of range, then it * will be silently changed to the nearest legal value. * * @param selectionStart The new start position for selected text. */ -public synchronized void -setSelectionStart(int selectionStart) -{ - select(selectionStart, getSelectionEnd()); -} + public synchronized void setSelectionStart(int selectionStart) + { + select(selectionStart, + (getSelectionEnd() < selectionStart) + ? selectionStart : getSelectionEnd()); + } -/*************************************************************************/ - -/** + /** * Returns the ending position of the selected text region. * If the text is not selected, then caret position is returned * * @return The ending position of the selected text region. */ -public synchronized int -getSelectionEnd() -{ - TextComponentPeer tcp = (TextComponentPeer)getPeer(); + public synchronized int getSelectionEnd() + { + TextComponentPeer tcp = (TextComponentPeer) getPeer(); if (tcp != null) selectionEnd = tcp.getSelectionEnd(); return(selectionEnd); -} + } -/*************************************************************************/ - -/** + /** * Sets the ending position of the selected region to the * specified value. If the specified value is out of range, then it * will be silently changed to the nearest legal value. * * @param selectionEnd The new start position for selected text. */ -public synchronized void -setSelectionEnd(int selectionEnd) -{ + public synchronized void setSelectionEnd(int selectionEnd) + { select(getSelectionStart(), selectionEnd); -} + } -/*************************************************************************/ - -/** + /** * This method sets the selected text range to the text between the * specified start and end positions. Illegal values for these * positions are silently fixed. @@ -465,9 +431,8 @@ * @param selectionStart The new start position for the selected text. * @param selectionEnd The new end position for the selected text. */ -public synchronized void -select(int selectionStart, int selectionEnd) -{ + public synchronized void select(int selectionStart, int selectionEnd) + { if (selectionStart < 0) selectionStart = 0; @@ -483,42 +448,34 @@ this.selectionStart = selectionStart; this.selectionEnd = selectionEnd; - TextComponentPeer tcp = (TextComponentPeer)getPeer(); + TextComponentPeer tcp = (TextComponentPeer) getPeer(); if (tcp != null) tcp.select(selectionStart, selectionEnd); -} + } -/*************************************************************************/ - -/** + /** * Selects all of the text in the component. */ -public synchronized void -selectAll() -{ + public synchronized void selectAll() + { select(0, getText().length()); -} + } -/*************************************************************************/ - -/** + /** * Returns the current caret position in the text. * * @return The caret position in the text. */ -public synchronized int -getCaretPosition() -{ - TextComponentPeer tcp = (TextComponentPeer)getPeer(); + public synchronized int getCaretPosition() + { + TextComponentPeer tcp = (TextComponentPeer) getPeer(); if (tcp != null) return(tcp.getCaretPosition()); else return(0); -} + } -/*************************************************************************/ - -/** + /** * Sets the caret position to the specified value. * * @param caretPosition The new caret position. @@ -528,111 +485,90 @@ * * @since 1.1 */ -public synchronized void -setCaretPosition(int caretPosition) -{ + public synchronized void setCaretPosition(int caretPosition) + { if (caretPosition < 0) - throw new IllegalArgumentException (); + throw new IllegalArgumentException(); - TextComponentPeer tcp = (TextComponentPeer)getPeer(); + TextComponentPeer tcp = (TextComponentPeer) getPeer(); if (tcp != null) tcp.setCaretPosition(caretPosition); -} + } -/*************************************************************************/ - -/** + /** * Tests whether or not this component's text can be edited. * * @return <code>true</code> if the text can be edited, <code>false</code> * otherwise. */ -public boolean -isEditable() -{ + public boolean isEditable() + { return(editable); -} + } -/*************************************************************************/ - -/** + /** * Sets whether or not this component's text can be edited. * * @param editable <code>true</code> to enable editing of the text, * <code>false</code> to disable it. */ -public synchronized void -setEditable(boolean editable) -{ + public synchronized void setEditable(boolean editable) + { this.editable = editable; - TextComponentPeer tcp = (TextComponentPeer)getPeer(); + TextComponentPeer tcp = (TextComponentPeer) getPeer(); if (tcp != null) tcp.setEditable(editable); -} + } -/*************************************************************************/ - -/** + /** * Notifies the component that it should destroy its native peer. */ -public void -removeNotify() -{ + public void removeNotify() + { super.removeNotify(); -} + } -/*************************************************************************/ - -/** + /** * Adds a new listener to the list of text listeners for this * component. * * @param listener The listener to be added. */ -public synchronized void -addTextListener(TextListener listener) -{ + public synchronized void addTextListener(TextListener listener) + { textListener = AWTEventMulticaster.add(textListener, listener); enableEvents(AWTEvent.TEXT_EVENT_MASK); -} + } -/*************************************************************************/ - -/** + /** * Removes the specified listener from the list of listeners * for this component. * * @param listener The listener to remove. */ -public synchronized void -removeTextListener(TextListener listener) -{ + public synchronized void removeTextListener(TextListener listener) + { textListener = AWTEventMulticaster.remove(textListener, listener); -} + } -/*************************************************************************/ - -/** + /** * Processes the specified event for this component. Text events are * processed by calling the <code>processTextEvent()</code> method. * All other events are passed to the superclass method. * * @param event The event to process. */ -protected void -processEvent(AWTEvent event) -{ + protected void processEvent(AWTEvent event) + { if (event instanceof TextEvent) processTextEvent((TextEvent)event); else super.processEvent(event); -} + } -/*************************************************************************/ - -/** + /** * Processes the specified text event by dispatching it to any listeners * that are registered. Note that this method will only be called * if text event's are enabled. This will be true if there are any @@ -641,16 +577,14 @@ * * @param event The text event to process. */ -protected void -processTextEvent(TextEvent event) -{ + protected void processTextEvent(TextEvent event) + { if (textListener != null) textListener.textValueChanged(event); -} + } -void -dispatchEventImpl(AWTEvent e) -{ + void dispatchEventImpl(AWTEvent e) + { if (e.id <= TextEvent.TEXT_LAST && e.id >= TextEvent.TEXT_FIRST && (textListener != null @@ -658,20 +592,17 @@ processEvent(e); else super.dispatchEventImpl(e); -} + } -/*************************************************************************/ - -/** + /** * Returns a debugging string. * * @return A debugging string. */ -protected String -paramString() -{ + protected String paramString() + { return(getClass().getName() + "(text=" + getText() + ")"); -} + } /** * Returns an array of all the objects currently registered as FooListeners @@ -681,20 +612,20 @@ * @exception ClassCastException If listenerType doesn't specify a class or * interface that implements java.util.EventListener. */ - public EventListener[] getListeners (Class listenerType) + public <T extends EventListener> T[] getListeners(Class<T> listenerType) { if (listenerType == TextListener.class) - return AWTEventMulticaster.getListeners (textListener, listenerType); + return AWTEventMulticaster.getListeners(textListener, listenerType); - return super.getListeners (listenerType); + return super.getListeners(listenerType); } /** * Returns all text listeners registered to this object. */ - public TextListener[] getTextListeners () + public TextListener[] getTextListeners() { - return (TextListener[]) getListeners (TextListener.class); + return (TextListener[]) getListeners(TextListener.class); } /** @@ -712,30 +643,35 @@ } - /*******************************/ // Provide AccessibleAWTTextComponent access to several peer functions that // aren't publicly exposed. This is package-private to avoid an accessor // method. - synchronized int - getIndexAtPoint(Point p) + synchronized int getIndexAtPoint(Point p) { - TextComponentPeer tcp = (TextComponentPeer)getPeer(); + TextComponentPeer tcp = (TextComponentPeer) getPeer(); if (tcp != null) return tcp.getIndexAtPoint(p.x, p.y); return -1; } - synchronized Rectangle - getCharacterBounds(int i) + synchronized Rectangle getCharacterBounds(int i) { - TextComponentPeer tcp = (TextComponentPeer)getPeer(); + TextComponentPeer tcp = (TextComponentPeer) getPeer(); if (tcp != null) return tcp.getCharacterBounds(i); return null; } - + /** + * All old mouse events for this component should + * be ignored. + * + * @return true to ignore all old mouse events. + */ + static boolean ignoreOldMouseEvents() + { + return true; + } - } // class TextComponent Modified: trunk/core/src/classpath/java/java/awt/TextField.java =================================================================== --- trunk/core/src/classpath/java/java/awt/TextField.java 2007-01-31 20:25:09 UTC (rev 3099) +++ trunk/core/src/classpath/java/java/awt/TextField.java 2007-01-31 21:51:44 UTC (rev 3100) @@ -1,5 +1,5 @@ /* TextField.java -- A one line text entry field - Copyright (C) 1999, 2002, 2004 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2004, 2006, Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -55,53 +55,40 @@ public class TextField extends TextComponent { -/* - * Static Variables + /** + * The number used to generate the name returned by getName. */ + private static transient long next_textfield_number; -// Serialization constant -private static final long serialVersionUID = -2966288784432217853L; -/*************************************************************************/ + private static final long serialVersionUID = -2966288784432217853L; -/* - * Instance Variables - */ -/** + /** * @serial The number of columns in the text entry field. */ -private int columns; + private int columns; -/** + /** * @serial The character that is echoed when doing protected input */ -private char echoChar; + private char echoChar; -// List of registered ActionListener's for this object. -private ActionListener action_listeners; + // List of registered ActionListener's for this object. + private ActionListener action_listeners; -/*************************************************************************/ - -/* - * Constructors - */ - -/** + /** * Initializes a new instance of <code>TextField</code> that is empty * and has one column. * * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true, */ -public -TextField() -{ - this("", 1); -} + public TextField() + { + this("", 0); + } -/*************************************************************************/ - -/** + /** * Initializes a new instance of <code>TextField</code> containing * the specified text. The number of columns will be equal to the * length of the text string. @@ -110,15 +97,12 @@ * * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true, */ -public -TextField(String text) -{ - this(text, text.length()); -} + public TextField(String text) + { + this(text, (text == null) ? 0 : text.length()); + } -/*************************************************************************/ - -/** + /** * Initializes a new instance of <code>TextField</code> that is empty * and has the specified number of columns. * @@ -126,15 +110,12 @@ * * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true, */ -public -TextField(int columns) -{ + public TextField(int columns) + { this("", columns); -} + } -/*************************************************************************/ - -/** + /** * Initializes a new instance of <code>TextField</code> with the * specified text and number of columns. * @@ -143,84 +124,69 @@ * * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true, */ -public -TextField(String text, int columns) -{ + public TextField(String text, int columns) + { super(text); + + if (columns < 0) + this.columns = 0; + else this.columns = columns; if (GraphicsEnvironment.isHeadless()) throw new HeadlessException (); -} + } -/*************************************************************************/ - -/* - * Instance Methods - */ - -/** + /** * Returns the number of columns in the field. * * @return The number of columns in the field. */ -public int -getColumns() -{ + public int getColumns() + { return(columns); -} + } -/*************************************************************************/ - -/** + /** * Sets the number of columns in this field to the specified value. * * @param columns The new number of columns in the field. * * @exception IllegalArgumentException If columns is less than zero. */ -public synchronized void -setColumns(int columns) -{ + public synchronized void setColumns(int columns) + { if (columns < 0) throw new IllegalArgumentException("Value is less than zero: " + columns); this.columns = columns; // FIXME: How to we communicate this to our peer? -} + } -/*************************************************************************/ - -/** + /** * Returns the character that is echoed to the screen when a text * field is protected (such as when a password is being entered). * * @return The echo character for this text field. */ -public char -getEchoChar() -{ + public char getEchoChar() + { return(echoChar); -} + } -/*************************************************************************/ - -/** + /** * Sets the character that is echoed when protected input such as * a password is displayed. * * @param echoChar The new echo character. */ -public void -setEchoChar(char echoChar) -{ - setEchoCharacter (echoChar); -} + public void setEchoChar(char echoChar) + { + setEchoCharacter(echoChar); + } -/*************************************************************************/ - -/** + /** * Sets the character that is echoed when protected input such as * a password is displayed. * @@ -229,64 +195,52 @@ * @deprecated This method is deprecated in favor of * <code>setEchoChar()</code> */ -public void -setEchoCharacter(char echoChar) -{ + public void setEchoCharacter(char echoChar) + { this.echoChar = echoChar; TextFieldPeer peer = (TextFieldPeer) getPeer (); if (peer != null) peer.setEchoChar (echoChar); -} + } -/*************************************************************************/ - -/** + /** * Tests whether or not this text field has an echo character set * so that characters the user type are not echoed to the screen. * * @return <code>true</code> if an echo character is set, * <code>false</code> otherwise. */ -public boolean -echoCharIsSet() -{ + public boolean echoCharIsSet() + { if (echoChar == '\u0000') return(false); else return(true); -} + } -/*************************************************************************/ - -/** + /** * Returns the minimum size for this text field. * * @return The minimum size for this text field. */ -public Dimension -getMinimumSize() -{ + public Dimension getMinimumSize() + { return getMinimumSize (getColumns ()); -} + } -/*************************************************************************/ - -/** + /** * Returns the minimum size of a text field with the specified number * of columns. * * @param columns The number of columns to get the minimum size for. */ -public Dimension -getMinimumSize(int columns) -{ - return minimumSize (columns); -} + public Dimension getMinimumSize(int columns) + { + return minimumSize(columns); + } -/*************************************************************************/ - -/** + /** * Returns the minimum size for this text field. * * @return The minimum size for this text field. @@ -294,15 +248,12 @@ * @deprecated This method is deprecated in favor of * <code>getMinimumSize()</code>. */ -public Dimension -minimumSize() -{ - return minimumSize (getColumns ()); -} + public Dimension minimumSize() + { + return minimumSize(getColumns ()); + } -/*************************************************************************/ - -/** + /** * Returns the minimum size of a text field with the specified number * of columns. * @@ -311,46 +262,40 @@ * @deprecated This method is deprecated in favor of * <code>getMinimumSize(int)</code>. */ -public Dimension -minimumSize(int columns) -{ + public Dimension minimumSize(int columns) + { + if (isMinimumSizeSet()) + return new Dimension(minSize); + TextFieldPeer peer = (TextFieldPeer) getPeer (); if (peer == null) - return null; // FIXME: What do we do if there is no peer? + return new Dimension(getWidth(), getHeight()); return peer.getMinimumSize (columns); -} + } -/*************************************************************************/ - -/** + /** * Returns the preferred size for this text field. * * @return The preferred size for this text field. */ -public Dimension -getPreferredSize() -{ - return getPreferredSize (getColumns ()); -} + public Dimension getPreferredSize() + { + return getPreferredSize(getColumns ()); + } -/*************************************************************************/ - -/** + /** * Returns the preferred size of a text field with the specified number * of columns. * * @param columns The number of columns to get the preferred size for. */ -public Dimension -getPreferredSize(int columns) -{ - return preferredSize (columns); -} + public Dimension getPreferredSize(int columns) + { + return preferredSize(columns); + } -/*************************************************************************/ - -/** + /** * Returns the preferred size for this text field. * * @return The preferred size for this text field. @@ -358,15 +303,12 @@ * @deprecated This method is deprecated in favor of * <code>getPreferredSize()</code>. */ -public Dimension -preferredSize() -{ - return preferredSize (getColumns ()); -} + public Dimension preferredSize() + { + return preferredSize(getColumns ()); + } -/*************************************************************************/ - -/** + /** * Returns the preferred size of a text field with the specified number * of columns. * @@ -375,63 +317,55 @@ * @deprecated This method is deprecated in favor of * <code>getPreferredSize(int)</code>. */ -public Dimension -preferredSize(int columns) -{ + public Dimension preferredSize(int columns) + { + if (isPreferredSizeSet()) + return new Dimension(prefSize); + TextFieldPeer peer = (TextFieldPeer) getPeer (); if (peer == null) - return new Dimension (0, 0); + return new Dimension (getWidth(), getHeight()); return peer.getPreferredSize (columns); -} + } -/*************************************************************************/ - -/** + /** * Notifies this object that it should create its native peer. */ -public void -addNotify() -{ + public void addNotify() + { if (getPeer() != null) return; setPeer((ComponentPeer)getToolkit().createTextField(this)); -} + super.addNotify(); + } -/*************************************************************************/ - -/** + /** * Addes a new listener to the list of action listeners for this * object. * * @param listener The listener to add to the list. */ -public synchronized void -addActionListener(ActionListener listener) -{ + public synchronized void addActionListener(ActionListener listener) + { action_listeners = AWTEventMulticaster.add(action_listeners, listener); enableEvents(AWTEvent.ACTION_EVENT_MASK); -} + } -/*************************************************************************/ - -/** + /** * Removes the specified listener from the list of action listeners * for this object. * * @param listener The listener to remove from the list. */ -public synchronized void -removeActionListener(ActionListener listener) -{ + public synchronized void removeActionListener(ActionListener listener) + { action_listeners = AWTEventMulticaster.remove(action_listeners, listener); -} + } -/*************************************************************************/ - -/** + /** * Processes the specified event. If the event is an instance of * <code>ActionEvent</code> then <code>processActionEvent()</code> is * called to process it, otherwise the event is sent to the @@ -439,18 +373,15 @@ * * @param event The event to process. */ -protected void -processEvent(AWTEvent event) -{ + protected void processEvent(AWTEvent event) + { if (event instanceof ActionEvent) processActionEvent((ActionEvent)event); else super.processEvent(event); -} + } -/*************************************************************************/ - -/** + /** * Processes an action event by calling any registered listeners. * Note to subclasses: This method is not called unless action events * are enabled on this object. This will be true if any listeners @@ -459,16 +390,14 @@ * * @param event The event to process. */ -protected void -processActionEvent(ActionEvent event) -{ + protected void processActionEvent(ActionEvent event) + { if (action_listeners != null) action_listeners.actionPerformed(event); -} + } -void -dispatchEventImpl(AWTEvent e) -{ + void dispatchEventImpl(AWTEvent e) + { if (e.id <= ActionEvent.ACTION_LAST && e.id >= ActionEvent.ACTION_FIRST && (action_listeners != null @@ -476,21 +405,18 @@ processEvent(e); else super.dispatchEventImpl(e); -} + } -/*************************************************************************/ - -/** + /** * Returns a debug string for this object. * * @return A debug string for this object. */ -protected String -paramString() -{ + protected String paramString() + { return(getClass().getName() + "(columns=" + getColumns() + ",echoChar=" + getEchoChar()); -} + } /** * Returns an array of all the objects currently registered as FooListeners @@ -502,7 +428,7 @@ * * @since 1.3 */ - public EventListener[] getListeners (Class listenerType) + public <T extends EventListener> T[] getListeners (Class<T> listenerType) { if (listenerType == ActionListener.class) return AWTEventMulticaster.getListeners (action_listeners, listenerType); @@ -521,6 +447,21 @@ return (ActionListener[]) getListeners (ActionListener.class); } + /** + * Generate a unique name for this <code>TextField</code>. + * + * @return A unique name for this <code>TextField</code>. + */ + String generateName() + { + return "textfield" + getUniqueLong(); + } + + private static synchronized long getUniqueLong() + { + return next_textfield_number++; + } + protected class AccessibleAWTTextField extends AccessibleAWTTextComponent { private static final long serialVersionUID = 6219164359235943158L; @@ -540,4 +481,4 @@ return new AccessibleAWTTextField(); } -} // class TextField +} Modified: trunk/core/src/classpath/java/java/awt/Toolkit.java =================================================================== --- trunk/core/src/classpath/java/java/awt/Toolkit.java 2007-01-31 20:25:09 UTC (rev 3099) +++ trunk/core/src/classpath/java/java/awt/Toolkit.java 2007-01-31 21:51:44 UTC (rev 3100) @@ -1,5 +1,5 @@ /* Toolkit.java -- AWT Toolkit superclass - Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005 + Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -39,7 +39,10 @@ package java.awt; +import gnu.classpath.SystemProperties; +import gnu.java.awt.AWTUtilities; import gnu.java.awt.peer.GLightweightPeer; +import gnu.java.awt.peer.headless.HeadlessToolkit; import java.awt.datatransfer.Clipboard; import java.awt.dnd.DragGestureEvent; @@ -50,6 +53,7 @@ import java.awt.event.AWTEventListener; import java.awt.event.AWTEventListenerProxy; import java.awt.event.KeyEvent; +import java.awt.font.TextAttribute; import java.awt.im.InputMethodHighlight; import java.awt.image.ColorModel; import java.awt.image.ImageObserver; @@ -69,6 +73,7 @@ import java.awt.peer.MenuBarPeer; import java.awt.peer.MenuItemPeer; import java.awt.peer.MenuPeer; +import java.awt.peer.MouseInfoPeer; import java.awt.peer.PanelPeer; import java.awt.peer.PopupMenuPeer; import java.awt.peer.ScrollPanePeer; @@ -76,13 +81,18 @@ import java.awt.peer.TextAreaPeer; import java.awt.peer.TextFieldPeer; import java.awt.peer.WindowPeer; -import java.awt.peer.MouseInfoPeer; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; +import java.io.File; +import java.io.FileInputStream; import java.net.URL; +import java.security.AccessController; +import java.security.PrivilegedAction; import java.util.ArrayList; +import java.util.Hashtable; import java.util.Map; import java.util.Properties; +import java.util.StringTokenizer; /** * The AWT system uses a set of native peer objects to implement its @@ -113,7 +123,8 @@ /** The toolkit properties. */ private static Properties props = new Properties(); - protected final Map desktopProperties = new Properties(); + protected final Map<String,Object> desktopProperties = + new Hashtable<String,Object>(); protected final PropertyChangeSupport desktopPropsSupport = new PropertyChangeSupport(this); @@ -541,11 +552,12 @@ * * @throws AWTError If the toolkit cannot be loaded. */ - public static Toolkit getDefaultToolkit() + public static synchronized Toolkit getDefaultToolkit() { if (toolkit != null) return toolkit; - String toolkit_name = System.getProperty("awt.toolkit", + + String toolkit_name = SystemProperties.getProperty("awt.toolkit", default_toolkit_name); try { @@ -559,6 +571,8 @@ throw new AWTError(toolkit_name + " is not a subclass of " + "java.awt.Toolkit"); toolkit = (Toolkit) obj; + + initAccessibility(); return toolkit; } catch (ThreadDeath death) @@ -567,9 +581,19 @@ } catch (Throwable t) { - AWTError e = new AWTError("Cannot load AWT toolkit: " + toolkit_name); + // Check for the headless property. + if (GraphicsEnvironment.isHeadless()) + { + toolkit = new HeadlessToolkit(); + return toolkit; + } + else + { + AWTError e = new AWTError("Cannot load AWT toolkit: " + + toolkit_name); throw (AWTError) e.initCause(t); - } + } + } } // @classpath-bugfix @@ -711,6 +735,14 @@ public PrintJob getPrintJob(Frame frame, String title, JobAttributes jobAttr, PageAttributes pageAttr) { + // FIXME: it is possible this check may be removed + // if this method, when written, always delegates to + // getPrintJob(Frame, String, Properties). + SecurityManager sm; + sm = System.getSecurityManager(); + if (sm != null) + sm.checkPrintJobAccess(); + return null; } @@ -775,12 +807,11 @@ */ public boolean getLockingKeyState(int keyCode) { - if (keyCode != KeyEvent.VK_CAPS_LOCK - && keyCode != KeyEvent.VK_NUM_LOCK - && keyCode != KeyEvent.VK_SCROLL_LOCK) - throw new IllegalArgumentException(); + if (AWTUtilities.isValidKey(keyCode)) + throw new UnsupportedOperationException + ("cannot get locking state of key code " + keyCode); - throw new UnsupportedOperationException(); + throw new IllegalArgumentException("invalid key code " + keyCode); } /** @@ -959,8 +990,8 @@ /** * @since 1.3 */ - public DragGestureRecognizer - createDragGestureRecognizer(Class recognizer, DragSource ds, + public <T extends DragGestureRecognizer> T + createDragGestureRecognizer(Class<T> recognizer, DragSource ds, Component comp, int actions, DragGestureListener l) { @@ -1247,5 +1278,140 @@ /** * @since 1.3 */ - public abstract Map mapInputMethodHighlight(InputMethodHighlight highlight); + public abstract Map<TextAttribute,?> + mapInputMethodHighlight(InputMethodHighlight highlight); + + /** + * Initializes the accessibility framework. In particular, this loads the + * properties javax.accessibility.screen_magnifier_present and + * javax.accessibility.screen_reader_present and loads + * the classes specified in javax.accessibility.assistive_technologies. + */ + private static void initAccessibility() + { + AccessController.doPrivileged + (new PrivilegedAction() + { + public Object run() + { + Properties props = new Properties(); + String sep = File.separator; + + // Try the user configuration. + try + { + File propsFile = new File(System.getProperty("user.home") + sep + + ".accessibility.properties"); + FileInputStream in = new FileInputStream(propsFile); + props.load(in); + in.close(); + } + catch (Exception ex) + { + // User configuration not present, ignore. + } + + // Try the system configuration if there was no user configuration. + if (props.size() == 0) + { + try + { + File propsFile = + new File(System.getProperty("gnu.classpath.home.url") + + sep + "accessibility.properties"); + FileInputStream in = new FileInputStream(propsFile); + props.load(in); + in.close(); + } + catch (Exception ex) + { + // System configuration not present, ignore. + } + } + + // Fetch the screen_magnifier_present property. Check systen properties + // first, then fallback to the configuration file. + String magPresent = SystemProperties.getProperty + ("javax.accessibility.screen_magnifier_present"); + if (magPresent == null) + { + magPresent = props.getProperty("screen_magnifier_present"); + if (magPresent != null) + { + SystemProperties.setProperty + ("javax.accessibility.screen_magnifier_present", magPresent); + } + } + + // Fetch the screen_reader_present property. Check systen properties + // first, then fallback to the configuration file. + String readerPresent = SystemProperties.getProperty + ("javax.accessibility.screen_reader_present"); + if (readerPresent == null) + { + readerPresent = props.getProperty("screen_reader_present"); + if (readerPresent != null) + { + SystemProperties.setProperty + ("javax.accessibility.screen_reader_present", readerPresent); + } + } + + // Fetch the list of classes to be loaded. + String classes = SystemProperties.getProperty + ("javax.accessibility.assistive_technologies"); + if (classes == null) + { + classes = props.getProperty("assistive_technologies"); + if (classes != null) + { + SystemProperties.setProperty + ("javax.accessibility.assistive_technologies", classes); + } + } + + // Try to load the assisitive_technologies classes. + if (classes != null) + { + ClassLoader cl = ClassLoader.getSystemClassLoader(); + StringTokenizer tokenizer = new StringTokenizer(classes, ","); + while (tokenizer.hasMoreTokens()) + { + String className = tokenizer.nextToken(); + try + { + Class atClass = cl.loadClass(className); + atClass.newInstance(); + } + catch (ClassNotFoundException ex) + { + AWTError err = new AWTError("Assistive Technology class not" + + " found: " + className); + err.initCause(ex); + throw err; + } + catch (InstantiationException ex) + { + AWTError err = + new AWTError("Assistive Technology class cannot be " + + "instantiated: " + className); + err.initCause(ex); + throw err; + } + catch (IllegalAccessException ex) + { + AWTError err = + new AWTError("Assistive Technology class cannot be " + + "accessed: " + className); + err.initCause(err); + throw err; + } + } + } + return null; + } + }); + + } + } // class Toolkit This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ls...@us...> - 2007-02-03 15:05:36
|
Revision: 3101 http://jnode.svn.sourceforge.net/jnode/?rev=3101&view=rev Author: lsantha Date: 2007-02-03 07:05:27 -0800 (Sat, 03 Feb 2007) Log Message: ----------- Classpath patches. Modified Paths: -------------- trunk/core/src/classpath/java/java/awt/Component.java trunk/core/src/classpath/java/java/awt/Container.java trunk/core/src/classpath/java/java/awt/Window.java Modified: trunk/core/src/classpath/java/java/awt/Component.java =================================================================== --- trunk/core/src/classpath/java/java/awt/Component.java 2007-01-31 21:51:44 UTC (rev 3100) +++ trunk/core/src/classpath/java/java/awt/Component.java 2007-02-03 15:05:27 UTC (rev 3101) @@ -581,7 +581,7 @@ transient ComponentPeer peer; /** The preferred component orientation. */ - transient ComponentOrientation orientation = ComponentOrientation.UNKNOWN; + transient ComponentOrientation componentOrientation = ComponentOrientation.UNKNOWN; /** * The associated graphics configuration. @@ -748,17 +748,24 @@ */ public Toolkit getToolkit() { - if (peer != null) + // Only heavyweight peers can handle this. + ComponentPeer p = peer; + Component comp = this; + while (p instanceof LightweightPeer) { - Toolkit tk = peer.getToolkit(); - if (tk != null) - return tk; + comp = comp.parent; + p = comp == null ? null : comp.peer; } - // Get toolkit for lightweight component. - if (parent != null) - return parent.getToolkit(); - return Toolkit.getDefaultToolkit(); + + Toolkit tk = null; + if (p != null) + { + tk = peer.getToolkit(); } + if (tk == null) + tk = Toolkit.getDefaultToolkit(); + return tk; + } /** * Tests whether or not this component is valid. A invalid component needs @@ -770,7 +777,9 @@ */ public boolean isValid() { - return valid; + // Tests show that components are invalid as long as they are not showing, even after validate() + // has been called on them. + return peer != null && valid; } /** @@ -814,10 +823,8 @@ */ public boolean isShowing() { - if (! visible || peer == null) - return false; - - return parent == null ? false : parent.isShowing(); + Component par = parent; + return visible && peer != null && (par == null || par.isShowing()); } /** @@ -856,10 +863,18 @@ */ public void enable() { - this.enabled = true; - if (peer != null) - peer.setEnabled (true); + if (! enabled) + { + // Need to lock the tree here, because the peers are involved. + synchronized (getTreeLock()) + { + enabled = true; + ComponentPeer p = peer; + if (p != null) + p.enable(); } + } + } /** * Enables or disables this component. @@ -883,10 +898,18 @@ */ public void disable() { - this.enabled = false; - if (peer != null) - peer.setEnabled (false); + if (enabled) + { + // Need to lock the tree here, because the peers are involved. + synchronized (getTreeLock()) + { + enabled = false; + ComponentPeer p = peer; + if (p != null) + p.disable(); } + } + } /** * Checks if this image is painted to an offscreen image buffer that is @@ -1130,11 +1153,36 @@ return null; } - /** + /** + * Implementation of getFont(). This is pulled out of getFont() to prevent + * client programs from overriding this. + * + * @return the font of this component + */ + private final Font getFontImpl() + { + Font f = font; + if (f == null) + { + Component p = parent; + if (p != null) + f = p.getFontImpl(); + else + { + // It is important to return null here and not some kind of default + // font, otherwise the Swing UI would not install its fonts because + // it keeps non-UIResource fonts. + f = null; + } + } + return f; + } + + /** * Sets the font for this component to the specified font. This is a bound * property. * - * @param newFont the new font for this component + * @param f the new font for this component * * @see #getFont() */ @@ -1729,11 +1777,39 @@ return prefSize; } + /** + * The actual calculation is pulled out of preferredSize() so that + * we can call it from Container.preferredSize() and avoid creating a + * new intermediate Dimension object. + * + * @return the preferredSize of the component + */ + Dimension preferredSizeImpl() + { + Dimension size = prefSize; + // Try to use a cached value. + if (size == null || !(valid || prefSizeSet)) + { + // We need to lock here, because the calculation depends on the + // component structure not changing. + synchronized (getTreeLock()) + { + ComponentPeer p = peer; + if (p != null) + size = peer.preferredSize(); + else + size = minimumSizeImpl(); + } + } + return size; + } + /** * Returns the component's minimum size. * * @return the component's minimum size * @see #getPreferredSize() + * @see #setMinimumSize(Dimension) * @see LayoutManager */ public Dimension getMinimumSize() @@ -1937,8 +2013,33 @@ */ public void validate() { + if (! valid) + { + // Synchronize on the tree here as this might change the layout + // of the hierarchy. + synchronized (getTreeLock()) + { + // Create local variables for thread safety. + ComponentPeer p = peer; + if (p != null) + { + // Possibly update the peer's font. + Font newFont = getFont(); + Font oldFont = peerFont; + // Only update when the font really changed. + if (newFont != oldFont + && (oldFont == null || ! oldFont.equals(newFont))) + { + p.setFont(newFont); + peerFont = newFont; + } + // Let the peer perform any layout. + p.layout(); + } + } valid = true; } + } /** * Invalidates this component and all of its parent components. This will @@ -1947,12 +2048,26 @@ */ public void invalidate() { + // Need to lock here, to avoid races and other ugly stuff when doing + // layout or structure changes in other threads. + synchronized (getTreeLock()) + { + // Invalidate. valid = false; - prefSize = null; + + // Throw away cached layout information. + if (! minSizeSet) minSize = null; + if (! prefSizeSet) + prefSize = null; + if (! maxSizeSet) + maxSize = null; + + // Also invalidate the parent, if it hasn't already been invalidated. if (parent != null && parent.isValid()) parent.invalidate(); } + } /** * Returns a graphics object for this component. Returns <code>null</code> @@ -1998,10 +2113,18 @@ */ public FontMetrics getFontMetrics(Font font) { - return peer == null ? getToolkit().getFontMetrics(font) - : peer.getFontMetrics(font); + ComponentPeer p = peer; + Component comp = this; + while (p instanceof LightweightPeer) + { + comp = comp.parent; + p = comp == null ? null : comp.peer; } + return p == null ? getToolkit().getFontMetrics(font) + : p.getFontMetrics(font); + } + /** * Sets the cursor for this component to the specified cursor. The cursor * is displayed when the point is contained by the component, and the @@ -2018,10 +2141,20 @@ public void setCursor(Cursor cursor) { this.cursor = cursor; - if (peer != null) - peer.setCursor(cursor); + + // Only heavyweight peers handle this. + ComponentPeer p = peer; + Component comp = this; + while (p instanceof LightweightPeer) + { + comp = comp.parent; + p = comp == null ? null : comp.peer; } + if (p != null) + p.setCursor(cursor); + } + /** * Returns the cursor for this component. If not set, this is inherited * from the parent, or from Cursor.getDefaultCursor(). @@ -2077,19 +2210,14 @@ */ public void update(Graphics g) { - // Tests show that the clearing of the background is only done in - // two cases: - // - If the component is lightweight (yes this is in contrast to the spec). - // or - // - If the component is a toplevel container. - if (isLightweight() || getParent() == null) - { - Rectangle clip = g.getClipBounds(); - if (clip == null) - g.clearRect(0, 0, width, height); - else - g.clearRect(clip.x, clip.y, clip.width, clip.height); - } + // Note 1: We used to clear the background here for lightweights and + // toplevel components. Tests show that this is not what the JDK does + // here. Note that there is some special handling and background + // clearing code in Container.update(Graphics). + + // Note 2 (for peer implementors): The JDK doesn't seem call update() for + // toplevel components, even when an UPDATE event is sent (as a result + // of repaint). paint(g); } @@ -2102,10 +2230,15 @@ */ public void paintAll(Graphics g) { - if (! visible) - return; + if (isShowing()) + { + validate(); + if (peer instanceof LightweightPeer) paint(g); + else + peer.paint(g); } + } /** * Repaint this entire component. The <code>update()</code> method @@ -2165,13 +2298,44 @@ */ public void repaint(long tm, int x, int y, int width, int height) { - if (isShowing()) + // The repaint() call has previously been delegated to + // {@link ComponentPeer.repaint()}. Testing on the JDK using some + // dummy peers show that this methods is never called. I think it makes + // sense to actually perform the tasks below here, since it's pretty + // much peer independent anyway, and makes sure only heavyweights are + // bothered by this. + ComponentPeer p = peer; + + // Let the nearest heavyweight parent handle repainting for lightweight + // components. + // We need to recursivly call repaint() on the parent here, since + // a (lightweight) parent component might have overridden repaint() + // to perform additional custom tasks. + + if (p instanceof LightweightPeer) { - ComponentPeer p = peer; - if (p != null) - p.repaint(tm, x, y, width, height); + // We perform some boundary checking to restrict the paint + // region to this component. + if (parent != null) + { + int px = this.x + Math.max(0, x); + int py = this.y + Math.max(0, y); + int pw = Math.min(this.width, width); + int ph = Math.min(this.height, height); + parent.repaint(tm, px, py, pw, ph); } } + else + { + // Now send an UPDATE event to the heavyweight component that we've found. + if (isVisible() && p != null && width > 0 && height > 0) + { + PaintEvent pe = new PaintEvent(this, PaintEvent.UPDATE, + new Rectangle(x, y, width, height)); + getToolkit().getSystemEventQueue().postEvent(pe); + } + } + } /** * Prints this component. This method is provided so that printing can be @@ -2196,6 +2360,8 @@ */ public void printAll(Graphics g) { + if( peer != null ) + peer.print( g ); paintAll(g); } @@ -2255,11 +2421,22 @@ */ public Image createImage(ImageProducer producer) { + // Only heavyweight peers can handle this. + ComponentPeer p = peer; + Component comp = this; + while (p instanceof LightweightPeer) + { + comp = comp.parent; + p = comp == null ? null : comp.peer; + } + // Sun allows producer to be null. - if (peer != null) - return peer.createImage(producer); + Image im; + if (p != null) + im = p.createImage(producer); else - return getToolkit().createImage(producer); + im = getToolkit().createImage(producer); + return im; } /** @@ -2275,11 +2452,18 @@ Image returnValue = null; if (!GraphicsEnvironment.isHeadless ()) { - if (isLightweight () && parent != null) - returnValue = parent.createImage (width, height); - else if (peer != null) - returnValue = peer.createImage (width, height); + // Only heavyweight peers can handle this. + ComponentPeer p = peer; + Component comp = this; + while (p instanceof LightweightPeer) + { + comp = comp.parent; + p = comp == null ? null : comp.peer; } + + if (p != null) + returnValue = p.createImage(width, height); + } return returnValue; } @@ -2294,11 +2478,21 @@ */ public VolatileImage createVolatileImage(int width, int height) { - if (peer != null) - return peer.createVolatileImage(width, height); - return null; + // Only heavyweight peers can handle this. + ComponentPeer p = peer; + Component comp = this; + while (p instanceof LightweightPeer) + { + comp = comp.parent; + p = comp == null ? null : comp.peer; } + VolatileImage im = null; + if (p != null) + im = p.createVolatileImage(width, height); + return im; + } + /** * Creates an image with the specified width and height for use in * double buffering. Headless environments do not support images. The image @@ -2315,11 +2509,21 @@ ImageCapabilities caps) throws AWTException { - if (peer != null) - return peer.createVolatileImage(width, height); - return null; + // Only heavyweight peers can handle this. + ComponentPeer p = peer; + Component comp = this; + while (p instanceof LightweightPeer) + { + comp = comp.parent; + p = comp == null ? null : comp.peer; } + VolatileImage im = null; + if (p != null) + im = peer.createVolatileImage(width, height); + return im; + } + /** * Prepares the specified image for rendering on this component. * @@ -2347,10 +2551,21 @@ public boolean prepareImage(Image image, int width, int height, ImageObserver observer) { - if (peer != null) - return peer.prepareImage(image, width, height, observer); + // Only heavyweight peers handle this. + ComponentPeer p = peer; + Component comp = this; + while (p instanceof LightweightPeer) + { + comp = comp.parent; + p = comp == null ? null : comp.peer; + } + + boolean retval; + if (p != null) + retval = p.prepareImage(image, width, height, observer); else - return getToolkit().prepareImage(image, width, height, observer); + retval = getToolkit().prepareImage(image, width, height, observer); + return retval; } /** @@ -2384,11 +2599,23 @@ public int checkImage(Image image, int width, int height, ImageObserver observer) { - if (peer != null) - return peer.checkImage(image, width, height, observer); - return getToolkit().checkImage(image, width, height, observer); + // Only heavyweight peers handle this. + ComponentPeer p = peer; + Component comp = this; + while (p instanceof LightweightPeer) + { + comp = comp.parent; + p = comp == null ? null : comp.peer; } + int retval; + if (p != null) + retval = p.checkImage(image, width, height, observer); + else + retval = getToolkit().checkImage(image, width, height, observer); + return retval; + } + /** * Sets whether paint messages delivered by the operating system should be * ignored. This does not affect messages from AWT, except for those @@ -4328,7 +4555,84 @@ return false; } - /** + /** + * Helper method for all 4 requestFocus variants. + * + * @param temporary indicates if the focus change is temporary + * @param focusWindow indicates if the window focus may be changed + * + * @return <code>false</code> if the request has been definitely denied, + * <code>true</code> otherwise + */ + private boolean requestFocusImpl(boolean temporary, boolean focusWindow) + { + boolean retval = false; + + // Don't try to focus non-focusable and non-visible components. + if (isFocusable() && isVisible()) + { + ComponentPeer myPeer = peer; + if (peer != null) + { + // Find Window ancestor and find out if we're showing while + // doing this. + boolean showing = true; + Component window = this; + while (! (window instanceof Window)) + { + if (! window.isVisible()) + showing = false; + window = window.parent; + } + // Don't allow focus when there is no window or the window + // is not focusable. + if (window != null && ((Window) window).isFocusableWindow() + && showing) + { + // Search for nearest heavy ancestor (including this + // component). + Component heavyweightParent = this; + while (heavyweightParent.peer instanceof LightweightPeer) + heavyweightParent = heavyweightParent.parent; + + // Don't allow focus on lightweight components without + // visible heavyweight ancestor + if (heavyweightParent != null && heavyweightParent.isVisible()) + { + // Don't allow focus when heavyweightParent has no peer. + myPeer = heavyweightParent.peer; + if (myPeer != null) + { + // Register lightweight focus request. + if (heavyweightParent != this) + { + KeyboardFocusManager + .addLightweightFocusRequest(heavyweightParent, + this); + } + + // Try to focus the component. + long time = EventQueue.getMostRecentEventTime(); + boolean success = myPeer.requestFocus(this, temporary, + focusWindow, + time); + if (! success) + { + // Dequeue key events if focus request failed. + KeyboardFocusManager kfm = + KeyboardFocusManager.getCurrentKeyboardFocusManager(); + kfm.dequeueKeyEvents(time, this); + } + retval = success; + } + } + } + } + } + return retval; + } + + /** * Transfers focus to the next component in the focus traversal * order, as though this were the current focus owner. * @@ -4972,10 +5276,9 @@ */ public void setComponentOrientation(ComponentOrientation o) { - if (o == null) - throw new NullPointerException(); - ComponentOrientation oldOrientation = orientation; - orientation = o; + + ComponentOrientation oldOrientation = componentOrientation; + componentOrientation = o; firePropertyChange("componentOrientation", oldOrientation, o); } @@ -4987,7 +5290,7 @@ */ public ComponentOrientation getComponentOrientation() { - return orientation; + return componentOrientation; } /** @@ -5137,7 +5440,7 @@ if ((mods & InputEvent.ALT_DOWN_MASK) != 0) oldMods |= Event.ALT_MASK; - if (e instanceof MouseEvent) + if (e instanceof MouseEvent && !ignoreOldMouseEvents()) { if (id == MouseEvent.MOUSE_PRESSED) oldID = Event.MOUSE_DOWN; @@ -5471,6 +5774,26 @@ } /** + * Returns <code>true</code> when this component and all of its ancestors + * are visible, <code>false</code> otherwise. + * + * @return <code>true</code> when this component and all of its ancestors + * are visible, <code>false</code> otherwise + */ + boolean isHierarchyVisible() + { + boolean visible = isVisible(); + Component comp = parent; + while (comp != null && visible) + { + comp = comp.parent; + if (comp != null) + visible = visible && comp.isVisible(); + } + return visible; + } + + /** * This method is used to implement transferFocus(). CHILD is the child * making the request. This is overridden by Container; when called for an * ordinary component there is no child and so we always return null. Modified: trunk/core/src/classpath/java/java/awt/Container.java =================================================================== --- trunk/core/src/classpath/java/java/awt/Container.java 2007-01-31 21:51:44 UTC (rev 3100) +++ trunk/core/src/classpath/java/java/awt/Container.java 2007-02-03 15:05:27 UTC (rev 3101) @@ -215,10 +215,12 @@ */ public Insets insets() { - if (peer == null) - return new Insets (0, 0, 0, 0); - - return ((ContainerPeer) peer).getInsets (); + Insets i; + if (peer == null || peer instanceof LightweightPeer) + i = new Insets (0, 0, 0, 0); + else + i = ((ContainerPeer) peer).getInsets (); + return i; } /** @@ -527,6 +529,7 @@ public void setLayout(LayoutManager mgr) { layoutMgr = mgr; + if (valid) invalidate(); } @@ -681,22 +684,26 @@ */ public Dimension preferredSize() { - synchronized(treeLock) + Dimension size = prefSize; + // Try to return cached value if possible. + if (size == null || !(prefSizeSet || valid)) { - if(valid && prefSize != null) - return new Dimension(prefSize); - LayoutManager layout = getLayout(); - if (layout != null) + // Need to lock here. + synchronized (getTreeLock()) { - Dimension layoutSize = layout.preferredLayoutSize(this); - if(valid) - prefSize = layoutSize; - return new Dimension(layoutSize); - } + LayoutManager l = layoutMgr; + if (l != null) + prefSize = l.preferredLayoutSize(this); else - return super.preferredSize (); + prefSize = super.preferredSizeImpl(); + size = prefSize; } } + if (size != null) + return new Dimension(size); + else + return size; + } /** * Returns the minimum size of this container. @@ -717,17 +724,25 @@ */ public Dimension minimumSize() { - if(valid && minSize != null) - return new Dimension(minSize); - - LayoutManager layout = getLayout(); - if (layout != null) + Dimension size = minSize; + // Try to return cached value if possible. + if (size == null || !(minSizeSet || valid)) { - minSize = layout.minimumLayoutSize (this); - return minSize; + // Need to lock here. + synchronized (getTreeLock()) + { + LayoutManager l = layoutMgr; + if (l != null) + minSize = l.minimumLayoutSize(this); + else + minSize = super.minimumSizeImpl(); + size = minSize; } + } + if (size != null) + return new Dimension(size); else - return super.minimumSize (); + return size; } /** @@ -737,18 +752,26 @@ */ public Dimension getMaximumSize() { - if (valid && maxSize != null) - return new Dimension(maxSize); - - LayoutManager layout = getLayout(); - if (layout != null && layout instanceof LayoutManager2) + Dimension size = maxSize; + // Try to return cached value if possible. + if (size == null || !(maxSizeSet || valid)) { - LayoutManager2 lm2 = (LayoutManager2) layout; - maxSize = lm2.maximumLayoutSize(this); - return maxSize; + // Need to lock here. + synchronized (getTreeLock()) + { + LayoutManager l = layoutMgr; + if (l instanceof LayoutManager2) + maxSize = ((LayoutManager2) l).maximumLayoutSize(this); + else { + maxSize = super.maximumSizeImpl(); } + size = maxSize; + } + } + if (size != null) + return new Dimension(size); else - return super.getMaximumSize(); + return size; } /** @@ -764,9 +787,12 @@ float alignmentX = 0.0F; if (layout != null && layout instanceof LayoutManager2) { + synchronized (getTreeLock()) + { LayoutManager2 lm2 = (LayoutManager2) layout; alignmentX = lm2.getLayoutAlignmentX(this); } + } else alignmentX = super.getAlignmentX(); return alignmentX; @@ -785,9 +811,12 @@ float alignmentY = 0.0F; if (layout != null && layout instanceof LayoutManager2) { + synchronized (getTreeLock()) + { LayoutManager2 lm2 = (LayoutManager2) layout; alignmentY = lm2.getLayoutAlignmentY(this); } + } else alignmentY = super.getAlignmentY(); return alignmentY; @@ -804,14 +833,11 @@ */ public void paint(Graphics g) { - if (!isShowing()) - return; - - // Visit heavyweights if the background was cleared - // for this container. - visitChildren(g, GfxPaintVisitor.INSTANCE, !backCleared); - backCleared = false; + if (isShowing()) + { + visitChildren(g, GfxPaintVisitor.INSTANCE, true); } + } /** * Updates this container. The implementation of this method in this @@ -840,15 +866,16 @@ // that overrides isLightweight() to return false, the background is // also not cleared. So we do a check on !(peer instanceof LightweightPeer) // instead. + if (isShowing()) + { ComponentPeer p = peer; - if (p != null && ! (p instanceof LightweightPeer)) + if (! (p instanceof LightweightPeer)) { g.clearRect(0, 0, getWidth(), getHeight()); - backCleared = true; } - paint(g); } + } /** * Prints this container. The implementation of this method in this @@ -872,8 +899,8 @@ */ public void paintComponents(Graphics g) { - paint(g); - visitChildren(g, GfxPaintAllVisitor.INSTANCE, true); + if (isShowing()) + visitChildren(g, GfxPaintAllVisitor.INSTANCE, false); } /** @@ -1183,9 +1210,12 @@ */ public void addNotify() { + synchronized (getTreeLock()) + { super.addNotify(); addNotifyContainerChildren(); } + } /** * Called when this container is removed from its parent container to @@ -1196,8 +1226,14 @@ { synchronized (getTreeLock ()) { - for (int i = 0; i < ncomponents; ++i) - component[i].removeNotify(); + int ncomps = ncomponents; + Component[] comps = component; + for (int i = ncomps - 1; i >= 0; --i) + { + Component comp = comps[i]; + if (comp != null) + comp.removeNotify(); + } super.removeNotify(); } } @@ -1294,7 +1330,8 @@ * * @since 1.4 */ - public void setFocusTraversalKeys(int id, Set keystrokes) + public void setFocusTraversalKeys(int id, + Set<? extends AWTKeyStroke> keystrokes) { if (id != KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS && id != KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS && @@ -1382,7 +1419,8 @@ if (focusTraversalKeys == null) focusTraversalKeys = new Set[4]; - keystrokes = Collections.unmodifiableSet (new HashSet (keystrokes)); + keystrokes = + Collections.unmodifiableSet(new HashSet<AWTKeyStroke>(keystrokes)); firePropertyChange (name, focusTraversalKeys[id], keystrokes); focusTraversalKeys[id] = keystrokes; @@ -1400,7 +1438,7 @@ * * @since 1.4 */ - public Set getFocusTraversalKeys (int id) + public Set<AWTKeyStroke> getFocusTraversalKeys (int id) { if (id != KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS && id != KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS && @@ -1641,8 +1679,17 @@ { if (orientation == null) throw new NullPointerException (); + + setComponentOrientation(orientation); + for (int i = 0; i < ncomponents; i++) + { + if (component[i] instanceof Container) + ((Container) component[i]).applyComponentOrientation(orientation); + else + component[i].setComponentOrientation(orientation); } - + } + public void addPropertyChangeListener (PropertyChangeListener listener) { // TODO: Why is this overridden? @@ -1692,6 +1739,8 @@ if (comp == this) throw new IllegalArgumentException("cannot add component to itself"); + synchronized (getTreeLock()) + { // FIXME: Implement reparenting. if ( comp.getParent() != this) throw new AssertionError("Reparenting is not implemented yet"); @@ -1712,6 +1761,7 @@ component[index] = comp; } } + } /** * Returns the Z ordering index of <code>comp</code>. If <code>comp</code> @@ -1728,10 +1778,12 @@ */ public final int getComponentZOrder(Component comp) { + synchronized (getTreeLock()) + { int index = -1; if (component != null) { - for (int i = 0; i < component.length; i++) + for (int i = 0; i < ncomponents; i++) { if (component[i] == comp) { @@ -1742,6 +1794,7 @@ } return index; } + } // Hidden helper methods. Modified: trunk/core/src/classpath/java/java/awt/Window.java =================================================================== --- trunk/core/src/classpath/java/java/awt/Window.java 2007-01-31 21:51:44 UTC (rev 3100) +++ trunk/core/src/classpath/java/java/awt/Window.java 2007-02-03 15:05:27 UTC (rev 3101) @@ -410,8 +410,9 @@ { if (peer != null) { - WindowPeer wp = (WindowPeer) peer; - wp.toBack(); + if( alwaysOnTop ) + setAlwaysOnTop( false ); + ( (WindowPeer) peer ).toBack(); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ls...@us...> - 2007-02-03 18:44:50
|
Revision: 3102 http://jnode.svn.sourceforge.net/jnode/?rev=3102&view=rev Author: lsantha Date: 2007-02-03 10:44:48 -0800 (Sat, 03 Feb 2007) Log Message: ----------- Classpath patches. Modified Paths: -------------- trunk/core/src/classpath/java/java/awt/Component.java trunk/core/src/classpath/java/java/awt/Container.java trunk/core/src/classpath/java/java/awt/Window.java Modified: trunk/core/src/classpath/java/java/awt/Component.java =================================================================== --- trunk/core/src/classpath/java/java/awt/Component.java 2007-02-03 15:05:27 UTC (rev 3101) +++ trunk/core/src/classpath/java/java/awt/Component.java 2007-02-03 18:44:48 UTC (rev 3102) @@ -971,18 +971,40 @@ // case lightweight components are not initially painted -- // Container.paint first calls isShowing () before painting itself // and its children. - if(!isVisible()) + if(! visible) { - this.visible = true; + // Need to lock the tree here to avoid races and inconsistencies. + synchronized (getTreeLock()) + { + visible = true; // Avoid NullPointerExceptions by creating a local reference. ComponentPeer currentPeer=peer; if (currentPeer != null) + { currentPeer.show(); + // Fire HierarchyEvent. + fireHierarchyEvent(HierarchyEvent.HIERARCHY_CHANGED, + this, parent, + HierarchyEvent.SHOWING_CHANGED); + // The JDK repaints the component before invalidating the parent. // So do we. - if (isShowing() && isLightweight()) + if (peer instanceof LightweightPeer) repaint(); + } + + // Only post an event if this component actually has a listener + // or has this event explicitly enabled. + if (componentListener != null + || (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0) + { + ComponentEvent ce = + new ComponentEvent(this,ComponentEvent.COMPONENT_SHOWN); + getToolkit().getSystemEventQueue().postEvent(ce); + } + } + // Invalidate the parent if we have one. The component itself must // not be invalidated. We also avoid NullPointerException with // a local reference here. @@ -990,9 +1012,6 @@ if (currentParent != null) currentParent.invalidate(); - ComponentEvent ce = - new ComponentEvent(this,ComponentEvent.COMPONENT_SHOWN); - getToolkit().getSystemEventQueue().postEvent(ce); } } @@ -1018,29 +1037,47 @@ */ public void hide() { - if (isVisible()) + if (visible) { + // Need to lock the tree here to avoid races and inconsistencies. + synchronized (getTreeLock()) + { + visible = false; + // Avoid NullPointerExceptions by creating a local reference. ComponentPeer currentPeer=peer; if (currentPeer != null) - currentPeer.setVisible(false); - boolean wasShowing = isShowing(); - this.visible = false; + { + currentPeer.hide(); - // The JDK repaints the component before invalidating the parent. - // So do we. - if (wasShowing) + // Fire hierarchy event. + fireHierarchyEvent(HierarchyEvent.HIERARCHY_CHANGED, + this, parent, + HierarchyEvent.SHOWING_CHANGED); + // The JDK repaints the component before invalidating the + // parent. So do we. This only applies for lightweights. + if (peer instanceof LightweightPeer) repaint(); - // Invalidate the parent if we have one. The component itself must + } + + // Only post an event if this component actually has a listener + // or has this event explicitly enabled. + if (componentListener != null + || (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0) + { + ComponentEvent ce = + new ComponentEvent(this,ComponentEvent.COMPONENT_HIDDEN); + getToolkit().getSystemEventQueue().postEvent(ce); + } + } + + // Invalidate the parent if we have one. The component itself need // not be invalidated. We also avoid NullPointerException with // a local reference here. Container currentParent = parent; if (currentParent != null) currentParent.invalidate(); - ComponentEvent ce = - new ComponentEvent(this,ComponentEvent.COMPONENT_HIDDEN); - getToolkit().getSystemEventQueue().postEvent(ce); } } @@ -3935,19 +3972,38 @@ */ public void addNotify() { + // We need to lock the tree here to avoid races and inconsistencies. + synchronized (getTreeLock()) + { if (peer == null) peer = getToolkit().createComponent(this); else if (parent != null && parent.isLightweight()) new HeavyweightInLightweightListener(parent); - /* Now that all the children has gotten their peers, we should - have the event mask needed for this component and its - lightweight subcomponents. */ + // Now that all the children has gotten their peers, we should + // have the event mask needed for this component and its + //lightweight subcomponents. peer.setEventMask(eventMask); - /* We do not invalidate here, but rather leave that job up to - the peer. For efficiency, the peer can choose not to - invalidate if it is happy with the current dimensions, - etc. */ + + // We used to leave the invalidate() to the peer. However, I put it + // back here for 2 reasons: 1) The RI does call invalidate() from + // addNotify(); 2) The peer shouldn't be bother with validation too + // much. + invalidate(); + + if (dropTarget != null) + dropTarget.addNotify(peer); + + // Fetch the peerFont for later installation in validate(). + peerFont = getFont(); + + // Notify hierarchy listeners. + long flags = HierarchyEvent.DISPLAYABILITY_CHANGED; + if (isHierarchyVisible()) + flags |= HierarchyEvent.SHOWING_CHANGED; + fireHierarchyEvent(HierarchyEvent.HIERARCHY_CHANGED, this, parent, + flags); } + } /** * Called to inform this component is has been removed from its @@ -3960,6 +4016,9 @@ */ public void removeNotify() { + // We need to lock the tree here to avoid races and inconsistencies. + synchronized (getTreeLock()) + { // We null our peer field before disposing of it, such that if we're // not the event dispatch thread and the dispatch thread is awoken by // the dispose call, there will be no race checking the peer's null @@ -3967,12 +4026,21 @@ ComponentPeer tmp = peer; peer = null; + peerFont = null; if (tmp != null) { tmp.hide(); tmp.dispose(); } + + // Notify hierarchy listeners. + long flags = HierarchyEvent.DISPLAYABILITY_CHANGED; + if (isHierarchyVisible()) + flags |= HierarchyEvent.SHOWING_CHANGED; + fireHierarchyEvent(HierarchyEvent.HIERARCHY_CHANGED, this, parent, + flags); } + } /** * AWT 1.0 GOT_FOCUS event handler. This method is meant to be Modified: trunk/core/src/classpath/java/java/awt/Container.java =================================================================== --- trunk/core/src/classpath/java/java/awt/Container.java 2007-02-03 15:05:27 UTC (rev 3101) +++ trunk/core/src/classpath/java/java/awt/Container.java 2007-02-03 18:44:48 UTC (rev 3102) @@ -39,7 +39,6 @@ package java.awt; -import java.awt.event.ComponentListener; import java.awt.event.ContainerEvent; import java.awt.event.ContainerListener; import java.awt.event.HierarchyEvent; @@ -90,12 +89,7 @@ Dimension maxSize; - /** - * Keeps track if the Container was cleared during a paint/update. - */ - private boolean backCleared; - - /** + /* * @since 1.4 */ boolean focusCycleRoot; @@ -333,24 +327,7 @@ // we are. if (comp.parent != null) comp.parent.remove(comp); - comp.parent = this; - if (peer != null) - { - // Notify the component that it has a new parent. - comp.addNotify(); - - if (comp.isLightweight ()) - { - enableEvents (comp.eventMask); - if (!isLightweight ()) - enableEvents (AWTEvent.PAINT_EVENT_MASK); - } - } - - // Invalidate the layout of the added component and its ancestors. - comp.invalidate(); - if (component == null) component = new Component[4]; // FIXME, better initial size? @@ -374,6 +351,31 @@ ++ncomponents; } + // Give the new component a parent. + comp.parent = this; + + // Update the counter for Hierarchy(Bounds)Listeners. + int childHierarchyListeners = comp.numHierarchyListeners; + if (childHierarchyListeners > 0) + updateHierarchyListenerCount(AWTEvent.HIERARCHY_EVENT_MASK, + childHierarchyListeners); + int childHierarchyBoundsListeners = comp.numHierarchyBoundsListeners; + if (childHierarchyBoundsListeners > 0) + updateHierarchyListenerCount(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK, + childHierarchyListeners); + + // Invalidate the layout of this container. + if (valid) + invalidate(); + + // Create the peer _after_ the component has been added, so that + // the peer gets to know about the component hierarchy. + if (peer != null) + { + // Notify the component that it has a new parent. + comp.addNotify(); + } + // Notify the layout manager. if (layoutMgr != null) { @@ -394,14 +396,20 @@ // Also, the event was posted to the event queue. A Mauve test shows // that this event is not delivered using the event queue and it is // also sent when the container is not showing. + if (containerListener != null + || (eventMask & AWTEvent.CONTAINER_EVENT_MASK) != 0) + { ContainerEvent ce = new ContainerEvent(this, ContainerEvent.COMPONENT_ADDED, comp); - ContainerListener[] listeners = getContainerListeners(); - for (int i = 0; i < listeners.length; i++) - listeners[i].componentAdded(ce); + dispatchEvent(ce); } + + // Notify hierarchy listeners. + comp.fireHierarchyEvent(HierarchyEvent.HIERARCHY_CHANGED, comp, + this, HierarchyEvent.PARENT_CHANGED); } + } /** * Removes the component at the specified index from this container. @@ -412,33 +420,48 @@ { synchronized (getTreeLock ()) { + if (index < 0 || index >= ncomponents) + throw new ArrayIndexOutOfBoundsException(); + Component r = component[index]; + if (peer != null) + r.removeNotify(); - ComponentListener[] list = r.getComponentListeners(); - for (int j = 0; j < list.length; j++) - r.removeComponentListener(list[j]); + if (layoutMgr != null) + layoutMgr.removeLayoutComponent(r); - r.removeNotify(); + // Update the counter for Hierarchy(Bounds)Listeners. + int childHierarchyListeners = r.numHierarchyListeners; + if (childHierarchyListeners > 0) + updateHierarchyListenerCount(AWTEvent.HIERARCHY_EVENT_MASK, + -childHierarchyListeners); + int childHierarchyBoundsListeners = r.numHierarchyBoundsListeners; + if (childHierarchyBoundsListeners > 0) + updateHierarchyListenerCount(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK, + -childHierarchyListeners); + r.parent = null; + System.arraycopy(component, index + 1, component, index, ncomponents - index - 1); component[--ncomponents] = null; + if (valid) invalidate(); - if (layoutMgr != null) - layoutMgr.removeLayoutComponent(r); - - r.parent = null; - - if (isShowing ()) + if (containerListener != null + || (eventMask & AWTEvent.CONTAINER_EVENT_MASK) != 0) { // Post event to notify of removing the component. ContainerEvent ce = new ContainerEvent(this, ContainerEvent.COMPONENT_REMOVED, r); - getToolkit().getSystemEventQueue().postEvent(ce); + dispatchEvent(ce); } + + // Notify hierarchy listeners. + r.fireHierarchyEvent(HierarchyEvent.HIERARCHY_CHANGED, r, + this, HierarchyEvent.PARENT_CHANGED); } } @@ -477,14 +500,13 @@ // super.removeAll() ). // By doing it this way, user code cannot prevent the correct // removal of components. - for ( int index = 0; index < ncomponents; index++) + while (ncomponents > 0) { - Component r = component[index]; + ncomponents--; + Component r = component[ncomponents]; + component[ncomponents] = null; - ComponentListener[] list = r.getComponentListeners(); - for (int j = 0; j < list.length; j++) - r.removeComponentListener(list[j]); - + if (peer != null) r.removeNotify(); if (layoutMgr != null) @@ -492,21 +514,37 @@ r.parent = null; - if (isShowing ()) + // Send ContainerEvent if necessary. + if (containerListener != null + || (eventMask & AWTEvent.CONTAINER_EVENT_MASK) != 0) { // Post event to notify of removing the component. ContainerEvent ce = new ContainerEvent(this, ContainerEvent.COMPONENT_REMOVED, r); - - getToolkit().getSystemEventQueue().postEvent(ce); + dispatchEvent(ce); } - } - + + // Update the counter for Hierarchy(Bounds)Listeners. + int childHierarchyListeners = r.numHierarchyListeners; + if (childHierarchyListeners > 0) + updateHierarchyListenerCount(AWTEvent.HIERARCHY_EVENT_MASK, + -childHierarchyListeners); + int childHierarchyBoundsListeners = r.numHierarchyBoundsListeners; + if (childHierarchyBoundsListeners > 0) + updateHierarchyListenerCount(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK, + -childHierarchyListeners); + + + // Send HierarchyEvent if necessary. + fireHierarchyEvent(HierarchyEvent.HIERARCHY_CHANGED, r, this, + HierarchyEvent.PARENT_CHANGED); + + } + + if (valid) invalidate(); - - ncomponents = 0; } } @@ -571,11 +609,20 @@ */ public void validate() { + ComponentPeer p = peer; + if (! valid && p != null) + { + ContainerPeer cPeer = null; + if (p instanceof ContainerPeer) + cPeer = (ContainerPeer) peer; synchronized (getTreeLock ()) { - if (! isValid() && peer != null) - { + if (cPeer != null) + cPeer.beginValidate(); validateTree(); + valid = true; + if (cPeer != null) + cPeer.endValidate(); } } } @@ -585,19 +632,18 @@ */ void invalidateTree() { - super.invalidate(); // Clean cached layout state. + synchronized (getTreeLock()) + { for (int i = 0; i < ncomponents; i++) { Component comp = component[i]; - comp.invalidate(); if (comp instanceof Container) ((Container) comp).invalidateTree(); + else if (comp.valid) + comp.invalidate(); } - - if (layoutMgr != null && layoutMgr instanceof LayoutManager2) - { - LayoutManager2 lm2 = (LayoutManager2) layoutMgr; - lm2.invalidateLayout(this); + if (valid) + invalidate(); } } @@ -607,60 +653,52 @@ */ protected void validateTree() { - if (valid) - return; - + if (!valid) + { ContainerPeer cPeer = null; - if (peer != null && ! (peer instanceof LightweightPeer)) + if (peer instanceof ContainerPeer) { cPeer = (ContainerPeer) peer; - cPeer.beginValidate(); + cPeer.beginLayout(); } - for (int i = 0; i < ncomponents; ++i) - { - Component comp = component[i]; - - if (comp.getPeer () == null) - comp.addNotify(); - } - doLayout (); for (int i = 0; i < ncomponents; ++i) { Component comp = component[i]; - if (! comp.isValid()) + if (comp instanceof Container && ! (comp instanceof Window) + && ! comp.valid) { - if (comp instanceof Container) - { ((Container) comp).validateTree(); } else { - component[i].validate(); + comp.validate(); } } + + if (cPeer != null) + { + cPeer = (ContainerPeer) peer; + cPeer.endLayout(); } + } /* children will call invalidate() when they are layed out. It is therefore important that valid is not set to true until after the children have been layed out. */ valid = true; - if (cPeer != null) - cPeer.endValidate(); } public void setFont(Font f) { - if( (f != null && (font == null || !font.equals(f))) - || f == null) + Font oldFont = getFont(); + super.setFont(f); + Font newFont = getFont(); + if (newFont != oldFont && (oldFont == null || ! oldFont.equals(newFont))) { - super.setFont(f); - // FIXME: Although it might make more sense to invalidate only - // those children whose font == null, Sun invalidates all children. - // So we'll do the same. invalidateTree(); } } @@ -922,8 +960,13 @@ */ public synchronized void addContainerListener(ContainerListener listener) { - containerListener = AWTEventMulticaster.add(containerListener, listener); + if (listener != null) + { + containerListener = AWTEventMulticaster.add(containerListener, + listener); + newEventsOnly = true; } + } /** * Removes the specified container listener from this object's list of @@ -1853,6 +1896,7 @@ bounds.height); try { + g2.setFont(comp.getFont()); visitor.visit(comp, g2); } finally @@ -2053,15 +2097,9 @@ for (int i = ncomponents; --i >= 0; ) { component[i].addNotify(); - if (component[i].isLightweight ()) - { - enableEvents(component[i].eventMask); - if (peer != null && !isLightweight ()) - enableEvents (AWTEvent.PAINT_EVENT_MASK); } } } - } /** * Deserialize this Container: Modified: trunk/core/src/classpath/java/java/awt/Window.java =================================================================== --- trunk/core/src/classpath/java/java/awt/Window.java 2007-02-03 15:05:27 UTC (rev 3101) +++ trunk/core/src/classpath/java/java/awt/Window.java 2007-02-03 18:44:48 UTC (rev 3102) @@ -393,11 +393,17 @@ component[i].removeNotify(); this.removeNotify(); - // Post a WINDOW_CLOSED event. - WindowEvent we = new WindowEvent(this, WindowEvent.WINDOW_CLOSED); - getToolkit().getSystemEventQueue().postEvent(we); + // Post WINDOW_CLOSED from here. + if (windowListener != null + || (eventMask & AWTEvent.WINDOW_EVENT_MASK) != 0) + { + WindowEvent ev = new WindowEvent(this, + WindowEvent.WINDOW_CLOSED); + Toolkit tk = Toolkit.getDefaultToolkit(); + tk.getSystemEventQueue().postEvent(ev); } } + } /** * Sends this window to the back so that all other windows display in This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ls...@us...> - 2007-02-03 20:51:03
|
Revision: 3103 http://jnode.svn.sourceforge.net/jnode/?rev=3103&view=rev Author: lsantha Date: 2007-02-03 12:51:00 -0800 (Sat, 03 Feb 2007) Log Message: ----------- Classpath patches. Modified Paths: -------------- trunk/core/src/classpath/java/java/awt/Component.java trunk/core/src/classpath/java/java/awt/Container.java trunk/core/src/classpath/java/java/awt/Window.java Modified: trunk/core/src/classpath/java/java/awt/Component.java =================================================================== --- trunk/core/src/classpath/java/java/awt/Component.java 2007-02-03 18:44:48 UTC (rev 3102) +++ trunk/core/src/classpath/java/java/awt/Component.java 2007-02-03 20:51:00 UTC (rev 3103) @@ -1180,14 +1180,7 @@ */ public Font getFont() { - Font f = font; - if (f != null) - return f; - - Component p = parent; - if (p != null) - return p.getFont(); - return null; + return getFontImpl(); } /** @@ -1223,19 +1216,45 @@ * * @see #getFont() */ - public void setFont(Font newFont) + public void setFont(Font f) { - if((newFont != null && (font == null || !font.equals(newFont))) - || newFont == null) + Font oldFont; + Font newFont; + // Synchronize on the tree because getFontImpl() relies on the hierarchy + // not beeing changed. + synchronized (getTreeLock()) { - Font oldFont = font; - font = newFont; - if (peer != null) - peer.setFont(font); + // Synchronize on this here to guarantee thread safety wrt to the + // property values. + synchronized (this) + { + oldFont = font; + font = f; + newFont = f; + } + // Create local variable here for thread safety. + ComponentPeer p = peer; + if (p != null) + { + // The peer receives the real font setting, which can depend on + // the parent font when this component's font has been set to null. + f = getFont(); + if (f != null) + { + p.setFont(f); + peerFont = f; + } + } + } + + // Fire property change event. firePropertyChange("font", oldFont, newFont); + + // Invalidate when necessary as font changes can change the size of the + // component. + if (valid) invalidate(); } - } /** * Tests if the font was explicitly set, or just inherited from the parent. @@ -1521,55 +1540,50 @@ */ public void reshape(int x, int y, int width, int height) { + // We need to lock the tree here, otherwise we risk races and + // inconsistencies. + synchronized (getTreeLock()) + { int oldx = this.x; int oldy = this.y; int oldwidth = this.width; int oldheight = this.height; - if (this.x == x && this.y == y && this.width == width - && this.height == height) - return; + boolean resized = oldwidth != width || oldheight != height; + boolean moved = oldx != x || oldy != y; - invalidate(); - + if (resized || moved) + { + // Update the fields. this.x = x; this.y = y; this.width = width; this.height = height; - if (peer != null) - peer.setBounds (x, y, width, height); - // Erase old bounds and repaint new bounds for lightweights. - if (isLightweight() && isShowing()) + if (peer != null) { - if (parent != null) - { - Rectangle oldBounds = new Rectangle(oldx, oldy, oldwidth, - oldheight); - Rectangle newBounds = new Rectangle(x, y, width, height); - Rectangle destroyed = oldBounds.union(newBounds); - if (!destroyed.isEmpty()) - parent.repaint(0, destroyed.x, destroyed.y, destroyed.width, - destroyed.height); + peer.setBounds (x, y, width, height); + if (resized) + invalidate(); + if (parent != null && parent.valid) + parent.invalidate(); } - } - // Only post event if this component is visible and has changed size. - if (isShowing () - && (oldx != x || oldy != y)) + // Send some events to interested listeners. + notifyReshape(resized, moved); + + // Repaint this component and the parent if appropriate. + if (parent != null && peer instanceof LightweightPeer + && isShowing()) { - ComponentEvent ce = new ComponentEvent(this, - ComponentEvent.COMPONENT_MOVED); - getToolkit().getSystemEventQueue().postEvent(ce); + // The parent repaints the area that we occupied before. + parent.repaint(oldx, oldy, oldwidth, oldheight); + // This component repaints the area that we occupy now. + repaint(); } - if (isShowing () - && (oldwidth != width || oldheight != height)) - { - ComponentEvent ce = new ComponentEvent(this, - ComponentEvent.COMPONENT_RESIZED); - getToolkit().getSystemEventQueue().postEvent(ce); } } + } /** * Sends notification to interested listeners about resizing and/or moving @@ -1804,15 +1818,10 @@ */ public Dimension preferredSize() { - if (prefSize == null) - { - if (peer == null) - prefSize = minimumSize(); - else - prefSize = peer.getPreferredSize(); + // Create a new Dimension object, so that the application doesn't mess + // with the actual values. + return new Dimension(preferredSizeImpl()); } - return prefSize; - } /** * The actual calculation is pulled out of preferredSize() so that @@ -1895,10 +1904,9 @@ */ public Dimension minimumSize() { - if (minSize == null) - minSize = (peer != null ? peer.getMinimumSize() - : new Dimension(width, height)); - return minSize; + // Create a new Dimension object, so that the application doesn't mess + // with the actual values. + return new Dimension(minimumSizeImpl()); } /** @@ -1939,7 +1947,7 @@ */ public Dimension getMaximumSize() { - return new Dimension(Short.MAX_VALUE, Short.MAX_VALUE); + return new Dimension(maximumSizeImpl()); } /** @@ -2854,10 +2862,13 @@ */ public synchronized void addComponentListener(ComponentListener listener) { - componentListener = AWTEventMulticaster.add(componentListener, listener); - if (componentListener != null) - enableEvents(AWTEvent.COMPONENT_EVENT_MASK); + if (listener != null) + { + componentListener = AWTEventMulticaster.add(componentListener, + listener); + newEventsOnly = true; } + } /** * Removes the specified listener from the component. This is harmless if @@ -2902,10 +2913,12 @@ */ public synchronized void addFocusListener(FocusListener listener) { + if (listener != null) + { focusListener = AWTEventMulticaster.add(focusListener, listener); - if (focusListener != null) - enableEvents(AWTEvent.FOCUS_EVENT_MASK); + newEventsOnly = true; } + } /** * Removes the specified listener from the component. This is harmless if @@ -2949,10 +2962,21 @@ */ public synchronized void addHierarchyListener(HierarchyListener listener) { - hierarchyListener = AWTEventMulticaster.add(hierarchyListener, listener); - if (hierarchyListener != null) - enableEvents(AWTEvent.HIERARCHY_EVENT_MASK); + if (listener != null) + { + hierarchyListener = AWTEventMulticaster.add(hierarchyListener, + listener); + newEventsOnly = true; + // Need to lock the tree, otherwise we might end up inconsistent. + synchronized (getTreeLock()) + { + numHierarchyListeners++; + if (parent != null) + parent.updateHierarchyListenerCount(AWTEvent.HIERARCHY_EVENT_MASK, + 1); } + } + } /** * Removes the specified listener from the component. This is harmless if @@ -2967,7 +2991,16 @@ public synchronized void removeHierarchyListener(HierarchyListener listener) { hierarchyListener = AWTEventMulticaster.remove(hierarchyListener, listener); + + // Need to lock the tree, otherwise we might end up inconsistent. + synchronized (getTreeLock()) + { + numHierarchyListeners--; + if (parent != null) + parent.updateHierarchyListenerCount(AWTEvent.HIERARCHY_EVENT_MASK, + -1); } + } /** * Returns an array of all specified listeners registered on this component. @@ -2998,11 +3031,22 @@ public synchronized void addHierarchyBoundsListener(HierarchyBoundsListener listener) { + if (listener != null) + { hierarchyBoundsListener = AWTEventMulticaster.add(hierarchyBoundsListener, listener); - if (hierarchyBoundsListener != null) - enableEvents(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK); + newEventsOnly = true; + + // Need to lock the tree, otherwise we might end up inconsistent. + synchronized (getTreeLock()) + { + numHierarchyBoundsListeners++; + if (parent != null) + parent.updateHierarchyListenerCount + (AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK, 1); } + } + } /** * Removes the specified listener from the component. This is harmless if @@ -3019,7 +3063,17 @@ { hierarchyBoundsListener = AWTEventMulticaster.remove(hierarchyBoundsListener, listener); + + // Need to lock the tree, otherwise we might end up inconsistent. + synchronized (getTreeLock()) + { + numHierarchyBoundsListeners--; + if (parent != null) + parent.updateHierarchyListenerCount + (AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK, + -1); } + } /** * Returns an array of all specified listeners registered on this component. @@ -3083,10 +3137,12 @@ */ public synchronized void addKeyListener(KeyListener listener) { + if (listener != null) + { keyListener = AWTEventMulticaster.add(keyListener, listener); - if (keyListener != null) - enableEvents(AWTEvent.KEY_EVENT_MASK); + newEventsOnly = true; } + } /** * Removes the specified listener from the component. This is harmless if @@ -3130,10 +3186,12 @@ */ public synchronized void addMouseListener(MouseListener listener) { + if (listener != null) + { mouseListener = AWTEventMulticaster.add(mouseListener, listener); - if (mouseListener != null) - enableEvents(AWTEvent.MOUSE_EVENT_MASK); + newEventsOnly = true; } + } /** * Removes the specified listener from the component. This is harmless if @@ -3177,10 +3235,13 @@ */ public synchronized void addMouseMotionListener(MouseMotionListener listener) { - mouseMotionListener = AWTEventMulticaster.add(mouseMotionListener, listener); - if (mouseMotionListener != null) - enableEvents(AWTEvent.MOUSE_MOTION_EVENT_MASK); + if (listener != null) + { + mouseMotionListener = AWTEventMulticaster.add(mouseMotionListener, + listener); + newEventsOnly = true; } + } /** * Removes the specified listener from the component. This is harmless if @@ -3226,10 +3287,13 @@ */ public synchronized void addMouseWheelListener(MouseWheelListener listener) { - mouseWheelListener = AWTEventMulticaster.add(mouseWheelListener, listener); - if (mouseWheelListener != null) - enableEvents(AWTEvent.MOUSE_WHEEL_EVENT_MASK); + if (listener != null) + { + mouseWheelListener = AWTEventMulticaster.add(mouseWheelListener, + listener); + newEventsOnly = true; } + } /** * Removes the specified listener from the component. This is harmless if @@ -3276,10 +3340,13 @@ */ public synchronized void addInputMethodListener(InputMethodListener listener) { - inputMethodListener = AWTEventMulticaster.add(inputMethodListener, listener); - if (inputMethodListener != null) - enableEvents(AWTEvent.INPUT_METHOD_EVENT_MASK); + if (listener != null) + { + inputMethodListener = AWTEventMulticaster.add(inputMethodListener, + listener); + newEventsOnly = true; } + } /** * Removes the specified listener from the component. This is harmless if @@ -3445,19 +3512,42 @@ */ protected AWTEvent coalesceEvents(AWTEvent existingEvent, AWTEvent newEvent) { + AWTEvent coalesced = null; switch (existingEvent.id) { case MouseEvent.MOUSE_MOVED: case MouseEvent.MOUSE_DRAGGED: // Just drop the old (intermediate) event and return the new one. - return newEvent; + MouseEvent me1 = (MouseEvent) existingEvent; + MouseEvent me2 = (MouseEvent) newEvent; + if (me1.getModifiers() == me2.getModifiers()) + coalesced = newEvent; + break; case PaintEvent.PAINT: case PaintEvent.UPDATE: - return coalescePaintEvents((PaintEvent) existingEvent, - (PaintEvent) newEvent); + // For heavyweights the EventQueue should ask the peer. + if (peer == null || peer instanceof LightweightPeer) + { + PaintEvent pe1 = (PaintEvent) existingEvent; + PaintEvent pe2 = (PaintEvent) newEvent; + Rectangle r1 = pe1.getUpdateRect(); + Rectangle r2 = pe2.getUpdateRect(); + if (r1.contains(r2)) + coalesced = existingEvent; + else if (r2.contains(r1)) + coalesced = newEvent; + } + else + { + // Replace the event and let the heavyweight figure out the expanding + // of the repaint area. + coalesced = newEvent; + } + break; default: - return null; + coalesced = null; } + return coalesced; } /** Modified: trunk/core/src/classpath/java/java/awt/Container.java =================================================================== --- trunk/core/src/classpath/java/java/awt/Container.java 2007-02-03 18:44:48 UTC (rev 3102) +++ trunk/core/src/classpath/java/java/awt/Container.java 2007-02-03 20:51:00 UTC (rev 3103) @@ -87,9 +87,7 @@ Component[] component; LayoutManager layoutMgr; - Dimension maxSize; - - /* + /** * @since 1.4 */ boolean focusCycleRoot; @@ -1912,16 +1910,18 @@ */ void dispatchEventImpl(AWTEvent e) { - boolean dispatched = - LightweightDispatcher.getInstance().dispatchEvent(e); - if (! dispatched) + LightweightDispatcher dispatcher = LightweightDispatcher.getInstance(); + if (! isLightweight() && dispatcher.dispatchEvent(e)) { - if ((e.id <= ContainerEvent.CONTAINER_LAST - && e.id >= ContainerEvent.CONTAINER_FIRST) - && (containerListener != null - || (eventMask & AWTEvent.CONTAINER_EVENT_MASK) != 0)) - processEvent(e); + // Some lightweight descendent got this event dispatched. Consume + // it and let the peer handle it. + e.consume(); + ComponentPeer p = peer; + if (p != null) + p.handleEvent(e); + } else + { super.dispatchEventImpl(e); } } Modified: trunk/core/src/classpath/java/java/awt/Window.java =================================================================== --- trunk/core/src/classpath/java/java/awt/Window.java 2007-02-03 18:44:48 UTC (rev 3102) +++ trunk/core/src/classpath/java/java/awt/Window.java 2007-02-03 20:51:00 UTC (rev 3103) @@ -286,8 +286,6 @@ { synchronized (getTreeLock()) { - if (parent != null && ! parent.isDisplayable()) - parent.addNotify(); if (peer == null) addNotify(); @@ -529,8 +527,12 @@ */ public synchronized void addWindowListener(WindowListener listener) { + if (listener != null) + { + newEventsOnly = true; windowListener = AWTEventMulticaster.add(windowListener, listener); } + } /** * Removes the specified listener from the list of @@ -586,9 +588,14 @@ */ public void addWindowFocusListener (WindowFocusListener wfl) { - windowFocusListener = AWTEventMulticaster.add (windowFocusListener, wfl); + if (wfl != null) + { + newEventsOnly = true; + windowFocusListener = AWTEventMulticaster.add (windowFocusListener, + wfl); } - + } + /** * Adds the specified listener to this window. * @@ -596,9 +603,14 @@ */ public void addWindowStateListener (WindowStateListener wsl) { - windowStateListener = AWTEventMulticaster.add (windowStateListener, wsl); + if (wsl != null) + { + newEventsOnly = true; + windowStateListener = AWTEventMulticaster.add (windowStateListener, + wsl); } - + } + /** * Removes the specified listener from this window. */ @@ -636,17 +648,11 @@ void dispatchEventImpl(AWTEvent e) { - // Make use of event id's in order to avoid multiple instanceof tests. - if (e.id <= WindowEvent.WINDOW_LAST - && e.id >= WindowEvent.WINDOW_FIRST - && (windowListener != null - || windowFocusListener != null - || windowStateListener != null - || (eventMask & AWTEvent.WINDOW_EVENT_MASK) != 0)) - processEvent(e); - else if (e.id == ComponentEvent.COMPONENT_RESIZED) + if (e.getID() == ComponentEvent.COMPONENT_RESIZED) + { + invalidate(); validate (); - else + } super.dispatchEventImpl(e); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ls...@us...> - 2007-07-07 12:38:29
|
Revision: 3354 http://jnode.svn.sourceforge.net/jnode/?rev=3354&view=rev Author: lsantha Date: 2007-07-07 05:38:26 -0700 (Sat, 07 Jul 2007) Log Message: ----------- Openjdk integration. Modified Paths: -------------- trunk/core/src/classpath/java/java/awt/Component.java trunk/core/src/classpath/java/java/awt/Container.java trunk/core/src/classpath/java/java/awt/Dialog.java trunk/core/src/classpath/java/java/awt/EventQueue.java trunk/core/src/classpath/java/java/awt/Font.java trunk/core/src/classpath/java/java/awt/FontMetrics.java trunk/core/src/classpath/java/java/awt/GraphicsConfiguration.java trunk/core/src/classpath/java/java/awt/PopupMenu.java trunk/core/src/classpath/java/java/awt/Toolkit.java trunk/core/src/classpath/java/java/awt/Window.java trunk/core/src/classpath/java/java/awt/event/MouseEvent.java trunk/core/src/classpath/java/java/awt/font/GraphicAttribute.java trunk/core/src/classpath/java/java/awt/font/TextAttribute.java trunk/core/src/classpath/java/java/awt/font/TransformAttribute.java trunk/core/src/classpath/java/java/awt/geom/AffineTransform.java trunk/core/src/classpath/java/java/awt/geom/GeneralPath.java Modified: trunk/core/src/classpath/java/java/awt/Component.java =================================================================== --- trunk/core/src/classpath/java/java/awt/Component.java 2007-07-07 12:37:26 UTC (rev 3353) +++ trunk/core/src/classpath/java/java/awt/Component.java 2007-07-07 12:38:26 UTC (rev 3354) @@ -6095,7 +6095,274 @@ peer.hide(); } } - + + //jnode openjdk + /** + * Enumeration of the common ways the baseline of a component can + * change as the size changes. The baseline resize behavior is + * primarily for layout managers that need to know how the + * position of the baseline changes as the component size changes. + * In general the baseline resize behavior will be valid for sizes + * greater than or equal to the minimum size (the actual minimum + * size; not a developer specified minimum size). For sizes + * smaller than the minimum size the baseline may change in a way + * other than the baseline resize behavior indicates. Similarly, + * as the size approaches <code>Integer.MAX_VALUE</code> and/or + * <code>Short.MAX_VALUE</code> the baseline may change in a way + * other than the baseline resize behavior indicates. + * + * @see #getBaselineResizeBehavior + * @see #getBaseline(int,int) + * @since 1.6 + */ + public enum BaselineResizeBehavior { + /** + * Indicates the baseline remains fixed relative to the + * y-origin. That is, <code>getBaseline</code> returns + * the same value regardless of the height or width. For example, a + * <code>JLabel</code> containing non-empty text with a + * vertical alignment of <code>TOP</code> should have a + * baseline type of <code>CONSTANT_ASCENT</code>. + */ + CONSTANT_ASCENT, + + /** + * Indicates the baseline remains fixed relative to the height + * and does not change as the width is varied. That is, for + * any height H the difference between H and + * <code>getBaseline(w, H)</code> is the same. For example, a + * <code>JLabel</code> containing non-empty text with a + * vertical alignment of <code>BOTTOM</code> should have a + * baseline type of <code>CONSTANT_DESCENT</code>. + */ + CONSTANT_DESCENT, + + /** + * Indicates the baseline remains a fixed distance from + * the center of the component. That is, for any height H the + * difference between <code>getBaseline(w, H)</code> and + * <code>H / 2</code> is the same (plus or minus one depending upon + * rounding error). + * <p> + * Because of possible rounding errors it is recommended + * you ask for the baseline with two consecutive heights and use + * the return value to determine if you need to pad calculations + * by 1. The following shows how to calculate the baseline for + * any height: + * <pre> + * Dimension preferredSize = component.getPreferredSize(); + * int baseline = getBaseline(preferredSize.width, + * preferredSize.height); + * int nextBaseline = getBaseline(preferredSize.width, + * preferredSize.height + 1); + * // Amount to add to height when calculating where baseline + * // lands for a particular height: + * int padding = 0; + * // Where the baseline is relative to the mid point + * int baselineOffset = baseline - height / 2; + * if (preferredSize.height % 2 == 0 && + * baseline != nextBaseline) { + * padding = 1; + * } + * else if (preferredSize.height % 2 == 1 && + * baseline == nextBaseline) { + * baselineOffset--; + * padding = 1; + * } + * // The following calculates where the baseline lands for + * // the height z: + * int calculatedBaseline = (z + padding) / 2 + baselineOffset; + * </pre> + */ + CENTER_OFFSET, + + /** + * Indicates the baseline resize behavior can not be expressed using + * any of the other constants. This may also indicate the baseline + * varies with the width of the component. This is also returned + * by components that do not have a baseline. + */ + OTHER + } + + /** + * Returns the baseline. The baseline is measured from the top of + * the component. This method is primarily meant for + * <code>LayoutManager</code>s to align components along their + * baseline. A return value less than 0 indicates this component + * does not have a reasonable baseline and that + * <code>LayoutManager</code>s should not align this component on + * its baseline. + * <p> + * The default implementation returns -1. Subclasses that support + * baseline should override appropriately. If a value >= 0 is + * returned, then the component has a valid baseline for any + * size >= the minimum size and <code>getBaselineResizeBehavior</code> + * can be used to determine how the baseline changes with size. + * + * @param width the width to get the baseline for + * @param height the height to get the baseline for + * @return the baseline or < 0 indicating there is no reasonable + * baseline + * @throws IllegalArgumentException if width or height is < 0 + * @see #getBaselineResizeBehavior + * @see java.awt.FontMetrics + * @since 1.6 + */ + public int getBaseline(int width, int height) { + if (width < 0 || height < 0) { + throw new IllegalArgumentException( + "Width and height must be >= 0"); + } + return -1; + } + + /** + * Returns the <code>Window</code> ancestor of the component. + * @return Window ancestor of the component or component by itself if it is Window; + * null, if component is not a part of window hierarchy + */ + Window getContainingWindow() { + return getContainingWindow(this); + } + /** + * Returns the <code>Window</code> ancestor of the component <code>comp</code>. + * @return Window ancestor of the component or component by itself if it is Window; + * null, if component is not a part of window hierarchy + */ + static Window getContainingWindow(Component comp) { + while (comp != null && !(comp instanceof Window)) { + comp = comp.getParent(); + } + + return (Window)comp; + } + + /** + * Translates absolute coordinates into coordinates in the coordinate + * space of this component. + */ + Point pointRelativeToComponent(Point absolute) { + Point compCoords = getLocationOnScreen(); + return new Point(absolute.x - compCoords.x, + absolute.y - compCoords.y); + } + + /** + * Returns an enum indicating how the baseline of the component + * changes as the size changes. This method is primarily meant for + * layout managers and GUI builders. + * <p> + * The default implementation returns + * <code>BaselineResizeBehavior.OTHER</code>. Subclasses that have a + * baseline should override appropriately. Subclasses should + * never return <code>null</code>; if the baseline can not be + * calculated return <code>BaselineResizeBehavior.OTHER</code>. Callers + * should first ask for the baseline using + * <code>getBaseline</code> and if a value >= 0 is returned use + * this method. It is acceptable for this method to return a + * value other than <code>BaselineResizeBehavior.OTHER</code> even if + * <code>getBaseline</code> returns a value less than 0. + * + * @return an enum indicating how the baseline changes as the component + * size changes + * @see #getBaseline(int, int) + * @since 1.6 + */ + public BaselineResizeBehavior getBaselineResizeBehavior() { + return BaselineResizeBehavior.OTHER; + } + + /** + * Returns the position of the mouse pointer in this <code>Component</code>'s + * coordinate space if the <code>Component</code> is directly under the mouse + * pointer, otherwise returns <code>null</code>. + * If the <code>Component</code> is not showing on the screen, this method + * returns <code>null</code> even if the mouse pointer is above the area + * where the <code>Component</code> would be displayed. + * If the <code>Component</code> is partially or fully obscured by other + * <code>Component</code>s or native windows, this method returns a non-null + * value only if the mouse pointer is located above the unobscured part of the + * <code>Component</code>. + * <p> + * For <code>Container</code>s it returns a non-null value if the mouse is + * above the <code>Container</code> itself or above any of its descendants. + * Use {@link Container#getMousePosition(boolean)} if you need to exclude children. + * <p> + * Sometimes the exact mouse coordinates are not important, and the only thing + * that matters is whether a specific <code>Component</code> is under the mouse + * pointer. If the return value of this method is <code>null</code>, mouse + * pointer is not directly above the <code>Component</code>. + * + * @exception HeadlessException if GraphicsEnvironment.isHeadless() returns true + * @see #isShowing + * @see Container#getMousePosition + * @return mouse coordinates relative to this <code>Component</code>, or null + * @since 1.5 + */ + public Point getMousePosition() throws HeadlessException { + if (GraphicsEnvironment.isHeadless()) { + throw new HeadlessException(); + } + + PointerInfo pi = (PointerInfo)java.security.AccessController.doPrivileged( + new java.security.PrivilegedAction() { + public Object run() { + return MouseInfo.getPointerInfo(); + } + } + ); + + synchronized (getTreeLock()) { + Component inTheSameWindow = findUnderMouseInWindow(pi); + if (!isSameOrAncestorOf(inTheSameWindow, true)) { + return null; + } + return pointRelativeToComponent(pi.getLocation()); + } + } + /** + * Assuming that mouse location is stored in PointerInfo passed + * to this method, it finds a Component that is in the same + * Window as this Component and is located under the mouse pointer. + * If no such Component exists, null is returned. + * NOTE: this method should be called under the protection of + * tree lock, as it is done in Component.getMousePosition() and + * Container.getMousePosition(boolean). + */ + Component findUnderMouseInWindow(PointerInfo pi) { + if (!isShowing()) { + return null; + } + Window win = getContainingWindow(); + if (!Toolkit.getDefaultToolkit().getMouseInfoPeer().isWindowUnderMouse(win)) { + return null; + } + final boolean INCLUDE_DISABLED = true; + Point relativeToWindow = win.pointRelativeToComponent(pi.getLocation()); + Component inTheSameWindow = win.findComponentAt(relativeToWindow.x, + relativeToWindow.y, + INCLUDE_DISABLED); + return inTheSameWindow; + } + + boolean isSameOrAncestorOf(Component comp, boolean allowChildren) { + return this == comp || (allowChildren && isParentOf(comp)); + } + /** + * Check if this component is the child of this container or its children. + * Note: this function acquires treeLock + * Note: this function traverses children tree only in one Window. + * @param comp a component in test, must not be null + */ + private boolean isParentOf(Component comp) { + synchronized(getTreeLock()) { + while (comp != null && comp != this && !(comp instanceof Window)) { + comp = comp.getParent(); + } + return (comp == this); + } + } /** * This class provides accessibility support for subclasses of container. * Modified: trunk/core/src/classpath/java/java/awt/Container.java =================================================================== --- trunk/core/src/classpath/java/java/awt/Container.java 2007-07-07 12:37:26 UTC (rev 3353) +++ trunk/core/src/classpath/java/java/awt/Container.java 2007-07-07 12:38:26 UTC (rev 3354) @@ -2338,4 +2338,124 @@ } } // class AccessibleContainerHandler } // class AccessibleAWTContainer + + //jnode openjdk + + /** + * Returns the position of the mouse pointer in this <code>Container</code>'s + * coordinate space if the <code>Container</code> is under the mouse pointer, + * otherwise returns <code>null</code>. + * This method is similar to {@link Component#getMousePosition()} with the exception + * that it can take the <code>Container</code>'s children into account. + * If <code>allowChildren</code> is <code>false</code>, this method will return + * a non-null value only if the mouse pointer is above the <code>Container</code> + * directly, not above the part obscured by children. + * If <code>allowChildren</code> is <code>true</code>, this method returns + * a non-null value if the mouse pointer is above <code>Container</code> or any + * of its descendants. + * + * @exception HeadlessException if GraphicsEnvironment.isHeadless() returns true + * @param allowChildren true if children should be taken into account + * @see Component#getMousePosition + * @return mouse coordinates relative to this <code>Component</code>, or null + * @since 1.5 + */ + public Point getMousePosition(boolean allowChildren) throws HeadlessException { + if (GraphicsEnvironment.isHeadless()) { + throw new HeadlessException(); + } + PointerInfo pi = (PointerInfo)java.security.AccessController.doPrivileged( + new java.security.PrivilegedAction() { + public Object run() { + return MouseInfo.getPointerInfo(); + } + } + ); + synchronized (getTreeLock()) { + Component inTheSameWindow = findUnderMouseInWindow(pi); + if (isSameOrAncestorOf(inTheSameWindow, allowChildren)) { + return pointRelativeToComponent(pi.getLocation()); + } + return null; + } + } + + + + /** + * Private version of findComponentAt which has a controllable + * behavior. Setting 'ignoreEnabled' to 'false' bypasses disabled + * Components during the search. This behavior is used by the + * lightweight cursor support in sun.awt.GlobalCursorManager. + * The cursor code calls this function directly via native code. + * + * The addition of this feature is temporary, pending the + * adoption of new, public API which exports this feature. + */ + final Component findComponentAt(int x, int y, boolean ignoreEnabled) + { + if (isRecursivelyVisible()){ + return findComponentAtImpl(x, y, ignoreEnabled); + } + return null; + } + + /** + * Determines whether this component will be displayed on the screen. + * @return <code>true</code> if the component and all of its ancestors + * until a toplevel window or null parent are visible, + * <code>false</code> otherwise + */ + boolean isRecursivelyVisible() { + return visible && (parent == null || parent.isRecursivelyVisible()); + } + + final Component findComponentAtImpl(int x, int y, boolean ignoreEnabled){ + if (!(contains(x, y) && visible && (ignoreEnabled || enabled))) { + return null; + } + int ncomponents = this.ncomponents; + Component component[] = this.component; + + // Two passes: see comment in sun.awt.SunGraphicsCallback + for (int i = 0 ; i < ncomponents ; i++) { + Component comp = component[i]; + if (comp != null && + !(comp.peer instanceof LightweightPeer)) { + if (comp instanceof Container) { + comp = ((Container)comp).findComponentAtImpl(x - comp.x, + y - comp.y, + ignoreEnabled); + } else { + comp = comp.locate(x - comp.x, y - comp.y); + } + if (comp != null && comp.visible && + (ignoreEnabled || comp.enabled)) + { + return comp; + } + } + } + for (int i = 0 ; i < ncomponents ; i++) { + Component comp = component[i]; + if (comp != null && + comp.peer instanceof LightweightPeer) { + if (comp instanceof Container) { + comp = ((Container)comp).findComponentAtImpl(x - comp.x, + y - comp.y, + ignoreEnabled); + } else { + comp = comp.locate(x - comp.x, y - comp.y); + } + if (comp != null && comp.visible && + (ignoreEnabled || comp.enabled)) + { + return comp; + } + } + } + return this; + } + + } // class Container Modified: trunk/core/src/classpath/java/java/awt/Dialog.java =================================================================== --- trunk/core/src/classpath/java/java/awt/Dialog.java 2007-07-07 12:37:26 UTC (rev 3353) +++ trunk/core/src/classpath/java/java/awt/Dialog.java 2007-07-07 12:38:26 UTC (rev 3354) @@ -552,4 +552,113 @@ { return next_dialog_number++; } + + //jnode openjdk +/** + * Modal dialogs block all input to some top-level windows. + * Whether a particular window is blocked depends on dialog's type + * of modality; this is called the "scope of blocking". The + * <code>ModalityType</code> enum specifies modal types and their + * associated scopes. + * + * @see Dialog#getModalityType + * @see Dialog#setModalityType + * @see Toolkit#isModalityTypeSupported + * + * @since 1.6 + */ + public static enum ModalityType { + /** + * <code>MODELESS</code> dialog doesn't block any top-level windows. + */ + MODELESS, + /** + * A <code>DOCUMENT_MODAL</code> dialog blocks input to all top-level windows + * from the same document except those from its own child hierarchy. + * A document is a top-level window without an owner. It may contain child + * windows that, together with the top-level window are treated as a single + * solid document. Since every top-level window must belong to some + * document, its root can be found as the top-nearest window without an owner. + */ + DOCUMENT_MODAL, + /** + * An <code>APPLICATION_MODAL</code> dialog blocks all top-level windows + * from the same Java application except those from its own child hierarchy. + * If there are several applets launched in a browser, they can be + * treated either as separate applications or a single one. This behavior + * is implementation-dependent. + */ + APPLICATION_MODAL, + /** + * A <code>TOOLKIT_MODAL</code> dialog blocks all top-level windows run + * from the same toolkit except those from its own child hierarchy. If there + * are several applets launched in a browser, all of them run with the same + * toolkit; thus, a toolkit-modal dialog displayed by an applet may affect + * other applets and all windows of the browser instance which embeds the + * Java runtime environment for this toolkit. + * Special <code>AWTPermission</code> "toolkitModality" must be granted to use + * toolkit-modal dialogs. If a <code>TOOLKIT_MODAL</code> dialog is being created + * and this permission is not granted, a <code>SecurityException</code> will be + * thrown, and no dialog will be created. If a modality type is being changed + * to <code>TOOLKIT_MODAL</code> and this permission is not granted, a + * <code>SecurityException</code> will be thrown, and the modality type will + * be left unchanged. + */ + TOOLKIT_MODAL + }; + + /** + * Default modality type for modal dialogs. The default modality type is + * <code>APPLICATION_MODAL</code>. Calling the oldstyle <code>setModal(true)</code> + * is equal to <code>setModalityType(DEFAULT_MODALITY_TYPE)</code>. + * + * @see java.awt.Dialog.ModalityType + * @see java.awt.Dialog#setModal + * + * @since 1.6 + */ + public final static ModalityType DEFAULT_MODALITY_TYPE = ModalityType.APPLICATION_MODAL; + + /** + * Any top-level window can be marked not to be blocked by modal + * dialogs. This is called "modal exclusion". This enum specifies + * the possible modal exclusion types. + * + * @see Window#getModalExclusionType + * @see Window#setModalExclusionType + * @see Toolkit#isModalExclusionTypeSupported + * + * @since 1.6 + */ + public static enum ModalExclusionType { + /** + * No modal exclusion. + */ + NO_EXCLUDE, + /** + * <code>APPLICATION_EXCLUDE</code> indicates that a top-level window + * won't be blocked by any application-modal dialogs. Also, it isn't + * blocked by document-modal dialogs from outside of its child hierarchy. + */ + APPLICATION_EXCLUDE, + /** + * <code>TOOLKIT_EXCLUDE</code> indicates that a top-level window + * won't be blocked by application-modal or toolkit-modal dialogs. Also, + * it isn't blocked by document-modal dialogs from outside of its + * child hierarchy. + * The "toolkitModality" <code>AWTPermission</code> must be granted + * for this exclusion. If an exclusion property is being changed to + * <code>TOOLKIT_EXCLUDE</code> and this permission is not granted, a + * <code>SecurityEcxeption</code> will be thrown, and the exclusion + * property will be left unchanged. + */ + TOOLKIT_EXCLUDE + }; + + /** + * @since 1.6 + */ + private final static ModalExclusionType DEFAULT_MODAL_EXCLUSION_TYPE = + ModalExclusionType.APPLICATION_EXCLUDE; + } Modified: trunk/core/src/classpath/java/java/awt/EventQueue.java =================================================================== --- trunk/core/src/classpath/java/java/awt/EventQueue.java 2007-07-07 12:37:26 UTC (rev 3353) +++ trunk/core/src/classpath/java/java/awt/EventQueue.java 2007-07-07 12:38:26 UTC (rev 3354) @@ -49,6 +49,7 @@ import java.awt.peer.ComponentPeer; import java.awt.peer.LightweightPeer; import java.lang.reflect.InvocationTargetException; +import java.lang.ref.WeakReference; import java.util.EmptyStackException; /* Written using on-line Java 2 Platform Standard Edition v1.3 API @@ -665,4 +666,46 @@ return System.currentTimeMillis(); return eq.lastWhen; } + + //jnode openjdk + static void setCurrentEventAndMostRecentTime(AWTEvent e) { + Toolkit.getEventQueue().setCurrentEventAndMostRecentTimeImpl(e); + } + private synchronized void setCurrentEventAndMostRecentTimeImpl(AWTEvent e) + { + if (Thread.currentThread() != dispatchThread) { + return; + } + + currentEvent = e; + + // This series of 'instanceof' checks should be replaced with a + // polymorphic type (for example, an interface which declares a + // getWhen() method). However, this would require us to make such + // a type public, or to place it in sun.awt. Both of these approaches + // have been frowned upon. So for now, we hack. + // + // In tiger, we will probably give timestamps to all events, so this + // will no longer be an issue. + long mostRecentEventTime2 = Long.MIN_VALUE; + if (e instanceof InputEvent) { + InputEvent ie = (InputEvent)e; + mostRecentEventTime2 = ie.getWhen(); + } else if (e instanceof InputMethodEvent) { + InputMethodEvent ime = (InputMethodEvent)e; + mostRecentEventTime2 = ime.getWhen(); + } else if (e instanceof ActionEvent) { + ActionEvent ae = (ActionEvent)e; + mostRecentEventTime2 = ae.getWhen(); + } else if (e instanceof InvocationEvent) { + InvocationEvent ie = (InvocationEvent)e; + mostRecentEventTime2 = ie.getWhen(); + } + mostRecentEventTime = Math.max(mostRecentEventTime, mostRecentEventTime2); + } + /* + * The time stamp of the last dispatched InputEvent or ActionEvent. + */ + private long mostRecentEventTime = System.currentTimeMillis(); + } Modified: trunk/core/src/classpath/java/java/awt/Font.java =================================================================== --- trunk/core/src/classpath/java/java/awt/Font.java 2007-07-07 12:37:26 UTC (rev 3353) +++ trunk/core/src/classpath/java/java/awt/Font.java 2007-07-07 12:38:26 UTC (rev 3354) @@ -61,6 +61,31 @@ import java.util.Locale; import java.util.Map; import java.util.StringTokenizer; +import sun.font.Font2DHandle; +import sun.font.AttributeValues; +import static sun.font.EAttribute.EFONT; +import static sun.font.EAttribute.EFAMILY; +import static sun.font.EAttribute.EWEIGHT; +import static sun.font.EAttribute.EWIDTH; +import static sun.font.EAttribute.EPOSTURE; +import static sun.font.EAttribute.ESIZE; +import static sun.font.EAttribute.ETRANSFORM; +import static sun.font.EAttribute.ESUPERSCRIPT; +import static sun.font.EAttribute.ETRACKING; +import static sun.font.EAttribute.ECHAR_REPLACEMENT; +import static sun.font.EAttribute.EFOREGROUND; +import static sun.font.EAttribute.EBACKGROUND; +import static sun.font.EAttribute.EUNDERLINE; +import static sun.font.EAttribute.ESTRIKETHROUGH; +import static sun.font.EAttribute.ERUN_DIRECTION; +import static sun.font.EAttribute.EBIDI_EMBEDDING; +import static sun.font.EAttribute.EJUSTIFICATION; +import static sun.font.EAttribute.EINPUT_METHOD_HIGHLIGHT; +import static sun.font.EAttribute.EINPUT_METHOD_UNDERLINE; +import static sun.font.EAttribute.ESWAP_COLORS; +import static sun.font.EAttribute.ENUMERIC_SHAPING; +import static sun.font.EAttribute.EKERNING; +import static sun.font.EAttribute.ELIGATURES; /** * This class represents a windowing system font. @@ -103,7 +128,49 @@ public static final int HANGING_BASELINE = 2; - /** + //jnode openjdk + /** + * A String constant for the canonical family name of the + * logical font "Dialog". It is useful in Font construction + * to provide compile-time verification of the name. + * @since 1.6 + */ + public static final String DIALOG = "Dialog"; + + /** + * A String constant for the canonical family name of the + * logical font "DialogInput". It is useful in Font construction + * to provide compile-time verification of the name. + * @since 1.6 + */ + public static final String DIALOG_INPUT = "DialogInput"; + + /** + * A String constant for the canonical family name of the + * logical font "SansSerif". It is useful in Font construction + * to provide compile-time verification of the name. + * @since 1.6 + */ + public static final String SANS_SERIF = "SansSerif"; + + /** + * A String constant for the canonical family name of the + * logical font "Serif". It is useful in Font construction + * to provide compile-time verification of the name. + * @since 1.6 + */ + public static final String SERIF = "Serif"; + + /** + * A String constant for the canonical family name of the + * logical font "Monospaced". It is useful in Font construction + * to provide compile-time verification of the name. + * @since 1.6 + */ + public static final String MONOSPACED = "Monospaced"; + + + /** * Indicates to <code>createFont</code> that the supplied font data * is in TrueType format. * @@ -1376,4 +1443,161 @@ peer = getPeerFromToolkit(name, attrs); } + + //jnode openjdk + /** + * Return true if this Font contains attributes that require extra + * layout processing. + * @return true if the font has layout attributes + * @since 1.6 + */ + public boolean hasLayoutAttributes() { + return hasLayoutAttributes; + } + private transient boolean hasLayoutAttributes; + private transient long pData; // native JDK1.1 font pointer + private transient Font2DHandle font2DHandle; + + private transient AttributeValues values; + + /* + * This is true if the font transform is not identity. It + * is used to avoid unnecessary instantiation of an AffineTransform. + */ + private transient boolean nonIdentityTx; + + /* + * If the origin of a Font is a created font then this attribute + * must be set on all derived fonts too. + */ + private transient boolean createdFont = false; + /** + * Creates a new <code>Font</code> from the specified <code>font</code>. + * This constructor is intended for use by subclasses. + * @param font from which to create this <code>Font</code>. + * @throws NullPointerException if <code>font</code> is null + * @since 1.6 + */ + protected Font(Font font) { + if (font.values != null) { + initFromValues(font.getAttributeValues().clone()); + } else { + this.name = font.name; + this.style = font.style; + this.size = font.size; + this.pointSize = font.pointSize; + } + this.font2DHandle = font.font2DHandle; + this.createdFont = font.createdFont; + } + + /** + * Initialize the standard Font fields from the values object. + */ + private void initFromValues(AttributeValues values) { + this.values = values; + values.defineAll(PRIMARY_MASK); // for 1.5 streaming compatibility + + this.name = values.getFamily(); + this.pointSize = values.getSize(); + this.size = (int)(values.getSize() + 0.5); + if (values.getWeight() >= 2f) this.style |= BOLD; // not == 2f + if (values.getPosture() >= .2f) this.style |= ITALIC; // not == .2f + + this.nonIdentityTx = values.anyNonDefault(EXTRA_MASK); + this.hasLayoutAttributes = values.anyNonDefault(LAYOUT_MASK); + } + + /** + * Return the AttributeValues object associated with this + * font. Most of the time, the internal object is null. + * If required, it will be created from the 'standard' + * state on the font. Only non-default values will be + * set in the AttributeValues object. + * + * <p>Since the AttributeValues object is mutable, and it + * is cached in the font, care must be taken to ensure that + * it is not mutated. + */ + private AttributeValues getAttributeValues() { + if (values == null) { + values = new AttributeValues(); + values.setFamily(name); + values.setSize(pointSize); // expects the float value. + + if ((style & BOLD) != 0) { + values.setWeight(2); // WEIGHT_BOLD + } + + if ((style & ITALIC) != 0) { + values.setPosture(.2f); // POSTURE_OBLIQUE + } + values.defineAll(PRIMARY_MASK); // for streaming compatibility + } + + return values; + } + + /** + * Font recognizes all attributes except FONT. + */ + private static final int RECOGNIZED_MASK = AttributeValues.MASK_ALL + & ~AttributeValues.getMask(EFONT); + + /** + * These attributes are considered primary by the FONT attribute. + */ + private static final int PRIMARY_MASK = + AttributeValues.getMask(EFAMILY, EWEIGHT, EWIDTH, EPOSTURE, ESIZE, + ETRANSFORM, ESUPERSCRIPT, ETRACKING); + + /** + * These attributes are considered secondary by the FONT attribute. + */ + private static final int SECONDARY_MASK = + RECOGNIZED_MASK & ~PRIMARY_MASK; + + /** + * These attributes are handled by layout. + */ + private static final int LAYOUT_MASK = + AttributeValues.getMask(ECHAR_REPLACEMENT, EFOREGROUND, EBACKGROUND, + EUNDERLINE, ESTRIKETHROUGH, ERUN_DIRECTION, + EBIDI_EMBEDDING, EJUSTIFICATION, + EINPUT_METHOD_HIGHLIGHT, EINPUT_METHOD_UNDERLINE, + ESWAP_COLORS, ENUMERIC_SHAPING, EKERNING, + ELIGATURES, ETRACKING); + + private static final int EXTRA_MASK = + AttributeValues.getMask(ETRANSFORM, ESUPERSCRIPT, EWIDTH); + + + /** + * Checks if this <code>Font</code> has a glyph for the specified + * character. + * + * @param codePoint the character (Unicode code point) for which a glyph + * is needed. + * @return <code>true</code> if this <code>Font</code> has a glyph for the + * character; <code>false</code> otherwise. + * @throws IllegalArgumentException if the code point is not a valid Unicode + * code point. + * @see Character#isValidCodePoint(int) + * @since 1.5 + */ + public boolean canDisplay(int codePoint) { + /* + if (!Character.isValidCodePoint(codePoint)) { + throw new IllegalArgumentException("invalid code point: " + + Integer.toHexString(codePoint)); + } + return getFont2D().canDisplay(codePoint); + */ + if (!Character.isValidCodePoint(codePoint)) { + throw new IllegalArgumentException("invalid code point: " + + Integer.toHexString(codePoint)); + } + return canDisplay((char) codePoint); + } + } Modified: trunk/core/src/classpath/java/java/awt/FontMetrics.java =================================================================== --- trunk/core/src/classpath/java/java/awt/FontMetrics.java 2007-07-07 12:37:26 UTC (rev 3353) +++ trunk/core/src/classpath/java/java/awt/FontMetrics.java 2007-07-07 12:38:26 UTC (rev 3354) @@ -445,4 +445,23 @@ { return font.hasUniformLineMetrics(); } + + //jnode openjdk + /** + * Gets the <code>FontRenderContext</code> used by this + * <code>FontMetrics</code> object to measure text. + * <p> + * Note that methods in this class which take a <code>Graphics</code> + * parameter measure text using the <code>FontRenderContext</code> + * of that <code>Graphics</code> object, and not this + * <code>FontRenderContext</code> + * @return the <code>FontRenderContext</code> used by this + * <code>FontMetrics</code> object. + * @since 1.6 + */ + public FontRenderContext getFontRenderContext() { + return DEFAULT_FRC; + } + private static final FontRenderContext + DEFAULT_FRC = new FontRenderContext(null, false, false); } Modified: trunk/core/src/classpath/java/java/awt/GraphicsConfiguration.java =================================================================== --- trunk/core/src/classpath/java/java/awt/GraphicsConfiguration.java 2007-07-07 12:37:26 UTC (rev 3353) +++ trunk/core/src/classpath/java/java/awt/GraphicsConfiguration.java 2007-07-07 12:38:26 UTC (rev 3354) @@ -44,6 +44,7 @@ import java.awt.image.BufferedImage; import java.awt.image.ColorModel; import java.awt.image.VolatileImage; +import java.awt.image.WritableRaster; /** * This class describes the configuration of various graphics devices, such @@ -101,19 +102,83 @@ */ public abstract BufferedImage createCompatibleImage(int w, int h); - /** - * Returns a buffered volatile image optimized to this device, so that - * blitting can be supported in the buffered image. Because the buffer is - * volatile, it can be optimized by native graphics accelerators. - * - * @param w the width of the buffer - * @param h the height of the buffer - * @return the buffered image, or null if none is supported - * @see Component#createVolatileImage(int, int) - * @since 1.4 - */ - public abstract VolatileImage createCompatibleVolatileImage(int w, int h); + //jnode openjdk + /** + * Returns a {@link VolatileImage} with a data layout and color model + * compatible with this <code>GraphicsConfiguration</code>. + * The returned <code>VolatileImage</code> + * may have data that is stored optimally for the underlying graphics + * device and may therefore benefit from platform-specific rendering + * acceleration. + * @param width the width of the returned <code>VolatileImage</code> + * @param height the height of the returned <code>VolatileImage</code> + * @return a <code>VolatileImage</code> whose data layout and color + * model is compatible with this <code>GraphicsConfiguration</code>. + * @see Component#createVolatileImage(int, int) + * @since 1.4 + */ + public VolatileImage createCompatibleVolatileImage(int width, int height) { + VolatileImage vi = null; + try { + vi = createCompatibleVolatileImage(width, height, + null, Transparency.OPAQUE); + } catch (AWTException e) { + // shouldn't happen: we're passing in null caps + assert false; + } + return vi; + } + /** + * Returns a {@link VolatileImage} with a data layout and color model + * compatible with this <code>GraphicsConfiguration</code>. + * The returned <code>VolatileImage</code> + * may have data that is stored optimally for the underlying graphics + * device and may therefore benefit from platform-specific rendering + * acceleration. + * @param width the width of the returned <code>VolatileImage</code> + * @param height the height of the returned <code>VolatileImage</code> + * @param transparency the specified transparency mode + * @return a <code>VolatileImage</code> whose data layout and color + * model is compatible with this <code>GraphicsConfiguration</code>. + * @throws IllegalArgumentException if the transparency is not a valid value + * @see Transparency#OPAQUE + * @see Transparency#BITMASK + * @see Transparency#TRANSLUCENT + * @see Component#createVolatileImage(int, int) + * @since 1.5 + */ + public VolatileImage createCompatibleVolatileImage(int width, int height, + int transparency) + { + VolatileImage vi = null; + try { + vi = createCompatibleVolatileImage(width, height, null, transparency); + } catch (AWTException e) { + // shouldn't happen: we're passing in null caps + assert false; + } + return vi; + } + + public VolatileImage createCompatibleVolatileImage(int width, int height, + ImageCapabilities caps, int transparency) throws AWTException + { + return null; + /* + VolatileImage vi = + new SunVolatileImage(this, width, height, transparency, caps); + if (caps != null && caps.isAccelerated() && + !vi.getCapabilities().isAccelerated()) + { + throw new AWTException("Supplied image capabilities could not " + + "be met by this graphics configuration."); + } + return vi; + */ + } + + /** * Returns a buffered volatile image optimized to this device, and with the * given capabilities, so that blitting can be supported in the buffered @@ -134,37 +199,42 @@ throw new AWTException("not implemented"); } - /** - * Returns a buffered volatile image optimized to this device, and - * with the given transparency. Because the buffer is volatile, it - * can be optimized by native graphics accelerators. - * - * @param width the width of the buffer - * @param height the height of the buffer - * @param transparency the transparency value for the buffer - * @return the buffered image, or null if none is supported - * @since 1.5 - */ - public abstract VolatileImage createCompatibleVolatileImage(int width, - int height, - int transparency); + /** + * Returns a <code>BufferedImage</code> that supports the specified + * transparency and has a data layout and color model + * compatible with this <code>GraphicsConfiguration</code>. This + * method has nothing to do with memory-mapping + * a device. The returned <code>BufferedImage</code> has a layout and + * color model that can be optimally blitted to a device + * with this <code>GraphicsConfiguration</code>. + * @param width the width of the returned <code>BufferedImage</code> + * @param height the height of the returned <code>BufferedImage</code> + * @param transparency the specified transparency mode + * @return a <code>BufferedImage</code> whose data layout and color + * model is compatible with this <code>GraphicsConfiguration</code> + * and also supports the specified transparency. + * @throws IllegalArgumentException if the transparency is not a valid value + * @see Transparency#OPAQUE + * @see Transparency#BITMASK + * @see Transparency#TRANSLUCENT + */ + public BufferedImage createCompatibleImage(int width, int height, + int transparency) + { + if (getColorModel().getTransparency() == transparency) { + return createCompatibleImage(width, height); + } + ColorModel cm = getColorModel(transparency); + if (cm == null) { + throw new IllegalArgumentException("Unknown transparency: " + + transparency); + } + WritableRaster wr = cm.createCompatibleWritableRaster(width, height); + return new BufferedImage(cm, wr, cm.isAlphaPremultiplied(), null); + } + /** - * Returns a buffered image optimized to this device, and with the specified - * transparency, so that blitting can be supported in the buffered image. - * - * @param w the width of the buffer - * @param h the height of the buffer - * @param transparency the transparency of the buffer - * @return the buffered image, or null if none is supported - * @see Transparency#OPAQUE - * @see Transparency#BITMASK - * @see Transparency#TRANSLUCENT - */ - public abstract BufferedImage createCompatibleImage(int w, int h, - int transparency); - - /** * Gets the color model of the corresponding device. * * @return the color model @@ -247,4 +317,5 @@ imageCapabilities = new ImageCapabilities(false); return imageCapabilities; } + } // class GraphicsConfiguration Modified: trunk/core/src/classpath/java/java/awt/PopupMenu.java =================================================================== --- trunk/core/src/classpath/java/java/awt/PopupMenu.java 2007-07-07 12:37:26 UTC (rev 3353) +++ trunk/core/src/classpath/java/java/awt/PopupMenu.java 2007-07-07 12:38:26 UTC (rev 3354) @@ -62,6 +62,8 @@ // Serialization Constant private static final long serialVersionUID = - 4620452533522760060L; + //jnode openjdk + transient boolean isTrayIconPopup = false; /*************************************************************************/ Modified: trunk/core/src/classpath/java/java/awt/Toolkit.java =================================================================== --- trunk/core/src/classpath/java/java/awt/Toolkit.java 2007-07-07 12:37:26 UTC (rev 3353) +++ trunk/core/src/classpath/java/java/awt/Toolkit.java 2007-07-07 12:38:26 UTC (rev 3354) @@ -81,6 +81,7 @@ import java.awt.peer.TextAreaPeer; import java.awt.peer.TextFieldPeer; import java.awt.peer.WindowPeer; +import java.awt.peer.DesktopPeer; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; import java.io.File; @@ -1414,4 +1415,78 @@ } + //jnode openjdk + private static boolean loaded = false; + static void loadLibraries() { + /* + if (!loaded) { + java.security.AccessController.doPrivileged( + new sun.security.action.LoadLibraryAction("awt")); + loaded = true; + } + */ + } + + /* Accessor method for use by AWT package routines. */ + static EventQueue getEventQueue() { + return getDefaultToolkit().getSystemEventQueueImpl(); + } + + /* + * This method notifies any AWTEventListeners that an event + * is about to be dispatched. + * + * @param theEvent the event which will be dispatched. + */ + void notifyAWTEventListeners(AWTEvent theEvent) { + // This is a workaround for headless toolkits. It would be + // better to override this method but it is declared package private. + // "this instanceof" syntax defeats polymorphism. + // --mm, 03/03/00 + if (this instanceof sun.awt.HeadlessToolkit) { + ((sun.awt.HeadlessToolkit)this).getUnderlyingToolkit() + .notifyAWTEventListeners(theEvent); + return; + } + + AWTEventListener eventListener = this.eventListener; + if (eventListener != null) { + eventListener.eventDispatched(theEvent); + } + } + private AWTEventListener eventListener = null; + + /** + * Returns whether the given modal exclusion type is supported by this + * toolkit. If an unsupported modal exclusion type property is set on a window, + * then <code>Dialog.ModalExclusionType.NO_EXCLUDE</code> is used instead. + * + * @param modalExclusionType modal exclusion type to be checked for support by this toolkit + * + * @return <code>true</code>, if current toolkit supports given modal exclusion + * type, <code>false</code> otherwise + * + * @see java.awt.Dialog.ModalExclusionType + * @see java.awt.Window#getModalExclusionType + * @see java.awt.Window#setModalExclusionType + * + * @since 1.6 + */ + public abstract boolean isModalExclusionTypeSupported(Dialog.ModalExclusionType modalExclusionType); + + /** + * Creates this toolkit's implementation of the <code>Desktop</code> + * using the specified peer interface. + * @param target the desktop to be implemented + * @return this toolkit's implementation of the <code>Desktop</code> + * @exception HeadlessException if GraphicsEnvironment.isHeadless() + * returns true + * @see java.awt.GraphicsEnvironment#isHeadless + * @see java.awt.Desktop + * @see java.awt.peer.DesktopPeer + * @since 1.6 + */ + protected abstract DesktopPeer createDesktopPeer(Desktop target) + throws HeadlessException; + } // class Toolkit Modified: trunk/core/src/classpath/java/java/awt/Window.java =================================================================== --- trunk/core/src/classpath/java/java/awt/Window.java 2007-07-07 12:37:26 UTC (rev 3353) +++ trunk/core/src/classpath/java/java/awt/Window.java 2007-07-07 12:38:26 UTC (rev 3354) @@ -54,12 +54,16 @@ import java.util.Locale; import java.util.ResourceBundle; import java.util.Vector; +import java.util.Arrays; +import java.util.ArrayList; import javax.accessibility.Accessible; import javax.accessibility.AccessibleContext; import javax.accessibility.AccessibleRole; import javax.accessibility.AccessibleState; import javax.accessibility.AccessibleStateSet; +import sun.security.util.SecurityConstants; +import sun.awt.AppContext; /** * This class represents a top-level window with no decorations. @@ -1343,4 +1347,214 @@ { return next_window_number++; } + + //jnode openjdk + + /** + * Specifies the modal exclusion type for this window. If a window is modal + * excluded, it is not blocked by some modal dialogs. See {@link + * java.awt.Dialog.ModalExclusionType Dialog.ModalExclusionType} for + * possible modal exclusion types. + * <p> + * If the given type is not supported, <code>NO_EXCLUDE</code> is used. + * <p> + * Note: changing the modal exclusion type for a visible window may have no + * effect until it is hidden and then shown again. + * + * @param exclusionType the modal exclusion type for this window; a <code>null</code> + * value is equivivalent to {@link Dialog.ModalExclusionType#NO_EXCLUDE + * NO_EXCLUDE} + * @throws SecurityException if the calling thread does not have permission + * to set the modal exclusion property to the window with the given + * <code>exclusionType</code> + * @see java.awt.Dialog.ModalExclusionType + * @see java.awt.Window#getModalExclusionType + * @see java.awt.Toolkit#isModalExclusionTypeSupported + * + * @since 1.6 + */ + public void setModalExclusionType(Dialog.ModalExclusionType exclusionType) { + if (exclusionType == null) { + exclusionType = Dialog.ModalExclusionType.NO_EXCLUDE; + } + if (!Toolkit.getDefaultToolkit().isModalExclusionTypeSupported(exclusionType)) { + exclusionType = Dialog.ModalExclusionType.NO_EXCLUDE; + } + if (modalExclusionType == exclusionType) { + return; + } + if (exclusionType == Dialog.ModalExclusionType.TOOLKIT_EXCLUDE) { + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + sm.checkPermission(SecurityConstants.TOOLKIT_MODALITY_PERMISSION); + } + } + modalExclusionType = exclusionType; + + // if we want on-fly changes, we need to uncomment the lines below + // and override the method in Dialog to use modalShow() instead + // of updateChildrenBlocking() + /* + if (isModalBlocked()) { + modalBlocker.unblockWindow(this); + } + Dialog.checkShouldBeBlocked(this); + updateChildrenBlocking(); + */ + } + /** + * @serial + * + * @see java.awt.Dialog.ModalExclusionType + * @see #getModalExclusionType + * @see #setModalExclusionType + * + * @since 1.6 + */ + Dialog.ModalExclusionType modalExclusionType; + + /** + * Returns the modal exclusion type of this window. + * + * @return the modal exclusion type of this window + * + * @see java.awt.Dialog.ModalExclusionType + * @see java.awt.Window#setModalExclusionType + * + * @since 1.6 + */ + public Dialog.ModalExclusionType getModalExclusionType() { + return modalExclusionType; + } + + /** + * Determines whether this component will be displayed on the screen. + * @return <code>true</code> if the component and all of its ancestors + * until a toplevel window are visible, <code>false</code> otherwise + */ + boolean isRecursivelyVisible() { + // 5079694 fix: for a toplevel to be displayed, its parent doesn't have to be visible. + // We're overriding isRecursivelyVisible to implement this policy. + return visible; + } + + /** + * Returns an array of all {@code Window}s created by this application + * that have no owner. They include {@code Frame}s and ownerless + * {@code Dialog}s and {@code Window}s. + * If called from an applet, the array includes only the {@code Window}s + * accessible by that applet. + * <p> + * <b>Warning:</b> this method may return system created windows, such + * as a print dialog. Applications should not assume the existence of + * these dialogs, nor should an application assume anything about these + * dialogs such as component positions, <code>LayoutManager</code>s + * or serialization. + * + * @see Frame#getFrames + * @see Window#getWindows() + * + * @since 1.6 + */ + public static Window[] getOwnerlessWindows() { + Window[] allWindows = Window.getWindows(); + + int ownerlessCount = 0; + for (Window w : allWindows) { + if (w.getOwner() == null) { + ownerlessCount++; + } + } + + Window[] ownerless = new Window[ownerlessCount]; + int c = 0; + for (Window w : allWindows) { + if (w.getOwner() == null) { + ownerless[c++] = w; + } + } + + return ownerless; + } + + /** + * Returns an array of all {@code Window}s, both owned and ownerless, + * created by this application. + * If called from an applet, the array includes only the {@code Window}s + * accessible by that applet. + * <p> + * <b>Warning:</b> this method may return system created windows, such + * as a print dialog. Applications should not assume the existence of + * these dialogs, nor should an application assume anything about these + * dialogs such as component positions, <code>LayoutManager</code>s + * or serialization. + * + * @see Frame#getFrames + * @see Window#getOwnerlessWindows + * + * @since 1.6 + */ + public static Window[] getWindows() { + return getWindows(AppContext.getAppContext()); + } + + private static Window[] getWindows(AppContext appContext) { + synchronized (Window.class) { + Window realCopy[]; + Vector<WeakReference<Window>> windowList = + (Vector<WeakReference<Window>>)appContext.get(Window.class); + if (windowList != null) { + int fullSize = windowList.size(); + int realSize = 0; + Window fullCopy[] = new Window[fullSize]; + for (int i = 0; i < fullSize; i++) { + Window w = windowList.get(i).get(); + if (w != null) { + fullCopy[realSize++] = w; + } + } + if (fullSize != realSize) { + realCopy = Arrays.copyOf(fullCopy, realSize); + } else { + realCopy = fullCopy; + } + } else { + realCopy = new Window[0]; + } + return realCopy; + } + } + + /** + * Returns the sequence of images to be displayed as the icon for this window. + * <p> + * This method returns a copy of the internally stored list, so all operations + * on the returned object will not affect the window's behavior. + * + * @return the copy of icon images' list for this window, or + * empty list if this window doesn't have icon images. + * @see #setIconImages + * @see #setIconImage(Image) + * @since 1.6 + */ + public java.util.List<Image> getIconImages() { + java.util.List<Image> icons = this.icons; + if (icons == null || icons.size() == 0) { + return new ArrayList<Image>(); + } + return new ArrayList<Image>(icons); + } + + /** + * {@code icons} is the graphical way we can + * represent the frames and dialogs. + * {@code Window} can't display icon but it's + * being inherited by owned {@code Dialog}s. + * + * @serial + * @see #getIconImages + * @see #setIconImages(List<? extends Image>) + */ + transient java.util.List<Image> icons; + } \ No newline at end of file Modified: trunk/core/src/classpath/java/java/awt/event/MouseEvent.java =================================================================== --- trunk/core/src/classpath/java/java/awt/event/MouseEvent.java 2007-07-07 12:37:26 UTC (rev 3353) +++ trunk/core/src/classpath/java/java/awt/event/MouseEvent.java 2007-07-07 12:38:26 UTC (rev 3354) @@ -432,4 +432,249 @@ modifiersEx = EventModifier.extend(modifiers) & EventModifier.NEW_MASK; } } + + //jndoe openjdk + /** + * Returns the absolute horizontal x position of the event. + * In a virtual device multi-screen environment in which the + * desktop area could span multiple physical screen devices, + * this coordinate is relative to the virtual coordinate system. + * Otherwise, this coordinate is relative to the coordinate system + * associated with the Component's GraphicsConfiguration. + * + * @return x an integer indicating absolute horizontal position. + * + * @see java.awt.GraphicsConfiguration + * @since 1.6 + */ + public int getXOnScreen() { + return xAbs; + } + + /** + * Returns the absolute vertical y position of the event. + * In a virtual device multi-screen environment in which the + * desktop area could span multiple physical screen devices, + * this coordinate is relative to the virtual coordinate system. + * Otherwise, this coordinate is relative to the coordinate system + * associated with the Component's GraphicsConfiguration. + * + * @return y an integer indicating absolute vertical position. + * + * @see java.awt.GraphicsConfiguration + * @since 1.6 + */ + public int getYOnScreen() { + return yAbs; + } + /** + * The mouse event's x absolute coordinate. + * In a virtual device multi-screen environment in which the + * desktop area could span multiple physical screen devices, + * this coordinate is relative to th... [truncated message content] |
From: <ls...@us...> - 2007-07-07 12:52:39
|
Revision: 3358 http://jnode.svn.sourceforge.net/jnode/?rev=3358&view=rev Author: lsantha Date: 2007-07-07 05:52:37 -0700 (Sat, 07 Jul 2007) Log Message: ----------- Openjdk integration. Removed Paths: ------------- trunk/core/src/classpath/java/java/awt/RenderingHints.java trunk/core/src/classpath/java/java/awt/font/FontRenderContext.java Deleted: trunk/core/src/classpath/java/java/awt/RenderingHints.java =================================================================== --- trunk/core/src/classpath/java/java/awt/RenderingHints.java 2007-07-07 12:47:46 UTC (rev 3357) +++ trunk/core/src/classpath/java/java/awt/RenderingHints.java 2007-07-07 12:52:37 UTC (rev 3358) @@ -1,804 +0,0 @@ -/* RenderingHints.java -- - Copyright (C) 2000, 2001, 2002, 2004, 2005 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - -/** - * A collection of (key, value) items that provide 'hints' for the - * {@link java.awt.Graphics2D} rendering pipeline. Because these - * items are hints only, they may be ignored by a particular - * {@link java.awt.Graphics2D} implementation. - * - * @author Rolf W. Rasmussen (ro...@ii...) - * @author Eric Blake (eb...@em...) - */ -public class RenderingHints - implements Map<Object,Object>, Cloneable -{ - /** - * The base class used to represent keys. - */ - public abstract static class Key - { - private final int key; - - /** - * Creates a new key. - * - * @param privateKey the private key. - */ - protected Key(int privateKey) - { - key = privateKey; - } - - /** - * Returns <code>true</code> if the specified value is compatible with - * this key, and <code>false</code> otherwise. - * - * @param value the value (<code>null</code> permitted). - * - * @return A boolean. - */ - public abstract boolean isCompatibleValue(Object value); - - /** - * Returns the private key for this instance. - * - * @return The private key. - */ - protected final int intKey() - { - return key; - } - - /** - * Returns a hash code for the key. - * - * @return A hash code. - */ - public final int hashCode() - { - return System.identityHashCode(this); - } - - /** - * Checks this key for equality with an arbitrary object. - * - * @param other the object (<code>null</code> permitted) - * - * @return A boolean. - */ - public final boolean equals(Object other) - { - return this == other; - } - } // class Key - - private static final class KeyImpl extends Key - { - final String description; - final Object v1; - final Object v2; - final Object v3; - - KeyImpl(int privateKey, String description, - Object v1, Object v2, Object v3) - { - super(privateKey); - this.description = description; - this.v1 = v1; - this.v2 = v2; - this.v3 = v3; - } - - /** - * Returns <code>true</code> if the specified value is compatible with - * this key, and <code>false</code> otherwise. - * - * @param value the value (<code>null</code> permitted). - * - * @return A boolean. - */ - public boolean isCompatibleValue(Object value) - { - return value == v1 || value == v2 || value == v3; - } - - /** - * Returns a string representation of the key. - * - * @return A string. - */ - public String toString() - { - return description; - } - } // class KeyImpl - - private HashMap hintMap = new HashMap(); - - /** - * A key for the 'antialiasing' hint. Permitted values are: - * <p> - * <table> - * <tr> - * <td>{@link #VALUE_ANTIALIAS_OFF}</td> - * <td>Render without antialiasing (better speed).</td> - * </tr> - * <tr> - * <td>{@link #VALUE_ANTIALIAS_ON}</td> - * <td>Render with antialiasing (better quality).</td> - * </tr> - * <tr> - * <td>{@link #VALUE_ANTIALIAS_DEFAULT}</td> - * <td>Use the default value for antialiasing.</td> - * </tr> - * </table> - */ - public static final Key KEY_ANTIALIASING; - - /** - * This value is for use with the {@link #KEY_ANTIALIASING} key. - */ - public static final Object VALUE_ANTIALIAS_ON - = "Antialiased rendering mode"; - - /** - * This value is for use with the {@link #KEY_ANTIALIASING} key. - */ - public static final Object VALUE_ANTIALIAS_OFF - = "Nonantialiased rendering mode"; - - /** - * This value is for use with the {@link #KEY_ANTIALIASING} key. - */ - public static final Object VALUE_ANTIALIAS_DEFAULT - = "Default antialiasing rendering mode"; - - /** - * A key for the 'rendering' hint. Permitted values are: - * <p> - * <table> - * <tr> - * <td>{@link #VALUE_RENDER_SPEED}</td> - * <td>Prefer speed over quality when rendering.</td> - * </tr> - * <tr> - * <td>{@link #VALUE_RENDER_QUALITY}</td> - * <td>Prefer quality over speed when rendering.</td> - * </tr> - * <tr> - * <td>{@link #VALUE_RENDER_DEFAULT}</td> - * <td>Use the default value for quality vs. speed when rendering.</td> - * </tr> - * </table> - */ - public static final Key KEY_RENDERING; - - /** - * This value is for use with the {@link #KEY_RENDERING} key. - */ - public static final Object VALUE_RENDER_SPEED - = "Fastest rendering methods"; - - /** - * This value is for use with the {@link #KEY_RENDERING} key. - */ - public static final Object VALUE_RENDER_QUALITY - = "Highest quality rendering methods"; - - /** - * This value is for use with the {@link #KEY_RENDERING} key. - */ - public static final Object VALUE_RENDER_DEFAULT - = "Default rendering methods"; - - /** - * A key for the 'dithering' hint. Permitted values are: - * <p> - * <table> - * <tr> - * <td>{@link #VALUE_DITHER_DISABLE}</td> - * <td>Disable dithering.</td> - * </tr> - * <tr> - * <td>{@link #VALUE_DITHER_ENABLE}</td> - * <td>Enable dithering.</td> - * </tr> - * <tr> - * <td>{@link #VALUE_DITHER_DEFAULT}</td> - * <td>Use the default value for dithering.</td> - * </tr> - * </table> - */ - public static final Key KEY_DITHERING; - - /** - * This value is for use with the {@link #KEY_DITHERING} key. - */ - public static final Object VALUE_DITHER_DISABLE - = "Nondithered rendering mode"; - - /** - * This value is for use with the {@link #KEY_DITHERING} key. - */ - public static final Object VALUE_DITHER_ENABLE - = "Dithered rendering mode"; - - /** - * This value is for use with the {@link #KEY_DITHERING} key. - */ - public static final Object VALUE_DITHER_DEFAULT - = "Default dithering mode"; - - /** - * A key for the 'text antialiasing' hint. Permitted values are: - * <p> - * <table> - * <tr> - * <td>{@link #VALUE_TEXT_ANTIALIAS_ON}</td> - * <td>Render text with antialiasing (better quality usually).</td> - * </tr> - * <tr> - * <td>{@link #VALUE_TEXT_ANTIALIAS_OFF}</td> - * <td>Render test without antialiasing (better speed).</td> - * </tr> - * <tr> - * <td>{@link #VALUE_TEXT_ANTIALIAS_DEFAULT}</td> - * <td>Use the default value for text antialiasing.</td> - * </tr> - * </table> - */ - public static final Key KEY_TEXT_ANTIALIASING; - - /** - * This value is for use with the {@link #KEY_TEXT_ANTIALIASING} key. - */ - public static final Object VALUE_TEXT_ANTIALIAS_ON - = "Antialiased text mode"; - - /** - * This value is for use with the {@link #KEY_TEXT_ANTIALIASING} key. - */ - public static final Object VALUE_TEXT_ANTIALIAS_OFF - = "Nonantialiased text mode"; - - /** - * This value is for use with the {@link #KEY_TEXT_ANTIALIASING} key. - */ - public static final Object VALUE_TEXT_ANTIALIAS_DEFAULT - = "Default antialiasing text mode"; - - /** - * A key for the 'fractional metrics' hint. Permitted values are: - * <p> - * <table> - * <tr> - * <td>{@link #VALUE_FRACTIONALMETRICS_OFF}</td> - * <td>Render text with fractional metrics off.</td> - * </tr> - * <tr> - * <td>{@link #VALUE_FRACTIONALMETRICS_ON}</td> - * <td>Render text with fractional metrics on.</td> - * </tr> - * <tr> - * <td>{@link #VALUE_FRACTIONALMETRICS_DEFAULT}</td> - * <td>Use the default value for fractional metrics.</td> - * </tr> - * </table> - */ - public static final Key KEY_FRACTIONALMETRICS; - - /** - * This value is for use with the {@link #KEY_FRACTIONALMETRICS} key. - */ - public static final Object VALUE_FRACTIONALMETRICS_OFF - = "Integer text metrics mode"; - - /** - * This value is for use with the {@link #KEY_FRACTIONALMETRICS} key. - */ - public static final Object VALUE_FRACTIONALMETRICS_ON - = "Fractional text metrics mode"; - - /** - * This value is for use with the {@link #KEY_FRACTIONALMETRICS} key. - */ - public static final Object VALUE_FRACTIONALMETRICS_DEFAULT - = "Default fractional text metrics mode"; - - /** - * A key for the 'interpolation' hint. Permitted values are: - * <p> - * <table> - * <tr> - * <td>{@link #VALUE_INTERPOLATION_NEAREST_NEIGHBOR}</td> - * <td>Use nearest neighbour interpolation.</td> - * </tr> - * <tr> - * <td>{@link #VALUE_INTERPOLATION_BILINEAR}</td> - * <td>Use bilinear interpolation.</td> - * </tr> - * <tr> - * <td>{@link #VALUE_INTERPOLATION_BICUBIC}</td> - * <td>Use bicubic interpolation.</td> - * </tr> - * </table> - */ - public static final Key KEY_INTERPOLATION; - - /** - * This value is for use with the {@link #KEY_INTERPOLATION} key. - */ - public static final Object VALUE_INTERPOLATION_NEAREST_NEIGHBOR - = "Nearest Neighbor image interpolation mode"; - - /** - * This value is for use with the {@link #KEY_INTERPOLATION} key. - */ - public static final Object VALUE_INTERPOLATION_BILINEAR - = "Bilinear image interpolation mode"; - - /** - * This value is for use with the {@link #KEY_INTERPOLATION} key. - */ - public static final Object VALUE_INTERPOLATION_BICUBIC - = "Bicubic image interpolation mode"; - - /** - * A key for the 'alpha interpolation' hint. Permitted values are: - * <p> - * <table> - * <tr> - * <td>{@link #VALUE_ALPHA_INTERPOLATION_SPEED}</td> - * <td>Prefer speed over quality.</td> - * </tr> - * <tr> - * <td>{@link #VALUE_ALPHA_INTERPOLATION_QUALITY}</td> - * <td>Prefer quality over speed.</td> - * </tr> - * <tr> - * <td>{@link #VALUE_ALPHA_INTERPOLATION_DEFAULT}</td> - * <td>Use the default setting.</td> - * </tr> - * </table> - */ - public static final Key KEY_ALPHA_INTERPOLATION; - - /** - * This value is for use with the {@link #KEY_ALPHA_INTERPOLATION} key. - */ - public static final Object VALUE_ALPHA_INTERPOLATION_SPEED - = "Fastest alpha blending methods"; - - /** - * This value is for use with the {@link #KEY_ALPHA_INTERPOLATION} key. - */ - public static final Object VALUE_ALPHA_INTERPOLATION_QUALITY - = "Highest quality alpha blending methods"; - - /** - * This value is for use with the {@link #KEY_ALPHA_INTERPOLATION} key. - */ - public static final Object VALUE_ALPHA_INTERPOLATION_DEFAULT - = "Default alpha blending methods"; - - /** - * A key for the 'color rendering' hint. Permitted values are: - * <p> - * <table> - * <tr> - * <td>{@link #VALUE_COLOR_RENDER_SPEED}</td> - * <td>Prefer speed over quality.</td> - * </tr> - * <tr> - * <td>{@link #VALUE_COLOR_RENDER_QUALITY}</td> - * <td>Prefer quality over speed.</td> - * </tr> - * <tr> - * <td>{@link #VALUE_COLOR_RENDER_DEFAULT}</td> - * <td>Use the default setting.</td> - * </tr> - * </table> - */ - public static final Key KEY_COLOR_RENDERING; - - /** - * This value is for use with the {@link #KEY_COLOR_RENDERING} key. - */ - public static final Object VALUE_COLOR_RENDER_SPEED - = "Fastest color rendering mode"; - - /** - * This value is for use with the {@link #KEY_COLOR_RENDERING} key. - */ - public static final Object VALUE_COLOR_RENDER_QUALITY - = "Highest quality color rendering mode"; - - /** - * This value is for use with the {@link #KEY_COLOR_RENDERING} key. - */ - public static final Object VALUE_COLOR_RENDER_DEFAULT - = "Default color rendering mode"; - - /** - * A key for the 'stroke control' hint. Permitted values are: - * <p> - * <table> - * <tr> - * <td>{@link #VALUE_STROKE_DEFAULT}</td> - * <td>Use the default setting.</td> - * </tr> - * <tr> - * <td>{@link #VALUE_STROKE_NORMALIZE}</td> - * <td>XXX</td> - * </tr> - * <tr> - * <td>{@link #VALUE_STROKE_PURE}</td> - * <td>XXX</td> - * </tr> - * </table> - */ - public static final Key KEY_STROKE_CONTROL; - - /** - * This value is for use with the {@link #KEY_STROKE_CONTROL} key. - */ - public static final Object VALUE_STROKE_DEFAULT - = "Default stroke normalization"; - - /** - * This value is for use with the {@link #KEY_STROKE_CONTROL} key. - */ - public static final Object VALUE_STROKE_NORMALIZE - = "Normalize strokes for consistent rendering"; - - /** - * This value is for use with the {@link #KEY_STROKE_CONTROL} key. - */ - public static final Object VALUE_STROKE_PURE - = "Pure stroke conversion for accurate paths"; - - static - { - KEY_ANTIALIASING = new KeyImpl(1, "Global antialiasing enable key", - VALUE_ANTIALIAS_ON, - VALUE_ANTIALIAS_OFF, - VALUE_ANTIALIAS_DEFAULT); - KEY_RENDERING = new KeyImpl(2, "Global rendering quality key", - VALUE_RENDER_SPEED, - VALUE_RENDER_QUALITY, - VALUE_RENDER_DEFAULT); - KEY_DITHERING = new KeyImpl(3, "Dithering quality key", - VALUE_DITHER_DISABLE, - VALUE_DITHER_ENABLE, - VALUE_DITHER_DEFAULT); - KEY_TEXT_ANTIALIASING - = new KeyImpl(4, "Text-specific antialiasing enable key", - VALUE_TEXT_ANTIALIAS_ON, - VALUE_TEXT_ANTIALIAS_OFF, - VALUE_TEXT_ANTIALIAS_DEFAULT); - KEY_FRACTIONALMETRICS = new KeyImpl(5, "Fractional metrics enable key", - VALUE_FRACTIONALMETRICS_OFF, - VALUE_FRACTIONALMETRICS_ON, - VALUE_FRACTIONALMETRICS_DEFAULT); - KEY_INTERPOLATION = new KeyImpl(6, "Image interpolation method key", - VALUE_INTERPOLATION_NEAREST_NEIGHBOR, - VALUE_INTERPOLATION_BILINEAR, - VALUE_INTERPOLATION_BICUBIC); - KEY_ALPHA_INTERPOLATION - = new KeyImpl(7, "Alpha blending interpolation method key", - VALUE_ALPHA_INTERPOLATION_SPEED, - VALUE_ALPHA_INTERPOLATION_QUALITY, - VALUE_ALPHA_INTERPOLATION_DEFAULT); - KEY_COLOR_RENDERING = new KeyImpl(8, "Color rendering quality key", - VALUE_COLOR_RENDER_SPEED, - VALUE_COLOR_RENDER_QUALITY, - VALUE_COLOR_RENDER_DEFAULT); - KEY_STROKE_CONTROL = new KeyImpl(9, "Stroke normalization control key", - VALUE_STROKE_DEFAULT, - VALUE_STROKE_NORMALIZE, - VALUE_STROKE_PURE); - } - - /** - * Creates a new collection of hints containing all the (key, value) pairs - * in the specified map. - * - * @param init a map containing a collection of hints (<code>null</code> - * permitted). - */ - public RenderingHints(Map<Key,?> init) - { - if (init != null) - putAll(init); - } - - /** - * Creates a new collection containing a single (key, value) pair. - * - * @param key the key. - * @param value the value. - */ - public RenderingHints(Key key, Object value) - { - put(key, value); - } - - /** - * Returns the number of hints in the collection. - * - * @return The number of hints. - */ - public int size() - { - return hintMap.size(); - } - - /** - * Returns <code>true</code> if there are no hints in the collection, - * and <code>false</code> otherwise. - * - * @return A boolean. - */ - public boolean isEmpty() - { - return hintMap.isEmpty(); - } - - /** - * Returns <code>true</code> if the collection of hints contains the - * specified key, and <code>false</code> otherwise. - * - * @param key the key (<code>null</code> not permitted). - * - * @return A boolean. - * - * @throws NullPointerException if <code>key</code> is <code>null</code>. - * @throws ClassCastException if <code>key</code> is not a {@link Key}. - */ - public boolean containsKey(Object key) - { - if (key == null) - throw new NullPointerException(); - // don't remove the cast, it is necessary to throw the required exception - return hintMap.containsKey((Key) key); - } - - /** - * Returns <code>true</code> if the collection of hints contains the - * specified value, and <code>false</code> otherwise. - * - * @param value the value. - * - * @return A boolean. - */ - public boolean containsValue(Object value) - { - return hintMap.containsValue(value); - } - - /** - * Returns the value associated with the specified key, or <code>null</code> - * if there is no value defined for the key. - * - * @param key the key (<code>null</code> permitted). - * - * @return The value (possibly <code>null</code>). - * - * @throws ClassCastException if <code>key</code> is not a {@link Key}. - * - * @see #containsKey(Object) - */ - public Object get(Object key) - { - // don't remove the cast, it is necessary to throw the required exception - return hintMap.get((Key) key); - } - - /** - * Adds a (key, value) pair to the collection of hints (if the - * collection already contains the specified key, then the - * value is updated). - * - * @param key the key. - * @param value the value. - * - * @return the previous value of the key or <code>null</code> if the key - * didn't have a value yet. - */ - public Object put(Object key, Object value) - { - if (key == null || value == null) - throw new NullPointerException(); - if (! ((Key) key).isCompatibleValue(value)) - throw new IllegalArgumentException(); - return hintMap.put(key, value); - } - - /** - * Adds all the hints from a collection to this collection. - * - * @param hints the hint collection. - */ - public void add(RenderingHints hints) - { - hintMap.putAll(hints); - } - - /** - * Clears all the hints from this collection. - */ - public void clear() - { - hintMap.clear(); - } - - /** - * Removes a hint from the collection. - * - * @param key the key. - * - * @return The value that was associated with the key, or <code>null</code> if - * the key was not part of the collection - * - * @throws ClassCastException if the key is not a subclass of - * {@link RenderingHints.Key}. - */ - public Object remove(Object key) - { - // don't remove the (Key) cast, it is necessary to throw the exception - // required by the spec - return hintMap.remove((Key) key); - } - - /** - * Adds a collection of (key, value) pairs to the collection. - * - * @param m a map containing (key, value) items. - * - * @throws ClassCastException if the map contains a key that is not - * a subclass of {@link RenderingHints.Key}. - * @throws IllegalArgumentException if the map contains a value that is - * not compatible with its key. - */ - public void putAll(Map<?,?> m) - { - // preprocess map to generate appropriate exceptions - Iterator iterator = m.keySet().iterator(); - while (iterator.hasNext()) - { - Key key = (Key) iterator.next(); - if (!key.isCompatibleValue(m.get(key))) - throw new IllegalArgumentException(); - } - // map is OK, update - hintMap.putAll(m); - } - - /** - * Returns a set containing the keys from this collection. - * - * @return A set of keys. - */ - public Set<Object> keySet() - { - return hintMap.keySet(); - } - - /** - * Returns a collection of the values from this hint collection. The - * collection is backed by the <code>RenderingHints</code> instance, - * so updates to one will affect the other. - * - * @return A collection of values. - */ - public Collection<Object> values() - { - return hintMap.values(); - } - - /** - * Returns a set of entries from the collection. - * - * @return A set of entries. - */ - public Set<Map.Entry<Object,Object>> entrySet() - { - return Collections.unmodifiableSet(hintMap.entrySet()); - } - - /** - * Checks this collection for equality with an arbitrary object. - * - * @param o the object (<code>null</code> permitted) - * - * @return A boolean. - */ - public boolean equals(Object o) - { - return hintMap.equals(o); - } - - /** - * Returns a hash code for the collection of hints. - * - * @return A hash code. - */ - public int hashCode() - { - return hintMap.hashCode(); - } - - /** - * Creates a clone of this instance. - * - * @return A clone. - */ - public Object clone() - { - try - { - RenderingHints copy = (RenderingHints) super.clone(); - copy.hintMap = (HashMap) hintMap.clone(); - return copy; - } - catch (CloneNotSupportedException e) - { - throw (Error) new InternalError().initCause(e); // Impossible - } - } - - /** - * Returns a string representation of this instance. - * - * @return A string. - */ - public String toString() - { - return hintMap.toString(); - } -} // class RenderingHints Deleted: trunk/core/src/classpath/java/java/awt/font/FontRenderContext.java =================================================================== --- trunk/core/src/classpath/java/java/awt/font/FontRenderContext.java 2007-07-07 12:47:46 UTC (rev 3357) +++ trunk/core/src/classpath/java/java/awt/font/FontRenderContext.java 2007-07-07 12:52:37 UTC (rev 3358) @@ -1,138 +0,0 @@ -/* FontRenderContext.java - Copyright (C) 2002, 2003 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt.font; - -import java.awt.geom.AffineTransform; - -/** - * @author Michael Koch - */ -public class FontRenderContext -{ - private AffineTransform affineTransform; - private boolean isAntiAliased; - private boolean usesFractionalMetrics; - - /** - * Construct a new <code>FontRenderContext</code>. - */ - protected FontRenderContext() - { - // Do nothing here. - } - - /** - * Construct a new <code>FontRenderContext</code>. - */ - public FontRenderContext (AffineTransform tx, boolean isAntiAliased, - boolean usesFractionalMetrics) - { - if (tx != null - && !tx.isIdentity ()) - { - this.affineTransform = new AffineTransform (tx); - } - - this.isAntiAliased = isAntiAliased; - this.usesFractionalMetrics = usesFractionalMetrics; - } - - public boolean equals (Object obj) - { - if (! (obj instanceof FontRenderContext)) - return false; - - return equals ((FontRenderContext) obj); - } - - public boolean equals (FontRenderContext rhs) - { - if (rhs == null) - return false; - - if (affineTransform == null && rhs.affineTransform != null - || affineTransform != null && rhs.affineTransform == null) - return false; - - return ((affineTransform == rhs.affineTransform - || affineTransform.equals (rhs.getTransform ())) - && isAntiAliased == rhs.isAntiAliased () - && usesFractionalMetrics == rhs.usesFractionalMetrics ()); - } - - - /** - * Retrieves the affine transform for scaling typographical points - * to raster pixels. - * - * @return a clone of the transform object. - */ - public AffineTransform getTransform () - { - if (affineTransform == null) - return new AffineTransform (); - else - return new AffineTransform (affineTransform); - } - - - /** - * Returns the hash code of the font render context. - */ - public int hashCode () - { - int code = ( isAntiAliased ? 1 : 0 ) + ( usesFractionalMetrics ? 2 : 0 ); - - if( affineTransform != null && !affineTransform.isIdentity() ) - code ^= affineTransform.hashCode(); - - return code; - } - - public boolean isAntiAliased () - { - return isAntiAliased; - } - - public boolean usesFractionalMetrics () - { - return usesFractionalMetrics; - } -} - This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ls...@us...> - 2007-08-11 14:33:16
|
Revision: 3387 http://jnode.svn.sourceforge.net/jnode/?rev=3387&view=rev Author: lsantha Date: 2007-08-11 07:32:55 -0700 (Sat, 11 Aug 2007) Log Message: ----------- Openjdk integration. Modified Paths: -------------- trunk/core/src/classpath/java/java/awt/AWTKeyStroke.java trunk/core/src/classpath/java/java/awt/AlphaComposite.java Modified: trunk/core/src/classpath/java/java/awt/AWTKeyStroke.java =================================================================== --- trunk/core/src/classpath/java/java/awt/AWTKeyStroke.java 2007-08-11 13:49:36 UTC (rev 3386) +++ trunk/core/src/classpath/java/java/awt/AWTKeyStroke.java 2007-08-11 14:32:55 UTC (rev 3387) @@ -92,8 +92,8 @@ /** The largest the keystroke cache can grow. */ private static final int MAX_CACHE_SIZE = 2048; - /** Prune stale entries. */ - protected boolean removeEldestEntry(Entry<AWTKeyStroke,AWTKeyStroke> + /** Prune stale entries. */ //jnode openjdk + protected boolean removeEldestEntry(Map.Entry<AWTKeyStroke,AWTKeyStroke> eldest) { return size() > MAX_CACHE_SIZE; Modified: trunk/core/src/classpath/java/java/awt/AlphaComposite.java =================================================================== --- trunk/core/src/classpath/java/java/awt/AlphaComposite.java 2007-08-11 13:49:36 UTC (rev 3386) +++ trunk/core/src/classpath/java/java/awt/AlphaComposite.java 2007-08-11 14:32:55 UTC (rev 3387) @@ -43,6 +43,7 @@ import java.awt.image.ColorModel; import java.util.LinkedHashMap; import java.util.Map; +import java.util.HashMap; /** * @@ -61,7 +62,7 @@ private static final int MAX_CACHE_SIZE = 2048; /** Prune stale entries. */ - protected boolean removeEldestEntry(Entry eldest) + protected boolean removeEldestEntry(Map.Entry eldest) //jnode openjdk { return size() > MAX_CACHE_SIZE; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ls...@us...> - 2007-08-27 17:41:11
|
Revision: 3415 http://jnode.svn.sourceforge.net/jnode/?rev=3415&view=rev Author: lsantha Date: 2007-08-25 12:27:54 -0700 (Sat, 25 Aug 2007) Log Message: ----------- Openjdk integration. Modified Paths: -------------- trunk/core/src/classpath/java/java/awt/Component.java trunk/core/src/classpath/java/java/awt/peer/ComponentPeer.java trunk/core/src/classpath/java/java/awt/peer/FramePeer.java Modified: trunk/core/src/classpath/java/java/awt/Component.java =================================================================== --- trunk/core/src/classpath/java/java/awt/Component.java 2007-08-25 19:26:55 UTC (rev 3414) +++ trunk/core/src/classpath/java/java/awt/Component.java 2007-08-25 19:27:54 UTC (rev 3415) @@ -4173,7 +4173,7 @@ */ public boolean isFocusTraversable() { - return enabled && visible && (peer == null || isLightweight() || peer.isFocusTraversable()); + return enabled && visible && (peer == null || isLightweight() || peer.isFocusable()); } /** Modified: trunk/core/src/classpath/java/java/awt/peer/ComponentPeer.java =================================================================== --- trunk/core/src/classpath/java/java/awt/peer/ComponentPeer.java 2007-08-25 19:26:55 UTC (rev 3414) +++ trunk/core/src/classpath/java/java/awt/peer/ComponentPeer.java 2007-08-25 19:27:54 UTC (rev 3415) @@ -64,6 +64,15 @@ */ public interface ComponentPeer { + //jnode openjdk + public static final int SET_LOCATION = 1, + SET_SIZE = 2, + SET_BOUNDS = 3, + SET_CLIENT_SIZE = 4, + RESET_OPERATION = 5, + NO_EMBEDDED_CHECK = (1 << 14), + DEFAULT_OPERATION = SET_BOUNDS; + /** * Returns the construction status of the specified image. This is called * by {@link Component#checkImage(Image, int, int, ImageObserver)}. @@ -200,14 +209,6 @@ /** * Returns <code>true</code> if the component can receive keyboard input - * focus. This is called from {@link Component#isFocusTraversable()}. - * - * @specnote Part of the earlier 1.1 API, replaced by isFocusable(). - */ - boolean isFocusTraversable(); - - /** - * Returns <code>true</code> if the component can receive keyboard input * focus. This is called from {@link Component#isFocusable()}. */ boolean isFocusable(); Modified: trunk/core/src/classpath/java/java/awt/peer/FramePeer.java =================================================================== --- trunk/core/src/classpath/java/java/awt/peer/FramePeer.java 2007-08-25 19:26:55 UTC (rev 3414) +++ trunk/core/src/classpath/java/java/awt/peer/FramePeer.java 2007-08-25 19:27:54 UTC (rev 3415) @@ -71,5 +71,7 @@ * @since 1.5 */ void setBoundsPrivate(int x, int y, int width, int height); + //jnode openjdk + Rectangle getBoundsPrivate(); } // interface FramePeer This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ls...@us...> - 2008-03-16 20:00:43
|
Revision: 3845 http://jnode.svn.sourceforge.net/jnode/?rev=3845&view=rev Author: lsantha Date: 2008-03-16 13:00:41 -0700 (Sun, 16 Mar 2008) Log Message: ----------- OpenJDK AWT & Swing integration. Modified Paths: -------------- trunk/core/src/classpath/java/java/awt/Toolkit.java Removed Paths: ------------- trunk/core/src/classpath/java/java/awt/AWTEvent.java trunk/core/src/classpath/java/java/awt/Component.java trunk/core/src/classpath/java/java/awt/Container.java trunk/core/src/classpath/java/java/awt/DefaultKeyboardFocusManager.java trunk/core/src/classpath/java/java/awt/Dialog.java trunk/core/src/classpath/java/java/awt/Frame.java trunk/core/src/classpath/java/java/awt/LightweightDispatcher.java trunk/core/src/classpath/java/java/awt/Window.java Deleted: trunk/core/src/classpath/java/java/awt/AWTEvent.java =================================================================== --- trunk/core/src/classpath/java/java/awt/AWTEvent.java 2008-03-16 13:55:01 UTC (rev 3844) +++ trunk/core/src/classpath/java/java/awt/AWTEvent.java 2008-03-16 20:00:41 UTC (rev 3845) @@ -1,570 +0,0 @@ - -/* AWTEvent.java -- the root event in AWT - Copyright (C) 1999, 2000, 2002, 2005 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.awt.event.*; -import java.util.EventObject; -import java.lang.reflect.Field; - -/** - * AWTEvent is the root event class for all AWT events in the JDK 1.1 event - * model. It supersedes the Event class from JDK 1.0. Subclasses outside of - * the java.awt package should have IDs greater than RESERVED_ID_MAX. - * - * <p>Event masks defined here are used by components in - * <code>enableEvents</code> to select event types not selected by registered - * listeners. Event masks are appropriately set when registering on - * components. - * - * @author Warren Levy (wa...@cy...) - * @author Aaron M. Renn (ar...@ur...) - * @since 1.1 - * @status updated to 1.4 - */ -public abstract class AWTEvent extends EventObject -{ - /** - * Compatible with JDK 1.1+. - */ - private static final long serialVersionUID = -1825314779160409405L; - - transient boolean focusManagerIsDispatching = false; - transient boolean isPosted; - /** - * The ID of the event. - * - * @see #getID() - * @see #AWTEvent(Object, int) - * @serial the identifier number of this event - */ - protected int id; - - /** - * Indicates if the event has been consumed. False mean it is passed to - * the peer, true means it has already been processed. Semantic events - * generated by low-level events always have the value true. - * - * @see #consume() - * @see #isConsumed() - * @serial whether the event has been consumed - */ - protected boolean consumed; - - /** - * Used for implementing a simple linked list in EventQueue. - */ - transient AWTEvent queueNext; - - /** - * Who knows? It's in the serial version. - * - * @serial No idea what this is for. - */ - byte[] bdata; - - /** - * Indicates if this event is dispatched by the KeyboardFocusManager. - */ - boolean isFocusManagerEvent = false; - - /** Mask for selecting component events. */ - public static final long COMPONENT_EVENT_MASK = 0x00001; - - /** Mask for selecting container events. */ - public static final long CONTAINER_EVENT_MASK = 0x00002; - - /** Mask for selecting component focus events. */ - public static final long FOCUS_EVENT_MASK = 0x00004; - - /** Mask for selecting keyboard events. */ - public static final long KEY_EVENT_MASK = 0x00008; - - /** Mask for mouse button events. */ - public static final long MOUSE_EVENT_MASK = 0x00010; - - /** Mask for mouse motion events. */ - public static final long MOUSE_MOTION_EVENT_MASK = 0x00020; - - /** Mask for window events. */ - public static final long WINDOW_EVENT_MASK = 0x00040; - - /** Mask for action events. */ - public static final long ACTION_EVENT_MASK = 0x00080; - - /** Mask for adjustment events. */ - public static final long ADJUSTMENT_EVENT_MASK = 0x00100; - - /** Mask for item events. */ - public static final long ITEM_EVENT_MASK = 0x00200; - - /** Mask for text events. */ - public static final long TEXT_EVENT_MASK = 0x00400; - - /** - * Mask for input method events. - * @since 1.3 - */ - public static final long INPUT_METHOD_EVENT_MASK = 0x00800; - - /** - * Mask if input methods are enabled. Package visible only. - */ - static final long INPUT_ENABLED_EVENT_MASK = 0x01000; - - /** - * Mask for paint events. - * @since 1.3 - */ - public static final long PAINT_EVENT_MASK = 0x02000; - - /** - * Mask for invocation events. - * @since 1.3 - */ - public static final long INVOCATION_EVENT_MASK = 0x04000; - - /** - * Mask for hierarchy events. - * @since 1.3 - */ - public static final long HIERARCHY_EVENT_MASK = 0x08000; - - /** - * Mask for hierarchy bounds events. - * @since 1.3 - */ - public static final long HIERARCHY_BOUNDS_EVENT_MASK = 0x10000; - - /** - * Mask for mouse wheel events. - * @since 1.4 - */ - public static final long MOUSE_WHEEL_EVENT_MASK = 0x20000; - - /** - * Mask for window state events. - * @since 1.4 - */ - public static final long WINDOW_STATE_EVENT_MASK = 0x40000; - - /** - * Mask for window focus events. - * @since 1.4 - */ - public static final long WINDOW_FOCUS_EVENT_MASK = 0x80000; - - /** - * This is the highest number for event ids that are reserved for use by - * the AWT system itself. Subclasses outside of java.awt should use higher - * ids. - */ - public static final int RESERVED_ID_MAX = 1999; - - - /** - * Initializes a new AWTEvent from the old Java 1.0 event object. - * - * @param event the old-style event - * @throws NullPointerException if event is null - */ - public AWTEvent(Event event) - { - this(event.target, event.id); - consumed = event.consumed; - } - - /** - * Create an event on the specified source object and id. - * - * @param source the object that caused the event - * @param id the event id - * @throws IllegalArgumentException if source is null - */ - public AWTEvent(Object source, int id) - { - super(source); - this.id = id; - } - - /** - * Retarget the event, such as converting a heavyweight component to a - * lightweight child of the original. This is not for general use, but - * is for event targeting systems like KeyboardFocusManager. - * - * @param source the new source - */ - public void setSource(Object source) - { - this.source = source; - } - - /** - * Returns the event type id. - * - * @return the id number of this event - */ - public int getID() - { - return id; - } - - /** - * Create a string that represents this event in the format - * <code>classname[eventstring] on sourcecomponentname</code>. - * - * @return a string representing this event - */ - public String toString () - { - String src; - if (source instanceof Component) - src = ((Component) source).getName(); - else if (source instanceof MenuComponent) - src = ((MenuComponent) source).getName(); - else if (source != null) - src = source.toString(); - else - src = "null"; - String string = getClass ().getName () + "[" + paramString () + "] on " - + src; - return string; - } - - /** - * Returns a string representation of the state of this event. It may be - * empty, but must not be null; it is implementation defined. - * - * @return a string representation of this event - */ - public String paramString() - { - return ""; - } - - /** - * Consumes this event so that it will not be processed in the default - * manner. - */ - protected void consume() - { - consumed = true; - } - - /** - * Tests whether not not this event has been consumed. A consumed event - * is not processed in the default manner. - * - * @return true if this event has been consumed - */ - protected boolean isConsumed() - { - return consumed; - } - - /** - * Converts an event id to the appropriate event mask. - * - * @param id the event id - * - * @return the event mask for the specified id - */ - static long eventIdToMask(int id) - { - long mask = 0; - switch (id) - { - case ActionEvent.ACTION_PERFORMED: - mask = ACTION_EVENT_MASK; - break; - case AdjustmentEvent.ADJUSTMENT_VALUE_CHANGED: - mask = ADJUSTMENT_EVENT_MASK; - break; - case ComponentEvent.COMPONENT_MOVED: - case ComponentEvent.COMPONENT_RESIZED: - case ComponentEvent.COMPONENT_SHOWN: - case ComponentEvent.COMPONENT_HIDDEN: - mask = COMPONENT_EVENT_MASK; - break; - case ContainerEvent.COMPONENT_ADDED: - case ContainerEvent.COMPONENT_REMOVED: - mask = CONTAINER_EVENT_MASK; - break; - case FocusEvent.FOCUS_GAINED: - case FocusEvent.FOCUS_LOST: - mask = FOCUS_EVENT_MASK; - break; - case InputMethodEvent.INPUT_METHOD_TEXT_CHANGED: - case InputMethodEvent.CARET_POSITION_CHANGED: - mask = INPUT_METHOD_EVENT_MASK; - break; - case InvocationEvent.INVOCATION_DEFAULT: - mask = INVOCATION_EVENT_MASK; - break; - case ItemEvent.ITEM_STATE_CHANGED: - mask = ITEM_EVENT_MASK; - break; - case KeyEvent.KEY_TYPED: - case KeyEvent.KEY_PRESSED: - case KeyEvent.KEY_RELEASED: - mask = KEY_EVENT_MASK; - break; - case MouseEvent.MOUSE_CLICKED: - case MouseEvent.MOUSE_PRESSED: - case MouseEvent.MOUSE_RELEASED: - mask = MOUSE_EVENT_MASK; - break; - case MouseEvent.MOUSE_MOVED: - case MouseEvent.MOUSE_ENTERED: - case MouseEvent.MOUSE_EXITED: - case MouseEvent.MOUSE_DRAGGED: - mask = MOUSE_MOTION_EVENT_MASK; - break; - case MouseEvent.MOUSE_WHEEL: - mask = MOUSE_WHEEL_EVENT_MASK; - break; - case PaintEvent.PAINT: - case PaintEvent.UPDATE: - mask = PAINT_EVENT_MASK; - break; - case TextEvent.TEXT_VALUE_CHANGED: - mask = TEXT_EVENT_MASK; - break; - case WindowEvent.WINDOW_OPENED: - case WindowEvent.WINDOW_CLOSING: - case WindowEvent.WINDOW_CLOSED: - case WindowEvent.WINDOW_ICONIFIED: - case WindowEvent.WINDOW_DEICONIFIED: - case WindowEvent.WINDOW_ACTIVATED: - case WindowEvent.WINDOW_DEACTIVATED: - mask = WINDOW_EVENT_MASK; - break; - case WindowEvent.WINDOW_GAINED_FOCUS: - case WindowEvent.WINDOW_LOST_FOCUS: - mask = WINDOW_FOCUS_EVENT_MASK; - break; - case WindowEvent.WINDOW_STATE_CHANGED: - mask = WINDOW_STATE_EVENT_MASK; - break; - default: - mask = 0; - } - return mask; - } - - //jnode openjdk -/** - * Converts a new event to an old one (used for compatibility). - * If the new event cannot be converted (because no old equivalent - * exists) then this returns null. - * - * Note: this method is here instead of in each individual new - * event class in java.awt.event because we don't want to make - * it public and it needs to be called from java.awt. - */ - Event convertToOld() { - Object src = getSource(); - int newid = id; - - switch(id) { - case KeyEvent.KEY_PRESSED: - case KeyEvent.KEY_RELEASED: - KeyEvent ke = (KeyEvent)this; - if (ke.isActionKey()) { - newid = (id == KeyEvent.KEY_PRESSED? - Event.KEY_ACTION : Event.KEY_ACTION_RELEASE); - } - int keyCode = ke.getKeyCode(); - if (keyCode == KeyEvent.VK_SHIFT || - keyCode == KeyEvent.VK_CONTROL || - keyCode == KeyEvent.VK_ALT) { - return null; // suppress modifier keys in old event model. - } - // no mask for button1 existed in old Event - strip it out - return new Event(src, ke.getWhen(), newid, 0, 0, - Event.getOldEventKey(ke), - (ke.getModifiers() & ~InputEvent.BUTTON1_MASK)); - - case MouseEvent.MOUSE_PRESSED: - case MouseEvent.MOUSE_RELEASED: - case MouseEvent.MOUSE_MOVED: - case MouseEvent.MOUSE_DRAGGED: - case MouseEvent.MOUSE_ENTERED: - case MouseEvent.MOUSE_EXITED: - MouseEvent me = (MouseEvent)this; - // no mask for button1 existed in old Event - strip it out - Event olde = new Event(src, me.getWhen(), newid, - me.getX(), me.getY(), 0, - (me.getModifiers() & ~InputEvent.BUTTON1_MASK)); - olde.clickCount = me.getClickCount(); - return olde; - - case FocusEvent.FOCUS_GAINED: - return new Event(src, Event.GOT_FOCUS, null); - - case FocusEvent.FOCUS_LOST: - return new Event(src, Event.LOST_FOCUS, null); - - case WindowEvent.WINDOW_CLOSING: - case WindowEvent.WINDOW_ICONIFIED: - case WindowEvent.WINDOW_DEICONIFIED: - return new Event(src, newid, null); - - case ComponentEvent.COMPONENT_MOVED: - if (src instanceof Frame || src instanceof Dialog) { - Point p = ((Component)src).getLocation(); - return new Event(src, 0, Event.WINDOW_MOVED, p.x, p.y, 0, 0); - } - break; - - case ActionEvent.ACTION_PERFORMED: - ActionEvent ae = (ActionEvent)this; - String cmd; - if (src instanceof Button) { - cmd = ((Button)src).getLabel(); - } else if (src instanceof MenuItem) { - cmd = ((MenuItem)src).getLabel(); - } else { - cmd = ae.getActionCommand(); - } - return new Event(src, 0, newid, 0, 0, 0, ae.getModifiers(), cmd); - - case ItemEvent.ITEM_STATE_CHANGED: - ItemEvent ie = (ItemEvent)this; - Object arg; - if (src instanceof List) { - newid = (ie.getStateChange() == ItemEvent.SELECTED? - Event.LIST_SELECT : Event.LIST_DESELECT); - arg = ie.getItem(); - } else { - newid = Event.ACTION_EVENT; - if (src instanceof Choice) { - arg = ie.getItem(); - - } else { // Checkbox - arg = Boolean.valueOf(ie.getStateChange() == ItemEvent.SELECTED); - } - } - return new Event(src, newid, arg); - - case AdjustmentEvent.ADJUSTMENT_VALUE_CHANGED: - AdjustmentEvent aje = (AdjustmentEvent)this; - switch(aje.getAdjustmentType()) { - case AdjustmentEvent.UNIT_INCREMENT: - newid = Event.SCROLL_LINE_DOWN; - break; - case AdjustmentEvent.UNIT_DECREMENT: - newid = Event.SCROLL_LINE_UP; - break; - case AdjustmentEvent.BLOCK_INCREMENT: - newid = Event.SCROLL_PAGE_DOWN; - break; - case AdjustmentEvent.BLOCK_DECREMENT: - newid = Event.SCROLL_PAGE_UP; - break; - case AdjustmentEvent.TRACK: - if (aje.getValueIsAdjusting()) { - newid = Event.SCROLL_ABSOLUTE; - } - else { - newid = Event.SCROLL_END; - } - break; - default: - return null; - } - return new Event(src, newid, Integer.valueOf(aje.getValue())); - - default: - } - return null; - } - /** - * The pseudo event mask for enabling input methods. - * We're using one bit in the eventMask so we don't need - * a separate field inputMethodsEnabled. - */ - final static long INPUT_METHODS_ENABLED_MASK = 0x1000; - - /** - * Copies all private data from this event into that. - * Space is allocated for the copied data that will be - * freed when the that is finalized. Upon completion, - * this event is not changed. - */ - void copyPrivateDataInto(AWTEvent that) { - that.bdata = this.bdata; - // Copy canAccessSystemClipboard value from this into that. - if (this instanceof InputEvent && that instanceof InputEvent) { - Field field = get_InputEvent_CanAccessSystemClipboard(); - if (field != null) { - try { - boolean b = field.getBoolean(this); - field.setBoolean(that, b); - } catch(IllegalAccessException e) { - } - } - } - } - - private static synchronized Field get_InputEvent_CanAccessSystemClipboard() { - if (inputEvent_CanAccessSystemClipboard_Field == null) { - inputEvent_CanAccessSystemClipboard_Field = - (Field)java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public Object run() { - Field field = null; - try { - field = InputEvent.class. - getDeclaredField("canAccessSystemClipboard"); - field.setAccessible(true); - return field; - } catch (SecurityException e) { - } catch (NoSuchFieldException e) { - } - return null; - } - }); - } - - return inputEvent_CanAccessSystemClipboard_Field; - } - // security stuff - private static Field inputEvent_CanAccessSystemClipboard_Field = null; -} // class AWTEvent Deleted: trunk/core/src/classpath/java/java/awt/Component.java =================================================================== --- trunk/core/src/classpath/java/java/awt/Component.java 2008-03-16 13:55:01 UTC (rev 3844) +++ trunk/core/src/classpath/java/java/awt/Component.java 2008-03-16 20:00:41 UTC (rev 3845) @@ -1,7928 +0,0 @@ -/* Component.java -- a graphics component - Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2006 - Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -//import gnu.java.awt.dnd.peer.gtk.GtkDropTargetContextPeer; - -import java.awt.dnd.DropTarget; -import java.awt.event.*; -import java.awt.im.InputContext; -import java.awt.im.InputMethodRequests; -import java.awt.image.BufferStrategy; -import java.awt.image.ColorModel; -import java.awt.image.ImageObserver; -import java.awt.image.ImageProducer; -import java.awt.image.VolatileImage; -import java.awt.peer.ComponentPeer; -import java.awt.peer.LightweightPeer; -import java.awt.peer.ContainerPeer; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.PrintStream; -import java.io.PrintWriter; -import java.io.Serializable; -import java.lang.reflect.Array; -import java.util.Collections; -import java.util.EventListener; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Locale; -import java.util.Set; -import java.util.Vector; -import java.util.logging.Level; -import java.util.logging.Logger; - -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 sun.awt.*; -import sun.awt.im.CompositionArea; -import sun.awt.dnd.SunDropTargetEvent; -import sun.java2d.SunGraphics2D; - -/** - * The root of all evil. All graphical representations are subclasses of this - * giant class, which is designed for screen display and user interaction. - * This class can be extended directly to build a lightweight component (one - * not associated with a native window); lightweight components must reside - * inside a heavyweight window. - * - * <p>This class is Serializable, which has some big implications. A user can - * save the state of all graphical components in one VM, and reload them in - * another. Note that this class will only save Serializable listeners, and - * ignore the rest, without causing any serialization exceptions. However, by - * making a listener serializable, and adding it to another element, you link - * in that entire element to the state of this component. To get around this, - * use the idiom shown in the example below - make listeners non-serializable - * in inner classes, rather than using this object itself as the listener, if - * external objects do not need to save the state of this object. - * - * <pre> - * import java.awt.*; - * import java.awt.event.*; - * import java.io.Serializable; - * class MyApp implements Serializable - * { - * BigObjectThatShouldNotBeSerializedWithAButton bigOne; - * // Serializing aButton will not suck in an instance of MyApp, with its - * // accompanying field bigOne. - * Button aButton = new Button(); - * class MyActionListener implements ActionListener - * { - * public void actionPerformed(ActionEvent e) - * { - * System.out.println("Hello There"); - * } - * } - * MyApp() - * { - * aButton.addActionListener(new MyActionListener()); - * } - * } - * </pre> - * - * <p>Status: Incomplete. The event dispatch mechanism is implemented. All - * other methods defined in the J2SE 1.3 API javadoc exist, but are mostly - * incomplete or only stubs; except for methods relating to the Drag and - * Drop, Input Method, and Accessibility frameworks: These methods are - * present but commented out. - * - * @author original author unknown - * @author Eric Blake (eb...@em...) - * @since 1.0 - * @status still missing 1.4 support - */ -public abstract class Component - implements ImageObserver, MenuContainer, Serializable -{ - // Word to the wise - this file is huge. Search for '\f' (^L) for logical - // sectioning by fields, public API, private API, and nested classes. - - - /** - * Compatible with JDK 1.0+. - */ - private static final long serialVersionUID = -7644114512714619750L; - - /** - * Constant returned by the <code>getAlignmentY</code> method to indicate - * that the component wishes to be aligned to the top relative to - * other components. - * - * @see #getAlignmentY() - */ - public static final float TOP_ALIGNMENT = 0; - - /** - * Constant returned by the <code>getAlignmentY</code> and - * <code>getAlignmentX</code> methods to indicate - * that the component wishes to be aligned to the center relative to - * other components. - * - * @see #getAlignmentX() - * @see #getAlignmentY() - */ - public static final float CENTER_ALIGNMENT = 0.5f; - - /** - * Constant returned by the <code>getAlignmentY</code> method to indicate - * that the component wishes to be aligned to the bottom relative to - * other components. - * - * @see #getAlignmentY() - */ - public static final float BOTTOM_ALIGNMENT = 1; - - /** - * Constant returned by the <code>getAlignmentX</code> method to indicate - * that the component wishes to be aligned to the right relative to - * other components. - * - * @see #getAlignmentX() - */ - public static final float RIGHT_ALIGNMENT = 1; - - /** - * Constant returned by the <code>getAlignmentX</code> method to indicate - * that the component wishes to be aligned to the left relative to - * other components. - * - * @see #getAlignmentX() - */ - public static final float LEFT_ALIGNMENT = 0; - - /** - * Make the treelock a String so that it can easily be identified - * in debug dumps. We clone the String in order to avoid a conflict in - * the unlikely event that some other package uses exactly the same string - * as a lock object. - */ - static final Object LOCK = new String("AWT_TREE_LOCK"); - - /** - * The default maximum size. - */ - private static final Dimension DEFAULT_MAX_SIZE - = new Dimension(Short.MAX_VALUE, Short.MAX_VALUE); - - // Serialized fields from the serialization spec. - - /** - * The x position of the component in the parent's coordinate system. - * - * @see #getLocation() - * @serial the x position - */ - int x; - - /** - * The y position of the component in the parent's coordinate system. - * - * @see #getLocation() - * @serial the y position - */ - int y; - - /** - * The component width. - * - * @see #getSize() - * @serial the width - */ - int width; - - /** - * The component height. - * - * @see #getSize() - * @serial the height - */ - int height; - - /** - * The foreground color for the component. This may be null. - * - * @see #getForeground() - * @see #setForeground(Color) - * @serial the foreground color - */ - Color foreground; - - /** - * The background color for the component. This may be null. - * - * @see #getBackground() - * @see #setBackground(Color) - * @serial the background color - */ - Color background; - - /** - * The default font used in the component. This may be null. - * - * @see #getFont() - * @see #setFont(Font) - * @serial the font - */ - Font font; - - /** - * The font in use by the peer, or null if there is no peer. - * - * @serial the peer's font - */ - Font peerFont; - - /** - * The cursor displayed when the pointer is over this component. This may - * be null. - * - * @see #getCursor() - * @see #setCursor(Cursor) - */ - Cursor cursor; - - /** - * The locale for the component. - * - * @see #getLocale() - * @see #setLocale(Locale) - */ - Locale locale = Locale.getDefault (); - - /** - * True if the object should ignore repaint events (usually because it is - * not showing). - * - * @see #getIgnoreRepaint() - * @see #setIgnoreRepaint(boolean) - * @serial true to ignore repaints - * @since 1.4 - */ - boolean ignoreRepaint; - - /** - * True when the object is visible (although it is only showing if all - * ancestors are likewise visible). For component, this defaults to true. - * - * @see #isVisible() - * @see #setVisible(boolean) - * @serial true if visible - */ - boolean visible = true; - - /** - * True if the object is enabled, meaning it can interact with the user. - * For component, this defaults to true. - * - * @see #isEnabled() - * @see #setEnabled(boolean) - * @serial true if enabled - */ - boolean enabled = true; - - /** - * True if the object is valid. This is set to false any time a size - * adjustment means the component need to be layed out again. - * - * @see #isValid() - * @see #validate() - * @see #invalidate() - * @serial true if layout is valid - */ - boolean valid; - - /** - * The DropTarget for drag-and-drop operations. - * - * @see #getDropTarget() - * @see #setDropTarget(DropTarget) - * @serial the drop target, or null - * @since 1.2 - */ - DropTarget dropTarget; - - /** - * The list of popup menus for this component. - * - * @see #add(PopupMenu) - * @serial the list of popups - */ - Vector popups; - - /** - * The component's name. May be null, in which case a default name is - * generated on the first use. - * - * @see #getName() - * @see #setName(String) - * @serial the name - */ - String name; - - /** - * True once the user has set the name. Note that the user may set the name - * to null. - * - * @see #name - * @see #getName() - * @see #setName(String) - * @serial true if the name has been explicitly set - */ - boolean nameExplicitlySet; - - /** - * Indicates if the object can be focused. Defaults to true for components. - * - * @see #isFocusable() - * @see #setFocusable(boolean) - * @since 1.4 - */ - boolean focusable = true; - - /** - * Tracks whether this component's {@link #isFocusTraversable} - * method has been overridden. - * - * @since 1.4 - */ - int isFocusTraversableOverridden; - - /** - * The focus traversal keys, if not inherited from the parent or - * default keyboard focus manager. These sets will contain only - * AWTKeyStrokes that represent press and release events to use as - * focus control. - * - * @see #getFocusTraversalKeys(int) - * @see #setFocusTraversalKeys(int, Set) - * @since 1.4 - */ - Set[] focusTraversalKeys; - - /** - * True if focus traversal keys are enabled. This defaults to true for - * Component. If this is true, keystrokes in focusTraversalKeys are trapped - * and processed automatically rather than being passed on to the component. - * - * @see #getFocusTraversalKeysEnabled() - * @see #setFocusTraversalKeysEnabled(boolean) - * @since 1.4 - */ - boolean focusTraversalKeysEnabled = true; - - /** - * Cached information on the minimum size. Should have been transient. - * - * @serial ignore - */ - Dimension minSize; - - /** - * Flag indicating whether the minimum size for the component has been set - * by a call to {@link #setMinimumSize(Dimension)} with a non-null value. - */ - boolean minSizeSet; - - /** - * The maximum size for the component. - * @see #setMaximumSize(Dimension) - */ - Dimension maxSize; - - /** - * A flag indicating whether the maximum size for the component has been set - * by a call to {@link #setMaximumSize(Dimension)} with a non-null value. - */ - boolean maxSizeSet; - - /** - * Cached information on the preferred size. Should have been transient. - * - * @serial ignore - */ - Dimension prefSize; - - /** - * Flag indicating whether the preferred size for the component has been set - * by a call to {@link #setPreferredSize(Dimension)} with a non-null value. - */ - boolean prefSizeSet; - - /** - * Set to true if an event is to be handled by this component, false if - * it is to be passed up the hierarcy. - * - * @see #dispatchEvent(AWTEvent) - * @serial true to process event locally - */ - boolean newEventsOnly; - - /** - * Set by subclasses to enable event handling of particular events, and - * left alone when modifying listeners. For component, this defaults to - * enabling only input methods. - * - * @see #enableInputMethods(boolean) - * @see AWTEvent - * @serial the mask of events to process - */ - long eventMask = AWTEvent.INPUT_ENABLED_EVENT_MASK; - - /** - * Describes all registered PropertyChangeListeners. - * - * @see #addPropertyChangeListener(PropertyChangeListener) - * @see #removePropertyChangeListener(PropertyChangeListener) - * @see #firePropertyChange(String, Object, Object) - * @serial the property change listeners - * @since 1.2 - */ - PropertyChangeSupport changeSupport; - - /** - * True if the component has been packed (layed out). - * - * @serial true if this is packed - */ - boolean isPacked; - - /** - * The serialization version for this class. Currently at version 4. - * - * XXX How do we handle prior versions? - * - * @serial the serialization version - */ - int componentSerializedDataVersion = 4; - - /** - * The accessible context associated with this component. This is only set - * by subclasses. - * - * @see #getAccessibleContext() - * @serial the accessibility context - * @since 1.2 - */ - AccessibleContext accessibleContext; - - - // Guess what - listeners are special cased in serialization. See - // readObject and writeObject. - - /** Component listener chain. */ - transient ComponentListener componentListener; - - /** Focus listener chain. */ - transient FocusListener focusListener; - - /** Key listener chain. */ - transient KeyListener keyListener; - - /** Mouse listener chain. */ - transient MouseListener mouseListener; - - /** Mouse motion listener chain. */ - transient MouseMotionListener mouseMotionListener; - - /** - * Mouse wheel listener chain. - * - * @since 1.4 - */ - transient MouseWheelListener mouseWheelListener; - - /** - * Input method listener chain. - * - * @since 1.2 - */ - transient InputMethodListener inputMethodListener; - - /** - * Hierarcy listener chain. - * - * @since 1.3 - */ - transient HierarchyListener hierarchyListener; - - /** - * Hierarcy bounds listener chain. - * - * @since 1.3 - */ - transient HierarchyBoundsListener hierarchyBoundsListener; - - // Anything else is non-serializable, and should be declared "transient". - - /** The parent. */ - transient Container parent; - - /** The associated native peer. */ - transient ComponentPeer peer; - - /** The preferred component orientation. */ - transient ComponentOrientation componentOrientation = ComponentOrientation.UNKNOWN; - - /** - * The associated graphics configuration. - * - * @since 1.4 - */ - transient GraphicsConfiguration graphicsConfig; - - /** - * The buffer strategy for repainting. - * - * @since 1.4 - */ - transient BufferStrategy bufferStrategy; - - /** - * The number of hierarchy listeners of this container plus all of its - * children. This is needed for efficient handling of HierarchyEvents. - * These must be propagated to all child components with HierarchyListeners - * attached. To avoid traversal of the whole subtree, we keep track of - * the number of HierarchyListeners here and only walk the paths that - * actually have listeners. - */ - int numHierarchyListeners; - int numHierarchyBoundsListeners; - - /** - * true if requestFocus was called on this component when its - * top-level ancestor was not focusable. - */ - private transient FocusEvent pendingFocusRequest = null; - - /** - * The system properties that affect image updating. - */ - private static transient boolean incrementalDraw; - private static transient Long redrawRate; - - static - { - incrementalDraw = Boolean.getBoolean ("awt.image.incrementalDraw"); - redrawRate = Long.getLong ("awt.image.redrawrate"); - } - - // Public and protected API. - - /** - * Default constructor for subclasses. When Component is extended directly, - * it forms a lightweight component that must be hosted in an opaque native - * container higher in the tree. - */ - protected Component() - { - // Nothing to do here. - } - - /** - * Returns the name of this component. - * - * @return the name of this component - * @see #setName(String) - * @since 1.1 - */ - public String getName() - { - if (name == null && ! nameExplicitlySet) - name = generateName(); - return name; - } - - /** - * Sets the name of this component to the specified name (this is a bound - * property with the name 'name'). - * - * @param name the new name (<code>null</code> permitted). - * @see #getName() - * @since 1.1 - */ - public void setName(String name) - { - nameExplicitlySet = true; - String old = this.name; - this.name = name; - firePropertyChange("name", old, name); - } - - /** - * Returns the parent of this component. - * - * @return the parent of this component - */ - public Container getParent() - { - return parent; - } - - /** - * Returns the native windowing system peer for this component. Only the - * platform specific implementation code should call this method. - * - * @return the peer for this component - * @deprecated user programs should not directly manipulate peers; use - * {@link #isDisplayable()} instead - */ - // Classpath's Gtk peers rely on this. - public ComponentPeer getPeer() - { - return peer; - } - - /** - * Set the associated drag-and-drop target, which receives events when this - * is enabled. - * - * @param dt the new drop target - * @see #isEnabled() - */ - public void setDropTarget(DropTarget dt) - { - this.dropTarget = dt; - - if (peer != null) - dropTarget.addNotify(peer); - } - - /** - * Gets the associated drag-and-drop target, if there is one. - * - * @return the drop target - */ - public DropTarget getDropTarget() - { - return dropTarget; - } - - /** - * Returns the graphics configuration of this component, if there is one. - * If it has not been set, it is inherited from the parent. - * - * @return the graphics configuration, or null - * @since 1.3 - */ - public GraphicsConfiguration getGraphicsConfiguration() - { - return getGraphicsConfigurationImpl(); - } - - /** - * Returns the object used for synchronization locks on this component - * when performing tree and layout functions. - * - * @return the synchronization lock for this component - */ - public final Object getTreeLock() - { - return LOCK; - } - - /** - * Returns the toolkit in use for this component. The toolkit is associated - * with the frame this component belongs to. - * - * @return the toolkit for this component - */ - public Toolkit getToolkit() - { - // Only heavyweight peers can handle this. - ComponentPeer p = peer; - Component comp = this; - while (p instanceof LightweightPeer) - { - comp = comp.parent; - p = comp == null ? null : comp.peer; - } - - Toolkit tk = null; - if (p != null) - { - tk = peer.getToolkit(); - } - if (tk == null) - tk = Toolkit.getDefaultToolkit(); - return tk; - } - - /** - * Tests whether or not this component is valid. A invalid component needs - * to have its layout redone. - * - * @return true if this component is valid - * @see #validate() - * @see #invalidate() - */ - public boolean isValid() - { - // Tests show that components are invalid as long as they are not showing, even after validate() - // has been called on them. - return peer != null && valid; - } - - /** - * Tests if the component is displayable. It must be connected to a native - * screen resource. This reduces to checking that peer is not null. A - * containment hierarchy is made displayable when a window is packed or - * made visible. - * - * @return true if the component is displayable - * @see Container#add(Component) - * @see Container#remove(Component) - * @see Window#pack() - * @see Window#show() - * @see Window#dispose() - * @since 1.2 - */ - public boolean isDisplayable() - { - return peer != null; - } - - /** - * Tests whether or not this component is visible. Except for top-level - * frames, components are initially visible. - * - * @return true if the component is visible - * @see #setVisible(boolean) - */ - public boolean isVisible() - { - return visible; - } - - /** - * Tests whether or not this component is actually being shown on - * the screen. This will be true if and only if it this component is - * visible and its parent components are all visible. - * - * @return true if the component is showing on the screen - * @see #setVisible(boolean) - */ - public boolean isShowing() - { - Component par = parent; - return visible && peer != null && (par == null || par.isShowing()); - } - - /** - * Tests whether or not this component is enabled. Components are enabled - * by default, and must be enabled to receive user input or generate events. - * - * @return true if the component is enabled - * @see #setEnabled(boolean) - */ - public boolean isEnabled() - { - return enabled; - } - - /** - * Enables or disables this component. The component must be enabled to - * receive events (except that lightweight components always receive mouse - * events). - * - * @param enabled true to enable this component - * - * @see #isEnabled() - * @see #isLightweight() - * - * @since 1.1 - */ - public void setEnabled(boolean enabled) - { - enable(enabled); - } - - /** - * Enables this component. - * - * @deprecated use {@link #setEnabled(boolean)} instead - */ - public void enable() - { - if (! enabled) - { - // Need to lock the tree here, because the peers are involved. - synchronized (getTreeLock()) - { - enabled = true; - ComponentPeer p = peer; - if (p != null) - p.enable(); - } - } - } - - /** - * Enables or disables this component. - * - * @param enabled true to enable this component - * - * @deprecated use {@link #setEnabled(boolean)} instead - */ - public void enable(boolean enabled) - { - if (enabled) - enable(); - else - disable(); - } - - /** - * Disables this component. - * - * @deprecated use {@link #setEnabled(boolean)} instead - */ - public void disable() - { - if (enabled) - { - // Need to lock the tree here, because the peers are involved. - synchronized (getTreeLock()) - { - enabled = false; - ComponentPeer p = peer; - if (p != null) - p.disable(); - } - } - } - - /** - * Checks if this image is painted to an offscreen image buffer that is - * later copied to screen (double buffering reduces flicker). This version - * returns false, so subclasses must override it if they provide double - * buffering. - * - * @return true if this is double buffered; defaults to false - */ - public boolean isDoubleBuffered() - { - return false; - } - - /** - * Enables or disables input method support for this component. By default, - * components have this enabled. Input methods are given the opportunity - * to process key events before this component and its listeners. - * - * @param enable true to enable input method processing - * @see #processKeyEvent(KeyEvent) - * @since 1.2 - */ - public void enableInputMethods(boolean enable) - { - if (enable) - eventMask |= AWTEvent.INPUT_ENABLED_EVENT_MASK; - else - eventMask &= ~AWTEvent.INPUT_ENABLED_EVENT_MASK; - } - - /** - * Makes this component visible or invisible. Note that it wtill might - * not show the component, if a parent is invisible. - * - * @param visible true to make this component visible - * - * @see #isVisible() - * - * @since 1.1 - */ - public void setVisible(boolean visible) - { - // Inspection by subclassing shows that Sun's implementation calls - // show(boolean) which then calls show() or hide(). It is the show() - // method that is overriden in subclasses like Window. - show(visible); - } - - /** - * Makes this component visible on the screen. - * - * @deprecated use {@link #setVisible(boolean)} instead - */ - public void show() - { - // We must set visible before showing the peer. Otherwise the - // peer could post paint events before visible is true, in which - // case lightweight components are not initially painted -- - // Container.paint first calls isShowing () before painting itself - // and its children. - if(! visible) - { - // Need to lock the tree here to avoid races and inconsistencies. - synchronized (getTreeLock()) - { - visible = true; - // Avoid NullPointerExceptions by creating a local reference. - ComponentPeer currentPeer=peer; - if (currentPeer != null) - { - currentPeer.show(); - - // Fire HierarchyEvent. - fireHierarchyEvent(HierarchyEvent.HIERARCHY_CHANGED, - this, parent, - HierarchyEvent.SHOWING_CHANGED); - - // The JDK repaints the component before invalidating the parent. - // So do we. - if (peer instanceof LightweightPeer) - repaint(); - } - - // Only post an event if this component actually has a listener - // or has this event explicitly enabled. - if (componentListener != null - || (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0) - { - ComponentEvent ce = - new ComponentEvent(this,ComponentEvent.COMPONENT_SHOWN); - getToolkit().getSystemEventQueue().postEvent(ce); - } - } - - // Invalidate the parent if we have one. The component itself must - // not be invalidated. We also avoid NullPointerException with - // a local reference here. - Container currentParent = parent; - if (currentParent != null) - currentParent.invalidate(); - - } - } - - /** - * Makes this component visible or invisible. - * - * @param visible true to make this component visible - * - * @deprecated use {@link #setVisible(boolean)} instead - */ - public void show(boolean visible) - { - if (visible) - show(); - else - hide(); - } - - /** - * Hides this component so that it is no longer shown on the screen. - * - * @deprecated use {@link #setVisible(boolean)} instead - */ - public void hide() - { - if (visible) - { - // Need to lock the tree here to avoid races and inconsistencies. - synchronized (getTreeLock()) - { - visible = false; - - // Avoid NullPointerExceptions by creating a local reference. - ComponentPeer currentPeer=peer; - if (currentPeer != null) - { - currentPeer.hide(); - - // Fire hierarchy event. - fireHierarchyEvent(HierarchyEvent.HIERARCHY_CHANGED, - this, parent, - HierarchyEvent.SHOWING_CHANGED); - // The JDK repaints the component before invalidating the - // parent. So do we. This only applies for lightweights. - if (peer instanceof LightweightPeer) - repaint(); - } - - // Only post an event if this component actually has a listener - // or has this event explicitly enabled. - if (componentListener != null - || (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0) - { - ComponentEvent ce = - new ComponentEvent(this,ComponentEvent.COMPONENT_HIDDEN); - getToolkit().getSystemEventQueue().postEvent(ce); - } - } - - // Invalidate the parent if we have one. The component itself need - // not be invalidated. We also avoid NullPointerException with - // a local reference here. - Container currentParent = parent; - if (currentParent != null) - currentParent.invalidate(); - - } - } - - /** - * Returns this component's foreground color. If not set, this is inherited - * from the parent. - * - * @return this component's foreground color, or null - * @see #setForeground(Color) - */ - public Color getForeground() - { - if (foreground != null) - return foreground; - return parent == null ? null : parent.getForeground(); - } - - /** - * Sets this component's foreground color to the specified color. This is a - * bound property. - * - * @param c the new foreground color - * @see #getForeground() - */ - public void setForeground(Color c) - { - if (peer != null) - peer.setForeground(c); - - Color previous = foreground; - foreground = c; - firePropertyChange("foreground", previous, c); - } - - /** - * Tests if the foreground was explicitly set, or just inherited from the - * parent. - * - * @return true if the foreground has been set - * @since 1.4 - */ - public boolean isForegroundSet() - { - return foreground != null; - } - - /** - * Returns this component's background color. If not set, this is inherited - * from the parent. - * - * @return the background color of the component, or null - * @see #setBackground(Color) - */ - public Color getBackground() - { - if (background != null) - return background; - return parent == null ? null : parent.getBackground(); - } - - /** - * Sets this component's background color to the specified color. The parts - * of the component affected by the background color may by system dependent. - * This is a bound property. - * - * @param c the new background color - * @see #getBackground() - */ - public void setBackground(Color c) - { - // return if the background is already set to that color. - if ((c != null) && c.equals(background)) - return; - - Color previous = background; - background = c; - if (peer != null && c != null) - peer.setBackground(c); - firePropertyChange("background", previous, c); - } - - /** - * Tests if the background was explicitly set, or just inherited from the - * parent. - * - * @return true if the background has been set - * @since 1.4 - */ - public boolean isBackgroundSet() - { - return background != null; - } - - /** - * Returns the font in use for this component. If not set, this is inherited - * from the parent. - * - * @return the font for this component - * @see #setFont(Font) - */ - public Font getFont() - { - return getFontImpl(); - } - - /** - * Implementation of getFont(). This is pulled out of getFont() to prevent - * client programs from overriding this. - * - * @return the font of this component - */ - private final Font getFontImpl() - { - Font f = font; - if (f == null) - { - Component p = parent; - if (p != null) - f = p.getFontImpl(); - else - { - // It is important to return null here and not some kind of default - // font, otherwise the Swing UI would not install its fonts because - // it keeps non-UIResource fonts. - f = null; - } - } - return f; - } - - /** - * Sets the font for this component to the specified font. This is a bound - * property. - * - * @param f the new font for this component - * - * @see #getFont() - */ - public void setFont(Font f) - { - Font oldFont; - Font newFont; - // Synchronize on the tree because getFontImpl() relies on the hierarchy - // not beeing changed. - synchronized (getTreeLock()) - { - // Synchronize on this here to guarantee thread safety wrt to the - // property values. - synchronized (this) - { - oldFont = font; - font = f; - newFont = f; - } - // Create local variable here for thread safety. - ComponentPeer p = peer; - if (p != null) - { - // The peer receives the real font setting, which can depend on - // the parent font when this component's font has been set to null. - f = getFont(); - if (f != null) - { - p.setFont(f); - peerFont = f; - } - } - } - - // Fire property change event. - firePropertyChange("font", oldFont, newFont); - - // Invalidate when necessary as font changes can change the size of the - // component. - if (valid) - invalidate(); - } - - /** - * Tests if the font was explicitly set, or just inherited from the parent. - * - * @return true if the font has been set - * @since 1.4 - */ - public boolean isFontSet() - { - return font != null; - } - - /** - * Returns the locale for this component. If this component does not - * have a locale, the locale of the parent component is returned. - * - * @return the locale for this component - * @throws IllegalComponentStateException if it has no locale or parent - * @see #setLocale(Locale) - * @since 1.1 - */ - public Locale getLocale() - { - if (locale != null) - return locale; - if (parent == null) - throw new IllegalComponentStateException - ("Component has no parent: can't determine Locale"); - return parent.getLocale(); - } - - /** - * Sets the locale for this component to the specified locale. This is a - * bound property. - * - * @param newLocale the new locale for this component - */ - public void setLocale(Locale newLocale) - { - if (locale == newLocale) - return; - - Locale oldLocale = locale; - locale = newLocale; - firePropertyChange("locale", oldLocale, newLocale); - // New writing/layout direction or more/less room for localized labels. - invalidate(); - } - - /** - * Returns the color model of the device this componet is displayed on. - * - * @return this object's color model - * @see Toolkit#getColorModel() - */ - public ColorModel getColorModel() - { - GraphicsConfiguration config = getGraphicsConfiguration(); - return config != null ? config.getColorModel() - : getToolkit().getColorModel(); - } - - /** - * Returns the location of this component's top left corner relative to - * its parent component. This may be outdated, so for synchronous behavior, - * you should use a component listner. - * - * @return the location of this component - * @see #setLocation(int, int) - * @see #getLocationOnScreen() - * @since 1.1 - */ - public Point getLocation() - { - return location (); - } - - /** - * Returns the location of this component's top left corner in screen - * coordinates. - * - * @return the location of this component in screen coordinates - * @throws IllegalComponentStateException if the component is not showing - */ - public Point getLocationOnScreen() - { - if (! isShowing()) - throw new IllegalComponentStateException("component " - + getClass().getName() - + " not showing"); - // We know peer != null here. - return peer.getLocationOnScreen(); - } - - /** - * Returns the location of this component's top left corner relative to - * its parent component. - * - * @return the location of this component - * @deprecated use {@link #getLocation()} instead - */ - public Point location() - { - return new Point (x, y); - } - - /** - * Moves this component to the specified location, relative to the parent's - * coordinates. The coordinates are the new upper left corner of this - * component. - * - * @param x the new X coordinate of this component - * @param y the new Y coordinate of this component - * @see #getLocation() - * @see #setBounds(int, int, int, int) - */ - public void setLocation(int x, int y) - { - move (x, y); - } - - /** - * Moves this component to the specified location, relative to the parent's - * coordinates. The coordinates are the new upper left corner of this - * component. - * - * @param x the new X coordinate of this component - * @param y the new Y coordinate of this component - * @deprecated use {@link #setLocation(int, int)} instead - */ - public void move(int x, int y) - { - setBounds(x, y, this.width, this.height); - } - - /** - * Moves this component to the specified location, relative to the parent's - * coordinates. The coordinates are the new upper left corner of this - * component. - * - * @param p new coordinates for this component - * @throws NullPointerException if p is null - * @see #getLocation() - * @see #setBounds(int, int, int, int) - * @since 1.1 - */ - public void setLocation(Point p) - { - setLocation(p.x, p.y); - } - - /** - * Returns the size of this object. - * - * @return the size of this object - * @see #setSize(int, int) - * @since 1.1 - */ - public Dimension getSize() - { - return size (); - } - - /** - * Returns the size of this object. - * - * @return the size of this object - * @deprecated use {@link #getSize()} instead - */ - public Dimension size() - { - return new Dimension (width, height); - } - - /** - * Sets the size of this component to the specified width and height. - * - * @param width the new width of this component - * @param height the new height of this component - * @see #getSize() - * @see #setBounds(int, int, int, int) - */ - public void setSize(int width, int height) - { - resize (width, height); - } - - /** - * Sets the size of this component to the specified value. - * - * @param width the new width of the component - * @param height the new height of the component - * @deprecated use {@link #setSize(int, int)} instead - */ - public void resize(int width, int height) - { - setBounds(this.x, this.y, width, height); - } - - /** - * Sets the size of this component to the specified value. - * - * @param d the new size of this component - * @throws NullPointerException if d is null - * @see #setSize(int, int) - * @see #setBounds(int, int, int, int) - * @since 1.1 - */ - public void setSize(Dimension d) - { - resize (d); - } - - /** - * Sets the size of this component to the specified value. - * - * @param d the new size of this component - * @throws NullPointerException if d is null - * @deprecated use {@link #setSize(Dimension)} instead - */ - public void resize(Dimension d) - { - resize (d.width, d.height); - } - - /** - * Returns a bounding rectangle for this component. Note that the - * returned rectange is relative to this component's parent, not to - * the screen. - * ... [truncated message content] |
From: <ls...@us...> - 2008-03-16 20:25:31
|
Revision: 3856 http://jnode.svn.sourceforge.net/jnode/?rev=3856&view=rev Author: lsantha Date: 2008-03-16 13:25:30 -0700 (Sun, 16 Mar 2008) Log Message: ----------- OpenJDK AWT & Swing integration. Removed Paths: ------------- trunk/core/src/classpath/java/java/awt/Event.java trunk/core/src/classpath/java/java/awt/EventDispatchThread.java trunk/core/src/classpath/java/java/awt/EventQueue.java trunk/core/src/classpath/java/java/awt/KeyboardFocusManager.java Deleted: trunk/core/src/classpath/java/java/awt/Event.java =================================================================== --- trunk/core/src/classpath/java/java/awt/Event.java 2008-03-16 20:23:32 UTC (rev 3855) +++ trunk/core/src/classpath/java/java/awt/Event.java 2008-03-16 20:25:30 UTC (rev 3856) @@ -1,263 +0,0 @@ -/* Copyright (C) 1999, 2000, 2002 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.awt.event.KeyEvent; - -/** - * Written using on-line Java Platform 1.2 API Specification, as well - * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998). - * Status: Believed complete and correct. - */ - -public class Event implements java.io.Serializable -{ - static final long serialVersionUID = 5488922509400504703L; - - public static final int SHIFT_MASK = 1; - public static final int CTRL_MASK = 2; - public static final int META_MASK = 4; - public static final int ALT_MASK = 8; - - public static final int ACTION_EVENT = 1001; - public static final int BACK_SPACE = 8; - public static final int CAPS_LOCK = 1022; - public static final int DELETE = 127; - public static final int DOWN = 1005; - public static final int END = 1001; - public static final int ENTER = 10; - public static final int ESCAPE = 27; - public static final int F1 = 1008; - public static final int F10 = 1017; - public static final int F11 = 1018; - public static final int F12 = 1019; - public static final int F2 = 1009; - public static final int F3 = 1010; - public static final int F4 = 1011; - public static final int F5 = 1012; - public static final int F6 = 1013; - public static final int F7 = 1014; - public static final int F8 = 1015; - public static final int F9 = 1016; - public static final int GOT_FOCUS = 1004; - public static final int HOME = 1000; - public static final int INSERT = 1025; - public static final int KEY_ACTION = 403; - public static final int KEY_ACTION_RELEASE = 404; - public static final int KEY_PRESS = 401; - public static final int KEY_RELEASE = 402; - public static final int LEFT = 1006; - public static final int LIST_DESELECT = 702; - public static final int LIST_SELECT = 701; - public static final int LOAD_FILE = 1002; - public static final int LOST_FOCUS = 1005; - public static final int MOUSE_DOWN = 501; - public static final int MOUSE_DRAG = 506; - public static final int MOUSE_ENTER = 504; - public static final int MOUSE_EXIT = 505; - public static final int MOUSE_MOVE = 503; - public static final int MOUSE_UP = 502; - public static final int NUM_LOCK = 1023; - public static final int PAUSE = 1024; - public static final int PGDN = 1003; - public static final int PGUP = 1002; - public static final int PRINT_SCREEN = 1020; - public static final int RIGHT = 1007; - public static final int SAVE_FILE = 1003; - public static final int SCROLL_ABSOLUTE = 605; - public static final int SCROLL_BEGIN = 606; - public static final int SCROLL_END = 607; - public static final int SCROLL_LINE_DOWN = 602; - public static final int SCROLL_LINE_UP = 601; - public static final int SCROLL_LOCK = 1021; - public static final int SCROLL_PAGE_DOWN = 604; - public static final int SCROLL_PAGE_UP = 603; - public static final int TAB = 9; - public static final int UP = 1004; - public static final int WINDOW_DEICONIFY = 204; - public static final int WINDOW_DESTROY = 201; - public static final int WINDOW_EXPOSE = 202; - public static final int WINDOW_ICONIFY = 203; - public static final int WINDOW_MOVED = 205; - - public Object arg; - public int clickCount; - boolean consumed; // Required by serialization spec. - public Event evt; - public int id; - public int key; - public int modifiers; - public Object target; - public long when; - public int x; - public int y; - - public Event (Object target, int id, Object arg) - { - this.id = id; - this.target = target; - this.arg = arg; - } - - public Event (Object target, long when, int id, int x, int y, int key, - int modifiers) - { - this.target = target; - this.when = when; - this.id = id; - this.x = x; - this.y = y; - this.key = key; - this.modifiers = modifiers; - } - - public Event (Object target, long when, int id, int x, int y, int key, - int modifiers, Object arg) - { - this (target, when, id, x, y, key, modifiers); - this.arg = arg; - } - - public boolean controlDown () - { - return ((modifiers & CTRL_MASK) == 0 ? false : true); - } - - public boolean metaDown () - { - return ((modifiers & META_MASK) == 0 ? false : true); - } - - protected String paramString () - { - return "id=" + id + ",x=" + x + ",y=" + y - + ",target=" + target + ",arg=" + arg; - } - - public boolean shiftDown() - { - return ((modifiers & SHIFT_MASK) == 0 ? false : true); - } - - public String toString() - { - return getClass().getName() + "[" + paramString() + "]"; - } - - public void translate (int x, int y) - { - this.x += x; - this.y += y; - } - - //jnode openjdk -/* - * <b>NOTE:</b> The <code>Event</code> class is obsolete and is - * available only for backwards compatilibility. It has been replaced - * by the <code>AWTEvent</code> class and its subclasses. - * <p> - * Returns the integer key-code associated with the key in this event, - * as described in java.awt.Event. - */ -static int getOldEventKey(KeyEvent e) { - int keyCode = e.getKeyCode(); - for (int i = 0; i < actionKeyCodes.length; i++) { - if (actionKeyCodes[i][0] == keyCode) { - return actionKeyCodes[i][1]; - } - } - return (int)e.getKeyChar(); -} - -/* table for mapping old Event action keys to KeyEvent virtual keys. */ -private static final int actionKeyCodes[][] = { -/* virtual key action key */ - { KeyEvent.VK_HOME, Event.HOME }, - { KeyEvent.VK_END, Event.END }, - { KeyEvent.VK_PAGE_UP, Event.PGUP }, - { KeyEvent.VK_PAGE_DOWN, Event.PGDN }, - { KeyEvent.VK_UP, Event.UP }, - { KeyEvent.VK_DOWN, Event.DOWN }, - { KeyEvent.VK_LEFT, Event.LEFT }, - { KeyEvent.VK_RIGHT, Event.RIGHT }, - { KeyEvent.VK_F1, Event.F1 }, - { KeyEvent.VK_F2, Event.F2 }, - { KeyEvent.VK_F3, Event.F3 }, - { KeyEvent.VK_F4, Event.F4 }, - { KeyEvent.VK_F5, Event.F5 }, - { KeyEvent.VK_F6, Event.F6 }, - { KeyEvent.VK_F7, Event.F7 }, - { KeyEvent.VK_F8, Event.F8 }, - { KeyEvent.VK_F9, Event.F9 }, - { KeyEvent.VK_F10, Event.F10 }, - { KeyEvent.VK_F11, Event.F11 }, - { KeyEvent.VK_F12, Event.F12 }, - { KeyEvent.VK_PRINTSCREEN, Event.PRINT_SCREEN }, - { KeyEvent.VK_SCROLL_LOCK, Event.SCROLL_LOCK }, - { KeyEvent.VK_CAPS_LOCK, Event.CAPS_LOCK }, - { KeyEvent.VK_NUM_LOCK, Event.NUM_LOCK }, - { KeyEvent.VK_PAUSE, Event.PAUSE }, - { KeyEvent.VK_INSERT, Event.INSERT } -}; - - /* - * <b>NOTE:</b> The <code>Event</code> class is obsolete and is - * available only for backwards compatilibility. It has been replaced - * by the <code>AWTEvent</code> class and its subclasses. - * <p> - * Returns a new KeyEvent char which corresponds to the int key - * of this old event. - */ - char getKeyEventChar() { - for (int i = 0; i < actionKeyCodes.length; i++) { - if (actionKeyCodes[i][1] == key) { - return KeyEvent.CHAR_UNDEFINED; - } - } - return (char)key; - } - - /** - * <b>NOTE:</b> The <code>Event</code> class is obsolete and is - * available only for backwards compatilibility. It has been replaced - * by the <code>AWTEvent</code> class and its subclasses. - */ - boolean isConsumed() { - return consumed; - } -} Deleted: trunk/core/src/classpath/java/java/awt/EventDispatchThread.java =================================================================== --- trunk/core/src/classpath/java/java/awt/EventDispatchThread.java 2008-03-16 20:23:32 UTC (rev 3855) +++ trunk/core/src/classpath/java/java/awt/EventDispatchThread.java 2008-03-16 20:25:30 UTC (rev 3856) @@ -1,117 +0,0 @@ -/* EventDispatchThread.java - - Copyright (C) 2000, 2002, 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -package java.awt; - -/** - * @author Bryce McKinlay - * @status believed complete, but untested. - */ -class EventDispatchThread extends Thread -{ - /** - * The default priority when no property has been set. - */ - private static final int DEFAULT_PRIORITY = NORM_PRIORITY + 1; - - private static int dispatchThreadNum; - - private EventQueue queue; - - EventDispatchThread(EventQueue queue) - { - super(); - setName("AWT-EventQueue-" + ++dispatchThreadNum); - this.queue = queue; - - int priority = DEFAULT_PRIORITY; - try - { - String priorityString = - System.getProperty("gnu.awt.dispatchthread.priority"); - if (priorityString != null) - { - priority = Integer.parseInt(priorityString); - } - } - catch (NumberFormatException ex) - { - // Ignore and use default. - } - setPriority(priority); - - // Make sure that an event dispatch thread is never a daemon thread. - setDaemon(false); - } - - public void run() - { - while (true) - { - try - { - AWTEvent evt = queue.getNextEvent(); - - KeyboardFocusManager manager; - manager = KeyboardFocusManager.getCurrentKeyboardFocusManager (); - - // Try to dispatch this event to the current keyboard focus - // manager. It will dispatch all FocusEvents, all - // WindowEvents related to focus, and all KeyEvents, - // returning true. Otherwise, it returns false and we - // dispatch the event normally. - if (!manager.dispatchEvent (evt)) - queue.dispatchEvent(evt); - } - catch (ThreadDeath death) - { - // If someone wants to kill us, let them. - return; - } - catch (InterruptedException ie) - { - // We are interrupted when we should finish executing - return; - } - catch (Throwable x) - { - System.err.println("Exception during event dispatch:"); - x.printStackTrace(System.err); - } - } - } -} Deleted: trunk/core/src/classpath/java/java/awt/EventQueue.java =================================================================== --- trunk/core/src/classpath/java/java/awt/EventQueue.java 2008-03-16 20:23:32 UTC (rev 3855) +++ trunk/core/src/classpath/java/java/awt/EventQueue.java 2008-03-16 20:25:30 UTC (rev 3856) @@ -1,759 +0,0 @@ -/* EventQueue.java -- - Copyright (C) 1999, 2000, 2001, 2002, 2003, 2005 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import gnu.java.awt.LowPriorityEvent; -import gnu.java.awt.peer.NativeEventLoopRunningEvent; - -import java.awt.event.*; -import java.awt.peer.ComponentPeer; -import java.awt.peer.LightweightPeer; -import java.lang.reflect.InvocationTargetException; -import java.util.EmptyStackException; - -/* Written using on-line Java 2 Platform Standard Edition v1.3 API - * Specification, as well as "The Java Class Libraries", 2nd edition - * (Addison-Wesley, 1998). - * Status: Believed complete, but untested. - */ - -/** - * This class manages a queue of <code>AWTEvent</code> objects that - * are posted to it. The AWT system uses only one event queue for all - * events. - * - * @author Bryce McKinlay - * @author Aaron M. Renn (ar...@ur...) - */ -public class EventQueue -{ - /** - * Indicates events that are processed with normal priority. This is normally - * all events except PaintEvents. - */ - private static final int NORM_PRIORITY = 0; - - /** - * Indicates events that are processed with lowes priority. This is normally - * all PaintEvents and LowPriorityEvents. - */ - private static final int LOW_PRIORITY = 1; - - /** - * Implements the actual queue. EventQueue has 2 internal queues for - * different priorities: - * 1 PaintEvents are always dispatched with low priority. - * 2. All other events are dispatched with normal priority. - * - * This makes sure that the actual painting (output) is performed _after_ all - * available input has been processed and that the paint regions are - * coalesced as much as possible. - */ - private class Queue - { - /** - * The first item in the queue. This is where events are popped from. - */ - AWTEvent queueHead; - - /** - * The last item. This is where events are posted to. - */ - AWTEvent queueTail; - } - - /** - * The three internal event queues. - * - * @see Queue - */ - private Queue[] queues; - - private EventQueue next; - private EventQueue prev; - private AWTEvent currentEvent; - private long lastWhen = System.currentTimeMillis(); - - private EventDispatchThread dispatchThread = new EventDispatchThread(this); - private boolean nativeLoopRunning = false; - private boolean shutdown = false; - - // @vm-specific allow JNode access from VMAwtAPI - synchronized void setShutdown (boolean b) - //synchronized private void setShutdown (boolean b) - { - shutdown = b; - } - - synchronized boolean isShutdown () - { - if (shutdown) - return true; - - // This is the exact self-shutdown condition specified in J2SE: - // http://java.sun.com/j2se/1.4.2/docs/api/java/awt/doc-files/AWTThreadIssues.html - - if (nativeLoopRunning) - return false; - - if (peekEvent() != null) - return false; - - Frame[] frames = Frame.getFrames(); - for (int i = 0; i < frames.length; ++i) - if (frames[i].isDisplayable()) - return false; - - return true; - } - - /** - * Initializes a new instance of <code>EventQueue</code>. - */ - public EventQueue() - { - queues = new Queue[2]; - queues[NORM_PRIORITY] = new Queue(); - queues[LOW_PRIORITY] = new Queue(); - } - - /** - * Returns the next event in the queue. This method will block until - * an event is available or until the thread is interrupted. - * - * @return The next event in the queue. - * - * @exception InterruptedException If this thread is interrupted while - * waiting for an event to be posted to the queue. - */ - public synchronized AWTEvent getNextEvent() - throws InterruptedException - { - if (next != null) - return next.getNextEvent(); - - AWTEvent res = getNextEventImpl(true); - - while (res == null) - { - if (isShutdown()) - { - // Explicitly set dispathThread to null. If we don't do - // this, there is a race condition where dispatchThread - // can be != null even after the event dispatch thread has - // stopped running. If that happens, then the - // dispatchThread == null check in postEventImpl will - // fail, and a new event dispatch thread will not be - // created, leaving invokeAndWaits waiting indefinitely. - dispatchThread = null; - - // Interrupt the event dispatch thread. - throw new InterruptedException(); - } - - wait(); - res = getNextEventImpl(true); - } - - return res; - } - - /** - * Fetches and possibly removes the next event from the internal queues. - * This method returns immediately. When all queues are empty, this returns - * <code>null</code>: - * - * @param remove <true> when the event should be removed from the queue, - * <code>false</code> otherwise - * - * @return the next event or <code>null</code> when all internal queues - * are empty - */ - private AWTEvent getNextEventImpl(boolean remove) - { - AWTEvent next = null; - for (int i = 0; i < queues.length && next == null; i++) - { - Queue q = queues[i]; - if (q.queueHead != null) - { - // Got an event, remove it. - next = q.queueHead; - if (remove) - { - // Unlink event from the queue. - q.queueHead = next.queueNext; - if (q.queueHead == null) - q.queueTail = null; - next.queueNext = null; - } - } - } - return next; - } - - /** - * Returns the next event in the queue without removing it from the queue. - * This method will block until an event is available or until the thread - * is interrupted. - * - * @return The next event in the queue. - * @specnote Does not block. Returns null if there are no events on the - * queue. - */ - public synchronized AWTEvent peekEvent() - { - if (next != null) - return next.peekEvent(); - - return getNextEventImpl(false); - } - - /** - * Returns the next event in the queue that has the specified id - * without removing it from the queue. - * This method will block until an event is available or until the thread - * is interrupted. - * - * @param id The event id to return. - * - * @return The next event in the queue. - * - * @specnote Does not block. Returns null if there are no matching events - * on the queue. - */ - public synchronized AWTEvent peekEvent(int id) - { - if (next != null) - return next.peekEvent(id); - - AWTEvent evt = null; - for (int i = 0; i < queues.length && evt == null; i++) - { - Queue q = queues[i]; - evt = q.queueHead; - while (evt != null && evt.id != id) - evt = evt.queueNext; - // At this point we either have found an event (evt != null -> exit - // for loop), or we have found no event (evt == null -> search next - // internal queue). - } - return evt; - } - - /** - * Posts a new event to the queue. - * - * @param evt The event to post to the queue. - * - * @exception NullPointerException If event is null. - */ - public void postEvent(AWTEvent evt) - { - postEventImpl(evt); - } - - /** - * Sorts events to their priority and calls - * {@link #postEventImpl(AWTEvent, int)}. - * - * @param evt the event to post - */ - private synchronized final void postEventImpl(AWTEvent evt) - { - int priority = NORM_PRIORITY; - if (evt instanceof PaintEvent || evt instanceof LowPriorityEvent) - priority = LOW_PRIORITY; - // TODO: Maybe let Swing RepaintManager events also be processed with - // low priority. - if (evt instanceof NativeEventLoopRunningEvent) - { - nativeLoopRunning = ((NativeEventLoopRunningEvent) evt).isRunning(); - notify(); - return; - } - postEventImpl(evt, priority); - } - - /** - * Actually performs the event posting. This is needed because the - * RI doesn't use the public postEvent() method when transferring events - * between event queues in push() and pop(). - * - * @param evt the event to post - * @param priority the priority of the event - */ - private final void postEventImpl(AWTEvent evt, int priority) - { - if (evt == null) - throw new NullPointerException(); - - if (next != null) - { - next.postEvent(evt); - return; - } - - Object source = evt.getSource(); - - Queue q = queues[priority]; - if (source instanceof Component) - { - // For PaintEvents, ask the ComponentPeer to coalesce the event - // when the component is heavyweight. - Component comp = (Component) source; - ComponentPeer peer = comp.peer; - if (peer != null && evt instanceof PaintEvent - && ! (peer instanceof LightweightPeer)) - peer.coalescePaintEvent((PaintEvent) evt); - - // Check for any events already on the queue with the same source - // and ID. - AWTEvent previous = null; - for (AWTEvent qevt = q.queueHead; qevt != null; qevt = qevt.queueNext) - { - Object src = qevt.getSource(); - if (qevt.id == evt.id && src == comp) - { - // If there are, call coalesceEvents on the source component - // to see if they can be combined. - Component srccmp = (Component) src; - AWTEvent coalescedEvt = srccmp.coalesceEvents(qevt, evt); - if (coalescedEvt != null) - { - // Yes. Replace the existing event with the combined event. - if (qevt != coalescedEvt) - { - if (previous != null) - { - assert previous.queueNext == qevt; - previous.queueNext = coalescedEvt; - } - else - { - assert q.queueHead == qevt; - q.queueHead = coalescedEvt; - } - coalescedEvt.queueNext = qevt.queueNext; - if (q.queueTail == qevt) - q.queueTail = coalescedEvt; - qevt.queueNext = null; - } - return; - } - } - previous = qevt; - } - } - - if (q.queueHead == null) - { - // We have an empty queue. Set this event both as head and as tail. - q.queueHead = evt; - q.queueTail = evt; - } - else - { - // Note: queueTail should not be null here. - q.queueTail.queueNext = evt; - q.queueTail = evt; - } - - if (dispatchThread == null || !dispatchThread.isAlive()) - { - dispatchThread = new EventDispatchThread(this); - dispatchThread.start(); - } - - notify(); - } - - /** - * Causes runnable to have its run method called in the dispatch thread of the - * EventQueue. This will happen after all pending events are processed. The - * call blocks until this has happened. This method will throw an Error if - * called from the event dispatcher thread. - * - * @exception InterruptedException If another thread has interrupted - * this thread. - * @exception InvocationTargetException If an exception is thrown when running - * runnable. - * - * @since 1.2 - */ - public static void invokeAndWait(Runnable runnable) - throws InterruptedException, InvocationTargetException - { - if (isDispatchThread ()) - throw new Error("Can't call invokeAndWait from event dispatch thread"); - - EventQueue eq = Toolkit.getDefaultToolkit().getSystemEventQueue(); - Object notifyObject = new Object(); - - InvocationEvent ie = - new InvocationEvent(eq, runnable, notifyObject, true); - - synchronized (notifyObject) - { - eq.postEvent(ie); - notifyObject.wait(); - } - - Exception exception; - - if ((exception = ie.getException()) != null) - throw new InvocationTargetException(exception); - } - - /** - * This arranges for runnable to have its run method called in the - * dispatch thread of the EventQueue. This will happen after all - * pending events are processed. - * - * @since 1.2 - */ - public static void invokeLater(Runnable runnable) - { - EventQueue eq = Toolkit.getDefaultToolkit().getSystemEventQueue(); - - InvocationEvent ie = - new InvocationEvent(eq, runnable, null, false); - - eq.postEvent(ie); - } - - /** - * Return true if the current thread is the current AWT event dispatch - * thread. - */ - public static boolean isDispatchThread() - { - EventQueue eq = Toolkit.getDefaultToolkit().getSystemEventQueue(); - - /* Find last EventQueue in chain */ - while (eq.next != null) - eq = eq.next; - - return (Thread.currentThread() == eq.dispatchThread); - } - - /** - * Return the event currently being dispatched by the event - * dispatch thread. If the current thread is not the event - * dispatch thread, this method returns null. - * - * @since 1.4 - */ - public static AWTEvent getCurrentEvent() - { - EventQueue eq = Toolkit.getDefaultToolkit().getSystemEventQueue(); - Thread ct = Thread.currentThread(); - - /* Find out if this thread is the dispatch thread for any of the - EventQueues in the chain */ - while (ct != eq.dispatchThread) - { - // Try next EventQueue, if any - if (eq.next == null) - return null; // Not an event dispatch thread - eq = eq.next; - } - - return eq.currentEvent; - } - - /** - * Allows a custom EventQueue implementation to replace this one. - * All pending events are transferred to the new queue. Calls to postEvent, - * getNextEvent, and peekEvent and others are forwarded to the pushed queue - * until it is removed with a pop(). - * - * @exception NullPointerException if newEventQueue is null. - */ - public synchronized void push(EventQueue newEventQueue) - { - if (newEventQueue == null) - throw new NullPointerException (); - - /* Make sure we are at the top of the stack because callers can - only get a reference to the one at the bottom using - Toolkit.getDefaultToolkit().getSystemEventQueue() */ - if (next != null) - { - next.push (newEventQueue); - return; - } - - /* Make sure we have a live dispatch thread to drive the queue */ - if (dispatchThread == null) - dispatchThread = new EventDispatchThread(this); - - synchronized (newEventQueue) - { - // The RI transfers the events without calling the new eventqueue's - // push(), but using getNextEvent(). - while (peekEvent() != null) - { - try - { - newEventQueue.postEventImpl(getNextEvent()); - } - catch (InterruptedException ex) - { - // What should we do with this? - ex.printStackTrace(); - } - } - newEventQueue.prev = this; - } - - next = newEventQueue; - } - - /** Transfer any pending events from this queue back to the parent queue that - * was previously push()ed. Event dispatch from this queue is suspended. - * - * @exception EmptyStackException If no previous push was made on this - * EventQueue. - */ - protected void pop() throws EmptyStackException - { - /* The order is important here, we must get the prev lock first, - or deadlock could occur as callers usually get here following - prev's next pointer, and thus obtain prev's lock before trying - to get this lock. */ - EventQueue previous = prev; - if (previous == null) - throw new EmptyStackException(); - synchronized (previous) - { - synchronized (this) - { - EventQueue nextQueue = next; - if (nextQueue != null) - { - nextQueue.pop(); - } - else - { - previous.next = null; - - // The RI transfers the events without calling the new eventqueue's - // push(), so this should be OK and most effective. - while (peekEvent() != null) - { - try - { - previous.postEventImpl(getNextEvent()); - } - catch (InterruptedException ex) - { - // What should we do with this? - ex.printStackTrace(); - } - } - - prev = null; - setShutdown(true); - dispatchThread = null; - this.notifyAll(); - } - } - } - } - - /** - * Dispatches an event. The manner in which the event is dispatched depends - * upon the type of the event and the type of the event's source object. - * - * @exception NullPointerException If event is null. - */ - protected void dispatchEvent(AWTEvent evt) - { - currentEvent = evt; - - if (evt instanceof InputEvent) - lastWhen = ((InputEvent) evt).getWhen(); - else if (evt instanceof ActionEvent) - lastWhen = ((ActionEvent) evt).getWhen(); - else if (evt instanceof InvocationEvent) - lastWhen = ((InvocationEvent) evt).getWhen(); - - if (evt instanceof ActiveEvent) - { - ActiveEvent active_evt = (ActiveEvent) evt; - active_evt.dispatch(); - } - else - { - Object source = evt.getSource(); - - if (source instanceof Component) - { - Component srccmp = (Component) source; - srccmp.dispatchEvent(evt); - } - else if (source instanceof MenuComponent) - { - MenuComponent srccmp = (MenuComponent) source; - srccmp.dispatchEvent(evt); - } - } - } - - /** - * Returns the timestamp of the most recent event that had a timestamp, or - * the initialization time of the event queue if no events have been fired. - * At present, only <code>InputEvent</code>s, <code>ActionEvent</code>s, - * <code>InputMethodEvent</code>s, and <code>InvocationEvent</code>s have - * timestamps, but this may be added to other events in future versions. - * If this is called by the event dispatching thread, it can be any - * (sequential) value, but to other threads, the safest bet is to return - * System.currentTimeMillis(). - * - * @return the most recent timestamp - * @see InputEvent#getWhen() - * @see ActionEvent#getWhen() - * @see InvocationEvent#getWhen() - * @see InputMethodEvent#getWhen() - * @since 1.4 - */ - public static long getMostRecentEventTime() - { - EventQueue eq = Toolkit.getDefaultToolkit().getSystemEventQueue(); - if (Thread.currentThread() != eq.dispatchThread) - return System.currentTimeMillis(); - return eq.lastWhen; - } - - //jnode openjdk - static void setCurrentEventAndMostRecentTime(AWTEvent e) { - Toolkit.getEventQueue().setCurrentEventAndMostRecentTimeImpl(e); - } - private synchronized void setCurrentEventAndMostRecentTimeImpl(AWTEvent e) - { - if (Thread.currentThread() != dispatchThread) { - return; - } - - currentEvent = e; - - // This series of 'instanceof' checks should be replaced with a - // polymorphic type (for example, an interface which declares a - // getWhen() method). However, this would require us to make such - // a type public, or to place it in sun.awt. Both of these approaches - // have been frowned upon. So for now, we hack. - // - // In tiger, we will probably give timestamps to all events, so this - // will no longer be an issue. - long mostRecentEventTime2 = Long.MIN_VALUE; - if (e instanceof InputEvent) { - InputEvent ie = (InputEvent)e; - mostRecentEventTime2 = ie.getWhen(); - } else if (e instanceof InputMethodEvent) { - InputMethodEvent ime = (InputMethodEvent)e; - mostRecentEventTime2 = ime.getWhen(); - } else if (e instanceof ActionEvent) { - ActionEvent ae = (ActionEvent)e; - mostRecentEventTime2 = ae.getWhen(); - } else if (e instanceof InvocationEvent) { - InvocationEvent ie = (InvocationEvent)e; - mostRecentEventTime2 = ie.getWhen(); - } - mostRecentEventTime = Math.max(mostRecentEventTime, mostRecentEventTime2); - } - /* - * The time stamp of the last dispatched InputEvent or ActionEvent. - */ - private long mostRecentEventTime = System.currentTimeMillis(); - -/* - * Removes any pending events for the specified source object. - * If removeAllEvents parameter is <code>true</code> then all - * events for the specified source object are removed, if it - * is <code>false</code> then <code>SequencedEvent</code>, <code>SentEvent</code>, - * <code>FocusEvent</code>, <code>WindowEvent</code>, <code>KeyEvent</code>, - * and <code>InputMethodEvent</code> are kept in the queue, but all other - * events are removed. - * - * This method is normally called by the source's - * <code>removeNotify</code> method. - */ -final void removeSourceEvents(Object source, boolean removeAllEvents) { - /* - SunToolkit.flushPendingEvents(); - synchronized (this) { - for (int i = 0; i < NUM_PRIORITIES; i++) { - EventQueueItem entry = queues[i].head; - EventQueueItem prev = null; - while (entry != null) { - if ((entry.event.getSource() == source) - && (removeAllEvents - || ! (entry.event instanceof SequencedEvent - || entry.event instanceof SentEvent - || entry.event instanceof FocusEvent - || entry.event instanceof WindowEvent - || entry.event instanceof KeyEvent - || entry.event instanceof InputMethodEvent))) - { - if (entry.event instanceof SequencedEvent) { - ((SequencedEvent)entry.event).dispose(); - } - if (entry.event instanceof SentEvent) { - ((SentEvent)entry.event).dispose(); - } - if (prev == null) { - queues[i].head = entry.next; - } else { - prev.next = entry.next; - } - uncacheEQItem(entry); - } else { - prev = entry; - } - entry = entry.next; - } - queues[i].tail = prev; - } - } - */ -} - - -} Deleted: trunk/core/src/classpath/java/java/awt/KeyboardFocusManager.java =================================================================== --- trunk/core/src/classpath/java/java/awt/KeyboardFocusManager.java 2008-03-16 20:23:32 UTC (rev 3855) +++ trunk/core/src/classpath/java/java/awt/KeyboardFocusManager.java 2008-03-16 20:25:30 UTC (rev 3856) @@ -1,1489 +0,0 @@ -/* KeyboardFocusManager.java -- manage component focusing via the keyboard - Copyright (C) 2002, 2004 Free Software Foundation - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package java.awt; - -import java.applet.Applet; -import java.awt.FocusTraversalPolicy; -import java.awt.event.FocusEvent; -import java.awt.event.KeyEvent; -import java.awt.event.WindowEvent; -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; -import java.beans.PropertyVetoException; -import java.beans.VetoableChangeListener; -import java.beans.VetoableChangeSupport; -import java.util.*; -import java.util.List; - -/** - * The <code>KeyboardFocusManager</code> handles the focusing of - * windows for receiving keyboard events. The manager handles - * the dispatch of all <code>FocusEvent</code>s and - * <code>KeyEvent</code>s, along with <code>WindowEvent</code>s - * relating to the focused window. Users can use the manager - * to ascertain the current focus owner and fire events. - * <br /> - * <br /> - * The focus owner is the <code>Component</code> that receives - * key events. The focus owner is either the currently focused - * window or a component within this window. - * <br /> - * <br /> - * The underlying native windowing system may denote the active - * window or its children with special decorations (e.g. a highlighted - * title bar). The active window is always either a <code>Frame</code> - * or <code>Dialog</code>, and is either the currently focused - * window or its owner. - * <br /> - * <br /> - * Applets may be partitioned into different applet contexts, according - * to their code base. In this case, each context has its own - * <code>KeyboardFocusManager</code>, as opposed to the global - * manager maintained by applets which share the same context. - * Each context is insulated from the others, and they don't interact. - * The resulting behaviour, as with context division, depends on the browser - * supporting the applets. Regardless, there can only ever be - * one focused window, one active window and one focus owner - * per <code>ClassLoader</code>. - * <br /> - * <br /> - * To support this separation of focus managers, the manager instances - * and the internal state information is grouped by the - * <code>ThreadGroup</code> to which it pertains. With respect to - * applets, each code base has its own <code>ThreadGroup</code>, so the - * isolation of each context is enforced within the manager. - * <br /> - * <br /> - * By default, the manager defines TAB and Ctrl+TAB as the - * forward focus traversal keys and Shift+TAB and Ctrl+Shift+TAB - * as the backward focus traversal keys. No up or down cycle - * traversal keys are defined by default. Traversal takes effect - * on the firing of a relevant <code>KEY_PRESSED</code> event. - * However, all other key events related to the use of the - * defined focus traversal key sequence are consumed and not - * dispatched. - * <br /> - * <br /> - * These default traversal keys come into effect on all windows - * for which no alternative set of keys is defined. This also - * applies recursively to any child components of such a window, - * which define no traversal keys of their own. - * - * @author Eric Blake (eb...@em...) - * @author Thomas Fitzsimmons (fi...@re...) - * @author Andrew John Hughes (gnu...@me...) - * @since 1.4 - */ -public abstract class KeyboardFocusManager - implements KeyEventDispatcher, KeyEventPostProcessor -{ - /** Identifies {@link AWTKeyStroke}s that move the focus forward in - the focus cycle. */ - public static final int FORWARD_TRAVERSAL_KEYS = 0; - - /** Identifies {@link AWTKeyStroke}s that move the focus backward in - the focus cycle. */ - public static final int BACKWARD_TRAVERSAL_KEYS = 1; - - /** Identifies {@link AWTKeyStroke}s that move the focus up to the - parent focus cycle root. */ - public static final int UP_CYCLE_TRAVERSAL_KEYS = 2; - - /** Identifies {@link AWTKeyStroke}s that move the focus down to the - child focus cycle root. */ - public static final int DOWN_CYCLE_TRAVERSAL_KEYS = 3; - - /** The set of {@link AWTKeyStroke}s that cause focus to be moved to - the next focusable Component in the focus cycle. */ - private static final Set DEFAULT_FORWARD_KEYS; - - /** The set of {@link AWTKeyStroke}s that cause focus to be moved to - the previous focusable Component in the focus cycle. */ - private static final Set DEFAULT_BACKWARD_KEYS; - - /** Populate the DEFAULT_FORWARD_KEYS and DEFAULT_BACKWARD_KEYS - {@link java.util.Set}s. */ - static - { - Set s = new HashSet(); - s.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB, 0)); - s.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB, - KeyEvent.CTRL_DOWN_MASK)); - DEFAULT_FORWARD_KEYS = Collections.unmodifiableSet(s); - s = new HashSet(); - s.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB, - KeyEvent.SHIFT_DOWN_MASK)); - s.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB, - KeyEvent.SHIFT_DOWN_MASK - | KeyEvent.CTRL_DOWN_MASK)); - DEFAULT_BACKWARD_KEYS = Collections.unmodifiableSet(s); - } - - /** The global object {@link java.util.Map}s. */ - - /** For security reasons, {@link java.applet.Applet}s in different - codebases must be insulated from one another. Since {@link - KeyboardFocusManager}s have the ability to return {@link - Component}s from a given {@link java.applet.Applet}, each - codebase must have an independent {@link KeyboardFocusManager}. - Since each codebase has its own {@link ThreadGroup} in which its - {@link Applet}s run, it makes sense to partition {@link - KeyboardFocusManager}s according to {@link - java.lang.ThreadGroup}. Thus, currentKeyboardFocusManagers is a - {@link java.util.Map} keyed on {@link java.lang.ThreadGroup}. */ - private static Map currentKeyboardFocusManagers = new HashMap (); - - /** {@link java.applet.Applet}s in one codebase must not be allowed - to access {@link Component}s in {@link java.applet.Applet}s in - other codebases. To enforce this restriction, we key the - following {@link java.util.Map}s on {@link java.lang.ThreadGroup}s (which - are per-codebase). For example, if {@link - java.lang.ThreadGroup} A calls {@link #setGlobalFocusOwner}, - passing {@link Component} C, currentFocusOwners[A] is assigned - C, and all other currentFocusOwners values are nullified. Then - if {@link java.lang.ThreadGroup} A subsequently calls {@link - #getGlobalFocusOwner}, it will return currentFocusOwners[A], - that is, {@link Component} C. If another {@link - java.lang.ThreadGroup} K calls {@link #getGlobalFocusOwner}, it - will return currentFocusOwners[K], that is, null. - - Since this is a static field, we ensure that there is only one - focused {@link Component} per class loader. */ - private static Map currentFocusOwners = new HashMap (); - - /** A {@link java.util.Map} keyed on {@link java.lang.ThreadGroup}s - that stores the {@link Component} that owns the permanent - keyboard focus. @see currentFocusOwners */ - private static Map currentPermanentFocusOwners = new HashMap (); - - /** A {@link java.util.Map} keyed on {@link java.lang.ThreadGroup}s - that stores the focused {@link Window}. @see - currentFocusOwners */ - private static Map currentFocusedWindows = new HashMap (); - - /** A {@link java.util.Map} keyed on {@link java.lang.ThreadGroup}s - that stores the active {@link Window}. @see - currentFocusOwners */ - private static Map currentActiveWindows = new HashMap (); - - /** A {@link java.util.Map} keyed on {@link java.lang.ThreadGroup}s - that stores the focus cycle root {@link Container}. @see - currentFocusOwners */ - private static Map currentFocusCycleRoots = new HashMap (); - - /** The default {@link FocusTraversalPolicy} that focus-managing - {@link Container}s will use to define their initial focus - traversal policy. */ - private FocusTraversalPolicy defaultPolicy; - - /** An array that stores the {@link #FORWARD_TRAVERSAL_KEYS}, {@link - #BACKWARD_TRAVERSAL_KEYS}, {@link #UP_CYCLE_TRAVERSAL_KEYS} and - {@link #DOWN_CYCLE_TRAVERSAL_KEYS} {@link AWTKeyStroke}s {@link - java.util.Set}s. */ - private Set[] defaultFocusKeys = new Set[] - { - DEFAULT_FORWARD_KEYS, DEFAULT_BACKWARD_KEYS, - Collections.EMPTY_SET, Collections.EMPTY_SET - }; - - /** - * A utility class to support the handling of events relating to property changes. - */ - private final PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport (this); - - /** - * A utility class to support the handling of events relating to vetoable changes. - */ - private final VetoableChangeSupport vetoableChangeSupport = new VetoableChangeSupport (this); - - /** A list of {@link KeyEventDispatcher}s that process {@link - KeyEvent}s before they are processed the default keyboard focus - manager. */ - private final ArrayList keyEventDispatchers = new ArrayList(); - - /** A list of {@link KeyEventPostProcessor}s that process unconsumed - {@link KeyEvent}s. */ - private final ArrayList keyEventPostProcessors = new ArrayList(); - - /** - * Construct a KeyboardFocusManager. - */ - public KeyboardFocusManager () - { - } - - /** - * Retrieve the keyboard focus manager associated with the {@link - * java.lang.ThreadGroup} to which the calling thread belongs. - * - * @return the keyboard focus manager associated with the current - * thread group - */ - public static KeyboardFocusManager getCurrentKeyboardFocusManager () - { - ThreadGroup currentGroup = Thread.currentThread ().getThreadGroup (); - - if (currentKeyboardFocusManagers.get (currentGroup) == null) - setCurrentKeyboardFocusManager (null); - - return (KeyboardFocusManager) currentKeyboardFocusManagers.get (currentGroup); - } - - /** - * Set the keyboard focus manager associated with the {@link - * java.lang.ThreadGroup} to which the calling thread belongs. - * - * @param m the keyboard focus manager for the current thread group - */ - public static void setCurrentKeyboardFocusManager (KeyboardFocusManager m) - { - SecurityManager sm = System.getSecurityManager (); - if (sm != null) - sm.checkPermission (new AWTPermission ("replaceKeyboardFocusManager")); - - ThreadGroup currentGroup = Thread.currentThread ().getThreadGroup (); - KeyboardFocusManager manager; - - if (m == null) - manager = new DefaultKeyboardFocusManager(); - else - manager = m; - - currentKeyboardFocusManagers.put (currentGroup, manager); - } - - /** - * Retrieve the {@link Component} that has the keyboard focus, or - * null if the focus owner was not set by a thread in the current - * {@link java.lang.ThreadGroup}. - * - * @return the keyboard focus owner or null - */ - public Component getFocusOwner () - { - Component owner = (Component) getObject (currentFocusOwners); - if (owner == null) - owner = (Component) getObject (currentPermanentFocusOwners); - return owner; - } - - /** - * Retrieve the {@link Component} that has the keyboard focus, - * regardless of whether or not it was set by a thread in the - * current {@link java.lang.ThreadGroup}. If there is no temporary - * focus owner in effect then this method will return the same value - * as {@link #getGlobalPermanentFocusOwner}. - * - * @return the keyboard focus owner - * @throws SecurityException if this is not the keyboard focus - * manager associated with the current {@link java.lang.ThreadGroup} - */ - protected Component getGlobalFocusOwner () - { - // Check if there is a temporary focus owner. - Component focusOwner = (Component) getGlobalObject (currentFocusOwners); - - return (focusOwner == null) ? getGlobalPermanentFocusOwner () : focusOwner; - } - - /** - * Set the {@link Component} that will be returned by {@link - * #getFocusOwner} (when it is called from the current {@link - * java.lang.ThreadGroup}) and {@link #getGlobalFocusOwner}. This - * method does not actually transfer the keyboard focus. - * - * @param owner the Component to return from getFocusOwner and - * getGlobalFocusOwner - * - * @see Component#requestFocus() - * @see Component#requestFocusInWindow() - */ - protected void setGlobalFocusOwner (Component owner) - { - if (owner == null || owner.focusable) - setGlobalObject (currentFocusOwners, owner, "focusOwner"); - } - - /** - * Clear the global focus owner and deliver a FOCUS_LOST event to - * the previously-focused {@link Component}. Until another {@link - * Component} becomes the keyboard focus owner, key events will be - * discarded by top-level windows. - */ - public void clearGlobalFocusOwner () - { - synchronized (currentFocusOwners) - { - Component focusOwner = getGlobalFocusOwner (); - Component permanentFocusOwner = getGlobalPermanentFocusOwner (); - - setGlobalFocusOwner (null); - setGlobalPermanentFocusOwner (null); - - // Inform the old focus owner that it has lost permanent - // focus. - if (focusOwner != null) - { - // We can't cache the event queue, because of - // bootstrapping issues. We need to set the default - // KeyboardFocusManager in EventQueue before the event - // queue is started. - EventQueue q = Toolkit.getDefaultToolkit ().getSystemEventQueue (); - if (focusOwner != permanentFocusOwner) - q.postEvent (new FocusEvent (focusOwner, FocusEvent.FOCUS_LOST, true)); - else - q.postEvent (new FocusEvent (focusOwner, FocusEvent.FOCUS_LOST, false)); - } - - if (focusOwner != permanentFocusOwner) - { - EventQueue q = Toolkit.getDefaultToolkit ().getSystemEventQueue (); - q.postEvent (new FocusEvent (permanentFocusOwner, FocusEvent.FOCUS_LOST, false)); - } - } - } - - /** - * Retrieve the {@link Component} that has the permanent keyboard - * focus, or null if the focus owner was not set by a thread in the - * current {@link java.lang.ThreadGroup}. - * - * @return the keyboard focus owner or null - */ - public Component getPermanentFocusOwner () - { - return (Component) getObject (currentPermanentFocusOwners); - } - - /** - * Retrieve the {@link Component} that has the permanent keyboard - * focus, regardless of whether or not it was set by a thread in the - * current {@link java.lang.ThreadGroup}. - * - * @return the keyboard focus owner - * @throws SecurityException if this is not the keyboard focus - * manager associated with the current {@link java.lang.ThreadGroup} - */ - protected Component getGlobalPermanentFocusOwner () - { - return (Component) getGlobalObject (currentPermanentFocusOwners); - } - - /** - * Set the {@link Component} that will be returned by {@link - * #getPermanentFocusOwner} (when it is called from the current - * {@link java.lang.ThreadGroup}) and {@link - * #getGlobalPermanentFocusOwner}. This method does not actually - * transfer the keyboard focus. - * - * @param focusOwner the Component to return from - * getPermanentFocusOwner and getGlobalPermanentFocusOwner - * - * @see Component#requestFocus() - * @see Component#requestFocusInWindow() - */ - protected void setGlobalPermanentFocusOwner (Component focusOwner) - { - if (focusOwner == null || focusOwner.focusable) - setGlobalObject (currentPermanentFocusOwners, focusOwner, - "permanentFocusOwner"); - } - - /** - * Retrieve the {@link Window} that is or contains the keyboard - * focus owner, or null if the focused window was not set by a - * thread in the current {@link java.lang.ThreadGroup}. - * - * @return the focused window or null - */ - public Window getFocusedWindow () - { - return (Window) getObject (currentFocusedWindows); - } - - /** - * Retrieve the {@link Window} that is or contains the focus owner, - * regardless of whether or not the {@link Window} was set focused - * by a thread in the current {@link java.lang.ThreadGroup}. - * - * @return the focused window - * @throws SecurityException if this is not the keyboard focus - * manager associated with the current {@link java.lang.ThreadGroup} - */ - protected Window getGlobalFocusedWindow () - { - return (Window) getGlobalObject (currentFocusedWindows); - } - - /** - * Set the {@link Window} that will be returned by {@link - * #getFocusedWindow} (when it is called from the current {@link - * java.lang.ThreadGroup}) and {@link #getGlobalFocusedWindow}. - * This method does not actually cause <code>window</code> to become - * the focused {@link Window}. - * - * @param window the Window to return from getFocusedWindow and - * getGlobalFocusedWindow - */ - protected void setGlobalFocusedWindow (Window window) - { - if (window == null || window.focusable) - setGlobalObject (currentFocusedWindows, window, "focusedWindow"); - } - - /** - * Retrieve the active {@link Window}, or null if the active window - * was not set by a thread in the current {@link - * java.lang.ThreadGroup}. - * - * @return the active window or null - */ - public Window getActiveWindow() - { - return (Window) getObject (currentActiveWindows); - } - - /** - * Retrieve the active {@link Window}, regardless of whether or not - * the {@link Window} was made active by a thread in the current - * {@link java.lang.ThreadGroup}. - * - * @return the active window - * @throws SecurityException if this is not the keyboard focus - * manager associated with the current {@link java.lang.ThreadGroup} - */ - protected Window getGlobalActiveWindow() - { - return (Window) getGlobalObject (currentActiveWindows); - } - - /** - * Set the {@link Window} that will be returned by {@link - * #getActiveWindow} (when it is called from the current {@link - * java.lang.ThreadGroup}) and {@link #getGlobalActiveWindow}. This - * method does not actually cause <code>window</code> to be made - * active. - * - * @param window the Window to return from ge... [truncated message content] |
From: <ls...@us...> - 2008-03-24 18:56:00
|
Revision: 3870 http://jnode.svn.sourceforge.net/jnode/?rev=3870&view=rev Author: lsantha Date: 2008-03-24 11:55:57 -0700 (Mon, 24 Mar 2008) Log Message: ----------- OpenJDK integration. Removed Paths: ------------- trunk/core/src/classpath/java/java/awt/color/ trunk/core/src/classpath/java/java/awt/image/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |