Commit 31e632d3 by Graydon Hoare

[multiple changes]

2004-04-09  Thomas Fitzsimmons  <fitzsim@redhat.com>

	* gnu/java/awt/peer/gtk/GtkPanelPeer.java (connectSignals):
	Remove method.
	* jni/gtk-peer/gnu_java_awt_peer_gtk_GtkPanelPeer.c: Remove
	unused code.

2004-04-02  Olga Rodimina  <rodimina@redhat.com>

	* Makefile.am: Added new file.
	* Makefile.in: Regenerate.
	* javax/swing/ImageIcon.java:
	(ImageIcon(file)): set description of the icon
	to the file name
	* javax/swing/JCheckBoxMenuItem.java:
	Mostly Implemented. Work in progress.
	* javax/swing/JRadioButtonMenuItem.java:
 	Reimplement constructors to use JToggleButtonModel.
	* javax/swing/plaf/basic/BasicIconFactory.java:
	(getCheckBoxMenuItemIcon): return check box
	icon.
	* javax/swing/plaf/basic/BasicMenuItemUI.java:
	paint menu item selected only when it is armed and
	pressed.

2004-04-02  David Jee  <djee@redhat.com>

	* gnu/java/awt/peer/gtk/GtkMenuItemPeer.java
	(GtkMenuItemPeer): Only connect signals if this isn't a Menu peer.
	* java/awt/Component.java
	(add): Set the parent of the popup as this component.
	* java/awt/PopupMenu.java
	(addNotify): Create popup menu when peer is null.
	(show): Call addNotify() if peer is null.
	* jni/gtk-peer/gnu_java_awt_peer_gtk_GtkPopupMenuPeer.c
	(Java_gnu_java_awt_peer_gtk_GtkPopupMenuPeer_show): Set the button
	argument for gtk_menu_popup() as zero. This causes the popup menu to
	respond to any mouse button.

2004-03-31  Olga Rodimina  <rodimina@redhat.com>

	* Makefile.am: Added new file.
	* Makefile.in: Regenerate.
	* javax/swing/JRadioButtonMenuItem.java:
	Implemented.
	* javax/swing/plaf/basic/BasicIconFactory.java:
	(getRadioButtonMenuItemIcon): Return
	radio button icon.
	* javax/swing/plaf/basic/BasicMenuItemUI.java:
	(getPreferredSize): Add size of checkIcon if it
	exists.
	(installDefaults): Don't initialize checkIcon.
	It's value will be set in subclasses.
	(uninstallDefaults): remove uninstallation of
	checkIcon.
	(paint): Moved code to paintMenuItem().
	(paintMenuItem): Implemented.
	* javax/swing/plaf/basic/BasicRadioButtonMenuItemUI.java:
	UI delegate for JRadioButtonMenuItem.

2004-03-29  Olga Rodimina  <rodimina@redhat.com>

	* javax/swing/plaf/basic/BasicMenuItemUI.java:
	Corrected position of the accelerator.

2004-03-29  Olga Rodimina  <rodimina@redhat.com>

	* Makefile.am: Added new file.
	* Makefile.in: Regenerate.
	* javax/swing/JMenuItem.java: Partly
	implemented. Work in progress
	* javax/swing/plaf/basic/BasicLookAndFeel.java:
	Changed default value of acceleratorDelimiter.
	* javax/swing/plaf/basic/BasicMenuItemUI.java:
	New class. Partly implemented.

2004-03-26  Mark Wielaard  <mark@klomp.org>

	* native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkChoicePeer.c
	(item_activate): Declare label before use.
	* native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c
	(gtkSetFont): Removed unused variable label.
	(addExposeFilter): Declare variables before use.
	(removeExposeFilter): Likewise.
	* native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkFileDialogPeer.c
	(ok_clicked): Declare str_fileName before use.

2004-03-26  David Jee  <djee@redhat.com>

	* gnu/java/awt/peer/gtk/GtkMenuPeer.java
	(addSeparator): Remove.
	* java/awt/Menu.java
	(separator): Remove static final MenuItem field.
	(separatorLabel): New static final String field.
	(addSeparator): Do not use peer method; use add(MenuItem) instead.
	Use separatorLabel to denote that it is a separator.
	(insertSeparator): Create a new MenuItem with separatorLabel, instead
	of reusing the static separator instance, because a MenuItem instance
	can't be added more than once without being cloned.
	* java/awt/peer/MenuPeer.java
	(addSeparator): Remove from interface.

2004-03-26  David Jee  <djee@redhat.com>

	* gnu/java/awt/peer/gtk/GtkMenuItemPeer.java
	(connectSignals): New native method declaration.
	(GtkMenuItemPeer): Connect signals if the parent is a Menu.
	* java/awt/MenuItem.java
	(getActionCommand): Return the label if the action command is not set.
	* jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuBarPeer.c
	(Java_gnu_java_awt_peer_gtk_GtkMenuBarPeer_addMenu): Use
	gtk_menu_shell_append().
	* jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuItemPeer.c
	(item_activate): Fix argument type.
	(Java_gnu_java_awt_peer_gtk_GtkMenuItemPeer_create): Do not connect
	signal here.
	(Java_gnu_java_awt_peer_gtk_GtkMenuItemPeer_connectSignals): New
	method.
	* jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuPeer.c
	(Java_gnu_java_awt_peer_gtk_GtkMenuPeer_create): Check if a label is
	given. Add the menu widget's top-level GtkWindow to the global window
	group, so it can grab the pointer.
	(Java_gnu_java_awt_peer_gtk_GtkMenuPeer_addItem): Use
	gtk_menu_shell_append().

2004-03-23  Graydon Hoare  <graydon@redhat.com>

	* java/text/AttributedString.java
	(addAttribute): Fix off-by-one.
	(getIterator): Likewise.
	* java/text/AttributedStringIterator.java
	(getRunLimit): Correct logic.
	(getRunStart): Likewise.
	(getAttribute): Fix inequality.
	(getAttributes): Likewise.
	* testsuite/libjava.mauve/xfails: Remove AttributedString xfail.

2004-03-23  Kim Ho  <kho@redhat.com>

	* javax/swing/plaf/basic/BasicTabbedPaneUI.java:
	(calculateSizes): Return real width and height.

2004-03-23  Kim Ho  <kho@redhat.com>

	* javax/swing/plaf/basic/BasicTabbedPaneUI.java
	(calculateTabRects): Set the selectedRun before
	trying to rotate tabs.

2004-03-23  Kim Ho  <kho@redhat.com>

	* Makefile.am: New file
	* Makefile.in: Regenerate
	* java/awt/Graphics.java: (drawRect):
	Draw to the correct point.
	* javax/swing/DefaultSingleSelectionModel.java
	(isSelected): Return true if the selected index
	is not -1.
	* javax/swing/JLabel.java: Do not change mnemonic
	index if text is null.
	* javax/swing/JProgressBar.java: Use JComponent's
	EventListenerList.
	* javax/swing/JScrollBar.java: Ditto.
	* javax/swing/JSlider.java: Ditto.
	* javax/swing/JTabbedPane.java: Reimplement.
	* javax/swing/plaf/basic/BasicLookAndFeel.java:
	Add defaults for TabbedPane.
	* javax/swing/plaf/basic/BasicArrowButton.java:
	Implement
	* javax/swing/plaf/basic/BasicProgressBarUI.java:
	(paintDeterminate): Don't paint String if it's
	empty.
	(paintIndeterminate): ditto.
	* javax/swing/plaf/basic/BasicTabbedPaneUI.java:
	Reimplement.

2004-03-19  Michael Koch  <konqueror@gmx.de>

	* java/awt/image/AffineTransformOp.java
	(AffineTransformOp): Made public.
	* javax/swing/JComponent.java
	(listenerList): Made protected.
	(accessibleContext): Likewise.
	* javax/swing/JList.java
	(valueChanged): Dont use internal fields of ListSelectionEvent.
	* javax/swing/JViewport.java
	(getView): Dont use internal fields of Component.
	(addImpl): Likewise.
	* javax/swing/Timer.java
	(isRunning): Made public.
	(start): Likewise.
	(stop): Likewise.
	* javax/swing/UIDefaults.java
	(getInt): Made public.
	* javax/swing/plaf/basic/BasicListUI.java
	(mousePressed): Dont use internal fields of MouseEvent.
	(propertyChanged): Dont use internal fields of PropertyChangeEvent.
	* javax/swing/plaf/basic/BasicScrollBarUI.java
	(arrowIcon): Made static.
	* javax/swing/plaf/basic/BasicViewportUI.java
	(stateChanged): Dont use internal field on ChangeEvent.
	* javax/swing/text/JTextComponent.java
	(getUI): Call UIManager.getUI().
	(updateUI): Use getUI().

2004-03-19  Graydon Hoare  <graydon@redhat.com>

	* javax/swing/JComponent.java: Turn off double buffer by default.
	* javax/swing/plaf/basic/BasicViewportUI.java: Clear rects before painting.
	* jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics2D.c
	(Java_gnu_java_awt_peer_gtk_GdkGraphics2D_gdkDrawDrawable):
	Use cairo to copy areas.
	(Java_gnu_java_awt_peer_gtk_GdkGraphics2D_cairoClip):
	Initialize and set clip region.

2004-03-15  Thomas Fitzsimmons  <fitzsim@redhat.com>

	* java/applet/Applet.java (preferredSize): Override deprecated
	variant of getPreferredSize.
	(minimumSize): Override deprecated variant of getMinimumSize.

