aboutsummaryrefslogtreecommitdiff
path: root/libjava/javax
diff options
context:
space:
mode:
authorGraydon Hoare <graydon@gcc.gnu.org>2004-09-02 05:10:34 +0000
committerGraydon Hoare <graydon@gcc.gnu.org>2004-09-02 05:10:34 +0000
commit57579172585eae4fd6f57c0dbd55ea998ddfb63f (patch)
treea420c1005dbef38d790847b62b0d57eb9bc758cb /libjava/javax
parent1e8964cf94aa8b0e7176434d7b31fbf040416764 (diff)
downloadgcc-57579172585eae4fd6f57c0dbd55ea998ddfb63f.zip
gcc-57579172585eae4fd6f57c0dbd55ea998ddfb63f.tar.gz
gcc-57579172585eae4fd6f57c0dbd55ea998ddfb63f.tar.bz2
[multiple changes]
2004-08-31 Michael Koch <konqueror@gmx.de> * javax/swing/plaf/basic/BasicTextAreaUI.java (create): New method. * javax/swing/text/DefaultHighlighter.java (DefaultHighlightPainter.debugRect): Removed. * javax/swing/text/StyleContext.java (DEFAULT_STYLE): New field. 2004-08-31 Michael Koch <konqueror@gmx.de> * javax/swing/plaf/basic/BasicLookAndFeel.java (initComponentDefaults): Add keybindings for selection.backward and selection-forward for text components. * javax/swing/plaf/basic/BasicTextUI.java (paintSafely): Paint highlight only when something is actually selected. * javax/swing/text/DefaultCaret.java (handleHighlight): New method. (setSelectionVisible): Don't do anything when nothing changes. Handle highlight. (moveDot): Reimplemented. Handle highlight. (setDot): Set mark too. Handle highlight. (getSelectionPainter): New method. * javax/swing/text/DefaultEditorKit.java (defaultActions): Added new actions for text selection. * javax/swing/text/DefaultHighlighter.java (DefaultHighlightPainter): New inner class. (DefaultPainter): New field. (paint): Implemented. * javax/swing/text/PlainView.java (paint): Don't draw background here again. * javax/swing/text/Utilities.java (getTabbedTextWidth): Use width of ' ' instead of 'm' for tabsize. (drawTabbedText): Likewise. 2004-08-31 Graydon Hoare <graydon@redhat.com> * javax/swing/JComponent.java (resetKeyboardActions): Add null checks. 2004-08-31 Graydon Hoare <graydon@redhat.com> * javax/swing/DefaultButtonModel.java: Skip group notification when no group is set. 2004-08-31 Graydon Hoare <graydon@redhat.com> * javax/swing/JColorChooser.java: Make a couple inner classes static, for jikes. 2004-08-31 Michael Koch <konqueror@gmx.de> * javax/swing/plaf/basic/BasicTextUI.java (RottView.modelToView): New method. (UpdateHandler): Renamed from EventHandler. (updateHandler): Renamed from eventHandler. (modelToView): Implemented. * javax/swing/text/AbstractDocument.java (BranchElement.getElement): Return null for non-existing indeces. (BranchElement.getElementIndex): Return 0 in some corner cases. * javax/swing/text/FieldView.java (modelToView): New method. * javax/swing/text/PlainView.java (modelToView): Made public. 2004-08-31 Kim Ho <kho@redhat.com> * Makefile.am: New files. * Makefile.in: Regenerate. * gcj/Makefile.in: Regenerate. * include/Makefile.in: Regenerate. * java/awt/Color.java: Fix documentation. (RGBtoHSB): Use floats for conversions. * javax/swing/ButtonGroup.java: Run Jalopy. (setSelected): Reimplement. * javax/swing/DefaultButtonModel.java: Run Jalopy. (changeState): Let ButtonGroup know that the button is changing state. * javax/swing/JColorChooser.java: Implement. * javax/swing/JLabel.java: Run Jalopy. * javax/swing/JSpinner.java: Run Jalopy. (setValue): New method. * javax/swing/JTabbedPane.java: Run Jalopy. (removeTabAt): Call correct remove method. * javax/swing/SpinnerNumberModel.java: Run Jalopy. (getPreviousValue): Compare minimum value. * javax/swing/Timer.java: Run Jalopy. (run): Comment out println. * javax/swing/ToolTipManager.java: (mouseMoved): Get new tooltip text for location. * javax/swing/colorchooser/AbstractColorChooserPanel.java: Jalopy and Javadoc. * javax/swing/colorchooser/ColorChooserComponentFactory.java: Implement. * javax/swing/colorchooser/DefaultColorSelectionModel.java: Run Jalopy. (setSelectedColor): Fire ChangeEvent. * javax/swing/colorchooser/DefaultHSBChooserPanel.java: New file. Implement. * javax/swing/colorchooser/DefaultPreviewPanel.java: Ditto. * javax/swing/colorchooser/DefaultRGBChooserPanel.java: Ditto. * javax/swing/colorchooser/DefaultSwatchChooserPanel.java: Ditto. * javax/swing/plaf/basic/BasicArrowButton.java: (getArrow): Fix size of upward pointing button. * javax/swing/plaf/basic/BasicColorChooserUI.java: Implement. * javax/swing/plaf/basic/BasicSliderUI.java: (getWidthOfWidestLabel): Use preferred dimensions. (getHeightOfTallestLabel): Ditto. * javax/swing/plaf/basic/BasicSpinnerUI.java: Run Jalopy. (mousePressed): Disable changes to spinner if it is not enabled. * testsuite/Makefile.in: Regenerate. 2004-08-31 Michael Koch <konqueror@gmx.de> * javax/swing/plaf/basic/BasicTableHeaderUI.java, javax/swing/plaf/basic/BasicTableUI.java: Added copyright notice. 2004-08-31 Olga Rodimina <rodimina@redhat.com> * Makefile.am: Added new files. * Makefile.in: Regenerate. * javax/swing/ComboBoxEditor.java: Added javadocs. * javax/swing/ComboBoxModel.java: Likewise. * javax/swing/DefaultComboBoxModel.java: Implemented. * javax/swing/DefaultListCellRenderer.java: Added javadocs and ran through jalopy to fix formatting style. (getListCellRendererComponent): Use appropriate border if renderer has focus and use noFocusBorder when it doesn't. * javax/swing/JComboBox.java: Implemented. * javax/swing/JList.java: (locationToIndex): New Method. Implemented. (indexToLocation): New Method. * javax/swing/JPopupMenu.java: (visible): New field. (isVisible): Changed to use new field above. (setVisible): Likewise. * javax/swing/MutableComboBoxModel.java: Added javadocs. * javax/swing/plaf/basic/BasicArrowButton.java: (shadow): Changed default color to Color.gray. * javax/swing/plaf/basic/BasicComboBoxUI.java: New File. UI delegate for JComboBox. * javax/swing/plaf/basic/BasicComboPopup.java: New File. Popup menu containing list of JComboBox's items. * javax/swing/plaf/basic/BasicComboBoxEditor.java: New File. * javax/swing/plaf/basic/BasicComboBoxRenderer.java: New File. * javax/swing/plaf/basic/BasicComboBoxUI.java: New File. * javax/swing/plaf/basic/BasicComboPopup.java: New File. * javax/swing/plaf/basic/BasicPopupMenuUI.java: (popupMenuWillBecomeVisible): Set selected path to the first element only if it is of type MenuElement. Also fix formatting style. * javax/swing/plaf/basic/ComboPopup.java: Added javadocs and missing methods signatures. 2004-08-31 Michael Koch <konqueror@gmx.de> * javax/swing/text/AbstractDocument.java (createBranchElement): Use new constructor of BranchElement. (createLeafElement): Renamed arguments. (getRootElements): Implemented. (BranchElement.start): Removed. (BranchElement.end): Likewise. (BranchElement.BranchElement): Fixed arguments. (BranchElement.getEndOffset): Reimplemented. (BranchElement.getStartOffset): Likewis. * javax/swing/text/DefaultCaret.java (paint): Draw simple vertical line as caret instead of a rectangle. * javax/swing/text/JTextComponent.java (setText): Use doc directly. * javax/swing/text/PlainView.java (nextTabStop): Implemented. * javax/swing/text/Utilities.java (drawTabbedText): nextTabStop() returns an absolute x position. (getTabbedTextWidth): Likewise. 2004-08-31 Graydon Hoare <graydon@redhat.com> * java/awt/Component.java (isFocusTraversable): Predicate on isLightweight() (setFocusable): Set isFocusTraversableOverridden. (requestFocus): Predicate peer dispatch on !isLightweight() (requestFocusInWindow): Likewise. (dispatchEventImpl): Coordinate with KeyboardFocusManager. * java/awt/Container.java (dispatchEventImpl): Predicate on event mask. (LightweightDispatcher): Remove focus machinery. * java/awt/DefaultFocusTraversalPolicy.java (accept): Expand predicate to include isFocusable(). * java/awt/DefaultKeyboardFocusManager.java: Globally change c.dispatchEvent(e) to redispatchEvent(c,e) * java/awt/KeyboardFocusManager.java (redispatchEvent): Synchronize on event to prevent feedback. * javax/swing/AbstractButton.java (ButtonFocusListener): Remove class. (init): Set focusPainted, focusable. * javax/swing/ActionMap.java (get): Check parent for null. * javax/swing/InputMap.java (get): Likewise. * javax/swing/JComponent.java (inputMap_whenFocused): New InputMap. (inputMap_whenAncestorOfFocused): Likewise. (inputMap_whenInFocusedWindow): Likewise. (getActionForKeyStroke): Rewrite. (getConditionForKeystroke): Likewise. (ActionListenerProxy): New private class. (setInputMap): Implement. (getInputMap): Likewise. (setActionMap): Likewise. (getActionMap): Likewise. (processComponentKeyEvent): New empty method. (processKeyEvent): Implement. (processKeyBinding): Likewise. (resetKeyboardActions): Rewrite. * javax/swing/KeyStroke.java: Rewrite. * javax/swing/SwingUtilities.java (notifyAction): Implement. (replaceUIActionMap): Likewise. (replaceUIInputMap): Likewise. * javax/swing/plaf/basic/BasicButtonListener.java (focusGained): Implement. (focusLost): Repaint if focusPainted(). (installKeyboardActions): Install pressed / released actions. (uninstallKeyboardActions): Implement. * javax/swing/plaf/basic/BasicButtonUI.java (focusColor): New field. (installDefaults): Load focus color, install input map. (installKeyboardActions): Implement. (uninstallKeyboardActions): Likewise. (paintFocus): Rewrite. * javax/swing/plaf/basic/BasicLookAndFeel.java (Button.focus): New default, midPurple. * javax/swing/plaf/basic/BasicTextUI.java (kit): Make static. (installUI): Get doc from kit, load defaults. (getKeymapName): Implement. (createKeymap): Likewise. (installKeyboardActions): Likewise. (getInputMap): Likewise. (getActionMap): Likewise. (createActionMap): Likewise. * javax/swing/text/AbstractDocument.java (getStartPosition): Implement. (getEndPosition): Likewise. * javax/swing/text/DefaultEditorKit.java (CopyAction): New class. (CutAction): Likewise. (DefaultKeyTypedAction): Likewise. (InsertBreakAction): Likewise. (InsertContentAction): Likewise. (InsertTabAction): Likewise. (PasteAction): Likewise. (defaultActions): New static table. (createCaret): Implement. (getActions): Likewise. * javax/swing/text/JTextComponent.java (KeymapWrapper): New private class. (KeymapActionMap): Likewise. (DefaultKeymap): New class. (keymaps): New static table. (keymap): New field. (getKeymap): Implement. (removeKeymap): Likewise. (addKeymap): Likewise. (setKeymap): Likewise. (loadKeymap): Likewise. (getActions): Likewise. (margin): New field. (JTextComponent): Build and install default keymap. * javax/swing/text/TextAction.java (textAction): Call super properly. (getTextComponent): Implement. * javax/swing/text/Utilities.java (drawTabbedText): Adjust position by ascent. 2004-08-31 David Jee <djee@redhat.com> PR AWT/17156 * gnu/java/awt/peer/gtk/GtkMenuItemPeer.java (setEnabled): Make it a native method. * java/awt/DefaultKeyboardFocusManager.java (postProcessKeyEvent): Only post event if the menu item is active. * java/awt/MenuItem.java: Private field 'enabled' should be true by default. * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuItemPeer.c (setEnabled): New function. 2004-08-31 David Jee <djee@redhat.com> PR AWT/17059 * gnu/java/awt/peer/gtk/GtkMenuBarPeer.java (nativeSetHelpMenu): New native method declaration. (addHelpMenu): Call nativeSetHelpMenu(). (addMenu): Remove. * java/awt/MenuBar.java (setHelpMenu): Call addNotify() on the new help menu. (add): Call addNotify() on the new menu. (addNotify): Set the help menu if one exists. * java/awt/peer/MenuBarPeer.java (addMenu): Remove. * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuBarPeer.c (nativeSetHelpMenu): New method. 2004-08-31 Graydon Hoare <graydon@redhat.com> * Makefile.am: Add new files. * Makefile.in: Regenerate. * javax/swing/Box.java: Fix setting of layout in ctor. * javax/swing/JScrollPane.java: Scroll headers as well. * javax/swing/JTable.java: Reimplement. * javax/swing/JViewPort.java: Only add non-null children. * javax/swing/ScrollPaneLayout.java: Correct header calculations. * javax/swing/Timer.java: Fix stopping null waker. * javax/swing/plaf/basic/BasicTableHeaderUI.java: New file. * javax/swing/plaf/basic/BasicTableUI.java: New file. * javax/swing/table/DefaultTableCellRenderer.java: Configure. * javax/swing/table/DefaultTableColumnModel.java: Flesh out. * javax/swing/table/DefaultTableModel.java: Clean up. * javax/swing/table/JTableHeader.java: Implement. 2004-08-31 Mark Wielaard <mark@klomp.org> * javax/swing/JSpinner.java (getChangeListeners): Remove double semi-colon. 2004-08-31 Mark Wielaard <mark@klomp.org> * jni/gtk-peer/gnu_java_awt_peer_gtk_GdkClasspathFontPeerMetrics.c: Declare variables at top of functions/block. * jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics2D.c: Likewise. 2004-08-31 Mark Wielaard <mark@klomp.org> * java/lang/Rectangle.java (intersects): Check r.width and r.height first. 2004-08-31 Michael Koch <konqueror@gmx.de> * javax/swing/text/PlainView.java (selectedColor): New field. (unselectedColor): Likewise. (font): Likewise. (updateMetrics): New method. (lineToRect): Likewise. (modelToView): Likewise. (drawSelectedText): Use color from JTextComponent ad draw with Utilities class. (drawUnselectedText): Likewise. (paint): Initialize helper fields. * javax/swing/text/View.java (getChildAllocation): New method. (getViewIndex): Likewise. (getToolTipText): Likewise. 2004-08-31 Michael Koch <konqueror@gmx.de> * javax/swing/text/Utilities.java (drawTabbedText): Reimplemented. (getTabbedTextWidth): Likewise. 2004-08-31 Michael Koch <konqueror@gmx.de> * javax/swing/plaf/basic/BasicTextUI.java (installDefaults): Install caret and highlighter. (modelToView): Use Bias.Forward when calling sibling. * javax/swing/text/AbstractDocument.java (ElementEdit): Implements DocumentEvent.ElementChange. (ElementEdit.ElementEdit): New method. (ElementEdit.getChildrenAdded): Likewise. (ElementEdit.getChildrenRemoved): Likewise. (ElementEdit.getElement): Likewise. (ElementEdit.getIndex): Likewise. * javax/swing/text/DefaultCaret.java (color): Removed. (textComponent): Renamed from parent, made private. (selectionVisible): Renamed from vis_sel, made private. (blinkRate): Renamed from blink, made private. (magicCaretPosition): Renamed from magic, made private. (visible): Renamed from vis, made private. (dot): Made private. (mark): Likewise. (deinstall): Remove as MouseMotionListener. (install): Initialize textComponent first. Add as MouseMotionListener. (paint): Reimplemented. * javax/swing/text/JTextComponent.java (setCaret): Deinstall old caret, install new one and fire property change after setting property. (setHighlighter): Deinstall old highlighter, install new one and fire property change after setting property. (setCaretColor): Fire property change after setting property. (setDisabledTextColor): Likewise. (setSelectedTextColor): Likewise. (setSelectionColor): Likewise. (modelToView): New method. 2004-08-31 Michael Koch <konqueror@gmx.de> * javax/swing/text/AbstractDocument.java (getText): Simplified. * javax/swing/text/Segment.java (current): New field. (current): Reimplemented. (first): Likewise. (getIndex): Likewise. (last): Likewise. (next): Likewise. (previous): Likewise. (setIndex): Likewise. 2004-08-31 Michael Koch <konqueror@gmx.de> * javax/swing/plaf/basic/BasicButtonUI.java (defaultTextIconGap): Made protected. (defaultTextShiftOffset): Likewise. (textShiftOffset): New field. (clearTextShiftOffset): New method. (getTextShiftOffset): Likewise. (setTextShiftOffset): Likewise. 2004-08-31 Michael Koch <konqueror@gmx.de> * javax/swing/plaf/basic/BasicTextUI.java (installUI): Add eventHandler as property listener. (uninstallUI): remove eventHandler as propert listener. (installDefaults): Added comment. (installListeners): Likewise. (installKeyboardActions): Likewise. (uninstallDefaults): Likewise. (uninstallListeners): Likewise. (uninstallKeyboardActions): Likewise. 2004-08-31 Michael Koch <konqueror@gmx.de> * javax/swing/text/AbstractDocument.java: Fixed some typos in comments. (insertString): Reimplemented. (remove): Likewise. (replace): New method. (children): Dont use fully qualified class name. (DefaultDocumentEvent.offset): Renamed from off. (DefaultDocumentEvent.length): Renamed from len. (DefaultDocumentEvent.type): New field. (DefaultDocumentEvent.DefaultDocumentEvent): New constructor. (DefaultDocumentEvent.getType): Implemented. 2004-08-31 Michael Koch <konqueror@gmx.de> * javax/swing/plaf/basic/BasicTextUI.java (RootView.textComponent): Removed. (RootView.RootView): Don't initialize textComponent. (RootView.getViewFactory): New method. (EventHandler): New inner class. (rootView): Initialize at instance creation. (eventHandler): New field. (installUI): Don't create view hierarchy directly, call modelChanged() instead. (modelChanged): New method. * javax/swing/text/JTextComponent.java (setDocument): Fire property change event. 2004-08-31 Michael Koch <konqueror@gmx.de> * javax/swing/plaf/basic/BasicTextUI.java (RootView.paint): Removed debug output. (paintSafely): Draw highlighter before text. (paintBackground): Use background color of text component. * javax/swing/plaf/basic/BasicToggleButtonUI.java: Reformatted. 2004-08-31 Michael Koch <konqueror@gmx.de> * javax/swing/plaf/basic/BasicToolBarUI.java (BasicToolBarUI): Fixed arguments for constructor. (createUI): Fixed creation of object. 2004-08-31 Michael Koch <konqueror@gmx.de> * javax/swing/DefaultListSelectionModel.java (fireValueChanged): Renamed from fireSelectionValueChanged, made protected. 2004-08-31 Michael Koch <konqueror@gmx.de> * javax/swing/text/TabSet.java (TabSet): Implements java.io.Serializable. * javax/swing/text/TabStop.java (TabStop): Implements java.io.Serializable. (TabStop): Made public. 2004-08-31 Michael Koch <konqueror@gmx.de> * javax/swing/JComponent.java (setUI): Fire PropertyChange. * javax/swing/JLabel.java (text): Renamed from labelText. (horizontalAlignment): New default vlaue. (icon): Renamed from activeIcon. (displayedMnemonic): Renamed from mnemonicKey, added default value. (displayedMnemonicIndex): Renamed from underlineChar. (setDisplayedMnemonic): Reimplemented. * javax/swing/JRadioButton.java (JRadioButton): New constructors. * javax/swing/JTextField.java (JTextField): Throw exception if colums < 0, initialitialz this.columns directly and initialize document with text conditionally. 2004-08-31 Michael Koch <konqueror@gmx.de> * javax/swing/plaf/basic/BasicFormattedTextFieldUI.java, javax/swing/plaf/basic/BasicPasswordFieldUI.java, javax/swing/plaf/basic/BasicTextAreaUI.java: New files. * javax/swing/text/FieldView.java (paint): Just call super method for now. * Makefile.am: Added new files. * Makefile.in: Regenerated. 2004-08-31 Ka-Hing Cheung <kahing@javabsp.org> * javax/swing/AbstractSpinnerModel.java, javax/swing/JSpinner.java, javax/swing/SpinnerNumberModel.java, javax/swing/plaf/basic/BasicSpinnerUI.java: New files. * javax/swing/plaf/basic/BasicLookAndFeel.java (initClassDefaults): Added defaults for BasicSpinnerUI. 2004-08-31 Michael Koch <konqueror@gmx.de> * Makefile.am: Added new files. * Makefile.in: Regenerated. 2004-08-31 Michael Koch <konqueror@gmx.de> * javax/swing/TransferHandler.java, javax/swing/plaf/basic/ComboPopup.java: New files * Makefile.am: Added javax/swing/TransferHandler.java and javax/swing/plaf/basic/ComboPopup.java * Makefile.in: Regenerated. 2004-08-31 Roman Kennke <roman@ontographics.com> * javax/swing/text/Utilities.java: New file. 2004-08-31 Michael Koch <konqueror@gmx.de> * Makefile.am: Added javax/swing/text/Utilities.java. * Makefile.in: Regenerated. 2004-08-31 Graydon Hoare <graydon@redhat.com> * javax/swing/text/SimpleAttributeSet.java: New file. * javax/swing/text/StyleConstants.java: New file. * javax/swing/text/StyleContext.java: New file. * javax/swing/text/TabSet.java: New file. * javax/swing/text/TabStop.java: New file. * javax/swing/text/AbstactDocument.java: (AbstractElement): Implement attribute support. * javax/swing/text/AttributeSet.java (NameAttribute): New static field. (ResolveAttribute): New static field. * Makefile.am: Update for new files. * Makefile.in: Regenerate. 2004-08-31 Craig Black <craig.black@aonix.com> * gnu/java/awt/peer/gtk/GdkGraphics.java (drawImage): Add support for scaling pixmaps. * jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics.c (copyAndScalePixmap): New native method. 2004-08-31 Thomas Fitzsimmons <fitzsim@redhat.com> PR AWT/16121 * jni/gtk-peer/gthread-jni.c: Include stdio.h. Eliminate type-punning compiler warnings using unions. (throw): Replace bzero with memset. 2004-08-31 Andreas Tobler <a.tobler@schweiz.ch> Thomas Fitzsimmons <fitzsim@redhat.com> * jni/gtk-peer/gnu_java_awt_peer_gtk_GdkPixbufDecoder.c: Move NSA_PB macros to gtkpeer.h. Include gtkpeer.h. * jni/gtk-peer/gtkpeer.h: Move NSA_PB macros here. * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c (nativeSetIconImageFromDecoder): Use NSA_GET_PB_PTR macro. 2004-08-31 Mark Wielaard <mark@klomp.org> * native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkPixbufDecoder.c: #include gdk.h, not gtk.h. #include jni.h, native_state.h, string.h and stdlib.h, not gtkpeer.h. (*vm): New static variable. (areaPreparedID): Make static. (areaUpdatedID): Likewise. (area_prepared): Get and use JNIEnv through stored JavaVM *vm. (area_prepared): Likewise. (area_updated): Likewise. (closed): Likewise. (initStaticState): Initialize *vm javaVM. (pumpBytes): Use given env, not global gdk_env. 2004-08-31 Mark Wielaard <mark@klomp.org> * java/awt/geom/CubicCurve2D.java (solveCubic): Removed duplicate comments. 2004-08-31 Sven de Marothy <sven@physto.se> * java/awt/geom/CubicCurve2D.java: Reindent. (contains): Implemented. (intersects): Implemented. * java/awt/geom/QuadCurve2D.java: Likewise. * java/awt/geom/GeneralPath.java: Reindent and document. Fully (re)implemented using separate xpoints and ypoints float[] coords. * java/awt/geom/RoundRectangle2D.java: Several bugfixes (Bug #6007). 2004-08-31 Michael Koch <konqueror@gmx.de> * javax/swing/JMenuItem.java (getMenuDragMouseListeners): New method. (getMenuKeyListeners): Likewise. 2004-08-31 Michael Koch <konqueror@gmx.de> * javax/swing/AbstractButton.java (model): Made protected. (actionListener): Likewise. (changeListener): Likewise. (itemListener): Likewise. (multiClickThreshhold): New field. (getActionListeners): New method. (getChangeListeners): Likewise. (getItemListeners): Likewise. (fireItemStateChanged): Simplified implementation. (fireActionPerformed): Likewise. (fireStateChanged): Likewise. (getMultiClickThreshhold): New method. (setMultiClickThreshhold): Likewise. 2004-08-31 Tom Tromey <tromey@redhat.com> * java/awt/image/Kernel.java (clone): Use super.clone(). 2004-08-31 David Jee <djee@redhat.com> PR AWT/16682 * gnu/java/awt/peer/gtk/GtkFramePeer.java (nativeSetIconImage): Rename to nativeSetIconImageFromDecoder. (nativeSetIconImageFromData): New native method declaration. (setIconImage): Handle images not produced from GdkPixbufDecoder. * gnu/java/awt/peer/gtk/GtkImage.java (getPixelCache): New method. (getColorModel): New method. * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c (nativeSetIconImage): Rename to nativeSetIconImageFromDecoder. (free_pixbuf_data): New helper function. (nativeSetIconImageFromData): New function. 2004-08-31 Graydon Hoare <graydon@redhat.com> PR SWING/16576 * javax/swing/JLayeredPane.java (setLayer): Permit changing layer after addition. (setPosition): Permit over-length positions. (layerToRange): Compare intValue()s. * javax/swing/Box.java (createHorizontalBox): Implement. (createRigidArea): Likewise. (createVerticalBox): Likewise. 2004-08-31 Kim Ho <kho@redhat.com> * java/awt/Component.java: (processMouseEvent): Consume event after listeners process it. (processMouseMotionEvent): ditto. (processMouseWheelEvent): ditto. * java/awt/Container.java: (acquireComponentForMouseEvent): Do not dispatch to events that have been removed from the Container. (handleEvent): Consume the MouseEvents. * javax/swing/RepaintManager.java: (paintDirtyRegions): Do not add to list of damaged areas if the component has no root. 2004-08-31 Michael Koch <konqueror@gmx.de> * javax/swing/plaf/basic/BasicMenuItemUI.java: Clean ip imports. 2004-08-31 Mark Wielaard <mark@klomp.org> * gnu/java/awt/peer/gtk/GtkToolkit.java (getFontPeer): Don't return null when a MissingResourceException is thrown. Should never happen. 2004-08-31 Mark Wielaard <mark@klomp.org> * java/awt/EventQueue.java (postEvent): Throw NullPointerException when argument is null. 2004-08-31 Mark Wielaard <mark@klomp.org> * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c (Java_gnu_java_awt_peer_gtk_GtkComponentPeer_addExposeFilter): Define hid at start of function. (Java_gnu_java_awt_peer_gtk_GtkComponentPeer_removeExposeFilter): Likewise. 2004-08-31 Mark Wielaard <mark@klomp.org> * gnu/java/awt/EmbeddedWindow.java: Reindent. * javax/swing/JButton.java: Reindent. * javax/swing/JCheckBox.java: Reindent. 2004-08-31 Mark Wielaard <mark@klomp.org> * Makefile.am (gtk_c_source_files): Added jni/gtk-peer/gnu_java_awt_peer_gtk_GThreadNativeMethodRunner.c. (gtk_awt_peer_sources): Added gnu/java/awt/peer/gtk/GThreadMutex.java and gnu/java/awt/peer/gtk/GThreadNativeMethodRunner.java. * Makefile.in: Regenerated. 2004-08-31 Archie Cobbs <archie@dellroad.org> * jni/gtk-peer/gthread-jni.c: don't #include nonexistent files 2004-08-31 Steven Augart <augart@watson.ibm.com> * jni/gtk-peer/gthread-jni.c (c-font-lock-extra-types): Added jfieldID, jmethodID. 2004-08-31 Mark Wielaard <mark@klomp.org> * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMainThread.c (Java_gnu_java_awt_peer_gtk_GtkMainThread_gtkInit): Initialize gdk_env before calling any gdk or gtk function. * gnu/java/awt/peer/gtk/GtkMainThread.java (gtkInitCalled): New field. (GtkMainThread): Call wait() in while loop waiting for gtkInitCalled. (run): Set gtkInitCalled. 2004-08-31 Steven Augart <augart@watson.ibm.com> * gnu/java/awt/peer/gtk/GtkMainThread.java (run): Pass the value of the gnu.classpath.awt.gtk.portable.native.sync system property to C. * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMainThread.c (Java_gnu_java_awt_peer_gtk_GtkMainThread_gtkInit): New argument, portableNativeSync. Delegate PORTABLE_NATIVE_SYNC work to init_glib_threads. (init_glib_threads): New function. 2004-08-31 Mark Wielaard <mark@klomp.org> * jni/gtk-peer/gthread-jni.c: Define MIN_, MAX_ and NORM_ PRIORITY when not already defined in header file. 2004-08-31 Mark Wielaard <mark@klomp.org> * jni/gtk-peer/gthread-jni.c (setup_cache): Call ExceptionOccurred, not ExceptionCheck, when we don't have JNI 1.2. 2004-08-31 Steven Augart <augart@watson.ibm.com> * gnu/native/jni/gtk-peer/gthread-jni.c: Indentation fixes. Implemented missing functions for GTK2. Added error handling. Renamed static functions out of the g_ namespace. Added TRACE_API_CALLS, EXPLAIN_TROUBLE, EXPLAIN_BROKEN, EXPLAIN_BADLY_BROKEN, and DELETE_LOCAL_REFS options. Rewrote global-reference code. Eliminated cascading errors. (mutex_trylock_jni_impl) Fully implemented. (cond_timed_wait_jni_impl) Went from millisecond to microsecond resolution. (setup_cache) New function. (mutex_cond_wait_jni_impl, mutex_cond_timed_wait_jni_impl) Fixed bug where they were not unlocking the GMutex associated with the condition variable during the wait on that condition variable. * native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMainThread.c, native/jni/gtk-peer/gthread-jni.c, native/jni/gtk-peer/gthread-jni.h (g_thread_jni_functions): Renamed to ... (portable_native_sync_jni_functions): this name. (gdk_vm): Renamed to... (the_vm): this name. * native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMainThread.c (gdk_vm): Removed duplicate definition. (gtkInit): Removed stray message to stdout. (gtkInit): Use g_malloc and g_free instead of malloc and free. (gtkInit): Fix a const assignment bug. (gtkInit): Simplified code. * gnu/java/awt/peer/gtk/GThreadNativeMethodRunner.java, native/jni/gtk-peer/gnu_java_awt_peer_gtk_GThreadNativeMethodRunner.c, native/jni/gtk-peer/gnu_java_awt_peer_gtk_GThreadNativeMethodRunner.h, gnu/java/awt/peer/gtk/GThreadMutex.java: New files. 2004-08-31 Mark Wielaard <mark@klomp.org> * javax/swing/Box.java: Put FIXME comment above class declaration. * javax/swing/JButton.java: Remove illegal L&F HTML from comments. * javax/swing/JCheckBox.java: Likewise. * javax/swing/JDialog.java: Likewise. * javax/swing/JRadioButton.java: Likewise. * javax/swing/JToggleButton.java: Likewise. * javax/swing/UIManager.java: Likewise. * javax/swing/border/TitledBorder.java: Likewise. * javax/swing/plaf/basic/BasicLabelUI.java: Likewise. * javax/swing/plaf/basic/BasicLookAndFeel.java: Likewise. * javax/swing/plaf/basic/BasicPopupMenuSeparatorUI.java: Likewise. * javax/swing/plaf/basic/BasicProgressBarUI.java: Likewise. * javax/swing/plaf/basic/BasicScrollBarUI.java: Likewise. * javax/swing/plaf/basic/BasicSeparatorUI.java: Likewise. * javax/swing/text/JTextComponent.java: Likewise. 2004-08-31 David Jee <djee@redhat.com> PR AWT/16682 * gnu/java/awt/peer/gtk/GtkFramePeer.java (setIconImage): Add a FIXME for unhandled cases. 2004-08-31 Thomas Fitzsimmons <fitzsim@redhat.com> PR AWT/16040 * gnu/awt/LightweightRedirector.java: Call getModifiersEx, not getModifiers. Replace old button masks with new ones. * gnu/awt/xlib/XEventLoop.java: Likewise. * gnu/java/awt/peer/gtk/GtkButtonPeer.java: Likewise. * gnu/java/awt/peer/gtk/GtkComponentPeer.java, jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c: Likewise. * gnu/java/awt/peer/gtk/GtkListPeer.java: Likewise. * gnu/java/awt/peer/gtk/GtkTextFieldPeer.java: Likewise. * java/awt/AWTKeyStroke.java: Remove old modifier masks. * java/awt/Component.java: Replace old modifier masks with new ones. * java/awt/Container.java: Call getModifiersEx, not getModifiers. * java/awt/DefaultKeyboardFocusManager.java: Likewise. Remove old modifier masks. * javax/swing/JMenuItem.java: Replace old button masks with new ones. * javax/swing/KeyStroke.java: Call getModifiersEx, not getModifiers. * javax/swing/SwingUtilities.java: Likewise. * javax/swing/plaf/basic/BasicButtonListener.java: Likewise. * javax/swing/plaf/basic/BasicInternalFrameUI.java: Likewise. * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkEvents.c: Replace old mask macros with new ones. * jni/gtk-peer/gtkpeer.h: Replace old button and modifier mask macros with new ones representing new masks. 2004-08-31 Craig Black <craig.black@aonix.com> * gnu/java/awt/peer/gtk/GdkGraphics.java (drawRoundRect): Implemented. (fillRoundRect): Implemented. * gnu/java/awt/peer/gtk/GdkGraphics2D.java (drawRoundRect): Reimplemented to match GdkGraphics. (fillRoundRect): Reimplemented to match GdkGraphics. 2004-08-31 Mark Wielaard <mark@klomp.org> * Makefile.in: Regenerated. 2004-08-31 Michael Koch <konqueror@gmx.de> * gnu/java/awt/EmbeddedWindow.java (addNotify): Use AccessController to allow execution of privileged code. 2004-08-31 Michael Koch <konqueror@gmx.de> * gnu/java/awt/EmbeddedWindow.java (static): Removed. (addNotify): Set peer via reflection. (setWindowPeer): Removed. * gnu/java/awt/natEmbeddedWindow.cc: Removed. * Makefile.am (nat_source_files): Removed gnu/java/awt/natEmbeddedWindow.cc. 2004-08-31 Bryce McKinlay <mckinlay@redhat.com> * Makefile.am: Add gnu/java/security/action/GetPropertyAction.java and gnu/java/security/action/SetAccessibleAction.java. 2004-08-31 Bryce McKinlay <mckinlay@redhat.com> * gnu/java/security/action/GetPropertyAction.java (setParameters): Renamed from 'setName'. New 2-argument form with default value. (run): Pass default 'value' parameter to System.getProperty(). * gnu/java/security/action/SetAccessibleAction.java: Fix javadoc typos. 2004-08-31 Bryce McKinlay <mckinlay@redhat.com> * gnu/java/security/action/GetPropertyAction.java: New class. * gnu/java/security/action/SetAccessibleAction.java: New class. 2004-08-31 David Jee <djee@redhat.com> * gnu/java/awt/peer/gtk/GtkFramePeer.java (setIconImage): Check if image is null. 2004-08-31 David Jee <djee@redhat.com> * gnu/java/awt/peer/gtk/GtkFramePeer.java (create): Set the icon image. (nativeSetIconImage): New native method declaration. (setIconImage): Implement. * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c (nativeSetIconImage): New function. 2004-08-31 Dalibor Topic <robilad@kaffe.org> * native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkFileDialogPeer.c (filenameFilterCallback): Declare local variable accepted before use. 2004-08-31 Dalibor Topic <robilad@kaffe.org> * gnu/java/awt/ComponentDataBlitOp.java: Cleaned up imports. 2004-08-31 Tom Tromey <tromey@redhat.com> * gnu/java/awt/peer/GLightweightPeer.java, gnu/java/awt/peer/gtk/GdkGraphics2D.java, gnu/java/awt/peer/gtk/GtkComponentPeer.java, javax/swing/JScrollPane.java: Removed redundant imports. 2004-08-31 David Jee <djee@redhat.com> * java/awt/DefaultKeyboardFocusManager.java (postProcessKeyEvent): Only activate MenuShortcuts on KEY_PRESSED event. Fix shift modifier checking. * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuPeer.c (accel_attach): Remove. (setupAccelGroup): Remove calls to accel_attach. 2004-08-31 Thomas Fitzsimmons <fitzsim@redhat.com> * gnu/java/awt/peer/gtk/GtkArg.java: Remove file. * gnu/java/awt/peer/gtk/GtkArgList.java: Remove file. * Makefile.am (gtk_awt_peer_sources): Remove GtkArg.java and GtkArgList.java. (gtk_c_files): Use CAIRO_CFLAGS and PANGOFT2_CFLAGS, not _LIBS. * Makefile.in: Regenerate. * gnu/java/awt/peer/gtk/GtkButtonPeer.java, jni/gtk-peer/gnu_java_awt_peer_gtk_GtkButtonPeer.c (create(String)): New method. (create): Call new create method. (getArgs): Remove method. * gnu/java/awt/peer/gtk/GtkCheckboxPeer.java, jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCheckboxPeer.c (nativeCreate): Rename to create. (gtkSetLabel): Rename to gtkButtonSetLabel. (gtkToggleButtonSetActive): New method. (create): Call gtkToggleButtonSetActive and gtkButtonSetLabel. (setState): Replace set call with gtkToggleButtonSetActive. (setLabel): Replace gtkSetLabel call with gtkButtonSetLabel. (getArgs): Remove method. * gnu/java/awt/peer/gtk/GtkComponentPeer.java, jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c (gtkWidgetSetSensitive): New method. (gtkWidgetSetParent): Likewise. (GtkComponentPeer): Call setParent, setComponentBounds and setVisibleAndEnabled. (setParent): New method. (setComponentBounds): New method. (setVisibleAndEnabled): New method. (setEnabled): Call gtkWidgetSetSensitive. (getArgs): Remove method. Remove all set methods. * gnu/java/awt/peer/gtk/GtkDialogPeer.java (create): Call gtkWindowSetModal, setTitle and setResizable. (getArgs): Remove method. * gnu/java/awt/peer/gtk/GtkFileDialogPeer.java (setComponentBounds): New method. * gnu/java/awt/peer/gtk/GtkFramePeer.java (setResizable): Replace set call with gtkWindowSetResizable. (getArgs): Remove method. (create): Call setTitle and setResizable. * gnu/java/awt/peer/gtk/GtkWindowPeer.java, jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c (gtkWindowSetTitle): New method. (gtkWindowSetResizable): New method. (gtkWindowSetModal): New method. (setParent): New method. (setVisibleAndEnabled): New method. (getArgs): Remove method. (setTitle): Call gtkWindowSetTitle. (setResizable): Call gtkWindowSetResizable. * jni/gtk-peer/gtkpeer.h [DEBUG_LOCKING]: New define to turn on and off locking instrumentation. 2004-08-31 Kim Ho <kho@redhat.com> * Makefile.am: Add new file. * Makefile.in: Regenerate. * gcj/Makefile.in: Regenerate * include/Makefile.in: * java/awt/Container.java: (acquireComponentForMouseEvent): Respect the event mask when looking for candidate. * javax/swing/JComponent.java: Remove toolTip field. (createToolTip): Create a tooltip on demand. (setToolTipText): Register with the ToolTipManager. (getToolTipText(MouseEvent)): Return getToolTipText(). * javax/swing/JToolTip.java: Implement. * javax/swing/Timer.java: Jalopy. (restart): Call stop, then start. (stop): Interrupt the timer rather than wait for the timer to come to a stop naturally. * javax/swing/ToolTipManager.java: Implement. * javax/swing/plaf/basic/BasicLookAndFeel.java: Change ToolTip.background color. * javax/swing/plaf/basic/BasicToolTipUI.java: Implement. * testsuite/Makefile.in: Regenerate 2004-08-31 Jerry Quinn <jlquinn@optonline.net> * java/awt/image/DirectColorModel.java (DirectColorModel): Fix constructor param comments. 2004-08-31 Thomas Fitzsimmons <fitzsim@redhat.com> * java/awt/Component.java: Document AWT 1.0 event handler methods. 2004-08-31 Roman Kennke <roman@ontographics.com> * javax/swing/Box.java: (createGlue): Implemented (createHorizontalGlue): Implemented (createHorizontalStrut): Implemented (createVerticalGlue): Implemented (createVerticalStrut): Implemented 2004-08-31 David Jee <djee@redhat.com> * gnu/java/awt/peer/gtk/GtkChoicePeer.java (GtkChoicePeer): Do not automatically select first item. (getHistory): Remove. (nativeGetSelected): New method. (nativeRemoveAll): New method. (add): Use nativeGetSelected() instead of getHistory(). (remove): Likewise. (removeAll): Call nativeRemoveAll(). * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkChoicePeer.c (create): Migrate to GtkComboBox. (append): Likewise. (nativeAdd): Likewise. (nativeRemove): Likewise. (select): Likewise. (nativeRemoveAll): New method. (nativeGetSelected): New method. (selection_changed): New method. (getHistory): Remove. (item_activate): Remove. (item_removed): Remove. (connect_choice_item_selectable_hook): Remove. 2004-08-31 Thomas Fitzsimmons <fitzsim@redhat.com> * gnu/java/awt/peer/gtk/GtkTextFieldPeer.java (create): Use tf variable in setEditable call. * gnu/java/awt/peer/gtk/GtkTextFieldPeer.java, jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextFieldPeer.c (gtkWidgetSetBackground): New method. (gtkWidgetSetForeground): Likewise. (create): Set peer's editable state based on awtComponent's. * java/awt/Button.java (Button()): Use empty string rather than null in no-label constructor. 2004-08-31 Roman Kennke <roman@ontographics.com> * javax/swing/BoxLayout.java: Reimplement. 2004-08-31 Thomas Fitzsimmons <fitzsim@redhat.com> * gnu/java/awt/peer/gtk/GdkGraphics.java, gnu_java_awt_peer_gtk_GdkGraphics.c (initState(GtkComponentPeer)): Don't return array of colour values. (GdkGraphics(int,int)): Set default font to size 12. (GdkGraphics(GtkComponentPeer)): Set graphics colour to component's foreground colour. * gnu/java/awt/peer/gtk/GdkGraphics2D.java, gnu_java_awt_peer_gtk_GdkGraphics2D.c (initState(GtkComponentPeer)): Don't return array of colour values. (GdkGraphics2D(GtkComponentPeer)): Set foreground and background colours to component's colours. (current_colors_of_widget): Remove function. * gnu/java/awt/peer/gtk/GtkOffScreenImage.java (getGraphics): Return a new graphics object. * java/awt/Font.java (toString): Fix format. * java/awt/Graphics.java (toString): Likewise. 2004-08-31 Craig Black <craig.black@aonix.com> * native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuPeer.c (addTearOff): New function. * gnu/java/awt/peer/gtk/GtkMenuPeer.java (addTearOff): New native method. (init): Call addTearOff() when menu.isTearOff(). 2004-08-31 Bryce McKinlay <mckinlay@redhat.com> * gnu/java/awt/ClasspathToolkit.java (createImageProducer): New. Default implementation. * gnu/java/awt/peer/gtk/GtkToolkit.java (createImageProducer): New. Implement using GdkPixbufDecoder. 2004-08-31 David Jee <djee@redhat.com> * gnu/java/awt/peer/gtk/GtkComponentPeer.java (GtkComponentPeer): Use gtkWidgetGetPreferredDimensions() for setting the size of GtkFileDialogPeers. * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c (gtkWidgetGetPreferredDimensions): For widgets extending GtkWindow, use their default sizes rather than their natural requisitions. 2004-08-31 Michael Koch <konqueror@gmx.de> * javax/swing/JFormattedTextField.java (JFormattedTextField): Implemented. * javax/swing/text/DefaultEditorKit.java (BeepAction): New inner class. * javax/swing/text/Segment.java (partialReturn): New field. (setPartialReturn): New method. (isPartialReturn): Likewise. * javax/swing/text/View.java (createFragment): Fixed typo. (getStartOffset): New method. (getEndOffset): Likewise. 2004-08-31 Michael Koch <konqueror@gmx.de> * javax/swing/table/DefaultTableColumnModel.java (serialVersionUID): Made private. (listenerList): Initialize. (changeEvent): Initialize. * javax/swing/table/JTableHeader.java (JTableHeader): New constructors. (createDefaultColumnModel): New method. * javax/swing/table/TableColumn.java (setHeaderRenderer): Simplified code. (setCellRenderer): Likewise. (setWidth): Likewise. From-SVN: r86956
Diffstat (limited to 'libjava/javax')
-rw-r--r--libjava/javax/swing/AbstractButton.java138
-rw-r--r--libjava/javax/swing/ActionMap.java4
-rw-r--r--libjava/javax/swing/Box.java115
-rw-r--r--libjava/javax/swing/BoxLayout.java229
-rw-r--r--libjava/javax/swing/ButtonGroup.java76
-rw-r--r--libjava/javax/swing/ComboBoxEditor.java95
-rw-r--r--libjava/javax/swing/ComboBoxModel.java46
-rw-r--r--libjava/javax/swing/DefaultButtonModel.java267
-rw-r--r--libjava/javax/swing/DefaultComboBoxModel.java317
-rw-r--r--libjava/javax/swing/DefaultListCellRenderer.java117
-rw-r--r--libjava/javax/swing/DefaultListSelectionModel.java14
-rw-r--r--libjava/javax/swing/InputMap.java6
-rw-r--r--libjava/javax/swing/JCheckBox.java2
-rw-r--r--libjava/javax/swing/JColorChooser.java932
-rw-r--r--libjava/javax/swing/JComboBox.java1791
-rw-r--r--libjava/javax/swing/JComponent.java308
-rw-r--r--libjava/javax/swing/JFormattedTextField.java4
-rw-r--r--libjava/javax/swing/JLabel.java194
-rw-r--r--libjava/javax/swing/JLayeredPane.java7
-rw-r--r--libjava/javax/swing/JList.java22
-rw-r--r--libjava/javax/swing/JMenuItem.java37
-rw-r--r--libjava/javax/swing/JPopupMenu.java9
-rw-r--r--libjava/javax/swing/JRadioButton.java64
-rw-r--r--libjava/javax/swing/JScrollPane.java18
-rw-r--r--libjava/javax/swing/JTabbedPane.java135
-rw-r--r--libjava/javax/swing/JTable.java1388
-rw-r--r--libjava/javax/swing/JTextField.java10
-rw-r--r--libjava/javax/swing/JToolTip.java147
-rw-r--r--libjava/javax/swing/JViewport.java9
-rw-r--r--libjava/javax/swing/KeyStroke.java288
-rw-r--r--libjava/javax/swing/MutableComboBoxModel.java70
-rw-r--r--libjava/javax/swing/RepaintManager.java5
-rw-r--r--libjava/javax/swing/ScrollPaneLayout.java6
-rw-r--r--libjava/javax/swing/SwingUtilities.java111
-rw-r--r--libjava/javax/swing/Timer.java283
-rw-r--r--libjava/javax/swing/ToolTipManager.java685
-rw-r--r--libjava/javax/swing/UIManager.java2
-rw-r--r--libjava/javax/swing/colorchooser/AbstractColorChooserPanel.java190
-rw-r--r--libjava/javax/swing/colorchooser/ColorChooserComponentFactory.java78
-rw-r--r--libjava/javax/swing/colorchooser/DefaultColorSelectionModel.java73
-rw-r--r--libjava/javax/swing/plaf/basic/BasicArrowButton.java22
-rw-r--r--libjava/javax/swing/plaf/basic/BasicButtonListener.java46
-rw-r--r--libjava/javax/swing/plaf/basic/BasicButtonUI.java63
-rw-r--r--libjava/javax/swing/plaf/basic/BasicInternalFrameUI.java4
-rw-r--r--libjava/javax/swing/plaf/basic/BasicLookAndFeel.java14
-rw-r--r--libjava/javax/swing/plaf/basic/BasicPopupMenuUI.java47
-rw-r--r--libjava/javax/swing/plaf/basic/BasicSliderUI.java13
-rw-r--r--libjava/javax/swing/plaf/basic/BasicTextUI.java189
-rw-r--r--libjava/javax/swing/plaf/basic/BasicToggleButtonUI.java12
-rw-r--r--libjava/javax/swing/plaf/basic/BasicToolBarUI.java18
-rw-r--r--libjava/javax/swing/table/DefaultTableCellRenderer.java23
-rw-r--r--libjava/javax/swing/table/DefaultTableColumnModel.java258
-rw-r--r--libjava/javax/swing/table/DefaultTableModel.java826
-rw-r--r--libjava/javax/swing/table/JTableHeader.java532
-rw-r--r--libjava/javax/swing/table/TableColumn.java88
-rw-r--r--libjava/javax/swing/text/AbstractDocument.java323
-rw-r--r--libjava/javax/swing/text/AttributeSet.java23
-rw-r--r--libjava/javax/swing/text/DefaultCaret.java134
-rw-r--r--libjava/javax/swing/text/DefaultEditorKit.java243
-rw-r--r--libjava/javax/swing/text/DefaultHighlighter.java100
-rw-r--r--libjava/javax/swing/text/FieldView.java8
-rw-r--r--libjava/javax/swing/text/JTextComponent.java584
-rw-r--r--libjava/javax/swing/text/PlainView.java100
-rw-r--r--libjava/javax/swing/text/Segment.java143
-rw-r--r--libjava/javax/swing/text/TextAction.java8
-rw-r--r--libjava/javax/swing/text/View.java45
66 files changed, 8603 insertions, 3555 deletions
diff --git a/libjava/javax/swing/AbstractButton.java b/libjava/javax/swing/AbstractButton.java
index 3c2a4cd..11ab198 100644
--- a/libjava/javax/swing/AbstractButton.java
+++ b/libjava/javax/swing/AbstractButton.java
@@ -51,7 +51,6 @@ import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
-import java.util.EventListener;
import javax.accessibility.AccessibleAction;
import javax.accessibility.AccessibleIcon;
@@ -214,24 +213,28 @@ public abstract class AbstractButton extends JComponent
Action action;
/** The button's current state. */
- ButtonModel model;
+ protected ButtonModel model;
/** The margin between the button's border and its label. */
Insets margin;
- /** a hint to the look and feel class, suggesting which character in the
+ /** A hint to the look and feel class, suggesting which character in the
* button's label should be underlined when drawing the label. */
int mnemonicIndex;
/** Listener the button uses to receive ActionEvents from its model. */
- ActionListener actionListener;
+ protected ActionListener actionListener;
/** Listener the button uses to receive ItemEvents from its model. */
- ItemListener itemListener;
+ protected ItemListener itemListener;
/** Listener the button uses to receive ChangeEvents from its model. */
- ChangeListener changeListener;
+ protected ChangeListener changeListener;
+ /** The time in miliseconds in which clicks get coalesced into a single
+ * <code>ActionEvent</code>. */
+ long multiClickThreshhold;
+
/** Listener the button uses to receive PropertyChangeEvents from its
Action. */
PropertyChangeListener actionPropertyChangeListener;
@@ -296,9 +299,9 @@ public abstract class AbstractButton extends JComponent
/** Fired in a PropertyChangeEvent when the "verticalTextPosition" property changes. */
public static final String VERTICAL_TEXT_POSITION_CHANGED_PROPERTY = "verticalTextPosition";
- /**
+ /**
* A Java Accessibility extension of the AbstractButton.
- */
+ */
protected abstract class AccessibleAbstractButton
extends AccessibleJComponent implements AccessibleAction, AccessibleValue,
AccessibleText
@@ -430,7 +433,7 @@ public abstract class AbstractButton extends JComponent
}
public String getSelectedText()
- {
+ {
return null; // TODO
}
@@ -440,33 +443,6 @@ public abstract class AbstractButton extends JComponent
}
}
- /**
- * Helper class used to subscribe to FocusEvents received by the button.
- */
- private class ButtonFocusListener implements FocusListener
- {
- /**
- * Possibly repaint the model in response to loss of focus.
- *
- * @param event The loss-of-focus event
- */
- public void focusLost(FocusEvent event)
- {
- if (AbstractButton.this.isFocusPainted())
- AbstractButton.this.repaint();
- }
-
- /**
- * Possibly repaint the button in response to acquisition of focus.
- *
- * @param event The gained-focus event
- */
- public void focusGained(FocusEvent event)
- {
- if (AbstractButton.this.isFocusPainted())
- AbstractButton.this.repaint();
- }
- }
/**
* Creates a new AbstractButton object.
@@ -549,12 +525,12 @@ public abstract class AbstractButton extends JComponent
borderPainted = true;
contentAreaFilled = true;
- iconTextGap = 4;
+ focusPainted = true;
+ setFocusable(true);
setAlignmentX(LEFT_ALIGNMENT);
setAlignmentY(CENTER_ALIGNMENT);
- addFocusListener(new ButtonFocusListener());
setDisplayedMnemonicIndex(-1);
}
@@ -602,6 +578,18 @@ public abstract class AbstractButton extends JComponent
}
/**
+ * Returns all added <code>ActionListener</code> objects.
+ *
+ * @return an array of listeners
+ *
+ * @since 1.4
+ */
+ public ActionListener[] getActionListeners()
+ {
+ return (ActionListener[]) listenerList.getListeners(ActionListener.class);
+ }
+
+ /**
* Adds an ItemListener to the button's listener list. When the button's
* model changes state (between any of ARMED, ENABLED, PRESSED, ROLLOVER
* or SELECTED) it fires an ItemEvent, and these listeners will be
@@ -625,6 +613,18 @@ public abstract class AbstractButton extends JComponent
}
/**
+ * Returns all added <code>ItemListener</code> objects.
+ *
+ * @return an array of listeners
+ *
+ * @since 1.4
+ */
+ public ItemListener[] getItemListeners()
+ {
+ return (ItemListener[]) listenerList.getListeners(ItemListener.class);
+ }
+
+ /**
* Adds a ChangeListener to the button's listener list. When the button's
* model changes any of its (non-bound) properties, these listeners will be
* called.
@@ -647,6 +647,18 @@ public abstract class AbstractButton extends JComponent
}
/**
+ * Returns all added <code>ChangeListener</code> objects.
+ *
+ * @return an array of listeners
+ *
+ * @since 1.4
+ */
+ public ChangeListener[] getChangeListeners()
+ {
+ return (ChangeListener[]) listenerList.getListeners(ChangeListener.class);
+ }
+
+ /**
* Calls {@link ItemListener.itemStateChanged} on each ItemListener in
* the button's listener list.
*
@@ -655,9 +667,10 @@ public abstract class AbstractButton extends JComponent
public void fireItemStateChanged(ItemEvent e)
{
e.setSource(this);
- EventListener[] ll = listenerList.getListeners(ItemListener.class);
- for (int i = 0; i < ll.length; i++)
- ((ItemListener)ll[i]).itemStateChanged(e);
+ ItemListener[] listeners = getItemListeners();
+
+ for (int i = 0; i < listeners.length; i++)
+ listeners[i].itemStateChanged(e);
}
/**
@@ -669,9 +682,10 @@ public abstract class AbstractButton extends JComponent
public void fireActionPerformed(ActionEvent e)
{
e.setSource(this);
- EventListener[] ll = listenerList.getListeners(ActionListener.class);
- for (int i = 0; i < ll.length; i++)
- ((ActionListener)ll[i]).actionPerformed(e);
+ ActionListener[] listeners = getActionListeners();
+
+ for (int i = 0; i < listeners.length; i++)
+ listeners[i].actionPerformed(e);
}
/**
@@ -683,9 +697,10 @@ public abstract class AbstractButton extends JComponent
*/
public void fireStateChanged(ChangeEvent e)
{
- EventListener[] ll = listenerList.getListeners(ChangeListener.class);
- for (int i = 0; i < ll.length; i++)
- ((ChangeListener)ll[i]).stateChanged(changeEvent);
+ ChangeListener[] listeners = getChangeListeners();
+
+ for (int i = 0; i < listeners.length; i++)
+ listeners[i].stateChanged(changeEvent);
}
/**
@@ -1879,4 +1894,33 @@ public abstract class AbstractButton extends JComponent
public void updateUI()
{
}
+
+ /**
+ * Returns the current time in milliseconds in which clicks gets coalesced
+ * into a single <code>ActionEvent</code>.
+ *
+ * @return the time in milliseconds
+ *
+ * @since 1.4
+ */
+ public long getMultiClickThreshhold()
+ {
+ return multiClickThreshhold;
+ }
+
+ /**
+ * Sets the time in milliseconds in which clicks gets coalesced into a single
+ * <code>ActionEvent</code>.
+ *
+ * @param threshhold the time in milliseconds
+ *
+ * @since 1.4
+ */
+ public void setMultiClickThreshhold(long threshhold)
+ {
+ if (threshhold < 0)
+ throw new IllegalArgumentException();
+
+ multiClickThreshhold = threshhold;
+ }
}
diff --git a/libjava/javax/swing/ActionMap.java b/libjava/javax/swing/ActionMap.java
index 2a5c67a..9861591 100644
--- a/libjava/javax/swing/ActionMap.java
+++ b/libjava/javax/swing/ActionMap.java
@@ -86,8 +86,8 @@ public class ActionMap
{
Object result = actionMap.get(key);
- if (result == null)
- result = parent.get(key);
+ if (result == null && parent != null)
+ result = parent.get(key);
return (Action) result;
}
diff --git a/libjava/javax/swing/Box.java b/libjava/javax/swing/Box.java
index 4e33874..26588a5 100644
--- a/libjava/javax/swing/Box.java
+++ b/libjava/javax/swing/Box.java
@@ -47,7 +47,11 @@ import java.awt.Dimension;
import java.awt.AWTError;
/**
- * Needs some work I guess....
+ * A component that uses a {@link BoxLayout} as Layout Manager.
+ *
+ * In addition to that, this class provides a set of static methods for
+ * creating some filler components ('struts' and 'glue') for use in
+ * containers that are laid out using BoxLayout.
*
* @author Ronald Veldema (rveldema@cs.vu.nl)
*/
@@ -69,7 +73,10 @@ public class Box extends JComponent implements Accessible
return null;
}
}
-
+
+ /**
+ * A component that servers as a filler in BoxLayout controlled containers.
+ */
public static class Filler extends JComponent implements Accessible
{
private static final long serialVersionUID = -1204263191910183998L;
@@ -93,11 +100,25 @@ public class Box extends JComponent implements Accessible
private transient Dimension min, pref, max;
+ /**
+ * Creates a new instance of Filler.
+ *
+ * @param min the minimum size of the filler.
+ * @param pref the preferred size of the filler.
+ * @param max the maximum size of the filler.
+ */
public Filler(Dimension min, Dimension pref, Dimension max)
{
changeShape(min, pref, max);
}
+ /**
+ * Changes the dimensions of this Filler.
+ *
+ * @param min the new minimum size of the filler.
+ * @param pref the new preferred size of the filler.
+ * @param max the new maximum size of the filler.
+ */
public void changeShape(Dimension min, Dimension pref, Dimension max)
{
this.min = min;
@@ -113,65 +134,137 @@ public class Box extends JComponent implements Accessible
return accessibleContext;
}
+ /**
+ * Returns the maximum size of this Filler.
+ *
+ * @return the maximum size of this Filler.
+ */
public Dimension getMaximumSize()
{
return max;
}
+ /**
+ * Returns the minimum size of this Filler.
+ *
+ * @return the minimum size of this Filler.
+ */
public Dimension getMinimumSize()
{
return min;
}
+ /**
+ * Returns the preferred size of this Filler.
+ *
+ * @return the preferred size of this Filler.
+ */
public Dimension getPreferredSize()
{
return pref;
}
}
+ /**
+ * Creates a new Box component, that lays out its children according
+ * to the <code>axis</code> parameter.
+ *
+ * @param axis the orientation of the BoxLayout.
+ *
+ * @see BoxLayout#X_AXIS
+ * @see BoxLayout#Y_AXIS
+ * @see BoxLayout#LINE_AXIS
+ * @see BoxLayout#PAGE_AXIS
+ */
public Box(int axis)
{
- setLayout(new BoxLayout(this, axis));
+ super.setLayout(new BoxLayout(this, axis));
}
+ /**
+ * Creates a filler component which acts as glue between components.
+ * It does not take space unless some extra space is available. If extra
+ * space is available, this component can expand in both X and Y directions.
+ *
+ * @return a glue-like filler component.
+ */
public static Component createGlue()
{
- return null;
+ Filler glue = new Filler(new Dimension(0,0), new Dimension(0,0),
+ new Dimension(Integer.MAX_VALUE,Integer.MAX_VALUE)
+ );
+ return glue;
}
public static Box createHorizontalBox()
{
- return null;
+ return new Box(BoxLayout.X_AXIS);
}
+ /**
+ * Creates a filler component which acts as glue between components.
+ * It does not take space unless some extra space is available. If extra
+ * space is available, this component can expand in the X direction.
+ *
+ * @return a glue-like filler component.
+ */
public static Component createHorizontalGlue()
{
- return null;
+ return createGlue();
}
+ /**
+ * Creates a filler component which acts as strut between components.
+ * It will fill exactly the specified horizontal size.
+ *
+ * @param width the width of this strut in pixels.
+ *
+ * @return a strut-like filler component.
+ */
public static Component createHorizontalStrut(int width)
{
- return null;
+ Filler strut = new Filler(new Dimension(width, 0),
+ new Dimension(width, 0),
+ new Dimension(width, Integer.MAX_VALUE));
+ return strut;
}
public static Component createRigidArea(Dimension d)
{
- return null;
+ return new Filler(d, d, d);
}
public static Box createVerticalBox()
{
- return null;
+ return new Box(BoxLayout.Y_AXIS);
}
+ /**
+ * Creates a filler component which acts as glue between components.
+ * It does not take space unless some extra space is available. If extra
+ * space is available, this component can expand in the Y direction.
+ *
+ * @return a glue-like filler component.
+ */
public static Component createVerticalGlue()
{
- return null;
+ return createGlue();
}
+ /**
+ * Creates a filler component which acts as strut between components.
+ * It will fill exactly the specified vertical size.
+ *
+ * @param height the height of this strut in pixels.
+ *
+ * @return a strut-like filler component.
+ */
public static Component createVerticalStrut(int height)
{
- return null;
+ Filler strut = new Filler(new Dimension(0, height),
+ new Dimension(0, height),
+ new Dimension(Integer.MAX_VALUE, height));
+ return strut;
}
public void setLayout(LayoutManager l)
diff --git a/libjava/javax/swing/BoxLayout.java b/libjava/javax/swing/BoxLayout.java
index 0dd97ac..7b12602 100644
--- a/libjava/javax/swing/BoxLayout.java
+++ b/libjava/javax/swing/BoxLayout.java
@@ -42,15 +42,11 @@ import java.awt.Component;
import java.awt.ComponentOrientation;
import java.awt.Container;
import java.awt.Dimension;
-import java.awt.GridLayout;
import java.awt.LayoutManager2;
import java.io.Serializable;
-
/**
* A layout for swing components.
- * This implementation delegates its methods to
- * java.awt.GridLayout to do its work.
*
* @author Ronald Veldema (rveldema@cs.vu.nl)
*/
@@ -87,11 +83,6 @@ public class BoxLayout implements LayoutManager2, Serializable
private Container container;
/*
- * Internal layout.
- */
- private GridLayout grid;
-
- /*
* Current type of component layouting. Defaults to X_AXIS.
*/
private int way = X_AXIS;
@@ -108,75 +99,41 @@ public class BoxLayout implements LayoutManager2, Serializable
{
int width = 0;
int height = 0;
- ComponentOrientation orientation = container.getComponentOrientation();
-
this.container = container;
this.way = way;
-
- switch (way)
- {
- case X_AXIS:
- width = 1;
- break;
- case Y_AXIS:
- height = 1;
- break;
- case LINE_AXIS:
- if (orientation.isHorizontal())
- height = 1;
- else
- width = 1;
- break;
- case PAGE_AXIS:
- if (!orientation.isHorizontal())
- height = 1;
- else
- width = 1;
- break;
- default:
- throw new AWTError("Invalid value for way");
- }
-
- grid = new GridLayout(width, height);
}
/**
- * Adds a component to the layout.
+ * Adds a component to the layout. Not used in BoxLayout.
*
* @param name The name of the component to add.
* @param component the component to add to the layout.
*/
public void addLayoutComponent(String name, Component component)
{
- if (way == X_AXIS
- || (way == LINE_AXIS
- && component.getComponentOrientation().isHorizontal())
- || (way == PAGE_AXIS
- && !component.getComponentOrientation().isHorizontal()))
- grid.setColumns(grid.getColumns() + 1);
- else
- grid.setRows(grid.getRows() + 1);
}
/**
- * Removes a component from the layout.
+ * Removes a component from the layout. Not used in BoxLayout.
*
* @param component The component to remove from the layout.
*/
public void removeLayoutComponent(Component component)
{
- grid.removeLayoutComponent(component);
-
- if (way == X_AXIS
- || (way == LINE_AXIS
- && component.getComponentOrientation().isHorizontal())
- || (way == PAGE_AXIS
- && !component.getComponentOrientation().isHorizontal()))
- grid.setColumns(grid.getColumns() - 1);
- else
- grid.setRows(grid.getRows() - 1);
}
+ private boolean isHorizontalIn(Container parent)
+ {
+ ComponentOrientation orientation = parent.getComponentOrientation();
+ return this.way == X_AXIS
+ || (this.way == LINE_AXIS
+ && orientation.isHorizontal())
+ || (this.way == PAGE_AXIS
+ && (!orientation.isHorizontal()));
+ }
+
+
+
/**
* Returns the preferred size of the layout.
*
@@ -188,8 +145,38 @@ public class BoxLayout implements LayoutManager2, Serializable
{
if (parent != container)
throw new AWTError("invalid parent");
+
+ int x = 0;
+ int y = 0;
+
+ Component[] children = parent.getComponents();
+
+ if (isHorizontalIn(parent))
+ {
+ // sum up preferred widths of components, find maximum of preferred
+ // heights
+ for (int index = 0; index < children.length; index++)
+ {
+ Component comp = children[index];
+ Dimension sz = comp.getPreferredSize();
+ x += sz.width;
+ y = Math.max(y, sz.height);
+ }
+ }
+ else
+ {
+ // sum up preferred heights of components, find maximum of
+ // preferred widths
+ for (int index = 0; index < children.length; index++)
+ {
+ Component comp = children[index];
+ Dimension sz = comp.getPreferredSize();
+ y += sz.height;
+ x = Math.max(x, sz.width);
+ }
+ }
- return grid.preferredLayoutSize(parent);
+ return new Dimension(x, y);
}
/**
@@ -203,8 +190,38 @@ public class BoxLayout implements LayoutManager2, Serializable
{
if (parent != container)
throw new AWTError("invalid parent");
+
+ int x = 0;
+ int y = 0;
+
+ Component[] children = parent.getComponents();
+
+ if (isHorizontalIn(parent))
+ {
+ // sum up preferred widths of components, find maximum of preferred
+ // heights
+ for (int index = 0; index < children.length; index++)
+ {
+ Component comp = children[index];
+ Dimension sz = comp.getMinimumSize();
+ x += sz.width;
+ y = Math.max(y, sz.height);
+ }
+ }
+ else
+ {
+ // sum up preferred heights of components, find maximum of
+ // preferred widths
+ for (int index = 0; index < children.length; index++)
+ {
+ Component comp = children[index];
+ Dimension sz = comp.getMinimumSize();
+ y += sz.height;
+ x = Math.max(x, sz.width);
+ }
+ }
- return grid.minimumLayoutSize(parent);
+ return new Dimension(x, y);
}
/**
@@ -216,19 +233,69 @@ public class BoxLayout implements LayoutManager2, Serializable
{
if (parent != container)
throw new AWTError("invalid parent");
-
- grid.layoutContainer(parent);
- }
+ Dimension size = parent.getSize();
+
+ Component[] children = parent.getComponents();
+
+ if (isHorizontalIn(parent))
+ {
+ int x = 0;
+ for (int index = 0; index < children.length; index++)
+ {
+ Component comp = children[index];
+ Dimension sz = comp.getPreferredSize();
+ int width = sz.width;
+ int height = sz.height;
+ int cy = 0;
+ if (height > size.height)
+ {
+ height = size.height;
+ }
+ else
+ {
+ cy = (int) ((size.height - height) * comp.getAlignmentY());
+ }
+
+ comp.setSize(width, height);
+ comp.setLocation(x, cy);
+ x = x + width;
+ }
+ }
+ else
+ {
+ int y = 0;
+ for (int index = 0; index < children.length; index++)
+ {
+ Component comp = children[index];
+ Dimension sz = comp.getPreferredSize();
+ int width = sz.width;
+ int height = sz.height;
+ int cx = 0;
+ if (width > size.width)
+ {
+ width = size.width;
+ }
+ else
+ {
+ cx = (int) ((size.width - width) * comp.getAlignmentX());
+ }
+
+ comp.setSize(width, height);
+ comp.setLocation(cx, y);
+ y = y + height;
+ }
+ }
+ }
+
/**
- * Adds a component to the layout.
+ * Adds a component to the layout. Not used in BoxLayout
*
* @param child The component to add to the layout.
* @param constraints The constraints for the component in the layout.
*/
public void addLayoutComponent(Component child, Object constraints)
{
- addLayoutComponent("", child);
}
/**
@@ -284,7 +351,37 @@ public class BoxLayout implements LayoutManager2, Serializable
{
if (parent != container)
throw new AWTError("invalid parent");
-
- return preferredLayoutSize(parent);
+
+ int x = 0;
+ int y = 0;
+
+ Component[] children = parent.getComponents();
+
+ if (isHorizontalIn(parent))
+ {
+
+ // sum up preferred widths of components, find maximum of preferred
+ // heights
+ for (int index = 0; index < children.length; index++)
+ {
+ Component comp = children[index];
+ Dimension sz = comp.getMaximumSize();
+ x += sz.width;
+ y = Math.max(y, sz.height);
+ }
+ }
+ else
+ {
+ // sum up preferred heights of components, find maximum of
+ // preferred widths
+ for (int index = 0; index < children.length; index++)
+ {
+ Component comp = children[index];
+ Dimension sz = comp.getMaximumSize();
+ y += sz.height;
+ x = Math.max(x, sz.width);
+ }
+ }
+ return new Dimension(x, y);
}
}
diff --git a/libjava/javax/swing/ButtonGroup.java b/libjava/javax/swing/ButtonGroup.java
index 8202fa6..5f6a28d 100644
--- a/libjava/javax/swing/ButtonGroup.java
+++ b/libjava/javax/swing/ButtonGroup.java
@@ -42,19 +42,18 @@ import java.util.Enumeration;
import java.util.Vector;
-public class ButtonGroup
- implements Serializable
+/**
+ * DOCUMENT ME!
+ */
+public class ButtonGroup implements Serializable
{
+ /** DOCUMENT ME! */
private static final long serialVersionUID = 4259076101881721375L;
- /**
- * The buttons added to this button group.
- */
+ /** The buttons added to this button group. */
protected Vector buttons = new Vector();
- /**
- * The currently selected button model.
- */
+ /** The currently selected button model. */
ButtonModel sel;
/**
@@ -99,17 +98,24 @@ public class ButtonGroup
/**
* Returns the currently selected button model.
*
- * @return the currently selected button model,
- * null if none was selected yet
+ * @return the currently selected button model, null if none was selected
+ * yet
*/
public ButtonModel getSelection()
{
return sel;
}
+ /**
+ * DOCUMENT ME!
+ *
+ * @param m DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
AbstractButton FindButton(ButtonModel m)
{
- for (int i = 0;i < buttons.size(); i++)
+ for (int i = 0; i < buttons.size(); i++)
{
AbstractButton a = (AbstractButton) buttons.get(i);
if (a.getModel() == m)
@@ -119,46 +125,40 @@ public class ButtonGroup
}
/**
- * Sets the currently selected button model. Only one button of a group
- * can be selected at a time.
+ * Sets the currently selected button model. Only one button of a group can
+ * be selected at a time.
*
* @param m the model to select
* @param b true if this button is to be selected, false otherwise
*/
public void setSelected(ButtonModel m, boolean b)
{
- if ((m == sel) && (b == true))
- {
- // clicked on same item twice.
- System.out.println("PRESSED TWICE:" + m + ", sel=" + sel);
- return;
- }
+ if ((sel != m || b) && (! b || sel == m))
+ return;
- if (sel != null)
+ if (b && sel != m)
{
- System.out.println("DESELECTING: " + sel);
- sel.setSelected(! b);
-
- AbstractButton but = FindButton(sel);
- if (but != null)
- {
- System.out.println("REPAINT-REQUEST: " + but.text);
- //but.revalidate();
- but.repaint();
- }
+ ButtonModel old = sel;
+ sel = m;
+
+ if (old != null)
+ old.setSelected(false);
+ AbstractButton button = FindButton(old);
+ if (button != null)
+ button.repaint();
}
- else
- System.out.println("NO SELECTION YET");
-
- sel = m;
+ else if (! b && sel == m)
+ m.setSelected(true);
}
/**
- * Checks if the given <code>ButtonModel</code> is selected
- * in this button group.
+ * Checks if the given <code>ButtonModel</code> is selected in this button
+ * group.
+ *
+ * @param m DOCUMENT ME!
*
- * @return true of given <code>ButtonModel</code> is selected,
- * false otherwise
+ * @return true of given <code>ButtonModel</code> is selected, false
+ * otherwise
*/
public boolean isSelected(ButtonModel m)
{
diff --git a/libjava/javax/swing/ComboBoxEditor.java b/libjava/javax/swing/ComboBoxEditor.java
index 8559217..30813175 100644
--- a/libjava/javax/swing/ComboBoxEditor.java
+++ b/libjava/javax/swing/ComboBoxEditor.java
@@ -42,49 +42,56 @@ import java.awt.event.ActionListener;
/**
* ComboBoxEditor
- * @author Andrew Selkirk
- * @version 1.0
+ *
+ * @author Andrew Selkirk
+ * @author Olga Rodimina
+ * @version 1.0
*/
-public interface ComboBoxEditor {
-
- //-------------------------------------------------------------
- // Methods ----------------------------------------------------
- //-------------------------------------------------------------
-
- /**
- * getEditorComponent
- * @returns Component
- */
- Component getEditorComponent();
-
- /**
- * setItem
- * @param item TODO
- */
- void setItem(Object item);
-
- /**
- * getItem
- * @returns Object
- */
- Object getItem();
-
- /**
- * selectAll
- */
- void selectAll();
-
- /**
- * addActionListener
- * @param listener TODO
- */
- void addActionListener(ActionListener listener);
-
- /**
- * removeActionListener
- * @param listener TODO
- */
- void removeActionListener(ActionListener listener);
-
-
+public interface ComboBoxEditor
+{
+ /**
+ * This method returns component that will be used by the combo box to
+ * display/edit currently selected item in the combo box.
+ *
+ * @return Component that will be used by the combo box to display/edit
+ * currently selected item
+ */
+ Component getEditorComponent();
+
+ /**
+ * Sets item that should be editted when any editting operation is performed
+ * by the user. The value is always equal to the currently selected value
+ * in the combo box. Thus, whenever a different value is selected from the
+ * combo box list then this method should be called to change editting item
+ * to the new selected item.
+ *
+ * @param selectedItem item that is currently selected in the combo box
+ */
+ void setItem(Object item);
+
+ /**
+ * This method returns item that is currently editable.
+ *
+ * @return Item in the combo box that is currently editable
+ */
+ Object getItem();
+
+ /**
+ * selectAll
+ */
+ void selectAll();
+
+ /**
+ * This method adds specified ActionListener to this ComboBoxEditor.
+ *
+ * @param listener
+ */
+ void addActionListener(ActionListener listener);
+
+ /**
+ * This method removes given ActionListener from this ComboBoxEditor.
+ *
+ * @param listener TODO
+ */
+ void removeActionListener(ActionListener listener);
} // ComboBoxEditor
diff --git a/libjava/javax/swing/ComboBoxModel.java b/libjava/javax/swing/ComboBoxModel.java
index b3b2112..c3b59bd 100644
--- a/libjava/javax/swing/ComboBoxModel.java
+++ b/libjava/javax/swing/ComboBoxModel.java
@@ -37,28 +37,32 @@ exception statement from your version. */
package javax.swing;
+
/**
- * ComboBoxModel
- * @author Andrew Selkirk
- * @version 1.0
+ * ComboBoxModel is a data model for JComboBox. This model keeps
+ * track of elements contained in the JComboBox as well as the current
+ * combo box selection. Whenever selection in the JComboBox changes, the
+ * ComboBoxModel should fire ListDataEvents to ComboBox's ListDataListeners.
+ *
+ * @author Andrew Selkirk
+ * @version 1.0
*/
-public interface ComboBoxModel extends ListModel {
-
- //-------------------------------------------------------------
- // Methods ----------------------------------------------------
- //-------------------------------------------------------------
-
- /**
- * setSelectedItem
- * @param item TODO
- */
- void setSelectedItem(Object item);
-
- /**
- * getSelectedItem
- * @returns Object
- */
- Object getSelectedItem();
-
+public interface ComboBoxModel extends ListModel
+{
+ /**
+ * This method sets the selected item in the combo box. Class
+ * implementing this interface should fire ListDataEvents to
+ * all registered ListDataListeners to indicated that the
+ * selection has changed.
+ *
+ * @param item item in the combo box that should be selected
+ */
+ void setSelectedItem(Object item);
+ /**
+ * The method returns currently selected item in the combo box
+ *
+ * @returns item that is currently selected in the combo box.
+ */
+ Object getSelectedItem();
} // ComboBoxModel
diff --git a/libjava/javax/swing/DefaultButtonModel.java b/libjava/javax/swing/DefaultButtonModel.java
index e9a1356..4c7c247 100644
--- a/libjava/javax/swing/DefaultButtonModel.java
+++ b/libjava/javax/swing/DefaultButtonModel.java
@@ -1,4 +1,4 @@
-/* DefaultButtonModel.java --
+/* DefaultButtonModel.java --
Copyright (C) 2002, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -44,87 +44,103 @@ import java.awt.event.ItemListener;
import java.awt.event.KeyEvent;
import java.io.Serializable;
import java.util.EventListener;
-
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.EventListenerList;
+
/**
* The purpose of this class is to model the dynamic state of an abstract
* button. The concrete button type holding this state may be a a "toggle"
* button (checkbox, radio button) or a "push" button (menu button, button).
- *
- * If the model is disabled, only the "selected" property can be changed.
- * An attempt to change the "armed", "rollover" or "pressed" properties
- * while the model is disabled will be blocked.
- *
- * Any successful (non-blocked) change to the model's properties will
- * trigger the firing of a ChangeEvent.
- *
- * Any change to the "selected" property will trigger the firing of an
- * ItemEvent in addition to ChangeEvent. This is true whether the model is
- * enabled or not.
- *
- * One other state change is special: the transition from "enabled, armed
- * and pressd" to "enabled, armed and not-pressed". This is considered the
- * "trailing edge" of a successful mouse click, and therefore fires an
- * ActionEvent in addition to a ChangeEvent.
+ * If the model is disabled, only the "selected" property can be changed. An
+ * attempt to change the "armed", "rollover" or "pressed" properties while
+ * the model is disabled will be blocked. Any successful (non-blocked) change
+ * to the model's properties will trigger the firing of a ChangeEvent. Any
+ * change to the "selected" property will trigger the firing of an ItemEvent
+ * in addition to ChangeEvent. This is true whether the model is enabled or
+ * not. One other state change is special: the transition from "enabled,
+ * armed and pressd" to "enabled, armed and not-pressed". This is considered
+ * the "trailing edge" of a successful mouse click, and therefore fires an
+ * ActionEvent in addition to a ChangeEvent. In all other respects this class
+ * is just a container of boolean flags.
*
- * In all other respects this class is just a container of boolean flags.
- *
- * @author Graydon Hoare (graydon@redhat.com)
+ * @author Graydon Hoare (graydon_at_redhat.com)
*/
public class DefaultButtonModel implements ButtonModel, Serializable
{
+ /** DOCUMENT ME! */
static final long serialVersionUID = -5342609566534980231L;
- /** Indicates that the button is <em>partially</em> committed to being
- pressed, but not entirely. This usually happens when a user has pressed
- but not yet released the mouse button. */
+ /**
+ * Indicates that the button is <em>partially</em> committed to being
+ * pressed, but not entirely. This usually happens when a user has pressed
+ * but not yet released the mouse button.
+ */
public static final int ARMED = 1;
- /** State constant indicating that the button is enabled. Buttons cannot
- be pressed or selected unless they are enabled. */
+ /**
+ * State constant indicating that the button is enabled. Buttons cannot be
+ * pressed or selected unless they are enabled.
+ */
public static final int ENABLED = 8;
- /** State constant indicating that the user is holding down the button.
- When this transitions from true to false, an ActionEvent may be fired,
- depending on the value of the "armed" property.*/
+ /**
+ * State constant indicating that the user is holding down the button. When
+ * this transitions from true to false, an ActionEvent may be fired,
+ * depending on the value of the "armed" property.
+ */
public static final int PRESSED = 4;
- /** State constant indicating that the mouse is currently positioned over
- the button. */
+ /**
+ * State constant indicating that the mouse is currently positioned over the
+ * button.
+ */
public static final int ROLLOVER = 16;
- /** State constant indicating that the button is selected. This constant
- is only meaningful for toggle-type buttons (radio buttons,
- checkboxes). */
+ /**
+ * State constant indicating that the button is selected. This constant is
+ * only meaningful for toggle-type buttons (radio buttons, checkboxes).
+ */
public static final int SELECTED = 2;
- /** Represents the "state properties" (armed, enabled, pressed, rollover
- and selected) by a bitwise combination of integer constants. */
+ /**
+ * Represents the "state properties" (armed, enabled, pressed, rollover and
+ * selected) by a bitwise combination of integer constants.
+ */
protected int stateMask = ENABLED;
- /** List of ItemListeners, ChangeListeners, and ActionListeners
- registered on this model. */
- protected EventListenerList listenerList = new EventListenerList();;
+ /**
+ * List of ItemListeners, ChangeListeners, and ActionListeners registered on
+ * this model.
+ */
+ protected EventListenerList listenerList = new EventListenerList();
+ ;
- /** The single ChangeEvent this model (re)uses to call its
- ChangeListeners. */
+ /** The single ChangeEvent this model (re)uses to call its ChangeListeners. */
protected ChangeEvent changeEvent = new ChangeEvent(this);
- /** The group this model belongs to. Only one button in a group may be
- selected at any given time. */
+ /**
+ * The group this model belongs to. Only one button in a group may be
+ * selected at any given time.
+ */
protected ButtonGroup group;
-
- /** The key code (one of {@link java.awt.event.KeyEvent} VK_*) used to
- press this button via a keyboard interface. */
+
+ /**
+ * The key code (one of {@link java.awt.event.KeyEvent} VK_) used to press
+ * this button via a keyboard interface.
+ */
protected int mnemonic = KeyEvent.VK_UNDEFINED;
- /** The string used as the "command" property of any ActionEvent this
- model sends. */
+ /**
+ * The string used as the "command" property of any ActionEvent this model
+ * sends.
+ */
protected String actionCommand;
+ /**
+ * Creates a new DefaultButtonModel object.
+ */
public DefaultButtonModel()
{
}
@@ -135,10 +151,10 @@ public class DefaultButtonModel implements ButtonModel, Serializable
*
* @return <code>null</code>
*/
- public Object[] getSelectedObjects()
- {
- return null;
- }
+ public Object[] getSelectedObjects()
+ {
+ return null;
+ }
/**
* Returns a specified class of listeners.
@@ -151,10 +167,10 @@ public class DefaultButtonModel implements ButtonModel, Serializable
{
return listenerList.getListeners(listenerType);
}
-
+
/**
- * Add an ActionListener to the model. Usually only called to subscribe
- * an AbstractButton's listener to the model.
+ * Add an ActionListener to the model. Usually only called to subscribe an
+ * AbstractButton's listener to the model.
*
* @param l The listener to add
*/
@@ -162,10 +178,10 @@ public class DefaultButtonModel implements ButtonModel, Serializable
{
listenerList.add(ActionListener.class, l);
}
-
+
/**
- * Remove an ActionListener to the model. Usually only called to
- * unsubscribe an AbstractButton's listener to the model.
+ * Remove an ActionListener to the model. Usually only called to unsubscribe
+ * an AbstractButton's listener to the model.
*
* @param l The listener to remove
*/
@@ -185,8 +201,8 @@ public class DefaultButtonModel implements ButtonModel, Serializable
}
/**
- * Add an ItemListener to the model. Usually only called to subscribe
- * an AbstractButton's listener to the model.
+ * Add an ItemListener to the model. Usually only called to subscribe an
+ * AbstractButton's listener to the model.
*
* @param l The listener to add
*/
@@ -196,8 +212,8 @@ public class DefaultButtonModel implements ButtonModel, Serializable
}
/**
- * Remove an ItemListener to the model. Usually only called to
- * unsubscribe an AbstractButton's listener to the model.
+ * Remove an ItemListener to the model. Usually only called to unsubscribe
+ * an AbstractButton's listener to the model.
*
* @param l The listener to remove
*/
@@ -217,8 +233,8 @@ public class DefaultButtonModel implements ButtonModel, Serializable
}
/**
- * Add a ChangeListener to the model. Usually only called to subscribe
- * an AbstractButton's listener to the model.
+ * Add a ChangeListener to the model. Usually only called to subscribe an
+ * AbstractButton's listener to the model.
*
* @param l The listener to add
*/
@@ -228,8 +244,8 @@ public class DefaultButtonModel implements ButtonModel, Serializable
}
/**
- * Remove a ChangeListener to the model. Usually only called to
- * unsubscribe an AbstractButton's listener to the model.
+ * Remove a ChangeListener to the model. Usually only called to unsubscribe
+ * an AbstractButton's listener to the model.
*
* @param l The listener to remove
*/
@@ -258,61 +274,60 @@ public class DefaultButtonModel implements ButtonModel, Serializable
public void fireItemStateChanged(ItemEvent e)
{
ItemListener[] ll = getItemListeners();
-
+
for (int i = 0; i < ll.length; i++)
ll[i].itemStateChanged(e);
}
/**
* Inform each ActionListener in the {@link listenerList} that an
- * ActionEvent has occurred. This happens in response to the any change
- * to the {@link stateMask} field which makes the enabled, armed and
- * pressed properties all simultaneously <code>true</code>.
+ * ActionEvent has occurred. This happens in response to the any change to
+ * the {@link stateMask} field which makes the enabled, armed and pressed
+ * properties all simultaneously <code>true</code>.
*
* @param e The ActionEvent to fire
*/
public void fireActionPerformed(ActionEvent e)
{
ActionListener[] ll = getActionListeners();
-
+
for (int i = 0; i < ll.length; i++)
ll[i].actionPerformed(e);
}
/**
- * Inform each ChangeListener in the {@link listenerList} that a
- * ChangeEvent has occurred. This happens in response to the any change
- * to a property of the model.
- *
- * @param event The ChangeEvent to fire
+ * Inform each ChangeListener in the {@link listenerList} that a ChangeEvent
+ * has occurred. This happens in response to the any change to a property
+ * of the model.
*/
public void fireStateChanged()
{
ChangeListener[] ll = getChangeListeners();
-
+
for (int i = 0; i < ll.length; i++)
ll[i].stateChanged(changeEvent);
}
/**
- * Helper method to fire a ChangeEvent with the model as the event's
- * source.
+ * Helper method to fire a ChangeEvent with the model as the event's source.
+ *
+ * @param stateflag DOCUMENT ME!
+ * @param b DOCUMENT ME!
*/
protected void changeState(int stateflag, boolean b)
- {
+ {
int oldstate = stateMask;
int newstate;
if (b)
newstate = oldstate | stateflag;
else
- newstate = oldstate & ~stateflag;
+ newstate = oldstate & ~ stateflag;
if (oldstate == newstate)
return;
- if ((stateflag != SELECTED)
- && (stateflag != ENABLED)
+ if ((stateflag != SELECTED) && (stateflag != ENABLED)
&& (stateMask & ENABLED) == 0)
return;
@@ -320,35 +335,38 @@ public class DefaultButtonModel implements ButtonModel, Serializable
fireStateChanged();
- if ((oldstate & SELECTED) == 0
- && (newstate & SELECTED) == SELECTED)
- fireItemStateChanged(new ItemEvent(this, ItemEvent.ITEM_STATE_CHANGED,
- null, ItemEvent.SELECTED));
+ if ((oldstate & SELECTED) == 0 && (newstate & SELECTED) == SELECTED)
+ {
+ fireItemStateChanged(new ItemEvent(this, ItemEvent.ITEM_STATE_CHANGED,
+ null, ItemEvent.SELECTED));
+ if (group != null)
+ group.setSelected(this, true);
+ }
- else if ((oldstate & SELECTED) == SELECTED
- && (newstate & SELECTED) == 0)
- fireItemStateChanged(new ItemEvent(this, ItemEvent.ITEM_STATE_CHANGED,
- null, ItemEvent.DESELECTED));
-
- else if (((oldstate & ARMED) == ARMED && (oldstate & PRESSED) == PRESSED)
- &&
- ((newstate & ARMED) == ARMED && (newstate & PRESSED) == 0))
+ else if ((oldstate & SELECTED) == SELECTED && (newstate & SELECTED) == 0)
{
- fireActionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED,
- actionCommand));
+ fireItemStateChanged(new ItemEvent(this, ItemEvent.ITEM_STATE_CHANGED,
+ null, ItemEvent.DESELECTED));
+ if (group != null)
+ group.setSelected(this, false);
}
- }
-
+
+ else if (((oldstate & ARMED) == ARMED && (oldstate & PRESSED) == PRESSED)
+ && ((newstate & ARMED) == ARMED && (newstate & PRESSED) == 0))
+ fireActionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED,
+ actionCommand));
+ }
+
/**
* Get the value of the model's "armed" property.
- *
- * @return The current "armed" property
+ *
+ * @return The current "armed" property
*/
public boolean isArmed()
{
return (stateMask & ARMED) == ARMED;
}
-
+
/**
* Set the value of the model's "armed" property.
*
@@ -365,9 +383,9 @@ public class DefaultButtonModel implements ButtonModel, Serializable
* @return The current "enabled" property.
*/
public boolean isEnabled()
- {
+ {
return (stateMask & ENABLED) == ENABLED;
- }
+ }
/**
* Set the value of the model's "enabled" property.
@@ -385,9 +403,9 @@ public class DefaultButtonModel implements ButtonModel, Serializable
* @param p The new "pressed" property
*/
public void setPressed(boolean p)
- {
+ {
changeState(PRESSED, p);
- }
+ }
/**
* Get the value of the model's "pressed" property.
@@ -409,7 +427,6 @@ public class DefaultButtonModel implements ButtonModel, Serializable
changeState(ROLLOVER, r);
}
-
/**
* Set the value of the model's "selected" property.
*
@@ -436,9 +453,9 @@ public class DefaultButtonModel implements ButtonModel, Serializable
* @return The current "rollover" property
*/
public boolean isRollover()
- {
+ {
return (stateMask & ROLLOVER) == ROLLOVER;
- }
+ }
/**
* Get the value of the model's "mnemonic" property.
@@ -446,7 +463,7 @@ public class DefaultButtonModel implements ButtonModel, Serializable
* @return The current "mnemonic" property
*/
public int getMnemonic()
- {
+ {
return mnemonic;
}
@@ -459,15 +476,15 @@ public class DefaultButtonModel implements ButtonModel, Serializable
{
if (mnemonic != key)
{
- mnemonic = key;
- fireStateChanged();
+ mnemonic = key;
+ fireStateChanged();
}
}
-
+
/**
- * Set the value of the model's "actionCommand" property. This property
- * is used as the "command" property of the {@link ActionEvent} fired
- * from the model.
+ * Set the value of the model's "actionCommand" property. This property is
+ * used as the "command" property of the {@link ActionEvent} fired from the
+ * model.
*
* @param s The new "actionCommand" property.
*/
@@ -475,11 +492,11 @@ public class DefaultButtonModel implements ButtonModel, Serializable
{
if (actionCommand != s)
{
- actionCommand = s;
- fireStateChanged();
+ actionCommand = s;
+ fireStateChanged();
}
- }
-
+ }
+
/**
* Returns the current value of the model's "actionCommand" property.
*
@@ -491,9 +508,9 @@ public class DefaultButtonModel implements ButtonModel, Serializable
}
/**
- * Set the value of the model's "group" property. The model is said to be
- * a member of the {@link ButtonGroup} held in its "group" property, and
- * only one model in a given group can have their "selected" property be
+ * Set the value of the model's "group" property. The model is said to be a
+ * member of the {@link ButtonGroup} held in its "group" property, and only
+ * one model in a given group can have their "selected" property be
* <code>true</code> at a time.
*
* @param g The new "group" property
@@ -502,8 +519,8 @@ public class DefaultButtonModel implements ButtonModel, Serializable
{
if (group != g)
{
- group = g;
- fireStateChanged();
+ group = g;
+ fireStateChanged();
}
}
diff --git a/libjava/javax/swing/DefaultComboBoxModel.java b/libjava/javax/swing/DefaultComboBoxModel.java
index 55faf8f..a5546f2 100644
--- a/libjava/javax/swing/DefaultComboBoxModel.java
+++ b/libjava/javax/swing/DefaultComboBoxModel.java
@@ -38,146 +38,191 @@ exception statement from your version. */
package javax.swing;
import java.io.Serializable;
+import java.util.Arrays;
import java.util.Vector;
+
/**
- * DefaultComboBoxModel
- * @author Andrew Selkirk
- * @version 1.0
+ * DefaultComboBoxModel is a data model for JComboBox. This model keeps track
+ * of elements contained in the JComboBox as well as the current combo box
+ * selection. Whenever selection in the JComboBox changes, the ComboBoxModel
+ * will fire ListDataEvents to ComboBox's ListDataListeners.
+ *
+ * @author Andrew Selkirk
+ * @author Olga Rodimina
+ * @version 1.0
*/
-public class DefaultComboBoxModel extends AbstractListModel
- implements MutableComboBoxModel, Serializable
+public class DefaultComboBoxModel extends AbstractListModel
+ implements MutableComboBoxModel, Serializable
{
static final long serialVersionUID = 6698657703676921904L;
- //-------------------------------------------------------------
- // Variables --------------------------------------------------
- //-------------------------------------------------------------
-
- /**
- * list
- */
- private Vector list;
-
- /**
- * selectedItem
- */
- private Object selectedItem;
-
-
- //-------------------------------------------------------------
- // Initialization ---------------------------------------------
- //-------------------------------------------------------------
-
- /**
- * Constructor DefaultComboBoxModel
- */
- public DefaultComboBoxModel() {
- // TODO
- } // DefaultComboBoxModel()
-
- /**
- * Constructor DefaultComboBoxModel
- * @param items TODO
- */
- public DefaultComboBoxModel(Object[] items) {
- // TODO
- } // DefaultComboBoxModel()
-
- /**
- * Constructor DefaultComboBoxModel
- * @param vector TODO
- */
- public DefaultComboBoxModel(Vector vector) {
- // TODO
- } // DefaultComboBoxModel()
-
-
- //-------------------------------------------------------------
- // Methods ----------------------------------------------------
- //-------------------------------------------------------------
-
- /**
- * addElement
- * @param object TODO
- */
- public void addElement(Object object) {
- // TODO
- } // addElement()
-
- /**
- * removeElementAt
- * @param index TODO
- */
- public void removeElementAt(int index) {
- // TODO
- } // removeElementAt()
-
- /**
- * insertElementAt
- * @param object TODO
- * @param index TODO
- */
- public void insertElementAt(Object object, int index) {
- // TODO
- } // insertElementAt()
-
- /**
- * removeElement
- * @param object TODO
- */
- public void removeElement(Object object) {
- // TODO
- } // removeElement()
-
- /**
- * removeAllElements
- */
- public void removeAllElements() {
- // TODO
- } // removeAllElements()
-
- /**
- * getSize
- * @returns int
- */
- public int getSize() {
- return 0; // TODO
- } // getSize()
-
- /**
- * setSelectedItem
- * @param object TODO
- */
- public void setSelectedItem(Object object) {
- // TODO
- } // setSelectedItem()
-
- /**
- * getSelectedItem
- * @returns Object
- */
- public Object getSelectedItem() {
- return null; // TODO
- } // getSelectedItem()
-
- /**
- * getElementAt
- * @param index TODO
- * @returns Object
- */
- public Object getElementAt(int index) {
- return null; // TODO
- } // getElementAt()
-
- /**
- * getIndexOf
- * @param object TODO
- * @returns int
- */
- public int getIndexOf(Object object) {
- return 0; // TODO
- } // getIndexOf()
-
-
-} // DefaultComboBoxModel
+ /**
+ * List containing items in the combo box
+ */
+ private Vector list;
+
+ /**
+ * Currently selected item in the combo box list
+ */
+ private Object selectedItem = null;
+
+ /**
+ * Constructor DefaultComboBoxModel. Create empty JComboBox.
+ */
+ public DefaultComboBoxModel()
+ {
+ list = new Vector();
+ }
+
+ /**
+ * Constructs new DefaultComboBoxModel object and initializes its item list
+ * to values in the given array.
+ *
+ * @param items array containing items of the combo box.
+ */
+ public DefaultComboBoxModel(Object[] items)
+ {
+ list = new Vector(Arrays.asList(items));
+ }
+
+ /**
+ * Consturcts new DefaultComboBoxModel object and initializes its item list
+ * to values in the given vector.
+ *
+ * @param vector Vector containing items for this combo box.
+ */
+ public DefaultComboBoxModel(Vector vector)
+ {
+ this.list = vector;
+ }
+
+ /**
+ * This method adds element to the combo box list. It fires ListDataEvent
+ * indicating that component was added to the combo box to all of the
+ * JComboBox's registered ListDataListeners.
+ *
+ * @param object item to add to the combo box list
+ */
+ public void addElement(Object object)
+ {
+ list.add(object);
+ fireIntervalAdded(this, list.size(), list.size());
+ }
+
+ /**
+ * This method removes element at the specified index from the combo box
+ * list. It fires ListDataEvent indicating that component was removed from
+ * the combo box list to all of the JComboBox's registered
+ * ListDataListeners.
+ *
+ * @param index index specifying location of the element to remove in the
+ * combo box list.
+ */
+ public void removeElementAt(int index)
+ {
+ list.remove(index);
+ fireIntervalRemoved(this, index, index);
+ }
+
+ /**
+ * This method inserts given object to the combo box list at the specified
+ * index. It fires ListDataEvent indicating that component was inserted to
+ * the combo box list to all of the JComboBox's registered
+ * ListDataListeners.
+ *
+ * @param object element to insert
+ * @param index index specifing position in the list where given element
+ * should be inserted.
+ */
+ public void insertElementAt(Object object, int index)
+ {
+ list.insertElementAt(object, index);
+ fireIntervalAdded(this, index, index);
+ }
+
+ /**
+ * Removes given object from the combo box list. It fires ListDataEvent
+ * indicating that component was removed from the combo box list to all of
+ * the JComboBox's registered ListDataListeners.
+ *
+ * @param object Element that will be removed from the combo box list
+ */
+ public void removeElement(Object object)
+ {
+ int index = getIndexOf(object);
+ if (index != -1)
+ removeElementAt(index);
+ }
+
+ /**
+ * Removes all the items from the JComboBox's item list. It fires
+ * ListDataEvent indicating that all the elements were removed from the
+ * combo box list to all of the JComboBox's registered ListDataListeners.
+ */
+ public void removeAllElements()
+ {
+ int listSize = getSize();
+ list.clear();
+ fireIntervalAdded(this, 0, listSize - 1);
+ }
+
+ /**
+ * Returns number of items in the combo box list
+ *
+ * @return number of items in the combo box list
+ */
+ public int getSize()
+ {
+ return list.size();
+ }
+
+ /**
+ * Selects given object in the combo box list. This method fires
+ * ListDataEvent to all registered ListDataListeners of the JComboBox. The
+ * start and end index of the event is set to -1 to indicate combo box's
+ * selection has changed, and not its contents.
+ *
+ * @param object item to select in the JComboBox
+ */
+ public void setSelectedItem(Object object)
+ {
+ selectedItem = object;
+ fireContentsChanged(this, -1, -1);
+ }
+
+ /**
+ * Returns currently selected item in the combo box list
+ *
+ * @return currently selected item in the combo box list
+ */
+ public Object getSelectedItem()
+ {
+ return selectedItem;
+ }
+
+ /**
+ * Returns element in the combo box list located at the given index
+ *
+ * @param index specifying location of the element in the list
+ *
+ * @return return element in the combo box list located at the given index
+ */
+ public Object getElementAt(int index)
+ {
+ return list.elementAt(index);
+ }
+
+ /**
+ * Returns index of the specified object in the combo box list.
+ *
+ * @param object element to look for in the combo box list .
+ *
+ * @return Index specifying position of the specified element in combo box
+ * list.
+ */
+ public int getIndexOf(Object object)
+ {
+ return list.indexOf(object);
+ }
+}
diff --git a/libjava/javax/swing/DefaultListCellRenderer.java b/libjava/javax/swing/DefaultListCellRenderer.java
index cfb1f40..fe4b3d0 100644
--- a/libjava/javax/swing/DefaultListCellRenderer.java
+++ b/libjava/javax/swing/DefaultListCellRenderer.java
@@ -41,16 +41,18 @@ import java.awt.Component;
import java.awt.Rectangle;
import java.io.Serializable;
import javax.swing.border.Border;
+import javax.swing.border.EmptyBorder;
/**
- * DefaultListCellRenderer
+ * DefaultListCellRenderer. This class is responsible for rendering list
+ * cells.
*
* @author Andrew Selkirk
* @version 1.0
*/
-public class DefaultListCellRenderer
- extends JLabel implements ListCellRenderer, Serializable
+public class DefaultListCellRenderer extends JLabel implements ListCellRenderer,
+ Serializable
{
static final long serialVersionUID = 7708947179685189462L;
@@ -62,19 +64,22 @@ public class DefaultListCellRenderer
}
}
- /** noFocusBorder */
- protected static Border noFocusBorder = null; // TODO
+ /**
+ * This border is used whenever renderer doesn't have a focus.
+ */
+ protected static Border noFocusBorder = new EmptyBorder(1, 1, 1, 1);
/**
* getListCellRendererComponent
*
- * @param list TODO
- * @param value TODO
- * @param index TODO
- * @param isSelected TODO
- * @param cellHasFocus TODO
+ * @param list JList list for the 'value'
+ * @param value object that should be rendered in the cell
+ * @param index index of the cell
+ * @param isSelected draw cell highlighted if isSelected is true
+ * @param cellHasFocus draw focus rectangle around cell if the cell has
+ * focus
*
- * @return Component
+ * @return Component that will be painted to the desired cell.
*/
public Component getListCellRendererComponent(JList list, Object value,
int index, boolean isSelected,
@@ -86,31 +91,87 @@ public class DefaultListCellRenderer
if (isSelected)
{
- setBackground(list.getSelectionBackground());
- setForeground(list.getSelectionForeground());
+ setBackground(list.getSelectionBackground());
+ setForeground(list.getSelectionForeground());
}
else
{
- setBackground(list.getBackground());
- setForeground(list.getForeground());
+ setBackground(list.getBackground());
+ setForeground(list.getForeground());
}
setEnabled(list.isEnabled());
setFont(list.getFont());
+
+ // Use focusCellHighlightBorder when renderer has focus and
+ // noFocusBorder otherwise
+
+ if (cellHasFocus)
+ setBorder(UIManager.getBorder("List.focusCellHighlightBorder"));
+ else
+ setBorder(noFocusBorder);
+
return this;
}
- public void validate() {}
- public void revalidate() {}
- public void repaint(long tm, int x, int y, int w, int h) {}
- public void repaint(Rectangle rect) {}
- protected void firePropertyChange(String propertyName, Object oldValue, Object newValue){}
- public void firePropertyChange(String propertyName, byte oldValue, byte newValue) {}
- public void firePropertyChange(String propertyName, char oldValue, char newValue) {}
- public void firePropertyChange(String propertyName, short oldValue, short newValue) {}
- public void firePropertyChange(String propertyName, int oldValue, int newValue) {}
- public void firePropertyChange(String propertyName, long oldValue, long newValue) {}
- public void firePropertyChange(String propertyName, float oldValue, float newValue) {}
- public void firePropertyChange(String propertyName, double oldValue, double newValue) {}
- public void firePropertyChange(String propertyName, boolean oldValue, boolean newValue) {}
+ public void validate()
+ {
+ }
+
+ public void revalidate()
+ {
+ }
+
+ public void repaint(long tm, int x, int y, int w, int h)
+ {
+ }
+
+ public void repaint(Rectangle rect)
+ {
+ }
+
+ protected void firePropertyChange(String propertyName, Object oldValue,
+ Object newValue)
+ {
+ }
+
+ public void firePropertyChange(String propertyName, byte oldValue,
+ byte newValue)
+ {
+ }
+
+ public void firePropertyChange(String propertyName, char oldValue,
+ char newValue)
+ {
+ }
+
+ public void firePropertyChange(String propertyName, short oldValue,
+ short newValue)
+ {
+ }
+
+ public void firePropertyChange(String propertyName, int oldValue,
+ int newValue)
+ {
+ }
+
+ public void firePropertyChange(String propertyName, long oldValue,
+ long newValue)
+ {
+ }
+
+ public void firePropertyChange(String propertyName, float oldValue,
+ float newValue)
+ {
+ }
+
+ public void firePropertyChange(String propertyName, double oldValue,
+ double newValue)
+ {
+ }
+
+ public void firePropertyChange(String propertyName, boolean oldValue,
+ boolean newValue)
+ {
+ }
}
diff --git a/libjava/javax/swing/DefaultListSelectionModel.java b/libjava/javax/swing/DefaultListSelectionModel.java
index 67ad1df..4b8ddc3 100644
--- a/libjava/javax/swing/DefaultListSelectionModel.java
+++ b/libjava/javax/swing/DefaultListSelectionModel.java
@@ -264,7 +264,7 @@ public class DefaultListSelectionModel implements Cloneable,
{
end = i;
}
- fireSelectionValueChanged(beg, end, valueIsAdjusting);
+ fireValueChanged(beg, end, valueIsAdjusting);
}
/**
@@ -409,7 +409,7 @@ public class DefaultListSelectionModel implements Cloneable,
int hi = Math.max(index0, index1);
sel.set(lo, hi+1);
- fireSelectionValueChanged(lo, hi, valueIsAdjusting);
+ fireValueChanged(lo, hi, valueIsAdjusting);
}
@@ -429,7 +429,7 @@ public class DefaultListSelectionModel implements Cloneable,
int lo = Math.min(index0, index1);
int hi = Math.max(index0, index1);
sel.clear(lo, hi+1);
- fireSelectionValueChanged(lo, hi, valueIsAdjusting);
+ fireValueChanged(lo, hi, valueIsAdjusting);
}
/**
@@ -439,7 +439,7 @@ public class DefaultListSelectionModel implements Cloneable,
{
int sz = sel.size();
sel.clear();
- fireSelectionValueChanged(0, sz, valueIsAdjusting);
+ fireValueChanged(0, sz, valueIsAdjusting);
}
/**
@@ -460,7 +460,7 @@ public class DefaultListSelectionModel implements Cloneable,
int lo = Math.min(index0, index1);
int hi = Math.max(index0, index1);
sel.set(lo, hi+1);
- fireSelectionValueChanged(lo, hi, valueIsAdjusting);
+ fireValueChanged(lo, hi, valueIsAdjusting);
}
/**
@@ -522,8 +522,8 @@ public class DefaultListSelectionModel implements Cloneable,
* @param isAdjusting Whether this change is part of a seqence of adjustments
* made to the selection, such as during interactive scrolling
*/
- public void fireSelectionValueChanged(int firstIndex, int lastIndex,
- boolean isAdjusting)
+ protected void fireValueChanged(int firstIndex, int lastIndex,
+ boolean isAdjusting)
{
ListSelectionEvent evt = new ListSelectionEvent(this, firstIndex,
lastIndex, isAdjusting);
diff --git a/libjava/javax/swing/InputMap.java b/libjava/javax/swing/InputMap.java
index fdcc828..c737ae4 100644
--- a/libjava/javax/swing/InputMap.java
+++ b/libjava/javax/swing/InputMap.java
@@ -89,9 +89,9 @@ public class InputMap
{
Object result = inputMap.get(keystroke);
- if (result == null)
- result = parent.get(keystroke);
- return result;
+ if (result == null && parent != null)
+ result = parent.get(keystroke);
+ return result;
}
/**
diff --git a/libjava/javax/swing/JCheckBox.java b/libjava/javax/swing/JCheckBox.java
index f5cc78a..8490c0b 100644
--- a/libjava/javax/swing/JCheckBox.java
+++ b/libjava/javax/swing/JCheckBox.java
@@ -114,7 +114,7 @@ public class JCheckBox extends JToggleButton
}
/**
- * Returns a string that specifies the name of the L&amp;F class
+ * Returns a string that specifies the name of the Look and Feel class
* that renders this component.
*/
public String getUIClassID()
diff --git a/libjava/javax/swing/JColorChooser.java b/libjava/javax/swing/JColorChooser.java
index 70dde6a..6ba70ce 100644
--- a/libjava/javax/swing/JColorChooser.java
+++ b/libjava/javax/swing/JColorChooser.java
@@ -35,11 +35,16 @@ this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
-
package javax.swing;
+import java.awt.AWTError;
+import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
+import java.awt.Dialog;
+import java.awt.FlowLayout;
+import java.awt.Frame;
+import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.io.ObjectOutputStream;
@@ -47,314 +52,521 @@ import javax.accessibility.Accessible;
import javax.accessibility.AccessibleContext;
import javax.accessibility.AccessibleRole;
import javax.swing.colorchooser.AbstractColorChooserPanel;
+import javax.swing.colorchooser.ColorChooserComponentFactory;
import javax.swing.colorchooser.ColorSelectionModel;
+import javax.swing.colorchooser.DefaultColorSelectionModel;
import javax.swing.plaf.ColorChooserUI;
+
/**
- * JColorChooser
- * @author Andrew Selkirk
- * @version 1.0
+ * The JColorChooser is a Swing widget that offers users different ways to
+ * select a color. By default, three different panels are presented to the
+ * user that are capable of changing the selected color. There are three ways
+ * to utilize JColorChooser. The first is to build a JColorChooser and add it
+ * to the content pane. The second is to use the createDialog method to
+ * create a JDialog that holds a JColorChooser. The third is to show a
+ * JColorChooser in a JDialog directly using the showDialog method.
*/
-public class JColorChooser extends JComponent implements Accessible {
-
+public class JColorChooser extends JComponent implements Accessible
+{
+ /** DOCUMENT ME! */
private static final long serialVersionUID = 9168066781620640889L;
-
- //-------------------------------------------------------------
- // Classes ----------------------------------------------------
- //-------------------------------------------------------------
-
- /**
- * AccessibleJColorChooser
- */
- protected class AccessibleJColorChooser extends JComponent.AccessibleJComponent {
-
- private static final long serialVersionUID = -2038297864782299082L;
-
- //-------------------------------------------------------------
- // Variables --------------------------------------------------
- //-------------------------------------------------------------
-
-
- //-------------------------------------------------------------
- // Initialization ---------------------------------------------
- //-------------------------------------------------------------
-
- /**
- * Constructor AccessibleJColorChooser
- * @param component TODO
- */
- protected AccessibleJColorChooser()
+
+ /**
+ * AccessibleJColorChooser
+ */
+ protected class AccessibleJColorChooser
+ extends JComponent.AccessibleJComponent
+ {
+ /** DOCUMENT ME! */
+ private static final long serialVersionUID = -2038297864782299082L;
+
+ /**
+ * Constructor AccessibleJColorChooser
+ */
+ protected AccessibleJColorChooser()
+ {
+ }
+
+ /**
+ * getAccessibleRole
+ *
+ * @return AccessibleRole
+ */
+ public AccessibleRole getAccessibleRole()
+ {
+ return AccessibleRole.COLOR_CHOOSER;
+ } // getAccessibleRole()
+ } // AccessibleJColorChooser
+
+ /** The model used with the JColorChooser. */
+ private ColorSelectionModel selectionModel;
+
+ /** The preview panel associated with the JColorChooser. */
+ private JComponent previewPanel;
+
+ /**
+ * The set of AbstractColorChooserPanels associated with the JColorChooser.
+ */
+ private AbstractColorChooserPanel[] chooserPanels;
+
+ /** A Drag and Drop property. */
+ private boolean dragEnabled;
+
+ /**
+ * The property fired by the JColorChooser when the selectionModel property
+ * changes.
+ */
+ public static final String SELECTION_MODEL_PROPERTY = "selectionModel";
+
+ /**
+ * The property fired by the JColorChooser when the previewPanel property
+ * changes.
+ */
+ public static final String PREVIEW_PANEL_PROPERTY = "previewPanel";
+
+ /**
+ * The property fired by the JColorChooser when the chooserPanels property
+ * changes.
+ */
+ public static final String CHOOSER_PANELS_PROPERTY = "chooserPanels";
+
+ /** accessibleContext */
+ protected AccessibleContext accessibleContext;
+
+ /**
+ * This method creates a new JColorChooser with the default initial color.
+ */
+ public JColorChooser()
+ {
+ this(new DefaultColorSelectionModel());
+ } // JColorChooser()
+
+ /**
+ * This method creates a new JColorChooser with the given initial color.
+ *
+ * @param initial The initial color.
+ */
+ public JColorChooser(Color initial)
+ {
+ this(new DefaultColorSelectionModel(initial));
+ } // JColorChooser()
+
+ /**
+ * This method creates a new JColorChooser with the given model. The model
+ * will dictate what the initial color for the JColorChooser is.
+ *
+ * @param model The Model to use with the JColorChooser.
+ */
+ public JColorChooser(ColorSelectionModel model)
+ {
+ if (model == null)
+ model = new DefaultColorSelectionModel();
+ selectionModel = model;
+ updateUI();
+ } // JColorChooser()
+
+ /**
+ * This method sets the current color for the JColorChooser.
+ *
+ * @param color The new color for the JColorChooser.
+ */
+ public void setColor(Color color)
+ {
+ if (color != null)
+ selectionModel.setSelectedColor(color);
+ } // setColor()
+
+ /**
+ * This method sets the current color for the JColorChooser using RGB
+ * values.
+ *
+ * @param r The red value.
+ * @param g The green value.
+ * @param b The blue value.
+ */
+ public void setColor(int r, int g, int b)
+ {
+ selectionModel.setSelectedColor(new Color(r, g, b));
+ } // setColor()
+
+ /**
+ * This method sets the current color for the JColorChooser using the
+ * integer value. Bits 0-7 represent the blue value. Bits 8-15 represent
+ * the green value. Bits 16-23 represent the red value.
+ *
+ * @param color The new current color of the JColorChooser.
+ */
+ public void setColor(int color)
+ {
+ setColor(new Color(color, false));
+ } // setColor()
+
+ /**
+ * This method shows a JColorChooser inside a JDialog. The JDialog will
+ * block until it is hidden. The JDialog comes with three buttons: OK,
+ * Cancel, and Reset. Pressing OK or Cancel hide the JDialog. Pressing
+ * Reset will reset the JColorChooser to its initial value.
+ *
+ * @param component The Component that parents the JDialog.
+ * @param title The title displayed in the JDialog.
+ * @param initial The initial color.
+ *
+ * @return The selected color.
+ */
+ public static Color showDialog(Component component, String title,
+ Color initial)
+ {
+ JColorChooser choose = new JColorChooser(initial);
+
+ JDialog dialog = createDialog(component, title, true, choose, null, null);
+
+ dialog.getContentPane().add(choose);
+ dialog.pack();
+ dialog.show();
+
+ return choose.getColor();
+ } // showDialog()
+
+ /**
+ * This is a helper method to make the given JDialog block until it is
+ * hidden.
+ *
+ * @param dialog The JDialog to block.
+ */
+ private static void makeModal(JDialog dialog)
+ {
+ try
+ {
+ synchronized (dialog)
{
+ while (dialog.isVisible())
+ dialog.wait();
}
+ }
+ catch (InterruptedException e)
+ {
+ }
+ }
+
+ /**
+ * This is a helper method to find the first Frame or Dialog ancestor of the
+ * given Component.
+ *
+ * @param c The Component to find ancestors for.
+ *
+ * @return A Frame or Dialog ancestor. Null if none are found.
+ */
+ private static Component findParent(Component c)
+ {
+ Component parent = SwingUtilities.getAncestorOfClass(Frame.class, c);
+ if (parent != null)
+ return parent;
+ parent = SwingUtilities.getAncestorOfClass(Dialog.class, c);
+ return parent;
+ }
+
+ /**
+ * This method will take the given JColorChooser and place it in a JDialog
+ * with the given modal property. Three buttons are displayed in the
+ * JDialog: OK, Cancel and Reset. If OK or Cancel are pressed, the JDialog
+ * is hidden. If Reset is pressed, then the JColorChooser will take on its
+ * default color value. The given okListener will be registered to the OK
+ * button and the cancelListener will be registered to the Cancel button.
+ * If the modal property is set, then the JDialog will block until it is
+ * hidden.
+ *
+ * @param component The Component that will parent the JDialog.
+ * @param title The title displayed in the JDialog.
+ * @param modal The modal property.
+ * @param chooserPane The JColorChooser to place in the JDialog.
+ * @param okListener The ActionListener to register to the OK button.
+ * @param cancelListener The ActionListener to register to the Cancel
+ * button.
+ *
+ * @return A JDialog with the JColorChooser inside of it.
+ *
+ * @throws AWTError If the component is not a suitable parent.
+ */
+ public static JDialog createDialog(Component component, String title,
+ boolean modal, JColorChooser chooserPane,
+ ActionListener okListener,
+ ActionListener cancelListener)
+ {
+ Component parent = findParent(component);
+ if (parent == null)
+ throw new AWTError("No suitable parent found for Component.");
+ JDialog dialog;
+ if (parent instanceof Frame)
+ dialog = new ModalDialog((Frame) parent, title);
+ else
+ dialog = new ModalDialog((Dialog) parent, title);
+ dialog.setModal(modal);
+
+ dialog.getContentPane().setLayout(new BorderLayout());
+
+ JPanel panel = new JPanel();
+ panel.setLayout(new FlowLayout());
+
+ ActionListener al = new DefaultOKCancelListener(dialog);
+
+ JButton ok = new JButton("OK");
+ ok.addActionListener(okListener);
+ ok.addActionListener(al);
+
+ JButton cancel = new JButton("Cancel");
+ cancel.addActionListener(cancelListener);
+ cancel.addActionListener(al);
+
+ JButton reset = new JButton("Reset");
+ reset.addActionListener(new DefaultResetListener(chooserPane));
+
+ dialog.getContentPane().add(chooserPane, BorderLayout.NORTH);
+
+ panel.add(ok);
+ panel.add(cancel);
+ panel.add(reset);
+
+ dialog.getContentPane().add(panel, BorderLayout.SOUTH);
+
+ return dialog;
+ } // createDialog()
+
+ /**
+ * This method returns the UI Component used for this JColorChooser.
+ *
+ * @return The UI Component for this JColorChooser.
+ */
+ public ColorChooserUI getUI()
+ {
+ return (ColorChooserUI) ui;
+ } // getUI()
- /**
- * getAccessibleRole
- * @returns AccessibleRole
- */
- public AccessibleRole getAccessibleRole() {
- return AccessibleRole.COLOR_CHOOSER;
- } // getAccessibleRole()
-
-
- } // AccessibleJColorChooser
-
-
- //-------------------------------------------------------------
- // Variables --------------------------------------------------
- //-------------------------------------------------------------
-
- /**
- * uiClassID
- */
- private static final String uiClassID = "ColorChooserUI";
-
- /**
- * selectionModel
- */
- private ColorSelectionModel selectionModel;
-
- /**
- * previewPanel
- */
- private JComponent previewPanel;
-
- /**
- * chooserPanels
- */
- private AbstractColorChooserPanel[] chooserPanels;
-
- /**
- * SELECTION_MODEL_PROPERTY
- */
- public static final String SELECTION_MODEL_PROPERTY = "selectionModel";
-
- /**
- * PREVIEW_PANEL_PROPERTY
- */
- public static final String PREVIEW_PANEL_PROPERTY = "previewPanel";
-
- /**
- * CHOOSER_PANELS_PROPERTY
- */
- public static final String CHOOSER_PANELS_PROPERTY = "chooserPanels";
-
- /**
- * accessibleContext
- */
- protected AccessibleContext accessibleContext;
-
-
- //-------------------------------------------------------------
- // Initialization ---------------------------------------------
- //-------------------------------------------------------------
-
- /**
- * Constructor JColorChooser
- */
- public JColorChooser() {
- // TODO
- } // JColorChooser()
-
- /**
- * Constructor JColorChooser
- * @param initial TODO
- */
- public JColorChooser(Color initial) {
- // TODO
- } // JColorChooser()
-
- /**
- * Constructor JColorChooser
- * @param model TODO
- */
- public JColorChooser(ColorSelectionModel model) {
- // TODO
- } // JColorChooser()
-
-
- //-------------------------------------------------------------
- // Methods ----------------------------------------------------
- //-------------------------------------------------------------
-
- /**
- * writeObject
- * @param stream TODO
- * @exception IOException TODO
- */
- private void writeObject(ObjectOutputStream stream) throws IOException {
- // TODO
- } // writeObject()
-
- /**
- * setColor
- * @param color TODO
- */
- public void setColor(Color color) {
- // TODO
- } // setColor()
-
- /**
- * setColor
- * @param r TODO
- * @param g TODO
- * @param b TODO
- */
- public void setColor(int r, int g, int b) {
- // TODO
- } // setColor()
-
- /**
- * setColor
- * @param color TODO
- */
- public void setColor(int color) {
- // TODO
- } // setColor()
-
- /**
- * showDialog
- * @param component TODO
- * @param title TODO
- * @param initial TODO
- * @returns Color
- */
- public static Color showDialog(Component component, String title,
- Color initial) {
- return null; // TODO
- } // showDialog()
-
- /**
- * createDialog
- * @param component TODO
- * @param title TODO
- * @param modal TODO
- * @param chooserPane TODO
- * @param okListener TODO
- * @param cancelListener TODO
- * @returns JDialog
- */
- public static JDialog createDialog(Component component, String title,
- boolean modal, JColorChooser chooserPane,
- ActionListener okListener, ActionListener cancelListener) {
- return null; // TODO
- } // createDialog()
-
- /**
- * getUI
- * @returns ColorChooserUI
- */
- public ColorChooserUI getUI() {
- return (ColorChooserUI) ui;
- } // getUI()
-
- /**
- * setUI
- * @param ui TODO
- */
- public void setUI(ColorChooserUI ui) {
- super.setUI(ui);
- } // setUI()
-
- /**
- * updateUI
- */
- public void updateUI() {
- setUI((ColorChooserUI) UIManager.get(this));
- invalidate();
- } // updateUI()
-
- /**
- * getUIClassID
- * @returns String
- */
- public String getUIClassID() {
- return uiClassID;
- } // getUIClassID()
-
- /**
- * getColor
- * @returns Color
- */
- public Color getColor() {
- return null; // TODO
- } // getColor()
-
- /**
- * setPreviewPanel
- * @param component TODO
- */
- public void setPreviewPanel(JComponent component) {
- // TODO
- } // setPreviewPanel()
-
- /**
- * getPreviewPanel
- * @returns JComponent
- */
- public JComponent getPreviewPanel() {
- return null; // TODO
- } // getPreviewPanel()
-
- /**
- * addChooserPanel
- * @param panel TODO
- */
- public void addChooserPanel(AbstractColorChooserPanel panel) {
- // TODO
- } // addChooserPanel()
-
- /**
- * removeChooserPanel
- * @param panel TODO
- * @returns AbstractColorChooserPanel
- */
- public AbstractColorChooserPanel removeChooserPanel(
- AbstractColorChooserPanel panel) {
- return null; // TODO
- } // removeChooserPanel()
-
- /**
- * setChooserPanels
- * @param panels TODO
- */
- public void setChooserPanels(AbstractColorChooserPanel[] panels) {
- // TODO
- } // setChooserPanels()
-
- /**
- * getChooserPanels
- * @returns AbstractColorChooserPanel[]
- */
- public AbstractColorChooserPanel[] getChooserPanels() {
- return null; // TODO
- } // getChooserPanels()
-
- /**
- * getSelectionModel
- * @returns ColorSelectionModel
- */
- public ColorSelectionModel getSelectionModel() {
- return null; // TODO
- } // getSelectionModel()
-
- /**
- * setSelectionModel
- * @param model TODO
- */
- public void setSelectionModel(ColorSelectionModel model) {
- // TODO
- } // setSelectionModel()
-
- /**
- * paramString
- * @returns String
- */
- protected String paramString() {
- return null; // TODO
- } // paramString()
+ /**
+ * This method sets the UI Component used for this JColorChooser.
+ *
+ * @param ui The UI Component to use with this JColorChooser.
+ */
+ public void setUI(ColorChooserUI ui)
+ {
+ super.setUI(ui);
+ } // setUI()
+
+ /**
+ * This method resets the UI Component property to the Look and Feel
+ * default.
+ */
+ public void updateUI()
+ {
+ setUI((ColorChooserUI) UIManager.getUI(this));
+ revalidate();
+ } // updateUI()
+
+ /**
+ * This method returns a String identifier for the UI Class to be used with
+ * the JColorChooser.
+ *
+ * @return The String identifier for the UI Class.
+ */
+ public String getUIClassID()
+ {
+ return "ColorChooserUI";
+ } // getUIClassID()
+
+ /**
+ * This method returns the current color for the JColorChooser.
+ *
+ * @return The current color for the JColorChooser.
+ */
+ public Color getColor()
+ {
+ return selectionModel.getSelectedColor(); // TODO
+ } // getColor()
+
+ /**
+ * This method changes the previewPanel property for the JTabbedPane. The
+ * previewPanel is responsible for indicating the current color of the
+ * JColorChooser.
+ *
+ * @param component The Component that will act as the previewPanel.
+ */
+ public void setPreviewPanel(JComponent component)
+ {
+ if (component != previewPanel)
+ {
+ JComponent old = previewPanel;
+ previewPanel = component;
+ firePropertyChange(PREVIEW_PANEL_PROPERTY, old, previewPanel);
+ }
+ } // setPreviewPanel()
+
+ /**
+ * This method returns the current previewPanel used with this
+ * JColorChooser.
+ *
+ * @return The current previewPanel.
+ */
+ public JComponent getPreviewPanel()
+ {
+ return previewPanel; // TODO
+ } // getPreviewPanel()
+
+ /**
+ * This method adds the given AbstractColorChooserPanel to the list of the
+ * JColorChooser's chooserPanels.
+ *
+ * @param panel The AbstractColorChooserPanel to add.
+ */
+ public void addChooserPanel(AbstractColorChooserPanel panel)
+ {
+ if (panel == null)
+ return;
+ AbstractColorChooserPanel[] old = chooserPanels;
+ AbstractColorChooserPanel[] newPanels = new AbstractColorChooserPanel[(old == null)
+ ? 1
+ : old.length
+ + 1];
+ if (old != null)
+ System.arraycopy(old, 0, newPanels, 0, old.length);
+ newPanels[newPanels.length - 1] = panel;
+ chooserPanels = newPanels;
+ panel.installChooserPanel(this);
+ firePropertyChange(CHOOSER_PANELS_PROPERTY, old, newPanels);
+ } // addChooserPanel()
+
+ /**
+ * This method removes the given AbstractColorChooserPanel from the
+ * JColorChooser's list of chooserPanels.
+ *
+ * @param panel The AbstractColorChooserPanel to remove.
+ *
+ * @return The AbstractColorChooserPanel that was removed.
+ */
+ public AbstractColorChooserPanel removeChooserPanel(AbstractColorChooserPanel panel)
+ {
+ int index = -1;
+ for (int i = 0; i < chooserPanels.length; i++)
+ if (panel == chooserPanels[i])
+ {
+ index = i;
+ break;
+ }
+
+ if (index == -1)
+ return null;
+
+ AbstractColorChooserPanel[] old = chooserPanels;
+ if (chooserPanels.length == 1)
+ chooserPanels = null;
+ else
+ {
+ AbstractColorChooserPanel[] newPanels = new AbstractColorChooserPanel[chooserPanels.length
+ - 1];
+ System.arraycopy(chooserPanels, 0, newPanels, 0, index);
+ System.arraycopy(chooserPanels, index, newPanels, index - 1,
+ chooserPanels.length - index);
+ chooserPanels = newPanels;
+ }
+ panel.uninstallChooserPanel(this);
+ firePropertyChange(CHOOSER_PANELS_PROPERTY, old, chooserPanels);
+ return panel;
+ }
+
+ /**
+ * This method sets the chooserPanels property for this JColorChooser.
+ *
+ * @param panels The new set of AbstractColorChooserPanels to use.
+ */
+ public void setChooserPanels(AbstractColorChooserPanel[] panels)
+ {
+ if (panels != chooserPanels)
+ {
+ if (chooserPanels != null)
+ for (int i = 0; i < chooserPanels.length; i++)
+ if (chooserPanels[i] != null)
+ chooserPanels[i].uninstallChooserPanel(this);
+
+ AbstractColorChooserPanel[] old = chooserPanels;
+ chooserPanels = panels;
+
+ if (panels != null)
+ for (int i = 0; i < panels.length; i++)
+ if (panels[i] != null)
+ panels[i].installChooserPanel(this);
+
+ firePropertyChange(CHOOSER_PANELS_PROPERTY, old, chooserPanels);
+ }
+ } // setChooserPanels()
+
+ /**
+ * This method returns the AbstractColorChooserPanels used with this
+ * JColorChooser.
+ *
+ * @return The AbstractColorChooserPanels used with this JColorChooser.
+ */
+ public AbstractColorChooserPanel[] getChooserPanels()
+ {
+ return chooserPanels;
+ } // getChooserPanels()
+
+ /**
+ * This method returns the ColorSelectionModel used with this JColorChooser.
+ *
+ * @return The ColorSelectionModel.
+ */
+ public ColorSelectionModel getSelectionModel()
+ {
+ return selectionModel;
+ } // getSelectionModel()
+
+ /**
+ * This method sets the ColorSelectionModel to be used with this
+ * JColorChooser.
+ *
+ * @param model The ColorSelectionModel to be used with this JColorChooser.
+ *
+ * @throws AWTError If the given model is null.
+ */
+ public void setSelectionModel(ColorSelectionModel model)
+ {
+ if (model == null)
+ throw new AWTError("ColorSelectionModel is not allowed to be null.");
+ selectionModel = model;
+ } // setSelectionModel()
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public boolean getDragEnabled()
+ {
+ return dragEnabled;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param b DOCUMENT ME!
+ */
+ public void setDragEnabled(boolean b)
+ {
+ dragEnabled = b;
+ }
+
+ /**
+ * This method returns a String describing the JColorChooser.
+ *
+ * @return A String describing the JColorChooser.
+ */
+ protected String paramString()
+ {
+ return "JColorChooser";
+ } // paramString()
/**
* getAccessibleContext
+ *
* @return AccessibleContext
*/
public AccessibleContext getAccessibleContext()
@@ -364,4 +576,130 @@ public class JColorChooser extends JComponent implements Accessible {
return accessibleContext;
}
+
+ /**
+ * A helper class that hides a JDialog when the action is performed.
+ */
+ static class DefaultOKCancelListener implements ActionListener
+ {
+ /** The JDialog to hide. */
+ private JDialog dialog;
+
+ /**
+ * Creates a new DefaultOKCancelListener with the given JDialog to hide.
+ *
+ * @param dialog The JDialog to hide.
+ */
+ public DefaultOKCancelListener(JDialog dialog)
+ {
+ super();
+ this.dialog = dialog;
+ }
+
+ /**
+ * This method hides the JDialog when called.
+ *
+ * @param e The ActionEvent.
+ */
+ public void actionPerformed(ActionEvent e)
+ {
+ dialog.hide();
+ }
+ }
+
+ /**
+ * This method resets the JColorChooser color to the initial color when the
+ * action is performed.
+ */
+ static class DefaultResetListener implements ActionListener
+ {
+ /** The JColorChooser to reset. */
+ private JColorChooser chooser;
+
+ /** The initial color. */
+ private Color init;
+
+ /**
+ * Creates a new DefaultResetListener with the given JColorChooser.
+ *
+ * @param chooser The JColorChooser to reset.
+ */
+ public DefaultResetListener(JColorChooser chooser)
+ {
+ super();
+ this.chooser = chooser;
+ init = chooser.getColor();
+ }
+
+ /**
+ * This method resets the JColorChooser to its initial color.
+ *
+ * @param e The ActionEvent.
+ */
+ public void actionPerformed(ActionEvent e)
+ {
+ chooser.setColor(init);
+ }
+ }
+
+ /**
+ * This is a custom JDialog that will notify when it is hidden and the modal
+ * property is set.
+ */
+ static class ModalDialog extends JDialog
+ {
+ /** The modal property. */
+ private boolean modal;
+
+ /**
+ * Creates a new ModalDialog object with the given parent and title.
+ *
+ * @param parent The parent of the JDialog.
+ * @param title The title of the JDialog.
+ */
+ public ModalDialog(Frame parent, String title)
+ {
+ super(parent, title);
+ }
+
+ /**
+ * Creates a new ModalDialog object with the given parent and title.
+ *
+ * @param parent The parent of the JDialog.
+ * @param title The title of the JDialog.
+ */
+ public ModalDialog(Dialog parent, String title)
+ {
+ super(parent, title);
+ }
+
+ /**
+ * This method sets the modal property.
+ *
+ * @param modal The modal property.
+ */
+ public void setModal(boolean modal)
+ {
+ this.modal = modal;
+ }
+
+ /**
+ * This method shows the ModalDialog.
+ */
+ public void show()
+ {
+ super.show();
+ if (modal)
+ makeModal(this);
+ }
+
+ /**
+ * This method hides the ModalDialog.
+ */
+ public synchronized void hide()
+ {
+ super.hide();
+ notifyAll();
+ }
+ }
}
diff --git a/libjava/javax/swing/JComboBox.java b/libjava/javax/swing/JComboBox.java
index b66dcb3..9d480dc 100644
--- a/libjava/javax/swing/JComboBox.java
+++ b/libjava/javax/swing/JComboBox.java
@@ -35,761 +35,958 @@ this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
-
package javax.swing;
+import java.awt.Component;
+import java.awt.Dimension;
import java.awt.ItemSelectable;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.KeyEvent;
+import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.Vector;
-
import javax.accessibility.Accessible;
import javax.accessibility.AccessibleAction;
import javax.accessibility.AccessibleContext;
import javax.accessibility.AccessibleRole;
import javax.accessibility.AccessibleSelection;
+import javax.swing.JComponent;
import javax.swing.event.ListDataEvent;
import javax.swing.event.ListDataListener;
import javax.swing.event.PopupMenuListener;
import javax.swing.plaf.ComboBoxUI;
+
/**
- * JComboBox
- * @author Andrew Selkirk
- * @version 1.0
+ * JComboBox. JComboBox is a container, that keeps track of elements added to
+ * it by the user. JComboBox allows user to select any item in its list and
+ * displays the selected item to the user. JComboBox also can show/hide popup
+ * menu containing its list of item whenever the mouse is pressed over it.
+ *
+ * @author Andrew Selkirk
+ * @author Olga Rodimina
*/
-public class JComboBox extends JComponent
- implements ItemSelectable, ListDataListener, ActionListener, Accessible
+public class JComboBox extends JComponent implements ItemSelectable,
+ ListDataListener,
+ ActionListener,
+ Accessible
{
private static final long serialVersionUID = 5654585963292734470L;
/**
- * AccessibleJComboBox
+ * KeySelectionManager interface. Class implementing this interface are
+ * responsible for matching key characters typed by the user with combo
+ * box's items.
*/
- protected class AccessibleJComboBox extends AccessibleJComponent
- implements AccessibleAction, AccessibleSelection
+ public static interface KeySelectionManager
{
- private static final long serialVersionUID = 8217828307256675666L;
+ int selectionForKey(char aKey, ComboBoxModel aModel);
+ }
+
+ /**
+ * Maximum number of rows that should be visible by default in the
+ * JComboBox's popup
+ */
+ public static final int DEFAULT_MAXIMUM_ROW_COUNT = 8;
+
+ /**
+ * Fired in a PropertyChangeEvent when the 'editable' property changes.
+ */
+ public static final String EDITABLE_CHANGED_PROPERTY = "editable";
+
+ /**
+ * Fired in a PropertyChangeEvent when the 'maximumRowCount' property
+ * changes.
+ */
+ public static final String MAXIMUM_ROW_COUNT_CHANGED_PROPERTY = "maximumRowCount";
+
+ /**
+ * Fired in a PropertyChangeEvent when the 'enabled' property changes.
+ */
+ public static final String ENABLED_CHANGED_PROPERTY = "enabled";
+
+ /**
+ * Fired in a PropertyChangeEvent when the 'renderer' property changes.
+ */
+ public static final String RENDERER_CHANGED_PROPERTY = "renderer";
+
+ /**
+ * Fired in a PropertyChangeEvent when the 'editor' property changes.
+ */
+ public static final String EDITOR_CHANGED_PROPERTY = "editor";
+
+ /**
+ * Fired in a PropertyChangeEvent when the 'dataModel' property changes.
+ */
+ public static final String MODEL_CHANGED_PROPERTY = "dataModel";
+
+ /**
+ * name for the UI delegate for this combo box.
+ */
+ private static final String uiClassID = "ComboBoxUI";
+
+ /**
+ * dataModel used by JComboBox to keep track of its list data and currently
+ * selected element in the list.
+ */
+ protected ComboBoxModel dataModel;
+
+ /**
+ * Renderer renders(paints) every object in the combo box list in its
+ * associated list cell. This ListCellRenderer is used only when this
+ * JComboBox is uneditable.
+ */
+ protected ListCellRenderer renderer;
+
+ /**
+ * editor that is responsible for editting an object in a combo box list
+ */
+ protected ComboBoxEditor editor;
+
+ /**
+ * Number of rows that will be visible in the JComboBox's popup.
+ */
+ protected int maximumRowCount;
+
+ /**
+ * This field indicates if textfield of this JComboBox is editable or not.
+ */
+ protected boolean isEditable;
+
+ /**
+ * This field is reference to the current selection of the combo box.
+ */
+ protected Object selectedItemReminder;
+
+ /**
+ * keySelectionManager
+ */
+ protected KeySelectionManager keySelectionManager;
+
+ /**
+ * This actionCommand is used in ActionEvent that is fired to JComboBox's
+ * ActionListeneres.
+ */
+ protected String actionCommand;
+
+ /**
+ * This property indicates if heavyweight popup or lightweight popup will be
+ * used to diplay JComboBox's elements.
+ */
+ protected boolean lightWeightPopupEnabled;
+
+ /**
+ * The action taken when new item is selected in the JComboBox
+ */
+ private Action action;
+
+ /**
+ * since 1.4 If this field is set then comboBox's display area for the
+ * selected item will be set by default to this value.
+ */
+ private Object prototypeDisplayValue;
+
+ /**
+ * Constructs JComboBox object with specified data model for it. The first
+ * item in the specified data model is selected by default.
+ *
+ * @param model Data model that will be used by this JComboBox to keep track
+ * of its list of items.
+ */
+ public JComboBox(ComboBoxModel model)
+ {
+ setEditable(false);
+ setEnabled(true);
+ setMaximumRowCount(DEFAULT_MAXIMUM_ROW_COUNT);
+ setModel(model);
+ setActionCommand("comboBoxChanged");
+
+ // by default set selected item to the first element in the combo box
+ if (getItemCount() != 0)
+ setSelectedItem(getItemAt(0));
+
+ lightWeightPopupEnabled = true;
+ isEditable = false;
+
+ updateUI();
+ }
+
+ /**
+ * Constructs JComboBox with specified list of items.
+ *
+ * @param itemArray array containing list of items for this JComboBox
+ */
+ public JComboBox(Object[] itemArray)
+ {
+ this(new DefaultComboBoxModel(itemArray));
+ }
+
+ /**
+ * Constructs JComboBox object with specified list of items.
+ *
+ * @param itemVector vector containing list of items for this JComboBox.
+ */
+ public JComboBox(Vector itemVector)
+ {
+ this(new DefaultComboBoxModel(itemVector));
+ }
+
+ /**
+ * Constructor. Creates new empty JComboBox. ComboBox's data model is set to
+ * DefaultComboBoxModel.
+ */
+ public JComboBox()
+ {
+ this(new DefaultComboBoxModel());
+ }
+
+ private void writeObject(ObjectOutputStream stream) throws IOException
+ {
+ }
+
+ /**
+ * This method returns true JComboBox is editable and false otherwise
+ *
+ * @return boolean true if JComboBox is editable and false otherwise
+ */
+ public boolean isEditable()
+ {
+ return isEditable;
+ }
- /**
- * Constructor AccessibleJComboBox
- * @param component TODO
+ /*
+ * This method adds ancestor listener to this JComboBox.
+ */
+ protected void installAncestorListener()
+ {
+ /* FIXME: Need to implement.
+ *
+ * Need to add ancestor listener to this JComboBox. This listener
+ * should close combo box's popup list of items whenever it
+ * receives an AncestorEvent.
*/
- protected AccessibleJComboBox()
- {
- }
+ }
+
+ /**
+ * Set the "UI" property of the combo box, which is a look and feel class
+ * responsible for handling comboBox's input events and painting it.
+ *
+ * @param ui The new "UI" property
+ */
+ public void setUI(ComboBoxUI ui)
+ {
+ super.setUI(ui);
+ }
+
+ /**
+ * This method sets this comboBox's UI to the UIManager's default for the
+ * current look and feel.
+ */
+ public void updateUI()
+ {
+ setUI((ComboBoxUI) UIManager.getUI(this));
+ invalidate();
+ }
+
+ /**
+ * This method returns the String identifier for the UI class to the used
+ * with the JComboBox.
+ *
+ * @return The String identifier for the UI class.
+ */
+ public String getUIClassID()
+ {
+ return uiClassID;
+ }
+
+ /**
+ * This method returns the UI used to display the JComboBox.
+ *
+ * @return The UI used to display the JComboBox.
+ */
+ public ComboBoxUI getUI()
+ {
+ return (ComboBoxUI) ui;
+ }
+
+ /**
+ * Set the data model for this JComboBox. This un-registers all listeners
+ * associated with the current model, and re-registers them with the new
+ * model.
+ *
+ * @param newDataModel The new data model for this JComboBox
+ */
+ public void setModel(ComboBoxModel newDataModel)
+ {
+ if (this.dataModel == newDataModel)
+ return;
+
+ if (this.dataModel != null)
+ // remove all listeners currently registered with the model.
+ dataModel.removeListDataListener(this);
+
+ ComboBoxModel oldDataModel = this.dataModel;
+ this.dataModel = newDataModel;
+
+ if (this.dataModel != null)
+ // register all listeners with the new data model
+ dataModel.addListDataListener(this);
+
+ firePropertyChange(MODEL_CHANGED_PROPERTY, oldDataModel, this.dataModel);
+ }
+
+ /**
+ * This method returns data model for this comboBox.
+ *
+ * @return ComboBoxModel containing items for this combo box.
+ */
+ public ComboBoxModel getModel()
+ {
+ return dataModel;
+ }
+
+ /**
+ * This method sets JComboBox's popup to be either lightweight or
+ * heavyweight. If 'enabled' is true then lightweight popup is used and
+ * heavyweight otherwise. By default lightweight popup is used to display
+ * this JComboBox's elements.
+ *
+ * @param enabled indicates if lightweight popup or heavyweight popup should
+ * be used to display JComboBox's elements.
+ */
+ public void setLightWeightPopupEnabled(boolean enabled)
+ {
+ this.lightWeightPopupEnabled = enabled;
+ }
+
+ /**
+ * This method returns whether popup menu that is used to display list of
+ * combo box's item is lightWeight or not.
+ *
+ * @return boolean true if popup menu is lightweight and false otherwise.
+ */
+ public boolean isLightWeightPopupEnabled()
+ {
+ return lightWeightPopupEnabled;
+ }
+
+ /**
+ * This method sets editability of the combo box. If combo box is editable
+ * the user can choose component from the combo box list by typing
+ * component's name in the editor(JTextfield by default). Otherwise if not
+ * editable, the user should use the list to choose the component. This
+ * method fires PropertyChangeEvents to JComboBox's registered
+ * PropertyChangeListeners to indicate that 'editable' property of the
+ * JComboBox has changed.
+ *
+ * @param editable indicates if the JComboBox's textfield should be editable
+ * or not.
+ */
+ public void setEditable(boolean editable)
+ {
+ if (this.isEditable != editable)
+ {
+ this.isEditable = editable;
+ firePropertyChange(EDITABLE_CHANGED_PROPERTY, ! isEditable, isEditable);
+ }
+ }
+
+ /**
+ * Sets number of rows that should be visible in this JComboBox's popup. If
+ * this JComboBox's popup has more elements that maximum number or rows
+ * then popup will have a scroll pane to allow users to view other
+ * elements.
+ *
+ * @param rowCount number of rows that will be visible in JComboBox's popup.
+ */
+ public void setMaximumRowCount(int rowCount)
+ {
+ if (maximumRowCount != rowCount)
+ {
+ int oldMaximumRowCount = this.maximumRowCount;
+ this.maximumRowCount = rowCount;
+ firePropertyChange(MAXIMUM_ROW_COUNT_CHANGED_PROPERTY,
+ oldMaximumRowCount, this.maximumRowCount);
+ }
+ }
+
+ /**
+ * This method returns number of rows visible in the JComboBox's list of
+ * items.
+ *
+ * @return int maximun number of visible rows in the JComboBox's list.
+ */
+ public int getMaximumRowCount()
+ {
+ return maximumRowCount;
+ }
+
+ /**
+ * This method sets cell renderer for this JComboBox that will be used to
+ * paint combo box's items. The Renderer should only be used only when
+ * JComboBox is not editable. In the case when JComboBox is editable the
+ * editor must be used. This method also fires PropertyChangeEvent when
+ * cellRendered for this JComboBox has changed.
+ *
+ * @param aRenderer cell renderer that will be used by this JComboBox to
+ * paint its elements.
+ */
+ public void setRenderer(ListCellRenderer aRenderer)
+ {
+ if (this.renderer != aRenderer)
+ {
+ ListCellRenderer oldRenderer = this.renderer;
+ this.renderer = aRenderer;
+ firePropertyChange(RENDERER_CHANGED_PROPERTY, oldRenderer,
+ this.renderer);
+ }
+ }
+
+ /**
+ * This method returns renderer responsible for rendering selected item in
+ * the combo box
+ *
+ * @return ListCellRenderer
+ */
+ public ListCellRenderer getRenderer()
+ {
+ return renderer;
+ }
+
+ /**
+ * Sets editor for this JComboBox
+ *
+ * @param newEditor ComboBoxEditor for this JComboBox. This method fires
+ * PropertyChangeEvent when 'editor' property is changed.
+ */
+ public void setEditor(ComboBoxEditor newEditor)
+ {
+ if (editor == newEditor)
+ return;
+
+ if (editor != null)
+ editor.removeActionListener(this);
+
+ ComboBoxEditor oldEditor = editor;
+ editor = newEditor;
+
+ if (editor != null)
+ editor.addActionListener(this);
+
+ firePropertyChange(EDITOR_CHANGED_PROPERTY, oldEditor, editor);
+ }
+
+ /**
+ * Returns editor component that is responsible for displaying/editting
+ * selected item in the combo box.
+ *
+ * @return ComboBoxEditor
+ */
+ public ComboBoxEditor getEditor()
+ {
+ return editor;
+ }
+
+ /**
+ * Forces combo box to select given item
+ *
+ * @param item element in the combo box to select.
+ */
+ public void setSelectedItem(Object item)
+ {
+ dataModel.setSelectedItem(item);
+ }
+
+ /**
+ * Returns currently selected item in the combo box.
+ *
+ * @return element that is currently selected in this combo box.
+ */
+ public Object getSelectedItem()
+ {
+ Object item = dataModel.getSelectedItem();
+
+ if (item == null && getItemCount() != 0)
+ item = getItemAt(0);
+
+ return item;
+ }
- /**
- * getAccessibleChildrenCount
- * @returns int
- */
- public int getAccessibleChildrenCount() {
- return 0; // TODO
- } // getAccessibleChildrenCount()
-
- /**
- * getAccessibleChild
- * @param value0 TODO
- * @returns Accessible
- */
- public Accessible getAccessibleChild(int value0) {
- return null; // TODO
- } // getAccessibleChild()
-
- /**
- * getAccessibleSelection
- * @returns AccessibleSelection
- */
- public AccessibleSelection getAccessibleSelection() {
- return null; // TODO
- } // getAccessibleSelection()
-
- /**
- * getAccessibleSelection
- * @param value0 TODO
- * @returns Accessible
- */
- public Accessible getAccessibleSelection(int value0) {
- return null; // TODO
- } // getAccessibleSelection()
-
- /**
- * isAccessibleChildSelected
- * @param value0 TODO
- * @returns boolean
- */
- public boolean isAccessibleChildSelected(int value0) {
- return false; // TODO
- } // isAccessibleChildSelected()
-
- /**
- * getAccessibleRole
- * @returns AccessibleRole
- */
- public AccessibleRole getAccessibleRole() {
- return AccessibleRole.COMBO_BOX;
- } // getAccessibleRole()
-
- /**
- * getAccessibleAction
- * @returns AccessibleAction
- */
- public AccessibleAction getAccessibleAction() {
- return null; // TODO
- } // getAccessibleAction()
-
- /**
- * getAccessibleActionDescription
- * @param value0 TODO
- * @returns String
- */
- public String getAccessibleActionDescription(int value0) {
- return null; // TODO
- } // getAccessibleActionDescription()
-
- /**
- * getAccessibleActionCount
- * @returns int
- */
- public int getAccessibleActionCount() {
- return 0; // TODO
- } // getAccessibleActionCount()
-
- /**
- * doAccessibleAction
- * @param value0 TODO
- * @returns boolean
- */
- public boolean doAccessibleAction(int value0) {
- return false; // TODO
- } // doAccessibleAction()
-
- /**
- * getAccessibleSelectionCount
- * @returns int
- */
- public int getAccessibleSelectionCount() {
- return 0; // TODO
- } // getAccessibleSelectionCount()
-
- /**
- * addAccessibleSelection
- * @param value0 TODO
- */
- public void addAccessibleSelection(int value0) {
- // TODO
- } // addAccessibleSelection()
-
- /**
- * removeAccessibleSelection
- * @param value0 TODO
- */
- public void removeAccessibleSelection(int value0) {
- // TODO
- } // removeAccessibleSelection()
-
- /**
- * clearAccessibleSelection
- */
- public void clearAccessibleSelection() {
- // TODO
- } // clearAccessibleSelection()
-
- /**
- * selectAllAccessibleSelection
- */
- public void selectAllAccessibleSelection() {
- // TODO
- } // selectAllAccessibleSelection()
-
-
- } // AccessibleJComboBox
-
- /**
- * KeySelectionManager
- */
- public static interface KeySelectionManager {
-
- //-------------------------------------------------------------
- // Methods ----------------------------------------------------
- //-------------------------------------------------------------
-
- /**
- * selectionForKey
- * @param value0 TODO
- * @param value1 TODO
- * @returns int
- */
- int selectionForKey(char value0, ComboBoxModel value1);
-
-
- } // KeySelectionManager
-
-
- //-------------------------------------------------------------
- // Variables --------------------------------------------------
- //-------------------------------------------------------------
-
- /**
- * uiClassID
- */
- private static final String uiClassID = "ComboBoxUI";
-
- /**
- * dataModel
- */
- protected ComboBoxModel dataModel;
-
- /**
- * renderer
- */
- protected ListCellRenderer renderer;
-
- /**
- * editor
- */
- protected ComboBoxEditor editor;
-
- /**
- * maximumRowCount
- */
- protected int maximumRowCount;
-
- /**
- * isEditable
- */
- protected boolean isEditable;
-
- /**
- * selectedItemReminder
- */
- protected Object selectedItemReminder;
-
- /**
- * keySelectionManager
- */
- protected JComboBox.KeySelectionManager keySelectionManager;
-
- /**
- * actionCommand
- */
- protected String actionCommand;
-
- /**
- * lightWeightPopupEnabled
- */
- protected boolean lightWeightPopupEnabled;
-
-
- //-------------------------------------------------------------
- // Initialization ---------------------------------------------
- //-------------------------------------------------------------
-
- /**
- * Constructor JComboBox
- * @param value0 TODO
- */
- public JComboBox(ComboBoxModel value0) {
- // TODO
- } // JComboBox()
-
- /**
- * Constructor JComboBox
- * @param value0 TODO
- */
- public JComboBox(Object[] value0) {
- // TODO
- } // JComboBox()
-
- /**
- * Constructor JComboBox
- * @param value0 TODO
- */
- public JComboBox(Vector value0) {
- // TODO
- } // JComboBox()
-
- /**
- * Constructor JComboBox
- */
- public JComboBox() {
- // TODO
- } // JComboBox()
-
-
- //-------------------------------------------------------------
- // Methods ----------------------------------------------------
- //-------------------------------------------------------------
-
- /**
- * writeObject
- * @param stream TODO
- * @exception IOException TODO
- */
- private void writeObject(ObjectOutputStream stream) throws IOException {
- // TODO
- } // writeObject()
-
- /**
- * isEditable
- * @returns boolean
- */
- public boolean isEditable() {
- return false; // TODO
- } // isEditable()
-
- /**
- * installAncestorListener
- */
- protected void installAncestorListener() {
- // TODO
- } // installAncestorListener()
-
- /**
- * setUI
- * @param ui TODO
- */
- public void setUI(ComboBoxUI ui) {
- super.setUI(ui);
- } // setUI()
-
- /**
- * updateUI
- */
- public void updateUI() {
- setUI((ComboBoxUI) UIManager.get(this));
- invalidate();
- } // updateUI()
-
- /**
- * getUIClassID
- * @returns String
- */
- public String getUIClassID() {
- return uiClassID;
- } // getUIClassID()
-
- /**
- * getUI
- * @returns ComboBoxUI
- */
- public ComboBoxUI getUI() {
- return (ComboBoxUI) ui;
- } // getUI()
-
- /**
- * setModel
- * @param value0 TODO
- */
- public void setModel(ComboBoxModel value0) {
- // TODO
- } // setModel()
-
- /**
- * getModel
- * @returns ComboBoxModel
- */
- public ComboBoxModel getModel() {
- return null; // TODO
- } // getModel()
-
- /**
- * setLightWeightPopupEnabled
- * @param value0 TODO
- */
- public void setLightWeightPopupEnabled(boolean value0) {
- // TODO
- } // setLightWeightPopupEnabled()
-
- /**
- * isLightWeightPopupEnabled
- * @returns boolean
- */
- public boolean isLightWeightPopupEnabled() {
- return false; // TODO
- } // isLightWeightPopupEnabled()
-
- /**
- * setEditable
- * @param value0 TODO
- */
- public void setEditable(boolean value0) {
- // TODO
- } // setEditable()
-
- /**
- * setMaximumRowCount
- * @param value0 TODO
- */
- public void setMaximumRowCount(int value0) {
- // TODO
- } // setMaximumRowCount()
-
- /**
- * getMaximumRowCount
- * @returns int
- */
- public int getMaximumRowCount() {
- return 0; // TODO
- } // getMaximumRowCount()
-
- /**
- * setRenderer
- * @param value0 TODO
- */
- public void setRenderer(ListCellRenderer value0) {
- // TODO
- } // setRenderer()
-
- /**
- * getRenderer
- * @returns ListCellRenderer
- */
- public ListCellRenderer getRenderer() {
- return null; // TODO
- } // getRenderer()
-
- /**
- * setEditor
- * @param value0 TODO
- */
- public void setEditor(ComboBoxEditor value0) {
- // TODO
- } // setEditor()
-
- /**
- * getEditor
- * @returns ComboBoxEditor
- */
- public ComboBoxEditor getEditor() {
- return null; // TODO
- } // getEditor()
-
- /**
- * setSelectedItem
- * @param value0 TODO
- */
- public void setSelectedItem(Object value0) {
- // TODO
- } // setSelectedItem()
-
- /**
- * getSelectedItem
- * @returns Object
- */
- public Object getSelectedItem() {
- return null; // TODO
- } // getSelectedItem()
-
- /**
- * setSelectedIndex
- * @param value0 TODO
- */
- public void setSelectedIndex(int value0) {
- // TODO
- } // setSelectedIndex()
-
- /**
- * getSelectedIndex
- * @returns int
- */
- public int getSelectedIndex() {
- return 0; // TODO
- } // getSelectedIndex()
-
- /**
- * addItem
- * @param value0 TODO
- */
- public void addItem(Object value0) {
- // TODO
- } // addItem()
-
- /**
- * insertItemAt
- * @param value0 TODO
- * @param value1 TODO
- */
- public void insertItemAt(Object value0, int value1) {
- // TODO
- } // insertItemAt()
-
- /**
- * removeItem
- * @param value0 TODO
- */
- public void removeItem(Object value0) {
- // TODO
- } // removeItem()
-
- /**
- * removeItemAt
- * @param value0 TODO
- */
- public void removeItemAt(int value0) {
- // TODO
- } // removeItemAt()
-
- /**
- * removeAllItems
- */
- public void removeAllItems() {
- // TODO
- } // removeAllItems()
-
- /**
- * showPopup
- */
- public void showPopup() {
- // TODO
- } // showPopup()
-
- /**
- * hidePopup
- */
- public void hidePopup() {
- // TODO
- } // hidePopup()
-
- /**
- * setPopupVisible
- * @param value0 TODO
- */
- public void setPopupVisible(boolean value0) {
- // TODO
- } // setPopupVisible()
-
- /**
- * isPopupVisible
- * @returns boolean
- */
- public boolean isPopupVisible() {
- return false; // TODO
- } // isPopupVisible()
-
- /**
- * setActionCommand
- * @param value0 TODO
- */
- public void setActionCommand(String value0) {
- // TODO
- } // setActionCommand()
-
- /**
- * getActionCommand
- * @returns String
- */
- public String getActionCommand() {
- return null; // TODO
- } // getActionCommand()
-
- /**
- * setAction
- * @param value0 TODO
- */
- public void setAction(Action value0) {
- // TODO
- } // setAction()
-
- /**
- * isListener
- * @param value0 TODO
- * @param value1 TODO
- * @returns boolean
- */
- private boolean isListener(Class value0, ActionListener value1) {
- return false; // TODO
- } // isListener()
-
- /**
- * getAction
- * @returns Action
- */
- public Action getAction() {
- return null; // TODO
- } // getAction()
-
- /**
- * configurePropertiesFromAction
- * @param value0 TODO
- */
- protected void configurePropertiesFromAction(Action value0) {
- // TODO
- } // configurePropertiesFromAction()
-
- /**
- * createActionPropertyChangeListener
- * @param value0 TODO
- * @returns PropertyChangeListener
- */
- protected PropertyChangeListener createActionPropertyChangeListener(Action value0) {
- return null; // TODO
- } // createActionPropertyChangeListener()
-
- /**
- * fireItemStateChanged
- * @param value0 TODO
- */
- protected void fireItemStateChanged(ItemEvent value0) {
- // TODO
- } // fireItemStateChanged()
-
- /**
- * fireActionEvent
- */
- protected void fireActionEvent() {
- // TODO
- } // fireActionEvent()
-
- /**
- * selectedItemChanged
- */
- protected void selectedItemChanged() {
- // TODO
- } // selectedItemChanged()
-
- /**
- * getSelectedObjects
- * @returns Object[]
- */
- public Object[] getSelectedObjects() {
- return null; // TODO
- } // getSelectedObjects()
-
- /**
- * actionPerformed
- * @param value0 TODO
- */
- public void actionPerformed(ActionEvent value0) {
- // TODO
- } // actionPerformed()
-
- /**
- * contentsChanged
- * @param value0 TODO
- */
- public void contentsChanged(ListDataEvent value0) {
- // TODO
- } // contentsChanged()
-
- /**
- * selectWithKeyChar
- * @param value0 TODO
- * @returns boolean
- */
- public boolean selectWithKeyChar(char value0) {
- return false; // TODO
- } // selectWithKeyChar()
-
- /**
- * intervalAdded
- * @param value0 TODO
- */
- public void intervalAdded(ListDataEvent value0) {
- // TODO
- } // intervalAdded()
-
- /**
- * intervalRemoved
- * @param value0 TODO
- */
- public void intervalRemoved(ListDataEvent value0) {
- // TODO
- } // intervalRemoved()
-
- /**
- * setEnabled
- * @param value0 TODO
- */
- public void setEnabled(boolean value0) {
- // TODO
- } // setEnabled()
-
- /**
- * configureEditor
- * @param value0 TODO
- * @param value1 TODO
- */
- public void configureEditor(ComboBoxEditor value0, Object value1) {
- // TODO
- } // configureEditor()
-
- /**
- * processKeyEvent
- * @param value0 TODO
- */
- public void processKeyEvent(KeyEvent value0) {
- // TODO
- } // processKeyEvent()
-
- /**
- * isFocusTraversable
- * @returns boolean
- * @deprecated
- */
- public boolean isFocusTraversable() {
- return false; // TODO
- } // isFocusTraversable()
-
- /**
- * setKeySelectionManager
- * @param value0 TODO
- */
- public void setKeySelectionManager(KeySelectionManager value0) {
- // TODO
- } // setKeySelectionManager()
-
- /**
- * getKeySelectionManager
- * @returns JComboBox.KeySelectionManager
- */
- public JComboBox.KeySelectionManager getKeySelectionManager() {
- return null; // TODO
- } // getKeySelectionManager()
-
- /**
- * getItemCount
- * @returns int
- */
- public int getItemCount() {
- return 0; // TODO
- } // getItemCount()
-
- /**
- * getItemAt
- * @param value0 TODO
- * @returns Object
- */
- public Object getItemAt(int value0) {
- return null; // TODO
- } // getItemAt()
-
- /**
- * createDefaultKeySelectionManager
- * @returns KeySelectionManager
- */
- protected KeySelectionManager createDefaultKeySelectionManager() {
- return null; // TODO
- } // createDefaultKeySelectionManager()
-
- /**
- * paramString
- * @returns String
- */
- protected String paramString() {
- return null; // TODO
- } // paramString()
-
- /**
- * getAccessibleContext
- * @returns AccessibleContext
+ /**
+ * Forces JComboBox to select component located in the given index in the
+ * combo box.
+ *
+ * @param index index specifying location of the component that should be
+ * selected.
+ */
+ public void setSelectedIndex(int index)
+ {
+ // FIXME: if index == -1 then nothing should be selected
+ setSelectedItem(dataModel.getElementAt(index));
+ }
+
+ /**
+ * Returns index of the item that is currently selected in the combo box.
+ * If no item is currently selected, then -1 is returned.
+ *
+ * @return int index specifying location of the currently selected item in
+ * the combo box or -1 if nothing is selected in the combo box.
+ */
+ public int getSelectedIndex()
+ {
+ Object selectedItem = getSelectedItem();
+ if (selectedItem != null && (dataModel instanceof DefaultComboBoxModel))
+ return ((DefaultComboBoxModel) dataModel).getIndexOf(selectedItem);
+
+ return -1;
+ }
+
+ public Object getPrototypeDisplayValue()
+ {
+ return prototypeDisplayValue;
+ }
+
+ public void setPrototypeDisplayValue(Object prototypeDisplayValue)
+ {
+ this.prototypeDisplayValue = prototypeDisplayValue;
+ }
+
+ /**
+ * This method adds given element to this JComboBox.
+ *
+ * @param element element to add
+ */
+ public void addItem(Object element)
+ {
+ ((MutableComboBoxModel) dataModel).addElement(element);
+ }
+
+ /**
+ * Inserts given element at the specified index to this JComboBox
+ *
+ * @param element element to insert
+ * @param index position where to insert the element
+ */
+ public void insertItemAt(Object element, int index)
+ {
+ ((MutableComboBoxModel) dataModel).insertElementAt(element, index);
+ }
+
+ /**
+ * This method removes given element from this JComboBox.
+ *
+ * @param element element to remove
*/
+ public void removeItem(Object element)
+ {
+ ((MutableComboBoxModel) dataModel).removeElement(element);
+ }
+
+ /**
+ * This method remove element location in the specified index in the
+ * JComboBox.
+ *
+ * @param index index specifying position of the element to remove
+ */
+ public void removeItemAt(int index)
+ {
+ ((MutableComboBoxModel) dataModel).removeElementAt(index);
+ }
+
+ /**
+ * This method removes all elements from this JComboBox.
+ */
+ public void removeAllItems()
+ {
+ if (dataModel instanceof DefaultComboBoxModel)
+ ((DefaultComboBoxModel) dataModel).removeAllElements();
+ }
+
+ /**
+ * This method displays popup with list of combo box's items on the screen
+ */
+ public void showPopup()
+ {
+ setPopupVisible(true);
+ }
+
+ /**
+ * This method hides popup containing list of combo box's items
+ */
+ public void hidePopup()
+ {
+ setPopupVisible(false);
+ }
+
+ /**
+ * This method either displayes or hides the popup containing list of combo
+ * box's items.
+ *
+ * @param visible show popup if 'visible' is true and hide it otherwise
+ */
+ public void setPopupVisible(boolean visible)
+ {
+ getUI().setPopupVisible(this, visible);
+ }
+
+ /**
+ * Checks if popup is currently visible on the screen.
+ *
+ * @return boolean true if popup is visible and false otherwise
+ */
+ public boolean isPopupVisible()
+ {
+ return getUI().isPopupVisible(this);
+ }
+
+ /**
+ * This method sets actionCommand to the specified string. ActionEvent fired
+ * to this JComboBox registered ActionListeners will contain this
+ * actionCommand.
+ *
+ * @param aCommand new action command for the JComboBox's ActionEvent
+ */
+ public void setActionCommand(String aCommand)
+ {
+ actionCommand = aCommand;
+ }
+
+ /**
+ * Returns actionCommand associated with the ActionEvent fired by the
+ * JComboBox to its registered ActionListeners.
+ *
+ * @return String actionCommand for the ActionEvent
+ */
+ public String getActionCommand()
+ {
+ return actionCommand;
+ }
+
+ /**
+ * setAction
+ *
+ * @param a action to set
+ */
+ public void setAction(Action a)
+ {
+ Action old = action;
+ action = a;
+ configurePropertiesFromAction(action);
+ if (action != null)
+ // FIXME: remove from old action and add to new action
+ // PropertyChangeListener to listen to changes in the action
+ addActionListener(action);
+ }
+
+ /**
+ * This method returns Action that is invoked when selected item is changed
+ * in the JComboBox.
+ *
+ * @return Action
+ */
+ public Action getAction()
+ {
+ return action;
+ }
+
+ /**
+ * Configure properties of the JComboBox by reading properties of specified
+ * action. This method always sets the comboBox's "enabled" property to the
+ * value of the Action's "enabled" property.
+ *
+ * @param a An Action to configure the combo box from
+ */
+ protected void configurePropertiesFromAction(Action a)
+ {
+ if (a == null)
+ {
+ setEnabled(true);
+ setToolTipText(null);
+ }
+ else
+ {
+ setEnabled(a.isEnabled());
+ setToolTipText((String) (a.getValue(Action.SHORT_DESCRIPTION)));
+ }
+ }
+
+ /**
+ * Creates PropertyChangeListener to listen for the changes in comboBox's
+ * action properties.
+ *
+ * @param action action to listen to for property changes
+ *
+ * @return $PropertyChangeListener$ Listener that listens to changes in
+ * action properties.
+ */
+ protected PropertyChangeListener createActionPropertyChangeListener(Action action)
+ {
+ return new PropertyChangeListener()
+ {
+ public void propertyChange(PropertyChangeEvent e)
+ {
+ Action act = (Action) (e.getSource());
+ configurePropertiesFromAction(act);
+ }
+ };
+ }
+
+ /**
+ * This method fires ItemEvent to this JComboBox's registered ItemListeners.
+ * This method is invoked when currently selected item in this combo box
+ * has changed.
+ *
+ * @param e the ItemEvent describing the change in the combo box's
+ * selection.
+ */
+ protected void fireItemStateChanged(ItemEvent e)
+ {
+ ItemListener[] ll = getItemListeners();
+
+ for (int i = 0; i < ll.length; i++)
+ ll[i].itemStateChanged(e);
+ }
+
+ /**
+ * This method fires ActionEvent to this JComboBox's registered
+ * ActionListeners. This method is invoked when user explicitly changes
+ * currently selected item.
+ */
+ protected void fireActionEvent()
+ {
+ ActionListener[] ll = getActionListeners();
+
+ for (int i = 0; i < ll.length; i++)
+ ll[i].actionPerformed(new ActionEvent(this,
+ ActionEvent.ACTION_PERFORMED,
+ actionCommand));
+ }
+
+ /**
+ * This method is invoked whenever selected item changes in the combo box's
+ * data model. It fires ItemEvent and ActionEvent to all registered
+ * ComboBox's ItemListeners and ActionListeners respectively, indicating
+ * the change.
+ */
+ protected void selectedItemChanged()
+ {
+ // Fire ItemEvent to indicated that previously selected item is now
+ // deselected
+ if (selectedItemReminder != null)
+ fireItemStateChanged(new ItemEvent(this, ItemEvent.ITEM_STATE_CHANGED,
+ selectedItemReminder,
+ ItemEvent.DESELECTED));
+
+ // Fire ItemEvent to indicate that new item is selected
+ Object newSelection = getSelectedItem();
+ fireItemStateChanged(new ItemEvent(this, ItemEvent.ITEM_STATE_CHANGED,
+ newSelection, ItemEvent.SELECTED));
+
+ // Fire Action Event to JComboBox's registered listeners
+ fireActionEvent();
+
+ selectedItemReminder = newSelection;
+ }
+
+ /**
+ * Returns Object array of size 1 containing currently selected element in
+ * the JComboBox.
+ *
+ * @return Object[] Object array of size 1 containing currently selected
+ * element in the JComboBox.
+ */
+ public Object[] getSelectedObjects()
+ {
+ Object selectedObject = getSelectedItem();
+ return new Object[] { selectedObject };
+ }
+
+ /**
+ * This method handles actionEvents fired by the ComboBoxEditor. It changes
+ * this JComboBox's selection to the new value currently in the editor and
+ * hides list of combo box items.
+ *
+ * @param e the ActionEvent
+ */
+ public void actionPerformed(ActionEvent e)
+ {
+ setSelectedItem(((ComboBoxEditor) e.getSource()).getItem());
+ setPopupVisible(false);
+ }
+
+ /**
+ * This method selects item in this combo box that matches specified
+ * specified keyChar and returns true if such item is found. Otherwise
+ * false is returned.
+ *
+ * @param keyChar character indicating which item in the combo box should be
+ * selected.
+ *
+ * @return boolean true if item corresponding to the specified keyChar
+ * exists in the combo box. Otherwise false is returned.
+ */
+ public boolean selectWithKeyChar(char keyChar)
+ {
+ // FIXME: Need to implement
+ return false;
+ }
+
+ /**
+ * The part of implementation of ListDataListener interface. This method is
+ * invoked when some items where added to the JComboBox's data model.
+ *
+ * @param event ListDataEvent describing the change
+ */
+ public void intervalAdded(ListDataEvent event)
+ {
+ // FIXME: Need to implement
+ repaint();
+ }
+
+ /**
+ * The part of implementation of ListDataListener interface. This method is
+ * invoked when some items where removed from the JComboBox's data model.
+ *
+ * @param event ListDataEvent describing the change.
+ */
+ public void intervalRemoved(ListDataEvent event)
+ {
+ // FIXME: Need to implement
+ repaint();
+ }
+
+ /**
+ * The part of implementation of ListDataListener interface. This method is
+ * invoked when contents of the JComboBox's data model changed.
+ *
+ * @param event ListDataEvent describing the change
+ */
+ public void contentsChanged(ListDataEvent event)
+ {
+ // if first and last index of the given ListDataEvent are both -1,
+ // then it indicates that selected item in the combo box data model
+ // have changed.
+ if (event.getIndex0() == -1 && event.getIndex1() == -1)
+ selectedItemChanged();
+ }
+
+ /**
+ * This method disables or enables JComboBox. If the JComboBox is enabled,
+ * then user is able to make item choice, otherwise if JComboBox is
+ * disabled then user is not able to make a selection.
+ *
+ * @param enabled if 'enabled' is true then enable JComboBox and disable it
+ */
+ public void setEnabled(boolean enabled)
+ {
+ boolean oldEnabled = super.isEnabled();
+ if (enabled != oldEnabled)
+ {
+ super.setEnabled(enabled);
+ firePropertyChange(ENABLED_CHANGED_PROPERTY, oldEnabled,
+ (boolean) enabled);
+ }
+ }
+
+ /**
+ * This method initializes specified ComboBoxEditor to display given item.
+ *
+ * @param anEditor ComboBoxEditor to initialize
+ * @param anItem Item that should displayed in the specified editor
+ */
+ public void configureEditor(ComboBoxEditor anEditor, Object anItem)
+ {
+ anEditor.setItem(anItem);
+ }
+
+ /**
+ * This method hides combo box's popup whenever TAB key is pressed.
+ *
+ * @param e The KeyEvent indicating which key was pressed.
+ */
+ public void processKeyEvent(KeyEvent e)
+ {
+ }
+
+ /**
+ * This method always returns false to indicate that JComboBox itself is
+ * not focus traversable.
+ *
+ * @return false to indicate that JComboBox itself is not focus traversable.
+ *
+ * @deprecated
+ */
+ public boolean isFocusTraversable()
+ {
+ return false;
+ }
+
+ /**
+ * setKeySelectionManager
+ *
+ * @param aManager
+ */
+ public void setKeySelectionManager(KeySelectionManager aManager)
+ {
+ }
+
+ /**
+ * getKeySelectionManager
+ *
+ * @return JComboBox.KeySelectionManager
+ */
+ public KeySelectionManager getKeySelectionManager()
+ {
+ return null;
+ }
+
+ /**
+ * This method returns number of elements in this JComboBox
+ *
+ * @return int number of elements in this JComboBox
+ */
+ public int getItemCount()
+ {
+ return ((DefaultComboBoxModel) dataModel).getSize();
+ }
+
+ /**
+ * Returns elements located in the combo box at the given index.
+ *
+ * @param index index specifying location of the component to return.
+ *
+ * @return component in the combo box that is located in the given index.
+ */
+ public Object getItemAt(int index)
+ {
+ return ((MutableComboBoxModel) dataModel).getElementAt(index);
+ }
+
+ /**
+ * createDefaultKeySelectionManager
+ *
+ * @return KeySelectionManager
+ */
+ protected KeySelectionManager createDefaultKeySelectionManager()
+ {
+ return null;
+ }
+
+ /**
+ * A string that describes this JComboBox. Normally only used for debugging.
+ *
+ * @return A string describing this JComboBox
+ */
+ protected String paramString()
+ {
+ return "JComboBox";
+ }
+
public AccessibleContext getAccessibleContext()
{
if (accessibleContext == null)
@@ -797,74 +994,180 @@ public class JComboBox extends JComponent
return accessibleContext;
}
-
+
/**
- * addActionListener
- * @param listener TODO
+ * This methods adds specified ActionListener to this JComboBox.
+ *
+ * @param listener to add
*/
- public void addActionListener (ActionListener listener)
+ public void addActionListener(ActionListener listener)
{
- listenerList.add (ActionListener.class, listener);
+ listenerList.add(ActionListener.class, listener);
}
/**
- * removeActionListener
- * @param listener TODO
+ * This method removes specified ActionListener from this JComboBox.
+ *
+ * @param listener ActionListener
*/
- public void removeActionListener (ActionListener listener)
+ public void removeActionListener(ActionListener listener)
{
- listenerList.remove (ActionListener.class, listener);
+ listenerList.remove(ActionListener.class, listener);
}
/**
+ * This method returns array of ActionListeners that are registered with
+ * this JComboBox.
+ *
* @since 1.4
*/
public ActionListener[] getActionListeners()
{
- return (ActionListener[]) getListeners (ActionListener.class);
+ return (ActionListener[]) getListeners(ActionListener.class);
}
/**
- * addItemListener
- * @param listener TODO
+ * This method registers given ItemListener with this JComboBox
+ *
+ * @param listener to remove
*/
public void addItemListener(ItemListener listener)
{
- listenerList.add (ItemListener.class, listener);
+ listenerList.add(ItemListener.class, listener);
}
/**
- * removeItemListener
- * @param listener TODO
+ * This method unregisters given ItemListener from this JComboBox
+ *
+ * @param listener to remove
*/
public void removeItemListener(ItemListener listener)
{
- listenerList.remove (ItemListener.class, listener);
+ listenerList.remove(ItemListener.class, listener);
}
/**
+ * This method returns array of ItemListeners that are registered with this
+ * JComboBox.
+ *
* @since 1.4
*/
public ItemListener[] getItemListeners()
{
- return (ItemListener[]) getListeners (ItemListener.class);
+ return (ItemListener[]) getListeners(ItemListener.class);
}
- public void addPopupMenuListener (PopupMenuListener listener)
+ /**
+ * Adds PopupMenuListener to combo box to listen to the events fired by the
+ * combo box's popup menu containing its list of items
+ *
+ * @param listener to add
+ */
+ public void addPopupMenuListener(PopupMenuListener listener)
{
- listenerList.add (PopupMenuListener.class, listener);
+ listenerList.add(PopupMenuListener.class, listener);
}
- public void removePopupMenuListener (PopupMenuListener listener)
+ /**
+ * Removes PopupMenuListener to combo box to listen to the events fired by
+ * the combo box's popup menu containing its list of items
+ *
+ * @param listener to add
+ */
+ public void removePopupMenuListener(PopupMenuListener listener)
{
- listenerList.remove (PopupMenuListener.class, listener);
+ listenerList.remove(PopupMenuListener.class, listener);
}
/**
- * @since 1.4
+ * Returns array of PopupMenuListeners that are registered with combo box.
*/
public PopupMenuListener[] getPopupMenuListeners()
{
- return (PopupMenuListener[]) getListeners (PopupMenuListener.class);
+ return (PopupMenuListener[]) getListeners(PopupMenuListener.class);
+ }
+
+ /**
+ * AccessibleJComboBox
+ */
+ protected class AccessibleJComboBox extends AccessibleJComponent
+ implements AccessibleAction, AccessibleSelection
+ {
+ private static final long serialVersionUID = 8217828307256675666L;
+
+ protected AccessibleJComboBox()
+ {
+ }
+
+ public int getAccessibleChildrenCount()
+ {
+ return 0;
+ }
+
+ public Accessible getAccessibleChild(int value0)
+ {
+ return null;
+ }
+
+ public AccessibleSelection getAccessibleSelection()
+ {
+ return null;
+ }
+
+ public Accessible getAccessibleSelection(int value0)
+ {
+ return null;
+ }
+
+ public boolean isAccessibleChildSelected(int value0)
+ {
+ return false;
+ }
+
+ public AccessibleRole getAccessibleRole()
+ {
+ return AccessibleRole.COMBO_BOX;
+ }
+
+ public AccessibleAction getAccessibleAction()
+ {
+ return null;
+ }
+
+ public String getAccessibleActionDescription(int value0)
+ {
+ return null;
+ }
+
+ public int getAccessibleActionCount()
+ {
+ return 0;
+ }
+
+ public boolean doAccessibleAction(int value0)
+ {
+ return false;
+ }
+
+ public int getAccessibleSelectionCount()
+ {
+ return 0;
+ }
+
+ public void addAccessibleSelection(int value0)
+ {
+ }
+
+ public void removeAccessibleSelection(int value0)
+ {
+ }
+
+ public void clearAccessibleSelection()
+ {
+ }
+
+ public void selectAllAccessibleSelection()
+ {
+ }
}
}
diff --git a/libjava/javax/swing/JComponent.java b/libjava/javax/swing/JComponent.java
index e8f01d0..eadf855 100644
--- a/libjava/javax/swing/JComponent.java
+++ b/libjava/javax/swing/JComponent.java
@@ -37,6 +37,7 @@ exception statement from your version. */
package javax.swing;
+import java.awt.AWTEvent;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
@@ -48,11 +49,13 @@ import java.awt.Image;
import java.awt.Insets;
import java.awt.Point;
import java.awt.Rectangle;
+import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ContainerEvent;
import java.awt.event.ContainerListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
+import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.geom.Rectangle2D;
import java.awt.image.ImageObserver;
@@ -192,22 +195,12 @@ public abstract class JComponent extends Container implements Serializable
Border border;
/**
- * A tooltip associated with this component.
- *
- * @see #setToolTip
- * @see #getToolTip
- * @see #toolTipText
- */
- JToolTip toolTip;
-
- /**
- * The text to show in the tooltip associated with this component.
+ * The text to show in the tooltip associated with this component.
*
* @see #setToolTipText
* @see #getToolTipText
- * @see #toolTip
*/
- String toolTipText;
+ String toolTipText;
/**
* <p>Whether to double buffer this component when painting. This flag
@@ -325,6 +318,11 @@ public abstract class JComponent extends Container implements Serializable
* first client property.
*/
private Hashtable clientProperties;
+
+ private InputMap inputMap_whenFocused;
+ private InputMap inputMap_whenAncestorOfFocused;
+ private InputMap inputMap_whenInFocusedWindow;
+ private ActionMap actionMap;
/**
* A lock held during recursive painting; this is used to serialize
@@ -757,18 +755,6 @@ public abstract class JComponent extends Container implements Serializable
return null;
}
- /**
- * Get the ActionListener (typically an {@link Action} object) which is
- * associated with a particular keystroke.
- *
- * @param aKeyStroke The keystroke to retrieve the action of
- *
- * @return The action associated with the specified keystroke
- */
- public ActionListener getActionForKeyStroke(KeyStroke aKeyStroke)
- {
- return null;
- }
/**
* Get the value of the {@link #alignmentX} property.
@@ -875,24 +861,6 @@ public abstract class JComponent extends Container implements Serializable
return g;
}
- /**
- * Return the condition that determines whether a registered action
- * occurs in response to the specified keystroke.
- *
- * @param aKeyStroke The keystroke to return the condition of
- *
- * @return One of the values {@link #UNDEFINED_CONDITION}, {@link
- * #WHEN_ANCESTOR_OF_FOCUSED_COMPONENT}, {@link #WHEN_FOCUSED}, or {@link
- * #WHEN_IN_FOCUSED_WINDOW}
- *
- * @see #registerKeyboardAction
- * @see #unregisterKeyboardAction
- * @see #resetKeyboardActiond
- */
- public int getConditionForKeyStroke(KeyStroke aKeyStroke)
- {
- return UNDEFINED_CONDITION;
- }
/**
* Get the value of the {@link #debugGraphicsOptions} property.
@@ -1113,11 +1081,9 @@ public abstract class JComponent extends Container implements Serializable
*/
public JToolTip createToolTip()
{
- if (toolTip == null)
- {
- toolTip = new JToolTip();
+ JToolTip toolTip = new JToolTip();
+ toolTip.setComponent(this);
toolTip.setTipText(toolTipText);
- }
return toolTip;
}
@@ -1145,7 +1111,22 @@ public abstract class JComponent extends Container implements Serializable
*/
public void setToolTipText(String text)
{
+ if (text == null)
+ {
+ ToolTipManager.sharedInstance().unregisterComponent(this);
+ toolTipText = null;
+ return;
+ }
+
+ // XXX: The tip text doesn't get updated unless you set it to null
+ // and then to something not-null. This is consistent with the behaviour
+ // of Sun's ToolTipManager.
+
+ String oldText = toolTipText;
toolTipText = text;
+
+ if (oldText == null)
+ ToolTipManager.sharedInstance().registerComponent(this);
}
/**
@@ -1172,7 +1153,7 @@ public abstract class JComponent extends Container implements Serializable
*/
public String getToolTipText(MouseEvent event)
{
- return toolTipText;
+ return getToolTipText();
}
/**
@@ -1519,6 +1500,51 @@ public abstract class JComponent extends Container implements Serializable
registerKeyboardAction(act, null, stroke, cond);
}
+ /*
+ * There is some charmingly undocumented behavior sun seems to be using
+ * to simulate the old register/unregister keyboard binding API. It's not
+ * clear to me why this matters, but we shall endeavour to follow suit.
+ *
+ * Two main thing seem to be happening when you do registerKeyboardAction():
+ *
+ * - no actionMap() entry gets created, just an entry in inputMap()
+ *
+ * - the inputMap() entry is a proxy class which invokes the the
+ * binding's actionListener as a target, and which clobbers the command
+ * name sent in the ActionEvent, providing the binding command name
+ * instead.
+ *
+ * This much you can work out just by asking the input and action maps
+ * what they contain after making bindings, and watching the event which
+ * gets delivered to the recipient. Beyond that, it seems to be a
+ * sun-private solution so I will only immitate it as much as it matters
+ * to external observers.
+ */
+
+ private static class ActionListenerProxy
+ extends AbstractAction
+ {
+ ActionListener target;
+ String bindingCommandName;
+
+ public ActionListenerProxy(ActionListener li,
+ String cmd)
+ {
+ target = li;
+ bindingCommandName = cmd;
+ }
+
+ public void actionPerformed(ActionEvent e)
+ {
+ ActionEvent derivedEvent = new ActionEvent(e.getSource(),
+ e.getID(),
+ bindingCommandName,
+ e.getModifiers());
+ target.actionPerformed(derivedEvent);
+ }
+ }
+
+
/**
* An obsolete method to register a keyboard action on this component.
* You should use <code>getInputMap</code> and <code>getActionMap</code>
@@ -1543,9 +1569,186 @@ public abstract class JComponent extends Container implements Serializable
KeyStroke stroke,
int cond)
{
+ getInputMap(cond).put(stroke, new ActionListenerProxy(act, cmd));
+ }
+
+
+
+ public final void setInputMap(int condition, InputMap map)
+ {
+ enableEvents(AWTEvent.KEY_EVENT_MASK);
+ switch (condition)
+ {
+ case WHEN_FOCUSED:
+ inputMap_whenFocused = map;
+ break;
+
+ case WHEN_ANCESTOR_OF_FOCUSED_COMPONENT:
+ inputMap_whenAncestorOfFocused = map;
+ break;
+
+ case WHEN_IN_FOCUSED_WINDOW:
+ inputMap_whenInFocusedWindow = map;
+ break;
+
+ case UNDEFINED_CONDITION:
+ default:
+ throw new IllegalArgumentException();
+ }
+ }
+
+ public final InputMap getInputMap(int condition)
+ {
+ enableEvents(AWTEvent.KEY_EVENT_MASK);
+ switch (condition)
+ {
+ case WHEN_FOCUSED:
+ if (inputMap_whenFocused == null)
+ inputMap_whenFocused = new InputMap();
+ return inputMap_whenFocused;
+
+ case WHEN_ANCESTOR_OF_FOCUSED_COMPONENT:
+ if (inputMap_whenAncestorOfFocused == null)
+ inputMap_whenAncestorOfFocused = new InputMap();
+ return inputMap_whenAncestorOfFocused;
+
+ case WHEN_IN_FOCUSED_WINDOW:
+ if (inputMap_whenInFocusedWindow == null)
+ inputMap_whenInFocusedWindow = new InputMap();
+ return inputMap_whenInFocusedWindow;
+
+ case UNDEFINED_CONDITION:
+ default:
+ return null;
+ }
+ }
+
+ public final InputMap getInputMap()
+ {
+ return getInputMap(WHEN_FOCUSED);
+ }
+
+ public final ActionMap getActionMap()
+ {
+ if (actionMap == null)
+ actionMap = new ActionMap();
+ return actionMap;
+ }
+
+ public final void setActionMap(ActionMap map)
+ {
+ actionMap = map;
}
/**
+ * @deprecated As of 1.3 KeyStrokes can be registered with multiple
+ * simultaneous conditions.
+ *
+ * Return the condition that determines whether a registered action
+ * occurs in response to the specified keystroke.
+ *
+ * @param aKeyStroke The keystroke to return the condition of
+ *
+ * @return One of the values {@link #UNDEFINED_CONDITION}, {@link
+ * #WHEN_ANCESTOR_OF_FOCUSED_COMPONENT}, {@link #WHEN_FOCUSED}, or {@link
+ * #WHEN_IN_FOCUSED_WINDOW}
+ *
+ * @see #registerKeyboardAction
+ * @see #unregisterKeyboardAction
+ * @see #resetKeyboardActiond
+ */
+ public int getConditionForKeyStroke(KeyStroke ks)
+ {
+ if (inputMap_whenFocused != null
+ && inputMap_whenFocused.get(ks) != null)
+ return WHEN_FOCUSED;
+ else if (inputMap_whenAncestorOfFocused != null
+ && inputMap_whenAncestorOfFocused.get(ks) != null)
+ return WHEN_ANCESTOR_OF_FOCUSED_COMPONENT;
+ else if (inputMap_whenInFocusedWindow != null
+ && inputMap_whenInFocusedWindow.get(ks) != null)
+ return WHEN_IN_FOCUSED_WINDOW;
+ else
+ return UNDEFINED_CONDITION;
+ }
+
+ /**
+ * @deprecated Use {@link #getActionMap()}
+ *
+ * Get the ActionListener (typically an {@link Action} object) which is
+ * associated with a particular keystroke.
+ *
+ * @param aKeyStroke The keystroke to retrieve the action of
+ *
+ * @return The action associated with the specified keystroke
+ */
+ public ActionListener getActionForKeyStroke(KeyStroke ks)
+ {
+ Object cmd = getInputMap().get(ks);
+ if (cmd != null)
+ {
+ if (cmd instanceof ActionListenerProxy)
+ return (ActionListenerProxy) cmd;
+ else if (cmd instanceof String)
+ return getActionMap().get(cmd);
+ }
+ return null;
+ }
+
+ /**
+ * A hook for subclasses which want to customize event processing.
+ */
+ protected void processComponentKeyEvent(KeyEvent e)
+ {
+ }
+
+ /**
+ * Override the default key dispatch system from Component to hook into
+ * the swing {@link InputMap} / {@link ActionMap} system.
+ *
+ * See <a
+ * href="http://java.sun.com/products/jfc/tsc/special_report/kestrel/keybindings.html">this
+ * report</a> for more details, it's somewhat complex.
+ */
+ protected void processKeyEvent(KeyEvent e)
+ {
+ processComponentKeyEvent(e);
+
+ // FIXME: this needs to be elaborated significantly, to do all the
+ // focus / ancestor / window searching for the various binding modes.
+ if (! e.isConsumed() &&
+ processKeyBinding(KeyStroke.getKeyStrokeForEvent(e),
+ e, WHEN_FOCUSED, e.getID() == KeyEvent.KEY_PRESSED))
+ e.consume();
+ }
+
+ protected boolean processKeyBinding(KeyStroke ks,
+ KeyEvent e,
+ int condition,
+ boolean pressed)
+ {
+ if (isEnabled())
+ {
+ Action act = null;
+ InputMap map = getInputMap(condition);
+ if (map != null)
+ {
+ Object cmd = map.get(ks);
+ if (cmd != null)
+ {
+ if (cmd instanceof ActionListenerProxy)
+ act = (Action) cmd;
+ else
+ act = (Action) getActionMap().get(cmd);
+ }
+ }
+ if (act != null && act.isEnabled())
+ return SwingUtilities.notifyAction(act, ks, e, this, e.getModifiers());
+ }
+ return false;
+ }
+
+ /**
* Remove a keyboard action registry.
*
* @param stroke The keystroke to unregister
@@ -1568,6 +1771,14 @@ public abstract class JComponent extends Container implements Serializable
*/
public void resetKeyboardActions()
{
+ if (inputMap_whenFocused != null)
+ inputMap_whenFocused.clear();
+ if (inputMap_whenAncestorOfFocused != null)
+ inputMap_whenAncestorOfFocused.clear();
+ if (inputMap_whenInFocusedWindow != null)
+ inputMap_whenInFocusedWindow.clear();
+ if (actionMap != null)
+ actionMap.clear();
}
@@ -1875,11 +2086,14 @@ public abstract class JComponent extends Container implements Serializable
if (ui != null)
ui.uninstallUI(this);
+ ComponentUI oldUI = ui;
ui = newUI;
if (ui != null)
ui.installUI(this);
+ firePropertyChange("UI", oldUI, newUI);
+
revalidate();
repaint();
}
diff --git a/libjava/javax/swing/JFormattedTextField.java b/libjava/javax/swing/JFormattedTextField.java
index b84d7cc..8074799 100644
--- a/libjava/javax/swing/JFormattedTextField.java
+++ b/libjava/javax/swing/JFormattedTextField.java
@@ -135,7 +135,7 @@ public class JFormattedTextField extends JTextField
public JFormattedTextField ()
{
- throw new InternalError ("not implemented");
+ this((AbstractFormatterFactory) null);
}
public JFormattedTextField (Format format)
@@ -150,7 +150,7 @@ public class JFormattedTextField extends JTextField
public JFormattedTextField (AbstractFormatterFactory factory)
{
- throw new InternalError ("not implemented");
+ this(factory, null);
}
public JFormattedTextField (AbstractFormatterFactory factory, Object value)
diff --git a/libjava/javax/swing/JLabel.java b/libjava/javax/swing/JLabel.java
index 0a15cfc..652c965 100644
--- a/libjava/javax/swing/JLabel.java
+++ b/libjava/javax/swing/JLabel.java
@@ -38,8 +38,9 @@ exception statement from your version. */
package javax.swing;
import java.awt.Component;
-import java.awt.Image;
import java.awt.Font;
+import java.awt.Image;
+import java.awt.event.KeyEvent;
import javax.accessibility.Accessible;
import javax.accessibility.AccessibleContext;
import javax.swing.Icon;
@@ -48,7 +49,7 @@ import javax.swing.plaf.LabelUI;
/**
* <p>
- * A swing widget that displays a text message and/or an icon.
+ * A swing widget that displays a text message and/or an icon.
* </p>
*/
public class JLabel extends JComponent implements Accessible, SwingConstants
@@ -63,10 +64,10 @@ public class JLabel extends JComponent implements Accessible, SwingConstants
protected Component labelFor;
/** The label's text. */
- private transient String labelText;
+ private transient String text;
/** Where the label will be positioned horizontally. */
- private transient int horizontalAlignment = CENTER;
+ private transient int horizontalAlignment = LEADING;
/** Where the label text will be placed horizontally relative to the icon. */
private transient int horizontalTextPosition = TRAILING;
@@ -78,16 +79,16 @@ public class JLabel extends JComponent implements Accessible, SwingConstants
private transient int verticalTextPosition = CENTER;
/** The icon painted when the label is enabled. */
- private transient Icon activeIcon;
+ private transient Icon icon;
/** The icon painted when the label is disabled. */
private transient Icon disabledIcon;
/** The label's mnemnonic key. */
- private transient char mnemonicKey;
+ private transient int displayedMnemonic = KeyEvent.VK_UNDEFINED;
/** The index of the menemonic character in the text. */
- private transient int underlinedChar = -1;
+ private transient int displayedMnemonicIndex = -1;
/** The gap between the icon and the text. */
private transient int iconTextGap = 4;
@@ -102,10 +103,11 @@ public class JLabel extends JComponent implements Accessible, SwingConstants
* changes.
*/
public static final String DISPLAYED_MNEMONIC_CHANGED_PROPERTY = "displayedMnemonic";
-
+
/**
- * Fired in a PropertyChangeEvent when the "displayedMnemonicIndex"
- * property changes. */
+ * Fired in a PropertyChangeEvent when the "displayedMnemonicIndex" property
+ * changes.
+ */
public static final String DISPLAYED_MNEMONIC_INDEX_CHANGED_PROPERTY = "displayedMnemonicIndex";
/**
@@ -145,8 +147,8 @@ public class JLabel extends JComponent implements Accessible, SwingConstants
public static final String VERTICAL_TEXT_POSITION_CHANGED_PROPERTY = "verticalTextPosition";
/**
- * Creates a new horizontally and vertically centered JLabel object with no text and no
- * icon.
+ * Creates a new horizontally and vertically centered JLabel object with no
+ * text and no icon.
*/
public JLabel()
{
@@ -154,8 +156,8 @@ public class JLabel extends JComponent implements Accessible, SwingConstants
}
/**
- * Creates a new horizontally and vertically centered JLabel object with no text and the
- * given icon.
+ * Creates a new horizontally and vertically centered JLabel object with no
+ * text and the given icon.
*
* @param image The icon to use with the label.
*/
@@ -165,8 +167,9 @@ public class JLabel extends JComponent implements Accessible, SwingConstants
}
/**
- * Creates a new vertically centered JLabel object with no text and the given icon and
- * horizontal alignment. By default, the text is TRAILING the image.
+ * Creates a new vertically centered JLabel object with no text and the
+ * given icon and horizontal alignment. By default, the text is TRAILING
+ * the image.
*
* @param image The icon to use with the label.
* @param horizontalAlignment The horizontal alignment of the label.
@@ -177,8 +180,8 @@ public class JLabel extends JComponent implements Accessible, SwingConstants
}
/**
- * Creates a new horizontally and vertically centered JLabel object with no icon and the
- * given text.
+ * Creates a new horizontally and vertically centered JLabel object with no
+ * icon and the given text.
*
* @param text The text to use with the label.
*/
@@ -188,8 +191,8 @@ public class JLabel extends JComponent implements Accessible, SwingConstants
}
/**
- * Creates a new vertically centered JLabel object with no icon and the given text and
- * horizontal alignment.
+ * Creates a new vertically centered JLabel object with no icon and the
+ * given text and horizontal alignment.
*
* @param text The text to use with the label.
* @param horizontalAlignment The horizontal alignment of the label.
@@ -200,8 +203,8 @@ public class JLabel extends JComponent implements Accessible, SwingConstants
}
/**
- * Creates a new vertically centered JLabel object with the given text, icon, and horizontal
- * alignment.
+ * Creates a new vertically centered JLabel object with the given text,
+ * icon, and horizontal alignment.
*
* @param text The text to use with the label.
* @param icon The icon to use with the label.
@@ -209,8 +212,8 @@ public class JLabel extends JComponent implements Accessible, SwingConstants
*/
public JLabel(String text, Icon icon, int horizontalAlignment)
{
- labelText = text;
- activeIcon = icon;
+ this.text = text;
+ this.icon = icon;
this.horizontalAlignment = horizontalAlignment;
updateUI();
}
@@ -273,24 +276,25 @@ public class JLabel extends JComponent implements Accessible, SwingConstants
*/
public String getText()
{
- return labelText;
+ return text;
}
/**
* This method changes the "text" property. The given text will be painted
* in the label.
*
- * @param text The label's text.
+ * @param newText The label's text.
*/
- public void setText(String text)
+ public void setText(String newText)
{
- if (text != labelText)
+ if (text != newText)
{
- String oldText = labelText;
- labelText = text;
- firePropertyChange(TEXT_CHANGED_PROPERTY, oldText, labelText);
- if (labelText != null && labelText.length() <= underlinedChar)
- setDisplayedMnemonicIndex(labelText.length() - 1);
+ String oldText = text;
+ text = newText;
+ firePropertyChange(TEXT_CHANGED_PROPERTY, oldText, newText);
+
+ if (text != null && text.length() <= displayedMnemonicIndex)
+ setDisplayedMnemonicIndex(text.length() - 1);
}
}
@@ -302,37 +306,39 @@ public class JLabel extends JComponent implements Accessible, SwingConstants
*/
public Icon getIcon()
{
- return activeIcon;
+ return icon;
}
/**
* This method changes the "icon" property. This icon (the active icon) will
* be the one displayed when the label is enabled.
*
- * @param icon The active icon.
+ * @param newIcon The active icon.
*/
- public void setIcon(Icon icon)
+ public void setIcon(Icon newIcon)
{
- if (icon != activeIcon)
+ if (icon != newIcon)
{
- Icon oldIcon = activeIcon;
- activeIcon = icon;
- firePropertyChange(ICON_CHANGED_PROPERTY, oldIcon, activeIcon);
+ Icon oldIcon = icon;
+ icon = newIcon;
+ firePropertyChange(ICON_CHANGED_PROPERTY, oldIcon, newIcon);
}
}
/**
* This method returns the disabled icon. The disabled icon is painted when
- * the label is disabled. If the disabled icon is null and the active icon is
- * an ImageIcon, this method returns a grayed version of the icon. The grayed
- * version of the icon becomes the disabledIcon.
+ * the label is disabled. If the disabled icon is null and the active icon
+ * is an ImageIcon, this method returns a grayed version of the icon. The
+ * grayed version of the icon becomes the disabledIcon.
*
* @return The disabled icon.
*/
public Icon getDisabledIcon()
{
- if (disabledIcon == null && activeIcon instanceof ImageIcon)
- disabledIcon = new ImageIcon(GrayFilter.createDisabledImage(((ImageIcon) activeIcon).getImage()));
+ if (disabledIcon == null && icon instanceof ImageIcon)
+ disabledIcon = new ImageIcon(GrayFilter.createDisabledImage(((ImageIcon) icon)
+ .getImage()));
+
return disabledIcon;
}
@@ -340,16 +346,15 @@ public class JLabel extends JComponent implements Accessible, SwingConstants
* This method changes the "disabledIcon" property. This icon (the disabled
* icon) will be the one displayed when the label is disabled.
*
- * @param disabledIcon The disabled icon.
+ * @param newIcon The disabled icon.
*/
- public void setDisabledIcon(Icon disabledIcon)
+ public void setDisabledIcon(Icon newIcon)
{
- if (disabledIcon != this.disabledIcon)
+ if (disabledIcon != newIcon)
{
- Icon oldDisabledIcon = this.disabledIcon;
- this.disabledIcon = disabledIcon;
- firePropertyChange(DISABLED_ICON_CHANGED_PROPERTY, oldDisabledIcon,
- this.disabledIcon);
+ Icon oldIcon = disabledIcon;
+ disabledIcon = newIcon;
+ firePropertyChange(DISABLED_ICON_CHANGED_PROPERTY, oldIcon, newIcon);
}
}
@@ -358,11 +363,19 @@ public class JLabel extends JComponent implements Accessible, SwingConstants
* label is used as a label for another component, the label will give
* focus to that component when the mnemonic is activated.
*
- * @param key The keycode to use for the mnemonic.
+ * @param mnemonic The keycode to use for the mnemonic.
*/
- public void setDisplayedMnemonic(int key)
+ public void setDisplayedMnemonic(int mnemonic)
{
- setDisplayedMnemonic((char) key);
+ if (displayedMnemonic != mnemonic)
+ {
+ firePropertyChange(DISPLAYED_MNEMONIC_CHANGED_PROPERTY,
+ displayedMnemonic, mnemonic);
+ displayedMnemonic = mnemonic;
+
+ if (text != null)
+ setDisplayedMnemonicIndex(text.indexOf(mnemonic));
+ }
}
/**
@@ -370,19 +383,11 @@ public class JLabel extends JComponent implements Accessible, SwingConstants
* label is used as a label for another component, the label will give
* focus to that component when the mnemonic is activated.
*
- * @param aChar The character to use for the mnemonic.
+ * @param mnemonic The character to use for the mnemonic.
*/
- public void setDisplayedMnemonic(char aChar)
+ public void setDisplayedMnemonic(char mnemonic)
{
- if (aChar != mnemonicKey)
- {
- char oldKey = mnemonicKey;
- mnemonicKey = aChar;
- firePropertyChange(DISPLAYED_MNEMONIC_CHANGED_PROPERTY, oldKey,
- mnemonicKey);
- if (labelText != null)
- setDisplayedMnemonicIndex(labelText.indexOf(mnemonicKey));
- }
+ setDisplayedMnemonic((int) mnemonic);
}
/**
@@ -392,7 +397,7 @@ public class JLabel extends JComponent implements Accessible, SwingConstants
*/
public int getDisplayedMnemonic()
{
- return (int) mnemonicKey;
+ return (int) displayedMnemonic;
}
/**
@@ -401,27 +406,26 @@ public class JLabel extends JComponent implements Accessible, SwingConstants
* no mnemonic. If the index is less than -1 or if the index is equal to
* the length, this method will throw an IllegalArgumentException.
*
- * @param index The index of the character to underline.
+ * @param newIndex The index of the character to underline.
*
* @throws IllegalArgumentException If index less than -1 or index equals
* length.
*/
- public void setDisplayedMnemonicIndex(int index)
+ public void setDisplayedMnemonicIndex(int newIndex)
throws IllegalArgumentException
{
- if (index < -1 || labelText != null && index >= labelText.length())
+ if (newIndex < -1 || (text != null && newIndex >= text.length()))
throw new IllegalArgumentException();
-
- if (labelText == null || labelText.charAt(index) != mnemonicKey)
- index = -1;
-
- if (index != underlinedChar)
- {
- int oldIndex = underlinedChar;
- underlinedChar = index;
- firePropertyChange(DISPLAYED_MNEMONIC_INDEX_CHANGED_PROPERTY,
- oldIndex, underlinedChar);
- }
+
+ if (text == null || text.charAt(newIndex) != displayedMnemonic)
+ newIndex = -1;
+
+ if (newIndex != displayedMnemonicIndex)
+ {
+ firePropertyChange(DISPLAYED_MNEMONIC_INDEX_CHANGED_PROPERTY,
+ displayedMnemonicIndex, newIndex);
+ displayedMnemonicIndex = newIndex;
+ }
}
/**
@@ -432,7 +436,7 @@ public class JLabel extends JComponent implements Accessible, SwingConstants
*/
public int getDisplayedMnemonicIndex()
{
- return underlinedChar;
+ return displayedMnemonicIndex;
}
/**
@@ -490,16 +494,14 @@ public class JLabel extends JComponent implements Accessible, SwingConstants
* This method changes the "iconTextGap" property. The iconTextGap
* determines how much space there is between the icon and the text.
*
- * @param iconTextGap The gap between the icon and the text.
+ * @param newGap The gap between the icon and the text.
*/
- public void setIconTextGap(int iconTextGap)
+ public void setIconTextGap(int newGap)
{
- if (iconTextGap != this.iconTextGap)
+ if (iconTextGap != newGap)
{
- int oldIconTextGap = this.iconTextGap;
- this.iconTextGap = iconTextGap;
- firePropertyChange(ICON_TEXT_GAP_CHANGED_PROPERTY, oldIconTextGap,
- iconTextGap);
+ firePropertyChange(ICON_TEXT_GAP_CHANGED_PROPERTY, iconTextGap, newGap);
+ iconTextGap = newGap;
}
}
@@ -632,11 +634,12 @@ public class JLabel extends JComponent implements Accessible, SwingConstants
public boolean imageUpdate(Image img, int infoflags, int x, int y, int w,
int h)
{
- Icon currIcon = (isEnabled()) ? activeIcon : disabledIcon;
+ Icon currIcon = isEnabled() ? icon : disabledIcon;
- //Is this the correct way to check for image equality?
+ // XXX: Is this the correct way to check for image equality?
if (currIcon != null && currIcon instanceof ImageIcon)
return (((ImageIcon) currIcon).getImage() == img);
+
return false;
}
@@ -664,15 +667,14 @@ public class JLabel extends JComponent implements Accessible, SwingConstants
{
if (c != labelFor)
{
- Component oldLabelFor = labelFor;
+ firePropertyChange(LABEL_FOR_CHANGED_PROPERTY, labelFor, c);
labelFor = c;
- firePropertyChange(LABEL_FOR_CHANGED_PROPERTY, oldLabelFor, labelFor);
}
}
-
+
/**
- * This method overrides setFont so that we can call for a repaint
- * after the font is changed.
+ * This method overrides setFont so that we can call for a repaint after the
+ * font is changed.
*
* @param f The font for this label.
*/
diff --git a/libjava/javax/swing/JLayeredPane.java b/libjava/javax/swing/JLayeredPane.java
index 78ff95e..a184e21 100644
--- a/libjava/javax/swing/JLayeredPane.java
+++ b/libjava/javax/swing/JLayeredPane.java
@@ -153,7 +153,7 @@ public class JLayeredPane extends JComponent implements Accessible
Map.Entry pair = (Map.Entry) i.next();
Integer layerNum = (Integer) pair.getKey ();
Integer layerSz = (Integer) pair.getValue ();
- if (layerNum == layer)
+ if (layerNum.intValue() == layer.intValue())
{
ret[0] = ret[1] - layerSz.intValue ();
return ret;
@@ -314,7 +314,7 @@ public class JLayeredPane extends JComponent implements Accessible
int bot = range[1];
if (position == -1)
position = (bot - top) - 1;
- int targ = top + position;
+ int targ = Math.min(top + position, bot-1);
int curr = -1;
Component[] comps = getComponents();
@@ -539,7 +539,8 @@ public class JLayeredPane extends JComponent implements Accessible
int layer,
int position)
{
- componentToLayer.put (c, getObjectForLayer (layer));
+ remove(c);
+ add(c, getObjectForLayer (layer));
setPosition(c, position);
revalidate();
repaint();
diff --git a/libjava/javax/swing/JList.java b/libjava/javax/swing/JList.java
index 937d41c..b763881 100644
--- a/libjava/javax/swing/JList.java
+++ b/libjava/javax/swing/JList.java
@@ -588,6 +588,28 @@ public class JList extends JComponent implements Accessible, Scrollable
return getUI().locationToIndex(this, r.getLocation());
}
+
+ /**
+ * Returns index of the cell to which specified location is closest to
+ * @param location for which to look for in the list
+ *
+ * @return index of the cell to which specified location is closest to.
+ */
+ public int locationToIndex(Point location) {
+ return getUI().locationToIndex(this, location);
+ }
+
+ /**
+ * Returns location of the cell located at the specified index in the list.
+ * @param index of the cell for which location will be determined
+ *
+ * @return location of the cell located at the specified index in the list.
+ */
+ public Point indexToLocation(int index){
+ //FIXME: Need to implement.
+ return null;
+ }
+
/**
* Returns the list index of the lower right or lower left corner of the
* {@link #visibleRect} property, depending on the {@link
diff --git a/libjava/javax/swing/JMenuItem.java b/libjava/javax/swing/JMenuItem.java
index b137271..6bf2abc 100644
--- a/libjava/javax/swing/JMenuItem.java
+++ b/libjava/javax/swing/JMenuItem.java
@@ -313,7 +313,8 @@ public class JMenuItem extends AbstractButton implements Accessible,
MenuSelectionManager manager)
{
// Fire MenuDragMouseEvents if mouse is being dragged.
- boolean dragged = (event.getModifiers() & InputEvent.BUTTON1_MASK) != 0;
+ boolean dragged
+ = (event.getModifiersEx() & InputEvent.BUTTON1_DOWN_MASK) != 0;
if (dragged)
processMenuDragMouseEvent(createMenuDragMouseEvent(event, path, manager));
@@ -335,11 +336,11 @@ public class JMenuItem extends AbstractButton implements Accessible,
setArmed(false);
break;
case MouseEvent.MOUSE_PRESSED:
- if ((event.getModifiers() & InputEvent.BUTTON1_MASK) != 0)
- {
- model.setArmed(true);
- model.setPressed(true);
- }
+ if ((event.getModifiersEx() & InputEvent.BUTTON1_DOWN_MASK) != 0)
+ {
+ model.setArmed(true);
+ model.setPressed(true);
+ }
break;
case MouseEvent.MOUSE_RELEASED:
break;
@@ -589,6 +590,18 @@ public class JMenuItem extends AbstractButton implements Accessible,
}
/**
+ * Returns all added MenuDragMouseListener objects.
+ *
+ * @return an array of listeners
+ *
+ * @since 1.4
+ */
+ public MenuDragMouseListener[] getMenuDragMouseListeners()
+ {
+ return (MenuDragMouseListener[]) listenerList.getListeners(MenuDragMouseListener.class);
+ }
+
+ /**
* Adds an MenuKeyListener to this menu item. This listener will be
* invoked when MenuKeyEvents will be fired by this menu item.
*
@@ -610,6 +623,18 @@ public class JMenuItem extends AbstractButton implements Accessible,
}
/**
+ * Returns all added MenuKeyListener objects.
+ *
+ * @return an array of listeners
+ *
+ * @since 1.4
+ */
+ public MenuKeyListener[] getMenuKeyListeners()
+ {
+ return (MenuKeyListener[]) listenerList.getListeners(MenuKeyListener.class);
+ }
+
+ /**
* A string that describes this JMenuItem. Normally only used
* for debugging.
*
diff --git a/libjava/javax/swing/JPopupMenu.java b/libjava/javax/swing/JPopupMenu.java
index 9c06400..d7d3e43 100644
--- a/libjava/javax/swing/JPopupMenu.java
+++ b/libjava/javax/swing/JPopupMenu.java
@@ -144,6 +144,9 @@ public class JPopupMenu extends JComponent implements Accessible, MenuElement
/* Location of the popup */
private Point popupLocation;
+ /* Field indicating if popup menu is visible or not */
+ private boolean visible = false;
+
/* Bound Property indicating visibility of the popup menu*/
public static final String VISIBLE_CHANGED_PROPERTY = "visible";
@@ -564,7 +567,7 @@ public class JPopupMenu extends JComponent implements Accessible, MenuElement
*/
public boolean isVisible()
{
- return super.isVisible();
+ return visible;
}
/**
@@ -577,7 +580,7 @@ public class JPopupMenu extends JComponent implements Accessible, MenuElement
public void setVisible(boolean visible)
{
boolean old = isVisible();
- super.setVisible(visible);
+ this.visible = visible;
if (old != isVisible())
{
firePropertyChange(VISIBLE_CHANGED_PROPERTY, old, (boolean) isVisible());
@@ -615,7 +618,7 @@ public class JPopupMenu extends JComponent implements Accessible, MenuElement
.getLayeredPane();
Point p = new Point(popupLocation.x, popupLocation.y);
SwingUtilities.convertPointFromScreen(p, layeredPane);
- popup.show(p.x, p.y, size.width, size.height);
+ popup.show(p.x, p.y, size.width, size.height);
}
else
{
diff --git a/libjava/javax/swing/JRadioButton.java b/libjava/javax/swing/JRadioButton.java
index 21e545e..b1f733a 100644
--- a/libjava/javax/swing/JRadioButton.java
+++ b/libjava/javax/swing/JRadioButton.java
@@ -44,33 +44,47 @@ public class JRadioButton extends JToggleButton
{
private static final long serialVersionUID = 7751949583255506856L;
- public JRadioButton()
- {
- this(null, null);
- }
- public JRadioButton(Action a)
- {
- this();
- setAction(a);
- }
-
- public JRadioButton(Icon icon)
- {
- this(null, icon);
- }
+ public JRadioButton()
+ {
+ this(null, null);
+ }
+
+ public JRadioButton(Action a)
+ {
+ this();
+ setAction(a);
+ }
+
+ public JRadioButton(Icon icon)
+ {
+ this(null, icon);
+ }
- public JRadioButton(String text)
- {
- this(text, null);
- }
+ public JRadioButton(Icon icon, boolean selected)
+ {
+ this(null, icon, selected);
+ }
+
+ public JRadioButton(String text)
+ {
+ this(text, null);
+ }
+
+ public JRadioButton(String text, boolean selected)
+ {
+ this(text, null, selected);
+ }
- public JRadioButton(String text, Icon icon)
- {
- super(text, icon);
- borderPainted = false;
- contentAreaFilled = false;
- }
-
+ public JRadioButton(String text, Icon icon)
+ {
+ super(text, icon);
+ borderPainted = false;
+ contentAreaFilled = false;
+ }
+
+ public JRadioButton(String text, Icon icon, boolean selected)
+ {
+ }
public AccessibleContext getAccessibleContext()
{
diff --git a/libjava/javax/swing/JScrollPane.java b/libjava/javax/swing/JScrollPane.java
index 8ccee7a..798c48b 100644
--- a/libjava/javax/swing/JScrollPane.java
+++ b/libjava/javax/swing/JScrollPane.java
@@ -41,7 +41,6 @@ package javax.swing;
import java.awt.Component;
import java.awt.ComponentOrientation;
import java.awt.Dimension;
-import java.awt.LayoutManager;
import java.awt.Insets;
import java.awt.LayoutManager;
import java.awt.Point;
@@ -510,7 +509,8 @@ public class JScrollPane
else
{
// otherwise we got a change update from either the VSB or
- // HSB model, and we need to update the viewport position to
+ // HSB model, and we need to update the viewport positions of
+ // both the main viewport and any row or column headers to
// match.
int xpos = 0;
@@ -527,6 +527,20 @@ public class JScrollPane
if (vp != null
&& vp.getViewPosition() != pt)
vp.setViewPosition(pt);
+
+ pt.x = 0;
+
+ if (rowHeader != null
+ && rowHeader.getViewPosition() != pt)
+ rowHeader.setViewPosition(pt);
+
+ pt.x = xpos;
+ pt.y = 0;
+
+ if (columnHeader != null
+ && columnHeader.getViewPosition() != pt)
+ columnHeader.setViewPosition(pt);
+
}
}
};
diff --git a/libjava/javax/swing/JTabbedPane.java b/libjava/javax/swing/JTabbedPane.java
index efe1abe..0f3fbce 100644
--- a/libjava/javax/swing/JTabbedPane.java
+++ b/libjava/javax/swing/JTabbedPane.java
@@ -44,7 +44,6 @@ import java.awt.Rectangle;
import java.awt.event.MouseEvent;
import java.io.Serializable;
import java.util.Vector;
-
import javax.accessibility.Accessible;
import javax.accessibility.AccessibleContext;
import javax.accessibility.AccessibleRole;
@@ -79,12 +78,11 @@ public class JTabbedPane extends JComponent implements Serializable,
protected class AccessibleJTabbedPane extends JComponent.AccessibleJComponent
implements AccessibleSelection, ChangeListener
{
+ /** DOCUMENT ME! */
private static final long serialVersionUID = 7610530885966830483L;
-
+
/**
* Creates a new AccessibleJTabbedPane object.
- *
- * @param c DOCUMENT ME!
*/
public AccessibleJTabbedPane()
{
@@ -226,12 +224,16 @@ public class JTabbedPane extends JComponent implements Serializable,
*/
protected class ModelListener implements ChangeListener, Serializable
{
+ /** DOCUMENT ME! */
private static final long serialVersionUID = 497359819958114132L;
+ /**
+ * Creates a new ModelListener object.
+ */
protected ModelListener()
{
}
-
+
/**
* This method is called whenever the model is changed.
*
@@ -387,7 +389,8 @@ public class JTabbedPane extends JComponent implements Serializable,
return title;
}
- private static final long serialVersionUID = 1614381073220130939L;
+ /** DOCUMENT ME! */
+ private static final long serialVersionUID = 1614381073220130939L;
/**
* This method sets the title of the tab.
@@ -398,7 +401,7 @@ public class JTabbedPane extends JComponent implements Serializable,
{
title = text;
if (title != null && title.length() <= underlinedChar)
- setDisplayedMnemonicIndex(title.length() - 1);
+ setDisplayedMnemonicIndex(title.length() - 1);
}
/**
@@ -817,16 +820,21 @@ public class JTabbedPane extends JComponent implements Serializable,
* This method checks the index.
*
* @param index The index to check.
+ * @param start DOCUMENT ME!
+ * @param end DOCUMENT ME!
+ *
+ * @throws IndexOutOfBoundsException DOCUMENT ME!
*/
private void checkIndex(int index, int start, int end)
{
if (index < start || index >= end)
- throw new IndexOutOfBoundsException("Index < " + start + " || Index >= " + end);
+ throw new IndexOutOfBoundsException("Index < " + start + " || Index >= "
+ + end);
}
/**
- * This method sets the selected index. This method
- * will hide the old component and show the new component.
+ * 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.
*/
@@ -839,7 +847,7 @@ public class JTabbedPane extends JComponent implements Serializable,
getSelectedComponent().hide();
if (index != -1 && getComponentAt(index) != null)
getComponentAt(index).show();
- model.setSelectedIndex(index);
+ model.setSelectedIndex(index);
}
}
@@ -867,8 +875,8 @@ public class JTabbedPane extends JComponent implements Serializable,
}
/**
- * This method inserts tabs into JTabbedPane. This includes
- * adding the component to the JTabbedPane and hiding it.
+ * 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.
@@ -885,11 +893,11 @@ public class JTabbedPane extends JComponent implements Serializable,
// Hide the component so we don't see it. Do it before we parent it
// so we don't trigger a repaint.
if (component != null)
- {
- component.hide();
- super.add(component);
- }
-
+ {
+ component.hide();
+ super.add(component);
+ }
+
if (getSelectedIndex() == -1)
setSelectedIndex(0);
@@ -934,15 +942,14 @@ public class JTabbedPane extends JComponent implements Serializable,
}
/**
- * 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
+ * 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.
+ * @return The Component that was added.
*/
public Component add(Component component)
{
@@ -954,17 +961,16 @@ public class JTabbedPane extends JComponent implements Serializable,
}
/**
- * 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.
+ * 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)
+ public Component add(String title, Component component)
{
if (component instanceof UIResource)
super.add(component);
@@ -974,10 +980,9 @@ public class JTabbedPane extends JComponent implements Serializable,
}
/**
- * 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.
+ * 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.
@@ -994,12 +999,11 @@ public class JTabbedPane extends JComponent implements Serializable,
}
/**
- * 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.
+ * 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.
@@ -1010,12 +1014,11 @@ public class JTabbedPane extends JComponent implements Serializable,
}
/**
- * 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.
+ * 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.
@@ -1037,27 +1040,25 @@ public class JTabbedPane extends JComponent implements Serializable,
}
/**
- * 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.
+ * 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);
+ super.remove(index);
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.
+ * 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.
*/
@@ -1071,8 +1072,8 @@ public class JTabbedPane extends JComponent implements Serializable,
}
/**
- * This method removes the tab and component from the JTabbedPane.
- * It simply calls removeTabAt(int index).
+ * 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.
*/
@@ -1082,8 +1083,8 @@ public class JTabbedPane extends JComponent implements Serializable,
}
/**
- * This method removes all tabs and associated components
- * from the JTabbedPane.
+ * This method removes all tabs and associated components from the
+ * JTabbedPane.
*/
public void removeAll()
{
@@ -1102,8 +1103,7 @@ public class JTabbedPane extends JComponent implements Serializable,
}
/**
- * This method returns the number of runs used
- * to paint the JTabbedPane.
+ * This method returns the number of runs used to paint the JTabbedPane.
*
* @return The number of runs.
*/
@@ -1204,8 +1204,8 @@ public class JTabbedPane extends JComponent implements Serializable,
}
/**
- * This method returns whether this tab is enabled.
- * Disabled tabs cannot be selected.
+ * This method returns whether this tab is enabled. Disabled tabs cannot be
+ * selected.
*
* @param index The index of the tab.
*
@@ -1244,8 +1244,7 @@ public class JTabbedPane extends JComponent implements Serializable,
}
/**
- * This method returns the bounds of the tab given
- * the index.
+ * This method returns the bounds of the tab given the index.
*
* @param index The index of the tab.
*
@@ -1441,9 +1440,9 @@ public class JTabbedPane extends JComponent implements Serializable,
}
/**
- * 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
+ * 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.
@@ -1470,8 +1469,8 @@ public class JTabbedPane extends JComponent implements Serializable,
}
/**
- * This method returns a string representation of this JTabbedPane. It
- * is mainly used for debugging purposes.
+ * This method returns a string representation of this JTabbedPane. It is
+ * mainly used for debugging purposes.
*
* @return A string representation of this JTabbedPane.
*/
diff --git a/libjava/javax/swing/JTable.java b/libjava/javax/swing/JTable.java
index c628b71..4a81e04 100644
--- a/libjava/javax/swing/JTable.java
+++ b/libjava/javax/swing/JTable.java
@@ -39,12 +39,14 @@ exception statement from your version. */
package javax.swing;
import java.awt.Color;
+import java.awt.Component;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.util.Vector;
import java.util.Hashtable;
import javax.accessibility.Accessible;
+import javax.accessibility.AccessibleContext;
import javax.swing.event.CellEditorListener;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ListSelectionEvent;
@@ -53,11 +55,14 @@ import javax.swing.event.TableColumnModelEvent;
import javax.swing.event.TableColumnModelListener;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
+import javax.swing.plaf.TableUI;
import javax.swing.table.DefaultTableColumnModel;
+import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableCellRenderer;
+import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;
import javax.swing.table.TableModel;
@@ -66,34 +71,259 @@ public class JTable extends JComponent
ListSelectionListener, CellEditorListener, Accessible
{
private static final long serialVersionUID = 3876025080382781659L;
-
- public static final int AUTO_RESIZE_ALL_COLUMNS = 4;
- public static final int AUTO_RESIZE_LAST_COLUMN = 3;
- public static final int AUTO_RESIZE_NEXT_COLUMN = 1;
+
+
+ /**
+ * When resizing columns, do not automatically change any columns. In this
+ * case the table should be enclosed in a {@link JScrollPane} in order to
+ * accomodate cases in which the table size exceeds its visible area.
+ */
public static final int AUTO_RESIZE_OFF = 0;
+
+ /**
+ * When resizing column <code>i</code>, automatically change only the
+ * single column <code>i+1</code> to provide or absorb excess space
+ * requirements.
+ */
+ public static final int AUTO_RESIZE_NEXT_COLUMN = 1;
+
+ /**
+ * When resizing column <code>i</code> in a table of <code>n</code>
+ * columns, automatically change all columns in the range <code>[i+1,
+ * n)</code>, uniformly, to provide or absorb excess space requirements.
+ */
public static final int AUTO_RESIZE_SUBSEQUENT_COLUMNS = 2;
- protected boolean autoCreateColumnsFromModel;
- protected int autoResizeMode;
- protected TableCellEditor cellEditor;
- protected boolean cellSelectionEnabled;
- protected TableColumnModel columnModel;
- protected TableModel dataModel;
+ /**
+ * When resizing column <code>i</code> in a table of <code>n</code>
+ * columns, automatically change all columns in the range <code>[0,
+ * n)</code> (with the exception of column i) uniformly, to provide or
+ * absorb excess space requirements.
+ */
+ public static final int AUTO_RESIZE_ALL_COLUMNS = 4;
+
+ /**
+ * When resizing column <code>i</code> in a table of <code>n</code>
+ * columns, automatically change column <code>n-1</code> (the last column
+ * in the table) to provide or absorb excess space requirements.
+ */
+ public static final int AUTO_RESIZE_LAST_COLUMN = 3;
+
+
+ /**
+ * A table mapping {@link java.lang.Class} objects to
+ * {@link TableCellEditor} objects. This table is consulted by the
+ *
+ */
protected Hashtable defaultEditorsByColumnClass;
protected Hashtable defaultRenderersByColumnClass;
protected int editingColumn;
protected int editingRow;
- protected Color gridColor;
- protected Dimension preferredViewportSize;
+
+ /**
+ * Whether or not the table should automatically compute a matching
+ * {@link TableColumnModel} and assign it to the {@link #columnModel}
+ * property when the {@link #dataModel} property is changed.
+ *
+ * @see #setModel()
+ * @see #createColumnsFromModel()
+ * @see #setColumnModel()
+ * @see #setAutoCreateColumnsFromModel()
+ * @see #getAutoCreateColumnsFromModel()
+ */
+ protected boolean autoCreateColumnsFromModel;
+
+ /**
+ * A numeric code specifying the resizing behavior of the table. Must be
+ * one of {@link #AUTO_RESIZE_ALL_COLUMNS} (the default), {@link
+ * #AUTO_RESIZE_LAST_COLUMN}, {@link #AUTO_RESIZE_NEXT_COLUMN}, {@link
+ * #AUTO_RESIZE_SUBSEQUENT_COLUMNS}, or {@link #AUTO_RESIZE_OFF}.
+ *
+ * @see #doLayout()
+ * @see #setAutoResizeMode()
+ * @see #getAutoResizeMode()
+ */
+ protected int autoResizeMode;
+
+ /**
+ * The height in pixels of any row of the table. All rows in a table are
+ * of uniform height. This differs from column width, which varies on a
+ * per-column basis, and is stored in the individual columns of the
+ * {@link #columnModel}.
+ *
+ * @see #getRowHeight()
+ * @see #setRowHeight()
+ * @see TableColumn#getWidth()
+ * @see TableColumn#setWidth()
+ */
protected int rowHeight;
+
+ /**
+ * The height in pixels of the gap left between any two rows of the table.
+ *
+ * @see #setRowMargin()
+ * @see #getRowHeight()
+ * @see #getInterCellSpacing()
+ * @see #setInterCellSpacing()
+ * @see TableColumnModel#getColumnMargin()
+ * @see TableColumnModel#setColumnMargin()
+ */
protected int rowMargin;
+
+ /**
+ * Whether or not the table should allow row selection. If the table
+ * allows both row <em>and</em> column selection, it is said to allow
+ * "cell selection". Previous versions of the JDK supported cell
+ * selection as an independent concept, but it is now represented solely
+ * in terms of simultaneous row and column selection.
+ *
+ * @see TableColumnModel#columnSelectionAllowed()
+ * @see #setRowSelectionAllowed()
+ * @see #getRowSelectionAllowed()
+ * @see #getCellSelectionEnabled()
+ * @see #setCellSelectionEnabled()
+ */
protected boolean rowSelectionAllowed;
- protected Color selectionBackground;
- protected Color selectionForeground;
+
+ /**
+ * @deprecated Use {@link #rowSelectionAllowed}, {@link
+ * #columnSelectionAllowed}, or the combined methods {@link
+ * getCellSelectionEnabled} and {@link setCellSelectionEnabled}.
+ */
+ protected boolean cellSelectionEnabled;
+
+ /**
+ * The model for data stored in the table. Confusingly, the published API
+ * requires that this field be called <code>dataModel</code>, despite its
+ * property name. The table listens to its model as a {@link
+ * TableModelListener}.
+ *
+ * @see #tableChanged()
+ * @see TableModel#addTableModelListener()
+ */
+ protected TableModel dataModel;
+
+ /**
+ * <p>A model of various aspects of the columns of the table, <em>not
+ * including</em> the data stored in them. The {@link TableColumnModel}
+ * is principally concerned with holding a set of {@link TableColumn}
+ * objects, each of which describes the display parameters of a column
+ * and the numeric index of the column from the data model which the
+ * column is presenting.</p>
+ *
+ * <p>The TableColumnModel also contains a {@link ListSelectionModel} which
+ * indicates which columns are currently selected. This selection model
+ * works in combination with the {@link selectionModel} of the table
+ * itself to specify a <em>table selection</em>: a combination of row and
+ * column selections.</p>
+ *
+ * <p>Most application programmers do not need to work with this property
+ * at all: setting {@link #autoCreateColumnsFromModel} will construct the
+ * columnModel automatically, and the table acts as a facade for most of
+ * the interesting properties of the columnModel anyways.</p>
+ *
+ * @see #setColumnModel()
+ * @see #getColumnModel()
+ */
+ protected TableColumnModel columnModel;
+
+ /**
+ * A model of the rows of this table which are currently selected. This
+ * model is used in combination with the column selection model held as a
+ * member of the {@link columnModel} property, to represent the rows and
+ * columns (or both: cells) of the table which are currently selected.
+ *
+ * @see #rowSelectionAllowed
+ * @see #setSelectionModel()
+ * @see #getSelectionModel()
+ * @see TableColumnModel#getSelectionModel()
+ * @see ListSelectionModel#addListSelectionListener()
+ */
protected ListSelectionModel selectionModel;
+
+ /**
+ * The accessibleContext property.
+ */
+ protected AccessibleContext accessibleContext;
+
+ /**
+ * The current cell editor.
+ */
+ protected TableCellEditor cellEditor;
+
+ /**
+ * Whether or not drag-and-drop is enabled on this table.
+ *
+ * @see #setDragEnabled()
+ * @see #getDragEnabled()
+ */
+ protected boolean dragEnabled;
+
+ /**
+ * The color to paint the grid lines of the table, when either {@link
+ * #showHorizontalLines} or {@link #showVerticalLines} is set.
+ *
+ * @see #setGridColor()
+ * @see #getGridColor()
+ */
+ protected Color gridColor;
+
+ /**
+ * The size this table would prefer its viewport assume, if it is
+ * contained in a {@link JScrollPane}.
+ *
+ * @see #setPreferredScrollableViewportSize()
+ * @see #getPreferredScrollableViewportSize()
+ */
+ protected Dimension preferredScrollableViewportSize;
+
+ /**
+ * The color to paint the background of selected cells. Fires a property
+ * change event with name {@link #SELECTION_BACKGROUND_CHANGED_PROPERTY}
+ * when its value changes.
+ *
+ * @see #setSelectionBackground()
+ * @see #getSelectionBackground()
+ */
+ Color selectionBackground;
+
+ /**
+ * The name carried in property change events when the {@link
+ * #selectionBackground} property changes.
+ */
+ private static final String SELECTION_BACKGROUND_CHANGED_PROPERTY = "selectionBackground";
+
+ /**
+ * The color to paint the foreground of selected cells. Fires a property
+ * change event with name {@link #SELECTION_FOREGROUND_CHANGED_PROPERTY}
+ * when its value changes.
+ *
+ * @see #setSelectionForeground()
+ * @see #getSelectionForeground()
+ */
+ Color selectionForeground;
+
+ /**
+ * The name carried in property change events when the
+ * {@link #selectionForeground} property changes.
+ */
+ private static final String SELECTION_FOREGROUND_CHANGED_PROPERTY = "selectionForeground";
+
+ /**
+ * The showHorizontalLines property.
+ */
protected boolean showHorizontalLines;
+
+ /**
+ * The showVerticalLines property.
+ */
protected boolean showVerticalLines;
+
+ /**
+ * The tableHeader property.
+ */
protected JTableHeader tableHeader;
+
/**
* Creates a new <code>JTable</code> instance.
@@ -156,8 +386,33 @@ public class JTable extends JComponent
public JTable (TableModel dm, TableColumnModel cm, ListSelectionModel sm)
{
this.dataModel = dm == null ? createDefaultDataModel() : dm;
- this.columnModel = cm == null ? createDefaultColumnModel() : cm;
- this.selectionModel = sm == null ? createDefaultListSelectionModel() : sm;
+ setSelectionModel(sm == null ? createDefaultListSelectionModel() : sm);
+
+ this.columnModel = cm;
+ this.autoCreateColumnsFromModel = false;
+ if (cm == null)
+ {
+ this.autoCreateColumnsFromModel = true;
+ createColumnsFromModel();
+ }
+ this.columnModel.addColumnModelListener(this);
+
+ this.defaultRenderersByColumnClass = new Hashtable();
+ this.defaultEditorsByColumnClass = new Hashtable();
+
+ this.autoResizeMode = AUTO_RESIZE_ALL_COLUMNS;
+ this.rowHeight = 16;
+ this.rowMargin = 1;
+ this.rowSelectionAllowed = true;
+ // this.accessibleContext = new AccessibleJTable();
+ this.cellEditor = null;
+ this.dragEnabled = false;
+ this.preferredScrollableViewportSize = new Dimension(450,400);
+ this.showHorizontalLines = true;
+ this.showVerticalLines = true;
+ setInterCellSpacing(new Dimension(1,1));
+ setTableHeader(new JTableHeader(columnModel));
+ updateUI();
}
/**
@@ -178,216 +433,1129 @@ public class JTable extends JComponent
{
return new JScrollPane(table);
}
+
+ protected TableColumnModel createDefaultColumnModel()
+ {
+ return new DefaultTableColumnModel();
+ }
- public void clearSelection()
+ protected TableModel createDefaultDataModel()
{
- selectionModel.clearSelection();
+ return new DefaultTableModel();
}
+ protected ListSelectionModel createDefaultListSelectionModel()
+ {
+ return new DefaultListSelectionModel();
+ }
+
+ private void createColumnsFromModel()
+ {
+ if (dataModel == null)
+ return;
+
+ TableColumnModel cm = createDefaultColumnModel();
+
+ for (int i = 0; i < dataModel.getColumnCount(); ++i)
+ {
+ cm.addColumn(new TableColumn(i));
+ }
+ this.setColumnModel(cm);
+ }
+
+ // listener support
+
public void columnAdded (TableColumnModelEvent event)
{
- throw new Error ("Not implemented");
+ revalidate();
+ repaint();
}
public void columnMarginChanged (ChangeEvent event)
{
- throw new Error ("Not implemented");
+ revalidate();
+ repaint();
}
-
+
public void columnMoved (TableColumnModelEvent event)
{
- throw new Error ("Not implemented");
+ revalidate();
+ repaint();
}
-
+
public void columnRemoved (TableColumnModelEvent event)
{
- throw new Error ("Not implemented");
+ revalidate();
+ repaint();
}
public void columnSelectionChanged (ListSelectionEvent event)
{
- throw new Error ("Not implemented");
+ repaint();
}
-
- protected TableColumnModel createDefaultColumnModel()
+
+ public void editingCanceled (ChangeEvent event)
{
- return new DefaultTableColumnModel();
+ repaint();
}
- protected TableModel createDefaultDataModel()
+ public void editingStopped (ChangeEvent event)
{
- return new DefaultTableModel();
+ repaint();
}
- protected ListSelectionModel createDefaultListSelectionModel()
+ public void tableChanged (TableModelEvent event)
{
- return new DefaultListSelectionModel();
+ repaint();
}
- public void editingCanceled (ChangeEvent event)
+ public void valueChanged (ListSelectionEvent event)
{
- throw new Error ("Not implemented");
+ repaint();
}
- public void editingStopped (ChangeEvent event)
+
+ /**
+ * Calculate the visible rectangle for a particular row and column. The
+ * row and column are specified in visual terms; the column may not match
+ * the {@link #dataModel} column.
+ *
+ * @param row the visible row to get the cell rectangle of
+ *
+ * @param column the visible column to get the cell rectangle of, which may
+ * differ from the {@link #dataModel} column
+ *
+ * @param includeSpacing whether or not to include the cell margins in the
+ * resulting cell. If <code>false</code>, the result will only contain the
+ * inner area of the target cell, not including its margins.
+ *
+ * @return a rectangle enclosing the specified cell
+ */
+ public Rectangle getCellRect(int row,
+ int column,
+ boolean includeSpacing)
{
- throw new Error ("Not implemented");
+ int height = getHeight();
+ int width = columnModel.getColumn(column).getWidth();
+ int x_gap = columnModel.getColumnMargin();
+ int y_gap = rowMargin;
+
+ column = Math.max(0, Math.min(column, getColumnCount() - 1));
+ row = Math.max(0, Math.min(row, getRowCount() - 1));
+
+ int x = 0;
+ int y = (height + y_gap) * row;
+
+ for (int i = 0; i < column; ++i)
+ {
+ x += columnModel.getColumn(i).getWidth();
+ x += x_gap;
+ }
+
+ if (includeSpacing)
+ return new Rectangle(x, y, width, height);
+ else
+ return new Rectangle(x, y, width - x_gap, height - y_gap);
}
- public TableColumnModel getColumnModel ()
+ public void clearSelection()
{
- return columnModel;
+ selectionModel.clearSelection();
+ }
+
+ /**
+ * Get the value of the {@link #selectedRow} property by delegation to
+ * the {@link ListSelectionModel#getMinSelectionIndex} method of the
+ * {@link #selectionModel} field.
+ *
+ * @return The current value of the selectedRow property
+ */
+ public int getSelectedRow ()
+ {
+ return selectionModel.getMinSelectionIndex();
}
- public TableModel getModel()
+ /**
+ * Get the value of the {@link #selectionModel} property.
+ *
+ * @return The current value of the property
+ */
+ public ListSelectionModel getSelectionModel()
{
- return dataModel;
+ if (! rowSelectionAllowed)
+ return null;
+
+ return selectionModel;
}
- public Dimension getPreferredScrollableViewportSize ()
+ public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction)
{
- throw new Error ("Not implemented");
+ if (orientation == SwingConstants.VERTICAL)
+ return visibleRect.height * direction;
+ else
+ return visibleRect.width * direction;
}
- public int getScrollableBlockIncrement (Rectangle visibleRect, int orientation, int direction)
+ /**
+ * Get the value of the {@link #scrollableTracksViewportHeight} property.
+ *
+ * @return The constant value <code>false</code>
+ */
+
+ public boolean getScrollableTracksViewportHeight()
{
- throw new Error ("Not implemented");
+ return false;
}
+
+ /**
+ * Get the value of the {@link #scrollableTracksViewportWidth} property.
+ *
+ * @return <code>true</code> unless the {@link autoResizeMode} prperty is
+ * <code>AUTO_RESIZE_OFF</code>
+ */
- public boolean getScrollableTracksViewportHeight ()
+ public boolean getScrollableTracksViewportWidth()
{
- throw new Error ("Not implemented");
+ if (autoResizeMode == AUTO_RESIZE_OFF)
+ return false;
+ else
+ return true;
}
-
- public boolean getScrollableTracksViewportWidth ()
+
+ public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction)
{
- throw new Error ("Not implemented");
+ // FIXME: I don't exactly know what sun does here. in both cases they
+ // pick values which do *not* simply expose the next cell in a given
+ // scroll direction.
+
+ if (orientation == SwingConstants.VERTICAL)
+ return rowHeight;
+ else
+ {
+ int sum = 0;
+ for (int i = 0; i < getColumnCount(); ++i)
+ sum += columnModel.getColumn(0).getWidth();
+ return getColumnCount() == 0 ? 10 : sum / getColumnCount();
+ }
}
- public int getScrollableUnitIncrement (Rectangle visibleRect, int orientation, int direction)
+
+ public TableCellEditor getCellEditor(int row, int column)
{
- throw new Error ("Not implemented");
+ TableCellEditor editor = columnModel.getColumn(column).getCellEditor();
+
+ if (editor == null)
+ editor = getDefaultEditor(dataModel.getColumnClass(column));
+
+ return editor;
}
- public int getSelectedRow ()
+ public TableCellEditor getDefaultEditor(Class columnClass)
{
- return selectionModel.getMinSelectionIndex();
+ if (defaultEditorsByColumnClass.containsKey(columnClass))
+ return (TableCellEditor) defaultEditorsByColumnClass.get(columnClass);
+ else
+ {
+ TableCellEditor r = new DefaultCellEditor(new JTextField());
+ defaultEditorsByColumnClass.put(columnClass, r);
+ return r;
+ }
}
-
- public ListSelectionModel getSelectionModel ()
+
+
+
+ public TableCellRenderer getCellRenderer(int row, int column)
{
- if (! rowSelectionAllowed)
- return null;
+ TableCellRenderer renderer =
+ columnModel.getColumn(column).getCellRenderer();
+
+ if (renderer == null)
+ renderer = getDefaultRenderer(dataModel.getColumnClass(column));
+
+ return renderer;
+ }
- return selectionModel;
+ public TableCellRenderer getDefaultRenderer(Class columnClass)
+ {
+ if (defaultRenderersByColumnClass.containsKey(columnClass))
+ return (TableCellRenderer) defaultRenderersByColumnClass.get(columnClass);
+ else
+ {
+ TableCellRenderer r = new DefaultTableCellRenderer();
+ defaultRenderersByColumnClass.put(columnClass, r);
+ return r;
+ }
}
- public void tableChanged (TableModelEvent event)
+ public int convertColumnIndexToModel(int vc)
{
- throw new Error ("Not implemented");
+ if (vc < 0)
+ return vc;
+ else if (vc > getColumnCount())
+ return -1;
+ else
+ return columnModel.getColumn(vc).getModelIndex();
}
- public void setModel (TableModel model)
+ public int convertColumnIndexToView(int mc)
{
- if (model == null)
- throw new IllegalArgumentException();
+ if (mc < 0)
+ return mc;
+ int ncols = getColumnCount();
+ for (int vc = 0; vc < ncols; ++vc)
+ {
+ if (columnModel.getColumn(vc).getModelIndex() == mc)
+ return vc;
+ }
+ return -1;
+ }
- // FIXME: Should we deregister from old model ?
+ public Component prepareRenderer(TableCellRenderer renderer,
+ int row,
+ int column)
+ {
+ boolean rsa = getRowSelectionAllowed();
+ boolean csa = getColumnSelectionAllowed();
+ boolean rs = rsa ? getSelectionModel().isSelectedIndex(row) : false;
+ boolean cs = csa ? columnModel.getSelectionModel().isSelectedIndex(column) : false;
+ boolean isSelected = ((rsa && csa && rs && cs)
+ || (rsa && !csa && rs)
+ || (!rsa && csa && cs));
- dataModel = model;
- dataModel.addTableModelListener(this);
+ return renderer.getTableCellRendererComponent(this,
+ dataModel.getValueAt(row,
+ convertColumnIndexToView(column)),
+ isSelected,
+ false, // hasFocus
+ row, column);
}
- public void setSelectionMode (int selectionMode)
+
+ /**
+ * Get the value of the {@link #autoCreateColumnsFromModel} property.
+ *
+ * @return The current value of the property
+ */
+ public boolean getAutoCreateColumnsFromModel()
{
- throw new Error ("Not implemented");
+ return autoCreateColumnsFromModel;
}
- public void setSelectionModel (ListSelectionModel model)
+ /**
+ * Get the value of the {@link #autoResizeMode} property.
+ *
+ * @return The current value of the property
+ */
+ public int getAutoResizeMode()
{
- if (model == null)
- throw new IllegalArgumentException();
+ return autoResizeMode;
+ }
- // FIXME: Should we deregister from old model ?
-
- selectionModel = model;
- selectionModel.addListSelectionListener(this);
+ /**
+ * Get the value of the {@link #rowHeight} property.
+ *
+ * @return The current value of the property
+ */
+ public int getRowHeight()
+ {
+ return rowHeight;
}
- public void setShowGrid (boolean showGrid)
+ /**
+ * Get the value of the {@link #rowMargin} property.
+ *
+ * @return The current value of the property
+ */
+ public int getRowMargin()
{
- throw new Error ("Not implemented");
+ return rowMargin;
}
- public void valueChanged (ListSelectionEvent event)
+ /**
+ * Get the value of the {@link #rowSelectionAllowed} property.
+ *
+ * @return The current value of the property
+ */
+ public boolean getRowSelectionAllowed()
+ {
+ return rowSelectionAllowed;
+ }
+
+ /**
+ * Get the value of the {@link #cellSelectionEnabled} property.
+ *
+ * @return The current value of the property
+ */
+ public boolean getCellSelectionEnabled()
+ {
+ return getColumnSelectionAllowed() && getRowSelectionAllowed();
+ }
+
+ /**
+ * Get the value of the {@link #dataModel} property.
+ *
+ * @return The current value of the property
+ */
+ public TableModel getModel()
{
- throw new Error ("Not implemented");
+ return dataModel;
}
+ /**
+ * Get the value of the {@link #columnCount} property by
+ * delegation to the @{link #dataModel} field.
+ *
+ * @return The current value of the columnCount property
+ */
+ public int getColumnCount()
+ {
+ return dataModel.getColumnCount();
+ }
+
+ /**
+ * Get the value of the {@link #rowCount} property by
+ * delegation to the @{link #dataModel} field.
+ *
+ * @return The current value of the rowCount property
+ */
+ public int getRowCount()
+ {
+ return dataModel.getRowCount();
+ }
+
+ /**
+ * Get the value of the {@link #columnModel} property.
+ *
+ * @return The current value of the property
+ */
+ public TableColumnModel getColumnModel()
+ {
+ return columnModel;
+ }
+
+ /**
+ * Get the value of the {@link #selectedColumn} property by
+ * delegation to the @{link #columnModel} field.
+ *
+ * @return The current value of the selectedColumn property
+ */
+ public int getSelectedColumn()
+ {
+ return columnModel.getSelectionModel().getMinSelectionIndex();
+ }
+
+ private static int countSelections(ListSelectionModel lsm)
+ {
+ int lo = lsm.getMinSelectionIndex();
+ int hi = lsm.getMaxSelectionIndex();
+ int sum = 0;
+ if (lo != -1 && hi != -1)
+ {
+ switch (lsm.getSelectionMode())
+ {
+ case ListSelectionModel.SINGLE_SELECTION:
+ sum = 1;
+ break;
+
+ case ListSelectionModel.SINGLE_INTERVAL_SELECTION:
+ sum = hi - lo;
+ break;
+
+ case ListSelectionModel.MULTIPLE_INTERVAL_SELECTION:
+ for (int i = lo; i < hi; ++i)
+ if (lsm.isSelectedIndex(i))
+ ++sum;
+ break;
+ }
+ }
+ return sum;
+ }
+
+ private static int[] getSelections(ListSelectionModel lsm)
+ {
+ int sz = countSelections(lsm);
+ int [] ret = new int[sz];
+
+ int lo = lsm.getMinSelectionIndex();
+ int hi = lsm.getMaxSelectionIndex();
+ int j = 0;
+ java.util.ArrayList ls = new java.util.ArrayList();
+ if (lo != -1 && hi != -1)
+ {
+ switch (lsm.getSelectionMode())
+ {
+ case ListSelectionModel.SINGLE_SELECTION:
+ ret[0] = lo;
+ break;
+
+ case ListSelectionModel.SINGLE_INTERVAL_SELECTION:
+ for (int i = lo; i < hi; ++i)
+ ret[j++] = i;
+ break;
+
+ case ListSelectionModel.MULTIPLE_INTERVAL_SELECTION:
+ for (int i = lo; i < hi; ++i)
+ if (lsm.isSelectedIndex(i))
+ ret[j++] = i;
+ break;
+ }
+ }
+ return ret;
+ }
+
+ /**
+ * Get the value of the {@link #selectedColumnCount} property by
+ * delegation to the @{link #columnModel} field.
+ *
+ * @return The current value of the selectedColumnCount property
+ */
+ public int getSelectedColumnCount()
+ {
+ return countSelections(columnModel.getSelectionModel());
+ }
+
+ /**
+ * Get the value of the {@link #selectedColumns} property by
+ * delegation to the @{link #columnModel} field.
+ *
+ * @return The current value of the selectedColumns property
+ */
+ public int[] getSelectedColumns()
+ {
+ return getSelections(columnModel.getSelectionModel());
+ }
+
+ /**
+ * Get the value of the {@link #columnSelectionAllowed} property.
+ *
+ * @return The current value of the columnSelectionAllowed property
+ */
+ public boolean getColumnSelectionAllowed()
+ {
+ return getColumnModel().getColumnSelectionAllowed();
+ }
+
+ /**
+ * Get the value of the {@link #selectedRowCount} property by
+ * delegation to the @{link #selectionModel} field.
+ *
+ * @return The current value of the selectedRowCount property
+ */
+ public int getSelectedRowCount()
+ {
+ return countSelections(selectionModel);
+ }
+
+ /**
+ * Get the value of the {@link #selectedRows} property by
+ * delegation to the @{link #selectionModel} field.
+ *
+ * @return The current value of the selectedRows property
+ */
+ public int[] getSelectedRows()
+ {
+ return getSelections(selectionModel);
+ }
+
+ /**
+ * Get the value of the {@link #accessibleContext} property.
+ *
+ * @return The current value of the property
+ */
+ public AccessibleContext getAccessibleContext()
+ {
+ return accessibleContext;
+ }
+
+ /**
+ * Get the value of the {@link #cellEditor} property.
+ *
+ * @return The current value of the property
+ */
+ public TableCellEditor getCellEditor()
+ {
+ return cellEditor;
+ }
+
+ /**
+ * Get the value of the {@link #dragEnabled} property.
+ *
+ * @return The current value of the property
+ */
+ public boolean getDragEnabled()
+ {
+ return dragEnabled;
+ }
+
+ /**
+ * Get the value of the {@link #gridColor} property.
+ *
+ * @return The current value of the property
+ */
+ public Color getGridColor()
+ {
+ return gridColor;
+ }
+
+ /**
+ * Get the value of the {@link #interCellSpacing} property.
+ *
+ * @return The current value of the property
+ */
+ public Dimension getInterCellSpacing()
+ {
+ return new Dimension(columnModel.getColumnMargin(), rowMargin);
+ }
+
+ /**
+ * Get the value of the {@link #preferredScrollableViewportSize} property.
+ *
+ * @return The current value of the property
+ */
+ public Dimension getPreferredScrollableViewportSize()
+ {
+ return preferredScrollableViewportSize;
+ }
+
+ /**
+ * Get the value of the {@link #selectionBackground} property.
+ *
+ * @return The current value of the property
+ */
+ public Color getSelectionBackground()
+ {
+ return selectionBackground;
+ }
+
+ /**
+ * Get the value of the {@link #selectionForeground} property.
+ *
+ * @return The current value of the property
+ */
+ public Color getSelectionForeground()
+ {
+ return selectionForeground;
+ }
+
+ /**
+ * Get the value of the {@link #showHorizontalLines} property.
+ *
+ * @return The current value of the property
+ */
+ public boolean getShowHorizontalLines()
+ {
+ return showHorizontalLines;
+ }
+
+ /**
+ * Get the value of the {@link #showVerticalLines} property.
+ *
+ * @return The current value of the property
+ */
+ public boolean getShowVerticalLines()
+ {
+ return showVerticalLines;
+ }
+
+ /**
+ * Get the value of the {@link #tableHeader} property.
+ *
+ * @return The current value of the property
+ */
public JTableHeader getTableHeader()
{
return tableHeader;
}
- public void setTableHeader(JTableHeader newHeader)
+ /**
+ * Set the value of the {@link #autoCreateColumnsFromModel} property.
+ *
+ * @param a The new value of the autoCreateColumnsFromModel property
+ */
+ public void setAutoCreateColumnsFromModel(boolean a)
{
- tableHeader = newHeader;
+ autoCreateColumnsFromModel = a;
}
- public boolean getColumnSelectionAllowed()
+ /**
+ * Set the value of the {@link #autoResizeMode} property.
+ *
+ * @param a The new value of the autoResizeMode property
+ */
+ public void setAutoResizeMode(int a)
{
- return columnModel.getColumnSelectionAllowed();
+ autoResizeMode = a;
+ revalidate();
+ repaint();
}
-
- public void setColumnSelectionAllowed(boolean flag)
+
+ /**
+ * Set the value of the {@link #rowHeight} property.
+ *
+ * @param r The new value of the rowHeight property
+ */
+ public void setRowHeight(int r)
{
- columnModel.setColumnSelectionAllowed(flag);
+ rowHeight = r;
+ revalidate();
+ repaint();
}
- public boolean getRowSelectionAllowed()
+ /**
+ * Set the value of the {@link #rowMargin} property.
+ *
+ * @param r The new value of the rowMargin property
+ */
+ public void setRowMargin(int r)
{
- return rowSelectionAllowed;
+ rowMargin = r;
+ revalidate();
+ repaint();
}
-
- public void setRowSelectionAllowed(boolean flag)
+
+ /**
+ * Set the value of the {@link #rowSelectionAllowed} property.
+ *
+ * @param r The new value of the rowSelectionAllowed property
+ */
+ public void setRowSelectionAllowed(boolean r)
{
- rowSelectionAllowed = flag;
+ rowSelectionAllowed = r;
+ repaint();
}
- public int getAutoResizeMode()
+ /**
+ * Set the value of the {@link #cellSelectionEnabled} property.
+ *
+ * @param c The new value of the cellSelectionEnabled property
+ */
+ public void setCellSelectionEnabled(boolean c)
{
- return autoResizeMode;
+ setColumnSelectionAllowed(c);
+ setRowSelectionAllowed(c);
+ // for backward-compatibility sake:
+ cellSelectionEnabled = true;
+ }
+
+ /**
+ * <p>Set the value of the {@link #dataModel} property.</p>
+ *
+ * <p>Unregister <code>this</code> as a {@link TableModelListener} from
+ * previous {@link #dataModel} and register it with new parameter
+ * <code>m</code>.</p>
+ *
+ * @param m The new value of the model property
+ */
+ public void setModel(TableModel m)
+ {
+ if (m == null)
+ throw new IllegalArgumentException();
+ TableModel tmp = dataModel;
+ if (autoCreateColumnsFromModel)
+ createColumnsFromModel();
+ if (tmp != null)
+ tmp.removeTableModelListener(this);
+ if (m != null)
+ m.addTableModelListener(this);
+ dataModel = m;
+ revalidate();
+ repaint();
}
- public void setAutoResizeMode(int mode)
+ /**
+ * <p>Set the value of the {@link #columnModel} property.</p>
+ *
+ * <p>Unregister <code>this</code> as a {@link TableColumnModelListener}
+ * from previous {@link #columnModel} and register it with new parameter
+ * <code>c</code>.</p>
+ *
+ * @param c The new value of the columnModel property
+ */
+ public void setColumnModel(TableColumnModel c)
{
- autoResizeMode = mode;
+ if (c == null)
+ throw new IllegalArgumentException();
+ TableColumnModel tmp = columnModel;
+ if (tmp != null)
+ tmp.removeColumnModelListener(this);
+ if (c != null)
+ c.addColumnModelListener(this);
+ columnModel = c;
+ if (dataModel != null && columnModel != null)
+ {
+ int ncols = getColumnCount();
+ for (int i = 0; i < ncols; ++i)
+ columnModel.getColumn(i).setHeaderValue(dataModel.getColumnName(i));
+ }
+ revalidate();
+ repaint();
}
- public int getColumnCount()
+ /**
+ * Set the value of the {@link #columnSelectionAllowed} property.
+ *
+ * @param c The new value of the property
+ */
+ public void setColumnSelectionAllowed(boolean c)
{
- return dataModel.getColumnCount();
+ getColumnModel().setColumnSelectionAllowed(c);
+ repaint();
}
- public int getRowCount()
+ /**
+ * <p>Set the value of the {@link #selectionModel} property.</p>
+ *
+ * <p>Unregister <code>this</code> as a {@link ListSelectionListener}
+ * from previous {@link #selectionModel} and register it with new
+ * parameter <code>s</code>.</p>
+ *
+ * @param s The new value of the selectionModel property
+ */
+ public void setSelectionModel(ListSelectionModel s)
{
- return dataModel.getRowCount();
+ if (s == null)
+ throw new IllegalArgumentException();
+ ListSelectionModel tmp = selectionModel;
+ if (tmp != null)
+ tmp.removeListSelectionListener(this);
+ if (s != null)
+ s.addListSelectionListener(this);
+ selectionModel = s;
}
- public TableCellRenderer getCellRenderer(int row, int column)
+ /**
+ * Set the value of the {@link #selectionMode} property by
+ * delegation to the {@link #selectionModel} field.
+ *
+ * @param s The new value of the property
+ */
+ public void setSelectionMode(int s)
{
- TableCellRenderer renderer =
- columnModel.getColumn(column).getCellRenderer();
-
- if (renderer == null)
- renderer = getDefaultRenderer(dataModel.getColumnClass(column));
-
- return renderer;
+ selectionModel.setSelectionMode(s);
+ repaint();
}
- public TableCellRenderer getDefaultRenderer(Class columnClass)
+ /**
+ * <p>Set the value of the {@link #cellEditor} property.</p>
+ *
+ * <p>Unregister <code>this</code> as a {@link CellEditorListener} from
+ * previous {@link #cellEditor} and register it with new parameter
+ * <code>c</code>.</p>
+ *
+ * @param c The new value of the cellEditor property
+ */
+ public void setCellEditor(TableCellEditor c)
+ {
+ TableCellEditor tmp = cellEditor;
+ if (tmp != null)
+ tmp.removeCellEditorListener(this);
+ if (c != null)
+ c.addCellEditorListener(this);
+ cellEditor = c;
+ }
+
+ /**
+ * Set the value of the {@link #dragEnabled} property.
+ *
+ * @param d The new value of the dragEnabled property
+ */
+ public void setDragEnabled(boolean d)
+ {
+ dragEnabled = d;
+ }
+
+ /**
+ * Set the value of the {@link #gridColor} property.
+ *
+ * @param g The new value of the gridColor property
+ */
+ public void setGridColor(Color g)
+ {
+ gridColor = g;
+ repaint();
+ }
+
+ /**
+ * Set the value of the {@link #interCellSpacing} property.
+ *
+ * @param i The new value of the interCellSpacing property
+ */
+ public void setInterCellSpacing(Dimension i)
+ {
+ rowMargin = i.height;
+ columnModel.setColumnMargin(i.width);
+ repaint();
+ }
+
+ /**
+ * Set the value of the {@link #preferredScrollableViewportSize} property.
+ *
+ * @param p The new value of the preferredScrollableViewportSize property
+ */
+ public void setPreferredScrollableViewportSize(Dimension p)
+ {
+ preferredScrollableViewportSize = p;
+ revalidate();
+ repaint();
+ }
+
+ /**
+ * <p>Set the value of the {@link #selectionBackground} property.</p>
+ *
+ * <p>Fire a PropertyChangeEvent with name {@link
+ * #SELECTION_BACKGROUND_CHANGED_PROPERTY} to registered listeners, if
+ * selectionBackground changed.</p>
+ *
+ * @param s The new value of the selectionBackground property
+ */
+ public void setSelectionBackground(Color s)
+ {
+ Color tmp = selectionBackground;
+ selectionBackground = s;
+ if (((tmp == null && s != null)
+ || (s == null && tmp != null)
+ || (tmp != null && s != null && !tmp.equals(s))))
+ firePropertyChange(SELECTION_BACKGROUND_CHANGED_PROPERTY, tmp, s);
+ repaint();
+ }
+
+ /**
+ * <p>Set the value of the {@link #selectionForeground} property.</p>
+ *
+ * <p>Fire a PropertyChangeEvent with name {@link
+ * SELECTION_FOREGROUND_CHANGED_PROPERTY} to registered listeners, if
+ * selectionForeground changed.</p>
+ *
+ * @param s The new value of the selectionForeground property
+ */
+ public void setSelectionForeground(Color s)
+ {
+ Color tmp = selectionForeground;
+ selectionForeground = s;
+ if (((tmp == null && s != null)
+ || (s == null && tmp != null)
+ || (tmp != null && s != null && !tmp.equals(s))))
+ firePropertyChange(SELECTION_FOREGROUND_CHANGED_PROPERTY, tmp, s);
+ repaint();
+ }
+
+ /**
+ * Set the value of the {@link #showGrid} property.
+ *
+ * @param s The new value of the showGrid property
+ */
+ public void setShowGrid(boolean s)
+ {
+ setShowVerticalLines(s);
+ setShowHorizontalLines(s);
+ }
+
+ /**
+ * Set the value of the {@link #showHorizontalLines} property.
+ *
+ * @param s The new value of the showHorizontalLines property
+ */
+ public void setShowHorizontalLines(boolean s)
+ {
+ showHorizontalLines = s;
+ repaint();
+ }
+
+ /**
+ * Set the value of the {@link #showVerticalLines} property.
+ *
+ * @param s The new value of the showVerticalLines property
+ */
+ public void setShowVerticalLines(boolean s)
{
- // FIXME:
- return null;
+ showVerticalLines = s;
+ repaint();
}
+
+ /**
+ * Set the value of the {@link #tableHeader} property.
+ *
+ * @param t The new value of the tableHeader property
+ */
+ public void setTableHeader(JTableHeader t)
+ {
+ if (tableHeader != null)
+ tableHeader.setTable(null);
+ tableHeader = t;
+ if (tableHeader != null)
+ tableHeader.setTable(this);
+ revalidate();
+ repaint();
+ }
+
+ protected void configureEnclosingScrollPane()
+ {
+ JScrollPane jsp = (JScrollPane) SwingUtilities.getAncestorOfClass(JScrollPane.class, this);
+ if (jsp != null && tableHeader != null)
+ {
+ jsp.setColumnHeaderView(tableHeader);
+ }
+ }
+
+ protected void unconfigureEnclosingScrollPane()
+ {
+ JScrollPane jsp = (JScrollPane) SwingUtilities.getAncestorOfClass(JScrollPane.class, this);
+ if (jsp != null)
+ {
+ jsp.setColumnHeaderView(null);
+ }
+ }
+
+
+ public void addNotify()
+ {
+ super.addNotify();
+ configureEnclosingScrollPane();
+ }
+
+ public void removeNotify()
+ {
+ super.addNotify();
+ unconfigureEnclosingScrollPane();
+ }
+
+
+ /**
+ * Sun javadocs describe an unusual implementation of
+ * <code>doLayout</code> which involves some private interfaces. We try
+ * to implement the same algorithm as is documented, but using the
+ * columnModel directly. We still use a private helper method, but it has
+ * a simpler signature.
+ */
+
+ private void distributeSpill(TableColumn[] cols, int spill)
+ {
+ int MIN = 0;
+ int MAX = 0;
+ int PREF = 0;
+
+ int[] min = new int[cols.length];
+ int[] max = new int[cols.length];
+ int[] pref = new int[cols.length];
+
+ for (int i = 0; i < cols.length; ++i)
+ {
+ pref[i] = cols[i].getPreferredWidth();
+ min[i] = cols[i].getMinWidth();
+ max[i] = cols[i].getMaxWidth();
+ PREF += pref[i];
+ MIN += min[i];
+ MAX += max[i];
+ }
+
+ for (int i = 0; i < cols.length; ++i)
+ {
+ int adj = 0;
+ if (spill > 0)
+ adj = (spill * (pref[i] - min[i])) / (PREF - MIN);
+ else
+ adj = (spill * (max[i] - pref[i])) / (MAX - PREF);
+ cols[i].setWidth(pref[i] + adj);
+ }
+ }
+
+ public void doLayout()
+ {
+ TableColumn resizingColumn = null;
+
+ int ncols = getColumnCount();
+ if (ncols < 1)
+ return;
+
+ int[] pref = new int[ncols];
+ int prefSum = 0;
+ int rCol = -1;
+
+ if (tableHeader != null)
+ resizingColumn = tableHeader.getResizingColumn();
+
+ for (int i = 0; i < ncols; ++i)
+ {
+ TableColumn col = columnModel.getColumn(i);
+ int p = col.getWidth();
+ pref[i] = p;
+ prefSum += p;
+ if (resizingColumn == col)
+ rCol = i;
+ }
+
+ int spill = prefSum - getWidth();
+
+ if (resizingColumn != null)
+ {
+ TableColumn col;
+ TableColumn [] cols;
+
+ switch (getAutoResizeMode())
+ {
+ case AUTO_RESIZE_LAST_COLUMN:
+ col = columnModel.getColumn(ncols-1);
+ col.setWidth(col.getPreferredWidth() + spill);
+ break;
+
+ case AUTO_RESIZE_NEXT_COLUMN:
+ col = columnModel.getColumn(ncols-1);
+ col.setWidth(col.getPreferredWidth() + spill);
+ break;
+
+ case AUTO_RESIZE_ALL_COLUMNS:
+ cols = new TableColumn[ncols];
+ for (int i = 0; i < ncols; ++i)
+ cols[i] = columnModel.getColumn(i);
+ distributeSpill(cols, spill);
+ break;
+
+ case AUTO_RESIZE_SUBSEQUENT_COLUMNS:
+ cols = new TableColumn[ncols];
+ for (int i = rCol; i < ncols; ++i)
+ cols[i] = columnModel.getColumn(i);
+ distributeSpill(cols, spill);
+ break;
+
+ case AUTO_RESIZE_OFF:
+ default:
+ }
+ }
+ else
+ {
+ TableColumn [] cols = new TableColumn[ncols];
+ for (int i = 0; i < ncols; ++i)
+ cols[i] = columnModel.getColumn(i);
+ distributeSpill(cols, spill);
+ }
+ }
+
+ public void sizeColumnsToFit(boolean lastColumnOnly)
+ {
+ doLayout();
+ }
+
+ public void sizeColumnsToFit(int resizingColumn)
+ {
+ doLayout();
+ }
+
+
+ public String getUIClassID()
+ {
+ return "TableUI";
+ }
+
+ public TableUI getUI()
+ {
+ return (TableUI) ui;
+ }
+
+ public void updateUI()
+ {
+ setUI((TableUI) UIManager.getUI(this));
+ revalidate();
+ repaint();
+ }
+
}
diff --git a/libjava/javax/swing/JTextField.java b/libjava/javax/swing/JTextField.java
index 8872af6..4466f5a 100644
--- a/libjava/javax/swing/JTextField.java
+++ b/libjava/javax/swing/JTextField.java
@@ -137,9 +137,15 @@ public class JTextField extends JTextComponent
*/
public JTextField(Document doc, String text, int columns)
{
+ if (columns < 0)
+ throw new IllegalArgumentException();
+
+ this.columns = columns;
+
setDocument(doc == null ? createDefaultModel() : doc);
- setText(text);
- setColumns(columns);
+
+ if (text != null)
+ setText(text);
}
/**
diff --git a/libjava/javax/swing/JToolTip.java b/libjava/javax/swing/JToolTip.java
index 87e4610..daf9f0a 100644
--- a/libjava/javax/swing/JToolTip.java
+++ b/libjava/javax/swing/JToolTip.java
@@ -1,4 +1,4 @@
-/* JToolTip.java --
+/* JToolTip.java --
Copyright (C) 2002, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -35,25 +35,160 @@ this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
-
package javax.swing;
+import java.awt.AWTEvent;
import javax.accessibility.Accessible;
+import javax.accessibility.AccessibleContext;
+import javax.accessibility.AccessibleRole;
+import javax.swing.plaf.ToolTipUI;
+
+/**
+ * This class is used to display ToolTips. ToolTips are small floating windows
+ * that display text when the mouse comes to rest over a Component. ToolTips
+ * are set for JComponents using JComponent.setToolTipText(String).
+ */
public class JToolTip extends JComponent implements Accessible
{
+ /** DOCUMENT ME! */
private static final long serialVersionUID = -1138929898906751643L;
-
+
+ /**
+ * DOCUMENT ME!
+ */
+ protected class AccessibleJToolTip extends AccessibleJComponent
+ {
+ /**
+ * Creates a new AccessibleJToolTip object.
+ */
+ protected AccessibleJToolTip()
+ {
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public String getAccessibleDescription()
+ {
+ return null;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public AccessibleRole getAccessibleRole()
+ {
+ return null;
+ }
+ }
+
+ /** The text to display in the JToolTip. */
String text;
+ /** The JComponent this JToolTip is used for. */
+ JComponent component;
+
+ /**
+ * Creates a new JToolTip object.
+ */
public JToolTip()
{
+ disableEvents(AWTEvent.MOUSE_EVENT_MASK);
+ updateUI();
}
- public void setTipText(String newText)
+ /**
+ * This method returns the text this JToolTip displays.
+ *
+ * @return The text that this JToolTip displays.
+ */
+ public String getTipText()
{
- this.text = newText;
+ return text;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public AccessibleContext getAccessibleContext()
+ {
+ return null;
}
-}
+ /**
+ * This method returns the JComponent this JToolTip displays for.
+ *
+ * @return The JComponent this JToolTip displays for.
+ */
+ public JComponent getComponent()
+ {
+ return component;
+ }
+ /**
+ * This method returns the UI responsible for displaying this JToolTip.
+ *
+ * @return The UI responsible for displaying this JToolTip.
+ */
+ public ToolTipUI getUI()
+ {
+ return (ToolTipUI) ui;
+ }
+
+ /**
+ * This method returns the String identifier for the UI class.
+ *
+ * @return The String identifier for the UI class.
+ */
+ public String getUIClassID()
+ {
+ return "ToolTipUI";
+ }
+
+ /**
+ * This method returns a debugging String describing the JToolTip.
+ *
+ * @return A debugging String describing the JToolTip.
+ */
+ protected String paramString()
+ {
+ return "JToolTip";
+ }
+
+ /**
+ * This method sets the JComponent that the JToolTip displays for.
+ *
+ * @param c The JComponent that the JToolTip displays for.
+ */
+ public void setComponent(JComponent c)
+ {
+ component = c;
+ }
+
+ /**
+ * This method sets the text that the JToolTip displays.
+ *
+ * @param tipText The text that the JToolTip displays.
+ */
+ public void setTipText(String tipText)
+ {
+ text = tipText;
+ }
+
+ /**
+ * This method resets the UI used to the Look and Feel default.
+ */
+ public void updateUI()
+ {
+ setUI((ToolTipUI) UIManager.getUI(this));
+ revalidate();
+ repaint();
+ }
+}
diff --git a/libjava/javax/swing/JViewport.java b/libjava/javax/swing/JViewport.java
index 47ccdf7..a361183 100644
--- a/libjava/javax/swing/JViewport.java
+++ b/libjava/javax/swing/JViewport.java
@@ -249,8 +249,13 @@ public class JViewport extends JComponent
public void setView(Component v)
{
- add(v);
- fireStateChanged();
+ while (getComponentCount() > 0)
+ remove(0);
+ if (v != null)
+ {
+ add(v);
+ fireStateChanged();
+ }
}
public void revalidate()
diff --git a/libjava/javax/swing/KeyStroke.java b/libjava/javax/swing/KeyStroke.java
index b78be0c..afdbae8 100644
--- a/libjava/javax/swing/KeyStroke.java
+++ b/libjava/javax/swing/KeyStroke.java
@@ -37,235 +37,69 @@ exception statement from your version. */
package javax.swing;
+import java.awt.AWTKeyStroke;
import java.awt.event.KeyEvent;
import java.io.Serializable;
-/**
- * KeyStroke
- * @author Andrew Selkirk
- * @version 1.0
- */
-public class KeyStroke implements Serializable
+public class KeyStroke
+ extends AWTKeyStroke
+ implements Serializable
{
static final long serialVersionUID = -9060180771037902530L;
-
- //-------------------------------------------------------------
- // Variables --------------------------------------------------
- //-------------------------------------------------------------
-
- /**
- * keyChar
- */
- private char keyChar = 0;
-
- /**
- * keyCode
- */
- private int keyCode = 0;
-
- /**
- * modifiers
- */
- private int modifiers = 0;
-
- /**
- * onKeyRelease
- */
- private boolean onKeyRelease = false;
-
-
- //-------------------------------------------------------------
- // Initialization ---------------------------------------------
- //-------------------------------------------------------------
-
- /**
- * Constructor KeyStroke
- */
- private KeyStroke() {
- } // KeyStroke()
-
-
- //-------------------------------------------------------------
- // Methods ----------------------------------------------------
- //-------------------------------------------------------------
-
- /**
- * hashCode
- * @returns int
- */
- public int hashCode() {
- return 0; // TODO
- } // hashCode()
-
- /**
- * equals
- * @param object TODO
- * @returns boolean
- */
- public boolean equals(Object object) {
-
- // Variables
- KeyStroke key;
-
- if (object instanceof KeyStroke) {
- key = (KeyStroke) object;
- if (key.keyChar == keyChar &&
- key.keyCode == keyCode &&
- key.modifiers == modifiers &&
- key.onKeyRelease == onKeyRelease) {
- return true;
- } // if
- } // if
- return false;
-
- } // equals()
-
- /**
- * toString
- * @returns String
- */
- public String toString() {
- return null; // TODO
- } // toString()
-
- /**
- * getKeyStroke
- * @param keyChar TODO
- * @returns KeyStroke
- */
- public static KeyStroke getKeyStroke(char keyChar) {
-
- // Variables
- KeyStroke key;
-
- key = new KeyStroke();
- key.keyChar = keyChar;
- return key;
-
- } // getKeyStroke()
-
- /**
- * getKeyStroke - deprecated
- * @param keyChar TODO
- * @param onKeyRelease TODO
- * @returns KeyStroke
- * @deprecated Use getKeyStroke(char)
- */
- public static KeyStroke getKeyStroke(char keyChar, boolean onKeyRelease) {
- KeyStroke key = getKeyStroke(keyChar);
- key.onKeyRelease = onKeyRelease;
- return key;
- } // getKeyStroke()
-
- /**
- * getKeyStroke
- * @param keyChar TODO
- * @param modifiers TODO
- * @returns KeyStroke
- */
- public static KeyStroke getKeyStroke(Character keyChar, int modifiers) {
- KeyStroke key = getKeyStroke(keyChar.charValue());
- key.modifiers = modifiers;
- return key;
- } // getKeyStroke()
-
- /**
- * getKeyStroke
- * @param keyCode TODO
- * @param modifiers TODO
- * @param onKeyRelease TODO
- * @returns KeyStroke
- */
- public static KeyStroke getKeyStroke(int keyCode, int modifiers,
- boolean onKeyRelease) {
-
- // Variables
- KeyStroke key;
-
- key = new KeyStroke();
- key.keyCode = keyCode;
- key.modifiers = modifiers;
- key.onKeyRelease = onKeyRelease;
- return key;
-
- } // getKeyStroke()
-
- /**
- * getKeyStroke
- * @param keyCode TODO
- * @param modifiers TODO
- * @returns KeyStroke
- */
- public static KeyStroke getKeyStroke(int keyCode, int modifiers) {
- return getKeyStroke(keyCode, modifiers, false);
- } // getKeyStroke()
-
- /**
- * getKeyStroke
- * @param string TODO
- * @returns KeyStroke
- */
- public static KeyStroke getKeyStroke(String string) {
- return null; // TODO
- } // getKeyStroke()
-
- /**
- * getKeyStrokeForEvent
- * @param event TODO
- * @returns KeyStroke
- */
- public static KeyStroke getKeyStrokeForEvent(KeyEvent event) {
-
- // Variables
- int eventID;
- int eventMod;
-
- // Get Event ID
- eventID = event.getID();
- eventMod = event.getModifiers();
-
- // Check for KEY_TYPED event
- if (eventID == KeyEvent.KEY_TYPED) {
- return getKeyStroke(event.getKeyChar(), eventMod);
-
- // KEY_PRESSED or KEY_RELEASED event
- } else {
- return getKeyStroke(event.getKeyCode(), eventMod);
- } // if
-
- } // getKeyStrokeForEvent()
-
- /**
- * getKeyChar
- * @returns char
- */
- public char getKeyChar() {
- return keyChar;
- } // getKeyChar()
-
- /**
- * getKeyCode
- * @returns int
- */
- public int getKeyCode() {
- return keyCode;
- } // getKeyCode()
-
- /**
- * getModifiers
- * @returns int
- */
- public int getModifiers() {
- return modifiers; // TODO
- } // getModifiers()
-
- /**
- * isOnKeyRelease
- * @returns boolean
- */
- public boolean isOnKeyRelease() {
- return onKeyRelease;
- } // isOnKeyRelease()
-
-
-} // KeyStroke
+ private KeyStroke() {
+ }
+
+ protected KeyStroke(char keyChar, int keyCode, int modifiers,
+ boolean onKeyRelease)
+ {
+ super(keyChar, keyCode, modifiers, onKeyRelease);
+ }
+
+ static
+ {
+ AWTKeyStroke.registerSubclass(KeyStroke.class);
+ }
+
+ public static KeyStroke getKeyStroke(char keyChar)
+ {
+ return (KeyStroke) getAWTKeyStroke(keyChar);
+ }
+
+ /**
+ * @deprecated Use {@link #getKeyStroke(char)}
+ *
+ * This method, unlike all the other factory methods on this object,
+ * returns a non-cached, non-shared object. New code should not use it.
+ */
+ public static KeyStroke getKeyStroke(char keyChar, boolean onKeyRelease)
+ {
+ return new KeyStroke(keyChar, KeyEvent.VK_UNDEFINED, 0, onKeyRelease);
+ }
+
+ public static KeyStroke getKeyStroke(Character keyChar, int modifiers)
+ {
+ return (KeyStroke) getAWTKeyStroke(keyChar, modifiers);
+ }
+
+ public static KeyStroke getKeyStroke(int keyCode, int modifiers,
+ boolean onKeyRelease)
+ {
+ return (KeyStroke) getAWTKeyStroke(keyCode, modifiers, onKeyRelease);
+ }
+
+ public static KeyStroke getKeyStroke(int keyCode, int modifiers)
+ {
+ return (KeyStroke) getAWTKeyStroke(keyCode, modifiers);
+ }
+
+ public static KeyStroke getKeyStroke(String str)
+ {
+ return (KeyStroke) getAWTKeyStroke(str);
+ }
+
+ public static KeyStroke getKeyStrokeForEvent(KeyEvent event)
+ {
+ return (KeyStroke) getAWTKeyStrokeForEvent(event);
+ }
+
+}
diff --git a/libjava/javax/swing/MutableComboBoxModel.java b/libjava/javax/swing/MutableComboBoxModel.java
index 678aeaf..2c0f414 100644
--- a/libjava/javax/swing/MutableComboBoxModel.java
+++ b/libjava/javax/swing/MutableComboBoxModel.java
@@ -38,40 +38,46 @@ exception statement from your version. */
package javax.swing;
/**
- * MutableComboBoxModel
- * @author Andrew Selkirk
- * @version 1.0
+ * MutableComboBoxModel is interface for data model that keeps track of the
+ * components data and provides methods to insert and remove elements from
+ * it. The Classes implementing this interface should fire appropriate
+ * events indicating the undergoing change in the data model.
+ *
+ * @author Andrew Selkirk
+ * @author Olga Rodimina
+ * @version 1.0
*/
-public interface MutableComboBoxModel extends ComboBoxModel {
+public interface MutableComboBoxModel extends ComboBoxModel
+{
+ /**
+ * This method adds given object to its data model.
+ *
+ * @param object element to add to the data model.
+ */
+ void addElement(Object object);
- //-------------------------------------------------------------
- // Methods ----------------------------------------------------
- //-------------------------------------------------------------
-
- /**
- * addElement
- * @param object TODO
- */
- void addElement(Object object);
-
- /**
- * removeElementAt
- * @param index TODO
- */
- void removeElementAt(int index);
-
- /**
- * insertElementAt
- * @param object TODO
- * @param index TODO
- */
- void insertElementAt(Object object, int index);
-
- /**
- * removeElement
- * @param object TODO
- */
- void removeElement(Object object);
+ /**
+ * This method removes elements located at the given index in the data
+ * model.
+ *
+ * @param index index specifying location of the element to remove.
+ */
+ void removeElementAt(int index);
+ /**
+ * This method inserts givent element to the data model, at the specified
+ * index.
+ *
+ * @param object element to insert
+ * @param index index specifying the position in the data model where the
+ * given element should be inserted.
+ */
+ void insertElementAt(Object object, int index);
+ /**
+ * This method removes given element from the data model
+ *
+ * @param element to remove.
+ */
+ void removeElement(Object object);
} // MutableComboBoxModel
diff --git a/libjava/javax/swing/RepaintManager.java b/libjava/javax/swing/RepaintManager.java
index 05b974f..8910bf5 100644
--- a/libjava/javax/swing/RepaintManager.java
+++ b/libjava/javax/swing/RepaintManager.java
@@ -431,6 +431,9 @@ public class RepaintManager
if (damaged.width == 0 || damaged.height == 0)
continue;
JRootPane root = comp.getRootPane();
+ // If the component has no root, no repainting will occur.
+ if (root == null)
+ continue;
Rectangle rootDamage = SwingUtilities.convertRectangle(comp, damaged, root);
if (! roots.containsKey(root))
{
@@ -450,7 +453,7 @@ public class RepaintManager
Map.Entry ent = (Map.Entry) i.next();
JRootPane root = (JRootPane) ent.getKey();
Rectangle rect = (Rectangle) ent.getValue();
- root.paintImmediately(rect);
+ root.paintImmediately(rect);
}
}
diff --git a/libjava/javax/swing/ScrollPaneLayout.java b/libjava/javax/swing/ScrollPaneLayout.java
index 5e51e18..1103f3f 100644
--- a/libjava/javax/swing/ScrollPaneLayout.java
+++ b/libjava/javax/swing/ScrollPaneLayout.java
@@ -82,6 +82,8 @@ public class ScrollPaneLayout
public void syncWithScrollPane(JScrollPane scrollPane) {
viewport = scrollPane.getViewport();
+ rowHead = scrollPane.getRowHeader();
+ colHead = scrollPane.getColumnHeader();
vsb = scrollPane.getVerticalScrollBar();
hsb = scrollPane.getHorizontalScrollBar();
vsbPolicy = scrollPane.getVerticalScrollBarPolicy();
@@ -389,12 +391,12 @@ public class ScrollPaneLayout
y4 = scrollPaneBounds.y + scrollPaneBounds.height;
if (colHead != null)
- y2 = colHead.getPreferredSize().height;
+ y2 = y1 + colHead.getPreferredSize().height;
else
y2 = y1;
if (rowHead != null)
- x2 = rowHead.getPreferredSize().width;
+ x2 = x1 + rowHead.getPreferredSize().width;
else
x2 = x1;
diff --git a/libjava/javax/swing/SwingUtilities.java b/libjava/javax/swing/SwingUtilities.java
index 62b1561..731a7bc8d 100644
--- a/libjava/javax/swing/SwingUtilities.java
+++ b/libjava/javax/swing/SwingUtilities.java
@@ -51,9 +51,13 @@ import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.Toolkit;
import java.awt.Window;
+import java.awt.event.ActionEvent;
import java.awt.event.InputEvent;
+import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.lang.reflect.InvocationTargetException;
+import javax.swing.plaf.ActionMapUIResource;
+import javax.swing.plaf.InputMapUIResource;
/**
@@ -441,7 +445,7 @@ public class SwingUtilities implements SwingConstants
destination);
return new MouseEvent(destination, sourceEvent.getID(),
- sourceEvent.getWhen(), sourceEvent.getModifiers(),
+ sourceEvent.getWhen(), sourceEvent.getModifiersEx(),
newpt.x, newpt.y, sourceEvent.getClickCount(),
sourceEvent.isPopupTrigger(), sourceEvent.getButton());
}
@@ -863,7 +867,7 @@ public class SwingUtilities implements SwingConstants
*/
public static boolean isLeftMouseButton(MouseEvent event)
{
- return ((event.getModifiers() & InputEvent.BUTTON1_DOWN_MASK)
+ return ((event.getModifiersEx() & InputEvent.BUTTON1_DOWN_MASK)
== InputEvent.BUTTON1_DOWN_MASK);
}
@@ -876,7 +880,7 @@ public class SwingUtilities implements SwingConstants
*/
public static boolean isMiddleMouseButton(MouseEvent event)
{
- return ((event.getModifiers() & InputEvent.BUTTON2_DOWN_MASK)
+ return ((event.getModifiersEx() & InputEvent.BUTTON2_DOWN_MASK)
== InputEvent.BUTTON2_DOWN_MASK);
}
@@ -889,7 +893,7 @@ public class SwingUtilities implements SwingConstants
*/
public static boolean isRightMouseButton(MouseEvent event)
{
- return ((event.getModifiers() & InputEvent.BUTTON3_DOWN_MASK)
+ return ((event.getModifiersEx() & InputEvent.BUTTON3_DOWN_MASK)
== InputEvent.BUTTON3_DOWN_MASK);
}
@@ -911,4 +915,103 @@ public class SwingUtilities implements SwingConstants
return true;
}
}
+
+ public static boolean notifyAction(Action action,
+ KeyStroke ks,
+ KeyEvent event,
+ Object sender,
+ int modifiers)
+ {
+ if (action != null && action.isEnabled())
+ {
+ String name = (String) action.getValue(Action.ACTION_COMMAND_KEY);
+ if (name == null
+ && event.getKeyChar() != KeyEvent.CHAR_UNDEFINED)
+ name = new String(new char[] {event.getKeyChar()});
+ action.actionPerformed(new ActionEvent(sender,
+ ActionEvent.ACTION_PERFORMED,
+ name, modifiers));
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * <p>Change the shared, UI-managed {@link ActionMap} for a given
+ * component. ActionMaps are arranged in a hierarchy, in order to
+ * encourage sharing of common actions between components. The hierarchy
+ * unfortunately places UI-managed ActionMaps at the <em>end</em> of the
+ * parent-pointer chain, as illustrated:</p>
+ *
+ * <pre>
+ * [{@link javax.swing.JComponent#getActionMap()}]
+ * --&gt; [{@link javax.swing.ActionMap}]
+ * parent --&gt; [{@link javax.swing.text.KeymapActionMap}]
+ * parent --&gt; [{@link javax.swing.plaf.ActionMapUIResource}]
+ * </pre>
+ *
+ * <p>Our goal with this method is to replace the first ActionMap along
+ * this chain which is an instance of {@link ActionMapUIResource}, since
+ * these are the ActionMaps which are supposed to be shared between
+ * components.</p>
+ *
+ * <p>If the provided ActionMap is <code>null</code>, we interpret the
+ * call as a request to remove the UI-managed ActionMap from the
+ * component's ActionMap parent chain.</p>
+ */
+ public static void replaceUIActionMap(JComponent component,
+ ActionMap uiActionMap)
+ {
+ ActionMap child = component.getActionMap();
+ if (child == null)
+ component.setActionMap(uiActionMap);
+ else
+ {
+ while(child.getParent() != null
+ && !(child.getParent() instanceof ActionMapUIResource))
+ child = child.getParent();
+ if (child != null)
+ child.setParent(uiActionMap);
+ }
+ }
+
+ /**
+ * <p>Change the shared, UI-managed {@link InputMap} for a given
+ * component. InputMaps are arranged in a hierarchy, in order to
+ * encourage sharing of common input mappings between components. The
+ * hierarchy unfortunately places UI-managed InputMaps at the
+ * <em>end</em> of the parent-pointer chain, as illustrated:</p>
+ *
+ * <pre>
+ * [{@link javax.swing.JComponent#getInputMap()}]
+ * --&gt; [{@link javax.swing.InputMap}]
+ * parent --&gt; [{@link javax.swing.text.KeymapWrapper}]
+ * parent --&gt; [{@link javax.swing.plaf.InputMapUIResource}]
+ * </pre>
+ *
+ * <p>Our goal with this method is to replace the first InputMap along
+ * this chain which is an instance of {@link InputMapUIResource}, since
+ * these are the InputMaps which are supposed to be shared between
+ * components.</p>
+ *
+ * <p>If the provided InputMap is <code>null</code>, we interpret the
+ * call as a request to remove the UI-managed InputMap from the
+ * component's InputMap parent chain.</p>
+ */
+ public static void replaceUIInputMap(JComponent component,
+ int condition,
+ InputMap uiInputMap)
+ {
+ InputMap child = component.getInputMap(condition);
+ if (child == null)
+ component.setInputMap(condition, uiInputMap);
+ else
+ {
+ while(child.getParent() != null
+ && !(child.getParent() instanceof InputMapUIResource))
+ child = child.getParent();
+ if (child != null)
+ child.setParent(uiInputMap);
+ }
+ }
}
diff --git a/libjava/javax/swing/Timer.java b/libjava/javax/swing/Timer.java
index 2b2920a..529ad19 100644
--- a/libjava/javax/swing/Timer.java
+++ b/libjava/javax/swing/Timer.java
@@ -1,4 +1,4 @@
-/* Timer.java --
+/* Timer.java --
Copyright (C) 2002, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -35,22 +35,26 @@ this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
-
package javax.swing;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.Serializable;
import java.util.EventListener;
-
import javax.swing.event.EventListenerList;
+
+/**
+ * DOCUMENT ME!
+ */
public class Timer implements Serializable
{
+ /** DOCUMENT ME! */
private static final long serialVersionUID = -1116180831621385484L;
-
+
+ /** DOCUMENT ME! */
protected EventListenerList listenerList = new EventListenerList();
-
+
// This object manages a "queue" of virtual actionEvents, maintained as a
// simple long counter. When the timer expires, a new event is queued,
// and a dispatcher object is pushed into the system event queue. When
@@ -58,79 +62,127 @@ public class Timer implements Serializable
// ActionEvents as have been queued, unless the timer is set to
// coalescing mode, in which case it will fire only one ActionEvent.
+ /** DOCUMENT ME! */
private long queue;
+
+ /** DOCUMENT ME! */
private Object queueLock = new Object();
+
+ /** DOCUMENT ME! */
+ private Waker waker;
+
+ /**
+ * DOCUMENT ME!
+ */
private void queueEvent()
{
synchronized (queueLock)
{
- queue++;
- if (queue == 1)
- SwingUtilities.invokeLater(new Runnable() { public void run() { drainEvents(); } });
+ queue++;
+ if (queue == 1)
+ SwingUtilities.invokeLater(new Runnable()
+ {
+ public void run()
+ {
+ drainEvents();
+ }
+ });
+
}
}
+ /**
+ * DOCUMENT ME!
+ */
private void drainEvents()
{
synchronized (queueLock)
{
- if (isCoalesce())
- {
- if (queue > 0)
- fireActionPerformed();
- }
- else
- {
- while(queue > 0)
- {
- fireActionPerformed();
- queue--;
- }
- }
- queue = 0;
+ if (isCoalesce())
+ {
+ if (queue > 0)
+ fireActionPerformed();
+ }
+ else
+ {
+ while (queue > 0)
+ {
+ fireActionPerformed();
+ queue--;
+ }
+ }
+ queue = 0;
}
}
-
static boolean logTimers;
+
+ /** DOCUMENT ME! */
boolean coalesce = true;
+
+ /** DOCUMENT ME! */
boolean repeats = true;
+
+ /** DOCUMENT ME! */
boolean running;
+
+ /** DOCUMENT ME! */
int ticks;
+
+ /** DOCUMENT ME! */
int delay;
+
+ /** DOCUMENT ME! */
int initialDelay;
-
- private class Waker
- extends Thread
+
+ /**
+ * DOCUMENT ME!
+ */
+ private class Waker extends Thread
{
+ /**
+ * DOCUMENT ME!
+ */
public void run()
{
running = true;
- try
+ try
{
-
- sleep(initialDelay);
-
- while (running)
- {
- sleep(delay);
- queueEvent();
-
- if (logTimers)
- System.out.println("javax.swing.Timer -> clocktick");
-
- if (! repeats)
- break;
- }
- running = false;
- }
- catch (Exception e)
+ sleep(initialDelay);
+
+ while (running)
+ {
+ try
+ {
+ sleep(delay);
+ }
+ catch (InterruptedException e)
+ {
+ return;
+ }
+ queueEvent();
+
+ if (logTimers)
+ System.out.println("javax.swing.Timer -> clocktick");
+
+ if (! repeats)
+ break;
+ }
+ running = false;
+ }
+ catch (Exception e)
{
- System.out.println("swing.Timer::" + e);
+// System.out.println("swing.Timer::" + e);
}
}
}
+ /**
+ * Creates a new Timer object.
+ *
+ * @param d DOCUMENT ME!
+ * @param listener DOCUMENT ME!
+ */
public Timer(int d, ActionListener listener)
{
delay = d;
@@ -139,123 +191,214 @@ public class Timer implements Serializable
addActionListener(listener);
}
+ /**
+ * DOCUMENT ME!
+ *
+ * @param c DOCUMENT ME!
+ */
public void setCoalesce(boolean c)
{
coalesce = c;
}
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
public boolean isCoalesce()
{
return coalesce;
}
+ /**
+ * DOCUMENT ME!
+ *
+ * @param listener DOCUMENT ME!
+ */
public void addActionListener(ActionListener listener)
{
- listenerList.add (ActionListener.class, listener);
+ listenerList.add(ActionListener.class, listener);
}
-
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param listener DOCUMENT ME!
+ */
public void removeActionListener(ActionListener listener)
{
- listenerList.remove (ActionListener.class, listener);
+ listenerList.remove(ActionListener.class, listener);
}
/**
+ * DOCUMENT ME!
+ *
+ * @param listenerType DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ *
* @since 1.3
*/
- public EventListener[] getListeners (Class listenerType)
+ public EventListener[] getListeners(Class listenerType)
{
- return listenerList.getListeners (listenerType);
+ return listenerList.getListeners(listenerType);
}
-
+
/**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ *
* @since 1.4
*/
- public ActionListener[] getActionListeners ()
+ public ActionListener[] getActionListeners()
{
- return (ActionListener[]) listenerList.getListeners (ActionListener.class);
+ return (ActionListener[]) listenerList.getListeners(ActionListener.class);
}
- protected void fireActionPerformed (ActionEvent event)
+ /**
+ * DOCUMENT ME!
+ *
+ * @param event DOCUMENT ME!
+ */
+ protected void fireActionPerformed(ActionEvent event)
{
ActionListener[] listeners = getActionListeners();
-
+
for (int i = 0; i < listeners.length; i++)
- {
- listeners [i].actionPerformed (event);
- }
+ listeners[i].actionPerformed(event);
}
- void fireActionPerformed ()
+ /**
+ * DOCUMENT ME!
+ */
+ void fireActionPerformed()
{
- fireActionPerformed (new ActionEvent (this, ticks++, "Timer"));
+ fireActionPerformed(new ActionEvent(this, ticks++, "Timer"));
}
+ /**
+ * DOCUMENT ME!
+ *
+ * @param lt DOCUMENT ME!
+ */
public static void setLogTimers(boolean lt)
{
logTimers = lt;
}
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
public static boolean getLogTimers()
{
return logTimers;
}
-
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param d DOCUMENT ME!
+ */
public void setDelay(int d)
{
delay = d;
}
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
public int getDelay()
{
return delay;
}
+ /**
+ * DOCUMENT ME!
+ *
+ * @param i DOCUMENT ME!
+ */
public void setInitialDelay(int i)
{
initialDelay = i;
}
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
public int getInitialDelay()
{
return initialDelay;
}
+ /**
+ * DOCUMENT ME!
+ *
+ * @param r DOCUMENT ME!
+ */
public void setRepeats(boolean r)
{
repeats = r;
}
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
public boolean isRepeats()
{
return repeats;
}
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
public boolean isRunning()
{
return running;
}
+ /**
+ * DOCUMENT ME!
+ */
public void start()
{
if (isRunning())
- {
- System.err.println("attempt to start a running timer");
- return;
- }
- new Waker().start();
+ return;
+ waker = new Waker();
+ waker.start();
}
+ /**
+ * DOCUMENT ME!
+ */
public void restart()
{
- synchronized (queueLock)
- {
- queue = 0;
- }
+ stop();
start();
}
+ /**
+ * DOCUMENT ME!
+ */
public void stop()
{
running = false;
+ if (waker != null)
+ waker.interrupt();
+ synchronized (queueLock)
+ {
+ queue = 0;
+ }
}
}
diff --git a/libjava/javax/swing/ToolTipManager.java b/libjava/javax/swing/ToolTipManager.java
index 3a855f7..3556ef0 100644
--- a/libjava/javax/swing/ToolTipManager.java
+++ b/libjava/javax/swing/ToolTipManager.java
@@ -37,315 +37,608 @@ exception statement from your version. */
package javax.swing;
+import java.awt.AWTEvent;
+import java.awt.Component;
+import java.awt.Container;
+import java.awt.Dimension;
+import java.awt.FlowLayout;
+import java.awt.Insets;
+import java.awt.LayoutManager;
+import java.awt.Panel;
+import java.awt.Point;
+import java.awt.Rectangle;
+import java.awt.event.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
+import javax.swing.JComponent;
+import javax.swing.Popup;
+import javax.swing.PopupFactory;
+import javax.swing.SwingUtilities;
+import javax.swing.Timer;
/**
- * ToolTipManager
- *
- * @author Andrew Selkirk
+ * This class is responsible for the registration of JToolTips to Components
+ * and for displaying them when appropriate.
*/
-public class ToolTipManager extends MouseAdapter
- implements MouseMotionListener
+public class ToolTipManager extends MouseAdapter implements MouseMotionListener
{
- /**
- * stillInsideTimerAction
- */
- protected class stillInsideTimerAction
- implements ActionListener
+ /**
+ * This ActionListener is associated with the Timer that listens to whether
+ * the JToolTip can be hidden after four seconds.
+ */
+ protected class stillInsideTimerAction implements ActionListener
{
- /**
- * Constructor stillInsideTimerAction
- */
+ /**
+ * This method creates a new stillInsideTimerAction object.
+ */
protected stillInsideTimerAction()
{
- // TODO
}
- /**
- * actionPerformed
- * @param event TODO
- */
+ /**
+ * This method hides the JToolTip when the Timer has finished.
+ *
+ * @param event The ActionEvent.
+ */
public void actionPerformed(ActionEvent event)
{
- // TODO
+ hideTip();
}
}
- /**
- * outsideTimerAction
- */
- protected class outsideTimerAction
- implements ActionListener
+ /**
+ * This Actionlistener is associated with the Timer that listens to whether
+ * the mouse cursor has re-entered the JComponent in time for an immediate
+ * redisplay of the JToolTip.
+ */
+ protected class outsideTimerAction implements ActionListener
{
- /**
- * Constructor outsideTimerAction
- */
+ /**
+ * This method creates a new outsideTimerAction object.
+ */
protected outsideTimerAction()
{
- // TODO
}
- /**
- * actionPerformed
- * @param value0 TODO
- */
+ /**
+ * This method is called when the Timer that listens to whether the mouse
+ * cursor has re-entered the JComponent has run out.
+ *
+ * @param event The ActionEvent.
+ */
public void actionPerformed(ActionEvent event)
{
- // TODO
}
}
- /**
- * insideTimerAction
- */
- protected class insideTimerAction
- implements ActionListener
+ /**
+ * This ActionListener is associated with the Timer that listens to whether
+ * it is time for the JToolTip to be displayed after the mouse has entered
+ * the JComponent.
+ */
+ protected class insideTimerAction implements ActionListener
{
- /**
- * Constructor insideTimerAction
- */
+ /**
+ * This method creates a new insideTimerAction object.
+ */
protected insideTimerAction()
{
- // TODO
}
- /**
- * actionPerformed
- * @param event TODO
- */
+ /**
+ * This method displays the JToolTip when the Mouse has been still for the
+ * delay.
+ *
+ * @param event The ActionEvent.
+ */
public void actionPerformed(ActionEvent event)
{
- // TODO
+ showTip();
+ if (insideTimer != null)
+ insideTimer.start();
}
}
- /**
- * enterTimer
- */
- Timer enterTimer;
-
- /**
- * exitTimer
- */
- Timer exitTimer;
-
- /**
- * insideTimer
- */
- Timer insideTimer;
-
- /**
- * toolTipText
- */
- String toolTipText;
-
- /**
- * mouseEvent
- */
- MouseEvent mouseEvent;
-
- /**
- * showImmediately
- */
- boolean showImmediately;
-
- /**
- * tip
- */
- JToolTip tip;
-
- /**
- * enabled
- */
- boolean enabled;
-
- /**
- * timerEnter
- */
- private long timerEnter;
-
- /**
- * lightWeightPopupEnabled
- */
- protected boolean lightWeightPopupEnabled;
-
- /**
- * heavyWeightPopupEnabled
- */
- protected boolean heavyWeightPopupEnabled;
-
- /**
- * Constructor ToolTipManager
- */
+ /**
+ * The Timer that determines whether the Mouse has been still long enough
+ * for the JToolTip to be displayed.
+ */
+ Timer enterTimer;
+
+ /**
+ * The Timer that determines whether the Mouse has re-entered the JComponent
+ * quickly enough for the JToolTip to be displayed immediately.
+ */
+ Timer exitTimer;
+
+ /**
+ * The Timer that determines whether the JToolTip has been displayed long
+ * enough for it to be hidden.
+ */
+ Timer insideTimer;
+
+ /** A global enabled setting for the ToolTipManager. */
+ private transient boolean enabled = true;
+
+ /** lightWeightPopupEnabled */
+ protected boolean lightWeightPopupEnabled = true;
+
+ /** heavyWeightPopupEnabled */
+ protected boolean heavyWeightPopupEnabled = false;
+
+ /** The shared instance of the ToolTipManager. */
+ private static ToolTipManager shared;
+
+ /** The current component the tooltip is being displayed for. */
+ private static Component currentComponent;
+
+ /** The current tooltip. */
+ private static JToolTip currentTip;
+
+ /** The last known position of the mouse cursor. */
+ private static Point currentPoint;
+
+ /**
+ * The panel that holds the tooltip when the tooltip is displayed fully
+ * inside the current container.
+ */
+ private static Container containerPanel;
+
+ /**
+ * The window used when the tooltip doesn't fit inside the current
+ * container.
+ */
+ private static JWindow tooltipWindow;
+
+ /**
+ * Creates a new ToolTipManager and sets up the timers.
+ */
ToolTipManager()
{
- // TODO
+ enterTimer = new Timer(750, new insideTimerAction());
+ enterTimer.setRepeats(false);
+
+ insideTimer = new Timer(4000, new stillInsideTimerAction());
+ insideTimer.setRepeats(false);
+
+ exitTimer = new Timer(500, new outsideTimerAction());
+ exitTimer.setRepeats(false);
}
- /**
- * sharedInstance
- * @return ToolTipManager
- */
+ /**
+ * This method returns the shared instance of ToolTipManager used by all
+ * JComponents.
+ *
+ * @return The shared instance of ToolTipManager.
+ */
public static ToolTipManager sharedInstance()
{
- return null; // TODO
+ if (shared == null)
+ shared = new ToolTipManager();
+
+ return shared;
}
- /**
- * setEnabled
- * @param enabled TODO
- */
+ /**
+ * This method sets whether ToolTips are enabled or disabled for all
+ * JComponents.
+ *
+ * @param enabled Whether ToolTips are enabled or disabled for all
+ * JComponents.
+ */
public void setEnabled(boolean enabled)
{
- // TODO
+ if (! enabled)
+ {
+ enterTimer.stop();
+ exitTimer.stop();
+ insideTimer.stop();
+ }
+
+ this.enabled = enabled;
}
- /**
- * isEnabled
- * @return boolean
- */
+ /**
+ * This method returns whether ToolTips are enabled.
+ *
+ * @return Whether ToolTips are enabled.
+ */
public boolean isEnabled()
{
- return false; // TODO
+ return enabled;
}
- /**
- * isLightWeightPopupEnabled
- * @return boolean
- */
+ /**
+ * This method returns whether LightweightToolTips are enabled.
+ *
+ * @return Whether LighweightToolTips are enabled.
+ */
public boolean isLightWeightPopupEnabled()
{
- return false; // TODO
+ return lightWeightPopupEnabled;
}
- /**
- * setLightWeightPopupEnabled
- * @param enabled TODO
- */
+ /**
+ * This method sets whether LightweightToolTips are enabled. If you mix
+ * Lightweight and Heavyweight components, you must set this to false to
+ * ensure that the ToolTips popup above all other components.
+ *
+ * @param enabled Whether LightweightToolTips will be enabled.
+ */
public void setLightWeightPopupEnabled(boolean enabled)
{
- // TODO
+ lightWeightPopupEnabled = enabled;
+ heavyWeightPopupEnabled = ! enabled;
}
- /**
- * getInitialDelay
- * @return int
- */
+ /**
+ * This method returns the initial delay before the ToolTip is shown when
+ * the mouse enters a Component.
+ *
+ * @return The initial delay before the ToolTip is shown.
+ */
public int getInitialDelay()
{
- return 0; // TODO
+ return enterTimer.getDelay();
}
- /**
- * setInitialDelay
- * @param delay TODO
- */
+ /**
+ * This method sets the initial delay before the ToolTip is shown when the
+ * mouse enters a Component.
+ *
+ * @param delay The initial delay before the ToolTip is shown.
+ */
public void setInitialDelay(int delay)
{
- // TODO
+ enterTimer.setDelay(delay);
}
- /**
- * getDismissDelay
- * @return int
- */
+ /**
+ * This method returns the time the ToolTip will be shown before being
+ * hidden.
+ *
+ * @return The time the ToolTip will be shown before being hidden.
+ */
public int getDismissDelay()
{
- return 0; // TODO
+ return insideTimer.getDelay();
}
- /**
- * setDismissDelay
- * @param delay TODO
- */
+ /**
+ * This method sets the time the ToolTip will be shown before being hidden.
+ *
+ * @param delay The time the ToolTip will be shown before being hidden.
+ */
public void setDismissDelay(int delay)
{
- // TODO
+ insideTimer.setDelay(delay);
}
- /**
- * getReshowDelay
- * @return int
- */
+ /**
+ * This method returns the amount of delay where if the mouse re-enters a
+ * Component, the tooltip will be shown immediately.
+ *
+ * @return The reshow delay.
+ */
public int getReshowDelay()
{
- return 0; // TODO
+ return exitTimer.getDelay();
}
- /**
- * setReshowDelay
- * @param delay TODO
- */
+ /**
+ * This method sets the amount of delay where if the mouse re-enters a
+ * Component, the tooltip will be shown immediately.
+ *
+ * @param delay The reshow delay.
+ */
public void setReshowDelay(int delay)
{
- // TODO
+ exitTimer.setDelay(delay);
}
- /**
- * registerComponent
- * @param component TODO
- */
+ /**
+ * This method registers a JComponent with the ToolTipManager.
+ *
+ * @param component The JComponent to register with the ToolTipManager.
+ */
public void registerComponent(JComponent component)
{
- // TODO
+ component.addMouseListener(this);
+ component.addMouseMotionListener(this);
}
- /**
- * unregisterComponent
- * @param component TODO
- */
+ /**
+ * This method unregisters a JComponent with the ToolTipManager.
+ *
+ * @param component The JComponent to unregister with the ToolTipManager.
+ */
public void unregisterComponent(JComponent component)
{
- // TODO
+ component.removeMouseMotionListener(this);
+ component.removeMouseListener(this);
}
- /**
- * mouseEntered
- * @param event TODO
- */
+ /**
+ * This method is called whenever the mouse enters a JComponent registered
+ * with the ToolTipManager. When the mouse enters within the period of time
+ * specified by the reshow delay, the tooltip will be displayed
+ * immediately. Otherwise, it must wait for the initial delay before
+ * displaying the tooltip.
+ *
+ * @param event The MouseEvent.
+ */
public void mouseEntered(MouseEvent event)
{
- // TODO
+ if (currentComponent != null
+ && getContentPaneDeepestComponent(event) == currentComponent)
+ return;
+ currentPoint = event.getPoint();
+ currentComponent = (Component) event.getSource();
+
+ if (exitTimer.isRunning())
+ {
+ exitTimer.stop();
+ showTip();
+ insideTimer.start();
+ return;
+ }
+
+ // This should always be stopped unless we have just fake-exited.
+ if (! enterTimer.isRunning())
+ enterTimer.start();
}
- /**
- * mouseExited
- * @param event TODO
- */
+ /**
+ * This method is called when the mouse exits a JComponent registered with
+ * the ToolTipManager. When the mouse exits, the tooltip should be hidden
+ * immediately.
+ *
+ * @param event The MouseEvent.
+ */
public void mouseExited(MouseEvent event)
{
- // TODO
+ if (getContentPaneDeepestComponent(event) == currentComponent)
+ return;
+
+ currentPoint = event.getPoint();
+ currentComponent = null;
+ hideTip();
+
+ if (! enterTimer.isRunning() && insideTimer.isRunning())
+ exitTimer.start();
+ if (enterTimer.isRunning())
+ enterTimer.stop();
+ if (insideTimer.isRunning())
+ insideTimer.stop();
}
- /**
- * mousePressed
- * @param event TODO
- */
+ /**
+ * This method is called when the mouse is pressed on a JComponent
+ * registered with the ToolTipManager. When the mouse is pressed, the
+ * tooltip (if it is shown) must be hidden immediately.
+ *
+ * @param event The MouseEvent.
+ */
public void mousePressed(MouseEvent event)
{
- // TODO
+ currentPoint = event.getPoint();
+ if (enterTimer.isRunning())
+ enterTimer.restart();
+ else if (insideTimer.isRunning())
+ {
+ insideTimer.stop();
+ hideTip();
+ }
+ currentComponent.invalidate();
+ currentComponent.validate();
+ currentComponent.repaint();
}
- /**
- * mouseDragged
- * @param event TODO
- */
+ /**
+ * This method is called when the mouse is dragged in a JComponent
+ * registered with the ToolTipManager.
+ *
+ * @param event The MouseEvent.
+ */
public void mouseDragged(MouseEvent event)
{
- // TODO
+ currentPoint = event.getPoint();
+ if (enterTimer.isRunning())
+ enterTimer.restart();
}
- /**
- * mouseMoved
- * @param event TODO
- */
+ /**
+ * This method is called when the mouse is moved in a JComponent registered
+ * with the ToolTipManager.
+ *
+ * @param event The MouseEvent.
+ */
public void mouseMoved(MouseEvent event)
{
- // TODO
+ currentPoint = event.getPoint();
+ if (currentTip != null)
+ currentTip.setTipText(((JComponent) currentComponent).getToolTipText(event));
+ if (enterTimer.isRunning())
+ enterTimer.restart();
+ }
+
+ /**
+ * This method displays the ToolTip. It can figure out the method needed to
+ * show it as well (whether to display it in heavyweight/lightweight panel
+ * or a window.)
+ */
+ private void showTip()
+ {
+ if (! enabled)
+ return;
+
+ if (currentTip == null
+ || currentTip.getComponent() != currentComponent
+ && currentComponent instanceof JComponent)
+ currentTip = ((JComponent) currentComponent).createToolTip();
+ Point p = currentPoint;
+ Dimension dims = currentTip.getPreferredSize();
+ if (canToolTipFit(currentTip))
+ {
+ JLayeredPane pane = ((JRootPane) SwingUtilities.getAncestorOfClass(JRootPane.class,
+ currentComponent))
+ .getLayeredPane();
+
+ // This should never happen, but just in case.
+ if (pane == null)
+ return;
+
+ if (containerPanel != null)
+ hideTip();
+ if (isLightWeightPopupEnabled())
+ {
+ containerPanel = new Panel();
+ JRootPane root = new JRootPane();
+ root.getContentPane().add(currentTip);
+ containerPanel.add(root);
+ }
+ else
+ {
+ containerPanel = new JPanel();
+ containerPanel.add(currentTip);
+ }
+ LayoutManager lm = containerPanel.getLayout();
+ if (lm instanceof FlowLayout)
+ {
+ FlowLayout fm = (FlowLayout) lm;
+ fm.setVgap(0);
+ fm.setHgap(0);
+ }
+
+ p = getGoodPoint(p, pane, currentTip, dims);
+
+ pane.add(containerPanel);
+ containerPanel.setBounds(p.x, p.y, dims.width, dims.height);
+ currentTip.setBounds(0, 0, dims.width, dims.height);
+
+ pane.revalidate();
+ pane.repaint();
+ }
+ else
+ {
+ SwingUtilities.convertPointToScreen(p, currentComponent);
+ tooltipWindow = new JWindow();
+ tooltipWindow.getContentPane().add(currentTip);
+ tooltipWindow.setFocusable(false);
+ tooltipWindow.pack();
+ tooltipWindow.setBounds(p.x, p.y, dims.width, dims.height);
+ tooltipWindow.show();
+ }
+ currentTip.setVisible(true);
+ }
+
+ /**
+ * This method hides the ToolTip.
+ */
+ private void hideTip()
+ {
+ if (currentTip == null || ! currentTip.isVisible() || ! enabled)
+ return;
+ currentTip.setVisible(false);
+ if (containerPanel != null)
+ {
+ Container parent = containerPanel.getParent();
+ if (parent == null)
+ return;
+ parent.remove(containerPanel);
+ parent.invalidate();
+ parent.validate();
+ parent.repaint();
+
+ parent = currentTip.getParent();
+ if (parent == null)
+ return;
+ parent.remove(currentTip);
+
+ containerPanel = null;
+ }
+ if (tooltipWindow != null)
+ {
+ tooltipWindow.hide();
+ tooltipWindow.dispose();
+ tooltipWindow = null;
+ }
+ }
+
+ /**
+ * This method returns a point in the LayeredPane where the ToolTip can be
+ * shown. The point returned (if the ToolTip is to be displayed at the
+ * preferred dimensions) will always place the ToolTip inside the
+ * currentComponent if possible.
+ *
+ * @param p The last known good point for the mouse.
+ * @param c The JLayeredPane in the first RootPaneContainer up from the
+ * currentComponent.
+ * @param tip The ToolTip to display.
+ * @param dims The ToolTip preferred dimensions (can be null).
+ *
+ * @return A good point to place the ToolTip.
+ */
+ private Point getGoodPoint(Point p, JLayeredPane c, JToolTip tip,
+ Dimension dims)
+ {
+ if (dims == null)
+ dims = tip.getPreferredSize();
+ Rectangle bounds = currentComponent.getBounds();
+ if (p.x + dims.width > bounds.width)
+ p.x = bounds.width - dims.width;
+ if (p.y + dims.height > bounds.height)
+ p.y = bounds.height - dims.height;
+
+ p = SwingUtilities.convertPoint(currentComponent, p, c);
+ return p;
+ }
+
+ /**
+ * This method returns the deepest component in the content pane for the
+ * first RootPaneContainer up from the currentComponent. This method is
+ * used in conjunction with one of the mouseXXX methods.
+ *
+ * @param e The MouseEvent.
+ *
+ * @return The deepest component in the content pane.
+ */
+ private Component getContentPaneDeepestComponent(MouseEvent e)
+ {
+ Component source = (Component) e.getSource();
+ Container parent = (Container) SwingUtilities.getAncestorOfClass(JRootPane.class,
+ currentComponent);
+ if (parent == null)
+ return null;
+ parent = ((JRootPane) parent).getContentPane();
+ Point p = e.getPoint();
+ p = SwingUtilities.convertPoint(source, p, parent);
+ Component target = SwingUtilities.getDeepestComponentAt(parent, p.x, p.y);
+ return target;
+ }
+
+ /**
+ * This method returns whether the ToolTip can fit in the first
+ * RootPaneContainer up from the currentComponent.
+ *
+ * @param tip The ToolTip.
+ *
+ * @return Whether the ToolTip can fit.
+ */
+ private boolean canToolTipFit(JToolTip tip)
+ {
+ JRootPane root = (JRootPane) SwingUtilities.getAncestorOfClass(JRootPane.class,
+ currentComponent);
+ if (root == null)
+ return false;
+ Dimension pref = tip.getPreferredSize();
+ Dimension rootSize = root.getSize();
+ if (rootSize.width > pref.width && rootSize.height > pref.height)
+ return true;
+ return false;
}
}
diff --git a/libjava/javax/swing/UIManager.java b/libjava/javax/swing/UIManager.java
index eca96f9..a600972 100644
--- a/libjava/javax/swing/UIManager.java
+++ b/libjava/javax/swing/UIManager.java
@@ -278,7 +278,7 @@ public class UIManager implements Serializable
}
/**
- * Returns the L&amp;F object that renders the target component.
+ * Returns the Look and Feel object that renders the target component.
*/
public static ComponentUI getUI(JComponent target)
{
diff --git a/libjava/javax/swing/colorchooser/AbstractColorChooserPanel.java b/libjava/javax/swing/colorchooser/AbstractColorChooserPanel.java
index 3fa0ad1..37d6276 100644
--- a/libjava/javax/swing/colorchooser/AbstractColorChooserPanel.java
+++ b/libjava/javax/swing/colorchooser/AbstractColorChooserPanel.java
@@ -35,7 +35,6 @@ 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.colorchooser;
import java.awt.Color;
@@ -44,92 +43,119 @@ import javax.swing.Icon;
import javax.swing.JColorChooser;
import javax.swing.JPanel;
+
/**
* AbstractColorChooserPanel
- * @author Andrew Selkirk
- * @version 1.0
+ *
+ * @author Andrew Selkirk
+ * @version 1.0
*/
public abstract class AbstractColorChooserPanel extends JPanel
{
+ /** DOCUMENT ME! */
private static final long serialVersionUID = -977469671210173863L;
- /**
- * chooser
- */
- private JColorChooser chooser;
-
- /**
- * Constructor AbstractColorChooserPanel
- */
- public AbstractColorChooserPanel() {
- // TODO
- } // AbstractColorChooserPanel()
-
- /**
- * getDisplayName
- * @returns String
- */
- public abstract String getDisplayName();
-
- /**
- * updateChooser
- */
- public abstract void updateChooser();
-
- /**
- * buildChooser
- */
- protected abstract void buildChooser();
-
- /**
- * getSmallDisplayIcon
- * @returns Icon
- */
- public abstract Icon getSmallDisplayIcon();
-
- /**
- * getLargeDisplayIcon
- * @returns Icon
- */
- public abstract Icon getLargeDisplayIcon();
-
- /**
- * installChooserPanel
- * @param chooser TODO
- */
- public void installChooserPanel(JColorChooser chooser) {
- // TODO
- } // installChooserPanel()
-
- /**
- * uninstallChooserPanel
- * @param chooser TODO
- */
- public void uninstallChooserPanel(JColorChooser chooser) {
- // TODO
- } // uninstallChooserPanel()
-
- /**
- * getColorSelectionModel
- * @returns ColorSelectionModel
- */
- public ColorSelectionModel getColorSelectionModel() {
- return null; // TODO
- } // getColorSelectionModel()
-
- /**
- * getColorFromModel
- * @returns Color
- */
- protected Color getColorFromModel() {
- return null; // TODO
- } // getColorFromModel()
-
- /**
- * paint
- * @param graphics TODO
- */
- public void paint(Graphics graphics) {
- // TODO
- } // paint()
+ /** The chooser associated with this panel. */
+ private JColorChooser chooser;
+
+ /**
+ * This is the constructor for the AbstractColorChooserPanel.
+ */
+ public AbstractColorChooserPanel()
+ {
+ } // AbstractColorChooserPanel()
+
+ /**
+ * This method returns the name displayed in the tab for this chooser panel.
+ *
+ * @return The name displayed in the JTabbedPane's tabs.
+ */
+ public abstract String getDisplayName();
+
+ /**
+ * This method updates the chooser panel when the JColorChooser's color has
+ * changed.
+ */
+ public abstract void updateChooser();
+
+ /**
+ * This method constructs and does any initialization necessary for the
+ * chooser panel.
+ */
+ protected abstract void buildChooser();
+
+ /**
+ * This method sets the small icon used in the JTabbedPane for this chooser
+ * panel.
+ *
+ * @return The small icon used in the JTabbedPane.
+ */
+ public abstract Icon getSmallDisplayIcon();
+
+ /**
+ * This method sets the large icon useed in the jTabbedPane for this chooser
+ * panel.
+ *
+ * @return The large icon.
+ */
+ public abstract Icon getLargeDisplayIcon();
+
+ /**
+ * This method installs the chooser panel for the given JColorChooser.
+ *
+ * @param chooser The JColorChooser that will have this panel installed.
+ */
+ public void installChooserPanel(JColorChooser chooser)
+ {
+ this.chooser = chooser;
+ buildChooser();
+ } // installChooserPanel()
+
+ /**
+ * This method removes the chooser panel from the given JColorChooser and
+ * does any necessary clean up for the chooser panel.
+ *
+ * @param chooser The JColorChooser that is having this panel removed.
+ */
+ public void uninstallChooserPanel(JColorChooser chooser)
+ {
+ this.chooser = null;
+ } // uninstallChooserPanel()
+
+ /**
+ * This method returns the ColorSelectionModel for the JColorChooser
+ * associated with this chooser panel.
+ *
+ * @return The ColorSelectionModel for the JColorChooser associated with
+ * this chooser panel.
+ */
+ public ColorSelectionModel getColorSelectionModel()
+ {
+ if (chooser != null)
+ return chooser.getSelectionModel();
+ return null;
+ } // getColorSelectionModel()
+
+ /**
+ * This method returns the current color stored in the model for this
+ * chooser panel.
+ *
+ * @return The current color.
+ */
+ protected Color getColorFromModel()
+ {
+ if (chooser != null)
+ return chooser.getColor();
+ return null;
+ } // getColorFromModel()
+
+ /**
+ * This method paints the chooser panel.
+ *
+ * @param graphics The Graphics object to paint with.
+ */
+ public void paint(Graphics graphics)
+ {
+ super.paint(graphics);
+ } // paint()
} // AbstractColorChooserPanel
diff --git a/libjava/javax/swing/colorchooser/ColorChooserComponentFactory.java b/libjava/javax/swing/colorchooser/ColorChooserComponentFactory.java
index ffd8718..6e7ca33 100644
--- a/libjava/javax/swing/colorchooser/ColorChooserComponentFactory.java
+++ b/libjava/javax/swing/colorchooser/ColorChooserComponentFactory.java
@@ -35,49 +35,51 @@ 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.colorchooser;
import javax.swing.JComponent;
+
/**
* ColorChooserComponentFactory
- * @author Andrew Selkirk
- * @version 1.0
+ *
+ * @author Andrew Selkirk
+ * @version 1.0
*/
-public class ColorChooserComponentFactory {
-
- //-------------------------------------------------------------
- // Initialization ---------------------------------------------
- //-------------------------------------------------------------
-
- /**
- * Constructor ColorChooserComponentFactory
- */
- private ColorChooserComponentFactory() {
- // TODO
- } // ColorChooserComponentFactory()
-
-
- //-------------------------------------------------------------
- // Methods ----------------------------------------------------
- //-------------------------------------------------------------
-
- /**
- * getDefaultChooserPanels
- * @returns AbstractColorChooserPanel[]
- */
- public static AbstractColorChooserPanel[] getDefaultChooserPanels() {
- return null; // TODO
- } // getDefaultChooserPanels()
-
- /**
- * getPreviewPanel
- * @returns JComponent
- */
- public static JComponent getPreviewPanel() {
- return null; // TODO
- } // getPreviewPanel()
-
-
+public class ColorChooserComponentFactory
+{
+ /**
+ * Constructor ColorChooserComponentFactory
+ */
+ private ColorChooserComponentFactory()
+ {
+ } // ColorChooserComponentFactory()
+
+ /**
+ * This method returns the three default chooser panels to be used in
+ * JColorChooser.
+ *
+ * @return The default chooser panels.
+ */
+ public static AbstractColorChooserPanel[] getDefaultChooserPanels()
+ {
+ AbstractColorChooserPanel[] values =
+ {
+ new DefaultSwatchChooserPanel(),
+ new DefaultHSBChooserPanel(),
+ new DefaultRGBChooserPanel()
+ };
+ return values;
+ }
+
+ /**
+ * This method returns the default preview panel to be used with
+ * JColorChoosers.
+ *
+ * @return The default preview panel.
+ */
+ public static JComponent getPreviewPanel()
+ {
+ return new DefaultPreviewPanel();
+ } // getPreviewPanel()
} // ColorChooserComponentFactory
diff --git a/libjava/javax/swing/colorchooser/DefaultColorSelectionModel.java b/libjava/javax/swing/colorchooser/DefaultColorSelectionModel.java
index 43df7ed..90145ed 100644
--- a/libjava/javax/swing/colorchooser/DefaultColorSelectionModel.java
+++ b/libjava/javax/swing/colorchooser/DefaultColorSelectionModel.java
@@ -35,7 +35,6 @@ 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.colorchooser;
import java.awt.Color;
@@ -44,43 +43,55 @@ import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.EventListenerList;
+
/**
- * DefaultColorSelectionModel
- * @author Andrew Selkirk
- * @version 1.0
+ * This is the default implementation of the ColorSelectionModel interface
+ * that JColorChoosers use.
+ *
+ * @author Andrew Selkirk
+ * @version 1.0
*/
-public class DefaultColorSelectionModel
- implements ColorSelectionModel, Serializable
+public class DefaultColorSelectionModel implements ColorSelectionModel,
+ Serializable
{
+ /** DOCUMENT ME! */
private static final long serialVersionUID = -8117143602864778804L;
+ /** The currently selected color. */
private Color selectedColor;
- protected transient ChangeEvent changeEvent = new ChangeEvent (this);
- protected EventListenerList listenerList = new EventListenerList ();
+ /** The ChangeEvent fired to all ChangeListeners. */
+ protected transient ChangeEvent changeEvent = new ChangeEvent(this);
+
+ /** The list of listeners. */
+ protected EventListenerList listenerList = new EventListenerList();
/**
- * Creates a new color selection model.
+ * Creates a new color selection model with the default white color.
*/
public DefaultColorSelectionModel()
{
- this (Color.white);
+ this(Color.white);
}
/**
* Creates a new color selection model with a given selected color.
- *
- * @param color The selected color.
+ *
+ * @param color The initial color.
+ *
+ * @throws Error If the color is null.
*/
- public DefaultColorSelectionModel (Color color)
+ public DefaultColorSelectionModel(Color color)
{
super();
+ if (color == null)
+ throw new Error("ColorSelectionModel cannot be set to have null color.");
this.selectedColor = color;
}
/**
* Returns the selected color.
- *
+ *
* @return The selected color.
*/
public Color getSelectedColor()
@@ -89,31 +100,41 @@ public class DefaultColorSelectionModel
}
/**
+ * This method sets the color.
+ *
* @param color The color to set.
+ *
+ * @throws Error If the color is set.
*/
- public void setSelectedColor (Color color)
+ public void setSelectedColor(Color color)
{
- this.selectedColor = color;
+ if (color == null)
+ throw new Error("ColorSelectionModel cannot be set to have null color.");
+ if (color != selectedColor)
+ {
+ this.selectedColor = color;
+ fireStateChanged();
+ }
}
/**
* Adds a listener to this model.
- *
+ *
* @param listener The listener to add.
*/
- public void addChangeListener (ChangeListener listener)
+ public void addChangeListener(ChangeListener listener)
{
- listenerList.add (ChangeListener.class, listener);
+ listenerList.add(ChangeListener.class, listener);
}
/**
* Removes a listener from this model.
- *
+ *
* @param listener The listener to remove.
*/
- public void removeChangeListener (ChangeListener listener)
+ public void removeChangeListener(ChangeListener listener)
{
- listenerList.remove (ChangeListener.class, listener);
+ listenerList.remove(ChangeListener.class, listener);
}
/**
@@ -123,19 +144,19 @@ public class DefaultColorSelectionModel
*/
public ChangeListener[] getChangeListeners()
{
- return (ChangeListener[]) listenerList.getListeners (ChangeListener.class);
+ return (ChangeListener[]) listenerList.getListeners(ChangeListener.class);
}
/**
* Calls all the <code>stateChanged()</code> method of all added
- * <code>ChangeListener</code> objects with <code>changeEvent</code>
- * as argument.
+ * <code>ChangeListener</code> objects with <code>changeEvent</code> as
+ * argument.
*/
protected void fireStateChanged()
{
ChangeListener[] listeners = getChangeListeners();
for (int i = 0; i < listeners.length; i++)
- listeners [i].stateChanged (changeEvent);
+ listeners[i].stateChanged(changeEvent);
}
}
diff --git a/libjava/javax/swing/plaf/basic/BasicArrowButton.java b/libjava/javax/swing/plaf/basic/BasicArrowButton.java
index b124501..8354d06 100644
--- a/libjava/javax/swing/plaf/basic/BasicArrowButton.java
+++ b/libjava/javax/swing/plaf/basic/BasicArrowButton.java
@@ -163,7 +163,7 @@ public class BasicArrowButton extends JButton implements SwingConstants
/** The color the arrow is painted in if disabled and the bottom and
* right edges of the button. */
- private transient Color shadow = Color.BLACK;
+ private transient Color shadow = Color.gray;
/** The color the arrow is painted in if enabled and the bottom and
* right edges of the button. */
@@ -350,30 +350,30 @@ public class BasicArrowButton extends JButton implements SwingConstants
{
Polygon arrow;
double dsize = (double) size;
-
+
+ int one = (int) (dsize * 1 / 10);
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 five = (int) (dsize * 5 / 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);
+ arrow = new Polygon(new int[] { eight, five, one },
+ new int[] { eight, one, eight }, 3);
break;
case SOUTH:
- arrow = new Polygon(new int[] { two, five, eight },
- new int[] { three, seven, three }, 3);
+ arrow = new Polygon(new int[] { eight, five, two },
+ new int[] { two, eight, two }, 3);
break;
case EAST:
case RIGHT:
- arrow = new Polygon(new int[] { three, seven, three },
+ arrow = new Polygon(new int[] { two, eight, two },
new int[] { two, five, eight }, 3);
break;
case WEST:
case LEFT:
- arrow = new Polygon(new int[] { seven, three, seven },
+ arrow = new Polygon(new int[] { eight, two, eight },
new int[] { two, five, eight }, 3);
break;
default:
diff --git a/libjava/javax/swing/plaf/basic/BasicButtonListener.java b/libjava/javax/swing/plaf/basic/BasicButtonListener.java
index 4dafc7e..2b4be67 100644
--- a/libjava/javax/swing/plaf/basic/BasicButtonListener.java
+++ b/libjava/javax/swing/plaf/basic/BasicButtonListener.java
@@ -37,6 +37,7 @@ exception statement from your version. */
package javax.swing.plaf.basic;
+import java.awt.event.ActionEvent;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.InputEvent;
@@ -46,6 +47,7 @@ import java.awt.event.MouseMotionListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
+import javax.swing.AbstractAction;
import javax.swing.AbstractButton;
import javax.swing.ButtonModel;
import javax.swing.JComponent;
@@ -64,8 +66,14 @@ public class BasicButtonListener
}
public void focusGained(FocusEvent e)
{
+ if (e.getSource() instanceof AbstractButton)
+ {
+ AbstractButton button = (AbstractButton) e.getSource();
+ if (button.isFocusPainted())
+ button.repaint();
+ }
}
-
+
public void focusLost(FocusEvent e)
{
if (e.getSource() instanceof AbstractButton)
@@ -73,13 +81,43 @@ public class BasicButtonListener
AbstractButton button = (AbstractButton) e.getSource();
ButtonModel model = button.getModel();
model.setArmed(false);
+
+ if (button.isFocusPainted())
+ button.repaint();
}
}
public void installKeyboardActions(JComponent c)
{
+ c.getActionMap().put("pressed",
+ new AbstractAction()
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ AbstractButton button = (AbstractButton) e.getSource();
+ ButtonModel model = button.getModel();
+ // It is important that these transitions happen in this order.
+ model.setArmed(true);
+ model.setPressed(true);
+ }
+ });
+
+ c.getActionMap().put("released",
+ new AbstractAction()
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ AbstractButton button = (AbstractButton) e.getSource();
+ ButtonModel model = button.getModel();
+ // It is important that these transitions happen in this order.
+ model.setPressed(false);
+ model.setArmed(false);
+ }
+ });
}
public void uninstallKeyboardActions(JComponent c)
{
+ c.getActionMap().put("pressed", null);
+ c.getActionMap().put("released", null);
}
public void stateChanged(ChangeEvent e)
{
@@ -105,7 +143,7 @@ public class BasicButtonListener
{
AbstractButton button = (AbstractButton) e.getSource();
ButtonModel model = button.getModel();
- if ((e.getModifiers() & InputEvent.BUTTON1_MASK) != 0)
+ if ((e.getModifiersEx() & InputEvent.BUTTON1_DOWN_MASK) != 0)
{
// It is important that these transitions happen in this order.
model.setArmed(true);
@@ -128,7 +166,7 @@ public class BasicButtonListener
{
AbstractButton button = (AbstractButton) e.getSource();
ButtonModel model = button.getModel();
- if ((e.getModifiers() & InputEvent.BUTTON1_MASK) != 0)
+ if ((e.getModifiersEx() & InputEvent.BUTTON1_DOWN_MASK) != 0)
{
// It is important that these transitions happen in this order.
model.setPressed(false);
@@ -156,7 +194,7 @@ public class BasicButtonListener
model.setRollover(true);
if (model.isPressed()
- && (e.getModifiers() & InputEvent.BUTTON1_MASK) != 0)
+ && (e.getModifiersEx() & InputEvent.BUTTON1_DOWN_MASK) != 0)
model.setArmed(true);
else
model.setArmed(false);
diff --git a/libjava/javax/swing/plaf/basic/BasicButtonUI.java b/libjava/javax/swing/plaf/basic/BasicButtonUI.java
index 9134fb2..df7ac42 100644
--- a/libjava/javax/swing/plaf/basic/BasicButtonUI.java
+++ b/libjava/javax/swing/plaf/basic/BasicButtonUI.java
@@ -50,6 +50,7 @@ import java.awt.Stroke;
import javax.swing.AbstractButton;
import javax.swing.ButtonModel;
import javax.swing.Icon;
+import javax.swing.InputMap;
import javax.swing.JComponent;
import javax.swing.SwingUtilities;
import javax.swing.UIDefaults;
@@ -59,13 +60,21 @@ import javax.swing.plaf.ComponentUI;
public class BasicButtonUI extends ButtonUI
{
- /** A constant used to pad out elements in the button's layout and
- preferred size calculations. */
- int defaultTextIconGap = 4;
+ /**
+ * A constant used to pad out elements in the button's layout and
+ * preferred size calculations.
+ */
+ protected int defaultTextIconGap = 4;
- /** A constant added to the defaultTextIconGap to adjust the text
- within this particular button. */
- int defaultTextShiftOffset = 0;
+ /**
+ * A constant added to the defaultTextIconGap to adjust the text
+ * within this particular button.
+ */
+ protected int defaultTextShiftOffset = 0;
+
+ private int textShiftOffset;
+
+ private Color focusColor;
/**
* Factory method to create an instance of BasicButtonUI for a given
@@ -85,14 +94,32 @@ public class BasicButtonUI extends ButtonUI
return defaultTextIconGap;
}
+ protected void clearTextShiftOffset()
+ {
+ textShiftOffset = 0;
+ }
+
+ protected int getTextShiftOffset()
+ {
+ return textShiftOffset;
+ }
+
+ protected void setTextShiftOffset()
+ {
+ textShiftOffset = defaultTextShiftOffset;
+ }
+
protected void installDefaults(AbstractButton b)
{
UIDefaults defaults = UIManager.getLookAndFeelDefaults();
+ focusColor = defaults.getColor("Button.focus");
b.setForeground(defaults.getColor("Button.foreground"));
b.setBackground(defaults.getColor("Button.background"));
b.setMargin(defaults.getInsets("Button.margin"));
b.setBorder(defaults.getBorder("Button.border"));
b.setIconTextGap(defaults.getInt("Button.textIconGap"));
+ b.setInputMap(JComponent.WHEN_FOCUSED,
+ (InputMap) defaults.get("Button.focusInputMap"));
b.setOpaque(true);
}
@@ -133,10 +160,12 @@ public class BasicButtonUI extends ButtonUI
protected void installKeyboardActions(AbstractButton b)
{
+ listener.installKeyboardActions(b);
}
protected void uninstallKeyboardActions(AbstractButton b)
{
+ listener.uninstallKeyboardActions(b);
}
/**
@@ -271,22 +300,12 @@ public class BasicButtonUI extends ButtonUI
{
if (b.hasFocus() && b.isFocusPainted())
{
- Graphics2D g2 = (Graphics2D) g;
- Stroke saved_stroke = g2.getStroke();
- Color saved_color = g2.getColor();
- float dashes[] = new float[] {1.0f, 1.0f};
- BasicStroke s = new BasicStroke(1.0f,
- BasicStroke.CAP_SQUARE,
- BasicStroke.JOIN_MITER,
- 10, dashes, 0.0f);
- g2.setStroke(s);
- g2.setColor(Color.BLACK);
- g2.drawRect(vr.x + 2,
- vr.y + 2,
- vr.width - 4,
- vr.height - 4);
- g2.setStroke(saved_stroke);
- g2.setColor(saved_color);
+ Color saved_color = g.getColor();
+ g.setColor(focusColor);
+ Rectangle focusRect = ir.union(tr);
+ g.drawRect(focusRect.x, focusRect.y,
+ focusRect.width, focusRect.height);
+ g.setColor(saved_color);
}
}
diff --git a/libjava/javax/swing/plaf/basic/BasicInternalFrameUI.java b/libjava/javax/swing/plaf/basic/BasicInternalFrameUI.java
index d394b95..7101d42 100644
--- a/libjava/javax/swing/plaf/basic/BasicInternalFrameUI.java
+++ b/libjava/javax/swing/plaf/basic/BasicInternalFrameUI.java
@@ -765,7 +765,7 @@ public class BasicInternalFrameUI extends InternalFrameUI
lastComponentEntered);
MouseEvent exited = new MouseEvent(lastComponentEntered,
MouseEvent.MOUSE_EXITED,
- me.getWhen(), me.getModifiers(),
+ me.getWhen(), me.getModifiersEx(),
tp.x, tp.y, me.getClickCount(),
me.isPopupTrigger(),
me.getButton());
@@ -787,7 +787,7 @@ public class BasicInternalFrameUI extends InternalFrameUI
MouseEvent entered = new MouseEvent(lastComponentEntered,
MouseEvent.MOUSE_ENTERED,
me.getWhen(),
- me.getModifiers(), cp.x,
+ me.getModifiersEx(), cp.x,
cp.y, me.getClickCount(),
me.isPopupTrigger(),
me.getButton());
diff --git a/libjava/javax/swing/plaf/basic/BasicLookAndFeel.java b/libjava/javax/swing/plaf/basic/BasicLookAndFeel.java
index 324fa01..689cd8f 100644
--- a/libjava/javax/swing/plaf/basic/BasicLookAndFeel.java
+++ b/libjava/javax/swing/plaf/basic/BasicLookAndFeel.java
@@ -41,6 +41,7 @@ package javax.swing.plaf.basic;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
+import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.io.Serializable;
import java.util.Enumeration;
@@ -131,6 +132,7 @@ public abstract class BasicLookAndFeel extends LookAndFeel
"SeparatorUI", "javax.swing.plaf.basic.BasicSeparatorUI",
"SliderUI", "javax.swing.plaf.basic.BasicSliderUI",
"SplitPaneUI", "javax.swing.plaf.basic.BasicSplitPaneUI",
+ "SpinnerUI", "javax.swing.plaf.basic.BasicSpinnerUI",
"StandardDialogUI", "javax.swing.plaf.basic.BasicStandardDialogUI",
"TabbedPaneUI", "javax.swing.plaf.basic.BasicTabbedPaneUI",
"TableHeaderUI", "javax.swing.plaf.basic.BasicTableHeaderUI",
@@ -246,6 +248,7 @@ public abstract class BasicLookAndFeel extends LookAndFeel
"SPACE", "pressed",
"released SPACE", "released"
}),
+ "Button.focus", midPurple,
"Button.font", new FontUIResource("Dialog", Font.PLAIN, 12),
"Button.foreground", new ColorUIResource(Color.black),
"Button.highlight", new ColorUIResource(Color.white),
@@ -820,7 +823,14 @@ public abstract class BasicLookAndFeel extends LookAndFeel
"TextField.keyBindings", new JTextComponent.KeyBinding[] {
new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,
0),
- "notify-field-accept")},
+ "notify-field-accept"),
+ new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT,
+ InputEvent.SHIFT_DOWN_MASK),
+ "selection-backward"),
+ new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT,
+ InputEvent.SHIFT_DOWN_MASK),
+ "selection-forward"),
+ },
"TextField.margin", new InsetsUIResource(0, 0, 0, 0),
"TextField.selectionBackground", new ColorUIResource(lightPurple),
"TextField.selectionForeground", new ColorUIResource(Color.black),
@@ -881,7 +891,7 @@ public abstract class BasicLookAndFeel extends LookAndFeel
"ToolBar.font", new FontUIResource("Dialog", Font.PLAIN, 12),
"ToolBar.foreground", new ColorUIResource(Color.black),
"ToolBar.separatorSize", new DimensionUIResource(20, 20),
- "ToolTip.background", new ColorUIResource(Color.white),
+ "ToolTip.background", new ColorUIResource(122, 178, 241),
"ToolTip.border", new BorderUIResource.LineBorderUIResource(Color.lightGray),
"ToolTip.font", new FontUIResource("SansSerif", Font.PLAIN, 12),
"ToolTip.foreground", new ColorUIResource(Color.black),
diff --git a/libjava/javax/swing/plaf/basic/BasicPopupMenuUI.java b/libjava/javax/swing/plaf/basic/BasicPopupMenuUI.java
index f5b3e24..35fb005 100644
--- a/libjava/javax/swing/plaf/basic/BasicPopupMenuUI.java
+++ b/libjava/javax/swing/plaf/basic/BasicPopupMenuUI.java
@@ -163,6 +163,7 @@ public class BasicPopupMenuUI extends PopupMenuUI
popupMenu.setBorder(defaults.getBorder("PopupMenu.border"));
popupMenu.setFont(defaults.getFont("PopupMenu.font"));
popupMenu.setForeground(defaults.getColor("PopupMenu.foreground"));
+ popupMenu.setOpaque(true);
}
/**
@@ -228,11 +229,11 @@ public class BasicPopupMenuUI extends PopupMenuUI
}
/**
- * This method returns the minimum size of the JPopupMenu.
+ * This method returns the minimum size of the JPopupMenu.
*
- * @param c The JComponent to find a size for.
+ * @param c The JComponent to find a size for.
*
- * @return The minimum size.
+ * @return The minimum size.
*/
public Dimension getMinimumSize(JComponent c)
{
@@ -264,13 +265,13 @@ public class BasicPopupMenuUI extends PopupMenuUI
}
/**
- * Return true if given mouse event is a platform popup trigger,
- * and false otherwise
+ * Return true if given mouse event is a platform popup trigger, and false
+ * otherwise
*
* @param e MouseEvent that is to be checked for popup trigger event
*
- * @return true if given mouse event is a platform popup trigger,
- * and false otherwise
+ * @return true if given mouse event is a platform popup trigger, and false
+ * otherwise
*/
public boolean isPopupTrigger(MouseEvent e)
{
@@ -334,25 +335,25 @@ public class BasicPopupMenuUI extends PopupMenuUI
path[0] = popupMenu;
Component[] comps = popupMenu.getComponents();
if (comps.length != 0 && comps[0] instanceof MenuElement)
- path[1] = (MenuElement) comps[0];
- manager.setSelectedPath(path);
+ {
+ path[1] = (MenuElement) comps[0];
+ manager.setSelectedPath(path);
+ }
}
}
}
/**
- * ComponentListener that listens to Component Events fired by the
- * top - level window to which popup menu belongs. If top-level
- * window was resized, moved or hidded then popup menu will
- * be hidded and selected path of current menu hierarchy will be set
- * to null.
- *
+ * ComponentListener that listens to Component Events fired by the top -
+ * level window to which popup menu belongs. If top-level window was
+ * resized, moved or hidded then popup menu will be hidded and selected
+ * path of current menu hierarchy will be set to null.
*/
private class TopWindowListener implements ComponentListener
{
/**
- * This method is invoked when top-level window is resized.
- * This method closes current menu hierarchy.
+ * This method is invoked when top-level window is resized. This method
+ * closes current menu hierarchy.
*
* @param e The ComponentEvent
*/
@@ -363,8 +364,8 @@ public class BasicPopupMenuUI extends PopupMenuUI
}
/**
- * This method is invoked when top-level window is moved.
- * This method closes current menu hierarchy.
+ * This method is invoked when top-level window is moved. This method
+ * closes current menu hierarchy.
*
* @param e The ComponentEvent
*/
@@ -375,8 +376,8 @@ public class BasicPopupMenuUI extends PopupMenuUI
}
/**
- * This method is invoked when top-level window is shown
- * This method does nothing by default.
+ * This method is invoked when top-level window is shown This method does
+ * nothing by default.
*
* @param e The ComponentEvent
*/
@@ -387,8 +388,8 @@ public class BasicPopupMenuUI extends PopupMenuUI
}
/**
- * This method is invoked when top-level window is hidden
- * This method closes current menu hierarchy.
+ * This method is invoked when top-level window is hidden This method
+ * closes current menu hierarchy.
*
* @param e The ComponentEvent
*/
diff --git a/libjava/javax/swing/plaf/basic/BasicSliderUI.java b/libjava/javax/swing/plaf/basic/BasicSliderUI.java
index 7334b2e..b5c95cb 100644
--- a/libjava/javax/swing/plaf/basic/BasicSliderUI.java
+++ b/libjava/javax/swing/plaf/basic/BasicSliderUI.java
@@ -1226,6 +1226,7 @@ public class BasicSliderUI extends SliderUI
if (slider.getLabelTable() == null)
return 0;
+ Dimension pref;
for (Enumeration list = slider.getLabelTable().elements();
list.hasMoreElements();)
{
@@ -1233,8 +1234,9 @@ public class BasicSliderUI extends SliderUI
if (! (comp instanceof Component))
continue;
label = (Component) comp;
- if (label.getWidth() > widest)
- widest = label.getWidth();
+ pref = label.getPreferredSize();
+ if (pref != null && pref.width > widest)
+ widest = pref.width;
}
return widest;
}
@@ -1252,7 +1254,7 @@ public class BasicSliderUI extends SliderUI
if (slider.getLabelTable() == null)
return 0;
-
+ Dimension pref;
for (Enumeration list = slider.getLabelTable().elements();
list.hasMoreElements();)
{
@@ -1260,8 +1262,9 @@ public class BasicSliderUI extends SliderUI
if (! (comp instanceof Component))
continue;
label = (Component) comp;
- if (label.getHeight() > tallest)
- tallest = label.getHeight();
+ pref = label.getPreferredSize();
+ if (pref != null && pref.height > tallest)
+ tallest = pref.height;
}
return tallest;
}
diff --git a/libjava/javax/swing/plaf/basic/BasicTextUI.java b/libjava/javax/swing/plaf/basic/BasicTextUI.java
index 817a5e4..2ccf2fa 100644
--- a/libjava/javax/swing/plaf/basic/BasicTextUI.java
+++ b/libjava/javax/swing/plaf/basic/BasicTextUI.java
@@ -46,8 +46,16 @@ import java.awt.Insets;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Shape;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import javax.swing.Action;
+import javax.swing.ActionMap;
+import javax.swing.InputMap;
import javax.swing.JComponent;
+import javax.swing.SwingUtilities;
+import javax.swing.UIDefaults;
+import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.TextUI;
import javax.swing.plaf.UIResource;
@@ -61,7 +69,9 @@ import javax.swing.text.EditorKit;
import javax.swing.text.Element;
import javax.swing.text.Highlighter;
import javax.swing.text.JTextComponent;
+import javax.swing.text.Keymap;
import javax.swing.text.PlainDocument;
+import javax.swing.text.PlainView;
import javax.swing.text.Position;
import javax.swing.text.View;
import javax.swing.text.ViewFactory;
@@ -88,14 +98,18 @@ public abstract class BasicTextUI extends TextUI
private class RootView extends View
{
- private JTextComponent textComponent;
private View view;
- public RootView(JTextComponent parent)
- {
- super(null);
- textComponent = parent;
- }
+ public RootView()
+ {
+ super(null);
+ }
+
+ public ViewFactory getViewFactory()
+ {
+ // FIXME: Handle EditorKit somehow.
+ return BasicTextUI.this;
+ }
public void setView(View v)
{
@@ -123,17 +137,34 @@ public abstract class BasicTextUI extends TextUI
public void paint(Graphics g, Shape s)
{
- System.out.println("Michael: BasicTextUI.RootView.paint");
-
if (view != null)
view.paint(g, s);
- }
+ }
+
+ protected Rectangle modelToView(int position, Shape a, Position.Bias bias)
+ throws BadLocationException
+ {
+ return ((PlainView) view).modelToView(position, a, bias).getBounds();
+ }
+ }
+
+ class UpdateHandler implements PropertyChangeListener
+ {
+ public void propertyChange(PropertyChangeEvent event)
+ {
+ if (event.getPropertyName().equals("document"))
+ {
+ // Document changed.
+ modelChanged();
+ }
+ }
}
- RootView rootView;
+ static EditorKit kit = new DefaultEditorKit();
+
+ RootView rootView = new RootView();
JTextComponent textComponent;
- int gap = 3;
- EditorKit kit = new DefaultEditorKit();
+ UpdateHandler updateHandler = new UpdateHandler();
public BasicTextUI()
{
@@ -164,12 +195,12 @@ public abstract class BasicTextUI extends TextUI
Document doc = textComponent.getDocument();
if (doc == null)
{
- doc = new PlainDocument();
+ doc = getEditorKit(textComponent).createDefaultDocument();
textComponent.setDocument(doc);
- }
-
- rootView = new RootView(textComponent);
- setView(create(doc.getDefaultRootElement()));
+ }
+
+ textComponent.addPropertyChangeListener(updateHandler);
+ modelChanged();
installDefaults();
installListeners();
@@ -178,20 +209,115 @@ public abstract class BasicTextUI extends TextUI
protected void installDefaults()
{
+ Caret caret = textComponent.getCaret();
+ if (caret == null)
+ {
+ caret = createCaret();
+ textComponent.setCaret(caret);
+ }
+
+ Highlighter highlighter = textComponent.getHighlighter();
+ if (highlighter == null)
+ textComponent.setHighlighter(createHighlighter());
+
+ String prefix = getPropertyPrefix();
+ UIDefaults defaults = UIManager.getLookAndFeelDefaults();
+ textComponent.setBackground(defaults.getColor(prefix + ".background"));
+ textComponent.setForeground(defaults.getColor(prefix + ".foreground"));
+ textComponent.setMargin(defaults.getInsets(prefix + ".margin"));
+ textComponent.setBorder(defaults.getBorder(prefix + ".border"));
+ textComponent.setFont(defaults.getFont(prefix + ".font"));
+
+ caret.setBlinkRate(defaults.getInt(prefix + ".caretBlinkRate"));
}
protected void installListeners()
{
+ // Do nothing here.
+ }
+
+ protected String getKeymapName()
+ {
+ return "BasicTextUI";
+ }
+
+ protected Keymap createKeymap()
+ {
+ String prefix = getPropertyPrefix();
+ UIDefaults defaults = UIManager.getLookAndFeelDefaults();
+ JTextComponent.KeyBinding[] bindings =
+ (JTextComponent.KeyBinding[]) defaults.get(prefix + ".keyBindings");
+ Keymap km = JTextComponent.addKeymap(getKeymapName(),
+ JTextComponent.getKeymap(JTextComponent.DEFAULT_KEYMAP));
+ JTextComponent.loadKeymap(km, bindings, textComponent.getActions());
+ return km;
}
protected void installKeyboardActions()
+ {
+ // load any bindings for the older Keymap interface
+ Keymap km = JTextComponent.getKeymap(getKeymapName());
+ if (km == null)
+ km = createKeymap();
+ textComponent.setKeymap(km);
+
+ // load any bindings for the newer InputMap / ActionMap interface
+ SwingUtilities.replaceUIInputMap(textComponent,
+ JComponent.WHEN_FOCUSED,
+ getInputMap(JComponent.WHEN_FOCUSED));
+ SwingUtilities.replaceUIActionMap(textComponent, getActionMap());
+ }
+
+ InputMap getInputMap(int condition)
+ {
+ String prefix = getPropertyPrefix();
+ UIDefaults defaults = UIManager.getLookAndFeelDefaults();
+ switch (condition)
+ {
+ case JComponent.WHEN_IN_FOCUSED_WINDOW:
+ // FIXME: is this the right string? nobody seems to use it.
+ return (InputMap) defaults.get(prefix + ".windowInputMap");
+ case JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT:
+ return (InputMap) defaults.get(prefix + ".ancestorInputMap");
+ default:
+ case JComponent.WHEN_FOCUSED:
+ return (InputMap) defaults.get(prefix + ".focusInputMap");
+ }
+ }
+
+ ActionMap getActionMap()
+ {
+ String prefix = getPropertyPrefix();
+ UIDefaults defaults = UIManager.getLookAndFeelDefaults();
+ ActionMap am = (ActionMap) defaults.get(prefix + ".actionMap");
+ if (am == null)
+ {
+ am = createActionMap();
+ defaults.put(prefix + ".actionMap", am);
+ }
+ return am;
+ }
+
+ ActionMap createActionMap()
{
+ Action[] actions = textComponent.getActions();
+ ActionMap am = new ActionMap();
+ for (int i = 0; i < actions.length; ++i)
+ {
+ String name = (String) actions[i].getValue(Action.NAME);
+ if (name != null)
+ am.put(name, actions[i]);
+ }
+ return am;
}
- public void uninstallUI(final JComponent c)
+ public void uninstallUI(final JComponent component)
{
- super.uninstallUI(c);
- rootView = null;
+ super.uninstallUI(component);
+ rootView.setView(null);
+
+ textComponent.removePropertyChangeListener(updateHandler);
+ textComponent = null;
uninstallDefaults();
uninstallListeners();
@@ -200,14 +326,17 @@ public abstract class BasicTextUI extends TextUI
protected void uninstallDefaults()
{
+ // Do nothing here.
}
protected void uninstallListeners()
{
+ // Do nothing here.
}
protected void uninstallKeyboardActions()
{
+ // Do nothing here.
}
protected abstract String getPropertyPrefix();
@@ -235,18 +364,19 @@ public abstract class BasicTextUI extends TextUI
if (textComponent.isOpaque())
paintBackground(g);
- rootView.paint(g, getVisibleEditorRect());
-
- if (highlighter != null)
+ if (highlighter != null
+ && textComponent.getSelectionStart() != textComponent.getSelectionEnd())
highlighter.paint(g);
+ rootView.paint(g, getVisibleEditorRect());
+
if (caret != null)
caret.paint(g);
}
protected void paintBackground(Graphics g)
{
- g.setColor(Color.WHITE); // FIXME: set background color
+ g.setColor(textComponent.getBackground());
g.fillRect(0, 0, textComponent.getWidth(), textComponent.getHeight());
}
@@ -281,13 +411,13 @@ public abstract class BasicTextUI extends TextUI
public Rectangle modelToView(JTextComponent t, int pos)
throws BadLocationException
{
- return modelToView(t, pos, null);
+ return modelToView(t, pos, Position.Bias.Forward);
}
public Rectangle modelToView(JTextComponent t, int pos, Position.Bias bias)
throws BadLocationException
{
- return null;
+ return rootView.modelToView(pos, getVisibleEditorRect(), bias).getBounds();
}
public int viewToModel(JTextComponent t, Point pt)
@@ -331,4 +461,11 @@ public abstract class BasicTextUI extends TextUI
rootView.setView(view);
view.setParent(rootView);
}
+
+ protected void modelChanged()
+ {
+ ViewFactory factory = rootView.getViewFactory();
+ Element elem = textComponent.getDocument().getDefaultRootElement();
+ setView(factory.create(elem));
+ }
}
diff --git a/libjava/javax/swing/plaf/basic/BasicToggleButtonUI.java b/libjava/javax/swing/plaf/basic/BasicToggleButtonUI.java
index a319b0b..1dc6423 100644
--- a/libjava/javax/swing/plaf/basic/BasicToggleButtonUI.java
+++ b/libjava/javax/swing/plaf/basic/BasicToggleButtonUI.java
@@ -43,12 +43,10 @@ import javax.swing.plaf.ComponentUI;
public class BasicToggleButtonUI extends BasicButtonUI
{
-
- public static ComponentUI createUI(final JComponent c) {
- return new BasicToggleButtonUI();
- }
-}
-
-
+ public static ComponentUI createUI(final JComponent component)
+ {
+ return new BasicToggleButtonUI();
+ }
+}
diff --git a/libjava/javax/swing/plaf/basic/BasicToolBarUI.java b/libjava/javax/swing/plaf/basic/BasicToolBarUI.java
index 4fb142b..99e4475 100644
--- a/libjava/javax/swing/plaf/basic/BasicToolBarUI.java
+++ b/libjava/javax/swing/plaf/basic/BasicToolBarUI.java
@@ -157,13 +157,11 @@ public class BasicToolBarUI extends ToolBarUI implements SwingConstants
/**
* This method creates a new BasicToolBarUI object for the given JToolBar.
- *
- * @param b The JToolBar to represent with this UI.
*/
- public BasicToolBarUI(JToolBar b)
- {
- super();
- }
+ public BasicToolBarUI()
+ {
+ super();
+ }
/**
* This method returns whether the JToolBar can dock at the given position.
@@ -351,10 +349,10 @@ public class BasicToolBarUI extends ToolBarUI implements SwingConstants
*
* @return A new UI delegate.
*/
- public static ComponentUI createUI(JComponent c)
- {
- return new BasicToolBarUI((JToolBar) c);
- }
+ public static ComponentUI createUI(JComponent c)
+ {
+ return new BasicToolBarUI();
+ }
/**
* This method is called to drag the DragWindow around when the JToolBar is
diff --git a/libjava/javax/swing/table/DefaultTableCellRenderer.java b/libjava/javax/swing/table/DefaultTableCellRenderer.java
index 563d9e6..ef82988 100644
--- a/libjava/javax/swing/table/DefaultTableCellRenderer.java
+++ b/libjava/javax/swing/table/DefaultTableCellRenderer.java
@@ -122,8 +122,22 @@ public class DefaultTableCellRenderer extends JLabel
{
if (value!=null)
super.setText(value.toString());
-
- return this;
+
+ setOpaque(true);
+ if (isSelected)
+ {
+ setBackground(table.getSelectionBackground());
+ setForeground(table.getSelectionForeground());
+ }
+ else
+ {
+ setBackground(table.getBackground());
+ setForeground(table.getForeground());
+ }
+
+ setEnabled(table.isEnabled());
+ setFont(table.getFont());
+ return this;
}
/**
@@ -150,6 +164,11 @@ public class DefaultTableCellRenderer extends JLabel
// Does nothing.
}
+ public void revalidate()
+ {
+ // Does nothing.
+ }
+
/**
* Overriden for performance.
*
diff --git a/libjava/javax/swing/table/DefaultTableColumnModel.java b/libjava/javax/swing/table/DefaultTableColumnModel.java
index ea46ce5..d7a3c35 100644
--- a/libjava/javax/swing/table/DefaultTableColumnModel.java
+++ b/libjava/javax/swing/table/DefaultTableColumnModel.java
@@ -1,5 +1,5 @@
/* DefaultTableColumnModel.java --
- Copyright (C) 2002 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -44,6 +44,7 @@ import java.util.Enumeration;
import java.util.EventListener;
import java.util.Vector;
import javax.swing.ListSelectionModel;
+import javax.swing.DefaultListSelectionModel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.EventListenerList;
import javax.swing.event.ListSelectionEvent;
@@ -61,86 +62,93 @@ public class DefaultTableColumnModel
implements TableColumnModel, PropertyChangeListener, ListSelectionListener,
Serializable
{
- static final long serialVersionUID = 6580012493508960512L;
-
- /**
- * tableColumns
- */
- protected Vector tableColumns;
-
- /**
- * selectionModel
- */
- protected ListSelectionModel selectionModel;
-
- /**
- * columnMargin
- */
- protected int columnMargin;
-
- /**
- * listenerList
- */
- protected EventListenerList listenerList;
-
- /**
- * changeEvent
- */
- protected transient ChangeEvent changeEvent;
-
- /**
- * columnSelectionAllowed
- */
- protected boolean columnSelectionAllowed;
-
- /**
- * totalColumnWidth
- */
- protected int totalColumnWidth;
-
- /**
- * Constructor DefaultTableColumnModel
- */
+ private static final long serialVersionUID = 6580012493508960512L;
+
+ /**
+ * tableColumns
+ */
+ protected Vector tableColumns;
+
+ /**
+ * selectionModel
+ */
+ protected ListSelectionModel selectionModel;
+
+ /**
+ * columnMargin
+ */
+ protected int columnMargin;
+
+ /**
+ * listenerList
+ */
+ protected EventListenerList listenerList = new EventListenerList();
+
+ /**
+ * changeEvent
+ */
+ protected transient ChangeEvent changeEvent = new ChangeEvent(this);
+
+ /**
+ * columnSelectionAllowed
+ */
+ protected boolean columnSelectionAllowed;
+
+ /**
+ * totalColumnWidth
+ */
+ protected int totalColumnWidth;
+
+ /**
+ * Constructor DefaultTableColumnModel
+ */
public DefaultTableColumnModel()
{
- // TODO
+ tableColumns = new Vector();
+ setSelectionModel(new DefaultListSelectionModel());
+ columnMargin = 1;
+ columnSelectionAllowed = false;
}
- /**
- * addColumn
- * @param value0 TODO
- */
- public void addColumn(TableColumn value0)
+ /**
+ * addColumn
+ * @param value0 TODO
+ */
+ public void addColumn(TableColumn col)
{
- // TODO
+ tableColumns.add(col);
+ invalidateWidthCache();
}
- /**
- * removeColumn
- * @param value0 TODO
- */
- public void removeColumn(TableColumn value0)
+ /**
+ * removeColumn
+ * @param value0 TODO
+ */
+ public void removeColumn(TableColumn col)
{
- // TODO
+ tableColumns.remove(col);
+ invalidateWidthCache();
}
- /**
- * moveColumn
- * @param value0 TODO
- * @param value1 TODO
- */
- public void moveColumn(int value0, int value1)
+ /**
+ * moveColumn
+ * @param value0 TODO
+ * @param value1 TODO
+ */
+ public void moveColumn(int i, int j)
{
- // TODO
+ Object tmp = tableColumns.get(i);
+ tableColumns.set(i, tableColumns.get(j));
+ tableColumns.set(j, tmp);
}
- /**
- * setColumnMargin
- * @param value0 TODO
- */
- public void setColumnMargin(int value0)
+ /**
+ * setColumnMargin
+ * @param value0 TODO
+ */
+ public void setColumnMargin(int m)
{
- // TODO
+ columnMargin = m;
}
/**
@@ -149,7 +157,7 @@ public class DefaultTableColumnModel
*/
public int getColumnCount()
{
- return 0; // TODO
+ return tableColumns.size();
}
/**
@@ -158,27 +166,27 @@ public class DefaultTableColumnModel
*/
public Enumeration getColumns()
{
- return null; // TODO
+ return tableColumns.elements();
}
/**
* getColumnIndex
* @param value0 TODO
* @return int
- */
- public int getColumnIndex(Object value0)
+ */
+ public int getColumnIndex(Object obj)
{
- return 0; // TODO
+ return tableColumns.indexOf(obj, 0);
}
/**
* getColumn
* @param value0 TODO
* @return TableColumn
- */
- public TableColumn getColumn(int value0)
+ */
+ public TableColumn getColumn(int i)
{
- return null; // TODO
+ return (TableColumn) tableColumns.get(i);
}
/**
@@ -187,17 +195,25 @@ public class DefaultTableColumnModel
*/
public int getColumnMargin()
{
- return 0; // TODO
+ return columnMargin;
}
/**
* getColumnIndexAtX
* @param value0 TODO
* @return int
- */
- public int getColumnIndexAtX(int value0)
- {
- return 0; // TODO
+ */
+ public int getColumnIndexAtX(int x)
+ {
+ for (int i = 0; i < tableColumns.size(); ++i)
+ {
+ int w = ((TableColumn)tableColumns.get(i)).getWidth();
+ if (0 <= x && x < w)
+ return i;
+ else
+ x -= w;
+ }
+ return -1;
}
/**
@@ -206,16 +222,23 @@ public class DefaultTableColumnModel
*/
public int getTotalColumnWidth()
{
- return 0; // TODO
+ if (totalColumnWidth == -1)
+ recalcWidthCache();
+ return totalColumnWidth;
}
- /**
- * setSelectionModel
- * @param value0 TODO
- */
- public void setSelectionModel(ListSelectionModel value0)
+ /**
+ * setSelectionModel
+ * @param model TODO
+ * @exception IllegalArgumentException if model is null
+ */
+ public void setSelectionModel(ListSelectionModel model)
{
- // TODO
+ if (model == null)
+ throw new IllegalArgumentException();
+
+ selectionModel = model;
+ selectionModel.addListSelectionListener(this);
}
/**
@@ -224,16 +247,16 @@ public class DefaultTableColumnModel
*/
public ListSelectionModel getSelectionModel()
{
- return null; // TODO
+ return selectionModel;
}
- /**
- * setColumnSelectionAllowed
- * @param value0 TODO
- */
- public void setColumnSelectionAllowed(boolean value0)
+ /**
+ * setColumnSelectionAllowed
+ * @param value0 TODO
+ */
+ public void setColumnSelectionAllowed(boolean a)
{
- // TODO
+ columnSelectionAllowed = a;
}
/**
@@ -242,7 +265,7 @@ public class DefaultTableColumnModel
*/
public boolean getColumnSelectionAllowed()
{
- return false; // TODO
+ return columnSelectionAllowed;
}
/**
@@ -263,13 +286,13 @@ public class DefaultTableColumnModel
return 0; // TODO
}
- /**
- * addColumnModelListener
- * @param value0 TODO
- */
- public void addColumnModelListener(TableColumnModelListener value0)
+ /**
+ * addColumnModelListener
+ * @param value0 TODO
+ */
+ public void addColumnModelListener(TableColumnModelListener listener)
{
- // TODO
+ listenerList.add(TableColumnModelListener.class, listener);
}
/**
@@ -308,13 +331,15 @@ public class DefaultTableColumnModel
// TODO
}
- /**
- * fireColumnSelectionChanged
- * @param value0 TODO
- */
- protected void fireColumnSelectionChanged(ListSelectionEvent value0)
+ /**
+ * fireColumnSelectionChanged
+ * @param value0 TODO
+ */
+ protected void fireColumnSelectionChanged(ListSelectionEvent evt)
{
- // TODO
+ EventListener [] listeners = getListeners(TableColumnModelListener.class);
+ for (int i = 0; i < listeners.length; ++i)
+ ((TableColumnModelListener)listeners[i]).columnSelectionChanged(evt);
}
/**
@@ -329,10 +354,10 @@ public class DefaultTableColumnModel
* getListeners
* @param value0 TODO
* @return EventListener[]
- */
- public EventListener[] getListeners(Class value0)
+ */
+ public EventListener[] getListeners(Class klass)
{
- return null; // TODO
+ return listenerList.getListeners(klass);
}
/**
@@ -350,7 +375,7 @@ public class DefaultTableColumnModel
*/
public void valueChanged(ListSelectionEvent value0)
{
- // TODO
+ fireColumnSelectionChanged(value0);
}
/**
@@ -367,7 +392,14 @@ public class DefaultTableColumnModel
*/
protected void recalcWidthCache()
{
- // TODO
+ if (totalColumnWidth == -1)
+ {
+ totalColumnWidth = 0;
+ for (int i = 0; i < tableColumns.size(); ++i)
+ {
+ totalColumnWidth += ((TableColumn)tableColumns.get(i)).getWidth();
+ }
+ }
}
/**
@@ -375,6 +407,6 @@ public class DefaultTableColumnModel
*/
private void invalidateWidthCache()
{
- // TODO
+ totalColumnWidth = -1;
}
}
diff --git a/libjava/javax/swing/table/DefaultTableModel.java b/libjava/javax/swing/table/DefaultTableModel.java
index 5c57f81..8e11130 100644
--- a/libjava/javax/swing/table/DefaultTableModel.java
+++ b/libjava/javax/swing/table/DefaultTableModel.java
@@ -50,445 +50,387 @@ public class DefaultTableModel extends AbstractTableModel
implements Serializable
{
static final long serialVersionUID = 6680042567037222321L;
-
- //-------------------------------------------------------------
- // Variables --------------------------------------------------
- //-------------------------------------------------------------
-
- /**
- * dataVector
- */
- protected Vector dataVector;
-
- /**
- * columnIdentifiers
- */
- protected Vector columnIdentifiers;
-
-
- //-------------------------------------------------------------
- // Initialization ---------------------------------------------
- //-------------------------------------------------------------
-
- /**
- * Constructor DefaultTableModel
- */
- public DefaultTableModel() {
- this(0, 0);
- } // DefaultTableModel()
-
- /**
- * Constructor DefaultTableModel
- * @param value0 TODO
- * @param value1 TODO
- */
- public DefaultTableModel(int numRows, int numColumns) {
-
- // Variables
- int columnIndex;
- Vector defaultNames;
-
- // Create Column Names
- defaultNames = new Vector();
- for (columnIndex = 0; columnIndex < numColumns; columnIndex++) {
- defaultNames.addElement(super.getColumnName(columnIndex));
- } // for
-
- // Setup Data
-// setDataVector(defaultNames, numRows);
-
- } // DefaultTableModel()
-
- /**
- * Constructor DefaultTableModel
- * @param value0 TODO
- * @param value1 TODO
- */
- public DefaultTableModel(Vector columnNames, int numRows) {
-
- // Variables
- Vector data;
- Vector rowData;
- int rowIndex;
- int numColumns;
-
- // Create Data
- data = new Vector();
- if (columnNames == null) {
- numColumns = 0;
- } else {
- numColumns = columnNames.size();
- } // if
- for (rowIndex = 0; rowIndex < numRows; rowIndex++) {
- rowData = new Vector();
- rowData.setSize(numColumns);
- data.addElement(rowData);
- } // for
-
- // Setup Data
- setDataVector(data, columnNames);
-
- } // DefaultTableModel()
-
- /**
- * Constructor DefaultTableModel
- * @param value0 TODO
- * @param value1 TODO
- */
- public DefaultTableModel(Object[] columnNames, int numRows) {
- this(convertToVector(columnNames), numRows);
- } // DefaultTableModel()
-
- /**
- * Constructor DefaultTableModel
- * @param value0 TODO
- * @param value1 TODO
- */
- public DefaultTableModel(Vector data, Vector columnNames) {
- setDataVector(data, columnNames);
- } // DefaultTableModel()
-
- /**
- * Constructor DefaultTableModel
- * @param value0 TODO
- * @param value1 TODO
- */
- public DefaultTableModel(Object[][] data, Object[] columnNames) {
- this(convertToVector(data), convertToVector(columnNames));
- } // DefaultTableModel()
-
-
- //-------------------------------------------------------------
- // Methods ----------------------------------------------------
- //-------------------------------------------------------------
-
- /**
- * getDataVector
- * @returns Vector
- */
- public Vector getDataVector() {
- return dataVector;
- } // getDataVector()
-
- /**
- * setDataVector
- * @param value0 TODO
- * @param value1 TODO
- */
- public void setDataVector(Vector data, Vector columnNames) {
-
- // Variables
- int rowIndex;
- int numRows;
- int numColumns;
- Vector columnVector;
-
- // Set Data
- dataVector = data;
- columnIdentifiers = columnNames;
-
- // Check Data
- numRows = data.size();
- numColumns = columnNames.size();
- for (rowIndex = 0; rowIndex < numRows; rowIndex++) {
- columnVector = (Vector) dataVector.get(rowIndex);
- columnVector.setSize(numColumns);
- } // for
-
- } // setDataVector()
-
- /**
- * setDataVector
- * @param value0 TODO
- * @param value1 TODO
- */
- public void setDataVector(Object[][] data, Object[] columnNames) {
- setDataVector(convertToVector(data), convertToVector(columnNames));
- } // setDataVector()
-
- /**
- * newDataAvailable
- * @param value0 TODO
- */
- public void newDataAvailable(TableModelEvent event) {
- fireTableChanged(event);
- } // newDataAvailable()
-
- /**
- * newRowsAdded
- * @param value0 TODO
- */
- public void newRowsAdded(TableModelEvent event) {
- // TODO
- } // newRowsAdded()
-
- /**
- * rowsRemoved
- * @param value0 TODO
- */
- public void rowsRemoved(TableModelEvent event) {
- fireTableChanged(event);
- } // rowsRemoved()
-
- /**
- * setColumnIdentifiers
- * @param value0 TODO
- */
- public void setColumnIdentifiers(Vector columnIdentifiers) {
- this.columnIdentifiers = columnIdentifiers;
- setColumnCount(columnIdentifiers.size());
- } // setColumnIdentifiers()
-
- /**
- * setColumnIdentifiers
- * @param value0 TODO
- */
- public void setColumnIdentifiers(Object[] columnIdentifiers) {
- setColumnIdentifiers(convertToVector(columnIdentifiers));
- } // setColumnIdentifiers()
-
- /**
- * setNumRows
- * @param value0 TODO
- */
- public void setNumRows(int numRows) {
- setRowCount(numRows);
- } // setNumRows()
-
- /**
- * setRowCount
- * @param value0 TODO
- */
- public void setRowCount(int rowCount) {
- // TODO
- } // setRowCount()
-
- /**
- * setColumnCount
- * @param value0 TODO
- */
- public void setColumnCount(int columnCount) {
- // TODO
- } // setColumnCount()
-
- /**
- * addColumn
- * @param value0 TODO
- */
- public void addColumn(Object columnName) {
- addColumn(columnName, new Vector(dataVector.size()));
- } // addColumn()
-
- /**
- * addColumn
- * @param value0 TODO
- * @param value1 TODO
- */
- public void addColumn(Object columnName, Vector columnData) {
- // TODO
- } // addColumn()
-
- /**
- * addColumn
- * @param value0 TODO
- * @param value1 TODO
- */
- public void addColumn(Object columnName, Object[] columnData) {
- // TODO
- } // addColumn()
-
- /**
- * addRow
- * @param value0 TODO
- */
- public void addRow(Vector rowData) {
- // TODO
- } // addRow()
-
- /**
- * addRow
- * @param value0 TODO
- */
- public void addRow(Object[] rowData) {
- addRow(convertToVector(rowData));
- } // addRow()
-
- /**
- * insertRow
- * @param value0 TODO
- * @param value1 TODO
- */
- public void insertRow(int row, Vector rowData) {
- dataVector.add(row, rowData);
- } // insertRow()
-
- /**
- * insertRow
- * @param value0 TODO
- * @param value1 TODO
- */
- public void insertRow(int row, Object[] rowData) {
- insertRow(row, convertToVector(rowData));
- } // insertRow()
-
- /**
- * moveRow
- * @param value0 TODO
- * @param value1 TODO
- * @param value2 TODO
- */
- public void moveRow(int startIndex, int endIndex, int toIndex) {
-
- // Variables
- int index;
- Vector vector;
-
- // Move Rows
- for (index = 0; index < (endIndex - startIndex); index++) {
- vector = (Vector) dataVector.remove(startIndex);
- dataVector.add(toIndex, vector);
- } // for
-
- } // moveRow()
-
- /**
- * removeRow
- * @param value0 TODO
- */
- public void removeRow(int row) {
- dataVector.remove(row);
- } // removeRow()
-
- /**
- * getRowCount
- * @returns int
- */
- public int getRowCount() {
- return dataVector.size();
- } // getRowCount()
-
- /**
- * getColumnCount
- * @returns int
- */
- public int getColumnCount() {
- return columnIdentifiers.size();
- } // getColumnCount()
-
- /**
- * getColumnName
- * @param value0 TODO
- * @returns String
- */
- public String getColumnName(int column) {
-
- // Check for Column
- if (columnIdentifiers == null || column >= getColumnCount()) {
- return super.getColumnName(column);
- } // if
-
- // Return Column name
- return (String) columnIdentifiers.get(column);
-
- } // getColumnName()
-
- /**
- * isCellEditable
- * @param value0 TODO
- * @param value1 TODO
- * @returns boolean
- */
- public boolean isCellEditable(int row, int column) {
- return true;
- } // isCellEditable()
-
- /**
- * getValueAt
- * @param value0 TODO
- * @param value1 TODO
- * @returns Object
- */
- public Object getValueAt(int row, int column) {
-
- // Variables
- Vector rowVector;
-
- // Get Row Vector
- rowVector = (Vector) dataVector.get(row);
-
- // Get Data
- return rowVector.get(column);
-
- } // getValueAt()
-
- /**
- * setValueAt
- * @param value0 TODO
- * @param value1 TODO
- * @param value2 TODO
- */
- public void setValueAt(Object value, int row, int column) {
-
- // Variables
- Vector rowVector;
-
- // Get Row Vector
- rowVector = (Vector) dataVector.get(row);
-
- // Set Data
- rowVector.remove(column);
- rowVector.add(column, value);
-
- } // setValueAt()
-
- /**
- * convertToVector
- * @param value0 TODO
- * @returns Vector
- */
- protected static Vector convertToVector(Object[] data) {
-
- // Variables
- int index;
- Vector vector;
-
- // Check for null
- if (data == null) {
- return null;
- } // if
-
- // Process
- vector = new Vector();
- for (index = 0; index < data.length; index++) {
- vector.add(data[index]);
- } // for: index
-
- // Return new Vector
- return vector;
-
- } // convertToVector()
-
- /**
- * convertToVector
- * @param value0 TODO
- * @returns Vector
- */
- protected static Vector convertToVector(Object[][] data) {
-
- // Variables
- int index;
- Vector vector;
-
- // Process
- vector = new Vector();
- for (index = 0; index < data.length; index++) {
- vector.add(convertToVector(data[index]));
- } // for: index
-
- // Return new Vector
- return vector;
-
- } // convertToVector()
-
-
-} // DefaultTableModel
+ /**
+ * dataVector
+ */
+ protected Vector dataVector;
+
+ /**
+ * columnIdentifiers
+ */
+ protected Vector columnIdentifiers;
+
+ /**
+ * Constructor DefaultTableModel
+ */
+ public DefaultTableModel()
+ {
+ this(0, 0);
+ }
+
+ /**
+ * Constructor DefaultTableModel
+ * @param value0 TODO
+ * @param value1 TODO
+ */
+ public DefaultTableModel(int numRows, int numColumns)
+ {
+ Vector defaultNames = new Vector(numColumns);
+ Vector data = new Vector(numRows);
+ for (int i = 0; i < numColumns; i++)
+ {
+ defaultNames.add(super.getColumnName(i));
+ Vector tmp = new Vector(numColumns);
+ tmp.setSize(numColumns);
+ data.add(tmp);
+ }
+ setDataVector(defaultNames, data);
+ }
+
+ /**
+ * Constructor DefaultTableModel
+ * @param value0 TODO
+ * @param value1 TODO
+ */
+ public DefaultTableModel(Vector columnNames, int numRows)
+ {
+ Vector data = new Vector();
+ int numColumns = 0;
+
+ if (columnNames != null)
+ numColumns = columnNames.size();
+
+ while (0 < numRows--)
+ {
+ Vector rowData = new Vector();
+ rowData.setSize(numColumns);
+ data.add(rowData);
+ }
+ setDataVector(data, columnNames);
+ }
+
+ /**
+ * Constructor DefaultTableModel
+ * @param value0 TODO
+ * @param value1 TODO
+ */
+ public DefaultTableModel(Object[] columnNames, int numRows)
+ {
+ this(convertToVector(columnNames), numRows);
+ }
+
+ /**
+ * Constructor DefaultTableModel
+ * @param value0 TODO
+ * @param value1 TODO
+ */
+ public DefaultTableModel(Vector data, Vector columnNames)
+ {
+ setDataVector(data, columnNames);
+ }
+
+ /**
+ * Constructor DefaultTableModel
+ * @param value0 TODO
+ * @param value1 TODO
+ */
+ public DefaultTableModel(Object[][] data, Object[] columnNames)
+ {
+ this(convertToVector(data), convertToVector(columnNames));
+ }
+
+ /**
+ * getDataVector
+ * @returns Vector
+ */
+ public Vector getDataVector()
+ {
+ return dataVector;
+ }
+
+ /**
+ * setDataVector
+ * @param value0 TODO
+ * @param value1 TODO
+ */
+ public void setDataVector(Vector data, Vector columnNames)
+ {
+ dataVector = data;
+ columnIdentifiers = columnNames;
+ for (int r = 0; r < data.size(); r++) {
+ ((Vector) dataVector.get(r)).setSize(columnNames.size());
+ }
+ }
+
+ /**
+ * setDataVector
+ * @param value0 TODO
+ * @param value1 TODO
+ */
+ public void setDataVector(Object[][] data, Object[] columnNames)
+ {
+ setDataVector(convertToVector(data),
+ convertToVector(columnNames));
+ }
+
+ /**
+ * newDataAvailable
+ * @param value0 TODO
+ */
+ public void newDataAvailable(TableModelEvent event)
+ {
+ fireTableChanged(event);
+ }
+
+ /**
+ * newRowsAdded
+ * @param value0 TODO
+ */
+ public void newRowsAdded(TableModelEvent event)
+ {
+ fireTableChanged(event);
+ }
+
+ /**
+ * rowsRemoved
+ * @param value0 TODO
+ */
+ public void rowsRemoved(TableModelEvent event)
+ {
+ fireTableChanged(event);
+ }
+
+ /**
+ * setColumnIdentifiers
+ * @param value0 TODO
+ */
+ public void setColumnIdentifiers(Vector columnIdentifiers)
+ {
+ this.columnIdentifiers = columnIdentifiers;
+ setColumnCount(columnIdentifiers.size());
+ }
+
+ /**
+ * setColumnIdentifiers
+ * @param value0 TODO
+ */
+ public void setColumnIdentifiers(Object[] columnIdentifiers)
+ {
+ setColumnIdentifiers(convertToVector(columnIdentifiers));
+ }
+
+ /**
+ * setNumRows
+ * @param value0 TODO
+ */
+ public void setNumRows(int numRows)
+ {
+ setRowCount(numRows);
+ }
+
+ /**
+ * setRowCount
+ * @param value0 TODO
+ */
+ public void setRowCount(int rowCount)
+ {
+ dataVector.setSize(rowCount);
+ fireTableDataChanged();
+ }
+
+ /**
+ * setColumnCount
+ * @param value0 TODO
+ */
+ public void setColumnCount(int columnCount)
+ {
+ for (int i = 0; i < dataVector.size(); ++i)
+ {
+ ((Vector) dataVector.get(i)).setSize(columnCount);
+ }
+ columnIdentifiers.setSize(columnCount);
+ fireTableDataChanged();
+ }
+
+ /**
+ * addColumn
+ * @param value0 TODO
+ */
+ public void addColumn(Object columnName)
+ {
+ addColumn(columnName, (Object[]) null);
+ }
+
+ /**
+ * addColumn
+ * @param value0 TODO
+ * @param value1 TODO
+ */
+ public void addColumn(Object columnName, Vector columnData)
+ {
+ addColumn(columnName, columnData == null ? null : columnData.toArray());
+ }
+
+ /**
+ * addColumn
+ * @param value0 TODO
+ * @param value1 TODO
+ */
+ public void addColumn(Object columnName, Object[] columnData) {
+ for (int i = 0; i < dataVector.size(); ++i)
+ {
+ ((Vector) dataVector.get(i)).add(columnData == null ? null : columnData[i]);
+ }
+ columnIdentifiers.add(columnName);
+ fireTableDataChanged();
+ }
+
+ /**
+ * addRow
+ * @param value0 TODO
+ */
+ public void addRow(Vector rowData) {
+ dataVector.add(rowData);
+ fireTableDataChanged();
+ }
+
+ /**
+ * addRow
+ * @param value0 TODO
+ */
+ public void addRow(Object[] rowData) {
+ addRow(convertToVector(rowData));
+ }
+
+ /**
+ * insertRow
+ * @param value0 TODO
+ * @param value1 TODO
+ */
+ public void insertRow(int row, Vector rowData) {
+ dataVector.add(row, rowData);
+ fireTableDataChanged();
+ }
+
+ /**
+ * insertRow
+ * @param value0 TODO
+ * @param value1 TODO
+ */
+ public void insertRow(int row, Object[] rowData) {
+ insertRow(row, convertToVector(rowData));
+ }
+
+ /**
+ * moveRow
+ * @param value0 TODO
+ * @param value1 TODO
+ * @param value2 TODO
+ */
+ public void moveRow(int startIndex, int endIndex, int toIndex) {
+ for (int index = 0; index < (endIndex - startIndex); index++) {
+ Vector vector = (Vector) dataVector.remove(startIndex);
+ dataVector.add(toIndex, vector);
+ }
+ fireTableDataChanged();
+ }
+
+ /**
+ * removeRow
+ * @param value0 TODO
+ */
+ public void removeRow(int row) {
+ dataVector.remove(row);
+ fireTableDataChanged();
+ }
+
+ /**
+ * getRowCount
+ * @returns int
+ */
+ public int getRowCount() {
+ return dataVector.size();
+ }
+
+ /**
+ * getColumnCount
+ * @returns int
+ */
+ public int getColumnCount() {
+ return columnIdentifiers.size();
+ }
+
+ /**
+ * getColumnName
+ * @param value0 TODO
+ * @returns String
+ */
+ public String getColumnName(int column) {
+ // Check for Column
+ if (columnIdentifiers == null || column >= getColumnCount()) {
+ return super.getColumnName(column);
+ }
+
+ // Return Column name
+ return (String) columnIdentifiers.get(column);
+ }
+
+ /**
+ * isCellEditable
+ * @param value0 TODO
+ * @param value1 TODO
+ * @returns boolean
+ */
+ public boolean isCellEditable(int row, int column) {
+ return true;
+ }
+
+ /**
+ * getValueAt
+ * @param value0 TODO
+ * @param value1 TODO
+ * @returns Object
+ */
+ public Object getValueAt(int row, int column) {
+ return ((Vector) dataVector.get(row)).get(column);
+ }
+
+ /**
+ * setValueAt
+ * @param value0 TODO
+ * @param value1 TODO
+ * @param value2 TODO
+ */
+ public void setValueAt(Object value, int row, int column) {
+ ((Vector) dataVector.get(row)).set(column, value);
+ fireTableDataChanged();
+ }
+
+ /**
+ * convertToVector
+ * @param value0 TODO
+ * @returns Vector
+ */
+ protected static Vector convertToVector(Object[] data) {
+ if (data == null)
+ return null;
+ Vector vector = new Vector(data.length);
+ for (int i = 0; i < data.length; i++)
+ vector.add(data[i]);
+ return vector;
+ }
+
+ /**
+ * convertToVector
+ * @param value0 TODO
+ * @returns Vector
+ */
+ protected static Vector convertToVector(Object[][] data) {
+ if (data == null)
+ return null;
+ Vector vector = new Vector(data.length);
+ for (int i = 0; i < data.length; i++)
+ vector.add(convertToVector(data[i]));
+ return vector;
+ }
+}
diff --git a/libjava/javax/swing/table/JTableHeader.java b/libjava/javax/swing/table/JTableHeader.java
index 6b48601..9e55647 100644
--- a/libjava/javax/swing/table/JTableHeader.java
+++ b/libjava/javax/swing/table/JTableHeader.java
@@ -38,26 +38,536 @@ exception statement from your version. */
package javax.swing.table;
+import java.awt.event.FocusEvent;
+import java.awt.event.FocusListener;
+import java.awt.Color;
+import java.awt.Cursor;
+import java.awt.Dimension;
+import java.awt.Font;
+import java.awt.FontMetrics;
+import java.awt.Point;
+import java.awt.Rectangle;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.util.Locale;
+
+import javax.accessibility.Accessible;
+import javax.accessibility.AccessibleAction;
+import javax.accessibility.AccessibleComponent;
+import javax.accessibility.AccessibleContext;
+import javax.accessibility.AccessibleSelection;
+import javax.accessibility.AccessibleStateSet;
+import javax.accessibility.AccessibleRole;
+import javax.accessibility.AccessibleText;
+import javax.accessibility.AccessibleValue;
import javax.swing.JComponent;
import javax.swing.JTable;
+import javax.swing.UIManager;
+import javax.swing.plaf.TableHeaderUI;
public class JTableHeader extends JComponent
{
- protected class AccessibleJTableHeader
+ protected class AccessibleJTableHeader extends AccessibleJComponent
{
- protected class AccessibleJTableHeaderEntry
+ protected class AccessibleJTableHeaderEntry extends AccessibleContext
+ implements Accessible, AccessibleComponent
{
- }
+ public void addFocusListener(FocusListener l)
+ {
+ throw new Error("not implemented");
+ }
+ public void addPropertyChangeListener(PropertyChangeListener l)
+ {
+ throw new Error("not implemented");
+ }
+ public boolean contains(Point p)
+ {
+ throw new Error("not implemented");
+ }
+ public AccessibleAction getAccessibleAction()
+ {
+ throw new Error("not implemented");
+ }
+ public Accessible getAccessibleAt(Point p)
+ {
+ throw new Error("not implemented");
+ }
+ public Accessible getAccessibleChild(int i)
+ {
+ throw new Error("not implemented");
+ }
+ public int getAccessibleChildrenCount()
+ {
+ throw new Error("not implemented");
+ }
+ public AccessibleComponent getAccessibleComponent()
+ {
+ throw new Error("not implemented");
+ }
+ public AccessibleContext getAccessibleContext()
+ {
+ throw new Error("not implemented");
+ }
+ public String getAccessibleDescription()
+ {
+ throw new Error("not implemented");
+ }
+ public int getAccessibleIndexInParent()
+ {
+ throw new Error("not implemented");
+ }
+ public String getAccessibleName()
+ {
+ throw new Error("not implemented");
+ }
+ public AccessibleRole getAccessibleRole()
+ {
+ throw new Error("not implemented");
+ }
+ public AccessibleSelection getAccessibleSelection()
+ {
+ throw new Error("not implemented");
+ }
+ public AccessibleStateSet getAccessibleStateSet()
+ {
+ throw new Error("not implemented");
+ }
+ public AccessibleText getAccessibleText()
+ {
+ throw new Error("not implemented");
+ }
+ public AccessibleValue getAccessibleValue()
+ {
+ throw new Error("not implemented");
+ }
+ public Color getBackground()
+ {
+ throw new Error("not implemented");
+ }
+ public Rectangle getBounds()
+ {
+ throw new Error("not implemented");
+ }
+ public Cursor getCursor()
+ {
+ throw new Error("not implemented");
+ }
+ public Font getFont()
+ {
+ throw new Error("not implemented");
+ }
+ public FontMetrics getFontMetrics(Font f)
+ {
+ throw new Error("not implemented");
+ }
+ public Color getForeground()
+ {
+ throw new Error("not implemented");
+ }
+ public Locale getLocale()
+ {
+ throw new Error("not implemented");
+ }
+ public Point getLocation()
+ {
+ throw new Error("not implemented");
+ }
+ public Point getLocationOnScreen()
+ {
+ throw new Error("not implemented");
+ }
+ public Dimension getSize()
+ {
+ throw new Error("not implemented");
+ }
+ public boolean isEnabled()
+ {
+ throw new Error("not implemented");
+ }
+ public boolean isFocusTraversable()
+ {
+ throw new Error("not implemented");
+ }
+ public boolean isShowing()
+ {
+ throw new Error("not implemented");
+ }
+ public boolean isVisible()
+ {
+ throw new Error("not implemented");
+ }
+ public void removeFocusListener(FocusListener l)
+ {
+ throw new Error("not implemented");
+ }
+ public void removePropertyChangeListener(PropertyChangeListener l)
+ {
+ throw new Error("not implemented");
+ }
+ public void requestFocus()
+ {
+ throw new Error("not implemented");
+ }
+ public void setAccessibleDescription(String s)
+ {
+ throw new Error("not implemented");
+ }
+ public void setAccessibleName(String s)
+ {
+ throw new Error("not implemented");
+ }
+ public void setBackground(Color c)
+ {
+ throw new Error("not implemented");
+ }
+ public void setBounds(Rectangle r)
+ {
+ throw new Error("not implemented");
+ }
+ public void setCursor(Cursor c)
+ {
+ throw new Error("not implemented");
+ }
+ public void setEnabled(boolean b)
+ {
+ throw new Error("not implemented");
+ }
+ public void setFont(Font f)
+ {
+ throw new Error("not implemented");
+ }
+ public void setForeground(Color c)
+ {
+ throw new Error("not implemented");
+ }
+ public void setLocation(Point p)
+ {
+ throw new Error("not implemented");
+ }
+ public void setSize(Dimension d)
+ {
+ throw new Error("not implemented");
+ }
+ public void setVisible(boolean b)
+ {
+ throw new Error("not implemented");
+ }
+ };
}
private static final long serialVersionUID = 5144633983372967710L;
- protected TableColumnModel columnModel;
- protected TableColumn draggedColumn;
- protected int draggedDistance;
- protected boolean reorderingAllowed;
- protected boolean resizingAllowed;
- protected TableColumn resizingColumn;
- protected JTable table;
- protected boolean updateTableInRealTime;
+ /**
+ * The accessibleContext property.
+ */
+ AccessibleContext accessibleContext;
+
+ /**
+ * The columnModel property.
+ */
+ TableColumnModel columnModel;
+
+ /**
+ * The draggedColumn property.
+ */
+ TableColumn draggedColumn;
+
+ /**
+ * The draggedDistance property.
+ */
+ int draggedDistance;
+
+ /**
+ * The opaque property.
+ */
+ boolean opaque;
+
+ /**
+ * The reorderingAllowed property.
+ */
+ boolean reorderingAllowed;
+
+ /**
+ * The resizingAllowed property.
+ */
+ boolean resizingAllowed;
+
+ /**
+ * The resizingColumn property.
+ */
+ TableColumn resizingColumn;
+
+ /**
+ * The table property.
+ */
+ JTable table;
+
+ /**
+ * The updateTableInRealTime property.
+ */
+ boolean updateTableInRealTime;
+
+ TableCellRenderer cellRenderer;
+
+ public JTableHeader()
+ {
+ this(null);
+ }
+
+ public JTableHeader(TableColumnModel cm)
+ {
+ accessibleContext = new AccessibleJTableHeader();
+ columnModel = cm == null ? createDefaultTableColumnModel() : cm;
+ draggedColumn = null;
+ draggedDistance = 0;
+ opaque = true;
+ reorderingAllowed = true;
+ resizingAllowed = true;
+ resizingColumn = null;
+ table = null;
+ updateTableInRealTime = true;
+ cellRenderer = createDefaultRenderer();
+ updateUI();
+ }
+
+ protected TableColumnModel createDefaultTableColumnModel()
+ {
+ return new DefaultTableColumnModel();
+ }
+
+
+ /**
+ * Get the value of the {@link #accessibleContext} property.
+ *
+ * @return The current value of the property
+ */
+ public AccessibleContext getAccessibleContext()
+ {
+ return accessibleContext;
+ }
+
+ /**
+ * Get the value of the {@link #columnModel} property.
+ *
+ * @return The current value of the property
+ */
+ public TableColumnModel getColumnModel()
+ {
+ return columnModel;
+ }
+
+ /**
+ * Get the value of the {@link #draggedColumn} property.
+ *
+ * @return The current value of the property
+ */
+ public TableColumn getDraggedColumn()
+ {
+ return draggedColumn;
+ }
+
+ /**
+ * Get the value of the {@link #draggedDistance} property.
+ *
+ * @return The current value of the property
+ */
+ public int getDraggedDistance()
+ {
+ return draggedDistance;
+ }
+
+ /**
+ * Get the value of the {@link #reorderingAllowed} property.
+ *
+ * @return The current value of the property
+ */
+ public boolean getReorderingAllowed()
+ {
+ return reorderingAllowed;
+ }
+
+ /**
+ * Get the value of the {@link #resizingAllowed} property.
+ *
+ * @return The current value of the property
+ */
+ public boolean getResizingAllowed()
+ {
+ return resizingAllowed;
+ }
+
+ /**
+ * Get the value of the {@link #resizingColumn} property.
+ *
+ * @return The current value of the property
+ */
+ public TableColumn getResizingColumn()
+ {
+ return resizingColumn;
+ }
+
+ /**
+ * Get the value of the {@link #table} property.
+ *
+ * @return The current value of the property
+ */
+ public JTable getTable()
+ {
+ return table;
+ }
+
+ /**
+ * Get the value of the {@link #updateTableInRealTime} property.
+ *
+ * @return The current value of the property
+ */
+ public boolean getUpdateTableInRealTime()
+ {
+ return updateTableInRealTime;
+ }
+
+ /**
+ * Get the value of the {@link #opaque} property.
+ *
+ * @return The current value of the property
+ */
+ public boolean isOpaque()
+ {
+ return opaque;
+ }
+
+ /**
+ * Set the value of the {@link #columnModel} property.
+ *
+ * @param c The new value of the property
+ */
+ public void setColumnModel(TableColumnModel c)
+ {
+ columnModel = c;
+ }
+
+ /**
+ * Set the value of the {@link #draggedColumn} property.
+ *
+ * @param d The new value of the property
+ */
+ public void setDraggedColumn(TableColumn d)
+ {
+ draggedColumn = d;
+ }
+
+ /**
+ * Set the value of the {@link #draggedDistance} property.
+ *
+ * @param d The new value of the property
+ */
+ public void setDraggedDistance(int d)
+ {
+ draggedDistance = d;
+ }
+
+ /**
+ * Set the value of the {@link #opaque} property.
+ *
+ * @param o The new value of the property
+ */
+ public void setOpaque(boolean o)
+ {
+ opaque = o;
+ }
+
+ /**
+ * Set the value of the {@link #reorderingAllowed} property.
+ *
+ * @param r The new value of the property
+ */
+ public void setReorderingAllowed(boolean r)
+ {
+ reorderingAllowed = r;
+ }
+
+ /**
+ * Set the value of the {@link #resizingAllowed} property.
+ *
+ * @param r The new value of the property
+ */
+ public void setResizingAllowed(boolean r)
+ {
+ resizingAllowed = r;
+ }
+
+ /**
+ * Set the value of the {@link #resizingColumn} property.
+ *
+ * @param r The new value of the property
+ */
+ public void setResizingColumn(TableColumn r)
+ {
+ resizingColumn = r;
+ }
+
+ /**
+ * Set the value of the {@link #table} property.
+ *
+ * @param t The new value of the property
+ */
+ public void setTable(JTable t)
+ {
+ table = t;
+ }
+
+ /**
+ * Set the value of the {@link #updateTableInRealTime} property.
+ *
+ * @param u The new value of the property
+ */
+ public void setUpdateTableInRealTime(boolean u)
+ {
+ updateTableInRealTime = u;
+ }
+
+ protected TableCellRenderer createDefaultRenderer()
+ {
+ return new DefaultTableCellRenderer();
+ }
+
+ public TableCellRenderer getDefaultRenderer()
+ {
+ return cellRenderer;
+ }
+
+ public Rectangle getHeaderRect(int column)
+ {
+ Rectangle r = getTable().getCellRect(-1, column, true);
+ r.height = getHeight();
+ return r;
+ }
+
+ protected String paramString()
+ {
+ return "JTableHeader";
+ }
+
+ // UI support
+
+ public String getUIClassID()
+ {
+ return "TableHeaderUI";
+ }
+
+ public TableHeaderUI getUI()
+ {
+ return (TableHeaderUI) ui;
+ }
+
+ public void setUI(TableHeaderUI u)
+ {
+ super.setUI(u);
+ }
+
+ public void updateUI()
+ {
+ setUI((TableHeaderUI) UIManager.getUI(this));
+ }
+
}
diff --git a/libjava/javax/swing/table/TableColumn.java b/libjava/javax/swing/table/TableColumn.java
index 39ae1bd..02ef7f8 100644
--- a/libjava/javax/swing/table/TableColumn.java
+++ b/libjava/javax/swing/table/TableColumn.java
@@ -285,23 +285,19 @@ public class TableColumn
return headerValue;
}
- /**
- * setHeaderRenderer
- * @param headerRenderer TODO
- */
- public void setHeaderRenderer(TableCellRenderer headerRenderer)
+ /**
+ * setHeaderRenderer
+ * @param headerRenderer TODO
+ */
+ public void setHeaderRenderer(TableCellRenderer renderer)
{
- // Variables
- TableCellRenderer oldRenderer;
-
- // Get Old Renderer
- oldRenderer = this.headerRenderer;
-
- // Set Property
- this.headerRenderer = headerRenderer;
-
- // Notify Listeners of change
- firePropertyChange(HEADER_RENDERER_PROPERTY, oldRenderer, headerRenderer);
+ if (headerRenderer == renderer)
+ return;
+
+ TableCellRenderer oldRenderer = headerRenderer;
+ headerRenderer = renderer;
+ firePropertyChange(HEADER_RENDERER_PROPERTY,
+ oldRenderer, headerRenderer);
}
/**
@@ -313,23 +309,19 @@ public class TableColumn
return headerRenderer;
}
- /**
- * setCellRenderer
- * @param cellRenderer TODO
- */
- public void setCellRenderer(TableCellRenderer cellRenderer)
+ /**
+ * setCellRenderer
+ * @param cellRenderer TODO
+ */
+ public void setCellRenderer(TableCellRenderer renderer)
{
- // Variables
- TableCellRenderer oldRenderer;
-
- // Get Old Renderer
- oldRenderer = this.cellRenderer;
-
- // Set Property
- this.cellRenderer = cellRenderer;
-
- // Notify Listeners of change
- firePropertyChange(CELL_RENDERER_PROPERTY, oldRenderer, cellRenderer);
+ if (cellRenderer == renderer)
+ return;
+
+ TableCellRenderer oldRenderer = cellRenderer;
+ cellRenderer = renderer;
+ firePropertyChange(CELL_RENDERER_PROPERTY,
+ oldRenderer, cellRenderer);
}
/**
@@ -359,27 +351,25 @@ public class TableColumn
return cellEditor;
}
- /**
- * setWidth
- * @param width TODO
- */
- public void setWidth(int width)
+ /**
+ * setWidth
+ * @param newWidth TODO
+ */
+ public void setWidth(int newWidth)
{
- // Variables
- int oldWidth;
+ int oldWidth = width;
- // Get Old Width
- oldWidth = this.width;
-
- // Adjust Width within Limits
- if (width < minWidth)
- this.width = minWidth;
- else if (width > maxWidth)
- this.width = maxWidth;
+ if (newWidth < minWidth)
+ width = minWidth;
+ else if (newWidth > maxWidth)
+ width = maxWidth;
else
- this.width = width;
+ width = newWidth;
+
+ if (width == oldWidth)
+ return;
- firePropertyChange(COLUMN_WIDTH_PROPERTY, oldWidth, this.width);
+ firePropertyChange(COLUMN_WIDTH_PROPERTY, oldWidth, width);
}
/**
diff --git a/libjava/javax/swing/text/AbstractDocument.java b/libjava/javax/swing/text/AbstractDocument.java
index c1ea098..a7c8c90 100644
--- a/libjava/javax/swing/text/AbstractDocument.java
+++ b/libjava/javax/swing/text/AbstractDocument.java
@@ -38,6 +38,7 @@ exception statement from your version. */
package javax.swing.text;
import java.io.Serializable;
+import java.util.Collections;
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.EventListener;
@@ -63,33 +64,37 @@ public abstract class AbstractDocument
public static final String ParagraphElementName = "paragraph";
public static final String SectionElementName = "section";
public static final String ElementNameAttribute = "$ename";
+
Content content;
+ AttributeContext context;
protected EventListenerList listenerList = new EventListenerList();
protected AbstractDocument(Content doc)
{
- this(doc, null);
+ this(doc, StyleContext.getDefaultStyleContext());
}
- protected AbstractDocument(Content doc, AttributeContext context)
+ protected AbstractDocument(Content doc, AttributeContext ctx)
{
content = doc;
+ context = ctx;
}
- // these still need to be implemented by a derived class:
+ // These still need to be implemented by a derived class:
public abstract Element getParagraphElement(int pos);
public abstract Element getDefaultRootElement();
- protected Element createBranchElement(Element parent, AttributeSet a)
+ protected Element createBranchElement(Element parent,
+ AttributeSet attributes)
{
- return new BranchElement(parent, a, 0, 0);
+ return new BranchElement(parent, attributes);
}
- protected Element createLeafElement(Element parent, AttributeSet a, int p0,
- int p1)
+ protected Element createLeafElement(Element parent, AttributeSet attributes,
+ int start, int end)
{
- return new LeafElement(parent, a, p0, p1 - p0);
+ return new LeafElement(parent, attributes, start, end);
}
public Position createPosition(final int offset) throws BadLocationException
@@ -145,7 +150,7 @@ public abstract class AbstractDocument
protected AttributeContext getAttributeContext()
{
- return null;
+ return context;
}
public Element getBidiRootElement()
@@ -170,7 +175,13 @@ public abstract class AbstractDocument
public Position getEndPosition()
{
- return null;
+ return new Position()
+ {
+ public int getOffset()
+ {
+ return getLength();
+ }
+ };
}
public int getLength()
@@ -190,12 +201,20 @@ public abstract class AbstractDocument
public Element[] getRootElements()
{
- return null;
+ Element[] elements = new Element[1];
+ elements[0] = getDefaultRootElement();
+ return elements;
}
public Position getStartPosition()
{
- return null;
+ return new Position()
+ {
+ public int getOffset()
+ {
+ return 0;
+ }
+ };
}
public String getText(int offset, int length) throws BadLocationException
@@ -203,34 +222,25 @@ public abstract class AbstractDocument
return content.getString(offset, length);
}
- public void getText(int offset, int length, Segment txt)
+ public void getText(int offset, int length, Segment segment)
throws BadLocationException
{
- String a = getText(offset, length);
-
- if (a == null)
- {
- txt.offset = 0;
- txt.count = 0;
- txt.array = new char[0];
-
- return;
- }
-
- txt.offset = offset;
- txt.count = length;
-
- char[] chars = new char[a.length()];
-
- a.getChars(0, a.length(), chars, 0);
-
- txt.array = chars;
+ content.getChars(offset, length, segment);
}
- public void insertString(int offs, String str, AttributeSet a)
+ public void insertString(int offset, String text, AttributeSet attributes)
throws BadLocationException
{
- content.insertString(offs, str);
+ // Just return when no text to insert was given.
+ if (text == null || text.length() == 0)
+ return;
+
+ DefaultDocumentEvent event =
+ new DefaultDocumentEvent(offset, text.length(),
+ DocumentEvent.EventType.INSERT);
+ content.insertString(offset, text);
+ insertUpdate(event, attributes);
+ fireInsertUpdate(event);
}
protected void insertUpdate(DefaultDocumentEvent chng, AttributeSet attr)
@@ -255,6 +265,26 @@ public abstract class AbstractDocument
public void remove(int offset, int length) throws BadLocationException
{
+ DefaultDocumentEvent event =
+ new DefaultDocumentEvent(offset, length,
+ DocumentEvent.EventType.REMOVE);
+ removeUpdate(event);
+ content.remove(offset, length);
+ postRemoveUpdate(event);
+ fireRemoveUpdate(event);
+ }
+
+ /**
+ * Replaces some text in the document.
+ *
+ * @since 1.4
+ */
+ public void replace(int offset, int length, String text,
+ AttributeSet attributes)
+ throws BadLocationException
+ {
+ remove(offset, length);
+ insertString(offset, text, attributes);
}
/**
@@ -375,47 +405,51 @@ public abstract class AbstractDocument
}
public abstract class AbstractElement
- implements Element, TreeNode, Serializable
+ implements Element, MutableAttributeSet, TreeNode, Serializable
{
private static final long serialVersionUID = 1265312733007397733L;
int count;
int offset;
- AttributeSet attr;
- Vector elts = new Vector();
- String name;
- Element parent;
- Vector kids = new Vector();
+
+ AttributeSet attributes;
+
+ Element element_parent;
+ Vector element_children;
+
TreeNode tree_parent;
+ Vector tree_children;
public AbstractElement(Element p, AttributeSet s)
{
- parent = p;
- attr = s;
+ element_parent = p;
+ attributes = s;
}
+ // TreeNode implementation
+
public Enumeration children()
{
- return kids.elements();
+ return Collections.enumeration(tree_children);
}
-
+
public boolean getAllowsChildren()
{
return true;
}
-
+
public TreeNode getChildAt(int index)
{
- return (TreeNode) kids.elementAt(index);
+ return (TreeNode) tree_children.get(index);
}
-
+
public int getChildCount()
{
- return kids.size();
+ return tree_children.size();
}
-
+
public int getIndex(TreeNode node)
{
- return kids.indexOf(node);
+ return tree_children.indexOf(node);
}
public TreeNode getParent()
@@ -423,55 +457,134 @@ public abstract class AbstractDocument
return tree_parent;
}
+ public abstract boolean isLeaf();
+
+
+ // MutableAttributeSet support
+
+ public void addAttribute(Object name, Object value)
+ {
+ attributes = getAttributeContext().addAttribute(attributes, name, value);
+ }
+
+ public void addAttributes(AttributeSet attrs)
+ {
+ attributes = getAttributeContext().addAttributes(attributes, attrs);
+ }
+
+ public void removeAttribute(Object name)
+ {
+ attributes = getAttributeContext().removeAttribute(attributes, name);
+ }
+
+ public void removeAttributes(AttributeSet attrs)
+ {
+ attributes = getAttributeContext().removeAttributes(attributes, attrs);
+ }
+
+ public void removeAttributes(Enumeration names)
+ {
+ attributes = getAttributeContext().removeAttributes(attributes, names);
+ }
+
+ public void setResolveParent(AttributeSet parent)
+ {
+ attributes = getAttributeContext().addAttribute(attributes, ResolveAttribute, parent);
+ }
+
+
+ // AttributeSet interface support
+
+ public boolean containsAttribute(Object name, Object value)
+ {
+ return attributes.containsAttribute(name, value);
+ }
+
+ public boolean containsAttributes(AttributeSet attrs)
+ {
+ return attributes.containsAttributes(attrs);
+ }
+
+ public AttributeSet copyAttributes()
+ {
+ return attributes.copyAttributes();
+ }
+
+ public Object getAttribute(Object key)
+ {
+ return attributes.getAttribute(key);
+ }
+
+ public int getAttributeCount()
+ {
+ return attributes.getAttributeCount();
+ }
+
+ public Enumeration getAttributeNames()
+ {
+ return attributes.getAttributeNames();
+ }
+
+ public AttributeSet getResolveParent()
+ {
+ return attributes.getResolveParent();
+ }
+
+ public boolean isDefined(Object attrName)
+ {
+ return attributes.isDefined(attrName);
+ }
+
+ public boolean isEqual(AttributeSet attrs)
+ {
+ return attributes.isEqual(attrs);
+ }
+
+ // Element interface support
+
public AttributeSet getAttributes()
{
- return attr;
+ return attributes;
}
public Document getDocument()
{
return AbstractDocument.this;
}
-
+
public Element getElement(int index)
{
- return (Element) elts.elementAt(index);
+ return (Element) element_children.get(index);
}
-
+
public String getName()
{
- return name;
+ return (String) getAttribute(NameAttribute);
}
-
+
public Element getParentElement()
{
- return parent;
+ return element_parent;
}
-
- public abstract boolean isLeaf();
-
+
public abstract int getEndOffset();
-
+
public abstract int getElementCount();
-
+
public abstract int getElementIndex(int offset);
-
+
public abstract int getStartOffset();
}
public class BranchElement extends AbstractElement
{
private static final long serialVersionUID = -8595176318868717313L;
- private int start;
- private int end;
+
private Vector children = new Vector();
- public BranchElement(Element parent, AttributeSet attributes, int start,
- int end)
+ public BranchElement(Element parent, AttributeSet attributes)
{
super(parent, attributes);
- this.start = start;
- this.end = end;
}
public Enumeration children()
@@ -486,6 +599,9 @@ public abstract class AbstractDocument
public Element getElement(int index)
{
+ if (index < 0 || index >= children.size())
+ return null;
+
return (Element) children.get(index);
}
@@ -496,12 +612,20 @@ public abstract class AbstractDocument
public int getElementIndex(int offset)
{
- return children.indexOf(positionToElement(offset));
+ if (children.size() == 0)
+ return 0;
+
+ Element element = positionToElement(offset);
+
+ if (element == null)
+ return 0;
+
+ return children.indexOf(element);
}
public int getEndOffset()
{
- return end;
+ return ((Element) children.lastElement()).getEndOffset();
}
public String getName()
@@ -511,7 +635,7 @@ public abstract class AbstractDocument
public int getStartOffset()
{
- return start;
+ return ((Element) children.firstElement()).getStartOffset();
}
public boolean isLeaf()
@@ -554,8 +678,18 @@ public abstract class AbstractDocument
implements DocumentEvent
{
private static final long serialVersionUID = -7406103236022413522L;
- public int len;
- public int off;
+
+ private int offset;
+ private int length;
+ private DocumentEvent.EventType type;
+
+ public DefaultDocumentEvent(int offset, int length,
+ DocumentEvent.EventType type)
+ {
+ this.offset = offset;
+ this.length = length;
+ this.type = type;
+ }
public Document getDocument()
{
@@ -564,17 +698,17 @@ public abstract class AbstractDocument
public int getLength()
{
- return len;
+ return length;
}
public int getOffset()
{
- return off;
+ return offset;
}
public DocumentEvent.EventType getType()
{
- return null;
+ return type;
}
public DocumentEvent.ElementChange getChange(Element elem)
@@ -584,8 +718,43 @@ public abstract class AbstractDocument
}
public static class ElementEdit extends AbstractUndoableEdit
+ implements DocumentEvent.ElementChange
{
private static final long serialVersionUID = -1216620962142928304L;
+
+ private Element elem;
+ private int index;
+ private Element[] removed;
+ private Element[] added;
+
+ public ElementEdit(Element elem, int index,
+ Element[] removed, Element[] added)
+ {
+ this.elem = elem;
+ this.index = index;
+ this.removed = removed;
+ this.added = added;
+ }
+
+ public Element[] getChildrenAdded()
+ {
+ return added;
+ }
+
+ public Element[] getChildrenRemoved()
+ {
+ return removed;
+ }
+
+ public Element getElement()
+ {
+ return elem;
+ }
+
+ public int getIndex()
+ {
+ return index;
+ }
}
public class LeafElement extends AbstractElement
diff --git a/libjava/javax/swing/text/AttributeSet.java b/libjava/javax/swing/text/AttributeSet.java
index 3c31767..3f38a4c 100644
--- a/libjava/javax/swing/text/AttributeSet.java
+++ b/libjava/javax/swing/text/AttributeSet.java
@@ -56,14 +56,17 @@ public interface AttributeSet
static interface ParagraphAttribute
{
}
-
- boolean containsAttribute(Object name, Object value);
- boolean containsAttributes(AttributeSet attributes);
- AttributeSet copyAttributes();
- Object getAttribute(Object key);
- int getAttributeCount();
- Enumeration getAttributeNames();
- AttributeSet getResolveParent();
- boolean isDefined(Object attrName);
- boolean isEqual(AttributeSet attr);
+
+ static Object NameAttribute = StyleConstants.NameAttribute;
+ static Object ResolveAttribute = StyleConstants.ResolveAttribute;
+
+ boolean containsAttribute(Object name, Object value);
+ boolean containsAttributes(AttributeSet attributes);
+ AttributeSet copyAttributes();
+ Object getAttribute(Object key);
+ int getAttributeCount();
+ Enumeration getAttributeNames();
+ AttributeSet getResolveParent();
+ boolean isDefined(Object attrName);
+ boolean isEqual(AttributeSet attr);
}
diff --git a/libjava/javax/swing/text/DefaultCaret.java b/libjava/javax/swing/text/DefaultCaret.java
index 968bf1f..516f072 100644
--- a/libjava/javax/swing/text/DefaultCaret.java
+++ b/libjava/javax/swing/text/DefaultCaret.java
@@ -61,15 +61,15 @@ public class DefaultCaret extends Rectangle
protected ChangeEvent changeEvent = new ChangeEvent(this);
protected EventListenerList listenerList = new EventListenerList();
- Color color = new Color(0, 0, 0);
- JTextComponent parent;
- Point magic = null;
- int mark = 0;
- boolean vis_sel = true;
- int blink = 500;
- int dot = 0;
- boolean vis = true;
-
+ private JTextComponent textComponent;
+
+ private boolean selectionVisible = true;
+ private int blinkRate = 0;
+ private int dot = 0;
+ private int mark = 0;
+ private Point magicCaretPosition = null;
+ private boolean visible = true;
+ private Object highlightEntry;
public void mouseDragged(MouseEvent event)
{
@@ -117,27 +117,29 @@ public class DefaultCaret extends Rectangle
public void deinstall(JTextComponent c)
{
- parent.removeFocusListener(this);
- parent.removeMouseListener(this);
- parent = null;
+ textComponent.removeFocusListener(this);
+ textComponent.removeMouseListener(this);
+ textComponent.removeMouseMotionListener(this);
+ textComponent = null;
}
public void install(JTextComponent c)
{
- parent.addFocusListener(this);
- parent.addMouseListener(this);
- parent = c;
+ textComponent = c;
+ textComponent.addFocusListener(this);
+ textComponent.addMouseListener(this);
+ textComponent.addMouseMotionListener(this);
repaint();
}
public void setMagicCaretPosition(Point p)
{
- magic = p;
+ magicCaretPosition = p;
}
public Point getMagicCaretPosition()
{
- return magic;
+ return magicCaretPosition;
}
public int getMark()
@@ -145,27 +147,92 @@ public class DefaultCaret extends Rectangle
return mark;
}
+ private void handleHighlight()
+ {
+ Highlighter highlighter = textComponent.getHighlighter();
+
+ if (highlighter == null)
+ return;
+
+ int p0 = Math.min(dot, mark);
+ int p1 = Math.max(dot, mark);
+
+ if (selectionVisible && p0 != p1)
+ {
+ try
+ {
+ if (highlightEntry == null)
+ highlightEntry = highlighter.addHighlight(p0, p1, getSelectionPainter());
+ else
+ highlighter.changeHighlight(highlightEntry, p0, p1);
+ }
+ catch (BadLocationException e)
+ {
+ // This should never happen.
+ throw new InternalError();
+ }
+ }
+ else
+ {
+ if (highlightEntry != null)
+ {
+ highlighter.removeHighlight(highlightEntry);
+ highlightEntry = null;
+ }
+ }
+ }
+
public void setSelectionVisible(boolean v)
{
- vis_sel = v;
+ if (selectionVisible == v)
+ return;
+
+ selectionVisible = v;
+ handleHighlight();
repaint();
}
public boolean isSelectionVisible()
{
- return vis_sel;
+ return selectionVisible;
}
protected final void repaint()
{
- if (parent != null)
- parent.repaint();
+ if (textComponent != null)
+ textComponent.repaint();
}
public void paint(Graphics g)
{
- g.setColor(color);
- g.drawLine(x, y, x, y + height);
+ if (textComponent == null)
+ return;
+
+ int dot = getDot();
+ Rectangle rect = null;
+
+ try
+ {
+ rect = textComponent.modelToView(dot);
+ }
+ catch (BadLocationException e)
+ {
+ // This should never happen as dot should be always valid.
+ return;
+ }
+
+ if (rect == null)
+ return;
+
+ // First we need to delete the old caret.
+ // FIXME: Implement deleting of old caret.
+
+ // Now draw the caret on the new position if visible.
+ if (visible)
+ {
+ g.setColor(textComponent.getCaretColor());
+ g.drawLine(rect.x, rect.y, rect.x, rect.y + rect.height);
+ }
}
public EventListener[] getListeners(Class listenerType)
@@ -198,17 +265,17 @@ public class DefaultCaret extends Rectangle
protected final JTextComponent getComponent()
{
- return parent;
+ return textComponent;
}
public int getBlinkRate()
{
- return blink;
+ return blinkRate;
}
public void setBlinkRate(int rate)
{
- blink = rate;
+ blinkRate = rate;
}
public int getDot()
@@ -218,23 +285,32 @@ public class DefaultCaret extends Rectangle
public void moveDot(int dot)
{
- setDot(dot);
+ this.dot = dot;
+ handleHighlight();
+ repaint();
}
public void setDot(int dot)
{
this.dot = dot;
+ this.mark = dot;
+ handleHighlight();
repaint();
}
public boolean isVisible()
{
- return vis;
+ return visible;
}
public void setVisible(boolean v)
{
- vis = v;
+ visible = v;
repaint();
}
+
+ protected Highlighter.HighlightPainter getSelectionPainter()
+ {
+ return DefaultHighlighter.DefaultPainter;
+ }
}
diff --git a/libjava/javax/swing/text/DefaultEditorKit.java b/libjava/javax/swing/text/DefaultEditorKit.java
index 8611de5..03d4ef3 100644
--- a/libjava/javax/swing/text/DefaultEditorKit.java
+++ b/libjava/javax/swing/text/DefaultEditorKit.java
@@ -37,6 +37,8 @@ exception statement from your version. */
package javax.swing.text;
+import java.awt.Toolkit;
+import java.awt.event.ActionEvent;
import java.io.InputStream;
import java.io.IOException;
import java.io.OutputStream;
@@ -48,7 +50,121 @@ import javax.swing.JEditorPane;
public class DefaultEditorKit extends EditorKit
{
+ public static class BeepAction
+ extends TextAction
+ {
+ public BeepAction()
+ {
+ super(beepAction);
+ }
+
+ public void actionPerformed(ActionEvent event)
+ {
+ Toolkit.getDefaultToolkit().beep();
+ }
+ }
+
+ public static class CopyAction
+ extends TextAction
+ {
+ public CopyAction()
+ {
+ super(copyAction);
+ }
+ public void actionPerformed(ActionEvent event)
+ {
+ }
+ }
+
+ public static class CutAction
+ extends TextAction
+ {
+ public CutAction()
+ {
+ super(cutAction);
+ }
+ public void actionPerformed(ActionEvent event)
+ {
+ }
+ }
+
+ public static class DefaultKeyTypedAction
+ extends TextAction
+ {
+ public DefaultKeyTypedAction()
+ {
+ super(defaultKeyTypedAction);
+ }
+ public void actionPerformed(ActionEvent event)
+ {
+ JTextComponent t = getTextComponent(event);
+ if (t != null)
+ {
+ try
+ {
+ t.getDocument().insertString(t.getCaret().getDot(), event.getActionCommand(), null);
+ t.getCaret().setDot(Math.min(t.getCaret().getDot() + 1,
+ t.getDocument().getEndPosition().getOffset()));
+ t.repaint();
+ }
+ catch (BadLocationException be)
+ {
+ // FIXME: we're not authorized to throw this.. swallow it?
+ }
+ }
+ }
+ }
+
+ public static class InsertBreakAction
+ extends TextAction
+ {
+ public InsertBreakAction()
+ {
+ super(insertBreakAction);
+ }
+ public void actionPerformed(ActionEvent event)
+ {
+ }
+ }
+
+ public static class InsertContentAction
+ extends TextAction
+ {
+ public InsertContentAction()
+ {
+ super(insertContentAction);
+ }
+ public void actionPerformed(ActionEvent event)
+ {
+ }
+ }
+
+ public static class InsertTabAction
+ extends TextAction
+ {
+ public InsertTabAction()
+ {
+ super(insertTabAction);
+ }
+ public void actionPerformed(ActionEvent event)
+ {
+ }
+ }
+
+ public static class PasteAction
+ extends TextAction
+ {
+ public PasteAction()
+ {
+ super(pasteAction);
+ }
+ public void actionPerformed(ActionEvent event)
+ {
+ }
+ }
+
private static final long serialVersionUID = 9017245433028523428L;
+
public static final String backwardAction = "caret-backward";
public static final String beepAction = "beep";
public static final String beginAction = "caret-begin";
@@ -104,6 +220,113 @@ public class DefaultEditorKit extends EditorKit
{
}
+ private static Action[] defaultActions =
+ new Action[] {
+ new BeepAction(),
+ new CopyAction(),
+ new CutAction(),
+ new DefaultKeyTypedAction(),
+ new InsertBreakAction(),
+ new InsertContentAction(),
+ new InsertTabAction(),
+ new PasteAction(),
+ new TextAction(deleteNextCharAction)
+ {
+ public void actionPerformed(ActionEvent event)
+ {
+ JTextComponent t = getTextComponent(event);
+ if (t != null)
+ {
+ try
+ {
+ int pos = t.getCaret().getDot();
+ if (pos < t.getDocument().getEndPosition().getOffset())
+ {
+ t.getDocument().remove(t.getCaret().getDot(), 1);
+ t.repaint();
+ }
+ }
+ catch (BadLocationException e)
+ {
+ // FIXME: we're not authorized to throw this.. swallow it?
+ }
+ }
+ }
+ },
+ new TextAction(deletePrevCharAction)
+ {
+ public void actionPerformed(ActionEvent event)
+ {
+ JTextComponent t = getTextComponent(event);
+ if (t != null)
+ {
+ try
+ {
+ int pos = t.getCaret().getDot();
+ if (pos > t.getDocument().getStartPosition().getOffset())
+ {
+ t.getDocument().remove(pos - 1, 1);
+ t.getCaret().setDot(pos - 1);
+ t.repaint();
+ }
+ }
+ catch (BadLocationException e)
+ {
+ // FIXME: we're not authorized to throw this.. swallow it?
+ }
+ }
+ }
+ },
+ new TextAction(backwardAction)
+ {
+ public void actionPerformed(ActionEvent event)
+ {
+ JTextComponent t = getTextComponent(event);
+ if (t != null)
+ {
+ t.getCaret().setDot(Math.max(t.getCaret().getDot() - 1,
+ t.getDocument().getStartPosition().getOffset()));
+ }
+ }
+ },
+ new TextAction(forwardAction)
+ {
+ public void actionPerformed(ActionEvent event)
+ {
+ JTextComponent t = getTextComponent(event);
+ if (t != null)
+ {
+ t.getCaret().setDot(Math.min(t.getCaret().getDot() + 1,
+ t.getDocument().getEndPosition().getOffset()));
+ }
+ }
+ },
+ new TextAction(selectionBackwardAction)
+ {
+ public void actionPerformed(ActionEvent event)
+ {
+ JTextComponent t = getTextComponent(event);
+ if (t != null)
+ {
+ t.getCaret().moveDot(Math.max(t.getCaret().getDot() - 1,
+ t.getDocument().getStartPosition().getOffset()));
+ }
+ }
+ },
+ new TextAction(selectionForwardAction)
+ {
+ public void actionPerformed(ActionEvent event)
+ {
+ JTextComponent t = getTextComponent(event);
+ if (t != null)
+ {
+ t.getCaret().moveDot(Math.min(t.getCaret().getDot() + 1,
+ t.getDocument().getEndPosition().getOffset()));
+ }
+ }
+ },
+ };
+
/**
* Called when the kit is being removed from the JEditorPane.
*/
@@ -116,19 +339,19 @@ public class DefaultEditorKit extends EditorKit
}
public Caret createCaret()
- {
- return null;
- }
+ {
+ return new DefaultCaret();
+ }
public Document createDefaultDocument()
- {
- return new PlainDocument();
- }
-
+ {
+ return new PlainDocument();
+ }
+
public Action[] getActions()
- {
- return null;
- }
+ {
+ return defaultActions;
+ }
public String getContentType()
{
diff --git a/libjava/javax/swing/text/DefaultHighlighter.java b/libjava/javax/swing/text/DefaultHighlighter.java
index 003d17d..234fcad 100644
--- a/libjava/javax/swing/text/DefaultHighlighter.java
+++ b/libjava/javax/swing/text/DefaultHighlighter.java
@@ -38,7 +38,9 @@ exception statement from your version. */
package javax.swing.text;
+import java.awt.Color;
import java.awt.Graphics;
+import java.awt.Rectangle;
import java.awt.Shape;
import java.util.Vector;
@@ -48,6 +50,87 @@ import javax.swing.text.View;
public class DefaultHighlighter extends LayeredHighlighter
{
+ public static class DefaultHighlightPainter
+ extends LayerPainter
+ {
+ private Color color;
+
+ public DefaultHighlightPainter(Color c)
+ {
+ super();
+ color = c;
+ }
+
+ public Color getColor()
+ {
+ return color;
+ }
+
+ private void paintHighlight(Graphics g, Rectangle rect)
+ {
+ g.fillRect(rect.x, rect.y, rect.width, rect.height);
+ }
+
+ public void paint(Graphics g, int p0, int p1, Shape bounds,
+ JTextComponent c)
+ {
+ Rectangle r0 = null;
+ Rectangle r1 = null;
+ Rectangle rect = bounds.getBounds();
+
+ try
+ {
+ r0 = c.modelToView(p0);
+ r1 = c.modelToView(p1);
+ }
+ catch (BadLocationException e)
+ {
+ // This should never occur.
+ return;
+ }
+
+ if (r0 == null || r1 == null)
+ return;
+
+ if (color == null)
+ g.setColor(c.getSelectionColor());
+ else
+ g.setColor(color);
+
+ // Check if only one line to highlight.
+ if (r0.y == r1.y)
+ {
+ r0.width = r1.x - r0.x;
+ paintHighlight(g, r0);
+ return;
+ }
+
+ // First line, from p0 to end-of-line.
+ r0.width = rect.x + rect.width - r0.x;
+ paintHighlight(g, r0);
+
+ // FIXME: All the full lines in between, if any (assumes that all lines
+ // have the same height -- not a good assumption with JEditorPane/JTextPane).
+ r0.y += r0.height;
+ r0.x = rect.x;
+
+ while (r0.y < r1.y)
+ {
+ paintHighlight(g, r0);
+ r0.y += r0.height;
+ }
+
+ // Last line, from beginnin-of-line to p1.
+ paintHighlight(g, r1);
+ }
+
+ public Shape paintLayer(Graphics g, int p0, int p1, Shape bounds,
+ JTextComponent c, View view)
+ {
+ throw new InternalError();
+ }
+ }
+
private class HighlightEntry
{
int p0;
@@ -77,6 +160,12 @@ public class DefaultHighlighter extends LayeredHighlighter
}
}
+ /**
+ * @specnote final as of 1.4
+ */
+ public static final LayeredHighlighter.LayerPainter DefaultPainter =
+ new DefaultHighlightPainter(null);
+
private JTextComponent textComponent;
private Vector highlights = new Vector();
@@ -146,5 +235,16 @@ public class DefaultHighlighter extends LayeredHighlighter
public void paint(Graphics g)
{
+ // Check if there are any highlights.
+ if (highlights.size() == 0)
+ return;
+
+ Shape bounds = textComponent.getBounds();
+
+ for (int index = 0; index < highlights.size(); ++index)
+ {
+ HighlightEntry entry = (HighlightEntry) highlights.get(index);
+ entry.painter.paint(g, entry.p0, entry.p1, bounds, textComponent);
+ }
}
}
diff --git a/libjava/javax/swing/text/FieldView.java b/libjava/javax/swing/text/FieldView.java
index 29a00ac..06514b7 100644
--- a/libjava/javax/swing/text/FieldView.java
+++ b/libjava/javax/swing/text/FieldView.java
@@ -90,8 +90,14 @@ public class FieldView extends PlainView
return axis = axis == X_AXIS ? 1 : 0;
}
+ public Shape modelToView(int pos, Shape a, Position.Bias bias)
+ throws BadLocationException
+ {
+ return super.modelToView(pos, a, bias);
+ }
+
public void paint(Graphics g, Shape s)
{
- drawLine(0, g, 0, 0);
+ super.paint(g, s);
}
}
diff --git a/libjava/javax/swing/text/JTextComponent.java b/libjava/javax/swing/text/JTextComponent.java
index e44c529..ea69f5d 100644
--- a/libjava/javax/swing/text/JTextComponent.java
+++ b/libjava/javax/swing/text/JTextComponent.java
@@ -46,13 +46,20 @@ import java.awt.Insets;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.InputMethodListener;
+import java.awt.event.KeyEvent;
+
+import java.util.Enumeration;
+import java.util.Hashtable;
import javax.accessibility.Accessible;
import javax.accessibility.AccessibleContext;
import javax.accessibility.AccessibleRole;
import javax.accessibility.AccessibleStateSet;
import javax.accessibility.AccessibleText;
+import javax.swing.Action;
+import javax.swing.ActionMap;
import javax.swing.Icon;
+import javax.swing.InputMap;
import javax.swing.JComponent;
import javax.swing.JViewport;
import javax.swing.KeyStroke;
@@ -62,6 +69,8 @@ import javax.swing.event.CaretEvent;
import javax.swing.event.CaretListener;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
+import javax.swing.plaf.ActionMapUIResource;
+import javax.swing.plaf.InputMapUIResource;
import javax.swing.plaf.TextUI;
@@ -283,11 +292,505 @@ public abstract class JTextComponent extends JComponent
}
}
+ /**
+ * According to <a
+ * href="http://java.sun.com/products/jfc/tsc/special_report/kestrel/keybindings.html">this
+ * report</a>, a pair of private classes wraps a {@link
+ * javax.swing.text.Keymap} in the new {@link InputMap} / {@link
+ * ActionMap} interfaces, such that old Keymap-using code can make use of
+ * the new framework.</p>
+ *
+ * <p>A little bit of experimentation with these classes reveals the following
+ * structure:
+ *
+ * <ul>
+ *
+ * <li>KeymapWrapper extends {@link InputMap} and holds a reference to
+ * the underlying {@link Keymap}.</li>
+ *
+ * <li>KeymapWrapper maps {@link KeyStroke} objects to {@link Action}
+ * objects, by delegation to the underlying {@link Keymap}.</li>
+ *
+ * <li>KeymapActionMap extends {@link ActionMap} also holds a reference to
+ * the underlying {@link Keymap} but only appears to use it for listing
+ * its keys. </li>
+ *
+ * <li>KeymapActionMap maps all {@link Action} objects to
+ * <em>themselves</em>, whether they exist in the underlying {@link
+ * Keymap} or not, and passes other objects to the parent {@link
+ * ActionMap} for resolving.
+ *
+ * </ul>
+ */
+
+ private class KeymapWrapper extends InputMap
+ {
+ Keymap map;
+
+ public KeymapWrapper(Keymap k)
+ {
+ map = k;
+ }
+
+ public int size()
+ {
+ return map.getBoundKeyStrokes().length + super.size();
+ }
+
+ public Object get(KeyStroke ks)
+ {
+ Action mapped = null;
+ Keymap m = map;
+ while(mapped == null && m != null)
+ {
+ mapped = m.getAction(ks);
+ if (mapped == null && ks.getKeyEventType() == KeyEvent.KEY_TYPED)
+ mapped = m.getDefaultAction();
+ if (mapped == null)
+ m = m.getResolveParent();
+ }
+
+ if (mapped == null)
+ return super.get(ks);
+ else
+ return mapped;
+ }
+
+ public KeyStroke[] keys()
+ {
+ KeyStroke[] superKeys = super.keys();
+ KeyStroke[] mapKeys = map.getBoundKeyStrokes();
+ KeyStroke[] bothKeys = new KeyStroke[superKeys.length + mapKeys.length];
+ for (int i = 0; i < superKeys.length; ++i)
+ bothKeys[i] = superKeys[i];
+ for (int i = 0; i < mapKeys.length; ++i)
+ bothKeys[i + superKeys.length] = mapKeys[i];
+ return bothKeys;
+ }
+
+ public KeyStroke[] allKeys()
+ {
+ KeyStroke[] superKeys = super.allKeys();
+ KeyStroke[] mapKeys = map.getBoundKeyStrokes();
+ KeyStroke[] bothKeys = new KeyStroke[superKeys.length + mapKeys.length];
+ for (int i = 0; i < superKeys.length; ++i)
+ bothKeys[i] = superKeys[i];
+ for (int i = 0; i < mapKeys.length; ++i)
+ bothKeys[i + superKeys.length] = mapKeys[i];
+ return bothKeys;
+ }
+ }
+
+ private class KeymapActionMap extends ActionMap
+ {
+ Keymap map;
+
+ public KeymapActionMap(Keymap k)
+ {
+ map = k;
+ }
+
+ public Action get(Object cmd)
+ {
+ if (cmd instanceof Action)
+ return (Action) cmd;
+ else
+ return super.get(cmd);
+ }
+
+ public int size()
+ {
+ return map.getBoundKeyStrokes().length + super.size();
+ }
+
+ public Object[] keys()
+ {
+ Object[] superKeys = super.keys();
+ Object[] mapKeys = map.getBoundKeyStrokes();
+ Object[] bothKeys = new Object[superKeys.length + mapKeys.length];
+ for (int i = 0; i < superKeys.length; ++i)
+ bothKeys[i] = superKeys[i];
+ for (int i = 0; i < mapKeys.length; ++i)
+ bothKeys[i + superKeys.length] = mapKeys[i];
+ return bothKeys;
+ }
+
+ public Object[] allKeys()
+ {
+ Object[] superKeys = super.allKeys();
+ Object[] mapKeys = map.getBoundKeyStrokes();
+ Object[] bothKeys = new Object[superKeys.length + mapKeys.length];
+ for (int i = 0; i < superKeys.length; ++i)
+ bothKeys[i] = superKeys[i];
+ for (int i = 0; i < mapKeys.length; ++i)
+ bothKeys[i + superKeys.length] = mapKeys[i];
+ return bothKeys;
+ }
+
+ }
+
+ static class DefaultKeymap implements Keymap
+ {
+ String name;
+ Keymap parent;
+ Hashtable map;
+ Action defaultAction;
+
+ public DefaultKeymap(String name)
+ {
+ this.name = name;
+ this.map = new Hashtable();
+ }
+
+ public void addActionForKeyStroke(KeyStroke key, Action a)
+ {
+ map.put(key, a);
+ }
+
+ /**
+ * Looks up a KeyStroke either in the current map or the parent Keymap;
+ * does <em>not</em> return the default action if lookup fails.
+ *
+ * @param key The KeyStroke to look up an Action for.
+ *
+ * @return The mapping for <code>key</code>, or <code>null</code>
+ * if no mapping exists in this Keymap or any of its parents.
+ */
+ public Action getAction(KeyStroke key)
+ {
+ if (map.containsKey(key))
+ return (Action) map.get(key);
+ else if (parent != null)
+ return parent.getAction(key);
+ else
+ return null;
+ }
+
+ public Action[] getBoundActions()
+ {
+ Action [] ret = new Action[map.size()];
+ Enumeration e = map.elements();
+ int i = 0;
+ while (e.hasMoreElements())
+ {
+ ret[i++] = (Action) e.nextElement();
+ }
+ return ret;
+ }
+
+ public KeyStroke[] getBoundKeyStrokes()
+ {
+ KeyStroke [] ret = new KeyStroke[map.size()];
+ Enumeration e = map.keys();
+ int i = 0;
+ while (e.hasMoreElements())
+ {
+ ret[i++] = (KeyStroke) e.nextElement();
+ }
+ return ret;
+ }
+
+ public Action getDefaultAction()
+ {
+ return defaultAction;
+ }
+
+ public KeyStroke[] getKeyStrokesForAction(Action a)
+ {
+ int i = 0;
+ Enumeration e = map.keys();
+ while (e.hasMoreElements())
+ {
+ if (map.get(e.nextElement()).equals(a))
+ ++i;
+ }
+ KeyStroke [] ret = new KeyStroke[i];
+ i = 0;
+ e = map.keys();
+ while (e.hasMoreElements())
+ {
+ KeyStroke k = (KeyStroke) e.nextElement();
+ if (map.get(k).equals(a))
+ ret[i++] = k;
+ }
+ return ret;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public Keymap getResolveParent()
+ {
+ return parent;
+ }
+
+ public boolean isLocallyDefined(KeyStroke key)
+ {
+ return map.containsKey(key);
+ }
+
+ public void removeBindings()
+ {
+ map.clear();
+ }
+
+ public void removeKeyStrokeBinding(KeyStroke key)
+ {
+ map.remove(key);
+ }
+
+ public void setDefaultAction(Action a)
+ {
+ defaultAction = a;
+ }
+
+ public void setResolveParent(Keymap p)
+ {
+ parent = p;
+ }
+
+ }
+
private static final long serialVersionUID = -8796518220218978795L;
public static final String DEFAULT_KEYMAP = "default";
public static final String FOCUS_ACCELERATOR_KEY = "focusAcceleratorKey";
+
+ private static Hashtable keymaps = new Hashtable();
+ private Keymap keymap;
+
+ /**
+ * Get a Keymap from the global keymap table, by name.
+ *
+ * @param n The name of the Keymap to look up
+ *
+ * @return A Keymap associated with the provided name, or
+ * <code>null</code> if no such Keymap exists
+ *
+ * @see #addKeymap()
+ * @see #removeKeymap()
+ * @see #keymaps
+ */
+ public static Keymap getKeymap(String n)
+ {
+ return (Keymap) keymaps.get(n);
+ }
+
+ /**
+ * Remove a Keymap from the global Keymap table, by name.
+ *
+ * @param n The name of the Keymap to remove
+ *
+ * @return The keymap removed from the global table
+ *
+ * @see #addKeymap()
+ * @see #getKeymap()
+ * @see #keymaps
+ */
+ public static Keymap removeKeymap(String n)
+ {
+ Keymap km = (Keymap) keymaps.get(n);
+ keymaps.remove(n);
+ return km;
+ }
+
+ /**
+ * Create a new Keymap with a specific name and parent, and add the new
+ * Keymap to the global keymap table. The name may be <code>null</code>,
+ * in which case the new Keymap will <em>not</em> be added to the global
+ * Keymap table. The parent may also be <code>null</code>, which is
+ * harmless.
+ *
+ * @param n The name of the new Keymap, or <code>null</code>
+ * @param parent The parent of the new Keymap, or <code>null</code>
+ *
+ * @return The newly created Keymap
+ *
+ * @see #removeKeymap()
+ * @see #getKeymap()
+ * @see #keymaps
+ */
+ public static Keymap addKeymap(String n, Keymap parent)
+ {
+ Keymap k = new DefaultKeymap(n);
+ k.setResolveParent(parent);
+ if (n != null)
+ keymaps.put(n, k);
+ return k;
+ }
+ /**
+ * Get the current Keymap of this component.
+ *
+ * @return The component's current Keymap
+ *
+ * @see #setKeymap()
+ * @see #keymap
+ */
+ Keymap getKeymap()
+ {
+ return keymap;
+ }
+
+ /**
+ * Set the current Keymap of this component, installing appropriate
+ * {@link KeymapWrapper} and {@link KeymapActionMap} objects in the
+ * {@link InputMap} and {@link ActionMap} parent chains, respectively,
+ * and fire a property change event with name <code>"keymap"</code>.
+ *
+ * @see #getKeymap()
+ * @see #keymap
+ */
+ public void setKeymap(Keymap k)
+ {
+
+ // phase 1: replace the KeymapWrapper entry in the InputMap chain.
+ // the goal here is to always maintain the following ordering:
+ //
+ // [InputMap]? -> [KeymapWrapper]? -> [InputMapUIResource]*
+ //
+ // that is to say, component-specific InputMaps need to remain children
+ // of Keymaps, and Keymaps need to remain children of UI-installed
+ // InputMaps (and the order of each group needs to be preserved, of
+ // course).
+
+ KeymapWrapper kw = (k == null ? null : new KeymapWrapper(k));
+ InputMap childInputMap = getInputMap(JComponent.WHEN_FOCUSED);
+ if (childInputMap == null)
+ setInputMap(JComponent.WHEN_FOCUSED, kw);
+ else
+ {
+ while (childInputMap.getParent() != null
+ && !(childInputMap.getParent() instanceof KeymapWrapper)
+ && !(childInputMap.getParent() instanceof InputMapUIResource))
+ childInputMap = childInputMap.getParent();
+
+ // option 1: there is nobody to replace at the end of the chain
+ if (childInputMap.getParent() == null)
+ childInputMap.setParent(kw);
+
+ // option 2: there is already a KeymapWrapper in the chain which
+ // needs replacing (possibly with its own parents, possibly without)
+ else if (childInputMap.getParent() instanceof KeymapWrapper)
+ {
+ if (kw == null)
+ childInputMap.setParent(childInputMap.getParent().getParent());
+ else
+ {
+ kw.setParent(childInputMap.getParent().getParent());
+ childInputMap.setParent(kw);
+ }
+ }
+
+ // option 3: there is an InputMapUIResource in the chain, which marks
+ // the place where we need to stop and insert ourselves
+ else if (childInputMap.getParent() instanceof InputMapUIResource)
+ {
+ if (kw != null)
+ {
+ kw.setParent(childInputMap.getParent());
+ childInputMap.setParent(kw);
+ }
+ }
+ }
+
+ // phase 2: replace the KeymapActionMap entry in the ActionMap chain
+
+ KeymapActionMap kam = (k == null ? null : new KeymapActionMap(k));
+ ActionMap childActionMap = getActionMap();
+ if (childActionMap == null)
+ setActionMap(kam);
+ else
+ {
+ while (childActionMap.getParent() != null
+ && !(childActionMap.getParent() instanceof KeymapActionMap)
+ && !(childActionMap.getParent() instanceof ActionMapUIResource))
+ childActionMap = childActionMap.getParent();
+
+ // option 1: there is nobody to replace at the end of the chain
+ if (childActionMap.getParent() == null)
+ childActionMap.setParent(kam);
+
+ // option 2: there is already a KeymapActionMap in the chain which
+ // needs replacing (possibly with its own parents, possibly without)
+ else if (childActionMap.getParent() instanceof KeymapActionMap)
+ {
+ if (kam == null)
+ childActionMap.setParent(childActionMap.getParent().getParent());
+ else
+ {
+ kam.setParent(childActionMap.getParent().getParent());
+ childActionMap.setParent(kam);
+ }
+ }
+
+ // option 3: there is an ActionMapUIResource in the chain, which marks
+ // the place where we need to stop and insert ourselves
+ else if (childActionMap.getParent() instanceof ActionMapUIResource)
+ {
+ if (kam != null)
+ {
+ kam.setParent(childActionMap.getParent());
+ childActionMap.setParent(kam);
+ }
+ }
+ }
+
+ // phase 3: update the explicit keymap field
+
+ Keymap old = keymap;
+ keymap = k;
+ firePropertyChange("keymap", old, k);
+ }
+
+ /**
+ * Resolves a set of bindings against a set of actions and inserts the
+ * results into a {@link Keymap}. Specifically, for each provided binding
+ * <code>b</code>, if there exists a provided action <code>a</code> such
+ * that <code>a.getValue(Action.NAME) == b.ActionName</code> then an
+ * entry is added to the Keymap mapping <code>b</code> to
+ * </code>a</code>.
+ *
+ * @param map The Keymap to add new mappings to
+ * @param bindings The set of bindings to add to the Keymap
+ * @param actions The set of actions to resolve binding names against
+ *
+ * @see Action#NAME
+ * @see Action#getValue()
+ * @see KeyBinding#ActionName
+ */
+ public static void loadKeymap(Keymap map,
+ JTextComponent.KeyBinding[] bindings,
+ Action[] actions)
+ {
+ Hashtable acts = new Hashtable(actions.length);
+ for (int i = 0; i < actions.length; ++i)
+ acts.put(actions[i].getValue(Action.NAME), actions[i]);
+ for (int i = 0; i < bindings.length; ++i)
+ if (acts.containsKey(bindings[i].actionName))
+ map.addActionForKeyStroke(bindings[i].key, (Action) acts.get(bindings[i].actionName));
+ }
+
+ /**
+ * Returns the set of available Actions this component's associated
+ * editor can run. Equivalent to calling
+ * <code>getUI().getEditorKit().getActions()</code>. This set of Actions
+ * is a reasonable value to provide as a parameter to {@link
+ * #loadKeymap()}, when resolving a set of {@link #KeyBinding} objects
+ * against this component.
+ *
+ * @return The set of available Actions on this component's {@link EditorKit}
+ *
+ * @see TextUI#getEditorKit()
+ * @see EditorKit#getActions()
+ */
+ public Action[] getActions()
+ {
+ return getUI().getEditorKit(this).getActions();
+ }
+
private Document doc;
private Caret caret;
private Highlighter highlighter;
@@ -296,19 +799,47 @@ public abstract class JTextComponent extends JComponent
private Color selectedTextColor;
private Color selectionColor;
private boolean editable;
+ private Insets margin;
/**
* Creates a new <code>JTextComponent</code> instance.
*/
public JTextComponent()
{
+ Keymap defkeymap = getKeymap(DEFAULT_KEYMAP);
+ boolean creatingKeymap = false;
+ if (defkeymap == null)
+ {
+ defkeymap = addKeymap(DEFAULT_KEYMAP, null);
+ defkeymap.setDefaultAction(new DefaultEditorKit.DefaultKeyTypedAction());
+ creatingKeymap = true;
+ }
+
+ setFocusable(true);
enableEvents(AWTEvent.KEY_EVENT_MASK);
updateUI();
+
+ // need to do this after updateUI()
+ if (creatingKeymap)
+ loadKeymap(defkeymap,
+ new KeyBinding[] {
+ new KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0),
+ DefaultEditorKit.backwardAction),
+ new KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0),
+ DefaultEditorKit.forwardAction),
+ new KeyBinding(KeyStroke.getKeyStroke("typed \b"),
+ DefaultEditorKit.deletePrevCharAction),
+ new KeyBinding(KeyStroke.getKeyStroke("typed \u007f"),
+ DefaultEditorKit.deleteNextCharAction)
+ },
+ getActions());
}
- public void setDocument(Document s)
+ public void setDocument(Document newDoc)
{
- doc = s;
+ Document oldDoc = doc;
+ doc = newDoc;
+ firePropertyChange("document", oldDoc, newDoc);
revalidate();
repaint();
}
@@ -328,18 +859,22 @@ public abstract class JTextComponent extends JComponent
return null;
}
+ public void setMargin(Insets m)
+ {
+ margin = m;
+ }
+
public Insets getMargin()
{
- // FIXME: Not implemented.
- return null;
+ return margin;
}
public void setText(String text)
{
try
{
- getDocument().remove(0, doc.getLength());
- getDocument().insertString(0, text, null);
+ doc.remove(0, doc.getLength());
+ doc.insertString(0, text, null);
}
catch (BadLocationException e)
{
@@ -488,8 +1023,16 @@ public abstract class JTextComponent extends JComponent
*/
public void setCaret(Caret newCaret)
{
- firePropertyChange("caret", caret, newCaret);
+ if (caret != null)
+ caret.deinstall(this);
+
+ Caret oldCaret = caret;
caret = newCaret;
+
+ if (caret != null)
+ caret.install(this);
+
+ firePropertyChange("caret", oldCaret, newCaret);
}
public Color getCaretColor()
@@ -499,8 +1042,9 @@ public abstract class JTextComponent extends JComponent
public void setCaretColor(Color newColor)
{
- firePropertyChange("caretColor", caretColor, newColor);
+ Color oldCaretColor = caretColor;
caretColor = newColor;
+ firePropertyChange("caretColor", oldCaretColor, newColor);
}
public Color getDisabledTextColor()
@@ -510,8 +1054,9 @@ public abstract class JTextComponent extends JComponent
public void setDisabledTextColor(Color newColor)
{
- firePropertyChange("disabledTextColor", caretColor, newColor);
+ Color oldColor = disabledTextColor;
disabledTextColor = newColor;
+ firePropertyChange("disabledTextColor", oldColor, newColor);
}
public Color getSelectedTextColor()
@@ -521,8 +1066,9 @@ public abstract class JTextComponent extends JComponent
public void setSelectedTextColor(Color newColor)
{
- firePropertyChange("selectedTextColor", caretColor, newColor);
+ Color oldColor = selectedTextColor;
selectedTextColor = newColor;
+ firePropertyChange("selectedTextColor", oldColor, newColor);
}
public Color getSelectionColor()
@@ -532,8 +1078,9 @@ public abstract class JTextComponent extends JComponent
public void setSelectionColor(Color newColor)
{
- firePropertyChange("selectionColor", caretColor, newColor);
+ Color oldColor = selectionColor;
selectionColor = newColor;
+ firePropertyChange("selectionColor", oldColor, newColor);
}
/**
@@ -584,8 +1131,16 @@ public abstract class JTextComponent extends JComponent
public void setHighlighter(Highlighter newHighlighter)
{
- firePropertyChange("highlighter", highlighter, newHighlighter);
+ if (highlighter != null)
+ highlighter.deinstall(this);
+
+ Highlighter oldHighlighter = highlighter;
highlighter = newHighlighter;
+
+ if (highlighter != null)
+ highlighter.install(this);
+
+ firePropertyChange("highlighter", oldHighlighter, newHighlighter);
}
/**
@@ -773,4 +1328,9 @@ public abstract class JTextComponent extends JComponent
{
return (InputMethodListener[]) getListeners(InputMethodListener.class);
}
+
+ public Rectangle modelToView(int position) throws BadLocationException
+ {
+ return getUI().modelToView(this, position);
+ }
}
diff --git a/libjava/javax/swing/text/PlainView.java b/libjava/javax/swing/text/PlainView.java
index 229c7e1..3dd8fe4 100644
--- a/libjava/javax/swing/text/PlainView.java
+++ b/libjava/javax/swing/text/PlainView.java
@@ -39,6 +39,8 @@ exception statement from your version. */
package javax.swing.text;
import java.awt.Color;
+import java.awt.Component;
+import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Rectangle;
@@ -48,12 +50,70 @@ import java.awt.Shape;
public class PlainView extends View
implements TabExpander
{
+ private Color selectedColor;
+ private Color unselectedColor;
+ private Font font;
+
protected FontMetrics metrics;
public PlainView(Element elem)
{
super(elem);
}
+
+ /**
+ * @since 1.4
+ */
+ protected void updateMetrics()
+ {
+ Component component = getContainer();
+ Font font = component.getFont();
+
+ if (this.font != font)
+ {
+ this.font = font;
+ metrics = component.getFontMetrics(font);
+ }
+ }
+
+ /**
+ * @since 1.4
+ */
+ protected Rectangle lineToRect(Shape a, int line)
+ {
+ // Ensure metrics are up-to-date.
+ updateMetrics();
+
+ Rectangle rect = a.getBounds();
+ int fontHeight = metrics.getHeight();
+ return new Rectangle(rect.x, rect.y + (line * fontHeight),
+ rect.width, fontHeight);
+ }
+
+ public Shape modelToView(int position, Shape a, Position.Bias b)
+ throws BadLocationException
+ {
+ Document document = getDocument();
+
+ // Get rectangle of the line containing position.
+ int lineIndex = getElement().getElementIndex(position);
+ Rectangle rect = lineToRect(a, lineIndex);
+
+ // Get the rectangle for position.
+ Element line = getElement().getElement(lineIndex);
+ int lineStart = line.getStartOffset();
+ Segment segment = new Segment();
+ document.getText(lineStart, position - lineStart, segment);
+ int xoffset = Utilities.getTabbedTextWidth(segment, metrics, rect.x,
+ this, lineStart);
+
+ // Calc the real rectangle.
+ rect.x += xoffset;
+ rect.width = 1;
+ rect.height = metrics.getHeight();
+
+ return rect;
+ }
public void drawLine(int lineIndex, Graphics g, int x, int y)
{
@@ -73,30 +133,31 @@ public class PlainView extends View
public int drawSelectedText(Graphics g, int x, int y, int p0, int p1)
throws BadLocationException
{
- String text = getDocument().getText(p0, p1);
- g.setColor(Color.WHITE);
- g.drawString(text, x, y);
- return metrics.stringWidth(text);
+ g.setColor(selectedColor);
+ Segment segment = new Segment();
+ getDocument().getText(p0, p1 - p0, segment);
+ return Utilities.drawTabbedText(segment, x, y, g, this, 0);
}
public int drawUnselectedText(Graphics g, int x, int y, int p0, int p1)
throws BadLocationException
{
- String text = getDocument().getText(p0, p1);
- g.setColor(Color.BLACK);
- g.drawString(text, x, y);
- return metrics.stringWidth(text);
+ g.setColor(unselectedColor);
+ Segment segment = new Segment();
+ getDocument().getText(p0, p1 - p0, segment);
+ return Utilities.drawTabbedText(segment, x, y, g, this, 0);
}
public void paint(Graphics g, Shape s)
{
- System.out.println("Michael: PlainView.paint");
+ JTextComponent textComponent = (JTextComponent) getContainer();
+
+ g.setFont(textComponent.getFont());
+ selectedColor = textComponent.getSelectedTextColor();
+ unselectedColor = textComponent.getForeground();
Rectangle rect = s.getBounds();
- g.setColor(Color.WHITE);
- g.fillRect(rect.x, rect.y, rect.width, rect.height);
-
// FIXME: Text may be scrolled.
drawLine(0, g, rect.x, rect.y);
}
@@ -106,10 +167,18 @@ public class PlainView extends View
return 8;
}
+ /**
+ * Returns the next tab stop position after a given reference position.
+ *
+ * This implementation ignores the <code>tabStop</code> argument.
+ *
+ * @param x the current x position in pixels
+ * @param tabStop the position within the text stream that the tab occured at
+ */
public float nextTabStop(float x, int tabStop)
{
- System.out.println("Michael: PlainView.nextTabpStop: missing implementation");
- return x;
+ float tabSizePixels = getTabSize() + metrics.charWidth('m');
+ return (float) (Math.floor(x / tabSizePixels) + 1) * tabSizePixels;
}
public float getPreferredSpan(int axis)
@@ -119,4 +188,5 @@ public class PlainView extends View
return 10;
}
-} \ No newline at end of file
+}
+
diff --git a/libjava/javax/swing/text/Segment.java b/libjava/javax/swing/text/Segment.java
index 69e2fec..218768e 100644
--- a/libjava/javax/swing/text/Segment.java
+++ b/libjava/javax/swing/text/Segment.java
@@ -39,10 +39,12 @@ package javax.swing.text;
import java.text.CharacterIterator;
-
public class Segment
implements Cloneable, CharacterIterator
{
+ private boolean partialReturn;
+ private int current;
+
public char[] array;
public int count;
public int offset;
@@ -67,61 +69,108 @@ public class Segment
catch (CloneNotSupportedException e)
{
return null;
- }
+ }
}
+
+ public char current()
+ {
+ if (count == 0
+ || current >= getEndIndex())
+ return DONE;
- public char current()
- {
- return array[getIndex()];
- }
+ return array[current];
+ }
- public char first()
- {
- offset = getBeginIndex();
- return array[offset];
- }
+ public char first()
+ {
+ if (count == 0)
+ return DONE;
+
+ current = getBeginIndex();
+ return array[current];
+ }
+
+ public int getBeginIndex()
+ {
+ return offset;
+ }
+
+ public int getEndIndex()
+ {
+ return offset + count;
+ }
+
+ public int getIndex()
+ {
+ return current;
+ }
+
+ public char last()
+ {
+ if (count == 0)
+ return DONE;
- public int getBeginIndex()
- {
- return offset;
- }
+ current = getEndIndex() - 1;
+ return array[current];
+ }
+
+ public char next()
+ {
+ if (count == 0)
+ return DONE;
+
+ if ((current + 1) >= getEndIndex())
+ {
+ current = getEndIndex();
+ return DONE;
+ }
- public int getEndIndex()
- {
- return offset + count;
- }
+ current++;
+ return array[current];
+ }
- public int getIndex()
- {
- return offset;
- }
+ public char previous()
+ {
+ if (count == 0
+ || current == getBeginIndex())
+ return DONE;
+
+ current--;
+ return array[current];
+ }
- public char last()
- {
- offset = getEndIndex() - 1;
- return array[offset];
- }
+ public char setIndex(int position)
+ {
+ if (position < getBeginIndex()
+ || position > getEndIndex())
+ throw new IllegalArgumentException();
- public char next()
- {
- offset++;
- return array[offset];
- }
+ current = position;
- public char previous()
- {
- offset--;
- return array[offset];
- }
+ if (position == getEndIndex())
+ return DONE;
+
+ return array[current];
+ }
- public char setIndex(int position)
- {
- offset = position;
- return array[offset];
- }
+ public String toString()
+ {
+ return new String(array, offset, count);
+ }
- public String toString()
- {
- return new String(array, offset, count);
- }
+ /**
+ * @since 1.4
+ */
+ public void setPartialReturn(boolean p)
+ {
+ partialReturn = p;
+ }
+
+ /**
+ * @since 1.4
+ */
+ public boolean isPartialReturn()
+ {
+ return partialReturn;
+ }
}
diff --git a/libjava/javax/swing/text/TextAction.java b/libjava/javax/swing/text/TextAction.java
index 5fee0e8..029eed9 100644
--- a/libjava/javax/swing/text/TextAction.java
+++ b/libjava/javax/swing/text/TextAction.java
@@ -54,7 +54,7 @@ public abstract class TextAction extends AbstractAction
*/
public TextAction(String name)
{
- // TODO
+ super(name);
}
/**
@@ -64,7 +64,11 @@ public abstract class TextAction extends AbstractAction
*/
protected final JTextComponent getTextComponent(ActionEvent event)
{
- return null; // TODO
+ if (event.getSource() != null &&
+ event.getSource() instanceof JTextComponent)
+ return (JTextComponent) event.getSource();
+ else
+ return getFocusedComponent();
}
/**
diff --git a/libjava/javax/swing/text/View.java b/libjava/javax/swing/text/View.java
index 6c5a9c2..730753a 100644
--- a/libjava/javax/swing/text/View.java
+++ b/libjava/javax/swing/text/View.java
@@ -161,8 +161,49 @@ public abstract class View implements SwingConstants
public View createFragment(int p0, int p1)
{
- // The default implementation doesnt support fragmentation.
+ // The default implementation doesn't support fragmentation.
return this;
- }
+ }
+
+ public int getStartOffset()
+ {
+ return elt.getStartOffset();
+ }
+
+ public int getEndOffset()
+ {
+ return elt.getEndOffset();
+ }
+
+ public Shape getChildAllocation(int index, Shape a)
+ {
+ return null;
+ }
+
+ /**
+ * @since 1.4
+ */
+ public int getViewIndex(float x, float y, Shape allocation)
+ {
+ return -1;
+ }
+
+ /**
+ * @since 1.4
+ */
+ public String getToolTipText(float x, float y, Shape allocation)
+ {
+ int index = getViewIndex(x, y, allocation);
+
+ if (index < -1)
+ return null;
+
+ Shape childAllocation = getChildAllocation(index, allocation);
+
+ if (childAllocation.getBounds().contains(x, y))
+ return getView(index).getToolTipText(x, y, childAllocation);
+
+ return null;
+ }
}