summaryrefslogtreecommitdiffstats
path: root/libjava/javax/swing/JList.java
diff options
context:
space:
mode:
authorgraydon <graydon@138bc75d-0d04-0410-961f-82ee72b054a4>2004-03-17 21:29:02 +0000
committergraydon <graydon@138bc75d-0d04-0410-961f-82ee72b054a4>2004-03-17 21:29:02 +0000
commit26e56d50901d27a67646c97e14b3e71cec89ec68 (patch)
tree02790a2b250b62643a1de68b63bd078238bfaf46 /libjava/javax/swing/JList.java
parentf28cd43a6ebd2e92792019fc84a5ac1c42c8fd09 (diff)
downloadppe42-gcc-26e56d50901d27a67646c97e14b3e71cec89ec68.tar.gz
ppe42-gcc-26e56d50901d27a67646c97e14b3e71cec89ec68.zip
2004-03-12 Graydon Hoare <graydon@redhat.com>
* gnu/java/awt/peer/gtk/GdkGraphics2D.java: Clipping fixes. * javax/swing/JComponent.java (paint): Use persistent double buffer. * javax/swing/JList.java (ListListener): Revalidate on changes. * javax/swing/JScrollPane.java: Reimplement. * javax/swing/JViewport.java: Reimplement. * javax/swing/ScrollPaneLayout.java: Reimplement. * javax/swing/ViewportLayout.java: Tidy up. * javax/swing/plaf/basic/BasicButtonListener.java: Remove printlns. * javax/swing/plaf/basic/BasicScrollPaneUI.java: Reimplement. * javax/swing/plaf/basic/BasicSliderUI.java: Handle missing labels. * javax/swing/plaf/basic/BasicViewportUI.java: Implement in terms of backing store only. 2004-03-11 Thomas Fitzsimmons <fitzsim@redhat.com> * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c (window_wm_protocols_filter): New function. (window_focus_in_cb): Remove function. (window_focus_out_cb): Likewise. (window_focus_or_active_state_change_cb): New function. (create): Add filter that removes WM_TAKE_FOCUS client messages. (connectSignals): Don't attach handlers to focus-in-event or focus-out-event signals. Handle notify signal. 2004-03-11 David Jee <djee@redhat.com> * gnu/java/awt/peer/gtk/GtkCheckboxPeer.java (gtkSetLabel): New native method declaration. (setLabel): Use gtkSetLabel. * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCheckboxPeer.c (Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_gtkSetLabel): New method. 2004-03-10 Thomas Fitzsimmons <fitzsim@redhat.com> * gnu/java/awt/peer/gtk/GdkGraphics.java (setColor): Default to black when color argument is null. 2004-03-10 Kim Ho <kho@redhat.com> * java/awt/Container.java: Remove check for drag events. 2004-03-10 Kim Ho <kho@redhat.com> * java/awt/Container.java: (visitChild): Remove candidate clip. Use the component clip to intersect. * gnu/java/awt/peer/gtk/GtkComponentPeer.java: (handleEvent): Use the PaintEvent's clip. 2004-03-10 Kim Ho <kho@redhat.com> * gnu/java/awt/peer/gtk/GtkComponentPeer.java: (handleEvent): Don't set the clip for the Graphics object. 2004-03-09 Graydon Hoare <graydon@redhat.com> * jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGlyphVector.c: Fix double <-> fixed macros, reset font transform. * jni/gtk-peer/gnu_java_awt_peer_gtk_GdkClasspathFontPeerMetrics.c: Likewise. 2004-03-09�� Kim Ho <kho@redhat.com> * java/awt/Container.java: (visitChild): Move the x and y coordinate of the component rectangle to correct position. (handleEvent): Forward drag events to the pressed component. * javax/swing/plaf/basic/BasicScrollBarUI.java: Fix comments. (ArrowButtonListener::mousePressed): Stop the existing timer. (mouseDragged): Implement. (TrackListener::mousePressed): Only react if the press doesn't occur on the thumb, otherwise just set the offset. (TrackListener::mouseReleased): Unset the isAdjusting value. (createIncreaseIcon): Switch icon. (createDecreaseIcon): Switch icon. (calculatePreferredSize): Use width. (getThumbBounds): Use the top as the lower value. (layoutVScrollBar): Switch the button locations. (paintIncreaseHighlight): Paint correct side of thumb. (paintDecreaseHighlight): ditto. (valueForYPosition): Use top as the lower value. * javax/swing/plaf/basic/BasicSliderUI.java: Fix comments. (mouseDragged): Implement. (mousePressed): Only react when the thumb isn't pressed, otherwise just set offset. (mouseReleased): Handle a release of the thumb. (scrollDueToClickInTrack): Stop the timer first. * javax/swing/JProgressBar.java: (setString): Fix change condition. * javax/swing/JSeparator.java: Remove println's. 2004-03-08 David Jee <djee@redhat.com> * java/awt/image/AffineTransformOp.java: (filter): Use Graphics2D interface instead of directly using the GdkGraphics2D peer. 2004-03-05 David Jee <djee@redhat.com> * gnu/java/awt/peer/gtk/GtkButtonPeer.java (handleEvent): Action events are generated upon MOUSE_RELEASED. * java/awt/Container.java (acquireComponentForMouseEvent): Fixed. (handleEvent): Fixed. * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkEvents.c (state_to_awt_mods_with_button_states): New method. (pre_event_handler): Fixed mouse event generation. 2004-03-05 Olga Rodimina <rodimina@redhat.com> gnu/java/awt/peer/gtk/GdkGraphics2D.java (GdkGraphics2D (BufferedImage)): Initialize pixmap associated with specified BufferedImage. (setPaint): Changed implementation of Texture Paint to use AffineTransformOp. * java/awt/image/AffineTransformOp.java (createCompatibleDestRaster): Throw RasterFormatException if resulting width or height of raster is 0. 2004-03-04 Olga Rodimina <rodimina@redhat.com> * java/awt/image/AffineTransformOp.java: Removed unnecessary field interpolationType. Formatted some of the lines to be consistent with the GNU style. (AffineTransformOp): Create new RenderingHints containing specified interpolation type. (createCompatibleDestImage): Implemented. (createCompatibleDestRaster): Implemented. (filter): Implemented. (getBounds2D(BufferedImage)): Implemented. (getBounds2D(Raster)): Implemented. (getInterpolationType): Get interpolation value from rendering hints. 2004-03-04 David Jee <djee@redhat.com> * gnu/java/awt/peer/gtk/GtkContainerPeer.java (setFont): Check if child peers are null. 2004-03-04 Graydon Hoare <graydon@redhat.com> * testsuite/lib/libjava.exp (libjava_find_lib): Don't include .libs in -L option. (libjava_arguments): Add new libraries to argument list. 2004-03-04 Tom Tromey <tromey@redhat.com> * Makefile.in: Rebuilt. * Makefile.am (toolexeclib_LTLIBRARIES): Added lib-java-awt.la, lib-javax-swing.la, lib-java-applet.la, lib-java-beans.la. (misc_java_source_files): New macro. (swing_java_source_files): Likewise. (awt_java_source_files): Pruned. (applet_java_source_files): New macro. (beans_java_source_files): Likewise. (lib_java_applet_la_SOURCES): Likewise. (lib_java_awt_la_SOURCES): Likewise. (lib_javax_swing_la_SOURCES): Likewise. (lib_java_beans_la_SOURCES): Likewise. (all_java_object_files): Likewise. (%.lo: %.java): Use all_java_object_files. (all_java_source_files): Added new _SOURCES. (ordinary_java_source_files): Removed awt_java_source_files. 2004-03-02 Olga Rodimina <rodimina@redhat.com> * Makefile.am: Added java/awt/image/AffineTransformOp.java * Makefile.in: Re-generated. * java/awt/image/AffineTransformOp.java: New Class. 2004-03-01 Olga Rodimina <rodimina@redhat.com> * gnu/java/awt/peer/gtk/GdkGraphics2D.java (setPaint): Interpret correctly TexturePaint's anchor rectangle. (drawImage): Fixed scale factors of the affine transform. 2004-02-27 David Jee <djee@redhat.com> * gnu/java/awt/peer/gtk/GdkGraphics.java (GdkGraphics(Component)): Inherit font from component. (drawString): Use font style. * gnu/java/awt/peer/gtk/GtkCheckboxPeer.java (gtkSetFont): New native method declaration. (setFont): New method. * gnu/java/awt/peer/gtk/GtkComponentPeer.java (gtkSetFont): New native method declaration. (setFont): Call new native method gtkSetFont. * gnu/java/awt/peer/gtk/GtkContainerPeer.java (setFont): For all child components who do not their fonts set, set their peers' fonts with this container's font. * gnu/java/awt/peer/gtk/GtkLabelPeer.java: Move all native method declarations to the top for readability. (gtkSetFont): New native method declaration. (setFont): New method. * java/awt/Component.java (setFont): Invalidate after setting the font. * java/awt/Container.java (invalidateTree): New method. (setFont): Invalidate the container tree after setting the font. * jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics.c (Java_gnu_java_awt_peer_gtk_GdkGraphics_drawString): Use font style. * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCheckboxPeer.c (Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_gtkSetFont): New method. * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c (Java_gnu_java_awt_peer_gtk_GtkComponentPeer_gtkSetFont): New method. * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkLabelPeer.c (Java_gnu_java_awt_peer_gtk_GtkLabelPeer_gtkSetFont): New method. 2004-02-27 Olga Rodimina <rodimina@redhat.com> * gnu/java/awt/peer/gtk/GdkGraphics2D.java (updateBufferedImage): New helper function. Updates BufferedImage in memory if it was changed. (draw): changed to update BufferedImage in memory after this drawing operation (fill): Ditto. (draw3DRect): Ditto. (fill3DRect): Ditto. (clearRect): Ditto. (drawRaster): Ditto. (drawImage) : Ditto. Update only in case of GtkOffScreenImage with no affine transformation. (drawGlyphVector): Ditto. 2004-02-26 Olga Rodimina <rodimina@redhat.com> * gnu/java/awt/peer/gtk/GdkGraphics2D.java (isBufferedImageGraphics): New Helper function. Returns true if this graphics2d can be used to draw into buffered image and false otherwise. (updateImagePixels): New Helper function. Updates pixels in the BufferedImage. * jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics2D.c (getImagePixels): New function. Returns pixels of the buffered image associated with this Graphics2D. 2004-02-26 David Jee <djee@redhat.com> * java/awt/BorderLayout.java (layoutContainer): Fix width and height calculations to ensure that they're non-negative. * java/awt/Component.java (setBackground): If c is null, inherit from closest ancestor whose background color is set. 2004-02-26�� Kim Ho�� <kho@redhat.com> * Makefile.am: Add new files. * Makefile.in: Re-generate. * javax/swing/JProgressBar.java: (JProgressBar(int, int int)): Throw IllegalArgumentException if orientation is invalid. (JProgressBar(BoundedRangeModel)): Create ChangeListener and register it. UpdateUI. (getChangeListeners): Implement. (setModel): Reset ChangeListener. * javax/swing/JScrollBar.java: Implement. * javax/swing/JSeparator.java: Implement. * javax/swing/JSlider.java: (JSlider(int, int, int, int)): Throw IllegalArgumentException if orientation is invalid. (getChangeListeners): Fix method name. * javax/swing/SwingUtilities.java: (layoutCompoundLabel): If there is no text, set the text rectangle dimensions to 0. * javax/swing/plaf/basic/BasicButtonUI.java: (paint): If there is no text, don't paint it. * javax/swing/plaf/basic/BasicScrollBarUI.java: Implement. * javax/swing/plaf/basic/BasicSeparatorUI.java: Implement. * javax/swing/plaf/basic/BasicSliderUI.java: (propertyChange): If the model changes, change the listeners accordingly. 2004-02-25 Graydon Hoare <graydon@redhat.com> * javax/swing/AbstractButton.java: Add "final" qualifiers. * javax/swing/JList.java: Reimplement. * javax/swing/DefaultListSelectionModel.java: Reimplement. * javax/swing/plaf/basic/BasicListUI.java: Reimplement. * javax/swing/plaf/basic/BasicLookAndFeel.java: Add "purple" values. * javax/swing/ListModel.java: Javadoc. * javax/swing/ListSelectionModel.java: Add missing methods. * javax/swing/AbstractListModel.java: Javadoc and corrections. * javax/swing/DefaultListModel.java: Javadoc and corrections. * javax/swing/ListModel.java: Javadoc and corrections. * javax/swing/DefaultListCellRenderer.java: Minor tidying. 2004-02-25 David Jee <djee@redhat.com> * gnu/java/awt/peer/gtk/GtkFontPeer.java (GtkFontPeer): Change default size to 12. * gnu/java/awt/peer/gtk/GtkToolkit.java (getFontPeer): Change default size to 12. (getClasspathFontPeer): Likewise. Set default name to "Default". * java/awt/Font.java (Font(Map)): Call Font(String,Map). (Font(String,Map)): If attrs is null, initialize it as an empty HashMap, which will ensure that the Font will get default attributes. 2004-02-25 David Jee <djee@redhat.com> * gnu/java/awt/peer/gtk/GtkFontPeer.java (GtkFontPeer(String,int)): Call the new constructor with size 1. (GtkFontPeer(String,int,int)): New constructor with size attribute. * gnu/java/awt/peer/gtk/GtkToolkit.java (getFontPeer(String,int)): Call the new overload method with size 1. (getFontPeer(String,int,int)): New method. Overloaded with size attribute. (getClasspathFontPeer): Set the size of the font. 2004-02-24 Olga Rodimina <rodimina@redhat.com> * gnu/java/awt/peer/gtk/GdkGraphics2D.java (bimage): New field. (GdkGraphics2D): New Constructor. Constructs Graphics object that can be used to draw into the Buffered Image. * gnu/java/awt/peer/gtk/GdkGraphicsEnvironment.java: (GdkGraphicsEnvironment): Fixed to include public keyword. (createGraphics): Implemented. * gnu/java/awt/peer/gtk/GtkToolkit.java (getLocalGraphicsEnvironment): Implemented. * java/awt/GraphicsEnvironment.java: (getLocalGraphicsEnvironment): Implemented. * java/awt/image/BufferedImage.java: (createGraphics): Implemented. 2004-02-24 David Jee <djee@redhat.com> * java/awt/Component.java (eventTypeEnabled): Add MOUSE_MOVED and MOUSE_DRAGGED event types. * java/awt/Container.java (addNotifyContainerChildren): Fix event enabling. 2004-02-23 Olga Rodimina <rodimina@redhat.com> * Makefile.am: Added gnu/java/awt/peer/gtk/GdkGraphicsEnvironment.java * Makefile.in: Re-generated. * gnu/java/awt/peer/gtk/GdkGraphicsEnvironment.java: New Class. 2004-02-19 Kim Ho <kho@redhat.com> * Makefile.am: Add BasicProgressBarUI * Makefile.in: Regenerate. * javax/swing/JProgressBar.java: Re-implement. * javax/swing/plaf/basic/BasicLookAndFeel.java Add constants for JProgressBar. * javax/swing/plaf/basic/BasicProgressBarUI.java Implement. * javax/swing/plaf/basic/BasicSliderUI.java Change comments. (calculateGeometry): New method (paint): Remove unnecessary size calculations. 2004-02-18 Olga Rodimina <rodimina@redhat.com> * gnu/java/awt/peer/gtk/GdkGraphics2D.java (drawRaster): Fixed small error that caused imageToUser transformation to be set incorrectly. (toString): Implemented. 2004-02-18 David Jee <djee@redhat.com> * java/awt/CardLayout.java (addLayoutComponent): Show the first component added as the default. (removeLayoutComponent): After removing, show the next component. (gotoComponent): If there is only one component, show it and return. 2004-02-18 Kim Ho <kho@redhat.com> * javax/swing/JSlider.java: Re-order modifiers. * javax/swing/JLabel.java: Re-order modifiers. * javax/swing/JComponent.java: (addPropertyChangeListener): Implement. (removePropertyChangeListener): ditto. (firePropertyChangeEvent): ditto. 2004-02-17 David Jee <djee@redhat.com> * java/awt/Component.java (show): Dispatch ComponentEvent via system event queue. (hide): Likewise. (move): Likewise. (resize): Likewise. (reshape): Likewise. * java/awt/Window.java (setBoundsCallback): Likewise. 2004-02-17 David Jee <djee@redhat.com> * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c (Java_gnu_java_awt_peer_gtk_GtkComponentPeer_setNativeBounds): Use gtk_widget_set_size_request() instead of the deprecated gtk_widget_set_usize(). 2004-02-17 Kim Ho <kho@redhat.com> * javax/swing/JSlider.java: Fix comments and make property strings constants. (createStandardLabels): Use the labels preferred size as bounds. * javax/swing/plaf/basic/BasicSliderUI.java Fix comments. (ScrollHandler::actionPerformed): Don't calculate the timer stop value. Let the MouseListeners find the stop location. (getPreferredHorizontalSize): Re-implement. (getPreferredVerticalSize): ditto. (getMinimumHorizontalSize): ditto. (getMinimumVerticalSize): ditto. (getPreferredSize): ditto. (getMinimumSize): ditto. (getMaximumSize): ditto. (paintTicks): Use doubles to find the tick location. (paintHorizontalLabel):�� Use preferredSize as initial width and height. (paintVerticalLabel): ditto. 2004-02-17 Kim Ho <kho@redhat.com> * javax/swing/JLabel.java: Changed property strings to constants. (DISPLAYED_MNEMONIC_INDEX_CHANGED_PROPERTY): New property. (setText): Change mnemonic index if text is too short. (setDisplayedMnemonicIndex): Fire property change event. (getDisplayedMnemonicIndex): Remove check against short text. 2004-02-17 Olga Rodimina <rodimina@redhat.com> * gnu/java/awt/peer/gtk/GdkGraphics2D.java: (drawImage(img,xform,obs)): Invert xform before passing the xform to cairo. (drawImage(img,x,y,bgcolor,obs)): Implemented. (drawImage (img,x,y,w,h,bgcolor,obs)): Partly implemented. (drawImage (img,x,y,w,h,obs)): Implemented. (drawImage (img,dx1,dy1,dx2,dy2,sx1,sy1,sx2,sy2, bgcolor,obs)): Partly implemented. (drawImage (img,dx1,dy1,dx2,dy2,sx1,sy1,sx2,sy2,obs)): Implemented. * java/awt/image/BufferedImage.java: (copyData): if dest is null, create raster with same dimensions as the current image. 2004-02-16 Graydon Hoare <graydon@redhat.com> * javax/swing/plaf/basic/BasicLabelUI.java (getPreferredSize): Use layoutCL. * javax/swing/plaf/basic/BasicGraphicsUtils.java (getPreferredButtonSize): Start with empty view rect, layout using component's preferred alignment. * javax/swing/plaf/basic/BasicLookAndFeel.java: Add some Label and List defaults. 2004-02-16 David Jee <djee@redhat.com> * java/awt/Component.java (show): Dispatch COMPONENT_SHOWN ComponentEvent. (hide): Dispatch COMPONENT_HIDDEN ComponentEvent. (move): Erase old bounds and repaint new bounds. Dispatch COMPONENT_MOVED ComponentEvent. (resize): Erase old bounds and repaint new bounds. Dispatch COMPONENT_RESIZED ComponentEvent. (reshape): Dispatch COMPONENT_RESIZED and COMPONENT_MOVED ComponentEvents. * java/awt/Window.java (setBoundsCallback): Dispatch COMPONENT_RESIZED and COMPONENT_MOVED ComponentEvents. 2004-02-16 Olga Rodimina <rodimina@redhat.com> * gnu/java/awt/peer/gtk/GdkGraphics2D.java: (setRenderingHint): Added implementation of Interpolation rendering hints. (setRenderingHints): Ditto. * jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics2D.c: (drawPixels): fixed to allow user to choose type of filtering that should be used when displaying images. (cairoSurfaceSetFilter): New method. Sets filter type for interpolation of pixel values. 2004-02-16 David Jee <djee@redhat.com> * java/awt/GridBagLayout.java (calcCellSizes): Rows or columns with zero sizes should still be considered for extra space distribution. 2004-02-16 Kim Ho <kho@redhat.com> * javax/swing/JLabel.java: Re-implement. * javax/swing/plaf/basic/BasicLabelUI.java Re-implement. * javax/swing/plaf/basic/BasicLookAndFeel.java: Added constant. 2004-02-16�� Kim Ho�� <kho@redhat.com> * javax/swing/JSlider.java: Fix indentation and comments. (setModel): Remove null check to conform with Sun's. (setOrientation): Throw exception if not HORIZONTAL or VERTICAL. (getInverted): Use private variable instead of ComponentOrientation. (setInverted): ditto. * javax/swing/plaf/basic/BasicSliderUI.java: Fix indentation and comments. (propertyChange): Remove check for inverted slider, handle in main paint. (getMinimumSize): Return preferred size. (getMaximumSize): ditto. (calculateFocusRect): Don't relocate rectangle. (drawInverted): Return XOR of the slider's inversion and the component's orientation. (paint): Update leftToRightCache 2004-02-13 David Jee <djee@redhat.com> * java/awt/GridBagLayout.java (GetLayoutInfo): Fix weight and size distribution. Relocate repeated code to helper methods. (sortBySpan): New helper method. (distributeSizeAndWeight): Likewise. (calcCellWeights): Likewise. (calcCellSizes): Add comments. 2004-02-13 David Jee <djee@redhat.com> * java/awt/Component.java (show): Only do something if component is invisible at the moment. (hide): Only do something if component is visible at the moment. (reshape): If lightweight, erase old bounds and repaint new bounds. 2004-02-13�� Kim Ho�� <kho@redhat.com> * Makefile.am: Updated for new file. * Makefile.in: Regenerated. * javax/swing/JSlider.java: Reimplement. * javax/swing/SwingUtilities.java (layoutCompoundLabel): Use icon height instead of width. (paintComponent): Implement. * javax/swing/plaf/basic/BasicLookAndFeel.java: Add JSlider defaults. * javax/swing/plaf/basic/BasicSliderUI.java: Implement. New file. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@79607 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/javax/swing/JList.java')
-rw-r--r--libjava/javax/swing/JList.java1008
1 files changed, 845 insertions, 163 deletions
diff --git a/libjava/javax/swing/JList.java b/libjava/javax/swing/JList.java
index f87ce6201a9..92cce2240c1 100644
--- a/libjava/javax/swing/JList.java
+++ b/libjava/javax/swing/JList.java
@@ -1,4 +1,4 @@
-/* JList.java --
+/* JList.java --
Copyright (C) 2002, 2003 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -35,10 +35,10 @@ 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;
import java.awt.Color;
+import java.awt.Component;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.util.Vector;
@@ -46,208 +46,890 @@ import javax.accessibility.Accessible;
import javax.accessibility.AccessibleContext;
import javax.swing.event.ListDataEvent;
import javax.swing.event.ListDataListener;
+import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.plaf.ListUI;
+
+/**
+ * <p>This class is a facade over three separate objects: {@link
+ * javax.swing.ListModel}, {@link javax.swing.ListSelectionModel} and
+ * {@link javax.swing.plaf.ListUI}. The facade represents a unified "list"
+ * concept, with independently replacable (possibly client-provided) models
+ * for its contents and its current selection. In addition, each element in
+ * the list is rendered via a strategy class {@link
+ * javax.swing.ListCellRenderer}.</p>
+ *
+ * <p>Lists have many properties, some of which are stored in this class
+ * while others are delegated to the list's model or selection. The
+ * following properties are available:</p>
+ *
+ * <table>
+ * <tr><th>Property </th><th>Stored in</th><th>Bound?</th></tr>
+ * <tr><td>accessibleContext </td><td>list </td><td>no </td></tr>
+ * <tr><td>anchorSelectionIndex </td><td>selection</td><td>no </td></tr>
+ * <tr><td>cellRenderer </td><td>list </td><td>yes </td></tr>
+ * <tr><td>dragEnabled </td><td>list </td><td>no </td></tr>
+ * <tr><td>firstVisibleIndex </td><td>list </td><td>no </td></tr>
+ * <tr><td>fixedCellHeight </td><td>list </td><td>yes </td></tr>
+ * <tr><td>fixedCellWidth </td><td>list </td><td>yes </td></tr>
+ * <tr><td>lastVisibleIndex </td><td>list </td><td>no </td></tr>
+ * <tr><td>layoutOrientation </td><td>list </td><td>yes </td></tr>
+ * <tr><td>leadSelectionIndex </td><td>selection</td><td>no </td></tr>
+ * <tr><td>maxSelectionIndex </td><td>selection</td><td>no </td></tr>
+ * <tr><td>minSelectionIndex </td><td>selection</td><td>no </td></tr>
+ * <tr><td>model </td><td>list </td><td>yes </td></tr>
+ * <tr><td>opaque </td><td>list </td><td>no </td></tr>
+ * <tr><td>preferredScrollableViewportSize</td><td>list </td><td>no </td></tr>
+ * <tr><td>prototypeCellValue </td><td>list </td><td>yes </td></tr>
+ * <tr><td>scrollableTracksViewportHeight </td><td>list </td><td>no </td></tr>
+ * <tr><td>scrollableTracksViewportWidth </td><td>list </td><td>no </td></tr>
+ * <tr><td>selectedIndex </td><td>selection</td><td>no </td></tr>
+ * <tr><td>selectedIndices </td><td>selection</td><td>no </td></tr>
+ * <tr><td>selectedValue </td><td>model </td><td>no </td></tr>
+ * <tr><td>selectedValues </td><td>model </td><td>no </td></tr>
+ * <tr><td>selectionBackground </td><td>list </td><td>yes </td></tr>
+ * <tr><td>selectionEmpty </td><td>selection</td><td>no </td></tr>
+ * <tr><td>selectionForeground </td><td>list </td><td>yes </td></tr>
+ * <tr><td>selectionMode </td><td>selection</td><td>no </td></tr>
+ * <tr><td>selectionModel </td><td>list </td><td>yes </td></tr>
+ * <tr><td>UI </td><td>list </td><td>yes </td></tr>
+ * <tr><td>UIClassID </td><td>list </td><td>no </td></tr>
+ * <tr><td>valueIsAdjusting </td><td>list </td><td>no </td></tr>
+ * <tr><td>visibleRowCount </td><td>list </td><td>no </td></tr>
+ * </table>
+ *
+ * @author Graydon Hoare (graydon&064;redhat.com)
+ */
+
public class JList extends JComponent implements Accessible, Scrollable
{
private static final long serialVersionUID = 4406629526391098046L;
- Color select_back, select_fore;
- ListCellRenderer render;
- int visibles = 8;
-
- ListModel model;
- ListSelectionModel sel_model;
+ /**
+ * Constant value used in "layoutOrientation" property. This value means
+ * that cells are laid out in multiple columns "newspaper style",
+ * filling horizontally first, then vertically.
+ */
+ public static int HORIZONTAL_WRAP = 1;
- public JList()
- {
- init();
- }
+ /**
+ * Constant value used in "layoutOrientation" property. This value means
+ * that cells are laid out in a single vertical column. This is the default.
+ */
+ public static int VERTICAL = 2;
- public JList(Object[] listData)
- {
- init();
- setListData(listData);
- }
+ /**
+ * Constant value used in "layoutOrientation" property. This value means
+ * that cells are laid out in multiple columns "newspaper style", filling
+ * vertically first, then horizontally.
+ */
+ public static int VERTICAL_WRAP = 3;
+
+ /** Fired in a PropertyChangeEvent when the "cellRenderer" property changes. */
+ public static final String CELL_RENDERER_PROPERTY_CHANGED = "cellRenderer";
+ /** Fired in a PropertyChangeEvent when the "fixedCellHeight" property changes. */
+ public static final String FIXED_CELL_HEIGHT_PROPERTY_CHANGED = "fixedCellHeight";
- public JList(Vector listData)
- {
- init();
- setListData(listData);
- }
+ /** Fired in a PropertyChangeEvent when the "fixedCellWidth" property changes. */
+ public static final String FIXED_CELL_WIDTH_PROPERTY_CHANGED = "fixedCellWidth";
+ /** Fired in a PropertyChangeEvent when the "layoutOrientation" property changes. */
+ public static final String LAYOUT_ORIENTATION_PROPERTY_CHANGED = "layoutOrientation";
- public JList(ListModel listData)
- {
- init();
- setModel(listData);
- }
- void init()
- {
- render = new DefaultCellRenderer();
-
- sel_model = new DefaultListSelectionModel();
- setModel(new DefaultListModel());
+ /** Fired in a PropertyChangeEvent when the "model" property changes. */
+ public static final String MODEL_PROPERTY_CHANGED = "model";
- select_back = new Color(0,0,255);
- select_fore = new Color(255,255,255);
+ /** Fired in a PropertyChangeEvent when the "prototypeCellValue" property changes. */
+ public static final String PROTOTYPE_CELL_VALUE_PROPERTY_CHANGED = "prototypeCellValue";
- updateUI();
- }
+ /** Fired in a PropertyChangeEvent when the "selectionBackground" property changes. */
+ public static final String SELECTION_BACKGROUND_PROPERTY_CHANGED = "selectionBackground";
-
- public int getVisibleRowCount()
- { return visibles; }
- public void setVisibleRowCount(int visibleRowCount)
- {
- visibles = visibleRowCount;
- invalidate();
- repaint();
- }
+ /** Fired in a PropertyChangeEvent when the "selectionForeground" property changes. */
+ public static final String SELECTION_FOREGROUND_PROPERTY_CHANGED = "selectionForeground";
- public void addListSelectionListener (ListSelectionListener listener)
- {
- sel_model.addListSelectionListener (listener);
- }
+ /** Fired in a PropertyChangeEvent when the "selectionModel" property changes. */
+ public static final String SELECTION_MODEL_PROPERTY_CHANGED = "selectionModel";
+
+
+ /**
+ * This property indicates whether "drag and drop" functions are enabled
+ * on the list.
+ */
+ boolean dragEnabled;
+
+ /** This property provides a strategy for rendering cells in the list. */
+ ListCellRenderer cellRenderer;
+
+ /**
+ * This property indicates an fixed width to assign to all cells in the
+ * list. If its value is <code>-1</code>, no width has been
+ * assigned. This value can be set explicitly, or implicitly by setting
+ * the {@link #prototypeCellValue} property.
+ */
+ int fixedCellWidth;
- public void removeListSelectionListener (ListSelectionListener listener)
- {
- sel_model.removeListSelectionListener (listener);
- }
+ /**
+ * This property indicates an fixed height to assign to all cells in the
+ * list. If its value is <code>-1</code>, no height has been
+ * assigned. This value can be set explicitly, or implicitly by setting
+ * the {@link #prototypeCellValue} property.
+ */
+ int fixedCellHeight;
+
+ /**
+ * This property holds the current layout orientation of the list, which
+ * is one of the integer constants {@link #VERTICAL}, {@link
+ * #VERTICAL_WRAP}, or {@link #HORIZONTAL_WRAP}.
+ */
+
+ int layoutOrientation;
+
+ /** This property holds the data elements displayed by the list. */
+ ListModel model;
/**
- * @since 1.4
+ * <p>This property holds a reference to a "prototype" data value --
+ * typically a String -- which is used to calculate the {@link
+ * #fixedCellWidth} and {@link #fixedCellHeight} properties, using the
+ * {@link #cellRenderer} property to acquire a component to render the
+ * prototype.</p>
+ *
+ * <p>It is important that you <em>not</em> set this value to a
+ * component. It has to be a <em>data value</em> such as the objects you
+ * would find in the list's model. Setting it to a component will have
+ * undefined (and undesirable) affects. </p>
*/
- public ListSelectionListener[] getListSelectionListeners()
- {
- throw new Error ("not implemented");
- }
-
- void setSelectionMode(int a)
- { sel_model.setSelectionMode(a); }
- void setSelectedIndex(int a)
- { sel_model.setSelectionInterval(a,a); }
- int getSelectedIndex()
- { return sel_model.getMinSelectionIndex(); }
- Object getSelectedValue()
- {
- int index = getSelectedIndex();
- if (index == -1)
- return null;
- return getModel().getElementAt(index);
- }
+ Object prototypeCellValue;
+
+ /**
+ * This property specifies a foreground color for the selected cells in
+ * the list. When {@link ListCellRenderer.getListCellRendererComponent}
+ * is called with a selected cell object, the component returned will
+ * have its "foreground" set to this color.
+ */
+ Color selectionBackground;
+
+ /**
+ * This property specifies a background color for the selected cells in
+ * the list. When {@link ListCellRenderer.getListCellRendererComponent}
+ * is called with a selected cell object, the component returned will
+ * have its "background" property set to this color.
+ */
+ Color selectionForeground;
+
+ /**
+ * This property holds a description of which data elements in the {@link
+ * #model} property should be considered "selected", when displaying and
+ * interacting with the list.
+ */
+ ListSelectionModel selectionModel;
+
- Color getSelectionBackground()
- { return select_back; }
- Color getSelectionForeground()
- { return select_fore; }
+ /**
+ * This property indicates that the list's selection is currently
+ * "adjusting" -- perhaps due to a user actively dragging the mouse over
+ * multiple list elements -- and is therefore likely to change again in
+ * the near future. A {@link ListSelectionListener} might choose to delay
+ * updating its view of the list's selection until this property is
+ * false, meaning that the adjustment has completed.
+ */
+ boolean valueIsAdjusting;
+
+ /**
+ * This property indicates a <em>preference</em> for the number of rows
+ * displayed in the list, and will scale the
+ * {@link #preferredScrollableViewportSize} property accordingly. The actual
+ * number of displayed rows, when the list is placed in a real {@link
+ * Viewport} or other component, may be greater or less than this number.
+ */
+ int visibleRowCount;
+
+
+
+ /**
+ * Fire a {@link ListSelectionEvent} to all the registered ListSelectionListeners.
+ */
+ void fireSelectionValueChanged(int firstIndex, int lastIndex, boolean isAdjusting)
+ {
+ ListSelectionEvent evt = new ListSelectionEvent(this, firstIndex, lastIndex, isAdjusting);
+ ListSelectionListener listeners[] = getListSelectionListeners();
+ for (int i = 0; i < listeners.length; ++i)
+ {
+ listeners[i].valueChanged(evt);
+ }
+ }
- public void setListData(final Object[] listData)
+ /**
+ * This private listener propagates {@link ListSelectionEvent} events
+ * from the list's "selectionModel" property to the list's {@link
+ * ListSelectionListener} listeners. It also listens to {@link
+ * ListDataEvent} events from the list's {@link #model} property. If this
+ * class receives either type of event, it triggers repainting of the
+ * list.
+ */
+ private class ListListener
+ implements ListSelectionListener, ListDataListener
+ {
+ // ListDataListener events
+ public void contentsChanged(ListDataEvent event)
{
- class AL extends AbstractListModel
- {
- public int getSize() { return listData.length; }
- public Object getElementAt(int i) { return listData[i]; }
- };
-
- setModel (new AL());
+ JList.this.revalidate();
+ JList.this.repaint();
}
-
- public void setListData(final Vector listData)
+ public void intervalAdded(ListDataEvent event)
{
- class AL extends AbstractListModel
- {
- public int getSize() { return listData.size(); }
- public Object getElementAt(int i) { return listData.elementAt(i); }
- };
-
- setModel (new AL());
+ JList.this.revalidate();
+ JList.this.repaint();
}
-
-
- public ListCellRenderer getCellRenderer()
- { return render; }
- public void setCellRenderer(ListCellRenderer cellRenderer)
+ public void intervalRemoved(ListDataEvent event)
{
- render = cellRenderer;
- invalidate();
- repaint();
+ JList.this.revalidate();
+ JList.this.repaint();
}
-
- public void setModel(ListModel model)
+ // ListSelectionListener events
+ public void valueChanged(ListSelectionEvent event)
{
- ListDataListener l = new ListDataListener()
- {
- public void intervalAdded(ListDataEvent e) {
- repaint();
- }
- public void intervalRemoved(ListDataEvent e) {
- repaint();
- }
- public void contentsChanged(ListDataEvent e) {
- repaint();
- }
- };
-
- this.model = model;
- model.addListDataListener(l);
+ JList.this.fireSelectionValueChanged(event.firstIndex,
+ event.lastIndex,
+ event.isAdjusting);
+ JList.this.repaint();
}
+ };
- public ListModel getModel()
- { return model; }
-
-
- public ListUI getUI()
- { return (ListUI) ui; }
- public void setUI(ListUI ui)
- { super.setUI(ui); }
+ /**
+ * Shared ListListener instance, subscribed to both the current {@link
+ * #model} and {@link #selectionModel} properties of the list.
+ */
+ ListListener listListener;
- public void updateUI()
- {
- setUI((ListUI)UIManager.getUI(this));
- }
- public String getUIClassID()
- {
- return "ListUI";
- }
+ /**
+ * Creates a new JList object.
+ */
+ public JList()
+ {
+ init();
+ }
+
+ /**
+ * Creates a new JList object.
+ *
+ * @param listData Initial data to populate the list with
+ */
+ public JList(Object[] listData)
+ {
+ init();
+ setListData(listData);
+ }
+ /**
+ * Creates a new JList object.
+ *
+ * @param listData Initial data to populate the list with
+ */
+ public JList(Vector listData)
+ {
+ init();
+ setListData(listData);
+ }
- public AccessibleContext getAccessibleContext()
- {
+ /**
+ * Creates a new JList object.
+ *
+ * @param listData Initial data to populate the list with
+ */
+ public JList(ListModel listData)
+ {
+ init();
+ setModel(listData);
+ }
+
+ void init()
+ {
+ dragEnabled = false;
+ fixedCellHeight = -1;
+ fixedCellWidth = -1;
+ layoutOrientation = VERTICAL;
+ opaque = true;
+ valueIsAdjusting = false;
+ visibleRowCount = 8;
+
+ cellRenderer = new DefaultListCellRenderer();
+ listListener = new ListListener();
+
+ setModel(new DefaultListModel());
+ setSelectionModel(new DefaultListSelectionModel());
+
+ updateUI();
+ }
+
+ /**
+ * Gets the value of the {@link #fixedCellHeight} property. This property
+ * may be <code>-1</code> to indicate that no cell height has been
+ * set. This property is also set implicitly when the
+ * {@link #prototypeCellValue} property is set.
+ *
+ * @return The current value of the property
+ *
+ * @see #fixedCellHeight
+ * @see #setFixedCellHeight
+ * @see #setPrototypeCellValue
+ */
+ public int getFixedCellHeight()
+ {
+ return fixedCellHeight;
+ }
+
+ /**
+ * Sets the value of the {@link #fixedCellHeight} property. This property
+ * may be <code>-1</code> to indicate that no cell height has been
+ * set. This property is also set implicitly when the {@link
+ * #prototypeCellValue} property is set, but setting it explicitly
+ * overrides the height computed from {@link #prototypeCellValue}.
+ *
+ * @see #getFixedCellHeight
+ * @see #getPrototypeCellValue
+ */
+ public void setFixedCellHeight(int h)
+ {
+ int old = fixedCellHeight;
+ fixedCellHeight = h;
+ firePropertyChange(FIXED_CELL_WIDTH_PROPERTY_CHANGED, old, h);
+ }
+
+
+ /**
+ * Gets the value of the {@link #fixedCellWidth} property. This property
+ * may be <code>-1</code> to indicate that no cell width has been
+ * set. This property is also set implicitly when the {@link
+ * #prototypeCellValue} property is set.
+ *
+ * @return The current value of the property
+ *
+ * @see #setFixedCellWidth
+ * @see #setPrototypeCellValue
+ */
+ public int getFixedCellWidth()
+ {
+ return fixedCellWidth;
+ }
+
+ /**
+ * Sets the value of the {@link #fixedCellWidth} property. This property
+ * may be <code>-1</code> to indicate that no cell width has been
+ * set. This property is also set implicitly when the {@link
+ * #prototypeCellValue} property is set, but setting it explicitly
+ * overrides the width computed from {@link #prototypeCellValue}.
+ *
+ * @see #getFixedCellWidth
+ * @see #getPrototypeCellValue
+ */
+ public void setFixedCellWidth(int h)
+ {
+ int old = fixedCellHeight;
+ fixedCellHeight = h;
+ firePropertyChange(FIXED_CELL_HEIGHT_PROPERTY_CHANGED, old, h);
+ }
+
+
+ /**
+ * Gets the value of the {@link #visibleRowCount} property.
+ *
+ * @return the current value of the property.
+ */
+
+ public int getVisibleRowCount()
+ {
+ return visibleRowCount;
+ }
+
+ /**
+ * Sets the value of the {@link #visibleRowCount} property.
+ *
+ * @param visibleRowCount The new property value
+ */
+ public void setVisibleRowCount(int vc)
+ {
+ visibleRowCount = vc;
+ revalidate();
+ repaint();
+ }
+
+ /**
+ * Adds a {@link ListSelectionListener} to the listener list for this
+ * list. The listener will be called back with a {@link
+ * ListSelectionEvent} any time the list's {@link #selectionModel}
+ * property changes. The source of such events will be the JList,
+ * not the selection model.
+ *
+ * @param listener The new listener to add
+ */
+ public void addListSelectionListener(ListSelectionListener listener)
+ {
+ listenerList.add (ListSelectionListener.class, listener);
+ }
+
+ /**
+ * Removes a {@link ListSelectionListener} from the listener list for
+ * this list. The listener will no longer be called when the list's
+ * {@link #selectionModel} changes.
+ *
+ * @param listener The listener to remove
+ */
+ public void removeListSelectionListener(ListSelectionListener listener)
+ {
+ listenerList.remove(ListSelectionListener.class, listener);
+ }
+
+ /**
+ * Returns an array of all ListSelectionListeners subscribed to this
+ * list.
+ *
+ * @return The current subscribed listeners
+ *
+ * @since 1.4
+ */
+ public ListSelectionListener[] getListSelectionListeners()
+ {
+ return (ListSelectionListener[]) getListeners(ListSelectionListener.class);
+ }
+
+ /**
+ * Sets the list's "selectionMode" property, which simply mirrors the
+ * same property on the list's {@link #selectionModel} property. This
+ * property should be one of the integer constants
+ * <code>SINGLE_SELECTION</code>, <code>SINGLE_INTERVAL_SELECTION</code>,
+ * or <code>MULTIPLE_INTERVAL_SELECTION</code> from the {@link
+ * ListSelectionModel} interface.
+ *
+ * @param a The new selection mode
+ */
+ public void setSelectionMode(int a)
+ {
+ selectionModel.setSelectionMode(a);
+ }
+
+ /**
+ * Adds the interval <code>[a,a]</code> to the set of selections managed
+ * by this list's {@link #selectionModel} property. Depending on the
+ * selection mode, this may cause existing selections to become invalid,
+ * or may simply expand the set of selections.
+ *
+ * @param a A number in the half-open range <code>[0, x)</code> where
+ * <code>x = getModel.getSize()</code>, indicating the index of an
+ * element in the list to select.
+ *
+ * @see #setSelectionMode
+ * @see #selectionModel
+ */
+ public void setSelectedIndex(int a)
+ {
+ selectionModel.setSelectionInterval(a, a);
+ }
+
+ /**
+ * Returns the minimum index of an element in the list which is currently
+ * selected.
+ *
+ * @return A number in the half-open range <code>[0, x)</code> where
+ * <code>x = getModel.getSize()</code>, indicating the minimum index of
+ * an element in the list for which the element is selected, or
+ * <code>-1</code> if no elements are selected
+ */
+ public int getSelectedIndex()
+ {
+ return selectionModel.getMinSelectionIndex();
+ }
+
+ /**
+ * Indicates whether the list element at a given index value is
+ * currently selected.
+ *
+ * @param a The index to check
+ * @return <code>true</code> if <code>a</code> is the index of a selected
+ * list element
+ */
+ public boolean isSelectedIndex(int a)
+ {
+ return selectionModel.isSelectedIndex(a);
+ }
+
+ /**
+ * Returns the first value in the list's {@link #model} property which is
+ * selected, according to the list's {@link #selectionModel} property.
+ * This is equivalent to calling
+ * <code>getModel()getElementAt(getSelectedIndex())</code>, with a check
+ * for the special index value of <code>-1</code> which returns null
+ * <code>null</code>.
+ *
+ * @return The first selected element, or <code>null</code> if no element
+ * is selected.
+ */
+ public Object getSelectedValue()
+ {
+ int index = getSelectedIndex();
+ if (index == -1)
return null;
- }
+ return getModel().getElementAt(index);
+ }
- public Dimension getPreferredScrollableViewportSize()
- {
- return null;
- }
+ /**
+ * Gets the value of the {@link #selectionBackground} property.
+ *
+ * @return The current value of the property
+ */
+ public Color getSelectionBackground()
+ {
+ return selectionBackground;
+ }
- public int getScrollableUnitIncrement(Rectangle visibleRect,
- int orientation,
- int direction)
- {
- return 1;
- }
+ /**
+ * Sets the value of the {@link #selectionBackground} property.
+ *
+ * @param c The new value of the property
+ */
+ public void setSelectionBackground(Color c)
+ {
+ Color old = selectionBackground;
+ selectionBackground = c;
+ firePropertyChange(SELECTION_BACKGROUND_PROPERTY_CHANGED, old, c);
+ repaint();
+ }
- public int getScrollableBlockIncrement(Rectangle visibleRect,
- int orientation,
- int direction)
- {
- return 1;
- }
+ /**
+ * Gets the value of the {@link #selectionForeground} property.
+ *
+ * @return The current value of the property
+ */
+ public Color getSelectionForeground()
+ {
+ return selectionForeground;
+ }
+
+ /**
+ * Sets the value of the {@link #selectionForeground} property.
+ *
+ * @param c The new value of the property
+ */
+ public void setSelectionForeground(Color c)
+ {
+ Color old = selectionForeground;
+ selectionForeground = c;
+ firePropertyChange(SELECTION_FOREGROUND_PROPERTY_CHANGED, old, c);
+ }
- public boolean getScrollableTracksViewportWidth()
- {
- return false;
- }
+ /**
+ * Sets the {@link #model} property of the list to a new anonymous
+ * {@link AbstractListModel} subclass which accesses the provided Object
+ * array directly.
+ *
+ * @param listData The object array to build a new list model on
+ * @see #setModel
+ */
+ public void setListData(final Object[] listData)
+ {
+ setModel(new AbstractListModel()
+ {
+ public int getSize()
+ {
+ return listData.length;
+ }
+
+ public Object getElementAt(int i)
+ {
+ return listData[i];
+ }
+ });
+ }
- public boolean getScrollableTracksViewportHeight()
- {
- return false;
- }
-
+ /**
+ * Sets the {@link #model} property of the list to a new anonymous {@link
+ * AbstractListModel} subclass which accesses the provided vector
+ * directly.
+ *
+ * @param listData The object array to build a new list model on
+ * @see #setModel
+ */
+ public void setListData(final Vector listData)
+ {
+ setModel(new AbstractListModel()
+ {
+ public int getSize()
+ {
+ return listData.size();
+ }
+
+ public Object getElementAt(int i)
+ {
+ return listData.elementAt(i);
+ }
+ });
+ }
+
+ /**
+ * Gets the value of the {@link #cellRenderer} property.
+ *
+ * @return The current value of the property
+ */
+ public ListCellRenderer getCellRenderer()
+ {
+ return cellRenderer;
+ }
+
+ /**
+ * Sets the value of the {@link #celLRenderer} property.
+ *
+ * @param cellRenderer The new property value
+ */
+ public void setCellRenderer(ListCellRenderer cr)
+ {
+ ListCellRenderer old = cellRenderer;
+ cellRenderer = cr;
+ firePropertyChange(CELL_RENDERER_PROPERTY_CHANGED, old, cr);
+ revalidate();
+ repaint();
+ }
+
+ /**
+ * Gets the value of the {@link #model} property.
+ *
+ * @return The current value of the property
+ */
+ public ListModel getModel()
+ {
+ return model;
+ }
+
+ /**
+ * Sets the value of the {@link #model} property. The list's {@link
+ * #listListener} is unsubscribed from the existing model, if it exists,
+ * and re-subscribed to the new model.
+ *
+ * @param model The new property value
+ */
+ public void setModel(ListModel m)
+ {
+ ListModel old = model;
+ if (old != null)
+ old.removeListDataListener(listListener);
+ model = m;
+ if (model != null)
+ model.addListDataListener(listListener);
+ firePropertyChange(MODEL_PROPERTY_CHANGED, old, m);
+ }
+
+
+ public ListSelectionModel getSelectionModel()
+ {
+ return selectionModel;
+ }
+
+ /**
+ * Sets the value of the {@link #selectionModel} property. The list's
+ * {@link #listListener} is unsubscribed from the existing selection
+ * model, if it exists, and re-subscribed to the new selection model.
+ *
+ * @param l The new property value
+ */
+ public void setSelectionModel(ListSelectionModel l)
+ {
+ ListSelectionModel old = selectionModel;
+ if (old != null)
+ old.removeListSelectionListener(listListener);
+ selectionModel = l;
+ if (selectionModel != null)
+ selectionModel.addListSelectionListener(listListener);
+ firePropertyChange(SELECTION_MODEL_PROPERTY_CHANGED, old, l);
+ }
+
+ /**
+ * Gets the value of the UI property.
+ *
+ * @return The current property value
+ */
+ public ListUI getUI()
+ {
+ return (ListUI) ui;
+ }
+
+ /**
+ * Sets the value of the UI property.
+ *
+ * @param ui The new property value
+ */
+ public void setUI(ListUI ui)
+ {
+ super.setUI(ui);
+ }
+
+ /**
+ * Calls {@link #setUI} with the {@link ListUI} subclass
+ * returned from calling {@link UIManager#getUI}.
+ */
+ public void updateUI()
+ {
+ setUI((ListUI) UIManager.getUI(this));
+ }
+
+ /**
+ * Return the class identifier for the list's UI property. This should
+ * be the constant string <code>"ListUI"</code>, and map to an
+ * appropriate UI class in the {@link UIManager}.
+ *
+ * @return The class identifier
+ */
+ public String getUIClassID()
+ {
+ return "ListUI";
+ }
+
+
+ /**
+ * Returns the current value of the {@link #prototypeCellValue}
+ * property. This property holds a reference to a "prototype" data value
+ * -- typically a String -- which is used to calculate the {@link
+ * #fixedCellWidth} and {@link #fixedCellHeight} properties, using the
+ * {@link #cellRenderer} property to acquire a component to render the
+ * prototype.
+ *
+ * @return The current prototype cell value
+ * @see #setPrototypeCellValue
+ */
+ public Object getPrototypeCellValue()
+ {
+ return prototypeCellValue;
+ }
+
+ /**
+ * <p>Set the {@link #prototypeCellValue} property. This property holds a
+ * reference to a "prototype" data value -- typically a String -- which
+ * is used to calculate the {@link #fixedCellWidth} and {@link
+ * #fixedCellHeight} properties, using the {@link #cellRenderer} property
+ * to acquire a component to render the prototype.</p>
+ *
+ * <p>It is important that you <em>not</em> set this value to a
+ * component. It has to be a <em>data value</em> such as the objects you
+ * would find in the list's model. Setting it to a component will have
+ * undefined (and undesirable) affects. </p>
+ *
+ * @param obj The new prototype cell value
+ * @see #getPrototypeCellValue
+ */
+ public void setPrototypeCellValue(Object obj)
+ {
+ Object old = prototypeCellValue;
+ Component comp = getCellRenderer()
+ .getListCellRendererComponent(this, obj, 0, false, false);
+ Dimension d = comp.getPreferredSize();
+ fixedCellWidth = d.width;
+ fixedCellHeight = d.height;
+ prototypeCellValue = obj;
+ firePropertyChange(PROTOTYPE_CELL_VALUE_PROPERTY_CHANGED, old, obj);
+ }
+
+ public AccessibleContext getAccessibleContext()
+ {
+ return null;
+ }
+
+ /**
+ * Returns a size indicating how much space this list would like to
+ * consume, when contained in a scrollable viewport. This is part of the
+ * {@link Scrollable} interface, which interacts with {@link
+ * ScrollPaneLayout} and {@link Viewport} to define scrollable objects.
+ *
+ * @return The preferred size, or <code>null</code>
+ */
+ public Dimension getPreferredScrollableViewportSize()
+ {
+ return null;
+ }
+
+ /**
+ * <p>Return the number of pixels the list must scroll in order to move a
+ * "unit" of the list into the provided visible rectangle. When the
+ * provided direction is positive, the call describes a "downwards"
+ * scroll, which will be exposing a cell at a <em>greater</em> index in
+ * the list than those elements currently showing. Then the provided
+ * direction is negative, the call describes an "upwards" scroll, which
+ * will be exposing a cell at a <em>lesser</em> index in the list than
+ * those elements currently showing.</p>
+ *
+ * <p>If the provided orientation is <code>HORIZONTAL</code>, the above
+ * comments refer to "rightwards" for positive direction, and "leftwards"
+ * for negative.</p>
+ *
+ *
+ * @param visibleRect The rectangle to scroll an element into
+ * @param orientation One of the numeric consants <code>VERTICAL</code>
+ * or <code>HORIZONTAL</code>
+ * @param direction An integer indicating the scroll direction: positive means
+ * forwards (down, right), negative means backwards (up, left)
+ *
+ * @return The scrollable unit increment, in pixels
+ */
+ public int getScrollableUnitIncrement(Rectangle visibleRect,
+ int orientation, int direction)
+ {
+ return 1;
+ }
+
+ /**
+ * <p>Return the number of pixels the list must scroll in order to move a
+ * "block" of the list into the provided visible rectangle. When the
+ * provided direction is positive, the call describes a "downwards"
+ * scroll, which will be exposing a cell at a <em>greater</em> index in
+ * the list than those elements currently showing. Then the provided
+ * direction is negative, the call describes an "upwards" scroll, which
+ * will be exposing a cell at a <em>lesser</em> index in the list than
+ * those elements currently showing.</p>
+ *
+ * <p>If the provided orientation is <code>HORIZONTAL</code>, the above
+ * comments refer to "rightwards" for positive direction, and "leftwards"
+ * for negative.</p>
+ *
+ *
+ * @param visibleRect The rectangle to scroll an element into
+ * @param orientation One of the numeric consants <code>VERTICAL</code>
+ * or <code>HORIZONTAL</code>
+ * @param direction An integer indicating the scroll direction: positive means
+ * forwards (down, right), negative means backwards (up, left)
+ *
+ * @return The scrollable unit increment, in pixels
+ */
+ public int getScrollableBlockIncrement(Rectangle visibleRect,
+ int orientation, int direction)
+ {
+ return 1;
+ }
+
+ /**
+ * Gets the value of the {@link #scrollableTracksViewportWidth} property.
+ *
+ * @return <code>true</code> if the viewport is larger (horizontally)
+ * than the list and the list should be expanded to fit the viewport;
+ * <code>false</code> if the viewport is smaller than the list and the
+ * list should scroll (horizontally) within the viewport
+ */
+ public boolean getScrollableTracksViewportWidth()
+ {
+ return false;
+ }
+
+ /**
+ * Gets the value of the {@link #scrollableTracksViewportWidth} property.
+ *
+ * @return <code>true</code> if the viewport is larger (vertically)
+ * than the list and the list should be expanded to fit the viewport;
+ * <code>false</code> if the viewport is smaller than the list and the
+ * list should scroll (vertically) within the viewport
+ */
+ public boolean getScrollableTracksViewportHeight()
+ {
+ return false;
+ }
}
OpenPOWER on IntegriCloud