2004-03-15  Olga Rodimina  <rodimina@redhat.com>

	* gnu/java/awt/peer/gtk/GdkGraphics2D.java
	(drawImage(img,xform,bgcolor,obs)): New Method.
	Helper function that every drawImage method will
	use.
	(drawRaster): Added new parameter, bgcolor. All
	transparent pixels are changed to bgcolor before
	image is drawn.
	(drawRenderedImage): Fixed to use changed drawRaster().
	(drawImage(image,xform,obs): Fixed to use new helper function
	(drawImage(image,op,x,y)): Ditto.
	(drawImage (img,x,y,observer)): Ditto.
	((PainterThread) bgcolor): New Field.
	((PainterThread) (setPixels)): Changed all transparent pixels
	to bgcolor.
	(drawImage(img,x,y,width,height,bgcolor,observer)):
	Fixed FIXME - all the transparent pixels are
	changed to the specified bgcolor.
	(drawImage(img, x, y, width, height, observer): Changed to
	use function above.
	(drawImage (img,dx1,dy1,dx2,dy2,sx1,sy1,sx2,sy2,bgcolor,observer)):
	Fixed FIXME- changed all transparent pixels to bgcolor.
	(drawImage (img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, observer)):
	Changed to use function above.

2004-03-14  Thomas Fitzsimmons  <fitzsim@redhat.com>

	* java/applet/Applet.java (dimensions): New field.
	(getDimensions): New method.
	(getPreferredSize): Call getDimensions.
	(getMinimumSize): Likewise.

2004-03-13  Thomas Fitzsimmons  <fitzsim@redhat.com>

	* jni/classpath/jcl.c: Include stdlib.h, not malloc.h.
	* jni/classpath/jnilink.c: Likewise.

	* java/applet/Applet.java (getPreferredSize): New method.
	(getMinimumSize): New method.

From-SVN: r80762
parent 2d49ce67
2004-04-09 Thomas Fitzsimmons <fitzsim@redhat.com>
* gnu/java/awt/peer/gtk/GtkPanelPeer.java (connectSignals):
Remove method.
* jni/gtk-peer/gnu_java_awt_peer_gtk_GtkPanelPeer.c: Remove
unused code.
2004-04-02 Olga Rodimina <rodimina@redhat.com>
* Makefile.am: Added new file.
* Makefile.in: Regenerate.
* javax/swing/ImageIcon.java:
(ImageIcon(file)): set description of the icon
to the file name
* javax/swing/JCheckBoxMenuItem.java:
Mostly Implemented. Work in progress.
* javax/swing/JRadioButtonMenuItem.java:
Reimplement constructors to use JToggleButtonModel.
* javax/swing/plaf/basic/BasicIconFactory.java:
(getCheckBoxMenuItemIcon): return check box
icon.
* javax/swing/plaf/basic/BasicMenuItemUI.java:
paint menu item selected only when it is armed and
pressed.
2004-04-02 David Jee <djee@redhat.com>
* gnu/java/awt/peer/gtk/GtkMenuItemPeer.java
(GtkMenuItemPeer): Only connect signals if this isn't a Menu peer.
* java/awt/Component.java
(add): Set the parent of the popup as this component.
* java/awt/PopupMenu.java
(addNotify): Create popup menu when peer is null.
(show): Call addNotify() if peer is null.
* jni/gtk-peer/gnu_java_awt_peer_gtk_GtkPopupMenuPeer.c
(Java_gnu_java_awt_peer_gtk_GtkPopupMenuPeer_show): Set the button
argument for gtk_menu_popup() as zero. This causes the popup menu to
respond to any mouse button.
2004-03-31 Olga Rodimina <rodimina@redhat.com>
* Makefile.am: Added new file.
* Makefile.in: Regenerate.
* javax/swing/JRadioButtonMenuItem.java:
Implemented.
* javax/swing/plaf/basic/BasicIconFactory.java:
(getRadioButtonMenuItemIcon): Return
radio button icon.
* javax/swing/plaf/basic/BasicMenuItemUI.java:
(getPreferredSize): Add size of checkIcon if it
exists.
(installDefaults): Don't initialize checkIcon.
It's value will be set in subclasses.
(uninstallDefaults): remove uninstallation of
checkIcon.
(paint): Moved code to paintMenuItem().
(paintMenuItem): Implemented.
* javax/swing/plaf/basic/BasicRadioButtonMenuItemUI.java:
UI delegate for JRadioButtonMenuItem.
2004-03-29 Olga Rodimina <rodimina@redhat.com>
* javax/swing/plaf/basic/BasicMenuItemUI.java:
Corrected position of the accelerator.
2004-03-29 Olga Rodimina <rodimina@redhat.com>
* Makefile.am: Added new file.
* Makefile.in: Regenerate.
* javax/swing/JMenuItem.java: Partly
implemented. Work in progress
* javax/swing/plaf/basic/BasicLookAndFeel.java:
Changed default value of acceleratorDelimiter.
* javax/swing/plaf/basic/BasicMenuItemUI.java:
New class. Partly implemented.
2004-03-26 Mark Wielaard <mark@klomp.org>
* native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkChoicePeer.c
(item_activate): Declare label before use.
* native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c
(gtkSetFont): Removed unused variable label.
(addExposeFilter): Declare variables before use.
(removeExposeFilter): Likewise.
* native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkFileDialogPeer.c
(ok_clicked): Declare str_fileName before use.
2004-03-26 David Jee <djee@redhat.com>
* gnu/java/awt/peer/gtk/GtkMenuPeer.java
(addSeparator): Remove.
* java/awt/Menu.java
(separator): Remove static final MenuItem field.
(separatorLabel): New static final String field.
(addSeparator): Do not use peer method; use add(MenuItem) instead.
Use separatorLabel to denote that it is a separator.
(insertSeparator): Create a new MenuItem with separatorLabel, instead
of reusing the static separator instance, because a MenuItem instance
can't be added more than once without being cloned.
* java/awt/peer/MenuPeer.java
(addSeparator): Remove from interface.
2004-03-26 David Jee <djee@redhat.com>
* gnu/java/awt/peer/gtk/GtkMenuItemPeer.java
(connectSignals): New native method declaration.
(GtkMenuItemPeer): Connect signals if the parent is a Menu.
* java/awt/MenuItem.java
(getActionCommand): Return the label if the action command is not set.
* jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuBarPeer.c
(Java_gnu_java_awt_peer_gtk_GtkMenuBarPeer_addMenu): Use
gtk_menu_shell_append().
* jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuItemPeer.c
(item_activate): Fix argument type.
(Java_gnu_java_awt_peer_gtk_GtkMenuItemPeer_create): Do not connect
signal here.
(Java_gnu_java_awt_peer_gtk_GtkMenuItemPeer_connectSignals): New
method.
* jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuPeer.c
(Java_gnu_java_awt_peer_gtk_GtkMenuPeer_create): Check if a label is
given. Add the menu widget's top-level GtkWindow to the global window
group, so it can grab the pointer.
(Java_gnu_java_awt_peer_gtk_GtkMenuPeer_addItem): Use
gtk_menu_shell_append().
2004-03-23 Graydon Hoare <graydon@redhat.com>
* java/text/AttributedString.java
(addAttribute): Fix off-by-one.
(getIterator): Likewise.
* java/text/AttributedStringIterator.java
(getRunLimit): Correct logic.
(getRunStart): Likewise.
(getAttribute): Fix inequality.
(getAttributes): Likewise.
* testsuite/libjava.mauve/xfails: Remove AttributedString xfail.
2004-03-23 Kim Ho <kho@redhat.com>
* javax/swing/plaf/basic/BasicTabbedPaneUI.java:
(calculateSizes): Return real width and height.
2004-03-23 Kim Ho <kho@redhat.com>
* javax/swing/plaf/basic/BasicTabbedPaneUI.java
(calculateTabRects): Set the selectedRun before
trying to rotate tabs.
2004-03-23 Kim Ho <kho@redhat.com>
* Makefile.am: New file
* Makefile.in: Regenerate
* java/awt/Graphics.java: (drawRect):
Draw to the correct point.
* javax/swing/DefaultSingleSelectionModel.java
(isSelected): Return true if the selected index
is not -1.
* javax/swing/JLabel.java: Do not change mnemonic
index if text is null.
* javax/swing/JProgressBar.java: Use JComponent's
EventListenerList.
* javax/swing/JScrollBar.java: Ditto.
* javax/swing/JSlider.java: Ditto.
* javax/swing/JTabbedPane.java: Reimplement.
* javax/swing/plaf/basic/BasicLookAndFeel.java:
Add defaults for TabbedPane.
* javax/swing/plaf/basic/BasicArrowButton.java:
Implement
* javax/swing/plaf/basic/BasicProgressBarUI.java:
(paintDeterminate): Don't paint String if it's
empty.
(paintIndeterminate): ditto.
* javax/swing/plaf/basic/BasicTabbedPaneUI.java:
Reimplement.
2004-03-19 Michael Koch <konqueror@gmx.de>
* java/awt/image/AffineTransformOp.java
(AffineTransformOp): Made public.
* javax/swing/JComponent.java
(listenerList): Made protected.
(accessibleContext): Likewise.
* javax/swing/JList.java
(valueChanged): Dont use internal fields of ListSelectionEvent.
* javax/swing/JViewport.java
(getView): Dont use internal fields of Component.
(addImpl): Likewise.
* javax/swing/Timer.java
(isRunning): Made public.
(start): Likewise.
(stop): Likewise.
* javax/swing/UIDefaults.java
(getInt): Made public.
* javax/swing/plaf/basic/BasicListUI.java
(mousePressed): Dont use internal fields of MouseEvent.
(propertyChanged): Dont use internal fields of PropertyChangeEvent.
* javax/swing/plaf/basic/BasicScrollBarUI.java
(arrowIcon): Made static.
* javax/swing/plaf/basic/BasicViewportUI.java
(stateChanged): Dont use internal field on ChangeEvent.
* javax/swing/text/JTextComponent.java
(getUI): Call UIManager.getUI().
(updateUI): Use getUI().
2004-03-19 Graydon Hoare <graydon@redhat.com>
* javax/swing/JComponent.java: Turn off double buffer by default.
* javax/swing/plaf/basic/BasicViewportUI.java: Clear rects before painting.
* jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics2D.c
(Java_gnu_java_awt_peer_gtk_GdkGraphics2D_gdkDrawDrawable):
Use cairo to copy areas.
(Java_gnu_java_awt_peer_gtk_GdkGraphics2D_cairoClip):
Initialize and set clip region.
2004-03-15 Thomas Fitzsimmons <fitzsim@redhat.com>
* java/applet/Applet.java (preferredSize): Override deprecated
variant of getPreferredSize.
(minimumSize): Override deprecated variant of getMinimumSize.
2004-03-15 Olga Rodimina <rodimina@redhat.com>
* gnu/java/awt/peer/gtk/GdkGraphics2D.java
(drawImage(img,xform,bgcolor,obs)): New Method.
Helper function that every drawImage method will
use.
(drawRaster): Added new parameter, bgcolor. All
transparent pixels are changed to bgcolor before
image is drawn.
(drawRenderedImage): Fixed to use changed drawRaster().
(drawImage(image,xform,obs): Fixed to use new helper function
(drawImage(image,op,x,y)): Ditto.
(drawImage (img,x,y,observer)): Ditto.
((PainterThread) bgcolor): New Field.
((PainterThread) (setPixels)): Changed all transparent pixels
to bgcolor.
(drawImage(img,x,y,width,height,bgcolor,observer)):
Fixed FIXME - all the transparent pixels are
changed to the specified bgcolor.
(drawImage(img, x, y, width, height, observer): Changed to
use function above.
(drawImage (img,dx1,dy1,dx2,dy2,sx1,sy1,sx2,sy2,bgcolor,observer)):
Fixed FIXME- changed all transparent pixels to bgcolor.
(drawImage (img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, observer)):
Changed to use function above.
2004-03-14 Thomas Fitzsimmons <fitzsim@redhat.com>
* java/applet/Applet.java (dimensions): New field.
(getDimensions): New method.
(getPreferredSize): Call getDimensions.
(getMinimumSize): Likewise.
2004-03-13 Thomas Fitzsimmons <fitzsim@redhat.com>
* jni/classpath/jcl.c: Include stdlib.h, not malloc.h.
* jni/classpath/jnilink.c: Likewise.
* java/applet/Applet.java (getPreferredSize): New method.
(getMinimumSize): New method.
2004-04-15 Bryce McKinlay <mckinlay@redhat.com> 2004-04-15 Bryce McKinlay <mckinlay@redhat.com>
* prims.cc (_Jv_AllocObject): Remove `size' argument. * prims.cc (_Jv_AllocObject): Remove `size' argument.
......
...@@ -1326,17 +1326,21 @@ javax/swing/border/TitledBorder.java \ ...@@ -1326,17 +1326,21 @@ javax/swing/border/TitledBorder.java \
javax/swing/GrayFilter.java \ javax/swing/GrayFilter.java \
javax/swing/AbstractAction.java \ javax/swing/AbstractAction.java \
javax/swing/AbstractButton.java \ javax/swing/AbstractButton.java \
javax/swing/plaf/basic/BasicArrowButton.java \
javax/swing/plaf/basic/BasicButtonListener.java \ javax/swing/plaf/basic/BasicButtonListener.java \
javax/swing/plaf/basic/BasicButtonUI.java \ javax/swing/plaf/basic/BasicButtonUI.java \
javax/swing/plaf/basic/BasicCheckBoxUI.java \ javax/swing/plaf/basic/BasicCheckBoxUI.java \
javax/swing/plaf/basic/BasicGraphicsUtils.java \ javax/swing/plaf/basic/BasicGraphicsUtils.java \
javax/swing/plaf/basic/BasicLabelUI.java \ javax/swing/plaf/basic/BasicLabelUI.java \
javax/swing/plaf/basic/BasicListUI.java \ javax/swing/plaf/basic/BasicListUI.java \
javax/swing/plaf/basic/BasicMenuItemUI.java \
javax/swing/plaf/basic/BasicOptionPaneUI.java \ javax/swing/plaf/basic/BasicOptionPaneUI.java \
javax/swing/plaf/basic/BasicPanelUI.java \ javax/swing/plaf/basic/BasicPanelUI.java \
javax/swing/plaf/basic/BasicProgressBarUI.java \ javax/swing/plaf/basic/BasicProgressBarUI.java \
javax/swing/plaf/basic/BasicRootPaneUI.java \ javax/swing/plaf/basic/BasicRootPaneUI.java \
javax/swing/plaf/basic/BasicRadioButtonUI.java \ javax/swing/plaf/basic/BasicRadioButtonUI.java \
javax/swing/plaf/basic/BasicRadioButtonMenuItemUI.java \
javax/swing/plaf/basic/BasicCheckBoxMenuItemUI.java \
javax/swing/plaf/basic/BasicScrollBarUI.java \ javax/swing/plaf/basic/BasicScrollBarUI.java \
javax/swing/plaf/basic/BasicScrollPaneUI.java \ javax/swing/plaf/basic/BasicScrollPaneUI.java \
javax/swing/plaf/basic/BasicSeparatorUI.java \ javax/swing/plaf/basic/BasicSeparatorUI.java \
......
...@@ -1008,17 +1008,21 @@ javax/swing/border/TitledBorder.java \ ...@@ -1008,17 +1008,21 @@ javax/swing/border/TitledBorder.java \
javax/swing/GrayFilter.java \ javax/swing/GrayFilter.java \
javax/swing/AbstractAction.java \ javax/swing/AbstractAction.java \
javax/swing/AbstractButton.java \ javax/swing/AbstractButton.java \
javax/swing/plaf/basic/BasicArrowButton.java \
javax/swing/plaf/basic/BasicButtonListener.java \ javax/swing/plaf/basic/BasicButtonListener.java \
javax/swing/plaf/basic/BasicButtonUI.java \ javax/swing/plaf/basic/BasicButtonUI.java \
javax/swing/plaf/basic/BasicCheckBoxUI.java \ javax/swing/plaf/basic/BasicCheckBoxUI.java \
javax/swing/plaf/basic/BasicGraphicsUtils.java \ javax/swing/plaf/basic/BasicGraphicsUtils.java \
javax/swing/plaf/basic/BasicLabelUI.java \ javax/swing/plaf/basic/BasicLabelUI.java \
javax/swing/plaf/basic/BasicListUI.java \ javax/swing/plaf/basic/BasicListUI.java \
javax/swing/plaf/basic/BasicMenuItemUI.java \
javax/swing/plaf/basic/BasicOptionPaneUI.java \ javax/swing/plaf/basic/BasicOptionPaneUI.java \
javax/swing/plaf/basic/BasicPanelUI.java \ javax/swing/plaf/basic/BasicPanelUI.java \
javax/swing/plaf/basic/BasicProgressBarUI.java \ javax/swing/plaf/basic/BasicProgressBarUI.java \
javax/swing/plaf/basic/BasicRootPaneUI.java \ javax/swing/plaf/basic/BasicRootPaneUI.java \
javax/swing/plaf/basic/BasicRadioButtonUI.java \ javax/swing/plaf/basic/BasicRadioButtonUI.java \
javax/swing/plaf/basic/BasicRadioButtonMenuItemUI.java \
javax/swing/plaf/basic/BasicCheckBoxMenuItemUI.java \
javax/swing/plaf/basic/BasicScrollBarUI.java \ javax/swing/plaf/basic/BasicScrollBarUI.java \
javax/swing/plaf/basic/BasicScrollPaneUI.java \ javax/swing/plaf/basic/BasicScrollPaneUI.java \
javax/swing/plaf/basic/BasicSeparatorUI.java \ javax/swing/plaf/basic/BasicSeparatorUI.java \
...@@ -4533,18 +4537,22 @@ DEP_FILES = .deps/$(srcdir)/$(CONVERT_DIR)/gen-from-JIS.P \ ...@@ -4533,18 +4537,22 @@ DEP_FILES = .deps/$(srcdir)/$(CONVERT_DIR)/gen-from-JIS.P \
.deps/javax/swing/plaf/TextUI.P .deps/javax/swing/plaf/ToolBarUI.P \ .deps/javax/swing/plaf/TextUI.P .deps/javax/swing/plaf/ToolBarUI.P \
.deps/javax/swing/plaf/ToolTipUI.P .deps/javax/swing/plaf/TreeUI.P \ .deps/javax/swing/plaf/ToolTipUI.P .deps/javax/swing/plaf/TreeUI.P \
.deps/javax/swing/plaf/UIResource.P .deps/javax/swing/plaf/ViewportUI.P \ .deps/javax/swing/plaf/UIResource.P .deps/javax/swing/plaf/ViewportUI.P \
.deps/javax/swing/plaf/basic/BasicArrowButton.P \
.deps/javax/swing/plaf/basic/BasicBorders.P \ .deps/javax/swing/plaf/basic/BasicBorders.P \
.deps/javax/swing/plaf/basic/BasicButtonListener.P \ .deps/javax/swing/plaf/basic/BasicButtonListener.P \
.deps/javax/swing/plaf/basic/BasicButtonUI.P \ .deps/javax/swing/plaf/basic/BasicButtonUI.P \
.deps/javax/swing/plaf/basic/BasicCheckBoxMenuItemUI.P \
.deps/javax/swing/plaf/basic/BasicCheckBoxUI.P \ .deps/javax/swing/plaf/basic/BasicCheckBoxUI.P \
.deps/javax/swing/plaf/basic/BasicGraphicsUtils.P \ .deps/javax/swing/plaf/basic/BasicGraphicsUtils.P \
.deps/javax/swing/plaf/basic/BasicIconFactory.P \ .deps/javax/swing/plaf/basic/BasicIconFactory.P \
.deps/javax/swing/plaf/basic/BasicLabelUI.P \ .deps/javax/swing/plaf/basic/BasicLabelUI.P \
.deps/javax/swing/plaf/basic/BasicListUI.P \ .deps/javax/swing/plaf/basic/BasicListUI.P \
.deps/javax/swing/plaf/basic/BasicLookAndFeel.P \ .deps/javax/swing/plaf/basic/BasicLookAndFeel.P \
.deps/javax/swing/plaf/basic/BasicMenuItemUI.P \
.deps/javax/swing/plaf/basic/BasicOptionPaneUI.P \ .deps/javax/swing/plaf/basic/BasicOptionPaneUI.P \
.deps/javax/swing/plaf/basic/BasicPanelUI.P \ .deps/javax/swing/plaf/basic/BasicPanelUI.P \
.deps/javax/swing/plaf/basic/BasicProgressBarUI.P \ .deps/javax/swing/plaf/basic/BasicProgressBarUI.P \
.deps/javax/swing/plaf/basic/BasicRadioButtonMenuItemUI.P \
.deps/javax/swing/plaf/basic/BasicRadioButtonUI.P \ .deps/javax/swing/plaf/basic/BasicRadioButtonUI.P \
.deps/javax/swing/plaf/basic/BasicRootPaneUI.P \ .deps/javax/swing/plaf/basic/BasicRootPaneUI.P \
.deps/javax/swing/plaf/basic/BasicScrollBarUI.P \ .deps/javax/swing/plaf/basic/BasicScrollBarUI.P \
......
...@@ -201,7 +201,7 @@ public class GdkGraphics2D extends Graphics2D ...@@ -201,7 +201,7 @@ public class GdkGraphics2D extends Graphics2D
// draw current buffered image to the pixmap associated // draw current buffered image to the pixmap associated
// with it. // with it.
drawImage (bimage, new AffineTransform (1,0,0,1,0,0), null); drawImage (bimage, new AffineTransform (1,0,0,1,0,0), bg, null);
} }
...@@ -440,6 +440,69 @@ public class GdkGraphics2D extends Graphics2D ...@@ -440,6 +440,69 @@ public class GdkGraphics2D extends Graphics2D
} }
private boolean drawImage(Image img,
AffineTransform xform,
Color bgcolor,
ImageObserver obs)
{
if (img instanceof GtkOffScreenImage &&
img.getGraphics () instanceof GdkGraphics2D &&
(xform == null
|| xform.getType () == AffineTransform.TYPE_IDENTITY
|| xform.getType () == AffineTransform.TYPE_TRANSLATION)
)
{
// we are being asked to flush a double buffer from Gdk
GdkGraphics2D g2 = (GdkGraphics2D) img.getGraphics ();
gdkDrawDrawable (g2, (int)xform.getTranslateX(), (int)xform.getTranslateY());
if (isBufferedImageGraphics ())
updateBufferedImage();
return true;
}
else
{
// In this case, xform is an AffineTransform that transforms bounding
// box of the specified image from image space to user space. However
// when we pass this transform to cairo, cairo will use this transform
// to map "user coordinates" to "pixel" coordinates, which is the
// other way around. Therefore to get the "user -> pixel" transform
// that cairo wants from "image -> user" transform that we currently
// have, we will need to invert the transformation matrix.
AffineTransform invertedXform = new AffineTransform();
try
{
invertedXform = xform.createInverse();
if (img instanceof BufferedImage)
{
// draw an image which has actually been loaded
// into memory fully
BufferedImage b = (BufferedImage) img;
return drawRaster (b.getColorModel (),
b.getData (),
invertedXform,
bgcolor);
}
else
{
// begin progressive loading in a separate thread
new PainterThread (this, img, invertedXform, bgcolor);
return false;
}
}
catch (NoninvertibleTransformException e)
{
throw new ImagingOpException("Unable to invert transform "
+ xform.toString());
}
}
}
////////////////////////////////////////////////// //////////////////////////////////////////////////
////// Implementation of Graphics2D Methods ////// ////// Implementation of Graphics2D Methods //////
...@@ -965,7 +1028,8 @@ public class GdkGraphics2D extends Graphics2D ...@@ -965,7 +1028,8 @@ public class GdkGraphics2D extends Graphics2D
} }
private boolean drawRaster (ColorModel cm, Raster r, private boolean drawRaster (ColorModel cm, Raster r,
AffineTransform imageToUser) AffineTransform imageToUser,
Color bgcolor)
{ {
if (r == null) if (r == null)
return false; return false;
...@@ -1012,6 +1076,18 @@ public class GdkGraphics2D extends Graphics2D ...@@ -1012,6 +1076,18 @@ public class GdkGraphics2D extends Graphics2D
pixels = pixels2; pixels = pixels2;
} }
// change all transparent pixels in the image to the
// specified bgcolor
if (bgcolor != null)
{
for (int i = 0; i < pixels.length; i++)
{
if (cm.getAlpha (pixels[i]) == 0)
pixels[i] = bgcolor.getRGB ();
}
}
stateSave (); stateSave ();
translate (x, y); translate (x, y);
drawPixels (pixels, r.getWidth (), r.getHeight (), r.getWidth (), i2u); drawPixels (pixels, r.getWidth (), r.getHeight (), r.getWidth (), i2u);
...@@ -1026,7 +1102,7 @@ public class GdkGraphics2D extends Graphics2D ...@@ -1026,7 +1102,7 @@ public class GdkGraphics2D extends Graphics2D
public void drawRenderedImage(RenderedImage image, public void drawRenderedImage(RenderedImage image,
AffineTransform xform) AffineTransform xform)
{ {
drawRaster (image.getColorModel(), image.getData(), xform); drawRaster (image.getColorModel(), image.getData(), xform, bg);
} }
public void drawRenderableImage(RenderableImage image, public void drawRenderableImage(RenderableImage image,
...@@ -1039,60 +1115,7 @@ public class GdkGraphics2D extends Graphics2D ...@@ -1039,60 +1115,7 @@ public class GdkGraphics2D extends Graphics2D
AffineTransform xform, AffineTransform xform,
ImageObserver obs) ImageObserver obs)
{ {
if (img instanceof GtkOffScreenImage && return drawImage(img, xform, bg, obs);
img.getGraphics () instanceof GdkGraphics2D &&
(xform == null
|| xform.getType () == AffineTransform.TYPE_IDENTITY
|| xform.getType () == AffineTransform.TYPE_TRANSLATION)
)
{
// we are being asked to flush a double buffer from Gdk
GdkGraphics2D g2 = (GdkGraphics2D) img.getGraphics ();
gdkDrawDrawable (g2, (int)xform.getTranslateX(), (int)xform.getTranslateY());
if (isBufferedImageGraphics ())
updateBufferedImage();
return true;
}
else
{
// In this case, xform is an AffineTransform that transforms bounding
// box of the specified image from image space to user space. However
// when we pass this transform to cairo, cairo will use this transform
// to map "user coordinates" to "pixel" coordinates, which is the
// other way around. Therefore to get the "user -> pixel" transform
// that cairo wants from "image -> user" transform that we currently
// have, we will need to invert the transformation matrix.
AffineTransform invertedXform = new AffineTransform();
try
{
invertedXform = xform.createInverse();
if (img instanceof BufferedImage)
{
// draw an image which has actually been loaded
// into memory fully
BufferedImage b = (BufferedImage) img;
return drawRaster (b.getColorModel (),
b.getData (),
invertedXform);
}
else
{
// begin progressive loading in a separate thread
new PainterThread (this, img, invertedXform);
return false;
}
}
catch (NoninvertibleTransformException e)
{
throw new ImagingOpException("Unable to invert transform "
+ xform.toString());
}
}
} }
public void drawImage(BufferedImage image, public void drawImage(BufferedImage image,
...@@ -1101,13 +1124,13 @@ public class GdkGraphics2D extends Graphics2D ...@@ -1101,13 +1124,13 @@ public class GdkGraphics2D extends Graphics2D
int y) int y)
{ {
Image filtered = op.filter(image, null); Image filtered = op.filter(image, null);
drawImage(filtered, new AffineTransform(1f,0f,0f,1f,x,y), null); drawImage(filtered, new AffineTransform(1f,0f,0f,1f,x,y), bg, null);
} }
public boolean drawImage (Image img, int x, int y, public boolean drawImage (Image img, int x, int y,
ImageObserver observer) ImageObserver observer)
{ {
return drawImage(img, new AffineTransform(1f,0f,0f,1f,x,y), observer); return drawImage(img, new AffineTransform(1f,0f,0f,1f,x,y), bg, observer);
} }
...@@ -1130,11 +1153,14 @@ public class GdkGraphics2D extends Graphics2D ...@@ -1130,11 +1153,14 @@ public class GdkGraphics2D extends Graphics2D
Image image; Image image;
ColorModel defaultModel; ColorModel defaultModel;
AffineTransform xform; AffineTransform xform;
Color bgcolor;
public PainterThread (GdkGraphics2D g, Image im, AffineTransform xf) public PainterThread (GdkGraphics2D g, Image im,
AffineTransform xf, Color bg)
{ {
image = im; image = im;
xform = xf; xform = xf;
bgcolor = bg;
this.gr = (GdkGraphics2D) g.create (); this.gr = (GdkGraphics2D) g.create ();
new Thread (this).start (); new Thread (this).start ();
} }
...@@ -1184,6 +1210,18 @@ public class GdkGraphics2D extends Graphics2D ...@@ -1184,6 +1210,18 @@ public class GdkGraphics2D extends Graphics2D
else else
pixels2 = pixels; pixels2 = pixels;
// change all transparent pixels in the image to the
// specified bgcolor
if (bgcolor != null)
{
for (int i = 0; i < pixels2.length; i++)
{
if (model.getAlpha (pixels2[i]) == 0)
pixels2[i] = bgcolor.getRGB ();
}
}
double[] xf = new double[6]; double[] xf = new double[6];
xform.getMatrix(xf); xform.getMatrix(xf);
gr.drawPixels (pixels2, w, h, scansize, xf); gr.drawPixels (pixels2, w, h, scansize, xf);
...@@ -1347,40 +1385,27 @@ public class GdkGraphics2D extends Graphics2D ...@@ -1347,40 +1385,27 @@ public class GdkGraphics2D extends Graphics2D
Color bgcolor, ImageObserver observer) Color bgcolor, ImageObserver observer)
{ {
// FIXME: change all the transparent pixels in the image to
// bgcolor.
return drawImage (img, x, y, width, height, observer);
}
public boolean drawImage (Image img, int x, int y, int width, int height,
ImageObserver observer)
{
double scaleX = width / (double) img.getWidth (observer); double scaleX = width / (double) img.getWidth (observer);
double scaleY = height / (double) img.getHeight (observer); double scaleY = height / (double) img.getHeight (observer);
return drawImage (img, return drawImage (img,
new AffineTransform(scaleX, 0f, 0f, scaleY, x, y), new AffineTransform(scaleX, 0f, 0f, scaleY, x, y),
bgcolor,
observer); observer);
} }
public boolean drawImage (Image img, int dx1, int dy1, int dx2, int dy2, public boolean drawImage (Image img, int x, int y, int width, int height,
int sx1, int sy1, int sx2, int sy2, ImageObserver observer)
Color bgcolor, ImageObserver observer)
{ {
// FIXME: change all transparent pixels in the image to return drawImage (img, x, y, width, height, bg, observer);
// bgcolor
return drawImage (img, dx1, dy1, dx2, dy2,
sx1, sy1, sx2, sy2, observer);
} }
public boolean drawImage (Image img, int dx1, int dy1, int dx2, int dy2, public boolean drawImage (Image img, int dx1, int dy1, int dx2, int dy2,
int sx1, int sy1, int sx2, int sy2, int sx1, int sy1, int sx2, int sy2,
ImageObserver observer) Color bgcolor, ImageObserver observer)
{ {
Image subImage; Image subImage;
...@@ -1421,9 +1446,19 @@ public class GdkGraphics2D extends Graphics2D ...@@ -1421,9 +1446,19 @@ public class GdkGraphics2D extends Graphics2D
return drawImage(subImage, new AffineTransform(scaleX, 0, 0, return drawImage(subImage, new AffineTransform(scaleX, 0, 0,
scaleY, dx1, dy1), scaleY, dx1, dy1),
bgcolor,
observer); observer);
} }
public boolean drawImage (Image img, int dx1, int dy1, int dx2, int dy2,
int sx1, int sy1, int sx2, int sy2,
ImageObserver observer)
{
return drawImage (img, dx1, dy1, dx2, dy2,
sx1, sy1, sx2, sy2, bg, observer);
}
public void drawOval(int x, int y, int width, int height) public void drawOval(int x, int y, int width, int height)
{ {
drawArc (x, y, width, height, 0, 360); drawArc (x, y, width, height, 0, 360);
......
...@@ -50,6 +50,7 @@ public class GtkMenuItemPeer extends GtkMenuComponentPeer ...@@ -50,6 +50,7 @@ public class GtkMenuItemPeer extends GtkMenuComponentPeer
implements MenuItemPeer implements MenuItemPeer
{ {
native void create (String label); native void create (String label);
public native void connectSignals ();
public GtkMenuItemPeer (MenuItem item) public GtkMenuItemPeer (MenuItem item)
{ {
...@@ -57,6 +58,9 @@ public class GtkMenuItemPeer extends GtkMenuComponentPeer ...@@ -57,6 +58,9 @@ public class GtkMenuItemPeer extends GtkMenuComponentPeer
create (item.getLabel ()); create (item.getLabel ());
setEnabled (item.isEnabled ()); setEnabled (item.isEnabled ());
setParent (item); setParent (item);
if (item.getParent() instanceof Menu && ! (item instanceof Menu))
connectSignals();
} }
void setParent (MenuItem item) void setParent (MenuItem item)
......
...@@ -95,10 +95,5 @@ public class GtkMenuPeer extends GtkMenuItemPeer ...@@ -95,10 +95,5 @@ public class GtkMenuPeer extends GtkMenuItemPeer
addItem (item, key, shiftModifier); addItem (item, key, shiftModifier);
} }
public void addSeparator ()
{
addItem (new MenuItem ("-"));
}
native public void delItem (int index); native public void delItem (int index);
} }
...@@ -46,7 +46,6 @@ public class GtkPanelPeer extends GtkContainerPeer ...@@ -46,7 +46,6 @@ public class GtkPanelPeer extends GtkContainerPeer
{ {
native void create (); native void create ();
native void connectJObject (); native void connectJObject ();
native void connectSignals ();
public GtkPanelPeer (Panel p) public GtkPanelPeer (Panel p)
{ {
......
...@@ -78,6 +78,11 @@ public class Applet extends Panel ...@@ -78,6 +78,11 @@ public class Applet extends Panel
private transient AppletStub stub; private transient AppletStub stub;
/** /**
* The dimensions passed to this applet through its HTML tag.
*/
private transient Dimension dimensions;
/**
* The accessibility context for this applet. * The accessibility context for this applet.
* *
* @serial the accessibleContext for this * @serial the accessibleContext for this
...@@ -457,6 +462,41 @@ public class Applet extends Panel ...@@ -457,6 +462,41 @@ public class Applet extends Panel
s.defaultReadObject(); s.defaultReadObject();
} }
private Dimension getDimensions ()
{
if (dimensions == null)
{
int width = Integer.parseInt(stub.getParameter("width"));
int height = Integer.parseInt(stub.getParameter("height"));
dimensions = new Dimension(width, height);
}
return dimensions;
}
/**
* Returns an instance of {@link Dimension} representing the
* applet's width and height parameters.
*
* @return the applet's preferred size
*/
public Dimension preferredSize()
{
return getDimensions ();
}
/**
* Returns an instance of {@link Dimension} representing the
* applet's width and height parameters.
*
* @return the applet's minimum size
*/
public Dimension minimumSize()
{
return getDimensions ();
}
/** /**
* This class provides accessibility support for Applets, and is the * This class provides accessibility support for Applets, and is the
* runtime type returned by {@link #getAccessibleContext()}. * runtime type returned by {@link #getAccessibleContext()}.
......
...@@ -3816,6 +3816,12 @@ public abstract class Component ...@@ -3816,6 +3816,12 @@ public abstract class Component
if (popups == null) if (popups == null)
popups = new Vector(); popups = new Vector();
popups.add(popup); popups.add(popup);
if (popup.parent != null)
popup.parent.remove(popup);
popup.parent = this;
if (peer != null)
popup.addNotify();
} }
/** /**
......
...@@ -417,7 +417,7 @@ draw3DRect(int x, int y, int width, int height, boolean raised) ...@@ -417,7 +417,7 @@ draw3DRect(int x, int y, int width, int height, boolean raised)
drawLine(x1, y2, x1, y1); drawLine(x1, y2, x1, y1);
setColor(br); setColor(br);
drawLine(x2, y1, x2, y2); drawLine(x2, y1, x2, y2);
drawLine(x2, y1, x1, y2); drawLine(x2, y2, x1, y2);
setColor(color); setColor(color);
} }
......
...@@ -82,7 +82,7 @@ private boolean isHelpMenu; ...@@ -82,7 +82,7 @@ private boolean isHelpMenu;
// From the serialization spec. FIXME: what should it be? // From the serialization spec. FIXME: what should it be?
private int menuSerializedDataVersion; private int menuSerializedDataVersion;
static final MenuItem separator = new MenuItem("-"); static final String separatorLabel = "-";
/*************************************************************************/ /*************************************************************************/
...@@ -295,8 +295,7 @@ insert(String label, int index) ...@@ -295,8 +295,7 @@ insert(String label, int index)
public void public void
addSeparator() addSeparator()
{ {
if (peer != null) add(new MenuItem(separatorLabel));
((MenuPeer) peer).addSeparator();
} }
/*************************************************************************/ /*************************************************************************/
...@@ -314,7 +313,7 @@ addSeparator() ...@@ -314,7 +313,7 @@ addSeparator()
public void public void
insertSeparator(int index) insertSeparator(int index)
{ {
insert(separator, index); insert(new MenuItem(separatorLabel), index);
} }
/*************************************************************************/ /*************************************************************************/
......
...@@ -310,7 +310,10 @@ deleteShortcut() ...@@ -310,7 +310,10 @@ deleteShortcut()
public String public String
getActionCommand() getActionCommand()
{ {
return(actionCommand); if (actionCommand == null)
return label;
else
return actionCommand;
} }
/*************************************************************************/ /*************************************************************************/
......
...@@ -105,7 +105,7 @@ PopupMenu(String label) ...@@ -105,7 +105,7 @@ PopupMenu(String label)
public void public void
addNotify() addNotify()
{ {
if (peer != null) if (peer == null)
peer = getToolkit ().createPopupMenu (this); peer = getToolkit ().createPopupMenu (this);
super.addNotify (); super.addNotify ();
} }
...@@ -123,6 +123,8 @@ addNotify() ...@@ -123,6 +123,8 @@ addNotify()
public void public void
show(Component component, int x, int y) show(Component component, int x, int y)
{ {
if (getPeer() == null)
this.addNotify();
PopupMenuPeer pmp = (PopupMenuPeer)getPeer(); PopupMenuPeer pmp = (PopupMenuPeer)getPeer();
if (pmp != null) if (pmp != null)
{ {
......
...@@ -43,7 +43,6 @@ import java.awt.MenuItem; ...@@ -43,7 +43,6 @@ import java.awt.MenuItem;
public interface MenuPeer extends MenuItemPeer public interface MenuPeer extends MenuItemPeer
{ {
void addItem (MenuItem item); void addItem (MenuItem item);
void addSeparator ();
void delItem (int index); void delItem (int index);
} }
...@@ -38,6 +38,7 @@ exception statement from your version. */ ...@@ -38,6 +38,7 @@ exception statement from your version. */
package java.text; package java.text;
import java.util.Arrays;
import java.util.Iterator; import java.util.Iterator;
import java.util.HashMap; import java.util.HashMap;
import java.util.Hashtable; import java.util.Hashtable;
...@@ -219,26 +220,7 @@ AttributedString(AttributedCharacterIterator aci, int begin_index, ...@@ -219,26 +220,7 @@ AttributedString(AttributedCharacterIterator aci, int begin_index,
// Get the valid attribute list // Get the valid attribute list
Set all_attribs = aci.getAllAttributeKeys(); Set all_attribs = aci.getAllAttributeKeys();
if (attributes != null) if (attributes != null)
{ all_attribs.retainAll(Arrays.asList(attributes));
Set valid_attribs = new HashSet();
Iterator iter = all_attribs.iterator();
while (iter.hasNext())
{
Object obj = iter.next();
int i;
for (i = 0; i < attributes.length; i++)
if (obj.equals(attributes[0]))
break;
if (i == attributes.length)
continue;
valid_attribs.add(obj);
}
all_attribs = valid_attribs;
}
// Loop through and extract the attributes // Loop through and extract the attributes
char c = aci.setIndex(begin_index); char c = aci.setIndex(begin_index);
...@@ -320,7 +302,7 @@ AttributedString(AttributedCharacterIterator aci, int begin_index, ...@@ -320,7 +302,7 @@ AttributedString(AttributedCharacterIterator aci, int begin_index,
public void public void
addAttribute(AttributedCharacterIterator.Attribute attrib, Object value) addAttribute(AttributedCharacterIterator.Attribute attrib, Object value)
{ {
addAttribute(attrib, value, 0, sci.getEndIndex() - 1); addAttribute(attrib, value, 0, sci.getEndIndex());
} }
/*************************************************************************/ /*************************************************************************/
...@@ -389,8 +371,7 @@ addAttributes(Map attributes, int begin_index, int end_index) ...@@ -389,8 +371,7 @@ addAttributes(Map attributes, int begin_index, int end_index)
public AttributedCharacterIterator public AttributedCharacterIterator
getIterator() getIterator()
{ {
return(new AttributedStringIterator(sci, attribs, 0, sci.getEndIndex() - 1, return(new AttributedStringIterator(sci, attribs, 0, sci.getEndIndex(), null));
null));
} }
/*************************************************************************/ /*************************************************************************/
...@@ -409,7 +390,7 @@ getIterator() ...@@ -409,7 +390,7 @@ getIterator()
public AttributedCharacterIterator public AttributedCharacterIterator
getIterator(AttributedCharacterIterator.Attribute[] attributes) getIterator(AttributedCharacterIterator.Attribute[] attributes)
{ {
return(getIterator(attributes, 0, sci.getEndIndex() - 1)); return(getIterator(attributes, 0, sci.getEndIndex()));
} }
/*************************************************************************/ /*************************************************************************/
......
...@@ -221,39 +221,28 @@ getRunLimit(AttributedCharacterIterator.Attribute attrib) ...@@ -221,39 +221,28 @@ getRunLimit(AttributedCharacterIterator.Attribute attrib)
public synchronized int public synchronized int
getRunLimit(Set attribute_set) getRunLimit(Set attribute_set)
{ {
int orig_index = ci.getIndex(); boolean hit = false;
int run_limit; int runLimit = ci.getEndIndex ();
int pos = ci.getIndex ();
do for (int i = 0; i < attribs.length; ++i)
{
if (pos >= attribs[i].begin_index &&
pos <= attribs[i].end_index)
{ {
run_limit = ci.getIndex();
Map attribute_map = getAttributes();
boolean found = false;
Iterator iter = attribute_set.iterator(); Iterator iter = attribute_set.iterator();
while(iter.hasNext()) while(iter.hasNext())
if (!attribute_map.containsKey(iter.next())) if (attribs[i].attribs.containsKey(iter.next()))
{ {
found = true; hit = true;
break; runLimit = Math.min(runLimit, attribs[i].end_index);
} }
if (found)
break;
} }
while (ci.next() != CharacterIterator.DONE); }
if (hit)
boolean hit_end = (ci.previous() == CharacterIterator.DONE); return runLimit;
else
ci.setIndex(orig_index); return -1;
if (run_limit == orig_index)
return(-1); // No characters match the given attributes
// else if (!hit_end)
// --run_limit;
return(run_limit);
} }
/*************************************************************************/ /*************************************************************************/
...@@ -281,35 +270,28 @@ getRunStart(AttributedCharacterIterator.Attribute attrib) ...@@ -281,35 +270,28 @@ getRunStart(AttributedCharacterIterator.Attribute attrib)
public int public int
getRunStart(Set attribute_set) getRunStart(Set attribute_set)
{ {
int orig_index = ci.getIndex(); boolean hit = false;
int run_start; int runBegin = 0;
int pos = ci.getIndex ();
do for (int i = 0; i < attribs.length; ++i)
{
if (pos >= attribs[i].begin_index &&
pos <= attribs[i].end_index)
{ {
run_start = ci.getIndex();
Map attribute_map = getAttributes();
Iterator iter = attribute_set.iterator(); Iterator iter = attribute_set.iterator();
while(iter.hasNext()) while(iter.hasNext())
if (!attribute_map.containsKey(iter.next())) if (attribs[i].attribs.containsKey(iter.next()))
break; {
hit = true;
if (iter.hasNext()) runBegin = Math.max(runBegin, attribs[i].begin_index);
break;
} }
while (ci.previous() != CharacterIterator.DONE); }
}
boolean hit_beginning = (ci.previous() == CharacterIterator.DONE); if (hit)
return runBegin;
ci.setIndex(orig_index); else
return -1;
if (run_start == orig_index)
return(-1); // No characters match the given attributes
else if (!hit_beginning)
++run_start;
return(run_start);
} }
/*************************************************************************/ /*************************************************************************/
......
...@@ -115,7 +115,7 @@ public class DefaultSingleSelectionModel ...@@ -115,7 +115,7 @@ public class DefaultSingleSelectionModel
*/ */
public boolean isSelected () public boolean isSelected ()
{ {
return (index == -1); return (index != -1);
} }
/** /**
......
...@@ -56,7 +56,10 @@ public class ImageIcon implements Icon ...@@ -56,7 +56,10 @@ public class ImageIcon implements Icon
public ImageIcon(String s) public ImageIcon(String s)
{ {
this(s, ""); // if description is not specified, then file name becomes
// desciption for this icon
this(s, s);
} }
public ImageIcon(String file, public ImageIcon(String file,
......
...@@ -39,206 +39,135 @@ package javax.swing; ...@@ -39,206 +39,135 @@ package javax.swing;
import java.io.IOException; import java.io.IOException;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import javax.accessibility.Accessible; import javax.accessibility.Accessible;
import javax.accessibility.AccessibleContext; import javax.accessibility.AccessibleContext;
import javax.accessibility.AccessibleRole; import javax.accessibility.AccessibleRole;
/**
* JCheckBoxMenuItem
* @author Andrew Selkirk
* @version 1.0
*/
public class JCheckBoxMenuItem extends JMenuItem implements SwingConstants, Accessible
{
//-------------------------------------------------------------
// Classes ----------------------------------------------------
//-------------------------------------------------------------
/**
* AccessibleJCheckBoxMenuItem
*/
protected class AccessibleJCheckBoxMenuItem extends AccessibleJMenuItem {
//-------------------------------------------------------------
// Variables --------------------------------------------------
//-------------------------------------------------------------
//-------------------------------------------------------------
// Initialization ---------------------------------------------
//-------------------------------------------------------------
/**
* Constructor AccessibleJCheckBoxMenuItem
* @param component TODO
*/
protected AccessibleJCheckBoxMenuItem(JCheckBoxMenuItem component) {
super(component);
// TODO
} // AccessibleJCheckBoxMenuItem()
//-------------------------------------------------------------
// Methods ----------------------------------------------------
//-------------------------------------------------------------
/**
* getAccessibleRole
* @returns AccessibleRole
*/
public AccessibleRole getAccessibleRole() {
return AccessibleRole.CHECK_BOX;
} // getAccessibleRole()
} // AccessibleJCheckBoxMenuItem
public class JCheckBoxMenuItem extends JMenuItem implements SwingConstants,
Accessible
{
//------------------------------------------------------------- //-------------------------------------------------------------
// Variables -------------------------------------------------- // Variables --------------------------------------------------
//------------------------------------------------------------- //-------------------------------------------------------------
/**
* uiClassID
*/
private static final String uiClassID = "CheckBoxMenuItemUI"; private static final String uiClassID = "CheckBoxMenuItemUI";
private boolean state;
private Object[] selectedObjects;
//------------------------------------------------------------- //-------------------------------------------------------------
// Initialization --------------------------------------------- // Initialization ---------------------------------------------
//------------------------------------------------------------- //-------------------------------------------------------------
public JCheckBoxMenuItem()
/** {
* Constructor JCheckBoxMenuItem this(null, null);
*/
public JCheckBoxMenuItem() {
// TODO
} // JCheckBoxMenuItem() } // JCheckBoxMenuItem()
/** public JCheckBoxMenuItem(Icon icon)
* Constructor JCheckBoxMenuItem {
* @param icon TODO this(null, icon);
*/
public JCheckBoxMenuItem(Icon icon) {
// TODO
} // JCheckBoxMenuItem() } // JCheckBoxMenuItem()
/** public JCheckBoxMenuItem(String text)
* Constructor JCheckBoxMenuItem {
* @param text TODO this(text, null);
*/
public JCheckBoxMenuItem(String text) {
// TODO
} // JCheckBoxMenuItem() } // JCheckBoxMenuItem()
/** public JCheckBoxMenuItem(Action action)
* Constructor JCheckBoxMenuItem {
* @param action TODO this();
*/ setAction(action);
public JCheckBoxMenuItem(Action action) {
// TODO
} // JCheckBoxMenuItem() } // JCheckBoxMenuItem()
/** public JCheckBoxMenuItem(String text, Icon icon)
* Constructor JCheckBoxMenuItem {
* @param text TODO this(text, icon, false);
* @param icon TODO
*/
public JCheckBoxMenuItem(String text, Icon icon) {
// TODO
} // JCheckBoxMenuItem() } // JCheckBoxMenuItem()
/** public JCheckBoxMenuItem(String text, boolean state)
* Constructor JCheckBoxMenuItem {
* @param text TODO this(text, null, state);
* @param state TODO
*/
public JCheckBoxMenuItem(String text, boolean state) {
// TODO
} // JCheckBoxMenuItem() } // JCheckBoxMenuItem()
/** public JCheckBoxMenuItem(String text, Icon icon, boolean state)
* Constructor JCheckBoxMenuItem {
* @param text TODO super(text, icon);
* @param icon TODO setModel(new JToggleButton.ToggleButtonModel());
* @param state TODO this.state = state;
*/
public JCheckBoxMenuItem(String text, Icon icon, boolean state) {
// TODO
} // JCheckBoxMenuItem() } // JCheckBoxMenuItem()
//------------------------------------------------------------- //-------------------------------------------------------------
// Methods ---------------------------------------------------- // Methods ----------------------------------------------------
//------------------------------------------------------------- //-------------------------------------------------------------
private void writeObject(ObjectOutputStream stream) throws IOException
/** {
* writeObject
* @param stream TODO
* @exception IOException TODO
*/
private void writeObject(ObjectOutputStream stream) throws IOException {
// TODO // TODO
} // writeObject() } // writeObject()
/** public String getUIClassID()
* getUIClassID {
* @returns String
*/
public String getUIClassID() {
return uiClassID; return uiClassID;
} // getUIClassID() } // getUIClassID()
/** public boolean getState()
* getState {
* @returns boolean return state;
*/
public boolean getState() {
return false; // TODO
} // getState() } // getState()
/** public synchronized void setState(boolean state)
* setState {
* @param state TODO this.state = state;
*/
public synchronized void setState(boolean state) {
// TODO
} // setState() } // setState()
/** public Object[] getSelectedObjects()
* getSelectedObjects {
* @returns Object[] return selectedObjects;
*/
public Object[] getSelectedObjects() {
return null; // TODO
} // getSelectedObjects() } // getSelectedObjects()
/** public void requestFocus()
* requestFocus {
*/
public void requestFocus() {
// TODO // TODO
} // requestFocus() } // requestFocus()
/** protected String paramString()
* paramString {
* @returns String return "JCheckBoxMenuItem";
*/
protected String paramString() {
return null; // TODO
} // paramString() } // paramString()
/** public AccessibleContext getAccessibleContext()
* getAccessibleContext {
* @returns AccessibleContext if (accessibleContext == null)
*/ {
public AccessibleContext getAccessibleContext() {
if (accessibleContext == null) {
accessibleContext = new AccessibleJCheckBoxMenuItem(this); accessibleContext = new AccessibleJCheckBoxMenuItem(this);
} // if }
return accessibleContext; return accessibleContext;
} // getAccessibleContext() } // getAccessibleContext()
//-------------------------------------------------------------
// Classes ----------------------------------------------------
//-------------------------------------------------------------
protected class AccessibleJCheckBoxMenuItem extends AccessibleJMenuItem
{
//-------------------------------------------------------------
// Variables --------------------------------------------------
//-------------------------------------------------------------
//-------------------------------------------------------------
// Initialization ---------------------------------------------
//-------------------------------------------------------------
protected AccessibleJCheckBoxMenuItem(JCheckBoxMenuItem component)
{
super(component);
// TODO
} // AccessibleJCheckBoxMenuItem()
//-------------------------------------------------------------
// Methods ----------------------------------------------------
//-------------------------------------------------------------
public AccessibleRole getAccessibleRole()
{
return AccessibleRole.CHECK_BOX;
} // getAccessibleRole()
} // AccessibleJCheckBoxMenuItem
} // JCheckBoxMenuItem } // JCheckBoxMenuItem
...@@ -100,7 +100,7 @@ public abstract class JComponent extends Container implements Serializable ...@@ -100,7 +100,7 @@ public abstract class JComponent extends Container implements Serializable
Border border; Border border;
JToolTip tooltip; JToolTip tooltip;
String tool_tip_text; String tool_tip_text;
boolean use_double_buffer, opaque; boolean use_double_buffer = false, opaque;
Image doubleBuffer; Image doubleBuffer;
int doubleBufferWidth = -1; int doubleBufferWidth = -1;
int doubleBufferHeight = -1; int doubleBufferHeight = -1;
......
...@@ -289,7 +289,7 @@ public class JLabel extends JComponent implements Accessible, SwingConstants ...@@ -289,7 +289,7 @@ public class JLabel extends JComponent implements Accessible, SwingConstants
String oldText = labelText; String oldText = labelText;
labelText = text; labelText = text;
firePropertyChange(TEXT_CHANGED_PROPERTY, oldText, labelText); firePropertyChange(TEXT_CHANGED_PROPERTY, oldText, labelText);
if (labelText.length() <= underlinedChar) if (labelText != null && labelText.length() <= underlinedChar)
setDisplayedMnemonicIndex(labelText.length() - 1); setDisplayedMnemonicIndex(labelText.length() - 1);
} }
} }
......
...@@ -41,6 +41,7 @@ package javax.swing; ...@@ -41,6 +41,7 @@ package javax.swing;
import java.awt.Component; import java.awt.Component;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener; import java.beans.PropertyChangeListener;
import java.io.IOException; import java.io.IOException;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
...@@ -48,6 +49,7 @@ import java.io.ObjectOutputStream; ...@@ -48,6 +49,7 @@ import java.io.ObjectOutputStream;
import javax.accessibility.Accessible; import javax.accessibility.Accessible;
import javax.accessibility.AccessibleContext; import javax.accessibility.AccessibleContext;
import javax.accessibility.AccessibleRole; import javax.accessibility.AccessibleRole;
import javax.swing.UIManager;
import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener; import javax.swing.event.ChangeListener;
import javax.swing.event.MenuDragMouseEvent; import javax.swing.event.MenuDragMouseEvent;
...@@ -56,418 +58,259 @@ import javax.swing.event.MenuKeyEvent; ...@@ -56,418 +58,259 @@ import javax.swing.event.MenuKeyEvent;
import javax.swing.event.MenuKeyListener; import javax.swing.event.MenuKeyListener;
import javax.swing.plaf.MenuItemUI; import javax.swing.plaf.MenuItemUI;
/** public class JMenuItem extends AbstractButton implements Accessible,
* JMenuItem MenuElement
* @author Andrew Selkirk {
* @version 1.0
*/
public class JMenuItem extends AbstractButton implements Accessible, MenuElement {
//-------------------------------------------------------------
// Classes ----------------------------------------------------
//-------------------------------------------------------------
/**
* AccessibleJMenuItem
*/
protected class AccessibleJMenuItem extends AccessibleAbstractButton
implements ChangeListener {
//-------------------------------------------------------------
// Variables --------------------------------------------------
//-------------------------------------------------------------
//-------------------------------------------------------------
// Initialization ---------------------------------------------
//-------------------------------------------------------------
/**
* Constructor AccessibleJMenuItem
* @param component TODO
*/
AccessibleJMenuItem(JMenuItem component) {
super(component);
// TODO
} // AccessibleJMenuItem()
//-------------------------------------------------------------
// Methods ----------------------------------------------------
//-------------------------------------------------------------
/**
* stateChanged
* @param event TODO
*/
public void stateChanged(ChangeEvent event) {
// TODO
} // stateChanged()
/**
* getAccessibleRole
* @returns AccessibleRole
*/
public AccessibleRole getAccessibleRole() {
return AccessibleRole.MENU_ITEM;
} // getAccessibleRole()
} // AccessibleJMenuItem
//------------------------------------------------------------- //-------------------------------------------------------------
// Variables -------------------------------------------------- // Variables --------------------------------------------------
//------------------------------------------------------------- //-------------------------------------------------------------
/**
* uiClassID
*/
private static final String uiClassID = "MenuItemUI"; private static final String uiClassID = "MenuItemUI";
/**
* accelerator
*/
private KeyStroke accelerator; private KeyStroke accelerator;
//------------------------------------------------------------- //-------------------------------------------------------------
// Initialization --------------------------------------------- // Initialization ---------------------------------------------
//------------------------------------------------------------- //-------------------------------------------------------------
public JMenuItem()
/** {
* Constructor JMenuItem this(null, null);
*/
public JMenuItem() {
// TODO
} // JMenuItem() } // JMenuItem()
/** public JMenuItem(Icon icon)
* Constructor JMenuItem {
* @param icon TODO this(null, icon);
*/
public JMenuItem(Icon icon) {
// TODO
} // JMenuItem() } // JMenuItem()
/** public JMenuItem(String text)
* Constructor JMenuItem {
* @param text TODO this(text, null);
*/
public JMenuItem(String text) {
// TODO
} // JMenuItem() } // JMenuItem()
/** public JMenuItem(Action action)
* Constructor JMenuItem {
* @param action TODO
*/
public JMenuItem(Action action) {
// TODO // TODO
} // JMenuItem() } // JMenuItem()
/** public JMenuItem(String text, Icon icon)
* Constructor JMenuItem {
* @param text TODO super(text, icon);
* @param icon TODO
*/
public JMenuItem(String text, Icon icon) {
// TODO
} // JMenuItem() } // JMenuItem()
/** public JMenuItem(String text, int mnemonic)
* Constructor JMenuItem {
* @param text TODO super(text, null);
* @param mnemonic TODO setMnemonic(mnemonic);
*/
public JMenuItem(String text, int mnemonic) {
// TODO
} // JMenuItem() } // JMenuItem()
//------------------------------------------------------------- //-------------------------------------------------------------
// Methods ---------------------------------------------------- // Methods ----------------------------------------------------
//------------------------------------------------------------- //-------------------------------------------------------------
/**
* readObject
* @param stream TODO
* @exception IOException TODO
* @exception ClassNotFoundException TODO
*/
private void readObject(ObjectInputStream stream) private void readObject(ObjectInputStream stream)
throws IOException, ClassNotFoundException { throws IOException, ClassNotFoundException
{
// TODO // TODO
} // readObject() } // readObject()
/** private void writeObject(ObjectOutputStream stream) throws IOException
* writeObject {
* @param stream TODO
* @exception IOException TODO
*/
private void writeObject(ObjectOutputStream stream) throws IOException {
// TODO // TODO
} // writeObject() } // writeObject()
/** protected void init(String text, Icon icon)
* init {
* @param text TODO
* @param icon TODO
*/
protected void init(String text, Icon icon) {
// TODO // TODO
} // init() } // init()
/** public void setUI(MenuItemUI ui)
* setUI {
* @param ui TODO
*/
public void setUI(MenuItemUI ui) {
super.setUI(ui); super.setUI(ui);
// TODO
} // setUI() } // setUI()
/** public void updateUI()
* updateUI {
*/ MenuItemUI mi = ((MenuItemUI) UIManager.getUI(this));
public void updateUI() { setUI(mi);
setUI((MenuItemUI) UIManager.get(this));
invalidate(); invalidate();
} // updateUI() } // updateUI()
/** public String getUIClassID()
* getUIClassID {
* @returns String
*/
public String getUIClassID() {
return uiClassID; return uiClassID;
} // getUIClassID() } // getUIClassID()
/** public boolean isArmed()
* isArmed {
* @returns boolean return getModel().isArmed();
*/
public boolean isArmed() {
return false; // TODO
} // isArmed() } // isArmed()
/** public void setArmed(boolean armed)
* setArmed {
* @param armed TODO getModel().setArmed(armed);
*/
public void setArmed(boolean armed) {
// TODO
} // setArmed() } // setArmed()
/** public void setEnabled(boolean enabled)
* setEnabled {
* @param enabled TODO setEnabled(enabled);
*/
public void setEnabled(boolean enabled) {
// TODO
} // setEnabled() } // setEnabled()
/** public KeyStroke getAccelerator()
* getAccelerator {
* @returns KeyStroke return accelerator;
*/
public KeyStroke getAccelerator() {
return null; // TODO
} // getAccelerator() } // getAccelerator()
/** public void setAccelerator(KeyStroke keystroke)
* setAccelerator {
* @param keystroke TODO this.accelerator = keystroke;
*/
public void setAccelerator(KeyStroke keystroke) {
// TODO
} // setAccelerator() } // setAccelerator()
/** protected void configurePropertiesFromAction(Action action)
* configurePropertiesFromAction {
* @param action TODO super.configurePropertiesFromAction(action);
*/
protected void configurePropertiesFromAction(Action action) { if (action == null)
// TODO setAccelerator(null);
else
setAccelerator((KeyStroke) (action.getValue(Action.ACCELERATOR_KEY)));
} // configurePropertiesFromAction() } // configurePropertiesFromAction()
/** protected PropertyChangeListener createActionPropertyChangeListener(Action action)
* createActionPropertyChangeListener {
* @param action TODO return null;
* @returns PropertyChangeListener
*/
protected PropertyChangeListener createActionPropertyChangeListener(Action action) {
return null; // TODO
} // createActionPropertyChangeListener() } // createActionPropertyChangeListener()
/**
* processMouseEvent
* @param event TODO
* @param path TODO
* @param manager TODO
*/
public void processMouseEvent(MouseEvent event, MenuElement[] path, public void processMouseEvent(MouseEvent event, MenuElement[] path,
MenuSelectionManager manager) { MenuSelectionManager manager)
{
// TODO // TODO
} // processMouseEvent() } // processMouseEvent()
/**
* processKeyEvent
* @param event TODO
* @param path TODO
* @param manager TODO
*/
public void processKeyEvent(KeyEvent event, MenuElement[] path, public void processKeyEvent(KeyEvent event, MenuElement[] path,
MenuSelectionManager manager) { MenuSelectionManager manager)
{
// TODO // TODO
} // processKeyEvent() } // processKeyEvent()
/** public void processMenuDragMouseEvent(MenuDragMouseEvent event)
* processMenuDragMouseEvent {
* @param event TODO
*/
public void processMenuDragMouseEvent(MenuDragMouseEvent event) {
// TODO
} // processMenuDragMouseEvent() } // processMenuDragMouseEvent()
/** public void processMenuKeyEvent(MenuKeyEvent event)
* processMenuKeyEvent {
* @param event TODO
*/
public void processMenuKeyEvent(MenuKeyEvent event) {
// TODO // TODO
} // processMenuKeyEvent() } // processMenuKeyEvent()
/** protected void fireMenuDragMouseEntered(MenuDragMouseEvent event)
* fireMenuDragMouseEntered {
* @param event TODO
*/
protected void fireMenuDragMouseEntered(MenuDragMouseEvent event) {
// TODO // TODO
} // fireMenuDragMouseEntered() } // fireMenuDragMouseEntered()
/** protected void fireMenuDragMouseExited(MenuDragMouseEvent event)
* fireMenuDragMouseExited {
* @param event TODO
*/
protected void fireMenuDragMouseExited(MenuDragMouseEvent event) {
// TODO // TODO
} // fireMenuDragMouseExited() } // fireMenuDragMouseExited()
/** protected void fireMenuDragMouseDragged(MenuDragMouseEvent event)
* fireMenuDragMouseDragged {
* @param event TODO
*/
protected void fireMenuDragMouseDragged(MenuDragMouseEvent event) {
// TODO // TODO
} // fireMenuDragMouseDragged() } // fireMenuDragMouseDragged()
/** protected void fireMenuDragMouseReleased(MenuDragMouseEvent event)
* fireMenuDragMouseReleased {
* @param event TODO
*/
protected void fireMenuDragMouseReleased(MenuDragMouseEvent event) {
// TODO // TODO
} // fireMenuDragMouseReleased() } // fireMenuDragMouseReleased()
/** protected void fireMenuKeyPressed(MenuKeyEvent event)
* fireMenuKeyPressed {
* @param event TODO
*/
protected void fireMenuKeyPressed(MenuKeyEvent event) {
// TODO // TODO
} // fireMenuKeyPressed() } // fireMenuKeyPressed()
/** protected void fireMenuKeyReleased(MenuKeyEvent event)
* fireMenuKeyReleased {
* @param event TODO
*/
protected void fireMenuKeyReleased(MenuKeyEvent event) {
// TODO // TODO
} // fireMenuKeyReleased() } // fireMenuKeyReleased()
/** protected void fireMenuKeyTyped(MenuKeyEvent event)
* fireMenuKeyTyped {
* @param event TODO
*/
protected void fireMenuKeyTyped(MenuKeyEvent event) {
// TODO // TODO
} // fireMenuKeyTyped() } // fireMenuKeyTyped()
/** public void menuSelectionChanged(boolean changed)
* menuSelectionChanged {
* @param changed TODO
*/
public void menuSelectionChanged(boolean changed) {
// TODO // TODO
} // menuSelectionChanged() } // menuSelectionChanged()
/** public MenuElement[] getSubElements()
* getSubElements {
* @returns MenuElement[]
*/
public MenuElement[] getSubElements() {
return null; // TODO return null; // TODO
} // getSubElements() } // getSubElements()
/** public Component getComponent()
* getComponent {
* @returns Component
*/
public Component getComponent() {
return null; // TODO return null; // TODO
} // getComponent() } // getComponent()
/** public void addMenuDragMouseListener(MenuDragMouseListener listener)
* addMenuDragMouseListener {
* @param listener TODO
*/
public void addMenuDragMouseListener(MenuDragMouseListener listener) {
// TODO // TODO
} // addMenuDragMouseListener() } // addMenuDragMouseListener()
/** public void removeMenuDragMouseListener(MenuDragMouseListener listener)
* removeMenuDragMouseListener {
* @param listener TODO
*/
public void removeMenuDragMouseListener(MenuDragMouseListener listener) {
// TODO
} // removeMenuDragMouseListener() } // removeMenuDragMouseListener()
/** public void addMenuKeyListener(MenuKeyListener listener)
* addMenuKeyListener {
* @param listener TODO
*/
public void addMenuKeyListener(MenuKeyListener listener) {
// TODO
} // addMenuKeyListener() } // addMenuKeyListener()
/** public void removeMenuKeyListener(MenuKeyListener listener)
* removeMenuKeyListener {
* @param listener TODO
*/
public void removeMenuKeyListener(MenuKeyListener listener) {
// TODO
} // removeMenuKeyListener() } // removeMenuKeyListener()
/** protected String paramString()
* paramString {
* @returns String return "JMenuItem";
*/
protected String paramString() {
return null; // TODO
} // paramString() } // paramString()
/** public AccessibleContext getAccessibleContext()
* getAccessibleContext {
* @returns AccessibleContext if (accessibleContext == null)
*/ {
public AccessibleContext getAccessibleContext() {
if (accessibleContext == null) {
accessibleContext = new AccessibleJMenuItem(this); accessibleContext = new AccessibleJMenuItem(this);
} // if }
return accessibleContext; return accessibleContext;
} // getAccessibleContext() } // getAccessibleContext()
//-------------------------------------------------------------
// Classes ----------------------------------------------------
//-------------------------------------------------------------
protected class AccessibleJMenuItem extends AccessibleAbstractButton
implements ChangeListener
{
//-------------------------------------------------------------
// Variables --------------------------------------------------
//-------------------------------------------------------------
//-------------------------------------------------------------
// Initialization ---------------------------------------------
//-------------------------------------------------------------
AccessibleJMenuItem(JMenuItem component)
{
super(component);
// TODO
} // AccessibleJMenuItem()
//-------------------------------------------------------------
// Methods ----------------------------------------------------
//-------------------------------------------------------------
public void stateChanged(ChangeEvent event)
{
// TODO
} // stateChanged()
public AccessibleRole getAccessibleRole()
{
return AccessibleRole.MENU_ITEM;
} // getAccessibleRole()
} // AccessibleJMenuItem
} // JMenuItem } // JMenuItem
...@@ -185,9 +185,6 @@ public class JProgressBar extends JComponent implements SwingConstants, ...@@ -185,9 +185,6 @@ public class JProgressBar extends JComponent implements SwingConstants,
/** Fired in a PropertyChangeEvent when the "indeterminate" property changes. */ /** Fired in a PropertyChangeEvent when the "indeterminate" property changes. */
public static final String INDETERMINATE_CHANGED_PROPERTY = "indeterminate"; public static final String INDETERMINATE_CHANGED_PROPERTY = "indeterminate";
/** A list of ChangeListeners registered with this ProgressBar. */
private transient EventListenerList changeListenerList;
/** Whether the ProgressBar is determinate. */ /** Whether the ProgressBar is determinate. */
private transient boolean indeterminate = false; private transient boolean indeterminate = false;
...@@ -260,7 +257,6 @@ public class JProgressBar extends JComponent implements SwingConstants, ...@@ -260,7 +257,6 @@ public class JProgressBar extends JComponent implements SwingConstants,
this.orientation = orientation; this.orientation = orientation;
changeListener = createChangeListener(); changeListener = createChangeListener();
model.addChangeListener(changeListener); model.addChangeListener(changeListener);
changeListenerList = new EventListenerList();
updateUI(); updateUI();
} }
...@@ -275,7 +271,6 @@ public class JProgressBar extends JComponent implements SwingConstants, ...@@ -275,7 +271,6 @@ public class JProgressBar extends JComponent implements SwingConstants,
this.model = model; this.model = model;
changeListener = createChangeListener(); changeListener = createChangeListener();
model.addChangeListener(changeListener); model.addChangeListener(changeListener);
changeListenerList = new EventListenerList();
updateUI(); updateUI();
} }
...@@ -511,7 +506,7 @@ public class JProgressBar extends JComponent implements SwingConstants, ...@@ -511,7 +506,7 @@ public class JProgressBar extends JComponent implements SwingConstants,
*/ */
public void addChangeListener(ChangeListener listener) public void addChangeListener(ChangeListener listener)
{ {
changeListenerList.add(ChangeListener.class, listener); listenerList.add(ChangeListener.class, listener);
} }
/** /**
...@@ -521,7 +516,7 @@ public class JProgressBar extends JComponent implements SwingConstants, ...@@ -521,7 +516,7 @@ public class JProgressBar extends JComponent implements SwingConstants,
*/ */
public void removeChangeListener(ChangeListener listener) public void removeChangeListener(ChangeListener listener)
{ {
changeListenerList.remove(ChangeListener.class, listener); listenerList.remove(ChangeListener.class, listener);
} }
/** /**
...@@ -532,7 +527,7 @@ public class JProgressBar extends JComponent implements SwingConstants, ...@@ -532,7 +527,7 @@ public class JProgressBar extends JComponent implements SwingConstants,
*/ */
public ChangeListener[] getChangeListeners() public ChangeListener[] getChangeListeners()
{ {
return (ChangeListener[]) changeListenerList.getListenerList(); return (ChangeListener[]) listenerList.getListeners(ChangeListener.class);
} }
/** /**
...@@ -542,7 +537,7 @@ public class JProgressBar extends JComponent implements SwingConstants, ...@@ -542,7 +537,7 @@ public class JProgressBar extends JComponent implements SwingConstants,
*/ */
protected void fireStateChanged() protected void fireStateChanged()
{ {
Object[] changeListeners = changeListenerList.getListenerList(); Object[] changeListeners = listenerList.getListenerList();
if (changeEvent == null) if (changeEvent == null)
changeEvent = new ChangeEvent(this); changeEvent = new ChangeEvent(this);
for (int i = changeListeners.length - 2; i >= 0; i -= 2) for (int i = changeListeners.length - 2; i >= 0; i -= 2)
......
...@@ -39,186 +39,118 @@ package javax.swing; ...@@ -39,186 +39,118 @@ package javax.swing;
import java.io.IOException; import java.io.IOException;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import javax.accessibility.Accessible; import javax.accessibility.Accessible;
import javax.accessibility.AccessibleContext; import javax.accessibility.AccessibleContext;
import javax.accessibility.AccessibleRole; import javax.accessibility.AccessibleRole;
/**
* JRadioButtonMenuItem
* @author Andrew Selkirk
* @version 1.0
*/
public class JRadioButtonMenuItem extends JMenuItem implements Accessible public class JRadioButtonMenuItem extends JMenuItem implements Accessible
{ {
//-------------------------------------------------------------
// Classes ----------------------------------------------------
//-------------------------------------------------------------
/**
* AccessibleJRadioButtonMenuItem
*/
protected class AccessibleJRadioButtonMenuItem extends AccessibleJMenuItem {
//-------------------------------------------------------------
// Initialization ---------------------------------------------
//-------------------------------------------------------------
/**
* Constructor AccessibleJRadioButtonMenuItem
* @param component TODO
*/
protected AccessibleJRadioButtonMenuItem(JRadioButtonMenuItem component) {
super(component);
// TODO
} // AccessibleJRadioButtonMenuItem()
//-------------------------------------------------------------
// Methods ----------------------------------------------------
//-------------------------------------------------------------
/**
* getAccessibleRole
* @returns AccessibleRole
*/
public AccessibleRole getAccessibleRole() {
return AccessibleRole.RADIO_BUTTON;
} // getAccessibleRole()
} // AccessibleJRadioButtonMenuItem
//------------------------------------------------------------- //-------------------------------------------------------------
// Variables -------------------------------------------------- // Variables --------------------------------------------------
//------------------------------------------------------------- //-------------------------------------------------------------
/**
* uiClassID
*/
private static final String uiClassID = "RadioButtonMenuItemUI"; private static final String uiClassID = "RadioButtonMenuItemUI";
//------------------------------------------------------------- //-------------------------------------------------------------
// Initialization --------------------------------------------- // Initialization ---------------------------------------------
//------------------------------------------------------------- //-------------------------------------------------------------
public JRadioButtonMenuItem()
/** {
* Constructor JRadioButtonMenuItem this(null, null);
*/
public JRadioButtonMenuItem() {
// TODO
} // JRadioButtonMenuItem() } // JRadioButtonMenuItem()
/** public JRadioButtonMenuItem(Icon icon)
* Constructor JRadioButtonMenuItem {
* @param icon TODO this(null, icon);
*/
public JRadioButtonMenuItem(Icon icon) {
// TODO
} // JRadioButtonMenuItem() } // JRadioButtonMenuItem()
/** public JRadioButtonMenuItem(String text)
* Constructor JRadioButtonMenuItem {
* @param text TODO this(text, null);
*/
public JRadioButtonMenuItem(String text) {
// TODO
} // JRadioButtonMenuItem() } // JRadioButtonMenuItem()
/** public JRadioButtonMenuItem(Action action)
* Constructor JRadioButtonMenuItem {
* @param action TODO this();
*/ setAction(action);
public JRadioButtonMenuItem(Action action) {
// TODO
} // JRadioButtonMenuItem() } // JRadioButtonMenuItem()
/** public JRadioButtonMenuItem(String text, Icon icon)
* Constructor JRadioButtonMenuItem {
* @param text TODO this(text, icon, false);
* @param icon TODO
*/
public JRadioButtonMenuItem(String text, Icon icon) {
// TODO
} // JRadioButtonMenuItem() } // JRadioButtonMenuItem()
/** public JRadioButtonMenuItem(String text, boolean selected)
* Constructor JRadioButtonMenuItem {
* @param text TODO this(text, null, selected);
* @param selected TODO
*/
public JRadioButtonMenuItem(String text, boolean selected) {
// TODO
} // JRadioButtonMenuItem() } // JRadioButtonMenuItem()
/** public JRadioButtonMenuItem(Icon icon, boolean selected)
* Constructor JRadioButtonMenuItem {
* @param icon TODO this(null, icon, selected);
* @param selected TODO
*/
public JRadioButtonMenuItem(Icon icon, boolean selected) {
// TODO
} // JRadioButtonMenuItem() } // JRadioButtonMenuItem()
/** public JRadioButtonMenuItem(String text, Icon icon, boolean selected)
* Constructor JRadioButtonMenuItem {
* @param text TODO super(text, icon);
* @param icon TODO setModel(new JToggleButton.ToggleButtonModel());
* @param selected TODO model.setSelected(selected);
*/
public JRadioButtonMenuItem(String text, Icon icon, boolean selected) {
// TODO
} // JRadioButtonMenuItem() } // JRadioButtonMenuItem()
//------------------------------------------------------------- //-------------------------------------------------------------
// Methods ---------------------------------------------------- // Methods ----------------------------------------------------
//------------------------------------------------------------- //-------------------------------------------------------------
private void writeObject(ObjectOutputStream stream) throws IOException
/** {
* writeObject
* @param stream TODO
* @exception IOException TODO
*/
private void writeObject(ObjectOutputStream stream) throws IOException {
// TODO // TODO
} // writeObject() } // writeObject()
/** public String getUIClassID()
* getUIClassID {
* @returns String
*/
public String getUIClassID() {
return uiClassID; return uiClassID;
} // getUIClassID() } // getUIClassID()
/** public void requestFocus()
* requestFocus {
*/
public void requestFocus() {
// TODO // TODO
} // requestFocus() } // requestFocus()
/** protected String paramString()
* paramString {
* @returns String return "JRadioButtonMenuItem";
*/
protected String paramString() {
return null; // TODO
} // paramString() } // paramString()
/** public AccessibleContext getAccessibleContext()
* getAccessibleContext {
* @returns AccessibleContext if (accessibleContext == null)
*/ {
public AccessibleContext getAccessibleContext() {
if (accessibleContext == null) {
accessibleContext = new AccessibleJRadioButtonMenuItem(this); accessibleContext = new AccessibleJRadioButtonMenuItem(this);
} // if }
return accessibleContext; return accessibleContext;
} // getAccessibleContext() } // getAccessibleContext()
//-------------------------------------------------------------
// Classes ----------------------------------------------------
//-------------------------------------------------------------
protected class AccessibleJRadioButtonMenuItem extends AccessibleJMenuItem
{
//-------------------------------------------------------------
// Initialization ---------------------------------------------
//-------------------------------------------------------------
protected AccessibleJRadioButtonMenuItem(JRadioButtonMenuItem component)
{
super(component);
// TODO
} // AccessibleJRadioButtonMenuItem()
//-------------------------------------------------------------
// Methods ----------------------------------------------------
//-------------------------------------------------------------
public AccessibleRole getAccessibleRole()
{
return AccessibleRole.RADIO_BUTTON;
} // getAccessibleRole()
} // AccessibleJRadioButtonMenuItem
} // JRadioButtonMenuItem } // JRadioButtonMenuItem
...@@ -176,12 +176,6 @@ public class JScrollBar extends JComponent implements Adjustable, Accessible ...@@ -176,12 +176,6 @@ public class JScrollBar extends JComponent implements Adjustable, Accessible
/** How much the thumb moves when moving in a unit. */ /** How much the thumb moves when moving in a unit. */
protected int unitIncrement = 1; protected int unitIncrement = 1;
/** A list of all ChangeListeners attached to the scroll bar. */
private transient EventListenerList changeListenerList;
/** A list of all AdjustmentListeners attached to the scroll bar. */
private transient EventListenerList adjustmentListenerList;
/** The ChangeListener that listens to the model. */ /** The ChangeListener that listens to the model. */
private transient ChangeListener changeListener; private transient ChangeListener changeListener;
...@@ -228,8 +222,6 @@ public class JScrollBar extends JComponent implements Adjustable, Accessible ...@@ -228,8 +222,6 @@ public class JScrollBar extends JComponent implements Adjustable, Accessible
+ " is not a legal orientation"); + " is not a legal orientation");
this.orientation = orientation; this.orientation = orientation;
changeListener = createChangeListener(); changeListener = createChangeListener();
changeListenerList = new EventListenerList();
adjustmentListenerList = new EventListenerList();
model.addChangeListener(changeListener); model.addChangeListener(changeListener);
updateUI(); updateUI();
} }
...@@ -586,7 +578,7 @@ public class JScrollBar extends JComponent implements Adjustable, Accessible ...@@ -586,7 +578,7 @@ public class JScrollBar extends JComponent implements Adjustable, Accessible
*/ */
private void fireStateChanged() private void fireStateChanged()
{ {
Object[] changeListeners = changeListenerList.getListenerList(); Object[] changeListeners = listenerList.getListenerList();
if (changeEvent == null) if (changeEvent == null)
changeEvent = new ChangeEvent(this); changeEvent = new ChangeEvent(this);
for (int i = changeListeners.length - 2; i >= 0; i -= 2) for (int i = changeListeners.length - 2; i >= 0; i -= 2)
...@@ -603,7 +595,7 @@ public class JScrollBar extends JComponent implements Adjustable, Accessible ...@@ -603,7 +595,7 @@ public class JScrollBar extends JComponent implements Adjustable, Accessible
*/ */
public void addChangeListener(ChangeListener listener) public void addChangeListener(ChangeListener listener)
{ {
changeListenerList.add(ChangeListener.class, listener); listenerList.add(ChangeListener.class, listener);
} }
/** /**
...@@ -613,7 +605,7 @@ public class JScrollBar extends JComponent implements Adjustable, Accessible ...@@ -613,7 +605,7 @@ public class JScrollBar extends JComponent implements Adjustable, Accessible
*/ */
public void removeChangeListener(ChangeListener listener) public void removeChangeListener(ChangeListener listener)
{ {
changeListenerList.remove(ChangeListener.class, listener); listenerList.remove(ChangeListener.class, listener);
} }
/** /**
...@@ -624,7 +616,7 @@ public class JScrollBar extends JComponent implements Adjustable, Accessible ...@@ -624,7 +616,7 @@ public class JScrollBar extends JComponent implements Adjustable, Accessible
*/ */
public ChangeListener[] getChangeListeners() public ChangeListener[] getChangeListeners()
{ {
return (ChangeListener[]) changeListenerList.getListenerList(); return (ChangeListener[]) listenerList.getListeners(ChangeListener.class);
} }
/** /**
...@@ -634,7 +626,7 @@ public class JScrollBar extends JComponent implements Adjustable, Accessible ...@@ -634,7 +626,7 @@ public class JScrollBar extends JComponent implements Adjustable, Accessible
*/ */
public void addAdjustmentListener(AdjustmentListener listener) public void addAdjustmentListener(AdjustmentListener listener)
{ {
adjustmentListenerList.add(AdjustmentListener.class, listener); listenerList.add(AdjustmentListener.class, listener);
} }
/** /**
...@@ -644,7 +636,7 @@ public class JScrollBar extends JComponent implements Adjustable, Accessible ...@@ -644,7 +636,7 @@ public class JScrollBar extends JComponent implements Adjustable, Accessible
*/ */
public void removeAdjustmentListener(AdjustmentListener listener) public void removeAdjustmentListener(AdjustmentListener listener)
{ {
adjustmentListenerList.remove(AdjustmentListener.class, listener); listenerList.remove(AdjustmentListener.class, listener);
} }
/** /**
...@@ -655,7 +647,7 @@ public class JScrollBar extends JComponent implements Adjustable, Accessible ...@@ -655,7 +647,7 @@ public class JScrollBar extends JComponent implements Adjustable, Accessible
*/ */
public AdjustmentListener[] getAdjustmentListeners() public AdjustmentListener[] getAdjustmentListeners()
{ {
return (AdjustmentListener[]) adjustmentListenerList.getListenerList(); return (AdjustmentListener[]) listenerList.getListeners(AdjustmentListener.class);
} }
/** /**
...@@ -670,7 +662,7 @@ public class JScrollBar extends JComponent implements Adjustable, Accessible ...@@ -670,7 +662,7 @@ public class JScrollBar extends JComponent implements Adjustable, Accessible
*/ */
protected void fireAdjustmentValueChanged(int id, int type, int value) protected void fireAdjustmentValueChanged(int id, int type, int value)
{ {
Object[] adjustmentListeners = adjustmentListenerList.getListenerList(); Object[] adjustmentListeners = listenerList.getListenerList();
AdjustmentEvent adjustmentEvent = new AdjustmentEvent(this, AdjustmentEvent adjustmentEvent = new AdjustmentEvent(this,
AdjustmentEvent.ADJUSTMENT_VALUE_CHANGED, AdjustmentEvent.ADJUSTMENT_VALUE_CHANGED,
AdjustmentEvent.TRACK, AdjustmentEvent.TRACK,
......
...@@ -253,9 +253,6 @@ public class JSlider extends JComponent implements SwingConstants, Accessible, ...@@ -253,9 +253,6 @@ public class JSlider extends JComponent implements SwingConstants, Accessible,
*/ */
private transient Dictionary labelTable; private transient Dictionary labelTable;
/** A list of all ChangeListeners listening to this slider. */
private transient EventListenerList changeListenerList;
/** The model used to describe the slider. */ /** The model used to describe the slider. */
protected BoundedRangeModel sliderModel; protected BoundedRangeModel sliderModel;
...@@ -342,7 +339,6 @@ public class JSlider extends JComponent implements SwingConstants, Accessible, ...@@ -342,7 +339,6 @@ public class JSlider extends JComponent implements SwingConstants, Accessible,
throw new IllegalArgumentException(orientation + " is not a legal orientation"); throw new IllegalArgumentException(orientation + " is not a legal orientation");
this.orientation = orientation; this.orientation = orientation;
changeListener = createChangeListener(); changeListener = createChangeListener();
changeListenerList = new EventListenerList();
sliderModel.addChangeListener(changeListener); sliderModel.addChangeListener(changeListener);
updateUI(); updateUI();
} }
...@@ -359,7 +355,6 @@ public class JSlider extends JComponent implements SwingConstants, Accessible, ...@@ -359,7 +355,6 @@ public class JSlider extends JComponent implements SwingConstants, Accessible,
else else
sliderModel = model; sliderModel = model;
changeListener = createChangeListener(); changeListener = createChangeListener();
changeListenerList = new EventListenerList();
sliderModel.addChangeListener(changeListener); sliderModel.addChangeListener(changeListener);
updateUI(); updateUI();
} }
...@@ -453,7 +448,7 @@ public class JSlider extends JComponent implements SwingConstants, Accessible, ...@@ -453,7 +448,7 @@ public class JSlider extends JComponent implements SwingConstants, Accessible,
*/ */
public void addChangeListener(ChangeListener listener) public void addChangeListener(ChangeListener listener)
{ {
changeListenerList.add(ChangeListener.class, listener); listenerList.add(ChangeListener.class, listener);
} }
/** /**
...@@ -463,7 +458,7 @@ public class JSlider extends JComponent implements SwingConstants, Accessible, ...@@ -463,7 +458,7 @@ public class JSlider extends JComponent implements SwingConstants, Accessible,
*/ */
public void removeChangeListener(ChangeListener listener) public void removeChangeListener(ChangeListener listener)
{ {
changeListenerList.remove(ChangeListener.class, listener); listenerList.remove(ChangeListener.class, listener);
} }
/** /**
...@@ -473,7 +468,7 @@ public class JSlider extends JComponent implements SwingConstants, Accessible, ...@@ -473,7 +468,7 @@ public class JSlider extends JComponent implements SwingConstants, Accessible,
*/ */
protected void fireStateChanged() protected void fireStateChanged()
{ {
Object[] changeListeners = changeListenerList.getListenerList(); Object[] changeListeners = listenerList.getListenerList();
if (changeEvent == null) if (changeEvent == null)
changeEvent = new ChangeEvent(this); changeEvent = new ChangeEvent(this);
for (int i = changeListeners.length - 2; i >= 0; i -= 2) for (int i = changeListeners.length - 2; i >= 0; i -= 2)
...@@ -491,7 +486,7 @@ public class JSlider extends JComponent implements SwingConstants, Accessible, ...@@ -491,7 +486,7 @@ public class JSlider extends JComponent implements SwingConstants, Accessible,
*/ */
public ChangeListener[] getChangeListeners() public ChangeListener[] getChangeListeners()
{ {
return (ChangeListener[]) changeListenerList.getListenerList(); return (ChangeListener[]) listenerList.getListeners(ChangeListener.class);
} }
/** /**
......
/* JTabbedPane.java -- /* JTabbedPane.java --
Copyright (C) 2002 Free Software Foundation, Inc. Copyright (C) 2002, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath. This file is part of GNU Classpath.
...@@ -35,98 +35,1448 @@ this exception to your version of the library, but you are not ...@@ -35,98 +35,1448 @@ 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 obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */ exception statement from your version. */
package javax.swing; package javax.swing;
import java.awt.Color;
import java.awt.Component; import java.awt.Component;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.MouseEvent;
import java.io.Serializable;
import java.util.Vector; import java.util.Vector;
import javax.accessibility.Accessible; import javax.accessibility.Accessible;
import javax.accessibility.AccessibleContext; import javax.accessibility.AccessibleContext;
import javax.accessibility.AccessibleRole;
import javax.accessibility.AccessibleSelection;
import javax.accessibility.AccessibleStateSet;
import javax.accessibility.AccessibleValue;
import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener; import javax.swing.event.ChangeListener;
import javax.swing.event.EventListenerList;
import javax.swing.plaf.TabbedPaneUI; import javax.swing.plaf.TabbedPaneUI;
import javax.swing.plaf.UIResource;
public class JTabbedPane extends JComponent implements Accessible, SwingConstants /**
* <p>
* This is a container for components. One component is displayed at a time.
* Users can switch between components by clicking on tabs.
* </p>
*
* <p>
* Tabs can be oriented in several ways. They can be above, below, left and
* right of the component. Tabs can either wrap around (by creating multiple
* rows of tabs) or they can be scrolled (where only a subset of the tabs
* can be seen at once). More tabs can be added by calling the
* add/addTab/insertTab methods.
* </p>
*/
public class JTabbedPane extends JComponent implements Serializable,
Accessible,
SwingConstants
{ {
class Tab /**
* DOCUMENT ME!
*/
protected class AccessibleJTabbedPane extends JComponent.AccessibleJComponent
implements AccessibleSelection, ChangeListener
{
/**
* Creates a new AccessibleJTabbedPane object.
*
* @param c DOCUMENT ME!
*/
public AccessibleJTabbedPane(JTabbedPane c)
{
super(c);
}
/**
* DOCUMENT ME!
*
* @param e DOCUMENT ME!
*/
public void stateChanged(ChangeEvent e)
{
}
/**
* DOCUMENT ME!
*
* @return DOCUMENT ME!
*/
public AccessibleRole getAccessibleRole()
{
return null;
}
/**
* DOCUMENT ME!
*
* @return DOCUMENT ME!
*/
public int getAccessibleChildrenCount()
{
return 0;
}
/**
* DOCUMENT ME!
*
* @param i DOCUMENT ME!
*
* @return DOCUMENT ME!
*/
public Accessible getAccessibleChild(int i)
{
return null;
}
/**
* DOCUMENT ME!
*
* @return DOCUMENT ME!
*/
public AccessibleSelection getAccessibleSelection()
{
return null;
}
/**
* DOCUMENT ME!
*
* @param p DOCUMENT ME!
*
* @return DOCUMENT ME!
*/
public Accessible getAccessibleAt(Point p)
{
return null;
}
/**
* DOCUMENT ME!
*
* @return DOCUMENT ME!
*/
public int getAccessibleSelectionCount()
{
return 0;
}
/**
* DOCUMENT ME!
*
* @param i DOCUMENT ME!
*
* @return DOCUMENT ME!
*/
public Accessible getAccessibleSelection(int i)
{
return null;
}
/**
* DOCUMENT ME!
*
* @param i DOCUMENT ME!
*
* @return DOCUMENT ME!
*/
public boolean isAccessibleChildSelected(int i)
{
return false;
}
/**
* DOCUMENT ME!
*
* @param i DOCUMENT ME!
*/
public void addAccessibleSelection(int i)
{ {
Icon icon; }
String name, descr;
Component tab;
Tab(String name, /**
Icon icon, * DOCUMENT ME!
Component tab, *
String descr) * @param i DOCUMENT ME!
*/
public void removeAccessibleSelection(int i)
{ {
this.name = name; }
/**
* DOCUMENT ME!
*/
public void clearAccessibleSelection()
{
}
/**
* DOCUMENT ME!
*/
public void selectAllAccessibleSelection()
{
}
}
/**
* A helper class that listens for changes to the model.
*/
protected class ModelListener implements ChangeListener, Serializable
{
/**
* This method is called whenever the model is changed.
*
* @param e The ChangeEvent that is passed from the model.
*/
public void stateChanged(ChangeEvent e)
{
// Propagate to our listeners.
fireStateChanged();
}
}
/**
* A private class that holds all the information for each tab.
*/
private class Page
{
/** The tooltip string. */
private String tip;
/** The component associated with the tab. */
private Component component;
/** The active icon associated with the tab. */
private transient Icon icon;
/** The disabled icon associated with the tab. */
private transient Icon disabledIcon;
/** The tab's enabled status. */
private transient boolean enabled = true;
/** The string painted on the tab. */
private transient String title;
/** The background color of the tab. */
private transient Color bg;
/** The foreground color of the tab. */
private transient Color fg;
/** The mnemonic associated with the tab. */
private transient int mnemonicKey;
/** The index of the underlined character in the string. */
private transient int underlinedChar = -1;
/**
* Creates a new data storage for the tab.
*
* @param title The string displayed on the tab.
* @param icon The active icon displayed on the tab.
* @param component The component associated with the tab.
* @param tip The tooltip associated with the tab.
*/
protected Page(String title, Icon icon, Component component, String tip)
{
this.title = title;
this.icon = icon; this.icon = icon;
this.tab = tab; this.component = component;
this.descr = descr; this.tip = tip;
}
/**
* This method returns the component associated with the tab.
*
* @return The component associated with the tab.
*/
public Component getComponent()
{
return component;
}
/**
* This method sets the component associated with the tab.
*
* @param c The component associated with the tab.
*/
public void setComponent(Component c)
{
this.component = c;
}
/**
* This method returns the tooltip string.
*
* @return The tooltip string.
*/
public String getTip()
{
return tip;
}
/**
* This method sets the tooltip string.
*
* @param tip The tooltip string.
*/
public void setTip(String tip)
{
this.tip = tip;
}
/**
* This method returns the background color.
*
* @return The background color.
*/
public Color getBackground()
{
return bg;
}
/**
* This method sets the background color.
*
* @param background The background color.
*/
public void setBackground(Color background)
{
bg = background;
}
/**
* This method returns the foreground color.
*
* @return The foreground color.
*/
public Color getForeground()
{
return fg;
}
/**
* This method sets the foreground color.
*
* @param foreground The foreground color.
*/
public void setForeground(Color foreground)
{
fg = foreground;
} }
/**
* This method returns the title associated with the tab.
*
* @return The title of the tab.
*/
public String getTitle()
{
return title;
} }
private static final long serialVersionUID = 1614381073220130939L; private static final long serialVersionUID = 1614381073220130939L;
private Vector tabs = new Vector(); /**
* This method sets the title of the tab.
*
* @param text The title of the tab.
*/
public void setTitle(String text)
{
title = text;
if (title != null && title.length() <= underlinedChar)
setDisplayedMnemonicIndex(title.length() - 1);
}
/**
* This method returns the active icon.
*
* @return The active icon.
*/
public Icon getIcon()
{
return icon;
}
/**
* This method sets the active icon.
*
* @param icon The active icon.
*/
public void setIcon(Icon icon)
{
this.icon = icon;
}
/**
* This method returns the disabled icon.
*
* @return The disabled icon.
*/
public Icon getDisabledIcon()
{
if (disabledIcon == null && icon instanceof ImageIcon)
setDisabledIcon(icon);
return disabledIcon;
}
/**
* This method sets the disabled icon.
*
* @param disabledIcon The disabled icon.
*/
public void setDisabledIcon(Icon disabledIcon)
{
this.disabledIcon = disabledIcon;
}
/**
* This method returns whether the tab is enabled.
*
* @return Whether the tab is enabled.
*/
public boolean isEnabled()
{
return enabled;
}
/**
* This method sets whether the tab is enabled.
*
* @param enabled Whether this tab is enabled.
*/
public void setEnabled(boolean enabled)
{
this.enabled = enabled;
}
/**
* This method returns the mnemonic.
*
* @return The mnemonic.
*/
public int getMnemonic()
{
return (int) mnemonicKey;
}
/**
* This method sets the mnemonic. If the title is set, it will update the
* mnemonicIndex.
*
* @param key The mnemonic.
*/
public void setMnemonic(int key)
{
setMnemonic((char) key);
}
/**
* This method sets the mnemonic. If the title is set, it will update the
* mnemonicIndex.
*
* @param aChar The mnemonic.
*/
public void setMnemonic(char aChar)
{
mnemonicKey = aChar;
if (title != null)
setDisplayedMnemonicIndex(title.indexOf(mnemonicKey));
}
/**
* This method returns the mnemonicIndex.
*
* @return The mnemonicIndex.
*/
public int getDisplayedMnemonicIndex()
{
return underlinedChar;
}
/**
* This method sets the mnemonicIndex.
*
* @param index The mnemonicIndex.
*
* @throws IllegalArgumentException If index less than -1 || index greater
* or equal to title.length.
*/
public void setDisplayedMnemonicIndex(int index)
throws IllegalArgumentException
{
if (index < -1 || title != null && index >= title.length())
throw new IllegalArgumentException();
if (title == null || title.charAt(index) != mnemonicKey)
index = -1;
underlinedChar = index;
}
}
/** Fired in a PropertyChangeEvent when the "model" property changes. */
public static final String MODEL_CHANGED_PROPERTY = "model";
/**
* Fired in a PropertyChangeEvent when the "tabPlacement" property changes.
*/
public static final String TAB_PLACEMENT_CHANGED_PROPERTY = "tabPlacement";
/**
* Fired in a PropertyChangeEvent when the "tabLayoutPolicy" property
* changes.
*/
public static final String TAB_LAYOUT_POLICY_CHANGED_PROPERTY = "tabLayoutPolicy";
/** The changeEvent used to fire changes to listeners. */
protected ChangeEvent changeEvent;
/** The listener that listens to the model. */
protected ChangeListener changeListener;
/** The model that describes this JTabbedPane. */
protected SingleSelectionModel model;
/** Indicates that the TabbedPane is in scrolling mode. */
static int SCROLL_TAB_LAYOUT = 0;
/** Indicates that the TabbedPane is in wrap mode. */
static int WRAP_TAB_LAYOUT = 1;
/** The current tabPlacement of the TabbedPane. */
protected int tabPlacement = SwingConstants.TOP;
/** The current tabLayoutPolicy of the TabbedPane. */
private transient int layoutPolicy;
/** The list of tabs associated with the TabbedPane. */
transient Vector tabs = new Vector();
/**
* Creates a new JTabbedPane object with tabs on top and using wrap tab
* layout.
*/
public JTabbedPane() public JTabbedPane()
{ {
this(SwingConstants.TOP, WRAP_TAB_LAYOUT);
}
/**
* Creates a new JTabbedPane object using wrap tab layout and the given
* tabPlacement.
*
* @param tabPlacement Where the tabs will be placed.
*/
public JTabbedPane(int tabPlacement)
{
this(tabPlacement, WRAP_TAB_LAYOUT);
}
/**
* Creates a new JTabbedPane object with the given tabPlacement and
* tabLayoutPolicy.
*
* @param tabPlacement Where the tabs will be placed.
* @param tabLayoutPolicy The way tabs will be placed.
*
* @throws IllegalArgumentException If tabLayoutPolicy or tabPlacement are
* not valid.
*/
public JTabbedPane(int tabPlacement, int tabLayoutPolicy)
{
if (tabPlacement != TOP && tabPlacement != BOTTOM && tabPlacement != RIGHT
&& tabPlacement != LEFT)
throw new IllegalArgumentException("tabPlacement is not valid.");
if (tabLayoutPolicy != SCROLL_TAB_LAYOUT
&& tabLayoutPolicy != WRAP_TAB_LAYOUT)
throw new IllegalArgumentException("tabLayoutPolicy is not valid.");
this.tabPlacement = tabPlacement;
layoutPolicy = tabLayoutPolicy;
changeEvent = new ChangeEvent(this);
changeListener = createChangeListener();
model = new DefaultSingleSelectionModel();
model.addChangeListener(changeListener);
updateUI();
}
/**
* This method returns the UI used to display the JTabbedPane.
*
* @return The UI used to display the JTabbedPane.
*/
public TabbedPaneUI getUI()
{
return (TabbedPaneUI) ui;
}
/**
* This method sets the UI used to display the JTabbedPane.
*
* @param ui The UI used to display the JTabbedPane.
*/
public void setUI(TabbedPaneUI ui)
{
super.setUI(ui);
}
/**
* This method restores the UI to the defaults given by the UIManager.
*/
public void updateUI()
{
setUI((TabbedPaneUI) UIManager.getUI(this));
invalidate();
}
/**
* This method returns a string identifier that is used to determine which
* UI will be used with the JTabbedPane.
*
* @return A string identifier for the UI.
*/
public String getUIClassID()
{
return "TabbedPaneUI";
}
/**
* This method creates a ChangeListener that is used to listen to the model
* for events.
*
* @return A ChangeListener to listen to the model.
*/
protected ChangeListener createChangeListener()
{
return new ModelListener();
}
/**
* This method adds a ChangeListener to the JTabbedPane.
*
* @param l The ChangeListener to add.
*/
public void addChangeListener(ChangeListener l)
{
listenerList.add(ChangeListener.class, l);
}
/**
* This method removes a ChangeListener to the JTabbedPane.
*
* @param l The ChangeListener to remove.
*/
public void removeChangeListener(ChangeListener l)
{
listenerList.remove(ChangeListener.class, l);
} }
public void addTab(String name, /**
Component panel) * This method fires a ChangeEvent to all the JTabbedPane's ChangeListeners.
*/
protected void fireStateChanged()
{ {
addTab(name, null, panel, null); Object[] changeListeners = listenerList.getListenerList();
if (changeEvent == null)
changeEvent = new ChangeEvent(this);
for (int i = changeListeners.length - 2; i >= 0; i -= 2)
{
if (changeListeners[i] == ChangeListener.class)
((ChangeListener) changeListeners[i + 1]).stateChanged(changeEvent);
}
}
/**
* This method returns all ChangeListeners registered with the JTabbedPane.
*
* @return The ChangeListeners registered with the JTabbedPane.
*/
public ChangeListener[] getChangeListeners()
{
return (ChangeListener[]) super.getListeners(ChangeListener.class);
}
/**
* This method returns the model used with the JTabbedPane.
*
* @return The JTabbedPane's model.
*/
public SingleSelectionModel getModel()
{
return model;
}
/**
* This method changes the model property of the JTabbedPane.
*
* @param model The new model to use with the JTabbedPane.
*/
public void setModel(SingleSelectionModel model)
{
if (model != this.model)
{
SingleSelectionModel oldModel = this.model;
this.model.removeChangeListener(changeListener);
this.model = model;
this.model.addChangeListener(changeListener);
firePropertyChange(MODEL_CHANGED_PROPERTY, oldModel, this.model);
}
}
/**
* This method returns the tabPlacement.
*
* @return The tabPlacement used with the JTabbedPane.
*/
public int getTabPlacement()
{
return tabPlacement;
}
/**
* This method changes the tabPlacement property of the JTabbedPane.
*
* @param tabPlacement The tabPlacement to use.
*
* @throws IllegalArgumentException If tabPlacement is not one of TOP,
* BOTTOM, LEFT, or RIGHT.
*/
public void setTabPlacement(int tabPlacement)
{
if (tabPlacement != TOP && tabPlacement != BOTTOM && tabPlacement != RIGHT
&& tabPlacement != LEFT)
throw new IllegalArgumentException("tabPlacement is not valid.");
if (tabPlacement != this.tabPlacement)
{
int oldPlacement = this.tabPlacement;
this.tabPlacement = tabPlacement;
firePropertyChange(TAB_PLACEMENT_CHANGED_PROPERTY, oldPlacement,
this.tabPlacement);
}
}
/**
* This method returns the tabLayoutPolicy.
*
* @return The tabLayoutPolicy.
*/
public int getTabLayoutPolicy()
{
return layoutPolicy;
}
/**
* This method changes the tabLayoutPolicy property of the JTabbedPane.
*
* @param tabLayoutPolicy The tabLayoutPolicy to use.
*
* @throws IllegalArgumentException If tabLayoutPolicy is not one of
* SCROLL_TAB_LAYOUT or WRAP_TAB_LAYOUT.
*/
public void setTabLayoutPolicy(int tabLayoutPolicy)
{
if (tabLayoutPolicy != SCROLL_TAB_LAYOUT
&& tabLayoutPolicy != WRAP_TAB_LAYOUT)
throw new IllegalArgumentException("tabLayoutPolicy is not valid.");
if (tabLayoutPolicy != layoutPolicy)
{
int oldPolicy = layoutPolicy;
layoutPolicy = tabLayoutPolicy;
firePropertyChange(TAB_LAYOUT_POLICY_CHANGED_PROPERTY, oldPolicy,
layoutPolicy);
}
}
/**
* This method returns the index of the tab that is currently selected.
*
* @return The index of the selected tab.
*/
public int getSelectedIndex()
{
return model.getSelectedIndex();
}
/**
* This method checks the index.
*
* @param index The index to check.
*/
private void checkIndex(int index, int start, int end)
{
if (index < start || index >= end)
throw new IndexOutOfBoundsException("Index < " + start + " || Index >= " + end);
} }
public void addTab(String name,
Icon icon, /**
Component panel) * This method sets the selected index. This method
* will hide the old component and show the new component.
*
* @param index The index to set it at.
*/
public void setSelectedIndex(int index)
{ {
addTab(name, icon, panel, null); checkIndex(index, -1, tabs.size());
if (index != getSelectedIndex())
{
if (getSelectedIndex() != -1)
getSelectedComponent().hide();
if (index != -1)
getComponentAt(index).show();
}
model.setSelectedIndex(index);
} }
public void addTab(String name,
Icon icon, /**
Component panel, * This method returns the component at the selected index.
String descr) *
* @return The component at the selected index.
*/
public Component getSelectedComponent()
{ {
tabs.addElement(new Tab(name, icon, panel, descr)); return getComponentAt(getSelectedIndex());
} }
/**
* This method sets the component at the selected index.
*
* @param c The component associated with the selected index.
*/
public void setSelectedComponent(Component c)
{
if (c.getParent() == this)
setSelectedIndex(indexOfComponent(c));
else
setComponentAt(getSelectedIndex(), c);
}
/**
* This method inserts tabs into JTabbedPane. This includes
* adding the component to the JTabbedPane and hiding it.
*
* @param title The title of the tab.
* @param icon The tab's icon.
* @param component The component associated with the tab.
* @param tip The tooltip for the tab.
* @param index The index to insert the tab at.
*/
public void insertTab(String title, Icon icon, Component component,
String tip, int index)
{
Page p = new Page(title, icon, component, tip);
tabs.insertElementAt(p, index);
// Hide the component so we don't see it. Do it before we parent it
// so we don't trigger a repaint.
component.hide();
super.add(component);
if (getSelectedIndex() == -1)
setSelectedIndex(0);
layout();
}
/**
* This method adds a tab to the JTabbedPane.
*
* @param title The title of the tab.
* @param icon The icon for the tab.
* @param component The associated component.
* @param tip The associated tooltip.
*/
public void addTab(String title, Icon icon, Component component, String tip)
{
insertTab(title, icon, component, tip, tabs.size());
}
/**
* This method adds a tab to the JTabbedPane.
*
* @param title The title of the tab.
* @param icon The icon for the tab.
* @param component The associated component.
*/
public void addTab(String title, Icon icon, Component component)
{
insertTab(title, icon, component, null, tabs.size());
}
/**
* This method adds a tab to the JTabbedPane.
*
* @param title The title of the tab.
* @param component The associated component.
*/
public void addTab(String title, Component component)
{
insertTab(title, null, component, null, tabs.size());
}
/**
* This method adds a tab to the JTabbedPane.
* The title of the tab is the Component's name.
* If the Component is an instance of UIResource, it doesn't
* add the tab and instead add the component directly to the
* JTabbedPane.
*
* @param component The associated component.
*
* @return The Component that was added.
*/
public Component add(Component component)
{
if (component instanceof UIResource)
super.add(component);
else
insertTab(component.getName(), null, component, null, tabs.size());
return component;
}
/**
* This method adds a tab to the JTabbedPane.
* If the Component is an instance of UIResource, it doesn't
* add the tab and instead add the component directly to the
* JTabbedPane.
*
* @param title The title of the tab.
* @param component The associated component.
*
* @return The Component that was added.
*/
public Component add(String title, Component component)
{
if (component instanceof UIResource)
super.add(component);
else
insertTab(title, null, component, null, tabs.size());
return component;
}
/**
* This method adds a tab to the JTabbedPane.
* If the Component is an instance of UIResource, it doesn't
* add the tab and instead add the component directly to the
* JTabbedPane.
*
* @param component The associated component.
* @param index The index to insert the tab at.
*
* @return The Component that was added.
*/
public Component add(Component component, int index)
{
if (component instanceof UIResource)
super.add(component);
else
insertTab(component.getName(), null, component, null, index);
return component;
}
/**
* This method adds a tab to the JTabbedPane.
* If the Component is an instance of UIResource, it doesn't
* add the tab and instead add the component directly to the
* JTabbedPane. If the constraints object is an icon, it
* will be used as the tab's icon. If the constraints object
* is a string, we will use it as the title.
*
* @param component The associated component.
* @param constraints The constraints object.
*/
public void add(Component component, Object constraints)
{
add(component, constraints, tabs.size());
}
/**
* This method adds a tab to the JTabbedPane.
* If the Component is an instance of UIResource, it doesn't
* add the tab and instead add the component directly to the
* JTabbedPane. If the constraints object is an icon, it
* will be used as the tab's icon. If the constraints object
* is a string, we will use it as the title.
*
* @param component The associated component.
* @param constraints The constraints object.
* @param index The index to insert the tab at.
*/
public void add(Component component, Object constraints, int index)
{
if (component instanceof UIResource)
super.add(component);
else
{
if (constraints instanceof String)
insertTab((String) constraints, null, component, null, index);
else
insertTab(component.getName(),
(constraints instanceof Icon) ? (Icon) constraints : null,
component, null, index);
}
}
/**
* The tab and it's associated component are removed. After
* the component has been removed from the JTabbedPane, it's
* set visible to ensure that it can be seen.
*
* @param index The index of the tab to remove.
*
* @throws IndexOutOfBoundsException If the index is not in range.
*/
public void removeTabAt(int index)
{
checkIndex(index, 0, tabs.size());
Component c = getComponentAt(index);
super.remove(c);
c.show();
tabs.remove(index);
}
/**
* This method removes the component from the JTabbedPane. After
* the component has been removed from the JTabbedPane, it's
* set visible to ensure that it can be seen.
*
* @param component The Component to remove.
*/
public void remove(Component component)
{
// This simply removes the component.
int index = indexOfComponent(component);
super.remove(component);
component.show();
setComponentAt(index, null);
}
/**
* This method removes the tab and component from the JTabbedPane.
* It simply calls removeTabAt(int index).
*
* @param index The index of the tab to remove.
*/
public void remove(int index)
{
removeTabAt(index);
}
/**
* This method removes all tabs and associated components
* from the JTabbedPane.
*/
public void removeAll()
{
for (int i = tabs.size() - 1; i >= 0; i--)
removeTabAt(i);
}
/**
* This method returns how many tabs are in the JTabbedPane.
*
* @return The number of tabs in the JTabbedPane.
*/
public int getTabCount() public int getTabCount()
{ {
return tabs.size(); return tabs.size();
} }
public Component getComponentAt(int i)
/**
* This method returns the number of runs used
* to paint the JTabbedPane.
*
* @return The number of runs.
*/
public int getTabRunCount()
{
return ((TabbedPaneUI) ui).getTabRunCount(this);
}
/**
* This method returns the tab title given the index.
*
* @param index The index of the tab.
*
* @return The title for the tab.
*/
public String getTitleAt(int index)
{ {
Tab t = (Tab) tabs.elementAt(i); checkIndex(index, 0, tabs.size());
return t.tab; return ((Page) tabs.elementAt(index)).getTitle();
} }
public String getUIClassID() /**
{ return "TabbedPaneUI"; } * This method returns the active icon given the index.
*
* @param index The index of the tab.
*
* @return The active icon for the tab.
*/
public Icon getIconAt(int index)
{
checkIndex(index, 0, tabs.size());
return ((Page) tabs.elementAt(index)).getIcon();
}
/**
* This method returns the disabled icon given the index.
*
* @param index The index of the tab.
*
* @return The disabled icon for the tab.
*/
public Icon getDisabledIconAt(int index)
{
checkIndex(index, 0, tabs.size());
return ((Page) tabs.elementAt(index)).getDisabledIcon();
}
public void setUI(TabbedPaneUI ui) { /**
super.setUI(ui); * This method returns the tooltip string for the tab.
*
* @param index The index of the tab.
*
* @return The tooltip string for the tab.
*/
public String getToolTipTextAt(int index)
{
checkIndex(index, 0, tabs.size());
return ((Page) tabs.elementAt(index)).getTip();
}
/**
* This method returns the foreground color for the tab.
*
* @param index The index of the tab.
*
* @return The foreground color for the tab.
*/
public Color getForegroundAt(int index)
{
checkIndex(index, 0, tabs.size());
return ((Page) tabs.elementAt(index)).getForeground();
} }
public TabbedPaneUI getUI() { /**
return (TabbedPaneUI)ui; * This method returns the background color for the tab.
*
* @param index The index of the tab.
*
* @return The background color for the tab.
*/
public Color getBackgroundAt(int index)
{
checkIndex(index, 0, tabs.size());
return ((Page) tabs.elementAt(index)).getBackground();
} }
public void updateUI() /**
* This method returns the component associated with the tab.
*
* @param index The index of the tab.
*
* @return The component associated with the tab.
*/
public Component getComponentAt(int index)
{ {
setUI((TabbedPaneUI)UIManager.getUI(this)); checkIndex(index, 0, tabs.size());
return ((Page) tabs.elementAt(index)).getComponent();
} }
public AccessibleContext getAccessibleContext() /**
* This method returns whether this tab is enabled.
* Disabled tabs cannot be selected.
*
* @param index The index of the tab.
*
* @return Whether the tab is enabled.
*/
public boolean isEnabledAt(int index)
{ {
return null; checkIndex(index, 0, tabs.size());
return ((Page) tabs.elementAt(index)).isEnabled();
}
/**
* This method returns the mnemonic for the tab.
*
* @param tabIndex The index of the tab.
*
* @return The mnemonic for the tab.
*/
public int getMnemonicAt(int tabIndex)
{
checkIndex(tabIndex, 0, tabs.size());
return ((Page) tabs.elementAt(tabIndex)).getMnemonic();
}
/**
* This method returns the mnemonic index for the tab.
*
* @param tabIndex The index of the tab.
*
* @return The mnemonic index for the tab.
*/
public int getDisplayedMnemonicIndexAt(int tabIndex)
{
checkIndex(tabIndex, 0, tabs.size());
return ((Page) tabs.elementAt(tabIndex)).getDisplayedMnemonicIndex();
}
/**
* This method returns the bounds of the tab given
* the index.
*
* @param index The index of the tab.
*
* @return A rectangle describing the bounds of the tab.
*/
public Rectangle getBoundsAt(int index)
{
checkIndex(index, 0, tabs.size());
return ((TabbedPaneUI) ui).getTabBounds(this, index);
}
/**
* This method sets the title of the tab.
*
* @param index The index of the tab.
* @param title The new title.
*/
public void setTitleAt(int index, String title)
{
checkIndex(index, 0, tabs.size());
((Page) tabs.elementAt(index)).setTitle(title);
}
/**
* This method sets the icon of the tab.
*
* @param index The index of the tab.
* @param icon The new icon.
*/
public void setIconAt(int index, Icon icon)
{
checkIndex(index, 0, tabs.size());
((Page) tabs.elementAt(index)).setIcon(icon);
}
/**
* This method sets the disabled icon of the tab.
*
* @param index The index of the tab.
* @param disabledIcon The new disabled icon.
*/
public void setDisabledIconAt(int index, Icon disabledIcon)
{
checkIndex(index, 0, tabs.size());
((Page) tabs.elementAt(index)).setDisabledIcon(disabledIcon);
}
/**
* This method sets the tooltip text of the tab.
*
* @param index The index of the tab.
* @param toolTipText The tooltip text.
*/
public void setToolTipTextAt(int index, String toolTipText)
{
checkIndex(index, 0, tabs.size());
((Page) tabs.elementAt(index)).setTip(toolTipText);
}
/**
* This method sets the background color of the tab.
*
* @param index The index of the tab.
* @param background The background color of the tab.
*/
public void setBackgroundAt(int index, Color background)
{
checkIndex(index, 0, tabs.size());
((Page) tabs.elementAt(index)).setBackground(background);
}
/**
* This method sets the foreground color of the tab.
*
* @param index The index of the tab.
* @param foreground The foreground color of the tab.
*/
public void setForegroundAt(int index, Color foreground)
{
checkIndex(index, 0, tabs.size());
((Page) tabs.elementAt(index)).setForeground(foreground);
} }
/**
* This method sets whether the tab is enabled.
*
* @param index The index of the tab.
* @param enabled Whether the tab is enabled.
*/
public void setEnabledAt(int index, boolean enabled)
{
checkIndex(index, 0, tabs.size());
((Page) tabs.elementAt(index)).setEnabled(enabled);
}
/**
* This method sets the component associated with the tab.
*
* @param index The index of the tab.
* @param component The component associated with the tab.
*/
public void setComponentAt(int index, Component component)
{
checkIndex(index, 0, tabs.size());
((Page) tabs.elementAt(index)).setEnabled(enabled);
}
/**
* This method sets the displayed mnemonic index of the tab.
*
* @param tabIndex The index of the tab.
* @param mnemonicIndex The mnemonic index.
*/
public void setDisplayedMnemonicIndexAt(int tabIndex, int mnemonicIndex)
{
checkIndex(tabIndex, 0, tabs.size());
((Page) tabs.elementAt(tabIndex)).setDisplayedMnemonicIndex(mnemonicIndex);
}
/**
* This method sets the mnemonic for the tab.
*
* @param tabIndex The index of the tab.
* @param mnemonic The mnemonic.
*/
public void setMnemonicAt(int tabIndex, int mnemonic)
{
checkIndex(tabIndex, 0, tabs.size());
((Page) tabs.elementAt(tabIndex)).setMnemonic(mnemonic);
}
/**
* This method finds the index of a tab given the title.
*
* @param title The title that belongs to a tab.
*
* @return The index of the tab that has the title or -1 if not found.
*/
public int indexOfTab(String title)
{
int index = -1;
for (int i = 0; i < tabs.size(); i++)
{
if (((Page) tabs.elementAt(i)).getTitle().equals(title))
{
index = i;
break;
}
}
return index;
}
/**
* This method finds the index of a tab given the icon.
*
* @param icon The icon that belongs to a tab.
*
* @return The index of the tab that has the icon or -1 if not found.
*/
public int indexOfTab(Icon icon)
{
int index = -1;
for (int i = 0; i < tabs.size(); i++)
{
if (((Page) tabs.elementAt(i)).getIcon() == icon)
{
index = i;
break;
}
}
return index;
}
/**
* This method finds the index of a tab given the component.
*
* @param component A component associated with a tab.
*
* @return The index of the tab that has this component or -1 if not found.
*/
public int indexOfComponent(Component component)
{
int index = -1;
for (int i = 0; i < tabs.size(); i++)
{
if (((Page) tabs.elementAt(i)).getComponent() == component)
{
index = i;
break;
}
}
return index;
}
/**
* This method returns a tab index given an (x,y) location. The origin
* of the (x,y) pair will be the JTabbedPane's top left position. The
* tab returned will be the one that contains the point. This method is
* delegated to the UI.
*
* @param x The x coordinate of the point.
* @param y The y coordinate of the point.
*
* @return The index of the tab that contains the point.
*/
public int indexAtLocation(int x, int y)
{
return ((TabbedPaneUI) ui).tabForCoordinate(this, x, y);
}
/**
* This method returns the tooltip text given a mouse event.
*
* @param event The mouse event.
*
* @return The tool tip text that is associated with this mouse event.
*/
public String getToolTipText(MouseEvent event)
{
int index = indexAtLocation(event.getX(), event.getY());
return ((Page) tabs.elementAt(index)).getTip();
}
/**
* This method returns a string representation of this JTabbedPane. It
* is mainly used for debugging purposes.
*
* @return A string representation of this JTabbedPane.
*/
protected String paramString() protected String paramString()
{ {
return "JTabbedPane"; return "JTabbedPane";
} }
/**
* DOCUMENT ME!
*
* @return DOCUMENT ME!
*/
public AccessibleContext getAccessibleContext()
{
if (accessibleContext == null)
accessibleContext = new AccessibleJTabbedPane(this);
return accessibleContext;
}
} }
/* BasicArrowButton.java
Copyright (C) 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.Polygon;
import java.awt.Rectangle;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.SwingConstants;
/**
* This class draws simple arrow buttons for the Basic Look and Feel.
*/
public class BasicArrowButton extends JButton implements SwingConstants
{
/**
* A private helper class that draws icons.
*/
private class arrowIcon implements Icon
{
/** The polygon that describes the icon. */
private Polygon arrow;
/** The size of the icon. */
private int size = 10;
/**
* Creates a new arrowIcon object using the given arrow polygon.
*
* @param arrow The polygon that describes the arrow.
*/
public arrowIcon(Polygon arrow)
{
this.arrow = arrow;
}
/**
* Returns the height of the icon.
*
* @return The height of the icon.
*/
public int getIconHeight()
{
return size;
}
/**
* Returns the width of the icon.
*
* @return The width of the icon.
*/
public int getIconWidth()
{
return size;
}
/**
* Sets the size of the icon.
*
* @param size The size of the icon.
*/
public void setSize(int size)
{
this.size = size;
}
/**
* Sets the arrow polygon.
*
* @param arrow The arrow polygon.
*/
public void setArrow(Polygon arrow)
{
this.arrow = arrow;
}
/**
* Paints the icon.
*
* @param c The Component to paint for.
* @param g The Graphics object to draw with.
* @param x The X coordinate to draw at.
* @param y The Y coordinate to draw at.
*/
public void paintIcon(Component c, Graphics g, int x, int y)
{
Color arrowColor;
if (c.isEnabled())
arrowColor = darkShadow;
else
arrowColor = shadow;
paintIconImpl(g, x, y, arrowColor);
}
/**
* This method does the actual painting work.
*
* @param g The Graphics object to paint with.
* @param x The x coordinate to paint at.
* @param y The y coordinate to paint at.
* @param arrowColor The color to paint the arrow with.
*/
public void paintIconImpl(Graphics g, int x, int y, Color arrowColor)
{
g.translate(x, y);
Color saved = g.getColor();
g.setColor(arrowColor);
g.fillPolygon(arrow);
g.setColor(saved);
g.translate(-x, -y);
}
}
/** The direction to point in. */
protected int direction;
/** The color the arrow is painted in if disabled and the bottom and
* right edges of the button. */
private transient Color shadow = Color.BLACK;
/** The color the arrow is painted in if enabled and the bottom and
* right edges of the button. */
private transient Color darkShadow = Color.BLACK;
/** The top and left edges of the button. */
private transient Color highlight = Color.BLACK;
/**
* Creates a new BasicArrowButton object.
*
* @param direction The direction the arrow points in.
*/
public BasicArrowButton(int direction)
{
super();
setDirection(direction);
}
/**
* Creates a new BasicArrowButton object with the given colors and
* direction.
*
* @param direction The direction to point in.
* @param background The background color.
* @param shadow The shadow color.
* @param darkShadow The dark shadow color.
* @param highlight The highlight color.
*/
public BasicArrowButton(int direction, Color background, Color shadow,
Color darkShadow, Color highlight)
{
this(direction);
setBackground(background);
this.shadow = shadow;
this.darkShadow = darkShadow;
this.highlight = highlight;
}
/**
* This method returns the direction of the arrow.
*
* @return The direction of the arrow.
*/
public int getDirection()
{
return direction;
}
/**
* This method changes the direction of the arrow.
*
* @param dir The new direction of the arrow.
*/
public void setDirection(int dir)
{
Polygon arrow = getArrow(dir, 10);
if (getIcon() == null)
setIcon(new arrowIcon(arrow));
else
((arrowIcon) getIcon()).setArrow(arrow);
this.direction = direction;
}
/**
* This method paints the arrow button.
*
* @param g The Graphics object to paint with.
*/
public void paint(Graphics g)
{
super.paint(g);
Rectangle bounds = getBounds();
Color saved = g.getColor();
g.setColor(highlight);
g.drawLine(bounds.x, bounds.y, bounds.x, bounds.y + bounds.height);
g.drawLine(bounds.x, bounds.y, bounds.x + bounds.width, bounds.y);
g.setColor(shadow);
g.drawLine(bounds.x + 1, bounds.y + bounds.height - 1,
bounds.x + bounds.width - 1, bounds.y + bounds.height - 1);
g.drawLine(bounds.x + bounds.width - 1, bounds.y + 1,
bounds.x + bounds.width - 1, bounds.y + bounds.height - 1);
g.setColor(darkShadow);
g.drawLine(bounds.x, bounds.y + bounds.height, bounds.x + bounds.width,
bounds.y + bounds.height);
g.drawLine(bounds.x + bounds.width, bounds.y, bounds.x + bounds.width,
bounds.y + bounds.height);
g.setColor(saved);
}
/**
* This method returns the preferred size of the arrow button.
*
* @return The preferred size.
*/
public Dimension getPreferredSize()
{
return new Dimension(getIcon().getIconWidth(), getIcon().getIconHeight());
}
/**
* This method returns the minimum size of the arrow button.
*
* @return The minimum size.
*/
public Dimension getMinimumSize()
{
return getPreferredSize();
}
/**
* This method returns the maximum size of the arrow button.
*
* @return The maximum size.
*/
public Dimension getMaximumSize()
{
return getPreferredSize();
}
/**
* The method paints a triangle with the given size and direction at
* the given x and y coordinates.
*
* @param g The Graphics object to paint with.
* @param x The x coordinate to paint at.
* @param y The y coordinate to paint at.
* @param size The size of the icon.
* @param direction The direction of the icon.
* @param isEnabled Whether it is enabled.
*/
public void paintTriangle(Graphics g, int x, int y, int size, int direction,
boolean isEnabled)
{
Polygon arrow = getArrow(direction, size);
arrowIcon arrowI = new arrowIcon(arrow);
arrowI.setSize(size);
Color arrowColor;
if (isEnabled())
arrowColor = darkShadow;
else
arrowColor = shadow;
arrowI.paintIconImpl(g, x, y, arrowColor);
}
/**
* This is a private helper that creates polygons for a given size
* and direction.
*
* @param direction The direction of the arrow.
* @param size The size of the arrow.
*
* @return A new arrow polygon.
*/
private Polygon getArrow(int direction, int size)
{
Polygon arrow;
double dsize = (double) size;
int two = (int) (dsize * 2 / 10);
int three = (int) (dsize * 3 / 10);
int five = (int) (dsize * 5 / 10);
int seven = (int) (dsize * 7 / 10);
int eight = (int) (dsize * 8 / 10);
switch (direction)
{
case NORTH:
arrow = new Polygon(new int[] { two, five, eight },
new int[] { seven, three, seven }, 3);
break;
case SOUTH:
arrow = new Polygon(new int[] { two, five, eight },
new int[] { three, seven, three }, 3);
break;
case EAST:
case RIGHT:
arrow = new Polygon(new int[] { three, seven, three },
new int[] { two, five, eight }, 3);
break;
case WEST:
case LEFT:
arrow = new Polygon(new int[] { seven, three, seven },
new int[] { two, five, eight }, 3);
break;
default:
throw new IllegalArgumentException("Invalid direction given.");
}
return arrow;
}
}
/* BasicCheckBoxMenuItemUI.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.event.MouseEvent;
import javax.swing.AbstractButton;
import javax.swing.Icon;
import javax.swing.JComponent;
import javax.swing.JMenuItem;
import javax.swing.MenuElement;
import javax.swing.MenuSelectionManager;
import javax.swing.UIDefaults;
import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI;
public class BasicCheckBoxMenuItemUI extends BasicMenuItemUI
{
public static ComponentUI createUI(final JComponent c)
{
return new BasicCheckBoxMenuItemUI();
}
protected String getPropertyPrefix()
{
return null; // TODO
}
protected void installDefaults()
{
super.installDefaults();
UIDefaults defaults = UIManager.getLookAndFeelDefaults();
checkIcon = defaults.getIcon("CheckBoxMenuItem.checkIcon");
}
void processMouseEvent(JMenuItem item, MouseEvent e, MenuElement[] path,
MenuSelectionManager manager)
{
}
}
...@@ -196,11 +196,11 @@ public class BasicIconFactory implements Serializable ...@@ -196,11 +196,11 @@ public class BasicIconFactory implements Serializable
} }
public static Icon getCheckBoxMenuItemIcon() public static Icon getCheckBoxMenuItemIcon()
{ {
return new DummyIcon(); return getCheckBoxIcon();
} }
public static Icon getRadioButtonMenuItemIcon() public static Icon getRadioButtonMenuItemIcon()
{ {
return new DummyIcon(); return getRadioButtonIcon();
} }
public static Icon createEmptyFrameIcon() public static Icon createEmptyFrameIcon()
{ {
......
...@@ -501,7 +501,7 @@ public abstract class BasicLookAndFeel extends LookAndFeel ...@@ -501,7 +501,7 @@ public abstract class BasicLookAndFeel extends LookAndFeel
"MenuBar.windowBindings", new Object[] { "MenuBar.windowBindings", new Object[] {
"F10", "takeFocus" "F10", "takeFocus"
}, },
"MenuItem.acceleratorDelimiter", "+", "MenuItem.acceleratorDelimiter", "-",
"MenuItem.acceleratorFont", new FontUIResource("Dialog", Font.PLAIN, 12), "MenuItem.acceleratorFont", new FontUIResource("Dialog", Font.PLAIN, 12),
"MenuItem.acceleratorForeground", new ColorUIResource(Color.black), "MenuItem.acceleratorForeground", new ColorUIResource(Color.black),
"MenuItem.acceleratorSelectionForeground", new ColorUIResource(Color.white), "MenuItem.acceleratorSelectionForeground", new ColorUIResource(Color.white),
...@@ -703,9 +703,9 @@ public abstract class BasicLookAndFeel extends LookAndFeel ...@@ -703,9 +703,9 @@ public abstract class BasicLookAndFeel extends LookAndFeel
"ctrl UP", "requestFocus", "ctrl UP", "requestFocus",
"ctrl KP_UP", "requestFocus" "ctrl KP_UP", "requestFocus"
}), }),
"TabbedPane.background", new ColorUIResource(Color.lightGray), "TabbedPane.background", new ColorUIResource(Color.GRAY),
"TabbedPane.contentBorderInsets", new InsetsUIResource(2, 2, 3, 3), "TabbedPane.contentBorderInsets", new InsetsUIResource(2, 2, 3, 3),
"TabbedPane.darkShadow", new ColorUIResource(Color.black), "TabbedPane.darkShadow", new ColorUIResource(Color.darkGray),
"TabbedPane.focus", new ColorUIResource(Color.black), "TabbedPane.focus", new ColorUIResource(Color.black),
"TabbedPane.focusInputMap", new UIDefaults.LazyInputMap(new Object[] { "TabbedPane.focusInputMap", new UIDefaults.LazyInputMap(new Object[] {
"LEFT", "navigateLeft", "LEFT", "navigateLeft",
...@@ -725,8 +725,10 @@ public abstract class BasicLookAndFeel extends LookAndFeel ...@@ -725,8 +725,10 @@ public abstract class BasicLookAndFeel extends LookAndFeel
"TabbedPane.lightHighlight", new ColorUIResource(Color.white), "TabbedPane.lightHighlight", new ColorUIResource(Color.white),
"TabbedPane.selectedTabPadInsets", new InsetsUIResource(2, 2, 2, 1), "TabbedPane.selectedTabPadInsets", new InsetsUIResource(2, 2, 2, 1),
"TabbedPane.shadow", new ColorUIResource(Color.gray), "TabbedPane.shadow", new ColorUIResource(Color.gray),
"TabbedPane.tabAreaInsets", new InsetsUIResource(3, 2, 0, 2), "TabbedPane.tabbedPaneTabAreaInsets", new InsetsUIResource(3, 2, 1, 2),
"TabbedPane.tabInsets", new InsetsUIResource(0, 4, 1, 4), "TabbedPane.tabbedPaneTabInsets", new InsetsUIResource(1, 4, 1, 4),
"TabbedPane.tabbedPaneContentBorderInsets", new InsetsUIResource(3, 2, 1, 2),
"TabbedPane.tabbedPaneTabPadInsets", new InsetsUIResource(1, 1, 1, 1),
"TabbedPane.tabRunOverlay", new Integer(2), "TabbedPane.tabRunOverlay", new Integer(2),
"TabbedPane.textIconGap", new Integer(4), "TabbedPane.textIconGap", new Integer(4),
"Table.ancestorInputMap", new UIDefaults.LazyInputMap(new Object[] { "Table.ancestorInputMap", new UIDefaults.LazyInputMap(new Object[] {
......
/* BasicMenuItemUI.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.AWTKeyStroke;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Insets;
import java.awt.Rectangle;
import java.awt.Stroke;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.AbstractButton;
import javax.swing.ButtonModel;
import javax.swing.Icon;
import javax.swing.JComponent;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JMenuItem;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.KeyStroke;
import javax.swing.MenuElement;
import javax.swing.MenuSelectionManager;
import javax.swing.SwingUtilities;
import javax.swing.UIDefaults;
import javax.swing.UIManager;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.MenuDragMouseEvent;
import javax.swing.event.MenuDragMouseListener;
import javax.swing.event.MenuKeyEvent;
import javax.swing.event.MenuKeyListener;
import javax.swing.event.MouseInputListener;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.MenuItemUI;
public class BasicMenuItemUI extends MenuItemUI
{
/** Font to be used when displaying menu item's accelerator. */
protected Font acceleratorFont;
/** Color to be used when displaying menu item's accelerator. */
protected Color acceleratorForeground;
/** Color to be used when displaying menu item's accelerator
* when menu item is selected.
*/
protected Color acceleratorSelectionForeground;
/**
* Icon that is displayed after the text to indicated that this menu
* contains submenu.
*/
protected Icon arrowIcon;
/**
* Icon that is displayed before the text. This icon is only used in
* JCheckBoxMenuItem or JRadioBoxMenuItem.
*/
protected Icon checkIcon;
/** Number of spaces between icon and text. */
protected int defaultTextIconGap = 4;
/** Color of the text when menu item is disabled*/
protected Color disabledForeground;
/** The menu Drag mouse listener listening to the menu item. */
protected MenuDragMouseListener menuDragMouseListener;
/** The menu item itself*/
protected JMenuItem menuItem;
/** Menu Key listener listening to the menu item. */
protected MenuKeyListener menuKeyListener;
/** mouse input listener listening to menu item. */
protected MouseInputListener mouseInputListener;
/** Indicates if border should be painted */
protected boolean oldBorderPainted;
/** Color of text that is used when menu item is selected */
protected Color selectionBackground;
/** Color of the background that is used when menu item is selected.*/
protected Color selectionForeground;
/** String that separates description of the modifiers and the key*/
private String acceleratorDelimiter;
/** Number of spaces between accelerator and menu item's label. */
private int defaultAcceleratorLabelGap = 4;
// Constructor Summary
BasicMenuItemUI()
{
mouseInputListener = createMouseInputListener(menuItem);
menuDragMouseListener = createMenuDragMouseListener(menuItem);
menuKeyListener = createMenuKeyListener(menuItem);
}
// Method Summary
protected MenuDragMouseListener createMenuDragMouseListener(JComponent c)
{
return new MenuDragMouseHandler();
}
protected MenuKeyListener createMenuKeyListener(JComponent c)
{
return new MenuKeyHandler();
}
protected MouseInputListener createMouseInputListener(JComponent c)
{
return new MouseInputHandler();
}
public static ComponentUI createUI(JComponent c)
{
return new BasicMenuItemUI();
}
protected void doClick(MenuSelectionManager msm)
{
// TODO
}
public Dimension getMaximumSize(JComponent c)
{
// TODO
return null;
}
public Dimension getMinimumSize(JComponent c)
{
// TODO
return null;
}
public MenuElement[] getPath()
{
// TODO
return null;
}
protected Dimension getPreferredMenuItemSize(JComponent c, Icon checkIcon,
Icon arrowIcon,
int defaultTextIconGap)
{
// TODO
return null;
}
public Dimension getPreferredSize(JComponent c)
{
AbstractButton b = (AbstractButton) c;
Dimension d = BasicGraphicsUtils.getPreferredButtonSize(b,
defaultTextIconGap);
// if menu item has accelerator then take accelerator's size into account
// when calculating preferred size.
KeyStroke accelerator = ((JMenuItem) c).getAccelerator();
Rectangle rect;
if (accelerator != null)
{
rect = getAcceleratorRect(accelerator,
b.getToolkit().getFontMetrics(acceleratorFont));
// add width of accelerator's text
d.width = d.width + rect.width + defaultAcceleratorLabelGap;
// adjust the heigth of the preferred size if necessary
if (d.height < rect.height)
d.height = rect.height;
}
if (checkIcon != null)
{
d.width = d.width + checkIcon.getIconWidth() + defaultTextIconGap;
if (checkIcon.getIconHeight() > d.height)
d.height = checkIcon.getIconHeight();
}
return d;
}
protected String getPropertyPrefix()
{
// TODO
return null;
}
protected void installComponents(JMenuItem menuItem)
{
// TODO
}
protected void installDefaults()
{
UIDefaults defaults = UIManager.getLookAndFeelDefaults();
menuItem.setBackground(defaults.getColor("MenuItem.background"));
menuItem.setBorder(defaults.getBorder("MenuItem.border"));
menuItem.setFont(defaults.getFont("MenuItem.font"));
menuItem.setForeground(defaults.getColor("MenuItem.foreground"));
menuItem.setMargin(defaults.getInsets("MenuItem.margin"));
acceleratorFont = defaults.getFont("MenuItem.acceleratorFont");
acceleratorForeground = defaults.getColor("MenuItem.acceleratorForeground");
acceleratorSelectionForeground = defaults.getColor("MenuItem.acceleratorSelectionForeground");
arrowIcon = defaults.getIcon("MenuItem.arrowIcon");
selectionBackground = defaults.getColor("MenuItem.selectionBackground");
selectionForeground = defaults.getColor("MenuItem.selectionForeground");
acceleratorDelimiter = defaults.getString("MenuItem.acceleratorDelimiter");
}
protected void installKeyboardActions()
{
// TODO
}
protected void installListeners()
{
menuItem.addMouseListener(mouseInputListener);
menuItem.addMenuDragMouseListener(menuDragMouseListener);
menuItem.addMenuKeyListener(menuKeyListener);
}
public void installUI(JComponent c)
{
super.installUI(c);
menuItem = (JMenuItem) c;
installDefaults();
installListeners();
}
public void paint(Graphics g, JComponent c)
{
paintMenuItem(g, c, checkIcon, arrowIcon, c.getBackground(),
c.getForeground(), defaultTextIconGap);
}
protected void paintBackground(Graphics g, JMenuItem menuItem, Color bgColor)
{
Dimension size = getPreferredSize(menuItem);
Color foreground = g.getColor();
g.setColor(bgColor);
g.drawRect(0, 0, size.width, size.height);
g.setColor(foreground);
}
protected void paintMenuItem(Graphics g, JComponent c, Icon checkIcon,
Icon arrowIcon, Color background,
Color foreground, int defaultTextIconGap)
{
AbstractButton b = (AbstractButton) c;
Rectangle tr = new Rectangle(); // text rectangle
Rectangle ir = new Rectangle(); // icon rectangle
Rectangle vr = new Rectangle(); // view rectangle
Rectangle br = new Rectangle(); // border rectangle
Rectangle ar = new Rectangle(); // accelerator rectangle
Rectangle cr = new Rectangle(); // checkIcon rectangle
int vertAlign = b.getVerticalAlignment();
int horAlign = b.getHorizontalAlignment();
int vertTextPos = b.getVerticalTextPosition();
int horTextPos = b.getHorizontalTextPosition();
Font f = c.getFont();
g.setFont(f);
FontMetrics fm = g.getFontMetrics(f);
SwingUtilities.calculateInnerArea(b, br);
SwingUtilities.calculateInsetArea(br, b.getMargin(), vr);
paintBackground(g, (JMenuItem) c, c.getBackground());
if ((b.getModel().isArmed() && b.getModel().isPressed()))
{
if (((AbstractButton) b).isContentAreaFilled())
{
g.setColor(b.getBackground().darker());
g.fillRect(br.x, br.y, br.width, br.height);
}
}
else
{
if (((AbstractButton) b).isContentAreaFilled())
{
g.setColor(b.getBackground());
g.fillRect(br.x, br.y, br.width, br.height);
}
}
if (checkIcon != null)
{
SwingUtilities.layoutCompoundLabel(c, fm, null, checkIcon, vertAlign,
horAlign, vertTextPos, horTextPos,
vr, cr, tr, defaultTextIconGap);
checkIcon.paintIcon(c, g, cr.x, cr.y);
// We need to calculate position of the menu text and position of
// user menu icon if there exists one relative to the check icon.
// So we need to adjust view rectangle s.t. its starting point is at
// checkIcon.width + defaultTextIconGap.
vr.x = cr.x + cr.width + defaultTextIconGap;
}
if (arrowIcon != null)
{
// FIXME: if this menu contains a submenu, we need to draw arrow icon
// here as well
}
// paint text and user menu icon if it exists
SwingUtilities.layoutCompoundLabel(c, fm, b.getText(), b.getIcon(),
vertAlign, horAlign, vertTextPos,
horTextPos, vr, ir, tr,
defaultTextIconGap);
paintText(g, (JMenuItem) c, tr, b.getText());
// paint icon
// FIXME: should paint different icon at different button state's.
// i.e disabled icon when button is disabled.. etc.
/*
Icon i = b.getIcon();
if (i != null)
{
int x = ir.x;
int y = ir.y;
i.paintIcon(c, g, x, y);
}
*/
// paint accelerator
String acceleratorText = "";
if (((JMenuItem) c).getAccelerator() != null)
{
acceleratorText = getAcceleratorText(((JMenuItem) c).getAccelerator());
fm = g.getFontMetrics(acceleratorFont);
ar.width = fm.stringWidth(acceleratorText);
ar.x = br.width - ar.width;
vr.x = br.width - ar.width;
SwingUtilities.layoutCompoundLabel(c, fm, acceleratorText, null,
vertAlign, horAlign, vertTextPos,
horTextPos, vr, ir, ar,
defaultTextIconGap);
paintAccelerator(g, (JMenuItem) c, ar, acceleratorText);
}
}
protected void paintText(Graphics g, JMenuItem menuItem, Rectangle textRect,
String text)
{
Font f = menuItem.getFont();
g.setFont(f);
FontMetrics fm = g.getFontMetrics(f);
g.setColor(menuItem.getForeground());
BasicGraphicsUtils.drawString(g, text, 0, textRect.x,
textRect.y + fm.getAscent());
}
protected void uninstallComponents(JMenuItem menuItem)
{
// TODO
}
protected void uninstallDefaults()
{
menuItem.setForeground(null);
menuItem.setBackground(null);
menuItem.setBorder(null);
menuItem.setMargin(null);
menuItem.setBackground(null);
menuItem.setBorder(null);
menuItem.setFont(null);
menuItem.setForeground(null);
menuItem.setMargin(null);
acceleratorFont = null;
acceleratorForeground = null;
acceleratorSelectionForeground = null;
arrowIcon = null;
selectionBackground = null;
selectionForeground = null;
acceleratorDelimiter = null;
}
protected void uninstallKeyboardActions()
{
// TODO
}
protected void uninstallListeners()
{
menuItem.removeMouseListener(mouseInputListener);
menuItem.removeMenuDragMouseListener(menuDragMouseListener);
menuItem.removeMenuKeyListener(menuKeyListener);
}
public void uninstallUI(JComponent c)
{
uninstallListeners();
uninstallDefaults();
menuItem = null;
}
public void update(Graphics g, JComponent c)
{
// TODO
}
private String getAcceleratorText(KeyStroke accelerator)
{
// convert keystroke into string format
String modifiersText = "";
int modifiers = accelerator.getModifiers();
char keyChar = accelerator.getKeyChar();
int keyCode = accelerator.getKeyCode();
if (modifiers != 0)
modifiersText = KeyEvent.getKeyModifiersText(modifiers) +
acceleratorDelimiter;
if (keyCode == KeyEvent.VK_UNDEFINED)
return modifiersText + keyChar;
else
return modifiersText + KeyEvent.getKeyText(keyCode);
}
private Rectangle getAcceleratorRect(KeyStroke accelerator, FontMetrics fm)
{
int width = fm.stringWidth(getAcceleratorText(accelerator));
int height = fm.getHeight();
return new Rectangle(0, 0, width, height);
}
private void paintAccelerator(Graphics g, JMenuItem menuItem, Rectangle acceleratorRect,
String acceleratorText)
{
g.setFont(acceleratorFont);
FontMetrics fm = g.getFontMetrics(acceleratorFont);
g.setColor(acceleratorForeground);
BasicGraphicsUtils.drawString(g, acceleratorText, 0, acceleratorRect.x,
acceleratorRect.y + fm.getAscent());
}
protected class MouseInputHandler implements MouseInputListener
{
protected MouseInputHandler()
{
}
public void mouseClicked(MouseEvent e)
{
}
public void mouseDragged(MouseEvent e)
{
}
public void mouseEntered(MouseEvent e)
{
if (e.getSource() instanceof AbstractButton)
{
AbstractButton button = (AbstractButton) e.getSource();
ButtonModel model = button.getModel();
if (button.isRolloverEnabled())
{
model.setRollover(true);
}
if (model.isPressed() &&
((e.getModifiers() & InputEvent.BUTTON1_MASK) != 0))
{
model.setArmed(true);
}
else
{
model.setArmed(false);
}
}
}
public void mouseExited(MouseEvent e)
{
if (e.getSource() instanceof AbstractButton)
{
AbstractButton button = (AbstractButton) e.getSource();
ButtonModel model = button.getModel();
if (button.isRolloverEnabled())
{
model.setRollover(false);
}
model.setArmed(false);
}
}
public void mouseMoved(MouseEvent e)
{
}
public void mousePressed(MouseEvent e)
{
if (e.getSource() instanceof AbstractButton)
{
AbstractButton button = (AbstractButton) e.getSource();
ButtonModel model = button.getModel();
if ((e.getModifiers() & InputEvent.BUTTON1_MASK) != 0)
{
// It is important that these transitions happen in this order.
model.setArmed(true);
model.setPressed(true);
}
}
}
public void mouseReleased(MouseEvent e)
{
if (e.getSource() instanceof AbstractButton)
{
AbstractButton button = (AbstractButton) e.getSource();
ButtonModel model = button.getModel();
if ((e.getModifiers() & InputEvent.BUTTON1_MASK) != 0)
{
// It is important that these transitions happen in this order.
model.setPressed(false);
model.setArmed(false);
}
}
}
}
protected class MenuDragMouseHandler implements MenuDragMouseListener
{
public void menuDragMouseDragged(MenuDragMouseEvent e)
{
// TODO
}
public void menuDragMouseEntered(MenuDragMouseEvent e)
{
// TODO
}
public void menuDragMouseExited(MenuDragMouseEvent e)
{
// TODO
}
public void menuDragMouseReleased(MenuDragMouseEvent e)
{
// TODO
}
}
protected class MenuKeyHandler implements MenuKeyListener
{
public void menuKeyPressed(MenuKeyEvent e)
{
// TODO
}
public void menuKeyReleased(MenuKeyEvent e)
{
// TODO
}
public void menuKeyTyped(MenuKeyEvent e)
{
// TODO
}
}
protected class PropertyChangeHandler
{
public void propertyChange(PropertyChangeEvent evt)
{
// TODO
}
}
}
...@@ -573,7 +573,7 @@ public class BasicProgressBarUI extends ProgressBarUI ...@@ -573,7 +573,7 @@ public class BasicProgressBarUI extends ProgressBarUI
} }
} }
if (progressBar.isStringPainted()) if (progressBar.isStringPainted() && !progressBar.getString().equals(""))
paintString(g, 0, 0, or.width, or.height, amountFull, insets); paintString(g, 0, 0, or.width, or.height, amountFull, insets);
g.setColor(saved); g.setColor(saved);
} }
...@@ -605,7 +605,7 @@ public class BasicProgressBarUI extends ProgressBarUI ...@@ -605,7 +605,7 @@ public class BasicProgressBarUI extends ProgressBarUI
g.setColor(c.getForeground()); g.setColor(c.getForeground());
g.fill3DRect(box.x, box.y, box.width, box.height, true); g.fill3DRect(box.x, box.y, box.width, box.height, true);
if (progressBar.isStringPainted()) if (progressBar.isStringPainted() && !progressBar.getString().equals(""))
paintString(g, 0, 0, or.width, or.height, paintString(g, 0, 0, or.width, or.height,
getAmountFull(insets, or.width, or.height), insets); getAmountFull(insets, or.width, or.height), insets);
......
/* BasicRadioButtonMenuItemUI.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.event.MouseEvent;
import javax.swing.AbstractButton;
import javax.swing.Icon;
import javax.swing.JComponent;
import javax.swing.JMenuItem;
import javax.swing.UIDefaults;
import javax.swing.UIManager;
import javax.swing.MenuElement;
import javax.swing.MenuSelectionManager;
import javax.swing.plaf.ComponentUI;
public class BasicRadioButtonMenuItemUI extends BasicMenuItemUI
{
public BasicRadioButtonMenuItemUI()
{
super();
UIDefaults defaults = UIManager.getLookAndFeelDefaults();
checkIcon = defaults.getIcon("RadioButtonMenuItem.checkIcon");
}
public static ComponentUI createUI(JComponent b)
{
return new BasicRadioButtonMenuItemUI();
}
protected String getPropertyPrefix()
{
return null;
// TODO
}
void processMouseEvent(JMenuItem item, MouseEvent e, MenuElement[] path,
MenuSelectionManager manager)
{
}
}
/* BasicTabbedPaneUI.java /* BasicTabbedPaneUI.java
Copyright (C) 2002 Free Software Foundation, Inc. Copyright (C) 2002, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath. This file is part of GNU Classpath.
...@@ -28,82 +28,3012 @@ permission to link this library with independent modules to produce an ...@@ -28,82 +28,3012 @@ permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that independent module, the terms and conditions of7 the license of that
module. An independent module is a module which is not derived from 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 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 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 obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */ exception statement from your version. */
package javax.swing.plaf.basic; package javax.swing.plaf.basic;
import java.awt.Color;
import java.awt.Component; import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Insets; import java.awt.Insets;
import java.awt.LayoutManager;
import java.awt.Point;
import java.awt.Polygon;
import java.awt.Rectangle; import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.lang.Exception;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JTabbedPane; import javax.swing.JTabbedPane;
import javax.swing.JViewport;
import javax.swing.KeyStroke;
import javax.swing.SingleSelectionModel;
import javax.swing.SwingConstants; import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.UIDefaults;
import javax.swing.UIManager;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.plaf.ComponentUI; import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.PanelUI;
import javax.swing.plaf.TabbedPaneUI; import javax.swing.plaf.TabbedPaneUI;
import javax.swing.plaf.UIResource;
import javax.swing.plaf.ViewportUI;
import javax.swing.plaf.basic.BasicGraphicsUtils;
import javax.swing.text.View;
public class BasicTabbedPaneUI extends TabbedPaneUI /**
implements SwingConstants * This is the Basic Look and Feel's UI delegate for JTabbedPane.
*/
public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants
{ {
public static ComponentUI createUI(final JComponent c) /**
* A helper class that handles focus.
*/
protected class FocusHandler extends FocusAdapter
{ {
return new BasicTabbedPaneUI(); /**
* This method is called when the component gains focus.
*
* @param e The FocusEvent.
*/
public void focusGained(FocusEvent e)
{
// FIXME: Implement.
} }
public void installUI(final JComponent c) /**
* This method is called when the component loses focus.
*
* @param e The FocusEvent.
*/
public void focusLost(FocusEvent e)
{ {
super.installUI(c); // FIXME: Implement.
}
} }
public Dimension getPreferredSize(JComponent c) /**
* A helper class for determining if mouse presses occur inside tabs and
* sets the index appropriately. In SCROLL_TAB_MODE, this class also
* handles the mouse clicks on the scrolling buttons.
*/
protected class MouseHandler extends MouseAdapter
{
/**
* This method is called when the mouse is pressed. The index cannot
* change to a tab that is not enabled.
*
* @param e The MouseEvent.
*/
public void mousePressed(MouseEvent e)
{
int x = e.getX();
int y = e.getY();
int tabCount = tabPane.getTabCount();
if (tabPane.getTabLayoutPolicy() == JTabbedPane.SCROLL_TAB_LAYOUT)
{
if (e.getSource() == incrButton)
{
if (++currentScrollLocation >= tabCount)
currentScrollLocation = tabCount - 1;
if (currentScrollLocation == tabCount - 1)
incrButton.setEnabled(false);
else if (! decrButton.isEnabled())
decrButton.setEnabled(true);
tabPane.layout();
tabPane.repaint();
return;
}
else if (e.getSource() == decrButton)
{
if (--currentScrollLocation < 0)
currentScrollLocation = 0;
if (currentScrollLocation == 0)
decrButton.setEnabled(false);
else if (! incrButton.isEnabled())
incrButton.setEnabled(true);
tabPane.layout();
tabPane.repaint();
return;
}
}
int index = tabForCoordinate(tabPane, x, y);
// We need to check since there are areas where tabs cannot be
// e.g. in the inset area.
if (index != -1 && tabPane.isEnabledAt(index))
tabPane.setSelectedIndex(index);
}
}
/**
* This class handles PropertyChangeEvents fired from the JTabbedPane.
*/
protected class PropertyChangeHandler implements PropertyChangeListener
{
/**
* This method is called whenever one of the properties of the JTabbedPane
* changes.
*
* @param e The PropertyChangeEvent.
*/
public void propertyChange(PropertyChangeEvent e)
{ {
JTabbedPane p = (JTabbedPane) c; if (e.getPropertyName().equals(JTabbedPane.TAB_LAYOUT_POLICY_CHANGED_PROPERTY))
{
layoutManager = createLayoutManager();
Dimension d = new Dimension(50,50); tabPane.setLayout(layoutManager);
}
else if (e.getPropertyName().equals(JTabbedPane.TAB_PLACEMENT_CHANGED_PROPERTY)
&& tabPane.getTabLayoutPolicy() == JTabbedPane.SCROLL_TAB_LAYOUT)
{
incrButton = createIncreaseButton();
decrButton = createDecreaseButton();
}
tabPane.layout();
tabPane.repaint();
}
}
for (int i=0;i<p.getTabCount();i++) /**
* A LayoutManager responsible for placing all the tabs and the visible
* component inside the JTabbedPane. This class is only used for
* WRAP_TAB_LAYOUT.
*/
protected class TabbedPaneLayout implements LayoutManager
{ {
Component comp = p.getComponentAt(i); /**
* This method is called when a component is added to the JTabbedPane.
*
* @param name The name of the component.
* @param comp The component being added.
*/
public void addLayoutComponent(String name, Component comp)
{
// Do nothing.
}
Dimension pr = comp.getPreferredSize(); /**
* This method is called when the rectangles need to be calculated. It
* also fixes the size of the visible component.
*/
public void calculateLayoutInfo()
{
calculateTabRects(tabPane.getTabPlacement(), tabPane.getTabCount());
d.width = Math.max(d.width, comp.getWidth()); if (tabPane.getSelectedIndex() != -1)
d.height = Math.max(d.height, comp.getHeight()); {
Component visible = getVisibleComponent();
Insets insets = getContentBorderInsets(tabPane.getTabPlacement());
visible.setBounds(contentRect.x + insets.left,
contentRect.y + insets.top,
contentRect.width - insets.left - insets.right,
contentRect.height - insets.top - insets.bottom);
} }
}
/**
* This method calculates the size of the the JTabbedPane.
*
* @param minimum Whether the JTabbedPane will try to be as small as it
* can.
*
* @return The desired size of the JTabbedPane.
*/
protected Dimension calculateSize(boolean minimum)
{
int tabPlacement = tabPane.getTabPlacement();
int width = 0;
int height = 0;
Insets i = p.getInsets(); int componentHeight = 0;
int componentWidth = 0;
Component c;
Dimension dims;
for (int i = 0; i < tabPane.getTabCount(); i++)
{
c = tabPane.getComponentAt(i);
if (c == null)
continue;
calcRect = c.getBounds();
dims = c.getPreferredSize();
if (dims != null)
{
componentHeight = Math.max(componentHeight, dims.height);
componentWidth = Math.max(componentWidth, dims.width);
}
}
Insets insets = tabPane.getInsets();
d.width += i.left + i.right; if (tabPlacement == SwingConstants.TOP
d.height += i.top + i.bottom; || tabPlacement == SwingConstants.BOTTOM)
{
width = calculateMaxTabWidth(tabPlacement) * tabPane.getTabCount();
calcRect = tabPane.getParent().getBounds();
width = Math.max(width, componentWidth);
int height_of_tabs = 25; int tabAreaHeight = preferredTabAreaHeight(tabPlacement, width);
height = tabAreaHeight + componentHeight;
}
else
{
height = calculateMaxTabHeight(tabPlacement) * tabPane.getTabCount();
calcRect = tabPane.getParent().getBounds();
height = Math.max(height, componentHeight);
d.height += height_of_tabs; int tabAreaWidth = preferredTabAreaWidth(tabPlacement, height);
width = tabAreaWidth + componentWidth;
}
// FIXME: should be max of panes in p return new Dimension(width, height);
return d;
} }
// if tab placement is LEFT OR RIGHT, they share width.
// if tab placement is TOP OR BOTTOM, they share height
// PRE STEP: finds the default sizes for the labels as well as their locations.
// AND where they will be placed within the run system.
// 1. calls normalizeTab Runs.
// 2. calls rotate tab runs.
// 3. pads the tab runs.
// 4. pads the selected tab.
public Rectangle getTabBounds(JTabbedPane pane, int index) /**
* This method is called to calculate the tab rectangles. This method
* will calculate the size and position of all rectangles (taking into
* account which ones should be in which tab run). It will pad them and
* normalize them as necessary.
*
* @param tabPlacement The JTabbedPane's tab placement.
* @param tabCount The run the current selection is in.
*/
protected void calculateTabRects(int tabPlacement, int tabCount)
{ {
return null; if (tabCount == 0)
return;
assureRectsCreated(tabCount);
FontMetrics fm = getFontMetrics();
SwingUtilities.calculateInnerArea(tabPane, calcRect);
Insets tabAreaInsets = getTabAreaInsets(tabPlacement);
Insets insets = tabPane.getInsets();
int max = 0;
int runs = 0;
int start = getTabRunIndent(tabPlacement, 1);
if (tabPlacement == SwingConstants.TOP
|| tabPlacement == SwingConstants.BOTTOM)
{
int maxHeight = calculateMaxTabHeight(tabPlacement);
calcRect.width -= tabAreaInsets.left + tabAreaInsets.right;
max = calcRect.width + tabAreaInsets.left + insets.left;
start += tabAreaInsets.left + insets.left;
int width = 0;
int runWidth = start;
for (int i = 0; i < tabCount; i++)
{
width = calculateTabWidth(tabPlacement, i, fm);
if (runWidth + width > max)
{
runWidth = tabAreaInsets.left + insets.left
+ getTabRunIndent(tabPlacement, ++runs);
rects[i] = new Rectangle(runWidth,
insets.top + tabAreaInsets.top,
width, maxHeight);
runWidth += width;
if (runs > tabRuns.length - 1)
expandTabRunsArray();
tabRuns[runs] = i;
}
else
{
rects[i] = new Rectangle(runWidth,
insets.top + tabAreaInsets.top,
width, maxHeight);
runWidth += width;
}
}
runs++;
tabAreaRect.width = tabPane.getWidth() - insets.left - insets.right;
tabAreaRect.height = runs * maxTabHeight
- (runs - 1) * tabRunOverlay
+ tabAreaInsets.top + tabAreaInsets.bottom;
contentRect.width = tabAreaRect.width;
contentRect.height = tabPane.getHeight() - insets.top
- insets.bottom - tabAreaRect.height;
contentRect.x = insets.left;
tabAreaRect.x = insets.left;
if (tabPlacement == SwingConstants.BOTTOM)
{
contentRect.y = insets.top;
tabAreaRect.y = contentRect.y + contentRect.height;
} }
else
{
tabAreaRect.y = insets.top;
contentRect.y = tabAreaRect.y + tabAreaRect.height;
}
}
else
{
int maxWidth = calculateMaxTabWidth(tabPlacement);
calcRect.height -= tabAreaInsets.top + tabAreaInsets.bottom;
max = calcRect.height + tabAreaInsets.top + insets.top;
public int getTabRunCount(JTabbedPane pane) int height = 0;
start += tabAreaInsets.top + insets.top;
int runHeight = start;
int fontHeight = fm.getHeight();
for (int i = 0; i < tabCount; i++)
{ {
return 0; height = calculateTabHeight(tabPlacement, i, fontHeight);
if (runHeight + height > max)
{
runHeight = tabAreaInsets.top + insets.top
+ getTabRunIndent(tabPlacement, ++runs);
rects[i] = new Rectangle(insets.left + tabAreaInsets.left,
runHeight, maxWidth, height);
runHeight += height;
if (runs > tabRuns.length - 1)
expandTabRunsArray();
tabRuns[runs] = i;
}
else
{
rects[i] = new Rectangle(insets.left + tabAreaInsets.left,
runHeight, maxWidth, height);
runHeight += height;
}
} }
runs++;
public int tabForCoordinate(JTabbedPane pane, int x, int y) tabAreaRect.width = runs * maxTabWidth - (runs - 1) * tabRunOverlay
+ tabAreaInsets.left + tabAreaInsets.right;
tabAreaRect.height = tabPane.getHeight() - insets.top
- insets.bottom;
tabAreaRect.y = insets.top;
contentRect.width = tabPane.getWidth() - insets.left - insets.right
- tabAreaRect.width;
contentRect.height = tabAreaRect.height;
contentRect.y = insets.top;
if (tabPlacement == SwingConstants.LEFT)
{ {
return 0; tabAreaRect.x = insets.left;
contentRect.x = tabAreaRect.x + tabAreaRect.width;
} }
} else
{
contentRect.x = insets.left;
tabAreaRect.x = contentRect.x + contentRect.width;
}
}
runCount = runs;
tabRuns[0] = 0;
normalizeTabRuns(tabPlacement, tabCount, start, max);
selectedRun = getRunForTab(tabCount, tabPane.getSelectedIndex());
if (shouldRotateTabRuns(tabPlacement))
rotateTabRuns(tabPlacement, selectedRun);
// Need to pad the runs and move them to the correct location.
for (int i = 0; i < runCount; i++)
{
int first = lastTabInRun(tabCount, getPreviousTabRun(i)) + 1;
if (first == tabCount)
first = 0;
int last = lastTabInRun(tabCount, i);
if (shouldPadTabRun(tabPlacement, i))
padTabRun(tabPlacement, first, last, max);
// Done padding, now need to move it.
if (tabPlacement == SwingConstants.TOP && i > 0)
{
for (int j = first; j <= last; j++)
rects[j].y += (runCount - i) * maxTabHeight
+ (runCount - i) * tabRunOverlay;
}
if (tabPlacement == SwingConstants.BOTTOM)
{
int height = tabPane.getBounds().height - insets.bottom
- tabAreaInsets.bottom;
int adjustment;
if (i == 0)
adjustment = height - maxTabHeight;
else
adjustment = height - (runCount - i + 1) * maxTabHeight
- (runCount - i) * tabRunOverlay;
for (int j = first; j <= last; j++)
rects[j].y = adjustment;
}
if (tabPlacement == SwingConstants.LEFT && i > 0)
{
for (int j = first; j <= last; j++)
rects[j].x += (runCount - i) * maxTabWidth
- (runCount - i) * tabRunOverlay;
}
if (tabPlacement == SwingConstants.RIGHT)
{
int width = tabPane.getBounds().width - insets.right
- tabAreaInsets.right;
int adjustment;
if (i == 0)
adjustment = width - maxTabWidth;
else
adjustment = width - (runCount - i + 1) * maxTabWidth
+ (runCount - i) * tabRunOverlay;
for (int j = first; j <= last; j++)
rects[j].x = adjustment;
}
}
padSelectedTab(tabPlacement, tabPane.getSelectedIndex());
}
/**
* This method is called when the JTabbedPane is laid out in
* WRAP_TAB_LAYOUT. It calls calculateLayoutInfo to find the positions
* of all its components.
*
* @param parent The Container to lay out.
*/
public void layoutContainer(Container parent)
{
calculateLayoutInfo();
}
/**
* This method returns the minimum layout size for the given container.
*
* @param parent The container that is being sized.
*
* @return The minimum size.
*/
public Dimension minimumLayoutSize(Container parent)
{
return calculateSize(false);
}
// If there is more free space in an adjacent run AND the tab in the run can fit in the
// adjacent run, move it. This method is not perfect, it is merely an approximation.
// If you play around with Sun's JTabbedPane, you'll see that
// it does do some pretty strange things with regards to not moving tabs
// that should be moved.
// start = the x position where the tabs will begin
// max = the maximum position of where the tabs can go to (tabAreaInsets.left + the width of the tab area)
/**
* This method tries to "even out" the number of tabs in each run based on
* their widths.
*
* @param tabPlacement The JTabbedPane's tab placement.
* @param tabCount The number of tabs.
* @param start The x position where the tabs will begin.
* @param max The maximum x position where the tab can run to.
*/
protected void normalizeTabRuns(int tabPlacement, int tabCount, int start,
int max)
{
Insets tabAreaInsets = getTabAreaInsets(tabPlacement);
if (tabPlacement == SwingUtilities.TOP
|| tabPlacement == SwingUtilities.BOTTOM)
{
// We should only do this for runCount - 1, cause we can only shift that many times between
// runs.
for (int i = 1; i < runCount; i++)
{
Rectangle currRun = rects[lastTabInRun(tabCount, i)];
Rectangle nextRun = rects[lastTabInRun(tabCount, getNextTabRun(i))];
int spaceInCurr = currRun.x + currRun.width;
int spaceInNext = nextRun.x + nextRun.width;
int diffNow = spaceInCurr - spaceInNext;
int diffLater = (spaceInCurr - currRun.width)
- (spaceInNext + currRun.width);
while (Math.abs(diffLater) < Math.abs(diffNow)
&& spaceInNext + currRun.width < max)
{
tabRuns[i]--;
spaceInNext += currRun.width;
spaceInCurr -= currRun.width;
currRun = rects[lastTabInRun(tabCount, i)];
diffNow = spaceInCurr - spaceInNext;
diffLater = (spaceInCurr - currRun.width)
- (spaceInNext + currRun.width);
}
// Fix the bounds.
int first = lastTabInRun(tabCount, i) + 1;
int last = lastTabInRun(tabCount, getNextTabRun(i));
int currX = tabAreaInsets.left;
for (int j = first; j <= last; j++)
{
rects[j].x = currX;
currX += rects[j].width;
}
}
}
else
{
for (int i = 1; i < runCount; i++)
{
Rectangle currRun = rects[lastTabInRun(tabCount, i)];
Rectangle nextRun = rects[lastTabInRun(tabCount, getNextTabRun(i))];
int spaceInCurr = currRun.y + currRun.height;
int spaceInNext = nextRun.y + nextRun.height;
int diffNow = spaceInCurr - spaceInNext;
int diffLater = (spaceInCurr - currRun.height)
- (spaceInNext + currRun.height);
while (Math.abs(diffLater) < Math.abs(diffNow)
&& spaceInNext + currRun.height < max)
{
tabRuns[i]--;
spaceInNext += currRun.height;
spaceInCurr -= currRun.height;
currRun = rects[lastTabInRun(tabCount, i)];
diffNow = spaceInCurr - spaceInNext;
diffLater = (spaceInCurr - currRun.height)
- (spaceInNext + currRun.height);
}
int first = lastTabInRun(tabCount, i) + 1;
int last = lastTabInRun(tabCount, getNextTabRun(i));
int currY = tabAreaInsets.top;
for (int j = first; j <= last; j++)
{
rects[j].y = currY;
currY += rects[j].height;
}
}
}
}
/**
* This method pads the tab at the selected index by the selected tab pad
* insets (so that it looks larger).
*
* @param tabPlacement The placement of the tabs.
* @param selectedIndex The selected index.
*/
protected void padSelectedTab(int tabPlacement, int selectedIndex)
{
Insets insets = getSelectedTabPadInsets(tabPlacement);
rects[selectedIndex].x -= insets.left;
rects[selectedIndex].y -= insets.top;
rects[selectedIndex].width += insets.left + insets.right;
rects[selectedIndex].height += insets.top + insets.bottom;
}
// If the tabs on the run don't fill the width of the window, make it fit now.
// start = starting index of the run
// end = last index of the run
// max = tabAreaInsets.left + width (or equivalent)
// assert start <= end.
/**
* This method makes each tab in the run larger so that the tabs expand
* to fill the runs width/height (depending on tabPlacement).
*
* @param tabPlacement The placement of the tabs.
* @param start The index of the first tab.
* @param end The last index of the tab
* @param max The amount of space in the run (width for TOP and BOTTOM
* tabPlacement).
*/
protected void padTabRun(int tabPlacement, int start, int end, int max)
{
if (tabPlacement == SwingConstants.TOP
|| tabPlacement == SwingConstants.BOTTOM)
{
int runWidth = rects[end].x + rects[end].width;
int spaceRemaining = max - runWidth;
int numTabs = end - start + 1;
// now divvy up the space.
int spaceAllocated = spaceRemaining / numTabs;
int currX = rects[start].x;
for (int i = start; i <= end; i++)
{
rects[i].x = currX;
rects[i].width += spaceAllocated;
currX += rects[i].width;
// This is used because since the spaceAllocated
// variable is an int, it rounds down. Sometimes,
// we don't fill an entire row, so we make it do
// so now.
if (i == end && rects[i].x + rects[i].width != max)
rects[i].width = max - rects[i].x;
}
}
else
{
int runHeight = rects[end].y + rects[end].height;
int spaceRemaining = max - runHeight;
int numTabs = end - start + 1;
int spaceAllocated = spaceRemaining / numTabs;
int currY = rects[start].y;
for (int i = start; i <= end; i++)
{
rects[i].y = currY;
rects[i].height += spaceAllocated;
currY += rects[i].height;
if (i == end && rects[i].y + rects[i].height != max)
rects[i].height = max - rects[i].y;
}
}
}
/**
* This method returns the preferred layout size for the given container.
*
* @param parent The container to size.
*
* @return The preferred layout size.
*/
public Dimension preferredLayoutSize(Container parent)
{
return calculateSize(false);
}
/**
* This method returns the preferred tab height given a tabPlacement and
* width.
*
* @param tabPlacement The JTabbedPane's tab placement.
* @param width The expected width.
*
* @return The preferred tab area height.
*/
protected int preferredTabAreaHeight(int tabPlacement, int width)
{
if (tabPane.getTabCount() == 0)
return calculateTabAreaHeight(tabPlacement, 0, 0);
int runs = 0;
int runWidth = 0;
int tabWidth = 0;
FontMetrics fm = getFontMetrics();
Insets tabAreaInsets = getTabAreaInsets(tabPlacement);
Insets insets = tabPane.getInsets();
// Only interested in width, this is a messed up rectangle now.
width -= tabAreaInsets.left + tabAreaInsets.right + insets.left
+ insets.right;
// The reason why we can't use runCount:
// This method is only called to calculate the size request
// for the tabbedPane. However, this size request is dependent on
// our desired width. We need to find out what the height would
// be IF we got our desired width.
for (int i = 0; i < tabPane.getTabCount(); i++)
{
tabWidth = calculateTabWidth(tabPlacement, i, fm);
if (runWidth + tabWidth > width)
{
runWidth = tabWidth;
runs++;
}
else
runWidth += tabWidth;
}
runs++;
int maxTabHeight = calculateMaxTabHeight(tabPlacement);
int tabAreaHeight = calculateTabAreaHeight(tabPlacement, runs,
maxTabHeight);
return tabAreaHeight;
}
/**
* This method calculates the preferred tab area width given a tab
* placement and height.
*
* @param tabPlacement The JTabbedPane's tab placement.
* @param height The expected height.
*
* @return The preferred tab area width.
*/
protected int preferredTabAreaWidth(int tabPlacement, int height)
{
if (tabPane.getTabCount() == 0)
return calculateTabAreaHeight(tabPlacement, 0, 0);
int runs = 0;
int runHeight = 0;
int tabHeight = 0;
FontMetrics fm = getFontMetrics();
Insets tabAreaInsets = getTabAreaInsets(tabPlacement);
Insets insets = tabPane.getInsets();
height -= tabAreaInsets.top + tabAreaInsets.bottom + insets.top
+ insets.bottom;
int fontHeight = fm.getHeight();
for (int i = 0; i < tabPane.getTabCount(); i++)
{
tabHeight = calculateTabHeight(tabPlacement, i, fontHeight);
if (runHeight + tabHeight > height)
{
runHeight = tabHeight;
runs++;
}
else
runHeight += tabHeight;
}
runs++;
int maxTabWidth = calculateMaxTabWidth(tabPlacement);
int tabAreaWidth = calculateTabAreaWidth(tabPlacement, runs, maxTabWidth);
return tabAreaWidth;
}
/**
* This method rotates the places each run in the correct place the
* tabRuns array. See the comment for tabRuns for how the runs are placed
* in the array.
*
* @param tabPlacement The JTabbedPane's tab placement.
* @param selectedRun The run the current selection is in.
*/
protected void rotateTabRuns(int tabPlacement, int selectedRun)
{
if (selectedRun == 1 || selectedRun == -1)
return;
int[] newTabRuns = new int[tabRuns.length];
int currentRun = selectedRun;
int i = 1;
do
{
newTabRuns[i] = tabRuns[currentRun];
currentRun = getNextTabRun(currentRun);
i++;
}
while (i < runCount);
if (runCount > 1)
newTabRuns[0] = tabRuns[currentRun];
tabRuns = newTabRuns;
BasicTabbedPaneUI.this.selectedRun = 1;
}
/**
* This method is called when a component is removed from the
* JTabbedPane.
*
* @param comp The component removed.
*/
public void removeLayoutComponent(Component comp)
{
// Do nothing.
}
}
/**
* This class acts as the LayoutManager for the JTabbedPane in
* SCROLL_TAB_MODE.
*/
private class TabbedPaneScrollLayout extends TabbedPaneLayout
{
/**
* This method returns the preferred layout size for the given container.
*
* @param parent The container to calculate a size for.
*
* @return The preferred layout size.
*/
public Dimension preferredLayoutSize(Container parent)
{
return super.calculateSize(true);
}
/**
* This method returns the minimum layout size for the given container.
*
* @param parent The container to calculate a size for.
*
* @return The minimum layout size.
*/
public Dimension minimumLayoutSize(Container parent)
{
return super.calculateSize(true);
}
/**
* This method calculates the tab area height given a desired width.
*
* @param tabPlacement The JTabbedPane's tab placement.
* @param width The expected width.
*
* @return The tab area height given the width.
*/
protected int preferredTabAreaHeight(int tabPlacement, int width)
{
if (tabPane.getTabCount() == 0)
return calculateTabAreaHeight(tabPlacement, 0, 0);
int runs = 1;
int maxTabHeight = calculateMaxTabHeight(tabPlacement);
int tabAreaHeight = calculateTabAreaHeight(tabPlacement, runs,
maxTabHeight);
return tabAreaHeight;
}
/**
* This method calculates the tab area width given a desired height.
*
* @param tabPlacement The JTabbedPane's tab placement.
* @param height The expected height.
*
* @return The tab area width given the height.
*/
protected int preferredTabAreaWidth(int tabPlacement, int height)
{
if (tabPane.getTabCount() == 0)
return calculateTabAreaHeight(tabPlacement, 0, 0);
int runs = 1;
int maxTabWidth = calculateMaxTabWidth(tabPlacement);
int tabAreaWidth = calculateTabAreaWidth(tabPlacement, runs, maxTabWidth);
return tabAreaWidth;
}
/**
* This method is called to calculate the tab rectangles. This method
* will calculate the size and position of all rectangles (taking into
* account which ones should be in which tab run). It will pad them and
* normalize them as necessary.
*
* @param tabPlacement The JTabbedPane's tab placement.
* @param tabCount The number of tabs.
*/
protected void calculateTabRects(int tabPlacement, int tabCount)
{
if (tabCount == 0)
return;
assureRectsCreated(tabCount);
FontMetrics fm = getFontMetrics();
SwingUtilities.calculateInnerArea(tabPane, calcRect);
Insets tabAreaInsets = getTabAreaInsets(tabPlacement);
Insets insets = tabPane.getInsets();
int max = 0;
int runs = 1;
int start = 0;
int top = 0;
if (tabPlacement == SwingConstants.TOP
|| tabPlacement == SwingConstants.BOTTOM)
{
int maxHeight = calculateMaxTabHeight(tabPlacement);
calcRect.width -= tabAreaInsets.left + tabAreaInsets.right;
max = calcRect.width + tabAreaInsets.left + insets.left;
start = tabAreaInsets.left + insets.left;
int width = 0;
int runWidth = start;
top = insets.top + tabAreaInsets.top;
for (int i = 0; i < tabCount; i++)
{
width = calculateTabWidth(tabPlacement, i, fm);
rects[i] = new Rectangle(runWidth, top, width, maxHeight);
runWidth += width;
}
tabAreaRect.width = tabPane.getWidth() - insets.left - insets.right;
tabAreaRect.height = runs * maxTabHeight
- (runs - 1) * tabRunOverlay
+ tabAreaInsets.top + tabAreaInsets.bottom;
contentRect.width = tabAreaRect.width;
contentRect.height = tabPane.getHeight() - insets.top
- insets.bottom - tabAreaRect.height;
contentRect.x = insets.left;
tabAreaRect.x = insets.left;
if (tabPlacement == SwingConstants.BOTTOM)
{
contentRect.y = insets.top;
tabAreaRect.y = contentRect.y + contentRect.height;
}
else
{
tabAreaRect.y = insets.top;
contentRect.y = tabAreaRect.y + tabAreaRect.height;
}
}
else
{
int maxWidth = calculateMaxTabWidth(tabPlacement);
calcRect.height -= tabAreaInsets.top + tabAreaInsets.bottom;
max = calcRect.height + tabAreaInsets.top;
int height = 0;
start = tabAreaInsets.top + insets.top;
int runHeight = start;
int fontHeight = fm.getHeight();
top = insets.left + tabAreaInsets.left;
for (int i = 0; i < tabCount; i++)
{
height = calculateTabHeight(tabPlacement, i, fontHeight);
rects[i] = new Rectangle(top, runHeight, maxWidth, height);
runHeight += height;
}
tabAreaRect.width = runs * maxTabWidth - (runs - 1) * tabRunOverlay
+ tabAreaInsets.left + tabAreaInsets.right;
tabAreaRect.height = tabPane.getHeight() - insets.top
- insets.bottom;
tabAreaRect.y = insets.top;
contentRect.width = tabPane.getWidth() - insets.left - insets.right
- tabAreaRect.width;
contentRect.height = tabAreaRect.height;
contentRect.y = insets.top;
if (tabPlacement == SwingConstants.LEFT)
{
tabAreaRect.x = insets.left;
contentRect.x = tabAreaRect.x + tabAreaRect.width;
}
else
{
contentRect.x = insets.left;
tabAreaRect.x = contentRect.x + contentRect.width;
}
}
runCount = runs;
padSelectedTab(tabPlacement, tabPane.getSelectedIndex());
}
/**
* This method is called when the JTabbedPane is laid out in
* SCROLL_TAB_LAYOUT. It finds the position for all components in the
* JTabbedPane.
*
* @param pane The JTabbedPane to be laid out.
*/
public void layoutContainer(Container pane)
{
super.layoutContainer(pane);
int tabCount = tabPane.getTabCount();
if (tabCount == 0)
return;
int tabPlacement = tabPane.getTabPlacement();
incrButton.hide();
decrButton.hide();
if (tabPlacement == SwingConstants.TOP
|| tabPlacement == SwingConstants.BOTTOM)
{
if (tabAreaRect.x + tabAreaRect.width < rects[tabCount - 1].x
+ rects[tabCount - 1].width)
{
Dimension incrDims = incrButton.getPreferredSize();
Dimension decrDims = decrButton.getPreferredSize();
decrButton.setBounds(tabAreaRect.x + tabAreaRect.width
- incrDims.width - decrDims.width,
tabAreaRect.y, decrDims.width,
tabAreaRect.height);
incrButton.setBounds(tabAreaRect.x + tabAreaRect.width
- incrDims.width, tabAreaRect.y,
decrDims.width, tabAreaRect.height);
tabAreaRect.width -= decrDims.width + incrDims.width;
incrButton.show();
decrButton.show();
}
}
if (tabPlacement == SwingConstants.LEFT
|| tabPlacement == SwingConstants.RIGHT)
{
if (tabAreaRect.y + tabAreaRect.height < rects[tabCount - 1].y
+ rects[tabCount - 1].height)
{
Dimension incrDims = incrButton.getPreferredSize();
Dimension decrDims = decrButton.getPreferredSize();
decrButton.setBounds(tabAreaRect.x,
tabAreaRect.y + tabAreaRect.height
- incrDims.height - decrDims.height,
tabAreaRect.width, decrDims.height);
incrButton.setBounds(tabAreaRect.x,
tabAreaRect.y + tabAreaRect.height
- incrDims.height, tabAreaRect.width,
incrDims.height);
tabAreaRect.height -= decrDims.height + incrDims.height;
incrButton.show();
decrButton.show();
}
}
viewport.setBounds(tabAreaRect.x, tabAreaRect.y, tabAreaRect.width,
tabAreaRect.height);
int tabC = tabPane.getTabCount() - 1;
if (tabCount > 0)
{
int w = Math.max(rects[tabC].width + rects[tabC].x, tabAreaRect.width);
int h = Math.max(rects[tabC].height, tabAreaRect.height);
Point p = findPointForIndex(currentScrollLocation);
// we want to cover that entire space so that borders that run under
// the tab area don't show up when we move the viewport around.
panel.setBounds(0, 0, w + p.x, h + p.y);
}
viewport.setViewPosition(findPointForIndex(currentScrollLocation));
}
}
/**
* This class handles ChangeEvents from the JTabbedPane.
*/
protected class TabSelectionHandler implements ChangeListener
{
/**
* This method is called whenever a ChangeEvent is fired from the
* JTabbedPane.
*
* @param e The ChangeEvent fired.
*/
public void stateChanged(ChangeEvent e)
{
selectedRun = getRunForTab(tabPane.getTabCount(),
tabPane.getSelectedIndex());
tabPane.layout();
tabPane.repaint();
}
}
/**
* This helper class is a JPanel that fits inside the ScrollViewport. This
* panel's sole job is to paint the tab rectangles inside the viewport so
* that it's clipped correctly.
*/
private class ScrollingPanel extends JPanel
{
/**
* This is a private UI class for our panel.
*/
private class ScrollingPanelUI extends BasicPanelUI
{
/**
* This method overrides the default paint method. It paints the tab
* rectangles for the JTabbedPane in the panel.
*
* @param g The Graphics object to paint with.
* @param c The JComponent to paint.
*/
public void paint(Graphics g, JComponent c)
{
paintTabArea(g, tabPane.getTabPlacement(), tabPane.getSelectedIndex());
}
}
/**
* This method overrides the updateUI method. It makes the default UI for
* this ScrollingPanel to be a ScrollingPanelUI.
*/
public void updateUI()
{
setUI((PanelUI) new ScrollingPanelUI());
}
}
/**
* This is a helper class that paints the panel that paints tabs. This
* custom JViewport is used so that the tabs painted in the panel will be
* clipped. This class implements UIResource so tabs are not added when
* this objects of this class are added to the JTabbedPane.
*/
private class ScrollingViewport extends JViewport implements UIResource
{
/**
* This method is temporary until the viewport layouts are implemented.
* Need it because the flow layout it currently moves our panel around.
*
* @param g The graphics object to paint with.
*/
public void paint(Graphics g)
{
// FIXME: Remove this as well.
int tabC = tabPane.getTabCount() - 1;
if (tabC + 1 > 0)
{
int w = Math.max(rects[tabC].width + rects[tabC].x, tabAreaRect.width);
int h = Math.max(rects[tabC].height, tabAreaRect.height);
Point p = findPointForIndex(currentScrollLocation);
// we want to cover that entire space so that borders that run under
// the tab area don't show up when we move the viewport around.
panel.setBounds(0, 0, w + p.x, h + p.y);
}
// FIXME: Remove when ViewportLayout is done.
setViewPosition(findPointForIndex(currentScrollLocation));
super.paint(g);
}
}
/**
* This is a helper class that implements UIResource so it is not added as a
* tab when an object of this class is added to the JTabbedPane.
*/
private class ScrollingButton extends BasicArrowButton implements UIResource
{
/**
* Creates a ScrollingButton given the direction.
*
* @param dir The direction to point in.
*/
public ScrollingButton(int dir)
{
super(dir);
}
}
/** The button that increments the current scroll location. */
private transient ScrollingButton incrButton;
/** The button that decrements the current scroll location. */
private transient ScrollingButton decrButton;
/** The viewport used to display the tabs. */
private transient ScrollingViewport viewport;
/** The panel inside the viewport that paints the tabs. */
private transient ScrollingPanel panel;
/** The starting visible tab in the run in SCROLL_TAB_MODE. */
private transient int currentScrollLocation;
/** A reusable rectangle. */
protected Rectangle calcRect;
/** An array of Rectangles keeping track of the tabs' area and position. */
protected Rectangle[] rects;
/** The insets around the content area. */
protected Insets contentBorderInsets;
/** The extra insets around the selected tab. */
protected Insets selectedTabPadInsets;
/** The insets around the tab area. */
protected Insets tabAreaInsets;
/** The insets around each and every tab. */
protected Insets tabInsets;
/**
* The outer bottom and right edge color for both the tab and content
* border.
*/
protected Color darkShadow;
/** The color of the focus outline on the selected tab. */
protected Color focus;
/** FIXME: find a use for this. */
protected Color highlight;
/** The top and left edge color for both the tab and content border. */
protected Color lightHighlight;
/** The inner bottom and right edge color for the tab and content border. */
protected Color shadow;
/** The maximum tab height. */
protected int maxTabHeight;
/** The maximum tab width. */
protected int maxTabWidth;
/** The number of runs in the JTabbedPane. */
protected int runCount;
/** The index of the run that the selected index is in. */
protected int selectedRun;
/** The amount of space each run overlaps the previous by. */
protected int tabRunOverlay;
/** The gap between text and label */
protected int textIconGap;
// Keeps track of tab runs.
// The organization of this array is as follows (lots of experimentation to
// figure this out)
// index 0 = furthest away from the component area (aka outer run)
// index 1 = closest to component area (aka selected run)
// index > 1 = listed in order leading from selected run to outer run.
// each int in the array is the tab index + 1 (counting starts at 1)
// for the last tab in the run. (same as the rects array)
/** This array keeps track of which tabs are in which run. See above. */
protected int[] tabRuns;
/** Deprecated. This is the keystroke for moving down. */
protected KeyStroke downKey;
/** Deprecated. This is the keystroke for moving left. */
protected KeyStroke leftKey;
/** Deprecated. This is the keystroke for moving right. */
protected KeyStroke rightKey;
/** Deprecated. This is the keystroke for moving up. */
protected KeyStroke upKey;
/** The listener that listens for focus events. */
protected FocusListener focusListener;
/** The listener that listens for mouse events. */
protected MouseListener mouseListener;
/** The listener that listens for property change events. */
protected PropertyChangeListener propertyChangeListener;
/** The listener that listens for change events. */
protected ChangeListener tabChangeListener;
/** The tab pane that this UI paints. */
protected JTabbedPane tabPane;
/** The current layout manager for the tabPane. */
private transient LayoutManager layoutManager;
/** The rectangle that describes the tab area's position and size. */
private transient Rectangle tabAreaRect;
/** The rectangle that describes the content area's position and size. */
private transient Rectangle contentRect;
/**
* Creates a new BasicTabbedPaneUI object.
*/
public BasicTabbedPaneUI()
{
super();
}
/**
* This method creates a ScrollingButton that points in the appropriate
* direction for an increasing button.
*
* @return The increase ScrollingButton.
*/
private ScrollingButton createIncreaseButton()
{
if (incrButton == null)
incrButton = new ScrollingButton(SwingConstants.NORTH);
if (tabPane.getTabPlacement() == SwingConstants.TOP
|| tabPane.getTabPlacement() == SwingConstants.BOTTOM)
incrButton.setDirection(SwingConstants.EAST);
else
incrButton.setDirection(SwingConstants.SOUTH);
return incrButton;
}
/**
* This method creates a ScrollingButton that points in the appropriate
* direction for a decreasing button.
*
* @return The decrease ScrollingButton.
*/
private ScrollingButton createDecreaseButton()
{
if (decrButton == null)
decrButton = new ScrollingButton(SwingConstants.SOUTH);
if (tabPane.getTabPlacement() == SwingConstants.TOP
|| tabPane.getTabPlacement() == SwingConstants.BOTTOM)
decrButton.setDirection(SwingConstants.WEST);
else
decrButton.setDirection(SwingConstants.NORTH);
return decrButton;
}
/**
* This method finds the point to set the view position at given the index
* of a tab. The tab will be the first visible tab in the run.
*
* @param index The index of the first visible tab.
*
* @return The position of the first visible tab.
*/
private Point findPointForIndex(int index)
{
int tabPlacement = tabPane.getTabPlacement();
int selectedIndex = tabPane.getSelectedIndex();
Insets insets = getSelectedTabPadInsets(tabPlacement);
int w = 0;
int h = 0;
if (tabPlacement == TOP || tabPlacement == BOTTOM)
{
if (index > 0)
{
w += rects[index - 1].x + rects[index - 1].width;
if (index > selectedIndex)
w -= insets.left + insets.right;
}
}
else
{
if (index > 0)
{
h += rects[index - 1].y + rects[index - 1].height;
if (index > selectedIndex)
h -= insets.top + insets.bottom;
}
}
Point p = new Point(w, h);
return p;
}
/**
* This method creates a new BasicTabbedPaneUI.
*
* @param c The JComponent to create a UI for.
*
* @return A new BasicTabbedPaneUI.
*/
public static ComponentUI createUI(JComponent c)
{
return new BasicTabbedPaneUI();
}
/**
* This method installs the UI for the given JComponent.
*
* @param c The JComponent to install the UI for.
*/
public void installUI(JComponent c)
{
super.installUI(c);
if (c instanceof JTabbedPane)
{
tabPane = (JTabbedPane) c;
installComponents();
installDefaults();
installListeners();
installKeyboardActions();
layoutManager = createLayoutManager();
tabPane.setLayout(layoutManager);
tabPane.layout();
}
}
/**
* This method uninstalls the UI for the given JComponent.
*
* @param c The JComponent to uninstall the UI for.
*/
public void uninstallUI(JComponent c)
{
layoutManager = null;
uninstallKeyboardActions();
uninstallListeners();
uninstallDefaults();
uninstallComponents();
tabPane = null;
}
/**
* This method creates the appropriate layout manager for the JTabbedPane's
* current tab layout policy. If the tab layout policy is
* SCROLL_TAB_LAYOUT, then all the associated components that need to be
* created will be done so now.
*
* @return A layout manager given the tab layout policy.
*/
public LayoutManager createLayoutManager()
{
if (tabPane.getTabLayoutPolicy() == JTabbedPane.WRAP_TAB_LAYOUT)
return new TabbedPaneLayout();
else
{
incrButton = createIncreaseButton();
decrButton = createDecreaseButton();
viewport = new ScrollingViewport();
panel = new ScrollingPanel();
viewport.setView(panel);
tabPane.add(incrButton);
tabPane.add(decrButton);
tabPane.add(viewport);
currentScrollLocation = 0;
decrButton.setEnabled(false);
panel.addMouseListener(mouseListener);
incrButton.addMouseListener(mouseListener);
decrButton.addMouseListener(mouseListener);
viewport.setBackground(Color.LIGHT_GRAY);
return new TabbedPaneScrollLayout();
}
}
/**
* This method installs components for this JTabbedPane.
*/
protected void installComponents()
{
// Nothing to be done.
}
/**
* This method uninstalls components for this JTabbedPane.
*/
protected void uninstallComponents()
{
// Nothing to be done.
}
/**
* This method installs defaults for the Look and Feel.
*/
protected void installDefaults()
{
UIDefaults defaults = UIManager.getLookAndFeelDefaults();
tabPane.setFont(defaults.getFont("TabbedPane.font"));
tabPane.setForeground(defaults.getColor("TabbedPane.foreground"));
tabPane.setBackground(defaults.getColor("TabbedPane.background"));
highlight = defaults.getColor("TabbedPane.highlight");
lightHighlight = defaults.getColor("TabbedPane.lightHighlight");
shadow = defaults.getColor("TabbedPane.shadow");
darkShadow = defaults.getColor("TabbedPane.darkShadow");
focus = defaults.getColor("TabbedPane.focus");
textIconGap = defaults.getInt("TabbedPane.textIconGap");
tabRunOverlay = defaults.getInt("TabbedPane.tabRunOverlay");
tabInsets = defaults.getInsets("TabbedPane.tabbedPaneTabInsets");
selectedTabPadInsets = defaults.getInsets("TabbedPane.tabbedPaneTabPadInsets");
tabAreaInsets = defaults.getInsets("TabbedPane.tabbedPaneTabAreaInsets");
contentBorderInsets = defaults.getInsets("TabbedPane.tabbedPaneContentBorderInsets");
calcRect = new Rectangle();
tabRuns = new int[10];
tabAreaRect = new Rectangle();
contentRect = new Rectangle();
}
/**
* This method uninstalls defaults for the Look and Feel.
*/
protected void uninstallDefaults()
{
calcRect = null;
tabAreaRect = null;
contentRect = null;
tabRuns = null;
contentBorderInsets = null;
tabAreaInsets = null;
selectedTabPadInsets = null;
tabInsets = null;
focus = null;
darkShadow = null;
shadow = null;
lightHighlight = null;
highlight = null;
tabPane.setBackground(null);
tabPane.setForeground(null);
tabPane.setFont(null);
}
/**
* This method creates and installs the listeners for this UI.
*/
protected void installListeners()
{
mouseListener = createMouseListener();
tabChangeListener = createChangeListener();
propertyChangeListener = createPropertyChangeListener();
focusListener = createFocusListener();
tabPane.addMouseListener(mouseListener);
tabPane.addChangeListener(tabChangeListener);
tabPane.addPropertyChangeListener(propertyChangeListener);
tabPane.addFocusListener(focusListener);
}
/**
* This method removes and nulls the listeners for this UI.
*/
protected void uninstallListeners()
{
tabPane.removeFocusListener(focusListener);
tabPane.removePropertyChangeListener(propertyChangeListener);
tabPane.removeChangeListener(tabChangeListener);
tabPane.removeMouseListener(mouseListener);
focusListener = null;
propertyChangeListener = null;
tabChangeListener = null;
mouseListener = null;
}
/**
* This method creates a new MouseListener.
*
* @return A new MouseListener.
*/
protected MouseListener createMouseListener()
{
return new MouseHandler();
}
/**
* This method creates a new FocusListener.
*
* @return A new FocusListener.
*/
protected FocusListener createFocusListener()
{
return new FocusHandler();
}
/**
* This method creates a new ChangeListener.
*
* @return A new ChangeListener.
*/
protected ChangeListener createChangeListener()
{
return new TabSelectionHandler();
}
/**
* This method creates a new PropertyChangeListener.
*
* @return A new PropertyChangeListener.
*/
protected PropertyChangeListener createPropertyChangeListener()
{
return new PropertyChangeHandler();
}
/**
* This method installs keyboard actions for the JTabbedPane.
*/
protected void installKeyboardActions()
{
// FIXME: Implement.
}
/**
* This method uninstalls keyboard actions for the JTabbedPane.
*/
protected void uninstallKeyboardActions()
{
// FIXME: Implement.
}
/**
* This method returns the preferred size of the JTabbedPane.
*
* @param c The JComponent to find a size for.
*
* @return The preferred size.
*/
public Dimension getPreferredSize(JComponent c)
{
return layoutManager.preferredLayoutSize(tabPane);
}
/**
* This method returns the minimum size of the JTabbedPane.
*
* @param c The JComponent to find a size for.
*
* @return The minimum size.
*/
public Dimension getMinimumSize(JComponent c)
{
return layoutManager.minimumLayoutSize(tabPane);
}
/**
* This method returns the maximum size of the JTabbedPane.
*
* @param c The JComponent to find a size for.
*
* @return The maximum size.
*/
public Dimension getMaximumSize(JComponent c)
{
return getPreferredSize(c);
}
/**
* This method paints the JTabbedPane.
*
* @param g The Graphics object to paint with.
* @param c The JComponent to paint.
*/
public void paint(Graphics g, JComponent c)
{
if (tabPane.getTabCount() == 0)
return;
if (tabPane.getTabLayoutPolicy() == JTabbedPane.WRAP_TAB_LAYOUT)
paintTabArea(g, tabPane.getTabPlacement(), tabPane.getSelectedIndex());
paintContentBorder(g, tabPane.getTabPlacement(), tabPane.getSelectedIndex());
}
/**
* This method paints the tab area. This includes painting the rectangles
* that make up the tabs.
*
* @param g The Graphics object to paint with.
* @param tabPlacement The JTabbedPane's tab placement.
* @param selectedIndex The selected index.
*/
protected void paintTabArea(Graphics g, int tabPlacement, int selectedIndex)
{
Rectangle ir = new Rectangle();
Rectangle tr = new Rectangle();
// Please note: the ordering of the painting is important.
// we WANT to paint the outermost run first and then work our way in.
int tabCount = tabPane.getTabCount();
int currRun = 1;
if (tabCount < 1)
return;
if (runCount > 1)
currRun = 0;
for (int i = 0; i < runCount; i++)
{
int first = lastTabInRun(tabCount, getPreviousTabRun(currRun)) + 1;
if (first == tabCount)
first = 0;
int last = lastTabInRun(tabCount, currRun);
for (int j = first; j <= last; j++)
{
if (j != selectedIndex)
paintTab(g, tabPlacement, rects, j, ir, tr);
}
currRun = getNextTabRun(currRun);
}
paintTab(g, tabPlacement, rects, selectedIndex, ir, tr);
}
/**
* This method paints an individual tab.
*
* @param g The Graphics object to paint with.
* @param tabPlacement The JTabbedPane's tab placement.
* @param rects The array of rectangles that keep the size and position of
* the tabs.
* @param tabIndex The tab index to paint.
* @param iconRect The rectangle to use for the icon.
* @param textRect The rectangle to use for the text.
*/
protected void paintTab(Graphics g, int tabPlacement, Rectangle[] rects,
int tabIndex, Rectangle iconRect, Rectangle textRect)
{
FontMetrics fm = getFontMetrics();
Icon icon = getIconForTab(tabIndex);
String title = tabPane.getTitleAt(tabIndex);
boolean isSelected = tabIndex == tabPane.getSelectedIndex();
calcRect = getTabBounds(tabPane, tabIndex);
int x = calcRect.x;
int y = calcRect.y;
int w = calcRect.width;
int h = calcRect.height;
if (getRunForTab(tabPane.getTabCount(), tabIndex) == 1)
{
Insets insets = getTabAreaInsets(tabPlacement);
switch (tabPlacement)
{
case TOP:
h += insets.bottom;
break;
case LEFT:
w += insets.right;
break;
case BOTTOM:
y -= insets.top;
h += insets.top;
break;
case RIGHT:
x -= insets.left;
w += insets.left;
break;
}
}
layoutLabel(tabPlacement, fm, tabIndex, title, icon, calcRect, iconRect,
textRect, isSelected);
paintTabBackground(g, tabPlacement, tabIndex, x, y, w, h, isSelected);
paintTabBorder(g, tabPlacement, tabIndex, x, y, w, h, isSelected);
// FIXME: Paint little folding corner and jagged edge clipped tab.
if (icon != null)
paintIcon(g, tabPlacement, tabIndex, icon, iconRect, isSelected);
if (title == null || ! title.equals(""))
paintText(g, tabPlacement, tabPane.getFont(), fm, tabIndex, title,
textRect, isSelected);
}
/**
* This method lays out the tab and finds the location to paint the icon
* and text.
*
* @param tabPlacement The JTabbedPane's tab placement.
* @param metrics The font metrics for the font to paint with.
* @param tabIndex The tab index to paint.
* @param title The string painted.
* @param icon The icon painted.
* @param tabRect The tab bounds.
* @param iconRect The calculated icon bounds.
* @param textRect The calculated text bounds.
* @param isSelected Whether this tab is selected.
*/
protected void layoutLabel(int tabPlacement, FontMetrics metrics,
int tabIndex, String title, Icon icon,
Rectangle tabRect, Rectangle iconRect,
Rectangle textRect, boolean isSelected)
{
SwingUtilities.layoutCompoundLabel(metrics, title, icon,
SwingConstants.CENTER,
SwingConstants.CENTER,
SwingConstants.CENTER,
SwingConstants.CENTER, tabRect,
iconRect, textRect, textIconGap);
int shiftX = getTabLabelShiftX(tabPlacement, tabIndex, isSelected);
int shiftY = getTabLabelShiftY(tabPlacement, tabIndex, isSelected);
iconRect.x += shiftX;
iconRect.y += shiftY;
textRect.x += shiftX;
textRect.y += shiftY;
}
/**
* This method paints the icon.
*
* @param g The Graphics object to paint.
* @param tabPlacement The JTabbedPane's tab placement.
* @param tabIndex The tab index to paint.
* @param icon The icon to paint.
* @param iconRect The bounds of the icon.
* @param isSelected Whether this tab is selected.
*/
protected void paintIcon(Graphics g, int tabPlacement, int tabIndex,
Icon icon, Rectangle iconRect, boolean isSelected)
{
icon.paintIcon(tabPane, g, iconRect.x, iconRect.y);
}
/**
* This method paints the text for the given tab.
*
* @param g The Graphics object to paint with.
* @param tabPlacement The JTabbedPane's tab placement.
* @param font The font to paint with.
* @param metrics The fontmetrics of the given font.
* @param tabIndex The tab index.
* @param title The string to paint.
* @param textRect The bounds of the string.
* @param isSelected Whether this tab is selected.
*/
protected void paintText(Graphics g, int tabPlacement, Font font,
FontMetrics metrics, int tabIndex, String title,
Rectangle textRect, boolean isSelected)
{
View textView = getTextViewForTab(tabIndex);
if (textView != null)
{
textView.paint(g, textRect);
return;
}
Color fg = tabPane.getForegroundAt(tabIndex);
if (fg == null)
fg = tabPane.getForeground();
Color bg = tabPane.getBackgroundAt(tabIndex);
if (bg == null)
bg = tabPane.getBackground();
Color saved_color = g.getColor();
Font f = g.getFont();
g.setFont(font);
if (tabPane.isEnabledAt(tabIndex))
{
g.setColor(fg);
int mnemIndex = tabPane.getDisplayedMnemonicIndexAt(tabIndex);
if (mnemIndex != -1)
BasicGraphicsUtils.drawStringUnderlineCharAt(g, title, mnemIndex,
textRect.x,
textRect.y
+ metrics.getAscent());
else
g.drawString(title, textRect.x, textRect.y + metrics.getAscent());
}
else
{
g.setColor(bg.brighter());
int mnemIndex = tabPane.getDisplayedMnemonicIndexAt(tabIndex);
if (mnemIndex != -1)
BasicGraphicsUtils.drawStringUnderlineCharAt(g, title, mnemIndex,
textRect.x, textRect.y);
else
g.drawString(title, textRect.x, textRect.y);
g.setColor(bg.darker());
if (mnemIndex != -1)
BasicGraphicsUtils.drawStringUnderlineCharAt(g, title, mnemIndex,
textRect.x + 1,
textRect.y + 1);
else
g.drawString(title, textRect.x + 1, textRect.y + 1);
}
g.setColor(saved_color);
g.setFont(f);
}
/**
* This method returns how much the label for the tab should shift in the X
* direction.
*
* @param tabPlacement The JTabbedPane's tab placement.
* @param tabIndex The tab index being painted.
* @param isSelected Whether this tab is selected.
*
* @return The amount the label should shift by in the X direction.
*/
protected int getTabLabelShiftX(int tabPlacement, int tabIndex,
boolean isSelected)
{
// No reason to shift.
return 0;
}
/**
* This method returns how much the label for the tab should shift in the Y
* direction.
*
* @param tabPlacement The JTabbedPane's tab placement.
* @param tabIndex The tab index being painted.
* @param isSelected Whether this tab is selected.
*
* @return The amount the label should shift by in the Y direction.
*/
protected int getTabLabelShiftY(int tabPlacement, int tabIndex,
boolean isSelected)
{
// No reason to shift.
return 0;
}
/**
* This method paints the focus rectangle around the selected tab.
*
* @param g The Graphics object to paint with.
* @param tabPlacement The JTabbedPane's tab placement.
* @param rects The array of rectangles keeping track of size and position.
* @param tabIndex The tab index.
* @param iconRect The icon bounds.
* @param textRect The text bounds.
* @param isSelected Whether this tab is selected.
*/
protected void paintFocusIndicator(Graphics g, int tabPlacement,
Rectangle[] rects, int tabIndex,
Rectangle iconRect, Rectangle textRect,
boolean isSelected)
{
Color saved = g.getColor();
calcRect = iconRect.union(textRect);
g.setColor(focus);
g.drawRect(calcRect.x, calcRect.y, calcRect.width, calcRect.height);
g.setColor(saved);
}
/**
* This method paints the border for an individual tab.
*
* @param g The Graphics object to paint with.
* @param tabPlacement The JTabbedPane's tab placement.
* @param tabIndex The tab index.
* @param x The x position of the tab.
* @param y The y position of the tab.
* @param w The width of the tab.
* @param h The height of the tab.
* @param isSelected Whether the tab is selected.
*/
protected void paintTabBorder(Graphics g, int tabPlacement, int tabIndex,
int x, int y, int w, int h, boolean isSelected)
{
Color saved = g.getColor();
if (! isSelected || tabPlacement != SwingConstants.TOP)
{
g.setColor(shadow);
g.drawLine(x + 1, y + h - 1, x + w - 1, y + h - 1);
g.setColor(darkShadow);
g.drawLine(x, y + h, x + w, y + h);
}
if (! isSelected || tabPlacement != SwingConstants.LEFT)
{
g.setColor(darkShadow);
g.drawLine(x + w, y, x + w, y + h);
g.setColor(shadow);
g.drawLine(x + w - 1, y + 1, x + w - 1, y + h - 1);
}
if (! isSelected || tabPlacement != SwingConstants.RIGHT)
{
g.setColor(lightHighlight);
g.drawLine(x, y, x, y + h);
}
if (! isSelected || tabPlacement != SwingConstants.BOTTOM)
{
g.setColor(lightHighlight);
g.drawLine(x, y, x + w, y);
}
g.setColor(saved);
}
/**
* This method paints the background for an individual tab.
*
* @param g The Graphics object to paint with.
* @param tabPlacement The JTabbedPane's tab placement.
* @param tabIndex The tab index.
* @param x The x position of the tab.
* @param y The y position of the tab.
* @param w The width of the tab.
* @param h The height of the tab.
* @param isSelected Whether the tab is selected.
*/
protected void paintTabBackground(Graphics g, int tabPlacement,
int tabIndex, int x, int y, int w, int h,
boolean isSelected)
{
Color saved = g.getColor();
if (isSelected)
g.setColor(Color.LIGHT_GRAY);
else
{
Color bg = tabPane.getBackgroundAt(tabIndex);
if (bg == null)
bg = tabPane.getBackground();
g.setColor(bg);
}
g.fillRect(x, y, w, h);
g.setColor(saved);
}
/**
* This method paints the border around the content area.
*
* @param g The Graphics object to paint with.
* @param tabPlacement The JTabbedPane's tab placement.
* @param selectedIndex The index of the selected tab.
*/
protected void paintContentBorder(Graphics g, int tabPlacement,
int selectedIndex)
{
Insets insets = getContentBorderInsets(tabPlacement);
int x = contentRect.x;
int y = contentRect.y;
int w = contentRect.width;
int h = contentRect.height;
paintContentBorderTopEdge(g, tabPlacement, selectedIndex, x, y, w, h);
paintContentBorderLeftEdge(g, tabPlacement, selectedIndex, x, y, w, h);
paintContentBorderBottomEdge(g, tabPlacement, selectedIndex, x, y, w, h);
paintContentBorderRightEdge(g, tabPlacement, selectedIndex, x, y, w, h);
}
/**
* This method paints the top edge of the content border.
*
* @param g The Graphics object to paint with.
* @param tabPlacement The JTabbedPane's tab placement.
* @param selectedIndex The selected tab index.
* @param x The x coordinate for the content area.
* @param y The y coordinate for the content area.
* @param w The width of the content area.
* @param h The height of the content area.
*/
protected void paintContentBorderTopEdge(Graphics g, int tabPlacement,
int selectedIndex, int x, int y,
int w, int h)
{
Color saved = g.getColor();
g.setColor(lightHighlight);
int startgap = rects[selectedIndex].x;
int endgap = rects[selectedIndex].x + rects[selectedIndex].width;
int diff = 0;
if (tabPane.getTabLayoutPolicy() == JTabbedPane.SCROLL_TAB_LAYOUT)
{
Point p = findPointForIndex(currentScrollLocation);
diff = p.x;
}
if (tabPlacement == SwingConstants.TOP)
{
g.drawLine(x, y, startgap - diff, y);
g.drawLine(endgap - diff, y, x + w, y);
}
else
g.drawLine(x, y, x + w, y);
g.setColor(saved);
}
/**
* This method paints the left edge of the content border.
*
* @param g The Graphics object to paint with.
* @param tabPlacement The JTabbedPane's tab placement.
* @param selectedIndex The selected tab index.
* @param x The x coordinate for the content area.
* @param y The y coordinate for the content area.
* @param w The width of the content area.
* @param h The height of the content area.
*/
protected void paintContentBorderLeftEdge(Graphics g, int tabPlacement,
int selectedIndex, int x, int y,
int w, int h)
{
Color saved = g.getColor();
g.setColor(lightHighlight);
int startgap = rects[selectedIndex].y;
int endgap = rects[selectedIndex].y + rects[selectedIndex].height;
int diff = 0;
if (tabPane.getTabLayoutPolicy() == JTabbedPane.SCROLL_TAB_LAYOUT)
{
Point p = findPointForIndex(currentScrollLocation);
diff = p.y;
}
if (tabPlacement == SwingConstants.LEFT)
{
g.drawLine(x, y, x, startgap - diff);
g.drawLine(x, endgap - diff, x, y + h);
}
else
g.drawLine(x, y, x, y + h);
g.setColor(saved);
}
/**
* This method paints the bottom edge of the content border.
*
* @param g The Graphics object to paint with.
* @param tabPlacement The JTabbedPane's tab placement.
* @param selectedIndex The selected tab index.
* @param x The x coordinate for the content area.
* @param y The y coordinate for the content area.
* @param w The width of the content area.
* @param h The height of the content area.
*/
protected void paintContentBorderBottomEdge(Graphics g, int tabPlacement,
int selectedIndex, int x, int y,
int w, int h)
{
Color saved = g.getColor();
int startgap = rects[selectedIndex].x;
int endgap = rects[selectedIndex].x + rects[selectedIndex].width;
int diff = 0;
if (tabPane.getTabLayoutPolicy() == JTabbedPane.SCROLL_TAB_LAYOUT)
{
Point p = findPointForIndex(currentScrollLocation);
diff = p.x;
}
if (tabPlacement == SwingConstants.BOTTOM)
{
g.setColor(shadow);
g.drawLine(x + 1, y + h - 1, startgap - diff, y + h - 1);
g.drawLine(endgap - diff, y + h - 1, x + w - 1, y + h - 1);
g.setColor(darkShadow);
g.drawLine(x, y + h, startgap - diff, y + h);
g.drawLine(endgap - diff, y + h, x + w, y + h);
}
else
{
g.setColor(shadow);
g.drawLine(x + 1, y + h - 1, x + w - 1, y + h - 1);
g.setColor(darkShadow);
g.drawLine(x, y + h, x + w, y + h);
}
g.setColor(saved);
}
/**
* This method paints the right edge of the content border.
*
* @param g The Graphics object to paint with.
* @param tabPlacement The JTabbedPane's tab placement.
* @param selectedIndex The selected tab index.
* @param x The x coordinate for the content area.
* @param y The y coordinate for the content area.
* @param w The width of the content area.
* @param h The height of the content area.
*/
protected void paintContentBorderRightEdge(Graphics g, int tabPlacement,
int selectedIndex, int x, int y,
int w, int h)
{
Color saved = g.getColor();
int startgap = rects[selectedIndex].y;
int endgap = rects[selectedIndex].y + rects[selectedIndex].height;
int diff = 0;
if (tabPane.getTabLayoutPolicy() == JTabbedPane.SCROLL_TAB_LAYOUT)
{
Point p = findPointForIndex(currentScrollLocation);
diff = p.y;
}
if (tabPlacement == SwingConstants.RIGHT)
{
g.setColor(shadow);
g.drawLine(x + w - 1, y + 1, x + w - 1, startgap - diff);
g.drawLine(x + w - 1, endgap - diff, x + w - 1, y + h - 1);
g.setColor(darkShadow);
g.drawLine(x + w, y, x + w, startgap - diff);
g.drawLine(x + w, endgap - diff, x + w, y + h);
}
else
{
g.setColor(shadow);
g.drawLine(x + w - 1, y + 1, x + w - 1, y + h - 1);
g.setColor(darkShadow);
g.drawLine(x + w, y, x + w, y + h);
}
g.setColor(saved);
}
/**
* This method returns the tab bounds for the given index.
*
* @param pane The JTabbedPane.
* @param i The index to look for.
*
* @return The bounds of the tab with the given index.
*/
public Rectangle getTabBounds(JTabbedPane pane, int i)
{
return rects[i];
}
/**
* This method returns the number of runs.
*
* @param pane The JTabbedPane.
*
* @return The number of runs.
*/
public int getTabRunCount(JTabbedPane pane)
{
return runCount;
}
/**
* This method returns the tab index given a coordinate.
*
* @param pane The JTabbedPane.
* @param x The x coordinate.
* @param y The y coordinate.
*
* @return The tab index that the coordinate lands in.
*/
public int tabForCoordinate(JTabbedPane pane, int x, int y)
{
Point p = new Point(x, y);
int tabCount = tabPane.getTabCount();
int currRun = 1;
for (int i = 0; i < runCount; i++)
{
int first = lastTabInRun(tabCount, getPreviousTabRun(currRun)) + 1;
if (first == tabCount)
first = 0;
int last = lastTabInRun(tabCount, currRun);
for (int j = first; j <= last; j++)
{
if (getTabBounds(pane, j).contains(p))
return j;
}
currRun = getNextTabRun(currRun);
}
return -1;
}
/**
* This method returns the tab bounds in the given rectangle.
*
* @param tabIndex The index to get bounds for.
* @param dest The rectangle to store bounds in.
*
* @return The rectangle passed in.
*/
protected Rectangle getTabBounds(int tabIndex, Rectangle dest)
{
dest.setBounds(getTabBounds(tabPane, tabIndex));
return dest;
}
/**
* This method returns the component that is shown in the content area.
*
* @return The component that is shown in the content area.
*/
protected Component getVisibleComponent()
{
return tabPane.getComponentAt(tabPane.getSelectedIndex());
}
/**
* This method sets the visible component.
*
* @param component The component to be set visible.
*/
protected void setVisibleComponent(Component component)
{
component.setVisible(true);
tabPane.setSelectedComponent(component);
}
/**
* This method assures that enough rectangles are created given the
* tabCount. The old array is copied to the new one.
*
* @param tabCount The number of tabs.
*/
protected void assureRectsCreated(int tabCount)
{
if (rects == null)
rects = new Rectangle[tabCount];
if (tabCount == rects.length)
return;
else
{
int numToCopy = Math.min(tabCount, rects.length);
Rectangle[] tmp = new Rectangle[tabCount];
System.arraycopy(rects, 0, tmp, 0, numToCopy);
rects = tmp;
}
}
/**
* This method expands the tabRuns array to give it more room. The old array
* is copied to the new one.
*/
protected void expandTabRunsArray()
{
// This method adds another 10 index positions to the tabRuns array.
if (tabRuns == null)
tabRuns = new int[10];
else
{
int[] newRuns = new int[tabRuns.length + 10];
System.arraycopy(tabRuns, 0, newRuns, 0, tabRuns.length);
tabRuns = newRuns;
}
}
/**
* This method returns which run a particular tab belongs to.
*
* @param tabCount The number of tabs.
* @param tabIndex The tab to find.
*
* @return The tabRuns index that it belongs to.
*/
protected int getRunForTab(int tabCount, int tabIndex)
{
if (runCount == 1 && tabIndex < tabCount && tabIndex >= 0)
return 1;
for (int i = 0; i < runCount; i++)
{
int first = lastTabInRun(tabCount, getPreviousTabRun(i)) + 1;
if (first == tabCount)
first = 0;
int last = lastTabInRun(tabCount, i);
if (last >= tabIndex && first <= tabIndex)
return i;
}
return -1;
}
/**
* This method returns the index of the last tab in a run.
*
* @param tabCount The number of tabs.
* @param run The run to check.
*
* @return The last tab in the given run.
*/
protected int lastTabInRun(int tabCount, int run)
{
if (tabRuns[run] == 0)
return tabCount - 1;
else
return tabRuns[run] - 1;
}
/**
* This method returns the tab run overlay.
*
* @param tabPlacement The JTabbedPane's tab placement.
*
* @return The tab run overlay.
*/
protected int getTabRunOverlay(int tabPlacement)
{
return tabRunOverlay;
}
/**
* This method returns the tab run indent. It is used in WRAP_TAB_LAYOUT and
* makes each tab run start indented by a certain amount.
*
* @param tabPlacement The JTabbedPane's tab placement.
* @param run The run to get indent for.
*
* @return The amount a run should be indented.
*/
protected int getTabRunIndent(int tabPlacement, int run)
{
return 0;
}
/**
* This method returns whether a tab run should be padded.
*
* @param tabPlacement The JTabbedPane's tab placement.
* @param run The run to check.
*
* @return Whether the given run should be padded.
*/
protected boolean shouldPadTabRun(int tabPlacement, int run)
{
return true;
}
/**
* This method returns whether the tab runs should be rotated.
*
* @param tabPlacement The JTabbedPane's tab placement.
*
* @return Whether runs should be rotated.
*/
protected boolean shouldRotateTabRuns(int tabPlacement)
{
return true;
}
/**
* This method returns an icon for the tab. If the tab is disabled, it
* should return the disabledIcon. If it is enabled, then it should return
* the default icon.
*
* @param tabIndex The tab index to get an icon for.
*
* @return The icon for the tab index.
*/
protected Icon getIconForTab(int tabIndex)
{
if (tabPane.isEnabledAt(tabIndex))
return tabPane.getIconAt(tabIndex);
else
return tabPane.getDisabledIconAt(tabIndex);
}
/**
* This method returns a view that can paint the text for the label.
*
* @param tabIndex The tab index to get a view for.
*
* @return The view for the tab index.
*/
protected View getTextViewForTab(int tabIndex)
{
return null;
}
/**
* This method returns the tab height, including insets, for the given index
* and fontheight.
*
* @param tabPlacement The JTabbedPane's tab placement.
* @param tabIndex The index of the tab to calculate.
* @param fontHeight The font height.
*
* @return This tab's height.
*/
protected int calculateTabHeight(int tabPlacement, int tabIndex,
int fontHeight)
{
Icon icon = getIconForTab(tabIndex);
Insets insets = getTabInsets(tabPlacement, tabIndex);
if (icon != null)
{
Rectangle vr = new Rectangle();
Rectangle ir = new Rectangle();
Rectangle tr = new Rectangle();
layoutLabel(tabPlacement, getFontMetrics(), tabIndex,
tabPane.getTitleAt(tabIndex), icon, vr, ir, tr,
tabIndex == tabPane.getSelectedIndex());
calcRect = tr.union(ir);
}
else
calcRect.height = fontHeight;
calcRect.height += insets.top + insets.bottom;
return calcRect.height;
}
/**
* This method returns the max tab height.
*
* @param tabPlacement The JTabbedPane's tab placement.
*
* @return The maximum tab height.
*/
protected int calculateMaxTabHeight(int tabPlacement)
{
maxTabHeight = 0;
FontMetrics fm = getFontMetrics();
int fontHeight = fm.getHeight();
for (int i = 0; i < tabPane.getTabCount(); i++)
maxTabHeight = Math.max(calculateTabHeight(tabPlacement, i, fontHeight),
maxTabHeight);
return maxTabHeight;
}
/**
* This method calculates the tab width, including insets, for the given tab
* index and font metrics.
*
* @param tabPlacement The JTabbedPane's tab placement.
* @param tabIndex The tab index to calculate for.
* @param metrics The font's metrics.
*
* @return The tab width for the given index.
*/
protected int calculateTabWidth(int tabPlacement, int tabIndex,
FontMetrics metrics)
{
Icon icon = getIconForTab(tabIndex);
Insets insets = getTabInsets(tabPlacement, tabIndex);
if (icon != null)
{
Rectangle vr = new Rectangle();
Rectangle ir = new Rectangle();
Rectangle tr = new Rectangle();
layoutLabel(tabPlacement, getFontMetrics(), tabIndex,
tabPane.getTitleAt(tabIndex), icon, vr, ir, tr,
tabIndex == tabPane.getSelectedIndex());
calcRect = tr.union(ir);
}
else
calcRect.width = metrics.stringWidth(tabPane.getTitleAt(tabIndex));
calcRect.width += insets.left + insets.right;
return calcRect.width;
}
/**
* This method calculates the max tab width.
*
* @param tabPlacement The JTabbedPane's tab placement.
*
* @return The maximum tab width.
*/
protected int calculateMaxTabWidth(int tabPlacement)
{
maxTabWidth = 0;
FontMetrics fm = getFontMetrics();
for (int i = 0; i < tabPane.getTabCount(); i++)
maxTabWidth = Math.max(calculateTabWidth(tabPlacement, i, fm),
maxTabWidth);
return maxTabWidth;
}
/**
* This method calculates the tab area height, including insets, for the
* given amount of runs and tab height.
*
* @param tabPlacement The JTabbedPane's tab placement.
* @param horizRunCount The number of runs.
* @param maxTabHeight The max tab height.
*
* @return The tab area height.
*/
protected int calculateTabAreaHeight(int tabPlacement, int horizRunCount,
int maxTabHeight)
{
Insets insets = getTabAreaInsets(tabPlacement);
int tabAreaHeight = horizRunCount * maxTabHeight
- (horizRunCount - 1) * tabRunOverlay;
tabAreaHeight += insets.top + insets.bottom;
return tabAreaHeight;
}
/**
* This method calculates the tab area width, including insets, for the
* given amount of runs and tab width.
*
* @param tabPlacement The JTabbedPane's tab placement.
* @param vertRunCount The number of runs.
* @param maxTabWidth The max tab width.
*
* @return The tab area width.
*/
protected int calculateTabAreaWidth(int tabPlacement, int vertRunCount,
int maxTabWidth)
{
Insets insets = getTabAreaInsets(tabPlacement);
int tabAreaWidth = vertRunCount * maxTabWidth
- (vertRunCount - 1) * tabRunOverlay;
tabAreaWidth += insets.left + insets.right;
return tabAreaWidth;
}
/**
* This method returns the tab insets appropriately rotated.
*
* @param tabPlacement The JTabbedPane's tab placement.
* @param tabIndex The tab index.
*
* @return The tab insets for the given index.
*/
protected Insets getTabInsets(int tabPlacement, int tabIndex)
{
Insets target = new Insets(0, 0, 0, 0);
rotateInsets(tabInsets, target, tabPlacement);
return target;
}
/**
* This method returns the selected tab pad insets appropriately rotated.
*
* @param tabPlacement The JTabbedPane's tab placement.
*
* @return The selected tab pad insets.
*/
protected Insets getSelectedTabPadInsets(int tabPlacement)
{
Insets target = new Insets(0, 0, 0, 0);
rotateInsets(selectedTabPadInsets, target, tabPlacement);
return target;
}
/**
* This method returns the tab area insets appropriately rotated.
*
* @param tabPlacement The JTabbedPane's tab placement.
*
* @return The tab area insets.
*/
protected Insets getTabAreaInsets(int tabPlacement)
{
Insets target = new Insets(0, 0, 0, 0);
rotateInsets(tabAreaInsets, target, tabPlacement);
return target;
}
/**
* This method returns the content border insets appropriately rotated.
*
* @param tabPlacement The JTabbedPane's tab placement.
*
* @return The content border insets.
*/
protected Insets getContentBorderInsets(int tabPlacement)
{
Insets target = new Insets(0, 0, 0, 0);
rotateInsets(contentBorderInsets, target, tabPlacement);
return target;
}
/**
* This method returns the fontmetrics for the font of the JTabbedPane.
*
* @return The font metrics for the JTabbedPane.
*/
protected FontMetrics getFontMetrics()
{
FontMetrics fm = tabPane.getToolkit().getFontMetrics(tabPane.getFont());
return fm;
}
/**
* This method navigates from the selected tab into the given direction. As
* a result, a new tab will be selected (if possible).
*
* @param direction The direction to navigate in.
*/
protected void navigateSelectedTab(int direction)
{
int tabPlacement = tabPane.getTabPlacement();
if (tabPlacement == SwingConstants.TOP
|| tabPlacement == SwingConstants.BOTTOM)
{
if (direction == SwingConstants.WEST)
selectPreviousTabInRun(tabPane.getSelectedIndex());
else if (direction == SwingConstants.EAST)
selectNextTabInRun(tabPane.getSelectedIndex());
else
{
int offset = getTabRunOffset(tabPlacement, tabPane.getTabCount(),
tabPane.getSelectedIndex(),
(tabPlacement == SwingConstants.RIGHT)
? true : false);
selectAdjacentRunTab(tabPlacement, tabPane.getSelectedIndex(),
offset);
}
}
if (tabPlacement == SwingConstants.LEFT
|| tabPlacement == SwingConstants.RIGHT)
{
if (direction == SwingConstants.NORTH)
selectPreviousTabInRun(tabPane.getSelectedIndex());
else if (direction == SwingConstants.SOUTH)
selectNextTabInRun(tabPane.getSelectedIndex());
else
{
int offset = getTabRunOffset(tabPlacement, tabPane.getTabCount(),
tabPane.getSelectedIndex(),
(tabPlacement == SwingConstants.RIGHT)
? true : false);
selectAdjacentRunTab(tabPlacement, tabPane.getSelectedIndex(),
offset);
}
}
}
/**
* This method selects the next tab in the run.
*
* @param current The current selected index.
*/
protected void selectNextTabInRun(int current)
{
tabPane.setSelectedIndex(getNextTabIndexInRun(tabPane.getTabCount(),
current));
}
/**
* This method selects the previous tab in the run.
*
* @param current The current selected index.
*/
protected void selectPreviousTabInRun(int current)
{
tabPane.setSelectedIndex(getPreviousTabIndexInRun(tabPane.getTabCount(),
current));
}
/**
* This method selects the next tab (regardless of runs).
*
* @param current The current selected index.
*/
protected void selectNextTab(int current)
{
tabPane.setSelectedIndex(getNextTabIndex(current));
}
/**
* This method selects the previous tab (regardless of runs).
*
* @param current The current selected index.
*/
protected void selectPreviousTab(int current)
{
tabPane.setSelectedIndex(getPreviousTabIndex(current));
}
/**
* This method selects the correct tab given an offset from the current tab
* index. If the tab placement is TOP or BOTTOM, the offset will be in the
* y direction, otherwise, it will be in the x direction. A new coordinate
* will be found by adding the offset to the current location of the tab.
* The tab that the new location will be selected.
*
* @param tabPlacement The JTabbedPane's tab placement.
* @param tabIndex The tab to start from.
* @param offset The coordinate offset.
*/
protected void selectAdjacentRunTab(int tabPlacement, int tabIndex,
int offset)
{
int x = rects[tabIndex].x + rects[tabIndex].width / 2;
int y = rects[tabIndex].y + rects[tabIndex].height / 2;
switch (tabPlacement)
{
case SwingConstants.TOP:
case SwingConstants.BOTTOM:
y += offset;
break;
case SwingConstants.RIGHT:
case SwingConstants.LEFT:
x += offset;
break;
}
int index = tabForCoordinate(tabPane, x, y);
if (index != -1)
tabPane.setSelectedIndex(index);
}
// This method is called when you press up/down to cycle through tab runs.
// it returns the distance (between the two runs' x/y position.
// where one run is the current selected run and the other run is the run in the
// direction of the scroll (dictated by the forward flag)
// the offset is an absolute value of the difference
/**
* This method calculates the offset distance for use in
* selectAdjacentRunTab. The offset returned will be a difference in the y
* coordinate between the run in the desired direction and the current run
* (for tabPlacement in TOP or BOTTOM). Use x coordinate for LEFT and
* RIGHT.
*
* @param tabPlacement The JTabbedPane's tab placement.
* @param tabCount The number of tabs.
* @param tabIndex The starting index.
* @param forward If forward, the run in the desired direction will be the
* next run.
*
* @return The offset between the two runs.
*/
protected int getTabRunOffset(int tabPlacement, int tabCount, int tabIndex,
boolean forward)
{
int currRun = getRunForTab(tabCount, tabIndex);
int offset;
int nextRun = (forward) ? getNextTabRun(currRun) : getPreviousTabRun(currRun);
if (tabPlacement == SwingConstants.TOP
|| tabPlacement == SwingConstants.BOTTOM)
offset = rects[lastTabInRun(tabCount, nextRun)].y
- rects[lastTabInRun(tabCount, currRun)].y;
else
offset = rects[lastTabInRun(tabCount, nextRun)].x
- rects[lastTabInRun(tabCount, currRun)].x;
return offset;
}
/**
* This method returns the previous tab index.
*
* @param base The index to start from.
*
* @return The previous tab index.
*/
protected int getPreviousTabIndex(int base)
{
base--;
if (base < 0)
return tabPane.getTabCount() - 1;
return base;
}
/**
* This method returns the next tab index.
*
* @param base The index to start from.
*
* @return The next tab index.
*/
protected int getNextTabIndex(int base)
{
base++;
if (base == tabPane.getTabCount())
return 0;
return base;
}
/**
* This method returns the next tab index in the run. If the next index is
* out of this run, it will return the starting tab index for the run.
*
* @param tabCount The number of tabs.
* @param base The index to start from.
*
* @return The next tab index in the run.
*/
protected int getNextTabIndexInRun(int tabCount, int base)
{
int index = getNextTabIndex(base);
int run = getRunForTab(tabCount, base);
if (index == lastTabInRun(tabCount, run) + 1)
index = lastTabInRun(tabCount, getPreviousTabRun(run)) + 1;
return getNextTabIndex(base);
}
/**
* This method returns the previous tab index in the run. If the previous
* index is out of this run, it will return the last index for the run.
*
* @param tabCount The number of tabs.
* @param base The index to start from.
*
* @return The previous tab index in the run.
*/
protected int getPreviousTabIndexInRun(int tabCount, int base)
{
int index = getPreviousTabIndex(base);
int run = getRunForTab(tabCount, base);
if (index == lastTabInRun(tabCount, getPreviousTabRun(run)))
index = lastTabInRun(tabCount, run);
return getPreviousTabIndex(base);
}
/**
* This method returns the index of the previous run.
*
* @param baseRun The run to start from.
*
* @return The index of the previous run.
*/
protected int getPreviousTabRun(int baseRun)
{
if (getTabRunCount(tabPane) == 1)
return 1;
int prevRun = --baseRun;
if (prevRun < 0)
prevRun = getTabRunCount(tabPane) - 1;
return prevRun;
}
/**
* This method returns the index of the next run.
*
* @param baseRun The run to start from.
*
* @return The index of the next run.
*/
protected int getNextTabRun(int baseRun)
{
if (getTabRunCount(tabPane) == 1)
return 1;
int nextRun = ++baseRun;
if (nextRun == getTabRunCount(tabPane))
nextRun = 0;
return nextRun;
}
/**
* This method rotates the insets given a direction to rotate them in.
* Target placement should be one of TOP, LEFT, BOTTOM, RIGHT. The rotated
* insets will be stored in targetInsets. Passing in TOP as the direction
* does nothing. Passing in LEFT switches top and left, right and bottom.
* Passing in BOTTOM switches top and bottom. Passing in RIGHT switches top
* for left, left for bottom, bottom for right, and right for top.
*
* @param topInsets The reference insets.
* @param targetInsets An Insets object to store the new insets.
* @param targetPlacement The rotation direction.
*/
protected static void rotateInsets(Insets topInsets, Insets targetInsets,
int targetPlacement)
{
// Sun's version will happily throw an NPE if params are null,
// so I won't check it either.
switch (targetPlacement)
{
case SwingConstants.TOP:
targetInsets.top = topInsets.top;
targetInsets.left = topInsets.left;
targetInsets.right = topInsets.right;
targetInsets.bottom = topInsets.bottom;
break;
case SwingConstants.LEFT:
targetInsets.left = topInsets.top;
targetInsets.top = topInsets.left;
targetInsets.right = topInsets.bottom;
targetInsets.bottom = topInsets.right;
break;
case SwingConstants.BOTTOM:
targetInsets.top = topInsets.bottom;
targetInsets.bottom = topInsets.top;
targetInsets.left = topInsets.left;
targetInsets.right = topInsets.right;
break;
case SwingConstants.RIGHT:
targetInsets.top = topInsets.left;
targetInsets.left = topInsets.bottom;
targetInsets.bottom = topInsets.right;
targetInsets.right = topInsets.top;
break;
}
}
}
...@@ -127,6 +127,7 @@ public class BasicViewportUI extends ViewportUI ...@@ -127,6 +127,7 @@ public class BasicViewportUI extends ViewportUI
Point pos = v.getViewPosition(); Point pos = v.getViewPosition();
Rectangle viewBounds = view.getBounds(); Rectangle viewBounds = view.getBounds();
Rectangle portBounds = v.getBounds();
if (backingStoreImage == null if (backingStoreImage == null
|| backingStoreWidth != viewBounds.width || backingStoreWidth != viewBounds.width
...@@ -138,6 +139,32 @@ public class BasicViewportUI extends ViewportUI ...@@ -138,6 +139,32 @@ public class BasicViewportUI extends ViewportUI
} }
Graphics g2 = backingStoreImage.getGraphics(); Graphics g2 = backingStoreImage.getGraphics();
if (c.getBackground() != null)
{
// fill the backing store background
java.awt.Color save = g2.getColor();
g2.setColor(c.getBackground());
g2.fillRect (0, 0, backingStoreWidth, backingStoreHeight);
g2.setColor(save);
// fill the viewport background
save = g.getColor();
g.setColor(c.getBackground());
g.fillRect (0, 0, portBounds.width, portBounds.height);
g.setColor(save);
}
else
{
// clear the backing store background
g2.clearRect(0, 0, backingStoreWidth, backingStoreHeight);
// clear the viewport background
g.clearRect(0, 0, portBounds.width, portBounds.height);
}
view.paint(g2); view.paint(g2);
g2 = null; g2 = null;
g.drawImage(backingStoreImage, g.drawImage(backingStoreImage,
......
/* jcl.c /* jcl.c
Copyright (C) 1998 Free Software Foundation, Inc. Copyright (C) 1998, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath. This file is part of GNU Classpath.
...@@ -37,7 +37,7 @@ exception statement from your version. */ ...@@ -37,7 +37,7 @@ exception statement from your version. */
#include <stdio.h> #include <stdio.h>
#include <jcl.h> #include <jcl.h>
#include <malloc.h> #include <stdlib.h>
#ifndef __GNUC__ #ifndef __GNUC__
#define __attribute__(x) /* nothing */ #define __attribute__(x) /* nothing */
......
/* JNILINK 1.1: JNI version. /* JNILINK 1.1: JNI version.
Copyright (C) 1998 Free Software Foundation, Inc. Copyright (C) 1998, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath. This file is part of GNU Classpath.
...@@ -40,7 +40,7 @@ exception statement from your version. */ ...@@ -40,7 +40,7 @@ exception statement from your version. */
#include <string.h> #include <string.h>
#include <jcl.h> #include <jcl.h>
#include <malloc.h> #include <stdlib.h>
#define GETCLASS(c) *(jclass*)(c) #define GETCLASS(c) *(jclass*)(c)
......
...@@ -371,9 +371,12 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics2D_initState__II ...@@ -371,9 +371,12 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics2D_initState__II
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics2D_gdkDrawDrawable JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics2D_gdkDrawDrawable
(JNIEnv *env, jobject self, jobject other, jint x, jint y) (JNIEnv *env, jobject self, jobject other, jint x, jint y)
{ {
GdkRectangle clipRect;
struct graphics2d *src = NULL, *dst = NULL; struct graphics2d *src = NULL, *dst = NULL;
gint s_height, s_width, d_height, d_width, height, width; gint s_height, s_width, d_height, d_width, height, width;
cairo_matrix_t *matrix;
GdkGC *gc; GdkGC *gc;
cairo_operator_t tmp_op;
src = (struct graphics2d *)NSA_GET_G2D_PTR (env, other); src = (struct graphics2d *)NSA_GET_G2D_PTR (env, other);
dst = (struct graphics2d *)NSA_GET_G2D_PTR (env, self); dst = (struct graphics2d *)NSA_GET_G2D_PTR (env, self);
...@@ -386,19 +389,33 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics2D_gdkDrawDrawable ...@@ -386,19 +389,33 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics2D_gdkDrawDrawable
gdk_drawable_get_size (src->drawable, &s_width, &s_height); gdk_drawable_get_size (src->drawable, &s_width, &s_height);
gdk_drawable_get_size (dst->drawable, &d_width, &d_height); gdk_drawable_get_size (dst->drawable, &d_width, &d_height);
width = min (s_width, d_width); width = min (s_width, d_width);
height = min (s_width, d_height); height = min (s_height, d_height);
gdk_threads_leave ();
gc = gdk_gc_new (dst->drawable); begin_drawing_operation(dst);
g_assert (gc != NULL);
gdk_draw_drawable(dst->drawable, gc, src->drawable, matrix = cairo_matrix_create ();
0, 0, x, y, width, height); cairo_surface_get_matrix (src->surface, matrix);
gdk_flush (); cairo_matrix_translate (matrix, (double)-x, (double)-y);
cairo_surface_set_matrix (src->surface, matrix);
g_object_unref (gc); tmp_op = cairo_current_operator (dst->cr);
cairo_set_operator(dst->cr, CAIRO_OPERATOR_SRC);
cairo_show_surface (dst->cr, src->surface, width, height);
cairo_set_operator(dst->cr, tmp_op);
if (src->debug) printf ("copied %d x %d pixels from offscreen drawable\n", width, height); cairo_matrix_translate (matrix, (double)x, (double)y);
cairo_surface_set_matrix (src->surface, matrix);
cairo_matrix_destroy (matrix);
end_drawing_operation(dst);
gdk_threads_enter ();
gdk_flush ();
gdk_threads_leave (); gdk_threads_leave ();
if (src->debug) printf ("copied %d x %d pixels from offscreen drawable\n", width, height);
} }
static jintArray static jintArray
...@@ -1215,6 +1232,7 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics2D_cairoClip ...@@ -1215,6 +1232,7 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics2D_cairoClip
gr = (struct graphics2d *) NSA_GET_G2D_PTR (env, obj); gr = (struct graphics2d *) NSA_GET_G2D_PTR (env, obj);
g_assert (gr != NULL); g_assert (gr != NULL);
if (gr->debug) printf ("cairo_clip\n"); if (gr->debug) printf ("cairo_clip\n");
cairo_init_clip (gr->cr);
cairo_clip (gr->cr); cairo_clip (gr->cr);
} }
......
...@@ -249,9 +249,10 @@ static void ...@@ -249,9 +249,10 @@ static void
item_activate (GtkItem *item __attribute__((unused)), item_activate (GtkItem *item __attribute__((unused)),
struct item_event_hook_info *ie) struct item_event_hook_info *ie)
{ {
jstring label;
gdk_threads_leave (); gdk_threads_leave ();
jstring label = (*gdk_env)->NewStringUTF (gdk_env, ie->label); label = (*gdk_env)->NewStringUTF (gdk_env, ie->label);
(*gdk_env)->CallVoidMethod (gdk_env, ie->peer_obj, (*gdk_env)->CallVoidMethod (gdk_env, ie->peer_obj,
choicePostItemEventID, choicePostItemEventID,
label, label,
......
...@@ -136,7 +136,7 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkComponentPeer_requestFocus ...@@ -136,7 +136,7 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkComponentPeer_requestFocus
ptr = NSA_GET_PTR (env, obj); ptr = NSA_GET_PTR (env, obj);
gdk_threads_enter (); gdk_threads_enter ();
gtk_widget_grab_focus (GTK_WIDGET (ptr)); // gtk_widget_grab_focus (GTK_WIDGET (ptr));
gdk_threads_leave (); gdk_threads_leave ();
} }
...@@ -386,7 +386,6 @@ Java_gnu_java_awt_peer_gtk_GtkComponentPeer_gtkSetFont ...@@ -386,7 +386,6 @@ Java_gnu_java_awt_peer_gtk_GtkComponentPeer_gtkSetFont
{ {
const char *font_name; const char *font_name;
void *ptr; void *ptr;
GtkWidget *label;
PangoFontDescription *font_desc; PangoFontDescription *font_desc;
ptr = NSA_GET_PTR (env, obj); ptr = NSA_GET_PTR (env, obj);
...@@ -632,12 +631,13 @@ filter_expose_event_handler (GtkWidget *widget, GdkEvent *event, jobject peer) ...@@ -632,12 +631,13 @@ filter_expose_event_handler (GtkWidget *widget, GdkEvent *event, jobject peer)
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkComponentPeer_addExposeFilter JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkComponentPeer_addExposeFilter
(JNIEnv *env, jobject obj) (JNIEnv *env, jobject obj)
{ {
void *ptr = NSA_GET_PTR (env, obj);
jobject *gref = NSA_GET_GLOBAL_REF (env, obj);
g_assert (gref);
GtkObject *filterobj; GtkObject *filterobj;
GtkWidget *vbox, *layout; GtkWidget *vbox, *layout;
GList *children; GList *children;
void *ptr = NSA_GET_PTR (env, obj);
jobject *gref = NSA_GET_GLOBAL_REF (env, obj);
g_assert (gref);
gdk_threads_enter (); gdk_threads_enter ();
...@@ -675,12 +675,13 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkComponentPeer_addExposeFilt ...@@ -675,12 +675,13 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkComponentPeer_addExposeFilt
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkComponentPeer_removeExposeFilter JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkComponentPeer_removeExposeFilter
(JNIEnv *env, jobject obj) (JNIEnv *env, jobject obj)
{ {
void *ptr = NSA_GET_PTR (env, obj);
jobject *gref = NSA_GET_GLOBAL_REF (env, obj);
g_assert (gref);
GtkObject *filterobj; GtkObject *filterobj;
GtkWidget *vbox, *layout; GtkWidget *vbox, *layout;
GList *children; GList *children;
void *ptr = NSA_GET_PTR (env, obj);
jobject *gref = NSA_GET_GLOBAL_REF (env, obj);
g_assert (gref);
gdk_threads_enter (); gdk_threads_enter ();
......
...@@ -186,6 +186,7 @@ ok_clicked (GtkButton *button __attribute__((unused)), ...@@ -186,6 +186,7 @@ ok_clicked (GtkButton *button __attribute__((unused)),
static jmethodID hideID; static jmethodID hideID;
void *ptr; void *ptr;
G_CONST_RETURN gchar *fileName; G_CONST_RETURN gchar *fileName;
jstring str_fileName;
ptr = NSA_GET_PTR (gdk_env, peer_obj); ptr = NSA_GET_PTR (gdk_env, peer_obj);
...@@ -204,7 +205,7 @@ ok_clicked (GtkButton *button __attribute__((unused)), ...@@ -204,7 +205,7 @@ ok_clicked (GtkButton *button __attribute__((unused)),
gdk_threads_leave (); gdk_threads_leave ();
/* Set the Java object field 'file' with this value. */ /* Set the Java object field 'file' with this value. */
jstring str_fileName = (*gdk_env)->NewStringUTF (gdk_env, fileName); str_fileName = (*gdk_env)->NewStringUTF (gdk_env, fileName);
(*gdk_env)->CallVoidMethod (gdk_env, peer_obj, gtkSetFilenameID, str_fileName); (*gdk_env)->CallVoidMethod (gdk_env, peer_obj, gtkSetFilenameID, str_fileName);
/* We can hide the dialog now (and unblock show) */ /* We can hide the dialog now (and unblock show) */
......
...@@ -66,7 +66,7 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkMenuBarPeer_addMenu ...@@ -66,7 +66,7 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkMenuBarPeer_addMenu
menu = NSA_GET_PTR (env, menupeer); menu = NSA_GET_PTR (env, menupeer);
gdk_threads_enter (); gdk_threads_enter ();
gtk_menu_bar_append (GTK_MENU_BAR (mbar), GTK_WIDGET (menu)); gtk_menu_shell_append (GTK_MENU_SHELL (mbar), GTK_WIDGET (menu));
gdk_threads_leave (); gdk_threads_leave ();
} }
......
...@@ -41,18 +41,16 @@ exception statement from your version. */ ...@@ -41,18 +41,16 @@ exception statement from your version. */
#include "gnu_java_awt_peer_gtk_GtkComponentPeer.h" #include "gnu_java_awt_peer_gtk_GtkComponentPeer.h"
static void item_activate (GtkMenuItem *item __attribute__((unused)), static void item_activate (GtkMenuItem *item __attribute__((unused)),
jobject *peer_obj); jobject peer_obj);
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkMenuItemPeer_create JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkMenuItemPeer_create
(JNIEnv *env, jobject obj, jstring label) (JNIEnv *env, jobject obj, jstring label)
{ {
GtkWidget *widget; GtkWidget *widget;
const char *str; const char *str;
jobject *gref;
/* Create global reference and save it for future use */ /* Create global reference and save it for future use */
NSA_SET_GLOBAL_REF (env, obj); NSA_SET_GLOBAL_REF (env, obj);
gref = NSA_GET_GLOBAL_REF (env, obj);
str = (*env)->GetStringUTFChars (env, label, NULL); str = (*env)->GetStringUTFChars (env, label, NULL);
...@@ -63,10 +61,6 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkMenuItemPeer_create ...@@ -63,10 +61,6 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkMenuItemPeer_create
else else
widget = gtk_menu_item_new_with_label (str); widget = gtk_menu_item_new_with_label (str);
/* Connect activate hook */
g_signal_connect (G_OBJECT (widget), "activate",
GTK_SIGNAL_FUNC (item_activate), *gref);
gtk_widget_show (widget); gtk_widget_show (widget);
gdk_threads_leave (); gdk_threads_leave ();
...@@ -76,6 +70,22 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkMenuItemPeer_create ...@@ -76,6 +70,22 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkMenuItemPeer_create
NSA_SET_PTR (env, obj, widget); NSA_SET_PTR (env, obj, widget);
} }
JNIEXPORT void JNICALL
Java_gnu_java_awt_peer_gtk_GtkMenuItemPeer_connectSignals
(JNIEnv *env, jobject obj)
{
void *ptr = NSA_GET_PTR (env, obj);
jobject *gref = NSA_GET_GLOBAL_REF (env, obj);
g_assert (gref);
gdk_threads_enter ();
g_signal_connect (G_OBJECT (ptr), "activate",
G_CALLBACK (item_activate), *gref);
gdk_threads_leave ();
}
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkMenuItemPeer_setLabel JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkMenuItemPeer_setLabel
(JNIEnv *env, jobject obj, jstring label) (JNIEnv *env, jobject obj, jstring label)
{ {
...@@ -104,9 +114,9 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkMenuItemPeer_setLabel ...@@ -104,9 +114,9 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkMenuItemPeer_setLabel
} }
static void static void
item_activate (GtkMenuItem *item __attribute__((unused)), jobject *peer_obj) item_activate (GtkMenuItem *item __attribute__((unused)), jobject peer_obj)
{ {
(*gdk_env)->CallVoidMethod (gdk_env, *peer_obj, (*gdk_env)->CallVoidMethod (gdk_env, peer_obj,
postMenuActionEventID); postMenuActionEventID);
} }
...@@ -101,10 +101,21 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkMenuPeer_create ...@@ -101,10 +101,21 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkMenuPeer_create
menu = gtk_menu_new (); menu = gtk_menu_new ();
if (str != NULL)
menu_title = gtk_menu_item_new_with_label (str); menu_title = gtk_menu_item_new_with_label (str);
else
menu_title = gtk_menu_item_new();
gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_title), menu); gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_title), menu);
gtk_widget_show (menu); // Allow this menu to grab the pointer.
GtkWidget *toplevel = gtk_widget_get_toplevel (menu);
if (GTK_IS_WINDOW (toplevel))
{
gtk_window_group_add_window (global_gtk_window_group,
GTK_WINDOW(toplevel));
}
gtk_widget_show (menu_title); gtk_widget_show (menu_title);
NSA_SET_PTR (env, obj, menu_title); NSA_SET_PTR (env, obj, menu_title);
...@@ -125,8 +136,8 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkMenuPeer_addItem ...@@ -125,8 +136,8 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkMenuPeer_addItem
gdk_threads_enter (); gdk_threads_enter ();
menu = GTK_MENU (GTK_MENU_ITEM (ptr1)->submenu); menu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(ptr1));
gtk_menu_append (menu, GTK_WIDGET (ptr2)); gtk_menu_shell_append (GTK_MENU_SHELL(menu), GTK_WIDGET (ptr2));
if (key) if (key)
{ {
......
...@@ -58,14 +58,6 @@ Java_gnu_java_awt_peer_gtk_GtkPanelPeer_create ...@@ -58,14 +58,6 @@ Java_gnu_java_awt_peer_gtk_GtkPanelPeer_create
NSA_SET_PTR (env, obj, widget); NSA_SET_PTR (env, obj, widget);
} }
typedef struct _GtkLayoutChild GtkLayoutChild;
struct _GtkLayoutChild {
GtkWidget *widget;
gint x;
gint y;
};
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_gnu_java_awt_peer_gtk_GtkPanelPeer_connectJObject Java_gnu_java_awt_peer_gtk_GtkPanelPeer_connectJObject
(JNIEnv *env, jobject obj) (JNIEnv *env, jobject obj)
...@@ -80,59 +72,3 @@ Java_gnu_java_awt_peer_gtk_GtkPanelPeer_connectJObject ...@@ -80,59 +72,3 @@ Java_gnu_java_awt_peer_gtk_GtkPanelPeer_connectJObject
gdk_threads_leave (); gdk_threads_leave ();
} }
JNIEXPORT void JNICALL
Java_gnu_java_awt_peer_gtk_GtkPanelPeer_connectSignals
(JNIEnv *env, jobject obj)
{
void *ptr = NSA_GET_PTR (env, obj);
jobject *gref = NSA_GET_GLOBAL_REF (env, obj);
g_assert (gref);
gdk_threads_enter ();
gtk_widget_realize (GTK_WIDGET (ptr));
/* FIXME: If we don't need this then remove this method. */
/* g_signal_connect (G_OBJECT (ptr), "size_request", GTK_SIGNAL_FUNC (sr), */
/* NULL); */
gdk_threads_leave ();
/* Connect the superclass signals. */
Java_gnu_java_awt_peer_gtk_GtkComponentPeer_connectSignals (env, obj);
}
/* FIXME: The following doesn't seem to be used.
Is not declared as a native function in GtkPanelPeer.java */
/*
* Make a new panel.
*/
JNIEXPORT void JNICALL
Java_gnu_java_awt_peer_gtk_GtkPanelPeer_gtkPanelNew
(JNIEnv *env, jobject obj, jobject parent_obj)
{
GtkWidget *layout;
void *parent;
/* Create global reference and save it for future use */
NSA_SET_GLOBAL_REF (env, obj);
parent = NSA_GET_PTR (env, parent_obj);
gdk_threads_enter ();
layout = gtk_layout_new (NULL, NULL);
set_parent (layout, GTK_CONTAINER (parent));
gtk_widget_realize (layout);
connect_awt_hook (env, obj, 1, GTK_LAYOUT (layout)->bin_window);
set_visible (layout, 1);
gdk_threads_leave ();
NSA_SET_PTR (env, obj, layout);
}
...@@ -72,7 +72,7 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkPopupMenuPeer_show ...@@ -72,7 +72,7 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkPopupMenuPeer_show
gdk_threads_enter (); gdk_threads_enter ();
gtk_menu_popup (GTK_MENU (GTK_MENU_ITEM (ptr)->submenu), gtk_menu_popup (GTK_MENU (GTK_MENU_ITEM (ptr)->submenu),
NULL, NULL, menu_pos, p, 3, time); NULL, NULL, menu_pos, p, 0, time);
gdk_threads_leave (); gdk_threads_leave ();
g_free (p); g_free (p);
......
...@@ -32,7 +32,6 @@ FAIL: gnu.testlet.java.lang.String.getBytes13: String.getBytes("UnicodeLittleUnm ...@@ -32,7 +32,6 @@ FAIL: gnu.testlet.java.lang.String.getBytes13: String.getBytes("UnicodeLittleUnm
FAIL: gnu.testlet.java.lang.String.getBytes14: String.getBytes("ISO8859_15") (number 1) FAIL: gnu.testlet.java.lang.String.getBytes14: String.getBytes("ISO8859_15") (number 1)
FAIL: gnu.testlet.java.lang.String.getBytes14: String.getBytes("UTF-16BE") (number 1) FAIL: gnu.testlet.java.lang.String.getBytes14: String.getBytes("UTF-16BE") (number 1)
FAIL: gnu.testlet.java.lang.String.getBytes14: String.getBytes("UTF-16LE") (number 1) FAIL: gnu.testlet.java.lang.String.getBytes14: String.getBytes("UTF-16LE") (number 1)
FAIL: gnu.testlet.java.text.AttributedString.Test: Attribute key count (number 1)
FAIL: gnu.testlet.java.text.DateFormatSymbols.Test: patterns (number 2) FAIL: gnu.testlet.java.text.DateFormatSymbols.Test: patterns (number 2)
FAIL: gnu.testlet.java.text.SimpleDateFormat.getAndSet2DigitYearStart: get2DigitYearStart() initial (number 1) FAIL: gnu.testlet.java.text.SimpleDateFormat.getAndSet2DigitYearStart: get2DigitYearStart() initial (number 1)
FAIL: gnu.testlet.java.text.DateFormatSymbols.Test: invalid locale (number 1) FAIL: gnu.testlet.java.text.DateFormatSymbols.Test: invalid locale (number 1)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment