c5d2de6b4c
2004-05-25 David Jee <djee@redhat.com> * java/awt/Container.java (remove): Set component's parent to null only after we removed the component from its parent's layout manager. 2004-05-25 David Jee <djee@redhat.com> * gnu/java/awt/peer/gtk/GtkComponentPeer.java (GtkComponentPeer): Set bounds regardless of whether awtComponent is valid. * gnu/java/awt/peer/gtk/GtkListPeer.java (getSize): Change native method declaration. (minimumSize): Pass visible row count into getSize(). (preferredSize): Likewise. * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkListPeer.c (Java_gnu_java_awt_peer_gtk_GtkListPeer_getSize): Use scroll window's natural size. Use visible row count to determine the final height value to return. 2004-05-21 Graydon Hoare <graydon@redhat.com> * gnu/java/awt/peer/gtk/GdkGraphics2D.java (setClip): Minor correction to order of operations. * javax/swing/JScrollPane.java: Extend sketchy implementation. * javax/swing/ScrollPaneLayout.java: Likewise. * javax/swing/JViewPort.java: Likewise. * javax/swing/ViewportLayout.java: Likewise. * javax/swing/JComponent.java: Rewrite. * javax/swing/RepaintManager.java: Likewise. * javax/swing/JLayeredPane.java: Change validate() to revalidate(). * javax/swing/JList.java (setSelectedIndices): (getSelectedIndices): (getSelectedValues): New functions. (getPreferredScrollableViewportSize): Return preferred size. (getScrollableUnitIncrement): (getScrollableBlockIncrement): Initial implementations. * javax/swing/JRootPane.java: Clean up slightly. (getUI): (setUI): (updateUI): (getUIClassID): (isValidateRoot): Add overrides from JComponent. * javax/swing/JScrollBar.java: Set default orientation to VERTICAL. * javax/swing/UIManager.java (getDimension): Return the dimension. * javax/swing/plaf/basic/BasicButtonUI.java: Set component opaque. * javax/swing/plaf/basic/BasicLabelUI.java: Likewise. * javax/swing/plaf/basic/BasicMenuItemUI.java: Likewise. * javax/swing/plaf/basic/BasicProgressBarUI.java: Likewise. * javax/swing/plaf/basic/BasicSeparatorUI.java: Likewise. * javax/swing/plaf/basic/BasicSliderUI.java: Likewise. * javax/swing/plaf/basic/BasicTabbedPaneUI.java: Likewise. * javax/swing/plaf/basic/BasicRootPaneUI.java: Likewise, and set background. * javax/swing/plaf/basic/BasicListUI.java: Likewise, and improve a bit. * javax/swing/plaf/basic/BasicScrollBarUI.java: Likewise, and adjust calculations. * javax/swing/plaf/basic/BasicViewportUI.java: Likewise, and improve a bit. * javax/swing/plaf/basic/BasicLookAndFeel.java (Button.margin): Shrink. * jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGlyphVector.c: Hack to set horizontal always, workaround pango. * jni/gtk-peer/gtkcairopeer.h: Change to match pattern API. * jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics2D.c: Synchronize more often, check cairo status after ops, handle changes to cairo pattern API, check for disposal. 2004-05-21 Olga Rodimina <rodimina@redhat.com> * javax/swing/plaf/basic/BasicMenuItemUI.java: (BasicMenuItemUI): Create propertyChangeListener. (getPath):Implemented. (installListeners): Add propertyChangeListener to menuItem. (uninstallListeners): Remove propertyChangeListener from menuItem. (update): Implemented. * javax/swing/plaf/basic/BasicMenuUI.MouseInputHandler: (mouseEntered): Take insets of popup menu into account when calculating position of popup menu. 2004-05-18 Olga Rodimina <rodimina@redhat.com> * Makefile.am: Added new file. * Makefile.in: Regenerate. * javax/swing/JMenuBar.java: Started implementation. * javax/swing/JPopupMenu.java: (setVisible): Fixed location of lightweight/mediumweight popup menu. (show): Fixed location of PopupMenu. * javax/swing/plaf/basic/BasicMenuBarUI.java: New file. UI Delegate for JMenuBar. * javax/swing/plaf/basic/BasicMenuUI.MouseInputHandler: (mouseEntered): Corrected position of the submenu. 2004-05-18 Thomas Fitzsimmons <fitzsim@redhat.com> * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuPeer.c: Remove calls to _gtk_accel_group_attach. * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkPopupMenuPeer.c: Likewise. * gnu/java/awt/peer/gtk/GtkButtonPeer.java: Give gtkSetFont package access. Don't override setFont. * gnu/java/awt/peer/gtk/GtkCheckboxPeer.java: Likewise. * gnu/java/awt/peer/gtk/GtkComponentPeer.java: Give gtkWidgetRequestFocus package access. * gnu/java/awt/peer/gtk/GtkLabelPeer.java: Don't override setFont. * gnu/java/awt/peer/gtk/GtkListPeer.java: Override gtkSetFont. Give gtkWidgetRequestFocus package access. * gnu/java/awt/peer/gtk/GtkTextAreaPeer.java: Give gtkWidgetRequestFocus package access. Don't override setFont. * gnu/java/awt/peer/gtk/GtkTextFieldPeer.java: Don't override setFont. * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkButtonPeer.c (gtkSetLabel): Move call to gtk_bin_get_child into GDK critical region. (gtkSetFont): Likewise. * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkListPeer.c (gtkSetFont): Implement. * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextAreaPeer.c (gtkSetFont): Whitespace fix. * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c (gtkWidgetSetUsize): Remove method. 2004-05-18 David Jee <djee@redhat.com> * java/awt/image/MemoryImageSource.java (newPixels(int,int,int,int,boolean)): Set only the specified rectangle of pixels. (newPixels(byte[],ColorModel,int,int)): Implement. (newPixels(int[],ColorModel,int,int)): Implement. 2004-05-18 Olga Rodimina <rodimina@redhat.com> * Makefile.am: Added new file. * Makefile.in: Regenerate. * javax/swing/JMenu.java: Started implementation. * javax/swing/JPopupMenu.java: (insert): If specified index is -1, then add component at the end. (isPopupTrigger): Reimplemented. (JPopupMenu.LightWeightPopup): setBounds of the lightWeightPopup before adding it to the layeredPane. (javax/swing/plaf/basic/BasicIconFactory.java): (getMenuArrowIcon): Implemented. * javax/swing/plaf/basic/BasicMenuItemUI.java: (getPreferredSize): Add size of the arrow icon if this menu item is instance of JMenu. (paintMenuItem): Paint arrow icon if this menu item is a submenu. * javax/swing/plaf/basic/BasicMenuUI.java: New File. UI Delegate for JMenu. 2004-05-17 Thomas Fitzsimmons <fitzsim@redhat.com> * gnu/java/awt/peer/gtk/GtkComponentPeer.java (postKeyEvent): Post KEY_TYPED events. * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkEvents.c (generates_key_typed_event): Remove function. 2004-05-17 Olga Rodimina <rodimina@redhat.com> * javax/swing/JRootPane.java (JRootPane.RootLayout): Reimplemented to set bounds of contentPane and menuBar. (setJMenuBar): Add menu bar to the layered pane. (createLayeredPane): Set layout of layeredPane to null. * javax/swing/JLayeredPane.java: (addImpl): Calculate index of the component in the layeredPane according to the specified position within the layer. 2004-05-17 David Jee <djee@redhat.com> * gnu/java/awt/peer/gtk/GtkImagePainter.java (setPixels): Change color model to the default model after converting pixels. * java/awt/image/MemoryImageSource.java (newPixels): Set only the specified rectangle of pixels. 2004-05-13 Thomas Fitzsimmons <fitzsim@redhat.com> * libgcj.spec.in (lib): Add -l-java-awt -l-java-applet -l-java-beans -l-javax-accessibility -l-javax-swing. * java/awt/AWTEvent.java (toString): Print source's name rather than the source itself. 2004-05-12 Thomas Fitzsimmons <fitzsim@redhat.com> * gnu/java/awt/peer/gtk/GtkToolkit.java (loadSystemColors): Make native. * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkToolkit.c (gdk_color_to_java_color): New function. * jni/gtk-peer/gtkpeer.h: Add SystemColor defines. 2004-05-12 David Jee <djee@redhat.com> * java/awt/image/RGBImageFilter.java: Initialize origmodel as null. (makeColor): Fix pixel component order. (filterRGBPixels): Fix pixel iteration. (setPixels): Add extra checks for index color model. Convert pixels to default color model if necessary. (convertColorModelToDefault): New override method for byte pixels. (convertColorModelToDefault): For int pixels, fix pixel iteration. (makeColorbyDefaultCM): New override method for byte pixels. (makeColorbyDefaultCM): For int pixel, add color model as argument. (makeColor): Fix pixel component order. 2004-05-11 Kim Ho <kho@redhat.com> * javax/swing/Box.java: Comment out more parts of Box.Filler. 2004-05-11 Kim Ho <kho@redhat.com> * javax/swing/Box.java: Remove reference to AccessibleAWTComponent so it compiles again. 2004-05-10 Thomas Fitzsimmons <fitzsim@redhat.com> * gnu/java/awt/peer/gtk/GtkListPeer.java, jni/gtk-peer/gnu_java_awt_peer_gtk_GtkListPeer.c: Update implementation of list peer to use GtkTreeView instead of deprecated GtkCList. 2004-05-07 Thomas Fitzsimmons <fitzsim@redhat.com> * gnu/java/awt/peer/gtk/GtkComponentPeer.java (gtkWidgetDispatchKeyEvent): Remove keyChar parameter. (handleEvent): Remove keyChar argument to gtkWidgetDispatchKeyEvent calls. * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c: Fix compiler warnings. * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkEvents.c: Likewise. * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuPeer.c: Likewise. * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextComponentPeer.c: Likewise. 2004-05-06 Thomas Fitzsimmons <fitzsim@redhat.com> * gnu/java/awt/peer/gtk/GtkComponentPeer.java (gtkWidgetRequestFocus): Mark protected. (GtkComponentPeer): Only set the peer's bounds if its component is valid. * java/awt/Component.java (static): Set the default keyboard focus manager. (requestFocus(), requestFocus(boolean), requestFocusInWindow(), requestFocusInWindow(temporary)): Don't request focus if the component is not showing. Get tree lock before traversing component hierarchy. * java/awt/DefaultKeyboardFocusManager.java (dispatchEvent): Only set the global focus owner if it is not a Window. (processKeyEvent): Consume keystrokes associated with the focus traversal keystroke. (focusPreviousComponent, focusNextComponent, upFocusCycle, downFocusCycle): Call requestFocusInWindow instead of requestFocus. * java/awt/EventDispatchThread.java (run): Move setting of default keyboard focus manager to Component.java. * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c (awt_keycode_to_keysym): New function. (gtkWidgetDispatchKeyEvent): Finish implementation. * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkEvents.c (pre_event_handler): Add FIXME comment. * gnu/java/awt/peer/gtk/GtkTextAreaPeer.java, jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextAreaPeer.c (gtkWidgetRequestFocus): New method. * java/awt/TextArea.java (TextArea): Set focus traversal keys to disable Tab and Shift-Tab keystrokes. (addNotify, appendText, insertText, replaceText): Simplify peer retrieval code. * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextComponentPeer.c (connectSignals): Remove connections to "commit" signals. Remove C++-style comments. * gnu/java/awt/peer/gtk/GtkButtonPeer.java, jni/gtk-peer/gnu_java_awt_peer_gtk_GtkButtonPeer.c (handleEvent): Activate GTK button when the space bar key is pressed. (gtkActivate): New method. 2004-05-06 David Jee <djee@redhat.com> * java/awt/image/CropImageFilter.java (setPixels): Implement for byte array pixels. * java/awt/image/ReplicateScaleFilter.java (setPixels): Implement for byte array pixels. (replicatePixels): Overload for byte array pixels. 2004-05-06 Kim Ho <kho@redhat.com> * javax/swing/Box.java: (getAccessibleContext): Return an instance of the correct class. 2004-05-05 David Jee <djee@redhat.com> * gnu/java/awt/peer/gtk/GdkGraphics.java (drawImage): When component is null, use SystemColor.window as the default bgcolor. * gnu/java/awt/peer/gtk/GtkImage.java (setPixels): We can avoid iterating through the pixel rows only when height is 1. * java/awt/Image.java (getScaledInstance): Partially implement. * java/awt/image/CropImageFilter.java (setProperties): Fix "filter" property. (setPixels): Implement. * java/awt/image/ReplicateScaleFilter.java (setDimensions): Use scaled dimensions. (setPixels): Implement. (replicatePixels): New method. 2004-05-05 David Jee <djee@redhat.com> * gnu/java/awt/peer/gtk/GtkImagePainter.java (convertPixels): If either pixels or model is null, return null. * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkImagePainter.c (Java_gnu_java_awt_peer_gtk_GtkImagePainter_drawPixels): If jpixels is null, do nothing and return. 2004-05-03 Kim Ho <kho@redhat.com> * gnu/java/awt/peer/gtk/GtkDialogPeer.java: (getGraphics): Like GtkFramePeer, the Graphics object needs to be translate to account for window decorations. (postMouseEvent): New method. Account for translation. (postExposeEvent): ditto. * javax/swing/Box.java: Stubbed. * javax/swing/JDialog.java: Ran through jalopy to fix indentation. (JDialog): Call SwingUtilities' getOwnerFrame for null owners. (setLayout): Check isRootPaneCheckingEnabled * javax/swing/JOptionPane.java: Re-implemented. * javax/swing/SwingUtilities.java: (getOwnerFrame): Static method to grab a default owner frame for Dialogs that don't specify owners. * javax/swing/event/SwingPropertyChangeSupport.java: (firePropertyChange): Fix early exit condition. * javax/swing/plaf/basic/BasicLabelUI.java: (paint): Avoid painting text if it is null or empty. * javax/swing/plaf/basic/BasicOptionPaneUI.java: Implement. 2004-05-03 Olga Rodimina <rodimina@redhat.com> * Makefile.am: Added new file. * Makefile.in: Regenerate. * javax/swing/JPopupMenu.java: Started implementation. * javax/swing/JWindow.java (JWindow): call super() if parent for window is not specified. * javax/swing/plaf/basic/BasicPopupMenuUI.java: New File. UI Delegate for JPopupMenu. 2004-04-30 Olga Rodimina <rodimina@redhat.com> * javax/swing/JApplet.java: Indicated that JApplet implements RootPaneContainer and made method of this interface public. * javax/swing/JFrame.java: Ditto. * javax/swing/JWindow.java: Ditto. 2004-04-29 Thomas Fitzsimmons <fitzsim@redhat.com> * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c (nativeSetBounds): Call gdk_window_move in addition to gtk_window_move. * java/applet/Applet.java (preferredSize): Call parent's preferredSize if the applet stub is null. (minimumSize): Likewise for parent's minimumSize. 2004-04-27 Olga Rodimina <rodimina@redhat.com> * javax/swing/JMenuItem.java (createActionPropertyChangeListener): Implemented. (processMouseEvent): Ditto. (fireMenuDragMouseEntered): Ditto. (fireMenuDragMouseExited): Ditto. (fireMenuDragMouseDragged): Ditto. (fireMenuDragMouseReleased): Ditto. (menuSelectionChanged): Ditto. (getSubElements): Ditto. (getComponent): Ditto. (addMenuDragMouseListener): Ditto. (removeMenuDragMouseListener):Ditto. (addMenuKeyListener): Ditto. (removeMenuKeyListener): Ditto. * javax/swing/plaf/basic/BasicMenuItemUI.java (doClick): Imlemented. * javax/swing/plaf/basic/BasicMenuItemUI.MouseInputHandler: Don't handle mouse events here. Pass them to MenuSelectionManager. 2004-04-26 Olga Rodimina <rodimina@redhat.com> Used correct version of jalopy configuration file to fix style in the files below. 2004-04-26 Olga Rodimina <rodimina@redhat.com> * javax/swing/JCheckBoxMenuItem.java: Fixed style and removed unnecessary comments. * javax/swing/JMenuItem.java: Ditto. * javax/swing/JRadioButtonMenuItem.java: Ditto. * javax/swing/plaf/basic/BasicCheckBoxMenuItemUI.java: Ditto. * javax/swing/plaf/basic/BasicMenuItemUI.java: Ditto. * javax/swing/plaf/basic/BasicRadioButtonMenuItemUI.java: Ditto. 2004-04-23 Thomas Fitzsimmons <fitzsim@redhat.com> * gnu_java_awt_peer_gtk_GtkWindowPeer.c: Change FIXME comment to C-style. * gnu_java_awt_peer_gtk_GtkWindowPeer.c: Add FIXME comment. * java/awt/ContainerOrderFocusTraversalPolicy.java (getComponentAfter): Start from current component and work up the component hierarchy until an acceptable component is found. Synchronize on tree lock. (getComponentBefore): Likewise. 2004-04-22 Thomas Fitzsimmons <fitzsim@redhat.com> * gnu/java/awt/peer/gtk/GtkComponentPeer.java: Remove focus-related debugging messages. * java/awt/DefaultKeyboardFocusManager.java: Likewise. * java/awt/EventDispatchThread.java: Likewise. * java/awt/KeyboardFocusManager.java: Likewise. * java/awt/Window.java: Likewise. * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c: Likewise. * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkEvents.c: Likewise. * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c: Change new C++-style comments to C-style comments. * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkEvents.c: Likewise. * gnu/java/awt/peer/gtk/GtkComponentPeer.java, jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c (handleEvent): Dispatch key press and key release events to backing widget. (requestFocus): Post a FOCUS_GAINED event to the event queue. (gtkWidgetRequestFocus): New method. (gtkWidgetDispatchKeyEvent): Likewise. * java/awt/Component.java (requestFocus, requestFocus(boolean), requestFocusInWindow, requestFocusInWindow(boolean), getFocusCycleRootAncestor, nextFocus, transferFocus, transferFocusBackward, transferFocusUpCycle, hasFocus, isFocusOwner): Implement and document focus-handling methods. (setFocusTraversalKeys): Inherit focus traversal keys when keystrokes argument is null. Fix focus-handling documentation throughout class. * java/awt/Container.java (setFocusTraversalKeys, getFocusTraversalKeys, areFocusTraversalKeysSet, isFocusCycleRoot, setFocusTraversalPolicy, getFocusTraversalPolicy, isFocusTraversalPolicySet, setFocusCycleRoot, isFocusCycleRoot, transferFocusDownCycle): Implement and document focus-handling methods. (transferFocusBackward): Remove method. (readObject, writeObject): Implement and document serialization methods. * java/awt/ContainerOrderFocusTraversalPolicy.java: Implement and document. * java/awt/DefaultFocusTraversalPolicy.java: Implement and document. * java/awt/DefaultKeyboardFocusManager.java: Implement and partially document. * java/awt/EventDispatchThread.java (run): Set default keyboard focus manager. Attempt to dispatch each event to the keyboard focus manager before normal dispatch. * java/awt/KeyboardFocusManager.java: Implement and partially document. * java/awt/Window.java (Window): Set focusCycleRoot to true. (show): Focus initial component when window is shown for the first time. * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkEvents.c (pre_event_handler): Replace complex key press and key release logic with simple callbacks into GtkComponentPeer. * jni/gtk-peer/gtkpeer.h: Fix FOCUS_GAINED/FOCUS_LOST reversal. 2004-04-21 Olga Rodimina <rodimina@redhat.com> * javax/swing/MenuSelectionManager.java (componentForPoint): Added new method. (defaultManager): New Method. Implemented. (getSelectedPath): Ditto. (isComponentPartOfCurrentMenu): Ditto. (processKeyEvent): Added new method. (processMouseEvent): New Method. Implemented. (setSelectedPath): Ditto. (getPath): Ditto. 2004-04-19 Kim Ho <kho@redhat.com> * java/awt/Container.java: (remove): Set the component's parent to null. (getComponentAt): Implement. * javax/swing/JComponent.java: (JComponent): Initialize defaultLocale (getDefaultLocale): Implement. (setDefaultLocale): ditto. * javax/swing/JSlider.java: (JSlider): Fix calculation of value. * javax/swing/JSplitPane.java: Implement. * javax/swing/plaf/basic/BasicLookAndFeel.java: Change SplitPane's default divider size. * javax/swing/plaf/basic/BasicScrollBarUI.java: (paint): Remove unused code. * javax/swing/plaf/basic/BasicSplitPaneDivider.java: Added comments and ran through jalopy. (setBasicSplitPaneUI): Get reference to hidden divider and set up one touch buttons if necessary. (setBorder): Fire propertyChangeEvent only if borders are different. (getPreferredSize): Defer to layout manager. (propertyChange): Implement. (oneTouchExpandableChanged): ditto. (createLeftOneTouchButton): Use BasicArrowButton. (createRightOneTouchButton): ditto. (moveDividerTo): New method. Moves the divider to a set location based on the last divider location. (BasicSplitPaneDivider::MouseHandler): Implement. (BasicSplitPaneDivider::OneTouchButton): Removed. (BasicSplitPaneDivider::DragController): Implement. (BasicSplitPaneDivider::VerticalDragController): ditto. (BasicSplitPaneDivider::DividerLayout): ditto. * javax/swing/plaf/basic/BasicSplitPaneUI.java: Reimplement. * javax/swing/plaf/basic/BasicTabbedPaneUI.java: (calculateLayoutInfo): Don't show component if it's null. (paintTab): Fix title paint logic. From-SVN: r82314
709 lines
21 KiB
Java
709 lines
21 KiB
Java
/* BasicListUI.java
|
|
Copyright (C) 2002, 2004 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., 59 Temple Place, Suite 330, Boston, MA
|
|
02111-1307 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 javax.swing.plaf.basic;
|
|
|
|
import java.awt.Color;
|
|
import java.awt.Component;
|
|
import java.awt.Dimension;
|
|
import java.awt.Graphics;
|
|
import java.awt.Point;
|
|
import java.awt.Rectangle;
|
|
import java.awt.event.FocusEvent;
|
|
import java.awt.event.FocusListener;
|
|
import java.awt.event.MouseEvent;
|
|
import java.beans.PropertyChangeEvent;
|
|
import java.beans.PropertyChangeListener;
|
|
import javax.swing.JComponent;
|
|
import javax.swing.JList;
|
|
import javax.swing.ListCellRenderer;
|
|
import javax.swing.ListModel;
|
|
import javax.swing.ListSelectionModel;
|
|
import javax.swing.UIDefaults;
|
|
import javax.swing.UIManager;
|
|
import javax.swing.event.ListDataEvent;
|
|
import javax.swing.event.ListDataListener;
|
|
import javax.swing.event.ListSelectionEvent;
|
|
import javax.swing.event.ListSelectionListener;
|
|
import javax.swing.event.MouseInputListener;
|
|
import javax.swing.plaf.ComponentUI;
|
|
import javax.swing.plaf.ListUI;
|
|
|
|
|
|
/**
|
|
* The Basic Look and Feel UI delegate for the
|
|
* JList.
|
|
*/
|
|
public class BasicListUI extends ListUI
|
|
{
|
|
/**
|
|
* A helper class which listens for {@link FocusEvents}
|
|
* from the JList.
|
|
*/
|
|
class FocusHandler implements FocusListener
|
|
{
|
|
/**
|
|
* Called when the JList acquires focus.
|
|
*
|
|
* @param e The FocusEvent representing focus acquisition
|
|
*/
|
|
public void focusGained(FocusEvent e)
|
|
{
|
|
repaintCellFocus();
|
|
}
|
|
|
|
/**
|
|
* Called when the JList loses focus.
|
|
*
|
|
* @param e The FocusEvent representing focus loss
|
|
*/
|
|
public void focusLost(FocusEvent e)
|
|
{
|
|
repaintCellFocus();
|
|
}
|
|
|
|
/**
|
|
* Helper method to repaint the focused cell's
|
|
* lost or acquired focus state.
|
|
*/
|
|
void repaintCellFocus()
|
|
{
|
|
}
|
|
}
|
|
|
|
/**
|
|
* A helper class which listens for {@link ListDataEvent}s generated by
|
|
* the {@link JList}'s {@link ListModel}.
|
|
*
|
|
* @see javax.swing.JList#model
|
|
*/
|
|
class ListDataHandler implements ListDataListener
|
|
{
|
|
/**
|
|
* Called when a general change has happened in the model which cannot
|
|
* be represented in terms of a simple addition or deletion.
|
|
*
|
|
* @param e The event representing the change
|
|
*/
|
|
public void contentsChanged(ListDataEvent e)
|
|
{
|
|
// System.err.println(this + ".contentsChanged(" + e + ")");
|
|
BasicListUI.this.damageLayout();
|
|
}
|
|
|
|
/**
|
|
* Called when an interval of objects has been added to the model.
|
|
*
|
|
* @param e The event representing the addition
|
|
*/
|
|
public void intervalAdded(ListDataEvent e)
|
|
{
|
|
// System.err.println(this + ".intervalAdded(" + e + ")");
|
|
BasicListUI.this.damageLayout();
|
|
}
|
|
|
|
/**
|
|
* Called when an inteval of objects has been removed from the model.
|
|
*
|
|
* @param e The event representing the removal
|
|
*/
|
|
public void intervalRemoved(ListDataEvent e)
|
|
{
|
|
// System.err.println(this + ".intervalRemoved(" + e + ")");
|
|
BasicListUI.this.damageLayout();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* A helper class which listens for {@link ListSelectionEvent}s
|
|
* from the {@link JList}'s {@link ListSelectionModel}.
|
|
*/
|
|
class ListSelectionHandler implements ListSelectionListener
|
|
{
|
|
/**
|
|
* Called when the list selection changes.
|
|
*
|
|
* @param e The event representing the change
|
|
*/
|
|
public void valueChanged(ListSelectionEvent e)
|
|
{
|
|
// System.err.println(this + ".valueChanged(" + e + ")");
|
|
}
|
|
}
|
|
|
|
/**
|
|
* A helper class which listens for {@link MouseEvent}s
|
|
* from the {@link JList}.
|
|
*/
|
|
class MouseInputHandler implements MouseInputListener
|
|
{
|
|
/**
|
|
* Called when a mouse button press/release cycle completes
|
|
* on the {@link JList}
|
|
*
|
|
* @param event The event representing the mouse click
|
|
*/
|
|
public void mouseClicked(MouseEvent event)
|
|
{
|
|
}
|
|
|
|
/**
|
|
* Called when a mouse button is pressed down on the
|
|
* {@link JList}.
|
|
*
|
|
* @param event The event representing the mouse press
|
|
*/
|
|
public void mousePressed(MouseEvent event)
|
|
{
|
|
// System.err.println("got mouse click event " + event);
|
|
int row = BasicListUI.this.convertYToRow(event.getY());
|
|
if (row == -1)
|
|
return;
|
|
|
|
// System.err.println("clicked on row " + row);
|
|
BasicListUI.this.list.setSelectedIndex(row);
|
|
}
|
|
|
|
/**
|
|
* Called when a mouse button is released on
|
|
* the {@link JList}
|
|
*
|
|
* @param event The event representing the mouse press
|
|
*/
|
|
public void mouseReleased(MouseEvent event)
|
|
{
|
|
}
|
|
|
|
/**
|
|
* Called when the mouse pointer enters the area bounded
|
|
* by the {@link JList}
|
|
*
|
|
* @param event The event representing the mouse entry
|
|
*/
|
|
public void mouseEntered(MouseEvent event)
|
|
{
|
|
}
|
|
|
|
/**
|
|
* Called when the mouse pointer leaves the area bounded
|
|
* by the {@link JList}
|
|
*
|
|
* @param event The event representing the mouse exit
|
|
*/
|
|
public void mouseExited(MouseEvent event)
|
|
{
|
|
}
|
|
|
|
/**
|
|
* Called when the mouse pointer moves over the area bounded
|
|
* by the {@link JList} while a button is held down.
|
|
*
|
|
* @param event The event representing the mouse drag
|
|
*/
|
|
public void mouseDragged(MouseEvent event)
|
|
{
|
|
}
|
|
|
|
/**
|
|
* Called when the mouse pointer moves over the area bounded
|
|
* by the {@link JList}.
|
|
*
|
|
* @param event The event representing the mouse move
|
|
*/
|
|
public void mouseMoved(MouseEvent event)
|
|
{
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Helper class which listens to {@link PropertyChangeEvent}s
|
|
* from the {@link JList}.
|
|
*/
|
|
class PropertyChangeHandler implements PropertyChangeListener
|
|
{
|
|
/**
|
|
* Called when the {@link JList} changes one of its bound properties.
|
|
*
|
|
* @param e The event representing the property change
|
|
*/
|
|
public void propertyChange(PropertyChangeEvent e)
|
|
{
|
|
// System.err.println(this + ".propertyChange(" + e + ")");
|
|
if (e.getSource() == BasicListUI.this.list)
|
|
{
|
|
if (e.getOldValue() != null && e.getOldValue() instanceof ListModel)
|
|
((ListModel) e.getOldValue()).removeListDataListener(BasicListUI.this.listDataListener);
|
|
|
|
if (e.getNewValue() != null && e.getNewValue() instanceof ListModel)
|
|
((ListModel) e.getNewValue()).addListDataListener(BasicListUI.this.listDataListener);
|
|
}
|
|
BasicListUI.this.damageLayout();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Creates a new BasicListUI for the component.
|
|
*
|
|
* @param c The component to create a UI for
|
|
*
|
|
* @return A new UI
|
|
*/
|
|
public static ComponentUI createUI(final JComponent c)
|
|
{
|
|
return new BasicListUI();
|
|
}
|
|
|
|
/** The current focus listener. */
|
|
FocusHandler focusListener;
|
|
|
|
/** The data listener listening to the model. */
|
|
ListDataHandler listDataListener;
|
|
|
|
/** The selection listener listening to the selection model. */
|
|
ListSelectionHandler listSelectionListener;
|
|
|
|
/** The mouse listener listening to the list. */
|
|
MouseInputHandler mouseInputListener;
|
|
|
|
/** The property change listener listening to the list. */
|
|
PropertyChangeHandler propertyChangeListener;
|
|
|
|
/** Saved reference to the list this UI was created for. */
|
|
JList list;
|
|
|
|
/** The height of a single cell in the list. */
|
|
int cellHeight;
|
|
|
|
/** The width of a single cell in the list. */
|
|
int cellWidth;
|
|
|
|
/**
|
|
* An array of varying heights of cells in the list, in cases where each
|
|
* cell might have a different height.
|
|
*/
|
|
int[] cellHeights;
|
|
|
|
/**
|
|
* A simple counter. When nonzero, indicates that the UI class is out of
|
|
* date with respect to the underlying list, and must recalculate the
|
|
* list layout before painting or performing size calculations.
|
|
*/
|
|
int updateLayoutStateNeeded;
|
|
|
|
/**
|
|
* Calculate the height of a particular row. If there is a fixed {@link
|
|
* #cellHeight}, return it; otherwise return the specific row height
|
|
* requested from the {@link #cellHeights} array. If the requested row
|
|
* is invalid, return <code>-1</code>.
|
|
*
|
|
* @param row The row to get the height of
|
|
*
|
|
* @return The height, in pixels, of the specified row
|
|
*/
|
|
int getRowHeight(int row)
|
|
{
|
|
if (row < 0 || row >= cellHeights.length)
|
|
return -1;
|
|
else if (cellHeight != -1)
|
|
return cellHeight;
|
|
else
|
|
return cellHeights[row];
|
|
}
|
|
|
|
/**
|
|
* Calculate the bounds of a particular cell, considering the upper left
|
|
* corner of the list as the origin position <code>(0,0)</code>.
|
|
*
|
|
* @param l Ignored; calculates over <code>this.list</code>
|
|
* @param index1 The first row to include in the bounds
|
|
* @param index2 The last row to incude in the bounds
|
|
*
|
|
* @return A rectangle encompassing the range of rows between
|
|
* <code>index1</code> and <code>index2</code> inclusive
|
|
*/
|
|
public Rectangle getCellBounds(JList l, int index1, int index2)
|
|
{
|
|
if (l != list || cellWidth == -1)
|
|
return null;
|
|
|
|
int lo = Math.min(index1, index2);
|
|
int hi = Math.max(index1, index2);
|
|
Rectangle lobounds = new Rectangle(0, convertRowToY(lo), cellWidth,
|
|
getRowHeight(lo));
|
|
Rectangle hibounds = new Rectangle(0, convertRowToY(hi), cellWidth,
|
|
getRowHeight(hi));
|
|
return lobounds.union(hibounds);
|
|
}
|
|
|
|
/**
|
|
* Calculate the Y coordinate of the upper edge of a particular row,
|
|
* considering the Y coordinate <code>0</code> to occur at the top of the
|
|
* list.
|
|
*
|
|
* @param row The row to calculate the Y coordinate of
|
|
*
|
|
* @return The Y coordinate of the specified row, or <code>-1</code> if
|
|
* the specified row number is invalid
|
|
*/
|
|
int convertRowToY(int row)
|
|
{
|
|
int y = 0;
|
|
for (int i = 0; i < row; ++i)
|
|
{
|
|
int h = getRowHeight(i);
|
|
if (h == -1)
|
|
return -1;
|
|
y += h;
|
|
}
|
|
return y;
|
|
}
|
|
|
|
/**
|
|
* Calculate the row number containing a particular Y coordinate,
|
|
* considering the Y coodrinate <code>0</code> to occur at the top of the
|
|
* list.
|
|
*
|
|
* @param y0 The Y coordinate to calculate the row number for
|
|
*
|
|
* @return The row number containing the specified Y value, or <code>-1</code>
|
|
* if the specified Y coordinate is invalid
|
|
*/
|
|
int convertYToRow(int y0)
|
|
{
|
|
for (int row = 0; row < cellHeights.length; ++row)
|
|
{
|
|
int h = getRowHeight(row);
|
|
|
|
// System.err.println("convertYToRow(" + y0 + ") vs. " + h);
|
|
if (y0 < h)
|
|
return row;
|
|
y0 -= h;
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
/**
|
|
* Recomputes the {@link #cellHeights}, {@link #cellHeight}, and {@link
|
|
* #cellWidth} properties by examining the variouis properties of the
|
|
* {@link JList}.
|
|
*/
|
|
void updateLayoutState()
|
|
{
|
|
int nrows = list.getModel().getSize();
|
|
cellHeight = -1;
|
|
cellWidth = -1;
|
|
if (cellHeights == null || cellHeights.length != nrows)
|
|
cellHeights = new int[nrows];
|
|
if (list.getFixedCellHeight() == -1 || list.getFixedCellWidth() == -1)
|
|
{
|
|
ListCellRenderer rend = list.getCellRenderer();
|
|
for (int i = 0; i < nrows; ++i)
|
|
{
|
|
Component flyweight = rend.getListCellRendererComponent(list,
|
|
list.getModel()
|
|
.getElementAt(i),
|
|
0, false,
|
|
false);
|
|
Dimension dim = flyweight.getPreferredSize();
|
|
cellHeights[i] = dim.height;
|
|
cellWidth = Math.max(cellWidth, dim.width);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
cellHeight = list.getFixedCellHeight();
|
|
cellWidth = list.getFixedCellWidth();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Marks the current layout as damaged and requests revalidation from the
|
|
* JList.
|
|
*
|
|
* @see #updateLayoutStateNeeded
|
|
*/
|
|
void damageLayout()
|
|
{
|
|
updateLayoutStateNeeded = 1;
|
|
list.revalidate();
|
|
}
|
|
|
|
/**
|
|
* Calls {@link #updateLayoutState} if {@link #updateLayoutStateNeeded}
|
|
* is nonzero, then resets {@link #updateLayoutStateNeeded} to zero.
|
|
*/
|
|
void maybeUpdateLayoutState()
|
|
{
|
|
// System.err.println(this + ".maybeUpdateLayoutState()");
|
|
if (updateLayoutStateNeeded != 0)
|
|
{
|
|
updateLayoutState();
|
|
updateLayoutStateNeeded = 0;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Creates a new BasicListUI object.
|
|
*/
|
|
public BasicListUI()
|
|
{
|
|
focusListener = new FocusHandler();
|
|
listDataListener = new ListDataHandler();
|
|
listSelectionListener = new ListSelectionHandler();
|
|
mouseInputListener = new MouseInputHandler();
|
|
propertyChangeListener = new PropertyChangeHandler();
|
|
updateLayoutStateNeeded = 1;
|
|
}
|
|
|
|
/**
|
|
* Installs various default settings (mostly colors) from the {@link
|
|
* UIDefaults} into the {@link JList}
|
|
*
|
|
* @see #uninstallDefaults
|
|
*/
|
|
void installDefaults()
|
|
{
|
|
UIDefaults defaults = UIManager.getLookAndFeelDefaults();
|
|
list.setForeground(defaults.getColor("List.foreground"));
|
|
list.setBackground(defaults.getColor("List.background"));
|
|
list.setSelectionForeground(defaults.getColor("List.selectionForeground"));
|
|
list.setSelectionBackground(defaults.getColor("List.selectionBackground"));
|
|
list.setOpaque(true);
|
|
}
|
|
|
|
/**
|
|
* Resets to <code>null</code> those defaults which were installed in
|
|
* {@link #installDefaults}
|
|
*/
|
|
void uninstallDefaults()
|
|
{
|
|
UIDefaults defaults = UIManager.getLookAndFeelDefaults();
|
|
list.setForeground(null);
|
|
list.setBackground(null);
|
|
list.setSelectionForeground(null);
|
|
list.setSelectionBackground(null);
|
|
}
|
|
|
|
/**
|
|
* Attaches all the listeners we have in the UI class to the {@link
|
|
* JList}, its model and its selection model.
|
|
*
|
|
* @see #uninstallListeners
|
|
*/
|
|
void installListeners()
|
|
{
|
|
list.addFocusListener(focusListener);
|
|
list.getModel().addListDataListener(listDataListener);
|
|
list.addListSelectionListener(listSelectionListener);
|
|
list.addMouseListener(mouseInputListener);
|
|
list.addMouseMotionListener(mouseInputListener);
|
|
list.addPropertyChangeListener(propertyChangeListener);
|
|
}
|
|
|
|
/**
|
|
* Detaches all the listeners we attached in {@link #installListeners}.
|
|
*/
|
|
void uninstallListeners()
|
|
{
|
|
list.removeFocusListener(focusListener);
|
|
list.getModel().removeListDataListener(listDataListener);
|
|
list.removeListSelectionListener(listSelectionListener);
|
|
list.removeMouseListener(mouseInputListener);
|
|
list.removeMouseMotionListener(mouseInputListener);
|
|
list.removePropertyChangeListener(propertyChangeListener);
|
|
}
|
|
|
|
/**
|
|
* Installs keyboard actions for this UI in the {@link JList}.
|
|
*/
|
|
void installKeyboardActions()
|
|
{
|
|
}
|
|
|
|
/**
|
|
* Uninstalls keyboard actions for this UI in the {@link JList}.
|
|
*/
|
|
void uninstallKeyboardActions()
|
|
{
|
|
}
|
|
|
|
/**
|
|
* Installs the various aspects of the UI in the {@link JList}. In
|
|
* particular, calls {@link #installDefaults}, {@link #installListeners}
|
|
* and {@link #installKeyboardActions}. Also saves a reference to the
|
|
* provided component, cast to a {@link JList}.
|
|
*
|
|
* @param c The {@link JList} to install the UI into
|
|
*/
|
|
public void installUI(final JComponent c)
|
|
{
|
|
super.installUI(c);
|
|
list = (JList) c;
|
|
installDefaults();
|
|
installListeners();
|
|
installKeyboardActions();
|
|
// System.err.println(this + ".installUI()");
|
|
maybeUpdateLayoutState();
|
|
}
|
|
|
|
/**
|
|
* Uninstalls all the aspects of the UI which were installed in {@link
|
|
* #installUI}. When finished uninstalling, drops the saved reference to
|
|
* the {@link JList}.
|
|
*
|
|
* @param c Ignored; the UI is uninstalled from the {@link JList}
|
|
* reference saved during the call to {@link #installUI}
|
|
*/
|
|
public void uninstallUI(final JComponent c)
|
|
{
|
|
uninstallKeyboardActions();
|
|
uninstallListeners();
|
|
uninstallDefaults();
|
|
list = null;
|
|
}
|
|
|
|
/**
|
|
* Gets the maximum size this list can assume.
|
|
*
|
|
* @param c The component to measure the size of
|
|
*
|
|
* @return A new Dimension representing the component's maximum size
|
|
*/
|
|
public Dimension getMaximumSize(JComponent c)
|
|
{
|
|
return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
|
|
}
|
|
|
|
/**
|
|
* Gets the size this list would prefer to assume. This is calculated by
|
|
* calling {@link #getCellBounds} over the entire list.
|
|
*
|
|
* @param c Ignored; uses the saved {@link JList} reference
|
|
*
|
|
* @return DOCUMENT ME!
|
|
*/
|
|
public Dimension getPreferredSize(JComponent c)
|
|
{
|
|
maybeUpdateLayoutState();
|
|
if (list.getModel().getSize() == 0)
|
|
return new Dimension(0, 0);
|
|
int nrows = Math.min(list.getVisibleRowCount(), list.getModel().getSize());
|
|
Rectangle bounds = getCellBounds(list, 0, nrows - 1);
|
|
return bounds.getSize();
|
|
}
|
|
|
|
/**
|
|
* Paints the packground of the list using the background color
|
|
* of the specified component.
|
|
*
|
|
* @param g The graphics context to paint in
|
|
* @param c The component to paint the background of
|
|
*/
|
|
public void paintBackground(Graphics g, JComponent c)
|
|
{
|
|
Dimension size = getPreferredSize(c);
|
|
Color save = g.getColor();
|
|
g.setColor(c.getBackground());
|
|
g.fillRect(0, 0, size.width, size.height);
|
|
g.setColor(save);
|
|
}
|
|
|
|
/**
|
|
* Paints a single cell in the list.
|
|
*
|
|
* @param g The graphics context to paint in
|
|
* @param row The row number to paint
|
|
* @param bounds The bounds of the cell to paint, assuming a coordinate
|
|
* system beginning at <code>(0,0)</code> in the upper left corner of the
|
|
* list
|
|
* @param rend A cell renderer to paint with
|
|
* @param data The data to provide to the cell renderer
|
|
* @param sel A selection model to provide to the cell renderer
|
|
* @param lead The lead selection index of the list
|
|
*/
|
|
void paintCell(Graphics g, int row, Rectangle bounds, ListCellRenderer rend,
|
|
ListModel data, ListSelectionModel sel, int lead)
|
|
{
|
|
boolean is_sel = list.isSelectedIndex(row);
|
|
boolean has_focus = false;
|
|
Component comp = rend.getListCellRendererComponent(list,
|
|
data.getElementAt(row),
|
|
0, is_sel, has_focus);
|
|
g.translate(bounds.x, bounds.y);
|
|
comp.setBounds(new Rectangle(0, 0, bounds.width, bounds.height));
|
|
comp.paint(g);
|
|
g.translate(-bounds.x, -bounds.y);
|
|
}
|
|
|
|
/**
|
|
* Paints the list by calling {@link #paintBackground} and then repeatedly
|
|
* calling {@link #paintCell} for each visible cell in the list.
|
|
*
|
|
* @param g The graphics context to paint with
|
|
* @param c Ignored; uses the saved {@link JList} reference
|
|
*/
|
|
public void paint(Graphics g, JComponent c)
|
|
{
|
|
int nrows = Math.min(list.getVisibleRowCount(), list.getModel().getSize());
|
|
if (nrows == 0)
|
|
return;
|
|
|
|
maybeUpdateLayoutState();
|
|
ListCellRenderer render = list.getCellRenderer();
|
|
ListModel model = list.getModel();
|
|
ListSelectionModel sel = list.getSelectionModel();
|
|
int lead = sel.getLeadSelectionIndex();
|
|
paintBackground(g, list);
|
|
|
|
for (int row = 0; row < nrows; ++row)
|
|
{
|
|
Rectangle bounds = getCellBounds(list, row, row);
|
|
paintCell(g, row, bounds, render, model, sel, lead);
|
|
}
|
|
}
|
|
|
|
public int locationToIndex(JList list, Point location)
|
|
{
|
|
return convertYToRow(location.y);
|
|
}
|
|
|
|
public Point indexToLocation(JList list, int index)
|
|
{
|
|
return new Point(0, convertRowToY(index));
|
|
}
|
|
}
|