diff options
author | Andrew John Hughes <gnu_andrew@member.fsf.org> | 2005-09-20 18:46:20 +0000 |
---|---|---|
committer | Andrew John Hughes <gnu_andrew@member.fsf.org> | 2005-09-20 18:46:20 +0000 |
commit | 3baed5090a8b63218fd8a5808cd38caeb79a0f7d (patch) | |
tree | e3d5427d27e9ef1ebb9de69a3fd3639084d196d1 | |
parent | d30cf1c6c0de86bac88773529f7071497ce18916 (diff) | |
download | classpath-3baed5090a8b63218fd8a5808cd38caeb79a0f7d.tar.gz |
2005-09-20 Andrew John Hughes <gnu_andrew@member.fsf.org>
* Merge of generics-branch for 2005/09/07 - 2005/09/20 @ 10:05am GMT.
285 files changed, 18409 insertions, 6268 deletions
diff --git a/.cdtproject b/.cdtproject new file mode 100644 index 000000000..2ec939f28 --- /dev/null +++ b/.cdtproject @@ -0,0 +1,3 @@ +<?xml version='1.0'?> +<?eclipse-cdt version="2.0"?> +<cdtproject/>
\ No newline at end of file diff --git a/.classpath b/.classpath index 062a0ec83..f17003859 100644 --- a/.classpath +++ b/.classpath @@ -1,20 +1,10 @@ <?xml version="1.0" encoding="UTF-8"?> <classpath> - <classpathentry excluding="**/SliderTest.java|**/TestAWT.java|compat/|examples/|external/jaxp/source/|external/jaxp/tests/|external/sax/|external/w3c_dom/|gnu/javax/swing/plaf/|gnu/test/|test/|testsuite/|vm/reference/" kind="src" path=""> - <attributes> - </attributes> - </classpathentry> - <classpathentry kind="src" path="external/sax"> - <attributes> - </attributes> - </classpathentry> - <classpathentry kind="src" path="external/w3c_dom"> - <attributes> - </attributes> - </classpathentry> - <classpathentry kind="src" path="vm/reference"> - <attributes> - </attributes> - </classpathentry> - <classpathentry kind="output" path="bin"/> + <classpathentry excluding=".externalToolBuilders/|.settings/|ChangeLog*|Makefile*|autom4te.cache/|compat/|config*|doc/|examples/|external/|gnu/javax/swing/plaf/|include/|install/|lib/|m4/|native/|resource/|scripts/|test/|testsuite/|vm/reference/" kind="src" path=""/> + <classpathentry kind="src" path="resource"/> + <classpathentry kind="src" path="vm/reference"/> + <classpathentry kind="src" path="external/sax"/> + <classpathentry kind="src" path="external/w3c_dom"/> + <classpathentry kind="src" path="examples"/> + <classpathentry kind="output" path="install/share/classpath"/> </classpath> @@ -1,3 +1,41 @@ +2005-09-20 Roman Kennke <kennke@aicas.com> + + * javax/swing/plaf/basic/BasicButtonUI.java + (installDefaults): Handle the rollover UIDefaults property. + (paintText): Correctly paint disabled button label text. + * javax/swing/plaf/basic/BasicLookAndFeel.java + (initComponentDefaults): Fix some text component border defaults. + * javax/swing/plaf/basic/BasicTextPaneUI.java + (installUI): New method. This sets up some style attributes + for the JTextPane. + +2005-09-20 Roman Kennke <kennke@aicas.com> + + * javax/swing/plaf/metal/MetalLookAndFeel.java + (initComponentDefault): Added and fixed some UI defaults. + +2005-09-20 Roman Kennke <kennke@aicas.com> + + * javax/swing/plaf/metal/MetalBorders.java + (ButtonBorder.paintBorder): Fetch correct color for disabled + button border. + (getTextFieldBorder): Correctly initialize text field border. This + should be a compound border with a MarginBorder and TextFieldBorder + instead of a plain TextFieldBorder. + (getTextBorder): New method. + +2005-09-20 Roman Kennke <kennke@aicas.com> + + * javax/swing/text/DefaultStyledDocument.java + (setParagraphAttributes): Implemented this method. + (insertUpdate): Fixed attribute comparison to avoid NPE. + +2005-09-20 Thomas Fitzsimmons <fitzsim@redhat.com> + + PR awt/23951 + * native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c + (isRealized): Leave GDK critical region when exiting early. + 2005-09-19 Andrew John Hughes <gnu_andrew@member.fsf.org> * java/util/Collections.java: @@ -28,10 +66,2029 @@ (checkedSortedSet(SortedSet<E>,Class<E>)): Implemented. (Collections.CheckedSortedSet): New inner class. +2005-09-19 Tom Tromey <tromey@redhat.com> + + * java/awt/PopupMenu.java (AccessibleAWTPopupMenu.serialVersionUID): + New field. + * java/awt/TextField.java (AccessibleAWTTextField.serialVersionUID): + New field. + * java/awt/TextArea.java (AccessibleAWTTextArea.serialVersionUID): + New field. + * java/awt/Menu.java (AccessibleAWTMenu.serialVersionUID): New field. + * java/awt/CheckboxMenuItem.java (AccessibleAWTCheckboxMenuItem.serialVersionUID): + New field. + * java/awt/TextComponent.java (AccessibleAWTTextComponent.serialVersionUID): + New field. + * java/awt/MenuItem.java (AccessibleAWTMenuItem.serialVersionUID): + New field. + * java/awt/Frame.java (AccessibleAWTFrame.serialVersionUID): New + field. + * java/awt/Dialog.java (AccessibleAWTDialog.serialVersionUID): New + field. + * java/awt/Button.java (AccessibleAWTButton.serialVersionUID): New + field. + * java/awt/Window.java (AccessibleAWTWindow.serialVersionUID): New + field. + * java/awt/ScrollPane.java (AccessibleAWTScrollPane.serialVersionUID): + New field. + * java/awt/List.java (AccessibleAWTList.serialVersionUID): New field. + (AccessibleAWTListChild.serialVersionUID): Likewise. + (AccessibleAWTListChild.parent): Moved earlier. + (AccessibleAWTListChild.indexInParent): Renamed. + +2005-09-19 David Gilbert <david.gilbert@object-refinery.com> + + * javax/swing/filechooser/FileView.java: + Reformatted and added API doc comments. + +2005-09-19 Anthony Balkissoon <abalkiss@redhat.com> + + * javax/swing/JRootPane.java: + (createGlassPane): Don't set the layout manager to BorderLayout. Leave + it as JPanel's default FlowLayout. + +2005-09-19 Lillian Angel <langel@redhat.com> + + * javax/swing/ToolTipManager.java: + Changed tooltip to be JDialog (no entry in taskbar), + instead of JWindow. + (actionPerformed): No need to start timer here. + (mouseEntered): No need to call showTip here, it is called + when the timer fires. + (showTip): Shouldn't show tip if it is already visible or + the current component is not showing. + * javax/swing/plaf/basic/BasicTreeUI.java + (getRowForPath): Re-implemented. + (mousePressed): Call getRowForPath instead, also + added a check in for leaf icons. + +2005-09-19 Anthony Balkissoon <abalkiss@redhat.com> + + * javax/swing/JLayeredPane.java: + (<init>): Set layout manager to null. + +2005-09-19 Anthony Balkissoon <abalkiss@redhat.com> + + * javax/swing/plaf/basic/BasicInternalFrameUI.java: + (GlassPaneDispatcher.handleEvent): Added check for mouseEventTarget + being null to avoid NPE. + +2005-09-19 Anthony Balkissoon <abalkiss@redhat.com> + + * javax/swing/JRootPane.java: + (RootLayout.layoutContainer): Added comment about how the + components should be sized. Fixed size of glassPane which fills the + entire viewable region, including overtop the menuBar. Used bounds + minus insets for containerSize, as indicated in comment, rather than + getSize(). Used setBounds instead of setSize for layeredPane because + its relation to the other components' sizes is more obvious that way. + +2005-09-19 Anthony Balkissoon <abalkiss@redhat.com> + + * javax/swing/plaf/basic/BasicInternalFrameUI.java: + (GlassPaneDispatcher.handleEvent): Replaced call to SwingUtilities' + convertMouseEvent (with identical source and desination) with a simple + cast. If acquireComponentForMouseEvent reveals we're going to + re-dispatch this event to ourselves (and loop infinitely), return. Also + replaced contentPane by glassPane as the source argument to + SwingUtilities.convertMouseEvent since the glassPane is the real source. +2005-09-19 David Gilbert <david.gilbert@object-refinery.com> + + * javax/swing/plaf/basic/BasicArrowButton.java + (paintTriangle): minor correction to highlight on triangle for disabled + buttons. + +2005-09-19 Tom Tromey <tromey@redhat.com> + + * javax/print/DocFlavor.java (BYTE_ARRAY.serialVersionUID): New field. + (INPUT_STREAM.serialVersionUID): Likewise. + +2005-09-19 Tom Tromey <tromey@redhat.com> + + * java/text/DateFormat.java (serialVersionUID): New field. + +2005-19-19 Lillian Angel <langel@redhat.com> + + * javax/swing/plaf/basic/BasicTreeUI.java + (selectPath): Changed so DISCONTIGUOUS_TREE_SELECTION is the + default. + * javax/swing/JTree.java + (AccessibleJTreeNode): Initialized all fields. + (addAccessibleSelection): Implemented. + (clearAccessibleSelection): Implemented. + (doAccessibleAction): Implemented. + (getAccessibleAction): Implemented. + (getAccessibleActionCount): Implemented. + (getAccessibleActionDescription): Implemented. + (getAccesssibleChild): Remove mod variable, made global. + (getAccessibleComponent): Changed to return this, since this + class implements AccessibleComponent. + (getAccessibleSelection): Likewise. + (getAccessibleSelection): Implemented. + (getAccessibleSelectionCount): Implemented. + (getAccessibleStateSet): Remove mod variable, made global. + (getCursor): Implemented. + (isAccessibleChildSelected): Remove mod variable, made global. + (removeAccessibleSelection): Implemented. + (selectAllAccessibleSelection): Implemented. + (setCursor): Implemented. + (AccessibleJTree): Nothing to do. + (getAccessibleAt): Implemented. + (getAccessibleSelection): Implemented. + (getAccessibleSelection): Implemented. + +2005-09-19 Tom Tromey <tromey@redhat.com> + + * javax/xml/xpath/XPathFunctionException.java (serialVersionUID): New + field. + * javax/xml/xpath/XPathFactoryConfigurationException.java + (serialVersionUID): New field. + * javax/xml/xpath/XPathExpressionException.java (serialVersionUID): New + field. + * javax/xml/xpath/XPathException.java (serialVersionUID): New field. + * javax/xml/transform/TransformerConfigurationException.java (locator): + Removed. + (TransformerConfigurationException): Pass locator to super constructor. + (serialVersionUID): New field. + * javax/xml/transform/TransformerFactoryConfigurationError.java + (serialVersionUID): New field. + * javax/xml/transform/TransformerException.java (containedException): + Renamed field. + (serialVersionUID): New field. + +2005-09-19 Roman Kennke <kennke@aicas.com> + + * javax/swing/plaf/basic/BasicTextUI.java + (UpdateHandler.propertyChange): Handle changes of the editable + property. + (paintBackground): Moved implementation to + UpdateHandler.propertyChange. This method itself should not fill + the background. + +2005-09-19 Mark Wielaard <mark@klomp.org> + + * native/jni/java-net/java_net_VMInetAddress.c + (Java_java_net_VMInetAddress_getHostByAddr): Add error string as + exception message. + * native/jni/java-net/javanet.c (_javanet_accept): Likewise. + (_javanet_shutdownInput): Likewise. + (_javanet_shutdownOutput): Likewise. + +2005-09-19 Roman Kennke <kennke@aicas.com> + + * javax/swing/border/TitledBorder.java + (paintBorder): Correctly set the Y offset for the border title. + (getMeasurements): Determine the correct Y offset for the border + title. + +2005-09-19 Robert Schuster <robertschuster@fsfe.org> + + * java/awt/Checkbox.java: + (Checkbox): Properly set as selected checkbox in corresponding + checkbox group. + (paramString): Removed checkbox group information. + * java/awt/Component.java: + (paramString): Removed redundant "=". + +2005-09-19 David Gilbert <david.gilbert@object-refinery.com> + + * javax/swing/plaf/basic/BasicComboBoxUI.java + (installComponents): call configureArrowButton after creating button, + (configureEditor): set the selected item, + (configureArrowButton): set a zero margin, + (getPreferredSize): delegate to getMinimumSize(), + (getMinimumSize): now uses code that was in getPreferredSize(), + (getDefaultSize): reduce default height, + (ComboBoxLayoutManager.layoutComponent): use comboBox height as button + width, + (PropertyChangeHandler.propertyChange): set font on arrow button, + * javax/swing/plaf/metal/MetalComboBoxUI.java + (instances): deleted field, + (MetalComboBoxLayoutManager): new class, + (MetalPropertyChangeListener): new class, + (MetalComboPopup): new class, + (createUI): just return new instance, + (createEditor): implemented, + (createPopup): implemented, + (createArrowButton): implemented, + (createPropertyChangeListener): implemented, + (paint): implemented, + (editablePropertyChanged): implemented, + (createLayoutManager): implemented, + (removeListeners): implemented, + (getMinimumSize): implemented. + +2005-09-19 Andreas Tobler <a.tobler@schweiz.ch> + + * native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkFontPeer.c + (Java_gnu_java_awt_peer_gtk_GdkFontPeer_dispose): Fix double + unreferencing pfont->font. Unref pfont->layout instead. + +2005-09-18 Tom Tromey <tromey@redhat.com> + + * java/util/Timer.java (TaskQueue.purge): New method. + (Timer(String)): New constructor. + (Timer(String,boolean)): Likewise. + (purge): New method. + +2005-09-18 Tom Tromey <tromey@redhat.com> + + * java/lang/Short.java (valueOf): New method. + * java/lang/Double.java (valueOf): New method. + * java/lang/Float.java (valueOf): New method. + +2005-09-18 Tom Tromey <tromey@redhat.com> + + * java/lang/Long.java (reverse): Correctly handle sign extension. + +2005-09-18 David Gilbert <david.gilbert@object-refinery.com> + + * javax/swing/plaf/basic/BasicComboBoxUI.java + (installComponents): remove listBox color settings, + * javax/swing/plaf/basic/BasicLookAndFeel.java + (initComponentDefaults): corrected ComboBox and ListBox defaults. + +2005-09-18 David Gilbert <david.gilbert@object-refinery.com> + + * javax/swing/plaf/basic/BasicComboBoxRenderer.java + (BasicComboBoxRenderer): set no focus border, + (getListCellRendererComponent): set background color if cell has focus, + removed border switching code. + +2005-09-18 David Gilbert <david.gilbert@object-refinery.com> + + * javax/swing/plaf/basic/BasicComboBoxUI.java + (borderInsets): deleted, + (arrowButtonWidth): deleted, + (configureEditor): set font, + (isFocusTraversable): set to true for non-editable combobox, + (paint): deleted border painting code, + (paintBorder): deleted, + (getPreferredSize): returns a value, not null, + (getMinimumSize): likewise, + (getMaximumSize): likewise, + (rectangleForCurrentValue): reimplemented, + (paintCurrentValue): no longer adjusts for border insets, + (getDisplaySize): update maximum width and height independently, + (ComboBoxLayoutManager): removed redundant 'extends Object', + (ComboBoxLayoutManager.preferredLayoutSize): call getPreferredSize(), + (ComboBoxLayoutManager.minimumLayoutSize): delegate to + preferredLayoutSize(), + (ComboBoxLayoutManager.layoutContainer): use arrow button preferred + size in layout, + (PropertyChangeHandler.propertyChange): added 'font' handling. + +2005-09-18 David Gilbert <david.gilbert@object-refinery.com> + + * javax/swing/plaf/basic/BasicComboBoxUI.java + (installListeners): add listener to arrowButton instead of comboBox, + deleted call to configureArrowButton(), + (uninstallListeners): remove listener from arrowButton instead of + comboBox, and deleted call to unconfigureArrowButton(), + (configureArrowButton): set font and enabled state, deleted + addMouseListener() call, + (unconfigureArrowButton): deleted removeMouseListener() call, + (MouseHandler.mousePressed): just toggle display status of popup, + (MouseHandler.mouseReleased): deleted. + +2005-09-18 David Gilbert <david.gilbert@object-refinery.com> + + * javax/swing/plaf/basic/BasicComboBoxUI.java + (largestItemSize): renamed displaySize, + (getLargestItemSize): renamed getDisplaySize and changed to protected, + (ComboBoxLayoutManager.preferredLayoutSize): updated for renamed field + and method, + (ListDataHandler.intervalAdded): likewise, + (ListDataHandler.intervalRemoved): likewise. + +2005-09-18 David Gilbert <david.gilbert@object-refinery.com> + + * javax/swing/plaf/basic/BasicComboBoxUI.java: + Updated API docs all over. + +2005-09-18 David Gilbert <david.gilbert@object-refinery.com> + + * java/text/RuleBasedCollator.java: + Fixed spelling error in comment. + +2005-09-17 Tom Tromey <tromey@redhat.com> + + * .settings/org.eclipse.jdt.ui.prefs: Add file template. + +2005-09-17 Anthony Green <green@redhat.com> + + * java/security/Security.java (getProviders): Pre-allocate the + target array for Collection.toArray call. + * gnu/java/security/PolicyFile.java (parse): Ditto. + * javax/swing/filechooser/FileSystemView.java: Ditto. + * javax/swing/JFileChooser.java (getChoosableFileFilters): Ditto. + +2005-09-17 Tom Tromey <tromey@redhat.com> + + PR classpath/22963: + * java/nio/charset/Charset.java (forName): Javadoc fix. + (providers2): Use ServiceFactory. + +2005-09-17 Mark Wielaard <mark@klomp.org> + + * org/ietf/jgss/GSSException.java (BAD_BINDINGS, BAD_MECH, + BAD_NAME, BAD_NAMETYPE, CONTEXT_EXPIRED, CREDENTIALS_EXPIRED, + DEFECTIVE_CREDENTIAL, DEFECTIVE_TOKEN, DUPLICATE_TOKEN, FAILURE, + NO_CONTEXT, NO_CRED, OLD_TOKEN): Document official RFC values. + +2005-09-17 Tom Tromey <tromey@redhat.com> + + * java/lang/Short.java (SIZE): New constant. + (MIN_CACHE, MAX_CACHE): Likewise. + (shortCache): New field. + (reverseBytes): New method. + * java/lang/Long.java (SIZE): New constant. + (valueOf): New method. + (bitCount): New method. + (rotateLeft): New method. + (rotateRight): New method. + (highestOneBit): New method. + (numberOfLeadingZeros): New method. + (lowestOneBit): New method. + (numberOfTrailingZeros): New method. + (signum): New method. + (reverseBytes): New method. + (reverse): New method. + * java/lang/Float.java (SIZE): New constant. + * java/lang/Double.java (SIZE): New constant. + * java/lang/Character.java (SIZE): New constant. + (MAX_CACHE): Likewise. + (charCache): New field. + (valueOf): New method. + (reverseBytes): Likewise. + * java/lang/Byte.java (SIZE): New constant. + (byteCache): New field. + (valueOf): New method. + * java/lang/Boolean.java (parseBoolean): New method. + +2005-09-17 Mark Wielaard <mark@klomp.org> + + Reported by David Lichteblau <david@lichteblau.com> + * native/jni/classpath/jcl.c (JCL_NewRawDataObject): Create + NewGlobalRef before calling DeleteLocalRef. + +2005-09-17 Paul Jenner <psj@harker.dyndns.org> + + * configure.ac: Clarify that Werror configure option is + disabled by default. + +2005-09-17 Mark Wielaard <mark@klomp.org> + + * javax/swing/plaf/basic/BasicMenuItemUI.java: Reindent boilerplate. + +2005-09-17 Tom Tromey <tromey@redhat.com> + + * java/util/prefs/Preferences.java (systemNodeForPackage): + Javadoc fix. + (userNodeForPackage): Likewise. + * java/util/logging/LoggingPermission.java (serialVersionUID): + New field. + * java/io/ObjectInputStream.java (parseContent): Javadoc fix. + +2005-09-17 Mark Wielaard <mark@klomp.org> + + * doc/www.gnu.org/home.wml: Update mauve link. + +2005-09-16 Anthony Green <green@redhat.com> + + PR libgcj/20198 + * java/net/URLClassLoader.java (FileURLLoader.getResource): File + resources should all have canonicalized names. + +2005-09-16 Lillian Angel <langel@redhat.com> + + * javax/swing/JTree.java + (AccessibleJTreeNode): Fixed documentation. + (addAccessibleSelection): Likewise, still needs to + be implemented. + (addFocusListener): Implemented. + (addPropertyChangeListener): Implemented. + (clearAccessibleSelection): Implemented. + (contains): Implemented. + (doAccessibleAction): Fixed documentation, still + needs to be implemented. + (getAccessibleAction): Likewise. + (getAccessibleActionCount): Likewise. + (getAccessibleActionDescription): Implemented. + (getAccessibleAt): Implemented. + (getAccessibleChild): Implemented. + (getAccessibleChildrenCount): Implemented. + (getAccessibleComponent): Fixed documentation. + (getAccessibleContext): Implemented. + (getAccessibleDescription): Implemented. + (getAccessibleIndexInParent): Implemented. + (getAccessibleName): Implemented. + (getAccessibleParent): Fixed documentation. + (getAccessibleRole): Likewise. + (getAccessibleSelection): Likewise, still needs to + be implemented. + (getAccessibleSelection): Likewise. + (getAccessibleSelectionCount): Implemented. + (getAccessibleStateSet): Implemented. + (getAccessibleText): Fixed documentation. + (getAccessibleValue): Likewise. + (getBackground): Implemented. + (getBounds): Implemented. + (getCursor): Fixed documentation, still needs to be + implemented. + (getFont): Implemented. + (getFontMetrics): Implemented. + (getForeground): Implemented. + (getLocale): Implemented. + (getLocation): Implemented. + (getLocationInJTree): Implemented. + (getLocationOnScreen): Implemented. + (getSize): Implemented. + (isAccessibleChildSelected): Implemented. + (isEnabled): Implemented. + (isFocusTraversable): Implemented. + (isShowing): Implemented. + (isVisible): Implemented. + (removeAccessibleSelection): Fixed documentation, need to + fix current implementation. + (removeFocusListener): Implemented. + (removePropertyChangeListener): Implemented. + (requestFocus): Implemented. + (selectAllAccessibleSelection): Need to implement. Added FIXME. + (setAccessibleDescription): Implemented. + (setAccessibleName): Implemented. + (setBackground): Implemented. + (setBounds): Implemented. + (setCursor): Fixed documentation, still need to implement. + (setEnabled): Implemented. + (setFont): Implemented. + (setForeground): Implemented. + (setLocation): Implemented. + (setSize): Implemented. + (setVisible): Implemented. + (AccessibleJTree): Fixed documentation, still need + to implement. + (addAccessibleSelection): Implemented. + (clearAccessibleSelection): Implemented. + (fireVisibleDataPropertyChange): Implemented. + (getAccessibleAt): Fixed documentation, need to implement. + (getAccessibleChild): Implemented. + (getAccessibleChildrenCount): Implemented. + (getAccessibleIndexInParent): Fixed documentation. + (getAccessibleRole): Likewise. + (getAccessibleSelection): Likewise, still need to implement. + (getAccessibleSelection): Likewise. + (getAccessibleSelectionCount): Implemented. + (isAccessibleChildSelected): Implemented. + (removeAccessibleSelection): Implemented. + (selectAllAccessibleSelection): Implemented. + (treeCollapsed): Implemented. + (treeExpanded): Implemented. + (treeNodesChanged): Implemented. + (treeNodesInserted): Implemented. + (treeNodesRemoved): Implemented. + (treeStructureChanged): Implemented. + (valueChanged): Implemented. + (TreeModelListener): Fixed documentation. + +2005-09-16 Tom Tromey <tromey@redhat.com> + + * java/io/PrintWriter.java (PrintWriter): New constructors. + +2005-09-16 Tom Tromey <tromey@redhat.com> + + PR classpath/22689: + * java/io/PrintWriter.java (closed): New field. + (checkError): Only flush if stream not closed. + (close): Set 'closed'. + +2005-09-16 Tom Tromey <tromey@redhat.com> + + * java/lang/Character.java (MIN_SURROGATE, MAX_SURROGATE): New + constants. + (isHighSurrogate): New method. + (isLowSurrogate): Likewise. + (isSurrogatePair): Likewise. + (toCodePoint): Likewise. + (codePointAt): Likewise. + (codePointBefore): Likewise. + * java/lang/StringBuffer.java (codePointCount): Check bounds. + (codePointAt): Rewrote. + (codePointBefore): Likewise. + * java/lang/String.java (codePointAt): New method. + (codePointBefore): Likewise. + (codePointCount): Likewise. + (contentEquals): New overload. + +2005-09-16 Robert Schuster <robertschuster@fsfe.org> + + * javax/swing/ProgressMonitor: Implemented the former stubbed + class and added documentation. + (close): Implemented and added documentation. + (setProgress): Dito. + (isCanceled): Dito. + (setMinimum): Added documentation. + (getMinimum): Dito. + (setMaximum): Dito. + (getMaximum): Dito. + (setNote): Dito. + (getMillisToDecideToPopup): Dito. + (setMillisToDecideToPopup): Dito. + (getMillisToPopup): Dito. + (setMillisToPopup): Dito. + (getNote): Dito. + * javax/swing/ProgressMonitorInputStream: Implemented stub + methods. + (close): Implemented. + (read): Dito. + (reset): Dito. + (skip): Dito. + (getProgressMonitor): Dito. + +2005-09-16 Tom Tromey <tromey@redhat.com> + + PR classpath/23882: + * java/text/StringCharacterIterator.java (StringCharacterIterator): + Javadoc fix. + (hashCode): New method. + * java/text/ParsePosition.java (hashCode): New method + +2005-09-16 Audrius Meskauskas <AudriusA@Bioinformatics.org> + + * javax/swing/Timer.java (Waker.run): Do not enter loop on + repeats = false (fixes #23918). + +2005-09-16 Andrew Haley <aph@redhat.com> + + * java/io/ObjectStreamClass.java (findAccessibleMethod): Allow + protected readResolve(). Rewrite accessibility check. + +2005-09-16 Andrew Haley <aph@redhat.com> + + * scripts/loc: New file. + +2005-09-16 Anthony Green <green@redhat.com> + + * java/lang/String.java (getBytes): Throw an InternalError instead + of silently returning null. + +2005-09-16 Lillian Angel <langel@redhat.com> + + Fixes Bug #22610 + * java/awt/Container.java + (remove): Removed component listeners from the component + being removed. This was a problem if that same component + that was removed was added to a new component. + +2005-09-16 David Gilbert <david.gilbert@object-refinery.com> + + * javax/swing/plaf/metal/MetalComboBoxEditor.java + (MetalComboBoxEditorBorder.paintBorder): modified border appearance. + +2005-09-16 David Gilbert <david.gilbert@object-refinery.com> + + * javax/swing/plaf/basic/BasicComboBoxRenderer.java: updated API docs + and minor reformatting. + +2005-09-16 Roman Kennke <kennke@aicas.com> + + * javax/swing/JList.java + (AccessibleJList): New inner class. + +2005-09-16 David Gilbert <david.gilbert@object-refinery.com> + + * examples/gnu/classpath/examples/swing/ButtonDemo.java: new file. + +2005-09-16 David Gilbert <david.gilbert@object-refinery.com> + + * javax/swing/plaf/metal/MetalIconFactory.java + (RadioButtonIcon.paintIcon): change color of selection indicator + according to component state. + +2005-09-16 David Gilbert <david.gilbert@object-refinery.com> + + * javax/swing/plaf/metal/MetalCheckBoxIcon.java + (drawCheck): change color according to component state. + +2005-09-16 David Gilbert <david.gilbert@object-refinery.com> + + * javax/swing/plaf/metal/MetalBorders.java + (ButtonBorder.paintBorder): draw a different border for a disabled + button. + +2005-09-15 Tom Tromey <tromey@redhat.com> + + * java/lang/EnumConstantNotPresentException.java: New file. + +2005-09-15 Anthony Green <green@redhat.com> + + * java/awt/Color.java (RGBtoHSB): Don't use integer division when + calculating saturation. + * java/awt/Rectangle.java (equals): Explain why hashCode() isn't + required. + * java/awt/Point.java (equals): Ditto. + + * java/util/zip/ZipFile.java (checkZipFile): Make sure we read the + 4 byte magic number. + +2005-09-15 Tom Tromey <tromey@redhat.com> + + * javax/swing/text/html/parser/DTD.java (FILE_VERSION): Now + final. + +2005-09-15 Tom Tromey <tromey@redhat.com> + + * javax/naming/Name.java: Extends Comparable. + +2005-09-15 Anthony Balkissoon <abalkiss@redhat.com> + + * java/awt/Component.java: + (isDisplayable): Don't check the parent's displayability, only return + true if peer is non-null and false if peer is null. + +2005-09-15 David Gilbert <david.gilbert@object-refinery.com> + + * javax/swing/SwingUtilities.java + (layoutCompoundLabel): check for empty text string, + * javax/swing/plaf/basic/BasicButtonUI.java + (paint): check isBorderPainted() when calculating view rect, + * javax/swing/plaf/basic/BasicInternalFrameTitlePane.java + (CloseAction): new constructor, + (IconifyAction): new constructor, + (MaximizeAction): new constructor, + (MoveAction): new constructor, + (RestoreAction): new constructor, + (SizeAction): new constructor, + (TitlePaneLayout.layoutContainer): calculate button widths from icon + widths, + (installDefaults): initialise icon fields, + (uninstallDefaults): clear icon fields, + (createButtons): set button text to null, + (setButtonIcons): use icon fields. + +2005-09-15 Lillian Angel <langel@redhat.com> + + * javax/swing/plaf/basic/BasicComboBoxRenderer.java + (getListCellRendererComponent): Added code in to check if string + is larger than comboBox. If it is, the string is truncated and + '...' is drawn at the end of it. + * javax/swing/plaf/basic/BasicComboBoxUI.java + (getDefaultSize): Initially too small, still not fully implemented. + (getLargestItemSize): Made private, not in API. + (minimumLayoutSize): Implemented properly. + (intervalAdded): ComboBox should not be resized with every new + component. This is fixed. + 2005-09-15 Tom Tromey <tromey@redhat.com> * java/lang/EnumConstantNotPresentException.java: New file. +2005-09-15 Anthony Balkissoon <abalkiss@redhat.com> + + * javax/swing/plaf/basic/BasicInternalFrameUI.java: + Reformatted file. + +2005-09-15 Lillian Angel <langel@redhat.com> + + Fixes Bug #23678 + * javax/swing/plaf/basic/BasicFileChooserUI.java + (CBLabelRenderer): Removed. Not in API, and it is really + redundant to have. + (installComponents): Changed the renderer set for the combo box. + Also, added the buttonPanel to the parentsPanel, so they are + always painted correctly. Set the FlowLayout to LEFT + instead of default being CENTER. + +2005-09-15 Anthony Balkissoon <abalkiss@redhat.com> + + * javax/swing/JRootPane.java: + (setContentPane): Remove the old content pane first. Throw + IllegalComponentStateException if the parameter is null. Added docs. + +2005-09-15 Tom Tromey <tromey@redhat.com> + + Workaround for PR classpath/23863: + * native/fdlibm/mprec.h (MAX_BIGNUM_WDS): Define as 128 on + non-Pack_32 platforms. + +2005-09-15 Anthony Balkissoon <abalkiss@redhat.com> + + * java/awt/Component.java: + (isDisplayable): Return true if peer != null. + * java/awt/Window.java: + (isDisplayable): Removed this method. Now inherits from Component. + +2005-09-15 Anthony Green <green@redhat.com> + + * java/io/PushbackInputStream.java (available, read, skip): Handle + closed stream operations gracefully. + +2005-09-15 Anthony Green <green@redhat.com> + + * java/nio/charset/Charset.java: close() each stream we open. + * java/net/URLStreamHandler.java: Remove redundant null pointer + check. + * java/security/Identity.java (equals, identityEquals): Don't use + `==' to compare uninterned Strings. Use String.equals(). + * java/lang/Class.java (pd): Mark this field as transient for + FindBugs won't complain (although not strictly necessary). + +2005-09-15 Anthony Balkissoon <abalkiss@redhat.com> + + * javax/swing/JTextArea.java: + (append): Changed invalidate call to revalidate call. + (setRows): Likewise. + (setColumns): Likewise. + +2005-09-15 Lillian Angel <langel@redhat.com> + + Fixes #23873 + * javax/swing/plaf/basic/BasicOptionPaneUI.java + (createMessageArea): Changed orientation of message from EAST to + CENTER. Also, fixed empty border values to make message more centered. + * javax/swing/JOptionPane.java + (showConfirmDialog): Added check for pane.getValue, since clicking on + 'x' of window does not have an initialized value. Was causing a + ClassCastException. + (showConfirmDialog): Likewise. + (showConfirmDialog): Likewise. + (showConfirmDialog): Likewise. + +2005-09-15 David Gilbert <david.gilbert@object-refinery.com> + + * javax/swing/plaf/basic/BasicButtonUI.java + (installDefaults): set font, + (uninstallDefaults): clear font, + * javax/swing/plaf/metal/MetalLookAndFeel.java + (initComponentDefaults): update ToggleButton defaults, + * javax/swing/plaf/metal/MetalToggleButtonUI.java + (instance): removed field, + (createUI): just return new instance every time, + (MetalToggleButtonUI): look up defaults directly, + (getFocusColor): return value from field initialised in constructor, + (getSelectColor): likewise, + (getDisabledTextColor): likewise, + (installDefaults): override to make public, + (paintButtonPressed): implemented, + (paintText): implemented, + (paintFocus): implemented. + +2005-09-15 David Gilbert <david.gilbert@object-refinery.com> + + * javax/swing/plaf/metal/MetalBorders.java + (toggleButtonBorder): new private field, + (ToggleButtonBorder): new class, + (getToggleButtonBorder): new method. + +2005-09-14 Roman Kennke <kennke@aicas.com> + + * javax/swing/text/DefaultStyledDocument.java + (insertUpdate): Tweaked attribute comparison to avoid NPE. + +2005-09-14 Roman Kennke <kennke@aicas.com> + + * javax/swing/text/DefaultStyledDocument.java + (insertUpdate): Tweaked attribute comparison to avoid NPE. + * javax/swing/text/GlyphView.java + (DefaultGlyphPainter.getBoundedPosition): Implemented. + (DefaultGlyphPainter.viewToModel): Implemented. + (getTabExpander): Don't be specific to ParagraphView here. All + parents that implement TabExpander can be accepted. + (getBeginIndex): Removed. This method is not documented in the + specs. + (getBreakWeight): Implemented. + (changedUpdate): Implemented. + (insertUpdate): Implemented. + (removeUpdate): Implemented. + (createFragment): Implemented. + (breakView): Use createFragment. + * javax/swing/text/Utilities.java + (getTabbedTextOffset): Implemented both variants of this method. + +2005-09-14 Audrius Meskauskas <AudriusA@Bioinformatics.org> + + * gnu/CORBA/Connected_objects.java (equals), + * gnu/CORBA/Poa/activeObjectMap.java (equals): Removed, fixes + #23879. + * gnu/CORBA/Version.java (hashCode), + * gnu/CORBA/gnuAny.java (hashCode): New method, fixes #23879. + +2005-09-14 Lillian Angel <langel@redhat.com> + + * javax/swing/JProgressBar.java + (JProgressBar): Fixed to use setOrientation function. + * javax/swing/plaf/metal/MetalProgressBarUI.java + (createUI): Was using the same instance of the UI for + each new JProgressBar. Fixed this. + * javax/swing/plaf/basic/BasicTreeUI.java + (installUI): Added call to prepareForUIInstall. + (uninstallUI): Added call to prepareForUIUninstall. + +2005-09-14 Anthony Balkisoon <abalkiss@redhat.com> + + * javax/swing/text/ComponentView.java: + (createComponent): Implemented. + +2005-09-14 Audrius Meskauskas <AudriusA@Bioinformatics.org> + + * org/omg/CosNaming/NameComponent (hashCode): New method, + fixes #23883). + +2005-09-14 Lillian Angel <langel@redhat.com> + + Fixes Bug #23795 + * javax/swing/plaf/basic/BasicTreeUI.java: + Made private fields package private. + (setCellRenderer): Took out code that updateRenderer takes + care of. + (getPathBounds): Fixed to use treeModel field. + (getPathForRow): Likewise. + (getRowCount): Likewise. + (installComponents): Implemented. + (createNodeDimensions): Implemented. + (uninstallComponents): Implemented. + (getVerticalLegBuffer): Implemented. + (getHorizontalLegBuffer): Implemented. + (updateLayoutCacheExpandedNodes): Implemented. + (updateExpandedDescendants): Implemented. + (updateDepthOffset): Implemented. + (updateRenderer): Implemented. + (updateSize): Implemented. + (installDefaults): Added some more defaults. + (installUI): Moved code to installComponents. + (paint): Fixed to use treeModel field. + (ensureRowsAreVisible): Implemented. + (getMinimumSize): Implemented. + (getMaximumSize): Implemented. + (checkForClickInExpandControl): Implemented. + (isLocationInExpandControl): Implemented. + (handleExpandControlClick): Implemented. + (toggleExpandState): Implemented. + (isToggleSelectionEvent): Implemented. + (isMultiSelectEvent): Implemented. + (isToggleEvent): Implemented. + (selectPathForEvent): Implemented. + (actionPerformed): Changed to use toggleExpandState. + (mousePressed): Fixed code to use helper methods. Made + more efficent. + (TreeCancelEditingAction): Fixed Constructor signature. + (actionPerformed): Fixed to use treeModel field. + (paintRecursive): Fixed to use line drawing helper methods. + (paintControlIcons): Fixed to use control icons helper methods. + (getCurrentControlIcon): New method. + (findNode): Changed to use treeModel field. + (getNextNode): Likewise. + (getPreviousNode): Likewise. + (getNextSibling): Likewise. + (getPreviousSibling): Likewise. + (getPathToRoot): Likewise. + (drawDashedHorizontalLine): Implemented. + (drawDashedVerticalLine): Implemented. + (paintExpandControl): Implemented. + (paintHorizontalPartOfLeg): New method. + (paintVerticalPartOfLeg): New method. + (paintRow): New method. + (shouldPaintExpandControl): New Method. + * javax/swing/plaf/metal/MetalTreeUI.java: + Added private fields for listeners. + (getHorizontalLegBuffer): Implemented. + (installUI): Implemented. + (uninstallUI): Implemented. + (decodeLineStyle): New method. + (isLocationInExpandControl): Implemented. + (paint): Implemented. + (paintHorizontalSeparators): New method. + (paintVerticalPartOfLeg): Implemented. + (paintHorizontalPartOfLeg): Implemented. + +2005-09-14 Anthony Balkissoon <abalkiss@redhat.com> + + * javax/swing/JTextArea.java: + (append): After non-empty append, invalidate. + (setRows): If number of rows changes, invalidate. + (setColumns): If number of columns changes, invalidate. + +2005-09-14 Anthony Green <green@redhat.com> + + * java/net/InetSocketAddress.java (toString): Adjust to match Sun + JRE output, which is [HOSTNAME]/[IPADDRESS]:[PORT]. + * gnu/java/security/der/DERReader.java: Remove stray semicolon. + * gnu/xml/pipeline/ValidationConsumer.java: Fix flags test (was + constant expression). + * javax/swing/plaf/basic/BasicFileChooserUI.java, + * javax/swing/filechooser/FileSystemView.java, + * java/util/logging/LogManager.java, + * gnu/xml/libxmlj/dom/GnomeDocument.java, + * gnu/xml/aelfred2/JAXPFactory.java, + * gnu/java/security/x509/ext/Extension.java, + * gnu/java/security/x509/ext/BasicConstraints.java, + * gnu/java/rmi/server/RMIObjectInputStream.java, + * gnu/java/rmi/dgc/DGCImpl_Stub.java, + * gnu/java/beans/decoder/BooleanHandler.java: Use + Boolean.valueOf() instead of new Boolean. + +2005-09-13 Tom Tromey <tromey@redhat.com> + + * java/lang/StringBuffer.java (StringBuffer): New constructor. + (trimToSize): New method. + (codePointAt): Likewise. + (codePointBefore): Likewise. + (codePointCount): Likewise. + (appendCodePoint): Likewise. + (append): New overloads. + (insert): Likewise. + +2005-09-13 Tom Tromey <tromey@redhat.com> + + * java/lang/Character.java: Typo fixes in javadoc. + +2005-09-14 Roman Kennke <kennke@aicas.com> + + * javax/swing/plaf/basic/BasicTabbedPaneUI.java + (calculateTabWidth): Don't use the calcRect here. This lead to an + inconsistent state when this method is called from another method + that also uses calcRect. + (calculateTabHeight): Don't use the calcRect here. This lead to an + inconsistent state when this method is called from another method + that also uses calcRect. + +2005-09-14 Roman Kennke <kennke@aicas.com> + + * javax/swing/plaf/basic/BasicTabbedPaneUI.java: + Reformatted file. + +2005-09-14 Andrew John Hughes <gnu_andrew@member.fsf.org> + + * java/io/ObjectInputStream.java: + (readObject()): Moved marker parsing to its own method. + (parseContent(byte)): Fixed TC_OBJECT handling to loop on + blockdata written manually by the class. + +2005-09-14 Christian Thalinger <twisti@complang.tuwien.ac.at> + + * native/jni/classpath/jcl.c: Replaced undefined + POINTERS_ARE_64BIT with SIZEOF_VOID_P == 8. + +2005-09-14 David Gilbert <david.gilbert@object-refinery.com> + + * javax/swing/plaf/metal/MetalIconFactory.java + (PaletteCloseIcon): now implements UIResource. + +2005-09-14 Roman Kennke <kennke@aicas.com> + + * javax/swing/ButtonModel.java: Added API docs all over. + +2005-09-14 Roman Kennke <kennke@aicas.com> + + * javax/swing/JTabbedPane.java: Added API comments to make clear + that null values for tab titles are allowed. + +2005-09-14 Roman Kennke <kennke@aicas.com> + + Fixes Bug#23859. + * javax/swing/JTabbedPane.java + (insertTab): Check if title == null and if so, then set it + to "". Otherwise the null string would cause a segfault or + an assertion failure in font metrics calculation as reported + in bug#23859. + +2005-09-14 David Gilbert <david.gilbert@object-refinery.com> + + * gnu/CORBA/ExceptionCreator.java: minor API doc fixes, + * gnu/CORBA/Version.java: likewise. + +2005-09-14 David Gilbert <david.gilbert@object-refinery.com> + + * javax/swing/plaf/basic/BasicFormattedTextFieldUI.java: + (getPropertyPrefix): added API docs, + * javax/swing/plaf/basic/BasicPasswordFieldUI.java: + (getPropertyPrefix): added API docs, + * javax/swing/plaf/basic/BasicTextAreaUI.java: + (getPropertyPrefix): added API docs, + * javax/swing/plaf/basic/BasicTextFieldUI.java: + (getPropertyPrefix): added API docs, + * javax/swing/plaf/basic/BasicTextPaneUI.java: + (getPropertyPrefix): added API docs. + +2005-09-14 David Gilbert <david.gilbert@object-refinery.com> + + * org/omg/CORBA/ORB.java: minor API doc fixes, + * org/omg/CORBA/PERSIST_STORE.java: likewise, + * org/omg/CORBA/PolicyError.java: likewise, + * org/omg/CORBA/ValueBaseHolder.java: likewise, + * org/omg/CORBA/VisibilityHelper.java: likewise. + +2005-09-14 David Gilbert <david.gilbert@object-refinery.com> + + * javax/swing/plaf/metal/MetalComboBoxIcon.java: fixed header, + (paintIcon): change color to reflect component state. + +2005-09-13 Tom Tromey <tromey@redhat.com> + + * .settings/org.eclipse.jdt.core.prefs: Ignore javadoc warnings + for hidden or deprecated members. + +2005-09-14 Roman Kennke <kennke@aicas.com> + + * javax/swing/text/AbstractDocument.java + Bumped up serialVersionUIDs to JDK 1.5 compatibility. + (getContent): Made method final. + (AbstractElement.dumpElement): Removed superfluous private method. + (AbstractElement.dump): Made diagnostic output more speaking. + * javax/swing/text/BoxView.java + (paintChild): Don't allocate the child region here. + (paint): Allocate the child region here instead. + * javax/swing/text/ComponentView.java: + Added API doc comments. + * javax/swing/text/CompositeView.java + (getNextVisualPositionFrom): Declared to throw BadLocationException. + (getNextNorthSouthVisualPositionFrom): Likewise. + (getNextEastWestVisualPositionFrom): Likewise. + * javax/swing/text/DefaultCaret.java + Bumped up serialVersionUIDs to JDK 1.5 compatibility. + * javax/swing/text/DefaultEditorKit.java + Slight reformatting. + * javax/swing/text/DefaultFormatter.java + Bumped up serialVersionUIDs to JDK 1.5 compatibility. + * javax/swing/text/DefaultStyledEditorKit.java + (ElementBuffer.insertUpdate): Removed unneeded statement. + (ElementBuffer.insertStartTag): Attach a resolve parent to new + paragraph elements. + (createDefaultRoot): Attach a resolve parent to new paragraph + elements. + * javax/swing/text/InternationalFormatter.java + Bumped up serialVersionUIDs to JDK 1.5 compatibility. + * javax/swing/text/JTextComponent.java + Slight reformatting. + (paramString): Added TODO comment. + * javax/swing/text/SimpleAttributeSet.java + Bumped up serialVersionUIDs to JDK 1.5 compatibility. + (equals): Don't require object to be SimpleAttributeSet. Allows + comparing to all kinds of AttributeSets. + (isEqual): Likewise. + * javax/swing/text/StringContent.java + Bumped up serialVersionUIDs to JDK 1.5 compatibility. + * javax/swing/text/StyleConstants.java + (getBackground): Return white as default background instead of black. + * javax/swing/text/StyleConstext.java + Bumped up serialVersionUIDs to JDK 1.5 compatibility. + (SmallAttributeSet.equals): Don't require object to be + SmallAttributeSet. Allows comparing to all kinds of AttributeSets. + * javax/swing/text/StyledEditorKit.java + Fixed some comments. + * javax/swing/text/TabSet.java + Bumped up serialVersionUIDs to JDK 1.5 compatibility. + * javax/swing/text/TabStop.java + Bumped up serialVersionUIDs to JDK 1.5 compatibility. + * javax/swing/text/View.java + Removed unneeded import. + +2005-09-14 Robert Schuster <robertschuster@fsfe.org> + + * javax/swing/JOptionPane.java: + (showConfirmDialog): Changed QUESTION_MESSAGE like the JDK + does. + * javax/swing/plaf/basic/BasicOptionPaneUI.java: + (getButtons): Treat DEFAULT_OPTION like + YES_NO_CANCEL_OPTION like the JDK. + +2005-09-14 Roman Kennke <kennke@aicas.com> + + * javax/swing/text/GapContent.java + (GapContentPosition.getOffset): Made assertion more speaking. + (GapContent): Modified initialization for compatibility with JDK. + (shiftEnd): Update marks prior to modification of the content. + Use new getPositionsInRange method. + (shiftGap): Use new getPositionsInRange method. Tweaked to corectly + update the marks. + (shiftGapStartDown): New method. + (shiftGapEndUp): New method. + (replace): Use shiftGapEndUp. Modified resizing offset. + (getGapStart): New method. + (getGapEnd): New method. + (getPositionsInRange): New method. + +2005-09-14 Roman Kennke <kennke@aicas.com> + + * javax/swing/text/GlyphView.java + (AbstractGlyphPainter.getAscent): New abstract method. + (AbstractGlyphPainter.getDescent): New abstract method. + (AbstractGlyphPainter.getBoundedPosition): New abstract method. + (AbstractGlyphPainter.viewToModel): New abstract method. + (AbstractGlyphPainter.getNextVisualPositionFrom): New method. + (AbstractGlyphPainter.getPainter): New method. + (DefaultGlyphPainter.paint): Add support for more text attributes. + (DefaultGlyphPainter.getAscent): New method. + (DefaultGlyphPainter.getDescent): New method. + (DefaultGlyphPainter.getBoundedPosition): New method. + (DefaultGlyphPainter.viewToModel): New method. + (GlyphView): Store start and end offset in the GlyphView. + (getPreferredSpan): Differentiate the axis parameter. + (viewToModel): Implemented this method. + (getStartOffset): Return value of private field instead of the + element value. + (getEndOffset): Return value of private field instead of the + element value. + (getBackground): New method. + (isStrikeThrough): New method. + (isSubscript): New method. + (isSuperscript): New method. + (isUnderline): New method. + (clone): New method. + (breakView): New method. + (getBreakWeight): New method. + (changedUpdate): New method. + (insertUpdate): New method. + (removeUpdate): New method. + (createFragment): New method. + (getAlignment): New method. + (getNextVisualPositionFrom): New method. + +2005-09-13 Tom Tromey <tromey@redhat.com> + + * java/util/regex/Matcher.java (matches): Javadoc fix. + (start): Likewise. + * java/lang/reflect/Proxy.java (equals): Javadoc fix. + * java/io/ObjectInputStream.java (inputGetObjectStreamClasses): Javadoc + fix. + * java/util/zip/ZipFile.java (getEntry): Javadoc fix. + * java/util/logging/XMLFormatter.java (getHead): Javadoc fix. + * java/util/logging/LogManager.java (getLevelProperty): Javadoc fix. + * java/util/logging/Handler.java (getEncoding): Javadoc fix. + (setFilter): Likewise. + * java/util/logging/FileHandler.java: Organized imports. + * java/util/jar/Manifest.java (Manifest): Javadoc fix. + * java/util/TreeMap.java (putFromObjStream): Javadoc fix. + * java/util/SimpleTimeZone.java (isBefore): Javadoc fix. + * java/util/ResourceBundle.java (tryBundle): Javadoc fix. + * java/util/Random.java (seed): Javadoc fix. + * java/util/Collections.java (SynchronizedSortedSet): Javadoc fix. + (SingletonMap): Likewise. + (addAll): Javadoc fix. + * java/lang/reflect/UndeclaredThrowableException.java: Javadoc fix. + * java/lang/reflect/Member.java (DECLARED, PUBLIC): Javadoc fix. + * java/lang/ref/WeakReference.java: Javadoc fix. + * java/lang/ref/Reference.java: Javadoc fix. + (Reference): Likewise. + * java/lang/Thread.java (setContextClassLoader): Javadoc fix. + (getContextClassLoader): Likewise. + (stop): Likewise. + * java/lang/System.java (runFinalizersOnExit): Javadoc fix. + * java/lang/String.java (upperExpand): Javadoc fix. + * java/lang/StrictMath.java: Javadoc fixes. + * java/lang/SecurityManager.java: Added imports for javadoc. + (currentClassLoader): Javadoc fix. + (classLoaderDepth): Likewise. + (currentLoadedClass): Likewise. + (checkRead): Likewise. + (checkWrite): Likewise. + (checkAccess): Likewise. + * java/lang/RuntimePermission.java: Added import for javadoc. + * java/lang/Readable.java (read): Added import for javadoc. + +2005-09-13 Casey Marshall <csm@gnu.org> + + * gnu/classpath/ByteArray.java: new file. + * gnu/java/security/provider/Gnu.java + (<init>): add Diffie Hellman and RSA algorithms. + * gnu/javax/crypto/DiffieHellmanImpl.java: new file. + * gnu/javax/crypto/GnuDHPrivateKey.java: new file. + * gnu/javax/crypto/RSACipherImpl.java: new file. + +2005-09-13 David Gilbert <david.gilbert@object-refinery.com> + + * javax/swing/plaf/metal/MetalComboBoxButton.java: new file, + * javax/swing/plaf/metal/MetalComboBoxEditor.java: likewise. + +2005-09-13 Tom Tromey <tromey@redhat.com> + + * java/lang/Process.java: Added import for javadoc. + * java/lang/Object.java (notify): Javadoc fix. + (notifyAll): Likewise. + * java/io/PipedInputStream.java (connect): Javadoc fix. + * java/io/OutputStreamWriter.java: Organized imports. + * java/io/ObjectStreamField.java (setOffset): Javadoc fix. + * java/io/ObjectInputStream.java (readFields): Javadoc fix. + * java/io/DataOutputStream.java (writeChars): Javadoc fix. + (writeFloat): Likewise. + (writeDouble): Likewise. + * java/util/Locale.java (readObject): Javadoc fix. + (writeObject): Likewise. + * java/io/LineNumberReader.java (read): Javadoc fix. + (setLineNumber): Likewise. + (mark): Likewise. + * java/io/InputStreamReader.java: Updated imports. + * java/lang/Integer.java (parseInt): Javadoc fix. + * java/io/FilterReader.java (skip): Javadoc fix. + * java/util/HashMap.java (containsValue): Javadoc fix. + * java/lang/ClassLoader.java (findLibrary): Javadoc fix. + (setPackageAssertionStatus): Likewise. + (setClassAssertionStatus): Likewise. + * java/lang/Class.java: Added imports for javadoc. + (matchMethod): Javadoc fix. + * java/util/ArrayList.java (readObject): Javadoc fix. + (writeObject): Likewise. + * java/lang/String.java (CaseInsensitiveComparator): Javadoc fix. + * java/util/zip/PendingBuffer.java (toByteArray): Javadoc fix. + * javax/swing/plaf/metal/OceanTheme.java: Mark as 1.5. + * java/util/logging/SimpleFormatter.java (format): Javadoc fix. + * java/util/zip/ZipFile.java (getEntries): Javadoc fix. + +2005-09-13 David Gilbert <david.gilbert@object-refinery.com> + + * javax/swing/plaf/basic/BasicComboBoxUI.java + (lightHighlight): removed, + (installDefaults): only update component attributes if they are tagged + with UIResource, initialise button colors from correct defaults, + (uninstallDefaults): only clear attributes that are tagged with + UIResource. + +2005-09-13 Lillian Angel <langel@redhat.com> + + * javax/swing/JTree.java + (AccessibleJTree): Added new Inner class. + (AccessibleJTree.addAccessibleSelection): New method. + (AccessibleJTree.clearAccessibleSelection): New method. + (AccessibleJTree.fireVisibleDataPropertyChange): New method. + (AccessibleJTree.getAccessibleAt): New method. + (AccessibleJTree.getAccessibleChild): New method. + (AccessibleJTree.getAccessibleChildrenCount): New method. + (AccessibleJTree.getAccessibleIndexInParent): New method. + (AccessibleJTree.getAccessibleRole): New method. + (AccessibleJTree.getAccessibleSelection): New method. + (AccessibleJTree.getAccessibleSelection): New method. + (AccessibleJTree.getAccessibleSelectionCount): New method. + (AccessibleJTree.isAccessibleChildSelected): New method. + (AccessibleJTree.removeAccessibleSelection): New method. + (AccessibleJTree.selectAllAccessibleSelection): New method. + (AccessibleJTree.treeCollapsed): New method. + (AccessibleJTree.treeExpanded): New method. + (AccessibleJTree.treeNodesChanged): New method. + (AccessibleJTree.treeNodesInserted): New method. + (AccessibleJTree.treeNodesRemoved): New method. + (AccessibleJTree.treeStructureChanged): New method. + (AccessibleJTree.valueChanged): New method. + (AccessibleJTreeNode): Likewise. + (AccessibleJTreeNode.addAccessibleSelection): New method. + (AccessibleJTreeNode.addFocusListener): New method. + (AccessibleJTreeNode.addPropertyChangeListener): New method. + (AccessibleJTreeNode.clearAccessibleSelection): New method. + (AccessibleJTreeNode.contains): New method. + (AccessibleJTreeNode.doAccessibleAction): New method. + (AccessibleJTreeNode.getAccessibleAction): New method. + (AccessibleJTreeNode.getAccessibleActionCount): New method. + (AccessibleJTreeNode.getAccessibleActionDescription): New method. + (AccessibleJTreeNode.getAccessibleAt): New method. + (AccessibleJTreeNode.getAccessibleChild): New method. + (AccessibleJTreeNode.getAccessibleChildrenCount): New method. + (AccessibleJTreeNode.getAccessibleComponent): New method. + (AccessibleJTreeNode.getAccessibleContext): New method. + (AccessibleJTreeNode.getAccessibleDescription): New method. + (AccessibleJTreeNode.getAccessibleIndexInParent): New method. + (AccessibleJTreeNode.getAccessibleName): New method. + (AccessibleJTreeNode.getAccessibleParent): New method. + (AccessibleJTreeNode.getAccessibleRole): New method. + (AccessibleJTreeNode.getAccessibleSelection): New method. + (AccessibleJTreeNode.getAccessibleSelectionCount): New method. + (AccessibleJTreeNode.getAccessibleStateSet): New method. + (AccessibleJTreeNode.getAccessibleText): New method. + (AccessibleJTreeNode.getAccessibleValue): New method. + (AccessibleJTreeNode.getBackground): New method. + (AccessibleJTreeNode.getBounds): New method. + (AccessibleJTreeNode.getCursor): New method. + (AccessibleJTreeNode.getFont): New method. + (AccessibleJTreeNode.getFontMetrics): New method. + (AccessibleJTreeNode.getForeground): New method. + (AccessibleJTreeNode.getLocale): New method. + (AccessibleJTreeNode.getLocation): New method. + (AccessibleJTreeNode.getLocationInJTree): New method. + (AccessibleJTreeNode.getLocationOnScreen): New method. + (AccessibleJTreeNode.getSize): New method. + (AccessibleJTreeNode.isAccessibleChildSelected): New method. + (AccessibleJTreeNode.isEnabled): New method. + (AccessibleJTreeNode.isVisible): New method. + (AccessibleJTreeNode.removeAccessibleSelection): New method. + (AccessibleJTreeNode.removeFocusListener): New method. + (AccessibleJTreeNode.removePropertyChangeListener): New method. + (AccessibleJTreeNode.requestFocus): New method. + (AccessibleJTreeNode.selectAllAccessibleSelection): New method. + (AccessibleJTreeNode.setAccessibleDescription): New method. + (AccessibleJTreeNode.setAccessibleName): New method. + (AccessibleJTreeNode.setBackground): New method. + (AccessibleJTreeNode.setBounds): New method. + (AccessibleJTreeNode.setCursor): New method. + (AccessibleJTreeNode.setEnabled): New method. + (AccessibleJTreeNode.setFont): New method. + (AccessibleJTreeNode.setForeground): New method. + (AccessibleJTreeNode.setLocation): New method. + (AccessibleJTreeNode.setVisible): New method. + (removeDescendantToggledPaths): Implemented. + (treeDidChange): Implemented. + +2005-09-13 Thomas Fitzsimmons <fitzsim@redhat.com> + + * native/jawt/jawt.c (_Jv_AWTLock): Do nothing. + (_Jv_AWTUnlock): Likewise. + +2005-09-13 David Daney <ddaney@avtrex.com> + + * java/io/ByteArrayOutputStream.java: Reformated copyright notice. + (toString(int)): Pass correct parameters to String constructor. + +2005-09-13 David Gilbert <david.gilbert@object-refinery.com> + + * javax/swing/JComboBox.java + (getPrototypeDisplayValue): added API docs, + (setPrototypeDisplayValue): fire property change event. + +2005-09-13 Roman Kennke <kennke@aicas.com> + + * javax/swing/text/DefaultStyledDocument.java + (ElementSpec): New inner class. + (ElementBuffer.change): Also store the DefaultDocumentEvent. + (ElementBuffer.split): Also update the document event. + (ElementBuffer.insert): New method. + (ElementBuffer.insertUpdate): New method. + (ElementBuffer.insertStartTag): New method. + (ElementBuffer.insertEndTag): New method. + (ElementBuffer.insertContentTag): New method. + (SectionElement): New inner class. + (createDefaultRoot): Return SectionElement instead of BranchElement. + (getParagraphElement): Optimized access to paragraph element. + (setCharacterAttributes): Fire changedUpdate after modification. + (insertUpdate): New method. + +2005-09-13 Roman Kennke <kennke@aicas.com> + + * javax/swing/SizeRequirements.java + (toString): Implemented this method. + (calculateAlignedPositions): Partly implemented this method. + +2005-09-13 Roman Kennke <kennke@aicas.com> + + * javax/swing/JTabbedPane.java: Added API comments all over. + +2005-09-13 Roman Kennke <kennke@aicas.com> + + * javax/swing/JTree.java: Reformatted file. + * javax/swing/ListCellRenderer.java: Likewise. + * javax/swing/ListSelectionModel.java: Likewise. + * javax/swing/MenuElement.java: Likewise. + * javax/swing/OverlayLayout.java: Likewise. + * javax/swing/ProgressMonitor.java: Likewise. + * javax/swing/ProgressMonitorInputStream.java: Likewise. + * javax/swing/Renderer.java: Likewise. + * javax/swing/RepaintManager.java: Likewise. + * javax/swing/RootPaneContainer.java: Likewise. + * javax/swing/Scrollable.java: Likewise. + * javax/swing/SingleSelectionModel.java: Likewise. + * javax/swing/SizeSequence.java: Likewise. + * javax/swing/SpinnerListModel.java: Likewise. + * javax/swing/UnsupportedLookAndFeelException.java: Likewise. + * javax/swing/ViewportLayout.java: Likewise. + * javax/swing/WindowConstants.java: Likewise. + +2005-09-12 Tom Tromey <tromey@redhat.com> + + * .settings/org.eclipse.jdt.core.prefs: Enable javadoc warnings. + +2005-09-12 Tom Tromey <tromey@redhat.com> + + * java/lang/ThreadLocal.java: Organized imports. + * java/lang/Double.java: Organized imports. + +2005-09-12 Casey Marshall <csm@gnu.org> + + PR 23819 + * javax/security/auth/Subject.java (SecureSet.<init>): rename + input paremeter to 'inElements.' + (SecureSet.contains): return 'elements.contains,' not + 'elements.remove.' + + PR 23822 + * javax/security/auth/SubjectDomainCombiner.java + (combine): don't access 'subject' if null. + +2005-09-12 David Gilbert <david.gilbert@object-refinery.com> + + * examples/gnu/classpath/examples/swing/Demo.java + (mkDesktopWorld): add palette style frame, + * javax/swing/plaf/basic/BasicInternalFrameTitlePane.java + (closeIcon): new field, + (installListeners): call createPropertyChangeListener() to create the + new listener to allow for overriding, + (installDefaults): set the font in the title, read closeIcon from + defaults, + (uninstallDefaults): clear closeIcon, + (setButtonIcons): set icon for closeButton, + (paintComponent): set font for title, + * javax/swing/plaf/metal/MetalInternalFrameTitlePane.java + (MetalInternalFrameTitlePanePropertyChangeHandler): new support class, + (MetalTitlePaneLayout): likewise, + (paletteTitleHeight): initialise from defaults elsewhere, + (title): new private field, + (installDefaults): initialise various defaults, + (uninstallDefaults): clear defaults, + (addSubComponents): add sub-components used in this look and feel, + (createLayout): return new instance of MetalTitlePaneLayout, + (paintPalette): renders the title pane using the palette style, + (paintComponent): call paintPalette() if the internal frame uses the + palette style, otherwise handle painting without calling superclass + anymore, + (setPalette): update the icon visibility, + (createPropertyChangeListener): return a new change handler, + * javax/swing/plaf/metal/MetalInternalFrameUI.java + (IS_PALETTE): new static field, + (installUI): check IS_PALETTE property, + (createNorthPane): removed empty border, + (setPalette): update border as appropriate, + (paletteListener): new private field, + (installListeners): install a listener to handle changes in the + IS_PALETTE property, + (uninstallListeners): clear the listener from installListeners(), + * javax/swing/plaf/metal/MetalLookAndFeel.java + (initComponentDefaults): added defaults for 'DesktopIcon.border', + 'InternalFrame.paletteBorder', 'InternalFrame.paletteCloseIcon', and + 'InternalFrame.paletteTitleHeight'. + +2005-09-12 David Gilbert <david.gilbert@object-refinery.com> + + * javax/swing/JComponent.java + (putClientProperty): fire property change event. + +2005-09-12 Anthony Balkissoon <abalkiss@redhat.com> + + * javax/swing/JScrollPane.java: + (addNonNull): Changed from adding to container with no constraints to + adding to container with the appropriate ScrollPaneConstant as a + constraint. This avoids IllegalArgumentExceptions in ScrollPaneLayout. + (setColumnHeader): Added constraint to addNonNull call. + (setCorner): Likewise. + (setHorizontalScrollBar): Likewise. + (setRowHeader): Likewise. + (setVerticalScrollBar): Likewise. + (setViewport): Likewise. + * javax/swing/JViewport.java: + (setViewSize): Don't set the size or fireStateChanged unless the new + size is different from the old size. + (setView): Reset isViewSizeSet to false. + * javax/swing/ScrollPaneLayout: + (addSingletonComponent): Implemented and documented. + (addLayoutComponent): Throw an IllegalArgumentException if key is + not one of the appropriate ScrollPaneConstants constants. Added docs. + (setVerticalScrollBarPolicy): Likewise. + (setHorizontalScrollBarPolicy): Likewise. + (getCorner): Added docs. + +2005-09-12 Roman Kennke <kennke@aicas.com> + + * javax/swing/JCheckBox.java + (AccessibleJCheckBox): New inner class. + (getAccessibleContext): Implemented this method. + * javax/swing/JLayeredPane.java + (AccessibleJLayeredPane): New inner class. + (getAccessibleContext): Implemented this method. + +2005-09-12 Roman Kennke <kennke@aicas.com> + + * javax/swing/JTable.java + (getCellRect): Don't include cell gap in cell rectangle + calculation. It's already included in TableColumnModel.getWidth(). + (createDefaultColumnsFromModel): Initialize table header values. + * javax/swing/plaf/basic/BasicTableUI.java + (paint): Don't include cell gap in cell rectangle + calculation. It's already included in TableColumnModel.getWidth(). + +2005-09-12 Tom Tromey <tromey@redhat.com> + + * org/ietf/jgss/GSSException.java (BAD_BINDINGS, BAD_MECH, + BAD_NAME, BAD_NAMETYPE, CONTEXT_EXPIRED, CREDENTIALS_EXPIRED, + DEFECTIVE_CREDENTIAL, DEFECTIVE_TOKEN, DUPLICATE_TOKEN, FAILURE, + NO_CONTEXT, NO_CRED, OLD_TOKEN): Use values from JDK, not RFC. + +2005-09-12 Thomas Fitzsimmons <fitzsim@redhat.com> + + * lib/Makefile.am (JAVAC): Specify -source 1.4 to ecj. + +2005-09-12 Lillian Angel <langel@redhat.com> + + * javax/swing/tree/DefaultTreeCellEditor.java + (isCellEditable): Stopped the timer if it is started and + should not be restarted. This is a fix for the 'click-pause- + click' method to start editing. + +2005-09-12 Lillian Angel <langel@redhat.com> + + * gnu/java/awt/AWTUtilities.java + (convertPoint): Added a check to determine if source and + destination components are showing. + * javax/swing/JPopupMenu.java + (setVisible): Added check to determine if component is showing. + (show): Likewise. + * javax/swing/MenuSelectionManager.java + (componentForPoint): Added check to determine if component is showing. + * javax/swing/ToolTipManager.java + (showTip): Added check to determine if component is showing. + * javax/swing/plaf/basic/BasicToolBarUI.java + (mousePressed): Added check to determine if component is showing. + +2005-09-12 David Gilbert <david.gilbert@object-refinery.com> + + * javax/swing/plaf/metal/MetalIconFactory.java + (InternalFrameCloseIcon.paintIcon): change colors according to button + state, + (InternalFrameAltMaximizeIcon.paintIcon): likewise, + (InternalFrameMaximizeIcon.paintIcon): likewise, + (InternalFrameMinimizeIcon.paintIcon): likewise. + +2005-09-12 Roman Kennke <kennke@aicas.com> + + * javax/swing/plaf/metal/MetalBorders.java + (TableHeaderBorder): New inner class. + (TextFieldBorder.paintBorder): Only paint the active border + if the text field is enabled _and_ editable. + * javax/swing/plaf/metal/MetalLookAndFeel.java + (initComponentDefaults): Added default to use the new + TableHeaderBorder for table headers. + +2005-09-12 Anthony Balkissoon <abalkiss@redhat.com> + + * java/awt/Container.java: + (findComponentForMouseEventAt): Reduced visibility to package-private. + (getDeepestComponentForMouseEventAt): Reduced visibility to + package-private and removed static modifier. + +2005-09-12 David Gilbert <david.gilbert@object-refinery.com> + + * javax/swing/plaf/metal/MetalBorders.java + (desktopIconBorder): new private field, + (DesktopIconBorder): new support class, + (getDesktopIconBorder): implemented, + (InternalFrameBorder.paintBorder): change color of line highlights if + the internal frame is selected. + +2005-09-12 Chris Burdess <dog@gnu.org> + + * gnu/xml/dom/DomDocument.java: Implementation of xml:id W3C + Recommendation. + +2005-09-12 Roman Kennke <kennke@aicas.com> + + * javax/swing/JTable.java + (TableColumnPropertyChangeHandler): New inner class. Handles + changes of column widths. + (JTable(TableModel, TableColumnModel, ListSelectionModel)): + Check if column model == null and if so, create a default model. + (initializeLocalVars): Changed to use createDefaultColumnsFromModel + instead of createColumnsFromModel. + (addColumn): Add property change handler to new column. + (createColumnsFromModel): Removed redundant private method. + Use the public createDefaultColumnsFromModel instead. + (tableChanged): Use createDefaultColumnsFromModel instead of + createColumnsFromModel. + (setModel): Use createDefaultColumnsFromModel instead of + createColumnsFromModel. + (doLayout): When handling AUTO_RESIZE_OFF, then adjust the + size of the resizing column to it's (new) preferred size. + (createDefaultColumnsFromModel): Added assertion to make sure + that the column model is not null. Add property change handler + to new columns. + * javax/swing/table/TableColumn.java + (setWidth): Fire property change with name 'width' instead + of using the (obsolete) constant field COLUMN_WIDTH_PROPERTY. + (setPreferredWidth): Make this property a bound property. + +2005-09-11 Thomas Fitzsimmons <fitzsim@redhat.com> + + PR swing/22922 + * java/awt/event/InputEvent.java (modifiersEx): New field. + (InputEvent): Assume modifiers parameter contains both new- and + old-style masks. + (isShiftDown): Check modifiers for old-style shift mask and + modifiersEx for new-style shift mask. + (isControlDown): Likewise for control mask. + (isMetaDown): Likewise for meta mask. + (isAltDown): Likewise for alt mask. + (isAltGraphDown): Likewise for alt-graph mask. + (getModifiers): Return value of modifiers field. + (getModifiersEx): Return value of modifiersEx field. + * java/awt/event/MouseEvent.java + (MouseEvent(Component,int,long,int,int,int,int,boolean,int)): + Clear button new-style mask for mouse released events. + (paramString): Remove old-style modifier handling. + (readObject): Extend modifiers and assign to modifiersEx. + * java/awt/event/KeyEvent.java (readObject): Extend modifiers and + assign to modifiersEx. + * native/jni/gtk-peer/gtkpeer.h: Define macros for new-style mouse + masks. Define macros for old-style key masks. + * native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c: + Remove macros for old-style key masks. + (button_to_awt_mods): Always return bitwise OR of new- and + old-style modifiers. + (cp_gtk_state_to_awt_mods): Likewise. + (state_to_awt_mods_with_button_states): Likewise. + * native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c + (keyevent_state_to_awt_mods): Likewise. + +2005-09-11 Mark Wielaard <mark@klomp.org> + + * m4/acinclude.m4 (CLASSPATH_CHECK_GCJ): Check for gcj 4 with + #if __GNUC__ <= 3. + +2005-09-11 Mark Wielaard <mark@klomp.org> + + * lib/gen-classlist.sh.in: Use sort -r to work around bug #21418. + +2005-09-11 Mark Wielaard <mark@klomp.org> + + * gnu/java/nio/channels/FileChannelImpl.java (finalize): Check whether + fd != -1 before calling close(). + +2005-09-10 David Gilbert <david.gilbert@object-refinery.com> + + * javax/swing/plaf/metal/MetalBorders.java + (PaletteBorder): new class. + +2005-09-10 David Gilbert <david.gilbert@object-refinery.com> + + * javax/swing/plaf/metal/MetalIconFactory.java + (PaletteCloseIcon): new class. + +2005-09-10 David Gilbert <david.gilbert@object-refinery.com> + + * javax/swing/plaf/metal/MetalInternalFrameUI.java: + (instances): removed, + (createUI): just return new instance, + API docs all over. + +2005-09-10 Thomas Fitzsimmons <fitzsim@redhat.com> + + * gnu/java/awt/peer/gtk/GdkGraphics2D.java (fail_g2d): New method. + (GdkGraphics2D(GdkGraphics2D)): Call fail_g2d if Graphics2D not + specified. + (GdkGraphics2D(int,int)): Likewise. + (GdkGraphics2D(GtkComponentPeer)): Likewise. + +2005-09-10 Thomas Fitzsimmons <fitzsim@redhat.com> + + * gnu/java/awt/EmbeddedWindow.java (addNotify): Throw + AssertionError if field access fails. + +2005-09-09 Thomas Fitzsimmons <fitzsim@redhat.com> + + * gnu/java/awt/peer/gtk/GdkGraphics2D.java (static): Reindent + second error message. + +2005-09-09 Thomas Fitzsimmons <fitzsim@redhat.com> + + PR awt/23692 + * gnu/java/awt/peer/gtk/GdkGraphics2D.java (static): Only call + initStaticState if using Graphics2D. Otherwise print error and + exit. + (setClip(Shape)): If clip == null and component == null, do + nothing. + +2005-09-09 Thomas Fitzsimmons <fitzsim@redhat.com> + + * gnu/java/awt/peer/gtk/GdkGraphics.java + (GdkGraphics(GtkComponentPeer)): Set font field to a sensible + default if component font is null. + +2005-09-09 Keith Seitz <keiths@redhat.com> + + * vm/reference/gnu/classpath/jdwp/VMIdManager.java (newObjectId): + Set the reference for the ID. + +2005-09-09 Keith Seitz <keiths@redhat.com> + + * gnu/classpath/jdwp/event/VmDeathEvent.java: New file. + +2005-09-09 Tom Tromey <tromey@redhat.com> + + For PR libgcj/23288: + * java/net/URLClassLoader.java (definePackage): Correctly order + arguments to definePackage. Look up per-entry Attributes. + (getAttributeValue): New method. + +2005-09-09 Thomas Fitzsimmons <fitzsim@redhat.com> + + * javax/swing/plaf/basic/BasicTreeUI.java (installUI): Install + defaults after initializing tree. + +2005-09-09 Roman Kennke <kennke@aicas.com> + + * javax/swing/text/html/CSS.java + New file. Defines standard CSS attributes. + +2005-09-09 Thomas Fitzsimmons <fitzsim@redhat.com> + + * java/awt/Window.java (isDisplayable): Do not call super's + isDisplayable. + +2005-09-09 Thomas Fitzsimmons <fitzsim@redhat.com> + + PR swing/23796 + * gnu/java/awt/peer/gtk/GtkDialogPeer.java + (create): Respect dialog's decorated flag. + +2005-09-09 Thomas Fitzsimmons <fitzsim@redhat.com> + + PR swing/23558 + * native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c + (window_get_new_state): Remove function. + (window_get_new_state): Mark widget parameter as unused. Remove + call to window_get_new_state. + (window_active_state_change_cb): Remove function. + (connectSignals): Do not connect window_active_state_change_cb + callback. + +2005-09-09 Thomas Fitzsimmons <fitzsim@redhat.com> + + PR swing/23796 + * gnu/java/awt/peer/gtk/GtkFramePeer.java (create): Respect + frame's decorated flag. + +2005-09-09 Lillian Angel <langel@redhat.com> + + * javax/swing/plaf/basic/BasicTreeUI.java + (installDefaults): Fixed method signature. + (uninstallDefaults): Likewise. + (uninstallUI): Fixed call to uninstallDefaults. + (installUI): Fixed call to installDefaults. + * javax/swing/JPopupMenu.java + (HeavyWeightPopup): Fixed to extend JDialog, since + nothing is added to the taskbar with JDialog. Also, + fixed so the popup menu is undecorated. Frames and + title bars should not be drawn, when popup is a + HeavyWeightPopup. A new bug was filed since the + decorated and undecorated frames are all drawn + alike. + * javax/swing/JRootPane.java + (setWindowDecorationStyle): Added check for + PLAIN_DIALOG. + +2005-09-09 Roman Kennke <kennke@aicas.com> + + * javax/swing/plaf/metal/MetalLookAndFeel.java + (initComponentDefaults): Added the remaining color defaults. + +2005-09-09 Andrew Haley <aph@redhat.com> + + * java/net/URLClassLoader.java (addURLImpl): Synchronize on the + loader. + (toString): Likewise. + +2005-09-09 Jeroen Frijters <jeroen@frijters.net> + + * javax/security/auth/login/Configuration.java + (getConfiguration): Call getConfig() instead of doing the work. + (getConfig): Instantiate the configuration provider. + +2005-09-09 Jeroen Frijters <jeroen@frijters.net> + + * java/lang/reflect/Proxy.java + (pack): Initialize field. + +2005-09-09 Jeroen Frijters <jeroen@frijters.net> + + * java/io/ObjectInputStream.java: Removed static initializer. + * java/io/ObjectOutputStream.java: Removed static initializer. + * vm/reference/java/io/VMObjectInputStream.java: Added static + initializer. + (oisClass, vmoisClass): Removed unused fields. + * vm/reference/java/io/VMObjectStreamClass.java: Added static + initializer. + +2005-09-09 David Gilbert <david.gilbert@object-refinery.com> + + * javax/swing/plaf/basic/BasicLookAndFeel.java + (initComponentDefaults): re-added 'ScrollBar.width' default. + +2005-09-09 David Gilbert <david.gilbert@object-refinery.com> + + * javax/swing/plaf/basic/BasicArrowButton.java + (buttonBorder.paintBorder): fixed drawing issues, + (getMaximumSize): return constant value, + (getMinimumSize): likewise, + (getPreferredSize): likewise. + +2005-09-09 Thomas Fitzsimmons <fitzsim@redhat.com> + + PR swing/23558 + * javax/swing/plaf/basic/BasicComboBoxUI.java + (FocusHandler.focusLost): Do not call popup.hide. + +2005-09-08 Mark Wielaard <mark@klomp.org> + + * gnu/java/awt/peer/gtk/GdkGraphics2D.java (static): Fix typo + (Grahics -> Graphics). + +2005-09-08 Tom Tromey <tromey@redhat.com> + + * examples/gnu/classpath/examples/swing/ClasspathSwingActivityBoard.launch: + New file. + +2005-09-08 Roman Kennke <kennke@aicas.com> + + * javax/swing/plaf/metal/MetalLookAndFeel.java + (MetalLookAndFeel): Only load default theme if no theme has been + set before. + (initComponentDefaults): Fixed and added color default values + for various components. + +2005-09-08 Anthony Balkissoon <abalkiss@redhat.com> + + * java/awt/Container.java: + (findComponentForMouseEventAt): Removed check for opacity. + +2005-09-08 Keith Seitz <keiths@redhat.com> + + * gnu/classpath/jdwp/processor/VirtualMachineCommandSet.java + (executeVersion): Major and minor version are integers, not bytes. + +2005-09-08 Anthony Balkissoon <abalkiss@redhat.com> + + * java/awt/Container.java: + (findComponentForMouseEventAt): New implementation method. + (getDeepestComponentForMouseEventAt): New implementation method. + (acquireComponentForMouseEvent): Replaced call to + AWTUtilities.getDeepestComponentAt with call to new implementation + method getDeepestComponentAt to appropriately handle transparent + components with no MouseListeners attached. + +2005-09-08 Tom Tromey <tromey@redhat.com> + + * .classpath: Enable compilation of jdwp. + +2005-09-08 Keith Seitz <keiths@redhat.com> + + * gnu/classpath/jdwp/processor/ArrayReferenceCommandSet.java + (runCommand): Return value is true to indicate that the back-end + should shutdown; not whether it should stay alive. + * gnu/classpath/jdwp/processor/ArrayTypeCommandSet.java + (runCommand): Likewise. + * gnu/classpath/jdwp/processor/ClassLoaderReferenceCommandSet.java + (runCommand): Likewise. + * gnu/classpath/jdwp/processor/ClassTypeCommandSet.java + (runCommand): Likewise. + * gnu/classpath/jdwp/processor/EventRequestCommandSet.java + (runCommand): Likewise. + * gnu/classpath/jdwp/processor/MethodCommandSet.java (runCommand): + Likewise + * gnu/classpath/jdwp/processor/ObjectReferenceCommandSet.java + (runCommand): Likewise. + * gnu/classpath/jdwp/processor/ReferenceTypeCommandSet.java + (runCommand): Likewise. + * gnu/classpath/jdwp/processor/StackFrameCommandSet.java + (runCommand): Likewise. + * gnu/classpath/jdwp/processor/StringReferenceCommandSet.java + (runCommand): Likewise. + * gnu/classpath/jdwp/processor/ThreadGroupReferenceCommandSet.java + (runCommand): Likewise. + * gnu/classpath/jdwp/processor/ThreadReferenceCommandSet.java + (runCommand): Likewise. + * gnu/classpath/jdwp/processor/VirtualMachineCommandSet.java + (runCommand): Likewise. + +2005-09-08 Lillian Angel <langel@gmail.com> + + * javax/swing/JPopupMenu.java: + Fixes Bug #PR23533 + (setVisible): Adjusted popup menu's location + depending on the size of the screen. + +2005-09-08 Mark Wielaard <mark@klomp.org> + + * Makefile.am (EXTRA_DIST): Add autogen.sh + * lib/standard.omit: Remove gnu/classpath/jdwp, gnu/xml/stream and + javax/xml/stream. + * vm/reference/standard.omit: Removed. + +2005-09-08 Tom Tromey <tromey@redhat.com> + + * .classpath: Omit more directories and files. + * .settings/org.eclipse.jdt.core.prefs: Compile to 1.4 platform. + * .settings/org.eclipse.jdt.ui.prefs: Likewise. + +2005-09-08 Roman Kennke <kennke@aicas.com> + + * javax/swing/plaf/metal/OceanTheme.java + New class. Implements the ocean theme for Metal. + * javax/swing/plaf/metal/MetalLookAndFeel.java + (createDefaultTheme): Made Ocean the default theme as in JDK1.5. + +2005-09-08 David Gilbert <david.gilbert@object-refinery.com> + + * javax/swing/plaf/metal/MetalIconFactory.java + (FileChooserDetailViewIcon): new private class, + (FileChooserHomeFolderIcon): likewise, + (FileChooserListViewIcon): likewise, + (FileChooserNewFolderIcon): likewise, + (FileChooserUpFolderIcon): likewise, + (getFileChooserDetailViewIcon): implemented, + (getFileChooserHomeFolderIcon): implemented, + (getFileChooserListViewIcon): implemented, + (getFileChooserNewFolderIcon): implemented, + (getFileChooserUpFolderIcon): implemented. + +2005-09-08 Roman Kennke <kennke@aicas.com> + + * javax/swing/plaf/basic/BasicTextUI.java + (foreground): Removed this field. This is better stored + in the text component itself. + (inactiveForeground): Removed this field. This is stored + in the disabledTextColor property of the text component. + (installDefaults): Load foreground and disabledTextColor + properties from UIDefaults. Remove call to updateComponentColors. + (paintBackground): Set the correct background color here. + (updateComponentColor): Removed this method. + * javax/swing/text/PlainView.java + (disabledColor): New field. Stores the text color for disabled + text fields. + (drawUnselectedText): Respect the 'enabled' property of + the text component. + (paint): Fetch the disabled color of the text component. + +2005-09-08 Roman Kennke <kennke@aicas.com> + + * javax/swing/plaf/basic/BasicTextUI.java + (UpdateHandler.propertyChanged): Also update colors if the + 'editable' property is changed. + (updateComponentColors): Correctly handle editable vs. enabled + changes. + * javax/swing/plaf/metal/MetalLookAndFeel.java + (initComponentDefaults): Fixed color defaults for TextFields + to use the current theme. + +2005-09-08 Roman Kennke <kennke@aicas.com> + + * javax/swing/plaf/basic/BasicTextUI.java + (UpdateHandler.propertyChanged): Update the components colors + when the state of the 'enabled' property changes. + (foreground): New field that stores the foreground color. + (background): New field that stores the background color. + (inactiveForeground): New field that stores the inactive + foreground color. + (inactiveBackground): New field that stores the inactive + background color. + (updateComponentColors): New method. Updates the text + components' colors according to the state of the 'enabled' + property. + (installDefaults): Load the defaults for the component colors. + * javax/swing/plaf/metal/MetalLookAndFeel.java + (initComponentDefaults): Added defaults for TextField colors + and border. + +2005-09-08 Roman Kennke <kennke@aicas.com> + + * javax/swing/text/GapContent.java + Fixes Bug #22966. + (GapContentPosition.getOffset): Added assertion to check for + consistent state of the Position. Fixed condition in if-statement. + (serialVersionUID): Updated serialVersionUID to match JDK1.5. + (shiftGap): If gapStart == newGapStart, then return immediatly. + +2005-09-08 David Gilbert <david.gilbert@object-refinery.com> + + * javax/swing/plaf/basic/BasicLookAndFeel.java + (initComponentDefaults): added 'ScrollBar.width' default, + * javax/swing/plaf/metal/MetalScrollBarUI.java + (MetalScrollBarPropertyChangeHandler): new class, + (FREE_STANDING_PROP): added, + (MIN_THUMB_SIZE): modified dimensions, + (increaseButton): new field, + (decreaseButton): new field, + (scrollBarWidth): new field, + (isFreeStanding): new field, + (createUI): just return a new instance, + (installDefaults): implemented, + (createPropertyChangeListener): implemented, + (createDecreaseButton): implemented, + (createIncreaseButton): implemented, + (paintTrack): implemented, + (paintTrackHorizontal): new private method, + (paintTrackVertical): new private method, + (paintThumb): updated, + * javax/swing/plaf/metal/MetalScrollButton.java: implemented, + * javax/swing/plaf/metal/MetalUtils.java + (fillMetalPattern): modified alternating color calculation. + +2005-09-08 Jeroen Frijters <jeroen@frijters.net> + + * java/io/ObjectInputStream.java + (readObject): Removed println and fixed Proxy class descriptor + deserialization. + (resolveProxyClass): Use Class.forName() instead of calling + ClassLoader.loadClass() directly. + * java/io/ObjectOutputStream.java + (writeClassDescriptor): Added support for serializing Proxy + class descriptor. + +2005-09-08 Jeroen Frijters <jeroen@frijters.net> + + * javax/naming/CompoundName.java + (readObject, writeObject): New methods. + 2005-09-07 Lillian Angel <langel@redhat.com> * javax/swing/SpringLayout.java: diff --git a/Makefile.am b/Makefile.am index fdcb3f709..f17b9c718 100644 --- a/Makefile.am +++ b/Makefile.am @@ -10,7 +10,8 @@ native: lib EXTRA_DIST = HACKING BUGS THANKYOU mauve-classpath LICENSE \ ChangeLog-2003 ChangeLog-2004 \ - ChangeLog.gnujaxp.1 ChangeLog.gnujaxp.2 ChangeLog.libxmlj + ChangeLog.gnujaxp.1 ChangeLog.gnujaxp.2 ChangeLog.libxmlj \ + autogen.sh #DISTCHECK_CONFIGURE_FLAGS = --enable-gjdoc diff --git a/configure.ac b/configure.ac index 1b25b0905..4f9ea2e91 100644 --- a/configure.ac +++ b/configure.ac @@ -65,15 +65,15 @@ AC_ARG_ENABLE([core-jni], [COMPILE_CORE_JNI=yes]) AM_CONDITIONAL(CREATE_CORE_JNI_LIBRARIES, test "x${COMPILE_CORE_JNI}" = xyes) -dnl ----------------------------------------------------------- -dnl Whether to compile with -Werror or not (enabled by default) -dnl ----------------------------------------------------------- +dnl ------------------------------------------------------------ +dnl Whether to compile with -Werror or not (disabled by default) +dnl ------------------------------------------------------------ AC_ARG_ENABLE([Werror], - [AS_HELP_STRING(--disable-Werror,whether to compile C code with -Werror which turns any compiler warning into a compilation failure [default=no])], + [AS_HELP_STRING(--enable-Werror,whether to compile C code with -Werror which turns any compiler warning into a compilation failure [default=no])], [case "${enableval}" in yes) ENABLE_WERROR=yes ;; no) ENABLE_WERROR=no ;; - *) ENABLE_WERROR=yes ;; + *) ENABLE_WERROR=no ;; esac], [ENABLE_WERROR=no]) diff --git a/doc/www.gnu.org/home.wml b/doc/www.gnu.org/home.wml index 1d59593b8..ff512f22a 100644 --- a/doc/www.gnu.org/home.wml +++ b/doc/www.gnu.org/home.wml @@ -36,7 +36,7 @@ obtained by looking at these resources. <ul> <li><createlink url="tasks.html" name="Task descriptions"></li> <li>GNU Classpath vs: <createlink url="http://www.kaffe.org/~stuart/japi/htmlout/h-jdk10-classpath.html" name="JDK 1.0"> <createlink url="http://www.kaffe.org/~stuart/japi/htmlout/h-jdk11-classpath.html" name="JDK 1.1"> <createlink url="http://www.kaffe.org/~stuart/japi/htmlout/h-jdk12-classpath.html" name="JDK 1.2"> <createlink url="http://www.kaffe.org/~stuart/japi/htmlout/h-jdk13-classpath.html" name="JDK 1.3"> <createlink url="http://www.kaffe.org/~stuart/japi/htmlout/h-jdk14-classpath.html" name="JDK 1.4"> (updated nightly)</li> - <li>GNU Classpath <createlink url="http://ontographics.com/classpath/mauve/mauvereport.cgi" name="Mauve Results"></li> + <li>GNU Classpath <createlink url="http://www.object-refinery.com/classpath/mauve/report/" name="Mauve Results"></li> </ul> </p> </boxitem> diff --git a/examples/gnu/classpath/examples/swing/ButtonDemo.java b/examples/gnu/classpath/examples/swing/ButtonDemo.java new file mode 100644 index 000000000..ee59f8341 --- /dev/null +++ b/examples/gnu/classpath/examples/swing/ButtonDemo.java @@ -0,0 +1,264 @@ +/* ButtonDemo.java -- An example showing various buttons in Swing. + Copyright (C) 2005, Free Software Foundation, Inc. + +This file is part of GNU Classpath examples. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. +*/ + + +package gnu.classpath.examples.swing; + +import java.awt.BorderLayout; +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.BorderFactory; +import javax.swing.ButtonGroup; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.JRadioButton; +import javax.swing.JToggleButton; +import javax.swing.SwingConstants; +import javax.swing.plaf.metal.MetalIconFactory; + +/** + * A simple button demo showing various buttons in different states. + */ +public class ButtonDemo + extends JFrame + implements ActionListener +{ + + private JCheckBox buttonState; + private JButton button1; + private JButton button2; + private JButton button3; + private JButton button4; + + private JCheckBox toggleState; + private JToggleButton toggle1; + private JToggleButton toggle2; + private JToggleButton toggle3; + private JToggleButton toggle4; + + private JCheckBox checkBoxState; + private JCheckBox checkBox1; + private JCheckBox checkBox2; + private JCheckBox checkBox3; + + private JCheckBox radioState; + private JRadioButton radio1; + private JRadioButton radio2; + private JRadioButton radio3; + + /** + * Creates a new demo instance. + * + * @param title the frame title. + */ + public ButtonDemo(String title) + { + super(title); + getContentPane().add(createContent()); + } + + private JPanel createContent() + { + JPanel panel = new JPanel(new GridLayout(4, 1)); + panel.add(createButtonPanel()); + panel.add(createTogglePanel()); + panel.add(createCheckBoxPanel()); + panel.add(createRadioPanel()); + return panel; + } + + private JPanel createButtonPanel() + { + JPanel panel = new JPanel(new BorderLayout()); + this.buttonState = new JCheckBox("Enabled", true); + this.buttonState.setActionCommand("BUTTON_STATE"); + this.buttonState.addActionListener(this); + panel.add(this.buttonState, BorderLayout.EAST); + + JPanel buttonPanel = new JPanel(); + buttonPanel.setBorder(BorderFactory.createTitledBorder("JButton")); + this.button1 = new JButton("Button 1"); + + this.button2 = new JButton("Button 2"); + this.button2.setIcon(MetalIconFactory.getInternalFrameDefaultMenuIcon()); + + this.button3 = new JButton("Button 3"); + this.button3.setIcon(MetalIconFactory.getFileChooserHomeFolderIcon()); + this.button3.setHorizontalTextPosition(SwingConstants.CENTER); + this.button3.setVerticalTextPosition(SwingConstants.BOTTOM); + + this.button4 = new JButton("Button 4"); + this.button4.setIcon(MetalIconFactory.getFileChooserUpFolderIcon()); + this.button4.setText(null); + + buttonPanel.add(button1); + buttonPanel.add(button2); + buttonPanel.add(button3); + buttonPanel.add(button4); + + panel.add(buttonPanel); + + return panel; + } + + private JPanel createTogglePanel() + { + JPanel panel = new JPanel(new BorderLayout()); + + this.toggleState = new JCheckBox("Enabled", true); + this.toggleState.setActionCommand("TOGGLE_STATE"); + this.toggleState.addActionListener(this); + + panel.add(this.toggleState, BorderLayout.EAST); + + JPanel buttonPanel = new JPanel(); + buttonPanel.setBorder(BorderFactory.createTitledBorder("JToggleButton")); + + this.toggle1 = new JToggleButton("Toggle 1"); + + this.toggle2 = new JToggleButton("Toggle 2"); + this.toggle2.setIcon(MetalIconFactory.getInternalFrameDefaultMenuIcon()); + + this.toggle3 = new JToggleButton("Toggle 3"); + this.toggle3.setIcon(MetalIconFactory.getFileChooserHomeFolderIcon()); + this.toggle3.setHorizontalTextPosition(SwingConstants.CENTER); + this.toggle3.setVerticalTextPosition(SwingConstants.BOTTOM); + + this.toggle4 = new JToggleButton("Toggle 4"); + this.toggle4.setIcon(MetalIconFactory.getFileChooserUpFolderIcon()); + this.toggle4.setText(null); + + ButtonGroup toggleGroup = new ButtonGroup(); + toggleGroup.add(toggle1); + toggleGroup.add(toggle2); + toggleGroup.add(toggle3); + toggleGroup.add(toggle4); + + buttonPanel.add(toggle1); + buttonPanel.add(toggle2); + buttonPanel.add(toggle3); + buttonPanel.add(toggle4); + + panel.add(buttonPanel); + + return panel; + } + + private JPanel createCheckBoxPanel() + { + JPanel panel = new JPanel(new BorderLayout()); + + this.checkBoxState = new JCheckBox("Enabled", true); + this.checkBoxState.setActionCommand("CHECKBOX_STATE"); + this.checkBoxState.addActionListener(this); + + panel.add(this.checkBoxState, BorderLayout.EAST); + + JPanel buttonPanel = new JPanel(); + buttonPanel.setBorder(BorderFactory.createTitledBorder("JCheckBox")); + this.checkBox1 = new JCheckBox("CheckBox 1"); + + this.checkBox2 = new JCheckBox("CheckBox 2"); + + this.checkBox3 = new JCheckBox("CheckBox 3"); + + buttonPanel.add(checkBox1); + buttonPanel.add(checkBox2); + buttonPanel.add(checkBox3); + + panel.add(buttonPanel); + + return panel; + } + + private JPanel createRadioPanel() + { + JPanel panel = new JPanel(new BorderLayout()); + + this.radioState = new JCheckBox("Enabled", true); + this.radioState.setActionCommand("RADIO_STATE"); + this.radioState.addActionListener(this); + panel.add(this.radioState, BorderLayout.EAST); + + JPanel buttonPanel = new JPanel(); + buttonPanel.setBorder(BorderFactory.createTitledBorder("JRadioButton")); + this.radio1 = new JRadioButton("Radio 1"); + + this.radio2 = new JRadioButton("Radio 2"); + + this.radio3 = new JRadioButton("Radio 3"); + + ButtonGroup radioGroup = new ButtonGroup(); + radioGroup.add(radio1); + radioGroup.add(radio2); + radioGroup.add(radio3); + + buttonPanel.add(radio1); + buttonPanel.add(radio2); + buttonPanel.add(radio3); + + panel.add(buttonPanel); + + return panel; + } + + public void actionPerformed(ActionEvent e) + { + if (e.getActionCommand().equals("BUTTON_STATE")) + { + button1.setEnabled(buttonState.isSelected()); + button2.setEnabled(buttonState.isSelected()); + button3.setEnabled(buttonState.isSelected()); + button4.setEnabled(buttonState.isSelected()); + } + else if (e.getActionCommand().equals("TOGGLE_STATE")) + { + toggle1.setEnabled(toggleState.isSelected()); + toggle2.setEnabled(toggleState.isSelected()); + toggle3.setEnabled(toggleState.isSelected()); + toggle4.setEnabled(toggleState.isSelected()); + } + else if (e.getActionCommand().equals("CHECKBOX_STATE")) + { + checkBox1.setEnabled(checkBoxState.isSelected()); + checkBox2.setEnabled(checkBoxState.isSelected()); + checkBox3.setEnabled(checkBoxState.isSelected()); + } + else if (e.getActionCommand().equals("RADIO_STATE")) + { + radio1.setEnabled(radioState.isSelected()); + radio2.setEnabled(radioState.isSelected()); + radio3.setEnabled(radioState.isSelected()); + } + } + + public static void main(String[] args) + { + ButtonDemo app = new ButtonDemo("Button Demo"); + app.pack(); + app.setVisible(true); + } + +} diff --git a/examples/gnu/classpath/examples/swing/ClasspathSwingActivityBoard.launch b/examples/gnu/classpath/examples/swing/ClasspathSwingActivityBoard.launch new file mode 100644 index 000000000..7d041a0b0 --- /dev/null +++ b/examples/gnu/classpath/examples/swing/ClasspathSwingActivityBoard.launch @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="UTF-8"?> +<launchConfiguration type="org.eclipse.cdt.launch.localCLaunch"> +<stringAttribute key="org.eclipse.cdt.launch.DEBUGGER_ID" value="org.eclipse.cdt.debug.mi.core.CDebugger"/> +<stringAttribute key="org.eclipse.cdt.launch.protocol" value="mi"/> +<booleanAttribute key="org.eclipse.cdt.debug.mi.core.STOP_ON_SOLIB_EVENTS" value="false"/> +<stringAttribute key="org.eclipse.cdt.launch.DEBUGGER_START_MODE" value="run"/> +<listAttribute key="org.eclipse.cdt.debug.mi.core.SOLIB_PATH"/> +<booleanAttribute key="org.eclipse.debug.core.appendEnvironmentVariables" value="true"/> +<booleanAttribute key="org.eclipse.cdt.launch.ENABLE_REGISTER_BOOKKEEPING" value="false"/> +<booleanAttribute key="org.eclipse.cdt.debug.mi.core.AUTO_SOLIB" value="true"/> +<booleanAttribute key="org.eclipse.cdt.launch.DEBUGGER_STOP_AT_MAIN" value="true"/> +<booleanAttribute key="org.eclipse.cdt.launch.use_terminal" value="true"/> +<stringAttribute key="org.eclipse.cdt.launch.PROJECT_ATTR" value="jamvm"/> +<booleanAttribute key="org.eclipse.cdt.launch.ENABLE_VARIABLE_BOOKKEEPING" value="false"/> +<stringAttribute key="org.eclipse.cdt.debug.mi.core.DEBUG_NAME" value="gdb"/> +<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_NAME" value="src/jamvm"/> +<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_ARGUMENTS" value="-Dswing.defaultlaf=javax.swing.plaf.metal.MetalLookAndFeel gnu.classpath.examples.swing.Demo"/> +<stringAttribute key="org.eclipse.cdt.debug.mi.core.GDB_INIT" value=""/> +</launchConfiguration> diff --git a/examples/gnu/classpath/examples/swing/Demo.java b/examples/gnu/classpath/examples/swing/Demo.java index e8c428b59..cba46a79a 100644 --- a/examples/gnu/classpath/examples/swing/Demo.java +++ b/examples/gnu/classpath/examples/swing/Demo.java @@ -640,6 +640,14 @@ public class Demo panel.add(but, BorderLayout.NORTH); but.doClick(); but.doClick(); + JInternalFrame palette = new JInternalFrame("Palette", true, true, true, + true); + palette.putClientProperty("JInternalFrame.isPalette", Boolean.TRUE); + desk.add(palette, JDesktopPane.PALETTE_LAYER); + JLabel label = new JLabel("This is a floating palette!"); + palette.getContentPane().add(label); + palette.pack(); + palette.setVisible(true); return panel; } diff --git a/gnu/CORBA/Connected_objects.java b/gnu/CORBA/Connected_objects.java index b7eefb133..ce5761007 100644 --- a/gnu/CORBA/Connected_objects.java +++ b/gnu/CORBA/Connected_objects.java @@ -90,17 +90,6 @@ public class Connected_objects * applicable. */ public final java.lang.Object identity; - - public boolean equals(java.lang.Object other) - { - if (other instanceof cObject) - { - cObject o = (cObject) other; - return o.object.equals(object) && o.port == port; - } - else - return false; - } } /** diff --git a/gnu/CORBA/ExceptionCreator.java b/gnu/CORBA/ExceptionCreator.java index 8b7520505..abe309dc7 100644 --- a/gnu/CORBA/ExceptionCreator.java +++ b/gnu/CORBA/ExceptionCreator.java @@ -138,8 +138,8 @@ public class ExceptionCreator * @param idl the exception idl name. * @param input the stream to read from. * - * @return the loaded exception. - * @return null if the helper class cannot be found. + * @return the loaded exception, or <code>null</code> if the helper class + * cannot be found. */ public static UserException readUserException(String idl, InputStream input) { @@ -187,7 +187,7 @@ public class ExceptionCreator } /** - * Converts teh given IDL name to class name. + * Converts the given IDL name to class name. * * @param IDL the idl name. * diff --git a/gnu/CORBA/Poa/activeObjectMap.java b/gnu/CORBA/Poa/activeObjectMap.java index 1354ba9c5..c6ba6512f 100644 --- a/gnu/CORBA/Poa/activeObjectMap.java +++ b/gnu/CORBA/Poa/activeObjectMap.java @@ -142,17 +142,6 @@ public class activeObjectMap { deactivated = state; } - - public boolean equals(java.lang.Object other) - { - if (other instanceof Obj) - { - Obj o = (Obj) other; - return o.object.equals(object); - } - else - return false; - } } /** diff --git a/gnu/CORBA/Version.java b/gnu/CORBA/Version.java index 84f40bf4f..5a6eb5c25 100644 --- a/gnu/CORBA/Version.java +++ b/gnu/CORBA/Version.java @@ -70,8 +70,8 @@ public class Version /** * Create the version with the given version numbers. * - * @param major major number (0..255) - * @param minor minor number (0..255) + * @param _major major number (0..255) + * @param _minor minor number (0..255) */ public Version(int _major, int _minor) { @@ -99,6 +99,15 @@ public class Version Version that = (Version) other; return same(that); } + + /** + * Get the hashcode, higher 8 bits being the major version and lower 8 bits + * the minor version. + */ + public int hashCode() + { + return major << 8 | minor; + } /** * Read from the input stream, major number first. @@ -166,7 +175,7 @@ public class Version * Returs true if the given version is lower or equal to the * version, specified by the provided minor and major version * number. This means, the version, specified by these two numbers, - * should be supported by teh current version. + * should be supported by the current version. * * @param a_major a major version number. * @param a_minor a minor version number. @@ -203,4 +212,5 @@ public class Version throw new MARSHAL("IOException while writing message header"); } } + } diff --git a/gnu/CORBA/gnuAny.java b/gnu/CORBA/gnuAny.java index 7e5ef3351..80946b046 100644 --- a/gnu/CORBA/gnuAny.java +++ b/gnu/CORBA/gnuAny.java @@ -62,19 +62,15 @@ import org.omg.CORBA.StringHolder; import org.omg.CORBA.TCKind; import org.omg.CORBA.TypeCode; import org.omg.CORBA.TypeCodeHolder; -import org.omg.CORBA.TypeCodePackage.BadKind; import org.omg.CORBA.ValueBaseHolder; import org.omg.CORBA.portable.BoxedValueHelper; import org.omg.CORBA.portable.Streamable; -import java.io.IOException; import java.io.Serializable; - import java.lang.reflect.Field; - import java.math.BigDecimal; - import java.util.Arrays; +import java.util.zip.Adler32; /** * The implementation of {@link Any}. @@ -207,6 +203,28 @@ public class gnuAny return Arrays.equals(ba, bb); } + + /** + * Get the content - dependent hashcode. + */ + public int hashCode() + { + if (has == null) + return type().kind().value(); + else + { + Adler32 adler = new Adler32(); + + cdrBufOutput a = new cdrBufOutput(); + a.setOrb(orb); + write_value(a); + + adler.update(a.buffer.toByteArray()); + adler.update(type().kind().value()); + + return (int) adler.getValue() & Integer.MAX_VALUE; + } + } /** * Delegates functionality to {@link #equal(Any)}. diff --git a/gnu/classpath/ByteArray.java b/gnu/classpath/ByteArray.java new file mode 100644 index 000000000..de088772f --- /dev/null +++ b/gnu/classpath/ByteArray.java @@ -0,0 +1,112 @@ +/* ByteArray.java -- wrapper around a byte array, with nice toString output. + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is a part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License along +with GNU Classpath; if not, write to the + + Free Software Foundation, Inc., + 59 Temple Place, Suite 330, + Boston, MA 02111-1307 + USA + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under terms +of your choice, provided that you also meet, for each linked independent +module, the terms and conditions of the license of that module. An +independent module is a module which is not derived from or based on +this library. If you modify this library, you may extend this exception +to your version of the library, but you are not obligated to do so. If +you do not wish to do so, delete this exception statement from your +version. */ + + +package gnu.classpath; + +import java.io.PrintWriter; +import java.io.StringWriter; + +public final class ByteArray +{ + private final byte[] value; + + public ByteArray (final byte[] value) + { + this.value = value; + } + + public byte[] getValue () + { + return value; + } + + public String toString () + { + StringWriter str = new StringWriter (); + PrintWriter out = new PrintWriter (str); + int i = 0; + int len = value.length; + while (i < len) + { + out.print (formatInt (i, 16, 8)); + out.print (" "); + int l = Math.min (16, len - i); + String s = toHexString (value, i, l, ' '); + out.print (s); + for (int j = 56 - (56 - s.length ()); j < 56; j++) + out.print (" "); + for (int j = 0; j < l; j++) + { + byte b = value[i+j]; + if ((b & 0xFF) < 0x20 || (b & 0xFF) > 0x7E) + out.print ("."); + else + out.print ((char) (b & 0xFF)); + } + out.println (); + i += 16; + } + return str.toString (); + } + + public static String toHexString (byte[] buf, int off, int len, char sep) + { + StringBuffer str = new StringBuffer(); + for (int i = 0; i < len; i++) + { + str.append (Character.forDigit (buf[i+off] >>> 4 & 0x0F, 16)); + str.append (Character.forDigit (buf[i+off] & 0x0F, 16)); + if (i < len - 1) + str.append(sep); + } + return str.toString(); + } + + public static String formatInt (int value, int radix, int len) + { + String s = Integer.toString (value, radix); + StringBuffer buf = new StringBuffer (); + for (int j = 0; j < len - s.length(); j++) + buf.append ("0"); + buf.append (s); + return buf.toString(); + } +} diff --git a/gnu/classpath/jdwp/event/VmDeathEvent.java b/gnu/classpath/jdwp/event/VmDeathEvent.java new file mode 100644 index 000000000..b0d9b6565 --- /dev/null +++ b/gnu/classpath/jdwp/event/VmDeathEvent.java @@ -0,0 +1,85 @@ +/* VmDeathEvent.java -- An event specifying that the VM has terminated + Copyright (C) 2005 Free Software Foundation + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.classpath.jdwp.event; + +import gnu.classpath.jdwp.JdwpConstants; + +import java.io.DataOutputStream; +import java.io.IOException; + +/** + * Event notifying the debugger that the virtual machine has terminated. + * + * @author Keith Seitz (keiths@redhat.com) + */ +public class VmDeathEvent + extends Event +{ + /** + * Constructs a <code>VmDeathEvent</code> object + * + * @param thread the initial thread + */ + public VmDeathEvent () + { + super (JdwpConstants.EventKind.VM_DEATH); + } + + /** + * Returns a specific filtering parameter for this event. + * This event has no valid types. + * + * @param type the type of parameter desired + * @returns the desired parameter or <code>null</code> + */ + public Object getParameter (Class type) + { + return null; + } + + /** + * Writes out event-specific data + */ + protected void _writeData (DataOutputStream outStream) + throws IOException + { + // no data (request ID done by VMIdManager) + } +} diff --git a/gnu/classpath/jdwp/processor/ArrayReferenceCommandSet.java b/gnu/classpath/jdwp/processor/ArrayReferenceCommandSet.java index 247021662..a9dc6cc81 100644 --- a/gnu/classpath/jdwp/processor/ArrayReferenceCommandSet.java +++ b/gnu/classpath/jdwp/processor/ArrayReferenceCommandSet.java @@ -88,7 +88,8 @@ public class ArrayReferenceCommandSet // So if we throw an IOException we're in serious trouble throw new JdwpInternalErrorException(ex); } - return true; + + return false; } private void executeLength(ByteBuffer bb, DataOutputStream os) diff --git a/gnu/classpath/jdwp/processor/ArrayTypeCommandSet.java b/gnu/classpath/jdwp/processor/ArrayTypeCommandSet.java index 8ae1b4508..b77c3a833 100644 --- a/gnu/classpath/jdwp/processor/ArrayTypeCommandSet.java +++ b/gnu/classpath/jdwp/processor/ArrayTypeCommandSet.java @@ -82,7 +82,8 @@ public class ArrayTypeCommandSet // So if we throw an IOException we're in serious trouble throw new JdwpInternalErrorException(ex); } - return true; + + return false; } public void executeNewInstance(ByteBuffer bb, DataOutputStream os) diff --git a/gnu/classpath/jdwp/processor/ClassLoaderReferenceCommandSet.java b/gnu/classpath/jdwp/processor/ClassLoaderReferenceCommandSet.java index 4e8e23ede..cc591b17d 100644 --- a/gnu/classpath/jdwp/processor/ClassLoaderReferenceCommandSet.java +++ b/gnu/classpath/jdwp/processor/ClassLoaderReferenceCommandSet.java @@ -86,7 +86,8 @@ public class ClassLoaderReferenceCommandSet // So if we throw an IOException we're in serious trouble throw new JdwpInternalErrorException(ex); } - return true; + + return false; } public void executeVisibleClasses(ByteBuffer bb, DataOutputStream os) diff --git a/gnu/classpath/jdwp/processor/ClassObjectReferenceCommandSet.java b/gnu/classpath/jdwp/processor/ClassObjectReferenceCommandSet.java index dcafa6f84..cfec20bc7 100644 --- a/gnu/classpath/jdwp/processor/ClassObjectReferenceCommandSet.java +++ b/gnu/classpath/jdwp/processor/ClassObjectReferenceCommandSet.java @@ -79,7 +79,8 @@ public class ClassObjectReferenceCommandSet // So if we throw an IOException we're in serious trouble throw new JdwpInternalErrorException(ex); } - return true; + + return false; } public void executeReflectedType(ByteBuffer bb, DataOutputStream os) diff --git a/gnu/classpath/jdwp/processor/ClassTypeCommandSet.java b/gnu/classpath/jdwp/processor/ClassTypeCommandSet.java index ff6010e59..f60da7b70 100644 --- a/gnu/classpath/jdwp/processor/ClassTypeCommandSet.java +++ b/gnu/classpath/jdwp/processor/ClassTypeCommandSet.java @@ -95,7 +95,8 @@ public class ClassTypeCommandSet // So if we throw an IOException we're in serious trouble throw new JdwpInternalErrorException(ex); } - return true; + + return false; } private void executeSuperclass(ByteBuffer bb, DataOutputStream os) diff --git a/gnu/classpath/jdwp/processor/EventRequestCommandSet.java b/gnu/classpath/jdwp/processor/EventRequestCommandSet.java index 389b2d349..e4b1b602e 100644 --- a/gnu/classpath/jdwp/processor/EventRequestCommandSet.java +++ b/gnu/classpath/jdwp/processor/EventRequestCommandSet.java @@ -102,7 +102,8 @@ public class EventRequestCommandSet // So if we throw an IOException we're in serious trouble throw new JdwpInternalErrorException(ex); } - return true; + + return false; } private void executeSet(ByteBuffer bb, DataOutputStream os) diff --git a/gnu/classpath/jdwp/processor/MethodCommandSet.java b/gnu/classpath/jdwp/processor/MethodCommandSet.java index b5db664e4..53308d7c1 100644 --- a/gnu/classpath/jdwp/processor/MethodCommandSet.java +++ b/gnu/classpath/jdwp/processor/MethodCommandSet.java @@ -94,7 +94,8 @@ public class MethodCommandSet // So if we throw an IOException we're in serious trouble throw new JdwpInternalErrorException(ex); } - return true; + + return false; } private void executeLineTable(ByteBuffer bb, DataOutputStream os) diff --git a/gnu/classpath/jdwp/processor/ObjectReferenceCommandSet.java b/gnu/classpath/jdwp/processor/ObjectReferenceCommandSet.java index 23a64c341..ef421ea5b 100644 --- a/gnu/classpath/jdwp/processor/ObjectReferenceCommandSet.java +++ b/gnu/classpath/jdwp/processor/ObjectReferenceCommandSet.java @@ -106,7 +106,8 @@ public class ObjectReferenceCommandSet // So if we throw an IOException we're in serious trouble throw new JdwpInternalErrorException(ex); } - return true; + + return false; } private void executeReferenceType(ByteBuffer bb, DataOutputStream os) diff --git a/gnu/classpath/jdwp/processor/ReferenceTypeCommandSet.java b/gnu/classpath/jdwp/processor/ReferenceTypeCommandSet.java index b9944f7d9..7338480fc 100644 --- a/gnu/classpath/jdwp/processor/ReferenceTypeCommandSet.java +++ b/gnu/classpath/jdwp/processor/ReferenceTypeCommandSet.java @@ -128,7 +128,8 @@ public class ReferenceTypeCommandSet // So if we throw an IOException we're in serious trouble throw new JdwpInternalErrorException(ex); } - return true; + + return false; } private void executeSignature(ByteBuffer bb, DataOutputStream os) diff --git a/gnu/classpath/jdwp/processor/StackFrameCommandSet.java b/gnu/classpath/jdwp/processor/StackFrameCommandSet.java index 480f4ca28..7890a8e4b 100644 --- a/gnu/classpath/jdwp/processor/StackFrameCommandSet.java +++ b/gnu/classpath/jdwp/processor/StackFrameCommandSet.java @@ -91,7 +91,8 @@ public class StackFrameCommandSet // So if we throw an IOException we're in serious trouble throw new JdwpInternalErrorException(ex); } - return true; + + return false; } private void executeGetValues(ByteBuffer bb, DataOutputStream os) diff --git a/gnu/classpath/jdwp/processor/StringReferenceCommandSet.java b/gnu/classpath/jdwp/processor/StringReferenceCommandSet.java index 8f5bc685c..13fde0ac7 100644 --- a/gnu/classpath/jdwp/processor/StringReferenceCommandSet.java +++ b/gnu/classpath/jdwp/processor/StringReferenceCommandSet.java @@ -84,7 +84,8 @@ public class StringReferenceCommandSet // So if we throw an IOException we're in serious trouble throw new JdwpInternalErrorException(ex); } - return true; + + return false; } private void executeValue(ByteBuffer bb, DataOutputStream os) diff --git a/gnu/classpath/jdwp/processor/ThreadGroupReferenceCommandSet.java b/gnu/classpath/jdwp/processor/ThreadGroupReferenceCommandSet.java index 8a11195a7..ba36251f6 100644 --- a/gnu/classpath/jdwp/processor/ThreadGroupReferenceCommandSet.java +++ b/gnu/classpath/jdwp/processor/ThreadGroupReferenceCommandSet.java @@ -85,7 +85,8 @@ public class ThreadGroupReferenceCommandSet // So if we throw an IOException we're in serious trouble throw new JdwpInternalErrorException(ex); } - return true; + + return false; } private void executeName(ByteBuffer bb, DataOutputStream os) diff --git a/gnu/classpath/jdwp/processor/ThreadReferenceCommandSet.java b/gnu/classpath/jdwp/processor/ThreadReferenceCommandSet.java index 73643b6a8..559e405b6 100644 --- a/gnu/classpath/jdwp/processor/ThreadReferenceCommandSet.java +++ b/gnu/classpath/jdwp/processor/ThreadReferenceCommandSet.java @@ -118,7 +118,8 @@ public class ThreadReferenceCommandSet // So if we throw an IOException we're in serious trouble throw new JdwpInternalErrorException(ex); } - return true; + + return false; } private void executeName(ByteBuffer bb, DataOutputStream os) diff --git a/gnu/classpath/jdwp/processor/VirtualMachineCommandSet.java b/gnu/classpath/jdwp/processor/VirtualMachineCommandSet.java index b83406873..6bdb23681 100644 --- a/gnu/classpath/jdwp/processor/VirtualMachineCommandSet.java +++ b/gnu/classpath/jdwp/processor/VirtualMachineCommandSet.java @@ -67,7 +67,7 @@ public class VirtualMachineCommandSet public boolean runCommand(ByteBuffer bb, DataOutputStream os, byte command) throws JdwpException { - boolean keepRunning = true; + boolean shutdown = false; try { switch (command) @@ -91,7 +91,7 @@ public class VirtualMachineCommandSet executeIDsizes(bb, os); break; case JdwpConstants.CommandSet.VirtualMachine.DISPOSE: - keepRunning = false; + shutdown = true; executeDispose(bb, os); break; case JdwpConstants.CommandSet.VirtualMachine.SUSPEND: @@ -101,7 +101,7 @@ public class VirtualMachineCommandSet executeResume(bb, os); break; case JdwpConstants.CommandSet.VirtualMachine.EXIT: - keepRunning = false; + shutdown = true; executeExit(bb, os); break; case JdwpConstants.CommandSet.VirtualMachine.CREATE_STRING: @@ -145,7 +145,8 @@ public class VirtualMachineCommandSet // So if we throw an IOException we're in serious trouble throw new JdwpInternalErrorException(ex); } - return keepRunning; + + return shutdown; } private void executeVersion(ByteBuffer bb, DataOutputStream os) @@ -164,8 +165,8 @@ public class VirtualMachineCommandSet String vmVersion = props.getProperty("java.version"); String vmName = props.getProperty("java.vm.name"); JdwpString.writeString(os, description); - os.write(jdwpMajor); - os.write(jdwpMinor); + os.writeInt(jdwpMajor); + os.writeInt(jdwpMinor); JdwpString.writeString(os, vmName); JdwpString.writeString(os, vmVersion); } diff --git a/gnu/java/awt/AWTUtilities.java b/gnu/java/awt/AWTUtilities.java index af1fc13ca..ca7b55118 100644 --- a/gnu/java/awt/AWTUtilities.java +++ b/gnu/java/awt/AWTUtilities.java @@ -592,9 +592,12 @@ public class AWTUtilities if (destination == null) destination = getRoot(source); - - convertPointToScreen(pt, source); - convertPointFromScreen(pt, destination); + + if (source.isShowing() && destination.isShowing()) + { + convertPointToScreen(pt, source); + convertPointFromScreen(pt, destination); + } return pt; } diff --git a/gnu/java/awt/EmbeddedWindow.java b/gnu/java/awt/EmbeddedWindow.java index 08b2140f4..99f90c9f8 100644 --- a/gnu/java/awt/EmbeddedWindow.java +++ b/gnu/java/awt/EmbeddedWindow.java @@ -98,13 +98,11 @@ public class EmbeddedWindow extends Frame } catch (IllegalAccessException e) { - throw new RuntimeException - ("couldn't set java.awt.Component.peer field"); + throw new AssertionError (e); } catch (NoSuchFieldException e) { - throw new RuntimeException - ("couldn't set java.awt.Component.peer field"); + throw new AssertionError (e); } super.addNotify(); diff --git a/gnu/java/awt/peer/gtk/GdkGraphics.java b/gnu/java/awt/peer/gtk/GdkGraphics.java index 160602b03..7d8531bf1 100644 --- a/gnu/java/awt/peer/gtk/GdkGraphics.java +++ b/gnu/java/awt/peer/gtk/GdkGraphics.java @@ -116,6 +116,8 @@ public class GdkGraphics extends Graphics { this.component = component; font = component.awtComponent.getFont (); + if (font == null) + font = new Font ("Dialog", Font.PLAIN, 12); color = Color.black; if (component.isRealized ()) diff --git a/gnu/java/awt/peer/gtk/GdkGraphics2D.java b/gnu/java/awt/peer/gtk/GdkGraphics2D.java index 6d9aabf77..687c0c109 100644 --- a/gnu/java/awt/peer/gtk/GdkGraphics2D.java +++ b/gnu/java/awt/peer/gtk/GdkGraphics2D.java @@ -101,7 +101,7 @@ public class GdkGraphics2D extends Graphics2D static { if (! Configuration.GTK_CAIRO_ENABLED) - throw new Error("Grahics2D not implemented. " + throw new Error("Graphics2D not implemented. " + "Cairo was not found or disabled at configure time"); if (Configuration.INIT_LOAD_LIBRARY) @@ -157,8 +157,19 @@ public class GdkGraphics2D extends Graphics2D return new GdkGraphics2D(width, height); } + private void fail_g2d () + { + System.err.println ("Attempted to instantiate GdkGraphics2D" + + " but Graphics2D not enabled. Try again with" + + " -Dgnu.java.awt.peer.gtk.Graphics=Graphics2D"); + System.exit (1); + } + GdkGraphics2D(GdkGraphics2D g) { + if (!GtkToolkit.useGraphics2D ()) + fail_g2d (); + paint = g.paint; stroke = g.stroke; setRenderingHints(g.hints); @@ -200,6 +211,9 @@ public class GdkGraphics2D extends Graphics2D GdkGraphics2D(int width, int height) { + if (!GtkToolkit.useGraphics2D ()) + fail_g2d (); + initState(width, height); setColor(Color.black); @@ -215,6 +229,9 @@ public class GdkGraphics2D extends Graphics2D GdkGraphics2D(GtkComponentPeer component) { + if (!GtkToolkit.useGraphics2D ()) + fail_g2d (); + this.component = component; if (component.isRealized()) @@ -992,8 +1009,11 @@ public class GdkGraphics2D extends Graphics2D if (clip == null) { // Reset clipping. - Dimension d = component.awtComponent.getSize(); - setClip(0, 0, d.width, d.height); + if (component != null) + { + Dimension d = component.awtComponent.getSize(); + setClip(0, 0, d.width, d.height); + } } else { diff --git a/gnu/java/awt/peer/gtk/GtkDialogPeer.java b/gnu/java/awt/peer/gtk/GtkDialogPeer.java index c2cbc37dc..cfb54d6e9 100644 --- a/gnu/java/awt/peer/gtk/GtkDialogPeer.java +++ b/gnu/java/awt/peer/gtk/GtkDialogPeer.java @@ -83,7 +83,8 @@ public class GtkDialogPeer extends GtkWindowPeer void create () { // Create a decorated dialog window. - create (GDK_WINDOW_TYPE_HINT_DIALOG, true); + create (GDK_WINDOW_TYPE_HINT_DIALOG, + !((Dialog) awtComponent).isUndecorated ()); Dialog dialog = (Dialog) awtComponent; diff --git a/gnu/java/awt/peer/gtk/GtkFramePeer.java b/gnu/java/awt/peer/gtk/GtkFramePeer.java index 6eb90ffa0..99cca0cff 100644 --- a/gnu/java/awt/peer/gtk/GtkFramePeer.java +++ b/gnu/java/awt/peer/gtk/GtkFramePeer.java @@ -168,7 +168,8 @@ public class GtkFramePeer extends GtkWindowPeer void create () { // Create a normal decorated window. - create (GDK_WINDOW_TYPE_HINT_NORMAL, true); + create (GDK_WINDOW_TYPE_HINT_NORMAL, + !((Frame) awtComponent).isUndecorated ()); Frame frame = (Frame) awtComponent; diff --git a/gnu/java/beans/decoder/BooleanHandler.java b/gnu/java/beans/decoder/BooleanHandler.java index a34fe346e..a675e8c90 100644 --- a/gnu/java/beans/decoder/BooleanHandler.java +++ b/gnu/java/beans/decoder/BooleanHandler.java @@ -57,10 +57,10 @@ class BooleanHandler extends SimpleHandler protected Object parse(String number) throws AssemblyException { if (number.equals("true")) - return new Boolean(true); + return Boolean.TRUE; if (number.equals("false")) - return new Boolean(false); + return Boolean.FALSE; throw new AssemblyException(new IllegalArgumentException("Element contained no valid boolean value.")); } diff --git a/gnu/java/nio/channels/FileChannelImpl.java b/gnu/java/nio/channels/FileChannelImpl.java index 0ee5d3fc2..466f3dd55 100644 --- a/gnu/java/nio/channels/FileChannelImpl.java +++ b/gnu/java/nio/channels/FileChannelImpl.java @@ -175,7 +175,8 @@ public final class FileChannelImpl extends FileChannel */ protected void finalize() throws IOException { - this.close(); + if (fd != -1) + close(); } public int read (ByteBuffer dst) throws IOException diff --git a/gnu/java/rmi/dgc/DGCImpl_Stub.java b/gnu/java/rmi/dgc/DGCImpl_Stub.java index b1e086a73..9f18d129e 100644 --- a/gnu/java/rmi/dgc/DGCImpl_Stub.java +++ b/gnu/java/rmi/dgc/DGCImpl_Stub.java @@ -81,7 +81,7 @@ public final class DGCImpl_Stub public void clean(java.rmi.server.ObjID[] $param_0, long $param_1, java.rmi.dgc.VMID $param_2, boolean $param_3) throws java.rmi.RemoteException { try { if (useNewInvoke) { - ref.invoke(this, $method_clean_0, new java.lang.Object[] {$param_0, new java.lang.Long($param_1), $param_2, new java.lang.Boolean($param_3)}, -5803803475088455571L); + ref.invoke(this, $method_clean_0, new java.lang.Object[] {$param_0, new java.lang.Long($param_1), $param_2, Boolean.valueOf($param_3)}, -5803803475088455571L); } else { java.rmi.server.RemoteCall call = ref.newCall((java.rmi.server.RemoteObject)this, operations, 0, interfaceHash); diff --git a/gnu/java/rmi/server/RMIObjectInputStream.java b/gnu/java/rmi/server/RMIObjectInputStream.java index 888b30bf6..587d57fc7 100644 --- a/gnu/java/rmi/server/RMIObjectInputStream.java +++ b/gnu/java/rmi/server/RMIObjectInputStream.java @@ -102,7 +102,7 @@ protected Class resolveProxyClass(String intfs[]) protected Object readValue(Class valueClass) throws IOException, ClassNotFoundException { if(valueClass.isPrimitive()){ if(valueClass == Boolean.TYPE) - return new Boolean(readBoolean()); + return Boolean.valueOf(readBoolean()); if(valueClass == Byte.TYPE) return new Byte(readByte()); if(valueClass == Character.TYPE) diff --git a/gnu/java/security/PolicyFile.java b/gnu/java/security/PolicyFile.java index c6a3061ea..3064f041b 100644 --- a/gnu/java/security/PolicyFile.java +++ b/gnu/java/security/PolicyFile.java @@ -533,7 +533,7 @@ public final class PolicyFile extends Policy if (clazz == null) { currentPerms.add(new UnresolvedPermission(className, - null, null, (Certificate[]) currentCerts.toArray(new Certificate[0]))); + null, null, (Certificate[]) currentCerts.toArray(new Certificate[currentCerts.size()]))); continue; } try @@ -555,7 +555,7 @@ public final class PolicyFile extends Policy if (clazz == null) { currentPerms.add(new UnresolvedPermission(className, - target, null, (Certificate[]) currentCerts.toArray(new Certificate[0]))); + target, null, (Certificate[]) currentCerts.toArray(new Certificate[currentCerts.size()]))); continue; } try @@ -598,7 +598,7 @@ public final class PolicyFile extends Policy if (clazz == null) { currentPerms.add(new UnresolvedPermission(className, - target, action, (Certificate[]) currentCerts.toArray(new Certificate[0]))); + target, action, (Certificate[]) currentCerts.toArray(new Certificate[currentCerts.size()]))); continue; } else diff --git a/gnu/java/security/der/DERReader.java b/gnu/java/security/der/DERReader.java index cb07f1432..09ec1e2df 100644 --- a/gnu/java/security/der/DERReader.java +++ b/gnu/java/security/der/DERReader.java @@ -389,7 +389,7 @@ public class DERReader implements DER Integer.parseInt(str.substring( 4, 6)), // day Integer.parseInt(str.substring( 6, 8)), // hour Integer.parseInt(str.substring( 8, 10))); // minute - if (date.length() == 12); + if (date.length() == 12) calendar.set(Calendar.SECOND, Integer.parseInt(str.substring(10, 12))); } diff --git a/gnu/java/security/provider/Gnu.java b/gnu/java/security/provider/Gnu.java index 849f63c16..47c774538 100644 --- a/gnu/java/security/provider/Gnu.java +++ b/gnu/java/security/provider/Gnu.java @@ -46,7 +46,7 @@ public final class Gnu extends Provider { public Gnu() { - super("GNU", 1.0, "GNU provider v1.0 implementing SHA-1, MD5, DSA, RSA, X.509 Certificates and CRLs, PKIX certificate path validators, Collection cert stores"); + super("GNU", 1.0, "GNU provider v1.0 implementing SHA-1, MD5, DSA, RSA, X.509 Certificates and CRLs, PKIX certificate path validators, Collection cert stores, Diffie-Hellman key agreement"); AccessController.doPrivileged (new PrivilegedAction() { @@ -161,6 +161,14 @@ public final class Gnu extends Provider // CertStore put("CertStore.Collection", CollectionCertStoreImpl.class.getName()); + // KeyAgreement + put("KeyAgreement.DiffieHellman", gnu.javax.crypto.DiffieHellmanImpl.class.getName()); + put("Alg.Alias.KeyAgreement.DH", "DiffieHellman"); + + // Cipher + put("Cipher.RSAES-PKCS1-v1_5", gnu.javax.crypto.RSACipherImpl.class.getName()); + put("Alg.Alias.Cipher.RSA", "RSAES-PKCS1-v1_5"); + return null; } }); diff --git a/gnu/java/security/x509/ext/BasicConstraints.java b/gnu/java/security/x509/ext/BasicConstraints.java index 00f7a6ed2..d8f5c6158 100644 --- a/gnu/java/security/x509/ext/BasicConstraints.java +++ b/gnu/java/security/x509/ext/BasicConstraints.java @@ -112,7 +112,7 @@ public class BasicConstraints extends Extension.Value if (encoded == null) { List bc = new ArrayList (2); - bc.add (new DERValue (DER.BOOLEAN, new Boolean (ca))); + bc.add (new DERValue (DER.BOOLEAN, Boolean.valueOf (ca))); if (pathLenConstraint >= 0) bc.add (new DERValue (DER.INTEGER, BigInteger.valueOf ((long) pathLenConstraint))); diff --git a/gnu/java/security/x509/ext/Extension.java b/gnu/java/security/x509/ext/Extension.java index 5ca9ac3a9..ee2aa073a 100644 --- a/gnu/java/security/x509/ext/Extension.java +++ b/gnu/java/security/x509/ext/Extension.java @@ -232,7 +232,7 @@ public class Extension { List ext = new ArrayList (3); ext.add (new DERValue (DER.OBJECT_IDENTIFIER, oid)); - ext.add (new DERValue (DER.BOOLEAN, new Boolean (critical))); + ext.add (new DERValue (DER.BOOLEAN, Boolean.valueOf (critical))); ext.add (new DERValue (DER.OCTET_STRING, value.getEncoded())); return new DERValue (DER.CONSTRUCTED|DER.SEQUENCE, ext); } diff --git a/gnu/javax/crypto/DiffieHellmanImpl.java b/gnu/javax/crypto/DiffieHellmanImpl.java new file mode 100644 index 000000000..9052feb4f --- /dev/null +++ b/gnu/javax/crypto/DiffieHellmanImpl.java @@ -0,0 +1,170 @@ +/* DiffieHellmanImpl.java -- implementation of the Diffie-Hellman key agreement. + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.javax.crypto; + +import gnu.java.security.provider.GnuDHPublicKey; + +import java.math.BigInteger; + +import java.security.Key; +import java.security.InvalidKeyException; +import java.security.PrivateKey; +import java.security.PublicKey; +import java.security.SecureRandom; +import java.security.spec.AlgorithmParameterSpec; + +import javax.crypto.KeyAgreementSpi; +import javax.crypto.SecretKey; +import javax.crypto.interfaces.DHPrivateKey; +import javax.crypto.interfaces.DHPublicKey; +import javax.crypto.spec.DHParameterSpec; +import javax.crypto.spec.SecretKeySpec; + +/** + * The Diffie-Hellman key agreement. + * + * @author Casey Marshall (csm@gnu.org) + */ +public final class DiffieHellmanImpl extends KeyAgreementSpi +{ + + /** The private key being used for this agreement. */ + private DHPrivateKey key; + + /** The random-number generator used to generate secrets. */ + private SecureRandom random; + + /** The current result. */ + private BigInteger result; + + /** True if the caller told us we are done. */ + private boolean last_phase_done; + + /** Trivial default constructor. */ + public DiffieHellmanImpl () + { + key = null; + random = null; + result = null; + last_phase_done = false; + } + + // KeyAgreementSpi methods. + + protected Key engineDoPhase (final Key incoming, final boolean lastPhase) + throws InvalidKeyException + { + if (key == null) + throw new IllegalStateException ("not initialized"); + if (last_phase_done) + throw new IllegalStateException ("last phase already done"); + + if (!(incoming instanceof DHPublicKey)) + throw new InvalidKeyException ("expecting javax.crypto.interfaces.DHPublicKey"); + DHPublicKey pub = (DHPublicKey) incoming; + DHParameterSpec s1 = key.getParams(); + DHParameterSpec s2 = key.getParams(); + if (!s1.getG().equals (s2.getG()) + || !s1.getP().equals (s2.getP()) + || s1.getL() != s2.getL()) + throw new InvalidKeyException ("supplied key is not compatible"); + + BigInteger randval = new BigInteger (s1.getL(), random); + BigInteger out = s1.getG().modPow (key.getX(), s1.getP()); + if (result == null) + result = s1.getG(); + result = result.modPow (pub.getY(), s1.getP()); + if (lastPhase) + { + last_phase_done = true; + return null; + } + return new GnuDHPublicKey (s1, out, null); + } + + protected byte[] engineGenerateSecret () + { + if (result == null || !last_phase_done) + throw new IllegalStateException ("not finished"); + + byte[] buf = result.toByteArray (); + if (buf[0] == 0x00) + { + byte[] buf2 = new byte[buf.length - 1]; + System.arraycopy (buf, 1, buf2, 0, buf2.length); + buf = buf2; + } + return buf; + } + + protected int engineGenerateSecret (final byte[] secret, final int offset) + { + byte[] s = engineGenerateSecret(); + System.arraycopy (s, 0, secret, offset, s.length); + return s.length; + } + + protected SecretKey engineGenerateSecret (final String algorithm) + throws InvalidKeyException + { + byte[] s = engineGenerateSecret(); + return new SecretKeySpec (s, algorithm); + } + + protected void engineInit (final Key key, final SecureRandom random) + throws InvalidKeyException + { + if (!(key instanceof DHPrivateKey)) + throw new InvalidKeyException ("not a javax.crypto.interfaces.DHPrivateKey"); + this.key = (DHPrivateKey) key; + if (random != null) + this.random = random; + else if (this.random == null) + this.random = new SecureRandom(); + result = null; + last_phase_done = false; + } + + protected void engineInit (final Key key, final AlgorithmParameterSpec params, + final SecureRandom random) + throws InvalidKeyException + { + engineInit (key, random); + } +} diff --git a/gnu/javax/crypto/GnuDHPrivateKey.java b/gnu/javax/crypto/GnuDHPrivateKey.java new file mode 100644 index 000000000..25af3e5a8 --- /dev/null +++ b/gnu/javax/crypto/GnuDHPrivateKey.java @@ -0,0 +1,90 @@ +/* GnuDHPrivateKey.java -- a Diffie-Hellman private key. + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.javax.crypto; + +import java.math.BigInteger; + +import javax.crypto.interfaces.DHKey; +import javax.crypto.interfaces.DHPrivateKey; +import javax.crypto.spec.DHParameterSpec; + +/** + * A Diffie-Hellman private key. + * + * @author Casey Marshall (csm@gnu.org) + */ +public class GnuDHPrivateKey implements DHPrivateKey +{ + + private final BigInteger x; + private final DHParameterSpec params; + + public GnuDHPrivateKey (final BigInteger x, final DHParameterSpec params) + { + x.getClass (); + params.getClass (); + this.x = x; + this.params = params; + } + + public DHParameterSpec getParams() + { + return params; + } + + public String getAlgorithm() + { + return "DiffieHellman"; + } + + public String getFormat () + { + return "NONE"; + } + + public byte[] getEncoded () + { + return null; + } + + public BigInteger getX () + { + return x; + } +} diff --git a/gnu/javax/crypto/RSACipherImpl.java b/gnu/javax/crypto/RSACipherImpl.java new file mode 100644 index 000000000..a92fa361b --- /dev/null +++ b/gnu/javax/crypto/RSACipherImpl.java @@ -0,0 +1,311 @@ +/* DiffieHellmanImpl.java -- implementation of the Diffie-Hellman key agreement. + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.javax.crypto; + +import gnu.classpath.ByteArray; +import gnu.classpath.debug.Component; +import gnu.classpath.debug.SystemLogger; + +import java.math.BigInteger; + +import java.security.AlgorithmParameters; +import java.security.InvalidAlgorithmParameterException; +import java.security.InvalidKeyException; +import java.security.Key; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; + +import java.security.interfaces.RSAKey; +import java.security.interfaces.RSAPrivateKey; +import java.security.interfaces.RSAPrivateCrtKey; +import java.security.interfaces.RSAPublicKey; + +import java.security.spec.AlgorithmParameterSpec; + +import java.util.logging.Logger; + +import javax.crypto.BadPaddingException; +import javax.crypto.Cipher; +import javax.crypto.CipherSpi; +import javax.crypto.IllegalBlockSizeException; +import javax.crypto.NoSuchPaddingException; +import javax.crypto.ShortBufferException; + +public class RSACipherImpl extends CipherSpi +{ + private static final Logger logger = SystemLogger.SYSTEM; + + private static final byte[] EMPTY = new byte[0]; + private int opmode = -1; + private RSAPrivateKey decipherKey = null; + private RSAPublicKey blindingKey = null; + private RSAPublicKey encipherKey = null; + private SecureRandom random = null; + private byte[] dataBuffer = null; + private int pos = 0; + + protected void engineSetMode (String mode) throws NoSuchAlgorithmException + { + throw new NoSuchAlgorithmException ("only one mode available"); + } + + protected void engineSetPadding (String pad) throws NoSuchPaddingException + { + throw new NoSuchPaddingException ("only one padding available"); + } + + protected int engineGetBlockSize () + { + return 1; + } + + protected int engineGetOutputSize (int inputLen) + { + int outputLen = 0; + if (decipherKey != null) + { + outputLen = (decipherKey.getModulus ().bitLength () + 7) / 8; + } + else if (encipherKey != null) + { + outputLen = (encipherKey.getModulus ().bitLength () + 7) / 8; + } + else + throw new IllegalStateException ("not initialized"); + if (inputLen > outputLen) + throw new IllegalArgumentException ("not configured to encode " + inputLen + + "bytes; at most " + outputLen); + return outputLen; + } + + protected int engineGetKeySize (final Key key) throws InvalidKeyException + { + if (!(key instanceof RSAKey)) + throw new InvalidKeyException ("not an RSA key"); + return ((RSAKey) key).getModulus ().bitLength (); + } + + protected byte[] engineGetIV () + { + return null; + } + + protected AlgorithmParameters engineGetParameters() + { + return null; + } + + protected void engineInit (int opmode, Key key, SecureRandom random) + throws InvalidKeyException + { + int outputLen = 0; + if (opmode == Cipher.ENCRYPT_MODE) + { + if (!(key instanceof RSAPublicKey)) + throw new InvalidKeyException ("expecting a RSAPublicKey"); + encipherKey = (RSAPublicKey) key; + decipherKey = null; + blindingKey = null; + outputLen = (encipherKey.getModulus ().bitLength () + 7) / 8; + } + else if (opmode == Cipher.DECRYPT_MODE) + { + if (key instanceof RSAPrivateKey) + { + decipherKey = (RSAPrivateKey) key; + encipherKey = null; + blindingKey = null; + outputLen = (decipherKey.getModulus ().bitLength () + 7) / 8; + } + else if (key instanceof RSAPublicKey) + { + if (decipherKey == null) + throw new IllegalStateException ("must configure decryption key first"); + if (!decipherKey.getModulus ().equals (((RSAPublicKey) key).getModulus ())) + throw new InvalidKeyException ("blinding key is not compatible"); + blindingKey = (RSAPublicKey) key; + return; + } + else + throw new InvalidKeyException ("expecting either an RSAPrivateKey or an RSAPublicKey (for blinding)"); + } + else + throw new IllegalArgumentException ("only encryption and decryption supported"); + this.random = random; + this.opmode = opmode; + pos = 0; + dataBuffer = new byte[outputLen]; + } + + protected void engineInit (int opmode, Key key, AlgorithmParameterSpec spec, SecureRandom random) + throws InvalidKeyException + { + engineInit (opmode, key, random); + } + + protected void engineInit (int opmode, Key key, AlgorithmParameters params, SecureRandom random) + throws InvalidKeyException + { + engineInit (opmode, key, random); + } + + protected byte[] engineUpdate (byte[] in, int offset, int length) + { + if (opmode != Cipher.ENCRYPT_MODE && opmode != Cipher.DECRYPT_MODE) + throw new IllegalStateException ("not initialized"); + System.arraycopy (in, offset, dataBuffer, pos, length); + pos += length; + return EMPTY; + } + + protected int engineUpdate (byte[] in, int offset, int length, byte[] out, int outOffset) + { + engineUpdate (in, offset, length); + return 0; + } + + protected byte[] engineDoFinal (byte[] in, int offset, int length) + throws IllegalBlockSizeException, BadPaddingException + { + engineUpdate (in, offset, length); + if (opmode == Cipher.DECRYPT_MODE) + { + if (pos < dataBuffer.length) + throw new IllegalBlockSizeException ("expecting exactly " + dataBuffer.length + " bytes"); + BigInteger enc = new BigInteger (1, dataBuffer); + byte[] dec = rsaDecrypt (enc); + logger.log (Component.CRYPTO, "RSA: decryption produced\n{0}", + new ByteArray (dec)); + if (dec[0] != 0x02) + throw new BadPaddingException ("expected padding type 2"); + int i; + for (i = 1; i < dec.length && dec[i] != 0x00; i++); + int len = dec.length - i; + byte[] result = new byte[len]; + System.arraycopy (dec, i, result, 0, len); + pos = 0; + return result; + } + else + { + offset = dataBuffer.length - pos; + if (offset < 3) + throw new IllegalBlockSizeException ("input is too large to encrypt"); + byte[] dec = new byte[dataBuffer.length]; + dec[0] = 0x02; + if (random == null) + random = new SecureRandom (); + byte[] pad = new byte[offset - 2]; + random.nextBytes (pad); + for (int i = 0; i < pad.length; i++) + if (pad[i] == 0) + pad[i] = 1; + System.arraycopy (pad, 0, dec, 1, pad.length); + dec[dec.length - pos] = 0x00; + System.arraycopy (dataBuffer, 0, dec, offset, pos); + logger.log (Component.CRYPTO, "RSA: produced padded plaintext\n{0}", + new ByteArray (dec)); + BigInteger x = new BigInteger (1, dec); + BigInteger y = x.modPow (encipherKey.getPublicExponent (), + encipherKey.getModulus ()); + byte[] enc = y.toByteArray (); + if (enc[0] == 0x00) + { + byte[] tmp = new byte[enc.length - 1]; + System.arraycopy (enc, 1, tmp, 0, tmp.length); + enc = tmp; + } + pos = 0; + return enc; + } + } + + protected int engineDoFinal (byte[] out, int offset) + throws ShortBufferException, IllegalBlockSizeException, BadPaddingException + { + byte[] result = engineDoFinal (EMPTY, 0, 0); + if (out.length - offset < result.length) + throw new ShortBufferException ("need " + result.length + ", have " + + (out.length - offset)); + System.arraycopy (result, 0, out, offset, result.length); + return result.length; + } + + protected int engineDoFinal (final byte[] input, final int offset, final int length, + final byte[] output, final int outputOffset) + throws ShortBufferException, IllegalBlockSizeException, BadPaddingException + { + byte[] result = engineDoFinal (input, offset, length); + if (output.length - outputOffset < result.length) + throw new ShortBufferException ("need " + result.length + ", have " + + (output.length - outputOffset)); + System.arraycopy (result, 0, output, outputOffset, result.length); + return result.length; + } + + /** + * Decrypts the ciphertext, employing RSA blinding if possible. + */ + private byte[] rsaDecrypt (BigInteger enc) + { + if (random == null) + random = new SecureRandom (); + BigInteger n = decipherKey.getModulus (); + BigInteger r = null; + BigInteger pubExp = null; + if (blindingKey != null) + pubExp = blindingKey.getPublicExponent (); + if (pubExp != null && (decipherKey instanceof RSAPrivateCrtKey)) + pubExp = ((RSAPrivateCrtKey) decipherKey).getPublicExponent (); + if (pubExp != null) + { + r = new BigInteger (n.bitLength () - 1, random); + enc = r.modPow (pubExp, n).multiply (enc).mod (n); + } + + BigInteger dec = enc.modPow (decipherKey.getPrivateExponent (), n); + + if (pubExp != null) + { + dec = dec.multiply (r.modInverse (n)).mod (n); + } + + return dec.toByteArray (); + } +} diff --git a/gnu/xml/aelfred2/JAXPFactory.java b/gnu/xml/aelfred2/JAXPFactory.java index 37e8cc9c1..011ca3c6a 100644 --- a/gnu/xml/aelfred2/JAXPFactory.java +++ b/gnu/xml/aelfred2/JAXPFactory.java @@ -109,7 +109,7 @@ public final class JAXPFactory // (flags can't necessarily be set before parsing) new JaxpParser().getXMLReader().setFeature(name, value); - flags.put(name, new Boolean(value)); + flags.put(name, Boolean.valueOf(value)); } catch (SAXNotRecognizedException e) { diff --git a/gnu/xml/dom/DomDocument.java b/gnu/xml/dom/DomDocument.java index dc476b582..29b8dc72e 100644 --- a/gnu/xml/dom/DomDocument.java +++ b/gnu/xml/dom/DomDocument.java @@ -210,13 +210,15 @@ public class DomDocument */ public Element getElementById(String id) { - DomDoctype doctype = (DomDoctype) getDoctype(); - - if (doctype == null || !doctype.hasIds() - || id == null || id.length() == 0) + if (id == null || id.length() == 0) { return null; } + DomDoctype doctype = (DomDoctype) getDoctype(); + if (doctype != null && !doctype.hasIds()) + { + doctype = null; + } // yes, this is linear in size of document. // it'd be easy enough to maintain a hashtable. @@ -233,25 +235,39 @@ public class DomDocument if (current.getNodeType() == ELEMENT_NODE) { DomElement element = (DomElement) current; - DTDElementTypeInfo info = - doctype.getElementTypeInfo(current.getNodeName()); - if (info != null && - id.equals(element.getAttribute(info.idAttrName))) - { - return element; - } - else if (element.userIdAttrs != null) + if (doctype != null) { - for (Iterator i = element.userIdAttrs.iterator(); - i.hasNext(); ) + DTDElementTypeInfo info = + doctype.getElementTypeInfo(current.getNodeName()); + if (info != null && + id.equals(element.getAttribute(info.idAttrName))) { - Node idAttr = (Node) i.next(); - if (id.equals(idAttr.getNodeValue())) + return element; + } + else if (element.userIdAttrs != null) + { + for (Iterator i = element.userIdAttrs.iterator(); + i.hasNext(); ) { - return element; + Node idAttr = (Node) i.next(); + if (id.equals(idAttr.getNodeValue())) + { + return element; + } } } } + // xml:id + String xmlId = element.getAttribute("xml:id"); + if (xmlId == null) + { + xmlId = element.getAttributeNS(XMLConstants.XML_NS_URI, + "id"); + } + if (id.equals(xmlId)) + { + return element; + } } // descend? diff --git a/gnu/xml/libxmlj/dom/GnomeDocument.java b/gnu/xml/libxmlj/dom/GnomeDocument.java index 3706fba84..03420c463 100644 --- a/gnu/xml/libxmlj/dom/GnomeDocument.java +++ b/gnu/xml/libxmlj/dom/GnomeDocument.java @@ -376,31 +376,31 @@ public class GnomeDocument name = name.toLowerCase(); if ("canonical-form".equals(name)) { - return new Boolean(canonicalForm); + return Boolean.valueOf(canonicalForm); } else if ("cdata-sections".equals(name)) { - return new Boolean(cdataSections); + return Boolean.valueOf(cdataSections); } else if ("check-character-normalization".equals(name)) { - return new Boolean(checkCharacterNormalization); + return Boolean.valueOf(checkCharacterNormalization); } else if ("comments".equals(name)) { - return new Boolean(comments); + return Boolean.valueOf(comments); } else if ("datatype-normalization".equals(name)) { - return new Boolean(datatypeNormalization); + return Boolean.valueOf(datatypeNormalization); } else if ("element-content-whitespace".equals(name)) { - return new Boolean(elementContentWhitespace); + return Boolean.valueOf(elementContentWhitespace); } else if ("entities".equals(name)) { - return new Boolean(entities); + return Boolean.valueOf(entities); } else if ("error-handler".equals(name)) { @@ -408,43 +408,43 @@ public class GnomeDocument } else if ("infoset".equals(name)) { - return new Boolean(!validateIfSchema && - !entities && - !datatypeNormalization && - !cdataSections && - namespaceDeclarations && - wellFormed && - elementContentWhitespace && - comments && - namespaces); + return Boolean.valueOf(!validateIfSchema && + !entities && + !datatypeNormalization && + !cdataSections && + namespaceDeclarations && + wellFormed && + elementContentWhitespace && + comments && + namespaces); } else if ("namespaces".equals(name)) { - return new Boolean(namespaces); + return Boolean.valueOf(namespaces); } else if ("namespace-declarations".equals(name)) { - return new Boolean(namespaceDeclarations); + return Boolean.valueOf(namespaceDeclarations); } else if ("normalize-characters".equals(name)) { - return new Boolean(normalizeCharacters); + return Boolean.valueOf(normalizeCharacters); } else if ("split-cdata-sections".equals(name)) { - return new Boolean(splitCdataSections); + return Boolean.valueOf(splitCdataSections); } else if ("validate".equals(name)) { - return new Boolean(validate); + return Boolean.valueOf(validate); } else if ("validate-if-schema".equals(name)) { - return new Boolean(validateIfSchema); + return Boolean.valueOf(validateIfSchema); } else if ("well-formed".equals(name)) { - return new Boolean(wellFormed); + return Boolean.valueOf(wellFormed); } else { @@ -497,7 +497,7 @@ public class GnomeDocument } else if (value instanceof String) { - return new Boolean ((String) value).booleanValue(); + return Boolean.valueOf ((String) value).booleanValue(); } return false; } diff --git a/gnu/xml/pipeline/ValidationConsumer.java b/gnu/xml/pipeline/ValidationConsumer.java index 0fbfa9264..839176749 100644 --- a/gnu/xml/pipeline/ValidationConsumer.java +++ b/gnu/xml/pipeline/ValidationConsumer.java @@ -1607,7 +1607,7 @@ public final class ValidationConsumer extends EventFilter throw new RuntimeException ("patchNext"); } - if (table != null && (flags | F_LOOPHEAD) != 0) + if (table != null && (flags & F_LOOPHEAD) != 0) table.put (this, this); } diff --git a/java/awt/Button.java b/java/awt/Button.java index 90be1e5b1..e788d824e 100644 --- a/java/awt/Button.java +++ b/java/awt/Button.java @@ -98,6 +98,8 @@ private transient ActionListener action_listeners; protected class AccessibleAWTButton extends AccessibleAWTComponent implements AccessibleAction, AccessibleValue { + public static final long serialVersionUID = -5932203980244017102L; + protected AccessibleAWTButton() { // Do nothing here. diff --git a/java/awt/Checkbox.java b/java/awt/Checkbox.java index cd39ad436..93f609247 100644 --- a/java/awt/Checkbox.java +++ b/java/awt/Checkbox.java @@ -392,6 +392,11 @@ Checkbox(String label, boolean state, CheckboxGroup group) this.label = label; this.state = state; this.group = group; + + if ( state && group != null ) + { + group.setSelectedCheckbox(this); + } } /*************************************************************************/ @@ -610,8 +615,10 @@ dispatchEventImpl(AWTEvent e) protected String paramString() { - return ("label=" + label + ",state=" + state + ",group=" + group - + "," + super.paramString()); + // Note: We cannot add the checkbox group information here because this + // would trigger infinite recursion when CheckboxGroup.toString() is + // called and the box is in its selected state. + return ("label=" + label + ",state=" + state + "," + super.paramString()); } /** diff --git a/java/awt/CheckboxMenuItem.java b/java/awt/CheckboxMenuItem.java index 5e446b84c..197065f65 100644 --- a/java/awt/CheckboxMenuItem.java +++ b/java/awt/CheckboxMenuItem.java @@ -335,6 +335,8 @@ paramString() implements AccessibleAction, AccessibleValue { // I think the base class provides the necessary implementation + + private static final long serialVersionUID = -1122642964303476L; } /** diff --git a/java/awt/Color.java b/java/awt/Color.java index 4ad46d0c0..b03129241 100644 --- a/java/awt/Color.java +++ b/java/awt/Color.java @@ -762,7 +762,7 @@ public class Color implements Paint, Serializable if (max == 0) array[1] = 0; else - array[1] = (max - min) / max; + array[1] = ((float) (max - min)) / ((float) max); // Calculate hue. if (array[1] == 0) array[0] = 0; diff --git a/java/awt/Component.java b/java/awt/Component.java index 0363437e1..7985a0c20 100644 --- a/java/awt/Component.java +++ b/java/awt/Component.java @@ -720,8 +720,9 @@ public abstract class Component /** * Tests if the component is displayable. It must be connected to a native - * screen resource, and all its ancestors must be displayable. A containment - * hierarchy is made displayable when a window is packed or made visible. + * screen resource. This reduces to checking that peer is not null. A + * containment hierarchy is made displayable when a window is packed or + * made visible. * * @return true if the component is displayable * @see Container#add(Component) @@ -733,9 +734,7 @@ public abstract class Component */ public boolean isDisplayable() { - if (parent != null) - return parent.isDisplayable(); - return false; + return peer != null; } /** @@ -4242,9 +4241,9 @@ public abstract class Component if (isDoubleBuffered()) param.append(",doublebuffered"); if (parent == null) - param.append(",parent==null"); + param.append(",parent=null"); else - param.append(",parent==").append(parent.getName()); + param.append(",parent=").append(parent.getName()); return param.toString(); } diff --git a/java/awt/Container.java b/java/awt/Container.java index 571c6c855..37f27b099 100644 --- a/java/awt/Container.java +++ b/java/awt/Container.java @@ -39,6 +39,7 @@ exception statement from your version. */ package java.awt; +import java.awt.event.ComponentListener; import java.awt.event.ContainerEvent; import java.awt.event.ContainerListener; import java.awt.event.KeyEvent; @@ -421,6 +422,10 @@ public class Container extends Component { Component r = component[index]; + ComponentListener[] list = r.getComponentListeners(); + for (int j = 0; j < list.length; j++) + r.removeComponentListener(list[j]); + r.removeNotify(); System.arraycopy(component, index + 1, component, index, @@ -1049,6 +1054,53 @@ public class Container extends Component return this; } } + + /** + * Finds the visible child component that contains the specified position. + * The top-most child is returned in the case where there is overlap. + * If the top-most child is transparent and has no MouseListeners attached, + * we discard it and return the next top-most component containing the + * specified position. + * @param x the x coordinate + * @param y the y coordinate + * @return null if the <code>this</code> does not contain the position, + * otherwise the top-most component (out of this container itself and + * its descendants) meeting the criteria above. + */ + Component findComponentForMouseEventAt(int x, int y) + { + synchronized (getTreeLock()) + { + if (!contains(x, y)) + return null; + + for (int i = 0; i < ncomponents; ++i) + { + // Ignore invisible children... + if (!component[i].isVisible()) + continue; + + int x2 = x - component[i].x; + int y2 = y - component[i].y; + // We don't do the contains() check right away because + // findComponentAt would redundantly do it first thing. + if (component[i] instanceof Container) + { + Container k = (Container) component[i]; + Component r = k.findComponentForMouseEventAt(x2, y2); + if (r != null) + return r; + } + else if (component[i].contains(x2, y2)) + return component[i]; + } + + //don't return transparent components with no MouseListeners + if (this.getMouseListeners().length == 0) + return null; + return this; + } + } public Component findComponentAt(Point p) { @@ -1959,6 +2011,30 @@ class LightweightDispatcher implements Serializable eventMask |= l; } + /** + * Returns the deepest visible descendent of parent that contains the + * specified location and that is not transparent and MouseListener-less. + * @param parent the root component to begin the search + * @param x the x coordinate + * @param y the y coordinate + * @return null if <code>parent</code> doesn't contain the location, + * parent if parent is not a container or has no child that contains the + * location, otherwise the appropriate component from the conditions + * above. + */ + Component getDeepestComponentForMouseEventAt ( + Component parent, int x, int y) + { + if (parent == null || (! parent.contains(x, y))) + return null; + + if (! (parent instanceof Container)) + return parent; + + Container c = (Container) parent; + return c.findComponentForMouseEventAt(x, y); + } + Component acquireComponentForMouseEvent(MouseEvent me) { int x = me.getX (); @@ -1972,7 +2048,7 @@ class LightweightDispatcher implements Serializable while (candidate == null && parent != null) { candidate = - AWTUtilities.getDeepestComponentAt(parent, p.x, p.y); + getDeepestComponentForMouseEventAt(parent, p.x, p.y); if (candidate == null || (candidate.eventMask & me.getID()) == 0) { candidate = null; diff --git a/java/awt/Dialog.java b/java/awt/Dialog.java index d3eb975a8..7e5e7215a 100644 --- a/java/awt/Dialog.java +++ b/java/awt/Dialog.java @@ -519,6 +519,8 @@ paramString() protected class AccessibleAWTDialog extends AccessibleAWTWindow { + private static final long serialVersionUID = 4837230331833941201L; + public AccessibleRole getAccessibleRole() { return AccessibleRole.DIALOG; diff --git a/java/awt/Frame.java b/java/awt/Frame.java index 05c938496..d6651f83e 100644 --- a/java/awt/Frame.java +++ b/java/awt/Frame.java @@ -591,6 +591,8 @@ public static Frame[] getFrames() protected class AccessibleAWTFrame extends AccessibleAWTWindow { + private static final long serialVersionUID = -6172960752956030250L; + public AccessibleRole getAccessibleRole() { return AccessibleRole.FRAME; diff --git a/java/awt/List.java b/java/awt/List.java index ab7d35963..00636a022 100644 --- a/java/awt/List.java +++ b/java/awt/List.java @@ -1088,18 +1088,23 @@ paramString() protected class AccessibleAWTList extends AccessibleAWTComponent implements AccessibleSelection, ItemListener, ActionListener { + private static final long serialVersionUID = 7924617370136012829L; + protected class AccessibleAWTListChild extends AccessibleAWTComponent implements Accessible { - private int index; + private static final long serialVersionUID = 4412022926028300317L; + + // Field names are fixed by serialization spec. private List parent; + private int indexInParent; public AccessibleAWTListChild(List parent, int indexInParent) { this.parent = parent; - index = indexInParent; + this.indexInParent = indexInParent; if (parent == null) - index = -1; + this.indexInParent = -1; } /* (non-Javadoc) @@ -1118,14 +1123,14 @@ paramString() public AccessibleStateSet getAccessibleStateSet() { AccessibleStateSet states = super.getAccessibleStateSet(); - if (parent.isIndexSelected(index)) + if (parent.isIndexSelected(indexInParent)) states.add(AccessibleState.SELECTED); return states; } public int getAccessibleIndexInParent() { - return index; + return indexInParent; } } diff --git a/java/awt/Menu.java b/java/awt/Menu.java index 56ceccfc5..13ebb5211 100644 --- a/java/awt/Menu.java +++ b/java/awt/Menu.java @@ -441,6 +441,8 @@ paramString() */ protected class AccessibleAWTMenu extends AccessibleAWTMenuItem { + private static final long serialVersionUID = 5228160894980069094L; + protected AccessibleAWTMenu() { } diff --git a/java/awt/MenuItem.java b/java/awt/MenuItem.java index 58dcb6741..3e39d118a 100644 --- a/java/awt/MenuItem.java +++ b/java/awt/MenuItem.java @@ -108,6 +108,8 @@ private transient ActionListener action_listeners; extends MenuComponent.AccessibleAWTMenuComponent implements AccessibleAction, AccessibleValue { + private static final long serialVersionUID = -217847831945965825L; + /** Constructor */ public AccessibleAWTMenuItem() { diff --git a/java/awt/Point.java b/java/awt/Point.java index 492749b8d..31b72e2cc 100644 --- a/java/awt/Point.java +++ b/java/awt/Point.java @@ -226,6 +226,10 @@ public class Point extends Point2D implements Serializable */ public boolean equals(Object obj) { + // NOTE: No special hashCode() method is required for this class, + // as this equals() implementation is functionally equivalent to + // super.equals(), which does define a proper hashCode(). + if (! (obj instanceof Point2D)) return false; Point2D p = (Point2D) obj; diff --git a/java/awt/PopupMenu.java b/java/awt/PopupMenu.java index 90d48d903..540fffda7 100644 --- a/java/awt/PopupMenu.java +++ b/java/awt/PopupMenu.java @@ -140,6 +140,8 @@ show(Component component, int x, int y) protected class AccessibleAWTPopupMenu extends AccessibleAWTMenu { + private static final long serialVersionUID = -4282044795947239955L; + protected AccessibleAWTPopupMenu() { } diff --git a/java/awt/Rectangle.java b/java/awt/Rectangle.java index 0f21d495c..c4ba6ba14 100644 --- a/java/awt/Rectangle.java +++ b/java/awt/Rectangle.java @@ -727,6 +727,10 @@ public class Rectangle extends Rectangle2D implements Shape, Serializable */ public boolean equals(Object obj) { + // NOTE: No special hashCode() method is required for this class, + // as this equals() implementation is functionally equivalent to + // super.equals(), which does define a proper hashCode(). + if (! (obj instanceof Rectangle2D)) return false; Rectangle2D r = (Rectangle2D) obj; diff --git a/java/awt/ScrollPane.java b/java/awt/ScrollPane.java index b3ecc59fc..d35d9490d 100644 --- a/java/awt/ScrollPane.java +++ b/java/awt/ScrollPane.java @@ -592,6 +592,8 @@ paramString() protected class AccessibleAWTScrollPane extends AccessibleAWTContainer { + private static final long serialVersionUID = 6100703663886637L; + public AccessibleRole getAccessibleRole() { return AccessibleRole.SCROLL_PANE; diff --git a/java/awt/TextArea.java b/java/awt/TextArea.java index d422d3306..b04cdc892 100644 --- a/java/awt/TextArea.java +++ b/java/awt/TextArea.java @@ -603,6 +603,8 @@ public class TextArea extends TextComponent implements java.io.Serializable protected class AccessibleAWTTextArea extends AccessibleAWTTextComponent { + private static final long serialVersionUID = 3472827823632144419L; + protected AccessibleAWTTextArea() { } diff --git a/java/awt/TextComponent.java b/java/awt/TextComponent.java index 60e72fcb5..f08e59c9f 100644 --- a/java/awt/TextComponent.java +++ b/java/awt/TextComponent.java @@ -107,6 +107,8 @@ protected transient TextListener textListener; extends AccessibleAWTComponent implements AccessibleText, TextListener { + private static final long serialVersionUID = 3631432373506317811L; + // Constructor // Adds a listener for tracking caret changes public AccessibleAWTTextComponent() diff --git a/java/awt/TextField.java b/java/awt/TextField.java index 4d62d024a..3302a2eff 100644 --- a/java/awt/TextField.java +++ b/java/awt/TextField.java @@ -523,6 +523,8 @@ paramString() protected class AccessibleAWTTextField extends AccessibleAWTTextComponent { + private static final long serialVersionUID = 6219164359235943158L; + protected AccessibleAWTTextField() { } diff --git a/java/awt/Window.java b/java/awt/Window.java index 1689d0370..53c54d2c0 100644 --- a/java/awt/Window.java +++ b/java/awt/Window.java @@ -101,6 +101,8 @@ public class Window extends Container implements Accessible protected class AccessibleAWTWindow extends AccessibleAWTContainer { + private static final long serialVersionUID = 4215068635060671780L; + public AccessibleRole getAccessibleRole() { return AccessibleRole.WINDOW; @@ -346,13 +348,6 @@ public class Window extends Container implements Accessible super.hide(); } - public boolean isDisplayable() - { - if (super.isDisplayable()) - return true; - return peer != null; - } - /** * Destroys any resources associated with this window. This includes * all components in the window and all owned top-level windows. diff --git a/java/awt/event/InputEvent.java b/java/awt/event/InputEvent.java index 8f9aed611..28cd90185 100644 --- a/java/awt/event/InputEvent.java +++ b/java/awt/event/InputEvent.java @@ -197,17 +197,28 @@ public abstract class InputEvent extends ComponentEvent private final long when; /** - * The modifiers in effect for this event. Package visible for use by - * subclasses. The old style (bitmask 0x3f) should not be mixed with the - * new style (bitmasks 0xffffffc0). + * The old-style modifiers in effect for this event. Package visible + * for use by subclasses. The old style (bitmask 0x3f) should not be + * mixed with the new style (bitmasks 0xffffffc0). * * @see #getModifiers() * @see MouseEvent - * @serial the modifier state, stored in the new style + * @serial the modifier state, stored in the old style */ int modifiers; /** + * The new-style modifiers in effect for this event. Package visible + * for use by subclasses. The old style (bitmask 0x3f) should not be + * mixed with the new style (bitmasks 0xffffffc0). + * + * @see #getModifiersEx() + * @see MouseEvent + * @serial the modifier state, stored in the new style + */ + int modifiersEx; + + /** * Initializes a new instance of <code>InputEvent</code> with the specified * source, id, timestamp, and modifiers. Note that an invalid id leads to * unspecified results. @@ -222,7 +233,8 @@ public abstract class InputEvent extends ComponentEvent { super(source, id); this.when = when; - this.modifiers = EventModifier.extend(modifiers); + this.modifiers = modifiers & EventModifier.OLD_MASK; + this.modifiersEx = modifiers & EventModifier.NEW_MASK; } /** @@ -232,7 +244,8 @@ public abstract class InputEvent extends ComponentEvent */ public boolean isShiftDown() { - return (modifiers & SHIFT_DOWN_MASK) != 0; + return ((modifiers & SHIFT_MASK) != 0) + || ((modifiersEx & SHIFT_DOWN_MASK) != 0); } /** @@ -243,7 +256,8 @@ public abstract class InputEvent extends ComponentEvent */ public boolean isControlDown() { - return (modifiers & CTRL_DOWN_MASK) != 0; + return ((modifiers & CTRL_MASK) != 0) + || ((modifiersEx & CTRL_DOWN_MASK) != 0); } /** @@ -253,7 +267,8 @@ public abstract class InputEvent extends ComponentEvent */ public boolean isMetaDown() { - return (modifiers & META_DOWN_MASK) != 0; + return ((modifiers & META_MASK) != 0) + || ((modifiersEx & META_DOWN_MASK) != 0); } /** @@ -263,7 +278,8 @@ public abstract class InputEvent extends ComponentEvent */ public boolean isAltDown() { - return (modifiers & ALT_DOWN_MASK) != 0; + return ((modifiers & ALT_MASK) != 0) + || ((modifiersEx & ALT_DOWN_MASK) != 0); } /** @@ -274,7 +290,8 @@ public abstract class InputEvent extends ComponentEvent */ public boolean isAltGraphDown() { - return (modifiers & ALT_GRAPH_DOWN_MASK) != 0; + return ((modifiers & ALT_GRAPH_MASK) != 0) + || ((modifiersEx & ALT_GRAPH_DOWN_MASK) != 0); } /** @@ -300,7 +317,7 @@ public abstract class InputEvent extends ComponentEvent */ public int getModifiers() { - return EventModifier.revert(modifiers); + return modifiers; } /** @@ -321,7 +338,7 @@ public abstract class InputEvent extends ComponentEvent */ public int getModifiersEx() { - return modifiers; + return modifiersEx; } /** diff --git a/java/awt/event/KeyEvent.java b/java/awt/event/KeyEvent.java index a40a8e15c..d4b93ba3e 100644 --- a/java/awt/event/KeyEvent.java +++ b/java/awt/event/KeyEvent.java @@ -1735,6 +1735,6 @@ public class KeyEvent extends InputEvent throws IOException, ClassNotFoundException { s.defaultReadObject(); - modifiers = EventModifier.extend(modifiers); + modifiersEx = EventModifier.extend(modifiers) & EventModifier.NEW_MASK; } } // class KeyEvent diff --git a/java/awt/event/MouseEvent.java b/java/awt/event/MouseEvent.java index 249c3d112..b13a8c599 100644 --- a/java/awt/event/MouseEvent.java +++ b/java/awt/event/MouseEvent.java @@ -227,6 +227,12 @@ public class MouseEvent extends InputEvent else if ((modifiers & BUTTON3_MASK) != 0) this.button = BUTTON3; } + // clear the mouse button modifier masks if this is a button + // release event. + if (id == MOUSE_RELEASED) + this.modifiersEx &= ~(BUTTON1_DOWN_MASK + | BUTTON2_DOWN_MASK + | BUTTON3_DOWN_MASK); } /** @@ -392,17 +398,9 @@ public class MouseEvent extends InputEvent s.append("unknown type,("); } s.append(x).append(',').append(y).append("),button=").append(button); - if ((modifiers & EventModifier.NEW_MASK) != 0) - { - int mod = modifiers; - if ((mod & (ALT_DOWN_MASK | BUTTON2_DOWN_MASK)) != 0) - mod |= ALT_DOWN_MASK | BUTTON2_DOWN_MASK; - if ((mod & (META_DOWN_MASK | BUTTON3_DOWN_MASK)) != 0) - mod |= META_DOWN_MASK | BUTTON3_DOWN_MASK; - s.append(",modifiers=").append(getModifiersExText(mod)); - } - if (modifiers != 0) - s.append(",extModifiers=").append(getModifiersExText(modifiers)); + // FIXME: need a mauve test for this method + if (modifiersEx != 0) + s.append(",extModifiers=").append(getModifiersExText(modifiersEx)); return s.append(",clickCount=").append(clickCount).toString(); } @@ -426,7 +424,7 @@ public class MouseEvent extends InputEvent button = BUTTON2; else if ((modifiers & BUTTON3_MASK) != 0) button = BUTTON3; - modifiers = EventModifier.extend(modifiers); + modifiersEx = EventModifier.extend(modifiers) & EventModifier.NEW_MASK; } } } // class MouseEvent diff --git a/java/io/ByteArrayOutputStream.java b/java/io/ByteArrayOutputStream.java index e996ebbc7..4196523d2 100644 --- a/java/io/ByteArrayOutputStream.java +++ b/java/io/ByteArrayOutputStream.java @@ -1,5 +1,6 @@ /* BufferedReader.java - Copyright (C) 1998, 1999, 2000, 2001, 2003, 2005 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2000, 2001, 2003, 2005 + Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -192,7 +193,7 @@ public class ByteArrayOutputStream extends OutputStream */ public String toString (int hibyte) { - return new String (buf, 0, count, hibyte); + return new String (buf, hibyte, 0, count); } // Resize buffer to accommodate new bytes. diff --git a/java/io/DataOutputStream.java b/java/io/DataOutputStream.java index 39f7ed1ff..25178160d 100644 --- a/java/io/DataOutputStream.java +++ b/java/io/DataOutputStream.java @@ -302,7 +302,7 @@ public class DataOutputStream extends FilterOutputStream implements DataOutput * * @exception IOException If an error occurs * - * @see writeInt + * @see #writeInt(int) * @see DataInput#readFloat * @see Float#floatToIntBits */ @@ -326,7 +326,7 @@ public class DataOutputStream extends FilterOutputStream implements DataOutput * * @exception IOException If an error occurs * - * @see writeLong + * @see #writeLong(long) * @see DataInput#readDouble * @see Double#doubleToLongBits */ @@ -363,7 +363,7 @@ public class DataOutputStream extends FilterOutputStream implements DataOutput * * @exception IOException If an error occurs * - * @see writeChar + * @see #writeChar(char) */ public final void writeChars (String value) throws IOException { diff --git a/java/io/FilterReader.java b/java/io/FilterReader.java index 2bd040a7f..1abaa8a4b 100644 --- a/java/io/FilterReader.java +++ b/java/io/FilterReader.java @@ -131,7 +131,7 @@ public abstract class FilterReader extends Reader /** * Calls the <code>in.skip(long)</code> method * - * @param numBytes The requested number of chars to skip. + * @param num_chars The requested number of chars to skip. * * @return The value returned from <code>in.skip(long)</code> * diff --git a/java/io/InputStreamReader.java b/java/io/InputStreamReader.java index 315af83e1..4f77172af 100644 --- a/java/io/InputStreamReader.java +++ b/java/io/InputStreamReader.java @@ -38,16 +38,14 @@ exception statement from your version. */ package java.io; -import java.nio.charset.UnsupportedCharsetException; -import java.nio.charset.CharacterCodingException; -import java.nio.charset.IllegalCharsetNameException; -import java.nio.charset.CoderResult; -import java.nio.charset.CodingErrorAction; +import gnu.java.nio.charset.EncodingHelper; + +import java.nio.ByteBuffer; +import java.nio.CharBuffer; import java.nio.charset.Charset; import java.nio.charset.CharsetDecoder; -import java.nio.CharBuffer; -import java.nio.ByteBuffer; -import gnu.java.nio.charset.EncodingHelper; +import java.nio.charset.CoderResult; +import java.nio.charset.CodingErrorAction; /** * This class reads characters from a byte input stream. The characters diff --git a/java/io/LineNumberReader.java b/java/io/LineNumberReader.java index ea418a5e4..5e263f761 100644 --- a/java/io/LineNumberReader.java +++ b/java/io/LineNumberReader.java @@ -115,7 +115,7 @@ public class LineNumberReader extends BufferedReader /** * This method sets the current line number to the specified value. * - * @param line_number The new line number + * @param lineNumber The new line number */ public void setLineNumber(int lineNumber) { @@ -139,7 +139,7 @@ public class LineNumberReader extends BufferedReader * is called, the line number will be restored to the saved line number in * addition to the stream position. * - * @param readlimit The number of chars that can be read before the + * @param readLimit The number of chars that can be read before the * mark becomes invalid * * @exception IOException If an error occurs @@ -269,7 +269,7 @@ public class LineNumberReader extends BufferedReader * * @param buf The array into which the chars read should be stored * @param offset The offset into the array to start storing chars - * @param len The requested number of chars to read + * @param count The requested number of chars to read * * @return The actual number of chars read, or -1 if end of stream * diff --git a/java/io/ObjectInputStream.java b/java/io/ObjectInputStream.java index f32703d09..12e384cec 100644 --- a/java/io/ObjectInputStream.java +++ b/java/io/ObjectInputStream.java @@ -39,7 +39,6 @@ exception statement from your version. */ package java.io; -import gnu.classpath.Configuration; import gnu.java.io.ObjectIdentityWrapper; import java.lang.reflect.Array; @@ -128,7 +127,8 @@ public class ObjectInputStream extends InputStream * @exception IOException Exception from underlying * <code>InputStream</code>. */ - public final Object readObject() throws ClassNotFoundException, IOException + public final Object readObject() + throws ClassNotFoundException, IOException { if (this.useSubclassMethod) return readObjectOverride(); @@ -138,7 +138,6 @@ public class ObjectInputStream extends InputStream Object ret_val; was_deserializing = this.isDeserializing; - boolean is_consumed = false; boolean old_mode = setBlockDataMode(false); this.isDeserializing = true; @@ -151,268 +150,285 @@ public class ObjectInputStream extends InputStream try { - switch (marker) + ret_val = parseContent(marker); + } + finally + { + setBlockDataMode(old_mode); + + this.isDeserializing = was_deserializing; + + depth -= 2; + + if (! was_deserializing) { - case TC_ENDBLOCKDATA: - { - ret_val = null; - is_consumed = true; - break; - } - - case TC_BLOCKDATA: - case TC_BLOCKDATALONG: - { - if (marker == TC_BLOCKDATALONG) - { if(dump) dumpElementln("BLOCKDATALONG"); } - else - { if(dump) dumpElementln("BLOCKDATA"); } - readNextBlock(marker); - throw new StreamCorruptedException("Unexpected blockData"); - } - - case TC_NULL: - { - if(dump) dumpElementln("NULL"); - ret_val = null; - break; - } - - case TC_REFERENCE: - { - if(dump) dumpElement("REFERENCE "); - Integer oid = new Integer(this.realInputStream.readInt()); - if(dump) dumpElementln(Integer.toHexString(oid.intValue())); - ret_val = ((ObjectIdentityWrapper) - this.objectLookupTable.get(oid)).object; - break; - } - - case TC_CLASS: + if (validators.size() > 0) + invokeValidators(); + } + } + + return ret_val; + } + + /** + * Handles a content block within the stream, which begins with a marker + * byte indicating its type. + * + * @param marker the byte marker. + * @return an object which represents the parsed content. + * @throws ClassNotFoundException if the class of an object being + * read in cannot be found. + * @throws IOException if invalid data occurs or one is thrown by the + * underlying <code>InputStream</code>. + */ + private Object parseContent(byte marker) + throws ClassNotFoundException, IOException + { + Object ret_val; + boolean is_consumed = false; + + switch (marker) + { + case TC_ENDBLOCKDATA: + { + ret_val = null; + is_consumed = true; + break; + } + + case TC_BLOCKDATA: + case TC_BLOCKDATALONG: + { + if (marker == TC_BLOCKDATALONG) + { if(dump) dumpElementln("BLOCKDATALONG"); } + else + { if(dump) dumpElementln("BLOCKDATA"); } + readNextBlock(marker); + throw new StreamCorruptedException("Unexpected blockData"); + } + + case TC_NULL: + { + if(dump) dumpElementln("NULL"); + ret_val = null; + break; + } + + case TC_REFERENCE: + { + if(dump) dumpElement("REFERENCE "); + Integer oid = new Integer(this.realInputStream.readInt()); + if(dump) dumpElementln(Integer.toHexString(oid.intValue())); + ret_val = ((ObjectIdentityWrapper) + this.objectLookupTable.get(oid)).object; + break; + } + + case TC_CLASS: + { + if(dump) dumpElementln("CLASS"); + ObjectStreamClass osc = (ObjectStreamClass)readObject(); + Class clazz = osc.forClass(); + assignNewHandle(clazz); + ret_val = clazz; + break; + } + + case TC_PROXYCLASSDESC: + { + if(dump) dumpElementln("PROXYCLASS"); + int n_intf = this.realInputStream.readInt(); + String[] intfs = new String[n_intf]; + for (int i = 0; i < n_intf; i++) + { + intfs[i] = this.realInputStream.readUTF(); + System.out.println(intfs[i]); + } + + boolean oldmode = setBlockDataMode(true); + Class cl = resolveProxyClass(intfs); + setBlockDataMode(oldmode); + + ObjectStreamClass osc = lookupClass(cl); + assignNewHandle(osc); + + if (!is_consumed) + { + byte b = this.realInputStream.readByte(); + if (b != TC_ENDBLOCKDATA) + throw new IOException("Data annotated to class was not consumed." + b); + } + else + is_consumed = false; + ObjectStreamClass superosc = (ObjectStreamClass)readObject(); + osc.setSuperclass(superosc); + ret_val = osc; + break; + } + + case TC_CLASSDESC: + { + ObjectStreamClass osc = readClassDescriptor(); + + if (!is_consumed) + { + byte b = this.realInputStream.readByte(); + if (b != TC_ENDBLOCKDATA) + throw new IOException("Data annotated to class was not consumed." + b); + } + else + is_consumed = false; + + osc.setSuperclass ((ObjectStreamClass)readObject()); + ret_val = osc; + break; + } + + case TC_STRING: + case TC_LONGSTRING: + { + if(dump) dumpElement("STRING="); + String s = this.realInputStream.readUTF(); + if(dump) dumpElementln(s); + ret_val = processResolution(null, s, assignNewHandle(s)); + break; + } + + case TC_ARRAY: + { + if(dump) dumpElementln("ARRAY"); + ObjectStreamClass osc = (ObjectStreamClass)readObject(); + Class componentType = osc.forClass().getComponentType(); + if(dump) dumpElement("ARRAY LENGTH="); + int length = this.realInputStream.readInt(); + if(dump) dumpElementln (length + "; COMPONENT TYPE=" + componentType); + Object array = Array.newInstance(componentType, length); + int handle = assignNewHandle(array); + readArrayElements(array, componentType); + if(dump) + for (int i = 0, len = Array.getLength(array); i < len; i++) + dumpElementln(" ELEMENT[" + i + "]=" + Array.get(array, i)); + ret_val = processResolution(null, array, handle); + break; + } + + case TC_OBJECT: + { + if(dump) dumpElementln("OBJECT"); + ObjectStreamClass osc = (ObjectStreamClass)readObject(); + Class clazz = osc.forClass(); + + if (!osc.realClassIsSerializable) + throw new NotSerializableException + (clazz + " is not Serializable, and thus cannot be deserialized."); + + if (osc.realClassIsExternalizable) { - if(dump) dumpElementln("CLASS"); - ObjectStreamClass osc = (ObjectStreamClass)readObject(); - Class clazz = osc.forClass(); - assignNewHandle(clazz); - ret_val = clazz; - break; - } - - case TC_PROXYCLASSDESC: - { - if(dump) dumpElementln("PROXYCLASS"); - int n_intf = this.realInputStream.readInt(); - String[] intfs = new String[n_intf]; - for (int i = 0; i < n_intf; i++) - { - intfs[i] = this.realInputStream.readUTF(); - System.out.println(intfs[i]); - } + Externalizable obj = osc.newInstance(); - boolean oldmode = setBlockDataMode(true); - Class cl = resolveProxyClass(intfs); - setBlockDataMode(oldmode); + int handle = assignNewHandle(obj); - ObjectStreamClass osc = lookupClass(cl); - assignNewHandle(osc); + boolean read_from_blocks = ((osc.getFlags() & SC_BLOCK_DATA) != 0); - if (!is_consumed) - { - byte b = this.realInputStream.readByte(); - if (b != TC_ENDBLOCKDATA) - throw new IOException("Data annotated to class was not consumed." + b); - } - else - is_consumed = false; - ObjectStreamClass superosc = (ObjectStreamClass)readObject(); - osc.setSuperclass(superosc); - ret_val = osc; - break; - } - - case TC_CLASSDESC: - { - ObjectStreamClass osc = readClassDescriptor(); + boolean oldmode = this.readDataFromBlock; + if (read_from_blocks) + setBlockDataMode(true); - if (!is_consumed) - { - byte b = this.realInputStream.readByte(); - if (b != TC_ENDBLOCKDATA) - throw new IOException("Data annotated to class was not consumed." + b); + obj.readExternal(this); + + if (read_from_blocks) + { + setBlockDataMode(oldmode); + if (!oldmode) + if (this.realInputStream.readByte() != TC_ENDBLOCKDATA) + throw new IOException("No end of block data seen for class with readExternal (ObjectInputStream) method."); } - else - is_consumed = false; - - osc.setSuperclass ((ObjectStreamClass)readObject()); - ret_val = osc; - break; - } - case TC_STRING: - case TC_LONGSTRING: - { - if(dump) dumpElement("STRING="); - String s = this.realInputStream.readUTF(); - if(dump) dumpElementln(s); - ret_val = processResolution(null, s, assignNewHandle(s)); - break; - } - - case TC_ARRAY: - { - if(dump) dumpElementln("ARRAY"); - ObjectStreamClass osc = (ObjectStreamClass)readObject(); - Class componentType = osc.forClass().getComponentType(); - if(dump) dumpElement("ARRAY LENGTH="); - int length = this.realInputStream.readInt(); - if(dump) dumpElementln (length + "; COMPONENT TYPE=" + componentType); - Object array = Array.newInstance(componentType, length); - int handle = assignNewHandle(array); - readArrayElements(array, componentType); - if(dump) - for (int i = 0, len = Array.getLength(array); i < len; i++) - dumpElementln(" ELEMENT[" + i + "]=" + Array.get(array, i)); - ret_val = processResolution(null, array, handle); - break; - } - - case TC_OBJECT: - { - if(dump) dumpElementln("OBJECT"); - ObjectStreamClass osc = (ObjectStreamClass)readObject(); - Class clazz = osc.forClass(); + ret_val = processResolution(osc, obj, handle); + break; - if (!osc.realClassIsSerializable) - throw new NotSerializableException - (clazz + " is not Serializable, and thus cannot be deserialized."); - - if (osc.realClassIsExternalizable) - { - Externalizable obj = osc.newInstance(); - - int handle = assignNewHandle(obj); - - boolean read_from_blocks = ((osc.getFlags() & SC_BLOCK_DATA) != 0); - - boolean oldmode = this.readDataFromBlock; - if (read_from_blocks) - setBlockDataMode(true); - - obj.readExternal(this); - - if (read_from_blocks) - { - setBlockDataMode(oldmode); - if (!oldmode) - if (this.realInputStream.readByte() != TC_ENDBLOCKDATA) - throw new IOException("No end of block data seen for class with readExternal (ObjectInputStream) method."); - } - - ret_val = processResolution(osc, obj, handle); - break; - } // end if (osc.realClassIsExternalizable) - - Object obj = newObject(clazz, osc.firstNonSerializableParentConstructor); - - int handle = assignNewHandle(obj); - Object prevObject = this.currentObject; - ObjectStreamClass prevObjectStreamClass = this.currentObjectStreamClass; - - this.currentObject = obj; - ObjectStreamClass[] hierarchy = - inputGetObjectStreamClasses(clazz); - - for (int i = 0; i < hierarchy.length; i++) - { - this.currentObjectStreamClass = hierarchy[i]; - - if(dump) dumpElementln("Reading fields of " + this.currentObjectStreamClass.getName ()); - - // XXX: should initialize fields in classes in the hierarchy - // that aren't in the stream - // should skip over classes in the stream that aren't in the - // real classes hierarchy - - Method readObjectMethod = this.currentObjectStreamClass.readObjectMethod; - if (readObjectMethod != null) - { - fieldsAlreadyRead = false; - boolean oldmode = setBlockDataMode(true); - callReadMethod(readObjectMethod, this.currentObjectStreamClass.forClass(), obj); - setBlockDataMode(oldmode); - } - else - { - readFields(obj, currentObjectStreamClass); - } - - if (this.currentObjectStreamClass.hasWriteMethod()) - { - if(dump) dumpElement("ENDBLOCKDATA? "); - try - { - // FIXME: XXX: This try block is to - // catch EOF which is thrown for some - // objects. That indicates a bug in - // the logic. - - if (this.realInputStream.readByte() != TC_ENDBLOCKDATA) - throw new IOException - ("No end of block data seen for class with readObject (ObjectInputStream) method."); - if(dump) dumpElementln("yes"); - } -// catch (EOFException e) -// { -// if(dump) dumpElementln("no, got EOFException"); -// } - catch (IOException e) - { - if(dump) dumpElementln("no, got IOException"); + } // end if (osc.realClassIsExternalizable) + + Object obj = newObject(clazz, osc.firstNonSerializableParentConstructor); + + int handle = assignNewHandle(obj); + Object prevObject = this.currentObject; + ObjectStreamClass prevObjectStreamClass = this.currentObjectStreamClass; + + this.currentObject = obj; + ObjectStreamClass[] hierarchy = + inputGetObjectStreamClasses(clazz); + + for (int i = 0; i < hierarchy.length; i++) + { + this.currentObjectStreamClass = hierarchy[i]; + if(dump) dumpElementln("Reading fields of " + this.currentObjectStreamClass.getName ()); + + // XXX: should initialize fields in classes in the hierarchy + // that aren't in the stream + // should skip over classes in the stream that aren't in the + // real classes hierarchy + + Method readObjectMethod = this.currentObjectStreamClass.readObjectMethod; + if (readObjectMethod != null) + { + fieldsAlreadyRead = false; + boolean oldmode = setBlockDataMode(true); + callReadMethod(readObjectMethod, this.currentObjectStreamClass.forClass(), obj); + setBlockDataMode(oldmode); + } + else + { + readFields(obj, currentObjectStreamClass); + } + + if (this.currentObjectStreamClass.hasWriteMethod()) + { + if(dump) dumpElement("ENDBLOCKDATA? "); + try + { + /* Read blocks until an end marker */ + byte writeMarker = this.realInputStream.readByte(); + while (writeMarker != TC_ENDBLOCKDATA) + { + parseContent(writeMarker); + writeMarker = this.realInputStream.readByte(); } + if(dump) dumpElementln("yes"); + } + catch (EOFException e) + { + throw (IOException) new IOException + ("No end of block data seen for class with readObject (ObjectInputStream) method.").initCause(e); } } - - this.currentObject = prevObject; - this.currentObjectStreamClass = prevObjectStreamClass; - ret_val = processResolution(osc, obj, handle); - - break; } - - case TC_RESET: - if(dump) dumpElementln("RESET"); - clearHandles(); - ret_val = readObject(); - break; - - case TC_EXCEPTION: - { - if(dump) dumpElement("EXCEPTION="); - Exception e = (Exception)readObject(); - if(dump) dumpElementln(e.toString()); - clearHandles(); - throw new WriteAbortedException("Exception thrown during writing of stream", e); - } - - default: - throw new IOException("Unknown marker on stream: " + marker); - } - } - finally - { - setBlockDataMode(old_mode); + + this.currentObject = prevObject; + this.currentObjectStreamClass = prevObjectStreamClass; + ret_val = processResolution(osc, obj, handle); + + break; + } - this.isDeserializing = was_deserializing; + case TC_RESET: + if(dump) dumpElementln("RESET"); + clearHandles(); + ret_val = readObject(); + break; - depth -= 2; + case TC_EXCEPTION: + { + if(dump) dumpElement("EXCEPTION="); + Exception e = (Exception)readObject(); + if(dump) dumpElementln(e.toString()); + clearHandles(); + throw new WriteAbortedException("Exception thrown during writing of stream", e); + } - if (! was_deserializing) - { - if (validators.size() > 0) - invokeValidators(); - } + default: + throw new IOException("Unknown marker on stream: " + marker); } - return ret_val; } @@ -812,7 +828,7 @@ public class ObjectInputStream extends InputStream /** * Reconstruct class hierarchy the same way - * {@link java.io.ObjectStreamClass.getObjectStreamClasses(java.lang.Class)} does + * {@link java.io.ObjectStreamClass#getObjectStreamClasses(Class)} does * but using lookupClass instead of ObjectStreamClass.lookup. This * dup is necessary localize the lookup table. Hopefully some future * rewritings will be able to prevent this. @@ -881,7 +897,7 @@ public class ObjectInputStream extends InputStream } else for (int i = 0; i < intfs.length; i++) - clss[i] = cl.loadClass(intfs[i]); + clss[i] = Class.forName(intfs[i], false, cl); try { return Proxy.getProxyClass(cl, clss); @@ -1202,7 +1218,7 @@ public class ObjectInputStream extends InputStream * This method should be called by a method called 'readObject' in the * deserializing class (if present). It cannot (and should not)be called * outside of it. Its goal is to read all fields in the real input stream - * and keep them accessible through the {@link #GetField} class. Calling + * and keep them accessible through the {@link GetField} class. Calling * this method will not alter the deserializing object. * * @return A valid freshly created 'GetField' instance to get access to @@ -1915,14 +1931,6 @@ public class ObjectInputStream extends InputStream System.out.print (Thread.currentThread() + ": "); } - static - { - if (Configuration.INIT_LOAD_LIBRARY) - { - System.loadLibrary ("javaio"); - } - } - // used to keep a prioritized list of object validators private static final class ValidatorAndPriority implements Comparable { diff --git a/java/io/ObjectOutputStream.java b/java/io/ObjectOutputStream.java index 21cc83142..3edb6e0b7 100644 --- a/java/io/ObjectOutputStream.java +++ b/java/io/ObjectOutputStream.java @@ -39,7 +39,6 @@ exception statement from your version. */ package java.io; -import gnu.classpath.Configuration; import gnu.java.io.ObjectIdentityWrapper; import gnu.java.lang.reflect.TypeSignature; import gnu.java.security.action.SetAccessibleAction; @@ -418,37 +417,53 @@ public class ObjectOutputStream extends OutputStream protected void writeClassDescriptor(ObjectStreamClass osc) throws IOException { - realOutput.writeByte(TC_CLASSDESC); - realOutput.writeUTF(osc.getName()); - realOutput.writeLong(osc.getSerialVersionUID()); - assignNewHandle(osc); + if (osc.isProxyClass) + { + realOutput.writeByte(TC_PROXYCLASSDESC); + Class[] intfs = osc.forClass().getInterfaces(); + realOutput.writeInt(intfs.length); + for (int i = 0; i < intfs.length; i++) + realOutput.writeUTF(intfs[i].getName()); + + boolean oldmode = setBlockDataMode(true); + annotateProxyClass(osc.forClass()); + setBlockDataMode(oldmode); + realOutput.writeByte(TC_ENDBLOCKDATA); + } + else + { + realOutput.writeByte(TC_CLASSDESC); + realOutput.writeUTF(osc.getName()); + realOutput.writeLong(osc.getSerialVersionUID()); + assignNewHandle(osc); - int flags = osc.getFlags(); + int flags = osc.getFlags(); - if (protocolVersion == PROTOCOL_VERSION_2 - && osc.isExternalizable()) - flags |= SC_BLOCK_DATA; + if (protocolVersion == PROTOCOL_VERSION_2 + && osc.isExternalizable()) + flags |= SC_BLOCK_DATA; - realOutput.writeByte(flags); + realOutput.writeByte(flags); - ObjectStreamField[] fields = osc.fields; - realOutput.writeShort(fields.length); + ObjectStreamField[] fields = osc.fields; + realOutput.writeShort(fields.length); - ObjectStreamField field; - for (int i = 0; i < fields.length; i++) - { - field = fields[i]; - realOutput.writeByte(field.getTypeCode ()); - realOutput.writeUTF(field.getName ()); + ObjectStreamField field; + for (int i = 0; i < fields.length; i++) + { + field = fields[i]; + realOutput.writeByte(field.getTypeCode ()); + realOutput.writeUTF(field.getName ()); - if (! field.isPrimitive()) - writeObject(field.getTypeString()); - } + if (! field.isPrimitive()) + writeObject(field.getTypeString()); + } - boolean oldmode = setBlockDataMode(true); - annotateClass(osc.forClass()); - setBlockDataMode(oldmode); - realOutput.writeByte(TC_ENDBLOCKDATA); + boolean oldmode = setBlockDataMode(true); + annotateClass(osc.forClass()); + setBlockDataMode(oldmode); + realOutput.writeByte(TC_ENDBLOCKDATA); + } if (osc.isSerializable() || osc.isExternalizable()) writeObject(osc.getSuper()); @@ -1573,12 +1588,4 @@ public class ObjectOutputStream extends OutputStream private boolean dump = false; private static final boolean DEBUG = false; - - static - { - if (Configuration.INIT_LOAD_LIBRARY) - { - System.loadLibrary("javaio"); - } - } } diff --git a/java/io/ObjectStreamClass.java b/java/io/ObjectStreamClass.java index 2b3c803bf..ddff8dfb4 100644 --- a/java/io/ObjectStreamClass.java +++ b/java/io/ObjectStreamClass.java @@ -521,14 +521,15 @@ outer: { Method res = c.getDeclaredMethod(name, noArgs); int mods = res.getModifiers(); - - if (c != from - && (Modifier.isPrivate(mods) - || ! Modifier.isPublic(mods) && ! inSamePackage(c, from))) - continue; - - AccessController.doPrivileged(new SetAccessibleAction(res)); - return res; + + if (c == from + || Modifier.isProtected(mods) + || Modifier.isPublic(mods) + || (! Modifier.isPrivate(mods) && inSamePackage(c, from))) + { + AccessController.doPrivileged(new SetAccessibleAction(res)); + return res; + } } catch (NoSuchMethodException e) { diff --git a/java/io/ObjectStreamField.java b/java/io/ObjectStreamField.java index 21578aca2..073277971 100644 --- a/java/io/ObjectStreamField.java +++ b/java/io/ObjectStreamField.java @@ -214,7 +214,7 @@ public class ObjectStreamField implements Comparable * This method sets the current offset of the field. * * @param off The offset of the field in bytes. - * @see getOffset() + * @see #getOffset() */ protected void setOffset (int off) { diff --git a/java/io/OutputStreamWriter.java b/java/io/OutputStreamWriter.java index ee229796c..a0ac3ff97 100644 --- a/java/io/OutputStreamWriter.java +++ b/java/io/OutputStreamWriter.java @@ -39,16 +39,14 @@ exception statement from your version. */ package java.io; import gnu.java.nio.charset.EncodingHelper; + import java.nio.ByteBuffer; import java.nio.CharBuffer; -import java.nio.charset.MalformedInputException; -import java.nio.charset.UnsupportedCharsetException; import java.nio.charset.CharacterCodingException; -import java.nio.charset.IllegalCharsetNameException; -import java.nio.charset.CoderResult; -import java.nio.charset.CodingErrorAction; import java.nio.charset.Charset; import java.nio.charset.CharsetEncoder; +import java.nio.charset.CodingErrorAction; +import java.nio.charset.MalformedInputException; /** * This class writes characters to an output stream that is byte oriented diff --git a/java/io/PipedInputStream.java b/java/io/PipedInputStream.java index beb310b4f..523ae2c70 100644 --- a/java/io/PipedInputStream.java +++ b/java/io/PipedInputStream.java @@ -130,7 +130,7 @@ public class PipedInputStream extends InputStream * This stream is then ready for reading. If this stream is already * connected or has been previously closed, then an exception is thrown * - * @param src The <code>PipedOutputStream</code> to connect this stream to + * @param source The <code>PipedOutputStream</code> to connect this stream to * * @exception IOException If this PipedInputStream or <code>source</code> * has been connected already. diff --git a/java/io/PrintWriter.java b/java/io/PrintWriter.java index 13570ff0a..1b81170f8 100644 --- a/java/io/PrintWriter.java +++ b/java/io/PrintWriter.java @@ -70,6 +70,11 @@ public class PrintWriter extends Writer * on this stream. */ private boolean error; + + /** + * Indicates whether or not the stream has been closed. + */ + private boolean closed; /** * This is the underlying <code>Writer</code> we are sending output @@ -138,32 +143,66 @@ public class PrintWriter extends Writer this.autoflush = autoflush; } - /** @since 1.5 */ - public PrintWriter(String path) - throws FileNotFoundException + /** + * This initializes a new PrintWriter object to write to the specified + * file. It creates a FileOutputStream object and wraps it in an + * OutputStreamWriter using the default encoding. + * @param file name of the file to write to + * @throws FileNotFoundException if the file cannot be written or created + * + * @since 1.5 + */ + public PrintWriter(String file) throws FileNotFoundException { - this(new OutputStreamWriter(new FileOutputStream(path))); + this(new FileOutputStream(file)); } - /** @since 1.5 */ - public PrintWriter(String path, String encoding) + /** + * This initializes a new PrintWriter object to write to the specified + * file. It creates a FileOutputStream object and wraps it in an + * OutputStreamWriter using the specified encoding. + * @param file name of the file to write to + * @param enc the encoding to use + * @throws FileNotFoundException if the file cannot be written or created + * @throws UnsupportedEncodingException if the encoding is not supported + * + * @since 1.5 + */ + public PrintWriter(String file, String enc) throws FileNotFoundException, UnsupportedEncodingException { - this(new OutputStreamWriter(new FileOutputStream(path), encoding)); + this(new OutputStreamWriter(new FileOutputStream(file), enc)); } - /** @since 1.5 */ - public PrintWriter(File path) - throws FileNotFoundException + /** + * This initializes a new PrintWriter object to write to the specified + * file. It creates a FileOutputStream object and wraps it in an + * OutputStreamWriter using the default encoding. + * @param file the file to write to + * @throws FileNotFoundException if the file cannot be written or created + * + * @since 1.5 + */ + public PrintWriter(File file) throws FileNotFoundException { - this(new OutputStreamWriter(new FileOutputStream(path))); + this(new FileOutputStream(file)); } - /** @since 1.5 */ - public PrintWriter(File path, String encoding) + /** + * This initializes a new PrintWriter object to write to the specified + * file. It creates a FileOutputStream object and wraps it in an + * OutputStreamWriter using the specified encoding. + * @param file the file to write to + * @param enc the encoding to use + * @throws FileNotFoundException if the file cannot be written or created + * @throws UnsupportedEncodingException if the encoding is not supported + * + * @since 1.5 + */ + public PrintWriter(File file, String enc) throws FileNotFoundException, UnsupportedEncodingException { - this(new OutputStreamWriter(new FileOutputStream(path), encoding)); + this(new OutputStreamWriter(new FileOutputStream(file), enc)); } /** @@ -186,7 +225,8 @@ public class PrintWriter extends Writer */ public boolean checkError() { - flush(); + if (! closed) + flush(); return error; } @@ -213,7 +253,8 @@ public class PrintWriter extends Writer { try { - out.close(); + out.close(); + closed = true; } catch (IOException ex) { diff --git a/java/io/PushbackInputStream.java b/java/io/PushbackInputStream.java index 71cf24427..ff202c72d 100644 --- a/java/io/PushbackInputStream.java +++ b/java/io/PushbackInputStream.java @@ -116,7 +116,14 @@ public class PushbackInputStream extends FilterInputStream */ public int available() throws IOException { - return (buf.length - pos) + super.available(); + try + { + return (buf.length - pos) + super.available(); + } + catch (NullPointerException npe) + { + throw new IOException ("Stream closed"); + } } /** diff --git a/java/lang/Boolean.java b/java/lang/Boolean.java index df9fcfe6e..0af8a9c6e 100644 --- a/java/lang/Boolean.java +++ b/java/lang/Boolean.java @@ -223,24 +223,24 @@ public final class Boolean implements Serializable, Comparable<Boolean> } /** - * If the String argument is "true", ignoring case, return true. - * Otherwise, return false. - * - * @param b String to parse + * This implements the comparison contract specified by Comparable. + * @see Comparable * @since 1.5 */ - public static boolean parseBoolean(String b) + public int compareTo(Boolean other) { - return "true".equalsIgnoreCase(b) ? true : false; + return value == other.value ? 0 : (value ? 1 : -1); } /** - * This implements the comparison contract specified by Comparable. - * @see Comparable + * If the String argument is "true", ignoring case, return true. + * Otherwise, return false. + * + * @param b String to parse * @since 1.5 */ - public int compareTo(Boolean other) + public static boolean parseBoolean(String b) { - return value == other.value ? 0 : (value ? 1 : -1); + return "true".equalsIgnoreCase(b) ? true : false; } } diff --git a/java/lang/Character.java b/java/lang/Character.java index 146d7f2ef..e33c15585 100644 --- a/java/lang/Character.java +++ b/java/lang/Character.java @@ -1688,6 +1688,7 @@ public final class Character implements Serializable, Comparable<Character> /** * The minimum Unicode 4.0 code point. This value is <code>0</code>. + * @since 1.5 */ public static final int MIN_CODE_POINT = 0; @@ -1695,6 +1696,7 @@ public final class Character implements Serializable, Comparable<Character> * The maximum Unicode 4.0 code point, which is greater than the range * of the char data type. * This value is <code>0x10FFFF</code>. + * @since 1.5 */ public static final int MAX_CODE_POINT = 0x10FFFF; @@ -1702,6 +1704,7 @@ public final class Character implements Serializable, Comparable<Character> * The minimum Unicode high surrogate code unit, or * <emph>leading-surrogate</emph>, in the UTF-16 character encoding. * This value is <code>'\uD800'</code>. + * @since 1.5 */ public static final char MIN_HIGH_SURROGATE = '\uD800'; @@ -1709,6 +1712,7 @@ public final class Character implements Serializable, Comparable<Character> * The maximum Unicode high surrogate code unit, or * <emph>leading-surrogate</emph>, in the UTF-16 character encoding. * This value is <code>'\uDBFF'</code>. + * @since 1.5 */ public static final char MAX_HIGH_SURROGATE = '\uDBFF'; @@ -1716,6 +1720,7 @@ public final class Character implements Serializable, Comparable<Character> * The minimum Unicode low surrogate code unit, or * <emph>trailing-surrogate</emph>, in the UTF-16 character encoding. * This value is <code>'\uDC00'</code>. + * @since 1.5 */ public static final char MIN_LOW_SURROGATE = '\uDC00'; @@ -1723,20 +1728,23 @@ public final class Character implements Serializable, Comparable<Character> * The maximum Unicode low surrogate code unit, or * <emph>trailing-surrogate</emph>, in the UTF-16 character encoding. * This value is <code>'\uDFFF'</code>. + * @since 1.5 */ public static final char MAX_LOW_SURROGATE = '\uDFFF'; /** * The minimum Unicode surrogate code unit in the UTF-16 character encoding. * This value is <code>'\uD800'</code>. + * @since 1.5 */ - public static final char MIN_SURROGATE = '\uD800'; + public static final char MIN_SURROGATE = MIN_HIGH_SURROGATE; /** * The maximum Unicode surrogate code unit in the UTF-16 character encoding. * This value is <code>'\uDFFF'</code>. + * @since 1.5 */ - public static final char MAX_SURROGATE = '\uDFFF'; + public static final char MAX_SURROGATE = MAX_LOW_SURROGATE; /** * The lowest possible supplementary Unicode code point (the first code @@ -2972,6 +2980,7 @@ public final class Character implements Serializable, Comparable<Character> * * @param val the value to wrap * @return the <code>Character</code> + * @since 1.5 */ public static Character valueOf(char val) { @@ -3107,4 +3116,210 @@ public final class Character implements Serializable, Comparable<Character> { return codePoint >= MIN_CODE_POINT && codePoint <= MAX_CODE_POINT; } + + /** + * Return true if the given character is a high surrogate. + * @param ch the character + * @return true if the character is a high surrogate character + * + * @since 1.5 + */ + public static boolean isHighSurrogate(char ch) + { + return ch >= MIN_HIGH_SURROGATE && ch <= MAX_HIGH_SURROGATE; + } + + /** + * Return true if the given character is a low surrogate. + * @param ch the character + * @return true if the character is a low surrogate character + * + * @since 1.5 + */ + public static boolean isLowSurrogate(char ch) + { + return ch >= MIN_LOW_SURROGATE && ch <= MAX_LOW_SURROGATE; + } + + /** + * Return true if the given characters compose a surrogate pair. + * This is true if the first character is a high surrogate and the + * second character is a low surrogate. + * @param ch1 the first character + * @param ch2 the first character + * @return true if the characters compose a surrogate pair + * + * @since 1.5 + */ + public static boolean isSurrogatePair(char ch1, char ch2) + { + return isHighSurrogate(ch1) && isLowSurrogate(ch2); + } + + /** + * Given a valid surrogate pair, this returns the corresponding + * code point. + * @param high the high character of the pair + * @param low the low character of the pair + * @return the corresponding code point + * + * @since 1.5 + */ + public static int toCodePoint(char high, char low) + { + return ((high - MIN_HIGH_SURROGATE) << 10) + (low - MIN_LOW_SURROGATE); + } + + /** + * Get the code point at the specified index in the CharSequence. + * This is like CharSequence#charAt(int), but if the character is + * the start of a surrogate pair, and there is a following + * character, and this character completes the pair, then the + * corresponding supplementary code point is returned. Otherwise, + * the character at the index is returned. + * + * @param sequence the CharSequence + * @param index the index of the codepoint to get, starting at 0 + * @return the codepoint at the specified index + * @throws IndexOutOfBoundsException if index is negative or >= length() + * @since 1.5 + */ + public static int codePointAt(CharSequence sequence, int index) + { + int len = sequence.length(); + if (index < 0 || index >= len) + throw new IndexOutOfBoundsException(); + char high = sequence.charAt(index); + if (! isHighSurrogate(high) || ++index >= len) + return high; + char low = sequence.charAt(index); + if (! isLowSurrogate(low)) + return high; + return toCodePoint(high, low); + } + + /** + * Get the code point at the specified index in the CharSequence. + * If the character is the start of a surrogate pair, and there is a + * following character, and this character completes the pair, then + * the corresponding supplementary code point is returned. + * Otherwise, the character at the index is returned. + * + * @param chars the character array in which to look + * @param index the index of the codepoint to get, starting at 0 + * @return the codepoint at the specified index + * @throws IndexOutOfBoundsException if index is negative or >= length() + * @since 1.5 + */ + public static int codePointAt(char[] chars, int index) + { + return codePointAt(chars, index, chars.length); + } + + /** + * Get the code point at the specified index in the CharSequence. + * If the character is the start of a surrogate pair, and there is a + * following character within the specified range, and this + * character completes the pair, then the corresponding + * supplementary code point is returned. Otherwise, the character + * at the index is returned. + * + * @param chars the character array in which to look + * @param index the index of the codepoint to get, starting at 0 + * @param limit the limit past which characters should not be examined + * @return the codepoint at the specified index + * @throws IndexOutOfBoundsException if index is negative or >= + * limit, or if limit is negative or >= the length of the array + * @since 1.5 + */ + public static int codePointAt(char[] chars, int index, int limit) + { + if (index < 0 || index >= limit || limit < 0 || limit >= chars.length) + throw new IndexOutOfBoundsException(); + char high = chars[index]; + if (! isHighSurrogate(high) || ++index >= limit) + return high; + char low = chars[index]; + if (! isLowSurrogate(low)) + return high; + return toCodePoint(high, low); + } + + /** + * Get the code point before the specified index. This is like + * #codePointAt(char[], int), but checks the characters at + * <code>index-1</code> and <code>index-2</code> to see if they form + * a supplementary code point. If they do not, the character at + * <code>index-1</code> is returned. + * + * @param chars the character array + * @param index the index just past the codepoint to get, starting at 0 + * @return the codepoint at the specified index + * @throws IndexOutOfBoundsException if index is negative or >= length() + * @since 1.5 + */ + public static int codePointBefore(char[] chars, int index) + { + return codePointBefore(chars, index, 1); + } + + /** + * Get the code point before the specified index. This is like + * #codePointAt(char[], int), but checks the characters at + * <code>index-1</code> and <code>index-2</code> to see if they form + * a supplementary code point. If they do not, the character at + * <code>index-1</code> is returned. The start parameter is used to + * limit the range of the array which may be examined. + * + * @param chars the character array + * @param index the index just past the codepoint to get, starting at 0 + * @param start the index before which characters should not be examined + * @return the codepoint at the specified index + * @throws IndexOutOfBoundsException if index is > start or > + * the length of the array, or if limit is negative or >= the + * length of the array + * @since 1.5 + */ + public static int codePointBefore(char[] chars, int index, int start) + { + if (index < start || index > chars.length + || start < 0 || start >= chars.length) + throw new IndexOutOfBoundsException(); + --index; + char low = chars[index]; + if (! isLowSurrogate(low) || --index < start) + return low; + char high = chars[index]; + if (! isHighSurrogate(high)) + return low; + return toCodePoint(high, low); + } + + /** + * Get the code point before the specified index. This is like + * #codePointAt(CharSequence, int), but checks the characters at + * <code>index-1</code> and <code>index-2</code> to see if they form + * a supplementary code point. If they do not, the character at + * <code>index-1</code> is returned. + * + * @param sequence the CharSequence + * @param index the index just past the codepoint to get, starting at 0 + * @return the codepoint at the specified index + * @throws IndexOutOfBoundsException if index is negative or >= length() + * @since 1.5 + */ + public static int codePointBefore(CharSequence sequence, int index) + { + int len = sequence.length(); + if (index < 1 || index > len) + throw new IndexOutOfBoundsException(); + --index; + char low = sequence.charAt(index); + if (! isLowSurrogate(low) || --index < 0) + return low; + char high = sequence.charAt(index); + if (! isHighSurrogate(high)) + return low; + return toCodePoint(high, low); + } } // class Character diff --git a/java/lang/Class.java b/java/lang/Class.java index f7e768443..adb673851 100644 --- a/java/lang/Class.java +++ b/java/lang/Class.java @@ -106,7 +106,7 @@ public final class Class<T> /** The class signers. */ private Object[] signers = null; /** The class protection domain. */ - private final ProtectionDomain pd; + private final transient ProtectionDomain pd; /* We use an inner class, so that Class doesn't have a static initializer */ private static final class StaticData @@ -728,7 +728,7 @@ public final class Class<T> * @param list List of methods to search * @param name Name of method * @param args Method parameter types - * @see #getMethod() + * @see #getMethod(String, Class[]) */ private static Method matchMethod(Method[] list, String name, Class[] args) { @@ -836,7 +836,7 @@ public final class Class<T> * public and final, but not an interface. * * @return the modifiers of this class - * @see Modifer + * @see Modifier * @since 1.1 */ public int getModifiers() diff --git a/java/lang/ClassLoader.java b/java/lang/ClassLoader.java index 3dc12677b..ffba56b9a 100644 --- a/java/lang/ClassLoader.java +++ b/java/lang/ClassLoader.java @@ -893,7 +893,7 @@ public abstract class ClassLoader * * @param name the (system specific) name of the requested library * @return the full pathname to the requested library, or null - * @see Runtime#loadLibrary() + * @see Runtime#loadLibrary(String) * @since 1.2 */ protected String findLibrary(String name) @@ -923,7 +923,7 @@ public abstract class ClassLoader * * @param name the package (and subpackages) to affect * @param enabled true to set the default to enabled - * @see #setDefaultAssertionStatus(String, boolean) + * @see #setDefaultAssertionStatus(boolean) * @see #setClassAssertionStatus(String, boolean) * @see #clearAssertionStatus() * @since 1.4 @@ -944,7 +944,7 @@ public abstract class ClassLoader * @param name the class to affect * @param enabled true to set the default to enabled * @throws NullPointerException if name is null - * @see #setDefaultAssertionStatus(String, boolean) + * @see #setDefaultAssertionStatus(boolean) * @see #setPackageAssertionStatus(String, boolean) * @see #clearAssertionStatus() * @since 1.4 diff --git a/java/lang/Double.java b/java/lang/Double.java index 504b719fc..f79432a99 100644 --- a/java/lang/Double.java +++ b/java/lang/Double.java @@ -38,7 +38,6 @@ exception statement from your version. */ package java.lang; -import gnu.classpath.Configuration; /** * Instances of class <code>Double</code> represent primitive @@ -91,6 +90,12 @@ public final class Double extends Number implements Comparable<Double> public static final double NaN = 0.0 / 0.0; /** + * The number of bits needed to represent a <code>double</code>. + * @since 1.5 + */ + public static final int SIZE = 64; + + /** * The primitive type <code>double</code> is represented by this * <code>Class</code> object. * @since 1.1 @@ -98,12 +103,6 @@ public final class Double extends Number implements Comparable<Double> public static final Class<Double> TYPE = (Class<Double>) VMClassLoader.getPrimitiveClass('D'); /** - * The number of bits needed to represent a <code>double</code>. - * @since 1.5 - */ - public static final int SIZE = 64; - - /** * The immutable value of this Double. * * @serial the wrapped double @@ -176,6 +175,21 @@ public final class Double extends Number implements Comparable<Double> } /** + * Returns a <code>Double</code> object wrapping the value. + * In contrast to the <code>Double</code> constructor, this method + * may cache some values. It is used by boxing conversion. + * + * @param val the value to wrap + * @return the <code>Double</code> + * @since 1.5 + */ + public static Double valueOf(double val) + { + // We don't actually cache, but we could. + return new Double(val); + } + + /** * Create a new <code>Double</code> object using the <code>String</code>. * * @param s the <code>String</code> to convert @@ -191,20 +205,6 @@ public final class Double extends Number implements Comparable<Double> } /** - * Returns a <code>Double</code> object wrapping the value. - * In contrast to the <code>Double</code> constructor, this method - * may cache some values. It is used by boxing conversion. - * - * @param val the value to wrap - * @return the <code>Double</code> - */ - public static Double valueOf(double val) - { - // We don't actually cache, but we could. - return new Double(val); - } - - /** * Parse the specified <code>String</code> as a <code>double</code>. The * extended BNF grammar is as follows:<br> * <pre> diff --git a/java/lang/Float.java b/java/lang/Float.java index ff7440765..56cc8e136 100644 --- a/java/lang/Float.java +++ b/java/lang/Float.java @@ -206,6 +206,7 @@ public final class Float extends Number implements Comparable<Float> * * @param val the value to wrap * @return the <code>Float</code> + * @since 1.5 */ public static Float valueOf(float val) { diff --git a/java/lang/Integer.java b/java/lang/Integer.java index 71d62601e..e38eb53ed 100644 --- a/java/lang/Integer.java +++ b/java/lang/Integer.java @@ -692,8 +692,8 @@ public final class Integer extends Number implements Comparable<Integer> * @throws NullPointerException if decode is true and str if null * @see #parseInt(String, int) * @see #decode(String) - * @see Byte#parseInt(String, int) - * @see Short#parseInt(String, int) + * @see Byte#parseByte(String, int) + * @see Short#parseShort(String, int) */ static int parseInt(String str, int radix, boolean decode) { diff --git a/java/lang/Long.java b/java/lang/Long.java index ce88a5b1c..f0fbc904c 100644 --- a/java/lang/Long.java +++ b/java/lang/Long.java @@ -294,6 +294,7 @@ public final class Long extends Number implements Comparable<Long> * * @param val the value to wrap * @return the <code>Long</code> + * @since 1.5 */ public static synchronized Long valueOf(long val) { @@ -641,9 +642,9 @@ public final class Long extends Number implements Comparable<Long> */ public static long reverse(long val) { - int hi = Integer.reverse((int) val); - int lo = Integer.reverse((int) (val >>> 32)); - return (((long) hi) << 32) | lo; + long hi = Integer.reverse((int) val) & 0xffffffffL; + long lo = Integer.reverse((int) (val >>> 32)) & 0xffffffffL; + return (hi << 32) | lo; } /** diff --git a/java/lang/Object.java b/java/lang/Object.java index a94f4c636..fbd1dc77d 100644 --- a/java/lang/Object.java +++ b/java/lang/Object.java @@ -343,7 +343,7 @@ public class Object * * <p>This thread still holds a lock on the object, so it is * typical to release the lock by exiting the synchronized - * code, calling wait(), or calling {@link Thread#sleep()}, so + * code, calling wait(), or calling {@link Thread#sleep(long)}, so * that the newly awakened thread can actually resume. The * awakened thread will most likely be awakened with an * {@link InterruptedException}, but that is not guaranteed. @@ -372,7 +372,7 @@ public class Object * * <p>This thread still holds a lock on the object, so it is * typical to release the lock by exiting the synchronized - * code, calling wait(), or calling {@link Thread#sleep()}, so + * code, calling wait(), or calling {@link Thread#sleep(long)}, so * that one of the newly awakened threads can actually resume. * The resuming thread will most likely be awakened with an * {@link InterruptedException}, but that is not guaranteed. diff --git a/java/lang/Process.java b/java/lang/Process.java index b6e18ca4d..ccaa3f153 100644 --- a/java/lang/Process.java +++ b/java/lang/Process.java @@ -39,6 +39,7 @@ exception statement from your version. */ package java.lang; +import java.io.File; import java.io.InputStream; import java.io.OutputStream; diff --git a/java/lang/Readable.java b/java/lang/Readable.java index efc1985d6..d8967652b 100644 --- a/java/lang/Readable.java +++ b/java/lang/Readable.java @@ -39,6 +39,7 @@ package java.lang; import java.io.IOException; import java.nio.CharBuffer; +import java.nio.ReadOnlyBufferException; /** * A <code>Readable</code> object is simply a source for Unicode character diff --git a/java/lang/RuntimePermission.java b/java/lang/RuntimePermission.java index ca33307d1..2f80b9107 100644 --- a/java/lang/RuntimePermission.java +++ b/java/lang/RuntimePermission.java @@ -39,6 +39,7 @@ exception statement from your version. */ package java.lang; import java.security.BasicPermission; +import java.security.Permission; /** * A <code>RuntimePermission</code> contains a permission name, but no diff --git a/java/lang/SecurityManager.java b/java/lang/SecurityManager.java index 8a890798a..0e1ea64a0 100644 --- a/java/lang/SecurityManager.java +++ b/java/lang/SecurityManager.java @@ -41,19 +41,35 @@ package java.lang; import gnu.classpath.VMStackWalker; import java.awt.AWTPermission; +import java.awt.Frame; +import java.awt.Toolkit; +import java.awt.Window; import java.io.File; import java.io.FileDescriptor; +import java.io.FileInputStream; +import java.io.FileOutputStream; import java.io.FilePermission; +import java.io.RandomAccessFile; import java.lang.reflect.Member; import java.net.InetAddress; +import java.net.ServerSocket; +import java.net.Socket; +import java.net.SocketImplFactory; import java.net.SocketPermission; +import java.net.URL; +import java.net.URLStreamHandlerFactory; import java.security.AccessControlContext; +import java.security.AccessControlException; import java.security.AccessController; import java.security.AllPermission; +import java.security.BasicPermission; import java.security.Permission; +import java.security.Policy; import java.security.PrivilegedAction; +import java.security.ProtectionDomain; import java.security.Security; import java.security.SecurityPermission; +import java.util.Properties; import java.util.PropertyPermission; import java.util.StringTokenizer; @@ -196,7 +212,7 @@ public class SecurityManager * <ul> * <li>All methods on the stack are from system classes</li> * <li>All methods on the stack up to the first "privileged" caller, as - * created by {@link AccessController.doPrivileged(PrivilegedAction)}, + * created by {@link AccessController#doPrivileged(PrivilegedAction)}, * are from system classes</li> * <li>A check of <code>java.security.AllPermission</code> succeeds.</li> * </ul> @@ -219,7 +235,7 @@ public class SecurityManager * <ul> * <li>All methods on the stack are from system classes</li> * <li>All methods on the stack up to the first "privileged" caller, as - * created by {@link AccessController.doPrivileged(PrivilegedAction)}, + * created by {@link AccessController#doPrivileged(PrivilegedAction)}, * are from system classes</li> * <li>A check of <code>java.security.AllPermission</code> succeeds.</li> * </ul> @@ -258,7 +274,7 @@ public class SecurityManager * <ul> * <li>All methods on the stack are from system classes</li> * <li>All methods on the stack up to the first "privileged" caller, as - * created by {@link AccessController.doPrivileged(PrivilegedAction)}, + * created by {@link AccessController#doPrivileged(PrivilegedAction)}, * are from system classes</li> * <li>A check of <code>java.security.AllPermission</code> succeeds.</li> * </ul> @@ -431,7 +447,7 @@ public class SecurityManager * @throws SecurityException if permission is denied * @throws NullPointerException if g is null * @see Thread#Thread() - * @see ThreadGroup#ThreadGroup() + * @see ThreadGroup#ThreadGroup(String) * @see ThreadGroup#stop() * @see ThreadGroup#suspend() * @see ThreadGroup#resume() @@ -537,7 +553,7 @@ public class SecurityManager * @throws NullPointerException if filename is null * @see File * @see FileInputStream#FileInputStream(String) - * @see RandomAccessFile#RandomAccessFile(String) + * @see RandomAccessFile#RandomAccessFile(String, String) */ public void checkRead(String filename) { @@ -602,9 +618,9 @@ public class SecurityManager * @see File * @see File#canWrite() * @see File#mkdir() - * @see File#renameTo() + * @see File#renameTo(File) * @see FileOutputStream#FileOutputStream(String) - * @see RandomAccessFile#RandomAccessFile(String) + * @see RandomAccessFile#RandomAccessFile(String, String) */ public void checkWrite(String filename) { diff --git a/java/lang/Short.java b/java/lang/Short.java index 7e1553d9e..41a31e260 100644 --- a/java/lang/Short.java +++ b/java/lang/Short.java @@ -210,6 +210,7 @@ public final class Short extends Number implements Comparable<Short> * * @param val the value to wrap * @return the <code>Short</code> + * @since 1.5 */ public static Short valueOf(short val) { diff --git a/java/lang/StrictMath.java b/java/lang/StrictMath.java index 32bd3540d..2079cc11e 100644 --- a/java/lang/StrictMath.java +++ b/java/lang/StrictMath.java @@ -1254,7 +1254,7 @@ public final strictfp class StrictMath /** * Super precision for 2/pi in 24-bit chunks, for use in - * {@link #remPiOver2()}. + * {@link #remPiOver2(double, double[])}. */ private static final int TWO_OVER_PI[] = { 0xa2f983, 0x6e4e44, 0x1529fc, 0x2757d1, 0xf534dd, 0xc0db62, @@ -1272,7 +1272,7 @@ public final strictfp class StrictMath /** * Super precision for pi/2 in 24-bit chunks, for use in - * {@link #remPiOver2()}. + * {@link #remPiOver2(double, double[])}. */ private static final double PI_OVER_TWO[] = { 1.570796251296997, // Long bits 0x3ff921fb40000000L. @@ -1286,8 +1286,8 @@ public final strictfp class StrictMath }; /** - * More constants related to pi, used in {@link #remPiOver2()} and - * elsewhere. + * More constants related to pi, used in + * {@link #remPiOver2(double, double[])} and elsewhere. */ private static final double PI_L = 1.2246467991473532e-16, // Long bits 0x3ca1a62633145c07L. @@ -1301,7 +1301,7 @@ public final strictfp class StrictMath /** * Natural log and square root constants, for calculation of * {@link #exp(double)}, {@link #log(double)} and - * {@link #power(double, double)}. CP is 2/(3*ln(2)). + * {@link #pow(double, double)}. CP is 2/(3*ln(2)). */ private static final double SQRT_1_5 = 1.224744871391589, // Long bits 0x3ff3988e1409212eL. diff --git a/java/lang/String.java b/java/lang/String.java index b8a3a6627..74a9a61cb 100644 --- a/java/lang/String.java +++ b/java/lang/String.java @@ -101,7 +101,7 @@ public final class String /** * Stores unicode multi-character uppercase expansion table. - * @see #toUpperCase(char) + * @see #toUpperCase(Locale) * @see CharData#UPPER_EXPAND */ private static final char[] upperExpand @@ -142,7 +142,7 @@ public final class String final int offset; /** - * An implementation for {@link CASE_INSENSITIVE_ORDER}. + * An implementation for {@link #CASE_INSENSITIVE_ORDER}. * This must be {@link Serializable}. The class name is dictated by * compatibility with Sun's JDK. */ @@ -557,6 +557,40 @@ public final class String } /** + * Get the code point at the specified index. This is like #charAt(int), + * but if the character is the start of a surrogate pair, and the + * following character completes the pair, then the corresponding + * supplementary code point is returned. + * @param index the index of the codepoint to get, starting at 0 + * @return the codepoint at the specified index + * @throws IndexOutOfBoundsException if index is negative or >= length() + * @since 1.5 + */ + public synchronized int codePointAt(int index) + { + // Use the CharSequence overload as we get better range checking + // this way. + return Character.codePointAt(this, index); + } + + /** + * Get the code point before the specified index. This is like + * #codePointAt(int), but checks the characters at <code>index-1</code> and + * <code>index-2</code> to see if they form a supplementary code point. + * @param index the index just past the codepoint to get, starting at 0 + * @return the codepoint at the specified index + * @throws IndexOutOfBoundsException if index is negative or >= length() + * (while unspecified, this is a StringIndexOutOfBoundsException) + * @since 1.5 + */ + public synchronized int codePointBefore(int index) + { + // Use the CharSequence overload as we get better range checking + // this way. + return Character.codePointBefore(this, index); + } + + /** * Copies characters from this String starting at a specified start index, * ending at a specified stop index, to a character array starting at * a specified destination begin index. @@ -631,21 +665,26 @@ public final class String ByteBuffer bbuf = cse.encode(CharBuffer.wrap(value, offset, count)); if(bbuf.hasArray()) return bbuf.array(); - + // Doubt this will happen. But just in case. byte[] bytes = new byte[bbuf.remaining()]; bbuf.get(bytes); return bytes; - - } catch(IllegalCharsetNameException e){ - throw new UnsupportedEncodingException("Encoding: "+enc+ - " not found."); - } catch(UnsupportedCharsetException e){ - throw new UnsupportedEncodingException("Encoding: "+enc+ - " not found."); - } catch(CharacterCodingException e){ - // XXX - Ignore coding exceptions? They shouldn't really happen. - return null; + } + catch(IllegalCharsetNameException e) + { + throw new UnsupportedEncodingException("Encoding: " + enc + + " not found."); + } + catch(UnsupportedCharsetException e) + { + throw new UnsupportedEncodingException("Encoding: " + enc + + " not found."); + } + catch(CharacterCodingException e) + { + // This shouldn't ever happen. + throw (InternalError) new InternalError().initCause(e); } } @@ -729,6 +768,26 @@ public final class String } /** + * Compares the given CharSequence to this String. This is true if + * the CharSequence has the same content as this String at this + * moment. + * + * @param seq the CharSequence to compare to + * @return true if CharSequence has the same character sequence + * @throws NullPointerException if the given CharSequence is null + * @since 1.5 + */ + public boolean contentEquals(CharSequence seq) + { + if (seq.length() != count) + return false; + for (int i = 0; i < count; ++i) + if (value[offset + i] != seq.charAt(i)) + return false; + return true; + } + + /** * Compares a String to this String, ignoring case. This does not handle * multi-character capitalization exceptions; instead the comparison is * made on a character-by-character basis, and is true if:<br><ul> @@ -1664,6 +1723,49 @@ public final class String } /** + * Return the number of code points between two indices in the + * <code>StringBuffer</code>. An unpaired surrogate counts as a + * code point for this purpose. Characters outside the indicated + * range are not examined, even if the range ends in the middle of a + * surrogate pair. + * + * @param start the starting index + * @param end one past the ending index + * @return the number of code points + * @since 1.5 + */ + public synchronized int codePointCount(int start, int end) + { + if (start < 0 || end >= count || start > end) + throw new StringIndexOutOfBoundsException(); + + start += offset; + end += offset; + int count = 0; + while (start < end) + { + char base = value[start]; + if (base < Character.MIN_HIGH_SURROGATE + || base > Character.MAX_HIGH_SURROGATE + || start == end + || start == count + || value[start + 1] < Character.MIN_LOW_SURROGATE + || value[start + 1] > Character.MAX_LOW_SURROGATE) + { + // Nothing. + } + else + { + // Surrogate pair. + ++start; + } + ++start; + ++count; + } + return count; + } + + /** * Helper function used to detect which characters have a multi-character * uppercase expansion. Note that this is only used in locations which * track one-to-many capitalization (java.lang.Character does not do this). diff --git a/java/lang/StringBuffer.java b/java/lang/StringBuffer.java index 1fabd6541..6fef4f7a2 100644 --- a/java/lang/StringBuffer.java +++ b/java/lang/StringBuffer.java @@ -257,7 +257,6 @@ public final class StringBuffer * @param index the index of the character to get, starting at 0 * @return the character at the specified index * @throws IndexOutOfBoundsException if index is negative or >= length() - * (while unspecified, this is a StringIndexOutOfBoundsException) */ public synchronized char charAt(int index) { @@ -267,6 +266,39 @@ public final class StringBuffer } /** + * Get the code point at the specified index. This is like #charAt(int), + * but if the character is the start of a surrogate pair, and the + * following character completes the pair, then the corresponding + * supplementary code point is returned. + * @param index the index of the codepoint to get, starting at 0 + * @return the codepoint at the specified index + * @throws IndexOutOfBoundsException if index is negative or >= length() + * @since 1.5 + */ + public synchronized int codePointAt(int index) + { + return Character.codePointAt(value, index, count); + } + + /** + * Get the code point before the specified index. This is like + * #codePointAt(int), but checks the characters at <code>index-1</code> and + * <code>index-2</code> to see if they form a supplementary code point. + * @param index the index just past the codepoint to get, starting at 0 + * @return the codepoint at the specified index + * @throws IndexOutOfBoundsException if index is negative or >= length() + * @since 1.5 + */ + public synchronized int codePointBefore(int index) + { + // Character.codePointBefore() doesn't perform this check. We + // could use the CharSequence overload, but this is just as easy. + if (index >= count) + throw new IndexOutOfBoundsException(); + return Character.codePointBefore(value, index, 1); + } + + /** * Get the specified array of characters. <code>srcOffset - srcEnd</code> * characters will be copied into the array you pass in. * @@ -403,6 +435,24 @@ public final class StringBuffer } /** + * Append the code point to this <code>StringBuffer</code>. + * This is like #append(char), but will append two characters + * if a supplementary code point is given. + * + * @param code the code point to append + * @return this <code>StringBuffer</code> + * @see Character#toChars(int, char[], int) + */ + public synchronized StringBuffer appendCodePoint(int code) + { + int len = Character.charCount(code); + ensureCapacity_unsynchronized(count + len); + Character.toChars(code, value, count); + count += len; + return this; + } + + /** * Append the <code>String</code> value of the argument to this * <code>StringBuffer</code>. Uses <code>String.valueOf()</code> to convert * to <code>String</code>. @@ -720,6 +770,54 @@ public final class StringBuffer } /** + * Insert the <code>CharSequence</code> argument into this + * <code>StringBuffer</code>. If the sequence is null, the String + * "null" is used instead. + * + * @param offset the place to insert in this buffer + * @param sequence the <code>CharSequence</code> to insert + * @return this <code>StringBuffer</code> + * @throws IndexOutOfBoundsException if offset is out of bounds + * @since 1.5 + */ + public synchronized StringBuffer insert(int offset, CharSequence sequence) + { + if (sequence == null) + sequence = "null"; + return insert(offset, sequence, 0, sequence.length()); + } + + /** + * Insert a subsequence of the <code>CharSequence</code> argument into this + * <code>StringBuffer</code>. If the sequence is null, the String + * "null" is used instead. + * + * @param offset the place to insert in this buffer + * @param sequence the <code>CharSequence</code> to insert + * @param start the starting index of the subsequence + * @param end one past the ending index of the subsequence + * @return this <code>StringBuffer</code> + * @throws IndexOutOfBoundsException if offset, start, + * or end are out of bounds + * @since 1.5 + */ + public synchronized StringBuffer insert(int offset, CharSequence sequence, + int start, int end) + { + if (sequence == null) + sequence = "null"; + if (start < 0 || end < 0 || start > end || end > sequence.length()) + throw new IndexOutOfBoundsException(); + int len = end - start; + ensureCapacity_unsynchronized(count + len); + VMSystem.arraycopy(value, offset, value, offset + len, count - offset); + for (int i = start; i < end; ++i) + value[offset++] = sequence.charAt(i); + count += len; + return this; + } + + /** * Insert the <code>char[]</code> argument into this * <code>StringBuffer</code>. * @@ -940,6 +1038,106 @@ public final class StringBuffer } /** + * This may reduce the amount of memory used by the StringBuffer, + * by resizing the internal array to remove unused space. However, + * this method is not required to resize, so this behavior cannot + * be relied upon. + * @since 1.5 + */ + public synchronized void trimToSize() + { + int wouldSave = value.length - count; + // Some random heuristics: if we save less than 20 characters, who + // cares. + if (wouldSave < 20) + return; + // If we save more than 200 characters, shrink. + // If we save more than 1/4 of the buffer, shrink. + if (wouldSave > 200 || wouldSave * 4 > value.length) + { + char[] newValue = new char[count]; + VMSystem.arraycopy(value, 0, newValue, 0, count); + value = newValue; + } + } + + /** + * Return the number of code points between two indices in the + * <code>StringBuffer</code>. An unpaired surrogate counts as a + * code point for this purpose. Characters outside the indicated + * range are not examined, even if the range ends in the middle of a + * surrogate pair. + * + * @param start the starting index + * @param end one past the ending index + * @return the number of code points + * @since 1.5 + */ + public synchronized int codePointCount(int start, int end) + { + if (start < 0 || end >= count || start > end) + throw new StringIndexOutOfBoundsException(); + + int count = 0; + while (start < end) + { + char base = value[start]; + if (base < Character.MIN_HIGH_SURROGATE + || base > Character.MAX_HIGH_SURROGATE + || start == end + || start == count + || value[start + 1] < Character.MIN_LOW_SURROGATE + || value[start + 1] > Character.MAX_LOW_SURROGATE) + { + // Nothing. + } + else + { + // Surrogate pair. + ++start; + } + ++start; + ++count; + } + return count; + } + + /** + * Starting at the given index, this counts forward by the indicated + * number of code points, and then returns the resulting index. An + * unpaired surrogate counts as a single code point for this + * purpose. + * + * @param start the starting index + * @param codePoints the number of code points + * @return the resulting index + * @since 1.5 + */ + public synchronized int offsetByCodePoints(int start, int codePoints) + { + while (codePoints > 0) + { + char base = value[start]; + if (base < Character.MIN_HIGH_SURROGATE + || base > Character.MAX_HIGH_SURROGATE + || start == count + || value[start + 1] < Character.MIN_LOW_SURROGATE + || value[start + 1] > Character.MAX_LOW_SURROGATE) + { + // Nothing. + } + else + { + // Surrogate pair. + ++start; + } + ++start; + --codePoints; + } + return start; + } + + /** * An unsynchronized version of ensureCapacity, used internally to avoid * the cost of a second lock on the same object. This also has the side * effect of duplicating the array, if it was shared (to form copy-on-write diff --git a/java/lang/System.java b/java/lang/System.java index 45ad0ef7e..07058d1bd 100644 --- a/java/lang/System.java +++ b/java/lang/System.java @@ -558,7 +558,7 @@ public final class System * * @param finalizeOnExit whether to run finalizers on exit * @throws SecurityException if permission is denied - * @see Runtime#runFinalizersOnExit() + * @see Runtime#runFinalizersOnExit(boolean) * @since 1.1 * @deprecated never rely on finalizers to do a clean, thread-safe, * mop-up from your code diff --git a/java/lang/Thread.java b/java/lang/Thread.java index dfaf1a4a0..e82f272d3 100644 --- a/java/lang/Thread.java +++ b/java/lang/Thread.java @@ -38,6 +38,7 @@ exception statement from your version. */ package java.lang; +import java.security.Permission; import java.util.Map; import java.util.WeakHashMap; @@ -724,7 +725,7 @@ public class Thread implements Runnable * * @return the context class loader * @throws SecurityException when permission is denied - * @see setContextClassLoader(ClassLoader) + * @see #setContextClassLoader(ClassLoader) * @since 1.2 */ public synchronized ClassLoader getContextClassLoader() @@ -746,7 +747,7 @@ public class Thread implements Runnable * * @param classloader the new context class loader * @throws SecurityException when permission is denied - * @see getContextClassLoader() + * @see #getContextClassLoader() * @since 1.2 */ public synchronized void setContextClassLoader(ClassLoader classloader) diff --git a/java/lang/ThreadLocal.java b/java/lang/ThreadLocal.java index 11d545d3f..670c13a03 100644 --- a/java/lang/ThreadLocal.java +++ b/java/lang/ThreadLocal.java @@ -38,7 +38,6 @@ exception statement from your version. */ package java.lang; import java.util.Map; -import java.util.WeakHashMap; /** diff --git a/java/lang/ref/Reference.java b/java/lang/ref/Reference.java index e7e316840..7c1fa2d3e 100644 --- a/java/lang/ref/Reference.java +++ b/java/lang/ref/Reference.java @@ -68,7 +68,7 @@ package java.lang.ref; * work. It is useful to keep track, when an object is finalized. * * @author Jochen Hoenicke - * @see java.util.WeakHashtable + * @see java.util.WeakHashMap */ public abstract class Reference<T> { @@ -104,7 +104,7 @@ public abstract class Reference<T> * Creates a new reference that is not registered to any queue. * Since it is package private, it is not possible to overload this * class in a different package. - * @param referent the object we refer to. + * @param ref the object we refer to. */ Reference(T ref) { @@ -115,7 +115,7 @@ public abstract class Reference<T> * Creates a reference that is registered to a queue. Since this is * package private, it is not possible to overload this class in a * different package. - * @param referent the object we refer to. + * @param ref the object we refer to. * @param q the reference queue to register on. * @exception NullPointerException if q is null. */ diff --git a/java/lang/ref/WeakReference.java b/java/lang/ref/WeakReference.java index 1de90fc2d..563563bf1 100644 --- a/java/lang/ref/WeakReference.java +++ b/java/lang/ref/WeakReference.java @@ -52,7 +52,7 @@ package java.lang.ref; * automatically cleared, and you may remove it from the set. <br> * * @author Jochen Hoenicke - * @see java.util.WeakHashtable + * @see java.util.WeakHashMap */ public class WeakReference<T> extends Reference<T> diff --git a/java/lang/reflect/Member.java b/java/lang/reflect/Member.java index 9983b275a..c39731f84 100644 --- a/java/lang/reflect/Member.java +++ b/java/lang/reflect/Member.java @@ -60,7 +60,7 @@ public interface Member * package-protected, but only which are declared in this class. * Used in SecurityManager.checkMemberAccess() to determine the * type of members to access. - * @see SecurityManager#checkMemberAccess() + * @see SecurityManager#checkMemberAccess(Class, int) */ int DECLARED = 1; @@ -68,7 +68,7 @@ public interface Member * Represents public members only, but includes all inherited members. * Used in SecurityManager.checkMemberAccess() to determine the type of * members to access. - * @see SecurityManager#checkMemberAccess() + * @see SecurityManager#checkMemberAccess(Class, int) */ int PUBLIC = 0; diff --git a/java/lang/reflect/Proxy.java b/java/lang/reflect/Proxy.java index 0cb914792..490730ffd 100644 --- a/java/lang/reflect/Proxy.java +++ b/java/lang/reflect/Proxy.java @@ -100,7 +100,7 @@ import java.util.Set; * belongs to the classloader you designated.</li> * <li>Reflection works as expected: {@link Class#getInterfaces()} and * {@link Class#getMethods()} work as they do on normal classes.</li> - * <li>The method {@link #isProxyClass()} will distinguish between + * <li>The method {@link #isProxyClass(Class)} will distinguish between * true proxy classes and user extensions of this class. It only * returns true for classes created by {@link #getProxyClass}.</li> * <li>The {@link ProtectionDomain} of a proxy class is the same as for @@ -126,7 +126,7 @@ import java.util.Set; * a {@link ClassCastException}.</li> * <li>Each proxy instance has an invocation handler, which can be * accessed by {@link #getInvocationHandler(Object)}. Any call - * to an interface method, including {@link Object#hashcode()}, + * to an interface method, including {@link Object#hashCode()}, * {@link Object#equals(Object)}, or {@link Object#toString()}, * but excluding the public final methods of Object, will be * encoded and passed to the {@link InvocationHandler#invoke} @@ -436,7 +436,7 @@ public class Proxy implements Serializable /** * Calculates equality. * - * @param the object to compare to + * @param other object to compare to * @return true if it is a ProxyType with same data */ public boolean equals(Object other) @@ -586,7 +586,7 @@ public class Proxy implements Serializable /** * Calculates equality. * - * @param the object to compare to + * @param other object to compare to * @return true if it is a ProxySignature with same data */ public boolean equals(Object other) @@ -617,7 +617,7 @@ public class Proxy implements Serializable * The package this class is in <b>including the trailing dot</b> * or an empty string for the unnamed (aka default) package. */ - String pack; + String pack = ""; /** * The interfaces this class implements. Non-null, but possibly empty. diff --git a/java/lang/reflect/UndeclaredThrowableException.java b/java/lang/reflect/UndeclaredThrowableException.java index 6d5a80084..ea574ad7c 100644 --- a/java/lang/reflect/UndeclaredThrowableException.java +++ b/java/lang/reflect/UndeclaredThrowableException.java @@ -65,7 +65,7 @@ public class UndeclaredThrowableException extends RuntimeException /** * The immutable exception that this wraps. This field is redundant - * with {@link Throwable#cause}, but is necessary for serial compatibility. + * with {@link Throwable#getCause()}, but is necessary for serial compatibility. * * @serial the chained exception */ diff --git a/java/net/InetSocketAddress.java b/java/net/InetSocketAddress.java index 30d34e7e8..edeaf2775 100644 --- a/java/net/InetSocketAddress.java +++ b/java/net/InetSocketAddress.java @@ -216,6 +216,6 @@ public class InetSocketAddress extends SocketAddress */ public String toString() { - return (addr == null ? hostname : addr.getHostName()) + ":" + port; + return (addr == null ? hostname : addr.toString()) + ":" + port; } } diff --git a/java/net/URLClassLoader.java b/java/net/URLClassLoader.java index 85b385781..0a8b1db5a 100644 --- a/java/net/URLClassLoader.java +++ b/java/net/URLClassLoader.java @@ -535,9 +535,16 @@ public class URLClassLoader extends SecureClassLoader /** get resource with the name "name" in the file url */ Resource getResource(String name) { - File file = new File(dir, name); - if (file.exists() && !file.isDirectory()) - return new FileResource(this, name, file); + try + { + File file = new File(dir, name).getCanonicalFile(); + if (file.exists() && !file.isDirectory()) + return new FileResource(this, file.getPath(), file); + } + catch (IOException e) + { + // Fall through... + } return null; } } @@ -701,7 +708,7 @@ public class URLClassLoader extends SecureClassLoader private void addURLImpl(URL newUrl) { - synchronized (urlloaders) + synchronized (this) { if (newUrl == null) return; // Silently ignore... @@ -758,30 +765,68 @@ public class URLClassLoader extends SecureClassLoader } /** + * Look in both Attributes for a given value. The first Attributes + * object, if not null, has precedence. + */ + private String getAttributeValue(Attributes.Name name, Attributes first, + Attributes second) + { + String result = null; + if (first != null) + result = first.getValue(name); + if (result == null) + result = second.getValue(name); + return result; + } + + /** * Defines a Package based on the given name and the supplied manifest - * information. The manifest indicates the tile, version and - * vendor information of the specification and implementation and wheter the + * information. The manifest indicates the title, version and + * vendor information of the specification and implementation and whether the * package is sealed. If the Manifest indicates that the package is sealed * then the Package will be sealed with respect to the supplied URL. * + * @exception IllegalArgumentException If this package name already exists + * in this class loader * @param name The name of the package * @param manifest The manifest describing the specification, * implementation and sealing details of the package * @param url the code source url to seal the package - * @exception IllegalArgumentException If this package name already exists - * in this class loader * @return the defined Package */ protected Package definePackage(String name, Manifest manifest, URL url) throws IllegalArgumentException { + // Compute the name of the package as it may appear in the + // Manifest. + StringBuffer xform = new StringBuffer(name); + for (int i = xform.length () - 1; i >= 0; --i) + if (xform.charAt(i) == '.') + xform.setCharAt(i, '/'); + xform.append('/'); + String xformName = xform.toString(); + + Attributes entryAttr = manifest.getAttributes(xformName); Attributes attr = manifest.getMainAttributes(); - String specTitle = attr.getValue(Attributes.Name.SPECIFICATION_TITLE); - String specVersion = attr.getValue(Attributes.Name.SPECIFICATION_VERSION); - String specVendor = attr.getValue(Attributes.Name.SPECIFICATION_VENDOR); - String implTitle = attr.getValue(Attributes.Name.IMPLEMENTATION_TITLE); - String implVersion = attr.getValue(Attributes.Name.IMPLEMENTATION_VERSION); - String implVendor = attr.getValue(Attributes.Name.IMPLEMENTATION_VENDOR); + + String specTitle + = getAttributeValue(Attributes.Name.SPECIFICATION_TITLE, + entryAttr, attr); + String specVersion + = getAttributeValue(Attributes.Name.SPECIFICATION_VERSION, + entryAttr, attr); + String specVendor + = getAttributeValue(Attributes.Name.SPECIFICATION_VENDOR, + entryAttr, attr); + String implTitle + = getAttributeValue(Attributes.Name.IMPLEMENTATION_TITLE, + entryAttr, attr); + String implVersion + = getAttributeValue(Attributes.Name.IMPLEMENTATION_VERSION, + entryAttr, attr); + String implVendor + = getAttributeValue(Attributes.Name.IMPLEMENTATION_VENDOR, + entryAttr, attr); // Look if the Manifest indicates that this package is sealed // XXX - most likely not completely correct! @@ -793,8 +838,10 @@ public class URLClassLoader extends SecureClassLoader // make sure that the URL is null so the package is not sealed url = null; - return definePackage(name, specTitle, specVersion, specVendor, implTitle, - implVersion, implVendor, url); + return definePackage(name, + specTitle, specVendor, specVersion, + implTitle, implVendor, implVersion, + url); } /** @@ -926,7 +973,7 @@ public class URLClassLoader extends SecureClassLoader */ public String toString() { - synchronized (urlloaders) + synchronized (this) { if (thisString == null) { diff --git a/java/net/URLStreamHandler.java b/java/net/URLStreamHandler.java index 57ce2dfa2..4b0ee49dd 100644 --- a/java/net/URLStreamHandler.java +++ b/java/net/URLStreamHandler.java @@ -511,7 +511,7 @@ public abstract class URLStreamHandler int size = protocol.length() + authority.length() + file.length() + 24; StringBuffer sb = new StringBuffer(size); - if (protocol != null && protocol.length() > 0) + if (protocol.length() > 0) { sb.append(protocol); sb.append(":"); diff --git a/java/nio/charset/Charset.java b/java/nio/charset/Charset.java index e145367bb..be4c4c075 100644 --- a/java/nio/charset/Charset.java +++ b/java/nio/charset/Charset.java @@ -38,19 +38,15 @@ exception statement from your version. */ package java.nio.charset; +import gnu.classpath.ServiceFactory; import gnu.classpath.SystemProperties; - import gnu.java.nio.charset.Provider; import gnu.java.nio.charset.iconv.IconvProvider; -import java.io.BufferedReader; -import java.io.InputStreamReader; -import java.net.URL; import java.nio.ByteBuffer; import java.nio.CharBuffer; import java.nio.charset.spi.CharsetProvider; import java.util.Collections; -import java.util.Enumeration; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashSet; @@ -174,7 +170,7 @@ public abstract class Charset implements Comparable<Charset> * Returns the Charset instance for the charset of the given name. * * @param charsetName - * @return + * @return the Charset instance for the indicated charset * @throws UnsupportedCharsetException if this VM does not support * the charset of the given name. * @throws IllegalCharsetNameException if the given charset name is @@ -265,23 +261,10 @@ public abstract class Charset implements Comparable<Charset> { try { - Enumeration en = ClassLoader.getSystemResources - ("META-INF/services/java.nio.charset.spi.CharsetProvider"); + Iterator i = ServiceFactory.lookupProviders(CharsetProvider.class); LinkedHashSet set = new LinkedHashSet(); - while (en.hasMoreElements()) - { - BufferedReader rdr = new BufferedReader(new InputStreamReader - (((URL) (en.nextElement())).openStream())); - while (true) - { - String s = rdr.readLine(); - if (s == null) - break; - CharsetProvider p = - (CharsetProvider) ((Class.forName(s)).newInstance()); - set.add(p); - } - } + while (i.hasNext()) + set.add(i.next()); providers = new CharsetProvider[set.size()]; set.toArray(providers); diff --git a/java/security/Identity.java b/java/security/Identity.java index 26b01a50a..7ef59cfe2 100644 --- a/java/security/Identity.java +++ b/java/security/Identity.java @@ -297,8 +297,8 @@ public abstract class Identity implements Principal, Serializable if (identity == this) return true; - if ((((Identity) identity).getName() == this.name) && - (((Identity) identity).getScope() == this.scope)) + if ((((Identity) identity).getName().equals(this.name)) && + (((Identity) identity).getScope().equals(this.scope))) return true; return identityEquals((Identity) identity); @@ -319,8 +319,8 @@ public abstract class Identity implements Principal, Serializable */ protected boolean identityEquals(Identity identity) { - return ((identity.getName() == this.name) && - (identity.getPublicKey() == this.publicKey)); + return ((identity.getName().equals(this.name)) && + (identity.getPublicKey().equals(this.publicKey))); } /** diff --git a/java/security/Security.java b/java/security/Security.java index 54b97923e..fd51d0535 100644 --- a/java/security/Security.java +++ b/java/security/Security.java @@ -1,5 +1,5 @@ /* Security.java --- Java base security class implementation - Copyright (C) 1999, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. + Copyright (C) 1999, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -651,7 +651,7 @@ public final class Security if (result.isEmpty()) return null; - return (Provider[]) result.toArray(new Provider[0]); + return (Provider[]) result.toArray(new Provider[result.size()]); } private static void selectProviders(String svc, String algo, String attr, diff --git a/java/text/DateFormat.java b/java/text/DateFormat.java index 5d412aada..73aa62d98 100644 --- a/java/text/DateFormat.java +++ b/java/text/DateFormat.java @@ -58,6 +58,9 @@ import java.util.TimeZone; public abstract class DateFormat extends Format implements Cloneable { + private static final long serialVersionUID = 7218322306649953788L; + + // Names fixed by serialization spec. protected Calendar calendar; protected NumberFormat numberFormat; diff --git a/java/text/ParsePosition.java b/java/text/ParsePosition.java index 782f5e0ed..b0a8a4a0b 100644 --- a/java/text/ParsePosition.java +++ b/java/text/ParsePosition.java @@ -136,6 +136,15 @@ public class ParsePosition ParsePosition other = (ParsePosition) obj; return index == other.index && error_index == other.error_index; } + + /** + * Return the hash code for this object. + * @return the hash code + */ + public int hashCode() + { + return index ^ error_index; + } /** * This method returns a <code>String</code> representation of this diff --git a/java/text/RuleBasedCollator.java b/java/text/RuleBasedCollator.java index ae84a4103..5756e9aa7 100644 --- a/java/text/RuleBasedCollator.java +++ b/java/text/RuleBasedCollator.java @@ -510,7 +510,7 @@ main_parse_loop: int idx; // Parse the subrules but do not iterate through all - // sublist. This is the priviledge of the first call. + // sublist. This is the privilege of the first call. idx = subParseString(true, sorted_rules, base_offset+i, subrules); // Merge new parsed rules into the list. diff --git a/java/text/StringCharacterIterator.java b/java/text/StringCharacterIterator.java index e26748813..85ca302cb 100644 --- a/java/text/StringCharacterIterator.java +++ b/java/text/StringCharacterIterator.java @@ -143,7 +143,7 @@ public final class StringCharacterIterator implements CharacterIterator * an existing StringCharacterIterator and resets the beginning and * ending index. * - * @param scci The StringCharacterIterator to copy the info from + * @param sci The StringCharacterIterator to copy the info from * @param begin The beginning index of the range we are interested in. * @param end The ending index of the range we are interested in. */ @@ -340,6 +340,16 @@ public final class StringCharacterIterator implements CharacterIterator && index == sci.index && text.equals (sci.text)); } + + /** + * Return the hash code for this object. + * @return the hash code + */ + public int hashCode() + { + // Incorporate all the data in a goofy way. + return begin ^ end ^ index ^ text.hashCode(); + } /*************************************************************************/ diff --git a/java/util/ArrayList.java b/java/util/ArrayList.java index c539b5945..6bbf3d01b 100644 --- a/java/util/ArrayList.java +++ b/java/util/ArrayList.java @@ -550,7 +550,7 @@ public class ArrayList<E> extends AbstractList<E> /** * Serializes this object to the given stream. * - * @param out the stream to write to + * @param s the stream to write to * @throws IOException if the underlying stream fails * @serialData the size field (int), the length of the backing array * (int), followed by its elements (Objects) in proper order. @@ -571,7 +571,7 @@ public class ArrayList<E> extends AbstractList<E> /** * Deserializes this object from the given stream. * - * @param in the stream to read from + * @param s the stream to read from * @throws ClassNotFoundException if the underlying stream fails * @throws IOException if the underlying stream fails * @serialData the size field (int), the length of the backing array diff --git a/java/util/Collections.java b/java/util/Collections.java index 2e501bd5c..146ef1aa0 100644 --- a/java/util/Collections.java +++ b/java/util/Collections.java @@ -1892,8 +1892,8 @@ public class Collections } /** - * The implementation of {@link #singletonMap(Object)}. This class name - * is required for compatibility with Sun's JDK serializability. + * The implementation of {@link #singletonMap(Object, Object)}. This class + * name is required for compatibility with Sun's JDK serializability. * * @author Eric Blake (ebb9@email.byu.edu) */ @@ -2683,12 +2683,13 @@ public class Collections } /** - * Add an element to the end of the underlying list (optional operation). - * If the list imposes restraints on what can be inserted, such as no null - * elements, this should be documented. A lock is obtained on the mutex before - * any of the elements are added. + * Add the contents of a collection to the underlying list at the given + * index (optional operation). If the list imposes restraints on what + * can be inserted, such as no null elements, this should be documented. + * A lock is obtained on the mutex before any of the elements are added. * - * @param o the object to add + * @param index the index at which to insert + * @param c the collection to add * @return <code>true</code>, as defined by Collection for a modified list * @throws UnsupportedOperationException if this list does not support the * add operation @@ -4029,7 +4030,7 @@ public class Collections /** * Called only by trusted code to specify the mutex as well as the set. * @param sync the mutex - * @param l the list + * @param ss the set */ SynchronizedSortedSet(Object sync, SortedSet<T> ss) { diff --git a/java/util/HashMap.java b/java/util/HashMap.java index f54f0ce6f..2ce74becc 100644 --- a/java/util/HashMap.java +++ b/java/util/HashMap.java @@ -451,7 +451,7 @@ public class HashMap<K, V> extends AbstractMap<K, V> * * @param value the value to search for in this HashMap * @return true if at least one key maps to the value - * @see containsKey(Object) + * @see #containsKey(Object) */ public boolean containsValue(Object value) { diff --git a/java/util/Locale.java b/java/util/Locale.java index 6d3f84632..9e7bbfea2 100644 --- a/java/util/Locale.java +++ b/java/util/Locale.java @@ -915,7 +915,7 @@ public final class Locale implements Serializable, Cloneable /** * Write the locale to an object stream. * - * @param output the stream to write to + * @param s the stream to write to * @throws IOException if the write fails * @serialData The first three fields are Strings representing language, * country, and variant. The fourth field is a placeholder for @@ -935,7 +935,7 @@ public final class Locale implements Serializable, Cloneable /** * Reads a locale from the input stream. * - * @param input the stream to read from + * @param s the stream to read from * @throws IOException if reading fails * @throws ClassNotFoundException if reading fails * @serialData the hashCode is always invalid and must be recomputed diff --git a/java/util/Random.java b/java/util/Random.java index bc0050751..b016f78d4 100644 --- a/java/util/Random.java +++ b/java/util/Random.java @@ -102,7 +102,7 @@ public class Random implements Serializable * in next. * * @serial the internal state of this generator - * @see #next() + * @see #next(int) */ private long seed; diff --git a/java/util/ResourceBundle.java b/java/util/ResourceBundle.java index 91007e9b1..54be9637a 100644 --- a/java/util/ResourceBundle.java +++ b/java/util/ResourceBundle.java @@ -508,8 +508,7 @@ public abstract class ResourceBundle * * @param baseName the raw bundle name, without locale qualifiers * @param locale the locale - * @param classloader the classloader - * @param bundle the backup (parent) bundle + * @param classLoader the classloader * @param wantBase whether a resource bundle made only from the base name * (with no locale information attached) should be returned. * @return the resource bundle if it was loaded, otherwise the backup diff --git a/java/util/SimpleTimeZone.java b/java/util/SimpleTimeZone.java index 995ccea84..76292996f 100644 --- a/java/util/SimpleTimeZone.java +++ b/java/util/SimpleTimeZone.java @@ -796,7 +796,7 @@ public class SimpleTimeZone extends TimeZone * dst and standard time. * @param calYear the year of the date to check (for leap day checking). * @param calMonth the month of the date to check. - * @param calDay the day of month of the date to check. + * @param calDayOfMonth the day of month of the date to check. * @param calDayOfWeek the day of week of the date to check. * @param calMillis the millis of day of the date to check (standard time). * @param mode the change mode; same semantic as startMode. diff --git a/java/util/Timer.java b/java/util/Timer.java index b145d2b7c..9b23a8fe7 100644 --- a/java/util/Timer.java +++ b/java/util/Timer.java @@ -474,13 +474,25 @@ public class Timer this(daemon, Thread.NORM_PRIORITY); } - /** @since 1.5 */ + /** + * Create a new Timer whose Thread has the indicated name. It will have + * normal priority and will not be a daemon thread. + * @param name the name of the Thread + * @since 1.5 + */ public Timer(String name) { this(false, Thread.NORM_PRIORITY, name); } - /** @since 1.5 */ + /** + * Create a new Timer whose Thread has the indicated name. It will have + * normal priority. The boolean argument controls whether or not it + * will be a daemon thread. + * @param name the name of the Thread + * @param daemon true if the Thread should be a daemon thread + * @since 1.5 + */ public Timer(String name, boolean daemon) { this(daemon, Thread.NORM_PRIORITY, name); @@ -680,7 +692,11 @@ public class Timer queue.setNullOnEmpty(true); } - /** @since 1.5 */ + /** + * Removes all cancelled tasks from the queue. + * @return the number of tasks removed + * @since 1.5 + */ public int purge() { return queue.purge(); diff --git a/java/util/TreeMap.java b/java/util/TreeMap.java index 031e9b859..46f405c59 100644 --- a/java/util/TreeMap.java +++ b/java/util/TreeMap.java @@ -1146,7 +1146,7 @@ public class TreeMap<K, V> extends AbstractMap<K, V> * * @param s the stream to read from * @param count the number of keys to read - * @param readValue true to read values, false to insert "" as the value + * @param readValues true to read values, false to insert "" as the value * @throws ClassNotFoundException if the underlying stream fails * @throws IOException if the underlying stream fails * @see #readObject(ObjectInputStream) diff --git a/java/util/jar/Manifest.java b/java/util/jar/Manifest.java index fdc76ff97..ff82aa2db 100644 --- a/java/util/jar/Manifest.java +++ b/java/util/jar/Manifest.java @@ -80,10 +80,10 @@ public class Manifest implements Cloneable /** * Creates a Manifest from the supplied input stream. * - * @see read(Inputstream) - * @see write(OutputStream) + * @see #read(InputStream) + * @see #write(OutputStream) * - * @param InputStream the input stream to read the manifest from + * @param in the input stream to read the manifest from * @exception IOException when an i/o exception occurs or the input stream * does not describe a valid manifest */ @@ -102,7 +102,7 @@ public class Manifest implements Cloneable * a particular entry also changes the attributes of that entry in the * original manifest. * - * @see clone() + * @see #clone() * @param man the Manifest to copy from */ public Manifest(Manifest man) diff --git a/java/util/logging/FileHandler.java b/java/util/logging/FileHandler.java index 3d958b7d7..b03df97ec 100644 --- a/java/util/logging/FileHandler.java +++ b/java/util/logging/FileHandler.java @@ -43,10 +43,6 @@ import java.io.FileOutputStream; import java.io.FilterOutputStream; import java.io.IOException; import java.io.OutputStream; - -import java.nio.channels.FileChannel; -import java.nio.channels.FileLock; - import java.util.LinkedList; import java.util.ListIterator; diff --git a/java/util/logging/Handler.java b/java/util/logging/Handler.java index c3227d6f5..616b50234 100644 --- a/java/util/logging/Handler.java +++ b/java/util/logging/Handler.java @@ -191,8 +191,8 @@ h.setFormatter(h.getFormatter());</pre> * Returns the character encoding which this handler uses for publishing * log records. * - * @param encoding the name of a character encoding, or <code>null</code> - * for the default platform encoding. + * @return the name of a character encoding, or <code>null</code> + * for the default platform encoding. */ public String getEncoding() { @@ -252,7 +252,7 @@ h.setFormatter(h.getFormatter());</pre> * Sets the <code>Filter</code> for controlling which * log records will be published by this <code>Handler</code>. * - * @return the <code>Filter</code> to use, or + * @param filter the <code>Filter</code> to use, or * <code>null</code> to filter log records purely based * on their severity level. */ diff --git a/java/util/logging/LogManager.java b/java/util/logging/LogManager.java index 7e3fd97d0..b62292f79 100644 --- a/java/util/logging/LogManager.java +++ b/java/util/logging/LogManager.java @@ -664,7 +664,7 @@ public class LogManager { try { - return (new Boolean(getLogManager().getProperty(name))).booleanValue(); + return (Boolean.valueOf(getLogManager().getProperty(name))).booleanValue(); } catch (Exception ex) { @@ -682,7 +682,7 @@ public class LogManager * * @param defaultValue the value that will be returned if the * property is not defined, or if - * {@link Level.parse(java.lang.String)} does not like + * {@link Level#parse(java.lang.String)} does not like * the property value. */ static Level getLevelProperty(String propertyName, Level defaultValue) diff --git a/java/util/logging/LoggingPermission.java b/java/util/logging/LoggingPermission.java index c7a2255ec..1139a793a 100644 --- a/java/util/logging/LoggingPermission.java +++ b/java/util/logging/LoggingPermission.java @@ -41,6 +41,8 @@ package java.util.logging; public final class LoggingPermission extends java.security.BasicPermission { + private static final long serialVersionUID = 63564341580231582L; + /** * Creates a new LoggingPermission. * diff --git a/java/util/logging/SimpleFormatter.java b/java/util/logging/SimpleFormatter.java index f7a442792..ff53db8c0 100644 --- a/java/util/logging/SimpleFormatter.java +++ b/java/util/logging/SimpleFormatter.java @@ -85,7 +85,7 @@ public class SimpleFormatter /** * Formats a log record into a String. * - * @param the log record to be formatted. + * @param record the log record to be formatted. * * @return a short human-readable message, typically one or two * lines. Lines are separated using the default platform line diff --git a/java/util/logging/XMLFormatter.java b/java/util/logging/XMLFormatter.java index 4dd632817..8bd83ba39 100644 --- a/java/util/logging/XMLFormatter.java +++ b/java/util/logging/XMLFormatter.java @@ -307,7 +307,7 @@ public class XMLFormatter * * @return a string for the header. * - * @param handler the handler which will prepend the returned + * @param h the handler which will prepend the returned * string in front of the first log record. This method * will inspect certain properties of the handler, for * example its encoding, in order to construct the header. diff --git a/java/util/prefs/Preferences.java b/java/util/prefs/Preferences.java index c407ae612..3fee1c5da 100644 --- a/java/util/prefs/Preferences.java +++ b/java/util/prefs/Preferences.java @@ -230,15 +230,15 @@ public abstract class Preferences { } /** - * Returns the system preferences node for the package of an object. - * The package node name of the object is determined by dropping the - * class name of the object of the fully quallified class name and - * replacing all '.' to '/' in the package name. If the class of the + * Returns the system preferences node for the package of a class. + * The package node name of the class is determined by dropping the + * final component of the fully qualified class name and + * changing all '.' to '/' in the package name. If the class of the * object has no package then the package node name is "<unnamed>". - * The returened node is <code>systemRoot().node(packageNodeName)</code>. + * The returned node is <code>systemRoot().node(packageNodeName)</code>. * - * @param o Object whose default system preference node is requested - * @returns system preferences node that should be used by object o + * @param c Object whose default system preference node is requested + * @returns system preferences node that should be used by class c * @exception SecurityException when a security manager is installed and * the caller does not have <code>RuntimePermission("preferences")</code>. */ @@ -249,15 +249,15 @@ public abstract class Preferences { } /** - * Returns the user preferences node for the package of an object. - * The package node name of the object is determined by dropping the - * class name of the object of the fully quallified class name and - * replacing all '.' to '/' in the package name. If the class of the + * Returns the user preferences node for the package of a class. + * The package node name of the class is determined by dropping the + * final component of the fully qualified class name and + * changing all '.' to '/' in the package name. If the class of the * object has no package then the package node name is "<unnamed>". - * The returened node is <code>userRoot().node(packageNodeName)</code>. + * The returned node is <code>userRoot().node(packageNodeName)</code>. * - * @param o Object whose default user preference node is requested - * @returns user preferences node that should be used by object o + * @param c Object whose default userpreference node is requested + * @returns userpreferences node that should be used by class c * @exception SecurityException when a security manager is installed and * the caller does not have <code>RuntimePermission("preferences")</code>. */ diff --git a/java/util/regex/Matcher.java b/java/util/regex/Matcher.java index bd97ace54..5d04bdbfc 100644 --- a/java/util/regex/Matcher.java +++ b/java/util/regex/Matcher.java @@ -227,9 +227,9 @@ public final class Matcher * If the match succeeds then more information can be obtained via the * start, end, and group methods. * - * @see #start - * @see #end - * @see #group + * @see #start() + * @see #end() + * @see #group() */ public boolean matches () { @@ -267,7 +267,7 @@ public final class Matcher } /** - * @param group The index of a capturing group in this matcher's pattern + * @returns the index of a capturing group in this matcher's pattern * * @exception IllegalStateException If no match has yet been attempted, * or if the previous match operation failed diff --git a/java/util/zip/PendingBuffer.java b/java/util/zip/PendingBuffer.java index dd7ed1008..9079b9804 100644 --- a/java/util/zip/PendingBuffer.java +++ b/java/util/zip/PendingBuffer.java @@ -183,7 +183,7 @@ class PendingBuffer /** * Flushes the pending buffer and returns that data in a new array * - * @param output the output stream + * @return the output stream */ public final byte[] toByteArray() diff --git a/java/util/zip/ZipFile.java b/java/util/zip/ZipFile.java index 0243abed1..4be845ea7 100644 --- a/java/util/zip/ZipFile.java +++ b/java/util/zip/ZipFile.java @@ -144,9 +144,18 @@ public class ZipFile implements ZipConstants private void checkZipFile() throws IOException, ZipException { byte[] magicBuf = new byte[4]; - raf.read(magicBuf); + boolean validRead = true; - if (readLeInt(magicBuf, 0) != LOCSIG) + try + { + raf.readFully(magicBuf); + } + catch (EOFException eof) + { + validRead = false; + } + + if (validRead == false || readLeInt(magicBuf, 0) != LOCSIG) { raf.close(); throw new ZipException("Not a valid zip file"); @@ -377,7 +386,7 @@ public class ZipFile implements ZipConstants * Checks that the ZipFile is still open and reads entries when necessary. * * @exception IllegalStateException when the ZipFile has already been closed. - * @exception IOEexception when the entries could not be read. + * @exception IOException when the entries could not be read. */ private HashMap getEntries() throws IOException { @@ -395,7 +404,7 @@ public class ZipFile implements ZipConstants /** * Searches for a zip entry in this archive with the given name. * - * @param the name. May contain directory components separated by + * @param name the name. May contain directory components separated by * slashes ('/'). * @return the zip entry, or null if no entry with that name exists. * diff --git a/javax/naming/CompoundName.java b/javax/naming/CompoundName.java index 4b30557f8..b23736fa7 100644 --- a/javax/naming/CompoundName.java +++ b/javax/naming/CompoundName.java @@ -38,6 +38,9 @@ exception statement from your version. */ package javax.naming; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; import java.io.Serializable; import java.util.Enumeration; import java.util.NoSuchElementException; @@ -48,9 +51,6 @@ import java.util.Vector; * @author Tom Tromey (tromey@redhat.com) * @date May 16, 2001 * - * FIXME: must write readObject and writeObject to conform to - * serialization spec. - * * FIXME: this class is underspecified. For instance, the `flat' * direction is never described. If it means that the CompoundName * can only have a single element, then the Enumeration-based @@ -469,6 +469,25 @@ public class CompoundName implements Name, Cloneable, Serializable "false")).booleanValue (); } + private void readObject(ObjectInputStream s) + throws IOException, ClassNotFoundException + { + mySyntax = (Properties) s.readObject(); + int count = s.readInt(); + elts = new Vector(count); + for (int i = 0; i < count; i++) + elts.addElement((String) s.readObject()); + } + + private void writeObject(ObjectOutputStream s) + throws IOException + { + s.writeObject(mySyntax); + s.writeInt(elts.size()); + for (int i = 0; i < elts.size(); i++) + s.writeObject(elts.elementAt(i)); + } + // The spec specifies this but does not document it in any way (it // is a package-private class). It is useless as far as I can tell. // So we ignore it. diff --git a/javax/naming/Name.java b/javax/naming/Name.java index f8592d9ea..f0475766a 100644 --- a/javax/naming/Name.java +++ b/javax/naming/Name.java @@ -1,5 +1,5 @@ /* Name.java -- Name build up from different components - Copyright (C) 2000, 2001, 2004 Free Software Foundation, Inc. + Copyright (C) 2000, 2001, 2004, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -60,7 +60,7 @@ import java.util.Enumeration; * @author Anthony Green (green@redhat.com) * @author Mark Wielaard (mark@klomp.org) */ -public interface Name extends Cloneable, Serializable +public interface Name extends Cloneable, Serializable, Comparable { long serialVersionUID = -3617482732056931635L; diff --git a/javax/print/DocFlavor.java b/javax/print/DocFlavor.java index 732823fbe..e889a4544 100644 --- a/javax/print/DocFlavor.java +++ b/javax/print/DocFlavor.java @@ -54,6 +54,8 @@ public class DocFlavor implements Cloneable, Serializable public static class BYTE_ARRAY extends DocFlavor { + private static final long serialVersionUID = -906557800693857475L; + public static final BYTE_ARRAY AUTOSENSE = new BYTE_ARRAY("application/octet-stream"); public static final BYTE_ARRAY GIF = new BYTE_ARRAY("image/gif"); public static final BYTE_ARRAY JPEG = new BYTE_ARRAY("image/jpeg"); @@ -103,6 +105,8 @@ public class DocFlavor implements Cloneable, Serializable public static class INPUT_STREAM extends DocFlavor { + private static final long serialVersionUID = -7045842700749194127L; + public static final INPUT_STREAM AUTOSENSE = new INPUT_STREAM("application/octet-stream"); public static final INPUT_STREAM GIF = new INPUT_STREAM("image/gif"); public static final INPUT_STREAM JPEG = new INPUT_STREAM("image/jpeg"); diff --git a/javax/security/auth/Subject.java b/javax/security/auth/Subject.java index 4e35a645d..1659c6425 100644 --- a/javax/security/auth/Subject.java +++ b/javax/security/auth/Subject.java @@ -1,5 +1,5 @@ /* Subject.java -- a single entity in the system. - Copyright (C) 2004 Free Software Foundation, Inc. + Copyright (C) 2004, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -385,19 +385,19 @@ public final class Subject implements Serializable // Constructors. // ----------------------------------------------------------------------- - SecureSet (final Subject subject, final int type, final Collection elements) + SecureSet (final Subject subject, final int type, final Collection inElements) { this (subject, type); - for (Iterator it = elements.iterator(); it.hasNext(); ) + for (Iterator it = inElements.iterator(); it.hasNext(); ) { Object o = it.next(); if (type == PRINCIPALS && !(o instanceof Principal)) { throw new IllegalArgumentException(o+" is not a Principal"); } - if (!elements.contains (o)) + if (!this.elements.contains (o)) { - elements.add (o); + this.elements.add (o); } } } @@ -511,7 +511,7 @@ public final class Subject implements Serializable public synchronized boolean contains (final Object element) { - return elements.remove (element); + return elements.contains (element); } public boolean removeAll (final Collection c) diff --git a/javax/security/auth/SubjectDomainCombiner.java b/javax/security/auth/SubjectDomainCombiner.java index 94a7160eb..927e7479d 100644 --- a/javax/security/auth/SubjectDomainCombiner.java +++ b/javax/security/auth/SubjectDomainCombiner.java @@ -1,5 +1,5 @@ /* SubjectDomainCombiner.java -- domain combiner for Subjects. - Copyright (C) 2004 Free Software Foundation, Inc. + Copyright (C) 2004, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -67,8 +67,9 @@ public class SubjectDomainCombiner implements DomainCombiner final ProtectionDomain[] assigned) { LinkedList domains = new LinkedList(); - Principal[] principals = - (Principal[]) subject.getPrincipals().toArray (new Principal[0]); + Principal[] principals = null; + if (subject != null) + principals = (Principal[]) subject.getPrincipals().toArray (new Principal[0]); if (current != null) { for (int i = 0; i < current.length; i++) diff --git a/javax/security/auth/login/Configuration.java b/javax/security/auth/login/Configuration.java index 1e0d272f1..eb5e4a819 100644 --- a/javax/security/auth/login/Configuration.java +++ b/javax/security/auth/login/Configuration.java @@ -67,29 +67,7 @@ public abstract class Configuration SecurityManager sm = System.getSecurityManager(); if (sm != null) sm.checkPermission (new AuthPermission ("getLoginConfiguration")); - if (config == null) - { - String conf = (String) AccessController.doPrivileged - (new PrivilegedAction() - { - public Object run() - { - return Security.getProperty ("login.configuration.provider"); - } - }); - try - { - if (conf != null) - config = (Configuration) Class.forName (conf).newInstance(); - else - config = new NullConfiguration(); - } - catch (Exception x) - { - config = new NullConfiguration(); - } - } - return config; + return getConfig(); } public static synchronized void setConfiguration (Configuration config) @@ -115,6 +93,28 @@ public abstract class Configuration */ static Configuration getConfig() { + if (config == null) + { + String conf = (String) AccessController.doPrivileged + (new PrivilegedAction() + { + public Object run() + { + return Security.getProperty ("login.configuration.provider"); + } + }); + try + { + if (conf != null) + config = (Configuration) Class.forName (conf).newInstance(); + else + config = new NullConfiguration(); + } + catch (Exception x) + { + config = new NullConfiguration(); + } + } return config; } } diff --git a/javax/swing/ButtonModel.java b/javax/swing/ButtonModel.java index 1bdc5d185..03fac13d2 100644 --- a/javax/swing/ButtonModel.java +++ b/javax/swing/ButtonModel.java @@ -49,37 +49,253 @@ import javax.swing.event.ChangeListener; */ public interface ButtonModel extends ItemSelectable { - boolean isArmed(); - void setArmed(boolean b); + /** + * Returns <code>true</code> if the button is armed, <code>false</code> + * otherwise. + * + * A button is armed, when the user has pressed the mouse over it, but has + * not yet released the mouse. + * + * @return <code>true</code> if the button is armed, <code>false</code> + * otherwise + * + * @see #setArmed(boolean) + */ + boolean isArmed(); - boolean isEnabled(); - void setEnabled(boolean b); + /** + * Sets the armed flag of the button. + * + * A button is armed, when the user has pressed the mouse over it, but has + * not yet released the mouse. + * + * @param b <code>true</code> if the button is armed, <code>false</code> + * otherwise + * + * @see #isArmed() + */ + void setArmed(boolean b); - void setPressed(boolean b); - boolean isPressed(); + /** + * Returns <code>true</code> if the button is enabled, <code>false</code> + * otherwise. + * + * When a button is disabled, it is usually grayed out and the user cannot + * change its state. + * + * @return <code>true</code> if the button is enabled, <code>false</code> + * otherwise + * + * @see #setEnabled(boolean) + */ + boolean isEnabled(); + /** + * Sets the enabled flag of the button. + * + * When a button is disabled, it is usually grayed out and the user cannot + * change its state. + * + * @param b <code>true</code> if the button is enabled, <code>false</code> + * otherwise + * + * @see #isEnabled() + */ + void setEnabled(boolean b); - void removeActionListener(ActionListener l); - void addActionListener(ActionListener l); + /** + * Sets the pressed flag of the button. + * + * The button usually gets pressed when the user clicks on a button, it will + * be un-pressed when the user releases the mouse. + * + * @param b <code>true</code> if the button is pressed, <code>false</code> + * otherwise + * + * @see #isPressed() + */ + void setPressed(boolean b); - void addItemListener(ItemListener l); - void removeItemListener(ItemListener l); - - void addChangeListener(ChangeListener l); - void removeChangeListener(ChangeListener l); + /** + * Returns <code>true</code> if the button is pressed, <code>false</code> + * otherwise. + * + * The button usually gets pressed when the user clicks on a button, it will + * be un-pressed when the user releases the mouse. + * + * @return <code>true</code> if the button is pressed, <code>false</code> + * otherwise + * + * @see #setPressed(boolean) + */ + boolean isPressed(); - void setRollover(boolean b); - boolean isRollover(); + /** + * Removes an {@link ActionListener} from the list of registered listeners. + * + * @param l the action listener to remove + * + * @see #addActionListener(ActionListener) + */ + void removeActionListener(ActionListener l); - int getMnemonic(); - void setMnemonic(int key); + /** + * Adds an {@link ActionListener} to the list of registered listeners. + * + * An <code>ActionEvent</code> is usually fired when the user clicks on a + * button. + * + * @param l the action listener to add + * + * @see #removeActionListener(ActionListener) + */ + void addActionListener(ActionListener l); - void setActionCommand(String s); - String getActionCommand(); + /** + * Adds an {@link ItemListener} to the list of registered listeners. + * + * An <code>ItemEvent</code> is usually fired when a button's selected + * state changes. This applies only to buttons that support the selected + * flag. + * + * @param l the item listener to add + * + * @see #removeItemListener(ItemListener) + */ + void addItemListener(ItemListener l); - void setGroup(ButtonGroup group); + /** + * Adds an {@link ItemListener} to the list of registered listeners. + * + * @param l the item listener to add + * + * @see #removeItemListener(ItemListener) + */ + void removeItemListener(ItemListener l); - void setSelected(boolean b); - boolean isSelected(); + /** + * Adds an {@link ChangeListener} to the list of registered listeners. + * + * A <code>ChangeEvent</code> is fired when any one of the button's flags + * changes. + * + * @param l the change listener to add + * + * @see #removeChangeListener(ChangeListener) + */ + void addChangeListener(ChangeListener l); + + /** + * Adds an {@link ChangeListener} to the list of registered listeners. + * + * @param l the change listener to add + * + * @see #removeChangeListener(ChangeListener) + */ + void removeChangeListener(ChangeListener l); + + /** + * Sets the rollover flag of the button. + * + * A button is rollover-ed, when the user has moved the mouse over it, but has + * not yet pressed the mouse. + * + * @param b <code>true</code> if the button is rollover, <code>false</code> + * otherwise + * + * @see #isRollover() + */ + void setRollover(boolean b); + + /** + * Returns <code>true</code> if the button is rollover-ed, <code>false</code> + * otherwise. + * + * A button is rollover-ed, when the user has moved the mouse over it, but has + * not yet pressed the mouse. + * + * @return <code>true</code> if the button is rollover, <code>false</code> + * otherwise + * + * @see #setRollover(boolean) + */ + boolean isRollover(); + + /** + * Returns the keyboard mnemonic for the button. This specifies a shortcut + * or accelerator key that can be used to activate the button. + * + * @return the keyboard mnemonic for the button + * + * @see #setMnemonic(int) + */ + int getMnemonic(); + + /** + * Sets the keyboard mnemonic for the button. This specifies a shortcut + * or accelerator key that can be used to activate the button. + * + * @param key the keyboard mnemonic for the button + * + * @see #getMnemonic() + */ + void setMnemonic(int key); + + /** + * Sets the action command for the button. This will be used in + * <code>ActionEvents</code> fired by the button. + * + * @param s the action command to set + * + * @see #getActionCommand() + */ + void setActionCommand(String s); + + /** + * Returns the action command of the button. + * + * @return the action command of the button + * + * @see #setActionCommand(String) + */ + String getActionCommand(); + + /** + * Sets the button group for the button. Some kinds of button (e.g. radio + * buttons) allow only one button within a button group selected at any one + * time. + * + * @param group the button group to set + */ + void setGroup(ButtonGroup group); + + /** + * Sets the selected flag of the button. + * + * Some kinds of buttons (e.g. toggle buttons, check boxes, radio buttons) + * can be in one of two states: selected or unselected. The selected state + * is usually toggled by clicking on the button. + * + * @param b <code>true</code> if the button is selected, <code>false</code> + * otherwise + * + * @see #isSelected() + */ + void setSelected(boolean b); + + /** + * Returns <code>true</code> if the button is selected, <code>false</code> + * otherwise. + * + * Some kinds of buttons (e.g. toggle buttons, check boxes, radio buttons) + * can be in one of two states: selected or unselected. The selected state + * is usually toggled by clicking on the button. + * + * @return <code>true</code> if the button is selected, <code>false</code> + * otherwise + * + * @see #setSelected(boolean) + */ + boolean isSelected(); } diff --git a/javax/swing/JCheckBox.java b/javax/swing/JCheckBox.java index a743308dc..f493782b2 100644 --- a/javax/swing/JCheckBox.java +++ b/javax/swing/JCheckBox.java @@ -38,7 +38,9 @@ exception statement from your version. */ package javax.swing; +import javax.accessibility.Accessible; import javax.accessibility.AccessibleContext; +import javax.accessibility.AccessibleRole; /** * A small box that displays a check or not, depending on it's @@ -54,8 +56,32 @@ import javax.accessibility.AccessibleContext; * * @author Ronald Veldema (rveldema@cs.vu.nl) */ -public class JCheckBox extends JToggleButton +public class JCheckBox extends JToggleButton implements Accessible { + + /** + * Provides accessibility support for <code>JCheckBox</code>. + */ + protected class AccessibleJCheckBox extends AccessibleJToggleButton + { + /** + * Creates a new instance of <code>AccessibleJCheckBox</code>. + */ + public AccessibleJCheckBox() + { + // Nothing to do here. + } + + /** + * Returns the accessble role of <code>JCheckBox</code>, + * {@link AccessibleRole#CHECK_BOX}. + */ + public AccessibleRole getAccessibleRole() + { + return AccessibleRole.CHECK_BOX; + } + } + private static final long serialVersionUID = -5246739313864538930L; public static final String BORDER_PAINTED_FLAT_CHANGED_PROPERTY = @@ -118,14 +144,6 @@ public class JCheckBox extends JToggleButton } /** - * Gets the AccessibleContext associated with this JCheckBox. - */ - public AccessibleContext getAccessibleContext() - { - return null; - } - - /** * Returns a string that specifies the name of the Look and Feel class * that renders this component. */ @@ -149,4 +167,16 @@ public class JCheckBox extends JToggleButton firePropertyChange("borderPaintedFlat", borderPaintedFlat, newValue); borderPaintedFlat = newValue; } + + /** + * Returns the accessible context for this <code>JCheckBox</code>. + * + * @return the accessible context for this <code>JCheckBox</code> + */ + public AccessibleContext getAccessibleContext() + { + if (accessibleContext == null) + accessibleContext = new AccessibleJCheckBox(); + return accessibleContext; + } } diff --git a/javax/swing/JComboBox.java b/javax/swing/JComboBox.java index 47d18323a..07e149e7e 100644 --- a/javax/swing/JComboBox.java +++ b/javax/swing/JComboBox.java @@ -551,14 +551,37 @@ public class JComboBox extends JComponent implements ItemSelectable, return -1; } + /** + * Returns an object that is used as the display value when calculating the + * preferred size for the combo box. This value is, of course, never + * displayed anywhere. + * + * @return The prototype display value (possibly <code>null</code>). + * + * @since 1.4 + * @see #setPrototypeDisplayValue(Object) + */ public Object getPrototypeDisplayValue() { return prototypeDisplayValue; } - public void setPrototypeDisplayValue(Object newPrototypeDisplayValue) + /** + * Sets the object that is assumed to be the displayed item when calculating + * the preferred size for the combo box. A {@link PropertyChangeEvent} (with + * the name <code>prototypeDisplayValue</code>) is sent to all registered + * listeners. + * + * @param value the new value (<code>null</code> permitted). + * + * @since 1.4 + * @see #getPrototypeDisplayValue() + */ + public void setPrototypeDisplayValue(Object value) { - prototypeDisplayValue = newPrototypeDisplayValue; + Object oldValue = prototypeDisplayValue; + prototypeDisplayValue = value; + firePropertyChange("prototypeDisplayValue", oldValue, value); } /** diff --git a/javax/swing/JComponent.java b/javax/swing/JComponent.java index dc7689b09..3b4dbf32a 100644 --- a/javax/swing/JComponent.java +++ b/javax/swing/JComponent.java @@ -452,7 +452,9 @@ public abstract class JComponent extends Container implements Serializable /** * Add a client property <code>value</code> to this component, associated * with <code>key</code>. If there is an existing client property - * associated with <code>key</code>, it will be replaced. + * associated with <code>key</code>, it will be replaced. A + * {@link PropertyChangeEvent} is sent to registered listeners (with the + * name of the property being <code>key.toString()</code>). * * @param key The key of the client property association to add * @param value The value of the client property association to add @@ -463,10 +465,13 @@ public abstract class JComponent extends Container implements Serializable */ public final void putClientProperty(Object key, Object value) { + Hashtable t = getClientProperties(); + Object old = t.get(key); if (value != null) - getClientProperties().put(key, value); + t.put(key, value); else - getClientProperties().remove(key); + t.remove(key); + firePropertyChange(key.toString(), old, value); } /** diff --git a/javax/swing/JFileChooser.java b/javax/swing/JFileChooser.java index 7569061ab..0eb832848 100644 --- a/javax/swing/JFileChooser.java +++ b/javax/swing/JFileChooser.java @@ -715,7 +715,7 @@ public class JFileChooser extends JComponent implements Accessible */ public FileFilter[] getChoosableFileFilters() { - return (FileFilter[]) choosableFilters.toArray(new FileFilter[0]); + return (FileFilter[]) choosableFilters.toArray(new FileFilter[choosableFilters.size()]); } /** diff --git a/javax/swing/JLayeredPane.java b/javax/swing/JLayeredPane.java index 1ea39dc50..e86910395 100644 --- a/javax/swing/JLayeredPane.java +++ b/javax/swing/JLayeredPane.java @@ -46,6 +46,8 @@ import java.util.Map; import java.util.TreeMap; import javax.accessibility.Accessible; +import javax.accessibility.AccessibleContext; +import javax.accessibility.AccessibleRole; /** * A container that adds depth to the usual <code>Container</code> semantics. @@ -116,6 +118,30 @@ import javax.accessibility.Accessible; */ public class JLayeredPane extends JComponent implements Accessible { + + /** + * Provides accessibility support for <code>JLayeredPane</code>. + */ + protected class AccessibleJLayeredPane extends AccessibleJComponent + { + /** + * Creates a new instance of <code>AccessibleJLayeredPane</code>. + */ + public AccessibleJLayeredPane() + { + // Nothing to do here. + } + + /** + * Returns the accessble role of <code>JLayeredPane</code>, + * {@link AccessibleRole#LAYERED_PANE}. + */ + public AccessibleRole getAccessibleRole() + { + return AccessibleRole.LAYERED_PANE; + } + } + private static final long serialVersionUID = 5534920399324590459L; public static final String LAYER_PROPERTY = "layeredContainerLayer"; @@ -135,6 +161,7 @@ public class JLayeredPane extends JComponent implements Accessible { layers = new TreeMap (); componentToLayer = new Hashtable (); + setLayout(null); } @@ -642,4 +669,16 @@ public class JLayeredPane extends JComponent implements Accessible { getLayeredPaneAbove(component).setLayer(component, layer); } + + /** + * Returns the accessible context for this <code>JLayeredPane</code>. + * + * @return the accessible context for this <code>JLayeredPane</code> + */ + public AccessibleContext getAccessibleContext() + { + if (accessibleContext == null) + accessibleContext = new AccessibleJLayeredPane(); + return accessibleContext; + } } diff --git a/javax/swing/JList.java b/javax/swing/JList.java index 92fe1ccfa..0aedee2ab 100644 --- a/javax/swing/JList.java +++ b/javax/swing/JList.java @@ -41,13 +41,25 @@ package javax.swing; import java.awt.Color; import java.awt.Component; import java.awt.ComponentOrientation; +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.awt.event.FocusListener; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.util.Locale; import java.util.Vector; import javax.accessibility.Accessible; +import javax.accessibility.AccessibleComponent; import javax.accessibility.AccessibleContext; +import javax.accessibility.AccessibleRole; +import javax.accessibility.AccessibleSelection; +import javax.accessibility.AccessibleState; +import javax.accessibility.AccessibleStateSet; import javax.swing.event.ListDataEvent; import javax.swing.event.ListDataListener; import javax.swing.event.ListSelectionEvent; @@ -108,6 +120,728 @@ import javax.swing.text.Position; public class JList extends JComponent implements Accessible, Scrollable { + + /** + * Provides accessibility support for <code>JList</code>. + */ + protected class AccessibleJList extends AccessibleJComponent + implements AccessibleSelection, PropertyChangeListener, + ListSelectionListener, ListDataListener + { + + /** + * Provides accessibility support for list elements in <code>JList</code>s. + */ + protected class AccessibleJListChild extends AccessibleContext + implements Accessible, AccessibleComponent + { + + /** + * The parent list. + */ + JList parent; + + /** + * The index in the list for that child. + */ + int listIndex; + + /** + * The cursor for this list child. + */ + // TODO: Testcases show that this class somehow stores state about the + // cursor. I cannot make up though how that could affect + // the actual list. + Cursor cursor = Cursor.getDefaultCursor(); + + /** + * Creates a new instance of <code>AccessibleJListChild</code>. + * + * @param list the list of which this is an accessible child + * @param index the list index for this child + */ + public AccessibleJListChild(JList list, int index) + { + parent = list; + listIndex = index; + } + + /** + * Returns the accessible context of this object. Returns + * <code>this</code> since <code>AccessibleJListChild</code>s are their + * own accessible contexts. + * + * @return the accessible context of this object, <code>this</code> + */ + public AccessibleContext getAccessibleContext() + { + return this; + } + + /** + * Returns the background color for this list child. This returns the + * background of the <code>JList</code> itself since the background + * cannot be set on list children individually + * + * @return the background color for this list child + */ + public Color getBackground() + { + return parent.getBackground(); + } + + /** + * Calling this method has no effect, since the background color cannot be + * set on list children individually. + * + * @param color not used here. + */ + public void setBackground(Color color) + { + // Calling this method has no effect, since the background color cannot + // be set on list children individually. + } + + /** + * Returns the foreground color for this list child. This returns the + * background of the <code>JList</code> itself since the foreground + * cannot be set on list children individually. + * + * @return the background color for this list child + */ + public Color getForeground() + { + return parent.getForeground(); + } + + /** + * Calling this method has no effect, since the foreground color cannot be + * set on list children individually. + * + * @param color not used here. + */ + public void setForeground(Color color) + { + // Calling this method has no effect, since the foreground color cannot + // be set on list children individually. + } + + /** + * Returns the cursor for this list child. + * + * @return the cursor for this list child + */ + public Cursor getCursor() + { + // TODO: Testcases show that this method returns the cursor that has + // been set by setCursor. I cannot make up though how that could affect + // the actual list. + return cursor; + } + + /** + * Sets the cursor for this list child. + */ + public void setCursor(Cursor cursor) + { + this.cursor = cursor; + // TODO: Testcases show that this method returns the cursor that has + // been set by setCursor. I cannot make up though how that could affect + // the actual list. + } + + /** + * Returns the font of the <code>JList</code> since it is not possible to + * set fonts for list children individually. + * + * @return the font of the <code>JList</code> + */ + public Font getFont() + { + return parent.getFont(); + } + + /** + * Does nothing since it is not possible to set the font on list children + * individually. + * + * @param font not used here + */ + public void setFont(Font font) + { + // Does nothing since it is not possible to set the font on list + // children individually. + } + + /** + * Returns the font metrics for the specified font. This method forwards + * to the parent <code>JList</code>. + * + * @param font the font for which the font metrics is queried + * + * @return the font metrics for the specified font + */ + public FontMetrics getFontMetrics(Font font) + { + return parent.getFontMetrics(font); + } + + /** + * Returns <code>true</code> if the parent <code>JList</code> is enabled, + * <code>false</code> otherwise. The list children cannot have an enabled + * flag set individually. + * + * @return <code>true</code> if the parent <code>JList</code> is enabled, + * <code>false</code> otherwise + */ + public boolean isEnabled() + { + return parent.isEnabled(); + } + + /** + * Does nothing since the enabled flag cannot be set for list children + * individually. + * + * @param b not used here + */ + public void setEnabled(boolean b) + { + // Does nothing since the enabled flag cannot be set for list children + // individually. + } + + /** + * Returns <code>true</code> if this list child is visible, + * <code>false</code> otherwise. The value of this property depends + * on {@link JList#getFirstVisibleIndex()} and + * {@link JList#getLastVisibleIndex()}. + * + * @return <code>true</code> if this list child is visible, + * <code>false</code> otherwise + */ + public boolean isVisible() + { + return listIndex >= parent.getFirstVisibleIndex() + && listIndex <= parent.getLastVisibleIndex(); + } + + /** + * The value of the visible property cannot be modified, so this method + * does nothing. + * + * @param b not used here + */ + public void setVisible(boolean b) + { + // The value of the visible property cannot be modified, so this method + // does nothing. + } + + /** + * Returns <code>true</code> if this list child is currently showing on + * screen and <code>false</code> otherwise. The list child is showing if + * it is visible and if it's parent JList is currently showing. + * + * @return <code>true</code> if this list child is currently showing on + * screen and <code>false</code> otherwise + */ + public boolean isShowing() + { + return isVisible() && parent.isShowing(); + } + + /** + * Returns <code>true</code> if this list child covers the screen location + * <code>point</code> (relative to the <code>JList</code> coordinate + * system, <code>false</code> otherwise. + * + * @return <code>true</code> if this list child covers the screen location + * <code>point</code> , <code>false</code> otherwise + */ + public boolean contains(Point point) + { + return getBounds().contains(point); + } + + /** + * Returns the absolute screen location of this list child. + * + * @return the absolute screen location of this list child + */ + public Point getLocationOnScreen() + { + Point loc = getLocation(); + SwingUtilities.convertPointToScreen(loc, parent); + return loc; + } + + /** + * Returns the screen location of this list child relative to it's parent. + * + * @return the location of this list child relative to it's parent + * + * @see JList#indexToLocation(int) + */ + public Point getLocation() + { + return parent.indexToLocation(listIndex); + } + + /** + * Does nothing since the screen location cannot be set on list children + * explictitly. + * + * @param point not used here + */ + public void setLocation(Point point) + { + // Does nothing since the screen location cannot be set on list children + // explictitly. + } + + /** + * Returns the bounds of this list child. + * + * @return the bounds of this list child + * + * @see JList#getCellBounds(int, int) + */ + public Rectangle getBounds() + { + return parent.getCellBounds(listIndex, listIndex); + } + + /** + * Does nothing since the bounds cannot be set on list children + * individually. + * + * @param rectangle not used here + */ + public void setBounds(Rectangle rectangle) + { + // Does nothing since the bounds cannot be set on list children + // individually. + } + + /** + * Returns the size of this list child. + * + * @return the size of this list child + */ + public Dimension getSize() + { + Rectangle b = getBounds(); + return b.getSize(); + } + + /** + * Does nothing since the size cannot be set on list children + * individually. + * + * @param dimension not used here + */ + public void setSize(Dimension dimension) + { + // Does nothing since the size cannot be set on list children + // individually. + } + + /** + * Returns <code>null</code> because list children do not have children + * themselves + * + * @return <code>null</code> + */ + public Accessible getAccessibleAt(Point point) + { + return null; + } + + /** + * Returns <code>true</code> since list children are focus traversable. + * + * @return true + */ + public boolean isFocusTraversable() + { + // TODO: Is this 100% ok? + return true; + } + + /** + * Requests focus on the parent list. List children cannot request focus + * individually. + */ + public void requestFocus() + { + // TODO: Is this 100% ok? + parent.requestFocus(); + } + + /** + * Adds a focus listener to the parent list. List children do not have + * their own focus management. + * + * @param listener the focus listener to add + */ + public void addFocusListener(FocusListener listener) + { + // TODO: Is this 100% ok? + parent.addFocusListener(listener); + } + + /** + * Removes a focus listener from the parent list. List children do not + * have their own focus management. + * + * @param listener the focus listener to remove + */ + public void removeFocusListener(FocusListener listener) + { + // TODO: Is this 100% + parent.removeFocusListener(listener); + } + + /** + * Returns the accessible role of this list item, which is + * {@link AccessibleRole#LABEL}. + * + * @return {@link AccessibleRole#LABEL} + */ + public AccessibleRole getAccessibleRole() + { + return AccessibleRole.LABEL; + } + + /** + * Returns the accessible state set of this list item. + * + * @return the accessible state set of this list item + */ + public AccessibleStateSet getAccessibleStateSet() + { + AccessibleStateSet states = new AccessibleStateSet(); + if (isVisible()) + states.add(AccessibleState.VISIBLE); + if (isShowing()) + states.add(AccessibleState.SHOWING); + if (isFocusTraversable()) + states.add(AccessibleState.FOCUSABLE); + // TODO: How should the active state be handled? The API docs + // suggest that this state is set on the activated list child, + // that is the one that is drawn with a box. However, I don't know how + // to implement this. + + // TODO: We set the selectable state here because list children are + // selectable. Is there a way to disable single children? + if (parent.isEnabled()) + states.add(AccessibleState.SELECTABLE); + + if (parent.isSelectedIndex(listIndex)) + states.add(AccessibleState.SELECTED); + + // TODO: Handle more states here? + return states; + } + + /** + * Returns the index of this list child within it's parent list. + * + * @return the index of this list child within it's parent list + */ + public int getAccessibleIndexInParent() + { + return listIndex; + } + + /** + * Returns <code>0</code> since list children don't have children + * themselves. + * + * @return <code>0</code> + */ + public int getAccessibleChildrenCount() + { + return 0; + } + + /** + * Returns <code>null</code> since list children don't have children + * themselves. + * + * @return <code>null</code> + */ + public Accessible getAccessibleChild(int i) + { + return null; + } + + /** + * Returns the locale of this component. This call is forwarded to the + * parent list since list children don't have a separate locale setting. + * + * @return the locale of this component + */ + public Locale getLocale() + { + return parent.getLocale(); + } + + /** + * This method does + * nothing, list children are transient accessible objects which means + * that they don't fire property change events. + * + * @param l not used here + */ + public void addPropertyChangeListener(PropertyChangeListener l) + { + // Do nothing here. + } + + /** + * This method does + * nothing, list children are transient accessible objects which means + * that they don't fire property change events. + * + * @param l not used here + */ + public void removePropertyChangeListener(PropertyChangeListener l) + { + // Do nothing here. + } + + // TODO: Implement the remaining methods of this class. + } + + /** + * Returns the number of selected accessible children. + * + * @return the number of selected accessible children + */ + public int getAccessibleSelectionCount() + { + return getSelectedIndices().length; + } + + /** + * Returns the n-th selected accessible child. + * + * @param n the index of the selected child to return + * + * @return the n-th selected accessible child + */ + public Accessible getAccessibleSelection(int n) + { + return new AccessibleJListChild(JList.this, getSelectedIndices()[n]); + } + + /** + * Returns <code>true</code> if the n-th child is selected, + * <code>false</code> otherwise. + * + * @param n the index of the child of which the selected state is queried + * + * @return <code>true</code> if the n-th child is selected, + * <code>false</code> otherwise + */ + public boolean isAccessibleChildSelected(int n) + { + return isSelectedIndex(n); + } + + /** + * Adds the accessible item with the specified index to the selected items. + * If multiple selections are supported, the item is added to the selection, + * otherwise the item replaces the current selection. + * + * @param i the index of the item to add to the selection + */ + public void addAccessibleSelection(int i) + { + addSelectionInterval(i, i); + } + + /** + * Removes the accessible item with the specified index to the selection. + * + * @param i the index of the item to be removed from the selection + */ + public void removeAccessibleSelection(int i) + { + removeSelectionInterval(i, i); + } + + /** + * Remove all selection items from the selection. + */ + public void clearAccessibleSelection() + { + clearSelection(); + } + + /** + * Selects all items if multiple selections are supported. + * Otherwise do nothing. + */ + public void selectAllAccessibleSelection() + { + addSelectionInterval(0, getModel().getSize()); + } + + /** + * Receices notification when the list selection is changed. This method + * fires two property change events, the first with + * {@link AccessibleContext#ACCESSIBLE_VISIBLE_DATA_PROPERTY} and the second + * with {@link AccessibleContext#ACCESSIBLE_SELECTION_PROPERTY}. + * + * @param event the list selection event + */ + public void valueChanged(ListSelectionEvent event) + { + firePropertyChange(ACCESSIBLE_VISIBLE_DATA_PROPERTY, Boolean.FALSE, + Boolean.TRUE); + firePropertyChange(ACCESSIBLE_SELECTION_PROPERTY, Boolean.FALSE, + Boolean.TRUE); + } + + /** + * Receives notification when items have changed in the + * <code>JList</code>. This method fires a property change event with + * {@link AccessibleContext#ACCESSIBLE_VISIBLE_DATA_PROPERTY}. + * + * @param event the list data event + */ + public void contentsChanged(ListDataEvent event) + { + firePropertyChange(ACCESSIBLE_VISIBLE_DATA_PROPERTY, Boolean.FALSE, + Boolean.TRUE); + } + + /** + * Receives notification when items are inserted into the + * <code>JList</code>. This method fires a property change event with + * {@link AccessibleContext#ACCESSIBLE_VISIBLE_DATA_PROPERTY}. + * + * @param event the list data event + */ + public void intervalAdded(ListDataEvent event) + { + firePropertyChange(ACCESSIBLE_VISIBLE_DATA_PROPERTY, Boolean.FALSE, + Boolean.TRUE); + } + + /** + * Receives notification when items are removed from the + * <code>JList</code>. This method fires a property change event with + * {@link AccessibleContext#ACCESSIBLE_VISIBLE_DATA_PROPERTY}. + * + * @param event the list data event + */ + public void intervalRemoved(ListDataEvent event) + { + firePropertyChange(ACCESSIBLE_VISIBLE_DATA_PROPERTY, Boolean.FALSE, + Boolean.TRUE); + } + + + /** + * Receives notification about changes of the <code>JList</code>'s + * properties. This is used to re-register this object as listener to + * the data model and selection model when the data model or selection model + * changes. + * + * @param e the property change event + */ + public void propertyChange(PropertyChangeEvent e) + { + String propertyName = e.getPropertyName(); + if (propertyName.equals("model")) + { + ListModel oldModel = (ListModel) e.getOldValue(); + oldModel.removeListDataListener(this); + ListModel newModel = (ListModel) e.getNewValue(); + newModel.addListDataListener(this); + } + else if (propertyName.equals("selectionModel")) + { + ListSelectionModel oldModel = (ListSelectionModel) e.getOldValue(); + oldModel.removeListSelectionListener(this); + ListSelectionModel newModel = (ListSelectionModel) e.getNewValue(); + oldModel.addListSelectionListener(this); + } + } + + /** + * Return the state set of the <code>JList</code>. + * + * @return the state set of the <code>JList</code> + */ + public AccessibleStateSet getAccessibleStateSet() + { + // TODO: Figure out if there is possibly more state that must be + // handled here. + AccessibleStateSet s = super.getAccessibleStateSet(); + if (getSelectionMode() != ListSelectionModel.SINGLE_SELECTION) + s.add(AccessibleState.MULTISELECTABLE); + return s; + } + + /** + * Returns the accessible role for <code>JList</code>, + * {@link AccessibleRole#LIST}. + * + * @return the accessible role for <code>JList</code> + */ + public AccessibleRole getAccessibleRole() + { + return AccessibleRole.LIST; + } + + /** + * Returns the accessible child at the visual location <code>p</code> + * (relative to the upper left corner of the <code>JList</code>). If there + * is no child at that location, this returns <code>null</code>. + * + * @param p the screen location for which to return the accessible child + * + * @return the accessible child at the specified location, or + * <code>null</code> if there is no child at that location + */ + public Accessible getAccessibleAt(Point p) + { + int childIndex = locationToIndex(p); + return getAccessibleChild(childIndex); + } + + /** + * Returns the number of accessible children in the <code>JList</code>. + * + * @return the number of accessible children in the <code>JList</code> + */ + public int getAccessibleChildrenCount() + { + return getModel().getSize(); + } + + /** + * Returns the n-th accessible child of this <code>JList</code>. This will + * be an instance of {@link AccessibleJListChild}. If there is no child + * at that index, <code>null</code> is returned. + * + * @param n the index of the child to return + * + * @return the n-th accessible child of this <code>JList</code> + */ + public Accessible getAccessibleChild(int n) + { + if (getModel().getSize() <= n) + return null; + return new AccessibleJListChild(JList.this, n); + } + } + private static final long serialVersionUID = 4406629526391098046L; /** diff --git a/javax/swing/JOptionPane.java b/javax/swing/JOptionPane.java index ad0772ab8..54e6abc0e 100644 --- a/javax/swing/JOptionPane.java +++ b/javax/swing/JOptionPane.java @@ -1,5 +1,5 @@ /* JOptionPane.java - Copyright (C) 2004 Free Software Foundation, Inc. + Copyright (C) 2004, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -858,13 +858,15 @@ public class JOptionPane extends JComponent implements Accessible */ public static int showConfirmDialog(Component parentComponent, Object message) { - JOptionPane pane = new JOptionPane(message); + JOptionPane pane = new JOptionPane(message, QUESTION_MESSAGE); JDialog dialog = pane.createDialog(parentComponent, "Select an Option"); dialog.pack(); dialog.show(); - - return ((Integer) pane.getValue()).intValue(); + + if (pane.getValue() instanceof Integer) + return ((Integer) pane.getValue()).intValue(); + return -1; } /** @@ -889,7 +891,9 @@ public class JOptionPane extends JComponent implements Accessible dialog.pack(); dialog.show(); - return ((Integer) pane.getValue()).intValue(); + if (pane.getValue() instanceof Integer) + return ((Integer) pane.getValue()).intValue(); + return -1; } /** @@ -915,7 +919,9 @@ public class JOptionPane extends JComponent implements Accessible dialog.pack(); dialog.show(); - return ((Integer) pane.getValue()).intValue(); + if (pane.getValue() instanceof Integer) + return ((Integer) pane.getValue()).intValue(); + return -1; } /** @@ -943,7 +949,9 @@ public class JOptionPane extends JComponent implements Accessible dialog.pack(); dialog.show(); - return ((Integer) pane.getValue()).intValue(); + if (pane.getValue() instanceof Integer) + return ((Integer) pane.getValue()).intValue(); + return -1; } /** diff --git a/javax/swing/JPopupMenu.java b/javax/swing/JPopupMenu.java index c4ee5fe73..18da20afa 100644 --- a/javax/swing/JPopupMenu.java +++ b/javax/swing/JPopupMenu.java @@ -556,58 +556,72 @@ public class JPopupMenu extends JComponent implements Accessible, MenuElement this.visible = visible; if (old != isVisible()) { - firePropertyChange("visible", old, isVisible()); - if (visible) - { - firePopupMenuWillBecomeVisible(); - Container rootContainer = (Container) SwingUtilities.getRoot(invoker); - - boolean fit = true; - Dimension size; - - // Determine the size of the popup menu - if (this.getSize().width == 0 && this.getSize().width == 0) - size = this.getPreferredSize(); - else - size = this.getSize(); - - if ((size.width > (rootContainer.getWidth() - popupLocation.x)) - || (size.height > (rootContainer.getHeight() - popupLocation.y))) - fit = false; - if (lightWeightPopupEnabled && fit) - popup = new LightWeightPopup(this); - else - { - if (fit) - popup = new MediumWeightPopup(this); - else - popup = new HeavyWeightPopup(this); - } - if (popup instanceof LightWeightPopup - || popup instanceof MediumWeightPopup) - { - JLayeredPane layeredPane; - layeredPane = SwingUtilities.getRootPane(invoker) - .getLayeredPane(); - Point p = new Point(popupLocation.x, popupLocation.y); - SwingUtilities.convertPointFromScreen(p, layeredPane); - popup.show(p.x, p.y, size.width, size.height); - } - else - { - // Subtract insets of the top-level container if popup menu's - // top-left corner is inside it. - Insets insets = rootContainer.getInsets(); - popup.show(popupLocation.x - insets.left, - popupLocation.y - insets.top, size.width, - size.height); - } - } - else - { - firePopupMenuWillBecomeInvisible(); - popup.hide(); - } + firePropertyChange("visible", old, isVisible()); + if (visible) + { + firePopupMenuWillBecomeVisible(); + Container rootContainer = (Container) SwingUtilities.getRoot(invoker); + Dimension screenSize = getToolkit().getScreenSize(); + + boolean fit = true; + Dimension size; + + // Determine the size of the popup menu + if (this.getSize().width == 0 && this.getSize().width == 0) + size = this.getPreferredSize(); + else + size = this.getSize(); + + if ((size.width > (rootContainer.getWidth() - popupLocation.x)) + || (size.height > (rootContainer.getHeight() - popupLocation.y))) + fit = false; + if (lightWeightPopupEnabled && fit) + popup = new LightWeightPopup(this); + else + { + if (fit) + popup = new MediumWeightPopup(this); + else + popup = new HeavyWeightPopup(this); + } + if (popup instanceof LightWeightPopup + || popup instanceof MediumWeightPopup) + { + JLayeredPane layeredPane; + layeredPane = SwingUtilities.getRootPane(invoker).getLayeredPane(); + Point p = new Point(popupLocation.x, popupLocation.y); + + if (layeredPane.isShowing()) + SwingUtilities.convertPointFromScreen(p, layeredPane); + + if (size.width + popupLocation.x > screenSize.width) + popupLocation.x -= size.width; + if (size.height + popupLocation.y > screenSize.height) + popupLocation.y -= size.height; + + popup.show(p.x, p.y, size.width, size.height); + } + else + { + // Subtract insets of the top-level container if popup menu's + // top-left corner is inside it. + Insets insets = rootContainer.getInsets(); + + if (size.width + popupLocation.x > screenSize.width) + popupLocation.x -= size.width; + if (size.height + popupLocation.y > screenSize.height) + popupLocation.y -= size.height; + + popup.show(popupLocation.x - insets.left, + popupLocation.y - insets.top, + size.width, size.height); + } + } + else + { + firePopupMenuWillBecomeInvisible(); + popup.hide(); + } } } @@ -657,11 +671,14 @@ public class JPopupMenu extends JComponent implements Accessible, MenuElement */ public void show(Component component, int x, int y) { - setInvoker(component); - Point p = new Point(x, y); - SwingUtilities.convertPointToScreen(p, component); - setLocation(p.x, p.y); - setVisible(true); + if (component.isShowing()) + { + setInvoker(component); + Point p = new Point(x, y); + SwingUtilities.convertPointToScreen(p, component); + setLocation(p.x, p.y); + setVisible(true); + } } /** @@ -1004,7 +1021,7 @@ public class JPopupMenu extends JComponent implements Accessible, MenuElement * HeavyWeightPopup is JWindow that is used to display JPopupMenu menu item's * on the screen */ - private class HeavyWeightPopup extends JWindow implements Popup + private class HeavyWeightPopup extends JDialog implements Popup { /** * Creates a new HeavyWeightPopup object. @@ -1014,6 +1031,8 @@ public class JPopupMenu extends JComponent implements Accessible, MenuElement public HeavyWeightPopup(Container c) { this.setContentPane(c); + this.setUndecorated(true); + this.getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG); } /** diff --git a/javax/swing/JProgressBar.java b/javax/swing/JProgressBar.java index 1b8fcea46..19815dbfd 100644 --- a/javax/swing/JProgressBar.java +++ b/javax/swing/JProgressBar.java @@ -243,7 +243,7 @@ public class JProgressBar extends JComponent implements SwingConstants, model = new DefaultBoundedRangeModel(minimum, 0, minimum, maximum); if (orientation != HORIZONTAL && orientation != VERTICAL) throw new IllegalArgumentException(orientation + " is not a legal orientation"); - this.orientation = orientation; + setOrientation(orientation); changeListener = createChangeListener(); model.addChangeListener(changeListener); updateUI(); diff --git a/javax/swing/JRootPane.java b/javax/swing/JRootPane.java index bb993bc3f..500083612 100644 --- a/javax/swing/JRootPane.java +++ b/javax/swing/JRootPane.java @@ -42,6 +42,7 @@ import java.awt.BorderLayout; import java.awt.Component; import java.awt.Container; import java.awt.Dimension; +import java.awt.IllegalComponentStateException; import java.awt.LayoutManager; import java.awt.LayoutManager2; import java.io.Serializable; @@ -163,9 +164,17 @@ public class JRootPane extends JComponent implements Accessible public void layoutContainer(Container c) { Dimension menuBarSize; - Dimension containerSize = c.getSize(null); + int containerWidth = c.getBounds().width - getInsets().left + - getInsets().right; + int containerHeight = c.getBounds().height - getInsets().top + - getInsets().bottom; Dimension contentPaneSize = contentPane.getPreferredSize(); + // 1. the glassPane fills entire viewable region (bounds - insets). + // 2. the layeredPane filles entire viewable region. + // 3. the menuBar is positioned at the upper edge of layeredPane. + // 4. the contentPane fills viewable region minus menuBar, if present. + /* if size of top-level window wasn't set then just set contentPane and menuBar to its preferred sizes. @@ -188,7 +197,7 @@ public class JRootPane extends JComponent implements Accessible +-------------------------------+ */ - if (containerSize.width == 0 && containerSize.height == 0) + if (containerWidth == 0 && containerHeight == 0) { if (menuBar != null) { @@ -196,12 +205,12 @@ public class JRootPane extends JComponent implements Accessible menuBarSize = menuBar.getPreferredSize(); maxWidth = Math.max(menuBarSize.width, contentPaneSize.width); menuBar.setBounds(0, 0, maxWidth, menuBarSize.height); - glassPane.setBounds(0, menuBarSize.height, maxWidth, - contentPaneSize.height); + glassPane.setBounds(0, 0, maxWidth, menuBarSize.height + + contentPaneSize.height); contentPane.setBounds(0, menuBarSize.height, maxWidth, contentPaneSize.height); - layeredPane.setSize(maxWidth, - menuBarSize.height + contentPaneSize.height); + layeredPane.setBounds(0, 0, maxWidth, menuBarSize.height + + contentPaneSize.height); } else { @@ -209,7 +218,8 @@ public class JRootPane extends JComponent implements Accessible contentPaneSize.height); contentPane.setBounds(0, 0, contentPaneSize.width, contentPaneSize.height); - layeredPane.setSize(contentPaneSize.width, contentPaneSize.height); + layeredPane.setBounds(0, 0, contentPaneSize.width, + contentPaneSize.height); } } else @@ -217,25 +227,19 @@ public class JRootPane extends JComponent implements Accessible if (menuBar != null) { menuBarSize = menuBar.getPreferredSize(); - if (menuBarSize.height > containerSize.height) - menuBarSize.height = containerSize.height; - menuBar.setBounds(0, 0, containerSize.width, menuBarSize.height); - int remainingHeight = containerSize.height - menuBarSize.height; - glassPane.setBounds(0, menuBarSize.height, containerSize.width, - containerSize.height - menuBarSize.height); - contentPane.setBounds(0, menuBarSize.height, - containerSize.width, - (containerSize.height - menuBarSize.height)); + if (menuBarSize.height > containerHeight) + menuBarSize.height = containerHeight; + menuBar.setBounds(0, 0, containerWidth, menuBarSize.height); + glassPane.setBounds(0, 0, containerWidth, containerHeight); + contentPane.setBounds(0, menuBarSize.height, containerWidth, + (containerHeight - menuBarSize.height)); } else { - glassPane.setBounds(0, 0, containerSize.width, - containerSize.height); - contentPane.setBounds(0, 0, containerSize.width, - containerSize.height); + glassPane.setBounds(0, 0, containerWidth, containerHeight); + contentPane.setBounds(0, 0, containerWidth, containerHeight); } - - layeredPane.setSize(containerSize.width, containerSize.height); + layeredPane.setBounds(0, 0, containerWidth, containerHeight); } } @@ -404,14 +408,25 @@ public class JRootPane extends JComponent implements Accessible } /** - * DOCUMENT ME! + * Sets the JRootPane's content pane. The content pane should typically be + * opaque for painting to work properly. This method also + * removes the old content pane from the layered pane. * - * @param p DOCUMENT ME! + * @param p the Container that will be the content pane + * @throws IllegalComponentStateException if p is null */ public void setContentPane(Container p) { - contentPane = p; - getLayeredPane().add(contentPane, JLayeredPane.FRAME_CONTENT_LAYER); + if (p == null) + throw new IllegalComponentStateException ("cannot " + + "have a null content pane"); + else + { + if (contentPane != null && contentPane.getParent() == layeredPane) + layeredPane.remove(contentPane); + contentPane = p; + getLayeredPane().add(contentPane, JLayeredPane.FRAME_CONTENT_LAYER); + } } /** @@ -525,7 +540,6 @@ public class JRootPane extends JComponent implements Accessible { JPanel p = new JPanel(); p.setName(this.getName() + ".glassPane"); - p.setLayout(new BorderLayout()); p.setVisible(false); p.setOpaque(false); return p; @@ -616,7 +630,8 @@ public class JRootPane extends JComponent implements Accessible && style != COLOR_CHOOSER_DIALOG && style != FILE_CHOOSER_DIALOG && style != QUESTION_DIALOG - && style != WARNING_DIALOG) + && style != WARNING_DIALOG + && style != PLAIN_DIALOG) throw new IllegalArgumentException("invalid style"); int oldStyle = windowDecorationStyle; diff --git a/javax/swing/JScrollPane.java b/javax/swing/JScrollPane.java index e83513f07..42d8ea76f 100644 --- a/javax/swing/JScrollPane.java +++ b/javax/swing/JScrollPane.java @@ -228,10 +228,10 @@ public class JScrollPane remove(c); } - private void addNonNull(Component c) + private void addNonNull(Component c, Object constraints) { if (c != null) - add(c); + add(c, constraints); } public void setComponentOrientation(ComponentOrientation co) @@ -250,7 +250,7 @@ public class JScrollPane JViewport old = columnHeader; removeNonNull(old); columnHeader = h; - addNonNull(h); + addNonNull(h, JScrollPane.COLUMN_HEADER); firePropertyChange("columnHeader", old, h); sync(); } @@ -294,25 +294,25 @@ public class JScrollPane { removeNonNull(lowerRight); lowerRight = c; - addNonNull(c); + addNonNull(c, JScrollPane.LOWER_RIGHT_CORNER); } else if (key == UPPER_RIGHT_CORNER) { removeNonNull(upperRight); upperRight = c; - addNonNull(c); + addNonNull(c, JScrollPane.UPPER_RIGHT_CORNER); } else if (key == LOWER_LEFT_CORNER) { removeNonNull(lowerLeft); lowerLeft = c; - addNonNull(c); + addNonNull(c, JScrollPane.LOWER_LEFT_CORNER); } else if (key == UPPER_LEFT_CORNER) { removeNonNull(upperLeft); upperLeft = c; - addNonNull(c); + addNonNull(c, JScrollPane.UPPER_LEFT_CORNER); } else throw new IllegalArgumentException("unknown corner " + key); @@ -327,7 +327,7 @@ public class JScrollPane JScrollBar old = horizontalScrollBar; removeNonNull(old); horizontalScrollBar = h; - addNonNull(h); + addNonNull(h, JScrollPane.HORIZONTAL_SCROLLBAR); firePropertyChange("horizontalScrollBar", old, h); sync(); @@ -379,7 +379,7 @@ public class JScrollPane JViewport old = rowHeader; removeNonNull(old); rowHeader = v; - addNonNull(v); + addNonNull(v, JScrollPane.ROW_HEADER); firePropertyChange("rowHeader", old, v); sync(); } @@ -400,7 +400,7 @@ public class JScrollPane JScrollBar old = verticalScrollBar; removeNonNull(old); verticalScrollBar = v; - addNonNull(v); + addNonNull(v, JScrollPane.VERTICAL_SCROLLBAR); firePropertyChange("verticalScrollBar", old, v); sync(); @@ -457,7 +457,7 @@ public class JScrollPane viewport = v; if (v != null) v.addChangeListener(scrollListener); - addNonNull(v); + addNonNull(v, JScrollPane.VIEWPORT); revalidate(); repaint(); firePropertyChange("viewport", old, v); diff --git a/javax/swing/JTabbedPane.java b/javax/swing/JTabbedPane.java index 828a69a24..77e49cba5 100644 --- a/javax/swing/JTabbedPane.java +++ b/javax/swing/JTabbedPane.java @@ -56,8 +56,9 @@ import javax.swing.plaf.TabbedPaneUI; import javax.swing.plaf.UIResource; /** - * This is a container for components. One component is displayed at a time. - * Users can switch between components by clicking on tabs. + * This is a container for components where only one component is displayed at + * a given time and the displayed component can be switched by clicking on + * tabs. * * <p> * Tabs can be oriented in several ways. They can be above, below, left and @@ -72,12 +73,14 @@ public class JTabbedPane extends JComponent implements Serializable, SwingConstants { /** - * DOCUMENT ME! + * Accessibility support for <code>JTabbedPane</code>. */ protected class AccessibleJTabbedPane extends JComponent.AccessibleJComponent implements AccessibleSelection, ChangeListener { - /** DOCUMENT ME! */ + /** + * The serialization UID. + */ private static final long serialVersionUID = 7610530885966830483L; /** @@ -89,18 +92,20 @@ public class JTabbedPane extends JComponent implements Serializable, } /** - * DOCUMENT ME! + * Receives notification when the selection state of the + * <code>JTabbedPane</code> changes. * - * @param e DOCUMENT ME! + * @param e the change event describing the change */ public void stateChanged(ChangeEvent e) { } /** - * DOCUMENT ME! + * Returns the accessible role of the <code>JTabbedPane</code>, which is + * {@link AccessibleRole#PAGE_TAB_LIST}. * - * @return DOCUMENT ME! + * @return the accessible role of the <code>JTabbedPane</code> */ public AccessibleRole getAccessibleRole() { @@ -108,9 +113,11 @@ public class JTabbedPane extends JComponent implements Serializable, } /** - * DOCUMENT ME! + * Returns the number of accessible child components of the + * <code>JTabbedPane</code>. * - * @return DOCUMENT ME! + * @return the number of accessible child components of the + * <code>JTabbedPane</code> */ public int getAccessibleChildrenCount() { @@ -118,11 +125,11 @@ public class JTabbedPane extends JComponent implements Serializable, } /** - * DOCUMENT ME! + * Returns the accessible child component at the specified index. * - * @param i DOCUMENT ME! + * @param i the index of the child component to fetch * - * @return DOCUMENT ME! + * @return the accessible child component at the specified index */ public Accessible getAccessibleChild(int i) { @@ -130,9 +137,10 @@ public class JTabbedPane extends JComponent implements Serializable, } /** - * DOCUMENT ME! + * Returns the current selection state of the <code>JTabbedPane</code> + * as AccessibleSelection object. * - * @return DOCUMENT ME! + * @return the current selection state of the <code>JTabbedPane</code> */ public AccessibleSelection getAccessibleSelection() { @@ -140,11 +148,15 @@ public class JTabbedPane extends JComponent implements Serializable, } /** - * DOCUMENT ME! + * Returns the accessible child component at the specified coordinates. + * If there is no child component at this location, then return the + * currently selected tab. * - * @param p DOCUMENT ME! + * @param p the coordinates at which to look up the child component * - * @return DOCUMENT ME! + * @return the accessible child component at the specified coordinates or + * the currently selected tab if there is no child component at + * this location */ public Accessible getAccessibleAt(Point p) { @@ -152,9 +164,13 @@ public class JTabbedPane extends JComponent implements Serializable, } /** - * DOCUMENT ME! + * The number of selected child components of the + * <code>JTabbedPane</code>. This will be <code>0</code> if the + * <code>JTabbedPane</code> has no children, or <code>1</code> otherwise, + * since there is always exactly one tab selected. * - * @return DOCUMENT ME! + * @return number of selected child components of the + * <code>JTabbedPane</code> */ public int getAccessibleSelectionCount() { @@ -863,15 +879,17 @@ public class JTabbedPane extends JComponent implements Serializable, * This method inserts tabs into JTabbedPane. This includes adding the * component to the JTabbedPane and hiding it. * - * @param title The title of the tab. - * @param icon The tab's icon. - * @param component The component associated with the tab. - * @param tip The tooltip for the tab. - * @param index The index to insert the tab at. + * @param title the title of the tab; may be <code>null</code> + * @param icon the tab's icon; may be <code>null</code> + * @param component the component associated with the tab + * @param tip the tooltip for the tab + * @param index the index to insert the tab at */ public void insertTab(String title, Icon icon, Component component, String tip, int index) { + if (title == null) + title = ""; Page p = new Page(title, icon, component, tip); tabs.insertElementAt(p, index); @@ -893,10 +911,10 @@ public class JTabbedPane extends JComponent implements Serializable, /** * This method adds a tab to the JTabbedPane. * - * @param title The title of the tab. - * @param icon The icon for the tab. - * @param component The associated component. - * @param tip The associated tooltip. + * @param title the title of the tab; may be <code>null</code> + * @param icon the icon for the tab; may be <code>null</code> + * @param component the associated component + * @param tip the associated tooltip */ public void addTab(String title, Icon icon, Component component, String tip) { @@ -906,9 +924,9 @@ public class JTabbedPane extends JComponent implements Serializable, /** * This method adds a tab to the JTabbedPane. * - * @param title The title of the tab. - * @param icon The icon for the tab. - * @param component The associated component. + * @param title the title of the tab; may be <code>null</code> + * @param icon the icon for the tab; may be <code>null</code> + * @param component the associated component */ public void addTab(String title, Icon icon, Component component) { @@ -918,8 +936,8 @@ public class JTabbedPane extends JComponent implements Serializable, /** * This method adds a tab to the JTabbedPane. * - * @param title The title of the tab. - * @param component The associated component. + * @param title the title of the tab; may be <code>null</code> + * @param component the associated component */ public void addTab(String title, Component component) { @@ -950,8 +968,8 @@ public class JTabbedPane extends JComponent implements Serializable, * 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. + * @param title the title of the tab; may be <code>null</code> + * @param component the associated component * * @return The Component that was added. */ diff --git a/javax/swing/JTable.java b/javax/swing/JTable.java index 21680d567..531838ab1 100644 --- a/javax/swing/JTable.java +++ b/javax/swing/JTable.java @@ -47,6 +47,8 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; import java.text.DateFormat; import java.text.NumberFormat; import java.util.Date; @@ -80,6 +82,33 @@ public class JTable extends JComponent implements TableModelListener, Scrollable, TableColumnModelListener, ListSelectionListener, CellEditorListener, Accessible { + /** + * Handles property changes from the <code>TableColumn</code>s of this + * <code>JTable</code>. + * + * More specifically, this triggers a {@link #revalidate} call if the + * preferredWidth of one of the observed columns changes. + */ + class TableColumnPropertyChangeHandler implements PropertyChangeListener + { + /** + * Receives notification that a property of the observed TableColumns + * has changed. + * + * @param ev the property change event + */ + public void propertyChange(PropertyChangeEvent ev) + { + if (ev.getPropertyName().equals("preferredWidth")) + { + JTableHeader header = getTableHeader(); + TableColumn col = (TableColumn) ev.getSource(); + header.setResizingColumn(col); + doLayout(); + header.setResizingColumn(null); + } + } + } /** * A cell renderer for boolean values. @@ -584,6 +613,12 @@ public class JTable extends JComponent Object oldCellValue; /** + * The property handler for this table's columns. + */ + TableColumnPropertyChangeHandler tableColumnPropertyChangeHandler = + new TableColumnPropertyChangeHandler(); + + /** * Creates a new <code>JTable</code> instance. */ public JTable () @@ -645,8 +680,17 @@ public class JTable extends JComponent { setModel(dm == null ? createDefaultDataModel() : dm); setSelectionModel(sm == null ? createDefaultSelectionModel() : sm); - - this.columnModel = cm; + + if (cm != null) + { + setColumnModel(cm); + setAutoCreateColumnsFromModel(false); + } + else + { + setColumnModel(createDefaultColumnModel()); + setAutoCreateColumnsFromModel(true); + } initializeLocalVars(); // The next two lines are for compliance with the JDK which starts // the JLists associated with a JTable with both lead selection @@ -659,12 +703,8 @@ public class JTable extends JComponent protected void initializeLocalVars() { setTableHeader(createDefaultTableHeader()); - this.autoCreateColumnsFromModel = false; - if (columnModel == null) - { - this.autoCreateColumnsFromModel = true; - createColumnsFromModel(); - } + if (autoCreateColumnsFromModel) + createDefaultColumnsFromModel(); this.columnModel.addColumnModelListener(this); this.defaultRenderersByColumnClass = new Hashtable(); @@ -754,6 +794,7 @@ public class JTable extends JComponent } columnModel.addColumn(column); + column.addPropertyChangeListener(tableColumnPropertyChangeHandler); } protected void createDefaultEditors() @@ -799,20 +840,6 @@ public class JTable extends JComponent return new JTableHeader(columnModel); } - 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) @@ -890,7 +917,7 @@ public class JTable extends JComponent if ((event.getFirstRow() ==TableModelEvent.HEADER_ROW) && autoCreateColumnsFromModel) - createColumnsFromModel(); + createDefaultColumnsFromModel(); repaint(); } @@ -990,10 +1017,7 @@ public class JTable extends JComponent int y = (height + y_gap) * row; for (int i = 0; i < column; ++i) - { - x += columnModel.getColumn(i).getWidth(); - x += x_gap; - } + x += columnModel.getColumn(i).getWidth(); if (includeSpacing) return new Rectangle(x, y, width, height); @@ -1663,15 +1687,15 @@ public class JTable extends JComponent if (m != null) { - // Set property. + // Set property. dataModel = m; - // Add table as TableModelListener to new model. - dataModel.addTableModelListener(this); + // Add table as TableModelListener to new model. + dataModel.addTableModelListener(this); - // Automatically create columns. - if (autoCreateColumnsFromModel) - createColumnsFromModel(); + // Automatically create columns. + if (autoCreateColumnsFromModel) + createDefaultColumnsFromModel(); } // Repaint table. @@ -2023,6 +2047,8 @@ public class JTable extends JComponent case AUTO_RESIZE_OFF: default: + int prefWidth = resizingColumn.getPreferredWidth(); + resizingColumn.setWidth(prefWidth); } } else @@ -2258,6 +2284,8 @@ public class JTable extends JComponent */ public void createDefaultColumnsFromModel() { + assert columnModel != null : "The columnModel must not be null."; + // remove existing columns int columnIndex = columnModel.getColumnCount() - 1; while (columnIndex >= 0) @@ -2272,7 +2300,9 @@ public class JTable extends JComponent { TableColumn column = new TableColumn(c); column.setIdentifier(dataModel.getColumnName(c)); + column.setHeaderValue(dataModel.getColumnName(c)); columnModel.addColumn(column); + column.addPropertyChangeListener(tableColumnPropertyChangeHandler); } } diff --git a/javax/swing/JTextArea.java b/javax/swing/JTextArea.java index 53591ffcc..e2157bcc6 100644 --- a/javax/swing/JTextArea.java +++ b/javax/swing/JTextArea.java @@ -208,6 +208,8 @@ public class JTextArea extends JTextComponent /* This shouldn't happen in theory -- but, if it does... */ throw new RuntimeException("Unexpected exception occurred.", exception); } + if (toAppend != null && toAppend.length() > 0) + revalidate(); } /** @@ -312,8 +314,12 @@ public class JTextArea extends JTextComponent { if (columns < 0) throw new IllegalArgumentException(); - - this.columns = columns; + + if (columns != this.columns) + { + this.columns = columns; + revalidate(); + } } /** @@ -337,8 +343,12 @@ public class JTextArea extends JTextComponent { if (rows < 0) throw new IllegalArgumentException(); - - this.rows = rows; + + if (rows != this.rows) + { + this.rows = rows; + revalidate(); + } } /** diff --git a/javax/swing/JTree.java b/javax/swing/JTree.java index bb24c7a45..15271bba4 100644 --- a/javax/swing/JTree.java +++ b/javax/swing/JTree.java @@ -37,16 +37,32 @@ exception statement from your version. */ package javax.swing; +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.awt.event.FocusListener; +import java.beans.PropertyChangeListener; import java.io.Serializable; import java.util.Enumeration; import java.util.Hashtable; import java.util.Iterator; +import java.util.Locale; import java.util.Vector; import javax.accessibility.Accessible; +import javax.accessibility.AccessibleAction; +import javax.accessibility.AccessibleComponent; import javax.accessibility.AccessibleContext; +import javax.accessibility.AccessibleRole; +import javax.accessibility.AccessibleSelection; +import javax.accessibility.AccessibleState; +import javax.accessibility.AccessibleStateSet; +import javax.accessibility.AccessibleText; +import javax.accessibility.AccessibleValue; import javax.swing.event.TreeExpansionEvent; import javax.swing.event.TreeExpansionListener; import javax.swing.event.TreeModelEvent; @@ -72,517 +88,1549 @@ public class JTree extends JComponent implements Scrollable, Accessible { - /** - * Listens to the model of the JTree and updates the property - * <code>expandedState</code> if nodes are removed or changed. - */ - protected class TreeModelHandler - implements - TreeModelListener - { - - /** - * Creates a new instance of TreeModelHandler. - */ - protected TreeModelHandler() - { - } - - /** - * Notifies when a node has changed in some ways. This does not include - * that a node has changed its location or changed it's children. It - * only means that some attributes of the node have changed that might - * affect its presentation. - * - * This method is called after the actual change occured. - * - * @param ev the TreeModelEvent describing the change - */ - public void treeNodesChanged(TreeModelEvent ev) - { - // nothing to do here - } - - /** - * Notifies when a node is inserted into the tree. - * - * This method is called after the actual change occured. - * - * @param ev the TreeModelEvent describing the change - */ - public void treeNodesInserted(TreeModelEvent ev) - { - // nothing to do here - } - - /** - * Notifies when a node is removed from the tree. - * - * This method is called after the actual change occured. - * - * @param ev the TreeModelEvent describing the change - */ - public void treeNodesRemoved(TreeModelEvent ev) - { - // TODO: The API docs suggest that this method should do something - // but I cannot really see what has to be done here ... - } - - /** - * Notifies when the structure of the tree is changed. - * - * This method is called after the actual change occured. - * - * @param ev the TreeModelEvent describing the change - */ - public void treeStructureChanged(TreeModelEvent ev) - { - // set state of new path - TreePath path = ev.getTreePath(); - setExpandedState(path, isExpanded(path)); - } - } // TreeModelHandler - - /** - * This redirects TreeSelectionEvents and rewrites the source of it to be - * this JTree. This is typically done when the tree model generates an - * event, but the JTree object associated with that model should be listed - * as the actual source of the event. - */ - protected class TreeSelectionRedirector - implements - TreeSelectionListener, - Serializable - { - /** The serial version UID. */ - private static final long serialVersionUID = -3505069663646241664L; - - /** - * Creates a new instance of TreeSelectionRedirector - */ - protected TreeSelectionRedirector() - { - } - - /** - * Notifies when the tree selection changes. - * - * @param ev the TreeSelectionEvent that describes the change - */ - public void valueChanged(TreeSelectionEvent ev) - { - TreeSelectionEvent rewritten = (TreeSelectionEvent) ev - .cloneWithSource(JTree.this); - fireValueChanged(rewritten); - JTree.this.repaint(); - } - } // TreeSelectionRedirector - - /** - * A TreeModel that does not allow anything to be selected. + + /** + * This class implements accessibility support for the JTree class. It + * provides an implementation of the Java Accessibility API appropriate + * to tree user-interface elements. + */ + protected class AccessibleJTree extends JComponent.AccessibleJComponent + implements AccessibleSelection, TreeSelectionListener, TreeModelListener, + TreeExpansionListener + { + + /** + * This class implements accessibility support for the JTree child. It provides + * an implementation of the Java Accessibility API appropriate to tree nodes. + */ + protected class AccessibleJTreeNode extends AccessibleContext + implements Accessible, AccessibleComponent, AccessibleSelection, + AccessibleAction + { + + private JTree tree; + private TreePath tp; + private Accessible acc; + private AccessibleStateSet states; + private Vector selectionList; + private Vector actionList; + private TreeModel mod; + private Cursor cursor; + + /** + * Constructs an AccessibleJTreeNode + * + * @param t - the current tree + * @param p - the current path to be dealt with + * @param ap - the accessible object to use + */ + public AccessibleJTreeNode(JTree t, TreePath p, Accessible ap) + { + states = new AccessibleStateSet(); + selectionList = new Vector(); + actionList = new Vector(); + mod = tree.getModel(); + cursor = JTree.this.getCursor(); + + tree = t; + tp = p; + acc = ap; + + // Add all the children of this path that may already be + // selected to the selection list. + TreePath[] selected = tree.getSelectionPaths(); + for (int i = 0; i < selected.length; i++) + { + TreePath sel = selected[i]; + if ((sel.getParentPath()).equals(tp)) + selectionList.add(sel); + } + + // Add all the actions available for a node to + // the action list. + actionList.add("EXPAND"); + actionList.add("COLLAPSE"); + actionList.add("EDIT"); + actionList.add("SELECT"); + actionList.add("DESELECT"); + } + + /** + * Adds the specified selected item in the object to the object's + * selection. + * + * @param i - the i-th child of this node. + */ + public void addAccessibleSelection(int i) + { + if (mod != null) + { + Object child = mod.getChild(tp.getLastPathComponent(), i); + if (child != null) + { + if (!states.contains(AccessibleState.MULTISELECTABLE)) + clearAccessibleSelection(); + selectionList.add(child); + tree.addSelectionPath(tp.pathByAddingChild(child)); + } + } + } + + /** + * Adds the specified focus listener to receive focus events + * from this component. + * + * @param l - the new focus listener + */ + public void addFocusListener(FocusListener l) + { + tree.addFocusListener(l); + } + + /** + * Add a PropertyChangeListener to the listener list. + * + * @param l - the new property change listener + */ + public void addPropertyChangeListener(PropertyChangeListener l) + { + // Nothing to do here. + } + + /** + * Clears the selection in the object, so that nothing in the + * object is selected. + */ + public void clearAccessibleSelection() + { + selectionList.clear(); + } + + /** + * Checks whether the specified point is within this object's + * bounds, where the point's x and y coordinates are defined to be + * relative to the coordinate system of the object. + * + * @param p - the point to check + * @return true if p is in the bounds + */ + public boolean contains(Point p) + { + return getBounds().contains(p); + } + + /** + * Perform the specified Action on the tree node. + * + * @param i - the i-th action to perform + * @return true if the the action was performed; else false. + */ + public boolean doAccessibleAction(int i) + { + if (i >= actionList.size() || i < 0) + return false; + + if (actionList.get(i).equals("EXPAND")) + tree.expandPath(tp); + else if (actionList.get(i).equals("COLLAPSE")) + tree.collapsePath(tp); + else if (actionList.get(i).equals("SELECT")) + tree.addSelectionPath(tp); + else if (actionList.get(i).equals("DESELECT")) + tree.removeSelectionPath(tp); + else if (actionList.get(i).equals("EDIT")) + tree.startEditingAtPath(tp); + else + return false; + return true; + } + + /** + * Get the AccessibleAction associated with this object. + * + * @return the action + */ + public AccessibleAction getAccessibleAction() + { + return this; + } + + /** + * Returns the number of accessible actions available in this tree node. + * + * @return the number of actions + */ + public int getAccessibleActionCount() + { + return actionList.size(); + } + + /** + * Return a description of the specified action of the tree node. + * + * @param i - the i-th action's description + * @return a description of the action + */ + public String getAccessibleActionDescription(int i) + { + if (i < 0 || i >= actionList.size()) + return (actionList.get(i)).toString(); + return super.getAccessibleDescription(); + } + + /** + * Returns the Accessible child, if one exists, contained at the + * local coordinate Point. + * + * @param p - the point of the accessible + * @return the accessible at point p if it exists + */ + public Accessible getAccessibleAt(Point p) + { + TreePath acc = tree.getClosestPathForLocation(p.x, p.y); + if (acc != null) + return new AccessibleJTreeNode(tree, acc, this); + return null; + } + + /** + * Return the specified Accessible child of the object. + * + * @param i - the i-th child of the current path + * @return the child if it exists + */ + public Accessible getAccessibleChild(int i) + { + if (mod != null) + { + Object child = mod.getChild(tp.getLastPathComponent(), i); + if (child != null) + return new AccessibleJTreeNode(tree, tp.pathByAddingChild(child), + acc); + } + return null; + } + + /** + * Returns the number of accessible children in the object. + * + * @return the number of children the current node has + */ + public int getAccessibleChildrenCount() + { + TreeModel mod = getModel(); + if (mod != null) + return mod.getChildCount(tp.getLastPathComponent()); + return 0; + } + + /** + * Get the AccessibleComponent associated with this object. + * + * @return the accessible component if it is supported. + */ + public AccessibleComponent getAccessibleComponent() + { + return this; + } + + /** + * Get the AccessibleContext associated with this tree node. + * + * @return an instance of this class + */ + public AccessibleContext getAccessibleContext() + { + return this; + } + + /** + * Get the accessible description of this object. + * + * @return the accessible description + */ + public String getAccessibleDescription() + { + return super.getAccessibleDescription(); + } + + /** + * Get the index of this object in its accessible parent. + * + * @return the index of this in the parent. + */ + public int getAccessibleIndexInParent() + { + AccessibleContext parent = getAccessibleParent().getAccessibleContext(); + if (parent != null) + for (int i = 0; i < parent.getAccessibleChildrenCount(); i++) + { + if ((parent.getAccessibleChild(i)).equals(this)) + return i; + } + return -1; + } + + /** + * Get the accessible name of this object. + * + * @return the accessible name + */ + public String getAccessibleName() + { + return super.getAccessibleName(); + } + + /** + * Get the Accessible parent of this object. + * + * @return the accessible parent if it exists. + */ + public Accessible getAccessibleParent() + { + return super.getAccessibleParent(); + } + + /** + * Get the role of this object. + * + * @return the accessible role + */ + public AccessibleRole getAccessibleRole() + { + return AccessibleJTree.this.getAccessibleRole(); + } + + /** + * Get the AccessibleSelection associated with this object if one exists. + * + * @return the accessible selection for this. + */ + public AccessibleSelection getAccessibleSelection() + { + return this; + } + + /** + * Returns an Accessible representing the specified selected item + * in the object. + * + * @return the accessible representing a certain selected item. + */ + public Accessible getAccessibleSelection(int i) + { + if (i > 0 && i < getAccessibleSelectionCount()) + return new AccessibleJTreeNode(tree, + tp.pathByAddingChild(selectionList.get(i)), acc); + return null; + } + + /** + * Returns the number of items currently selected. + * + * @return the number of items selected. + */ + public int getAccessibleSelectionCount() + { + return selectionList.size(); + } + + /** + * Get the state set of this object. + * + * @return the state set for this object + */ + public AccessibleStateSet getAccessibleStateSet() + { + if (isVisible()) + states.add(AccessibleState.VISIBLE); + if (tree.isCollapsed(tp)) + states.add(AccessibleState.COLLAPSED); + if (tree.isEditable()) + states.add(AccessibleState.EDITABLE); + if (mod != null && + !mod.isLeaf(tp.getLastPathComponent())) + states.add(AccessibleState.EXPANDABLE); + if (tree.isExpanded(tp)) + states.add(AccessibleState.EXPANDED); + if (isFocusable()) + states.add(AccessibleState.FOCUSABLE); + if (hasFocus()) + states.add(AccessibleState.FOCUSED); + if (tree.getSelectionModel().getSelectionMode() != + TreeSelectionModel.SINGLE_TREE_SELECTION) + states.add(AccessibleState.MULTISELECTABLE); + if (tree.isOpaque()) + states.add(AccessibleState.OPAQUE); + if (tree.isPathSelected(tp)) + states.add(AccessibleState.SELECTED); + if (isShowing()) + states.add(AccessibleState.SHOWING); + + states.add(AccessibleState.SELECTABLE); + return states; + } + + /** + * Get the AccessibleText associated with this object if one exists. + * + * @return the accessible text + */ + public AccessibleText getAccessibleText() + { + return super.getAccessibleText(); + } + + /** + * Get the AccessibleValue associated with this object if one exists. + * + * @return the accessible value if it exists + */ + public AccessibleValue getAccessibleValue() + { + return super.getAccessibleValue(); + } + + /** + * Get the background color of this object. + * + * @return the color of the background. + */ + public Color getBackground() + { + return tree.getBackground(); + } + + /** + * Gets the bounds of this object in the form of a Rectangle object. + * + * @return the bounds of the current node. + */ + public Rectangle getBounds() + { + return tree.getPathBounds(tp); + } + + /** + * Gets the Cursor of this object. + * + * @return the cursor for the current node + */ + public Cursor getCursor() + { + return cursor; + } + + /** + * Gets the Font of this object. + * + * @return the font for the current node + */ + public Font getFont() + { + return tree.getFont(); + } + + /** + * Gets the FontMetrics of this object. + * + * @param f - the current font. + * @return the font metrics for the given font. + */ + public FontMetrics getFontMetrics(Font f) + { + return tree.getFontMetrics(f); + } + + /** + * Get the foreground color of this object. + * + * @return the foreground for this object. + */ + public Color getForeground() + { + return tree.getForeground(); + } + + /** + * Gets the locale of the component. + * + * @return the locale of the component. + */ + public Locale getLocale() + { + return tree.getLocale(); + } + + /** + * Gets the location of the object relative to the + * parent in the form of a point specifying the object's + * top-left corner in the screen's coordinate space. + * + * @return the location of the current node. + */ + public Point getLocation() + { + return getLocationInJTree(); + } + + /** + * Returns the location in the tree. + * + * @return the location in the JTree. + */ + protected Point getLocationInJTree() + { + Rectangle bounds = tree.getPathBounds(tp); + return new Point(bounds.x, bounds.y); + } + + /** + * Returns the location of the object on the screen. + * + * @return the location of the object on the screen. + */ + public Point getLocationOnScreen() + { + Point loc = getLocation(); + SwingUtilities.convertPointToScreen(loc, tree); + return loc; + } + + /** + * Returns the size of this object in the form of a Dimension object. + * + * @return the size of the object + */ + public Dimension getSize() + { + Rectangle b = getBounds(); + return b.getSize(); + } + + /** + * Returns true if the current child of this object is selected. + * + * @param i - the child of the current node + * @return true if the child is selected. + */ + public boolean isAccessibleChildSelected(int i) + { + Object child = mod.getChild(tp.getLastPathComponent(), i); + if (child != null) + return tree.isPathSelected(tp.pathByAddingChild(child)); + return false; + } + + /** + * Determines if the object is enabled. + * + * @return true if the tree is enabled + */ + public boolean isEnabled() + { + return tree.isEnabled(); + } + + /** + * Returns whether this object can accept focus or not. + * + * @return true, it is always focus traversable + */ + public boolean isFocusTraversable() + { + return true; + } + + /** + * Determines if the object is showing. + * + * @return true if the object is visible and the + * parent is visible. + */ + public boolean isShowing() + { + return isVisible() && tree.isShowing(); + } + + /** + * Determines if the object is visible. + * + * @return true if the object is visible. + */ + public boolean isVisible() + { + return tree.isVisible(tp); + } + + /** + * Removes the specified selected item in the object from the + * object's selection. + * + * @param i - the specified item to remove + */ + public void removeAccessibleSelection(int i) + { + if (mod != null) + { + Object child = mod.getChild(tp.getLastPathComponent(), i); + if (child != null) + { + if (!states.contains(AccessibleState.MULTISELECTABLE)) + clearAccessibleSelection(); + if (selectionList.contains(child)) + { + selectionList.remove(child); + tree.removeSelectionPath(tp.pathByAddingChild(child)); + } + } + } + } + + /** + * Removes the specified focus listener so it no longer receives focus + * events from this component. + * + * @param l - the focus listener to remove + */ + public void removeFocusListener(FocusListener l) + { + tree.removeFocusListener(l); + } + + /** + * Remove a PropertyChangeListener from the listener list. + * + * @param l - the property change listener to remove. + */ + public void removePropertyChangeListener(PropertyChangeListener l) + { + // Nothing to do here. + } + + /** + * Requests focus for this object. + */ + public void requestFocus() + { + tree.requestFocus(); + } + + /** + * Causes every selected item in the object to be selected if the object + * supports multiple selections. + */ + public void selectAllAccessibleSelection() + { + Object parent = tp.getLastPathComponent(); + if (mod != null) + { + for (int i = 0; i < mod.getChildCount(parent); i++) + { + Object child = mod.getChild(parent, i); + if (child != null) + { + if (!states.contains(AccessibleState.MULTISELECTABLE)) + clearAccessibleSelection(); + if (selectionList.contains(child)) + { + selectionList.add(child); + tree.addSelectionPath(tp.pathByAddingChild(child)); + } + } + } + } + } + + /** + * Set the accessible description of this object. + * + * @param s - the string to set the accessible description to. + */ + public void setAccessibleDescription(String s) + { + super.setAccessibleDescription(s); + } + + /** + * Set the localized accessible name of this object. + * + * @param s - the string to set the accessible name to. + */ + public void setAccessibleName(String s) + { + super.setAccessibleName(s); + } + + /** + * Set the background color of this object. + * + * @param c - the color to set the background to. + */ + public void setBackground(Color c) + { + // Nothing to do here. + } + + /** + * Sets the bounds of this object in the form of a Rectangle object. + * + * @param r - the bounds to set the object o + */ + public void setBounds(Rectangle r) + { + // Nothing to do here. + } + + /** + * Sets the Cursor of this object. + * + * @param c - the new cursor + */ + public void setCursor(Cursor c) + { + cursor = c; + } + + /** + * Sets the enabled state of the object. + * + * @param b - boolean to enable or disable object + */ + public void setEnabled(boolean b) + { + // Nothing to do here. + } + + /** + * Sets the Font of this object. + * + * @param f - the new font. + */ + public void setFont(Font f) + { + // Nothing to do here. + } + + /** + * Sets the foreground color of this object. + * + * @param c - the new foreground color. + */ + public void setForeground(Color c) + { + // Nothing to do here. + } + + /** + * Sets the location of the object relative to the parent. + * + * @param p - the new location for the object. + */ + public void setLocation(Point p) + { + // Nothing to do here. + } + + /** + * Resizes this object so that it has width and height. + * + * @param d - the new size for the object. + */ + public void setSize(Dimension d) + { + // Nothing to do here. + } + + /** + * Sets the visible state of the object. + * + * @param b - sets the objects visibility. + */ + public void setVisible(boolean b) + { + // Nothing to do here. + } + } + + /** + * Constructor + */ + public AccessibleJTree() + { + // Nothing to do here. + } + + /** + * Adds the specified selected item in the object to the object's selection. + * + * @param i - the row to add to the tree's selection + */ + public void addAccessibleSelection(int i) + { + addSelectionInterval(i, i); + } + + /** + * Clears the selection in the object, so that nothing in the object is selected. + */ + public void clearAccessibleSelection() + { + clearSelection(); + } + + /** + * Fire a visible data property change notification. + */ + public void fireVisibleDataPropertyChange() + { + treeDidChange(); + } + + /** + * Returns the Accessible child, if one exists, contained at the local + * coordinate Point. + * + * @param p - the point of the accessible to get. + * @return the accessible at point p. + */ + public Accessible getAccessibleAt(Point p) + { + TreePath tp = getClosestPathForLocation(p.x, p.y); + if (tp != null) + return new AccessibleJTreeNode(JTree.this, tp, null); + return null; + } + + /** + * Return the nth Accessible child of the object. + * + * @param i - the accessible child to get + * @return the i-th child + */ + public Accessible getAccessibleChild(int i) + { + return null; + } + + /** + * Returns the number of top-level children nodes of this JTree. + * + * @return the number of top-level children + */ + public int getAccessibleChildrenCount() + { + TreeModel model = getModel(); + if (model != null) + return model.getChildCount(model.getRoot()); + return 0; + } + + /** + * Get the index of this object in its accessible parent. + * + * @return the index of this object. + */ + public int getAccessibleIndexInParent() + { + return 0; + } + + /** + * Get the role of this object. + * + * @return the role of this object + */ + public AccessibleRole getAccessibleRole() + { + return AccessibleRole.TREE; + } + + /** + * Get the AccessibleSelection associated with this object. + * + * @return the accessible selection of the tree + */ + public AccessibleSelection getAccessibleSelection() + { + TreeModel mod = getModel(); + if (mod != null) + return (new AccessibleJTreeNode(JTree.this, + new TreePath(mod.getRoot()), null)).getAccessibleSelection(); + return null; + } + + /** + * Returns an Accessible representing the specified selected item in the object. + * + * @return the i-th accessible in the selection + */ + public Accessible getAccessibleSelection(int i) + { + TreeModel mod = getModel(); + if (mod != null) + return (new AccessibleJTreeNode(JTree.this, + new TreePath(mod.getRoot()), null)).getAccessibleSelection(i); + return null; + } + + /** + * Returns the number of items currently selected. + * + * @param the number of selected accessibles. + */ + public int getAccessibleSelectionCount() + { + return getSelectionCount(); + } + + /** + * Returns true if the current child of this object is selected. + * + * @param i - the child of this object + * @return true if the i-th child is selected. + */ + public boolean isAccessibleChildSelected(int i) + { + // Nothing to do here. + return false; + } + + /** + * Removes the specified selected item in the object from the object's + * selection. + * + * @param i - the i-th selected item to remove + */ + public void removeAccessibleSelection(int i) + { + removeSelectionInterval(i, i); + } + + /** + * Causes every selected item in the object to be selected if the object + * supports multiple selections. + */ + public void selectAllAccessibleSelection() + { + if (getSelectionModel().getSelectionMode() != + TreeSelectionModel.SINGLE_TREE_SELECTION) + addSelectionInterval(0, getVisibleRowCount()); + } + + /** + * Tree Collapsed notification + * + * @param e - the event + */ + public void treeCollapsed(TreeExpansionEvent e) + { + fireTreeCollapsed(e.getPath()); + } + + /** + * Tree Model Expansion notification. + * + * @param e - the event + */ + public void treeExpanded(TreeExpansionEvent e) + { + fireTreeExpanded(e.getPath()); + } + + /** + * Tree Model Node change notification. + * + * @param e - the event + */ + public void treeNodesChanged(TreeModelEvent e) + { + // Nothing to do here. + } + + /** + * Tree Model Node change notification. + * + * @param e - the event + */ + public void treeNodesInserted(TreeModelEvent e) + { + // Nothing to do here. + } + + /** + * Tree Model Node change notification. + * + * @param e - the event + */ + public void treeNodesRemoved(TreeModelEvent e) + { + // Nothing to do here. + } + + /** + * Tree Model structure change change notification. + * + * @param e - the event + */ + public void treeStructureChanged(TreeModelEvent e) + { + // Nothing to do here. + } + + /** + * Tree Selection Listener value change method. + * + * @param e - the event + */ + public void valueChanged(TreeSelectionEvent e) + { + fireValueChanged(e); + } + } + + public static class DynamicUtilTreeNode extends DefaultMutableTreeNode + { + protected Object childValue; + + protected boolean loadedChildren; + + /** + * Currently not set or used by this class. It might be set and used in + * later versions of this class. + */ + protected boolean hasChildren; + + public DynamicUtilTreeNode(Object value, Object children) + { + super(value); + childValue = children; + loadedChildren = false; + } + + public int getChildCount() + { + loadChildren(); + return super.getChildCount(); + } + + protected void loadChildren() + { + if (!loadedChildren) + { + createChildren(this, childValue); + loadedChildren = true; + } + } + + public Enumeration children() + { + loadChildren(); + return super.children(); + } + + /** + * Returns the child node at position <code>pos</code>. Subclassed + * here to load the children if necessary. + * + * @param pos the position of the child node to fetch + * + * @return the childnode at the specified position + */ + public TreeNode getChildAt(int pos) + { + loadChildren(); + return super.getChildAt(pos); + } + + public boolean isLeaf() + { + return (childValue == null || !(childValue instanceof Hashtable + || childValue instanceof Vector || childValue.getClass() + .isArray())); + } + + public static void createChildren(DefaultMutableTreeNode parent, + Object children) + { + if (children instanceof Hashtable) + { + Hashtable tab = (Hashtable) children; + Enumeration e = tab.keys(); + while (e.hasMoreElements()) + { + Object key = e.nextElement(); + Object val = tab.get(key); + parent.add(new DynamicUtilTreeNode(key, val)); + } + } + else if (children instanceof Vector) + { + Iterator i = ((Vector) children).iterator(); + while (i.hasNext()) + { + Object n = i.next(); + parent.add(new DynamicUtilTreeNode(n, n)); + } + } + else if (children != null && children.getClass().isArray()) + { + Object[] arr = (Object[]) children; + for (int i = 0; i < arr.length; ++i) + parent.add(new DynamicUtilTreeNode(arr[i], arr[i])); + } + } + } + + /** + * Listens to the model of the JTree and updates the property + * <code>expandedState</code> if nodes are removed or changed. + */ + protected class TreeModelHandler implements TreeModelListener + { + + /** + * Creates a new instance of TreeModelHandler. + */ + protected TreeModelHandler() + { + } + + /** + * Notifies when a node has changed in some ways. This does not include + * that a node has changed its location or changed it's children. It + * only means that some attributes of the node have changed that might + * affect its presentation. + * + * This method is called after the actual change occured. + * + * @param ev the TreeModelEvent describing the change + */ + public void treeNodesChanged(TreeModelEvent ev) + { + // Nothing to do here. + } + + /** + * Notifies when a node is inserted into the tree. + * + * This method is called after the actual change occured. + * + * @param ev the TreeModelEvent describing the change + */ + public void treeNodesInserted(TreeModelEvent ev) + { + // nothing to do here + } + + /** + * Notifies when a node is removed from the tree. + * + * This method is called after the actual change occured. + * + * @param ev the TreeModelEvent describing the change */ - protected static class EmptySelectionModel - extends - DefaultTreeSelectionModel - { - /** The serial version UID. */ - private static final long serialVersionUID = -5815023306225701477L; - - /** - * The shared instance of this model. - */ - protected static final EmptySelectionModel sharedInstance = new EmptySelectionModel(); - - /** - * Creates a new instance of EmptySelectionModel. - */ - protected EmptySelectionModel() - { - } - - /** - * Returns the shared instance of EmptySelectionModel. - * - * @return the shared instance of EmptySelectionModel - */ - public static EmptySelectionModel sharedInstance() - { - return sharedInstance; - } - - /** - * This catches attempts to set a selection and sets nothing instead. - * - * @param paths not used here - */ - public void setSelectionPaths(TreePath[] paths) - { - // we don't allow selections in this class - } - - /** - * This catches attempts to add something to the selection. - * - * @param paths not used here - */ - public void addSelectionPaths(TreePath[] paths) - { - // we don't allow selections in this class - } - - /** - * This catches attempts to remove something from the selection. - * - * @param paths not used here - */ - public void removeSelectionPaths(TreePath[] paths) - { - // we don't allow selections in this class - } - }// EmptySelectionModel - - private static final long serialVersionUID = 7559816092864483649L; - public static final String CELL_EDITOR_PROPERTY = "cellEditor"; - public static final String CELL_RENDERER_PROPERTY = "cellRenderer"; - public static final String EDITABLE_PROPERTY = "editable"; - public static final String INVOKES_STOP_CELL_EDITING_PROPERTY = "invokesStopCellEditing"; - public static final String LARGE_MODEL_PROPERTY = "largeModel"; - public static final String ROOT_VISIBLE_PROPERTY = "rootVisible"; - public static final String ROW_HEIGHT_PROPERTY = "rowHeight"; - public static final String SCROLLS_ON_EXPAND_PROPERTY = "scrollsOnExpand"; - public static final String SELECTION_MODEL_PROPERTY = "selectionModel"; - public static final String SHOWS_ROOT_HANDLES_PROPERTY = "showsRootHandles"; - public static final String TOGGLE_CLICK_COUNT_PROPERTY = "toggleClickCount"; - public static final String TREE_MODEL_PROPERTY = "model"; - public static final String VISIBLE_ROW_COUNT_PROPERTY = "visibleRowCount"; + public void treeNodesRemoved(TreeModelEvent ev) + { + // TODO: The API docs suggest that this method should do something + // but I cannot really see what has to be done here ... + } - /** @since 1.3 */ - public static final String ANCHOR_SELECTION_PATH_PROPERTY = "anchorSelectionPath"; + /** + * Notifies when the structure of the tree is changed. + * + * This method is called after the actual change occured. + * + * @param ev the TreeModelEvent describing the change + */ + public void treeStructureChanged(TreeModelEvent ev) + { + // Set state of new path. + TreePath path = ev.getTreePath(); + setExpandedState(path, isExpanded(path)); + } + } - /** @since 1.3 */ - public static final String LEAD_SELECTION_PATH_PROPERTY = "leadSelectionPath"; + /** + * This redirects TreeSelectionEvents and rewrites the source of it to be + * this JTree. This is typically done when the tree model generates an + * event, but the JTree object associated with that model should be listed + * as the actual source of the event. + */ + protected class TreeSelectionRedirector implements TreeSelectionListener, + Serializable + { + /** The serial version UID. */ + private static final long serialVersionUID = -3505069663646241664L; + + /** + * Creates a new instance of TreeSelectionRedirector + */ + protected TreeSelectionRedirector() + { + } + + /** + * Notifies when the tree selection changes. + * + * @param ev the TreeSelectionEvent that describes the change + */ + public void valueChanged(TreeSelectionEvent ev) + { + TreeSelectionEvent rewritten = + (TreeSelectionEvent) ev.cloneWithSource(JTree.this); + fireValueChanged(rewritten); + JTree.this.repaint(); + } + } + + /** + * A TreeModel that does not allow anything to be selected. + */ + protected static class EmptySelectionModel extends DefaultTreeSelectionModel + { + /** The serial version UID. */ + private static final long serialVersionUID = -5815023306225701477L; + + /** + * The shared instance of this model. + */ + protected static final EmptySelectionModel sharedInstance = + new EmptySelectionModel(); + + /** + * Creates a new instance of EmptySelectionModel. + */ + protected EmptySelectionModel() + { + } + + /** + * Returns the shared instance of EmptySelectionModel. + * + * @return the shared instance of EmptySelectionModel + */ + public static EmptySelectionModel sharedInstance() + { + return sharedInstance; + } + + /** + * This catches attempts to set a selection and sets nothing instead. + * + * @param paths not used here + */ + public void setSelectionPaths(TreePath[] paths) + { + // We don't allow selections in this class. + } + + /** + * This catches attempts to add something to the selection. + * + * @param paths not used here + */ + public void addSelectionPaths(TreePath[] paths) + { + // We don't allow selections in this class. + } + + /** + * This catches attempts to remove something from the selection. + * + * @param paths not used here + */ + public void removeSelectionPaths(TreePath[] paths) + { + // We don't allow selections in this class. + } + } + + private static final long serialVersionUID = 7559816092864483649L; + + public static final String CELL_EDITOR_PROPERTY = "cellEditor"; + + public static final String CELL_RENDERER_PROPERTY = "cellRenderer"; + + public static final String EDITABLE_PROPERTY = "editable"; + + public static final String INVOKES_STOP_CELL_EDITING_PROPERTY = + "invokesStopCellEditing"; + + public static final String LARGE_MODEL_PROPERTY = "largeModel"; + + public static final String ROOT_VISIBLE_PROPERTY = "rootVisible"; + + public static final String ROW_HEIGHT_PROPERTY = "rowHeight"; + + public static final String SCROLLS_ON_EXPAND_PROPERTY = "scrollsOnExpand"; + + public static final String SELECTION_MODEL_PROPERTY = "selectionModel"; + + public static final String SHOWS_ROOT_HANDLES_PROPERTY = "showsRootHandles"; + + public static final String TOGGLE_CLICK_COUNT_PROPERTY = "toggleClickCount"; + + public static final String TREE_MODEL_PROPERTY = "model"; + + public static final String VISIBLE_ROW_COUNT_PROPERTY = "visibleRowCount"; + + /** @since 1.3 */ + public static final String ANCHOR_SELECTION_PATH_PROPERTY = + "anchorSelectionPath"; /** @since 1.3 */ - public static final String EXPANDS_SELECTED_PATHS_PROPERTY = "expandsSelectedPaths"; - private static final Object EXPANDED = new Object(); - private static final Object COLLAPSED = new Object(); - private boolean dragEnabled; - private boolean expandsSelectedPaths; - private TreePath anchorSelectionPath; - private TreePath leadSelectionPath; - - /* - * This contains the state of all nodes in the tree. Al/ entries map the - * TreePath of a note to to its state. Valid states are EXPANDED and - * COLLAPSED. Nodes not in this Hashtable are assumed state COLLAPSED. - */ - private Hashtable nodeStates = new Hashtable(); - protected transient TreeCellEditor cellEditor; - protected transient TreeCellRenderer cellRenderer; - protected boolean editable; - protected boolean invokesStopCellEditing; - protected boolean largeModel; - protected boolean rootVisible; - protected int rowHeight; - protected boolean scrollsOnExpand; - protected transient TreeSelectionModel selectionModel; - protected boolean showsRootHandles; - protected int toggleClickCount; - protected transient TreeModel treeModel; - protected int visibleRowCount; - - /** - * Handles TreeModelEvents to update the expandedState. - */ - protected transient TreeModelListener treeModelListener; + public static final String LEAD_SELECTION_PATH_PROPERTY = "leadSelectionPath"; - /** - * Redirects TreeSelectionEvents so that the source is this JTree. - */ - protected TreeSelectionRedirector selectionRedirector = - new TreeSelectionRedirector(); + /** @since 1.3 */ + public static final String EXPANDS_SELECTED_PATHS_PROPERTY = + "expandsSelectedPaths"; - /** - * Creates a new <code>JTree</code> object. - */ - public JTree() - { - this(createTreeModel(null)); - } - - /** - * Creates a new <code>JTree</code> object. - * - * @param value the initial nodes in the tree - */ - public JTree(Hashtable value) - { - this(createTreeModel(value)); - } - - /** - * Creates a new <code>JTree</code> object. - * - * @param value the initial nodes in the tree - */ - public JTree(Object[] value) - { - this(createTreeModel(value)); - } - - /** - * Creates a new <code>JTree</code> object. - * - * @param model the model to use - */ - public JTree(TreeModel model) - { - setModel(model); - setSelectionModel(EmptySelectionModel.sharedInstance()); - setCellRenderer(new DefaultTreeCellRenderer()); - updateUI(); - } - - /** - * Creates a new <code>JTree</code> object. - * - * @param root the root node - */ - public JTree(TreeNode root) - { - this(root, false); - } - - /** - * Creates a new <code>JTree</code> object. - * - * @param root the root node - * @param asksAllowChildren if false, all nodes without children are leaf - * nodes. If true, only nodes that do not allow children are leaf - * nodes. - */ - public JTree(TreeNode root, boolean asksAllowChildren) - { - this(new DefaultTreeModel(root, asksAllowChildren)); - } - - /** - * Creates a new <code>JTree</code> object. - * - * @param value the initial nodes in the tree - */ - public JTree(Vector value) - { - this(createTreeModel(value)); - } - - public static class DynamicUtilTreeNode - extends - DefaultMutableTreeNode - { - protected Object childValue; - protected boolean loadedChildren; - - /** - * Currently not set or used by this class. It might be set and used in - * later versions of this class. - */ - protected boolean hasChildren; - - public DynamicUtilTreeNode(Object value, Object children) - { - super(value); - childValue = children; - loadedChildren = false; - } - - public int getChildCount() - { - loadChildren(); - return super.getChildCount(); - } - - protected void loadChildren() - { - if (!loadedChildren) - { - createChildren(this, childValue); - loadedChildren = true; - } - } - - public Enumeration children() - { - loadChildren(); - return super.children(); - } - - /** - * Returns the child node at position <code>pos</code>. Subclassed - * here to load the children if necessary. - * - * @param pos the position of the child node to fetch - * - * @return the childnode at the specified position - */ - public TreeNode getChildAt(int pos) - { - loadChildren(); - return super.getChildAt(pos); - } - - public boolean isLeaf() - { - return (childValue == null || !(childValue instanceof Hashtable - || childValue instanceof Vector || childValue.getClass() - .isArray())); - } - - public static void createChildren(DefaultMutableTreeNode parent, - Object children) - { - if (children instanceof Hashtable) - { - Hashtable tab = (Hashtable) children; - Enumeration e = tab.keys(); - while (e.hasMoreElements()) - { - Object key = e.nextElement(); - Object val = tab.get(key); - parent.add(new DynamicUtilTreeNode(key, val)); - } - } else if (children instanceof Vector) - { - Iterator i = ((Vector) children).iterator(); - while (i.hasNext()) - { - Object n = i.next(); - parent.add(new DynamicUtilTreeNode(n, n)); - } - } else if (children != null && children.getClass().isArray()) - { - Object[] arr = (Object[]) children; - for (int i = 0; i < arr.length; ++i) - parent.add(new DynamicUtilTreeNode(arr[i], arr[i])); - } - } - } - - public int getRowForPath(TreePath path) - { - TreeUI ui = getUI(); - - if (ui != null) - return ui.getRowForPath(this, path); - - return -1; - } - - public TreePath getPathForRow(int row) - { - TreeUI ui = getUI(); - return ui != null ? ui.getPathForRow(this, row) : null; - } - - protected TreePath[] getPathBetweenRows(int index0, int index1) - { - TreeUI ui = getUI(); - - if (ui == null) - return null; - - int minIndex = Math.min(index0, index1); - int maxIndex = Math.max(index0, index1); - TreePath[] paths = new TreePath[maxIndex - minIndex + 1]; - - for (int i = minIndex; i <= maxIndex; ++i) - paths[i - minIndex] = ui.getPathForRow(this, i); - - return paths; - } - - /** - * Creates a new <code>TreeModel</code> object. - * - * @param value the values stored in the model - */ - protected static TreeModel createTreeModel(Object value) - { - return new DefaultTreeModel(new DynamicUtilTreeNode(value, value)); - } - - /** - * Return the UI associated with this <code>JTree</code> object. - * - * @return the associated <code>TreeUI</code> object - */ - public TreeUI getUI() - { - return (TreeUI) ui; - } - - /** - * Sets the UI associated with this <code>JTree</code> object. - * - * @param ui the <code>TreeUI</code> to associate - */ - public void setUI(TreeUI ui) - { - super.setUI(ui); - } + private static final Object EXPANDED = new Object(); - /** - * This method resets the UI used to the Look and Feel defaults.. - */ - public void updateUI() - { - setUI((TreeUI) UIManager.getUI(this)); - revalidate(); - repaint(); - } - - /** - * This method returns the String ID of the UI class of Separator. - * - * @return The UI class' String ID. - */ - public String getUIClassID() - { - return "TreeUI"; - } - - /** - * Gets the AccessibleContext associated with this - * <code>JToggleButton</code>. - * - * @return the associated context - */ - public AccessibleContext getAccessibleContext() - { - return null; - } - - /** - * Returns the preferred viewport size. - * - * @return the preferred size - */ - public Dimension getPreferredScrollableViewportSize() - { - return new Dimension (getPreferredSize().width, getVisibleRowCount()*getRowHeight()); - } - - public int getScrollableUnitIncrement(Rectangle visibleRect, - int orientation, int direction) - { - return 1; - } - - public int getScrollableBlockIncrement(Rectangle visibleRect, - int orientation, int direction) - { - return 1; - } + private static final Object COLLAPSED = new Object(); + + private boolean dragEnabled; + + private boolean expandsSelectedPaths; + + private TreePath anchorSelectionPath; + + private TreePath leadSelectionPath; + + /** + * This contains the state of all nodes in the tree. Al/ entries map the + * TreePath of a note to to its state. Valid states are EXPANDED and + * COLLAPSED. Nodes not in this Hashtable are assumed state COLLAPSED. + */ + private Hashtable nodeStates = new Hashtable(); + + protected transient TreeCellEditor cellEditor; + + protected transient TreeCellRenderer cellRenderer; + + protected boolean editable; + + protected boolean invokesStopCellEditing; + + protected boolean largeModel; + + protected boolean rootVisible; + + protected int rowHeight; + + protected boolean scrollsOnExpand; + + protected transient TreeSelectionModel selectionModel; + + protected boolean showsRootHandles; + + protected int toggleClickCount; + + protected transient TreeModel treeModel; + + protected int visibleRowCount; + + /** + * Handles TreeModelEvents to update the expandedState. + */ + protected transient TreeModelListener treeModelListener; + + /** + * Redirects TreeSelectionEvents so that the source is this JTree. + */ + protected TreeSelectionRedirector selectionRedirector = + new TreeSelectionRedirector(); + + /** + * Creates a new <code>JTree</code> object. + */ + public JTree() + { + this(createTreeModel(null)); + } + + /** + * Creates a new <code>JTree</code> object. + * + * @param value the initial nodes in the tree + */ + public JTree(Hashtable value) + { + this(createTreeModel(value)); + } + + /** + * Creates a new <code>JTree</code> object. + * + * @param value the initial nodes in the tree + */ + public JTree(Object[] value) + { + this(createTreeModel(value)); + } + + /** + * Creates a new <code>JTree</code> object. + * + * @param model the model to use + */ + public JTree(TreeModel model) + { + setModel(model); + setSelectionModel(EmptySelectionModel.sharedInstance()); + setCellRenderer(new DefaultTreeCellRenderer()); + updateUI(); + } + + /** + * Creates a new <code>JTree</code> object. + * + * @param root the root node + */ + public JTree(TreeNode root) + { + this(root, false); + } + + /** + * Creates a new <code>JTree</code> object. + * + * @param root the root node + * @param asksAllowChildren if false, all nodes without children are leaf + * nodes. If true, only nodes that do not allow children are leaf + * nodes. + */ + public JTree(TreeNode root, boolean asksAllowChildren) + { + this(new DefaultTreeModel(root, asksAllowChildren)); + } + + /** + * Creates a new <code>JTree</code> object. + * + * @param value the initial nodes in the tree + */ + public JTree(Vector value) + { + this(createTreeModel(value)); + } + + public int getRowForPath(TreePath path) + { + TreeUI ui = getUI(); + + if (ui != null) + return ui.getRowForPath(this, path); + + return -1; + } + + public TreePath getPathForRow(int row) + { + TreeUI ui = getUI(); + return ui != null ? ui.getPathForRow(this, row) : null; + } + + protected TreePath[] getPathBetweenRows(int index0, int index1) + { + TreeUI ui = getUI(); + + if (ui == null) + return null; + + int minIndex = Math.min(index0, index1); + int maxIndex = Math.max(index0, index1); + TreePath[] paths = new TreePath[maxIndex - minIndex + 1]; + + for (int i = minIndex; i <= maxIndex; ++i) + paths[i - minIndex] = ui.getPathForRow(this, i); + + return paths; + } + + /** + * Creates a new <code>TreeModel</code> object. + * + * @param value the values stored in the model + */ + protected static TreeModel createTreeModel(Object value) + { + return new DefaultTreeModel(new DynamicUtilTreeNode(value, value)); + } + + /** + * Return the UI associated with this <code>JTree</code> object. + * + * @return the associated <code>TreeUI</code> object + */ + public TreeUI getUI() + { + return (TreeUI) ui; + } + + /** + * Sets the UI associated with this <code>JTree</code> object. + * + * @param ui the <code>TreeUI</code> to associate + */ + public void setUI(TreeUI ui) + { + super.setUI(ui); + } + + /** + * This method resets the UI used to the Look and Feel defaults.. + */ + public void updateUI() + { + setUI((TreeUI) UIManager.getUI(this)); + revalidate(); + repaint(); + } + + /** + * This method returns the String ID of the UI class of Separator. + * + * @return The UI class' String ID. + */ + public String getUIClassID() + { + return "TreeUI"; + } + + /** + * Gets the AccessibleContext associated with this + * <code>JToggleButton</code>. + * + * @return the associated context + */ + public AccessibleContext getAccessibleContext() + { + return null; + } + + /** + * Returns the preferred viewport size. + * + * @return the preferred size + */ + public Dimension getPreferredScrollableViewportSize() + { + return new Dimension (getPreferredSize().width, getVisibleRowCount()*getRowHeight()); + } + + public int getScrollableUnitIncrement(Rectangle visibleRect, + int orientation, int direction) + { + return 1; + } + + public int getScrollableBlockIncrement(Rectangle visibleRect, + int orientation, int direction) + { + return 1; + } public boolean getScrollableTracksViewportWidth() { @@ -590,7 +1638,7 @@ public class JTree return ((JViewport) getParent()).getHeight() > getPreferredSize().height; return false; } - + public boolean getScrollableTracksViewportHeight() { if (getParent() instanceof JViewport) @@ -598,1224 +1646,1253 @@ public class JTree return false; } - /** - * Adds a <code>TreeExpansionListener</code> object to the tree. - * - * @param listener the listener to add - */ - public void addTreeExpansionListener(TreeExpansionListener listener) - { - listenerList.add(TreeExpansionListener.class, listener); - } - - /** - * Removes a <code>TreeExpansionListener</code> object from the tree. - * - * @param listener the listener to remove - */ - public void removeTreeExpansionListener(TreeExpansionListener listener) - { - listenerList.remove(TreeExpansionListener.class, listener); - } - - /** - * Returns all added <code>TreeExpansionListener</code> objects. - * - * @return an array of listeners - */ - public TreeExpansionListener[] getTreeExpansionListeners() - { - return (TreeExpansionListener[]) getListeners(TreeExpansionListener.class); - } - - /** - * Notifies all listeners that the tree was collapsed. - * - * @param path the path to the node that was collapsed - */ - public void fireTreeCollapsed(TreePath path) - { - TreeExpansionEvent event = new TreeExpansionEvent(this, path); - TreeExpansionListener[] listeners = getTreeExpansionListeners(); - - for (int index = 0; index < listeners.length; ++index) - listeners[index].treeCollapsed(event); - } - - /** - * Notifies all listeners that the tree was expanded. - * - * @param path the path to the node that was expanded - */ - public void fireTreeExpanded(TreePath path) - { - TreeExpansionEvent event = new TreeExpansionEvent(this, path); - TreeExpansionListener[] listeners = getTreeExpansionListeners(); - - for (int index = 0; index < listeners.length; ++index) - listeners[index].treeExpanded(event); - } - - /** - * Adds a <code>TreeSelctionListener</code> object to the tree. - * - * @param listener the listener to add - */ - public void addTreeSelectionListener(TreeSelectionListener listener) - { - listenerList.add(TreeSelectionListener.class, listener); - } - - /** - * Removes a <code>TreeSelectionListener</code> object from the tree. - * - * @param listener the listener to remove - */ - public void removeTreeSelectionListener(TreeSelectionListener listener) - { - listenerList.remove(TreeSelectionListener.class, listener); - } - - /** - * Returns all added <code>TreeSelectionListener</code> objects. - * - * @return an array of listeners - */ - public TreeSelectionListener[] getTreeSelectionListeners() - { - return (TreeSelectionListener[]) - getListeners(TreeSelectionListener.class); - } - - /** - * Notifies all listeners when the selection of the tree changed. - * - * @param event the event to send - */ - protected void fireValueChanged(TreeSelectionEvent event) - { - TreeSelectionListener[] listeners = getTreeSelectionListeners(); - - for (int index = 0; index < listeners.length; ++index) - listeners[index].valueChanged(event); - } - - /** - * Adds a <code>TreeWillExpandListener</code> object to the tree. - * - * @param listener the listener to add - */ - public void addTreeWillExpandListener(TreeWillExpandListener listener) - { - listenerList.add(TreeWillExpandListener.class, listener); - } - - /** - * Removes a <code>TreeWillExpandListener</code> object from the tree. - * - * @param listener the listener to remove - */ - public void removeTreeWillExpandListener(TreeWillExpandListener listener) - { - listenerList.remove(TreeWillExpandListener.class, listener); - } - - /** - * Returns all added <code>TreeWillExpandListener</code> objects. - * - * @return an array of listeners - */ - public TreeWillExpandListener[] getTreeWillExpandListeners() - { - return (TreeWillExpandListener[]) - getListeners(TreeWillExpandListener.class); - } - - /** - * Notifies all listeners that the tree will collapse. - * - * @param path the path to the node that will collapse - */ - public void fireTreeWillCollapse(TreePath path) throws ExpandVetoException - { - TreeExpansionEvent event = new TreeExpansionEvent(this, path); - TreeWillExpandListener[] listeners = getTreeWillExpandListeners(); - - for (int index = 0; index < listeners.length; ++index) - listeners[index].treeWillCollapse(event); - } - - /** - * Notifies all listeners that the tree will expand. - * - * @param path the path to the node that will expand - */ - public void fireTreeWillExpand(TreePath path) throws ExpandVetoException - { - TreeExpansionEvent event = new TreeExpansionEvent(this, path); - TreeWillExpandListener[] listeners = getTreeWillExpandListeners(); - - for (int index = 0; index < listeners.length; ++index) - listeners[index].treeWillExpand(event); - } - - /** - * Returns the model of this <code>JTree</code> object. - * - * @return the associated <code>TreeModel</code> - */ - public TreeModel getModel() - { - return treeModel; - } - - /** - * Sets the model to use in <code>JTree</code>. - * - * @param model the <code>TreeModel</code> to use - */ - public void setModel(TreeModel model) - { - if (treeModel == model) - return; - - // add treeModelListener to the new model - if (treeModelListener == null) - treeModelListener = createTreeModelListener(); - if (model != null) // as setModel(null) is allowed - model.addTreeModelListener(treeModelListener); - + /** + * Adds a <code>TreeExpansionListener</code> object to the tree. + * + * @param listener the listener to add + */ + public void addTreeExpansionListener(TreeExpansionListener listener) + { + listenerList.add(TreeExpansionListener.class, listener); + } + + /** + * Removes a <code>TreeExpansionListener</code> object from the tree. + * + * @param listener the listener to remove + */ + public void removeTreeExpansionListener(TreeExpansionListener listener) + { + listenerList.remove(TreeExpansionListener.class, listener); + } + + /** + * Returns all added <code>TreeExpansionListener</code> objects. + * + * @return an array of listeners + */ + public TreeExpansionListener[] getTreeExpansionListeners() + { + return (TreeExpansionListener[]) getListeners(TreeExpansionListener.class); + } + + /** + * Notifies all listeners that the tree was collapsed. + * + * @param path the path to the node that was collapsed + */ + public void fireTreeCollapsed(TreePath path) + { + TreeExpansionEvent event = new TreeExpansionEvent(this, path); + TreeExpansionListener[] listeners = getTreeExpansionListeners(); + + for (int index = 0; index < listeners.length; ++index) + listeners[index].treeCollapsed(event); + } + + /** + * Notifies all listeners that the tree was expanded. + * + * @param path the path to the node that was expanded + */ + public void fireTreeExpanded(TreePath path) + { + TreeExpansionEvent event = new TreeExpansionEvent(this, path); + TreeExpansionListener[] listeners = getTreeExpansionListeners(); + + for (int index = 0; index < listeners.length; ++index) + listeners[index].treeExpanded(event); + } + + /** + * Adds a <code>TreeSelctionListener</code> object to the tree. + * + * @param listener the listener to add + */ + public void addTreeSelectionListener(TreeSelectionListener listener) + { + listenerList.add(TreeSelectionListener.class, listener); + } + + /** + * Removes a <code>TreeSelectionListener</code> object from the tree. + * + * @param listener the listener to remove + */ + public void removeTreeSelectionListener(TreeSelectionListener listener) + { + listenerList.remove(TreeSelectionListener.class, listener); + } + + /** + * Returns all added <code>TreeSelectionListener</code> objects. + * + * @return an array of listeners + */ + public TreeSelectionListener[] getTreeSelectionListeners() + { + return (TreeSelectionListener[]) + getListeners(TreeSelectionListener.class); + } + + /** + * Notifies all listeners when the selection of the tree changed. + * + * @param event the event to send + */ + protected void fireValueChanged(TreeSelectionEvent event) + { + TreeSelectionListener[] listeners = getTreeSelectionListeners(); + + for (int index = 0; index < listeners.length; ++index) + listeners[index].valueChanged(event); + } + + /** + * Adds a <code>TreeWillExpandListener</code> object to the tree. + * + * @param listener the listener to add + */ + public void addTreeWillExpandListener(TreeWillExpandListener listener) + { + listenerList.add(TreeWillExpandListener.class, listener); + } + + /** + * Removes a <code>TreeWillExpandListener</code> object from the tree. + * + * @param listener the listener to remove + */ + public void removeTreeWillExpandListener(TreeWillExpandListener listener) + { + listenerList.remove(TreeWillExpandListener.class, listener); + } + + /** + * Returns all added <code>TreeWillExpandListener</code> objects. + * + * @return an array of listeners + */ + public TreeWillExpandListener[] getTreeWillExpandListeners() + { + return (TreeWillExpandListener[]) + getListeners(TreeWillExpandListener.class); + } + + /** + * Notifies all listeners that the tree will collapse. + * + * @param path the path to the node that will collapse + */ + public void fireTreeWillCollapse(TreePath path) throws ExpandVetoException + { + TreeExpansionEvent event = new TreeExpansionEvent(this, path); + TreeWillExpandListener[] listeners = getTreeWillExpandListeners(); + + for (int index = 0; index < listeners.length; ++index) + listeners[index].treeWillCollapse(event); + } + + /** + * Notifies all listeners that the tree will expand. + * + * @param path the path to the node that will expand + */ + public void fireTreeWillExpand(TreePath path) throws ExpandVetoException + { + TreeExpansionEvent event = new TreeExpansionEvent(this, path); + TreeWillExpandListener[] listeners = getTreeWillExpandListeners(); + + for (int index = 0; index < listeners.length; ++index) + listeners[index].treeWillExpand(event); + } + + /** + * Returns the model of this <code>JTree</code> object. + * + * @return the associated <code>TreeModel</code> + */ + public TreeModel getModel() + { + return treeModel; + } + + /** + * Sets the model to use in <code>JTree</code>. + * + * @param model the <code>TreeModel</code> to use + */ + public void setModel(TreeModel model) + { + if (treeModel == model) + return; + + // add treeModelListener to the new model + if (treeModelListener == null) + treeModelListener = createTreeModelListener(); + if (model != null) // as setModel(null) is allowed + model.addTreeModelListener(treeModelListener); + TreeModel oldValue = treeModel; treeModel = model; firePropertyChange(TREE_MODEL_PROPERTY, oldValue, model); - } + } - /** - * Checks if this <code>JTree</code> object is editable. - * - * @return <code>true</code> if this tree object is editable, - * <code>false</code> otherwise - */ - public boolean isEditable() - { - return editable; - } - - /** - * Sets the <code>editable</code> property. - * - * @param flag <code>true</code> to make this tree object editable, - * <code>false</code> otherwise - */ - public void setEditable(boolean flag) - { - if (editable == flag) - return; - - boolean oldValue = editable; - editable = flag; - firePropertyChange(EDITABLE_PROPERTY, oldValue, editable); - } - - /** - * Checks if the root element is visible. - * - * @return <code>true</code> if the root element is visible, - * <code>false</code> otherwise - */ - public boolean isRootVisible() - { - return rootVisible; - } - - public void setRootVisible(boolean flag) - { - if (rootVisible == flag) - return; - - boolean oldValue = rootVisible; - rootVisible = flag; - firePropertyChange(ROOT_VISIBLE_PROPERTY, oldValue, flag); - } - - public boolean getShowsRootHandles() - { - return showsRootHandles; - } - - public void setShowsRootHandles(boolean flag) - { - if (showsRootHandles == flag) - return; - - boolean oldValue = showsRootHandles; - showsRootHandles = flag; - firePropertyChange(SHOWS_ROOT_HANDLES_PROPERTY, oldValue, flag); - } - - public TreeCellEditor getCellEditor() - { - - return cellEditor; - } - - public void setCellEditor(TreeCellEditor editor) - { - if (cellEditor == editor) - return; - - TreeCellEditor oldValue = cellEditor; - cellEditor = editor; - firePropertyChange(CELL_EDITOR_PROPERTY, oldValue, editor); - } - - public TreeCellRenderer getCellRenderer() - { - return cellRenderer; - } - - public void setCellRenderer(TreeCellRenderer newRenderer) - { - if (cellRenderer == newRenderer) - return; - - TreeCellRenderer oldValue = cellRenderer; - cellRenderer = newRenderer; - firePropertyChange(CELL_RENDERER_PROPERTY, oldValue, newRenderer); - } - - public TreeSelectionModel getSelectionModel() - { - return selectionModel; - } - - public void setSelectionModel(TreeSelectionModel model) - { - if (selectionModel == model) - return; - - if (selectionModel != null) - selectionModel.removeTreeSelectionListener(selectionRedirector); - - TreeSelectionModel oldValue = selectionModel; - selectionModel = model; - - if (selectionModel != null) - selectionModel.addTreeSelectionListener(selectionRedirector); - - firePropertyChange(SELECTION_MODEL_PROPERTY, oldValue, model); - revalidate(); - repaint(); - } - - public int getVisibleRowCount() - { - return visibleRowCount; - } - - public void setVisibleRowCount(int rows) - { - if (visibleRowCount == rows) - return; - - int oldValue = visibleRowCount; - visibleRowCount = rows; - firePropertyChange(VISIBLE_ROW_COUNT_PROPERTY, oldValue, rows); - } - - public boolean isLargeModel() - { - return largeModel; - } - - public void setLargeModel(boolean large) - { - if (largeModel == large) - return; - - boolean oldValue = largeModel; - largeModel = large; - firePropertyChange(LARGE_MODEL_PROPERTY, oldValue, large); - } - - public int getRowHeight() - { - - return rowHeight; - } - - public void setRowHeight(int height) - { - if (rowHeight == height) - return; - - int oldValue = rowHeight; - rowHeight = height; - firePropertyChange(ROW_HEIGHT_PROPERTY, oldValue, height); - } - - public boolean isFixedRowHeight() - { - return rowHeight > 0; - } - - public boolean getInvokesStopCellEditing() - { - return invokesStopCellEditing; - } - - public void setInvokesStopCellEditing(boolean invoke) - { - if (invokesStopCellEditing == invoke) - return; - - boolean oldValue = invokesStopCellEditing; - invokesStopCellEditing = invoke; - firePropertyChange(INVOKES_STOP_CELL_EDITING_PROPERTY, - oldValue, invoke); - } - - /** - * @since 1.3 - */ - public int getToggleClickCount() - { - return toggleClickCount; - } + /** + * Checks if this <code>JTree</code> object is editable. + * + * @return <code>true</code> if this tree object is editable, + * <code>false</code> otherwise + */ + public boolean isEditable() + { + return editable; + } - /** - * @since 1.3 - */ - public void setToggleClickCount(int count) - { - if (toggleClickCount == count) - return; - - int oldValue = toggleClickCount; - toggleClickCount = count; - firePropertyChange(TOGGLE_CLICK_COUNT_PROPERTY, oldValue, count); - } - - public void scrollPathToVisible(TreePath path) - { - if (path == null) - return; + /** + * Sets the <code>editable</code> property. + * + * @param flag <code>true</code> to make this tree object editable, + * <code>false</code> otherwise + */ + public void setEditable(boolean flag) + { + if (editable == flag) + return; - Rectangle rect = getPathBounds(path); - - if (rect == null) - return; - - scrollRectToVisible(rect); - } + boolean oldValue = editable; + editable = flag; + firePropertyChange(EDITABLE_PROPERTY, oldValue, editable); + } - public void scrollRowToVisible(int row) - { - scrollPathToVisible(getPathForRow(row)); - } - - public boolean getScrollsOnExpand() - { - return scrollsOnExpand; - } - - public void setScrollsOnExpand(boolean scroll) - { - if (scrollsOnExpand == scroll) - return; - - boolean oldValue = scrollsOnExpand; - scrollsOnExpand = scroll; - firePropertyChange(SCROLLS_ON_EXPAND_PROPERTY, oldValue, scroll); - } - - public void setSelectionPath(TreePath path) - { - selectionModel.setSelectionPath(path); - } - - public void setSelectionPaths(TreePath[] paths) - { - selectionModel.setSelectionPaths(paths); - } - - public void setSelectionRow(int row) - { - TreePath path = getPathForRow(row); - - if (path != null) - selectionModel.setSelectionPath(path); - } - - public void setSelectionRows(int[] rows) - { - // Make sure we have an UI so getPathForRow() does not return null. - if (rows == null || getUI() == null) - return; - - TreePath[] paths = new TreePath[rows.length]; - - for (int i = rows.length - 1; i >= 0; --i) - paths[i] = getPathForRow(rows[i]); - - setSelectionPaths(paths); - } - - public void setSelectionInterval(int index0, int index1) - { - TreePath[] paths = getPathBetweenRows(index0, index1); - - if (paths != null) - setSelectionPaths(paths); - } - - public void addSelectionPath(TreePath path) - { - selectionModel.addSelectionPath(path); - } - - public void addSelectionPaths(TreePath[] paths) - { - selectionModel.addSelectionPaths(paths); - } - - public void addSelectionRow(int row) - { - TreePath path = getPathForRow(row); - - if (path != null) - selectionModel.addSelectionPath(path); - } - - public void addSelectionRows(int[] rows) - { - // Make sure we have an UI so getPathForRow() does not return null. - if (rows == null || getUI() == null) - return; - - TreePath[] paths = new TreePath[rows.length]; + /** + * Checks if the root element is visible. + * + * @return <code>true</code> if the root element is visible, + * <code>false</code> otherwise + */ + public boolean isRootVisible() + { + return rootVisible; + } - for (int i = rows.length - 1; i >= 0; --i) - paths[i] = getPathForRow(rows[i]); - - addSelectionPaths(paths); - } + public void setRootVisible(boolean flag) + { + if (rootVisible == flag) + return; - public void addSelectionInterval(int index0, int index1) - { - TreePath[] paths = getPathBetweenRows(index0, index1); - - if (paths != null) - addSelectionPaths(paths); - } - - public void removeSelectionPath(TreePath path) - { - selectionModel.removeSelectionPath(path); - } - - public void removeSelectionPaths(TreePath[] paths) - { - selectionModel.removeSelectionPaths(paths); - } + boolean oldValue = rootVisible; + rootVisible = flag; + firePropertyChange(ROOT_VISIBLE_PROPERTY, oldValue, flag); + } - public void removeSelectionRow(int row) - { - TreePath path = getPathForRow(row); + public boolean getShowsRootHandles() + { + return showsRootHandles; + } - if (path != null) - selectionModel.removeSelectionPath(path); - } + public void setShowsRootHandles(boolean flag) + { + if (showsRootHandles == flag) + return; + + boolean oldValue = showsRootHandles; + showsRootHandles = flag; + firePropertyChange(SHOWS_ROOT_HANDLES_PROPERTY, oldValue, flag); + } - public void removeSelectionRows(int[] rows) - { - if (rows == null || getUI() == null) - return; + public TreeCellEditor getCellEditor() + { + return cellEditor; + } - TreePath[] paths = new TreePath[rows.length]; + public void setCellEditor(TreeCellEditor editor) + { + if (cellEditor == editor) + return; - for (int i = rows.length - 1; i >= 0; --i) - paths[i] = getPathForRow(rows[i]); + TreeCellEditor oldValue = cellEditor; + cellEditor = editor; + firePropertyChange(CELL_EDITOR_PROPERTY, oldValue, editor); + } - removeSelectionPaths(paths); - } + public TreeCellRenderer getCellRenderer() + { + return cellRenderer; + } - public void removeSelectionInterval(int index0, int index1) - { - TreePath[] paths = getPathBetweenRows(index0, index1); + public void setCellRenderer(TreeCellRenderer newRenderer) + { + if (cellRenderer == newRenderer) + return; - if (paths != null) - removeSelectionPaths(paths); - } + TreeCellRenderer oldValue = cellRenderer; + cellRenderer = newRenderer; + firePropertyChange(CELL_RENDERER_PROPERTY, oldValue, newRenderer); + } - public void clearSelection() - { - selectionModel.clearSelection(); - setLeadSelectionPath(null); - } + public TreeSelectionModel getSelectionModel() + { + return selectionModel; + } - public TreePath getLeadSelectionPath() - { - return leadSelectionPath; - } + public void setSelectionModel(TreeSelectionModel model) + { + if (selectionModel == model) + return; - /** - * @since 1.3 - */ - public void setLeadSelectionPath(TreePath path) - { - if (leadSelectionPath == path) - return; - - TreePath oldValue = leadSelectionPath; - leadSelectionPath = path; - firePropertyChange(LEAD_SELECTION_PATH_PROPERTY, oldValue, path); - } - - /** - * @since 1.3 - */ - public TreePath getAnchorSelectionPath() - { - return anchorSelectionPath; - } + if (selectionModel != null) + selectionModel.removeTreeSelectionListener(selectionRedirector); - /** - * @since 1.3 - */ - public void setAnchorSelectionPath(TreePath path) - { - if (anchorSelectionPath == path) - return; - - TreePath oldValue = anchorSelectionPath; - anchorSelectionPath = path; - firePropertyChange(ANCHOR_SELECTION_PATH_PROPERTY, oldValue, path); - } - - public int getLeadSelectionRow() - { - return selectionModel.getLeadSelectionRow(); - } - - public int getMaxSelectionRow() - { - return selectionModel.getMaxSelectionRow(); - } - - public int getMinSelectionRow() - { - return selectionModel.getMinSelectionRow(); - } - - public int getSelectionCount() - { - return selectionModel.getSelectionCount(); - } - - public TreePath getSelectionPath() - { - return selectionModel.getSelectionPath(); - } - - public TreePath[] getSelectionPaths() - { - return selectionModel.getSelectionPaths(); - } - - public int[] getSelectionRows() - { - return selectionModel.getSelectionRows(); - } - - public boolean isPathSelected(TreePath path) - { - return selectionModel.isPathSelected(path); - } - - public boolean isRowSelected(int row) - { - return selectionModel.isPathSelected(getPathForRow(row)); - } - - public boolean isSelectionEmpty() - { - return selectionModel.isSelectionEmpty(); - } - - /** - * Return the value of the <code>dragEnabled</code> property. - * - * @return the value - * - * @since 1.4 - */ - public boolean getDragEnabled() - { - return dragEnabled; - } - - /** - * Set the <code>dragEnabled</code> property. - * - * @param enabled new value - * - * @since 1.4 - */ - public void setDragEnabled(boolean enabled) - { + TreeSelectionModel oldValue = selectionModel; + selectionModel = model; - dragEnabled = enabled; - } + if (selectionModel != null) + selectionModel.addTreeSelectionListener(selectionRedirector); - public int getRowCount() - { - TreeUI ui = getUI(); + firePropertyChange(SELECTION_MODEL_PROPERTY, oldValue, model); + revalidate(); + repaint(); + } - if (ui != null) - return ui.getRowCount(this); + public int getVisibleRowCount() + { + return visibleRowCount; + } - return 0; - } + public void setVisibleRowCount(int rows) + { + if (visibleRowCount == rows) + return; - public void collapsePath(TreePath path) - { - try - { - fireTreeWillCollapse(path); - } - catch (ExpandVetoException ev) - { - } - setExpandedState(path, false); - fireTreeCollapsed(path); - } + int oldValue = visibleRowCount; + visibleRowCount = rows; + firePropertyChange(VISIBLE_ROW_COUNT_PROPERTY, oldValue, rows); + } - public void collapseRow(int row) - { - if (row < 0 || row >= getRowCount()) - return; + public boolean isLargeModel() + { + return largeModel; + } - TreePath path = getPathForRow(row); + public void setLargeModel(boolean large) + { + if (largeModel == large) + return; - if (path != null) - collapsePath(path); - } + boolean oldValue = largeModel; + largeModel = large; + firePropertyChange(LARGE_MODEL_PROPERTY, oldValue, large); + } - public void expandPath(TreePath path) - { - // Don't expand if last path component is a leaf node. - if ((path == null) || (treeModel.isLeaf(path.getLastPathComponent()))) - return; - - try - { - fireTreeWillExpand(path); - } - catch (ExpandVetoException ev) - { - } - - setExpandedState(path, true); - fireTreeExpanded(path); - } + public int getRowHeight() + { + return rowHeight; + } + + public void setRowHeight(int height) + { + if (rowHeight == height) + return; + + int oldValue = rowHeight; + rowHeight = height; + firePropertyChange(ROW_HEIGHT_PROPERTY, oldValue, height); + } + + public boolean isFixedRowHeight() + { + return rowHeight > 0; + } + + public boolean getInvokesStopCellEditing() + { + return invokesStopCellEditing; + } + + public void setInvokesStopCellEditing(boolean invoke) + { + if (invokesStopCellEditing == invoke) + return; + + boolean oldValue = invokesStopCellEditing; + invokesStopCellEditing = invoke; + firePropertyChange(INVOKES_STOP_CELL_EDITING_PROPERTY, + oldValue, invoke); + } - public void expandRow(int row) - { - if (row < 0 || row >= getRowCount()) - return; + /** + * @since 1.3 + */ + public int getToggleClickCount() + { + return toggleClickCount; + } - TreePath path = getPathForRow(row); + /** + * @since 1.3 + */ + public void setToggleClickCount(int count) + { + if (toggleClickCount == count) + return; - if (path != null) - expandPath(path); - } + int oldValue = toggleClickCount; + toggleClickCount = count; + firePropertyChange(TOGGLE_CLICK_COUNT_PROPERTY, oldValue, count); + } - public boolean isCollapsed(TreePath path) - { - return !isExpanded(path); - } + public void scrollPathToVisible(TreePath path) + { + if (path == null) + return; - public boolean isCollapsed(int row) - { - if (row < 0 || row >= getRowCount()) - return false; + Rectangle rect = getPathBounds(path); - TreePath path = getPathForRow(row); + if (rect == null) + return; - if (path != null) - return isCollapsed(path); + scrollRectToVisible(rect); + } - return false; - } + public void scrollRowToVisible(int row) + { + scrollPathToVisible(getPathForRow(row)); + } - public boolean isExpanded(TreePath path) - { - if (path == null) - return false; + public boolean getScrollsOnExpand() + { + return scrollsOnExpand; + } - Object state = nodeStates.get(path); + public void setScrollsOnExpand(boolean scroll) + { + if (scrollsOnExpand == scroll) + return; - if ((state == null) || (state != EXPANDED)) - return false; + boolean oldValue = scrollsOnExpand; + scrollsOnExpand = scroll; + firePropertyChange(SCROLLS_ON_EXPAND_PROPERTY, oldValue, scroll); + } - TreePath parent = path.getParentPath(); + public void setSelectionPath(TreePath path) + { + selectionModel.setSelectionPath(path); + } - if (parent != null) - return isExpanded(parent); + public void setSelectionPaths(TreePath[] paths) + { + selectionModel.setSelectionPaths(paths); + } - return true; - } + public void setSelectionRow(int row) + { + TreePath path = getPathForRow(row); - public boolean isExpanded(int row) - { - if (row < 0 || row >= getRowCount()) - return false; + if (path != null) + selectionModel.setSelectionPath(path); + } - TreePath path = getPathForRow(row); + public void setSelectionRows(int[] rows) + { + // Make sure we have an UI so getPathForRow() does not return null. + if (rows == null || getUI() == null) + return; - if (path != null) - return isExpanded(path); + TreePath[] paths = new TreePath[rows.length]; - return false; - } + for (int i = rows.length - 1; i >= 0; --i) + paths[i] = getPathForRow(rows[i]); - /** - * @since 1.3 - */ - public boolean getExpandsSelectedPaths() - { - return expandsSelectedPaths; - } + setSelectionPaths(paths); + } - /** - * @since 1.3 - */ - public void setExpandsSelectedPaths(boolean flag) - { - if (expandsSelectedPaths == flag) - return; + public void setSelectionInterval(int index0, int index1) + { + TreePath[] paths = getPathBetweenRows(index0, index1); - boolean oldValue = expandsSelectedPaths; - expandsSelectedPaths = flag; - firePropertyChange(EXPANDS_SELECTED_PATHS_PROPERTY, oldValue, flag); - } + if (paths != null) + setSelectionPaths(paths); + } - public Rectangle getPathBounds(TreePath path) - { - TreeUI ui = getUI(); + public void addSelectionPath(TreePath path) + { + selectionModel.addSelectionPath(path); + } - if (ui == null) - return null; + public void addSelectionPaths(TreePath[] paths) + { + selectionModel.addSelectionPaths(paths); + } - return ui.getPathBounds(this, path); - } + public void addSelectionRow(int row) + { + TreePath path = getPathForRow(row); - public Rectangle getRowBounds(int row) - { - TreePath path = getPathForRow(row); + if (path != null) + selectionModel.addSelectionPath(path); + } - if (path != null) - return getPathBounds(path); + public void addSelectionRows(int[] rows) + { + // Make sure we have an UI so getPathForRow() does not return null. + if (rows == null || getUI() == null) + return; - return null; - } + TreePath[] paths = new TreePath[rows.length]; - public boolean isEditing() - { - TreeUI ui = getUI(); + for (int i = rows.length - 1; i >= 0; --i) + paths[i] = getPathForRow(rows[i]); - if (ui != null) - return ui.isEditing(this); + addSelectionPaths(paths); + } - return false; - } + public void addSelectionInterval(int index0, int index1) + { + TreePath[] paths = getPathBetweenRows(index0, index1); - public boolean stopEditing() - { - TreeUI ui = getUI(); + if (paths != null) + addSelectionPaths(paths); + } - if (ui != null) - return ui.stopEditing(this); + public void removeSelectionPath(TreePath path) + { + selectionModel.removeSelectionPath(path); + } - return false; - } + public void removeSelectionPaths(TreePath[] paths) + { + selectionModel.removeSelectionPaths(paths); + } - public void cancelEditing() - { - TreeUI ui = getUI(); + public void removeSelectionRow(int row) + { + TreePath path = getPathForRow(row); - if (ui != null) - ui.cancelEditing(this); - } + if (path != null) + selectionModel.removeSelectionPath(path); + } - public void startEditingAtPath(TreePath path) - { - TreeUI ui = getUI(); + public void removeSelectionRows(int[] rows) + { + if (rows == null || getUI() == null) + return; - if (ui != null) - ui.startEditingAtPath(this, path); - } + TreePath[] paths = new TreePath[rows.length]; - public TreePath getEditingPath() - { - TreeUI ui = getUI(); + for (int i = rows.length - 1; i >= 0; --i) + paths[i] = getPathForRow(rows[i]); - if (ui != null) - return ui.getEditingPath(this); + removeSelectionPaths(paths); + } - return null; - } + public void removeSelectionInterval(int index0, int index1) + { + TreePath[] paths = getPathBetweenRows(index0, index1); - public TreePath getPathForLocation(int x, int y) - { - TreePath path = getClosestPathForLocation(x, y); + if (paths != null) + removeSelectionPaths(paths); + } - if (path != null) - { - Rectangle rect = getPathBounds(path); + public void clearSelection() + { + selectionModel.clearSelection(); + setLeadSelectionPath(null); + } - if ((rect != null) && rect.contains(x, y)) - return path; - } + public TreePath getLeadSelectionPath() + { + return leadSelectionPath; + } - return null; - } + /** + * @since 1.3 + */ + public void setLeadSelectionPath(TreePath path) + { + if (leadSelectionPath == path) + return; + + TreePath oldValue = leadSelectionPath; + leadSelectionPath = path; + firePropertyChange(LEAD_SELECTION_PATH_PROPERTY, oldValue, path); + } - public int getRowForLocation(int x, int y) - { - TreePath path = getPathForLocation(x, y); + /** + * @since 1.3 + */ + public TreePath getAnchorSelectionPath() + { + return anchorSelectionPath; + } - if (path != null) - return getRowForPath(path); + /** + * @since 1.3 + */ + public void setAnchorSelectionPath(TreePath path) + { + if (anchorSelectionPath == path) + return; - return -1; - } + TreePath oldValue = anchorSelectionPath; + anchorSelectionPath = path; + firePropertyChange(ANCHOR_SELECTION_PATH_PROPERTY, oldValue, path); + } - public TreePath getClosestPathForLocation(int x, int y) - { - TreeUI ui = getUI(); + public int getLeadSelectionRow() + { + return selectionModel.getLeadSelectionRow(); + } - if (ui != null) - return ui.getClosestPathForLocation(this, x, y); + public int getMaxSelectionRow() + { + return selectionModel.getMaxSelectionRow(); + } - return null; - } + public int getMinSelectionRow() + { + return selectionModel.getMinSelectionRow(); + } - public int getClosestRowForLocation(int x, int y) - { - TreePath path = getClosestPathForLocation(x, y); + public int getSelectionCount() + { + return selectionModel.getSelectionCount(); + } + + public TreePath getSelectionPath() + { + return selectionModel.getSelectionPath(); + } + + public TreePath[] getSelectionPaths() + { + return selectionModel.getSelectionPaths(); + } - if (path != null) - return getRowForPath(path); + public int[] getSelectionRows() + { + return selectionModel.getSelectionRows(); + } - return -1; - } + public boolean isPathSelected(TreePath path) + { + return selectionModel.isPathSelected(path); + } - public Object getLastSelectedPathComponent() - { - TreePath path = getSelectionPath(); + public boolean isRowSelected(int row) + { + return selectionModel.isPathSelected(getPathForRow(row)); + } - if (path != null) - return path.getLastPathComponent(); + public boolean isSelectionEmpty() + { + return selectionModel.isSelectionEmpty(); + } - return null; - } + /** + * Return the value of the <code>dragEnabled</code> property. + * + * @return the value + * + * @since 1.4 + */ + public boolean getDragEnabled() + { + return dragEnabled; + } - private void doExpandParents(TreePath path, boolean state) - { - TreePath parent = path.getParentPath(); - - if (!isExpanded(parent) && parent != null) - doExpandParents(parent, false); + /** + * Set the <code>dragEnabled</code> property. + * + * @param enabled new value + * + * @since 1.4 + */ + public void setDragEnabled(boolean enabled) + { + dragEnabled = enabled; + } - nodeStates.put(path, state ? EXPANDED : COLLAPSED); - } + public int getRowCount() + { + TreeUI ui = getUI(); - protected void setExpandedState(TreePath path, boolean state) - { - if (path == null) - return; - TreePath parent = path.getParentPath(); + if (ui != null) + return ui.getRowCount(this); - doExpandParents(path, state); - } + return 0; + } - protected void clearToggledPaths() - { - nodeStates.clear(); - } + public void collapsePath(TreePath path) + { + try + { + fireTreeWillCollapse(path); + } + catch (ExpandVetoException ev) + { + } + setExpandedState(path, false); + fireTreeCollapsed(path); + } - protected Enumeration getDescendantToggledPaths(TreePath parent) - { - if (parent == null) - return null; + public void collapseRow(int row) + { + if (row < 0 || row >= getRowCount()) + return; - Enumeration nodes = nodeStates.keys(); - Vector result = new Vector(); + TreePath path = getPathForRow(row); - while (nodes.hasMoreElements()) - { - TreePath path = (TreePath) nodes.nextElement(); + if (path != null) + collapsePath(path); + } - if (path.isDescendant(parent)) - result.addElement(path); - } + public void expandPath(TreePath path) + { + // Don't expand if last path component is a leaf node. + if ((path == null) || (treeModel.isLeaf(path.getLastPathComponent()))) + return; + + try + { + fireTreeWillExpand(path); + } + catch (ExpandVetoException ev) + { + } + + setExpandedState(path, true); + fireTreeExpanded(path); + } - return result.elements(); - } + public void expandRow(int row) + { + if (row < 0 || row >= getRowCount()) + return; - public boolean hasBeenExpanded(TreePath path) - { - if (path == null) - return false; + TreePath path = getPathForRow(row); - return nodeStates.get(path) != null; - } + if (path != null) + expandPath(path); + } - public boolean isVisible(TreePath path) - { - if (path == null) - return false; + public boolean isCollapsed(TreePath path) + { + return !isExpanded(path); + } - TreePath parent = path.getParentPath(); + public boolean isCollapsed(int row) + { + if (row < 0 || row >= getRowCount()) + return false; - if (parent == null) - return true; // Is root node. + TreePath path = getPathForRow(row); - return isExpanded(parent); - } + if (path != null) + return isCollapsed(path); - public void makeVisible(TreePath path) - { - if (path == null) - return; + return false; + } - expandPath(path.getParentPath()); - } + public boolean isExpanded(TreePath path) + { + if (path == null) + return false; - public boolean isPathEditable(TreePath path) - { - return isEditable(); - } + Object state = nodeStates.get(path); - /** - * Creates and returns an instance of {@link TreeModelHandler}. - * - * @returns an instance of {@link TreeModelHandler} - */ - protected TreeModelListener createTreeModelListener() - { - return new TreeModelHandler(); - } - - /** - * Returns a sample TreeModel that can be used in a JTree. This can be used - * in Bean- or GUI-Builders to show something interesting. - * - * @return a sample TreeModel that can be used in a JTree - */ - protected static TreeModel getDefaultTreeModel() - { - DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root node"); - DefaultMutableTreeNode child1 = new DefaultMutableTreeNode( - "Child node 1"); - DefaultMutableTreeNode child11 = new DefaultMutableTreeNode( - "Child node 1.1"); - DefaultMutableTreeNode child12 = new DefaultMutableTreeNode( - "Child node 1.2"); - DefaultMutableTreeNode child13 = new DefaultMutableTreeNode( - "Child node 1.3"); - DefaultMutableTreeNode child2 = new DefaultMutableTreeNode( - "Child node 2"); - DefaultMutableTreeNode child21 = new DefaultMutableTreeNode( - "Child node 2.1"); - DefaultMutableTreeNode child22 = new DefaultMutableTreeNode( - "Child node 2.2"); - DefaultMutableTreeNode child23 = new DefaultMutableTreeNode( - "Child node 2.3"); - DefaultMutableTreeNode child24 = new DefaultMutableTreeNode( - "Child node 2.4"); - - DefaultMutableTreeNode child3 = new DefaultMutableTreeNode( - "Child node 3"); - root.add(child1); - root.add(child2); - root.add(child3); - child1.add(child11); - child1.add(child12); - child1.add(child13); - child2.add(child21); - child2.add(child22); - child2.add(child23); - child2.add(child24); - return new DefaultTreeModel(root); - } - - /** - * Converts the specified value to a String. This is used by the renderers - * of this JTree and its nodes. - * - * This implementation simply returns <code>value.toString()</code> and - * ignores all other parameters. Subclass this method to control the - * conversion. - * - * @param value the value that is converted to a String - * @param selected indicates if that value is selected or not - * @param expanded indicates if that value is expanded or not - * @param leaf indicates if that value is a leaf node or not - * @param row the row of the node - * @param hasFocus indicates if that node has focus or not - */ - public String convertValueToText(Object value, boolean selected, - boolean expanded, boolean leaf, int row, boolean hasFocus) - { - return value.toString(); - } - - /** - * A String representation of this JTree. This is intended to be used for - * debugging. The returned string may be empty but may not be - * <code>null</code>. - * - * @return a String representation of this JTree - */ - public String paramString() - { - // TODO: this is completely legal, but it would possibly be nice - // to return some more content, like the tree structure, some properties - // etc ... - return ""; - } - - /** - * Returns all TreePath objects which are a descendants of the given path - * and are exapanded at the moment of the execution of this method. If the - * state of any node is beeing toggled while this method is executing this - * change may be left unaccounted. - * - * @param path The parent of this request - * @return An Enumeration containing TreePath objects - */ - public Enumeration getExpandedDescendants(TreePath path) - { - Enumeration paths = nodeStates.keys(); - Vector relevantPaths = new Vector(); - while (paths.hasMoreElements()) - { - TreePath nextPath = (TreePath) paths.nextElement(); - if (nodeStates.get(nextPath) == EXPANDED - && path.isDescendant(nextPath)) - { - relevantPaths.add(nextPath); - } - } - return relevantPaths.elements(); - } - - /** - * Returns the next table element (beginning from the row - * <code>startingRow</code> that starts with <code>prefix</code>. - * Searching is done in the direction specified by <code>bias</code>. - * - * @param prefix the prefix to search for in the cell values - * @param startingRow the index of the row where to start searching from - * @param bias the search direction, either {@link Position.Bias#Forward} or - * {@link Position.Bias#Backward} - * - * @return the path to the found element or -1 if no such element has been - * found - * - * @throws IllegalArgumentException if prefix is <code>null</code> or - * startingRow is not valid - * - * @since 1.4 - */ - public TreePath getNextMatch(String prefix, int startingRow, - Position.Bias bias) - { - if (prefix == null) - throw new IllegalArgumentException( - "The argument 'prefix' must not be" + " null."); - if (startingRow < 0) - throw new IllegalArgumentException( - "The argument 'startingRow' must not" - + " be less than zero."); - - int size = getRowCount(); - if (startingRow > size) - throw new IllegalArgumentException( - "The argument 'startingRow' must not" - + " be greater than the number of" - + " elements in the TreeModel."); - - TreePath foundPath = null; - if (bias == Position.Bias.Forward) - { - for (int i = startingRow; i < size; i++) - { - TreePath path = getPathForRow(i); - Object o = path.getLastPathComponent(); - // FIXME: in the following call to convertValueToText the - // last argument (hasFocus) should be done right. - String item = convertValueToText(o, isRowSelected(i), - isExpanded(i), treeModel.isLeaf(o), i, false); - if (item.startsWith(prefix)) - { - foundPath = path; - break; - } - } - } else - { - for (int i = startingRow; i >= 0; i--) - { - TreePath path = getPathForRow(i); - Object o = path.getLastPathComponent(); - // FIXME: in the following call to convertValueToText the - // last argument (hasFocus) should be done right. - String item = convertValueToText(o, isRowSelected(i), - isExpanded(i), treeModel.isLeaf(o), i, false); - if (item.startsWith(prefix)) - { - foundPath = path; - break; - } - } - } - return foundPath; - } - - /** - * Removes any paths in the current set of selected paths that are - * descendants of <code>path</code>. If <code>includePath</code> is set - * to <code>true</code> and <code>path</code> itself is selected, then - * it will be removed too. - * - * @param path the path from which selected descendants are to be removed - * @param includeSelected if <code>true</code> then <code>path</code> itself - * will also be remove if it's selected - * - * @return <code>true</code> if something has been removed, - * <code>false</code> otherwise - * - * @since 1.3 - */ - protected boolean removeDescendantSelectedPaths(TreePath path, - boolean includeSelected) - { - boolean removedSomething = false; - TreePath[] selected = getSelectionPaths(); - for (int index = 0; index < selected.length; index++) - { - if ((selected[index] == path && includeSelected) - || (selected[index].isDescendant(path))) - { - removeSelectionPath(selected[index]); - removedSomething = true; - } - } - return removedSomething; - } + if ((state == null) || (state != EXPANDED)) + return false; + + TreePath parent = path.getParentPath(); + + if (parent != null) + return isExpanded(parent); + + return true; + } + + public boolean isExpanded(int row) + { + if (row < 0 || row >= getRowCount()) + return false; + + TreePath path = getPathForRow(row); + + if (path != null) + return isExpanded(path); + + return false; + } + + /** + * @since 1.3 + */ + public boolean getExpandsSelectedPaths() + { + return expandsSelectedPaths; + } + + /** + * @since 1.3 + */ + public void setExpandsSelectedPaths(boolean flag) + { + if (expandsSelectedPaths == flag) + return; + + boolean oldValue = expandsSelectedPaths; + expandsSelectedPaths = flag; + firePropertyChange(EXPANDS_SELECTED_PATHS_PROPERTY, oldValue, flag); + } + + public Rectangle getPathBounds(TreePath path) + { + TreeUI ui = getUI(); + + if (ui == null) + return null; + + return ui.getPathBounds(this, path); + } + + public Rectangle getRowBounds(int row) + { + TreePath path = getPathForRow(row); + + if (path != null) + return getPathBounds(path); + + return null; + } + + public boolean isEditing() + { + TreeUI ui = getUI(); + + if (ui != null) + return ui.isEditing(this); + + return false; + } + + public boolean stopEditing() + { + TreeUI ui = getUI(); + + if (ui != null) + return ui.stopEditing(this); + + return false; + } + + public void cancelEditing() + { + TreeUI ui = getUI(); + + if (ui != null) + ui.cancelEditing(this); + } + + public void startEditingAtPath(TreePath path) + { + TreeUI ui = getUI(); + + if (ui != null) + ui.startEditingAtPath(this, path); + } + + public TreePath getEditingPath() + { + TreeUI ui = getUI(); + + if (ui != null) + return ui.getEditingPath(this); + + return null; + } + + public TreePath getPathForLocation(int x, int y) + { + TreePath path = getClosestPathForLocation(x, y); + + if (path != null) + { + Rectangle rect = getPathBounds(path); + + if ((rect != null) && rect.contains(x, y)) + return path; + } + + return null; + } + + public int getRowForLocation(int x, int y) + { + TreePath path = getPathForLocation(x, y); + + if (path != null) + return getRowForPath(path); + + return -1; + } + + public TreePath getClosestPathForLocation(int x, int y) + { + TreeUI ui = getUI(); + + if (ui != null) + return ui.getClosestPathForLocation(this, x, y); + + return null; + } + + public int getClosestRowForLocation(int x, int y) + { + TreePath path = getClosestPathForLocation(x, y); + + if (path != null) + return getRowForPath(path); + + return -1; + } + + public Object getLastSelectedPathComponent() + { + TreePath path = getSelectionPath(); + + if (path != null) + return path.getLastPathComponent(); + + return null; + } + + private void doExpandParents(TreePath path, boolean state) + { + TreePath parent = path.getParentPath(); + + if (!isExpanded(parent) && parent != null) + doExpandParents(parent, false); + + nodeStates.put(path, state ? EXPANDED : COLLAPSED); + } + + protected void setExpandedState(TreePath path, boolean state) + { + if (path == null) + return; + TreePath parent = path.getParentPath(); + + doExpandParents(path, state); + } + + protected void clearToggledPaths() + { + nodeStates.clear(); + } + + protected Enumeration getDescendantToggledPaths(TreePath parent) + { + if (parent == null) + return null; + + Enumeration nodes = nodeStates.keys(); + Vector result = new Vector(); + + while (nodes.hasMoreElements()) + { + TreePath path = (TreePath) nodes.nextElement(); + + if (path.isDescendant(parent)) + result.addElement(path); + } + + return result.elements(); + } + + public boolean hasBeenExpanded(TreePath path) + { + if (path == null) + return false; + + return nodeStates.get(path) != null; + } + + public boolean isVisible(TreePath path) + { + if (path == null) + return false; + + TreePath parent = path.getParentPath(); + + if (parent == null) + return true; // Is root node. + + return isExpanded(parent); + } + + public void makeVisible(TreePath path) + { + if (path == null) + return; + + expandPath(path.getParentPath()); + } + + public boolean isPathEditable(TreePath path) + { + return isEditable(); + } + + /** + * Creates and returns an instance of {@link TreeModelHandler}. + * + * @return an instance of {@link TreeModelHandler} + */ + protected TreeModelListener createTreeModelListener() + { + return new TreeModelHandler(); + } + + /** + * Returns a sample TreeModel that can be used in a JTree. This can be used + * in Bean- or GUI-Builders to show something interesting. + * + * @return a sample TreeModel that can be used in a JTree + */ + protected static TreeModel getDefaultTreeModel() + { + DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root node"); + DefaultMutableTreeNode child1 = new DefaultMutableTreeNode("Child node 1"); + DefaultMutableTreeNode child11 = + new DefaultMutableTreeNode("Child node 1.1"); + DefaultMutableTreeNode child12 = + new DefaultMutableTreeNode("Child node 1.2"); + DefaultMutableTreeNode child13 = + new DefaultMutableTreeNode("Child node 1.3"); + DefaultMutableTreeNode child2 = new DefaultMutableTreeNode("Child node 2"); + DefaultMutableTreeNode child21 = + new DefaultMutableTreeNode("Child node 2.1"); + DefaultMutableTreeNode child22 = + new DefaultMutableTreeNode("Child node 2.2"); + DefaultMutableTreeNode child23 = + new DefaultMutableTreeNode("Child node 2.3"); + DefaultMutableTreeNode child24 = + new DefaultMutableTreeNode("Child node 2.4"); + + DefaultMutableTreeNode child3 = new DefaultMutableTreeNode("Child node 3"); + root.add(child1); + root.add(child2); + root.add(child3); + child1.add(child11); + child1.add(child12); + child1.add(child13); + child2.add(child21); + child2.add(child22); + child2.add(child23); + child2.add(child24); + return new DefaultTreeModel(root); + } + + /** + * Converts the specified value to a String. This is used by the renderers + * of this JTree and its nodes. + * + * This implementation simply returns <code>value.toString()</code> and + * ignores all other parameters. Subclass this method to control the + * conversion. + * + * @param value the value that is converted to a String + * @param selected indicates if that value is selected or not + * @param expanded indicates if that value is expanded or not + * @param leaf indicates if that value is a leaf node or not + * @param row the row of the node + * @param hasFocus indicates if that node has focus or not + */ + public String convertValueToText(Object value, boolean selected, + boolean expanded, boolean leaf, int row, boolean hasFocus) + { + return value.toString(); + } + + /** + * A String representation of this JTree. This is intended to be used for + * debugging. The returned string may be empty but may not be + * <code>null</code>. + * + * @return a String representation of this JTree + */ + public String paramString() + { + // TODO: this is completely legal, but it would possibly be nice + // to return some more content, like the tree structure, some properties + // etc ... + return ""; + } + + /** + * Returns all TreePath objects which are a descendants of the given path + * and are exapanded at the moment of the execution of this method. If the + * state of any node is beeing toggled while this method is executing this + * change may be left unaccounted. + * + * @param path The parent of this request + * + * @return An Enumeration containing TreePath objects + */ + public Enumeration getExpandedDescendants(TreePath path) + { + Enumeration paths = nodeStates.keys(); + Vector relevantPaths = new Vector(); + while (paths.hasMoreElements()) + { + TreePath nextPath = (TreePath) paths.nextElement(); + if (nodeStates.get(nextPath) == EXPANDED + && path.isDescendant(nextPath)) + { + relevantPaths.add(nextPath); + } + } + return relevantPaths.elements(); + } + + /** + * Returns the next table element (beginning from the row + * <code>startingRow</code> that starts with <code>prefix</code>. + * Searching is done in the direction specified by <code>bias</code>. + * + * @param prefix the prefix to search for in the cell values + * @param startingRow the index of the row where to start searching from + * @param bias the search direction, either {@link Position.Bias#Forward} or + * {@link Position.Bias#Backward} + * + * @return the path to the found element or -1 if no such element has been + * found + * + * @throws IllegalArgumentException if prefix is <code>null</code> or + * startingRow is not valid + * + * @since 1.4 + */ + public TreePath getNextMatch(String prefix, int startingRow, + Position.Bias bias) + { + if (prefix == null) + throw new IllegalArgumentException("The argument 'prefix' must not be" + + " null."); + if (startingRow < 0) + throw new IllegalArgumentException("The argument 'startingRow' must not" + + " be less than zero."); + + int size = getRowCount(); + if (startingRow > size) + throw new IllegalArgumentException("The argument 'startingRow' must not" + + " be greater than the number of" + + " elements in the TreeModel."); + + TreePath foundPath = null; + if (bias == Position.Bias.Forward) + { + for (int i = startingRow; i < size; i++) + { + TreePath path = getPathForRow(i); + Object o = path.getLastPathComponent(); + // FIXME: in the following call to convertValueToText the + // last argument (hasFocus) should be done right. + String item = convertValueToText(o, isRowSelected(i), + isExpanded(i), treeModel.isLeaf(o), + i, false); + if (item.startsWith(prefix)) + { + foundPath = path; + break; + } + } + } + else + { + for (int i = startingRow; i >= 0; i--) + { + TreePath path = getPathForRow(i); + Object o = path.getLastPathComponent(); + // FIXME: in the following call to convertValueToText the + // last argument (hasFocus) should be done right. + String item = convertValueToText(o, isRowSelected(i), + isExpanded(i), treeModel.isLeaf(o), i, false); + if (item.startsWith(prefix)) + { + foundPath = path; + break; + } + } + } + return foundPath; + } + + /** + * Removes any paths in the current set of selected paths that are + * descendants of <code>path</code>. If <code>includePath</code> is set + * to <code>true</code> and <code>path</code> itself is selected, then + * it will be removed too. + * + * @param path the path from which selected descendants are to be removed + * @param includeSelected if <code>true</code> then <code>path</code> itself + * will also be remove if it's selected + * + * @return <code>true</code> if something has been removed, + * <code>false</code> otherwise + * + * @since 1.3 + */ + protected boolean removeDescendantSelectedPaths(TreePath path, + boolean includeSelected) + { + boolean removedSomething = false; + TreePath[] selected = getSelectionPaths(); + for (int index = 0; index < selected.length; index++) + { + if ((selected[index] == path && includeSelected) + || (selected[index].isDescendant(path))) + { + removeSelectionPath(selected[index]); + removedSomething = true; + } + } + return removedSomething; + } + + /** + * Removes any descendants of the TreePaths in toRemove that have been + * expanded. + * + * @param toRemove - Enumeration of TreePaths that need to be removed from + * cache of toggled tree paths. + */ + protected void removeDescendantToggledPaths(Enumeration toRemove) + { + while (toRemove.hasMoreElements()) + { + TreePath current = (TreePath) toRemove.nextElement(); + Enumeration descendants = getDescendantToggledPaths(current); + + while (descendants.hasMoreElements()) + { + TreePath currentDes = (TreePath) descendants.nextElement(); + if (isExpanded(currentDes)) + nodeStates.remove(currentDes); + } + } + } + + /** + * Sent when the tree has changed enough that we need to resize the bounds, + * but not enough that we need to remove the expanded node set (e.g nodes + * were expanded or collapsed, or nodes were inserted into the tree). You + * should never have to invoke this, the UI will invoke this as it needs to. + */ + public void treeDidChange() + { + repaint(); + } } diff --git a/javax/swing/JViewport.java b/javax/swing/JViewport.java index a1ec80e46..a02fedd08 100644 --- a/javax/swing/JViewport.java +++ b/javax/swing/JViewport.java @@ -282,9 +282,14 @@ public class JViewport extends JComponent implements Accessible viewSize = newSize; Component view = getView(); if (view != null) - view.setSize(viewSize); + { + if (newSize != view.getSize()) + { + view.setSize(viewSize); + fireStateChanged(); + } + } isViewSizeSet = true; - fireStateChanged(); } /** @@ -314,6 +319,7 @@ public class JViewport extends JComponent implements Accessible { Point q = new Point(-p.x, -p.y); view.setLocation(q); + isViewSizeSet = false; fireStateChanged(); } } diff --git a/javax/swing/ListCellRenderer.java b/javax/swing/ListCellRenderer.java index 6ce115ea7..e234d184d 100644 --- a/javax/swing/ListCellRenderer.java +++ b/javax/swing/ListCellRenderer.java @@ -44,9 +44,7 @@ import java.awt.Component; */ public interface ListCellRenderer { - Component getListCellRendererComponent(JList list, - Object value, - int index, - boolean isSelected, - boolean cellHasFocus); + Component getListCellRendererComponent(JList list, Object value, int index, + boolean isSelected, + boolean cellHasFocus); } diff --git a/javax/swing/ListSelectionModel.java b/javax/swing/ListSelectionModel.java index f4680d737..324c05643 100644 --- a/javax/swing/ListSelectionModel.java +++ b/javax/swing/ListSelectionModel.java @@ -46,41 +46,51 @@ import javax.swing.event.ListSelectionListener; */ public interface ListSelectionModel { + int SINGLE_SELECTION = 0; + int SINGLE_INTERVAL_SELECTION = 1; + int MULTIPLE_INTERVAL_SELECTION = 2; void setSelectionMode(int a); + int getSelectionMode(); - + void clearSelection(); - + int getMinSelectionIndex(); + int getMaxSelectionIndex(); boolean isSelectedIndex(int a); boolean isSelectionEmpty(); + void setSelectionInterval(int index0, int index1); - void addSelectionInterval(int index0, - int index1); - void removeSelectionInterval(int index0, - int index1); - void insertIndexInterval(int index, - int length, - boolean before); - void removeIndexInterval(int index0, - int index1); + + void addSelectionInterval(int index0, int index1); + + void removeSelectionInterval(int index0, int index1); + + void insertIndexInterval(int index, int length, boolean before); + + void removeIndexInterval(int index0, int index1); int getAnchorSelectionIndex(); + void setAnchorSelectionIndex(int index); + int getLeadSelectionIndex(); + void setLeadSelectionIndex(int index); void setValueIsAdjusting(boolean valueIsAdjusting); + boolean getValueIsAdjusting(); void addListSelectionListener(ListSelectionListener listener); - void removeListSelectionListener(ListSelectionListener listener); + + void removeListSelectionListener(ListSelectionListener listener); } diff --git a/javax/swing/MenuElement.java b/javax/swing/MenuElement.java index 46eb8c2a5..dab7b9cf1 100644 --- a/javax/swing/MenuElement.java +++ b/javax/swing/MenuElement.java @@ -47,47 +47,43 @@ import java.awt.event.MouseEvent; * * @author Andrew Selkirk */ -public interface MenuElement { - - //------------------------------------------------------------- - // Methods ---------------------------------------------------- - //------------------------------------------------------------- - - /** - * processMouseEvent - * @param event TODO - * @param path TODO - * @param manager TODO - */ - void processMouseEvent(MouseEvent event, - MenuElement[] path, MenuSelectionManager manager); - - /** - * processKeyEvent - * @param event TODO - * @param path TODO - * @param manager TODO - */ - void processKeyEvent(KeyEvent event, - MenuElement[] path, MenuSelectionManager manager); - - /** - * menuSelectionChanged - * @param included TODO - */ - void menuSelectionChanged(boolean included); - - /** - * getSubElements - * @returns MenuElement[] - */ - MenuElement[] getSubElements(); - - /** - * getComponent - * @returns Component - */ - Component getComponent(); - - -} // MenuElement +public interface MenuElement +{ + + /** + * processMouseEvent + * @param event TODO + * @param path TODO + * @param manager TODO + */ + void processMouseEvent(MouseEvent event, MenuElement[] path, + MenuSelectionManager manager); + + /** + * processKeyEvent + * @param event TODO + * @param path TODO + * @param manager TODO + */ + void processKeyEvent(KeyEvent event, MenuElement[] path, + MenuSelectionManager manager); + + /** + * menuSelectionChanged + * @param included TODO + */ + void menuSelectionChanged(boolean included); + + /** + * getSubElements + * @returns MenuElement[] + */ + MenuElement[] getSubElements(); + + /** + * getComponent + * @returns Component + */ + Component getComponent(); + +} diff --git a/javax/swing/MenuSelectionManager.java b/javax/swing/MenuSelectionManager.java index 32d56b958..4e5275106 100644 --- a/javax/swing/MenuSelectionManager.java +++ b/javax/swing/MenuSelectionManager.java @@ -146,7 +146,9 @@ public class MenuSelectionManager { // Convert sourcePoint to screen coordinates. Point sourcePointOnScreen = sourcePoint; - SwingUtilities.convertPointToScreen(sourcePointOnScreen, source); + + if (source.isShowing()) + SwingUtilities.convertPointToScreen(sourcePointOnScreen, source); Point compPointOnScreen; Component resultComp = null; @@ -168,7 +170,10 @@ public class MenuSelectionManager && sourcePointOnScreen.y < compPointOnScreen.y + size.height) { Point p = sourcePointOnScreen; - SwingUtilities.convertPointFromScreen(p, comp); + + if (comp.isShowing()) + SwingUtilities.convertPointFromScreen(p, comp); + resultComp = SwingUtilities.getDeepestComponentAt(comp, p.x, p.y); break; } diff --git a/javax/swing/OverlayLayout.java b/javax/swing/OverlayLayout.java index e8aef98a5..143fecbef 100644 --- a/javax/swing/OverlayLayout.java +++ b/javax/swing/OverlayLayout.java @@ -48,144 +48,139 @@ import java.io.Serializable; * @author Andrew Selkirk * @version 1.0 */ -public class OverlayLayout - implements LayoutManager2, Serializable +public class OverlayLayout implements LayoutManager2, Serializable { private static final long serialVersionUID = 18082829169631543L; - //------------------------------------------------------------- - // Variables -------------------------------------------------- - //------------------------------------------------------------- - - /** - * target - */ - private Container target; - - /** - * xChildren - */ - private SizeRequirements[] xChildren; - - /** - * yChildren - */ - private SizeRequirements[] yChildren; - - /** - * xTotal - */ - private SizeRequirements xTotal; - - /** - * yTotal - */ - private SizeRequirements yTotal; - - - //------------------------------------------------------------- - // Initialization --------------------------------------------- - //------------------------------------------------------------- - - /** - * Constructor OverlayLayout - * @param target TODO - */ - public OverlayLayout(Container target) { - // TODO - } // OverlayLayout() - - - //------------------------------------------------------------- - // Methods ---------------------------------------------------- - //------------------------------------------------------------- - - /** - * invalidateLayout - * @param target TODO - */ - public void invalidateLayout(Container target) { - // TODO - } // invalidateLayout() - - /** - * addLayoutComponent - * @param string TODO - * @param component TODO - */ - public void addLayoutComponent(String string, Component component) { - // TODO - } // addLayoutComponent() - - /** - * addLayoutComponent - * @param component TODO - * @param constraints TODO - */ - public void addLayoutComponent(Component component, Object constraints) { - // TODO - } // addLayoutComponent() - - /** - * removeLayoutComponent - * @param component TODO - */ - public void removeLayoutComponent(Component component) { - // TODO - } // removeLayoutComponent() - - /** - * preferredLayoutSize - * @param target TODO - * @returns Dimension - */ - public Dimension preferredLayoutSize(Container target) { - return null; // TODO - } // preferredLayoutSize() - - /** - * minimumLayoutSize - * @param target TODO - * @returns Dimension - */ - public Dimension minimumLayoutSize(Container target) { - return null; // TODO - } // minimumLayoutSize() - - /** - * maximumLayoutSize - * @param target TODO - * @returns Dimension - */ - public Dimension maximumLayoutSize(Container target) { - return null; // TODO - } // maximumLayoutSize() - - /** - * getLayoutAlignmentX - * @param target TODO - * @returns float - */ - public float getLayoutAlignmentX(Container target) { - return (float) 0.0; // TODO - } // getLayoutAlignmentX() - - /** - * getLayoutAlignmentY - * @param target TODO - * @returns float - */ - public float getLayoutAlignmentY(Container target) { - return (float) 0.0; // TODO - } // getLayoutAlignmentY() - - /** - * layoutContainer - * @param target TODO - */ - public void layoutContainer(Container target) { - // TODO - } // layoutContainer() - - -} // OverlayLayout + /** + * target + */ + private Container target; + + /** + * xChildren + */ + private SizeRequirements[] xChildren; + + /** + * yChildren + */ + private SizeRequirements[] yChildren; + + /** + * xTotal + */ + private SizeRequirements xTotal; + + /** + * yTotal + */ + private SizeRequirements yTotal; + + /** + * Constructor OverlayLayout + * @param target TODO + */ + public OverlayLayout(Container target) + { + // TODO + } + + /** + * invalidateLayout + * @param target TODO + */ + public void invalidateLayout(Container target) + { + // TODO + } + + /** + * addLayoutComponent + * @param string TODO + * @param component TODO + */ + public void addLayoutComponent(String string, Component component) + { + // TODO + } + + /** + * addLayoutComponent + * @param component TODO + * @param constraints TODO + */ + public void addLayoutComponent(Component component, Object constraints) + { + // TODO + } + + /** + * removeLayoutComponent + * @param component TODO + */ + public void removeLayoutComponent(Component component) + { + // TODO + } + + /** + * preferredLayoutSize + * @param target TODO + * @returns Dimension + */ + public Dimension preferredLayoutSize(Container target) + { + return null; // TODO + } + + /** + * minimumLayoutSize + * @param target TODO + * @returns Dimension + */ + public Dimension minimumLayoutSize(Container target) + { + return null; // TODO + } + + /** + * maximumLayoutSize + * @param target TODO + * @returns Dimension + */ + public Dimension maximumLayoutSize(Container target) + { + return null; // TODO + } + + /** + * getLayoutAlignmentX + * @param target TODO + * @returns float + */ + public float getLayoutAlignmentX(Container target) + { + return (float) 0.0; // TODO + } + + /** + * getLayoutAlignmentY + * @param target TODO + * @returns float + */ + public float getLayoutAlignmentY(Container target) + { + return (float) 0.0; // TODO + } + + /** + * layoutContainer + * @param target TODO + */ + public void layoutContainer(Container target) + { + // TODO + } + +} diff --git a/javax/swing/ProgressMonitor.java b/javax/swing/ProgressMonitor.java index 844258f1b..60f1c7145 100644 --- a/javax/swing/ProgressMonitor.java +++ b/javax/swing/ProgressMonitor.java @@ -1,5 +1,5 @@ /* ProgressMonitor.java -- - Copyright (C) 2002, 2004 Free Software Foundation, Inc. + Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -38,191 +38,386 @@ exception statement from your version. */ package javax.swing; import java.awt.Component; +import java.awt.event.ActionListener; +import java.awt.event.ActionEvent; /** - * ProgressMonitor - * @author Andrew Selkirk - * @version 1.0 + * <p>Using this class you can easily monitor tasks where you cannot + * estimate the duration exactly.</p> + * + * <p>A ProgressMonitor instance waits until the first time setProgress + * is called. When <code>millisToDecideToPopup</code> time elapsed the + * instance estimates the duration until the whole operation is completed. + * If this duration exceeds <code>millisToPopup</code> a non-modal dialog + * with a message and a progress bar is shown.</p> + * + * <p>The value of <code>millisToDecideToPopup</code> defaults to + * <code>500</code> and <code>millisToPopup</code> to + * <code>2000</code>.</p> + * + * @author Andrew Selkirk + * @author Robert Schuster (robertschuster@fsfe.org) + * @since 1.2 + * @status updated to 1.2 */ -public class ProgressMonitor { - - //------------------------------------------------------------- - // Variables -------------------------------------------------- - //------------------------------------------------------------- - - /** - * parentComponent - */ - private Component component; - - /** - * note - */ - private String note; - - /** - * message - */ - private Object message; - - /** - * millisToDecideToPopup - */ - private int millisToDecideToPopup; - - /** - * millisToPopup - */ - private int millisToPopup; - - /** - * min - */ - private int minimum; - - /** - * max - */ - private int maximum; - - - //------------------------------------------------------------- - // Initialization --------------------------------------------- - //------------------------------------------------------------- - - /** - * Constructor ProgressMonitor - * @param component TODO - * @param message TODO - * @param note TODO - * @param minimum TODO - * @param maximum TODO - */ - public ProgressMonitor(Component component, Object message, - String note, int minimum, int maximum) { - - // Set Data - this.component = component; - this.message = message; - this.note = note; - this.minimum = minimum; - this.maximum = maximum; - - // TODO - } // ProgressMonitor() - - - //------------------------------------------------------------- - // Methods ---------------------------------------------------- - //------------------------------------------------------------- - - /** - * close - */ - public void close() { - // TODO - } // close() - - /** - * setProgress - * @param progress TODO - */ - public void setProgress(int progress) { - // TODO - } // setProgress() - - /** - * getMinimum - * @returns int - */ - public int getMinimum() { - return minimum; // TODO - } // getMinimum() - - /** - * setMinimum - * @param minimum TODO - */ - public void setMinimum(int minimum) { - this.minimum = minimum; - // TODO - } // setMinimum() - - /** - * getMaximum - * @returns int - */ - public int getMaximum() { - return maximum; // TODO - } // getMaximum() - - /** - * setMaximum - * @param maximum TODO - */ - public void setMaximum(int maximum) { - this.maximum = maximum; - // TODO - } // setMaximum() - - /** - * isCanceled - * @returns boolean - */ - public boolean isCanceled() { - return false; // TODO - } // isCanceled() - - /** - * getMillisToDecideToPopup - * @returns int - */ - public int getMillisToDecideToPopup() { - return millisToDecideToPopup; // TODO - } // getMillisToDecideToPopup() - - /** - * setMillisToDecideToPopup - * @param time TODO - */ - public void setMillisToDecideToPopup(int time) { - millisToDecideToPopup = time; - // TODO - } // setMillisToDecideToPopup() - - /** - * getMillisToPopup - * @returns int - */ - public int getMillisToPopup() { - return millisToPopup; // TODO - } // getMillisToPopup() - - /** - * setMillisToPopup - * @param time TODO - */ - public void setMillisToPopup(int time) { - millisToPopup = time; - // TODO - } // setMillisToPopup() - - /** - * getNote - * @returns String - */ - public String getNote() { - return note; // TODO - } // getNote() - - /** - * setNote - * @param note TODO - */ - public void setNote(String note) { - this.note = note; - // TODO - } // setNote() - - -} // ProgressMonitor +public class ProgressMonitor +{ + /** + * parentComponent + */ + Component component; + + /** + * note + */ + String note; + + /** + * message + */ + Object message; + + /** + * millisToDecideToPopup + */ + int millisToDecideToPopup = 500; + + /** + * millisToPopup + */ + int millisToPopup = 2000; + + int min, max, progress; + + JProgressBar progressBar; + + JLabel noteLabel; + + JDialog progressDialog; + + Timer timer; + + boolean canceled; + + /** + * Constructor ProgressMonitor + * @param component The parent component of the progress dialog or <code>null</code>. + * @param message A constant message object which works in the way it does in <code>JOptionPane</code>. + * @param note A string message which can be changed while the operation goes on. + * @param minimum The minimum value for the operation (start value). + * @param maximum The maximum value for the operation (end value). + */ + public ProgressMonitor(Component component, Object message, + String note, int minimum, int maximum) + { + + // Set data. + this.component = component; + this.message = message; + this.note = note; + + min = minimum; + max = maximum; + } + + /** + * <p>Hides the dialog and stops any measurements.</p> + * + * <p>Has no effect when <code>setProgress</code> is not at least + * called once.</p> + */ + public void close() + { + if ( progressDialog != null ) + { + progressDialog.setVisible(false); + } + + if ( timer != null ) + { + timer.stop(); + timer = null; + } + } + + /** + * <p>Updates the progress value.</p> + * + * <p>When called for the first time this initializes a timer + * which decides after <code>millisToDecideToPopup</code> time + * whether to show a progress dialog or not.</p> + * + * <p>If the progress value equals or exceeds the maximum + * value the progress dialog is closed automatically.</p> + * + * @param progress New progress value. + */ + public void setProgress(int progress) + { + this.progress = progress; + + // Initializes and starts a timer with a task + // which measures the duration and displays + // a progress dialog if neccessary. + if ( timer == null && progressDialog == null ) + { + timer = new Timer(25, null); + timer.addActionListener(new TimerListener()); + timer.start(); + } + + // Cancels timer and hides progress dialog if the + // maximum value is reached. + if ( progressBar != null && this.progress >= progressBar.getMaximum() ) + { + // The reason for using progressBar.getMaximum() instead of max is that + // we want to prevent that changes to the value have any effect after the + // progress dialog is visible (This is how the JDK behaves.). + close(); + } + + } + + /** Returns the minimum or start value of the operation. + * + * @returns Minimum or start value of the operation. + */ + public int getMinimum() + { + return min; + } + + /** + * <p>Use this method to set the minimum or start value of + * your operation.</p> + * + * <p>For typical application like copy operation this will be + * zero.</p> + * + * <p>Keep in mind that changing this value after the progress + * dialog is made visible has no effect upon the progress bar.</p> + * + * @param minimum The new minimum value. + */ + public void setMinimum(int minimum) + { + min = minimum; + } + + /** + * Return the maximum or end value of your operation. + * + * @returns Maximum or end value. + */ + public int getMaximum() + { + return max; + } + + /** + * <p>Sets the maximum or end value of the operation to the + * given integer.</p> + * + * @param maximum + */ + public void setMaximum(int maximum) + { + max = maximum; + } + + /** + * Returns whether the user canceled the operation. + * + * @returns Whether the operation was canceled. + */ + public boolean isCanceled() + { + // The value is predefined to false + // and changes only when the user clicks + // the cancel button in the progress dialog. + return canceled; + } + + /** + * Returns the amount of milliseconds to wait + * until the ProgressMonitor should decide whether + * a progress dialog is to be shown or not. + * + * @returns The duration in milliseconds. + */ + public int getMillisToDecideToPopup() + { + return millisToDecideToPopup; + } + + /** + * Sets the amount of milliseconds to wait until the + * ProgressMonitor should decide whether a progress dialog + * is to be shown or not. + * + * <p>This method has no effect when the progress dialog + * is already visible.</p> + * + * @param time The duration in milliseconds. + */ + public void setMillisToDecideToPopup(int time) + { + millisToDecideToPopup = time; + } + + /** + * getMillisToPopup + * @returns int + */ + public int getMillisToPopup() + { + return millisToPopup; + } + + /** + * setMillisToPopup + * @param time TODO + */ + public void setMillisToPopup(int time) + { + millisToPopup = time; + } + + /** + * Returns a message which is shown in the progress dialog. + * + * @returns The changeable message visible in the progress dialog. + */ + public String getNote() + { + return note; + } + + /** + * <p>Set the message shown in the progess dialog.</p> + * + * <p>Changing the note while the progress dialog is visible + * is possible.</p> + * + * @param note A message shown in the progress dialog. + */ + public void setNote(String note) + { + if ( noteLabel != null ) + { + noteLabel.setText(note); + } + else + { + this.note = note; + } + } + + /** Internal method that creates the progress dialog. + */ + void createDialog() + { + // If there is no note we suppress the generation of the + // label. + Object[] tmp = (note == null) ? + new Object[] + { + message, + progressBar = new JProgressBar(min, max) + } + : + new Object[] + { + message, + noteLabel = new JLabel(note), + progressBar = new JProgressBar(min, max) + }; + + JOptionPane pane = new JOptionPane(tmp, JOptionPane.INFORMATION_MESSAGE); + + // FIXME: Internationalize the button + JButton cancelButton = new JButton("Cancel"); + cancelButton.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent ae) + { + canceled = true; + } + }); + + pane.setOptions(new Object[] { cancelButton }); + + // FIXME: Internationalize the title + progressDialog = pane.createDialog(component, "Progress ..."); + progressDialog.setModal(false); + progressDialog.setResizable(true); + + progressDialog.pack(); + progressDialog.setVisible(true); + + } + + /** An ActionListener implementation which does the measurements + * and estimations of the ProgressMonitor. + */ + class TimerListener implements ActionListener + { + long timestamp; + + int lastProgress; + + boolean first = true; + + TimerListener() + { + timestamp = System.currentTimeMillis(); + } + + public void actionPerformed(ActionEvent ae) + { + long now = System.currentTimeMillis(); + + if ( first ) + { + if (( now - timestamp ) > millisToDecideToPopup ) + { + first = false; + long expected = ( now - timestamp ) * ( max - min ) / ( progress - min ); + + if ( expected > millisToPopup ) + { + createDialog(); + } + } + else + { + // We have not waited long enough to make a decision, + // so return and try again when the timer is invoked. + return; + } + } + else if ( progressDialog != null ) + { + // The progress dialog is being displayed. We now calculate + // whether setting the progress bar to the current progress + // value would result in a visual difference. + int delta = progress - progressBar.getValue(); + + if ( ( delta * progressBar.getWidth() / (max - min) ) > 0 ) + { + // At least one pixel would change. + progressBar.setValue(progress); + } + } + else + { + // No dialog necessary + timer.stop(); + timer = null; + } + + timestamp = now; + } + } + +} diff --git a/javax/swing/ProgressMonitorInputStream.java b/javax/swing/ProgressMonitorInputStream.java index 2022a1c24..02ac597b3 100644 --- a/javax/swing/ProgressMonitorInputStream.java +++ b/javax/swing/ProgressMonitorInputStream.java @@ -1,5 +1,5 @@ /* ProgressMonitorInputStream.java -- - Copyright (C) 2002, 2004 Free Software Foundation, Inc. + Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -39,122 +39,187 @@ exception statement from your version. */ package javax.swing; import java.awt.Component; + import java.io.FilterInputStream; -import java.io.IOException; import java.io.InputStream; +import java.io.InterruptedIOException; +import java.io.IOException; /** * ProgressMonitorInputStream * @author Andrew Selkirk - * @version 1.0 + * @author Robert Schuster (robertschuster@fsfe.org) + * @status updated to 1.2 + * @since 1.2 */ -public class ProgressMonitorInputStream extends FilterInputStream { - - //------------------------------------------------------------- - // Variables -------------------------------------------------- - //------------------------------------------------------------- - - /** - * monitor - */ - private ProgressMonitor monitor; - - /** - * nread - */ - private int nread; - - /** - * size - */ - private int size; - - - //------------------------------------------------------------- - // Initialization --------------------------------------------- - //------------------------------------------------------------- - - /** - * Constructor ProgressMonitorInputStream - * @param component TODO - * @param message TODO - * @param stream TODO - */ - public ProgressMonitorInputStream(Component component, Object message, - InputStream stream) { - super(stream); - // TODO - } // ProgressMonitorInputStream() - - - //------------------------------------------------------------- - // Methods ---------------------------------------------------- - //------------------------------------------------------------- - - /** - * reset - * @exception IOException TODO - */ - public synchronized void reset() throws IOException { - // TODO - } // reset() - - /** - * read - * @exception IOException TODO - * @returns int - */ - public int read() throws IOException { - return 0; // TODO - } // read() - - /** - * read - * @param data TODO - * @exception IOException TODO - * @returns int - */ - public int read(byte[] data) throws IOException { - return 0; // TODO - } // read() - - /** - * read - * @param data TODO - * @param offset TODO - * @param length TODO - * @exception IOException TODO - * @returns int - */ - public int read(byte[] data, int offset, int length) throws IOException { - return 0; // TODO - } // read() - - /** - * skip - * @param length TODO - * @exception IOException TODO - * @returns long - */ - public long skip(long length) throws IOException { - return 0; // TODO - } // skip() - - /** - * close - * @exception IOException TODO - */ - public void close() throws IOException { - // TODO - } // close() - - /** - * getProgressMonitor - * @returns ProgressMonitor - */ - public ProgressMonitor getProgressMonitor() { - return null; // TODO - } // getProgressMonitor() - - -} // ProgressMonitorInputStream +public class ProgressMonitorInputStream extends FilterInputStream +{ + + /** + * monitor + */ + private ProgressMonitor monitor; + + /** + * read + */ + private int read; + + /** + * Constructor ProgressMonitorInputStream + * @param component TODO + * @param message TODO + * @param stream TODO + */ + public ProgressMonitorInputStream(Component component, Object message, + InputStream stream) + { + super(stream); + + int max = 0; + + try + { + max = stream.available(); + } + catch ( IOException ioe ) + { + // Behave like the JDK here. + } + + monitor = new ProgressMonitor( + component, message, null, 0, max ); + } + + /** + * reset + * @exception IOException TODO + */ + public void reset() throws IOException + { + super.reset(); + + checkMonitorCanceled(); + + // TODO: The docs says the monitor should be resetted. But to which + // value? (mark is not overridden) + } + + /** + * read + * @exception IOException TODO + * @returns int + */ + public int read() throws IOException + { + int t = super.read(); + + monitor.setProgress(++read); + + checkMonitorCanceled(); + + return t; + } + + /** + * read + * @param data TODO + * @exception IOException TODO + * @returns int + */ + public int read(byte[] data) throws IOException + { + int t = super.read(data); + + if ( t > 0 ) + { + read += t; + monitor.setProgress(read); + + checkMonitorCanceled(); + } + else + { + monitor.close(); + } + + return t; + } + + /** + * read + * @param data TODO + * @param offset TODO + * @param length TODO + * @exception IOException TODO + * @returns int + */ + public int read(byte[] data, int offset, int length) throws IOException + { + int t = super.read(data, offset, length); + + if ( t > 0 ) + { + read += t; + monitor.setProgress(read); + + checkMonitorCanceled(); + } + else + { + monitor.close(); + } + + return t; + } + + /** + * skip + * @param length TODO + * @exception IOException TODO + * @returns long + */ + public long skip(long length) throws IOException + { + long t = super.skip(length); + + // 'read' may overflow here in rare situations. + assert ( (long) read + t <= (long) Integer.MAX_VALUE ); + + read += (int) t; + + monitor.setProgress(read); + + checkMonitorCanceled(); + + return t; + } + + /** + * close + * @exception IOException TODO + */ + public void close() throws IOException + { + super.close(); + monitor.close(); + } + + /** + * getProgressMonitor + * @returns ProgressMonitor + */ + public ProgressMonitor getProgressMonitor() + { + return monitor; + } + + private void checkMonitorCanceled() throws InterruptedIOException + { + if ( monitor.isCanceled() ) + { + throw new InterruptedIOException("ProgressMonitor was canceled"); + } + } + +} diff --git a/javax/swing/Renderer.java b/javax/swing/Renderer.java index c803e38fc..9a0e81a9f 100644 --- a/javax/swing/Renderer.java +++ b/javax/swing/Renderer.java @@ -49,24 +49,20 @@ import java.awt.Component; * * @author Andrew Selkirk */ -public interface Renderer { +public interface Renderer +{ + /** + * setValue + * @param value TODO + * @param selected TODO + */ + void setValue(Object value, boolean selected); - //------------------------------------------------------------- - // Methods ---------------------------------------------------- - //------------------------------------------------------------- + /** + * getComponent + * @returns Component + */ + Component getComponent(); - /** - * setValue - * @param value TODO - * @param selected TODO - */ - void setValue(Object value, boolean selected); - /** - * getComponent - * @returns Component - */ - Component getComponent(); - - -} // Renderer +} diff --git a/javax/swing/RepaintManager.java b/javax/swing/RepaintManager.java index 698dbe8e8..54243aea8 100644 --- a/javax/swing/RepaintManager.java +++ b/javax/swing/RepaintManager.java @@ -80,23 +80,27 @@ public class RepaintManager * swing paint thread, which revalidates all invalid components and * repaints any damage in the swing scene.</p> */ - protected class RepaintWorker implements Runnable { + boolean live; + public RepaintWorker() { live = false; } + public synchronized void setLive(boolean b) { live = b; } + public synchronized boolean isLive() { return live; } + public void run() { RepaintManager rm = RepaintManager.globalManager; @@ -104,9 +108,9 @@ public class RepaintManager rm.validateInvalidComponents(); rm.paintDirtyRegions(); } + } - /** * A table storing the dirty regions of components. The keys of this * table are components, the values are rectangles. Each component maps diff --git a/javax/swing/RootPaneContainer.java b/javax/swing/RootPaneContainer.java index b121f958a..4b1bece21 100644 --- a/javax/swing/RootPaneContainer.java +++ b/javax/swing/RootPaneContainer.java @@ -48,53 +48,49 @@ import java.awt.Container; * * @author Andrew Selkirk */ -public interface RootPaneContainer { - - //------------------------------------------------------------- - // Methods ---------------------------------------------------- - //------------------------------------------------------------- - - /** - * getRootPane - * @returns JRootPane - */ - JRootPane getRootPane(); - - /** - * setContentPane - * @param contentPane TODO - */ - void setContentPane(Container contentPane); - - /** - * getContentPane - * @returns Container - */ - Container getContentPane(); - - /** - * setLayeredPane - * @param layeredPane TODO - */ - void setLayeredPane(JLayeredPane layeredPane); - - /** - * getLayeredPane - * @returns JLayeredPane - */ - JLayeredPane getLayeredPane(); - - /** - * setGlassPane - * @param glassPane TODO - */ - void setGlassPane(Component glassPane); - - /** - * getGlassPane - * @returns Component - */ - Component getGlassPane(); - - -} // RootPaneContainer +public interface RootPaneContainer +{ + + /** + * getRootPane + * @returns JRootPane + */ + JRootPane getRootPane(); + + /** + * setContentPane + * @param contentPane TODO + */ + void setContentPane(Container contentPane); + + /** + * getContentPane + * @returns Container + */ + Container getContentPane(); + + /** + * setLayeredPane + * @param layeredPane TODO + */ + void setLayeredPane(JLayeredPane layeredPane); + + /** + * getLayeredPane + * @returns JLayeredPane + */ + JLayeredPane getLayeredPane(); + + /** + * setGlassPane + * @param glassPane TODO + */ + void setGlassPane(Component glassPane); + + /** + * getGlassPane + * @returns Component + */ + Component getGlassPane(); + +} diff --git a/javax/swing/ScrollPaneLayout.java b/javax/swing/ScrollPaneLayout.java index 75a6f9aa2..940d47d35 100644 --- a/javax/swing/ScrollPaneLayout.java +++ b/javax/swing/ScrollPaneLayout.java @@ -95,11 +95,31 @@ public class ScrollPaneLayout upperRight = scrollPane.getCorner(UPPER_RIGHT_CORNER); } + /** + * Removes an existing component. If oldComponent is not null + * and is not equal to newComponent, oldComponent must be removed + * from its parent. + * @param oldComponent the old Component that may need to be removed. + * @param newComponent the Component to add. + * @return the newComponent + */ protected Component addSingletonComponent(Component oldComponent, - Component newComponent) { - return null; + Component newComponent) + { + if (oldComponent != null && oldComponent != newComponent) + oldComponent.getParent().remove(oldComponent); + return newComponent; } + /** + * Add the specified component to the layout. + * @param key must be one of VIEWPORT, VERTICAL_SCROLLBAR, + * HORIZONTAL_SCROLLBAR, ROW_HEADER, COLUMN_HEADER, + * LOWER_RIGHT_CORNER, LOWER_LEFT_CORNER, UPPER_RIGHT_CORNER, + * UPPER_LEFT_CORNER. + * @param component the Component to add + * @throws IllegalArgumentException if key is not as above + */ public void addLayoutComponent(String key, Component component) { if (key == VIEWPORT) @@ -120,6 +140,8 @@ public class ScrollPaneLayout lowerLeft = component; else if (key == UPPER_LEFT_CORNER) upperLeft = component; + else + throw new IllegalArgumentException(); } public void removeLayoutComponent(Component component) { @@ -147,9 +169,20 @@ public class ScrollPaneLayout { return vsbPolicy; } - + + /** + * Sets the vertical scrollbar policy. + * @param policy must be one of VERTICAL_SCROLLBAR_AS_NEEDED, + * VERTICAL_SCROLLBAR_NEVER, VERTICAL_SCROLLBAR_ALWAYS. + * @throws IllegalArgumentException if policy is not one of the valid + * JScrollBar policies. + */ public void setVerticalScrollBarPolicy(int policy) { + if (policy != VERTICAL_SCROLLBAR_AS_NEEDED && + policy != VERTICAL_SCROLLBAR_NEVER && + policy != VERTICAL_SCROLLBAR_ALWAYS) + throw new IllegalArgumentException("Illegal Scrollbar Policy"); vsbPolicy = policy; } @@ -158,8 +191,19 @@ public class ScrollPaneLayout return hsbPolicy; } + /** + * Sets the horizontal scrollbar policy. + * @param policy must be one of HORIZONTAL_SCROLLBAR_AS_NEEDED, + * HORIZONTAL_SCROLLBAR_NEVER, HORIZONTAL_SCROLLBAR_ALWAYS. + * @throws IllegalArgumentException if policy is not one of the valid + * JScrollbar policies. + */ public void setHorizontalScrollBarPolicy(int policy) { + if (policy != HORIZONTAL_SCROLLBAR_AS_NEEDED && + policy != HORIZONTAL_SCROLLBAR_NEVER && + policy != HORIZONTAL_SCROLLBAR_ALWAYS) + throw new IllegalArgumentException("Illegal Scrollbar Policy"); hsbPolicy = policy; } @@ -188,6 +232,12 @@ public class ScrollPaneLayout return colHead; } + /** + * Returns the Component at the specified corner. + * @param key the corner. + * @return the Component at the specified corner, or null if + * key is not one of the four valid corners. + */ public Component getCorner(String key) { if (key == LOWER_RIGHT_CORNER) @@ -377,7 +427,7 @@ public class ScrollPaneLayout synchronized (sc.getTreeLock ()) { JViewport viewport = sc.getViewport(); - Dimension viewSize = viewport.getViewSize(); + Dimension viewSize = viewport.getViewSize(); Point viewPos = viewport.getViewPosition(); int x1 = 0, x2 = 0, x3 = 0, x4 = 0; diff --git a/javax/swing/Scrollable.java b/javax/swing/Scrollable.java index 197321923..9dce665d6 100644 --- a/javax/swing/Scrollable.java +++ b/javax/swing/Scrollable.java @@ -48,9 +48,16 @@ import java.awt.Rectangle; */ public interface Scrollable { - Dimension getPreferredScrollableViewportSize(); - int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction); - int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction); - boolean getScrollableTracksViewportWidth(); - boolean getScrollableTracksViewportHeight(); + Dimension getPreferredScrollableViewportSize(); + + int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, + int direction); + + int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, + int direction); + + boolean getScrollableTracksViewportWidth(); + + boolean getScrollableTracksViewportHeight(); + } diff --git a/javax/swing/SingleSelectionModel.java b/javax/swing/SingleSelectionModel.java index b5380c857..d57443b56 100644 --- a/javax/swing/SingleSelectionModel.java +++ b/javax/swing/SingleSelectionModel.java @@ -46,46 +46,41 @@ import javax.swing.event.ChangeListener; * * @author Andrew Selkirk */ -public interface SingleSelectionModel { - - //------------------------------------------------------------- - // Methods ---------------------------------------------------- - //------------------------------------------------------------- - - /** - * getSelectedIndex - * @returns int - */ - int getSelectedIndex(); - - /** - * setSelectedIndex - * @param index TODO - */ - void setSelectedIndex(int index); - - /** - * clearSelection - */ - void clearSelection(); - - /** - * isSelected - * @returns boolean - */ - boolean isSelected(); - - /** - * addChangeListener - * @param listener TODO - */ - void addChangeListener(ChangeListener listener); - - /** - * removeChangeListener - * @param listener TODO - */ - void removeChangeListener(ChangeListener listener); - - -} // SingleSelectionModel +public interface SingleSelectionModel +{ + /** + * getSelectedIndex + * @returns int + */ + int getSelectedIndex(); + + /** + * setSelectedIndex + * @param index TODO + */ + void setSelectedIndex(int index); + + /** + * clearSelection + */ + void clearSelection(); + + /** + * isSelected + * @returns boolean + */ + boolean isSelected(); + + /** + * addChangeListener + * @param listener TODO + */ + void addChangeListener(ChangeListener listener); + + /** + * removeChangeListener + * @param listener TODO + */ + void removeChangeListener(ChangeListener listener); + +} diff --git a/javax/swing/SizeRequirements.java b/javax/swing/SizeRequirements.java index 77b42db1c..4f9d41824 100644 --- a/javax/swing/SizeRequirements.java +++ b/javax/swing/SizeRequirements.java @@ -116,7 +116,17 @@ public class SizeRequirements implements Serializable */ public String toString() { - return null; // TODO + StringBuilder b = new StringBuilder(); + b.append("<["); + b.append(minimum); + b.append(','); + b.append(preferred); + b.append(','); + b.append(maximum); + b.append("]@"); + b.append(alignment); + b.append('>'); + return b.toString(); } /** @@ -271,7 +281,8 @@ public class SizeRequirements implements Serializable SizeRequirements[] children, int[] offsets, int[] spans) { - calculateTiledPositions(allocated, total, children, offsets, spans, true); + calculateAlignedPositions(allocated, total, children, offsets, spans, + true); } /** @@ -306,7 +317,12 @@ public class SizeRequirements implements Serializable int[] offset, int[] spans, boolean forward) { - // TODO + // TODO: Implement this correctly. + for (int i = 0; i < children.length; ++i) + { + // This is only a hack to make things work a little. + spans[i] = Math.min(allocated, children[i].maximum); + } } /** diff --git a/javax/swing/SizeSequence.java b/javax/swing/SizeSequence.java index cf6e5f042..dff966b3e 100644 --- a/javax/swing/SizeSequence.java +++ b/javax/swing/SizeSequence.java @@ -42,208 +42,197 @@ package javax.swing; * @author Andrew Selkirk * @version 1.0 */ -public class SizeSequence { - - //------------------------------------------------------------- - // Variables -------------------------------------------------- - //------------------------------------------------------------- - - /** - * sizes - */ - private int[] sizes = new int[0]; - - - //------------------------------------------------------------- - // Initialization --------------------------------------------- - //------------------------------------------------------------- - - /** - * Constructor SizeSequence - */ - public SizeSequence() { - sizes = new int[0]; - } // SizeSequence() - - /** - * Constructor SizeSequence - * @param numEntries TODO - */ - public SizeSequence(int numEntries) { - this(numEntries, 0); - } // SizeSequence() - - /** - * Constructor SizeSequence - * @param numEntries TODO - * @param value TODO - */ - public SizeSequence(int numEntries, int value) { - insertEntries(0, numEntries, value); - } // SizeSequence() - - /** - * Constructor SizeSequence - * @param sizes TODO - */ - public SizeSequence(int[] sizes) { - setSizes(sizes); - } // SizeSequence() - - - //------------------------------------------------------------- - // Methods ---------------------------------------------------- - //------------------------------------------------------------- - - /** - * setSize - * @param index TODO - * @param size TODO - */ - public void setSize(int index, int size) { - sizes[index] = size; - } // setSize() - - /** - * getIndex - * @param position TODO - * @returns int - */ - public int getIndex(int position) { - return 0; // TODO - } // getIndex() - - /** - * getSize - * @param index TODO - * @returns int - */ - public int getSize(int index) { - return sizes[index]; - } // getSize() - - /** - * setSizes - * @param sizes TODO - */ - public void setSizes(int[] sizes) { - - // Variables - int index; - - // Initialize Sizes - this.sizes = new int[sizes.length]; - for (index = 0; index < sizes.length; index++) { - this.sizes[index] = sizes[index]; - } // for - - } // setSizes() - - /** - * getSizes - * @returns int[] - */ - public int[] getSizes() { - - // Variables - int[] array; - int index; - - // Create New Array - array = new int[sizes.length]; - for (index = 0; index < sizes.length; index++) { - array[index] = sizes[index]; - } // for - - // Return Newly created array - return array; - - } // getSizes() - - /** - * getPosition - * @param index TODO - * @returns int - */ - public int getPosition(int index) { - - // Variables - int position; - int loop; - - // Process Sizes - position = 0; - for (loop = 0; loop < index; loop++) { - position += sizes[loop]; - } // for - - // Return Position - return position; - - } // getPosition() - - /** - * insertEntries - * @param start TODO - * @param length TODO - * @param value TODO - */ - public void insertEntries(int start, int length, int value) { - - // Variables - int[] array; - int index; - int arrayIndex; - int loop; - - // Create New Array - array = new int[sizes.length + length]; - arrayIndex = 0; - for (index = 0; index < sizes.length; index++) { - if (index == start) { - for (loop = 0; loop < length; loop++) { - array[arrayIndex] = value; - arrayIndex++; - } // for - } else { - array[arrayIndex] = sizes[index]; - arrayIndex++; - } // if - } // for - - } // insertEntries() - - /** - * removeEntries - * @param start TODO - * @param length TODO - */ - public void removeEntries(int start, int length) { - - // Variables - int[] array; - int index; - int arrayIndex; - - // Sanity Check - if ((start + length) > sizes.length) { - throw new IllegalArgumentException("Specified start/length that " + - "is greater than available sizes"); - } // if - - // Create New Array - array = new int[sizes.length - length]; - arrayIndex = 0; - for (index = 0; index < sizes.length; index++) { - if (index == start) { - index += length - 1; - } else { - array[arrayIndex] = sizes[index]; - arrayIndex++; - } // if - } // for - - } // removeEntries() - - -} // SizeSequence +public class SizeSequence +{ + + /** + * sizes + */ + private int[] sizes = new int[0]; + + /** + * Constructor SizeSequence + */ + public SizeSequence() + { + sizes = new int[0]; + } + + /** + * Constructor SizeSequence + * @param numEntries TODO + */ + public SizeSequence(int numEntries) + { + this(numEntries, 0); + } + + /** + * Constructor SizeSequence + * @param numEntries TODO + * @param value TODO + */ + public SizeSequence(int numEntries, int value) + { + insertEntries(0, numEntries, value); + } + + /** + * Constructor SizeSequence + * @param sizes TODO + */ + public SizeSequence(int[] sizes) + { + setSizes(sizes); + } + + /** + * setSize + * @param index TODO + * @param size TODO + */ + public void setSize(int index, int size) + { + sizes[index] = size; + } + + /** + * getIndex + * @param position TODO + * @returns int + */ + public int getIndex(int position) + { + return 0; // TODO + } + + /** + * getSize + * @param index TODO + * @returns int + */ + public int getSize(int index) + { + return sizes[index]; + } + + /** + * setSizes + * @param sizes TODO + */ + public void setSizes(int[] sizes) + { + int index; + // Initialize sizes. + this.sizes = new int[sizes.length]; + for (index = 0; index < sizes.length; index++) + this.sizes[index] = sizes[index]; + + } + + /** + * getSizes + * @returns int[] + */ + public int[] getSizes() + { + int[] array; + int index; + + // Create new array. + array = new int[sizes.length]; + for (index = 0; index < sizes.length; index++) + array[index] = sizes[index]; + + // Return newly created array. + return array; + + } + + /** + * getPosition + * @param index TODO + * @returns int + */ + public int getPosition(int index) + { + int position; + int loop; + + // Process sizes. + position = 0; + for (loop = 0; loop < index; loop++) + position += sizes[loop]; + + // Return position. + return position; + + } + + /** + * insertEntries + * @param start TODO + * @param length TODO + * @param value TODO + */ + public void insertEntries(int start, int length, int value) + { + int[] array; + int index; + int arrayIndex; + int loop; + + // Create new array. + array = new int[sizes.length + length]; + arrayIndex = 0; + for (index = 0; index < sizes.length; index++) + { + if (index == start) + { + for (loop = 0; loop < length; loop++) + { + array[arrayIndex] = value; + arrayIndex++; + } + } + else + { + array[arrayIndex] = sizes[index]; + arrayIndex++; + } + } + + } + + /** + * removeEntries + * @param start TODO + * @param length TODO + */ + public void removeEntries(int start, int length) + { + int[] array; + int index; + int arrayIndex; + + // Sanity check. + if ((start + length) > sizes.length) + throw new IllegalArgumentException("Specified start/length that " + + "is greater than available sizes"); + + // Create new array. + array = new int[sizes.length - length]; + arrayIndex = 0; + for (index = 0; index < sizes.length; index++) + { + if (index == start) + index += length - 1; + else + { + array[arrayIndex] = sizes[index]; + arrayIndex++; + } + } + } + +} diff --git a/javax/swing/SpinnerListModel.java b/javax/swing/SpinnerListModel.java index 85dc4efa6..d8e2f22d5 100644 --- a/javax/swing/SpinnerListModel.java +++ b/javax/swing/SpinnerListModel.java @@ -68,231 +68,228 @@ import javax.swing.event.ChangeEvent; * @since 1.4 */ -public class SpinnerListModel - extends AbstractSpinnerModel - implements Serializable +public class SpinnerListModel extends AbstractSpinnerModel + implements Serializable { - /** - * For compatability with Sun's JDK - */ - private static final long serialVersionUID = 3358804052191994516L; + /** + * For compatability with Sun's JDK + */ + private static final long serialVersionUID = 3358804052191994516L; - /** - * The backing list for this model. - */ - private List list; + /** + * The backing list for this model. + */ + private List list; - /** - * The current index in the list. - */ - private transient int index; + /** + * The current index in the list. + */ + private transient int index; - /** - * Constructs a default <code>SpinnerListModel</code>. This - * is a model backed by a list containing only the single - * <code>String</code> element, "empty". - */ - public SpinnerListModel() - { - List defaultList; + /** + * Constructs a default <code>SpinnerListModel</code>. This + * is a model backed by a list containing only the single + * <code>String</code> element, "empty". + */ + public SpinnerListModel() + { + List defaultList; - /* Create an empty list */ - defaultList = new ArrayList(); - /* Add the string "empty" */ - defaultList.add("empty"); - /* Set the list */ - setList(defaultList); - } + // Create an empty list. + defaultList = new ArrayList(); + // Add the string "empty". + defaultList.add("empty"); + // Set the list. + setList(defaultList); + } - /** - * Constructs a <code>SpinnerListModel</code> using the supplied list. - * The model maintains a reference to this list, and returns - * consecutive elements in response to calls to <code>getNextValue()</code>. - * The initial value is that at position 0, so an initial call - * to <code>getValue()</code> returns the same as <code>list.get(0)</code>. - * - * @param list The list to use for this model. - * @throws IllegalArgumentException if the list is null or contains no - * elements. - * @see SpinnerListModel#getNextValue() - * @see SpinnerListModel#getValue() - */ - public SpinnerListModel(List list) - { - /* Retain a reference to the valid list */ - setList(list); - } + /** + * Constructs a <code>SpinnerListModel</code> using the supplied list. + * The model maintains a reference to this list, and returns + * consecutive elements in response to calls to <code>getNextValue()</code>. + * The initial value is that at position 0, so an initial call + * to <code>getValue()</code> returns the same as <code>list.get(0)</code>. + * + * @param list The list to use for this model. + * + * @throws IllegalArgumentException if the list is null or contains no + * elements. + * + * @see SpinnerListModel#getNextValue() + * @see SpinnerListModel#getValue() + */ + public SpinnerListModel(List list) + { + // Retain a reference to the valid list. + setList(list); + } - /** - * Constructs a <code>SpinnerListModel</code> using the supplied array. - * The model stores a reference to the wrapper list returned by - * <code>Arrays.asList()</code>. The wrapper list reflects modifications - * in the underlying array, so these changes will also be reflected - * by the model. The model produces consecutive elements from the array - * in response to calls to <code>getNextValue()</code>. The initial - * value returned by <code>getValue()</code> is the same as - * <code>array[0]</code>. - * - * @param array The array to use for this model. - * @throws IllegalArgumentException if the array is null or contains - * no elements. - * @see Arrays#asList(Object[]) - * @see SpinnerListModel#getNextValue() - * @see SpinnerListModel#getValue() - */ - public SpinnerListModel(Object[] array) - { - /* Check for a null or zero-sized array */ - if (array == null || array.length == 0) - { - throw new IllegalArgumentException("The supplied array was invalid."); - } - /* - Retain a reference to a wrapper around the valid array - The array, in list form, will be tested again here, but we can't really - avoid this -- a null value to Arrays.asList will throw a NullPointerException - */ - setList(Arrays.asList(array)); - } + /** + * Constructs a <code>SpinnerListModel</code> using the supplied array. + * The model stores a reference to the wrapper list returned by + * <code>Arrays.asList()</code>. The wrapper list reflects modifications + * in the underlying array, so these changes will also be reflected + * by the model. The model produces consecutive elements from the array + * in response to calls to <code>getNextValue()</code>. The initial + * value returned by <code>getValue()</code> is the same as + * <code>array[0]</code>. + * + * @param array The array to use for this model. + * + * @throws IllegalArgumentException if the array is null or contains + * no elements. + * + * @see Arrays#asList(Object[]) + * @see SpinnerListModel#getNextValue() + * @see SpinnerListModel#getValue() + */ + public SpinnerListModel(Object[] array) + { + // Check for a null or zero-sized array. + if (array == null || array.length == 0) + { + throw new IllegalArgumentException("The supplied array was invalid."); + } - /** - * Returns the backing list for this model. - * - * @return The backing list. - */ - public List getList() - { - return list; - } + // Retain a reference to a wrapper around the valid array. + // The array, in list form, will be tested again here, but we can't really + // avoid this -- a null value to Arrays.asList will throw a + // NullPointerException. + setList(Arrays.asList(array)); + } + + /** + * Returns the backing list for this model. + * + * @return The backing list. + */ + public List getList() + { + return list; + } - /** - * Returns the next value from the list, which is the same as the element - * stored at the current index + 1. Null is returned if there are no more - * values to be returned (the end of the list has been reached). An - * ambiguity can occur here, as null may also be returned as a valid list - * element. This operation does not change the current value. - * - * @return The next value from the list or null. - */ - public Object getNextValue() - { - /* Check for a next value */ - if (index < (list.size() - 1)) - { - /* Return the element at the next index */ - return list.get(index + 1); - } - else - { - /* Return null as this is the end of the list */ - return null; - } + /** + * Returns the next value from the list, which is the same as the element + * stored at the current index + 1. Null is returned if there are no more + * values to be returned (the end of the list has been reached). An + * ambiguity can occur here, as null may also be returned as a valid list + * element. This operation does not change the current value. + * + * @return The next value from the list or null. + */ + public Object getNextValue() + { + // Check for a next value. + if (index < (list.size() - 1)) + // Return the element at the next index. + return list.get(index + 1); + else + // Return null as this is the end of the list. + return null; } - /** - * Returns the previous value from the list, which is the same as the element - * stored at the current index - 1. Null is returned if there are no more - * values to be returned (the start of the list has been reached). An - * ambiguity can occur here, as null may also be returned as a valid list - * element. This operation does not change the current value. - * - * @return The previous value from the list or null. - */ - public Object getPreviousValue() - { - /* Check for a previous value. */ - if (index > 0) - { - /* Return the element at the previous position */ - return list.get(index - 1); - } + /** + * Returns the previous value from the list, which is the same as the element + * stored at the current index - 1. Null is returned if there are no more + * values to be returned (the start of the list has been reached). An + * ambiguity can occur here, as null may also be returned as a valid list + * element. This operation does not change the current value. + * + * @return The previous value from the list or null. + */ + public Object getPreviousValue() + { + // Check for a previous value. + if (index > 0) + // Return the element at the previous position. + return list.get(index - 1); else - { - /* Return null as this is the start of the list */ - return null; - } + // Return null as this is the start of the list. + return null; } - /** - * Returns the current value of the model. Initially, this will - * be the element at position 0. On later invocations, this will - * be the last element returned by <code>getNextValue()</code> - * or <code>getPreviousValue()</code>. - * - * @return The current value. - * @see SpinnerListModel#getPreviousValue() - * @see SpinnerListModel#getNextValue() - */ - public Object getValue() - { - return list.get(index); - } + /** + * Returns the current value of the model. Initially, this will + * be the element at position 0. On later invocations, this will + * be the last element returned by <code>getNextValue()</code> + * or <code>getPreviousValue()</code>. + * + * @return The current value. + * + * @see SpinnerListModel#getPreviousValue() + * @see SpinnerListModel#getNextValue() + */ + public Object getValue() + { + return list.get(index); + } - /** - * Changes the backing list for this model. The model only stores - * a reference to the list, so any changes made to the list elsewhere - * will be reflected in the values returned by the model. A - * <code>ChangeEvent</code> is fired if the list being used actually - * changes (i.e. the new list is not referentially equal (!=) to the - * old one). - * - * @param list The new list to use. - * @throws IllegalArgumentException if the list is null or contains - * no elements. - * @see ChangeEvent - */ - public void setList(List list) - { - /* Check for null or zero size list */ - if (list == null || list.size() == 0) - { - throw new IllegalArgumentException("The supplied list was invalid."); - } - /* Check for a change of referenced list */ - if (this.list != list) - { - /* Store the new list */ - this.list = list; - /* Notify listeners of a change */ - fireStateChanged(); - } - /* We reset the other values in either case */ - /* Set the index to 0 */ - index = 0; - } + /** + * Changes the backing list for this model. The model only stores + * a reference to the list, so any changes made to the list elsewhere + * will be reflected in the values returned by the model. A + * <code>ChangeEvent</code> is fired if the list being used actually + * changes (i.e. the new list is not referentially equal (!=) to the + * old one). + * + * @param list The new list to use. + * + * @throws IllegalArgumentException if the list is null or contains + * no elements. + * + * @see ChangeEvent + */ + public void setList(List list) + { + // Check for null or zero size list. + if (list == null || list.size() == 0) + throw new IllegalArgumentException("The supplied list was invalid."); - /** - * Sets the current value of the model to be the one supplied. - * The value must exist within the backing list in order for - * the change to take place. Otherwise, an exception is thrown. - * The value used is the first occurrence of the value within - * the backing list. Listeners are notified of this change. - * Following the change, <code>getNextValue()</code> and - * <code>getPreviousValue()</code> return the objects following - * and prior to the supplied value, respectively. - * - * @param value The requested new value of the list. - * @throws IllegalArgumentException if the supplied value does - * not exist in the backing list. - * @see SpinnerListModel#getPreviousValue() - * @see SpinnerListModel#getNextValue() - */ - public void setValue(Object value) - { - int valueIndex; + // Check for a change of referenced list. + if (this.list != list) + { + // Store the new list. + this.list = list; + // Notify listeners of a change. + fireStateChanged(); + } + // We reset the other values in either case. + // Set the index to 0. + index = 0; + } - /* Search for the value in the list */ - valueIndex = list.indexOf(value); - /* Check for the value being found */ - if (valueIndex == -1) - { - throw new IllegalArgumentException("The supplied value does not " - + "exist in this list"); - } - /* Make the indices match */ - index = valueIndex; - /* Notify the listeners */ - fireStateChanged(); - } + /** + * Sets the current value of the model to be the one supplied. + * The value must exist within the backing list in order for + * the change to take place. Otherwise, an exception is thrown. + * The value used is the first occurrence of the value within + * the backing list. Listeners are notified of this change. + * Following the change, <code>getNextValue()</code> and + * <code>getPreviousValue()</code> return the objects following + * and prior to the supplied value, respectively. + * + * @param value The requested new value of the list. + * + * @throws IllegalArgumentException if the supplied value does + * not exist in the backing list. + * + * @see SpinnerListModel#getPreviousValue() + * @see SpinnerListModel#getNextValue() + */ + public void setValue(Object value) + { + int valueIndex; + + // Search for the value in the list. + valueIndex = list.indexOf(value); + // Check for the value being found. + if (valueIndex == -1) + throw new IllegalArgumentException("The supplied value does not " + + "exist in this list"); + // Make the indices match. + index = valueIndex; + // Notify the listeners. + fireStateChanged(); + } } diff --git a/javax/swing/SwingUtilities.java b/javax/swing/SwingUtilities.java index ee5fa74d4..216057e0e 100644 --- a/javax/swing/SwingUtilities.java +++ b/javax/swing/SwingUtilities.java @@ -840,7 +840,7 @@ public class SwingUtilities iconR.width = icon.getIconWidth(); iconR.height = icon.getIconHeight(); } - if (text == null) + if (text == null || text.equals("")) { textIconGap = 0; textR.width = 0; diff --git a/javax/swing/Timer.java b/javax/swing/Timer.java index 87f420a43..e38915dc3 100644 --- a/javax/swing/Timer.java +++ b/javax/swing/Timer.java @@ -72,24 +72,25 @@ public class Timer queueEvent(); - while (running) - { - try - { - sleep(delay); - } - catch (InterruptedException e) - { - return; - } - queueEvent(); - - if (logTimers) - System.out.println("javax.swing.Timer -> clocktick"); - - if ( ! repeats) - break; - } + if (repeats) + 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) diff --git a/javax/swing/ToolTipManager.java b/javax/swing/ToolTipManager.java index 616937638..227144f44 100644 --- a/javax/swing/ToolTipManager.java +++ b/javax/swing/ToolTipManager.java @@ -129,8 +129,6 @@ public class ToolTipManager extends MouseAdapter implements MouseMotionListener public void actionPerformed(ActionEvent event) { showTip(); - if (insideTimer != null) - insideTimer.start(); } } @@ -183,7 +181,7 @@ public class ToolTipManager extends MouseAdapter implements MouseMotionListener * The window used when the tooltip doesn't fit inside the current * container. */ - private static JWindow tooltipWindow; + private static JDialog tooltipWindow; /** * Creates a new ToolTipManager and sets up the timers. @@ -373,7 +371,6 @@ public class ToolTipManager extends MouseAdapter implements MouseMotionListener if (exitTimer.isRunning()) { exitTimer.stop(); - showTip(); insideTimer.start(); return; } @@ -474,13 +471,15 @@ public class ToolTipManager extends MouseAdapter implements MouseMotionListener */ void showTip() { - if (! enabled || currentComponent == null) + if (! enabled || currentComponent == null || + (currentTip != null && currentTip.isVisible())) return; if (currentTip == null || currentTip.getComponent() != currentComponent && currentComponent instanceof JComponent) currentTip = ((JComponent) currentComponent).createToolTip(); + Point p = currentPoint; Dimension dims = currentTip.getPreferredSize(); if (canToolTipFit(currentTip)) @@ -526,13 +525,19 @@ public class ToolTipManager extends MouseAdapter implements MouseMotionListener } 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(); + if (currentComponent.isShowing()) + { + SwingUtilities.convertPointToScreen(p, currentComponent); + tooltipWindow = new JDialog(); + tooltipWindow.getContentPane().add(currentTip); + tooltipWindow.setUndecorated(true); + tooltipWindow.getRootPane(). + setWindowDecorationStyle(JRootPane.PLAIN_DIALOG); + tooltipWindow.setFocusable(false); + tooltipWindow.pack(); + tooltipWindow.setBounds(p.x, p.y, dims.width, dims.height); + tooltipWindow.show(); + } } currentTip.setVisible(true); } diff --git a/javax/swing/UnsupportedLookAndFeelException.java b/javax/swing/UnsupportedLookAndFeelException.java index 5abe45fe1..f99c0ac19 100644 --- a/javax/swing/UnsupportedLookAndFeelException.java +++ b/javax/swing/UnsupportedLookAndFeelException.java @@ -40,8 +40,8 @@ package javax.swing; public class UnsupportedLookAndFeelException extends Exception { - public UnsupportedLookAndFeelException(String a) - { - super(a); - } + public UnsupportedLookAndFeelException(String a) + { + super(a); + } } diff --git a/javax/swing/ViewportLayout.java b/javax/swing/ViewportLayout.java index 197358393..fe7453fc6 100644 --- a/javax/swing/ViewportLayout.java +++ b/javax/swing/ViewportLayout.java @@ -57,9 +57,11 @@ public class ViewportLayout implements LayoutManager, Serializable public ViewportLayout() { } + public void addLayoutComponent(String name, Component c) { } + public void removeLayoutComponent(Component c) { } diff --git a/javax/swing/WindowConstants.java b/javax/swing/WindowConstants.java index 5e3644344..aaa0cb9a3 100644 --- a/javax/swing/WindowConstants.java +++ b/javax/swing/WindowConstants.java @@ -43,31 +43,26 @@ package javax.swing; * * @author Andrew Selkirk */ -public interface WindowConstants { +public interface WindowConstants +{ + /** + * DO_NOTHING_ON_CLOSE + */ + int DO_NOTHING_ON_CLOSE = 0; - //------------------------------------------------------------- - // Variables -------------------------------------------------- - //------------------------------------------------------------- + /** + * HIDE_ON_CLOSE + */ + int HIDE_ON_CLOSE = 1; - /** - * DO_NOTHING_ON_CLOSE - */ - int DO_NOTHING_ON_CLOSE = 0; + /** + * DISPOSE_ON_CLOSE + */ + int DISPOSE_ON_CLOSE = 2; - /** - * HIDE_ON_CLOSE - */ - int HIDE_ON_CLOSE = 1; + /** + * EXIT_ON_CLOSE + */ + int EXIT_ON_CLOSE =3; - /** - * DISPOSE_ON_CLOSE - */ - int DISPOSE_ON_CLOSE = 2; - - /** - * EXIT_ON_CLOSE - */ - int EXIT_ON_CLOSE =3; - - -} // WindowConstants +} diff --git a/javax/swing/border/TitledBorder.java b/javax/swing/border/TitledBorder.java index ceae2b1c9..3ed60815a 100644 --- a/javax/swing/border/TitledBorder.java +++ b/javax/swing/border/TitledBorder.java @@ -46,6 +46,9 @@ import java.awt.FontMetrics; import java.awt.Graphics; import java.awt.Insets; import java.awt.Shape; +import java.awt.font.FontRenderContext; +import java.awt.font.LineMetrics; +import java.awt.geom.AffineTransform; import javax.swing.UIManager; @@ -607,7 +610,8 @@ public class TitledBorder case TOP: case DEFAULT_POSITION: default: - textY = y + mes.borderSpacing.top + mes.borderInsets.top - mes.textAscent; + textY = y + mes.borderSpacing.top + mes.borderInsets.top - mes.textAscent + + mes.lineHeight; break; case BELOW_TOP: @@ -1000,6 +1004,16 @@ public class TitledBorder m.textAscent = fmet.getAscent(); m.textDescent = fmet.getDescent(); + + FontRenderContext frc = new FontRenderContext(new AffineTransform(), false, + false); + LineMetrics lmet = m.font.getLineMetrics(m.trimmedText, 0, + m.trimmedText.length(), frc); + m.lineHeight = (int) lmet.getStrikethroughOffset(); + // Fallback in case that LineMetrics is not available/working. + if (m.lineHeight == 0) + m.lineHeight = (int) (0.3333 * (double) m.textAscent); + if (m.trimmedText != null) m.textWidth = fmet.stringWidth(m.trimmedText) + 3; @@ -1072,6 +1086,11 @@ public class TitledBorder */ int textDescent; + /** + * The number of pixels between the base line and the height where + * a strike-through would be drawn. + */ + int lineHeight; /** * The title text after removing leading and trailing white space diff --git a/javax/swing/filechooser/FileSystemView.java b/javax/swing/filechooser/FileSystemView.java index ffa41ca07..0c3dfbf6e 100644 --- a/javax/swing/filechooser/FileSystemView.java +++ b/javax/swing/filechooser/FileSystemView.java @@ -143,7 +143,7 @@ public abstract class FileSystemView for (int i = 0; i < files.length; i++) if (! files[i].isHidden()) trim.add(files[i]); - File[] value = (File[]) trim.toArray(new File[0]); + File[] value = (File[]) trim.toArray(new File[trim.size()]); return value; } @@ -356,6 +356,6 @@ public abstract class FileSystemView // traversable. (No files are listed when you traverse the directory) // My best guess is that as long as it's a directory, the file is // traversable. - return new Boolean(f.isDirectory()); + return Boolean.valueOf(f.isDirectory()); } } diff --git a/javax/swing/filechooser/FileView.java b/javax/swing/filechooser/FileView.java index c431fd461..f07114342 100644 --- a/javax/swing/filechooser/FileView.java +++ b/javax/swing/filechooser/FileView.java @@ -1,5 +1,5 @@ /* FileView.java -- - Copyright (C) 2002, 2004 Free Software Foundation, Inc. + Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -43,72 +43,85 @@ import java.io.File; import javax.swing.Icon; /** - * FileView - * @author Andrew Selkirk - * @version 1.0 + * An abstract class that provides presentation information about files and + * directories. . + * + * @author Andrew Selkirk */ -public abstract class FileView { - - //------------------------------------------------------------- - // Initialization --------------------------------------------- - //------------------------------------------------------------- - - /** - * Constructor FileView - */ - public FileView() { - // TODO - } // FileView() - - - //------------------------------------------------------------- - // Methods ---------------------------------------------------- - //------------------------------------------------------------- - - /** - * getName - * @param file TODO - * @returns String - */ - public String getName(File file) { - return null; // TODO - } // getName() - - /** - * getDescription - * @param value0 TODO - * @returns String - */ - public String getDescription(File value0) { - return null; // TODO - } // getDescription() - - /** - * getTypeDescription - * @param value0 TODO - * @returns String - */ - public String getTypeDescription(File value0) { - return null; // TODO - } // getTypeDescription() - - /** - * getIcon - * @param value0 TODO - * @returns Icon - */ - public Icon getIcon(File value0) { - return null; // TODO - } // getIcon() - - /** - * isTraversable - * @param value0 TODO - * @returns Boolean - */ - public Boolean isTraversable(File value0) { - return null; // TODO - } // isTraversable() - - -} // FileView +public abstract class FileView +{ + + /** + * Creates a new <code>FileView</code> instance. + */ + public FileView() + { + } + + /** + * Returns the name for the specified file. This method always returns + * <code>null</code> and should be overridden by subclasses. + * + * @param file the file. + * + * @return Always <code>null</code>. + */ + public String getName(File file) + { + return null; + } + + /** + * Returns a description for the specified file. This method always returns + * <code>null</code> and should be overridden by subclasses. + * + * @param file the file. + * + * @return Always <code>null</code>. + */ + public String getDescription(File file) + { + return null; + } + + /** + * Returns a description for the type of the specified file. This method + * always returns <code>null</code> and should be overridden by subclasses. + * + * @param file the file. + * + * @return Always <code>null</code>. + */ + public String getTypeDescription(File file) + { + return null; + } + + /** + * Returns an {@link Icon} to represent the specified file. This method + * always returns <code>null</code> and should be overridden by subclasses. + * + * @param file the file. + * + * @return Always <code>null</code>. + */ + public Icon getIcon(File file) + { + return null; + } + + /** + * Returns {@link Boolean#TRUE} if the given directory is traversable, and + * {@link Boolean#FALSE} if it is not. This method always returns + * <code>null</code> and should be overridden by subclasses. + * + * @param directory the directory. + * + * @returns Always <code>null</code>. + */ + public Boolean isTraversable(File directory) + { + return null; + } + +} diff --git a/javax/swing/plaf/basic/BasicArrowButton.java b/javax/swing/plaf/basic/BasicArrowButton.java index 836ef2234..e6d7188c4 100644 --- a/javax/swing/plaf/basic/BasicArrowButton.java +++ b/javax/swing/plaf/basic/BasicArrowButton.java @@ -46,6 +46,7 @@ import java.awt.Insets; import java.awt.Polygon; import java.awt.Rectangle; +import javax.swing.AbstractButton; import javax.swing.JButton; import javax.swing.SwingConstants; import javax.swing.border.Border; @@ -113,23 +114,29 @@ public class BasicArrowButton extends JButton implements SwingConstants public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) { - Color saved = g.getColor(); - g.setColor(highlight); - - g.drawLine(x + 1, y + 1, x + w - 1, y + 1); - g.drawLine(x + 1, y + 1, x + 1, y + h - 1); - - g.setColor(shadow); - - g.drawLine(x + 1, y + h - 1, x + w - 1, y + h - 1); - g.drawLine(x + w - 1, y + 1, x + w - 1, y + h - 1); - - g.setColor(darkShadow); - - g.drawLine(x, y + h, x + w, y + h); - g.drawLine(x + w, y, x + w, y + h); - - g.setColor(saved); + Color saved = g.getColor(); + AbstractButton b = (AbstractButton) c; + if (b.getModel().isPressed()) + { + g.setColor(darkShadow); + g.drawRect(x, y, x + w - 1, y + h - 1); + } + else + { + g.setColor(highlight); + g.drawLine(x + 1, y + 1, x + w - 3, y + 1); + g.drawLine(x + 1, y + 1, x + 1, y + h - 2); + + g.setColor(shadow); + g.drawLine(x + 1, y + h - 2, x + w - 1, y + h - 2); + g.drawLine(x + w - 2, y + 1, x + w - 2, y + h - 2); + + g.setColor(darkShadow); + g.drawLine(x, y + h - 1, x + w - 1, y + h - 1); + g.drawLine(x + w - 1, y, x + w - 1, y + h - 1); + + g.setColor(saved); + } } }; @@ -213,6 +220,16 @@ public class BasicArrowButton extends JButton implements SwingConstants paintTriangle(g, x, y, defaultSize, direction, isEnabled()); } + /** The preferred size for the button. */ + private static final Dimension PREFERRED_SIZE = new Dimension(16, 16); + + /** The minimum size for the button. */ + private static final Dimension MINIMUM_SIZE = new Dimension(5, 5); + + /** The maximum size for the button. */ + private static final Dimension MAXIMUM_SIZE + = new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE); + /** * This method returns the preferred size of the arrow button. * @@ -220,11 +237,7 @@ public class BasicArrowButton extends JButton implements SwingConstants */ public Dimension getPreferredSize() { - Insets insets = getInsets(); - int w = defaultSize + insets.left + insets.right; - int h = defaultSize + insets.top + insets.bottom; - - return new Dimension(w, h); + return PREFERRED_SIZE; } /** @@ -234,7 +247,7 @@ public class BasicArrowButton extends JButton implements SwingConstants */ public Dimension getMinimumSize() { - return getPreferredSize(); + return MINIMUM_SIZE; } /** @@ -244,7 +257,7 @@ public class BasicArrowButton extends JButton implements SwingConstants */ public Dimension getMaximumSize() { - return getPreferredSize(); + return MAXIMUM_SIZE; } /** @@ -309,8 +322,8 @@ public class BasicArrowButton extends JButton implements SwingConstants break; case SOUTH: x1 = xPoints[1]; - y1 = yPoints[1] + 1; - x2 = xPoints[2] - 1; + y1 = yPoints[1]; + x2 = xPoints[2]; y2 = yPoints[2]; break; case LEFT: diff --git a/javax/swing/plaf/basic/BasicButtonUI.java b/javax/swing/plaf/basic/BasicButtonUI.java index 6c80f14b6..acc1265a6 100644 --- a/javax/swing/plaf/basic/BasicButtonUI.java +++ b/javax/swing/plaf/basic/BasicButtonUI.java @@ -55,6 +55,7 @@ import javax.swing.UIDefaults; import javax.swing.UIManager; import javax.swing.plaf.ButtonUI; import javax.swing.plaf.ComponentUI; +import javax.swing.plaf.UIResource; public class BasicButtonUI extends ButtonUI { @@ -122,6 +123,7 @@ public class BasicButtonUI extends ButtonUI { UIDefaults defaults = UIManager.getLookAndFeelDefaults(); String prefix = getPropertyPrefix(); + b.setFont(defaults.getFont(prefix + "font")); focusColor = defaults.getColor(prefix + "focus"); b.setForeground(defaults.getColor(prefix + "foreground")); b.setBackground(defaults.getColor(prefix + "background")); @@ -130,11 +132,14 @@ public class BasicButtonUI extends ButtonUI b.setIconTextGap(defaults.getInt(prefix + "textIconGap")); b.setInputMap(JComponent.WHEN_FOCUSED, (InputMap) defaults.get(prefix + "focusInputMap")); + b.setRolloverEnabled(defaults.getBoolean(prefix + "rollover")); b.setOpaque(true); } protected void uninstallDefaults(AbstractButton b) { + if (b.getFont() instanceof UIResource) + b.setFont(null); b.setForeground(null); b.setBackground(null); b.setBorder(null); @@ -264,7 +269,10 @@ public class BasicButtonUI extends ButtonUI g.setFont(f); - SwingUtilities.calculateInnerArea(b, vr); + if (b.isBorderPainted()) + SwingUtilities.calculateInnerArea(b, vr); + else + vr = SwingUtilities.getLocalBounds(b); String text = SwingUtilities.layoutCompoundLabel(c, g.getFontMetrics(f), b.getText(), currentIcon(b), @@ -401,15 +409,15 @@ public class BasicButtonUI extends ButtonUI if (b.isEnabled()) { - g.setColor(b.getForeground()); - g.drawString(text, textRect.x, textRect.y + fm.getAscent()); + g.setColor(b.getForeground()); + g.drawString(text, textRect.x, textRect.y + fm.getAscent()); } else { - g.setColor(b.getBackground().brighter()); - g.drawString(text, textRect.x, textRect.y + fm.getAscent()); - g.setColor(b.getBackground().darker()); - g.drawString(text, textRect.x + 1, textRect.y + fm.getAscent() + 1); + UIDefaults defaults = UIManager.getLookAndFeelDefaults(); + String prefix = getPropertyPrefix(); + g.setColor(defaults.getColor(prefix + "disabledText")); + g.drawString(text, textRect.x, textRect.y + fm.getAscent()); } } } diff --git a/javax/swing/plaf/basic/BasicComboBoxRenderer.java b/javax/swing/plaf/basic/BasicComboBoxRenderer.java index e4fbb8352..94a35bc69 100644 --- a/javax/swing/plaf/basic/BasicComboBoxRenderer.java +++ b/javax/swing/plaf/basic/BasicComboBoxRenderer.java @@ -1,5 +1,5 @@ /* BasicComboBoxRenderer.java -- - Copyright (C) 2004 Free Software Foundation, Inc. + Copyright (C) 2004, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -40,36 +40,39 @@ package javax.swing.plaf.basic; import java.awt.Component; import java.awt.Dimension; +import java.awt.FontMetrics; import java.io.Serializable; +import javax.swing.JComboBox; import javax.swing.JLabel; import javax.swing.JList; import javax.swing.ListCellRenderer; import javax.swing.SwingConstants; -import javax.swing.UIDefaults; -import javax.swing.UIManager; +import javax.swing.SwingUtilities; import javax.swing.border.Border; import javax.swing.border.EmptyBorder; /** - * This class is renderer for the combo box. + * A renderer for a {@link JComboBox}. * * @author Olga Rodimina */ -public class BasicComboBoxRenderer extends JLabel implements ListCellRenderer, - Serializable +public class BasicComboBoxRenderer + extends JLabel + implements ListCellRenderer, Serializable { /** - * This border is used whenever renderer doesn't have a focus. + * A shared border instance for all renderers. */ protected static Border noFocusBorder = new EmptyBorder(0, 0, 0, 0); /** - * Creates a new BasicComboBoxRenderer object. + * Creates a new <code>BasicComboBoxRenderer</code> object. */ public BasicComboBoxRenderer() { setHorizontalAlignment(SwingConstants.LEFT); + setBorder(noFocusBorder); } /** @@ -83,7 +86,8 @@ public class BasicComboBoxRenderer extends JLabel implements ListCellRenderer, } /** - * getListCellRendererComponent + * Returns a component that has been configured to display the given + * <code>value</code>. * * @param list List of items for which to the background and foreground * colors @@ -100,40 +104,55 @@ public class BasicComboBoxRenderer extends JLabel implements ListCellRenderer, boolean cellHasFocus) { String s = value.toString(); - setText(s); + + // String maybe larger than comboBox. + FontMetrics fm = getToolkit().getFontMetrics(list.getFont()); + int strWidth = SwingUtilities.computeStringWidth(fm, s); + int cbWidth = getSize().width; + if (cbWidth != 0 && strWidth > cbWidth) + { + char[] str = s.toCharArray(); + int currWidth = 0; + int i = 0; + String postStr = "... "; + cbWidth -= SwingUtilities.computeStringWidth(fm, postStr); + while (i < str.length && currWidth < cbWidth) + { + ++i; + currWidth = SwingUtilities.computeStringWidth(fm, new String(str, 0, i)); + } + setText(new String(str, 0, i) + postStr); + } + else + setText(s); + setOpaque(true); - UIDefaults defaults = UIManager.getLookAndFeelDefaults(); - - if (isSelected) + if (isSelected || cellHasFocus) { - 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; } + /** + * A subclass of {@link BasicComboBoxRenderer} that implements the + * {@link javax.swing.plaf.UIResource} interface. + */ public static class UIResource extends BasicComboBoxRenderer implements javax.swing.plaf.UIResource { /** - * Creates a new UIResource object. + * Creates a new <code>UIResource</code> object. */ public UIResource() { diff --git a/javax/swing/plaf/basic/BasicComboBoxUI.java b/javax/swing/plaf/basic/BasicComboBoxUI.java index 68e18a6ab..b4267e56a 100644 --- a/javax/swing/plaf/basic/BasicComboBoxUI.java +++ b/javax/swing/plaf/basic/BasicComboBoxUI.java @@ -42,6 +42,7 @@ import java.awt.Color; import java.awt.Component; import java.awt.Container; import java.awt.Dimension; +import java.awt.Font; import java.awt.Graphics; import java.awt.Insets; import java.awt.LayoutManager; @@ -69,15 +70,17 @@ import javax.swing.JComboBox; import javax.swing.JComponent; import javax.swing.JList; import javax.swing.ListCellRenderer; +import javax.swing.SwingUtilities; import javax.swing.UIDefaults; import javax.swing.UIManager; import javax.swing.event.ListDataEvent; import javax.swing.event.ListDataListener; import javax.swing.plaf.ComboBoxUI; import javax.swing.plaf.ComponentUI; +import javax.swing.plaf.UIResource; /** - * UI Delegate for JComboBox + * A UI delegate for the {@link JComboBox} component. * * @author Olga Rodimina * @author Robert Schuster @@ -85,52 +88,54 @@ import javax.swing.plaf.ComponentUI; public class BasicComboBoxUI extends ComboBoxUI { /** - * This arrow button that is displayed in the rigth side of JComboBox. This - * button is used to hide and show combo box's list of items + * The arrow button that is displayed in the right side of JComboBox. This + * button is used to hide and show combo box's list of items. */ protected JButton arrowButton; /** - * The combo box for which this UI delegate is for + * The combo box represented by this UI delegate. */ protected JComboBox comboBox; /** - * Component that is responsible for displaying/editting selected item of - * the combo box. By default JTextField is used as an editor for the - * JComboBox + * The component that is responsible for displaying/editing the selected + * item of the combo box. + * + * @see BasicComboBoxEditor#getEditorComponent() */ protected Component editor; /** - * Listener listening to focus events occuring in the JComboBox + * A listener listening to focus events occurring in the {@link JComboBox}. */ protected FocusListener focusListener; /** - * tells whether JComboBox currently has focus + * A flag indicating whether JComboBox currently has the focus. */ protected boolean hasFocus; /** - * Listener listening to item events fired by the JComboBox + * A listener listening to item events fired by the {@link JComboBox}. */ protected ItemListener itemListener; /** - * KeyListener listening to key events that occur while JComboBox has focus + * A listener listening to key events that occur while {@link JComboBox} has + * the focus. */ protected KeyListener keyListener; /** - * MouseListener listening to mouse events occuring in the combo box + * A listener listening to mouse events occuring in the {@link JComboBox}. */ private MouseListener mouseListener; /** * List used when rendering selected item of the combo box. The selection - * and foreground colors for combo box renderer are configured from this - * list + * and foreground colors for combo box renderer are configured from this + * list. */ protected JList listBox; @@ -140,7 +145,7 @@ public class BasicComboBoxUI extends ComboBoxUI protected ListDataListener listDataListener; /** - * Popup list containing combo box's menu items + * Popup list containing the combo box's menu items. */ protected ComboPopup popup; protected KeyListener popupKeyListener; @@ -158,24 +163,11 @@ public class BasicComboBoxUI extends ComboBoxUI private Color shadow; private Color darkShadow; private Color highlight; - private Color lightHighlight; /* Size of the largest item in the comboBox * This is package-private to avoid an accessor method. */ - Dimension largestItemSize; - - // It seems that JComboBox doesn't have a border set explicitely. So we just - // paint the border everytime combo box is displayed. - - /* border insets for this JComboBox - * This is package-private to avoid an accessor method. */ - static final Insets borderInsets = new Insets(2, 2, 2, 2); - - // Width of the arrow button - // This is package-private to avoid an accessor method. - // FIXME: has wrong name for a constant. - static final int arrowButtonWidth = 15; + Dimension displaySize; // FIXME: This fields aren't used anywhere at this moment. protected Dimension cachedMinimumSize; @@ -183,19 +175,19 @@ public class BasicComboBoxUI extends ComboBoxUI protected boolean isMinimumSizeDirty; /** - * Creates a new BasicComboBoxUI object. + * Creates a new <code>BasicComboBoxUI</code> object. */ public BasicComboBoxUI() { } /** - * Factory method to create a BasicComboBoxUI for the given {@link - * JComponent}, which should be a {@link JComboBox}. + * A factory method to create a UI delegate for the given + * {@link JComponent}, which should be a {@link JComboBox}. * * @param c The {@link JComponent} a UI is being created for. * - * @return A BasicComboBoxUI for the {@link JComponent}. + * @return A UI delegate for the {@link JComponent}. */ public static ComponentUI createUI(JComponent c) { @@ -203,9 +195,11 @@ public class BasicComboBoxUI extends ComboBoxUI } /** - * This method installs the UI for the given JComponent. + * Installs the UI for the given {@link JComponent}. * - * @param c The JComponent to install a UI for. + * @param c the JComponent to install a UI for. + * + * @see #uninstallUI(JComponent) */ public void installUI(JComponent c) { @@ -224,9 +218,11 @@ public class BasicComboBoxUI extends ComboBoxUI } /** - * This method uninstalls the UI. + * Uninstalls the UI for the given {@link JComponent}. * * @param c The JComponent that is having this UI removed. + * + * @see #installUI(JComponent) */ public void uninstallUI(JComponent c) { @@ -238,27 +234,34 @@ public class BasicComboBoxUI extends ComboBoxUI } /** - * This method installs the defaults that are defined in the Basic look and - * feel for this {@link JComboBox}. + * Installs the defaults that are defined in the {@link BasicLookAndFeel} + * for this {@link JComboBox}. + * + * @see #uninstallDefaults() */ protected void installDefaults() { UIDefaults defaults = UIManager.getLookAndFeelDefaults(); - comboBox.setBackground(defaults.getColor("ComboBox.background")); - comboBox.setFont(defaults.getFont("ComboBox.font")); - comboBox.setForeground(defaults.getColor("ComboBox.foreground")); + if (comboBox.getFont() instanceof UIResource) + comboBox.setFont(defaults.getFont("ComboBox.font")); + + if (comboBox.getForeground() instanceof UIResource) + comboBox.setForeground(defaults.getColor("ComboBox.foreground")); - // Set default color that should be used to to render selected item - // of the combo box. - shadow = defaults.getColor("Button.shadow"); - darkShadow = defaults.getColor("Button.darkShadow"); - lightHighlight = defaults.getColor("Button.light"); - highlight = defaults.getColor("Button.highlight"); + if (comboBox.getBackground() instanceof UIResource) + comboBox.setBackground(defaults.getColor("ComboBox.background")); + + // fetch the button color scheme + shadow = defaults.getColor("ComboBox.buttonShadow"); + darkShadow = defaults.getColor("ComboBox.buttonDarkShadow"); + highlight = defaults.getColor("ComboBox.buttonHighlight"); } /** - * This method creates and installs the listeners for this UI. + * Creates and installs the listeners for this UI. + * + * @see #uninstallListeners() */ protected void installListeners() { @@ -276,35 +279,39 @@ public class BasicComboBoxUI extends ComboBoxUI comboBox.addKeyListener(keyListener); mouseListener = createMouseListener(); - comboBox.addMouseListener(mouseListener); + arrowButton.addMouseListener(mouseListener); // install listeners that listen to combo box model listDataListener = createListDataListener(); comboBox.getModel().addListDataListener(listDataListener); - - configureArrowButton(); } /** - * This method uninstalls the defaults and sets any objects created during - * install to null + * Uninstalls the defaults and sets any objects created during + * install to <code>null</code>. + * + * @see #installDefaults() */ protected void uninstallDefaults() { - UIDefaults defaults = UIManager.getLookAndFeelDefaults(); + if (comboBox.getFont() instanceof UIResource) + comboBox.setFont(null); - comboBox.setBackground(null); - comboBox.setFont(null); - comboBox.setForeground(null); + if (comboBox.getForeground() instanceof UIResource) + comboBox.setForeground(null); + + if (comboBox.getBackground() instanceof UIResource) + comboBox.setBackground(null); shadow = null; darkShadow = null; - lightHighlight = null; highlight = null; } /** * Detaches all the listeners we attached in {@link #installListeners}. + * + * @see #installListeners() */ protected void uninstallListeners() { @@ -320,17 +327,15 @@ public class BasicComboBoxUI extends ComboBoxUI comboBox.removeKeyListener(keyListener); keyListener = null; - comboBox.removeMouseListener(mouseListener); + arrowButton.removeMouseListener(mouseListener); mouseListener = null; comboBox.getModel().removeListDataListener(listDataListener); listDataListener = null; - - unconfigureArrowButton(); } /** - * This method creates popup that will contain list of combo box's items + * Creates the popup that will contain list of combo box's items. * * @return popup containing list of combo box's items */ @@ -340,7 +345,7 @@ public class BasicComboBoxUI extends ComboBoxUI } /** - * Creates KeyListener to listen to key events. + * Creates a {@link KeyListener} to listen to key events. * * @return KeyListener that listens to key events. */ @@ -350,8 +355,8 @@ public class BasicComboBoxUI extends ComboBoxUI } /** - * This method create MouseListener that will listen to mouse event occuring - * in combo box. + * Creates a {@link MouseListener} that will listen to mouse events occurring + * in the combo box. * * @return the MouseListener */ @@ -361,10 +366,10 @@ public class BasicComboBoxUI extends ComboBoxUI } /** - * This method create FocusListener that will listen to changes in this + * Creates the {@link FocusListener} that will listen to changes in this * JComboBox's focus. * - * @return theFocusListener + * @return the FocusListener. */ protected FocusListener createFocusListener() { @@ -372,9 +377,9 @@ public class BasicComboBoxUI extends ComboBoxUI } /** - * This method create ListDataListener to listen to ComboBox's data model + * Creates a {@link ListDataListener} to listen to the combo box's data model. * - * @return ListDataListener + * @return The new listener. */ protected ListDataListener createListDataListener() { @@ -382,10 +387,10 @@ public class BasicComboBoxUI extends ComboBoxUI } /** - * This method creates ItemListener that will listen to to the changes in + * Creates an {@link ItemListener} that will listen to the changes in * the JComboBox's selection. * - * @return the ItemListener + * @return The ItemListener */ protected ItemListener createItemListener() { @@ -393,10 +398,10 @@ public class BasicComboBoxUI extends ComboBoxUI } /** - * This method creates PropertyChangeListener to listen to the changes in + * Creates a {@link PropertyChangeListener} to listen to the changes in * the JComboBox's bound properties. * - * @return the PropertyChangeListener + * @return The PropertyChangeListener */ protected PropertyChangeListener createPropertyChangeListener() { @@ -404,9 +409,10 @@ public class BasicComboBoxUI extends ComboBoxUI } /** - * This method returns layout manager for the combo box. + * Creates and returns a layout manager for the combo box. Subclasses can + * override this method to provide a different layout. * - * @return layout manager for the combo box + * @return a layout manager for the combo box. */ protected LayoutManager createLayoutManager() { @@ -414,10 +420,10 @@ public class BasicComboBoxUI extends ComboBoxUI } /** - * This method creates component that will be responsible for rendering the + * Creates a component that will be responsible for rendering the * selected component in the combo box. * - * @return render for the combo box + * @return A renderer for the combo box. */ protected ListCellRenderer createRenderer() { @@ -425,12 +431,12 @@ public class BasicComboBoxUI extends ComboBoxUI } /** - * Creates component that will be responsible for displaying/editting - * selected item in the combo box. This editor is used only when combo box - * is editable. + * Creates the component that will be responsible for displaying/editing + * the selected item in the combo box. This editor is used only when combo + * box is editable. * - * @return component that will be responsible for displaying/editting - * selected item in the combo box. + * @return A new component that will be responsible for displaying/editing + * the selected item in the combo box. */ protected ComboBoxEditor createEditor() { @@ -438,29 +444,21 @@ public class BasicComboBoxUI extends ComboBoxUI } /** - * This method installs components for this JComboBox. ArrowButton, main - * part of combo box (upper part) and popup list of items are created and + * Installs the components for this JComboBox. ArrowButton, main + * part of combo box (upper part) and popup list of items are created and * configured here. */ protected void installComponents() { // create and install arrow button arrowButton = createArrowButton(); - + configureArrowButton(); comboBox.add(arrowButton); // Set list that will be used by BasicComboBoxRender // in order to determine the right colors when rendering listBox = new JList(); - Color background = arrowButton.getBackground(); - listBox.setBackground(background); - listBox.setSelectionBackground(background.darker()); - - Color foreground = arrowButton.getForeground(); - listBox.setForeground(foreground); - listBox.setSelectionForeground(foreground); - // set editor and renderer for the combo box. Editor is used // only if combo box becomes editable, otherwise renderer is used // to paint the selected item; combobox is not editable by default. @@ -476,7 +474,9 @@ public class BasicComboBoxUI extends ComboBoxUI } /** - * This method uninstalls components from this JComboBox + * Uninstalls components from this {@link JComboBox}. + * + * @see #installComponents() */ protected void uninstallComponents() { @@ -495,7 +495,7 @@ public class BasicComboBoxUI extends ComboBoxUI } /** - * This method adds editor to the combo box + * Adds the current editor to the combo box. */ public void addEditor() { @@ -503,7 +503,7 @@ public class BasicComboBoxUI extends ComboBoxUI } /** - * This method removes editor from the combo box + * Removes the current editor from the combo box. */ public void removeEditor() { @@ -511,15 +511,17 @@ public class BasicComboBoxUI extends ComboBoxUI } /** - * This method configures editor for this combo box. + * Configures the editor for this combo box. */ protected void configureEditor() { + editor.setFont(comboBox.getFont()); + comboBox.getEditor().setItem(comboBox.getSelectedItem()); // FIXME: Need to implement. Set font and add listeners. } /** - * This method removes all the listeners for the editor. + * Unconfigures the editor for this combo nox. This method is not implemented. */ protected void unconfigureEditor() { @@ -527,28 +529,32 @@ public class BasicComboBoxUI extends ComboBoxUI } /** - * This method adds listeners to the arrow button part of the combo box. + * Configures the arrow button. + * + * @see #configureArrowButton() */ public void configureArrowButton() { - arrowButton.addMouseListener(mouseListener); + arrowButton.setEnabled(comboBox.isEnabled()); + arrowButton.setFont(comboBox.getFont()); + arrowButton.setMargin(new Insets(0, 0, 0, 0)); } /** - * This method removes listeners from the arrow button part of the combo - * box. + * Unconfigures the arrow button. + * + * @see #configureArrowButton() */ public void unconfigureArrowButton() { - arrowButton.removeMouseListener(mouseListener); } /** - * This method create arrow button for this JComboBox. Arrow button is - * responsible for displaying / hiding drop down list of items when it is - * clicked. + * Creates an arrow button for this {@link JComboBox}. The arrow button is + * displayed at the right end of the combo box and is used to display/hide + * the drop down list of items. * - * @return JButton arrow button for this JComboBox. + * @return A new button. */ protected JButton createArrowButton() { @@ -556,13 +562,13 @@ public class BasicComboBoxUI extends ComboBoxUI } /** - * This method checks if popup part of the combo box is visible on the - * screen + * Returns <code>true</code> if the popup is visible, and <code>false</code> + * otherwise. * * @param c The JComboBox to check * - * @return true if popup part of the JComboBox is visible and false - * otherwise. + * @return <code>true</code> if popup part of the JComboBox is visible and + * <code>false</code> otherwise. */ public boolean isPopupVisible(JComboBox c) { @@ -570,7 +576,7 @@ public class BasicComboBoxUI extends ComboBoxUI } /** - * Displays/Hides JComboBox's list of items on the screen. + * Displays/hides the {@link JComboBox}'s list of items on the screen. * * @param c The combo box, for which list of items should be * displayed/hidden @@ -593,7 +599,7 @@ public class BasicComboBoxUI extends ComboBoxUI */ public boolean isFocusTraversable(JComboBox c) { - if (comboBox.isEditable()) + if (!comboBox.isEditable()) return true; return false; @@ -607,56 +613,25 @@ public class BasicComboBoxUI extends ComboBoxUI */ public void paint(Graphics g, JComponent c) { - if (c instanceof JComboBox) - { - JComboBox cb = (JComboBox) c; - - paintBorder(g, comboBox.getBounds(), hasFocus); - - Rectangle rect = rectangleForCurrentValue(); - paintCurrentValueBackground(g, rect, hasFocus); - paintCurrentValue(g, rect, hasFocus); - } - } - - private void paintBorder(Graphics g, Rectangle bounds, boolean hasFocus) - { - int x = 0; - int y = 0; - int width = bounds.width; - int height = bounds.height; - - Color oldColor = g.getColor(); - - if (! arrowButton.getModel().isPressed()) - BasicGraphicsUtils.drawEtchedRect(g, x, y, width, height, Color.gray, - Color.white, Color.gray, Color.white); - else - { - g.setColor(darkShadow); - g.drawRect(x, y, width, height); - g.setColor(shadow); - g.drawRect(x + 1, y + 1, width - 3, height - 3); - } - g.setColor(oldColor); + Rectangle rect = rectangleForCurrentValue(); + paintCurrentValueBackground(g, rect, hasFocus); + paintCurrentValue(g, rect, hasFocus); } /** - * Returns preferred size for the given menu item. + * Returns preferred size for the combo box. * * @param c comboBox for which to get preferred size * - * @return $Dimension$ preferred size for the given combo box + * @return The preferred size for the given combo box */ public Dimension getPreferredSize(JComponent c) { - // return null to indicate that combo box's layout will determin its - // preferred size - return null; + return getMinimumSize(c); } /** - * This method returns the minimum size for this {@link JComboBox} for this + * Returns the minimum size for this {@link JComboBox} for this * look and feel. * * @param c The {@link JComponent} to find the minimum size for. @@ -665,11 +640,18 @@ public class BasicComboBoxUI extends ComboBoxUI */ public Dimension getMinimumSize(JComponent c) { - return null; + Dimension d = getDisplaySize(); + Dimension arrowDim = arrowButton.getPreferredSize(); + Dimension result = new Dimension(d.width + arrowDim.width, + Math.max(d.height, arrowDim.height)); + return result; } + /** The value returned by the getMaximumSize() method. */ + private static final Dimension MAXIMUM_SIZE = new Dimension(32767, 32767); + /** - * This method returns the maximum size for this {@link JComboBox} for this + * Returns the maximum size for this {@link JComboBox} for this * look and feel. * * @param c The {@link JComponent} to find the maximum size for @@ -678,7 +660,7 @@ public class BasicComboBoxUI extends ComboBoxUI */ public Dimension getMaximumSize(JComponent c) { - return null; + return MAXIMUM_SIZE; } public int getAccessibleChildrenCount(JComponent c) @@ -707,7 +689,7 @@ public class BasicComboBoxUI extends ComboBoxUI } /** - * This method selects next possible item relative to the current selection + * Selects next possible item relative to the current selection * to be next selected item in the combo box. */ protected void selectNextPossibleValue() @@ -718,7 +700,7 @@ public class BasicComboBoxUI extends ComboBoxUI } /** - * This method selects previous item relative to current selection to be + * Selects previous item relative to current selection to be * next selected item. */ protected void selectPreviousPossibleValue() @@ -729,8 +711,8 @@ public class BasicComboBoxUI extends ComboBoxUI } /** - * This method displays combo box popup if the popup is not currently shown - * on the screen and hides it if it is currently shown + * Displays combo box popup if the popup is not currently shown + * on the screen and hides it if it is currently shown */ protected void toggleOpenClose() { @@ -738,34 +720,23 @@ public class BasicComboBoxUI extends ComboBoxUI } /** - * This method returns bounds in which comboBox's selected Item will be - * displayed + * Returns the bounds in which comboBox's selected item will be + * displayed. * * @return rectangle bounds in which comboBox's selected Item will be * displayed */ protected Rectangle rectangleForCurrentValue() { - Rectangle cbBounds = comboBox.getBounds(); - - // Subtract width or the arrow button and border insets - Rectangle rectForCurrentValue = new Rectangle(cbBounds.x - + borderInsets.left, - cbBounds.y - + borderInsets.top, - cbBounds.width - - arrowButtonWidth - - borderInsets.left - - borderInsets.right, - cbBounds.height - - borderInsets.top - - borderInsets.bottom); - + Rectangle cbBounds = SwingUtilities.getLocalBounds(comboBox); + Rectangle abBounds = arrowButton.getBounds(); + Rectangle rectForCurrentValue = new Rectangle(cbBounds.x, cbBounds.y, + cbBounds.width - abBounds.width, cbBounds.height); return rectForCurrentValue; } /** - * This method returns insets of the current border. + * Returns the insets of the current border. * * @return Insets representing space between combo box and its border */ @@ -775,7 +746,7 @@ public class BasicComboBoxUI extends ComboBoxUI } /** - * This method paints currently selected value in the main part of the combo + * Paints currently selected value in the main part of the combo * box (part without popup). * * @param g graphics context @@ -794,28 +765,29 @@ public class BasicComboBoxUI extends ComboBoxUI * If there is currently no selected item we will take an empty * String as replacement. */ - Component comp = comboBox.getRenderer() - .getListCellRendererComponent(listBox, - (currentValue != null ? currentValue : ""), - -1, - isPressed, - hasFocus); - if (! comboBox.isEnabled()) - comp.setEnabled(false); - - g.translate(borderInsets.left, borderInsets.top); - comp.setBounds(0, 0, bounds.width, bounds.height); - comp.paint(g); - g.translate(-borderInsets.left, -borderInsets.top); - - comboBox.revalidate(); + Component comp = comboBox.getRenderer().getListCellRendererComponent( + listBox, (currentValue != null ? currentValue : ""), -1, + isPressed, hasFocus); + if (! comboBox.isEnabled()) + { + comp.setBackground(UIManager.getLookAndFeelDefaults().getColor( + "ComboBox.disabledBackground")); + comp.setForeground(UIManager.getLookAndFeelDefaults().getColor( + "ComboBox.disabledForeground")); + comp.setEnabled(false); + } + comp.setBounds(0, 0, bounds.width, bounds.height); + comp.setFont(comboBox.getFont()); + comp.paint(g); + + comboBox.revalidate(); } else comboBox.getEditor().setItem(comboBox.getSelectedItem()); } /** - * This method paints background of part of the combo box, where currently + * Paints the background of part of the combo box, where currently * selected value is displayed. If the combo box has focus this method * should also paint focus rectangle around the combo box. * @@ -839,7 +811,8 @@ public class BasicComboBoxUI extends ComboBoxUI */ protected Dimension getDefaultSize() { - return new Dimension(6, 17); + // FIXME: Not implemented properly. + return new Dimension(100, 5); } /** @@ -848,7 +821,7 @@ public class BasicComboBoxUI extends ComboBoxUI * * @return dimensions of the largest item in the combo box. */ - protected Dimension getLargestItemSize() + protected Dimension getDisplaySize() { ComboBoxModel model = comboBox.getModel(); int numItems = model.getSize(); @@ -857,8 +830,8 @@ public class BasicComboBoxUI extends ComboBoxUI // return its default size if (numItems == 0) { - largestItemSize = getDefaultSize(); - return largestItemSize; + displaySize = getDefaultSize(); + return displaySize; } Dimension size = new Dimension(0, 0); @@ -867,23 +840,27 @@ public class BasicComboBoxUI extends ComboBoxUI // size of the largest item in the combo box. ListCellRenderer renderer = comboBox.getRenderer(); + // FIXME: use the JComboBox.getPrototypeDisplayValue() if there is + // one for (int i = 0; i < numItems; i++) { - Object item = model.getElementAt(i); - String s = item.toString(); - Component comp = renderer.getListCellRendererComponent(listBox, item, - -1, false, false); - - if (comp.getPreferredSize().getWidth() > size.getWidth()) - size = comp.getPreferredSize(); + Object item = model.getElementAt(i); + String s = item.toString(); + Component comp = renderer.getListCellRendererComponent(listBox, item, + -1, false, false); + + Dimension compSize = comp.getPreferredSize(); + if (compSize.width > size.width) + size.width = compSize.width; + if (compSize.height > size.height) + size.height = compSize.height; } - - largestItemSize = size; - return largestItemSize; + displaySize = size; + return displaySize; } /** - * This method installs the keyboard actions for the JComboBox as specified + * Installs the keyboard actions for the {@link JComboBox} as specified * by the look and feel. */ protected void installKeyboardActions() @@ -892,7 +869,7 @@ public class BasicComboBoxUI extends ComboBoxUI } /** - * This method uninstalls the keyboard actions for the JComboBox there were + * Uninstalls the keyboard actions for the {@link JComboBox} there were * installed by in {@link #installListeners}. */ protected void uninstallKeyboardActions() @@ -901,9 +878,12 @@ public class BasicComboBoxUI extends ComboBoxUI } /** - * This class is Layout Manager for this combo box. + * A {@link LayoutManager} used to position the sub-components of the + * {@link JComboBox}. + * + * @see BasicComboBoxUI#createLayoutManager() */ - public class ComboBoxLayoutManager extends Object implements LayoutManager + public class ComboBoxLayoutManager implements LayoutManager { /** * Creates a new ComboBoxLayoutManager object. @@ -912,11 +892,24 @@ public class BasicComboBoxUI extends ComboBoxUI { } + /** + * Adds a component to the layout. This method does nothing, since the + * layout manager doesn't need to track the components. + * + * @param name the name to associate the component with (ignored). + * @param comp the component (ignored). + */ public void addLayoutComponent(String name, Component comp) { // Do nothing } + /** + * Removes a component from the layout. This method does nothing, since + * the layout manager doesn't need to track the components. + * + * @param comp the component. + */ public void removeLayoutComponent(Component comp) { // Do nothing @@ -925,43 +918,30 @@ public class BasicComboBoxUI extends ComboBoxUI /** * Returns preferred layout size of the JComboBox. * - * @param parent Container for which preferred size should be calculated + * @param parent the Container for which the preferred size should be + * calculated. * - * @return preferred size for the given container + * @return The preferred size for the given container */ public Dimension preferredLayoutSize(Container parent) { - Dimension d = new Dimension(0, 0); - - if (largestItemSize == null) - largestItemSize = getLargestItemSize(); - - // add size for the area that will display selected item - d.width += largestItemSize.getWidth(); - d.height += largestItemSize.getHeight(); - - // add size of the arrow button - d.width += arrowButtonWidth; - - // add width and height of the border - d.width += borderInsets.left + borderInsets.right; - d.height += borderInsets.left + borderInsets.right; - - // Add combo box's insets - Insets insets = parent.getInsets(); - d.width += insets.left + insets.right; - d.width += insets.left + insets.right; - - return d; + return getPreferredSize((JComponent) parent); } + /** + * Returns the minimum layout size. + * + * @param parent the container. + * + * @return The minimum size. + */ public Dimension minimumLayoutSize(Container parent) { return preferredLayoutSize(parent); } /** - * This method layouts out the components in the container. It puts arrow + * Arranges the components in the container. It puts arrow * button right end part of the comboBox. If the comboBox is editable * then editor is placed to the left of arrow button, starting from the * beginning. @@ -972,21 +952,19 @@ public class BasicComboBoxUI extends ComboBoxUI { // Position editor component to the left of arrow button if combo box is // editable - int editorWidth = comboBox.getBounds().width - arrowButtonWidth - 2; + int arrowSize = comboBox.getHeight(); + int editorWidth = comboBox.getBounds().width - arrowSize; if (comboBox.isEditable()) - editor.setBounds(borderInsets.left, borderInsets.top, editorWidth, - comboBox.getBounds().height - borderInsets.left - - borderInsets.top); - - arrowButton.setBounds(editorWidth, 2, arrowButtonWidth, - comboBox.getBounds().height - 4); + editor.setBounds(0, 0, editorWidth, comboBox.getBounds().height); + + arrowButton.setBounds(editorWidth, 0, arrowSize, arrowSize); comboBox.revalidate(); } } /** - * This class handles focus changes occuring in the combo box. This class is + * Handles focus changes occuring in the combo box. This class is * responsible for repainting combo box whenever focus is gained or lost * and also for hiding popup list of items whenever combo box loses its * focus. @@ -1001,8 +979,8 @@ public class BasicComboBoxUI extends ComboBoxUI } /** - * This mehtod is invoked when combo box gains focus. It repaints main - * part of combo box accordingally. + * Invoked when combo box gains focus. It repaints main + * part of combo box accordingly. * * @param e the FocusEvent */ @@ -1013,8 +991,8 @@ public class BasicComboBoxUI extends ComboBoxUI } /** - * This method is invoked when combo box loses focus It repaint main part - * of combo box accordingally and hides popup list of items. + * Invoked when the combo box loses focus. It repaints the main part + * of the combo box accordingly and hides the popup list of items. * * @param e the FocusEvent */ @@ -1022,13 +1000,12 @@ public class BasicComboBoxUI extends ComboBoxUI { hasFocus = false; comboBox.repaint(); - popup.hide(); } } /** - * This class handles ItemEvent fired by the JComboBox when its selected - * item changes. + * Handles {@link ItemEvent}s fired by the {@link JComboBox} when its + * selected item changes. */ public class ItemHandler extends Object implements ItemListener { @@ -1040,7 +1017,7 @@ public class BasicComboBoxUI extends ComboBoxUI } /** - * This method is invoked when selected item becomes deselected or when + * Invoked when selected item becomes deselected or when * new item becomes selected. * * @param e the ItemEvent representing item's state change. @@ -1060,9 +1037,8 @@ public class BasicComboBoxUI extends ComboBoxUI { } - /* - * This method is invoked whenever key is pressed while JComboBox is in - * focus. + /** + * Invoked whenever key is pressed while JComboBox is in focus. */ public void keyPressed(KeyEvent e) { @@ -1072,7 +1048,7 @@ public class BasicComboBoxUI extends ComboBoxUI } /** - * This class handles to the changes occuring in the JComboBox's data model + * Handles the changes occurring in the JComboBox's data model. */ public class ListDataHandler extends Object implements ListDataListener { @@ -1084,7 +1060,7 @@ public class BasicComboBoxUI extends ComboBoxUI } /** - * This method is invoked content's of JComboBox's data model are changed + * Invoked if the content's of JComboBox's data model are changed. * * @param e ListDataEvent describing the change. */ @@ -1094,36 +1070,27 @@ public class BasicComboBoxUI extends ComboBoxUI } /** - * This method is invoked when items were added to the JComboBox's data - * model. + * Invoked when items are added to the JComboBox's data model. * * @param e ListDataEvent describing the change. */ public void intervalAdded(ListDataEvent e) { - // must determine if the size of the combo box should change - int start = e.getIndex0(); - int end = e.getIndex1(); - ComboBoxModel model = comboBox.getModel(); ListCellRenderer renderer = comboBox.getRenderer(); - if (largestItemSize == null) - largestItemSize = new Dimension(0, 0); + if (displaySize == null) + displaySize = getDisplaySize(); + if (displaySize.width < getDefaultSize().width) + displaySize.width = getDefaultSize().width; + if (displaySize.height < getDefaultSize().height) + displaySize.height = getDefaultSize().height; - for (int i = start; i < end; i++) - { - Object item = model.getElementAt(i); - Component comp = renderer.getListCellRendererComponent(new JList(), - item, -1, - false, false); - if (comp.getPreferredSize().getWidth() > largestItemSize.getWidth()) - largestItemSize = comp.getPreferredSize(); - } + comboBox.repaint(); } /** - * This method is invoked when items were removed from the JComboBox's + * Invoked when items are removed from the JComboBox's * data model. * * @param e ListDataEvent describing the change. @@ -1131,23 +1098,28 @@ public class BasicComboBoxUI extends ComboBoxUI public void intervalRemoved(ListDataEvent e) { // recalculate display size of the JComboBox. - largestItemSize = getLargestItemSize(); + displaySize = getDisplaySize(); comboBox.repaint(); } } /** - * This class handles PropertyChangeEvents fired by JComboBox. + * Handles {@link PropertyChangeEvent}s fired by the {@link JComboBox}. */ public class PropertyChangeHandler extends Object implements PropertyChangeListener { + /** + * Creates a new instance. + */ public PropertyChangeHandler() { } /** - * This method is invoked whenever bound property of JComboBox changes. + * Invoked whenever bound property of JComboBox changes. + * + * @param e the event. */ public void propertyChange(PropertyChangeEvent e) { @@ -1185,59 +1157,36 @@ public class BasicComboBoxUI extends ComboBoxUI if ((ComboBoxModel) e.getNewValue() != null) comboBox.getModel().addListDataListener(listDataListener); } + else if (e.getPropertyName().equals("font")) + { + Font font = (Font) e.getNewValue(); + editor.setFont(font); + listBox.setFont(font); + arrowButton.setFont(font); + comboBox.revalidate(); + comboBox.repaint(); + } // FIXME: Need to handle changes in other bound properties. } } /** - * MouseHandler listens to mouse events occuring in the combo box. This - * class is responsible for repainting this JComboBox whenever the mouse is - * being pressed or released over it. + * A handler for mouse events occurring in the combo box. An instance of + * this class is returned by the <code>createMouseListener()</code> method. */ private class MouseHandler extends MouseAdapter { /** - * This method is invoked when mouse is pressed over the combo box. It - * repaints the combo box accordinglly + * Invoked when mouse is pressed over the combo box. It toggles the + * visibility of the popup list. * - * @param e the MouseEvent + * @param e the event */ public void mousePressed(MouseEvent e) { if (comboBox.isEnabled()) - { - if (e.getSource() instanceof JComboBox) - { - arrowButton.getModel().setPressed(true); - arrowButton.getModel().setArmed(true); - } - - comboBox.repaint(); - - if (e.getSource() instanceof BasicArrowButton) - toggleOpenClose(); - } - } - - /** - * This method is invoked when mouse is released over the combo box. It - * repaints the combo box accordinglly - * - * @param e the MouseEvent - */ - public void mouseReleased(MouseEvent e) - { - if (comboBox.isEnabled()) - { - if (e.getSource() instanceof JComboBox) - { - arrowButton.getModel().setPressed(false); - arrowButton.getModel().setArmed(false); - } - - comboBox.repaint(); - } + toggleOpenClose(); } } } diff --git a/javax/swing/plaf/basic/BasicFileChooserUI.java b/javax/swing/plaf/basic/BasicFileChooserUI.java index 2e38c012b..49013e199 100644 --- a/javax/swing/plaf/basic/BasicFileChooserUI.java +++ b/javax/swing/plaf/basic/BasicFileChooserUI.java @@ -277,7 +277,7 @@ public class BasicFileChooserUI extends FileChooserUI */ public Boolean isHidden(File f) { - return new Boolean(filechooser.getFileSystemView().isHiddenFile(f)); + return Boolean.valueOf(filechooser.getFileSystemView().isHiddenFile(f)); } } @@ -945,7 +945,7 @@ public class BasicFileChooserUI extends FileChooserUI File currDir = null; JPanel bottomPanel; - + /** DOCUMENT ME! */ JPanel closePanel; @@ -997,46 +997,6 @@ public class BasicFileChooserUI extends FileChooserUI } } - /** - * DOCUMENT ME! - */ - public class CBLabelRenderer extends JLabel implements ListCellRenderer - { - /** - * Creates a new CBLabelRenderer object. - */ - public CBLabelRenderer() - { - super(); - setOpaque(true); - } - - /** - * DOCUMENT ME! - * - * @param list DOCUMENT ME! - * @param value DOCUMENT ME! - * @param index DOCUMENT ME! - * @param isSelected DOCUMENT ME! - * @param cellHasFocus DOCUMENT ME! - * - * @return DOCUMENT ME! - */ - public Component getListCellRendererComponent(JList list, Object value, - int index, - boolean isSelected, - boolean cellHasFocus) - { - setHorizontalAlignment(SwingConstants.LEFT); - setIcon(directoryIcon); - setText(value.toString()); - setForeground(Color.BLACK); - setBackground(Color.WHITE); - - return this; - } - } - void closeDialog() { Window owner = SwingUtilities.windowForComponent(filechooser); @@ -1210,7 +1170,7 @@ public class BasicFileChooserUI extends FileChooserUI JLabel look = new JLabel("Look In:"); parents = new JComboBox(); - parents.setRenderer(new CBLabelRenderer()); + parents.setRenderer(new BasicComboBoxRenderer()); boxEntries(); look.setLabelFor(parents); JPanel parentsPanel = new JPanel(); @@ -1242,9 +1202,9 @@ public class BasicFileChooserUI extends FileChooserUI buttonPanel.add(detailsViewButton); JPanel topPanel = new JPanel(); - topPanel.setLayout(new java.awt.FlowLayout()); + parentsPanel.add(buttonPanel); + topPanel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 0, 0)); topPanel.add(parentsPanel); - topPanel.add(buttonPanel); accessoryPanel = new JPanel(); if (filechooser.getAccessory() != null) diff --git a/javax/swing/plaf/basic/BasicFormattedTextFieldUI.java b/javax/swing/plaf/basic/BasicFormattedTextFieldUI.java index 3abd76fe2..efef5d6d7 100644 --- a/javax/swing/plaf/basic/BasicFormattedTextFieldUI.java +++ b/javax/swing/plaf/basic/BasicFormattedTextFieldUI.java @@ -1,5 +1,5 @@ /* BasicFormattedTextFieldUI.java - Copyright (C) 2004 Free Software Foundation, Inc. + Copyright (C) 2004, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -39,6 +39,7 @@ exception statement from your version. */ package javax.swing.plaf.basic; import javax.swing.JComponent; +import javax.swing.UIDefaults; import javax.swing.plaf.ComponentUI; /** @@ -55,6 +56,11 @@ public class BasicFormattedTextFieldUI extends BasicTextFieldUI return new BasicFormattedTextFieldUI(); } + /** + * Returns the prefix for entries in the {@link UIDefaults} table. + * + * @return "FormattedTextField" + */ protected String getPropertyPrefix() { return "FormattedTextField"; diff --git a/javax/swing/plaf/basic/BasicInternalFrameTitlePane.java b/javax/swing/plaf/basic/BasicInternalFrameTitlePane.java index cc262948d..eded1c7fa 100644 --- a/javax/swing/plaf/basic/BasicInternalFrameTitlePane.java +++ b/javax/swing/plaf/basic/BasicInternalFrameTitlePane.java @@ -84,6 +84,14 @@ public class BasicInternalFrameTitlePane extends JComponent public class CloseAction extends AbstractAction { /** + * Creates a new action. + */ + public CloseAction() + { + super("Close"); + } + + /** * This method is called when something closes the JInternalFrame. * * @param e The ActionEvent. @@ -113,6 +121,14 @@ public class BasicInternalFrameTitlePane extends JComponent public class IconifyAction extends AbstractAction { /** + * Creates a new action. + */ + public IconifyAction() + { + super("Minimize"); + } + + /** * This method is called when the user wants to iconify the * JInternalFrame. * @@ -143,6 +159,13 @@ public class BasicInternalFrameTitlePane extends JComponent public class MaximizeAction extends AbstractAction { /** + * Creates a new action. + */ + public MaximizeAction() + { + super("Maximize"); + } + /** * This method is called when the user wants to maximize the * JInternalFrame. * @@ -173,6 +196,13 @@ public class BasicInternalFrameTitlePane extends JComponent public class MoveAction extends AbstractAction { /** + * Creates a new action. + */ + public MoveAction() + { + super("Move"); + } + /** * This method is called when the user wants to drag the JInternalFrame. * * @param e The ActionEvent. @@ -194,6 +224,13 @@ public class BasicInternalFrameTitlePane extends JComponent public class RestoreAction extends AbstractAction { /** + * Creates a new action. + */ + public RestoreAction() + { + super("Restore"); + } + /** * This method is called when the user wants to restore the * JInternalFrame. * @@ -224,6 +261,13 @@ public class BasicInternalFrameTitlePane extends JComponent public class SizeAction extends AbstractAction { /** + * Creates a new action. + */ + public SizeAction() + { + super("Size"); + } + /** * This method is called when the user wants to resize the JInternalFrame. * * @param e The ActionEvent. @@ -377,24 +421,26 @@ public class BasicInternalFrameTitlePane extends JComponent int loc = width + insets.left - 1; int top = insets.top + 1; - int buttonWidth = height - 2; int buttonHeight = height - 4; if (closeButton.isVisible()) { - loc -= buttonWidth + 2; - closeButton.setBounds(loc, top, buttonWidth, buttonHeight); + int buttonWidth = closeIcon.getIconWidth(); + loc -= buttonWidth + 2; + closeButton.setBounds(loc, top, buttonWidth, buttonHeight); } if (maxButton.isVisible()) { - loc -= buttonWidth + 2; - maxButton.setBounds(loc, top, buttonWidth, buttonHeight); + int buttonWidth = maxIcon.getIconWidth(); + loc -= buttonWidth + 2; + maxButton.setBounds(loc, top, buttonWidth, buttonHeight); } if (iconButton.isVisible()) { - loc -= buttonWidth + 2; - iconButton.setBounds(loc, top, buttonWidth, buttonHeight); + int buttonWidth = iconIcon.getIconWidth(); + loc -= buttonWidth + 2; + iconButton.setBounds(loc, top, buttonWidth, buttonHeight); } if (title != null) @@ -466,6 +512,7 @@ public class BasicInternalFrameTitlePane extends JComponent // These buttons cannot be given focus. return false; } + } /** The action command for the Close action. */ @@ -522,6 +569,9 @@ public class BasicInternalFrameTitlePane extends JComponent /** The icon displayed in the iconify button. */ protected Icon iconIcon = BasicIconFactory.createEmptyFrameIcon(); + /** The icon displayed in the close button. */ + protected Icon closeIcon; + /** The JInternalFrame that this TitlePane is used in. */ protected JInternalFrame frame; @@ -645,7 +695,7 @@ public class BasicInternalFrameTitlePane extends JComponent */ protected void installListeners() { - propertyChangeListener = new PropertyChangeHandler(); + propertyChangeListener = createPropertyChangeListener(); frame.addPropertyChangeListener(propertyChangeListener); } @@ -663,14 +713,17 @@ public class BasicInternalFrameTitlePane extends JComponent */ protected void installDefaults() { - // FIXME: move icons to defaults. UIDefaults defaults = UIManager.getLookAndFeelDefaults(); - setFont(defaults.getFont("InternalFrame.titleFont")); + title.setFont(defaults.getFont("InternalFrame.titleFont")); selectedTextColor = defaults.getColor("InternalFrame.activeTitleForeground"); selectedTitleColor = defaults.getColor("InternalFrame.activeTitleBackground"); notSelectedTextColor = defaults.getColor("InternalFrame.inactiveTitleForeground"); notSelectedTitleColor = defaults.getColor("InternalFrame.inactiveTitleBackground"); + + closeIcon = UIManager.getIcon("InternalFrame.closeIcon"); + iconIcon = UIManager.getIcon("InternalFrame.iconifyIcon"); + maxIcon = UIManager.getIcon("InternalFrame.maximizeIcon"); } /** @@ -683,6 +736,10 @@ public class BasicInternalFrameTitlePane extends JComponent selectedTitleColor = null; notSelectedTextColor = null; notSelectedTitleColor = null; + + closeIcon = null; + iconIcon = null; + maxIcon = null; } /** @@ -691,12 +748,15 @@ public class BasicInternalFrameTitlePane extends JComponent protected void createButtons() { closeButton = new PaneButton(closeAction); + closeButton.setText(null); if (!frame.isClosable()) closeButton.setVisible(false); iconButton = new PaneButton(iconifyAction); + iconButton.setText(null); if (!frame.isIconifiable()) iconButton.setVisible(false); maxButton = new PaneButton(maximizeAction); + maxButton.setText(null); if (!frame.isMaximizable()) maxButton.setVisible(false); } @@ -706,15 +766,12 @@ public class BasicInternalFrameTitlePane extends JComponent */ protected void setButtonIcons() { - Icon icon = UIManager.getIcon("InternalFrame.closeIcon"); - if (icon != null) - closeButton.setIcon(icon); - icon = UIManager.getIcon("InternalFrame.iconifyIcon"); - if (icon != null) - iconButton.setIcon(icon); - icon = UIManager.getIcon("InternalFrame.maximizeIcon"); - if (icon != null) - maxButton.setIcon(icon); + if (closeIcon != null) + closeButton.setIcon(closeIcon); + if (iconIcon != null) + iconButton.setIcon(iconIcon); + if (maxIcon != null) + maxButton.setIcon(maxIcon); } /** @@ -816,11 +873,12 @@ public class BasicInternalFrameTitlePane extends JComponent public void paintComponent(Graphics g) { paintTitleBackground(g); - Font f = g.getFont(); - FontMetrics fm = g.getFontMetrics(f); if (frame.getTitle() != null && title != null) { Color saved = g.getColor(); + Font f = title.getFont(); + g.setFont(f); + FontMetrics fm = g.getFontMetrics(f); if (frame.isSelected()) g.setColor(selectedTextColor); else diff --git a/javax/swing/plaf/basic/BasicInternalFrameUI.java b/javax/swing/plaf/basic/BasicInternalFrameUI.java index 8f76ea0cc..5f20fecff 100644 --- a/javax/swing/plaf/basic/BasicInternalFrameUI.java +++ b/javax/swing/plaf/basic/BasicInternalFrameUI.java @@ -202,67 +202,66 @@ public class BasicInternalFrameUI extends InternalFrameUI */ public void mouseDragged(MouseEvent e) { - // If the frame is maximized, there is nothing that + // If the frame is maximized, there is nothing that // can be dragged around. if (frame.isMaximum()) - return; + return; DesktopManager dm = getDesktopManager(); Rectangle b = frame.getBounds(); Dimension min = frame.getMinimumSize(); if (min == null) - min = new Dimension(0, 0); + min = new Dimension(0, 0); Insets insets = frame.getInsets(); int x = e.getX(); int y = e.getY(); if (e.getSource() == frame && frame.isResizable()) { - switch (direction) - { - case NORTH: - cacheRect.setBounds(b.x, - Math.min(b.y + y, b.y + b.height - - min.height), b.width, b.height - - y); - break; - case NORTH_EAST: - cacheRect.setBounds(b.x, - Math.min(b.y + y, b.y + b.height - - min.height), x, b.height - y); - break; - case EAST: - cacheRect.setBounds(b.x, b.y, x, b.height); - break; - case SOUTH_EAST: - cacheRect.setBounds(b.x, b.y, x, y); - break; - case SOUTH: - cacheRect.setBounds(b.x, b.y, b.width, y); - break; - case SOUTH_WEST: - cacheRect.setBounds(Math.min(b.x + x, b.x + b.width - min.width), - b.y, b.width - x, y); - break; - case WEST: - cacheRect.setBounds(Math.min(b.x + x, b.x + b.width - min.width), - b.y, b.width - x, b.height); - break; - case NORTH_WEST: - cacheRect.setBounds(Math.min(b.x + x, b.x + b.width - min.width), - Math.min(b.y + y, b.y + b.height - - min.height), b.width - x, - b.height - y); - break; - } - dm.resizeFrame(frame, cacheRect.x, cacheRect.y, - Math.max(min.width, cacheRect.width), - Math.max(min.height, cacheRect.height)); + switch (direction) + { + case NORTH: + cacheRect.setBounds(b.x, Math.min(b.y + y, b.y + b.height + - min.height), + b.width, b.height - y); + break; + case NORTH_EAST: + cacheRect.setBounds(b.x, Math.min(b.y + y, b.y + b.height + - min.height), x, + b.height - y); + break; + case EAST: + cacheRect.setBounds(b.x, b.y, x, b.height); + break; + case SOUTH_EAST: + cacheRect.setBounds(b.x, b.y, x, y); + break; + case SOUTH: + cacheRect.setBounds(b.x, b.y, b.width, y); + break; + case SOUTH_WEST: + cacheRect.setBounds(Math.min(b.x + x, b.x + b.width - min.width), + b.y, b.width - x, y); + break; + case WEST: + cacheRect.setBounds(Math.min(b.x + x, b.x + b.width - min.width), + b.y, b.width - x, b.height); + break; + case NORTH_WEST: + cacheRect.setBounds( + Math.min(b.x + x, b.x + b.width - min.width), + Math.min(b.y + y, b.y + b.height - min.height), + b.width - x, b.height - y); + break; + } + dm.resizeFrame(frame, cacheRect.x, cacheRect.y, + Math.max(min.width, cacheRect.width), + Math.max(min.height, cacheRect.height)); } else if (e.getSource() == titlePane) { - Rectangle fBounds = frame.getBounds(); + Rectangle fBounds = frame.getBounds(); - dm.dragFrame(frame, e.getX() - xOffset + b.x, - e.getY() - yOffset + b.y); + dm.dragFrame(frame, e.getX() - xOffset + b.x, e.getY() - yOffset + + b.y); } } @@ -304,17 +303,17 @@ public class BasicInternalFrameUI extends InternalFrameUI if (e.getSource() == frame && frame.isResizable()) { - direction = sectionOfClick(x, y); - dm.beginResizingFrame(frame, direction); + direction = sectionOfClick(x, y); + dm.beginResizingFrame(frame, direction); } else if (e.getSource() == titlePane) { - Rectangle tBounds = titlePane.getBounds(); + Rectangle tBounds = titlePane.getBounds(); - xOffset = e.getX() - tBounds.x + insets.left; - yOffset = e.getY() - tBounds.y + insets.top; + xOffset = e.getX() - tBounds.x + insets.left; + yOffset = e.getY() - tBounds.y + insets.top; - dm.beginDraggingFrame(frame); + dm.beginDraggingFrame(frame); } } @@ -329,9 +328,9 @@ public class BasicInternalFrameUI extends InternalFrameUI xOffset = 0; yOffset = 0; if (e.getSource() == frame && frame.isResizable()) - dm.endResizingFrame(frame); + dm.endResizingFrame(frame); else if (e.getSource() == titlePane) - dm.endDraggingFrame(frame); + dm.endDraggingFrame(frame); } /** @@ -348,21 +347,21 @@ public class BasicInternalFrameUI extends InternalFrameUI Insets insets = frame.getInsets(); Rectangle b = frame.getBounds(); if (x < insets.left && y < insets.top) - return NORTH_WEST; + return NORTH_WEST; else if (x > b.width - insets.right && y < insets.top) - return NORTH_EAST; + return NORTH_EAST; else if (x > b.width - insets.right && y > b.height - insets.bottom) - return SOUTH_EAST; + return SOUTH_EAST; else if (x < insets.left && y > b.height - insets.bottom) - return SOUTH_WEST; + return SOUTH_WEST; else if (y < insets.top) - return NORTH; + return NORTH; else if (x < insets.left) - return WEST; + return WEST; else if (y > b.height - insets.bottom) - return SOUTH; + return SOUTH; else if (x > b.width - insets.right) - return EAST; + return EAST; return -1; } @@ -377,8 +376,9 @@ public class BasicInternalFrameUI extends InternalFrameUI { /** * This method is called when the JDesktopPane is hidden. - * - * @param e The ComponentEvent fired. + * + * @param e + * The ComponentEvent fired. */ public void componentHidden(ComponentEvent e) { @@ -387,8 +387,9 @@ public class BasicInternalFrameUI extends InternalFrameUI /** * This method is called when the JDesktopPane is moved. - * - * @param e The ComponentEvent fired. + * + * @param e + * The ComponentEvent fired. */ public void componentMoved(ComponentEvent e) { @@ -397,22 +398,23 @@ public class BasicInternalFrameUI extends InternalFrameUI /** * This method is called when the JDesktopPane is resized. - * - * @param e The ComponentEvent fired. + * + * @param e + * The ComponentEvent fired. */ public void componentResized(ComponentEvent e) { if (frame.isMaximum()) { - JDesktopPane pane = (JDesktopPane) e.getSource(); - Insets insets = pane.getInsets(); - Rectangle bounds = pane.getBounds(); - - frame.setBounds(bounds.x + insets.left, bounds.y + insets.top, - bounds.width - insets.left - insets.right, - bounds.height - insets.top - insets.bottom); - frame.revalidate(); - frame.repaint(); + JDesktopPane pane = (JDesktopPane) e.getSource(); + Insets insets = pane.getInsets(); + Rectangle bounds = pane.getBounds(); + + frame.setBounds(bounds.x + insets.left, bounds.y + insets.top, + bounds.width - insets.left - insets.right, + bounds.height - insets.top - insets.bottom); + frame.revalidate(); + frame.repaint(); } // Sun also resizes the icons. but it doesn't seem to do anything. @@ -420,8 +422,9 @@ public class BasicInternalFrameUI extends InternalFrameUI /** * This method is called when the JDesktopPane is shown. - * - * @param e The ComponentEvent fired. + * + * @param e + * The ComponentEvent fired. */ public void componentShown(ComponentEvent e) { @@ -435,11 +438,13 @@ public class BasicInternalFrameUI extends InternalFrameUI public class InternalFrameLayout implements LayoutManager { /** - * This method is called when the given Component is added to the + * This method is called when the given Component is added to the * JInternalFrame. - * - * @param name The name of the Component. - * @param c The Component added. + * + * @param name + * The name of the Component. + * @param c + * The Component added. */ public void addLayoutComponent(String name, Component c) { @@ -448,8 +453,9 @@ public class BasicInternalFrameUI extends InternalFrameUI /** * This method is used to set the bounds of the children of the * JInternalFrame. - * - * @param c The Container to lay out. + * + * @param c + * The Container to lay out. */ public void layoutContainer(Container c) { @@ -468,38 +474,38 @@ public class BasicInternalFrameUI extends InternalFrameUI if (northPane != null) { - Dimension nDims = northPane.getPreferredSize(); - nh = Math.min(nDims.height, dims.height); + Dimension nDims = northPane.getPreferredSize(); + nh = Math.min(nDims.height, dims.height); - northPane.setBounds(insets.left, insets.top, dims.width, nh); + northPane.setBounds(insets.left, insets.top, dims.width, nh); } if (southPane != null) { - Dimension sDims = southPane.getPreferredSize(); - sh = Math.min(sDims.height, dims.height - nh); + Dimension sDims = southPane.getPreferredSize(); + sh = Math.min(sDims.height, dims.height - nh); - southPane.setBounds(insets.left, insets.top + dims.height - sh, - dims.width, sh); + southPane.setBounds(insets.left, insets.top + dims.height - sh, + dims.width, sh); } int remHeight = dims.height - sh - nh; if (westPane != null) { - Dimension wDims = westPane.getPreferredSize(); - ww = Math.min(dims.width, wDims.width); + Dimension wDims = westPane.getPreferredSize(); + ww = Math.min(dims.width, wDims.width); - westPane.setBounds(insets.left, insets.top + nh, ww, remHeight); + westPane.setBounds(insets.left, insets.top + nh, ww, remHeight); } if (eastPane != null) { - Dimension eDims = eastPane.getPreferredSize(); - ew = Math.min(eDims.width, dims.width - ww); + Dimension eDims = eastPane.getPreferredSize(); + ew = Math.min(eDims.width, dims.width - ww); - eastPane.setBounds(insets.left + dims.width - ew, insets.top + nh, - ew, remHeight); + eastPane.setBounds(insets.left + dims.width - ew, insets.top + nh, + ew, remHeight); } int remWidth = dims.width - ww - ew; @@ -510,9 +516,9 @@ public class BasicInternalFrameUI extends InternalFrameUI /** * This method returns the minimum layout size. - * - * @param c The Container to find a minimum layout size for. - * + * + * @param c + * The Container to find a minimum layout size for. * @return The minimum dimensions for the JInternalFrame. */ public Dimension minimumLayoutSize(Container c) @@ -522,9 +528,9 @@ public class BasicInternalFrameUI extends InternalFrameUI /** * This method returns the maximum layout size. - * - * @param c The Container to find a maximum layout size for. - * + * + * @param c + * The Container to find a maximum layout size for. * @return The maximum dimensions for the JInternalFrame. */ public Dimension maximumLayoutSize(Container c) @@ -534,9 +540,9 @@ public class BasicInternalFrameUI extends InternalFrameUI /** * Th8is method returns the preferred layout size. - * - * @param c The Container to find a preferred layout size for. - * + * + * @param c + * The Container to find a preferred layout size for. * @return The preferred dimensions for the JInternalFrame. */ public Dimension preferredLayoutSize(Container c) @@ -546,10 +552,11 @@ public class BasicInternalFrameUI extends InternalFrameUI /** * DOCUMENT ME! - * - * @param c DOCUMENT ME! - * @param min DOCUMENT ME! - * + * + * @param c + * DOCUMENT ME! + * @param min + * DOCUMENT ME! * @return DOCUMENT ME! */ private Dimension getSize(Container c, boolean min) @@ -558,7 +565,7 @@ public class BasicInternalFrameUI extends InternalFrameUI Dimension contentDims = frame.getContentPane().getPreferredSize(); if (min) - contentDims.width = contentDims.height = 0; + contentDims.width = contentDims.height = 0; int nWidth = 0; int nHeight = 0; int sWidth = 0; @@ -571,42 +578,42 @@ public class BasicInternalFrameUI extends InternalFrameUI if (northPane != null) { - dims = northPane.getPreferredSize(); - if (dims != null) - { - nWidth = dims.width; - nHeight = dims.height; - } + dims = northPane.getPreferredSize(); + if (dims != null) + { + nWidth = dims.width; + nHeight = dims.height; + } } if (southPane != null) { - dims = southPane.getPreferredSize(); - if (dims != null) - { - sWidth = dims.width; - sHeight = dims.height; - } + dims = southPane.getPreferredSize(); + if (dims != null) + { + sWidth = dims.width; + sHeight = dims.height; + } } if (eastPane != null) { - dims = eastPane.getPreferredSize(); - if (dims != null) - { - sWidth = dims.width; - sHeight = dims.height; - } + dims = eastPane.getPreferredSize(); + if (dims != null) + { + sWidth = dims.width; + sHeight = dims.height; + } } if (westPane != null) { - dims = westPane.getPreferredSize(); - if (dims != null) - { - wWidth = dims.width; - wHeight = dims.height; - } + dims = westPane.getPreferredSize(); + if (dims != null) + { + wWidth = dims.width; + wHeight = dims.height; + } } int width = Math.max(sWidth, nWidth); @@ -657,8 +664,9 @@ public class BasicInternalFrameUI extends InternalFrameUI /** * This method is called when the mouse enters the glass pane. - * - * @param e The MouseEvent. + * + * @param e + * The MouseEvent. */ public void mouseEntered(MouseEvent e) { @@ -667,8 +675,9 @@ public class BasicInternalFrameUI extends InternalFrameUI /** * This method is called when the mouse is clicked on the glass pane. - * - * @param e The MouseEvent. + * + * @param e + * The MouseEvent. */ public void mouseClicked(MouseEvent e) { @@ -677,8 +686,9 @@ public class BasicInternalFrameUI extends InternalFrameUI /** * This method is called when the mouse is dragged in the glass pane. - * - * @param e The MouseEvent. + * + * @param e + * The MouseEvent. */ public void mouseDragged(MouseEvent e) { @@ -687,8 +697,9 @@ public class BasicInternalFrameUI extends InternalFrameUI /** * This method is called when the mouse exits the glass pane. - * - * @param e The MouseEvent. + * + * @param e + * The MouseEvent. */ public void mouseExited(MouseEvent e) { @@ -697,8 +708,9 @@ public class BasicInternalFrameUI extends InternalFrameUI /** * This method is called when the mouse is moved in the glass pane. - * - * @param e The MouseEvent. + * + * @param e + * The MouseEvent. */ public void mouseMoved(MouseEvent e) { @@ -706,9 +718,10 @@ public class BasicInternalFrameUI extends InternalFrameUI } /** - * This method is called when the mouse is pressed in the glass pane. - * - * @param e The MouseEvent. + * This method is called when the mouse is pressed in the glass pane. + * + * @param e + * The MouseEvent. */ public void mousePressed(MouseEvent e) { @@ -717,9 +730,10 @@ public class BasicInternalFrameUI extends InternalFrameUI } /** - * This method is called when the mouse is released in the glass pane. - * - * @param e The MouseEvent. + * This method is called when the mouse is released in the glass pane. + * + * @param e + * The MouseEvent. */ public void mouseReleased(MouseEvent e) { @@ -727,10 +741,10 @@ public class BasicInternalFrameUI extends InternalFrameUI } /** - * This method acquires a candidate component to dispatch the MouseEvent - * to. - * - * @param me The MouseEvent to acquire a component for. + * This method acquires a candidate component to dispatch the MouseEvent to. + * + * @param me + * The MouseEvent to acquire a component for. */ private void acquireComponentForMouseEvent(MouseEvent me) { @@ -740,132 +754,135 @@ public class BasicInternalFrameUI extends InternalFrameUI // Find the candidate which should receive this event. Component parent = frame.getContentPane(); if (parent == null) - return; + return; Component candidate = null; Point p = me.getPoint(); while (candidate == null && parent != null) { - candidate = SwingUtilities.getDeepestComponentAt(parent, p.x, p.y); - if (candidate == null) - { - p = SwingUtilities.convertPoint(parent, p.x, p.y, - parent.getParent()); - parent = parent.getParent(); - } + candidate = SwingUtilities.getDeepestComponentAt(parent, p.x, p.y); + if (candidate == null) + { + p = SwingUtilities.convertPoint(parent, p.x, p.y, + parent.getParent()); + parent = parent.getParent(); + } } // If the only candidate we found was the native container itself, - // don't dispatch any event at all. We only care about the lightweight + // don't dispatch any event at all. We only care about the lightweight // children here. if (candidate == frame.getContentPane()) - candidate = null; + candidate = null; // If our candidate is new, inform the old target we're leaving. if (lastComponentEntered != null && lastComponentEntered.isShowing() && lastComponentEntered != candidate) { - Point tp = SwingUtilities.convertPoint(frame.getContentPane(), x, y, - lastComponentEntered); - MouseEvent exited = new MouseEvent(lastComponentEntered, - MouseEvent.MOUSE_EXITED, - me.getWhen(), me.getModifiersEx(), - tp.x, tp.y, me.getClickCount(), - me.isPopupTrigger(), - me.getButton()); + Point tp = SwingUtilities.convertPoint(frame.getContentPane(), x, y, + lastComponentEntered); + MouseEvent exited = new MouseEvent(lastComponentEntered, + MouseEvent.MOUSE_EXITED, + me.getWhen(), me.getModifiersEx(), + tp.x, tp.y, me.getClickCount(), + me.isPopupTrigger(), + me.getButton()); tempComponent = lastComponentEntered; - lastComponentEntered = null; - tempComponent.dispatchEvent(exited); + lastComponentEntered = null; + tempComponent.dispatchEvent(exited); } // If we have a candidate, maybe enter it. if (candidate != null) { - mouseEventTarget = candidate; - if (candidate.isLightweight() && candidate.isShowing() - && candidate != frame.getContentPane() - && candidate != lastComponentEntered) - { - lastComponentEntered = mouseEventTarget; - Point cp = SwingUtilities.convertPoint(frame.getContentPane(), - x, y, lastComponentEntered); - MouseEvent entered = new MouseEvent(lastComponentEntered, - MouseEvent.MOUSE_ENTERED, - me.getWhen(), - me.getModifiersEx(), cp.x, - cp.y, me.getClickCount(), - me.isPopupTrigger(), - me.getButton()); - lastComponentEntered.dispatchEvent(entered); - } + mouseEventTarget = candidate; + if (candidate.isLightweight() && candidate.isShowing() + && candidate != frame.getContentPane() + && candidate != lastComponentEntered) + { + lastComponentEntered = mouseEventTarget; + Point cp = SwingUtilities.convertPoint(frame.getContentPane(), x, + y, lastComponentEntered); + MouseEvent entered = new MouseEvent(lastComponentEntered, + MouseEvent.MOUSE_ENTERED, + me.getWhen(), + me.getModifiersEx(), cp.x, + cp.y, me.getClickCount(), + me.isPopupTrigger(), + me.getButton()); + lastComponentEntered.dispatchEvent(entered); + } } if (me.getID() == MouseEvent.MOUSE_RELEASED || me.getID() == MouseEvent.MOUSE_PRESSED && pressCount > 0 || me.getID() == MouseEvent.MOUSE_DRAGGED) - // If any of the following events occur while a button is held down, - // they should be dispatched to the same component to which the - // original MOUSE_PRESSED event was dispatched: - // - MOUSE_RELEASED - // - MOUSE_PRESSED: another button pressed while the first is held down - // - MOUSE_DRAGGED - mouseEventTarget = pressedComponent; + // If any of the following events occur while a button is held down, + // they should be dispatched to the same component to which the + // original MOUSE_PRESSED event was dispatched: + // - MOUSE_RELEASED + // - MOUSE_PRESSED: another button pressed while the first is held down + // - MOUSE_DRAGGED + mouseEventTarget = pressedComponent; else if (me.getID() == MouseEvent.MOUSE_CLICKED) { - // Don't dispatch CLICKED events whose target is not the same as the - // target for the original PRESSED event. - if (candidate != pressedComponent) - mouseEventTarget = null; - else if (pressCount == 0) - pressedComponent = null; + // Don't dispatch CLICKED events whose target is not the same as the + // target for the original PRESSED event. + if (candidate != pressedComponent) + mouseEventTarget = null; + else if (pressCount == 0) + pressedComponent = null; } } /** - * This is a helper method that dispatches the GlassPane MouseEvents to - * the proper component. - * - * @param e The AWTEvent to be dispatched. Usually an instance of - * MouseEvent. + * This is a helper method that dispatches the GlassPane MouseEvents to the + * proper component. + * + * @param e + * The AWTEvent to be dispatched. Usually an instance of + * MouseEvent. */ private void handleEvent(AWTEvent e) { if (e instanceof MouseEvent) { - MouseEvent me = SwingUtilities.convertMouseEvent(frame.getRootPane() - .getGlassPane(), - (MouseEvent) e, - frame.getRootPane() - .getGlassPane()); - - acquireComponentForMouseEvent(me); - - // Avoid dispatching ENTERED and EXITED events twice. - if (mouseEventTarget != null && mouseEventTarget.isShowing() - && e.getID() != MouseEvent.MOUSE_ENTERED - && e.getID() != MouseEvent.MOUSE_EXITED) - { - MouseEvent newEvt = SwingUtilities.convertMouseEvent(frame - .getContentPane(), - me, - mouseEventTarget); - mouseEventTarget.dispatchEvent(newEvt); - - switch (e.getID()) - { - case MouseEvent.MOUSE_PRESSED: - if (pressCount++ == 0) - pressedComponent = mouseEventTarget; - break; - case MouseEvent.MOUSE_RELEASED: - // Clear our memory of the original PRESSED event, only if - // we're not expecting a CLICKED event after this. If - // there is a CLICKED event after this, it will do clean up. - if (--pressCount == 0 - && mouseEventTarget != pressedComponent) - pressedComponent = null; - break; - } - } + MouseEvent me = (MouseEvent) e; + acquireComponentForMouseEvent(me); + + //If there is no target, return + if (mouseEventTarget == null) + return; + + //Avoid re-dispatching to ourselves and causing an infinite loop + if (mouseEventTarget.equals(frame.getGlassPane())) + return; + + // Avoid dispatching ENTERED and EXITED events twice. + if (mouseEventTarget.isShowing() + && e.getID() != MouseEvent.MOUSE_ENTERED + && e.getID() != MouseEvent.MOUSE_EXITED) + { + MouseEvent newEvt = SwingUtilities.convertMouseEvent( + frame.getGlassPane(), + me, + mouseEventTarget); + mouseEventTarget.dispatchEvent(newEvt); + + switch (e.getID()) + { + case MouseEvent.MOUSE_PRESSED: + if (pressCount++ == 0) + pressedComponent = mouseEventTarget; + break; + case MouseEvent.MOUSE_RELEASED: + // Clear our memory of the original PRESSED event, only if + // we're not expecting a CLICKED event after this. If + // there is a CLICKED event after this, it will do clean up. + if (--pressCount == 0 && mouseEventTarget != pressedComponent) + pressedComponent = null; + break; + } + } } } } @@ -874,17 +891,18 @@ public class BasicInternalFrameUI extends InternalFrameUI * This helper class listens for PropertyChangeEvents from the * JInternalFrame. */ - public class InternalFramePropertyChangeListener - implements PropertyChangeListener, VetoableChangeListener + public class InternalFramePropertyChangeListener implements + PropertyChangeListener, VetoableChangeListener { /** - * This method is called when one of the JInternalFrame's properties - * change. This method is to allow JInternalFrame to veto an attempt - * to close the internal frame. This allows JInternalFrame to honour - * its defaultCloseOperation if that is DO_NOTHING_ON_CLOSE. + * This method is called when one of the JInternalFrame's properties change. + * This method is to allow JInternalFrame to veto an attempt to close the + * internal frame. This allows JInternalFrame to honour its + * defaultCloseOperation if that is DO_NOTHING_ON_CLOSE. */ - public void vetoableChange(PropertyChangeEvent e) throws PropertyVetoException + public void vetoableChange(PropertyChangeEvent e) + throws PropertyVetoException { if (e.getPropertyName().equals(JInternalFrame.IS_CLOSED_PROPERTY)) { @@ -892,75 +910,78 @@ public class BasicInternalFrameUI extends InternalFrameUI { frame.setVisible(false); frame.getDesktopPane().repaint(); - throw new PropertyVetoException ("close operation is HIDE_ON_CLOSE\n", e); + throw new PropertyVetoException( + "close operation is HIDE_ON_CLOSE\n", + e); } else if (frame.getDefaultCloseOperation() == JInternalFrame.DISPOSE_ON_CLOSE) closeFrame(frame); else - throw new PropertyVetoException ("close operation is DO_NOTHING_ON_CLOSE\n", e); + throw new PropertyVetoException( + "close operation is DO_NOTHING_ON_CLOSE\n", + e); } } - + /** - * This method is called when one of the JInternalFrame's properties - * change. - * - * @param evt The PropertyChangeEvent. + * This method is called when one of the JInternalFrame's properties change. + * + * @param evt + * The PropertyChangeEvent. */ public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals(JInternalFrame.IS_MAXIMUM_PROPERTY)) { - if (frame.isMaximum()) - maximizeFrame(frame); - else - minimizeFrame(frame); + if (frame.isMaximum()) + maximizeFrame(frame); + else + minimizeFrame(frame); } else if (evt.getPropertyName().equals(JInternalFrame.IS_ICON_PROPERTY)) { - if (frame.isIcon()) - iconifyFrame(frame); - else - deiconifyFrame(frame); + if (frame.isIcon()) + iconifyFrame(frame); + else + deiconifyFrame(frame); } else if (evt.getPropertyName().equals(JInternalFrame.IS_SELECTED_PROPERTY)) { - if (frame.isSelected()) - activateFrame(frame); - else - getDesktopManager().deactivateFrame(frame); + if (frame.isSelected()) + activateFrame(frame); + else + getDesktopManager().deactivateFrame(frame); } else if (evt.getPropertyName().equals(JInternalFrame.ROOT_PANE_PROPERTY) - || evt.getPropertyName().equals(JInternalFrame.GLASS_PANE_PROPERTY)) + || evt.getPropertyName().equals( + JInternalFrame.GLASS_PANE_PROPERTY)) { - Component old = (Component) evt.getOldValue(); - old.removeMouseListener(glassPaneDispatcher); - old.removeMouseMotionListener(glassPaneDispatcher); + Component old = (Component) evt.getOldValue(); + old.removeMouseListener(glassPaneDispatcher); + old.removeMouseMotionListener(glassPaneDispatcher); - Component newPane = (Component) evt.getNewValue(); - newPane.addMouseListener(glassPaneDispatcher); - newPane.addMouseMotionListener(glassPaneDispatcher); + Component newPane = (Component) evt.getNewValue(); + newPane.addMouseListener(glassPaneDispatcher); + newPane.addMouseMotionListener(glassPaneDispatcher); - frame.revalidate(); + frame.revalidate(); } - /* FIXME: need to add ancestor properties to JComponents. - else if (evt.getPropertyName().equals(JComponent.ANCESTOR_PROPERTY)) - { - if (desktopPane != null) - desktopPane.removeComponentListener(componentListener); - desktopPane = frame.getDesktopPane(); - if (desktopPane != null) - desktopPane.addComponentListener(componentListener); - } - */ + /* + * FIXME: need to add ancestor properties to JComponents. else if + * (evt.getPropertyName().equals(JComponent.ANCESTOR_PROPERTY)) { if + * (desktopPane != null) + * desktopPane.removeComponentListener(componentListener); desktopPane = + * frame.getDesktopPane(); if (desktopPane != null) + * desktopPane.addComponentListener(componentListener); } + */ } } /** * This helper class is the border for the JInternalFrame. */ - private class InternalFrameBorder extends AbstractBorder - implements UIResource + private class InternalFrameBorder extends AbstractBorder implements + UIResource { /** The width of the border. */ private static final int bSize = 5; @@ -970,7 +991,7 @@ public class BasicInternalFrameUI extends InternalFrameUI /** * This method returns whether the border is opaque. - * + * * @return Whether the border is opaque. */ public boolean isBorderOpaque() @@ -980,9 +1001,9 @@ public class BasicInternalFrameUI extends InternalFrameUI /** * This method returns the insets of the border. - * - * @param c The Component to find border insets for. - * + * + * @param c + * The Component to find border insets for. * @return The border insets. */ public Insets getBorderInsets(Component c) @@ -992,13 +1013,19 @@ public class BasicInternalFrameUI extends InternalFrameUI /** * This method paints the border. - * - * @param c The Component that owns the border. - * @param g The Graphics object to paint with. - * @param x The x coordinate to paint at. - * @param y The y coordinate to paint at. - * @param width The width of the Component. - * @param height The height of the Component. + * + * @param c + * The Component that owns the border. + * @param g + * The Graphics object to paint with. + * @param x + * The x coordinate to paint at. + * @param y + * The y coordinate to paint at. + * @param width + * The width of the Component. + * @param height + * The height of the Component. */ public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) @@ -1135,21 +1162,21 @@ public class BasicInternalFrameUI extends InternalFrameUI { if (c instanceof JInternalFrame) { - frame = (JInternalFrame) c; + frame = (JInternalFrame) c; - internalFrameLayout = createLayoutManager(); - frame.setLayout(internalFrameLayout); + internalFrameLayout = createLayoutManager(); + frame.setLayout(internalFrameLayout); - ((JComponent) frame.getRootPane().getGlassPane()).setOpaque(false); - frame.getRootPane().getGlassPane().setVisible(true); + ((JComponent) frame.getRootPane().getGlassPane()).setOpaque(false); + frame.getRootPane().getGlassPane().setVisible(true); - installDefaults(); - installListeners(); - installComponents(); - installKeyboardActions(); + installDefaults(); + installListeners(); + installComponents(); + installKeyboardActions(); - frame.setOpaque(true); - frame.invalidate(); + frame.setOpaque(true); + frame.invalidate(); } } @@ -1343,14 +1370,14 @@ public class BasicInternalFrameUI extends InternalFrameUI { if (currentPane != null) { - deinstallMouseHandlers(currentPane); - frame.remove(currentPane); + deinstallMouseHandlers(currentPane); + frame.remove(currentPane); } if (newPane != null) { - installMouseHandlers(newPane); - frame.add(newPane); + installMouseHandlers(newPane); + frame.add(newPane); } } diff --git a/javax/swing/plaf/basic/BasicLookAndFeel.java b/javax/swing/plaf/basic/BasicLookAndFeel.java index d35ac9eb9..0c21d4256 100644 --- a/javax/swing/plaf/basic/BasicLookAndFeel.java +++ b/javax/swing/plaf/basic/BasicLookAndFeel.java @@ -362,7 +362,7 @@ public abstract class BasicLookAndFeel extends LookAndFeel "HOME", "homePassThrough", "END", "endPassThrough" }), - "ComboBox.background", new ColorUIResource(light), + "ComboBox.background", new ColorUIResource(Color.white), "ComboBox.buttonBackground", new ColorUIResource(light), "ComboBox.buttonDarkShadow", new ColorUIResource(shadow), "ComboBox.buttonHighlight", new ColorUIResource(highLight), @@ -371,7 +371,7 @@ public abstract class BasicLookAndFeel extends LookAndFeel "ComboBox.disabledForeground", new ColorUIResource(Color.gray), "ComboBox.font", new FontUIResource("SansSerif", Font.PLAIN, 12), "ComboBox.foreground", new ColorUIResource(Color.black), - "ComboBox.selectionBackground", new ColorUIResource(Color.black), + "ComboBox.selectionBackground", new ColorUIResource(0, 0, 128), "ComboBox.selectionForeground", new ColorUIResource(Color.white), "Desktop.ancestorInputMap", new UIDefaults.LazyInputMap(new Object[] { "KP_LEFT", "left", @@ -397,7 +397,8 @@ public abstract class BasicLookAndFeel extends LookAndFeel "DesktopIcon.border", new BorderUIResource.CompoundBorderUIResource(null, null), "EditorPane.background", new ColorUIResource(Color.white), - "EditorPane.border", new BasicBorders.MarginBorder(), + "EditorPane.border", + new BorderUIResource(BasicBorders.getMarginBorder()), "EditorPane.caretBlinkRate", new Integer(500), "EditorPane.caretForeground", new ColorUIResource(Color.black), "EditorPane.font", new FontUIResource("Serif", Font.PLAIN, 12), @@ -528,7 +529,7 @@ public abstract class BasicLookAndFeel extends LookAndFeel "Label.disabledShadow", new ColorUIResource(shadow), "Label.font", new FontUIResource("Dialog", Font.PLAIN, 12), "Label.foreground", new ColorUIResource(darkShadow), - "List.background", new ColorUIResource(light), + "List.background", new ColorUIResource(Color.white), "List.border", new BasicBorders.MarginBorder(), "List.focusInputMap", new UIDefaults.LazyInputMap(new Object[] { "PAGE_UP", "scrollUp", @@ -550,8 +551,8 @@ public abstract class BasicLookAndFeel extends LookAndFeel "shift PAGE_UP","scrollUpExtendSelection", "KP_DOWN", "selectNextRow" }), - "List.foreground", new ColorUIResource(darkShadow), - "List.selectionBackground", new ColorUIResource(Color.black), + "List.foreground", new ColorUIResource(Color.black), + "List.selectionBackground", new ColorUIResource(0, 0, 128), "List.selectionForeground", new ColorUIResource(Color.white), "List.focusCellHighlightBorder", new BorderUIResource. @@ -742,6 +743,7 @@ public abstract class BasicLookAndFeel extends LookAndFeel "ScrollBar.thumbShadow", new ColorUIResource(shadow), "ScrollBar.track", new ColorUIResource(light), "ScrollBar.trackHighlight", new ColorUIResource(shadow), + "ScrollBar.width", new Integer(16), "ScrollPane.ancestorInputMap", new UIDefaults.LazyInputMap(new Object[] { "PAGE_UP", "scrollUp", "KP_LEFT", "unitScrollLeft", @@ -914,10 +916,11 @@ public abstract class BasicLookAndFeel extends LookAndFeel "TableHeader.foreground", new ColorUIResource(darkShadow), "TextArea.background", new ColorUIResource(light), - "TextArea.border", new BasicBorders.MarginBorder(), + "TextArea.border", + new BorderUIResource(BasicBorders.getMarginBorder()), "TextArea.caretBlinkRate", new Integer(500), "TextArea.caretForeground", new ColorUIResource(Color.black), - "TextArea.font", new FontUIResource("MonoSpaced", Font.PLAIN, 12), + "TextArea.font", new FontUIResource("Monospaced", Font.PLAIN, 12), "TextArea.foreground", new ColorUIResource(Color.black), "TextArea.inactiveForeground", new ColorUIResource(Color.gray), "TextArea.keyBindings", new JTextComponent.KeyBinding[] { @@ -945,8 +948,8 @@ public abstract class BasicLookAndFeel extends LookAndFeel "TextField.font", new FontUIResource("SansSerif", Font.PLAIN, 12), "TextField.foreground", new ColorUIResource(Color.black), "TextField.highlight", new ColorUIResource(highLight), - "TextField.inactiveBackground", new ColorUIResource(light), - "TextField.inactiveForeground", new ColorUIResource(Color.gray), + "TextField.inactiveBackground", new ColorUIResource(Color.LIGHT_GRAY), + "TextField.inactiveForeground", new ColorUIResource(Color.GRAY), "TextField.light", new ColorUIResource(highLight), "TextField.highlight", new ColorUIResource(light), "TextField.keyBindings", new JTextComponent.KeyBinding[] { @@ -964,7 +967,8 @@ public abstract class BasicLookAndFeel extends LookAndFeel "TextField.selectionBackground", new ColorUIResource(Color.black), "TextField.selectionForeground", new ColorUIResource(Color.white), "TextPane.background", new ColorUIResource(Color.white), - "TextPane.border", new BasicBorders.MarginBorder(), + "TextPane.border", + new BorderUIResource(BasicBorders.getMarginBorder()), "TextPane.caretBlinkRate", new Integer(500), "TextPane.caretForeground", new ColorUIResource(Color.black), "TextPane.font", new FontUIResource("Serif", Font.PLAIN, 12), diff --git a/javax/swing/plaf/basic/BasicMenuItemUI.java b/javax/swing/plaf/basic/BasicMenuItemUI.java index e40e09170..488844336 100644 --- a/javax/swing/plaf/basic/BasicMenuItemUI.java +++ b/javax/swing/plaf/basic/BasicMenuItemUI.java @@ -1,39 +1,39 @@ /* BasicMenuItemUI.java -- - Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc. - - This file is part of GNU Classpath. - - GNU Classpath is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. - - GNU Classpath is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with GNU Classpath; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301 USA. - - Linking this library statically or dynamically with other modules is - making a combined work based on this library. Thus, the terms and - conditions of the GNU General Public License cover the whole - combination. - - As a special exception, the copyright holders of this library give you - permission to link this library with independent modules to produce an - executable, regardless of the license terms of these independent - modules, and to copy and distribute the resulting executable under - terms of your choice, provided that you also meet, for each linked - independent module, the terms and conditions of the license of that - module. An independent module is a module which is not derived from - or based on this library. If you modify this library, you may extend - this exception to your version of the library, but you are not - obligated to do so. If you do not wish to do so, delete this - exception statement from your version. */ + Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ package javax.swing.plaf.basic; diff --git a/javax/swing/plaf/basic/BasicOptionPaneUI.java b/javax/swing/plaf/basic/BasicOptionPaneUI.java index c9f623259..aa648d74d 100644 --- a/javax/swing/plaf/basic/BasicOptionPaneUI.java +++ b/javax/swing/plaf/basic/BasicOptionPaneUI.java @@ -860,10 +860,10 @@ public class BasicOptionPaneUI extends OptionPaneUI addIcon(messageArea); JPanel rightSide = new JPanel(); - rightSide.setBorder(BorderFactory.createEmptyBorder(0, 11, 17, 0)); + rightSide.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); rightSide.setLayout(new GridBagLayout()); GridBagConstraints con = createConstraints(); - + addMessageComponents(rightSide, con, getMessage(), getMaxCharactersPerLineCount(), false); @@ -886,7 +886,7 @@ public class BasicOptionPaneUI extends OptionPaneUI } } - messageArea.add(rightSide, BorderLayout.EAST); + messageArea.add(rightSide, BorderLayout.CENTER); return messageArea; } @@ -941,10 +941,10 @@ public class BasicOptionPaneUI extends OptionPaneUI { case JOptionPane.YES_NO_OPTION: return new Object[] { YES_STRING, NO_STRING }; + case JOptionPane.DEFAULT_OPTION: case JOptionPane.YES_NO_CANCEL_OPTION: return new Object[] { YES_STRING, NO_STRING, CANCEL_STRING }; case JOptionPane.OK_CANCEL_OPTION: - case JOptionPane.DEFAULT_OPTION: return new Object[] { OK_STRING, CANCEL_STRING }; } return null; diff --git a/javax/swing/plaf/basic/BasicPasswordFieldUI.java b/javax/swing/plaf/basic/BasicPasswordFieldUI.java index 044027b0b..089162ce3 100644 --- a/javax/swing/plaf/basic/BasicPasswordFieldUI.java +++ b/javax/swing/plaf/basic/BasicPasswordFieldUI.java @@ -39,6 +39,7 @@ exception statement from your version. */ package javax.swing.plaf.basic; import javax.swing.JComponent; +import javax.swing.UIDefaults; import javax.swing.plaf.ComponentUI; import javax.swing.text.Element; import javax.swing.text.PasswordView; @@ -60,6 +61,11 @@ public class BasicPasswordFieldUI extends BasicTextFieldUI return new BasicPasswordFieldUI(); } + /** + * Returns the prefix for entries in the {@link UIDefaults} table. + * + * @return "PasswordField" + */ protected String getPropertyPrefix() { return "PasswordField"; diff --git a/javax/swing/plaf/basic/BasicTabbedPaneUI.java b/javax/swing/plaf/basic/BasicTabbedPaneUI.java index 7e9d9b982..232136fc2 100644 --- a/javax/swing/plaf/basic/BasicTabbedPaneUI.java +++ b/javax/swing/plaf/basic/BasicTabbedPaneUI.java @@ -136,36 +136,36 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants if (tabPane.getTabLayoutPolicy() == JTabbedPane.SCROLL_TAB_LAYOUT) { - if (e.getSource() == incrButton) - { - if (++currentScrollLocation >= tabCount) - currentScrollLocation = tabCount - 1; - - int width = 0; - for (int i = currentScrollLocation - 1; i < tabCount; i++) - width += rects[i].width; - if (width < viewport.getWidth()) - // FIXME: Still getting mouse events after the button is disabled. - // incrButton.setEnabled(false); - currentScrollLocation--; - else if (! decrButton.isEnabled()) - decrButton.setEnabled(true); - tabPane.revalidate(); - tabPane.repaint(); - return; - } - else if (e.getSource() == decrButton) - { - if (--currentScrollLocation < 0) - currentScrollLocation = 0; - if (currentScrollLocation == 0) - decrButton.setEnabled(false); - else if (! incrButton.isEnabled()) - incrButton.setEnabled(true); - tabPane.revalidate(); - tabPane.repaint(); - return; - } + if (e.getSource() == incrButton) + { + if (++currentScrollLocation >= tabCount) + currentScrollLocation = tabCount - 1; + + int width = 0; + for (int i = currentScrollLocation - 1; i < tabCount; i++) + width += rects[i].width; + if (width < viewport.getWidth()) + // FIXME: Still getting mouse events after the button is disabled. + // incrButton.setEnabled(false); + currentScrollLocation--; + else if (! decrButton.isEnabled()) + decrButton.setEnabled(true); + tabPane.revalidate(); + tabPane.repaint(); + return; + } + else if (e.getSource() == decrButton) + { + if (--currentScrollLocation < 0) + currentScrollLocation = 0; + if (currentScrollLocation == 0) + decrButton.setEnabled(false); + else if (! incrButton.isEnabled()) + incrButton.setEnabled(true); + tabPane.revalidate(); + tabPane.repaint(); + return; + } } int index = tabForCoordinate(tabPane, x, y); @@ -173,7 +173,7 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants // We need to check since there are areas where tabs cannot be // e.g. in the inset area. if (index != -1 && tabPane.isEnabledAt(index)) - tabPane.setSelectedIndex(index); + tabPane.setSelectedIndex(index); tabPane.revalidate(); tabPane.repaint(); } @@ -198,15 +198,15 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants { if (e.getPropertyName().equals("tabLayoutPolicy")) { - layoutManager = createLayoutManager(); - - tabPane.setLayout(layoutManager); + layoutManager = createLayoutManager(); + + tabPane.setLayout(layoutManager); } else if (e.getPropertyName().equals("tabPlacement") - && tabPane.getTabLayoutPolicy() == JTabbedPane.SCROLL_TAB_LAYOUT) + && tabPane.getTabLayoutPolicy() == JTabbedPane.SCROLL_TAB_LAYOUT) { - incrButton = createIncreaseButton(); - decrButton = createDecreaseButton(); + incrButton = createIncreaseButton(); + decrButton = createDecreaseButton(); } tabPane.layout(); tabPane.repaint(); @@ -245,13 +245,13 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants if (tabPane.getSelectedIndex() != -1) { - Component visible = getVisibleComponent(); - Insets insets = getContentBorderInsets(tabPane.getTabPlacement()); - if (visible != null) - visible.setBounds(contentRect.x + insets.left, - contentRect.y + insets.top, - contentRect.width - insets.left - insets.right, - contentRect.height - insets.top - insets.bottom); + Component visible = getVisibleComponent(); + Insets insets = getContentBorderInsets(tabPane.getTabPlacement()); + if (visible != null) + visible.setBounds(contentRect.x + insets.left, + contentRect.y + insets.top, + contentRect.width - insets.left - insets.right, + contentRect.height - insets.top - insets.bottom); } } @@ -275,35 +275,35 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants Dimension dims; for (int i = 0; i < tabPane.getTabCount(); i++) { - c = tabPane.getComponentAt(i); - if (c == null) - continue; - calcRect = c.getBounds(); - dims = c.getPreferredSize(); - if (dims != null) - { - componentHeight = Math.max(componentHeight, dims.height); - componentWidth = Math.max(componentWidth, dims.width); - } + c = tabPane.getComponentAt(i); + if (c == null) + continue; + calcRect = c.getBounds(); + dims = c.getPreferredSize(); + if (dims != null) + { + componentHeight = Math.max(componentHeight, dims.height); + componentWidth = Math.max(componentWidth, dims.width); + } } Insets insets = tabPane.getInsets(); if (tabPlacement == SwingConstants.TOP || tabPlacement == SwingConstants.BOTTOM) { - int min = calculateMaxTabWidth(tabPlacement); - width = Math.max(min, componentWidth); - - int tabAreaHeight = preferredTabAreaHeight(tabPlacement, width); - height = tabAreaHeight + componentHeight; + int min = calculateMaxTabWidth(tabPlacement); + width = Math.max(min, componentWidth); + + int tabAreaHeight = preferredTabAreaHeight(tabPlacement, width); + height = tabAreaHeight + componentHeight; } else { - int min = calculateMaxTabHeight(tabPlacement); - height = Math.max(min, componentHeight); - - int tabAreaWidth = preferredTabAreaWidth(tabPlacement, height); - width = tabAreaWidth + componentWidth; + int min = calculateMaxTabHeight(tabPlacement); + height = Math.max(min, componentHeight); + + int tabAreaWidth = preferredTabAreaWidth(tabPlacement, height); + width = tabAreaWidth + componentWidth; } return new Dimension(width, height); @@ -330,7 +330,7 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants protected void calculateTabRects(int tabPlacement, int tabCount) { if (tabCount == 0) - return; + return; assureRectsCreated(tabCount); FontMetrics fm = getFontMetrics(); @@ -343,113 +343,113 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants if (tabPlacement == SwingConstants.TOP || tabPlacement == SwingConstants.BOTTOM) { - int maxHeight = calculateMaxTabHeight(tabPlacement); - - calcRect.width -= tabAreaInsets.left + tabAreaInsets.right; - max = calcRect.width + tabAreaInsets.left + insets.left; - start += tabAreaInsets.left + insets.left; - int width = 0; - int runWidth = start; - - for (int i = 0; i < tabCount; i++) - { - width = calculateTabWidth(tabPlacement, i, fm); - - if (runWidth + width > max) - { - runWidth = tabAreaInsets.left + insets.left - + getTabRunIndent(tabPlacement, ++runs); - rects[i] = new Rectangle(runWidth, - insets.top + tabAreaInsets.top, - width, maxHeight); - runWidth += width; - if (runs > tabRuns.length - 1) - expandTabRunsArray(); - tabRuns[runs] = i; - } - else - { - rects[i] = new Rectangle(runWidth, - insets.top + tabAreaInsets.top, - width, maxHeight); - runWidth += width; - } - } - runs++; - tabAreaRect.width = tabPane.getWidth() - insets.left - insets.right; - tabAreaRect.height = runs * maxTabHeight - - (runs - 1) * tabRunOverlay - + tabAreaInsets.top + tabAreaInsets.bottom; - contentRect.width = tabAreaRect.width; - contentRect.height = tabPane.getHeight() - insets.top - - insets.bottom - tabAreaRect.height; - contentRect.x = insets.left; - tabAreaRect.x = insets.left; - if (tabPlacement == SwingConstants.BOTTOM) - { - contentRect.y = insets.top; - tabAreaRect.y = contentRect.y + contentRect.height; - } - else - { - tabAreaRect.y = insets.top; - contentRect.y = tabAreaRect.y + tabAreaRect.height; - } + int maxHeight = calculateMaxTabHeight(tabPlacement); + + calcRect.width -= tabAreaInsets.left + tabAreaInsets.right; + max = calcRect.width + tabAreaInsets.left + insets.left; + start += tabAreaInsets.left + insets.left; + int width = 0; + int runWidth = start; + + for (int i = 0; i < tabCount; i++) + { + width = calculateTabWidth(tabPlacement, i, fm); + + if (runWidth + width > max) + { + runWidth = tabAreaInsets.left + insets.left + + getTabRunIndent(tabPlacement, ++runs); + rects[i] = new Rectangle(runWidth, + insets.top + tabAreaInsets.top, + width, maxHeight); + runWidth += width; + if (runs > tabRuns.length - 1) + expandTabRunsArray(); + tabRuns[runs] = i; + } + else + { + rects[i] = new Rectangle(runWidth, + insets.top + tabAreaInsets.top, + width, maxHeight); + runWidth += width; + } + } + runs++; + tabAreaRect.width = tabPane.getWidth() - insets.left - insets.right; + tabAreaRect.height = runs * maxTabHeight + - (runs - 1) * tabRunOverlay + + tabAreaInsets.top + tabAreaInsets.bottom; + contentRect.width = tabAreaRect.width; + contentRect.height = tabPane.getHeight() - insets.top + - insets.bottom - tabAreaRect.height; + contentRect.x = insets.left; + tabAreaRect.x = insets.left; + if (tabPlacement == SwingConstants.BOTTOM) + { + contentRect.y = insets.top; + tabAreaRect.y = contentRect.y + contentRect.height; + } + else + { + tabAreaRect.y = insets.top; + contentRect.y = tabAreaRect.y + tabAreaRect.height; + } } else { - int maxWidth = calculateMaxTabWidth(tabPlacement); - calcRect.height -= tabAreaInsets.top + tabAreaInsets.bottom; - max = calcRect.height + tabAreaInsets.top + insets.top; - - int height = 0; - start += tabAreaInsets.top + insets.top; - int runHeight = start; - - int fontHeight = fm.getHeight(); - - for (int i = 0; i < tabCount; i++) - { - height = calculateTabHeight(tabPlacement, i, fontHeight); - if (runHeight + height > max) - { - runHeight = tabAreaInsets.top + insets.top - + getTabRunIndent(tabPlacement, ++runs); - rects[i] = new Rectangle(insets.left + tabAreaInsets.left, - runHeight, maxWidth, height); - runHeight += height; - if (runs > tabRuns.length - 1) - expandTabRunsArray(); - tabRuns[runs] = i; - } - else - { - rects[i] = new Rectangle(insets.left + tabAreaInsets.left, - runHeight, maxWidth, height); - runHeight += height; - } - } - runs++; - - tabAreaRect.width = runs * maxTabWidth - (runs - 1) * tabRunOverlay - + tabAreaInsets.left + tabAreaInsets.right; - tabAreaRect.height = tabPane.getHeight() - insets.top - - insets.bottom; - tabAreaRect.y = insets.top; - contentRect.width = tabPane.getWidth() - insets.left - insets.right - - tabAreaRect.width; - contentRect.height = tabAreaRect.height; - contentRect.y = insets.top; - if (tabPlacement == SwingConstants.LEFT) - { - tabAreaRect.x = insets.left; - contentRect.x = tabAreaRect.x + tabAreaRect.width; - } - else - { - contentRect.x = insets.left; - tabAreaRect.x = contentRect.x + contentRect.width; - } + int maxWidth = calculateMaxTabWidth(tabPlacement); + calcRect.height -= tabAreaInsets.top + tabAreaInsets.bottom; + max = calcRect.height + tabAreaInsets.top + insets.top; + + int height = 0; + start += tabAreaInsets.top + insets.top; + int runHeight = start; + + int fontHeight = fm.getHeight(); + + for (int i = 0; i < tabCount; i++) + { + height = calculateTabHeight(tabPlacement, i, fontHeight); + if (runHeight + height > max) + { + runHeight = tabAreaInsets.top + insets.top + + getTabRunIndent(tabPlacement, ++runs); + rects[i] = new Rectangle(insets.left + tabAreaInsets.left, + runHeight, maxWidth, height); + runHeight += height; + if (runs > tabRuns.length - 1) + expandTabRunsArray(); + tabRuns[runs] = i; + } + else + { + rects[i] = new Rectangle(insets.left + tabAreaInsets.left, + runHeight, maxWidth, height); + runHeight += height; + } + } + runs++; + + tabAreaRect.width = runs * maxTabWidth - (runs - 1) * tabRunOverlay + + tabAreaInsets.left + tabAreaInsets.right; + tabAreaRect.height = tabPane.getHeight() - insets.top + - insets.bottom; + tabAreaRect.y = insets.top; + contentRect.width = tabPane.getWidth() - insets.left - insets.right + - tabAreaRect.width; + contentRect.height = tabAreaRect.height; + contentRect.y = insets.top; + if (tabPlacement == SwingConstants.LEFT) + { + tabAreaRect.x = insets.left; + contentRect.x = tabAreaRect.x + tabAreaRect.width; + } + else + { + contentRect.x = insets.left; + tabAreaRect.x = contentRect.x + contentRect.width; + } } runCount = runs; @@ -457,62 +457,62 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants normalizeTabRuns(tabPlacement, tabCount, start, max); selectedRun = getRunForTab(tabCount, tabPane.getSelectedIndex()); if (shouldRotateTabRuns(tabPlacement)) - rotateTabRuns(tabPlacement, selectedRun); + rotateTabRuns(tabPlacement, selectedRun); // Need to pad the runs and move them to the correct location. for (int i = 0; i < runCount; i++) { - int first = lastTabInRun(tabCount, getPreviousTabRun(i)) + 1; - if (first == tabCount) - first = 0; - int last = lastTabInRun(tabCount, i); - if (shouldPadTabRun(tabPlacement, i)) - padTabRun(tabPlacement, first, last, max); - - // Done padding, now need to move it. - if (tabPlacement == SwingConstants.TOP && i > 0) - { - for (int j = first; j <= last; j++) - rects[j].y += (runCount - i) * maxTabHeight - - (runCount - i) * tabRunOverlay; - } - - if (tabPlacement == SwingConstants.BOTTOM) - { - int height = tabPane.getBounds().height - insets.bottom - - tabAreaInsets.bottom; - int adjustment; - if (i == 0) - adjustment = height - maxTabHeight; - else - adjustment = height - (runCount - i + 1) * maxTabHeight - - (runCount - i) * tabRunOverlay; - - for (int j = first; j <= last; j++) - rects[j].y = adjustment; - } - - if (tabPlacement == SwingConstants.LEFT && i > 0) - { - for (int j = first; j <= last; j++) - rects[j].x += (runCount - i) * maxTabWidth - - (runCount - i) * tabRunOverlay; - } - - if (tabPlacement == SwingConstants.RIGHT) - { - int width = tabPane.getBounds().width - insets.right - - tabAreaInsets.right; - int adjustment; - if (i == 0) - adjustment = width - maxTabWidth; - else - adjustment = width - (runCount - i + 1) * maxTabWidth - + (runCount - i) * tabRunOverlay; - - for (int j = first; j <= last; j++) - rects[j].x = adjustment; - } + int first = lastTabInRun(tabCount, getPreviousTabRun(i)) + 1; + if (first == tabCount) + first = 0; + int last = lastTabInRun(tabCount, i); + if (shouldPadTabRun(tabPlacement, i)) + padTabRun(tabPlacement, first, last, max); + + // Done padding, now need to move it. + if (tabPlacement == SwingConstants.TOP && i > 0) + { + for (int j = first; j <= last; j++) + rects[j].y += (runCount - i) * maxTabHeight + - (runCount - i) * tabRunOverlay; + } + + if (tabPlacement == SwingConstants.BOTTOM) + { + int height = tabPane.getBounds().height - insets.bottom + - tabAreaInsets.bottom; + int adjustment; + if (i == 0) + adjustment = height - maxTabHeight; + else + adjustment = height - (runCount - i + 1) * maxTabHeight + - (runCount - i) * tabRunOverlay; + + for (int j = first; j <= last; j++) + rects[j].y = adjustment; + } + + if (tabPlacement == SwingConstants.LEFT && i > 0) + { + for (int j = first; j <= last; j++) + rects[j].x += (runCount - i) * maxTabWidth + - (runCount - i) * tabRunOverlay; + } + + if (tabPlacement == SwingConstants.RIGHT) + { + int width = tabPane.getBounds().width - insets.right + - tabAreaInsets.right; + int adjustment; + if (i == 0) + adjustment = width - maxTabWidth; + else + adjustment = width - (runCount - i + 1) * maxTabWidth + + (runCount - i) * tabRunOverlay; + + for (int j = first; j <= last; j++) + rects[j].x = adjustment; + } } padSelectedTab(tabPlacement, tabPane.getSelectedIndex()); } @@ -565,74 +565,74 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants if (tabPlacement == SwingUtilities.TOP || tabPlacement == SwingUtilities.BOTTOM) { - // We should only do this for runCount - 1, cause we can only shift that many times between - // runs. - for (int i = 1; i < runCount; i++) - { - Rectangle currRun = rects[lastTabInRun(tabCount, i)]; - Rectangle nextRun = rects[lastTabInRun(tabCount, getNextTabRun(i))]; - int spaceInCurr = currRun.x + currRun.width; - int spaceInNext = nextRun.x + nextRun.width; - - int diffNow = spaceInCurr - spaceInNext; - int diffLater = (spaceInCurr - currRun.width) - - (spaceInNext + currRun.width); - while (Math.abs(diffLater) < Math.abs(diffNow) - && spaceInNext + currRun.width < max) - { - tabRuns[i]--; - spaceInNext += currRun.width; - spaceInCurr -= currRun.width; - currRun = rects[lastTabInRun(tabCount, i)]; - diffNow = spaceInCurr - spaceInNext; - diffLater = (spaceInCurr - currRun.width) - - (spaceInNext + currRun.width); - } - - // Fix the bounds. - int first = lastTabInRun(tabCount, i) + 1; - int last = lastTabInRun(tabCount, getNextTabRun(i)); - int currX = tabAreaInsets.left; - for (int j = first; j <= last; j++) - { - rects[j].x = currX; - currX += rects[j].width; - } - } + // We should only do this for runCount - 1, cause we can only shift that many times between + // runs. + for (int i = 1; i < runCount; i++) + { + Rectangle currRun = rects[lastTabInRun(tabCount, i)]; + Rectangle nextRun = rects[lastTabInRun(tabCount, getNextTabRun(i))]; + int spaceInCurr = currRun.x + currRun.width; + int spaceInNext = nextRun.x + nextRun.width; + + int diffNow = spaceInCurr - spaceInNext; + int diffLater = (spaceInCurr - currRun.width) + - (spaceInNext + currRun.width); + while (Math.abs(diffLater) < Math.abs(diffNow) + && spaceInNext + currRun.width < max) + { + tabRuns[i]--; + spaceInNext += currRun.width; + spaceInCurr -= currRun.width; + currRun = rects[lastTabInRun(tabCount, i)]; + diffNow = spaceInCurr - spaceInNext; + diffLater = (spaceInCurr - currRun.width) + - (spaceInNext + currRun.width); + } + + // Fix the bounds. + int first = lastTabInRun(tabCount, i) + 1; + int last = lastTabInRun(tabCount, getNextTabRun(i)); + int currX = tabAreaInsets.left; + for (int j = first; j <= last; j++) + { + rects[j].x = currX; + currX += rects[j].width; + } + } } else { - for (int i = 1; i < runCount; i++) - { - Rectangle currRun = rects[lastTabInRun(tabCount, i)]; - Rectangle nextRun = rects[lastTabInRun(tabCount, getNextTabRun(i))]; - int spaceInCurr = currRun.y + currRun.height; - int spaceInNext = nextRun.y + nextRun.height; - - int diffNow = spaceInCurr - spaceInNext; - int diffLater = (spaceInCurr - currRun.height) - - (spaceInNext + currRun.height); - while (Math.abs(diffLater) < Math.abs(diffNow) - && spaceInNext + currRun.height < max) - { - tabRuns[i]--; - spaceInNext += currRun.height; - spaceInCurr -= currRun.height; - currRun = rects[lastTabInRun(tabCount, i)]; - diffNow = spaceInCurr - spaceInNext; - diffLater = (spaceInCurr - currRun.height) - - (spaceInNext + currRun.height); - } - - int first = lastTabInRun(tabCount, i) + 1; - int last = lastTabInRun(tabCount, getNextTabRun(i)); - int currY = tabAreaInsets.top; - for (int j = first; j <= last; j++) - { - rects[j].y = currY; - currY += rects[j].height; - } - } + for (int i = 1; i < runCount; i++) + { + Rectangle currRun = rects[lastTabInRun(tabCount, i)]; + Rectangle nextRun = rects[lastTabInRun(tabCount, getNextTabRun(i))]; + int spaceInCurr = currRun.y + currRun.height; + int spaceInNext = nextRun.y + nextRun.height; + + int diffNow = spaceInCurr - spaceInNext; + int diffLater = (spaceInCurr - currRun.height) + - (spaceInNext + currRun.height); + while (Math.abs(diffLater) < Math.abs(diffNow) + && spaceInNext + currRun.height < max) + { + tabRuns[i]--; + spaceInNext += currRun.height; + spaceInCurr -= currRun.height; + currRun = rects[lastTabInRun(tabCount, i)]; + diffNow = spaceInCurr - spaceInNext; + diffLater = (spaceInCurr - currRun.height) + - (spaceInNext + currRun.height); + } + + int first = lastTabInRun(tabCount, i) + 1; + int last = lastTabInRun(tabCount, getNextTabRun(i)); + int currY = tabAreaInsets.top; + for (int j = first; j <= last; j++) + { + rects[j].y = currY; + currY += rects[j].height; + } + } } } @@ -673,42 +673,42 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants if (tabPlacement == SwingConstants.TOP || tabPlacement == SwingConstants.BOTTOM) { - int runWidth = rects[end].x + rects[end].width; - int spaceRemaining = max - runWidth; - int numTabs = end - start + 1; - - // now divvy up the space. - int spaceAllocated = spaceRemaining / numTabs; - int currX = rects[start].x; - for (int i = start; i <= end; i++) - { - rects[i].x = currX; - rects[i].width += spaceAllocated; - currX += rects[i].width; - // This is used because since the spaceAllocated - // variable is an int, it rounds down. Sometimes, - // we don't fill an entire row, so we make it do - // so now. - if (i == end && rects[i].x + rects[i].width != max) - rects[i].width = max - rects[i].x; - } + int runWidth = rects[end].x + rects[end].width; + int spaceRemaining = max - runWidth; + int numTabs = end - start + 1; + + // now divvy up the space. + int spaceAllocated = spaceRemaining / numTabs; + int currX = rects[start].x; + for (int i = start; i <= end; i++) + { + rects[i].x = currX; + rects[i].width += spaceAllocated; + currX += rects[i].width; + // This is used because since the spaceAllocated + // variable is an int, it rounds down. Sometimes, + // we don't fill an entire row, so we make it do + // so now. + if (i == end && rects[i].x + rects[i].width != max) + rects[i].width = max - rects[i].x; + } } else { - int runHeight = rects[end].y + rects[end].height; - int spaceRemaining = max - runHeight; - int numTabs = end - start + 1; - - int spaceAllocated = spaceRemaining / numTabs; - int currY = rects[start].y; - for (int i = start; i <= end; i++) - { - rects[i].y = currY; - rects[i].height += spaceAllocated; - currY += rects[i].height; - if (i == end && rects[i].y + rects[i].height != max) - rects[i].height = max - rects[i].y; - } + int runHeight = rects[end].y + rects[end].height; + int spaceRemaining = max - runHeight; + int numTabs = end - start + 1; + + int spaceAllocated = spaceRemaining / numTabs; + int currY = rects[start].y; + for (int i = start; i <= end; i++) + { + rects[i].y = currY; + rects[i].height += spaceAllocated; + currY += rects[i].height; + if (i == end && rects[i].y + rects[i].height != max) + rects[i].height = max - rects[i].y; + } } } @@ -736,7 +736,7 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants protected int preferredTabAreaHeight(int tabPlacement, int width) { if (tabPane.getTabCount() == 0) - return calculateTabAreaHeight(tabPlacement, 0, 0); + return calculateTabAreaHeight(tabPlacement, 0, 0); int runs = 0; int runWidth = 0; @@ -758,14 +758,14 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants // be IF we got our desired width. for (int i = 0; i < tabPane.getTabCount(); i++) { - tabWidth = calculateTabWidth(tabPlacement, i, fm); - if (runWidth + tabWidth > width) - { - runWidth = tabWidth; - runs++; - } - else - runWidth += tabWidth; + tabWidth = calculateTabWidth(tabPlacement, i, fm); + if (runWidth + tabWidth > width) + { + runWidth = tabWidth; + runs++; + } + else + runWidth += tabWidth; } runs++; @@ -787,7 +787,7 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants protected int preferredTabAreaWidth(int tabPlacement, int height) { if (tabPane.getTabCount() == 0) - return calculateTabAreaHeight(tabPlacement, 0, 0); + return calculateTabAreaHeight(tabPlacement, 0, 0); int runs = 0; int runHeight = 0; @@ -804,14 +804,14 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants for (int i = 0; i < tabPane.getTabCount(); i++) { - tabHeight = calculateTabHeight(tabPlacement, i, fontHeight); - if (runHeight + tabHeight > height) - { - runHeight = tabHeight; - runs++; - } - else - runHeight += tabHeight; + tabHeight = calculateTabHeight(tabPlacement, i, fontHeight); + if (runHeight + tabHeight > height) + { + runHeight = tabHeight; + runs++; + } + else + runHeight += tabHeight; } runs++; @@ -831,19 +831,19 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants protected void rotateTabRuns(int tabPlacement, int selectedRun) { if (runCount == 1 || selectedRun == 1 || selectedRun == -1) - return; + return; int[] newTabRuns = new int[tabRuns.length]; int currentRun = selectedRun; int i = 1; do { - newTabRuns[i] = tabRuns[currentRun]; - currentRun = getNextTabRun(currentRun); - i++; + newTabRuns[i] = tabRuns[currentRun]; + currentRun = getNextTabRun(currentRun); + i++; } while (i < runCount); if (runCount > 1) - newTabRuns[0] = tabRuns[currentRun]; + newTabRuns[0] = tabRuns[currentRun]; tabRuns = newTabRuns; BasicTabbedPaneUI.this.selectedRun = 1; @@ -902,7 +902,7 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants protected int preferredTabAreaHeight(int tabPlacement, int width) { if (tabPane.getTabCount() == 0) - return calculateTabAreaHeight(tabPlacement, 0, 0); + return calculateTabAreaHeight(tabPlacement, 0, 0); int runs = 1; @@ -923,7 +923,7 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants protected int preferredTabAreaWidth(int tabPlacement, int height) { if (tabPane.getTabCount() == 0) - return calculateTabAreaHeight(tabPlacement, 0, 0); + return calculateTabAreaHeight(tabPlacement, 0, 0); int runs = 1; @@ -944,7 +944,7 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants protected void calculateTabRects(int tabPlacement, int tabCount) { if (tabCount == 0) - return; + return; assureRectsCreated(tabCount); FontMetrics fm = getFontMetrics(); @@ -958,76 +958,76 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants if (tabPlacement == SwingConstants.TOP || tabPlacement == SwingConstants.BOTTOM) { - int maxHeight = calculateMaxTabHeight(tabPlacement); - calcRect.width -= tabAreaInsets.left + tabAreaInsets.right; - max = calcRect.width + tabAreaInsets.left + insets.left; - start = tabAreaInsets.left + insets.left; - int width = 0; - int runWidth = start; - top = insets.top + tabAreaInsets.top; - for (int i = 0; i < tabCount; i++) - { - width = calculateTabWidth(tabPlacement, i, fm); - - rects[i] = new Rectangle(runWidth, top, width, maxHeight); - runWidth += width; - } - tabAreaRect.width = tabPane.getWidth() - insets.left - insets.right; - tabAreaRect.height = runs * maxTabHeight - - (runs - 1) * tabRunOverlay - + tabAreaInsets.top + tabAreaInsets.bottom; - contentRect.width = tabAreaRect.width; - contentRect.height = tabPane.getHeight() - insets.top - - insets.bottom - tabAreaRect.height; - contentRect.x = insets.left; - tabAreaRect.x = insets.left; - if (tabPlacement == SwingConstants.BOTTOM) - { - contentRect.y = insets.top; - tabAreaRect.y = contentRect.y + contentRect.height; - } - else - { - tabAreaRect.y = insets.top; - contentRect.y = tabAreaRect.y + tabAreaRect.height; - } + int maxHeight = calculateMaxTabHeight(tabPlacement); + calcRect.width -= tabAreaInsets.left + tabAreaInsets.right; + max = calcRect.width + tabAreaInsets.left + insets.left; + start = tabAreaInsets.left + insets.left; + int width = 0; + int runWidth = start; + top = insets.top + tabAreaInsets.top; + for (int i = 0; i < tabCount; i++) + { + width = calculateTabWidth(tabPlacement, i, fm); + + rects[i] = new Rectangle(runWidth, top, width, maxHeight); + runWidth += width; + } + tabAreaRect.width = tabPane.getWidth() - insets.left - insets.right; + tabAreaRect.height = runs * maxTabHeight + - (runs - 1) * tabRunOverlay + + tabAreaInsets.top + tabAreaInsets.bottom; + contentRect.width = tabAreaRect.width; + contentRect.height = tabPane.getHeight() - insets.top + - insets.bottom - tabAreaRect.height; + contentRect.x = insets.left; + tabAreaRect.x = insets.left; + if (tabPlacement == SwingConstants.BOTTOM) + { + contentRect.y = insets.top; + tabAreaRect.y = contentRect.y + contentRect.height; + } + else + { + tabAreaRect.y = insets.top; + contentRect.y = tabAreaRect.y + tabAreaRect.height; + } } else { - int maxWidth = calculateMaxTabWidth(tabPlacement); - - calcRect.height -= tabAreaInsets.top + tabAreaInsets.bottom; - max = calcRect.height + tabAreaInsets.top; - int height = 0; - start = tabAreaInsets.top + insets.top; - int runHeight = start; - int fontHeight = fm.getHeight(); - top = insets.left + tabAreaInsets.left; - for (int i = 0; i < tabCount; i++) - { - height = calculateTabHeight(tabPlacement, i, fontHeight); - rects[i] = new Rectangle(top, runHeight, maxWidth, height); - runHeight += height; - } - tabAreaRect.width = runs * maxTabWidth - (runs - 1) * tabRunOverlay - + tabAreaInsets.left + tabAreaInsets.right; - tabAreaRect.height = tabPane.getHeight() - insets.top - - insets.bottom; - tabAreaRect.y = insets.top; - contentRect.width = tabPane.getWidth() - insets.left - insets.right - - tabAreaRect.width; - contentRect.height = tabAreaRect.height; - contentRect.y = insets.top; - if (tabPlacement == SwingConstants.LEFT) - { - tabAreaRect.x = insets.left; - contentRect.x = tabAreaRect.x + tabAreaRect.width; - } - else - { - contentRect.x = insets.left; - tabAreaRect.x = contentRect.x + contentRect.width; - } + int maxWidth = calculateMaxTabWidth(tabPlacement); + + calcRect.height -= tabAreaInsets.top + tabAreaInsets.bottom; + max = calcRect.height + tabAreaInsets.top; + int height = 0; + start = tabAreaInsets.top + insets.top; + int runHeight = start; + int fontHeight = fm.getHeight(); + top = insets.left + tabAreaInsets.left; + for (int i = 0; i < tabCount; i++) + { + height = calculateTabHeight(tabPlacement, i, fontHeight); + rects[i] = new Rectangle(top, runHeight, maxWidth, height); + runHeight += height; + } + tabAreaRect.width = runs * maxTabWidth - (runs - 1) * tabRunOverlay + + tabAreaInsets.left + tabAreaInsets.right; + tabAreaRect.height = tabPane.getHeight() - insets.top + - insets.bottom; + tabAreaRect.y = insets.top; + contentRect.width = tabPane.getWidth() - insets.left - insets.right + - tabAreaRect.width; + contentRect.height = tabAreaRect.height; + contentRect.y = insets.top; + if (tabPlacement == SwingConstants.LEFT) + { + tabAreaRect.x = insets.left; + contentRect.x = tabAreaRect.x + tabAreaRect.width; + } + else + { + contentRect.x = insets.left; + tabAreaRect.x = contentRect.x + contentRect.width; + } } runCount = runs; @@ -1047,68 +1047,68 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants int tabCount = tabPane.getTabCount(); Point p = null; if (tabCount == 0) - return; + return; int tabPlacement = tabPane.getTabPlacement(); incrButton.hide(); decrButton.hide(); if (tabPlacement == SwingConstants.TOP || tabPlacement == SwingConstants.BOTTOM) { - if (tabAreaRect.x + tabAreaRect.width < rects[tabCount - 1].x - + rects[tabCount - 1].width) - { - Dimension incrDims = incrButton.getPreferredSize(); - Dimension decrDims = decrButton.getPreferredSize(); - - decrButton.setBounds(tabAreaRect.x + tabAreaRect.width - - incrDims.width - decrDims.width, - tabAreaRect.y, decrDims.width, - tabAreaRect.height); - incrButton.setBounds(tabAreaRect.x + tabAreaRect.width - - incrDims.width, tabAreaRect.y, - decrDims.width, tabAreaRect.height); - - tabAreaRect.width -= decrDims.width + incrDims.width; - incrButton.show(); - decrButton.show(); - } + if (tabAreaRect.x + tabAreaRect.width < rects[tabCount - 1].x + + rects[tabCount - 1].width) + { + Dimension incrDims = incrButton.getPreferredSize(); + Dimension decrDims = decrButton.getPreferredSize(); + + decrButton.setBounds(tabAreaRect.x + tabAreaRect.width + - incrDims.width - decrDims.width, + tabAreaRect.y, decrDims.width, + tabAreaRect.height); + incrButton.setBounds(tabAreaRect.x + tabAreaRect.width + - incrDims.width, tabAreaRect.y, + decrDims.width, tabAreaRect.height); + + tabAreaRect.width -= decrDims.width + incrDims.width; + incrButton.show(); + decrButton.show(); + } } if (tabPlacement == SwingConstants.LEFT || tabPlacement == SwingConstants.RIGHT) { - if (tabAreaRect.y + tabAreaRect.height < rects[tabCount - 1].y - + rects[tabCount - 1].height) - { - Dimension incrDims = incrButton.getPreferredSize(); - Dimension decrDims = decrButton.getPreferredSize(); - - decrButton.setBounds(tabAreaRect.x, - tabAreaRect.y + tabAreaRect.height - - incrDims.height - decrDims.height, - tabAreaRect.width, decrDims.height); - incrButton.setBounds(tabAreaRect.x, - tabAreaRect.y + tabAreaRect.height - - incrDims.height, tabAreaRect.width, - incrDims.height); - - tabAreaRect.height -= decrDims.height + incrDims.height; - incrButton.show(); - decrButton.show(); - } + if (tabAreaRect.y + tabAreaRect.height < rects[tabCount - 1].y + + rects[tabCount - 1].height) + { + Dimension incrDims = incrButton.getPreferredSize(); + Dimension decrDims = decrButton.getPreferredSize(); + + decrButton.setBounds(tabAreaRect.x, + tabAreaRect.y + tabAreaRect.height + - incrDims.height - decrDims.height, + tabAreaRect.width, decrDims.height); + incrButton.setBounds(tabAreaRect.x, + tabAreaRect.y + tabAreaRect.height + - incrDims.height, tabAreaRect.width, + incrDims.height); + + tabAreaRect.height -= decrDims.height + incrDims.height; + incrButton.show(); + decrButton.show(); + } } viewport.setBounds(tabAreaRect.x, tabAreaRect.y, tabAreaRect.width, tabAreaRect.height); int tabC = tabPane.getTabCount() - 1; if (tabCount > 0) { - int w = Math.max(rects[tabC].width + rects[tabC].x, tabAreaRect.width); - int h = Math.max(rects[tabC].height, tabAreaRect.height); - p = findPointForIndex(currentScrollLocation); - - // we want to cover that entire space so that borders that run under - // the tab area don't show up when we move the viewport around. - panel.setSize(w + p.x, h + p.y); + int w = Math.max(rects[tabC].width + rects[tabC].x, tabAreaRect.width); + int h = Math.max(rects[tabC].height, tabAreaRect.height); + p = findPointForIndex(currentScrollLocation); + + // we want to cover that entire space so that borders that run under + // the tab area don't show up when we move the viewport around. + panel.setSize(w + p.x, h + p.y); } viewport.setViewPosition(p); viewport.repaint(); @@ -1160,7 +1160,7 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants */ public void paint(Graphics g, JComponent c) { - paintTabArea(g, tabPane.getTabPlacement(), tabPane.getSelectedIndex()); + paintTabArea(g, tabPane.getTabPlacement(), tabPane.getSelectedIndex()); } } @@ -1407,22 +1407,22 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants if (tabPlacement == TOP || tabPlacement == BOTTOM) { - if (index > 0) - { - w += rects[index - 1].x + rects[index - 1].width; - if (index > selectedIndex) - w -= insets.left + insets.right; - } + if (index > 0) + { + w += rects[index - 1].x + rects[index - 1].width; + if (index > selectedIndex) + w -= insets.left + insets.right; + } } else { - if (index > 0) - { - h += rects[index - 1].y + rects[index - 1].height; - if (index > selectedIndex) - h -= insets.top + insets.bottom; - } + if (index > 0) + { + h += rects[index - 1].y + rects[index - 1].height; + if (index > selectedIndex) + h -= insets.top + insets.bottom; + } } Point p = new Point(w, h); @@ -1451,16 +1451,16 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants super.installUI(c); if (c instanceof JTabbedPane) { - tabPane = (JTabbedPane) c; - - installComponents(); - installDefaults(); - installListeners(); - installKeyboardActions(); - - layoutManager = createLayoutManager(); - tabPane.setLayout(layoutManager); - tabPane.layout(); + tabPane = (JTabbedPane) c; + + installComponents(); + installDefaults(); + installListeners(); + installKeyboardActions(); + + layoutManager = createLayoutManager(); + tabPane.setLayout(layoutManager); + tabPane.layout(); } } @@ -1495,23 +1495,23 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants return new TabbedPaneLayout(); else { - incrButton = createIncreaseButton(); - decrButton = createDecreaseButton(); - viewport = new ScrollingViewport(); - viewport.setLayout(null); - panel = new ScrollingPanel(); - viewport.setView(panel); - tabPane.add(incrButton); - tabPane.add(decrButton); - tabPane.add(viewport); - currentScrollLocation = 0; - decrButton.setEnabled(false); - panel.addMouseListener(mouseListener); - incrButton.addMouseListener(mouseListener); - decrButton.addMouseListener(mouseListener); - viewport.setBackground(Color.LIGHT_GRAY); - - return new TabbedPaneScrollLayout(); + incrButton = createIncreaseButton(); + decrButton = createDecreaseButton(); + viewport = new ScrollingViewport(); + viewport.setLayout(null); + panel = new ScrollingPanel(); + viewport.setView(panel); + tabPane.add(incrButton); + tabPane.add(decrButton); + tabPane.add(viewport); + currentScrollLocation = 0; + decrButton.setEnabled(false); + panel.addMouseListener(mouseListener); + incrButton.addMouseListener(mouseListener); + decrButton.addMouseListener(mouseListener); + viewport.setBackground(Color.LIGHT_GRAY); + + return new TabbedPaneScrollLayout(); } } @@ -1744,31 +1744,31 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants currRun = 0; for (int i = 0; i < runCount; i++) { - int first = lastTabInRun(tabCount, getPreviousTabRun(currRun)) + 1; - if (isScroll) - first = currentScrollLocation; - else if (first == tabCount) - first = 0; - int last = lastTabInRun(tabCount, currRun); - if (isScroll) - { - for (int k = first; k < tabCount; k++) - { - if (rects[k].x + rects[k].width - rects[first].x > viewport - .getWidth()) - { - last = k; - break; - } - } - } - - for (int j = first; j <= last; j++) - { - if (j != selectedIndex || isScroll) - paintTab(g, tabPlacement, rects, j, ir, tr); - } - currRun = getPreviousTabRun(currRun); + int first = lastTabInRun(tabCount, getPreviousTabRun(currRun)) + 1; + if (isScroll) + first = currentScrollLocation; + else if (first == tabCount) + first = 0; + int last = lastTabInRun(tabCount, currRun); + if (isScroll) + { + for (int k = first; k < tabCount; k++) + { + if (rects[k].x + rects[k].width - rects[first].x > viewport + .getWidth()) + { + last = k; + break; + } + } + } + + for (int j = first; j <= last; j++) + { + if (j != selectedIndex || isScroll) + paintTab(g, tabPlacement, rects, j, ir, tr); + } + currRun = getPreviousTabRun(currRun); } if (! isScroll) paintTab(g, tabPlacement, rects, selectedIndex, ir, tr); @@ -1800,24 +1800,24 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants int h = calcRect.height; if (getRunForTab(tabPane.getTabCount(), tabIndex) == 1) { - Insets insets = getTabAreaInsets(tabPlacement); - switch (tabPlacement) - { - case TOP: - h += insets.bottom; - break; - case LEFT: - w += insets.right; - break; - case BOTTOM: - y -= insets.top; - h += insets.top; - break; - case RIGHT: - x -= insets.left; - w += insets.left; - break; - } + Insets insets = getTabAreaInsets(tabPlacement); + switch (tabPlacement) + { + case TOP: + h += insets.bottom; + break; + case LEFT: + w += insets.right; + break; + case BOTTOM: + y -= insets.top; + h += insets.top; + break; + case RIGHT: + x -= insets.left; + w += insets.left; + break; + } } layoutLabel(tabPlacement, fm, tabIndex, title, icon, calcRect, iconRect, @@ -1904,8 +1904,8 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants View textView = getTextViewForTab(tabIndex); if (textView != null) { - textView.paint(g, textRect); - return; + textView.paint(g, textRect); + return; } Color fg = tabPane.getForegroundAt(tabIndex); @@ -1921,37 +1921,37 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants if (tabPane.isEnabledAt(tabIndex)) { - g.setColor(fg); + g.setColor(fg); - int mnemIndex = tabPane.getDisplayedMnemonicIndexAt(tabIndex); + int mnemIndex = tabPane.getDisplayedMnemonicIndexAt(tabIndex); - if (mnemIndex != -1) - BasicGraphicsUtils.drawStringUnderlineCharAt(g, title, mnemIndex, - textRect.x, - textRect.y - + metrics.getAscent()); - else - g.drawString(title, textRect.x, textRect.y + metrics.getAscent()); + if (mnemIndex != -1) + BasicGraphicsUtils.drawStringUnderlineCharAt(g, title, mnemIndex, + textRect.x, + textRect.y + + metrics.getAscent()); + else + g.drawString(title, textRect.x, textRect.y + metrics.getAscent()); } else { - g.setColor(bg.brighter()); - - int mnemIndex = tabPane.getDisplayedMnemonicIndexAt(tabIndex); - - if (mnemIndex != -1) - BasicGraphicsUtils.drawStringUnderlineCharAt(g, title, mnemIndex, - textRect.x, textRect.y); - else - g.drawString(title, textRect.x, textRect.y); - - g.setColor(bg.darker()); - if (mnemIndex != -1) - BasicGraphicsUtils.drawStringUnderlineCharAt(g, title, mnemIndex, - textRect.x + 1, - textRect.y + 1); - else - g.drawString(title, textRect.x + 1, textRect.y + 1); + g.setColor(bg.brighter()); + + int mnemIndex = tabPane.getDisplayedMnemonicIndexAt(tabIndex); + + if (mnemIndex != -1) + BasicGraphicsUtils.drawStringUnderlineCharAt(g, title, mnemIndex, + textRect.x, textRect.y); + else + g.drawString(title, textRect.x, textRect.y); + + g.setColor(bg.darker()); + if (mnemIndex != -1) + BasicGraphicsUtils.drawStringUnderlineCharAt(g, title, mnemIndex, + textRect.x + 1, + textRect.y + 1); + else + g.drawString(title, textRect.x + 1, textRect.y + 1); } g.setColor(saved_color); @@ -2037,30 +2037,30 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants if (! isSelected || tabPlacement != SwingConstants.TOP) { - g.setColor(shadow); - g.drawLine(x + 1, y + h - 1, x + w - 1, y + h - 1); - g.setColor(darkShadow); - g.drawLine(x, y + h, x + w, y + h); + g.setColor(shadow); + g.drawLine(x + 1, y + h - 1, x + w - 1, y + h - 1); + g.setColor(darkShadow); + g.drawLine(x, y + h, x + w, y + h); } if (! isSelected || tabPlacement != SwingConstants.LEFT) { - g.setColor(darkShadow); - g.drawLine(x + w, y, x + w, y + h); - g.setColor(shadow); - g.drawLine(x + w - 1, y + 1, x + w - 1, y + h - 1); + g.setColor(darkShadow); + g.drawLine(x + w, y, x + w, y + h); + g.setColor(shadow); + g.drawLine(x + w - 1, y + 1, x + w - 1, y + h - 1); } if (! isSelected || tabPlacement != SwingConstants.RIGHT) { - g.setColor(lightHighlight); - g.drawLine(x, y, x, y + h); + g.setColor(lightHighlight); + g.drawLine(x, y, x, y + h); } if (! isSelected || tabPlacement != SwingConstants.BOTTOM) { - g.setColor(lightHighlight); - g.drawLine(x, y, x + w, y); + g.setColor(lightHighlight); + g.drawLine(x, y, x + w, y); } g.setColor(saved); @@ -2087,10 +2087,10 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants g.setColor(Color.LIGHT_GRAY); else { - Color bg = tabPane.getBackgroundAt(tabIndex); - if (bg == null) - bg = Color.GRAY; - g.setColor(bg); + Color bg = tabPane.getBackgroundAt(tabIndex); + if (bg == null) + bg = Color.GRAY; + g.setColor(bg); } g.fillRect(x, y, w, h); @@ -2144,14 +2144,14 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants if (tabPlacement == SwingConstants.TOP) { - if (tabPane.getTabLayoutPolicy() == JTabbedPane.SCROLL_TAB_LAYOUT) - { - Point p = findPointForIndex(currentScrollLocation); - diff = p.x; - } - - g.drawLine(x, y, startgap - diff, y); - g.drawLine(endgap - diff, y, x + w, y); + if (tabPane.getTabLayoutPolicy() == JTabbedPane.SCROLL_TAB_LAYOUT) + { + Point p = findPointForIndex(currentScrollLocation); + diff = p.x; + } + + g.drawLine(x, y, startgap - diff, y); + g.drawLine(endgap - diff, y, x + w, y); } else g.drawLine(x, y, x + w, y); @@ -2184,14 +2184,14 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants if (tabPlacement == SwingConstants.LEFT) { - if (tabPane.getTabLayoutPolicy() == JTabbedPane.SCROLL_TAB_LAYOUT) - { - Point p = findPointForIndex(currentScrollLocation); - diff = p.y; - } - - g.drawLine(x, y, x, startgap - diff); - g.drawLine(x, endgap - diff, x, y + h); + if (tabPane.getTabLayoutPolicy() == JTabbedPane.SCROLL_TAB_LAYOUT) + { + Point p = findPointForIndex(currentScrollLocation); + diff = p.y; + } + + g.drawLine(x, y, x, startgap - diff); + g.drawLine(x, endgap - diff, x, y + h); } else g.drawLine(x, y, x, y + h); @@ -2223,26 +2223,26 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants if (tabPlacement == SwingConstants.BOTTOM) { - if (tabPane.getTabLayoutPolicy() == JTabbedPane.SCROLL_TAB_LAYOUT) - { - Point p = findPointForIndex(currentScrollLocation); - diff = p.x; - } - - g.setColor(shadow); - g.drawLine(x + 1, y + h - 1, startgap - diff, y + h - 1); - g.drawLine(endgap - diff, y + h - 1, x + w - 1, y + h - 1); - - g.setColor(darkShadow); - g.drawLine(x, y + h, startgap - diff, y + h); - g.drawLine(endgap - diff, y + h, x + w, y + h); + if (tabPane.getTabLayoutPolicy() == JTabbedPane.SCROLL_TAB_LAYOUT) + { + Point p = findPointForIndex(currentScrollLocation); + diff = p.x; + } + + g.setColor(shadow); + g.drawLine(x + 1, y + h - 1, startgap - diff, y + h - 1); + g.drawLine(endgap - diff, y + h - 1, x + w - 1, y + h - 1); + + g.setColor(darkShadow); + g.drawLine(x, y + h, startgap - diff, y + h); + g.drawLine(endgap - diff, y + h, x + w, y + h); } else { - g.setColor(shadow); - g.drawLine(x + 1, y + h - 1, x + w - 1, y + h - 1); - g.setColor(darkShadow); - g.drawLine(x, y + h, x + w, y + h); + g.setColor(shadow); + g.drawLine(x + 1, y + h - 1, x + w - 1, y + h - 1); + g.setColor(darkShadow); + g.drawLine(x, y + h, x + w, y + h); } g.setColor(saved); @@ -2271,26 +2271,26 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants if (tabPlacement == SwingConstants.RIGHT) { - if (tabPane.getTabLayoutPolicy() == JTabbedPane.SCROLL_TAB_LAYOUT) - { - Point p = findPointForIndex(currentScrollLocation); - diff = p.y; - } - - g.setColor(shadow); - g.drawLine(x + w - 1, y + 1, x + w - 1, startgap - diff); - g.drawLine(x + w - 1, endgap - diff, x + w - 1, y + h - 1); - - g.setColor(darkShadow); - g.drawLine(x + w, y, x + w, startgap - diff); - g.drawLine(x + w, endgap - diff, x + w, y + h); + if (tabPane.getTabLayoutPolicy() == JTabbedPane.SCROLL_TAB_LAYOUT) + { + Point p = findPointForIndex(currentScrollLocation); + diff = p.y; + } + + g.setColor(shadow); + g.drawLine(x + w - 1, y + 1, x + w - 1, startgap - diff); + g.drawLine(x + w - 1, endgap - diff, x + w - 1, y + h - 1); + + g.setColor(darkShadow); + g.drawLine(x + w, y, x + w, startgap - diff); + g.drawLine(x + w, endgap - diff, x + w, y + h); } else { - g.setColor(shadow); - g.drawLine(x + w - 1, y + 1, x + w - 1, y + h - 1); - g.setColor(darkShadow); - g.drawLine(x + w, y, x + w, y + h); + g.setColor(shadow); + g.drawLine(x + w - 1, y + 1, x + w - 1, y + h - 1); + g.setColor(darkShadow); + g.drawLine(x + w, y, x + w, y + h); } g.setColor(saved); @@ -2337,16 +2337,16 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants int currRun = 1; for (int i = 0; i < runCount; i++) { - int first = lastTabInRun(tabCount, getPreviousTabRun(currRun)) + 1; - if (first == tabCount) - first = 0; - int last = lastTabInRun(tabCount, currRun); - for (int j = first; j <= last; j++) - { - if (getTabBounds(pane, j).contains(p)) - return j; - } - currRun = getNextTabRun(currRun); + int first = lastTabInRun(tabCount, getPreviousTabRun(currRun)) + 1; + if (first == tabCount) + first = 0; + int last = lastTabInRun(tabCount, currRun); + for (int j = first; j <= last; j++) + { + if (getTabBounds(pane, j).contains(p)) + return j; + } + currRun = getNextTabRun(currRun); } return -1; } @@ -2400,10 +2400,10 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants return; else { - int numToCopy = Math.min(tabCount, rects.length); - Rectangle[] tmp = new Rectangle[tabCount]; - System.arraycopy(rects, 0, tmp, 0, numToCopy); - rects = tmp; + int numToCopy = Math.min(tabCount, rects.length); + Rectangle[] tmp = new Rectangle[tabCount]; + System.arraycopy(rects, 0, tmp, 0, numToCopy); + rects = tmp; } } @@ -2418,9 +2418,9 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants tabRuns = new int[10]; else { - int[] newRuns = new int[tabRuns.length + 10]; - System.arraycopy(tabRuns, 0, newRuns, 0, tabRuns.length); - tabRuns = newRuns; + int[] newRuns = new int[tabRuns.length + 10]; + System.arraycopy(tabRuns, 0, newRuns, 0, tabRuns.length); + tabRuns = newRuns; } } @@ -2438,12 +2438,12 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants return 1; for (int i = 0; i < runCount; i++) { - int first = lastTabInRun(tabCount, getPreviousTabRun(i)) + 1; - if (first == tabCount) - first = 0; - int last = lastTabInRun(tabCount, i); - if (last >= tabIndex && first <= tabIndex) - return i; + int first = lastTabInRun(tabCount, getPreviousTabRun(i)) + 1; + if (first == tabCount) + first = 0; + int last = lastTabInRun(tabCount, i); + if (last >= tabIndex && first <= tabIndex) + return i; } return -1; } @@ -2560,21 +2560,22 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants Icon icon = getIconForTab(tabIndex); Insets insets = getTabInsets(tabPlacement, tabIndex); + int height = 0; if (icon != null) { - Rectangle vr = new Rectangle(); - Rectangle ir = new Rectangle(); - Rectangle tr = new Rectangle(); - layoutLabel(tabPlacement, getFontMetrics(), tabIndex, - tabPane.getTitleAt(tabIndex), icon, vr, ir, tr, - tabIndex == tabPane.getSelectedIndex()); - calcRect = tr.union(ir); + Rectangle vr = new Rectangle(); + Rectangle ir = new Rectangle(); + Rectangle tr = new Rectangle(); + layoutLabel(tabPlacement, getFontMetrics(), tabIndex, + tabPane.getTitleAt(tabIndex), icon, vr, ir, tr, + tabIndex == tabPane.getSelectedIndex()); + height = tr.union(ir).height; } else - calcRect.height = fontHeight; + height = fontHeight; - calcRect.height += insets.top + insets.bottom; - return calcRect.height; + height += insets.top + insets.bottom; + return height; } /** @@ -2614,21 +2615,22 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants Icon icon = getIconForTab(tabIndex); Insets insets = getTabInsets(tabPlacement, tabIndex); + int width = 0; if (icon != null) { - Rectangle vr = new Rectangle(); - Rectangle ir = new Rectangle(); - Rectangle tr = new Rectangle(); - layoutLabel(tabPlacement, getFontMetrics(), tabIndex, - tabPane.getTitleAt(tabIndex), icon, vr, ir, tr, - tabIndex == tabPane.getSelectedIndex()); - calcRect = tr.union(ir); + Rectangle vr = new Rectangle(); + Rectangle ir = new Rectangle(); + Rectangle tr = new Rectangle(); + layoutLabel(tabPlacement, getFontMetrics(), tabIndex, + tabPane.getTitleAt(tabIndex), icon, vr, ir, tr, + tabIndex == tabPane.getSelectedIndex()); + width = tr.union(ir).width; } else - calcRect.width = metrics.stringWidth(tabPane.getTitleAt(tabIndex)); + width = metrics.stringWidth(tabPane.getTitleAt(tabIndex)); - calcRect.width += insets.left + insets.right; - return calcRect.width; + width += insets.left + insets.right; + return width; } /** @@ -2775,37 +2777,37 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants if (tabPlacement == SwingConstants.TOP || tabPlacement == SwingConstants.BOTTOM) { - if (direction == SwingConstants.WEST) - selectPreviousTabInRun(tabPane.getSelectedIndex()); - else if (direction == SwingConstants.EAST) - selectNextTabInRun(tabPane.getSelectedIndex()); - - else - { - int offset = getTabRunOffset(tabPlacement, tabPane.getTabCount(), - tabPane.getSelectedIndex(), - (tabPlacement == SwingConstants.RIGHT) - ? true : false); - selectAdjacentRunTab(tabPlacement, tabPane.getSelectedIndex(), - offset); - } + if (direction == SwingConstants.WEST) + selectPreviousTabInRun(tabPane.getSelectedIndex()); + else if (direction == SwingConstants.EAST) + selectNextTabInRun(tabPane.getSelectedIndex()); + + else + { + int offset = getTabRunOffset(tabPlacement, tabPane.getTabCount(), + tabPane.getSelectedIndex(), + (tabPlacement == SwingConstants.RIGHT) + ? true : false); + selectAdjacentRunTab(tabPlacement, tabPane.getSelectedIndex(), + offset); + } } if (tabPlacement == SwingConstants.LEFT || tabPlacement == SwingConstants.RIGHT) { - if (direction == SwingConstants.NORTH) - selectPreviousTabInRun(tabPane.getSelectedIndex()); - else if (direction == SwingConstants.SOUTH) - selectNextTabInRun(tabPane.getSelectedIndex()); - else - { - int offset = getTabRunOffset(tabPlacement, tabPane.getTabCount(), - tabPane.getSelectedIndex(), - (tabPlacement == SwingConstants.RIGHT) - ? true : false); - selectAdjacentRunTab(tabPlacement, tabPane.getSelectedIndex(), - offset); - } + if (direction == SwingConstants.NORTH) + selectPreviousTabInRun(tabPane.getSelectedIndex()); + else if (direction == SwingConstants.SOUTH) + selectNextTabInRun(tabPane.getSelectedIndex()); + else + { + int offset = getTabRunOffset(tabPlacement, tabPane.getTabCount(), + tabPane.getSelectedIndex(), + (tabPlacement == SwingConstants.RIGHT) + ? true : false); + selectAdjacentRunTab(tabPlacement, tabPane.getSelectedIndex(), + offset); + } } } @@ -2869,16 +2871,16 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants int y = rects[tabIndex].y + rects[tabIndex].height / 2; switch (tabPlacement) - { - case SwingConstants.TOP: - case SwingConstants.BOTTOM: - y += offset; - break; - case SwingConstants.RIGHT: - case SwingConstants.LEFT: - x += offset; - break; - } + { + case SwingConstants.TOP: + case SwingConstants.BOTTOM: + y += offset; + break; + case SwingConstants.RIGHT: + case SwingConstants.LEFT: + x += offset; + break; + } int index = tabForCoordinate(tabPane, x, y); if (index != -1) @@ -3042,31 +3044,31 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants // Sun's version will happily throw an NPE if params are null, // so I won't check it either. switch (targetPlacement) - { - case SwingConstants.TOP: - targetInsets.top = topInsets.top; - targetInsets.left = topInsets.left; - targetInsets.right = topInsets.right; - targetInsets.bottom = topInsets.bottom; - break; - case SwingConstants.LEFT: - targetInsets.left = topInsets.top; - targetInsets.top = topInsets.left; - targetInsets.right = topInsets.bottom; - targetInsets.bottom = topInsets.right; - break; - case SwingConstants.BOTTOM: - targetInsets.top = topInsets.bottom; - targetInsets.bottom = topInsets.top; - targetInsets.left = topInsets.left; - targetInsets.right = topInsets.right; - break; - case SwingConstants.RIGHT: - targetInsets.top = topInsets.left; - targetInsets.left = topInsets.bottom; - targetInsets.bottom = topInsets.right; - targetInsets.right = topInsets.top; - break; - } + { + case SwingConstants.TOP: + targetInsets.top = topInsets.top; + targetInsets.left = topInsets.left; + targetInsets.right = topInsets.right; + targetInsets.bottom = topInsets.bottom; + break; + case SwingConstants.LEFT: + targetInsets.left = topInsets.top; + targetInsets.top = topInsets.left; + targetInsets.right = topInsets.bottom; + targetInsets.bottom = topInsets.right; + break; + case SwingConstants.BOTTOM: + targetInsets.top = topInsets.bottom; + targetInsets.bottom = topInsets.top; + targetInsets.left = topInsets.left; + targetInsets.right = topInsets.right; + break; + case SwingConstants.RIGHT: + targetInsets.top = topInsets.left; + targetInsets.left = topInsets.bottom; + targetInsets.bottom = topInsets.right; + targetInsets.right = topInsets.top; + break; + } } } diff --git a/javax/swing/plaf/basic/BasicTableUI.java b/javax/swing/plaf/basic/BasicTableUI.java index 4559937eb..2308dc279 100644 --- a/javax/swing/plaf/basic/BasicTableUI.java +++ b/javax/swing/plaf/basic/BasicTableUI.java @@ -1030,12 +1030,8 @@ public class BasicTableUI gfx.translate(-x, -y); } y += height; - if (gap != null) - y += gap.height; } x += width; - if (gap != null) - x += gap.width; } // tighten up the x and y max bounds @@ -1053,10 +1049,8 @@ public class BasicTableUI boolean paintedLine = false; for (int c = 0; c < ncols && x < xmax; ++c) { - x += cols.getColumn(c).getWidth();; - if (gap != null) - x += gap.width; - gfx.drawLine(x, y0, x, ymax); + x += cols.getColumn(c).getWidth(); + gfx.drawLine(x - gap.width, y0, x - gap.width, ymax); paintedLine = true; } gfx.setColor(save); @@ -1072,8 +1066,6 @@ public class BasicTableUI for (int r = 0; r < nrows && y < ymax; ++r) { y += height; - if (gap != null) - y += gap.height; gfx.drawLine(x0, y, xmax, y); paintedLine = true; } diff --git a/javax/swing/plaf/basic/BasicTextAreaUI.java b/javax/swing/plaf/basic/BasicTextAreaUI.java index 97b0ccb6e..4c69f5707 100644 --- a/javax/swing/plaf/basic/BasicTextAreaUI.java +++ b/javax/swing/plaf/basic/BasicTextAreaUI.java @@ -40,6 +40,7 @@ package javax.swing.plaf.basic; import javax.swing.JComponent; +import javax.swing.UIDefaults; import javax.swing.plaf.ComponentUI; import javax.swing.text.Element; import javax.swing.text.PlainView; @@ -61,6 +62,11 @@ public class BasicTextAreaUI extends BasicTextUI return new PlainView(elem); } + /** + * Returns the prefix for entries in the {@link UIDefaults} table. + * + * @return "TextArea" + */ protected String getPropertyPrefix() { return "TextArea"; diff --git a/javax/swing/plaf/basic/BasicTextFieldUI.java b/javax/swing/plaf/basic/BasicTextFieldUI.java index a300446c2..07d1691fb 100644 --- a/javax/swing/plaf/basic/BasicTextFieldUI.java +++ b/javax/swing/plaf/basic/BasicTextFieldUI.java @@ -41,6 +41,7 @@ package javax.swing.plaf.basic; import java.beans.PropertyChangeEvent; import javax.swing.JComponent; +import javax.swing.UIDefaults; import javax.swing.plaf.ComponentUI; import javax.swing.text.Element; import javax.swing.text.FieldView; @@ -63,6 +64,11 @@ public class BasicTextFieldUI extends BasicTextUI return new BasicTextFieldUI(); } + /** + * Returns the prefix for entries in the {@link UIDefaults} table. + * + * @return "TextField" + */ protected String getPropertyPrefix() { return "TextField"; diff --git a/javax/swing/plaf/basic/BasicTextPaneUI.java b/javax/swing/plaf/basic/BasicTextPaneUI.java index 55d908e1b..decbed568 100644 --- a/javax/swing/plaf/basic/BasicTextPaneUI.java +++ b/javax/swing/plaf/basic/BasicTextPaneUI.java @@ -38,10 +38,18 @@ exception statement from your version. */ package javax.swing.plaf.basic; +import java.awt.Color; + import javax.swing.JComponent; +import javax.swing.JTextPane; +import javax.swing.plaf.ColorUIResource; +import javax.swing.UIDefaults; import javax.swing.plaf.ComponentUI; import javax.swing.text.Element; import javax.swing.text.PlainView; +import javax.swing.text.Style; +import javax.swing.text.StyleConstants; +import javax.swing.text.StyleContext; import javax.swing.text.View; public class BasicTextPaneUI extends BasicEditorPaneUI @@ -61,8 +69,32 @@ public class BasicTextPaneUI extends BasicEditorPaneUI return new PlainView(elem); } + /** + * Returns the prefix for entries in the {@link UIDefaults} table. + * + * @return "TextPane" + */ protected String getPropertyPrefix() { return "TextPane"; } + + /** + * Installs this UI on the specified <code>JTextPane</code>. This calls the + * super implementation and then adds a default style to the text pane. + * + * @param c the text pane to install the UI to + */ + public void installUI(JComponent c) + { + super.installUI(c); + JTextPane tp = (JTextPane) c; + Style defaultStyle = tp.getStyle(StyleContext.DEFAULT_STYLE); + defaultStyle.addAttribute(StyleConstants.Foreground, + new ColorUIResource(Color.BLACK)); + defaultStyle.addAttribute(StyleConstants.FontFamily, "Serif"); + defaultStyle.addAttribute(StyleConstants.Italic, Boolean.FALSE); + defaultStyle.addAttribute(StyleConstants.Bold, Boolean.FALSE); + defaultStyle.addAttribute(StyleConstants.FontSize, new Integer(12)); + } } diff --git a/javax/swing/plaf/basic/BasicTextUI.java b/javax/swing/plaf/basic/BasicTextUI.java index 91ccb0056..2bbf45d9c 100644 --- a/javax/swing/plaf/basic/BasicTextUI.java +++ b/javax/swing/plaf/basic/BasicTextUI.java @@ -38,6 +38,7 @@ exception statement from your version. */ package javax.swing.plaf.basic; +import java.awt.Color; import java.awt.Container; import java.awt.Dimension; import java.awt.Graphics; @@ -241,7 +242,7 @@ public abstract class BasicTextUI extends TextUI public void paint(Graphics g, Shape s) { if (view != null) - view.paint(g, s); + view.paint(g, s); } @@ -342,10 +343,17 @@ public abstract class BasicTextUI extends TextUI public void propertyChange(PropertyChangeEvent event) { if (event.getPropertyName().equals("document")) - { + { // Document changed. - modelChanged(); - } + modelChanged(); + } + else if (event.getPropertyName().equals("editable")) + { + if (textComponent.isEditable()) + textComponent.setBackground(background); + else + textComponent.setBackground(inactiveBackground); + } } } @@ -425,6 +433,18 @@ public abstract class BasicTextUI extends TextUI DocumentHandler documentHandler = new DocumentHandler(); /** + * The standard background color. This is the color which is used to paint + * text in enabled text components. + */ + Color background; + + /** + * The inactive background color. This is the color which is used to paint + * text in disabled text components. + */ + Color inactiveBackground; + + /** * Creates a new <code>BasicTextUI</code> instance. */ public BasicTextUI() @@ -507,13 +527,18 @@ public abstract class BasicTextUI extends TextUI 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")); + + // Fetch the colors for enabled/disabled text components. + background = defaults.getColor(prefix + ".background"); + inactiveBackground = defaults.getColor(prefix + ".inactiveBackground"); + textComponent.setForeground(defaults.getColor(prefix + ".foreground")); + textComponent.setDisabledTextColor + (defaults.getColor(prefix + ".inactiveForeground")); } /** @@ -797,8 +822,10 @@ public abstract class BasicTextUI extends TextUI */ protected void paintBackground(Graphics g) { - g.setColor(textComponent.getBackground()); - g.fillRect(0, 0, textComponent.getWidth(), textComponent.getHeight()); + // This method does nothing. All the background filling is done by the + // ComponentUI update method. However, the method is called by paint + // to provide a way for subclasses to draw something different (e.g. background + // images etc) on the background. } /** diff --git a/javax/swing/plaf/basic/BasicToolBarUI.java b/javax/swing/plaf/basic/BasicToolBarUI.java index 8be89efcf..807582d9f 100644 --- a/javax/swing/plaf/basic/BasicToolBarUI.java +++ b/javax/swing/plaf/basic/BasicToolBarUI.java @@ -1030,13 +1030,15 @@ public class BasicToolBarUI extends ToolBarUI implements SwingConstants } origin = new Point(0, 0); - SwingUtilities.convertPointToScreen(ssd, toolBar); + if (toolBar.isShowing()) + SwingUtilities.convertPointToScreen(ssd, toolBar); if (! (SwingUtilities.getAncestorOfClass(Window.class, toolBar) instanceof UIResource)) // Need to know who keeps the toolBar if it gets dragged back into it. origParent = toolBar.getParent(); - - SwingUtilities.convertPointToScreen(origin, toolBar); + + if (toolBar.isShowing()) + SwingUtilities.convertPointToScreen(origin, toolBar); isDragging = true; diff --git a/javax/swing/plaf/basic/BasicTreeUI.java b/javax/swing/plaf/basic/BasicTreeUI.java index 6f714a39c..df763a83d 100644 --- a/javax/swing/plaf/basic/BasicTreeUI.java +++ b/javax/swing/plaf/basic/BasicTreeUI.java @@ -44,6 +44,7 @@ import java.awt.Dimension; import java.awt.Font; import java.awt.FontMetrics; import java.awt.Graphics; +import java.awt.Insets; import java.awt.Point; import java.awt.Rectangle; import java.awt.event.ActionEvent; @@ -62,6 +63,7 @@ import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; +import java.util.Enumeration; import java.util.Hashtable; import javax.swing.AbstractAction; @@ -96,7 +98,6 @@ import javax.swing.text.Caret; import javax.swing.tree.AbstractLayoutCache; import javax.swing.tree.DefaultTreeCellEditor; import javax.swing.tree.DefaultTreeCellRenderer; -import javax.swing.tree.ExpandVetoException; import javax.swing.tree.FixedHeightLayoutCache; import javax.swing.tree.TreeCellEditor; import javax.swing.tree.TreeCellRenderer; @@ -174,6 +175,9 @@ public class BasicTreeUI /** Size needed to completely display all the nodes. */ protected Dimension preferredSize; + + /** Minimum size needed to completely display all the nodes. */ + protected Dimension preferredMinSize; /** Is the preferredSize valid? */ protected boolean validCachedPreferredSize; @@ -225,36 +229,30 @@ public class BasicTreeUI protected boolean editorHasDifferentSize; /** The action listener for the editor's Timer. */ - private Timer editorTimer = new EditorUpdateTimer(); + Timer editorTimer = new EditorUpdateTimer(); /** The new value of the node after editing. */ - private Object newVal; + Object newVal; /** The action bound to KeyStrokes. */ - private TreeAction action; + TreeAction action; /** Boolean to keep track of editing. */ - private boolean isEditing; + boolean isEditing; + + /** The bounds of the current cell. */ + Rectangle bounds; /** Listeners */ private PropertyChangeListener propertyChangeListener; - private FocusListener focusListener; - private TreeSelectionListener treeSelectionListener; - private MouseInputListener mouseInputListener; - private KeyListener keyListener; - private PropertyChangeListener selectionModelPropertyChangeListener; - private ComponentListener componentListener; - private CellEditorListener cellEditorListener; - private TreeExpansionListener treeExpansionListener; - private TreeModelListener treeModelListener; /** @@ -456,7 +454,6 @@ public class BasicTreeUI protected void setCellRenderer(TreeCellRenderer tcr) { currentCellRenderer = tcr; - tree.setCellRenderer(tcr); updateRenderer(); } @@ -625,14 +622,13 @@ public class BasicTreeUI { Object cell = path.getLastPathComponent(); - TreeModel mod = tree.getModel(); - if (mod != null) + if (treeModel != null) { - Object root = mod.getRoot(); + Object root = treeModel.getRoot(); if (!tree.isRootVisible() && tree.isExpanded(new TreePath(root))) root = getNextNode(root); - Point loc = getCellLocation(0, 0, tree, mod, cell, root); + Point loc = getCellLocation(0, 0, tree, treeModel, cell, root); return getCellBounds(loc.x, loc.y, cell); } } @@ -650,10 +646,9 @@ public class BasicTreeUI */ public TreePath getPathForRow(JTree tree, int row) { - TreeModel mod = tree.getModel(); - if (mod != null) + if (treeModel != null) { - Object node = mod.getRoot(); + Object node = treeModel.getRoot(); if (!tree.isRootVisible() && tree.isExpanded(new TreePath(getPathToRoot(node, 0)))) node = getNextNode(node); @@ -683,15 +678,13 @@ public class BasicTreeUI */ public int getRowForPath(JTree tree, TreePath path) { - int row = path.getPathCount(); - if (tree.isVisible(path)) - return row; - - path = path.getParentPath(); - while (row > 0 && !tree.isVisible(path)) + int row = 0; + Object dest = path.getLastPathComponent(); + Object curr = treeModel.getRoot(); + while (curr != null && !curr.equals(dest)) { - path = path.getParentPath(); - row--; + ++row; + curr = getNextVisibleNode(curr); } return row; } @@ -705,11 +698,10 @@ public class BasicTreeUI */ public int getRowCount(JTree tree) { - TreeModel mod = tree.getModel(); int count = 0; - if (mod != null) + if (treeModel != null) { - Object node = mod.getRoot(); + Object node = treeModel.getRoot(); if (!tree.isRootVisible() && tree.isExpanded(new TreePath((getPathToRoot(node, 0))))) node = getNextNode(node); @@ -828,7 +820,6 @@ public class BasicTreeUI */ protected void prepareForUIInstall() { - // FIXME: not implemented } /** @@ -837,7 +828,6 @@ public class BasicTreeUI */ protected void completeUIInstall() { - // FIXME: not implemented } /** @@ -846,7 +836,6 @@ public class BasicTreeUI */ protected void completeUIUninstall() { - // FIXME: not implemented } /** @@ -854,7 +843,10 @@ public class BasicTreeUI */ protected void installComponents() { - // FIXME: not implemented + currentCellRenderer = createDefaultCellRenderer(); + rendererPane = createCellRendererPane(); + createdRenderer = true; + setCellRenderer(currentCellRenderer); } /** @@ -865,8 +857,7 @@ public class BasicTreeUI */ protected AbstractLayoutCache.NodeDimensions createNodeDimensions() { - // FIXME: not implemented - return null; + return new NodeDimensionsHandler(); } /** @@ -1044,9 +1035,8 @@ public class BasicTreeUI TreeCellEditor tce = tree.getCellEditor(); if (tce != null) tce.removeCellEditorListener(cellEditorListener); - TreeModel tm = tree.getModel(); - if (tm != null) - tm.removeTreeModelListener(treeModelListener); + if (treeModel != null) + treeModel.removeTreeModelListener(treeModelListener); } /** @@ -1061,7 +1051,10 @@ public class BasicTreeUI */ protected void uninstallComponents() { - // FIXME: not implemented + currentCellRenderer = null; + rendererPane = null; + createdRenderer = false; + setCellRenderer(currentCellRenderer); } /** @@ -1072,8 +1065,7 @@ public class BasicTreeUI */ protected int getVerticalLegBuffer() { - // FIXME: not implemented - return 0; + return getRowHeight() / 2; } /** @@ -1085,17 +1077,18 @@ public class BasicTreeUI */ protected int getHorizontalLegBuffer() { - // FIXME: not implemented - return 0; + return rightChildIndent / 2; } /** * Make all the nodes that are expanded in JTree expanded in LayoutCache. This - * invokes update ExpandedDescendants with the root path. + * invokes updateExpandedDescendants with the root path. */ protected void updateLayoutCacheExpandedNodes() { - // FIXME: not implemented + if (treeModel != null) + updateExpandedDescendants(new TreePath(getPathToRoot(treeModel. + getRoot(), 0))); } /** @@ -1108,7 +1101,9 @@ public class BasicTreeUI */ protected void updateExpandedDescendants(TreePath path) { - // FIXME: not implemented + Enumeration expanded = tree.getExpandedDescendants(path); + while (expanded.hasMoreElements()) + treeState.setExpandedState(((TreePath) expanded.nextElement()), true); } /** @@ -1128,7 +1123,7 @@ public class BasicTreeUI */ protected void updateDepthOffset() { - // FIXME: not implemented + depthOffset += getVerticalLegBuffer(); } /** @@ -1148,7 +1143,8 @@ public class BasicTreeUI */ protected void updateRenderer() { - // FIXME: not implemented + if (tree != null) + tree.setCellRenderer(currentCellRenderer); } /** @@ -1166,7 +1162,9 @@ public class BasicTreeUI */ protected void updateSize() { - // FIXME: not implemented + preferredSize = null; + updateCachedPreferredSize(); + tree.treeDidChange(); } /** @@ -1206,7 +1204,7 @@ public class BasicTreeUI * @param tree * is the JTree to install defaults for */ - protected void installDefaults(JTree tree) + protected void installDefaults() { UIDefaults defaults = UIManager.getLookAndFeelDefaults(); @@ -1219,6 +1217,9 @@ public class BasicTreeUI leftChildIndent = defaults.getInt("Tree.leftChildIndent"); setRowHeight(defaults.getInt("Tree.rowHeight")); tree.requestFocusInWindow(false); + tree.setScrollsOnExpand(defaults.getBoolean("Tree.scrollsOnExpand")); + setExpandedIcon(defaults.getIcon("Tree.expandedIcon")); + setCollapsedIcon(defaults.getIcon("Tree.collapsedIcon")); } /** @@ -1325,13 +1326,12 @@ public class BasicTreeUI */ public void installUI(JComponent c) { + prepareForUIInstall(); super.installUI(c); - installDefaults((JTree) c); tree = (JTree) c; + installDefaults(); - currentCellRenderer = createDefaultCellRenderer(); - rendererPane = createCellRendererPane(); - createdRenderer = true; + installComponents(); setCellEditor(createDefaultCellEditor()); createdCellEditor = true; @@ -1355,7 +1355,7 @@ public class BasicTreeUI * @param tree * to uninstall defaults for */ - protected void uninstallDefaults(JTree tree) + protected void uninstallDefaults() { tree.setFont(null); tree.setForeground(null); @@ -1370,10 +1370,12 @@ public class BasicTreeUI */ public void uninstallUI(JComponent c) { - uninstallDefaults((JTree) c); + prepareForUIUninstall(); + uninstallDefaults(); uninstallKeyboardActions(); uninstallListeners(); tree = null; + uninstallComponents(); completeUIUninstall(); } @@ -1394,19 +1396,17 @@ public class BasicTreeUI { JTree tree = (JTree) c; - TreeModel mod = tree.getModel(); - - if (mod != null) + if (treeModel != null) { - Object root = mod.getRoot(); + Object root = treeModel.getRoot(); if (!tree.isRootVisible()) tree.expandPath(new TreePath(root)); - paintRecursive(g, 0, 0, 0, 0, tree, mod, root); + paintRecursive(g, 0, 0, 0, 0, tree, treeModel, root); if (hasControlIcons()) - paintControlIcons(g, 0, 0, 0, 0, tree, mod, root); + paintControlIcons(g, 0, 0, 0, 0, tree, treeModel, root); } } @@ -1420,7 +1420,19 @@ public class BasicTreeUI */ protected void ensureRowsAreVisible(int beginRow, int endRow) { - // FIXME: not implemented + if (beginRow < endRow) + { + int temp = endRow; + endRow = beginRow; + beginRow = temp; + } + + for (int i = beginRow; i < endRow; i++) + { + TreePath path = getPathForRow(tree, i); + if (!tree.isVisible(path)) + tree.makeVisible(path); + } } /** @@ -1473,12 +1485,11 @@ public class BasicTreeUI public Dimension getPreferredSize(JComponent c, boolean checkConsistancy) { // FIXME: checkConsistancy not implemented, c not used - TreeModel model = tree.getModel(); int maxWidth = 0; int count = 0; - if (model != null) + if (treeModel != null) { - Object node = model.getRoot(); + Object node = treeModel.getRoot(); if (node != null) { maxWidth = (int) (getCellBounds(0, 0, node).getWidth()); @@ -1506,8 +1517,10 @@ public class BasicTreeUI */ public Dimension getMinimumSize(JComponent c) { - // FIXME: not implemented - return getPreferredSize(c); + Dimension min = getPreferredMinSize(); + if (min == null) + return new Dimension(); + return min; } /** @@ -1520,8 +1533,9 @@ public class BasicTreeUI */ public Dimension getMaximumSize(JComponent c) { - // FIXME: not implemented - return getPreferredSize(c); + if (c instanceof JTree) + return ((JTree) c).getPreferredSize(); + return new Dimension(); } /** @@ -1565,7 +1579,7 @@ public class BasicTreeUI } if (messageTree) - tree.getModel().valueForPathChanged(tree.getLeadSelectionPath(), newVal); + treeModel.valueForPathChanged(tree.getLeadSelectionPath(), newVal); } /** @@ -1600,6 +1614,7 @@ public class BasicTreeUI { editingPath = path; editingRow = tree.getRowForPath(editingPath); + Object val = editingPath.getLastPathComponent(); cellEditor.addCellEditorListener(cellEditorListener); stopEditingInCompleteEditing = false; @@ -1634,7 +1649,8 @@ public class BasicTreeUI protected void checkForClickInExpandControl(TreePath path, int mouseX, int mouseY) { - // FIXME: not implemented + if (isLocationInExpandControl(path, mouseX, mouseY)) + toggleExpandState(path); } /** @@ -1655,8 +1671,24 @@ public class BasicTreeUI protected boolean isLocationInExpandControl(TreePath path, int mouseX, int mouseY) { - // FIXME: not implemented - return false; + boolean cntlClick = false; + int row = getRowForPath(tree, path); + + if (!isLeaf(row)) + { + if (bounds == null) + bounds = getPathBounds(tree, path); + if (tree.isExpanded(path) && expandedIcon != null) + bounds.x -= expandedIcon.getIconWidth() - 4; + else if (collapsedIcon != null) + bounds.x -= collapsedIcon.getIconWidth() - 4; + + Icon controlIcon = getCurrentControlIcon(path); + if (controlIcon != null && (mouseX < bounds.x) + && (mouseX > (bounds.x - controlIcon.getIconWidth()))) + cntlClick = true; + } + return cntlClick; } /** @@ -1672,7 +1704,7 @@ public class BasicTreeUI */ protected void handleExpandControlClick(TreePath path, int mouseX, int mouseY) { - // FIXME: not implemented + toggleExpandState(path); } /** @@ -1686,7 +1718,10 @@ public class BasicTreeUI */ protected void toggleExpandState(TreePath path) { - // FIXME: not implemented + if (tree.isExpanded(path)) + tree.collapsePath(path); + else + tree.expandPath(path); } /** @@ -1700,8 +1735,8 @@ public class BasicTreeUI */ protected boolean isToggleSelectionEvent(MouseEvent event) { - // FIXME: not implemented - return false; + return (tree.getSelectionModel().getSelectionMode() == + TreeSelectionModel.SINGLE_TREE_SELECTION); } /** @@ -1715,8 +1750,8 @@ public class BasicTreeUI */ protected boolean isMultiSelectEvent(MouseEvent event) { - // FIXME: not implemented - return false; + return (tree.getSelectionModel().getSelectionMode() == + TreeSelectionModel.CONTIGUOUS_TREE_SELECTION); } /** @@ -1731,8 +1766,7 @@ public class BasicTreeUI */ protected boolean isToggleEvent(MouseEvent event) { - // FIXME: not implemented - return false; + return true; } /** @@ -1749,7 +1783,29 @@ public class BasicTreeUI */ protected void selectPathForEvent(TreePath path, MouseEvent event) { - // FIXME: not implemented + if (isToggleSelectionEvent(event)) + { + if (tree.isPathSelected(path)) + tree.removeSelectionPath(path); + else + { + tree.addSelectionPath(path); + tree.setAnchorSelectionPath(path); + } + } + else if (isMultiSelectEvent(event)) + { + TreePath anchor = tree.getAnchorSelectionPath(); + if (anchor != null) + { + int aRow = getRowForPath(tree, anchor); + tree.addSelectionInterval(aRow, getRowForPath(tree, path)); + } + else + tree.addSelectionPath(path); + } + else + tree.addSelectionPath(path); } /** @@ -1766,7 +1822,7 @@ public class BasicTreeUI return true; Object node = pathForRow.getLastPathComponent(); - return tree.getModel().isLeaf(node); + return treeModel.isLeaf(node); } /** @@ -1802,7 +1858,7 @@ public class BasicTreeUI { TreePath[] paths = new TreePath[tree.getRowCount()]; - Object curr = getNextVisibleNode(tree.getModel().getRoot()); + Object curr = getNextVisibleNode(treeModel.getRoot()); int i = 0; while (curr != null && i < paths.length) { @@ -1822,13 +1878,8 @@ public class BasicTreeUI { Object last = lead.getLastPathComponent(); TreePath path = new TreePath(getPathToRoot(last, 0)); - if (!tree.getModel().isLeaf(last)) - { - if (tree.isExpanded(path)) - tree.collapsePath(path); - else - tree.expandPath(path); - } + if (!treeModel.isLeaf(last)) + toggleExpandState(path); } } else if (e.getActionCommand().equals("clearSelection")) @@ -2254,38 +2305,38 @@ public class BasicTreeUI public void mousePressed(MouseEvent e) { Point click = e.getPoint(); - int row = Math.round(click.y / getRowHeight()); TreePath path = getClosestPathForLocation(tree, click.x, click.y); if (path != null) { - boolean inBounds = false; - boolean cntlClick = false; - Rectangle bounds = getPathBounds(tree, path); - - bounds.x -= rightChildIndent - 4; - bounds.width += rightChildIndent + 4; - - if (bounds.contains(click.x, click.y)) - inBounds = true; - else if (hasControlIcons() - && (click.x < (bounds.x - rightChildIndent + 5) && - click.x > (bounds.x - rightChildIndent - 5))) - cntlClick = true; + bounds = getPathBounds(tree, path); + int row = getRowForPath(tree, path); + boolean cntlClick = isLocationInExpandControl(path, click.x, click.y); + + if (isLeaf(row)) + { + bounds.x -= rightChildIndent - 4; + bounds.width += rightChildIndent + 4; + } + else if (tree.isExpanded(path) && expandedIcon != null) + bounds.width += expandedIcon.getIconWidth() + 4; + else if (collapsedIcon != null) + bounds.width += collapsedIcon.getIconWidth() + 4; + boolean inBounds = bounds.contains(click.x, click.y); if ((inBounds || cntlClick) && tree.isVisible(path)) { selectPath(tree, path); - - if ((e.getClickCount() == 2 || cntlClick) && !isLeaf(row)) + if (inBounds && e.getClickCount() == 2 && !isLeaf(row)) + toggleExpandState(path); + + if (cntlClick) { - if (tree.isExpanded(path)) - tree.collapsePath(path); - else - tree.expandPath(path); + handleExpandControlClick(path, click.x, click.y); + if (cellEditor != null) + cellEditor.cancelCellEditing(); } - - if (!cntlClick && tree.isEditable()) + else if (tree.isEditable()) startEditing(path, e); } } @@ -2464,7 +2515,7 @@ public class BasicTreeUI /** * Constructor */ - public TreeCancelEditingAction() + public TreeCancelEditingAction(String name) { } @@ -2890,15 +2941,14 @@ public class BasicTreeUI */ public void actionPerformed(ActionEvent e) { - TreeModel mod = tree.getModel(); Object last = tree.getLeadSelectionPath().getLastPathComponent(); if (e.getActionCommand().equals("selectParent")) { TreePath path = new TreePath(getPathToRoot(last, 0)); - Object p = getParent(mod.getRoot(), last); + Object p = getParent(treeModel.getRoot(), last); - if (!mod.isLeaf(last) && tree.isExpanded(path)) + if (!treeModel.isLeaf(last) && tree.isExpanded(path)) tree.collapsePath(path); else if (p != null) selectPath(tree, new TreePath(getPathToRoot(p, 0))); @@ -2907,7 +2957,7 @@ public class BasicTreeUI { TreePath path = new TreePath(getPathToRoot(last, 0)); - if (!mod.isLeaf(last) && tree.isCollapsed(path)) + if (!treeModel.isLeaf(last) && tree.isCollapsed(path)) tree.expandPath(path); else { @@ -3120,8 +3170,8 @@ public class BasicTreeUI { g.setColor(getHashColor()); heightOfLine = descent + halfHeight; - g.drawLine(indentation + halfWidth, heightOfLine, - indentation + rightChildIndent, heightOfLine); + paintHorizontalLine(g, (JComponent) tree, heightOfLine, + indentation + halfWidth, indentation + rightChildIndent); } descent = paintRecursive(g, indent, descent, i, depth + 1, @@ -3135,8 +3185,8 @@ public class BasicTreeUI && mod.getChildCount(curr) > 0) { g.setColor(getHashColor()); - g.drawLine(indentation + halfWidth, y0, indentation + halfWidth, - heightOfLine); + paintVerticalLine(g, (JComponent) tree, indentation + halfWidth, + y0, heightOfLine); } return descent; @@ -3170,8 +3220,9 @@ public class BasicTreeUI { int h = descent; int rowHeight = getRowHeight(); - Icon ei = UIManager.getLookAndFeelDefaults().getIcon("Tree.expandedIcon"); - Icon ci = UIManager.getLookAndFeelDefaults().getIcon("Tree.collapsedIcon"); + TreePath path = new TreePath(getPathToRoot(node, 0)); + Icon icon = getCurrentControlIcon(path); + Rectangle clip = g.getClipBounds(); if (indentation > clip.x + clip.width + rightChildIndent || descent > clip.y + clip.height + getRowHeight()) @@ -3187,11 +3238,12 @@ public class BasicTreeUI int max = 0; if (!mod.isLeaf(node)) max = mod.getChildCount(node); - if (tree.isExpanded(new TreePath(getPathToRoot(node, 0)))) - { - if (!node.equals(mod.getRoot())) - ei.paintIcon(tree, g, indentation - rightChildIndent - 3, h); + if (!node.equals(mod.getRoot())) + icon.paintIcon(tree, g, indentation - rightChildIndent - 3, h); + + if (tree.isExpanded(path)) + { for (int i = 0; i < max; i++) { int indent = indentation + rightChildIndent; @@ -3202,26 +3254,38 @@ public class BasicTreeUI tree, mod, mod.getChild(node, i)); } } - else if (!node.equals(mod.getRoot())) - ci.paintIcon(tree, g, indentation - rightChildIndent - 3, - descent - getRowHeight()); } return descent; } /** - * Returns true if the LookAndFeel implements the control icons Package - * private for use in inner classes. + * Returns control icon. It is null if the LookAndFeel does not + * implements the control icons. + * Package private for use in inner classes. * - * @return true if control icons are visible + * @return control icon if it exists. + */ + Icon getCurrentControlIcon(TreePath path) + { + if (tree.isExpanded(path)) + return UIManager.getLookAndFeelDefaults().getIcon("Tree.expandedIcon"); + return UIManager.getLookAndFeelDefaults().getIcon("Tree.collapsedIcon"); + } + + /** + * Returns true if the LookAndFeel implements the control icons. + * Package private for use in inner classes. + * + * @returns true if there are control icons */ boolean hasControlIcons() { - if (UIManager.getLookAndFeelDefaults().getIcon("Tree.expandedIcon") == null - || UIManager.getLookAndFeelDefaults().getIcon("Tree.collapsedIcon") == null) - return false; - return true; + if (UIManager.getLookAndFeelDefaults().getIcon("Tree.expandedIcon") != null + || UIManager.getLookAndFeelDefaults().getIcon("Tree.collapsedIcon") + != null) + return true; + return false; } /** @@ -3253,16 +3317,15 @@ public class BasicTreeUI */ private Object findNode(Object root, Object node) { - TreeModel mod = tree.getModel(); int size = 0; - if (!mod.isLeaf(root)) - size = mod.getChildCount(root); + if (!treeModel.isLeaf(root)) + size = treeModel.getChildCount(root); for (int i = 0; i < size; i++) { - if (mod.getIndexOfChild(root, node) != -1) + if (treeModel.getIndexOfChild(root, node) != -1) return root; - Object n = findNode(mod.getChild(root, i), node); + Object n = findNode(treeModel.getChild(root, i), node); if (n != null) return n; } @@ -3346,9 +3409,8 @@ public class BasicTreeUI */ Object getNextNode(Object curr) { - TreeModel mod = tree.getModel(); - if (!mod.isLeaf(curr) && mod.getChildCount(curr) > 0) - return mod.getChild(curr, 0); + if (!treeModel.isLeaf(curr) && treeModel.getChildCount(curr) > 0) + return treeModel.getChild(curr, 0); Object node = curr; Object sibling = null; @@ -3356,7 +3418,7 @@ public class BasicTreeUI do { sibling = getNextSibling(node); - node = getParent(mod.getRoot(), node); + node = getParent(treeModel.getRoot(), node); } while (sibling == null && node != null); @@ -3373,8 +3435,7 @@ public class BasicTreeUI */ Object getPreviousNode(Object node) { - TreeModel mod = tree.getModel(); - Object parent = getParent(mod.getRoot(), node); + Object parent = getParent(treeModel.getRoot(), node); if (parent == null) return null; @@ -3384,13 +3445,13 @@ public class BasicTreeUI return parent; int size = 0; - if (!mod.isLeaf(sibling)) - size = mod.getChildCount(sibling); + if (!treeModel.isLeaf(sibling)) + size = treeModel.getChildCount(sibling); while (size > 0) { - sibling = mod.getChild(sibling, size - 1); - if (!mod.isLeaf(sibling)) - size = mod.getChildCount(sibling); + sibling = treeModel.getChild(sibling, size - 1); + if (!treeModel.isLeaf(sibling)) + size = treeModel.getChildCount(sibling); else size = 0; } @@ -3408,20 +3469,19 @@ public class BasicTreeUI */ Object getNextSibling(Object node) { - TreeModel mod = tree.getModel(); - Object parent = getParent(mod.getRoot(), node); + Object parent = getParent(treeModel.getRoot(), node); if (parent == null) return null; - int index = mod.getIndexOfChild(parent, node) + 1; + int index = treeModel.getIndexOfChild(parent, node) + 1; int size = 0; - if (!mod.isLeaf(parent)) - size = mod.getChildCount(parent); + if (!treeModel.isLeaf(parent)) + size = treeModel.getChildCount(parent); if (index == 0 || index >= size) return null; - return mod.getChild(parent, index); + return treeModel.getChild(parent, index); } /** @@ -3434,20 +3494,19 @@ public class BasicTreeUI */ Object getPreviousSibling(Object node) { - TreeModel mod = tree.getModel(); - Object parent = getParent(mod.getRoot(), node); + Object parent = getParent(treeModel.getRoot(), node); if (parent == null) return null; - int index = mod.getIndexOfChild(parent, node) - 1; + int index = treeModel.getIndexOfChild(parent, node) - 1; int size = 0; - if (!mod.isLeaf(parent)) - size = mod.getChildCount(parent); + if (!treeModel.isLeaf(parent)) + size = treeModel.getChildCount(parent); if (index < 0 || index >= size) return null; - return mod.getChild(parent, index); + return treeModel.getChild(parent, index); } /** @@ -3463,22 +3522,24 @@ public class BasicTreeUI { if (path != null) { - if (tree.getSelectionModel().getSelectionMode() == TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION) + if (tree.getSelectionModel().getSelectionMode() == + TreeSelectionModel.SINGLE_TREE_SELECTION) { + tree.getSelectionModel().clearSelection(); tree.addSelectionPath(path); tree.setLeadSelectionPath(path); } - else if (tree.getSelectionModel().getSelectionMode() == TreeSelectionModel.CONTIGUOUS_TREE_SELECTION) + else if (tree.getSelectionModel().getSelectionMode() == + TreeSelectionModel.CONTIGUOUS_TREE_SELECTION) { // TODO } else { - tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); - - tree.getSelectionModel().clearSelection(); tree.addSelectionPath(path); tree.setLeadSelectionPath(path); + tree.getSelectionModel().setSelectionMode + (TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION); } } } @@ -3495,7 +3556,6 @@ public class BasicTreeUI */ Object[] getPathToRoot(Object node, int depth) { - TreeModel mod = tree.getModel(); if (node == null) { if (depth == 0) @@ -3504,7 +3564,7 @@ public class BasicTreeUI return new Object[depth]; } - Object[] path = getPathToRoot(getParent(mod.getRoot(), node), depth + 1); + Object[] path = getPathToRoot(getParent(treeModel.getRoot(), node), depth + 1); path[path.length - depth - 1] = node; return path; } @@ -3523,7 +3583,7 @@ public class BasicTreeUI do { - current = getParent(tree.getModel().getRoot(), current); + current = getParent(treeModel.getRoot(), current); count++; } while (current != null); @@ -3592,4 +3652,144 @@ public class BasicTreeUI int beginPositionY = y - icon.getIconHeight() / 2; icon.paintIcon(c, g, beginPositionX, beginPositionY); } + + /** + * Draws a dashed horizontal line. + * + * @param g - the graphics configuration. + * @param y - the y location to start drawing at + * @param x1 - the x location to start drawing at + * @param x2 - the x location to finish drawing at + */ + protected void drawDashedHorizontalLine(Graphics g, int y, int x1, int x2) + { + for (int i = x1; i < x2; i += 2) + g.drawLine(i, y, i + 1, y); + } + + /** + * Draws a dashed vertical line. + * + * @param g - the graphics configuration. + * @param x - the x location to start drawing at + * @param y1 - the y location to start drawing at + * @param y2 - the y location to finish drawing at + */ + protected void drawDashedVerticalLine(Graphics g, int x, int y1, int y2) + { + for (int i = y1; i < y2; i += 2) + g.drawLine(x, i, x, i + 1); + } + + /** + * Paints the expand (toggle) part of a row. The receiver should NOT modify + * clipBounds, or insets. + * + * @param g - the graphics configuration + * @param clipBounds - + * @param insets - + * @param bounds - bounds of expand control + * @param path - path to draw control for + * @param row - row to draw control for + * @param isExpanded - is the row expanded + * @param hasBeenExpanded - has the row already been expanded + * @param isLeaf - is the path a leaf + */ + protected void paintExpandControl(Graphics g, Rectangle clipBounds, + Insets insets, Rectangle bounds, + TreePath path, int row, + boolean isExpanded, boolean hasBeenExpanded, + boolean isLeaf) + { + if (treeModel != null) + paintControlIcons(g, 0, 0, 0, 0, tree, treeModel, path.getLastPathComponent()); + } + + /** + * Paints the horizontal part of the leg. The receiver should NOT modify + * clipBounds, or insets. + * NOTE: parentRow can be -1 if the root is not visible. + * + * @param g - the graphics configuration + * @param clipBounds - + * @param insets - + * @param bounds - bounds of expand control + * @param path - path to draw control for + * @param row - row to draw control for + * @param isExpanded - is the row expanded + * @param hasBeenExpanded - has the row already been expanded + * @param isLeaf - is the path a leaf + */ + protected void paintHorizontalPartOfLeg(Graphics g, Rectangle clipBounds, + Insets insets, Rectangle bounds, + TreePath path, int row, + boolean isExpanded, boolean hasBeenExpanded, + boolean isLeaf) + { + // FIXME: not implemented + } + + /** + * Paints the vertical part of the leg. The receiver should NOT modify + * clipBounds, insets. + * + * @param g - the graphics configuration. + * @param clipbounds - + * @param insets - + * @param path - the path to draw the vertical part for. + */ + protected void paintVerticalPartOfLeg(Graphics g, Rectangle clipBounds, + Insets insets, TreePath path) + { + // FIXME: not implemented + } + + /** + * Paints the renderer part of a row. The receiver should NOT modify clipBounds, + * or insets. + * + * @param g - the graphics configuration + * @param clipBounds - + * @param insets - + * @param bounds - bounds of expand control + * @param path - path to draw control for + * @param row - row to draw control for + * @param isExpanded - is the row expanded + * @param hasBeenExpanded - has the row already been expanded + * @param isLeaf - is the path a leaf + */ + protected void paintRow(Graphics g, Rectangle clipBounds, + Insets insets, Rectangle bounds, + TreePath path, int row, + boolean isExpanded, boolean hasBeenExpanded, + boolean isLeaf) + { + // FIXME: not implemented. + } + + /** + * Prepares for the UI to uninstall. + */ + protected void prepareForUIUninstall() + { + } + + /** + * Returns true if the expand (toggle) control should be drawn for the + * specified row. + * + * @param path - current path to check for. + * @param row - current row to check for. + * @param isExpanded - true if the path is expanded + * @param hasBeenExpanded - true if the path has been expanded already + * @param isLeaf - true if the row is a lead + */ + protected boolean shouldPaintExpandControl(TreePath path, int row, + boolean isExpanded, + boolean hasBeenExpanded, + boolean isLeaf) + { + // FIXME: not implemented. + return false; + } } // BasicTreeUI diff --git a/javax/swing/plaf/metal/MetalBorders.java b/javax/swing/plaf/metal/MetalBorders.java index f55510684..3d2800657 100644 --- a/javax/swing/plaf/metal/MetalBorders.java +++ b/javax/swing/plaf/metal/MetalBorders.java @@ -44,17 +44,20 @@ import java.awt.Graphics; import java.awt.Insets; import javax.swing.AbstractButton; +import javax.swing.BorderFactory; import javax.swing.ButtonModel; import javax.swing.JInternalFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JTextField; +import javax.swing.JToggleButton; import javax.swing.border.AbstractBorder; import javax.swing.border.Border; import javax.swing.plaf.BorderUIResource; import javax.swing.plaf.UIResource; import javax.swing.plaf.basic.BasicBorders; +import javax.swing.text.JTextComponent; /** @@ -69,6 +72,12 @@ public class MetalBorders /** The shared instance for getButtonBorder(). */ private static Border buttonBorder; + /** The shared instance for getToggleButtonBorder(). */ + private static Border toggleButtonBorder; + + /** The shared instance for getDesktopIconBorder(). */ + private static Border desktopIconBorder; + /** The shared instance for getRolloverButtonBorder(). */ private static Border toolbarButtonBorder; @@ -76,6 +85,11 @@ public class MetalBorders private static Border textFieldBorder; /** + * The shared instance for getTextBorder(). + */ + private static Border textBorder; + + /** * A MarginBorder that gets shared by multiple components. * Created on demand by the private helper function {@link * #getMarginBorder()}. @@ -122,37 +136,46 @@ public class MetalBorders Color light = MetalLookAndFeel.getWhite(); Color middle = MetalLookAndFeel.getControl(); - // draw dark border - g.setColor(darkShadow); - g.drawRect(x, y, w - 2, h - 2); - - if (!bmodel.isPressed()) - { - // draw light border - g.setColor(light); - g.drawRect(x + 1, y + 1, w - 2, h - 2); + if (c.isEnabled()) + { + // draw dark border + g.setColor(darkShadow); + g.drawRect(x, y, w - 2, h - 2); - // draw crossing pixels of both borders - g.setColor(middle); - g.drawRect(x + 1, y + h - 2, 0, 0); - g.drawRect(x + w - 2, y + 1, 0, 0); - } - else - { - // draw light border - g.setColor(light); - g.drawLine(x + w - 1, y + 1, x + w - 1, y + h - 1); - g.drawLine(x + 1, y + h - 1, x + w - 1, y + h - 1); + if (!bmodel.isPressed()) + { + // draw light border + g.setColor(light); + g.drawRect(x + 1, y + 1, w - 2, h - 2); - // draw shadow border - g.setColor(middle); - g.drawLine(x + 1, y + 1, x + w - 2, y + 1); - g.drawLine(x + 1, y + 1, x + 1, y + h - 2); + // draw crossing pixels of both borders + g.setColor(middle); + g.drawRect(x + 1, y + h - 2, 0, 0); + g.drawRect(x + w - 2, y + 1, 0, 0); + } + else + { + // draw light border + g.setColor(light); + g.drawLine(x + w - 1, y + 1, x + w - 1, y + h - 1); + g.drawLine(x + 1, y + h - 1, x + w - 1, y + h - 1); - // draw crossing pixels of both borders - g.setColor(shadow); - g.drawRect(x + 1, y + h - 2, 0, 0); - g.drawRect(x + w - 2, y + 1, 0, 0); + // draw shadow border + g.setColor(middle); + g.drawLine(x + 1, y + 1, x + w - 2, y + 1); + g.drawLine(x + 1, y + 1, x + 1, y + h - 2); + + // draw crossing pixels of both borders + g.setColor(shadow); + g.drawRect(x + 1, y + h - 2, 0, 0); + g.drawRect(x + w - 2, y + 1, 0, 0); + } + } + else + { + // draw disabled border + g.setColor(MetalLookAndFeel.getInactiveControlTextColor()); + g.drawRect(x, y, w - 2, h - 2); } } @@ -191,6 +214,70 @@ public class MetalBorders } /** + * A border used when painting {@link JInternalFrame} instances. + */ + static class DesktopIconBorder extends AbstractBorder + implements UIResource + { + /** + * Creates a new border instance. + */ + public DesktopIconBorder() + { + } + + /** + * Returns the border insets. + * + * @param c the component (ignored). + * + * @return The border insets. + */ + public Insets getBorderInsets(Component c) + { + return getBorderInsets(c, null); + } + + /** + * Returns the border insets. + * + * @param c the component (ignored). + * @return The border insets. + */ + public Insets getBorderInsets(Component c, Insets newInsets) + { + if (newInsets == null) + newInsets = new Insets(3, 3, 2, 3); + else + { + newInsets.top = 3; + newInsets.left = 3; + newInsets.bottom = 2; + newInsets.right = 3; + } + return newInsets; + } + + /** + * Paints the border for the specified component. + * + * @param c the component. + * @param g the graphics device. + * @param x the x-coordinate. + * @param y the y-coordinate. + * @param w the width. + * @param h the height. + */ + public void paintBorder(Component c, Graphics g, int x, int y, int w, + int h) + { + g.setColor(MetalLookAndFeel.getControlDarkShadow()); + g.drawRect(x, y, w - 1, h - 1); + } + + } + + /** * A simple 3D border. */ public static class Flush3DBorder extends AbstractBorder @@ -262,6 +349,88 @@ public class MetalBorders } /** + * A border used for a {@link JInternalFrame} when it is being used as a + * palette. + * + * @since 1.3 + */ + public static class PaletteBorder + extends AbstractBorder + implements UIResource + { + /** + * Creates a new <code>PaletteBorder</code>. + */ + public PaletteBorder() + { + } + + /** + * Returns the border insets. + * + * @param c the component (ignored). + * + * @return The border insets. + */ + public Insets getBorderInsets(Component c) + { + return getBorderInsets(c, null); + } + + /** + * Returns the border insets. + * + * @param c the component (ignored). + * @param newInsets the insets object that, if non-<code>null</code>, will + * be populated with the result from this method. + * + * @return The border insets. + */ + public Insets getBorderInsets(Component c, Insets newInsets) + { + if (newInsets == null) + newInsets = new Insets(1, 1, 1, 1); + else + { + newInsets.top = 1; + newInsets.left = 1; + newInsets.bottom = 1; + newInsets.right = 1; + } + return newInsets; + } + + /** + * Paints the border for the specified component. + * + * @param c the component (ignored). + * @param g the graphics device. + * @param x the x-coordinate. + * @param y the y-coordinate. + * @param w the width. + * @param h the height. + */ + public void paintBorder(Component c, Graphics g, int x, int y, int w, + int h) + { + Color savedColor = g.getColor(); + + // draw the outline + g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow()); + g.drawRect(x, y, w - 1, h - 1); + + // put a dot in each corner + g.setColor(MetalLookAndFeel.getControl()); + g.fillRect(x, y, 1, 1); + g.fillRect(x + w - 1, y, 1, 1); + g.fillRect(x + w - 1, y + h - 1, 1, 1); + g.fillRect(x, y + h - 1, 1, 1); + g.setColor(savedColor); + } + + } + + /** * A border used for the {@link JTextField} component. */ public static class TextFieldBorder extends Flush3DBorder @@ -286,8 +455,9 @@ public class MetalBorders */ public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) - { - if (c.isEnabled()) + { + JTextComponent tc = (JTextComponent) c; + if (tc.isEnabled() && tc.isEditable()) super.paintBorder(c, g, x, y, w, h); else { @@ -386,7 +556,10 @@ public class MetalBorders g.drawLine(x + w - 3, y + 14, x + w - 3, y + h - 15); // draw the line highlights - g.setColor(MetalLookAndFeel.getControl()); + if (f.isSelected()) + g.setColor(MetalLookAndFeel.getPrimaryControlShadow()); + else + g.setColor(MetalLookAndFeel.getControlShadow()); g.drawLine(x + 15, y + 3, x + w - 14, y + 3); g.drawLine(x + 15, y + h - 2, x + w - 14, y + h - 2); g.drawLine(x + 3, y + 15, x + 3, y + h - 14); @@ -770,6 +943,156 @@ public class MetalBorders } /** + * A border used for {@link JToggleButton} components. + * + * @since 1.3 + */ + public static class ToggleButtonBorder + extends ButtonBorder + { + /** + * Creates a new border instance. + */ + public ToggleButtonBorder() + { + } + + /** + * Paints the toggle button border. + * + * @param c the component for which we paint the border + * @param g the Graphics context to use + * @param x the X coordinate of the upper left corner of c + * @param y the Y coordinate of the upper left corner of c + * @param w the width of c + * @param h the height of c + */ + public void paintBorder(Component c, Graphics g, int x, int y, int w, + int h) + { + ButtonModel bmodel = null; + + if (c instanceof AbstractButton) + bmodel = ((AbstractButton) c).getModel(); + + Color darkShadow = MetalLookAndFeel.getControlDarkShadow(); + Color shadow = MetalLookAndFeel.getControlShadow(); + Color light = MetalLookAndFeel.getWhite(); + Color middle = MetalLookAndFeel.getControl(); + + if (c.isEnabled()) + { + // draw dark border + g.setColor(darkShadow); + g.drawRect(x, y, w - 2, h - 2); + + if (!bmodel.isArmed()) + { + // draw light border + g.setColor(light); + g.drawLine(x + 1, y + h - 1, x + w - 1, y + h - 1); + g.drawLine(x + w - 1, y + 1, x + w - 1, y + h - 1); + if (bmodel.isSelected()) + g.setColor(middle); + g.drawLine(x + 1, y + 1, x + w - 3, y + 1); + g.drawLine(x + 1, y + 1, x + 1, y + h - 3); + + // draw crossing pixels of both borders + g.setColor(shadow); + g.drawLine(x + 1, y + h - 2, x + 1, y + h - 2); + g.drawLine(x + w - 2, y + 1, x + w - 2, y + 1); + } + else + { + // draw light border + g.setColor(light); + g.drawLine(x + w - 1, y + 1, x + w - 1, y + h - 1); + g.drawLine(x + 1, y + h - 1, x + w - 1, y + h - 1); + + // draw shadow border + g.setColor(shadow); + g.drawLine(x + 1, y + 1, x + w - 2, y + 1); + g.drawLine(x + 1, y + 1, x + 1, y + h - 2); + + // draw crossing pixels of both borders + g.setColor(shadow); + g.drawLine(x + 1, y + h - 2, x + 1, y + h - 2); + g.drawLine(x + w - 2, y + 1, x + w - 2, y + 1); + + } + // draw corners + g.setColor(middle); + g.drawLine(x, y + h - 1, x, y + h - 1); + g.drawLine(x + w - 1, y, x + w - 1, y); + } + else + { + // draw disabled border + g.setColor(MetalLookAndFeel.getControlDisabled()); + g.drawRect(x, y, w - 2, h - 2); + } + } + } + + /** + * A border for table header cells. + * + * @since 1.3 + */ + public static class TableHeaderBorder extends AbstractBorder + { + /** + * The insets of this border. + */ + // TODO: According to tests that I have done, this is really the border + // that should be returned by getBorderInsets(). However, the name + // is very distracting. Is there any deeper meaning in it? + protected Insets editorBorderInsets; + + /** + * Creates a new instance of <code>TableHeaderBorder</code>. + */ + public TableHeaderBorder() + { + editorBorderInsets = new Insets(1, 1, 1, 1); + } + + /** + * Return the insets of this border. + * + * @return the insets of this border + */ + public Insets getBorderInsets(Component c) + { + return editorBorderInsets; + } + + /** + * Paints the border. + * + * @param c the component for which to paint the border + * @param g the graphics context to use + * @param x the x cooridinate of the border rectangle + * @param y the y cooridinate of the border rectangle + * @param w the width of the border rectangle + * @param h the height of the border rectangle + */ + public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) + { + Color dark = MetalLookAndFeel.getControlDarkShadow(); + Color light = MetalLookAndFeel.getWhite(); + Color old = g.getColor(); + g.setColor(light); + g.drawLine(x, y, x + w - 2, y); + g.drawLine(x, y, x, y + h - 2); + g.setColor(dark); + g.drawLine(x + w - 1, y, x + w - 1, y + h - 1); + g.drawLine(x + 1, y + h - 1, x + w - 1, y + h - 1); + g.setColor(old); + } + } + + /** * Returns a border for Swing buttons in the Metal Look & Feel. * * @return a border for Swing buttons in the Metal Look & Feel @@ -785,6 +1108,40 @@ public class MetalBorders } return buttonBorder; } + + /** + * Returns a border for use with {@link JToggleButton} components. + * + * @return A border. + * + * @since 1.3 + */ + public static Border getToggleButtonBorder() + { + if (toggleButtonBorder == null) + { + Border outer = new ToggleButtonBorder(); + Border inner = getMarginBorder(); + toggleButtonBorder = new BorderUIResource.CompoundBorderUIResource + (outer, inner); + } + return toggleButtonBorder; + } + + /** + * Returns a border instance that is used with a {@link JInternalFrame} when + * it is in the iconified state. + * + * @return A border. + * + * @since 1.3 + */ + public static Border getDesktopIconBorder() + { + if (desktopIconBorder == null) + desktopIconBorder = new DesktopIconBorder(); + return desktopIconBorder; + } /** * Returns a border for use by the {@link JTextField} component. @@ -796,11 +1153,35 @@ public class MetalBorders public static Border getTextFieldBorder() { if (textFieldBorder == null) - textFieldBorder = new TextFieldBorder(); + { + Border inner = getMarginBorder(); + Border outer = new TextFieldBorder(); + textFieldBorder = BorderFactory.createCompoundBorder(outer, inner); + } return textFieldBorder; } /** + * Returns the border that is used for text components (except text fields, + * which use {@link #getTextFieldBorder}. + * + * @return the border that is used for text components + * + * @since 1.3 + */ + public static Border getTextBorder() + { + if (textBorder == null) + { + Border inner = getMarginBorder(); + Border outer = new Flush3DBorder(); + textBorder = + new BorderUIResource.CompoundBorderUIResource(outer, inner); + } + return textBorder; + } + + /** * Returns a border for Toolbar buttons in the Metal Look & Feel. * * @return a border for Toolbar buttons in the Metal Look & Feel diff --git a/javax/swing/plaf/metal/MetalCheckBoxIcon.java b/javax/swing/plaf/metal/MetalCheckBoxIcon.java index 3f3c9ce58..5536e7957 100644 --- a/javax/swing/plaf/metal/MetalCheckBoxIcon.java +++ b/javax/swing/plaf/metal/MetalCheckBoxIcon.java @@ -38,10 +38,8 @@ exception statement from your version. */ package javax.swing.plaf.metal; -import java.awt.Color; import java.awt.Component; import java.awt.Graphics; - import java.io.Serializable; import javax.swing.Icon; @@ -79,7 +77,10 @@ public class MetalCheckBoxIcon */ protected void drawCheck(Component c, Graphics g, int x, int y) { - g.setColor(Color.BLACK); + if (c.isEnabled()) + g.setColor(MetalLookAndFeel.getBlack()); + else + g.setColor(MetalLookAndFeel.getControlDisabled()); g.drawLine(3 + x, 5 + y, 3 + x, 9 + y); g.drawLine(4 + x, 5 + y, 4 + x, 9 + y); g.drawLine(5 + x, 7 + y, 9 + x, 3 + y); diff --git a/javax/swing/plaf/metal/MetalComboBoxButton.java b/javax/swing/plaf/metal/MetalComboBoxButton.java new file mode 100644 index 000000000..f9b802ab7 --- /dev/null +++ b/javax/swing/plaf/metal/MetalComboBoxButton.java @@ -0,0 +1,236 @@ +/* MetalComboBoxButton.java + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package javax.swing.plaf.metal; + +import java.awt.FontMetrics; +import java.awt.Graphics; +import java.awt.Insets; +import java.awt.Rectangle; + +import javax.swing.CellRendererPane; +import javax.swing.Icon; +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JList; +import javax.swing.SwingUtilities; + +/** + * A button used by the {@link MetalComboBoxUI} class. + */ +public class MetalComboBoxButton extends JButton { + + /** A reference to the JComboBox that the button belongs to. */ + protected JComboBox comboBox; + + /** A reference to the JList. */ + protected JList listBox; + + /** ??? */ + protected CellRendererPane rendererPane; + + /** The button icon. */ + protected Icon comboIcon; + + /** Display just the icon, or the icon plus the label. */ + protected boolean iconOnly; + + /** + * Creates a new button. + * + * @param cb the combo that the button is used for (<code>null</code> not + * permitted). + * @param i the icon displayed on the button. + * @param pane the rendering pane. + * @param list the list. + */ + public MetalComboBoxButton(JComboBox cb, Icon i, CellRendererPane pane, + JList list) + { + this(cb, i, cb.isEditable(), pane, list); + } + + /** + * Creates a new button. + * + * @param cb the combo that the button is used for (<code>null</code> not + * permitted). + * @param i the icon displayed on the button. + * @parma onlyIcon a flag that specifies whether the button displays only an + * icon, or text as well. + * @param pane the rendering pane. + * @param list the list. + */ + public MetalComboBoxButton(JComboBox cb, Icon i, boolean onlyIcon, + CellRendererPane pane, JList list) + { + super(i); + comboBox = cb; + comboIcon = i; + iconOnly = onlyIcon; + listBox = list; + rendererPane = pane; + } + + /** + * Returns the combo box that the button is used with. + * + * @return The combo box. + */ + public final JComboBox getComboBox() + { + return comboBox; + } + + /** + * Sets the combo box that the button is used with. + * + * @param cb the combo box. + */ + public final void setComboBox(JComboBox cb) + { + comboBox = cb; + } + + /** + * Returns the icon displayed by the button. By default, this will be an + * instance of {@link MetalComboBoxIcon}. + * + * @return The icon displayed by the button. + */ + public final Icon getComboIcon() + { + return comboIcon; + } + + /** + * Sets the icon displayed by the button. + * + * @param i the icon. + */ + public final void setComboIcon(Icon i) + { + comboIcon = i; + } + + /** + * Returns a flag that controls whether the button displays an icon only, + * or text as well. + * + * @return A boolean. + */ + public final boolean isIconOnly() + { + return iconOnly; + } + + /** + * Sets the flag that controls whether the button displays an icon only, + * or text as well. + * + * @param isIconOnly the flag. + */ + public final void setIconOnly(boolean isIconOnly) + { + iconOnly = isIconOnly; + } + + /** + * Returns <code>false</code>, to indicate that this component is not part + * of the focus traversal group. + * + * @return <code>false</code> + */ + public boolean isFocusTraversable() + { + return false; + } + + /** + * Enables or disables the button. + * + * @param enabled the new status. + */ + public void setEnabled(boolean enabled) + { + super.setEnabled(enabled); + // TODO: figure out what this might need to be used for + // perhaps it has something to do with the button's icon and/or border? + } + + /** + * Paints the component. + * + * @param g the graphics device. + */ + public void paintComponent(Graphics g) + { + if (iconOnly) + { + Rectangle bounds = getBounds(); + int x = (bounds.width - comboIcon.getIconWidth()) / 2; + int y = (bounds.height - comboIcon.getIconHeight()) / 2; + comboIcon.paintIcon(comboBox, g, x, y); + } + else + { + String text = comboBox.getModel().getSelectedItem().toString(); + Rectangle bounds = comboBox.getBounds(); + Rectangle innerArea = SwingUtilities.calculateInnerArea(this, null); + if (comboBox.hasFocus()) + { + g.setColor(MetalLookAndFeel.getFocusColor()); + g.drawRect(innerArea.x, innerArea.y - 1, innerArea.width - 1, + innerArea.height); + } + Insets insets = comboBox.getInsets(); + int iconX = bounds.width - insets.right - comboIcon.getIconWidth() - 7; + int iconY = insets.top + + (bounds.height - comboIcon.getIconHeight()) / 2; + comboIcon.paintIcon(comboBox, g, iconX, iconY); + if (comboBox.isEnabled()) + g.setColor(MetalLookAndFeel.getBlack()); + else + g.setColor(MetalLookAndFeel.getControlDisabled()); + FontMetrics fm = g.getFontMetrics(comboBox.getFont()); + // FIXME: the label may need truncating with '...' and the + // alignment needs work + g.drawString(text, insets.left + 5, fm.getAscent() + 4); + } + } +} diff --git a/javax/swing/plaf/metal/MetalComboBoxEditor.java b/javax/swing/plaf/metal/MetalComboBoxEditor.java new file mode 100644 index 000000000..c086ee70c --- /dev/null +++ b/javax/swing/plaf/metal/MetalComboBoxEditor.java @@ -0,0 +1,144 @@ +/* MetalComboBoxEditor.java + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package javax.swing.plaf.metal; + +import java.awt.Color; +import java.awt.Component; +import java.awt.Graphics; +import java.awt.Insets; + +import javax.swing.JTextField; +import javax.swing.plaf.basic.BasicComboBoxEditor; +import javax.swing.plaf.metal.MetalLookAndFeel; +import javax.swing.plaf.metal.MetalBorders.Flush3DBorder; + +/** + * An editor used by the {@link MetalComboBoxUI} class. + */ +public class MetalComboBoxEditor + extends BasicComboBoxEditor +{ + /** + * A border used for the {@link JTextField} component. + */ + static class MetalComboBoxEditorBorder extends Flush3DBorder + { + /** + * Creates a new border instance. + */ + public MetalComboBoxEditorBorder() + { + } + + /** + * Paints the border for the specified component. + * + * @param c the component (ignored). + * @param g the graphics device. + * @param x the x-coordinate. + * @param y the y-coordinate. + * @param w the width. + * @param h the height. + */ + public void paintBorder(Component c, Graphics g, int x, int y, int w, + int h) + { + Color savedColor = g.getColor(); + if (c.isEnabled()) + g.setColor(MetalLookAndFeel.getControlDarkShadow()); + else + g.setColor(MetalLookAndFeel.getControlShadow()); + g.drawLine(x, y, x + w - 1, y); + g.drawLine(x, y, x, y + h - 2); + g.drawLine(x + 2, y + h - 2, x + w - 1, y + h - 2); + g.setColor(MetalLookAndFeel.getControl()); + g.drawLine(x + 1, y + h - 2, x + 1, y + h - 2); + g.setColor(MetalLookAndFeel.getWhite()); + g.drawLine(x, y + h - 1, x + w - 1, y + h - 1); + g.setColor(savedColor); + } + + /** + * Measures the width of this border. + * + * @param c the component whose border is to be measured. + * + * @return an Insets object whose <code>left</code>, <code>right</code>, + * <code>top</code> and <code>bottom</code> fields indicate the + * width of the border at the respective edge, which is zero + * for the default implementation provided by AbstractButton. + * + * @see #getBorderInsets(java.awt.Component, java.awt.Insets) + */ + public Insets getBorderInsets(Component c) + { + return editorBorderInsets; + } + } + + /** + * A subclass of {@link MetalComboBoxEditor} that implements the + * {@link javax.swing.plaf.UIResource} interface. + */ + public static class UIResource + extends MetalComboBoxEditor + implements javax.swing.plaf.UIResource + { + /** + * Creates a new instance. + */ + public UIResource() + { + } + } + + /** The editor's border insets. */ + protected static Insets editorBorderInsets = new Insets(2, 2, 2, 2); + + /** + * Creates a new editor. + */ + public MetalComboBoxEditor() + { + super(); + editor = new JTextField(); + editor.setBorder(new MetalComboBoxEditorBorder()); + } + +} diff --git a/javax/swing/plaf/metal/MetalComboBoxIcon.java b/javax/swing/plaf/metal/MetalComboBoxIcon.java index ce4fa7d32..f21c5af61 100644 --- a/javax/swing/plaf/metal/MetalComboBoxIcon.java +++ b/javax/swing/plaf/metal/MetalComboBoxIcon.java @@ -1,4 +1,4 @@ -/* MetalComboBoxButton.java +/* MetalComboBoxIcon.java Copyright (C) 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -88,10 +88,11 @@ public class MetalComboBoxIcon implements Icon, Serializable { */ public void paintIcon(Component c, Graphics g, int x, int y) { - // TODO: work out whether/how the icon changes with different component - // states (and also different metal themes) Color savedColor = g.getColor(); - g.setColor(Color.black); + if (c.isEnabled()) + g.setColor(MetalLookAndFeel.getBlack()); + else + g.setColor(MetalLookAndFeel.getControlDisabled()); for (int i = 0; i < 5; i++) g.drawLine(x + i, y + i, x + 9 - i, y + i); g.setColor(savedColor); diff --git a/javax/swing/plaf/metal/MetalComboBoxUI.java b/javax/swing/plaf/metal/MetalComboBoxUI.java index 28c279d8e..7297d1a30 100644 --- a/javax/swing/plaf/metal/MetalComboBoxUI.java +++ b/javax/swing/plaf/metal/MetalComboBoxUI.java @@ -38,19 +38,130 @@ exception statement from your version. */ package javax.swing.plaf.metal; -import java.util.HashMap; +import java.awt.Container; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.LayoutManager; +import java.awt.Rectangle; +import java.awt.event.MouseEvent; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import javax.swing.CellRendererPane; +import javax.swing.ComboBoxEditor; +import javax.swing.JButton; +import javax.swing.JComboBox; import javax.swing.JComponent; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicComboBoxUI; +import javax.swing.plaf.basic.BasicComboPopup; +import javax.swing.plaf.basic.ComboPopup; + +/** + * A UI delegate for the {@link JComboBox} component. + */ public class MetalComboBoxUI extends BasicComboBoxUI { + /** + * A layout manager that arranges the editor component (if active) and the + * button that make up the combo box. + */ + public class MetalComboBoxLayoutManager + extends BasicComboBoxUI.ComboBoxLayoutManager + { + /** + * Creates a new instance of the layout manager. + */ + public MetalComboBoxLayoutManager() + { + } + + /** + * Arranges the editor (if visible) and button that comprise the combo + * box. + * + * @param parent the parent. + */ + public void layoutContainer(Container parent) + { + JComboBox cb = (JComboBox) parent; + if (!cb.isEditable()) + { + Rectangle bounds = parent.getBounds(); + arrowButton.setBounds(0, 0, bounds.width, bounds.height); + } + else + superLayout(parent); + } + + /** + * Calls the <code>layoutContainer(Container)</code> method in the super + * class. + * + * @param parent the container. + */ + public void superLayout(Container parent) + { + super.layoutContainer(parent); + } + } + + /** + * A listener used to handle property changes in the {@link JComboBox} + * component, to ensure that the UI delegate accurately reflects the current + * state in the rendering onscreen. + */ + public class MetalPropertyChangeListener + extends BasicComboBoxUI.PropertyChangeHandler + { + /** + * Creates a new listener. + */ + public MetalPropertyChangeListener() + { + } + + /** + * Handles a property change event, updating the UI components as + * appropriate. + * + * @param e the event. + */ + public void propertyChange(PropertyChangeEvent e) + { + if (e.getPropertyName().equals("editable")) + editablePropertyChanged(e); + super.propertyChange(e); + } + } - /** The UI instances for JComboBoxes. */ - private static HashMap instances = null; - + /** + * A popup menu for the combo-box. + * + * @see #createPopup() + * + * @deprecated 1.4 + */ + public class MetalComboPopup extends BasicComboPopup + { + /** + * Creates a new popup. + * + * @param cBox the combo box. + */ + public MetalComboPopup(JComboBox cBox) + { + super(cBox); + } + + public void delegateFocus(MouseEvent e) + { + super.delegateFocus(e); + } + } + /** * Constructs a new instance of MetalComboBoxUI. */ @@ -68,19 +179,117 @@ public class MetalComboBoxUI */ public static ComponentUI createUI(JComponent component) { - if (instances == null) - instances = new HashMap(); - - Object o = instances.get(component); - MetalComboBoxUI instance; - if (o == null) + return new MetalComboBoxUI(); + } + + /** + * Creates an editor for the combo box. + * + * @return An editor. + */ + protected ComboBoxEditor createEditor() + { + return new MetalComboBoxEditor.UIResource(); + } + + /** + * Creates a popup for the combo box. + * + * @return A popup. + */ + protected ComboPopup createPopup() + { + return new MetalComboPopup(comboBox); + } + + /** + * Creates a new button for use in rendering the JComboBox. + * + * @return A button. + */ + protected JButton createArrowButton() + { + return new MetalComboBoxButton(comboBox, new MetalComboBoxIcon(), + new CellRendererPane(), listBox); + } + + /** + * Creates a new property change listener. + * + * @return A new property change listener. + */ + public PropertyChangeListener createPropertyChangeListener() + { + return new MetalPropertyChangeListener(); + } + + public void paint(Graphics g, JComponent c) + { + // do nothing, the button and text field are painted elsewhere + } + + /** + * Updates the button and text field to reflect a change in the 'editable' + * property. + * + * @param e the event. + * + * @deprecated 1.4 + */ + protected void editablePropertyChanged(PropertyChangeEvent e) + { + if (arrowButton instanceof MetalComboBoxButton) { - instance = new MetalComboBoxUI(); - instances.put(component, instance); + MetalComboBoxButton b = (MetalComboBoxButton) arrowButton; + b.setIconOnly(comboBox.isEditable()); + } + if (comboBox.isEditable()) + { + arrowButton.setText(null); + if (editor != null) + editor.setVisible(true); } else - instance = (MetalComboBoxUI) o; - - return instance; + { + arrowButton.setText(comboBox.getSelectedItem().toString()); + if (editor != null) + editor.setVisible(true); + } + } + + /** + * Creates a new layout manager for the UI delegate. + * + * @return A new layout manager. + */ + protected LayoutManager createLayoutManager() + { + return new MetalComboBoxLayoutManager(); + } + + /** + * Not used in Classpath. + * + * @deprecated 1.4 + */ + protected void removeListeners() + { + // no longer used in JDK 1.4 + } + + /** + * Returns the minimum size for the combo. + * + * @param c the component + * + * @return The minimum size for the combo box. + */ + public Dimension getMinimumSize(JComponent c) + { + // FIXME: this needs work + Dimension result = super.getMinimumSize(c); + result.height = result.height + 9; + return result; } + } diff --git a/javax/swing/plaf/metal/MetalIconFactory.java b/javax/swing/plaf/metal/MetalIconFactory.java index 74386dce6..0c52272e2 100644 --- a/javax/swing/plaf/metal/MetalIconFactory.java +++ b/javax/swing/plaf/metal/MetalIconFactory.java @@ -43,9 +43,11 @@ import java.awt.Component; import java.awt.Graphics; import java.io.Serializable; +import javax.swing.AbstractButton; import javax.swing.Icon; import javax.swing.JCheckBox; import javax.swing.JCheckBoxMenuItem; +import javax.swing.JFileChooser; import javax.swing.JInternalFrame; import javax.swing.JRadioButton; import javax.swing.JRadioButtonMenuItem; @@ -137,6 +139,382 @@ public class MetalIconFactory implements Serializable } /** + * An icon used for the "detail view" button on a {@link JFileChooser} under + * the {@link MetalLookAndFeel}. + * + * @see MetalIconFactory#getFileChooserDetailViewIcon() + */ + private static class FileChooserDetailViewIcon + implements Icon, Serializable { + + /** + * Creates a new icon. + */ + public FileChooserDetailViewIcon() + { + } + + /** + * Returns the width of the icon, in pixels. + * + * @return The width of the icon. + */ + public int getIconWidth() + { + return 18; + } + + /** + * Returns the height of the icon, in pixels. + * + * @return The height of the icon. + */ + public int getIconHeight() + { + return 18; + } + + /** + * Paints the icon using colors from the {@link MetalLookAndFeel}. + * + * @param c the component (ignored). + * @param g the graphics device. + * @param x the x-coordinate for the top-left of the icon. + * @param y the y-coordinate for the top-left of the icon. + */ + public void paintIcon(Component c, Graphics g, int x, int y) + { + Color savedColor = g.getColor(); + g.setColor(MetalLookAndFeel.getBlack()); + + // file 1 outline + g.drawLine(x + 2, y + 2, x + 5, y + 2); + g.drawLine(x + 6, y + 3, x + 6, y + 7); + g.drawLine(x + 2, y + 7, x + 6, y + 7); + g.drawLine(x + 2, y + 2, x + 2, y + 7); + + // file 2 outline + g.drawLine(x + 2, y + 10, x + 5, y + 10); + g.drawLine(x + 6, y + 11, x + 6, y + 15); + g.drawLine(x + 2, y + 15, x + 6, y + 15); + g.drawLine(x + 2, y + 10, x + 2, y + 15); + + // detail lines + g.drawLine(x + 8, y + 5, x + 15, y + 5); + g.drawLine(x + 8, y + 13, x + 15, y + 13); + + // fill files + g.setColor(MetalLookAndFeel.getPrimaryControl()); + g.fillRect(x + 3, y + 3, 3, 4); + g.fillRect(x + 3, y + 11, 3, 4); + + // highlight files + g.setColor(MetalLookAndFeel.getPrimaryControlHighlight()); + g.drawLine(x + 4, y + 4, x + 4, y + 5); + g.drawLine(x + 4, y + 12, x + 4, y + 13); + + g.setColor(savedColor); + } + } + + /** + * An icon used for the "home folder" button on a {@link JFileChooser} under + * the {@link MetalLookAndFeel}. + * + * @see MetalIconFactory#getFileChooserHomeFolderIcon() + */ + private static class FileChooserHomeFolderIcon + implements Icon, Serializable { + + /** + * Creates a new icon. + */ + public FileChooserHomeFolderIcon() + { + } + + /** + * Returns the width of the icon, in pixels. + * + * @return The width of the icon. + */ + public int getIconWidth() + { + return 18; + } + + /** + * Returns the height of the icon, in pixels. + * + * @return The height of the icon. + */ + public int getIconHeight() + { + return 18; + } + + /** + * Paints the icon using colors from the {@link MetalLookAndFeel}. + * + * @param c the component (ignored). + * @param g the graphics device. + * @param x the x-coordinate for the top-left of the icon. + * @param y the y-coordinate for the top-left of the icon. + */ + public void paintIcon(Component c, Graphics g, int x, int y) + { + Color savedColor = g.getColor(); + g.setColor(MetalLookAndFeel.getBlack()); + + // roof + g.drawLine(x + 1, y + 8, x + 8, y + 1); + g.drawLine(x + 8, y + 1, x + 15, y + 8); + + // base of house + g.drawLine(x + 3, y + 6, x + 3, y + 15); + g.drawLine(x + 3, y + 15, x + 13, y + 15); + g.drawLine(x + 13, y + 6, x + 13, y + 15); + + // door frame + g.drawLine(x + 6, y + 9, x + 6, y + 15); + g.drawLine(x + 6, y + 9, x + 10, y + 9); + g.drawLine(x + 10, y + 9, x + 10, y + 15); + + // chimney + g.drawLine(x + 11, y + 2, x + 11, y + 4); + g.drawLine(x + 12, y + 2, x + 12, y + 5); + + g.setColor(MetalLookAndFeel.getControlDarkShadow()); + + // roof paint + int xx = x + 8; + for (int i = 0; i < 4; i++) + g.drawLine(xx - i, y + 2 + i, xx + i, y + 2 + i); + g.fillRect(x + 4, y + 6, 9, 2); + + // door knob + g.drawLine(x + 9, y + 12, x + 9, y + 12); + + // house paint + g.setColor(MetalLookAndFeel.getPrimaryControl()); + g.drawLine(x + 4, y + 8, x + 12, y + 8); + g.fillRect(x + 4, y + 9, 2, 6); + g.fillRect(x + 11, y + 9, 2, 6); + + g.setColor(savedColor); + } + } + + /** + * An icon used for the "list view" button on a {@link JFileChooser} under + * the {@link MetalLookAndFeel}. + * + * @see MetalIconFactory#getFileChooserListViewIcon() + */ + private static class FileChooserListViewIcon implements Icon, Serializable + { + /** + * Creates a new icon. + */ + public FileChooserListViewIcon() + { + } + + /** + * Returns the width of the icon, in pixels. + * + * @return The width of the icon. + */ + public int getIconWidth() + { + return 18; + } + + /** + * Returns the height of the icon, in pixels. + * + * @return The height of the icon. + */ + public int getIconHeight() + { + return 18; + } + + /** + * Paints the icon using colors from the {@link MetalLookAndFeel}. + * + * @param c the component (ignored). + * @param g the graphics device. + * @param x the x-coordinate for the top-left of the icon. + * @param y the y-coordinate for the top-left of the icon. + */ + public void paintIcon(Component c, Graphics g, int x, int y) + { + Color savedColor = g.getColor(); + g.setColor(MetalLookAndFeel.getBlack()); + + // file 1 outline + g.drawLine(x + 2, y + 2, x + 5, y + 2); + g.drawLine(x + 6, y + 3, x + 6, y + 7); + g.drawLine(x + 2, y + 7, x + 6, y + 7); + g.drawLine(x + 2, y + 2, x + 2, y + 7); + + // file 2 outline + g.drawLine(x + 2, y + 10, x + 5, y + 10); + g.drawLine(x + 6, y + 11, x + 6, y + 15); + g.drawLine(x + 2, y + 15, x + 6, y + 15); + g.drawLine(x + 2, y + 10, x + 2, y + 15); + + // file 3 outline + g.drawLine(x + 10, y + 2, x + 13, y + 2); + g.drawLine(x + 14, y + 3, x + 14, y + 7); + g.drawLine(x + 10, y + 7, x + 14, y + 7); + g.drawLine(x + 10, y + 2, x + 10, y + 7); + + // file 4 outline + g.drawLine(x + 10, y + 10, x + 13, y + 10); + g.drawLine(x + 14, y + 11, x + 14, y + 15); + g.drawLine(x + 10, y + 15, x + 14, y + 15); + g.drawLine(x + 10, y + 10, x + 10, y + 15); + + g.drawLine(x + 8, y + 5, x + 8, y + 5); + g.drawLine(x + 8, y + 13, x + 8, y + 13); + g.drawLine(x + 16, y + 5, x + 16, y + 5); + g.drawLine(x + 16, y + 13, x + 16, y + 13); + + // fill files + g.setColor(MetalLookAndFeel.getPrimaryControl()); + g.fillRect(x + 3, y + 3, 3, 4); + g.fillRect(x + 3, y + 11, 3, 4); + g.fillRect(x + 11, y + 3, 3, 4); + g.fillRect(x + 11, y + 11, 3, 4); + + // highlight files + g.setColor(MetalLookAndFeel.getPrimaryControlHighlight()); + g.drawLine(x + 4, y + 4, x + 4, y + 5); + g.drawLine(x + 4, y + 12, x + 4, y + 13); + g.drawLine(x + 12, y + 4, x + 12, y + 5); + g.drawLine(x + 12, y + 12, x + 12, y + 13); + + g.setColor(savedColor); + } + } + + /** + * An icon used for the "new folder" button on a {@link JFileChooser} under + * the {@link MetalLookAndFeel}. + * + * @see MetalIconFactory#getFileChooserNewFolderIcon() + */ + private static class FileChooserNewFolderIcon + implements Icon, Serializable + { + /** + * Creates a new icon. + */ + public FileChooserNewFolderIcon() + { + } + + /** + * Returns the width of the icon, in pixels. + * + * @return The width of the icon. + */ + public int getIconWidth() + { + return 18; + } + + /** + * Returns the height of the icon, in pixels. + * + * @return The height of the icon. + */ + public int getIconHeight() + { + return 18; + } + + /** + * Paints the icon using colors from the {@link MetalLookAndFeel}. + * + * @param c the component (ignored). + * @param g the graphics device. + * @param x the x-coordinate for the top-left of the icon. + * @param y the y-coordinate for the top-left of the icon. + */ + public void paintIcon(Component c, Graphics g, int x, int y) + { + Color savedColor = g.getColor(); + g.setColor(MetalLookAndFeel.getBlack()); + + g.drawLine(x + 2, y + 5, x + 9, y + 5); + g.drawLine(x + 10, y + 6, x + 15, y + 6); + g.drawLine(x + 15, y + 5, x + 15, y + 14); + g.drawLine(x + 2, y + 14, x + 15, y + 14); + g.drawLine(x + 1, y + 6, x + 1, y + 14); + + g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow()); + g.drawLine(x + 11, y + 3, x + 15, y + 3); + g.drawLine(x + 10, y + 4, x + 15, y + 4); + + g.setColor(MetalLookAndFeel.getPrimaryControl()); + g.fillRect(x + 3, y + 7, 7, 7); + g.fillRect(x + 10, y + 8, 5, 6); + g.drawLine(x + 10, y + 5, x + 14, y + 5); + + g.setColor(MetalLookAndFeel.getPrimaryControlHighlight()); + g.drawLine(x + 10, y + 7, x + 14, y + 7); + g.drawLine(x + 2, y + 6, x + 9, y + 6); + g.drawLine(x + 2, y + 6, x + 2, y + 13); + g.setColor(savedColor); + } + } + + /** + * An icon used for the "up folder" button on a {@link JFileChooser} under + * the {@link MetalLookAndFeel}. + * + * @see MetalIconFactory#getFileChooserNewFolderIcon() + */ + private static class FileChooserUpFolderIcon + extends FileChooserNewFolderIcon + implements Icon, Serializable + { + /** + * Creates a new icon. + */ + public FileChooserUpFolderIcon() + { + } + + /** + * Paints the icon using colors from the {@link MetalLookAndFeel}. + * + * @param c the component (ignored). + * @param g the graphics device. + * @param x the x-coordinate for the top-left of the icon. + * @param y the y-coordinate for the top-left of the icon. + */ + public void paintIcon(Component c, Graphics g, int x, int y) + { + Color savedColor = g.getColor(); + + // draw the folder + super.paintIcon(c, g, x, y); + + // now draw the up arrow + g.setColor(MetalLookAndFeel.getBlack()); + g.drawLine(x + 8, y + 9, x + 8, y + 16); + int xx = x + 8; + for (int i = 0; i < 4; i++) + g.drawLine(xx - i, y + 9 + i, xx + i, y + 9 + i); + g.setColor(savedColor); + } + } + + /** * An icon representing a file (drawn as a piece of paper with the top-right * corner turned down). */ @@ -285,7 +663,69 @@ public class MetalIconFactory implements Serializable } } - + + /** + * An icon used by the {@link MetalInternalFrameUI} class when the frame + * is displayed as a palette. + * + * @since 1.3 + */ + public static class PaletteCloseIcon + implements Icon, Serializable, UIResource + { + /** + * Returns the width of the icon, in pixels. + * + * @return The width of the icon. + */ + public int getIconWidth() + { + return 7; + } + + /** + * Returns the height of the icon, in pixels. + * + * @return The height of the icon. + */ + public int getIconHeight() + { + return 7; + } + + /** + * Paints the icon using colors from the {@link MetalLookAndFeel}. + * + * @param c the component (ignored). + * @param g the graphics device. + * @param x the x-coordinate for the top-left of the icon. + * @param y the y-coordinate for the top-left of the icon. + */ + public void paintIcon(Component c, Graphics g, int x, int y) + { + Color savedColor = g.getColor(); + AbstractButton button = (AbstractButton) c; + if (button.getModel().isPressed()) + g.setColor(MetalLookAndFeel.getBlack()); + else + g.setColor(MetalLookAndFeel.getControlDarkShadow()); + g.fillRect(x + 2, y + 2, 3, 3); + g.drawLine(x + 1, y, x + 1, y + 2); + g.drawLine(x, y + 1, x + 2, y + 1); + g.drawLine(x + 5, y, x + 5, y + 2); + g.drawLine(x + 4, y + 1, x + 6, y + 1); + g.drawLine(x + 1, y + 4, x + 1, y + 6); + g.drawLine(x, y + 5, x + 2, y + 5); + g.drawLine(x + 5, y + 4, x + 5, y + 6); + g.drawLine(x + 4, y + 5, x + 6, y + 5); + g.setColor(MetalLookAndFeel.getControlHighlight()); + g.drawLine(x + 2, y + 6, x + 3, y + 5); + g.drawLine(x + 5, y + 3, x + 6, y + 2); + g.drawLine(x + 6, y + 6, x + 6, y + 6); + g.setColor(savedColor); + } + } + /** * An {@link Icon} implementation for {@link JCheckBox}es in the * Metal Look & Feel. @@ -392,7 +832,10 @@ public class MetalIconFactory implements Serializable if (b.isSelected()) { - g.setColor(MetalLookAndFeel.getBlack()); + if (b.isEnabled()) + g.setColor(MetalLookAndFeel.getBlack()); + else + g.setColor(MetalLookAndFeel.getControlDisabled()); g.drawLine(x + 4, y + 3, x + 7, y + 3); g.fillRect(x + 3, y + 4, 6, 4); g.drawLine(x + 4, y + 8, x + 7, y + 8); @@ -637,25 +1080,53 @@ public class MetalIconFactory implements Serializable /** * Paints the icon. * - * @param c the component. + * @param c the component (an {@link JInternalFrame} is expected). * @param g the graphics device. * @param x the x-coordinate. * @param y the y-coordinate. */ public void paintIcon(Component c, Graphics g, int x, int y) { - // draw the gray areas first - g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow()); + Color savedColor = g.getColor(); + AbstractButton b = (AbstractButton) c; + + // fill the interior + if (b.getModel().isPressed()) + // FIXME: also need to take into account whether the internal frame is + // selected + g.setColor(MetalLookAndFeel.getPrimaryControlShadow()); + else + g.setColor(MetalLookAndFeel.getPrimaryControl()); + g.fillRect(x + 2, y + 2, 10, 10); + + // draw the outline box and the cross + if (b.getModel().isPressed()) + g.setColor(MetalLookAndFeel.getBlack()); + else + { + // FIXME: also need to take into account whether the internal frame is + // selected + boolean selected = true; + if (selected) + g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow()); + else + g.setColor(MetalLookAndFeel.getControlDarkShadow()); + } g.drawLine(x + 1, y + 1, x + 13, y + 1); g.drawLine(x + 1, y + 2, x + 1, y + 12); g.drawLine(x + 1, y + 13, x + 13, y + 13); g.drawLine(x + 13, y + 2, x + 13, y + 12); + g.drawLine(x + 2, y + 12, x + 2, y + 12); + g.drawLine(x + 12, y + 2, x + 12, y + 2); g.fillRect(x + 4, y + 4, 2, 2); - g.fillRect(x + 4, y + 9, 2, 2); - g.fillRect(x + 9, y + 4, 2, 2); - g.fillRect(x + 9, y + 9, 2, 2); - g.fillRect(x + 5, y + 5, 5, 5); + g.fillRect(x + 5, y + 5, 4, 4); + g.drawLine(x + 9, y + 4, x + 10, y + 4); + g.drawLine(x + 9, y + 4, x + 9, y + 5); + g.drawLine(x + 4, y + 9, x + 4, y + 10); + g.drawLine(x + 4, y + 9, x + 5, y + 9); + g.drawLine(x + 9, y + 8, x + 9, y + 10); + g.drawLine(x + 8, y + 9, x + 10, y + 9); g.setColor(MetalLookAndFeel.getBlack()); g.drawLine(x, y, x + 13, y); @@ -671,12 +1142,16 @@ public class MetalIconFactory implements Serializable g.drawLine(x + 1, y + 14, x + 14, y + 14); g.drawLine(x + 14, y + 1, x + 14, y + 14); - g.drawLine(x + 5, y + 10, x + 5, y + 10); - g.drawLine(x + 6, y + 9, x + 7, y + 9); - g.drawLine(x + 10, y + 5, x + 10, y + 5); - g.drawLine(x + 9, y + 6, x + 9, y + 7); - g.drawLine(x + 10, y + 10, x + 11, y + 10); - g.drawLine(x + 10, y + 11, x + 10, y + 11); + if (!b.getModel().isPressed()) + { + g.drawLine(x + 5, y + 10, x + 5, y + 10); + g.drawLine(x + 6, y + 9, x + 7, y + 9); + g.drawLine(x + 10, y + 5, x + 10, y + 5); + g.drawLine(x + 9, y + 6, x + 9, y + 7); + g.drawLine(x + 10, y + 10, x + 11, y + 10); + g.drawLine(x + 10, y + 11, x + 10, y + 11); + } + g.setColor(savedColor); } } @@ -800,14 +1275,23 @@ public class MetalIconFactory implements Serializable */ public void paintIcon(Component c, Graphics g, int x, int y) { - Color color = MetalLookAndFeel.getControlDarkShadow(); - if (c instanceof JInternalFrame) - { - JInternalFrame f = (JInternalFrame) c; - if (f.isSelected()) - color = MetalLookAndFeel.getPrimaryControlShadow(); - } - g.setColor(color); + Color savedColor = g.getColor(); + + AbstractButton b = (AbstractButton) c; + + // fill the small box interior + if (b.getModel().isPressed()) + g.setColor(MetalLookAndFeel.getPrimaryControlShadow()); + else + g.setColor(MetalLookAndFeel.getPrimaryControl()); + g.fillRect(x + 2, y + 6, 7, 7); + + + if (b.getModel().isPressed()) + g.setColor(MetalLookAndFeel.getBlack()); + else + g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow()); + g.drawLine(x + 12, y + 1, x + 13, y + 1); g.drawLine(x + 11, y + 2, x + 12, y + 2); g.drawLine(x + 10, y + 3, x + 11, y + 3); @@ -839,10 +1323,16 @@ public class MetalIconFactory implements Serializable g.drawLine(x + 13, y + 6, x + 13, y + 6); g.drawLine(x + 8, y + 7, x + 13, y + 7); g.drawLine(x + 6, y + 5, x + 6, y + 5); - g.drawLine(x + 2, y + 6, x + 6, y + 6); - g.drawLine(x + 2, y + 6, x + 2, y + 11); g.drawLine(x + 10, y + 8, x + 10, y + 13); g.drawLine(x + 1, y + 14, x + 10, y + 14); + + if (!b.getModel().isPressed()) + { + g.drawLine(x + 2, y + 6, x + 6, y + 6); + g.drawLine(x + 2, y + 6, x + 2, y + 11); + } + + g.setColor(savedColor); } } @@ -891,14 +1381,22 @@ public class MetalIconFactory implements Serializable */ public void paintIcon(Component c, Graphics g, int x, int y) { - Color color = MetalLookAndFeel.getControlDarkShadow(); - if (c instanceof JInternalFrame) - { - JInternalFrame f = (JInternalFrame) c; - if (f.isSelected()) - color = MetalLookAndFeel.getPrimaryControlShadow(); - } - g.setColor(color); + Color savedColor = g.getColor(); + + AbstractButton b = (AbstractButton) c; + + // fill the interior + if (b.getModel().isPressed()) + g.setColor(MetalLookAndFeel.getPrimaryControlShadow()); + else + g.setColor(MetalLookAndFeel.getPrimaryControl()); + g.fillRect(x + 2, y + 6, 7, 7); + + if (b.getModel().isPressed()) + g.setColor(MetalLookAndFeel.getBlack()); + else + g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow()); + g.drawLine(x + 9, y + 1, x + 10, y + 1); g.fillRect(x + 11, y + 1, 3, 3); g.fillRect(x + 12, y + 4, 2, 2); @@ -933,9 +1431,12 @@ public class MetalIconFactory implements Serializable // draw white g.setColor(MetalLookAndFeel.getWhite()); - g.drawLine(x + 2, y + 6, x + 5, y + 6); - g.drawLine(x + 2, y + 7, x + 2, y + 9); - g.drawLine(x + 4, y + 11, x + 7, y + 8); + if (!b.getModel().isPressed()) + { + g.drawLine(x + 2, y + 6, x + 5, y + 6); + g.drawLine(x + 2, y + 7, x + 2, y + 9); + g.drawLine(x + 4, y + 11, x + 7, y + 8); + } g.drawLine(x + 1, y + 14, x + 10, y + 14); g.drawLine(x + 10, y + 5, x + 10, y + 13); @@ -944,6 +1445,7 @@ public class MetalIconFactory implements Serializable g.drawLine(x + 11, y + 4, x + 11, y + 5); g.drawLine(x + 13, y + 6, x + 14, y + 6); g.drawLine(x + 14, y + 1, x + 14, y + 5); + g.setColor(savedColor); } } @@ -991,14 +1493,17 @@ public class MetalIconFactory implements Serializable */ public void paintIcon(Component c, Graphics g, int x, int y) { - Color color = MetalLookAndFeel.getControlDarkShadow(); - if (c instanceof JInternalFrame) - { - JInternalFrame f = (JInternalFrame) c; - if (f.isSelected()) - color = MetalLookAndFeel.getPrimaryControlShadow(); - } - g.setColor(color); + Color savedColor = g.getColor(); + + AbstractButton b = (AbstractButton) c; + + if (b.getModel().isPressed()) + g.setColor(MetalLookAndFeel.getBlack()); + else + // FIXME: here the color depends on whether or not the internal frame + // is selected + g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow()); + g.drawLine(x + 12, y + 1, x + 13, y + 1); g.drawLine(x + 11, y + 2, x + 12, y + 2); g.drawLine(x + 10, y + 3, x + 11, y + 3); @@ -1029,10 +1534,21 @@ public class MetalIconFactory implements Serializable g.drawLine(x + 11, y + 4, x + 13, y + 2); g.drawLine(x + 13, y + 6, x + 13, y + 6); g.drawLine(x + 8, y + 7, x + 13, y + 7); - g.drawLine(x + 2, y + 9, x + 4, y + 9); - g.drawLine(x + 2, y + 10, x + 2, y + 11); g.drawLine(x + 7, y + 9, x + 7, y + 13); g.drawLine(x + 1, y + 14, x + 7, y + 14); + + if (b.getModel().isPressed()) + { + g.setColor(MetalLookAndFeel.getPrimaryControlShadow()); + g.fillRect(x + 2, y + 9, 3, 3); + } + else + { + g.drawLine(x + 2, y + 9, x + 4, y + 9); + g.drawLine(x + 2, y + 10, x + 2, y + 11); + } + + g.setColor(savedColor); } } @@ -1388,6 +1904,56 @@ public class MetalIconFactory implements Serializable } /** + * Returns an icon for use by the {@link JFileChooser} component. + * + * @return An icon. + */ + public static Icon getFileChooserDetailViewIcon() + { + return new FileChooserDetailViewIcon(); + } + + /** + * Returns an icon for use by the {@link JFileChooser} component. + * + * @return An icon. + */ + public static Icon getFileChooserHomeFolderIcon() + { + return new FileChooserHomeFolderIcon(); + } + + /** + * Returns an icon for use by the {@link JFileChooser} component. + * + * @return An icon. + */ + public static Icon getFileChooserListViewIcon() + { + return new FileChooserListViewIcon(); + } + + /** + * Returns an icon for use by the {@link JFileChooser} component. + * + * @return An icon. + */ + public static Icon getFileChooserNewFolderIcon() + { + return new FileChooserNewFolderIcon(); + } + + /** + * Returns an icon for use by the {@link JFileChooser} component. + * + * @return An icon. + */ + public static Icon getFileChooserUpFolderIcon() + { + return new FileChooserUpFolderIcon(); + } + + /** * Returns an icon for RadioButtons in the Metal L&F. * * @return an icon for RadioButtons in the Metal L&F diff --git a/javax/swing/plaf/metal/MetalInternalFrameTitlePane.java b/javax/swing/plaf/metal/MetalInternalFrameTitlePane.java index 20526eba8..efae78417 100644 --- a/javax/swing/plaf/metal/MetalInternalFrameTitlePane.java +++ b/javax/swing/plaf/metal/MetalInternalFrameTitlePane.java @@ -38,30 +38,206 @@ exception statement from your version. */ package javax.swing.plaf.metal; +import java.awt.Color; +import java.awt.Component; import java.awt.Container; import java.awt.Dimension; import java.awt.Graphics; +import java.awt.Insets; import java.awt.LayoutManager; +import java.awt.Rectangle; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; import javax.swing.Icon; import javax.swing.JInternalFrame; +import javax.swing.JLabel; import javax.swing.JMenu; +import javax.swing.SwingConstants; +import javax.swing.SwingUtilities; +import javax.swing.UIDefaults; +import javax.swing.UIManager; import javax.swing.plaf.basic.BasicInternalFrameTitlePane; + /** - * The title pane for a {@link JInternalFrame}. + * The title pane for a {@link JInternalFrame}. This can be displayed in two + * styles: one for regular internal frames, and the other for "palette" style + * internal frames. */ public class MetalInternalFrameTitlePane extends BasicInternalFrameTitlePane { + /** + * A property change handler that listens for changes to the + * <code>JInternalFrame.isPalette</code> property and updates the title + * pane as appropriate. + */ + class MetalInternalFrameTitlePanePropertyChangeHandler + extends PropertyChangeHandler + { + /** + * Creates a new handler. + */ + public MetalInternalFrameTitlePanePropertyChangeHandler() + { + super(); + } + + /** + * Handles <code>JInternalFrame.isPalette</code> property changes, with all + * other propert changes being passed to the superclass. + * + * @param e the event. + */ + public void propertyChange(PropertyChangeEvent e) + { + String propName = e.getPropertyName(); + if (propName.equals("JInternalFrame.isPalette")) + { + if (e.getNewValue().equals(Boolean.TRUE)) + setPalette(true); + else + setPalette(false); + } + else + super.propertyChange(e); + } + } + + /** + * A layout manager for the title pane. + * + * @see #createLayout() + */ + private class MetalTitlePaneLayout implements LayoutManager + { + /** + * Creates a new <code>TitlePaneLayout</code> object. + */ + public MetalTitlePaneLayout() + { + // Do nothing. + } + + /** + * Adds a Component to the Container. + * + * @param name The name to reference the added Component by. + * @param c The Component to add. + */ + public void addLayoutComponent(String name, Component c) + { + // Do nothing. + } + + /** + * This method is called to lay out the children of the Title Pane. + * + * @param c The Container to lay out. + */ + public void layoutContainer(Container c) + { + + Dimension size = c.getSize(); + Insets insets = c.getInsets(); + int width = size.width - insets.left - insets.right; + int height = size.height - insets.top - insets.bottom; + + + int loc = width - insets.right - 1; + int top = insets.top + 2; + int buttonHeight = height - 4; + if (closeButton.isVisible()) + { + int buttonWidth = closeIcon.getIconWidth(); + loc -= buttonWidth + 2; + closeButton.setBounds(loc, top, buttonWidth, buttonHeight); + loc -= 6; + } + + if (maxButton.isVisible()) + { + int buttonWidth = maxIcon.getIconWidth(); + loc -= buttonWidth + 4; + maxButton.setBounds(loc, top, buttonWidth, buttonHeight); + } + + if (iconButton.isVisible()) + { + int buttonWidth = minIcon.getIconWidth(); + loc -= buttonWidth + 4; + iconButton.setBounds(loc, top, buttonWidth, buttonHeight); + loc -= 2; + } + + Dimension titlePreferredSize = title.getPreferredSize(); + title.setBounds(insets.left + 5, insets.top, + Math.min(titlePreferredSize.width, loc - insets.left - 10), + height); + + } + + /** + * This method returns the minimum size of the given Container given the + * children that it has. + * + * @param c The Container to get a minimum size for. + * + * @return The minimum size of the Container. + */ + public Dimension minimumLayoutSize(Container c) + { + return preferredLayoutSize(c); + } + + /** + * Returns the preferred size of the given Container taking + * into account the children that it has. + * + * @param c The Container to lay out. + * + * @return The preferred size of the Container. + */ + public Dimension preferredLayoutSize(Container c) + { + if (isPalette) + return new Dimension(paletteTitleHeight, paletteTitleHeight); + else + return new Dimension(22, 22); + } + + /** + * Removes a Component from the Container. + * + * @param c The Component to remove. + */ + public void removeLayoutComponent(Component c) + { + } + } + + /** A flag indicating whether the title pane uses the palette style. */ protected boolean isPalette; - protected Icon paletteCloseIcon = MetalIconFactory.getInternalFrameCloseIcon(16); + /** + * The icon used for the close button - this is fetched from the look and + * feel defaults using the key <code>InternalFrame.paletteCloseIcon</code>. + */ + protected Icon paletteCloseIcon; + + /** + * The height of the title pane when <code>isPalette</code> is + * <code>true</code>. This value is fetched from the look and feel defaults + * using the key <code>InternalFrame.paletteTitleHeight</code>. + */ + protected int paletteTitleHeight; + + /** The label used to display the title for the internal frame. */ + private JLabel title; - protected int paletteTitleHeight = 12; - /** - * Creates a new title pane. + * Creates a new title pane for the specified frame. * * @param f the internal frame. */ @@ -81,6 +257,15 @@ public class MetalInternalFrameTitlePane extends BasicInternalFrameTitlePane selectedTitleColor = MetalLookAndFeel.getWindowTitleBackground(); notSelectedTextColor = MetalLookAndFeel.getInactiveControlTextColor(); notSelectedTitleColor = MetalLookAndFeel.getWindowTitleInactiveBackground(); + + UIDefaults defaults = UIManager.getLookAndFeelDefaults(); + paletteTitleHeight = defaults.getInt("InternalFrame.paletteTitleHeight"); + paletteCloseIcon = defaults.getIcon("InternalFrame.paletteCloseIcon"); + minIcon = MetalIconFactory.getInternalFrameAltMaximizeIcon(16); + + title = new JLabel(frame.getTitle(), + MetalIconFactory.getInternalFrameDefaultMenuIcon(), + SwingConstants.LEFT); } /** @@ -93,6 +278,9 @@ public class MetalInternalFrameTitlePane extends BasicInternalFrameTitlePane selectedTitleColor = null; notSelectedTextColor = null; notSelectedTitleColor = null; + paletteCloseIcon = null; + minIcon = null; + title = null; } /** @@ -127,45 +315,116 @@ public class MetalInternalFrameTitlePane extends BasicInternalFrameTitlePane // do nothing } + protected void addSubComponents() + { + // FIXME: this method is probably overridden to only add the required + // buttons + add(title); + add(closeButton); + add(iconButton); + add(maxButton); + } + /** - * Creates a layout manager for the components in the title pane. + * Creates a new instance of {@link MetalTitlePaneLayout}. * - * @return A layout manager. - */ + * @return A new instance of {@link MetalTitlePaneLayout}. + */ protected LayoutManager createLayout() { - return new TitlePaneLayout() - { - public Dimension preferredLayoutSize(Container c) - { - return new Dimension(24, 24); - } - }; + return new MetalTitlePaneLayout(); } + /** + * Draws the title pane in the palette style. + * + * @param g the graphics device. + * + * @see #paintComponent(Graphics) + */ public void paintPalette(Graphics g) { - // FIXME: needs implementing - // most likely this is equivalent to paintComponent(g) when the isPalette - // flag is true + Color savedColor = g.getColor(); + Rectangle b = SwingUtilities.getLocalBounds(this); + g.setColor(MetalLookAndFeel.getPrimaryControlShadow()); + g.fillRect(b.x, b.y, b.width, b.height); + MetalUtils.fillMetalPattern(g, b.x + 4, b.y + 2, b.width + - paletteCloseIcon.getIconWidth() - 13, b.height - 5, + MetalLookAndFeel.getPrimaryControlHighlight(), + MetalLookAndFeel.getBlack()); + + // draw a line separating the title pane from the frame content + Dimension d = getSize(); + g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow()); + g.drawLine(0, d.height - 1, d.width - 1, d.height - 1); + + g.setColor(savedColor); } - + + /** + * Paints a representation of the current state of the internal frame. + * + * @param g the graphics device. + */ public void paintComponent(Graphics g) { - // probably need to check the isPalette flag here, if true pass over to - // paintPalette(Graphics) - super.paintComponent(g); - Dimension d = getSize(); - if (frame.isSelected()) - g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow()); + Color savedColor = g.getColor(); + if (isPalette) + paintPalette(g); else - g.setColor(MetalLookAndFeel.getControlDarkShadow()); - g.drawLine(0, d.height - 1, d.width - 1, d.height - 1); + { + paintTitleBackground(g); + paintChildren(g); + Dimension d = getSize(); + if (frame.isSelected()) + g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow()); + else + g.setColor(MetalLookAndFeel.getControlDarkShadow()); + + // put a dot in each of the top corners + g.drawLine(0, 0, 0, 0); + g.drawLine(d.width - 1, 0, d.width - 1, 0); + + g.drawLine(0, d.height - 1, d.width - 1, d.height - 1); + + // draw the metal pattern + Rectangle b = title.getBounds(); + int startX = b.x + b.width + 5; + int endX = startX; + if (iconButton.isVisible()) + endX = Math.max(iconButton.getX(), endX); + else if (maxButton.isVisible()) + endX = Math.max(maxButton.getX(), endX); + else if (closeButton.isVisible()) + endX = Math.max(closeButton.getX(), endX); + endX -= 7; + if (endX > startX) + MetalUtils.fillMetalPattern(g, startX, 3, endX - startX, getHeight() - 6, Color.white, Color.gray); + } + g.setColor(savedColor); } + /** + * Sets the flag that controls whether the title pane is drawn in the + * palette style or the regular style. + * + * @param b the new value of the flag. + */ public void setPalette(boolean b) { - isPalette = b; + isPalette = b; + title.setVisible(!isPalette); + iconButton.setVisible(!isPalette && frame.isIconifiable()); + maxButton.setVisible(!isPalette && frame.isMaximizable()); + if (isPalette) + closeButton.setIcon(paletteCloseIcon); + else + closeButton.setIcon(closeIcon); + } + + protected PropertyChangeListener createPropertyChangeListener() + { + return new MetalInternalFrameTitlePanePropertyChangeHandler(); } } diff --git a/javax/swing/plaf/metal/MetalInternalFrameUI.java b/javax/swing/plaf/metal/MetalInternalFrameUI.java index 7c7cb92e5..49b8a0661 100644 --- a/javax/swing/plaf/metal/MetalInternalFrameUI.java +++ b/javax/swing/plaf/metal/MetalInternalFrameUI.java @@ -38,24 +38,31 @@ exception statement from your version. */ package javax.swing.plaf.metal; -import java.util.HashMap; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; import javax.swing.JComponent; import javax.swing.JInternalFrame; -import javax.swing.border.EmptyBorder; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicInternalFrameUI; - +/** + * A UI delegate for the {@link JInternalFrame} component under the + * {@link MetalLookAndFeel}. + */ public class MetalInternalFrameUI extends BasicInternalFrameUI { - - /** The instances of MetalInternalFrameUI*/ - private static HashMap instances; + /** + * The key for the client property that controls whether the internal frame + * is displayed using the palette style. + */ + protected static String IS_PALETTE = "JInternalFrame.isPalette"; /** - * Constructs a new instance of MetalInternalFrameUI. + * Constructs a new instance of <code>MetalInternalFrameUI</code>. + * + * @param frame the frame. */ public MetalInternalFrameUI(JInternalFrame frame) { @@ -63,37 +70,96 @@ public class MetalInternalFrameUI } /** - * Returns an instance of MetalInternalFrameUI. + * Returns an instance of <code>MetalInternalFrameUI</code>. * - * @param component the component for which we return an UI instance + * @param component the internal frame. * - * @return an instance of MetalInternalFrameUI + * @return an instance of <code>MetalInternalFrameUI</code>. */ public static ComponentUI createUI(JComponent component) { - if (instances == null) - instances = new HashMap(); - - - Object o = instances.get(component); - MetalInternalFrameUI instance; - if (o == null) - { - instance = new MetalInternalFrameUI((JInternalFrame) component); - instances.put(component, instance); - } - else - instance = (MetalInternalFrameUI) o; - - return instance; + return new MetalInternalFrameUI((JInternalFrame) component); } + /** + * Sets the fields and properties for the component. + * + * @param c the component. + */ + public void installUI(JComponent c) + { + super.installUI(c); + JInternalFrame f = (JInternalFrame) c; + boolean isPalette = false; + Boolean p = (Boolean) f.getClientProperty(IS_PALETTE); + if (p != null) + isPalette = p.booleanValue(); + setPalette(isPalette); + } + + /** + * Creates and returns the component that will be used for the north pane + * of the {@link JInternalFrame}. + * + * @param w the internal frame. + * + * @return A new instance of {@link MetalInternalFrameTitlePane}. + */ protected JComponent createNorthPane(JInternalFrame w) { titlePane = new MetalInternalFrameTitlePane(w); - titlePane.setBorder(new EmptyBorder(2, 2, 2, 2)); return titlePane; } - + /** + * Sets the state of the {@link JInternalFrame} to reflect whether or not + * it is using the palette style. When a frame is displayed as a palette, + * it uses a different border and the title pane is drawn differently. + * + * @param isPalette use the palette style? + */ + public void setPalette(boolean isPalette) + { + MetalInternalFrameTitlePane title = (MetalInternalFrameTitlePane) northPane; + title.setPalette(isPalette); + if (isPalette) + frame.setBorder(new MetalBorders.PaletteBorder()); + else + frame.setBorder(new MetalBorders.InternalFrameBorder()); + } + + /** A listener that is used to handle IS_PALETTE property changes. */ + private PropertyChangeListener paletteListener; + + /** + * Adds the required listeners. + */ + protected void installListeners() + { + super.installListeners(); + paletteListener = new PropertyChangeListener() + { + public void propertyChange(PropertyChangeEvent e) + { + if (e.getPropertyName().equals(IS_PALETTE)) + { + if (Boolean.TRUE.equals(e.getNewValue())) + setPalette(true); + else + setPalette(false); + } + } + }; + frame.addPropertyChangeListener(paletteListener); + } + + /** + * Removes the listeners used. + */ + protected void uninstallListeners() + { + super.uninstallListeners(); + frame.removePropertyChangeListener(IS_PALETTE, paletteListener); + paletteListener = null; + } } diff --git a/javax/swing/plaf/metal/MetalLookAndFeel.java b/javax/swing/plaf/metal/MetalLookAndFeel.java index 5dfb7cc79..3bc9b25c8 100644 --- a/javax/swing/plaf/metal/MetalLookAndFeel.java +++ b/javax/swing/plaf/metal/MetalLookAndFeel.java @@ -69,7 +69,8 @@ public class MetalLookAndFeel extends BasicLookAndFeel */ public MetalLookAndFeel() { - createDefaultTheme(); + if (theme == null) + createDefaultTheme(); } /** @@ -77,7 +78,7 @@ public class MetalLookAndFeel extends BasicLookAndFeel */ protected void createDefaultTheme() { - setCurrentTheme(new DefaultMetalTheme()); + setCurrentTheme(new OceanTheme()); } /** @@ -759,64 +760,198 @@ public class MetalLookAndFeel extends BasicLookAndFeel { super.initComponentDefaults(defaults); Object[] myDefaults = new Object[] { - "Button.background", new ColorUIResource(getControl()), + "Button.background", getControl(), "Button.border", MetalBorders.getButtonBorder(), - "Button.darkShadow", new ColorUIResource(getControlDarkShadow()), - "Button.disabledText", new ColorUIResource(getControlDisabled()), - "Button.focus", new ColorUIResource(getFocusColor()), + "Button.darkShadow", getControlDarkShadow(), + "Button.disabledText", getInactiveControlTextColor(), + "Button.focus", getFocusColor(), "Button.font", getControlTextFont(), - "Button.foreground", new ColorUIResource(getSystemTextColor()), - "Button.highlight", new ColorUIResource(getControlHighlight()), - "Button.light", new ColorUIResource(getControlHighlight()), + "Button.foreground", getControlTextColor(), + "Button.highlight", getControlHighlight(), + "Button.light", getControlHighlight(), "Button.margin", new Insets(2, 14, 2, 14), - "Button.select", new ColorUIResource(getPrimaryControlShadow()), - "Button.shadow", new ColorUIResource(getPrimaryControlShadow()), - "CheckBox.background", new ColorUIResource(getControl()), + "Button.select", getControlShadow(), + "Button.shadow", getControlShadow(), + + "CheckBox.background", getControl(), "CheckBox.border", MetalBorders.getButtonBorder(), + "CheckBox.disabledText", getInactiveControlTextColor(), + "CheckBox.focus", getFocusColor(), + "CheckBox.font", new FontUIResource("Dialog", Font.BOLD, 12), + "CheckBox.foreground", getControlTextColor(), "CheckBox.icon", new UIDefaults.ProxyLazyValue ("javax.swing.plaf.metal.MetalCheckBoxIcon"), "CheckBox.checkIcon", new UIDefaults.ProxyLazyValue ("javax.swing.plaf.metal.MetalCheckBoxIcon"), - "CheckBoxMenuItem.background", new ColorUIResource(getControl()), + "Checkbox.select", getControlShadow(), + + "CheckBoxMenuItem.acceleratorFont", new FontUIResource("Dialog", Font.PLAIN, 10), + "CheckBoxMenuItem.acceleratorForeground", getAcceleratorForeground(), + "CheckBoxMenuItem.acceleratorSelectionForeground", getAcceleratorSelectedForeground(), + "CheckBoxMenuItem.background", getMenuBackground(), + "CheckBoxMenuItem.borderPainted", new Boolean(true), + "CheckBoxMenuItem.commandSound", "sounds/MenuItemCommand.wav", "CheckBoxMenuItem.checkIcon", MetalIconFactory.getCheckBoxMenuItemIcon(), - "ToolBar.background", new ColorUIResource(getControl()), - "Panel.background", new ColorUIResource(getControl()), - "Slider.background", new ColorUIResource(getControl()), - "OptionPane.background", new ColorUIResource(getControl()), - "ProgressBar.background", new ColorUIResource(getControl()), - "ScrollPane.border", new MetalBorders.ScrollPaneBorder(), - "TabbedPane.background", new ColorUIResource(getControl()), + "CheckBoxMenuItem.disabledForeground", getMenuDisabledForeground(), + "CheckBoxMenuItem.font", new FontUIResource("Dialog", Font.BOLD, 12), + "CheckBoxMenuItem.foreground", getMenuForeground(), + "CheckBoxMenuItem.selectionBackground", getMenuSelectedBackground(), + "CheckBoxMenuItem.selectionForeground", getMenuSelectedForeground(), + + "ColorChooser.background", getControl(), + "ColorChooser.foreground", getControlTextColor(), + "ColorChooser.rgbBlueMnemonic", new Integer(0), + "ColorChooser.rgbGreenMnemonic", new Integer(0), + "ColorChooser.rgbRedMnemonic", new Integer(0), + "ColorChooser.swatchesDefaultRecentColor", getControl(), + + "ComboBox.background", getControl(), + "ComboBox.buttonBackground", getControl(), + "ComboBox.buttonDarkShadow", getControlDarkShadow(), + "ComboBox.buttonHighlight", getControlHighlight(), + "ComboBox.buttonShadow", getControlShadow(), + "ComboBox.disabledBackground", getControl(), + "ComboBox.disabledForeground", getInactiveSystemTextColor(), + "ComboBox.font", new FontUIResource("Dialog", Font.BOLD, 12), + "ComboBox.foreground", getControlTextColor(), + "ComboBox.selectionBackground", getPrimaryControlShadow(), + "ComboBox.selectionForeground", getControlTextColor(), + + "Desktop.background", getDesktopColor(), + + "DesktopIcon.background", getControl(), + "DesktopIcon.foreground", getControlTextColor(), + "DesktopIcon.width", new Integer(160), + "DesktopIcon.border", MetalBorders.getDesktopIconBorder(), + + "EditorPane.background", getWindowBackground(), + "EditorPane.caretForeground", getUserTextColor(), + "EditorPane.font", new FontUIResource("Dialog", Font.PLAIN, 12), + "EditorPane.foreground", getUserTextColor(), + "EditorPane.inactiveForeground", getInactiveSystemTextColor(), + "EditorPane.selectionBackground", getTextHighlightColor(), + "EditorPane.selectionForeground", getHighlightedTextColor(), + + "FormattedTextField.background", getWindowBackground(), + "FormattedTextField.border", + new BorderUIResource(MetalBorders.getTextFieldBorder()), + "FormattedTextField.caretForeground", getUserTextColor(), + "FormattedTextField.font", new FontUIResource("Dialog", Font.PLAIN, 12), + "FormattedTextField.foreground", getUserTextColor(), + "FormattedTextField.inactiveBackground", getControl(), + "FormattedTextField.inactiveForeground", getInactiveSystemTextColor(), + "FormattedTextField.selectionBackground", getTextHighlightColor(), + "FormattedTextField.selectionForeground", getHighlightedTextColor(), + + + "InternalFrame.activeTitleBackground", getWindowTitleBackground(), + "InternalFrame.activeTitleForeground", getWindowTitleForeground(), "InternalFrame.border", new MetalBorders.InternalFrameBorder(), + "InternalFrame.borderColor", getControl(), + "InternalFrame.borderDarkShadow", getControlDarkShadow(), + "InternalFrame.borderHighlight", getControlHighlight(), + "InternalFrame.borderLight", getControlHighlight(), + "InternalFrame.borderShadow", getControlShadow(), "InternalFrame.icon", MetalIconFactory.getInternalFrameDefaultMenuIcon(), "InternalFrame.closeIcon", MetalIconFactory.getInternalFrameCloseIcon(16), + "InternalFrame.inactiveTitleBackground", getWindowTitleInactiveBackground(), + "InternalFrame.inactiveTitleForeground", getWindowTitleInactiveForeground(), "InternalFrame.maximizeIcon", MetalIconFactory.getInternalFrameMaximizeIcon(16), "InternalFrame.iconifyIcon", MetalIconFactory.getInternalFrameMinimizeIcon(16), - "Label.background", new ColorUIResource(getControl()), + "InternalFrame.paletteBorder", new MetalBorders.PaletteBorder(), + "InternalFrame.paletteCloseIcon", new MetalIconFactory.PaletteCloseIcon(), + "InternalFrame.paletteTitleHeight", new Integer(11), + + "Label.background", getControl(), + "Label.disabledForeground", getInactiveSystemTextColor(), + "Label.disabledShadow", getControlShadow(), "Label.font", getControlTextFont(), - "Label.disabledForeground", new ColorUIResource(getInactiveControlTextColor()), - "Label.foreground", new ColorUIResource(getControlTextColor()), - "Menu.background", new ColorUIResource(getControl()), + "Label.foreground", getSystemTextColor(), + + "List.background", getWindowBackground(), + "List.foreground", getUserTextColor(), + "List.selectionBackground", getTextHighlightColor(), + "List.selectionForeground", getHighlightedTextColor(), + + "Menu.acceleratorFont", new FontUIResource("Dialog", Font.PLAIN, 10), + "Menu.acceleratorForeground", getAcceleratorForeground(), + "Menu.acceleratorSelectionForeground", getAcceleratorSelectedForeground(), + "Menu.background", getMenuBackground(), "Menu.border", new MetalBorders.MenuItemBorder(), "Menu.borderPainted", Boolean.TRUE, + "Menu.disabledForeground", getMenuDisabledForeground(), "Menu.font", getControlTextFont(), + "Menu.foreground", getMenuForeground(), "Menu.selectionBackground", getMenuSelectedBackground(), "Menu.selectionForeground", getMenuSelectedForeground(), - "MenuBar.background", new ColorUIResource(getControl()), + + "MenuBar.background", getMenuBackground(), "MenuBar.border", new MetalBorders.MenuBarBorder(), "MenuBar.font", getControlTextFont(), - "MenuItem.background", new ColorUIResource(getControl()), + "MenuBar.foreground", getMenuForeground(), + "MenuBar.highlight", getControlHighlight(), + "MenuBar.shadow", getControlShadow(), + + "MenuItem.acceleratorFont", new FontUIResource("Dialog", Font.PLAIN, 10), + "MenuItem.acceleratorForeground", getAcceleratorForeground(), + "MenuItem.acceleratorSelectionForeground", getAcceleratorSelectedForeground(), + "MenuItem.background", getMenuBackground(), "MenuItem.border", new MetalBorders.MenuItemBorder(), + "MenuItem.disabledForeground", getMenuDisabledForeground(), "MenuItem.font", getControlTextFont(), + "MenuItem.foreground", getMenuForeground(), "MenuItem.selectionBackground", getMenuSelectedBackground(), "MenuItem.selectionForeground", getMenuSelectedForeground(), - "Panel.background", new ColorUIResource(getControl()), - "RadioButton.disabledText", - MetalLookAndFeel.getInactiveControlTextColor(), + + "OptionPane.background", getControl(), + "OptionPane.errorDialog.border.background", new ColorUIResource(153, 51, 51), + "OptionPane.errorDialog.titlePane.background", new ColorUIResource(255, 153, 153), + "OptionPane.errorDialog.titlePane.foreground", new ColorUIResource(51, 0, 0), + "OptionPane.errorDialog.titlePane.shadow", new ColorUIResource(204, 102, 102), + "OptionPane.foreground", getControlTextColor(), + "OptionPane.messageForeground", getControlTextColor(), + "OptionPane.questionDialog.border.background", new ColorUIResource(51, 102, 51), + "OptionPane.questionDialog.titlePane.background", new ColorUIResource(153, 204, 153), + "OptionPane.questionDialog.titlePane.foreground", new ColorUIResource(0, 51, 0), + "OptionPane.questionDialog.titlePane.shadow", new ColorUIResource(102, 153, 102), + "OptionPane.warningDialog.border.background", new ColorUIResource(153, 102, 51), + "OptionPane.warningDialog.titlePane.background", new ColorUIResource(255, 204, 153), + "OptionPane.warningDialog.titlePane.foreground", new ColorUIResource(102, 51, 0), + "OptionPane.warningDialog.titlePane.shadow", new ColorUIResource(204, 153, 102), + + "Panel.background", getControl(), + "Panel.foreground", getUserTextColor(), + + "PasswordField.background", getWindowBackground(), + "PasswordField.border", + new BorderUIResource(MetalBorders.getTextFieldBorder()), + "PasswordField.caretForeground", getUserTextColor(), + "PasswordField.foreground", getUserTextColor(), + "PasswordField.inactiveBackground", getControl(), + "PasswordField.inactiveForeground", getInactiveSystemTextColor(), + "PasswordField.selectionBackground", getTextHighlightColor(), + "PasswordField.selectionForeground", getHighlightedTextColor(), + + "PopupMenu.background", getMenuBackground(), + "PopupMenu.border", new MetalBorders.PopupMenuBorder(), + "PopupMenu.font", new FontUIResource("Dialog", Font.BOLD, 12), + "PopupMenu.foreground", getMenuForeground(), + + "ProgressBar.background", getControl(), + "ProgressBar.border", new BorderUIResource.LineBorderUIResource(getControlDarkShadow(), 1), + "ProgressBar.font", new FontUIResource("Dialog", Font.BOLD, 12), + "ProgressBar.foreground", getPrimaryControlShadow(), + "ProgressBar.selectionBackground", getPrimaryControlDarkShadow(), + "ProgressBar.selectionForeground", getControl(), + + "RadioButton.background", getControl(), + "RadioButton.darkShadow", getControlDarkShadow(), + "RadioButton.disabledText", getInactiveControlTextColor(), "RadioButton.icon", new UIDefaults.LazyValue() { @@ -827,80 +962,192 @@ public class MetalLookAndFeel extends BasicLookAndFeel }, "RadioButton.focus", MetalLookAndFeel.getFocusColor(), "RadioButton.font", MetalLookAndFeel.getControlTextFont(), - "RadioButton.select", MetalLookAndFeel.getControlShadow(), + "RadioButton.foreground", getControlTextColor(), + "RadioButton.highlight", getControlHighlight(), + "RadioButton.light", getControlHighlight(), + "RadioButton.select", getControlShadow(), + "RadioButton.shadow", getControlShadow(), + + "RadioButtonMenuItem.acceleratorFont", new Font("Dialog", Font.PLAIN, 10), + "RadioButtonMenuItem.acceleratorForeground", getAcceleratorForeground(), + "RadioButtonMenuItem.acceleratorSelectionForeground", getAcceleratorSelectedForeground(), + "RadioButtonMenuItem.background", getMenuBackground(), "RadioButtonMenuItem.border", new MetalBorders.MenuItemBorder(), "RadioButtonMenuItem.borderPainted", Boolean.TRUE, "RadioButtonMenuItem.checkIcon", MetalIconFactory.getRadioButtonMenuItemIcon(), + "RadioButtonMenuItem.disabledForeground", getMenuDisabledForeground(), "RadioButtonMenuItem.font", MetalLookAndFeel.getControlTextFont(), + "RadioButtonMenuItem.foreground", getMenuForeground(), "RadioButtonMenuItem.margin", new InsetsUIResource(2, 2, 2, 2), "RadioButtonMenuItem.selectionBackground", MetalLookAndFeel.getMenuSelectedBackground(), "RadioButtonMenuItem.selectionForeground", MetalLookAndFeel.getMenuSelectedForeground(), - "ScrollBar.background", new ColorUIResource(getControl()), - "ScrollBar.shadow", new ColorUIResource(getControlShadow()), - "ScrollBar.thumb", new ColorUIResource(getPrimaryControlShadow()), - "ScrollBar.thumbDarkShadow", - new ColorUIResource(getPrimaryControlDarkShadow()), - "ScrollBar.thumbHighlight", - new ColorUIResource(getPrimaryControl()), + "ScrollBar.background", getControl(), + "ScrollBar.darkShadow", getControlDarkShadow(), + "ScrollBar.foreground", getControl(), + "ScrollBar.highlight", getControlHighlight(), + "ScrollBar.shadow", getControlShadow(), + "ScrollBar.thumb", getPrimaryControlShadow(), + "ScrollBar.thumbDarkShadow", getControlDarkShadow(), + "ScrollBar.thumbHighlight", getPrimaryControl(), + "ScrollBar.thumbShadow", getPrimaryControlDarkShadow(), + "ScrollBar.track", getControl(), + "ScrollBar.trackHighlight", getControlDarkShadow(), + + "ScrollPane.background", getControl(), + "ScrollPane.border", new MetalBorders.ScrollPaneBorder(), + "ScrollPane.foreground", getControlTextColor(), - "SplitPane.darkShadow", - new ColorUIResource(getControlDarkShadow()), - "SplitPane.highlight", - new ColorUIResource(getControlHighlight()), + "Separator.background", getSeparatorBackground(), + "Separator.foreground", getSeparatorForeground(), + "Separator.highlight", getControlHighlight(), + "Separator.shadow", getControlShadow(), + "Slider.background", getControl(), + "Slider.focus", getFocusColor(), "Slider.focusInsets", new InsetsUIResource(0, 0, 0, 0), + "Slider.foreground", getPrimaryControlShadow(), + "Slider.highlight", getControlHighlight(), "Slider.horizontalThumbIcon", MetalIconFactory.getHorizontalSliderThumbIcon(), + "Slider.majorTickLength", new Integer(6), + "Slider.shadow", getControlShadow(), + "Slider.trackWidth", new Integer(7), "Slider.verticalThumbIcon", MetalIconFactory.getVerticalSliderThumbIcon(), - "Slider.trackWidth", new Integer(7), - "Slider.majorTickLength", new Integer(6), - + + "Spinner.background", getControl(), + "Spinner.font", new FontUIResource("Dialog", Font.BOLD, 12), + "Spinner.foreground", getControl(), + + "SplitPane.background", getControl(), + "SplitPane.darkShadow", getControlDarkShadow(), + "SplitPane.dividerFocusColor", getPrimaryControl(), + "SplitPane.highlight", getControlHighlight(), + "SplitPane.shadow", getControlShadow(), + + "SplitPaneDivider.draggingColor", Color.DARK_GRAY, + + "TabbedPane.background", getControlShadow(), + "TabbedPane.darkShadow", getControlDarkShadow(), + "TabbedPane.focus", getPrimaryControlDarkShadow(), "TabbedPane.font", new FontUIResource("Dialog", Font.BOLD, 12), - "TabbedPane.tabInsets", new InsetsUIResource(0, 9, 1, 9), + "TabbedPane.foreground", getControlTextColor(), + "TabbedPane.highlight", getControlHighlight(), + "TabbedPane.light", getControl(), + "TabbedPane.selected", getControl(), + "TabbedPane.selectHighlight", getControlHighlight(), "TabbedPane.selectedTabPadInsets", new InsetsUIResource(2, 2, 2, 1), + "TabbedPane.shadow", getControlShadow(), + "TabbedPane.tabAreaBackground", getControl(), "TabbedPane.tabAreaInsets", new InsetsUIResource(4, 2, 0, 6), + "TabbedPane.tabInsets", new InsetsUIResource(0, 9, 1, 9), - "ToggleButton.background", new ColorUIResource(getControl()), - "ToggleButton.border", MetalBorders.getButtonBorder(), - "ToggleButton.darkShadow", new ColorUIResource(getControlDarkShadow()), - "ToggleButton.disabledText", new ColorUIResource(getControlDisabled()), - "ToggleButton.focus", new ColorUIResource(getFocusColor()), + "Table.background", getWindowBackground(), + "Table.focusCellBackground", getWindowBackground(), + "Table.focusCellForeground", getControlTextColor(), + "Table.foreground", getControlTextColor(), + "Table.focusCellHighlightBorder", getControlShadow(), + "Table.focusCellBackground", getWindowBackground(), + "Table.gridColor", getControlDarkShadow(), + + "TableHeader.background", getControl(), + "TableHeader.cellBorder", new MetalBorders.TableHeaderBorder(), + "TableHeader.foreground", getControlTextColor(), + + "TextArea.background", getWindowBackground(), + "TextArea.caretForeground", getUserTextColor(), + "TextArea.font", new FontUIResource("Dialog", Font.PLAIN, 12), + "TextArea.foreground", getUserTextColor(), + "TextArea.inactiveForeground", getInactiveSystemTextColor(), + "TextArea.selectionBackground", getTextHighlightColor(), + "TextArea.selectionForeground", getHighlightedTextColor(), + + "TextField.background", getWindowBackground(), + "TextField.border", + new BorderUIResource(MetalBorders.getTextFieldBorder()), + "TextField.caretForeground", getUserTextColor(), + "TextField.darkShadow", getControlDarkShadow(), + "TextField.font", new FontUIResource("Dialog", Font.PLAIN, 12), + "TextField.foreground", getUserTextColor(), + "TextField.highlight", getControlHighlight(), + "TextField.inactiveBackground", getControl(), + "TextField.inactiveForeground", getInactiveSystemTextColor(), + "TextField.light", getControlHighlight(), + "TextField.selectionBackground", getTextHighlightColor(), + "TextField.selectionForeground", getHighlightedTextColor(), + "TextField.shadow", getControlShadow(), + + "TextPane.background", getWindowBackground(), + "TextPane.caretForeground", getUserTextColor(), + "TextPane.font", new FontUIResource("Dialog", Font.PLAIN, 12), + "TextPane.foreground", getUserTextColor(), + "TextPane.inactiveForeground", getInactiveSystemTextColor(), + "TextPane.selectionBackground", getTextHighlightColor(), + "TextPane.selectionForeground", getHighlightedTextColor(), + + "TitledBorder.font", new FontUIResource("Dialog", Font.BOLD, 12), + "TitledBorder.titleColor", getSystemTextColor(), + + "ToggleButton.background", getControl(), + "ToggleButton.border", MetalBorders.getToggleButtonBorder(), + "ToggleButton.darkShadow", getControlDarkShadow(), + "ToggleButton.disabledText", getInactiveControlTextColor(), + "ToggleButton.focus", getFocusColor(), "ToggleButton.font", getControlTextFont(), - "ToggleButton.foreground", new ColorUIResource(getSystemTextColor()), - "ToggleButton.highlight", new ColorUIResource(getControlHighlight()), - "ToggleButton.light", new ColorUIResource(getControlHighlight()), - "ToggleButton.margin", new Insets(2, 14, 2, 14), - "ToggleButton.select", new ColorUIResource(getPrimaryControlShadow()), - "ToggleButton.shadow", new ColorUIResource(getPrimaryControlShadow()), - - "Tree.openIcon", MetalIconFactory.getTreeFolderIcon(), + "ToggleButton.foreground", getControlTextColor(), + "ToggleButton.highlight", getControlHighlight(), + "ToggleButton.light", getControlHighlight(), + "ToggleButton.margin", new InsetsUIResource(2, 14, 2, 14), + "ToggleButton.select", getControlShadow(), + "ToggleButton.shadow", getControlShadow(), + + "ToolBar.background", getMenuBackground(), + "ToolBar.darkShadow", getControlDarkShadow(), + "ToolBar.dockingBackground", getMenuBackground(), + "ToolBar.dockingForeground", getPrimaryControlDarkShadow(), + "ToolBar.floatingBackground", getMenuBackground(), + "ToolBar.floatingForeground", getPrimaryControl(), + "ToolBar.font", new FontUIResource("Dialog", Font.BOLD, 12), + "ToolBar.foreground", getMenuForeground(), + "ToolBar.highlight", getControlHighlight(), + "ToolBar.light", getControlHighlight(), + "ToolBar.shadow", getControlShadow(), + + "ToolTip.background", getPrimaryControl(), + "ToolTip.backgroundInactive", getControl(), + "ToolTip.border", new BorderUIResource.LineBorderUIResource(getPrimaryControlDarkShadow(), 1), + "ToolTip.borderInactive", new BorderUIResource.LineBorderUIResource(getControlDarkShadow(), 1), + "ToolTip.font", new FontUIResource("Dialog", Font.PLAIN, 12), + "ToolTip.foreground", getPrimaryControlInfo(), + "ToolTip.foregroundInactive", getControlDarkShadow(), + + "Tree.background", getWindowBackground(), "Tree.closedIcon", MetalIconFactory.getTreeFolderIcon(), - "Tree.leafIcon", MetalIconFactory.getTreeLeafIcon(), "Tree.collapsedIcon", MetalIconFactory.getTreeControlIcon(true), "Tree.expandedIcon", MetalIconFactory.getTreeControlIcon(false), - "Tree.font", new FontUIResource(new Font("Helvetica", Font.PLAIN, 12)), - "Tree.background", new ColorUIResource(Color.white), - "Tree.foreground", new ColorUIResource(new Color(204, 204, 255)), - "Tree.hash", new ColorUIResource(new Color(204, 204, 255)), + "Tree.font", new FontUIResource("Dialog", Font.PLAIN, 12), + "Tree.foreground", getUserTextColor(), + "Tree.hash", getPrimaryControl(), + "Tree.leafIcon", MetalIconFactory.getTreeLeafIcon(), "Tree.leftChildIndent", new Integer(7), + "Tree.line", getPrimaryControl(), + "Tree.openIcon", MetalIconFactory.getTreeFolderIcon(), "Tree.rightChildIndent", new Integer(13), "Tree.rowHeight", new Integer(20), "Tree.scrollsOnExpand", Boolean.TRUE, - "Tree.selectionBackground", new ColorUIResource(new Color(204, 204, 255)), - "Tree.nonSelectionBackground", new ColorUIResource(Color.white), - "Tree.selectionBorderColor", new ColorUIResource(new Color(102, 102, 153)), + "Tree.selectionBackground", getTextHighlightColor(), "Tree.selectionBorder", new BorderUIResource.LineBorderUIResource(new Color(102, 102, 153)), - "Tree.nonSelectionBorder", new BorderUIResource.LineBorderUIResource(Color.white), - "Tree.selectionForeground", new ColorUIResource(Color.black), - "Tree.textBackground", new ColorUIResource(new Color(204, 204, 255)), - "Tree.textForeground", new ColorUIResource(Color.black), - "Tree.selectionForeground", new ColorUIResource(Color.black), - "PopupMenu.border", new MetalBorders.PopupMenuBorder() + "Tree.selectionBorderColor", getFocusColor(), + "Tree.selectionForeground", getHighlightedTextColor(), + "Tree.textBackground", getWindowBackground(), + "Tree.textForeground", getUserTextColor(), + + "Viewport.background", getControl(), + "Viewport.foreground", getUserTextColor() }; defaults.putDefaults(myDefaults); } diff --git a/javax/swing/plaf/metal/MetalProgressBarUI.java b/javax/swing/plaf/metal/MetalProgressBarUI.java index 96d1988fd..a32590d0a 100644 --- a/javax/swing/plaf/metal/MetalProgressBarUI.java +++ b/javax/swing/plaf/metal/MetalProgressBarUI.java @@ -38,17 +38,17 @@ exception statement from your version. */ package javax.swing.plaf.metal; +import java.util.HashMap; + import javax.swing.JComponent; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicProgressBarUI; public class MetalProgressBarUI extends BasicProgressBarUI -{ - - // FIXME: maybe replace by a Map of instances when this becomes stateful - /** The shared UI instance for MetalProgressBarUIs */ - private static MetalProgressBarUI instance = null; +{ + /** The UI instances for MetalTreeUIs */ + private static HashMap instances = null; /** * Constructs a new instance of MetalProgressBarUI. @@ -67,8 +67,19 @@ public class MetalProgressBarUI */ public static ComponentUI createUI(JComponent component) { - if (instance == null) - instance = new MetalProgressBarUI(); + if (instances == null) + instances = new HashMap(); + + Object o = instances.get(component); + MetalProgressBarUI instance; + if (o == null) + { + instance = new MetalProgressBarUI(); + instances.put(component, instance); + } + else + instance = (MetalProgressBarUI) o; + return instance; } } diff --git a/javax/swing/plaf/metal/MetalScrollBarUI.java b/javax/swing/plaf/metal/MetalScrollBarUI.java index 526dfb50a..5d7905a35 100644 --- a/javax/swing/plaf/metal/MetalScrollBarUI.java +++ b/javax/swing/plaf/metal/MetalScrollBarUI.java @@ -38,28 +38,87 @@ exception statement from your version. */ package javax.swing.plaf.metal; +import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Rectangle; -import java.util.HashMap; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import javax.swing.JButton; import javax.swing.JComponent; +import javax.swing.JScrollBar; import javax.swing.UIDefaults; import javax.swing.UIManager; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicScrollBarUI; +/** + * A UI delegate for the {@link JScrollBar} component. + */ public class MetalScrollBarUI extends BasicScrollBarUI { + + /** + * A property change handler for the UI delegate that monitors for + * changes to the "JScrollBar.isFreeStanding" property, and updates + * the buttons and track rendering as appropriate. + */ + class MetalScrollBarPropertyChangeHandler + extends BasicScrollBarUI.PropertyChangeHandler + { + /** + * Creates a new handler. + * + * @see #createPropertyChangeListener() + */ + public MetalScrollBarPropertyChangeHandler() + { + } + + /** + * Handles a property change event. If the event name is + * <code>JSlider.isFreeStanding</code>, this method updates the + * delegate, otherwise the event is passed up to the super class. + * + * @param e the property change event. + */ + public void propertyChange(PropertyChangeEvent e) + { + if (e.getPropertyName().equals(FREE_STANDING_PROP)) + { + Boolean prop = (Boolean) e.getNewValue(); + isFreeStanding = (prop == null ? true : prop.booleanValue()); + increaseButton.setFreeStanding(isFreeStanding); + decreaseButton.setFreeStanding(isFreeStanding); + } + } + } + + /** The name for the 'free standing' property. */ + public static final String FREE_STANDING_PROP = "JScrollBar.isFreeStanding"; /** The minimum thumb size */ - private static final Dimension MIN_THUMB_SIZE = new Dimension(18, 18); - - // FIXME: maybe replace by a Map of instances when this becomes stateful - /** The shared UI instance for JScrollBars. */ - private static HashMap instances = null; + private static final Dimension MIN_THUMB_SIZE = new Dimension(17, 17); + /** The button that increases the value in the scroll bar. */ + protected MetalScrollButton increaseButton; + + /** The button that decreases the value in the scroll bar. */ + protected MetalScrollButton decreaseButton; + + /** The scroll bar width. */ + protected int scrollBarWidth; + + /** + * A flag that indicates whether the scroll bar is "free standing", which + * means it has complete borders and can be used anywhere in the UI. A + * scroll bar which is not free standing has borders missing from one + * side, and relies on being part of another container with its own borders + * to look right visually. */ + protected boolean isFreeStanding; + /** * Constructs a new instance of MetalScrollBarUI. */ @@ -77,20 +136,166 @@ public class MetalScrollBarUI */ public static ComponentUI createUI(JComponent component) { - if (instances == null) - instances = new HashMap(); + return new MetalScrollBarUI(); + } + + /** + * Installs the defaults. + */ + protected void installDefaults() + { + // need to initialise isFreeStanding before calling the super class, + // so that the value is set when createIncreaseButton() and + // createDecreaseButton() are called (unless there is somewhere earlier + // that we can do this). + Boolean prop = (Boolean) scrollbar.getClientProperty(FREE_STANDING_PROP); + isFreeStanding = (prop == null ? true : prop.booleanValue()); + super.installDefaults(); + } + + /** + * Creates a property change listener for the delegate to use. This + * overrides the method to provide a custom listener for the + * {@link MetalLookAndFeel} that can handle the + * <code>JScrollBar.isFreeStanding</code> property. + * + * @return A property change listener. + */ + protected PropertyChangeListener createPropertyChangeListener() + { + return new MetalScrollBarPropertyChangeHandler(); + } + + /** + * Creates a new button to use as the control at the lower end of the + * {@link JScrollBar}. + * + * @param orientation the orientation of the button ({@link #NORTH}, + * {@link #SOUTH}, {@link #EAST} or {@link #WEST}). + * + * @return The button. + */ + protected JButton createDecreaseButton(int orientation) + { + UIDefaults defaults = UIManager.getLookAndFeelDefaults(); + scrollBarWidth = defaults.getInt("ScrollBar.width"); + return new MetalScrollButton(orientation, scrollBarWidth, isFreeStanding); + } - Object o = instances.get(component); - MetalScrollBarUI instance; - if (o == null) + /** + * Creates a new button to use as the control at the upper end of the + * {@link JScrollBar}. + * + * @param orientation the orientation of the button ({@link #NORTH}, + * {@link #SOUTH}, {@link #EAST} or {@link #WEST}). + * + * @return The button. + */ + protected JButton createIncreaseButton(int orientation) + { + UIDefaults defaults = UIManager.getLookAndFeelDefaults(); + scrollBarWidth = defaults.getInt("ScrollBar.width"); + return new MetalScrollButton(orientation, scrollBarWidth, isFreeStanding); + } + + /** + * Paints the track for the scrollbar. + * + * @param g the graphics device. + * @param c the component. + * @param trackBounds the track bounds. + */ + protected void paintTrack(Graphics g, JComponent c, Rectangle trackBounds) + { + g.setColor(MetalLookAndFeel.getControl()); + g.fillRect(trackBounds.x, trackBounds.y, trackBounds.width, + trackBounds.height); + if (scrollbar.getOrientation() == HORIZONTAL) + paintTrackHorizontal(g, c, trackBounds.x, trackBounds.y, + trackBounds.width, trackBounds.height); + else + paintTrackVertical(g, c, trackBounds.x, trackBounds.y, + trackBounds.width, trackBounds.height); + + } + + /** + * Paints the track for a horizontal scrollbar. + * + * @param g the graphics device. + * @param c the component. + * @param x the x-coordinate for the track bounds. + * @param y the y-coordinate for the track bounds. + * @param w the width for the track bounds. + * @param h the height for the track bounds. + */ + private void paintTrackHorizontal(Graphics g, JComponent c, + int x, int y, int w, int h) + { + if (c.isEnabled()) { - instance = new MetalScrollBarUI(); - instances.put(component, instance); + g.setColor(MetalLookAndFeel.getControlDarkShadow()); + g.drawLine(x, y, x, y + h - 1); + g.drawLine(x, y, x + w - 1, y); + g.drawLine(x + w - 1, y, x + w - 1, y + h - 1); + + g.setColor(MetalLookAndFeel.getControlShadow()); + g.drawLine(x + 1, y + 1, x + 1, y + h - 1); + g.drawLine(x + 1, y + 1, x + w - 2, y + 1); + + if (isFreeStanding) + { + g.setColor(MetalLookAndFeel.getControlDarkShadow()); + g.drawLine(x, y + h - 2, x + w - 1, y + h - 2); + g.setColor(MetalLookAndFeel.getControlShadow()); + g.drawLine(x, y + h - 1, x + w - 1, y + h - 1); + } } else - instance = (MetalScrollBarUI) o; - - return instance; + { + g.setColor(MetalLookAndFeel.getControlDisabled()); + g.drawRect(x, y, w - 1, h - 1); + } + } + + /** + * Paints the track for a vertical scrollbar. + * + * @param g the graphics device. + * @param c the component. + * @param x the x-coordinate for the track bounds. + * @param y the y-coordinate for the track bounds. + * @param w the width for the track bounds. + * @param h the height for the track bounds. + */ + protected void paintTrackVertical(Graphics g, JComponent c, + int x, int y, int w, int h) + { + if (c.isEnabled()) + { + g.setColor(MetalLookAndFeel.getControlDarkShadow()); + g.drawLine(x, y, x, y + h - 1); + g.drawLine(x, y, x + w - 1, y); + g.drawLine(x, y + h - 1, x + w - 1, y + h - 1); + + g.setColor(MetalLookAndFeel.getControlShadow()); + g.drawLine(x + 1, y + 1, x + w - 1, y + 1); + g.drawLine(x + 1, y + 1, x + 1, y + h - 2); + g.drawLine(x + 1, y + h - 2, x + w - 1, y + h - 2); + + if (isFreeStanding) + { + g.setColor(MetalLookAndFeel.getControlDarkShadow()); + g.drawLine(x + w - 2, y, x + w - 2, y + h - 1); + g.setColor(MetalLookAndFeel.getControlHighlight()); + g.drawLine(x + w - 1, y, x + w - 1, y + h - 1); + } + } + else + { + g.setColor(MetalLookAndFeel.getControlDisabled()); + g.drawRect(x, y, w - 1, h - 1); + } } /** @@ -102,15 +307,26 @@ public class MetalScrollBarUI */ protected void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds) { + // a disabled scrollbar has no thumb in the metal look and feel + if (!c.isEnabled()) + return; + // first we fill the background g.setColor(thumbColor); g.fillRect(thumbBounds.x, thumbBounds.y, thumbBounds.width, thumbBounds.height); // draw the outer dark line - g.setColor(thumbDarkShadowColor); - g.drawRect(thumbBounds.x, thumbBounds.y, thumbBounds.width - 1, - thumbBounds.height - 1); + int hAdj = 1; + int wAdj = 1; + if (scrollbar.getOrientation() == HORIZONTAL) + hAdj++; + else + wAdj++; + + g.setColor(new Color(102, 102, 153)); + g.drawRect(thumbBounds.x, thumbBounds.y, thumbBounds.width - wAdj, + thumbBounds.height - hAdj); // draw the inner light line g.setColor(thumbHighlightColor); @@ -131,7 +347,7 @@ public class MetalScrollBarUI // draw the pattern MetalUtils.fillMetalPattern(g, thumbBounds.x + 3, thumbBounds.y + 3, thumbBounds.width - 6, thumbBounds.height - 6, - thumbHighlightColor, thumbDarkShadowColor); + thumbHighlightColor, new Color(102, 102, 153)); } /** @@ -143,4 +359,6 @@ public class MetalScrollBarUI { return MIN_THUMB_SIZE; } + } + diff --git a/javax/swing/plaf/metal/MetalScrollButton.java b/javax/swing/plaf/metal/MetalScrollButton.java new file mode 100644 index 000000000..b9f53dc87 --- /dev/null +++ b/javax/swing/plaf/metal/MetalScrollButton.java @@ -0,0 +1,482 @@ +/* MetalScrollButton.java + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package javax.swing.plaf.metal; + +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.Rectangle; + +import javax.swing.SwingUtilities; +import javax.swing.plaf.basic.BasicArrowButton; + +/** + * A button used by the {@link MetalScrollBarUI}. The button appearance + * varies according to the button direction, whether or not it is part of a + * "free standing" scroll bar, and the current state of the button. + */ +public class MetalScrollButton extends BasicArrowButton +{ + + /** + * The maximum size for buttons. + * @see #getMaximumSize() + */ + private static Dimension maximumSize; + + /** The width of the button. */ + private int buttonWidth; + + /** + * A flag that indicates whether the button is part of a free standing + * scroll bar. This affects how the border is drawn. + */ + private boolean freeStanding; + + /** + * Creates a new button. + * + * @param direction the direction (this should be one of {@link #NORTH}, + * {@link #SOUTH}, {@link #EAST} and {@link #WEST}, but + * this is not enforced). + * @param width the button width. + * @param freeStanding a flag indicating whether the scroll button is free + * standing or not. + */ + public MetalScrollButton(int direction, int width, boolean freeStanding) + { + super(direction); + buttonWidth = width; + this.freeStanding = freeStanding; + } + + /** + * Returns the button width. + * + * @return The button width. + */ + public int getButtonWidth() + { + return buttonWidth; + } + + /** + * Sets the free standing flag. This controls how the button border is + * drawn. + * + * @param freeStanding the new value of the flag. + */ + public void setFreeStanding(boolean freeStanding) + { + this.freeStanding = freeStanding; + } + + /** + * Paints the button. + * + * @param g the graphics device. + */ + public void paint(Graphics g) + { + Rectangle bounds = SwingUtilities.getLocalBounds(this); + + // fill the background + if (getModel().isPressed()) + g.setColor(MetalLookAndFeel.getControlShadow()); + else + g.setColor(MetalLookAndFeel.getControl()); + g.fillRect(0, 0, bounds.width, bounds.height); + + paintArrow(g, bounds.width, bounds.height); + + // paint a border manually - I tried using a real (custom) Border + // but couldn't get it to stay set for the button, something was + // overwriting it... + if (freeStanding) + { + if (direction == WEST) + paintWestBorderFreeStanding(g, bounds.width, bounds.height); + else if (direction == EAST) + paintEastBorderFreeStanding(g, bounds.width, bounds.height); + else if (direction == SOUTH) + paintSouthBorderFreeStanding(g, bounds.width, bounds.height); + else // asume NORTH + paintNorthBorderFreeStanding(g, bounds.width, bounds.height); + } + else + { + if (direction == WEST) + paintWestBorder(g, bounds.width, bounds.height); + else if (direction == EAST) + paintEastBorder(g, bounds.width, bounds.height); + else if (direction == SOUTH) + paintSouthBorder(g, bounds.width, bounds.height); + else // asume NORTH + paintNorthBorder(g, bounds.width, bounds.height); + } + } + + private void paintArrow(Graphics g, int w, int h) + { + if (isEnabled()) + g.setColor(MetalLookAndFeel.getBlack()); + else + g.setColor(MetalLookAndFeel.getControlDisabled()); + + if (direction == SOUTH) + { + int x = w / 2; + int y = h / 2 + 2; + for (int i = 1; i < 5; i++) + g.drawLine(x - i, y - i, x + i - 1, y - i); + } + else if (direction == EAST) + { + int x = w / 2 + 2; + int y = h / 2; + for (int i = 1; i < 5; i++) + g.drawLine(x - i, y - i, x - i, y + i - 1); + } + else if (direction == WEST) + { + int x = w / 2 - 3; + int y = h / 2; + for (int i = 1; i < 5; i++) + g.drawLine(x + i, y - i, x + i, y + i - 1); + } + else // assume NORTH + { + int x = w / 2; + int y = h / 2 - 3; + for (int i = 1; i < 5; i++) + g.drawLine(x - i, y + i, x + i - 1, y + i); + } + } + /** + * Paints the border for a button with a {@link #NORTH} direction that + * belongs to a free standing scroll bar. + * + * @param g the graphics device. + * @param w the button width. + * @param h the button height. + */ + private void paintNorthBorderFreeStanding(Graphics g, int w, int h) + { + if (isEnabled()) + { + g.setColor(MetalLookAndFeel.getControlDarkShadow()); + g.drawLine(0, 0, w - 2, 0); + g.drawLine(0, 0, 0, h - 1); + g.drawLine(2, h - 1, w - 2, h - 1); + g.drawLine(w - 2, 2, w - 2, h - 1); + + g.setColor(MetalLookAndFeel.getControlHighlight()); + g.drawLine(1, 1, 1, h - 1); + g.drawLine(1, 1, w - 1, 1); + g.drawLine(w - 1, 1, w - 1, h - 1); + + g.setColor(MetalLookAndFeel.getControl()); + g.drawLine(1, h - 1, 1, h - 1); + g.drawLine(w - 1, 1, w - 1, 1); + } + else + { + g.setColor(MetalLookAndFeel.getControlDisabled()); + g.drawLine(0, 0, w - 1, 0); + g.drawLine(w - 1, 0, w - 1, h - 1); + g.drawLine(0, 0, 0, h - 1); + } + } + + /** + * Paints the border for a button with a {@link #SOUTH} direction that + * belongs to a free standing scroll bar. + * + * @param g the graphics device. + * @param w the button width. + * @param h the button height. + */ + private void paintSouthBorderFreeStanding(Graphics g, int w, int h) + { + if (isEnabled()) + { + g.setColor(MetalLookAndFeel.getControlDarkShadow()); + g.drawLine(0, 0, w - 2, 0); + g.drawLine(0, 0, 0, h - 1); + g.drawLine(2, h - 1, w - 2, h - 1); + g.drawLine(w - 2, 2, w - 2, h - 1); + + g.setColor(MetalLookAndFeel.getControlHighlight()); + g.drawLine(1, 1, 1, h - 1); + g.drawLine(1, 1, w - 1, 1); + g.drawLine(w - 1, 1, w - 1, h - 1); + + g.setColor(MetalLookAndFeel.getControl()); + g.drawLine(1, h - 1, 1, h - 1); + g.drawLine(w - 1, 1, w - 1, 1); + } + else + { + g.setColor(MetalLookAndFeel.getControlDisabled()); + g.drawLine(0, h - 1, w - 1, h - 1); + g.drawLine(w - 1, 0, w - 1, h - 1); + g.drawLine(0, 0, 0, h - 1); + } + } + + /** + * Paints the border for a button with an {@link #EAST} direction that + * belongs to a free standing scroll bar. + * + * @param g the graphics device. + * @param w the button width. + * @param h the button height. + */ + private void paintEastBorderFreeStanding(Graphics g, int w, int h) + { + if (isEnabled()) + { + g.setColor(MetalLookAndFeel.getControlDarkShadow()); + g.drawLine(0, 0, w - 2, 0); + g.drawLine(w - 2, 0, w - 2, h - 2); + g.drawLine(0, h - 2, w - 2, h - 2); + + g.setColor(MetalLookAndFeel.getControlHighlight()); + g.drawLine(0, 1, w - 1, 1); + g.drawLine(w - 1, 1, w - 1, h - 1); + g.drawLine(0, h - 1, w - 1, h - 1); + + g.setColor(MetalLookAndFeel.getControl()); + g.drawLine(w - 2, 1, w - 2, 1); + } + else + { + g.setColor(MetalLookAndFeel.getControlDisabled()); + g.drawLine(0, 0, w - 1, 0); + g.drawLine(w - 1, 0, w - 1, h - 1); + g.drawLine(0, h - 1, w - 1, h - 1); + } + } + + /** + * Paints the border for a button with a {@link #WEST} direction that + * belongs to a free standing scroll bar. + * + * @param g the graphics device. + * @param w the button width. + * @param h the button height. + */ + private void paintWestBorderFreeStanding(Graphics g, int w, int h) + { + if (isEnabled()) + { + g.setColor(MetalLookAndFeel.getControlDarkShadow()); + g.drawLine(0, 0, w - 1, 0); + g.drawLine(0, 0, 0, h - 2); + g.drawLine(0, h - 2, w - 1, h - 2); + + g.setColor(MetalLookAndFeel.getControlHighlight()); + g.drawLine(1, 1, w - 1, 1); + g.drawLine(1, 1, 1, h - 1); + g.drawLine(1, h - 1, w - 1, h - 1); + + g.setColor(MetalLookAndFeel.getControl()); + g.drawLine(1, h - 2, 1, h - 2); + } + else + { + g.setColor(MetalLookAndFeel.getControlDisabled()); + g.drawLine(0, 0, w - 1, 0); + g.drawLine(0, 0, 0, h - 1); + g.drawLine(0, h - 1, w - 1, h - 1); + } + } + + /** + * Paints the border for a button with a {@link #NORTH} direction that + * belongs to a scroll bar that is not free standing. + * + * @param g the graphics device. + * @param w the button width. + * @param h the button height. + */ + private void paintNorthBorder(Graphics g, int w, int h) + { + if (isEnabled()) + { + g.setColor(MetalLookAndFeel.getControlDarkShadow()); + g.drawLine(0, 0, 0, h - 1); + + g.setColor(MetalLookAndFeel.getControlHighlight()); + g.drawLine(1, 0, 1, h - 1); + g.drawLine(1, 0, w - 1, 0); + } + else + { + g.setColor(MetalLookAndFeel.getControlDisabled()); + g.drawLine(0, 0, 0, h - 1); + } + } + + /** + * Paints the border for a button with a {@link #SOUTH} direction that + * belongs to a scroll bar that is not free standing. + * + * @param g the graphics device. + * @param w the button width. + * @param h the button height. + */ + private void paintSouthBorder(Graphics g, int w, int h) + { + if (isEnabled()) + { + g.setColor(MetalLookAndFeel.getControlDarkShadow()); + g.drawLine(0, 0, 0, h - 1); + g.drawLine(0, h - 1, w - 1, h - 1); + + g.setColor(MetalLookAndFeel.getControlHighlight()); + g.drawLine(1, 0, 1, h - 1); + g.drawLine(1, 0, w - 1, 0); + + g.setColor(MetalLookAndFeel.getControl()); + g.drawLine(1, h - 1, 1, h - 1); + } + else + { + g.setColor(MetalLookAndFeel.getControlDisabled()); + g.drawLine(0, 0, 0, h - 1); + } + } + + /** + * Paints the border for a button with an {@link #EAST} direction that + * belongs to a scroll bar that is not free standing. + * + * @param g the graphics device. + * @param w the button width. + * @param h the button height. + */ + private void paintEastBorder(Graphics g, int w, int h) + { + if (isEnabled()) + { + g.setColor(MetalLookAndFeel.getControlDarkShadow()); + g.drawLine(0, 0, w - 1, 0); + g.drawLine(w - 1, 2, w - 1, h - 1); + g.setColor(MetalLookAndFeel.getControlHighlight()); + g.drawLine(0, 1, w - 2, 1); + g.drawLine(0, 1, 0, h - 1); + } + else + { + g.setColor(MetalLookAndFeel.getControlDisabled()); + g.drawLine(0, 0, w - 1, 0); + } + } + + /** + * Paints the border for a button with a {@link #WEST} direction that + * belongs to a scroll bar that is not free standing. + * + * @param g the graphics device. + * @param w the button width. + * @param h the button height. + */ + private void paintWestBorder(Graphics g, int w, int h) + { + Rectangle bounds = SwingUtilities.getLocalBounds(this); + if (isEnabled()) + { + g.setColor(MetalLookAndFeel.getControlDarkShadow()); + g.drawLine(0, 0, bounds.width - 1, 0); + g.setColor(MetalLookAndFeel.getControlHighlight()); + g.drawLine(0, 1, bounds.width - 1, 1); + g.drawLine(0, 1, 0, bounds.height - 1); + } + else + { + g.setColor(MetalLookAndFeel.getControlDisabled()); + g.drawLine(0, 0, bounds.width - 1, 0); + } + } + + /** + * Returns the preferred size for the button, which varies depending on + * the direction of the button and whether or not it is free standing. + * + * @return The preferred size. + */ + public Dimension getPreferredSize() + { + int adj = 1; + if (!freeStanding) + adj = 2; + + if (direction == EAST) + return new Dimension(buttonWidth - adj, buttonWidth); + else if (direction == WEST) + return new Dimension(buttonWidth - 2, buttonWidth); + else if (direction == SOUTH) + return new Dimension(buttonWidth, buttonWidth - adj); + else // assume NORTH + return new Dimension(buttonWidth, buttonWidth - 2); + } + + /** + * Returns the minimum size for the button. + * + * @return The minimum size for the button. + */ + public Dimension getMinimumSize() + { + return getPreferredSize(); + } + + /** + * Returns the maximum size for the button. + * + * @return <code>Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE)</code>. + */ + public Dimension getMaximumSize() + { + if (maximumSize == null) + maximumSize = new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE); + return maximumSize; + } + +} diff --git a/javax/swing/plaf/metal/MetalToggleButtonUI.java b/javax/swing/plaf/metal/MetalToggleButtonUI.java index be6d0c39e..5079562e8 100644 --- a/javax/swing/plaf/metal/MetalToggleButtonUI.java +++ b/javax/swing/plaf/metal/MetalToggleButtonUI.java @@ -39,13 +39,24 @@ exception statement from your version. */ package javax.swing.plaf.metal; import java.awt.Color; +import java.awt.Font; +import java.awt.FontMetrics; +import java.awt.Graphics; +import java.awt.Rectangle; +import javax.swing.AbstractButton; import javax.swing.JComponent; +import javax.swing.JToggleButton; +import javax.swing.SwingUtilities; import javax.swing.UIDefaults; import javax.swing.UIManager; import javax.swing.plaf.ComponentUI; +import javax.swing.plaf.basic.BasicButtonUI; import javax.swing.plaf.basic.BasicToggleButtonUI; +/** + * A UI delegate for {@link JToggleButton} components. + */ public class MetalToggleButtonUI extends BasicToggleButtonUI { @@ -59,8 +70,17 @@ public class MetalToggleButtonUI /** The color for disabled button labels. */ protected Color disabledTextColor; - /** The shared UI instance for MetalToggleButtonUIs */ - private static MetalToggleButtonUI instance = null; + /** + * Returns an instance of MetalToggleButtonUI. + * + * @param component the component for which we return an UI instance + * + * @return an instance of MetalToggleButtonUI + */ + public static ComponentUI createUI(JComponent component) + { + return new MetalToggleButtonUI(); + } /** * Constructs a new instance of MetalToggleButtonUI. @@ -68,12 +88,12 @@ public class MetalToggleButtonUI public MetalToggleButtonUI() { super(); - focusColor = getFocusColor(); - selectColor = getSelectColor(); - disabledTextColor = getDisabledTextColor(); + UIDefaults defaults = UIManager.getLookAndFeelDefaults(); + focusColor = defaults.getColor(getPropertyPrefix() + "focus"); + selectColor = defaults.getColor(getPropertyPrefix() + "select"); + disabledTextColor = defaults.getColor(getPropertyPrefix() + "disabledText"); } - /** * Returns the color for the focus border. * @@ -81,8 +101,7 @@ public class MetalToggleButtonUI */ protected Color getFocusColor() { - UIDefaults def = UIManager.getLookAndFeelDefaults(); - return def.getColor(getPropertyPrefix() + ".focus"); + return focusColor; } /** @@ -92,8 +111,7 @@ public class MetalToggleButtonUI */ protected Color getSelectColor() { - UIDefaults def = UIManager.getLookAndFeelDefaults(); - return def.getColor(getPropertyPrefix() + ".select"); + return selectColor; } /** @@ -103,21 +121,80 @@ public class MetalToggleButtonUI */ protected Color getDisabledTextColor() { - UIDefaults def = UIManager.getLookAndFeelDefaults(); - return def.getColor(getPropertyPrefix() + ".disabledText"); + return disabledTextColor; } /** - * Returns an instance of MetalToggleButtonUI. - * - * @param component the component for which we return an UI instance - * - * @return an instance of MetalToggleButtonUI + * Updates the button with the defaults for this look and feel. + * + * @param b the button. */ - public static ComponentUI createUI(JComponent component) + public void installDefaults(AbstractButton b) + { + // FIXME: for now, this override just changes the visibility of the method + // in the super-class, to satisfy japi...but there must be something else. + super.installDefaults(b); + } + + /** + * Paints the button background when it is pressed/selected. + * + * @param g the graphics device. + * @param b the button. + */ + protected void paintButtonPressed(Graphics g, AbstractButton b) + { + Color saved = g.getColor(); + Rectangle bounds = SwingUtilities.getLocalBounds(b); + g.setColor(selectColor); + g.fillRect(bounds.x, bounds.y, bounds.width, bounds.height); + g.setColor(saved); + } + + /** + * Paints the text for the button. + * + * @param g the graphics device. + * @param c the component. + * @param textRect the bounds for the text. + * @param text the text. + * + * @deprecated 1.4 Use {@link BasicButtonUI#paintText(java.awt.Graphics, + * javax.swing.AbstractButton, java.awt.Rectangle, java.lang.String)}. + */ + protected void paintText(Graphics g, JComponent c, Rectangle textRect, + String text) + { + Font savedFont = g.getFont(); + Color savedColor = g.getColor(); + g.setFont(c.getFont()); + if (c.isEnabled()) + g.setColor(c.getForeground()); + else + g.setColor(disabledTextColor); + FontMetrics fm = g.getFontMetrics(c.getFont()); + int ascent = fm.getAscent(); + g.drawString(text, textRect.x, textRect.y + ascent); + g.setFont(savedFont); + g.setColor(savedColor); + } + + /** + * Draws the focus highlight around the text and icon. + * + * @param g the graphics device. + * @param b the button. + */ + protected void paintFocus(Graphics g, AbstractButton b, Rectangle viewRect, + Rectangle textRect, Rectangle iconRect) { - if (instance == null) - instance = new MetalToggleButtonUI(); - return instance; + if (!b.hasFocus()) + return; + Color saved = g.getColor(); + g.setColor(focusColor); + Rectangle fr = iconRect.union(textRect); + g.drawRect(fr.x - 1, fr.y - 1, fr.width + 1, fr.height + 1); + g.setColor(saved); } + } diff --git a/javax/swing/plaf/metal/MetalTreeUI.java b/javax/swing/plaf/metal/MetalTreeUI.java index 8d16f7463..a5ca3fe11 100644 --- a/javax/swing/plaf/metal/MetalTreeUI.java +++ b/javax/swing/plaf/metal/MetalTreeUI.java @@ -38,9 +38,29 @@ exception statement from your version. */ package javax.swing.plaf.metal; +import java.awt.Graphics; +import java.awt.Insets; +import java.awt.Rectangle; +import java.awt.event.ComponentListener; +import java.awt.event.FocusListener; +import java.awt.event.KeyListener; +import java.beans.PropertyChangeListener; import java.util.HashMap; +import java.util.Hashtable; import javax.swing.JComponent; +import javax.swing.JTree; +import javax.swing.UIDefaults; +import javax.swing.UIManager; +import javax.swing.tree.TreeCellEditor; +import javax.swing.tree.TreeModel; +import javax.swing.tree.TreePath; +import javax.swing.event.CellEditorListener; +import javax.swing.event.MouseInputListener; +import javax.swing.event.TreeExpansionListener; +import javax.swing.event.TreeModelListener; +import javax.swing.event.TreeSelectionListener; + import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicTreeUI; @@ -48,6 +68,18 @@ public class MetalTreeUI extends BasicTreeUI { + /** Listeners */ + private PropertyChangeListener propertyChangeListener; + private FocusListener focusListener; + private TreeSelectionListener treeSelectionListener; + private MouseInputListener mouseInputListener; + private KeyListener keyListener; + private PropertyChangeListener selectionModelPropertyChangeListener; + private ComponentListener componentListener; + private CellEditorListener cellEditorListener; + private TreeExpansionListener treeExpansionListener; + private TreeModelListener treeModelListener; + /** The UI instances for MetalTreeUIs */ private static HashMap instances = null; @@ -83,4 +115,222 @@ public class MetalTreeUI return instance; } + + /** + * The horizontal element of legs between nodes starts at the right of the + * left-hand side of the child node by default. This method makes the + * leg end before that. + */ + protected int getHorizontalLegBuffer() + { + return super.getHorizontalLegBuffer(); + } + + /** + * Configures the specified component appropriate for the look and feel. + * This method is invoked when the ComponentUI instance is being installed + * as the UI delegate on the specified component. This method should completely + * configure the component for the look and feel, including the following: + * 1. Install any default property values for color, fonts, borders, icons, + * opacity, etc. on the component. Whenever possible, property values + * initialized by the client program should not be overridden. + * 2. Install a LayoutManager on the component if necessary. + * 3. Create/add any required sub-components to the component. + * 4. Create/install event listeners on the component. + * 5. Create/install a PropertyChangeListener on the component in order + * to detect and respond to component property changes appropriately. + * 6. Install keyboard UI (mnemonics, traversal, etc.) on the component. + * 7. Initialize any appropriate instance data. + */ + public void installUI(JComponent c) + { + tree = (JTree) c; + configureLayoutCache(); + + UIDefaults defaults = UIManager.getLookAndFeelDefaults(); + tree.setFont(defaults.getFont("Tree.font")); + tree.setForeground(defaults.getColor("Tree.foreground")); + tree.setBackground(defaults.getColor("Tree.background")); + tree.setOpaque(true); + tree.setScrollsOnExpand(defaults.getBoolean("Tree.scrollsOnExpand")); + rightChildIndent = defaults.getInt("Tree.rightChildIndent"); + leftChildIndent = defaults.getInt("Tree.leftChildIndent"); + setRowHeight(defaults.getInt("Tree.rowHeight")); + tree.requestFocusInWindow(false); + + setExpandedIcon(defaults.getIcon("Tree.expandedIcon")); + setCollapsedIcon(defaults.getIcon("Tree.collapsedIcon")); + + currentCellRenderer = createDefaultCellRenderer(); + rendererPane = createCellRendererPane(); + createdRenderer = true; + setCellEditor(createDefaultCellEditor()); + createdCellEditor = true; + TreeModel mod = tree.getModel(); + setModel(mod); + tree.setRootVisible(true); + if (mod != null) + tree.expandPath(new TreePath(mod.getRoot())); + treeSelectionModel = tree.getSelectionModel(); + drawingCache = new Hashtable(); + nodeDimensions = createNodeDimensions(); + + propertyChangeListener = createPropertyChangeListener(); + focusListener = createFocusListener(); + treeSelectionListener = createTreeSelectionListener(); + mouseInputListener = new MouseInputHandler(null, null, null); + keyListener = createKeyListener(); + selectionModelPropertyChangeListener = createSelectionModelPropertyChangeListener(); + componentListener = createComponentListener(); + cellEditorListener = createCellEditorListener(); + treeExpansionListener = createTreeExpansionListener(); + treeModelListener = createTreeModelListener(); + + editingRow = -1; + lastSelectedRow = -1; + + installKeyboardActions(); + + tree.addPropertyChangeListener(propertyChangeListener); + tree.addFocusListener(focusListener); + tree.addTreeSelectionListener(treeSelectionListener); + tree.addMouseListener(mouseInputListener); + tree.addKeyListener(keyListener); + tree.addPropertyChangeListener(selectionModelPropertyChangeListener); + tree.addComponentListener(componentListener); + tree.addTreeExpansionListener(treeExpansionListener); + if (treeModel != null) + treeModel.addTreeModelListener(treeModelListener); + + completeUIInstall(); + } + + /** + * Reverses configuration which was done on the specified component during + * installUI. This method is invoked when this UIComponent instance is being + * removed as the UI delegate for the specified component. This method should + * undo the configuration performed in installUI, being careful to leave the + * JComponent instance in a clean state (no extraneous listeners, + * look-and-feel-specific property objects, etc.). This should include + * the following: + * 1. Remove any UI-set borders from the component. + * 2. Remove any UI-set layout managers on the component. + * 3. Remove any UI-added sub-components from the component. + * 4. Remove any UI-added event/property listeners from the component. + * 5. Remove any UI-installed keyboard UI from the component. + * 6. Nullify any allocated instance data objects to allow for GC. + */ + public void uninstallUI(JComponent c) + { + tree.setFont(null); + tree.setForeground(null); + tree.setBackground(null); + + uninstallKeyboardActions(); + + tree.removePropertyChangeListener(propertyChangeListener); + tree.removeFocusListener(focusListener); + tree.removeTreeSelectionListener(treeSelectionListener); + tree.removeMouseListener(mouseInputListener); + tree.removeKeyListener(keyListener); + tree.removePropertyChangeListener(selectionModelPropertyChangeListener); + tree.removeComponentListener(componentListener); + tree.removeTreeExpansionListener(treeExpansionListener); + + TreeCellEditor tce = tree.getCellEditor(); + if (tce != null) + tce.removeCellEditorListener(cellEditorListener); + TreeModel tm = tree.getModel(); + if (tm != null) + tm.removeTreeModelListener(treeModelListener); + + tree = null; + uninstallComponents(); + completeUIUninstall(); + } + + /** + * This function converts between the string passed into the client + * property and the internal representation (currently an int). + * + * @param lineStyleFlag - String representation + */ + protected void decodeLineStyle(Object lineStyleFlag) + { + // FIXME: not implemented + } + + /** + * Checks if the location is in expand control. + * + * @param row - current row + * @param rowLevel - current level + * @param mouseX - current x location of the mouse click + * @param mouseY - current y location of the mouse click + */ + protected boolean isLocationInExpandControl(int row, int rowLevel, + int mouseX, int mouseY) + { + return super.isLocationInExpandControl(tree.getPathForRow(row), + mouseX, mouseY); + } + + /** + * Paints the specified component appropriate for the look and feel. + * This method is invoked from the ComponentUI.update method when the + * specified component is being painted. Subclasses should override this + * method and use the specified Graphics object to render the content of + * the component. + * + * @param g - the current graphics configuration. + * @param c - the current component to draw + */ + public void paint(Graphics g, JComponent c) + { + // Calls BasicTreeUI's paint since it takes care of painting all + // types of icons. + super.paint(g, c); + } + + /** + * Paints the horizontal separators. + * + * @param g - the current graphics configuration. + * @param c - the current component to draw + */ + protected void paintHorizontalSeparators(Graphics g, JComponent c) + { + // FIXME: not implemented + } + + + /** + * Paints the vertical part of the leg. The receiver should NOT modify + * clipBounds, insets. + * + * @param g - the current graphics configuration. + * @param clipBounds - + * @param insets - + * @param path - the current path + */ + protected void paintVerticalPartOfLeg(Graphics g, Rectangle clipBounds, + Insets insets, TreePath path) + { + super.paintVerticalPartOfLeg(g, clipBounds, insets, path); + } + + /** + * Paints the horizontal part of the leg. The receiver should NOT \ + * modify clipBounds, or insets. + * NOTE: parentRow can be -1 if the root is not visible. + */ + protected void paintHorizontalPartOfLeg(Graphics g, Rectangle clipBounds, + Insets insets, Rectangle bounds, + TreePath path, int row, + boolean isExpanded, boolean hasBeenExpanded, + boolean isLeaf) + { + super.paintHorizontalPartOfLeg(g, clipBounds, insets, bounds, path, row, + isExpanded, hasBeenExpanded, isLeaf); + } } diff --git a/javax/swing/plaf/metal/MetalUtils.java b/javax/swing/plaf/metal/MetalUtils.java index a342ee02b..6480365f8 100644 --- a/javax/swing/plaf/metal/MetalUtils.java +++ b/javax/swing/plaf/metal/MetalUtils.java @@ -1,4 +1,4 @@ -/* Metaltils.java +/* MetalUtils.java Copyright (C) 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -57,7 +57,7 @@ class MetalUtils * @param y the Y coordinate of the upper left corner of the rectangle to * fill * @param w the width of the rectangle to fill - * @param w the height of the rectangle to fill + * @param h the height of the rectangle to fill * @param light the light color to use * @param dark the dark color to use */ @@ -68,7 +68,7 @@ class MetalUtils for (int mY = y; mY < (y + h); mY++) { // set color alternating with every line - if ((mY % 2) == 0) + if (((mY - y) % 2) == 0) g.setColor(light); else g.setColor(dark); diff --git a/javax/swing/plaf/metal/OceanTheme.java b/javax/swing/plaf/metal/OceanTheme.java new file mode 100644 index 000000000..3a837cb5a --- /dev/null +++ b/javax/swing/plaf/metal/OceanTheme.java @@ -0,0 +1,198 @@ +/* DefaultMetalTheme.java -- A modern theme for the Metal L&F + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.swing.plaf.metal; + +import javax.swing.plaf.ColorUIResource; + +/** + * A modern theme for the Metal Look & Feel. + * @since 1.5 + * + * @author Roman Kennke (roman@kennke.org) + */ +public class OceanTheme extends DefaultMetalTheme +{ + /** + * The OceanTheme value for black. + */ + static final ColorUIResource BLACK = new ColorUIResource(51, 51, 51); + + /** + * The OceanTheme value for primary1. + */ + static final ColorUIResource PRIMARY1 = new ColorUIResource(99, 130, 191); + + /** + * The OceanTheme value for primary1. + */ + static final ColorUIResource PRIMARY2 = new ColorUIResource(163, 184, 204); + + /** + * The OceanTheme value for primary1. + */ + static final ColorUIResource PRIMARY3 = new ColorUIResource(184, 207, 229); + + /** + * The OceanTheme value for secondary1. + */ + static final ColorUIResource SECONDARY1 = new ColorUIResource(122, 138, 153); + + /** + * The OceanTheme value for secondary2. + */ + static final ColorUIResource SECONDARY2 = new ColorUIResource(184, 207, 229); + + /** + * The OceanTheme value for secondary3. + */ + static final ColorUIResource SECONDARY3 = new ColorUIResource(238, 238, 238); + + /** + * The OceanTheme value for inactive control text. + */ + static final ColorUIResource INACTIVE_CONTROL_TEXT = + new ColorUIResource(153, 153, 153); + + /** + * Returns the name of this theme, "Ocean" + */ + public String getName() + { + return "Ocean"; + } + + /** + * Returns the color for control text, which is the + * value of the theme's black value. + */ + public ColorUIResource getControlTextColor() + { + return getBlack(); + } + + /** + * Returns the desktop color, which is the theme's white color. + */ + public ColorUIResource getDesktopColor() + { + return getWhite(); + } + + /** + * Returns the color for inactive control text, which is the + * RGB value (153, 153, 153). + */ + public ColorUIResource getInactiveControlTextColor() + { + return INACTIVE_CONTROL_TEXT; + } + + /** + * Returns the OceanTheme's color for disabled menu foreground, + * + */ + public ColorUIResource getMenuDisabledForeground() + { + return INACTIVE_CONTROL_TEXT; + } + + + /** + * Returns the OceanTheme's color for black, the RGB value + * (51, 51, 51). + * + * @return Returns the OceanTheme's value for black + */ + protected ColorUIResource getBlack() + { + return BLACK; + } + + /** + * Return the OceanTheme's value for primary 1, the RGB value + * (99, 130, 191). + */ + protected ColorUIResource getPrimary1() + { + return PRIMARY1; + } + + /** + * Return the OceanTheme's value for primary 2, the RGB value + * (163, 184, 204). + */ + protected ColorUIResource getPrimary2() + { + return PRIMARY2; + } + + /** + * Return the OceanTheme's value for primary 1, the RGB value + * (184, 207, 229). + */ + protected ColorUIResource getPrimary3() + { + return PRIMARY3; + } + + /** + * Return the OceanTheme's value for secondary 1, the RGB value + * (122, 138, 153). + */ + protected ColorUIResource getSecondary1() + { + return SECONDARY1; + } + + /** + * Return the OceanTheme's value for secondary 2, the RGB value + * (184, 207, 229). + */ + protected ColorUIResource getSecondary2() + { + return SECONDARY2; + } + /** + * Return the OceanTheme's value for secondary 3, the RGB value + * (238, 238, 238). + */ + protected ColorUIResource getSecondary3() + { + return SECONDARY3; + } +} diff --git a/javax/swing/table/TableColumn.java b/javax/swing/table/TableColumn.java index 9c36bb05a..9f06c5b7f 100644 --- a/javax/swing/table/TableColumn.java +++ b/javax/swing/table/TableColumn.java @@ -402,7 +402,11 @@ public class TableColumn if (width == oldWidth) return; - firePropertyChange(COLUMN_WIDTH_PROPERTY, oldWidth, width); + // We do have a constant field COLUMN_WIDTH_PROPERTY, + // however, tests show that the actual fired property name is 'width' + // and even Sun's API docs say that this constant field is obsolete and + // not used. + firePropertyChange("width", oldWidth, width); } /** @@ -422,12 +426,16 @@ public class TableColumn */ public void setPreferredWidth(int preferredWidth) { + int oldPrefWidth = this.preferredWidth; + if (preferredWidth < minWidth) this.preferredWidth = minWidth; else if (preferredWidth > maxWidth) this.preferredWidth = maxWidth; else this.preferredWidth = preferredWidth; + + firePropertyChange("preferredWidth", oldPrefWidth, this.preferredWidth); } /** diff --git a/javax/swing/text/AbstractDocument.java b/javax/swing/text/AbstractDocument.java index 3c9a4d497..660cd2b09 100644 --- a/javax/swing/text/AbstractDocument.java +++ b/javax/swing/text/AbstractDocument.java @@ -65,11 +65,10 @@ import javax.swing.undo.UndoableEdit; * @author original author unknown * @author Roman Kennke (roman@kennke.org) */ -public abstract class AbstractDocument - implements Document, Serializable +public abstract class AbstractDocument implements Document, Serializable { - /** The serial version UID for this class as of JDK1.4. */ - private static final long serialVersionUID = -116069779446114664L; + /** The serialization UID (compatible with JDK1.5). */ + private static final long serialVersionUID = 6842927725919637215L; /** * Standard error message to indicate a bad location. @@ -332,7 +331,7 @@ public abstract class AbstractDocument * @see GapContent * @see StringContent */ - protected Content getContent() + protected final Content getContent() { return content; } @@ -970,8 +969,8 @@ public abstract class AbstractDocument public abstract class AbstractElement implements Element, MutableAttributeSet, TreeNode, Serializable { - /** The serial version UID for AbstractElement. */ - private static final long serialVersionUID = 1265312733007397733L; + /** The serialization UID (compatible with JDK1.5). */ + private static final long serialVersionUID = 1712240033321461704L; /** The number of characters that this Element spans. */ int count; @@ -1355,49 +1354,6 @@ public abstract class AbstractDocument public abstract int getStartOffset(); /** - * Prints diagnostic information to the specified stream. - * - * @param stream the stream to dump to - * @param indent the indentation level - * @param element the element to be dumped - */ - private void dumpElement(PrintStream stream, String indent, - Element element) - { - // FIXME: Should the method be removed? - System.out.println(indent + "<" + element.getName() +">"); - - if (element.isLeaf()) - { - int start = element.getStartOffset(); - int end = element.getEndOffset(); - String text = ""; - try - { - text = getContent().getString(start, end - start); - } - catch (BadLocationException e) - { - AssertionError error = - new AssertionError("BadLocationException should not be " - + "thrown here. start = " + start - + ", end = " + end); - error.initCause(e); - throw error; - } - System.out.println(indent + " [" - + start + "," - + end + "][" - + text + "]"); - } - else - { - for (int i = 0; i < element.getElementCount(); ++i) - dumpElement(stream, indent + " ", element.getElement(i)); - } - } - - /** * Prints diagnostic output to the specified stream. * * @param stream the stream to write to @@ -1405,10 +1361,65 @@ public abstract class AbstractDocument */ public void dump(PrintStream stream, int indent) { - String indentStr = ""; + StringBuffer b = new StringBuffer(); for (int i = 0; i < indent; ++i) - indentStr += " "; - dumpElement(stream, indentStr, this); + b.append(' '); + b.append('<'); + b.append(getName()); + // Dump attributes if there are any. + if (getAttributeCount() > 0) + { + b.append('\n'); + Enumeration attNames = getAttributeNames(); + while (attNames.hasMoreElements()) + { + for (int i = 0; i < indent + 2; ++i) + b.append(' '); + Object attName = attNames.nextElement(); + b.append(attName); + b.append('='); + Object attribute = getAttribute(attName); + b.append(attribute); + b.append('\n'); + } + } + b.append(">\n"); + + // Dump element content for leaf elements. + if (isLeaf()) + { + for (int i = 0; i < indent + 2; ++i) + b.append(' '); + int start = getStartOffset(); + int end = getEndOffset(); + b.append('['); + b.append(start); + b.append(','); + b.append(end); + b.append("]["); + try + { + b.append(getDocument().getText(start, end - start)); + } + catch (BadLocationException ex) + { + AssertionError err = new AssertionError("BadLocationException " + + "must not be thrown " + + "here."); + err.initCause(ex); + } + b.append("]\n"); + } + stream.print(b.toString()); + + // Dump child elements if any. + int count = getElementCount(); + for (int i = 0; i < count; ++i) + { + Element el = getElement(i); + if (el instanceof AbstractElement) + ((AbstractElement) el).dump(stream, indent + 2); + } } } @@ -1418,8 +1429,8 @@ public abstract class AbstractDocument */ public class BranchElement extends AbstractElement { - /** The serial version UID for BranchElement. */ - private static final long serialVersionUID = -8595176318868717313L; + /** The serialization UID (compatible with JDK1.5). */ + private static final long serialVersionUID = -6037216547466333183L; /** The child elements of this BranchElement. */ private Element[] children = new Element[0]; @@ -1642,8 +1653,8 @@ public abstract class AbstractDocument public class DefaultDocumentEvent extends CompoundEdit implements DocumentEvent { - /** The serial version UID of DefaultDocumentEvent. */ - private static final long serialVersionUID = -7406103236022413522L; + /** The serialization UID (compatible with JDK1.5). */ + private static final long serialVersionUID = 5230037221564563284L; /** The starting offset of the change. */ private int offset; @@ -1843,8 +1854,8 @@ public abstract class AbstractDocument */ public class LeafElement extends AbstractElement { - /** The serial version UID of LeafElement. */ - private static final long serialVersionUID = 5115368706941283802L; + /** The serialization UID (compatible with JDK1.5). */ + private static final long serialVersionUID = -8906306331347768017L; /** Manages the start offset of this element. */ Position startPos; diff --git a/javax/swing/text/BoxView.java b/javax/swing/text/BoxView.java index 0f8ba1ce1..bc08626bd 100644 --- a/javax/swing/text/BoxView.java +++ b/javax/swing/text/BoxView.java @@ -221,7 +221,6 @@ public class BoxView protected void paintChild(Graphics g, Rectangle alloc, int index) { View child = getView(index); - childAllocation(index, alloc); child.paint(g, alloc); } @@ -306,12 +305,8 @@ public class BoxView int count = getViewCount(); for (int i = 0; i < count; ++i) { - // TODO: Figure out if the parameter to paintChild is meant to - // be the child allocation or the allocation of this BoxView. - // I assume the second option here. - // We pass this method a copy of the inside rectangle here because - // it modifies the actual values. copy.setBounds(inside); + childAllocation(i, copy); paintChild(g, copy, i); } } diff --git a/javax/swing/text/ComponentView.java b/javax/swing/text/ComponentView.java index f6feda215..e280e7c0c 100644 --- a/javax/swing/text/ComponentView.java +++ b/javax/swing/text/ComponentView.java @@ -1,5 +1,5 @@ /* ComponentView.java -- - Copyright (C) 2002, 2004 Free Software Foundation, Inc. + Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -41,32 +41,82 @@ import java.awt.Component; import java.awt.Graphics; import java.awt.Shape; +/** + * A {@link View} implementation that is able to render arbitrary + * {@link Components}. This uses the attribute + * {@link StyleConstants#ComponentAttribute} to determine the + * <code>Component</code> that should be rendered. This <code>Component</code> + * becomes a direct child of the <code>JTextComponent</code> that contains + * this <code>ComponentView</code>, so this view must not be shared between + * multiple <code>JTextComponent</code>s. + * + * @author original author unknown + * @author Roman Kennke (roman@kennke.org) + */ public class ComponentView extends View { - public ComponentView(Element elem) - { - super(elem); - } - - protected Component createComponent() - { - return null; - } - - public float getAlignment(int axis) - { - return 0; - } + /** + * Creates a new instance of <code>ComponentView</code> for the specified + * <code>Element</code>. + * + * @param elem the element that this <code>View</code> is rendering + */ + public ComponentView(Element elem) + { + super(elem); + } - public final Component getComponent() - { - return null; - } - - public float getMaximumSpan(int axis) - { - return 0; - } + /** + * Creates the <code>Component</code> that this <code>View</code> is + * rendering. The <code>Component</code> is determined using + * the {@link StyleConstants#ComponentAttribute} of the associated + * <code>Element</code>. + * + * @return the component that is rendered + */ + protected Component createComponent() + { + return StyleConstants.getComponent(getElement().getAttributes()); + } + + /** + * Returns the alignment of this <code>View</code> along the specified axis. + * + * @param axis either {@link View#X_AXIS} or {@link View#Y_AXIS} + * + * @return the alignment of this <code>View</code> along the specified axis + */ + public float getAlignment(int axis) + { + return 0; + } + + /** + * Returns the <code>Component</code> that is rendered by this + * <code>ComponentView</code>. + * + * @return the <code>Component</code> that is rendered by this + * <code>ComponentView</code> + */ + public final Component getComponent() + { + return null; + } + + /** + * Returns the maximum span of this <code>View</code> along the specified + * axis. + * + * This will return {@link Component#getMaximumSize()} for the specified + * axis. + * + * @return the maximum span of this <code>View</code> along the specified + * axis + */ + public float getMaximumSpan(int axis) + { + return 0; + } public float getMinimumSpan(int axis) { diff --git a/javax/swing/text/CompositeView.java b/javax/swing/text/CompositeView.java index 6776c9572..b3dd6123e 100644 --- a/javax/swing/text/CompositeView.java +++ b/javax/swing/text/CompositeView.java @@ -314,6 +314,7 @@ public abstract class CompositeView */ public int getNextVisualPositionFrom(int pos, Position.Bias b, Shape a, int direction, Position.Bias[] biasRet) + throws BadLocationException { int retVal = -1; switch (direction) @@ -594,6 +595,7 @@ public abstract class CompositeView protected int getNextNorthSouthVisualPositionFrom(int pos, Position.Bias b, Shape a, int direction, Position.Bias[] biasRet) + throws BadLocationException { // FIXME: Implement this correctly. return pos; @@ -627,6 +629,7 @@ public abstract class CompositeView protected int getNextEastWestVisualPositionFrom(int pos, Position.Bias b, Shape a, int direction, Position.Bias[] biasRet) + throws BadLocationException { // FIXME: Implement this correctly. return pos; diff --git a/javax/swing/text/DefaultCaret.java b/javax/swing/text/DefaultCaret.java index 33c3ae3bf..c247afcff 100644 --- a/javax/swing/text/DefaultCaret.java +++ b/javax/swing/text/DefaultCaret.java @@ -60,10 +60,8 @@ import javax.swing.event.EventListenerList; public class DefaultCaret extends Rectangle implements Caret, FocusListener, MouseListener, MouseMotionListener { - /** - * The serial version UID for DefaultCaret. - */ - private static final long serialVersionUID = 228155774675466193L; + /** The serialization UID (compatible with JDK1.5). */ + private static final long serialVersionUID = 4325555698756477346L; /** * The <code>ChangeEvent</code> that is fired by {@link #fireStateChanged()}. diff --git a/javax/swing/text/DefaultEditorKit.java b/javax/swing/text/DefaultEditorKit.java index a14f3ff4f..2f901947f 100644 --- a/javax/swing/text/DefaultEditorKit.java +++ b/javax/swing/text/DefaultEditorKit.java @@ -66,8 +66,7 @@ public class DefaultEditorKit extends EditorKit * * @see Toolkit#beep() */ - public static class BeepAction - extends TextAction + public static class BeepAction extends TextAction { /** * Creates a new <code>BeepAction</code>. @@ -95,8 +94,7 @@ public class DefaultEditorKit extends EditorKit * @see CutAction * @see PasteAction */ - public static class CopyAction - extends TextAction + public static class CopyAction extends TextAction { /** @@ -128,8 +126,7 @@ public class DefaultEditorKit extends EditorKit * @see CopyAction * @see PasteAction */ - public static class CutAction - extends TextAction + public static class CutAction extends TextAction { /** @@ -159,8 +156,7 @@ public class DefaultEditorKit extends EditorKit * @see CopyAction * @see CutAction */ - public static class PasteAction - extends TextAction + public static class PasteAction extends TextAction { /** @@ -243,8 +239,7 @@ public class DefaultEditorKit extends EditorKit * of the text component. This is typically triggered by hitting * ENTER on the keyboard. */ - public static class InsertBreakAction - extends TextAction + public static class InsertBreakAction extends TextAction { /** @@ -273,8 +268,7 @@ public class DefaultEditorKit extends EditorKit */ // FIXME: Figure out what this Action is supposed to do. Obviously text // that is entered by the user is inserted through DefaultKeyTypedAction. - public static class InsertContentAction - extends TextAction + public static class InsertContentAction extends TextAction { /** @@ -298,8 +292,7 @@ public class DefaultEditorKit extends EditorKit /** * Inserts a TAB character into the text editor. */ - public static class InsertTabAction - extends TextAction + public static class InsertTabAction extends TextAction { /** diff --git a/javax/swing/text/DefaultFormatter.java b/javax/swing/text/DefaultFormatter.java index c97d90703..16d40c24b 100644 --- a/javax/swing/text/DefaultFormatter.java +++ b/javax/swing/text/DefaultFormatter.java @@ -57,8 +57,7 @@ import javax.swing.JFormattedTextField; * * @author Roman Kennke (roman@kennke.org) */ -public class DefaultFormatter - extends JFormattedTextField.AbstractFormatter +public class DefaultFormatter extends JFormattedTextField.AbstractFormatter implements Cloneable, Serializable { @@ -156,9 +155,6 @@ public class DefaultFormatter * Checks if the value in the input field is valid. If the * property allowsInvalid is set to <code>false</code>, then * the string in the input field is not allowed to be entered. - * - * @param doc the document of the input field - * @param value the current (old) value of the input field */ private void checkValidInput() { @@ -186,8 +182,8 @@ public class DefaultFormatter } } - /** The serialVersoinUID. */ - private static final long serialVersionUID = -7369196326612908900L; + /** The serialization UID (compatible with JDK1.5). */ + private static final long serialVersionUID = -355018354457785329L; /** * Indicates if the value should be committed after every diff --git a/javax/swing/text/DefaultStyledDocument.java b/javax/swing/text/DefaultStyledDocument.java index 3545e52c4..765477507 100644 --- a/javax/swing/text/DefaultStyledDocument.java +++ b/javax/swing/text/DefaultStyledDocument.java @@ -1,5 +1,5 @@ /* DefaultStyledDocument.java -- - Copyright (C) 2004 Free Software Foundation, Inc. + Copyright (C) 2004, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -41,6 +41,7 @@ package javax.swing.text; import java.awt.Color; import java.awt.Font; import java.io.Serializable; +import java.util.Vector; import javax.swing.event.DocumentEvent; @@ -60,12 +61,278 @@ public class DefaultStyledDocument extends AbstractDocument implements StyledDocument { /** + * Carries specification information for new {@link Element}s that should + * be created in {@link ElementBuffer}. This allows the parsing process + * to be decoupled from the <code>Element</code> creation process. + */ + public static class ElementSpec + { + /** + * This indicates a start tag. This is a possible value for + * {@link #getType}. + */ + public static final short StartTagType = 1; + + /** + * This indicates an end tag. This is a possible value for + * {@link #getType}. + */ + public static final short EndTagType = 2; + + /** + * This indicates a content element. This is a possible value for + * {@link #getType}. + */ + public static final short ContentType = 3; + + /** + * This indicates that the data associated with this spec should be joined + * with what precedes it. This is a possible value for + * {@link #getDirection}. + */ + public static final short JoinPreviousDirection = 4; + + /** + * This indicates that the data associated with this spec should be joined + * with what follows it. This is a possible value for + * {@link #getDirection}. + */ + public static final short JoinNextDirection = 5; + + /** + * This indicates that the data associated with this spec should be used + * to create a new element. This is a possible value for + * {@link #getDirection}. + */ + public static final short OriginateDirection = 6; + + /** + * This indicates that the data associated with this spec should be joined + * to the fractured element. This is a possible value for + * {@link #getDirection}. + */ + public static final short JoinFractureDirection = 7; + + /** + * The type of the tag. + */ + short type; + + /** + * The direction of the tag. + */ + short direction; + + /** + * The offset of the content. + */ + int offset; + + /** + * The length of the content. + */ + int length; + + /** + * The actual content. + */ + char[] content; + + /** + * The attributes for the tag. + */ + AttributeSet attributes; + + /** + * Creates a new <code>ElementSpec</code> with no content, length or + * offset. This is most useful for start and end tags. + * + * @param a the attributes for the element to be created + * @param type the type of the tag + */ + public ElementSpec(AttributeSet a, short type) + { + this(a, type, 0); + } + + /** + * Creates a new <code>ElementSpec</code> that specifies the length but + * not the offset of an element. Such <code>ElementSpec</code>s are + * processed sequentially from a known starting point. + * + * @param a the attributes for the element to be created + * @param type the type of the tag + * @param len the length of the element + */ + public ElementSpec(AttributeSet a, short type, int len) + { + this(a, type, null, 0, len); + } + + /** + * Creates a new <code>ElementSpec</code> with document content. + * + * @param a the attributes for the element to be created + * @param type the type of the tag + * @param txt the actual content + * @param offs the offset into the <code>txt</code> array + * @param len the length of the element + */ + public ElementSpec(AttributeSet a, short type, char[] txt, int offs, + int len) + { + attributes = a; + this.type = type; + offset = offs; + length = len; + content = txt; + direction = OriginateDirection; + } + + /** + * Sets the type of the element. + * + * @param type the type of the element to be set + */ + public void setType(short type) + { + this.type = type; + } + + /** + * Returns the type of the element. + * + * @return the type of the element + */ + public short getType() + { + return type; + } + + /** + * Sets the direction of the element. + * + * @param dir the direction of the element to be set + */ + public void setDirection(short dir) + { + direction = dir; + } + + /** + * Returns the direction of the element. + * + * @return the direction of the element + */ + public short getDirection() + { + return direction; + } + + /** + * Returns the attributes of the element. + * + * @return the attributes of the element + */ + public AttributeSet getAttributes() + { + return attributes; + } + + /** + * Returns the actual content of the element. + * + * @return the actual content of the element + */ + public char[] getArray() + { + return content; + } + + /** + * Returns the offset of the content. + * + * @return the offset of the content + */ + public int getOffset() + { + return offset; + } + + /** + * Returns the length of the content. + * + * @return the length of the content + */ + public int getLength() + { + return length; + } + + /** + * Returns a String representation of this <code>ElementSpec</code> + * describing the type, direction and length of this + * <code>ElementSpec</code>. + * + * @return a String representation of this <code>ElementSpec</code> + */ + public String toString() + { + StringBuilder b = new StringBuilder(); + b.append('<'); + switch (type) + { + case StartTagType: + b.append("StartTag"); + break; + case EndTagType: + b.append("EndTag"); + break; + case ContentType: + b.append("Content"); + break; + default: + b.append("??"); + break; + } + + b.append(':'); + + switch (direction) + { + case JoinPreviousDirection: + b.append("JoinPrevious"); + break; + case JoinNextDirection: + b.append("JoinNext"); + break; + case OriginateDirection: + b.append("Originate"); + break; + case JoinFractureDirection: + b.append("Fracture"); + break; + default: + b.append("??"); + break; + } + + b.append(':'); + b.append(length); + + return b.toString(); + } + } + + /** * Performs all <em>structural</code> changes to the <code>Element</code> * hierarchy. */ - public class ElementBuffer - implements Serializable + public class ElementBuffer implements Serializable { + /** The serialization UID (compatible with JDK1.5). */ + private static final long serialVersionUID = 1688745877691146623L; + /** The root element of the hierarchy. */ private Element root; @@ -76,6 +343,19 @@ public class DefaultStyledDocument extends AbstractDocument private int length; /** + * Holds fractured elements during insertion of end and start tags. + * Inserting an end tag may lead to fracturing of the current paragraph + * element. The elements that have been cut off may be added to the + * next paragraph that is created in the next start tag. + */ + Element[] fracture; + + /** + * The ElementChange that describes the latest changes. + */ + DefaultDocumentEvent documentEvent; + + /** * Creates a new <code>ElementBuffer</code> for the specified * <code>root</code> element. * @@ -114,6 +394,7 @@ public class DefaultStyledDocument extends AbstractDocument { this.offset = offset; this.length = length; + documentEvent = ev; changeUpdate(); } @@ -158,7 +439,11 @@ public class DefaultStyledDocument extends AbstractDocument Element child2 = createLeafElement(par, ael, offset, endOffset); int index = par.getElementIndex(startOffset); - par.replace(index, 1, new Element[]{ child1, child2 }); + Element[] add = new Element[]{ child1, child2 }; + par.replace(index, 1, add); + documentEvent.addEdit(new ElementEdit(par, index, + new Element[]{ el }, + add)); } else throw new AssertionError("paragraph elements are expected to " @@ -171,8 +456,267 @@ public class DefaultStyledDocument extends AbstractDocument + "instances of " + "javax.swing.text.AbstractDocument.AbstractElement"); } + + /** + * Inserts new <code>Element</code> in the document at the specified + * position. + * + * Most of the work is done by {@link #insertUpdate}, after some fields + * have been prepared for it. + * + * @param offset the location in the document at which the content is + * inserted + * @param length the length of the inserted content + * @param data the element specifications for the content to be inserted + * @param ev the document event that is updated to reflect the structural + * changes + */ + public void insert(int offset, int length, ElementSpec[] data, + DefaultDocumentEvent ev) + { + this.offset = offset; + this.length = length; + documentEvent = ev; + insertUpdate(data); + } + + /** + * Performs the actual structural change for {@link #insert}. This + * creates a bunch of {@link Element}s as specified by <code>data</code> + * and inserts it into the document as specified in the arguments to + * {@link #insert}. + * + * @param data the element specifications for the elements to be inserte + */ + protected void insertUpdate(ElementSpec[] data) + { + for (int i = 0; i < data.length; i++) + { + switch (data[i].getType()) + { + case ElementSpec.StartTagType: + insertStartTag(data[i]); + break; + case ElementSpec.EndTagType: + insertEndTag(data[i]); + break; + default: + insertContentTag(data[i]); + break; + } + } + } + + /** + * Insert a new paragraph after the paragraph at the current position. + * + * @param tag the element spec that describes the element to be inserted + */ + void insertStartTag(ElementSpec tag) + { + BranchElement root = (BranchElement) getDefaultRootElement(); + int index = root.getElementIndex(offset); + if (index == -1) + index = 0; + + BranchElement newParagraph = + (BranchElement) createBranchElement(root, tag.getAttributes()); + newParagraph.setResolveParent(getStyle(StyleContext.DEFAULT_STYLE)); + + // Add new paragraph into document structure. + Element[] added = new Element[]{newParagraph}; + root.replace(index + 1, 0, added); + ElementEdit edit = new ElementEdit(root, index + 1, new Element[0], + added); + documentEvent.addEdit(edit); + + // Maybe add fractured elements. + if (tag.getDirection() == ElementSpec.JoinFractureDirection) + { + Element[] newFracture = new Element[fracture.length]; + for (int i = 0; i < fracture.length; i++) + { + Element oldLeaf = fracture[i]; + Element newLeaf = createLeafElement(newParagraph, + oldLeaf.getAttributes(), + oldLeaf.getStartOffset(), + oldLeaf.getEndOffset()); + newFracture[i] = newLeaf; + } + newParagraph.replace(0, 0, newFracture); + edit = new ElementEdit(newParagraph, 0, new Element[0], + fracture); + documentEvent.addEdit(edit); + fracture = new Element[0]; + } + } + + /** + * Inserts an end tag into the document structure. This cuts of the + * current paragraph element, possibly fracturing it's child elements. + * The fractured elements are saved so that they can be joined later + * with a new paragraph element. + */ + void insertEndTag(ElementSpec tag) + { + BranchElement root = (BranchElement) getDefaultRootElement(); + int parIndex = root.getElementIndex(offset); + BranchElement paragraph = (BranchElement) root.getElement(parIndex); + + int index = paragraph.getElementIndex(offset); + LeafElement content = (LeafElement) paragraph.getElement(index); + // We might have to split the element at offset. + split(content, offset); + index = paragraph.getElementIndex(offset); + + int count = paragraph.getElementCount(); + // Store fractured elements. + fracture = new Element[count - index]; + for (int i = index; i < count; ++i) + fracture[i - index] = paragraph.getElement(i); + + // Delete fractured elements. + paragraph.replace(index, count - index, new Element[0]); + + // Add this action to the document event. + ElementEdit edit = new ElementEdit(paragraph, index, fracture, + new Element[0]); + documentEvent.addEdit(edit); + } + + /** + * Inserts a content element into the document structure. + * + * @param tag the element spec + */ + void insertContentTag(ElementSpec tag) + { + int len = tag.getLength(); + int dir = tag.getDirection(); + if (dir == ElementSpec.JoinPreviousDirection) + { + Element prev = getCharacterElement(offset); + BranchElement prevParent = (BranchElement) prev.getParentElement(); + Element join = createLeafElement(prevParent, tag.getAttributes(), + prev.getStartOffset(), + Math.max(prev.getEndOffset(), + offset + len)); + int ind = prevParent.getElementIndex(offset); + if (ind == -1) + ind = 0; + Element[] add = new Element[]{join}; + prevParent.replace(ind, 1, add); + + // Add this action to the document event. + ElementEdit edit = new ElementEdit(prevParent, ind, + new Element[]{prev}, add); + documentEvent.addEdit(edit); + } + else if (dir == ElementSpec.JoinNextDirection) + { + Element next = getCharacterElement(offset + len); + BranchElement nextParent = (BranchElement) next.getParentElement(); + Element join = createLeafElement(nextParent, tag.getAttributes(), + offset, + next.getEndOffset()); + int ind = nextParent.getElementIndex(offset + len); + if (ind == -1) + ind = 0; + Element[] add = new Element[]{join}; + nextParent.replace(ind, 1, add); + + // Add this action to the document event. + ElementEdit edit = new ElementEdit(nextParent, ind, + new Element[]{next}, add); + documentEvent.addEdit(edit); + } + else + { + BranchElement par = (BranchElement) getParagraphElement(offset); + + int ind = par.getElementIndex(offset); + + // Make room for the element. + // Cut previous element. + Element prev = par.getElement(ind); + if (prev != null && prev.getStartOffset() < offset) + { + Element cutPrev = createLeafElement(par, prev.getAttributes(), + prev.getStartOffset(), + offset); + Element[] remove = new Element[]{prev}; + Element[] add = new Element[]{cutPrev}; + if (prev.getEndOffset() > offset + len) + { + Element rem = createLeafElement(par, prev.getAttributes(), + offset + len, + prev.getEndOffset()); + add = new Element[]{cutPrev, rem}; + } + + par.replace(ind, 1, add); + documentEvent.addEdit(new ElementEdit(par, ind, remove, add)); + ind++; + } + // ind now points to the next element. + + // Cut next element if necessary. + Element next = par.getElement(ind); + if (next != null && next.getStartOffset() < offset + len) + { + Element cutNext = createLeafElement(par, next.getAttributes(), + offset + len, + next.getEndOffset()); + Element[] remove = new Element[]{next}; + Element[] add = new Element[]{cutNext}; + par.replace(ind, 1, add); + documentEvent.addEdit(new ElementEdit(par, ind, remove, + add)); + } + + // Insert new element. + Element newEl = createLeafElement(par, tag.getAttributes(), + offset, offset + len); + Element[] added = new Element[]{newEl}; + par.replace(ind, 0, added); + // Add this action to the document event. + ElementEdit edit = new ElementEdit(par, ind, new Element[0], + added); + documentEvent.addEdit(edit); + } + offset += len; + } + } + + /** + * An element type for sections. This is a simple BranchElement with + * a unique name. + */ + protected class SectionElement extends BranchElement + { + /** + * Creates a new SectionElement. + */ + public SectionElement() + { + super(null, null); + } + + /** + * Returns the name of the element. This method always returns + * "section". + * + * @return the name of the element + */ + public String getName() + { + return "section"; + } } + /** The serialization UID (compatible with JDK1.5). */ + private static final long serialVersionUID = 940485415728614849L; + /** * The default size to use for new content buffers. */ @@ -250,9 +794,11 @@ public class DefaultStyledDocument extends AbstractDocument Element[] tmp; // FIXME: Create a SecionElement here instead of a BranchElement. // Use createBranchElement() and createLeafElement instead. - BranchElement section = new BranchElement(null, null); - - BranchElement paragraph = new BranchElement(section, null); + SectionElement section = new SectionElement(); + + BranchElement paragraph = + (BranchElement) createBranchElement(section, null); + paragraph.setResolveParent(getStyle(StyleContext.DEFAULT_STYLE)); tmp = new Element[1]; tmp[0] = paragraph; section.replace(0, 0, tmp); @@ -261,7 +807,7 @@ public class DefaultStyledDocument extends AbstractDocument tmp = new Element[1]; tmp[0] = leaf; paragraph.replace(0, 0, tmp); - + return section; } @@ -360,8 +906,9 @@ public class DefaultStyledDocument extends AbstractDocument */ public Element getParagraphElement(int position) { - Element element = getCharacterElement(position); - return element.getParentElement(); + BranchElement root = (BranchElement) getDefaultRootElement(); + Element par = root.positionToElement(position); + return par; } /** @@ -445,6 +992,8 @@ public class DefaultStyledDocument extends AbstractDocument + "javax.swing.text.AbstractDocument.AbstractElement"); } } + + fireChangedUpdate(ev); } /** @@ -476,10 +1025,110 @@ public class DefaultStyledDocument extends AbstractDocument * selection are overridden, otherwise they are merged */ public void setParagraphAttributes(int offset, int length, - AttributeSet attributes, - boolean replace) + AttributeSet attributes, + boolean replace) { - // FIXME: Implement me. - throw new Error("not implemented"); + int index = offset; + while (index < offset + length) + { + AbstractElement par = (AbstractElement) getParagraphElement(index); + AttributeContext ctx = getAttributeContext(); + if (replace) + par.removeAttributes(par); + par.addAttributes(attributes); + index = par.getElementCount(); + } } + + /** + * Called in response to content insert actions. This is used to + * update the element structure. + * + * @param ev the <code>DocumentEvent</code> describing the change + * @param attr the attributes for the change + */ + protected void insertUpdate(DefaultDocumentEvent ev, AttributeSet attr) + { + super.insertUpdate(ev, attr); + int offset = ev.getOffset(); + int length = ev.getLength(); + int endOffset = offset + length; + Segment txt = new Segment(); + try + { + getText(offset, length, txt); + } + catch (BadLocationException ex) + { + throw new AssertionError("BadLocationException must not be thrown " + + "here."); + } + + int len = 0; + Vector specs = new Vector(); + + Element prev = getCharacterElement(offset); + Element next = getCharacterElement(endOffset); + + for (int i = offset; i < endOffset; ++i) + { + len++; + if (txt.array[i] == '\n') + { + ElementSpec spec = new ElementSpec(attr, ElementSpec.ContentType, + len); + + // If we are at the last index, then check if we could probably be + // joined with the next element. + if (i == endOffset - 1) + { + if (next.getAttributes().isEqual(attr)) + spec.setDirection(ElementSpec.JoinNextDirection); + } + // If we are at the first new element, then check if it could be + // joined with the previous element. + else if (specs.size() == 0) + { + if (prev.getAttributes().isEqual(attr)) + spec.setDirection(ElementSpec.JoinPreviousDirection); + } + + specs.add(spec); + + // Add ElementSpecs for the newline. + ElementSpec endTag = new ElementSpec(null, ElementSpec.EndTagType); + specs.add(endTag); + ElementSpec startTag = new ElementSpec(null, + ElementSpec.StartTagType); + startTag.setDirection(ElementSpec.JoinFractureDirection); + specs.add(startTag); + + len = 0; + offset += len; + } + } + + // Create last element if last character hasn't been a newline. + if (len > 0) + { + ElementSpec spec = new ElementSpec(attr, ElementSpec.ContentType, len); + // If we are at the first new element, then check if it could be + // joined with the previous element. + if (specs.size() == 0) + { + if (prev.getAttributes().isEqual(attr)) + spec.setDirection(ElementSpec.JoinPreviousDirection); + } + // Check if we could probably be joined with the next element. + else if (next.getAttributes().isEqual(attr)) + spec.setDirection(ElementSpec.JoinNextDirection); + + specs.add(spec); + } + + ElementSpec[] elSpecs = + (ElementSpec[]) specs.toArray(new ElementSpec[specs.size()]); + + buffer.insert(offset, length, elSpecs, ev); + } } diff --git a/javax/swing/text/GapContent.java b/javax/swing/text/GapContent.java index 8e408f36c..5c8f81865 100644 --- a/javax/swing/text/GapContent.java +++ b/javax/swing/text/GapContent.java @@ -39,9 +39,11 @@ exception statement from your version. */ package javax.swing.text; import java.io.Serializable; +import java.util.ArrayList; import java.util.Collections; -import java.util.LinkedList; +import java.util.Iterator; import java.util.ListIterator; +import java.util.Vector; import javax.swing.undo.UndoableEdit; @@ -59,7 +61,6 @@ import javax.swing.undo.UndoableEdit; public class GapContent implements AbstractDocument.Content, Serializable { - /** * A {@link Position} implementation for <code>GapContent</code>. */ @@ -114,6 +115,11 @@ public class GapContent */ public int getOffset() { + // Check precondition. + assert mark <= gapStart || mark > gapEnd : "mark: " + mark + + ", gapStart: " + gapStart + + ", gapEnd: " + gapEnd; + if (mark <= gapEnd) return mark; else @@ -121,13 +127,14 @@ public class GapContent } } - private static final long serialVersionUID = 8374645204155842629L; + /** The serialization UID (compatible with JDK1.5). */ + private static final long serialVersionUID = -6226052713477823730L; /** * This is the default buffer size and the amount of bytes that a buffer is * extended if it is full. */ - static final int DEFAULT_BUFSIZE = 64; + static final int DEFAULT_BUFSIZE = 10; /** * The text buffer. @@ -148,7 +155,7 @@ public class GapContent * The positions generated by this GapContent. They are kept in an ordered * fashion, so they can be looked up easily. */ - LinkedList positions; + ArrayList positions; /** * Creates a new GapContent object. @@ -166,10 +173,10 @@ public class GapContent public GapContent(int size) { buffer = (char[]) allocateArray(size); - gapStart = 0; - gapEnd = size - 1; - buffer[size - 1] = '\n'; - positions = new LinkedList(); + gapStart = 1; + gapEnd = size; + buffer[0] = '\n'; + positions = new ArrayList(); } /** @@ -386,7 +393,19 @@ public class GapContent */ protected void shiftEnd(int newSize) { - int delta = (gapEnd - gapStart) - newSize; + assert newSize > (gapEnd - gapStart) : "The new gap size must be greater " + + "than the old gap size"; + + int delta = newSize - gapEnd + gapStart; + // Update the marks after the gapEnd. + Vector v = getPositionsInRange(null, gapEnd, buffer.length - gapEnd); + for (Iterator i = v.iterator(); i.hasNext();) + { + GapContentPosition p = (GapContentPosition) i.next(); + p.mark += delta; + } + + // Copy the data around. char[] newBuf = (char[]) allocateArray(length() + newSize); System.arraycopy(buffer, 0, newBuf, 0, gapStart); System.arraycopy(buffer, gapEnd, newBuf, gapStart + newSize, buffer.length @@ -394,18 +413,6 @@ public class GapContent gapEnd = gapStart + newSize; buffer = newBuf; - // Update the marks after the gapEnd. - int index = Collections.binarySearch(positions, new GapContentPosition( - gapEnd)); - if (index < 0) - { - index = -(index + 1); - } - for (ListIterator i = positions.listIterator(index); i.hasNext();) - { - GapContentPosition p = (GapContentPosition) i.next(); - p.mark += delta; - } } /** @@ -415,32 +422,22 @@ public class GapContent */ protected void shiftGap(int newGapStart) { - int newGapEnd = newGapStart + (gapEnd - gapStart); + if (newGapStart == gapStart) + return; - // Update the positions between newGapEnd and (old) gapEnd. The marks - // must be shifted by (gapEnd - newGapEnd). - int index1 = Collections.binarySearch(positions, - new GapContentPosition(gapEnd)); - int index2 = Collections.binarySearch(positions, - new GapContentPosition(newGapEnd)); - if (index1 > 0 && index2 > 0) + int newGapEnd = newGapStart + gapEnd - gapStart; + + if (newGapStart < gapStart) { - int i1 = Math.min(index1, index2); - int i2 = Math.max(index1, index2); - for (ListIterator i = positions.listIterator(i1); i.hasNext();) + // Update the positions between newGapStart and (old) gapStart. The marks + // must be shifted by (gapEnd - gapStart). + Vector v = getPositionsInRange(null, newGapStart + 1, + gapStart - newGapStart + 1); + for (Iterator i = v.iterator(); i.hasNext();) { - if (i.nextIndex() > i2) - break; - GapContentPosition p = (GapContentPosition) i.next(); - p.mark += gapEnd - newGapEnd; + p.mark += gapEnd - gapStart; } - } - - if (newGapStart == gapStart) - return; - else if (newGapStart < gapStart) - { System.arraycopy(buffer, newGapStart, buffer, newGapEnd, gapStart - newGapStart); gapStart = newGapStart; @@ -448,6 +445,15 @@ public class GapContent } else { + // Update the positions between newGapEnd and (old) gapEnd. The marks + // must be shifted by (gapEnd - gapStart). + Vector v = getPositionsInRange(null, gapEnd, + newGapEnd - gapEnd); + for (Iterator i = v.iterator(); i.hasNext();) + { + GapContentPosition p = (GapContentPosition) i.next(); + p.mark -= gapEnd - gapStart; + } System.arraycopy(buffer, gapEnd, buffer, gapStart, newGapStart - gapStart); gapStart = newGapStart; @@ -456,6 +462,54 @@ public class GapContent } /** + * Shifts the gap start downwards. This does not affect the content of the + * buffer. This only updates the gap start and all the marks that are between + * the old gap start and the new gap start. They all are squeezed to the start + * of the gap, because their location has been removed. + * + * @param newGapStart the new gap start + */ + protected void shiftGapStartDown(int newGapStart) + { + if (newGapStart == gapStart) + return; + + assert newGapStart < gapStart : "The new gap start must be less than the " + + "old gap start."; + Vector v = getPositionsInRange(null, newGapStart, gapStart - newGapStart); + for (Iterator i = v.iterator(); i.hasNext();) + { + GapContentPosition p = (GapContentPosition) i.next(); + p.mark = gapStart; + } + gapStart = newGapStart; + } + + /** + * Shifts the gap end upwards. This does not affect the content of the + * buffer. This only updates the gap end and all the marks that are between + * the old gap end and the new end start. They all are squeezed to the end + * of the gap, because their location has been removed. + * + * @param newGapEnd the new gap start + */ + protected void shiftGapEndUp(int newGapEnd) + { + if (newGapEnd == gapEnd) + return; + + assert newGapEnd > gapEnd : "The new gap end must be greater than the " + + "old gap end."; + Vector v = getPositionsInRange(null, gapEnd, newGapEnd - gapEnd); + for (Iterator i = v.iterator(); i.hasNext();) + { + GapContentPosition p = (GapContentPosition) i.next(); + p.mark = newGapEnd + 1; + } + gapEnd = newGapEnd; + } + + /** * Returns the allocated buffer array. * * @return the allocated buffer array @@ -478,11 +532,11 @@ public class GapContent { // Remove content shiftGap(position); - gapEnd += rmSize; + shiftGapEndUp(gapEnd + rmSize); // If gap is too small, enlarge the gap. - if ((gapEnd - gapStart) < addSize) - shiftEnd(addSize); + if ((gapEnd - gapStart) <= addSize) + shiftEnd((addSize - gapEnd + gapStart + 1) * 2 + gapEnd + DEFAULT_BUFSIZE); // Add new items to the buffer. if (addItems != null) @@ -491,4 +545,64 @@ public class GapContent gapStart += addSize; } } + + /** + * Returns the start index of the gap within the buffer array. + * + * @return the start index of the gap within the buffer array + */ + protected final int getGapStart() + { + return gapStart; + } + + /** + * Returns the end index of the gap within the buffer array. + * + * @return the end index of the gap within the buffer array + */ + protected final int getGapEnd() + { + return gapEnd; + } + + /** + * Returns all <code>Position</code>s that are in the range specified by + * <code>offset</code> and </code>length</code> within the buffer array. + * + * @param v the vector to use; if <code>null</code>, a new Vector is allocated + * @param offset the start offset of the range to search + * @param length the length of the range to search + * + * @return the positions within the specified range + */ + protected Vector getPositionsInRange(Vector v, int offset, int length) + { + Vector res = v; + if (res == null) + res = new Vector(); + else + res.clear(); + + int endOffset = offset + length; + + int index1 = Collections.binarySearch(positions, + new GapContentPosition(offset)); + int index2 = Collections.binarySearch(positions, + new GapContentPosition(endOffset)); + if (index1 < 0) + index1 = -(index1 + 1); + if (index2 < 0) + index2 = -(index2 + 1); + for (ListIterator i = positions.listIterator(index1); i.hasNext();) + { + if (i.nextIndex() > index2) + break; + + GapContentPosition p = (GapContentPosition) i.next(); + if (p.mark >= offset && p.mark <= endOffset) + res.add(p); + } + return res; + } } diff --git a/javax/swing/text/GlyphView.java b/javax/swing/text/GlyphView.java index f9e60972d..6ffab23c4 100644 --- a/javax/swing/text/GlyphView.java +++ b/javax/swing/text/GlyphView.java @@ -44,6 +44,11 @@ import java.awt.FontMetrics; import java.awt.Graphics; import java.awt.Rectangle; import java.awt.Shape; +import java.text.BreakIterator; + +import javax.swing.SwingConstants; +import javax.swing.event.DocumentEvent; +import javax.swing.text.Position.Bias; /** * Renders a run of styled text. This {@link View} subclass paints the @@ -52,9 +57,7 @@ import java.awt.Shape; * * @author Roman Kennke (roman@kennke.org) */ -public class GlyphView - extends View - implements TabableView, Cloneable +public class GlyphView extends View implements TabableView, Cloneable { /** @@ -71,12 +74,43 @@ public class GlyphView } /** + * Returns the ascent of the font that is used by this glyph painter. + * + * @param v the glyph view + * + * @return the ascent of the font that is used by this glyph painter + */ + public abstract float getAscent(GlyphView v); + + /** + * Returns the descent of the font that is used by this glyph painter. + * + * @param v the glyph view + * + * @return the descent of the font that is used by this glyph painter + */ + public abstract float getDescent(GlyphView v); + + /** * Returns the full height of the rendered text. * * @return the full height of the rendered text */ public abstract float getHeight(GlyphView view); - + + /** + * Determines the model offset, so that the text between <code>p0</code> + * and this offset fits within the span starting at <code>x</code> with + * the length of <code>len</code>. + * + * @param v the glyph view + * @param p0 the starting offset in the model + * @param x the start location in the view + * @param len the length of the span in the view + */ + public abstract int getBoundedPosition(GlyphView v, int p0, float x, + float len); + /** * Paints the glyphs. * @@ -97,8 +131,8 @@ public class GlyphView * @param view the glyph view * @param pos the position of the character in the model * @param a the area that is occupied by the view - * @param bias either {@link Position.Bias.Forward} or - * {@link Position.Bias.Backward} depending on the preferred + * @param b either {@link Position.Bias#Forward} or + * {@link Position.Bias#Backward} depending on the preferred * direction bias. If <code>null</code> this defaults to * <code>Position.Bias.Forward</code> * @@ -114,6 +148,20 @@ public class GlyphView throws BadLocationException; /** + * Maps a visual position into a document location. + * + * @param v the glyph view + * @param x the X coordinate of the visual position + * @param y the Y coordinate of the visual position + * @param a the allocated region + * @param biasRet filled with the bias of the model location on method exit + * + * @return the model location that represents the specified view location + */ + public abstract int viewToModel(GlyphView v, float x, float y, Shape a, + Position.Bias[] biasRet); + + /** * Determine the span of the glyphs from location <code>p0</code> to * location <code>p1</code>. If <code>te</code> is not <code>null</code>, * then TABs are expanded using this <code>TabExpander</code>. @@ -122,7 +170,7 @@ public class GlyphView * * @param view the glyph view * @param p0 the starting location in the document model - * @param p0 the end location in the document model + * @param p1 the end location in the document model * @param te the tab expander to use * @param x the location at which the view is located * @@ -132,6 +180,69 @@ public class GlyphView public abstract float getSpan(GlyphView view, int p0, int p1, TabExpander te, float x); + + /** + * Returns the model location that should be used to place a caret when + * moving the caret through the document. + * + * @param v the glyph view + * @param pos the current model location + * @param b the bias for <code>p</code> + * @param a the allocated region for the glyph view + * @param direction the direction from the current position; Must be one of + * {@link SwingConstants#EAST}, {@link SwingConstants#WEST}, + * {@link SwingConstants#NORTH} or {@link SwingConstants#SOUTH} + * @param biasRet filled with the bias of the resulting location when method + * returns + * + * @return the location within the document that should be used to place the + * caret when moving the caret around the document + * + * @throws BadLocationException if <code>pos</code> is an invalid model + * location + * @throws IllegalArgumentException if <code>d</code> is invalid + */ + public int getNextVisualPositionFrom(GlyphView v, int pos, Position.Bias b, + Shape a, int direction, + Position.Bias[] biasRet) + throws BadLocationException + + { + int result = pos; + switch (direction) + { + case SwingConstants.EAST: + result = pos + 1; + break; + case SwingConstants.WEST: + result = pos - 1; + break; + case SwingConstants.NORTH: + case SwingConstants.SOUTH: + default: + // This should be handled in enclosing view, since the glyph view + // does not layout vertically. + break; + } + return result; + } + + /** + * Returns a painter that can be used to render the specified glyph view. + * If this glyph painter is stateful, then it should return a new instance. + * However, if this painter is stateless it should return itself. The + * default behaviour is to return itself. + * + * @param v the glyph view for which to create a painter + * @param p0 the start offset of the rendered area + * @param p1 the end offset of the rendered area + * + * @return a painter that can be used to render the specified glyph view + */ + public GlyphPainter getPainter(GlyphView v, int p0, int p1) + { + return this; + } } /** @@ -173,11 +284,40 @@ public class GlyphView if (parent instanceof TabExpander) tabEx = (TabExpander) parent; - // FIXME: Set character attributes like font-family, font-size, colors. - Color foreground = view.getForeground(); - g.setColor(foreground); - Utilities.drawTabbedText(txt, bounds.x, bounds.y, g, tabEx, - txt.offset); + // Fill the background of the text run. + Color background = view.getBackground(); + g.setColor(background); + int width = Utilities.getTabbedTextWidth(txt, g.getFontMetrics(), + bounds.x, tabEx, txt.offset); + g.fillRect(bounds.x, bounds.y, width, height); + + // Draw the actual text. + g.setColor(view.getForeground()); + g.setFont(view.getFont()); + if (view.isSuperscript()) + // TODO: Adjust font for superscripting. + Utilities.drawTabbedText(txt, bounds.x, bounds.y - height / 2, g, tabEx, + txt.offset); + else if (view.isSubscript()) + // TODO: Adjust font for subscripting. + Utilities.drawTabbedText(txt, bounds.x, bounds.y + height / 2, g, tabEx, + txt.offset); + else + Utilities.drawTabbedText(txt, bounds.x, bounds.y, g, tabEx, + txt.offset); + + if (view.isStikeThrough()) + { + int strikeHeight = (int) (getAscent(view) / 2); + g.drawLine(bounds.x, bounds.y + strikeHeight, bounds.height + width, + bounds.y + strikeHeight); + } + if (view.isUnderline()) + { + int lineHeight = (int) getAscent(view); + g.drawLine(bounds.x, bounds.y + lineHeight, bounds.height + width, + bounds.y + lineHeight); + } } /** @@ -188,8 +328,8 @@ public class GlyphView * @param view the glyph view * @param pos the position of the character in the model * @param a the area that is occupied by the view - * @param bias either {@link Position.Bias.Forward} or - * {@link Position.Bias.Backward} depending on the preferred + * @param b either {@link Position.Bias#Forward} or + * {@link Position.Bias#Backward} depending on the preferred * direction bias. If <code>null</code> this defaults to * <code>Position.Bias.Forward</code> * @@ -225,7 +365,7 @@ public class GlyphView * * @param view the glyph view * @param p0 the starting location in the document model - * @param p0 the end location in the document model + * @param p1 the end location in the document model * @param te the tab expander to use * @param x the location at which the view is located * @@ -242,6 +382,85 @@ public class GlyphView int span = Utilities.getTabbedTextWidth(txt, fm, (int) x, te, p0); return span; } + + /** + * Returns the ascent of the text run that is rendered by this + * <code>GlyphPainter</code>. + * + * @param v the glyph view + * + * @return the ascent of the text run that is rendered by this + * <code>GlyphPainter</code> + * + * @see FontMetrics#getAscent() + */ + public float getAscent(GlyphView v) + { + Font font = v.getFont(); + FontMetrics fm = v.getContainer().getFontMetrics(font); + return fm.getAscent(); + } + + /** + * Returns the descent of the text run that is rendered by this + * <code>GlyphPainter</code>. + * + * @param v the glyph view + * + * @return the descent of the text run that is rendered by this + * <code>GlyphPainter</code> + * + * @see FontMetrics#getDescent() + */ + public float getDescent(GlyphView v) + { + Font font = v.getFont(); + FontMetrics fm = v.getContainer().getFontMetrics(font); + return fm.getDescent(); + } + + /** + * Determines the model offset, so that the text between <code>p0</code> + * and this offset fits within the span starting at <code>x</code> with + * the length of <code>len</code>. + * + * @param v the glyph view + * @param p0 the starting offset in the model + * @param x the start location in the view + * @param len the length of the span in the view + */ + public int getBoundedPosition(GlyphView v, int p0, float x, float len) + { + TabExpander te = v.getTabExpander(); + Segment txt = v.getText(p0, v.getEndOffset()); + Font font = v.getFont(); + FontMetrics fm = v.getContainer().getFontMetrics(font); + int pos = Utilities.getTabbedTextOffset(txt, fm, (int) x, + (int) (x + len), te, p0, false); + return pos; + } + + /** + * Maps a visual position into a document location. + * + * @param v the glyph view + * @param x the X coordinate of the visual position + * @param y the Y coordinate of the visual position + * @param a the allocated region + * @param biasRet filled with the bias of the model location on method exit + * + * @return the model location that represents the specified view location + */ + public int viewToModel(GlyphView v, float x, float y, Shape a, + Bias[] biasRet) + { + Rectangle b = a.getBounds(); + assert b.contains(x, y) : "The coordinates are expected to be within the " + + "view's bounds: x=" + x + ", y=" + y + + "a=" + a; + int pos = getBoundedPosition(v, v.getStartOffset(), b.x, x - b.x); + return pos; + } } /** @@ -250,6 +469,16 @@ public class GlyphView GlyphPainter glyphPainter; /** + * The start offset within the document for this view. + */ + int startOffset; + + /** + * The end offset within the document for this view. + */ + int endOffset; + + /** * Creates a new <code>GlyphView</code> for the given <code>Element</code>. * * @param element the element that is rendered by this GlyphView @@ -257,6 +486,8 @@ public class GlyphView public GlyphView(Element element) { super(element); + startOffset = element.getStartOffset(); + endOffset = element.getEndOffset(); } /** @@ -319,16 +550,21 @@ public class GlyphView */ public float getPreferredSpan(int axis) { - Element el = getElement(); + float span = 0; checkPainter(); GlyphPainter painter = getGlyphPainter(); - TabExpander tabEx = null; - View parent = getParent(); - if (parent instanceof TabExpander) - tabEx = (TabExpander) parent; - // FIXME: Figure out how to determine the x parameter. - float span = painter.getSpan(this, el.getStartOffset(), el.getEndOffset(), - tabEx, 0.F); + if (axis == X_AXIS) + { + Element el = getElement(); + TabExpander tabEx = null; + View parent = getParent(); + if (parent instanceof TabExpander) + tabEx = (TabExpander) parent; + span = painter.getSpan(this, getStartOffset(), getEndOffset(), + tabEx, 0.F); + } + else + span = painter.getHeight(this); return span; } @@ -372,8 +608,9 @@ public class GlyphView */ public int viewToModel(float x, float y, Shape a, Position.Bias[] b) { - // FIXME: not implemented - return 0; + checkPainter(); + GlyphPainter painter = getGlyphPainter(); + return painter.viewToModel(this, x, y, a, b); } /** @@ -383,12 +620,11 @@ public class GlyphView */ public TabExpander getTabExpander() { - // TODO: Figure out if this is correct. TabExpander te = null; View parent = getParent(); - if (parent instanceof ParagraphView) - te = (ParagraphView) parent; + if (parent instanceof TabExpander) + te = (TabExpander) parent; return te; } @@ -436,15 +672,15 @@ public class GlyphView } /** - * Returns the starting offset in the document model of the portion + * Returns the start offset in the document model of the portion * of text that this view is responsible for. * - * @return the starting offset in the document model of the portion + * @return the start offset in the document model of the portion * of text that this view is responsible for */ - public int getBeginIndex() + public int getStartOffset() { - return getElement().getStartOffset(); + return startOffset; } /** @@ -454,9 +690,9 @@ public class GlyphView * @return the end offset in the document model of the portion * of text that this view is responsible for */ - public int getEndIndex() + public int getEndOffset() { - return getElement().getEndOffset(); + return endOffset; } /** @@ -518,4 +754,302 @@ public class GlyphView AttributeSet atts = el.getAttributes(); return StyleConstants.getForeground(atts); } + + /** + * Returns the background color which should be used to paint the text. + * This is fetched from the associated element's text attributes using + * {@link StyleConstants#getBackground}. + * + * @return the background color which should be used to paint the text + */ + public Color getBackground() + { + Element el = getElement(); + AttributeSet atts = el.getAttributes(); + return StyleConstants.getBackground(atts); + } + + /** + * Determines whether the text should be rendered strike-through or not. This + * is determined using the method + * {@link StyleConstants#isStrikeThrough(AttributeSet)} on the element of + * this view. + * + * @return whether the text should be rendered strike-through or not + */ + public boolean isStikeThrough() + { + Element el = getElement(); + AttributeSet atts = el.getAttributes(); + return StyleConstants.isStrikeThrough(atts); + } + + /** + * Determines whether the text should be rendered as subscript or not. This + * is determined using the method + * {@link StyleConstants#isSubscript(AttributeSet)} on the element of + * this view. + * + * @return whether the text should be rendered as subscript or not + */ + public boolean isSubscript() + { + Element el = getElement(); + AttributeSet atts = el.getAttributes(); + return StyleConstants.isSubscript(atts); + } + + /** + * Determines whether the text should be rendered as superscript or not. This + * is determined using the method + * {@link StyleConstants#isSuperscript(AttributeSet)} on the element of + * this view. + * + * @return whether the text should be rendered as superscript or not + */ + public boolean isSuperscript() + { + Element el = getElement(); + AttributeSet atts = el.getAttributes(); + return StyleConstants.isSuperscript(atts); + } + + /** + * Determines whether the text should be rendered as underlined or not. This + * is determined using the method + * {@link StyleConstants#isUnderline(AttributeSet)} on the element of + * this view. + * + * @return whether the text should be rendered as underlined or not + */ + public boolean isUnderline() + { + Element el = getElement(); + AttributeSet atts = el.getAttributes(); + return StyleConstants.isUnderline(atts); + } + + /** + * Creates and returns a shallow clone of this GlyphView. This is used by + * the {@link #createFragment} and {@link #breakView} methods. + * + * @return a shallow clone of this GlyphView + */ + protected final Object clone() + { + try + { + return super.clone(); + } + catch (CloneNotSupportedException ex) + { + AssertionError err = new AssertionError("CloneNotSupportedException " + + "must not be thrown here"); + err.initCause(ex); + throw err; + } + } + + /** + * Tries to break the view near the specified view span <code>len</code>. + * The glyph view can only be broken in the X direction. For Y direction it + * returns itself. + * + * @param axis the axis for breaking, may be {@link View#X_AXIS} or + * {@link View#Y_AXIS} + * @param p0 the model location where the fragment should start + * @param pos the view position along the axis where the fragment starts + * @param len the desired length of the fragment view + * + * @return the fragment view, or <code>this</code> if breaking was not + * possible + */ + public View breakView(int axis, int p0, float pos, float len) + { + if (axis == Y_AXIS) + return this; + + checkPainter(); + GlyphPainter painter = getGlyphPainter(); + int breakLocation = painter.getBoundedPosition(this, p0, pos, len); + // Try to find a suitable line break. + BreakIterator lineBreaker = BreakIterator.getLineInstance(); + Segment txt = new Segment(); + try + { + getDocument().getText(getStartOffset(), getEndOffset(), txt); + } + catch (BadLocationException ex) + { + AssertionError err = new AssertionError("BadLocationException must not " + + "be thrown here."); + err.initCause(ex); + throw err; + } + lineBreaker.setText(txt); + int goodBreakLocation = lineBreaker.previous(); + if (goodBreakLocation != BreakIterator.DONE) + breakLocation = goodBreakLocation; + + View brokenView = createFragment(p0, breakLocation); + return brokenView; + } + + /** + * Determines how well the specified view location is suitable for inserting + * a line break. If <code>axis</code> is <code>View.Y_AXIS</code>, then + * this method forwards to the superclass, if <code>axis</code> is + * <code>View.X_AXIS</code> then this method returns + * {@link View#ExcellentBreakWeight} if there is a suitable break location + * (usually whitespace) within the specified view span, or + * {@link View#GoodBreakWeight} if not. + * + * @param axis the axis along which the break weight is requested + * @param pos the starting view location + * @param len the length of the span at which the view should be broken + * + * @return the break weight + */ + public int getBreakWeight(int axis, float pos, float len) + { + int weight; + if (axis == Y_AXIS) + weight = super.getBreakWeight(axis, pos, len); + else + { + // Determine the model locations at pos and pos + len. + int spanX = (int) getPreferredSpan(X_AXIS); + int spanY = (int) getPreferredSpan(Y_AXIS); + Rectangle dummyAlloc = new Rectangle(0, 0, spanX, spanY); + Position.Bias[] biasRet = new Position.Bias[1]; + int offset1 = viewToModel(pos, spanY / 2, dummyAlloc, biasRet); + int offset2 = viewToModel(pos, spanY / 2, dummyAlloc, biasRet); + Segment txt = getText(offset1, offset2); + BreakIterator lineBreaker = BreakIterator.getLineInstance(); + lineBreaker.setText(txt); + int breakLoc = lineBreaker.previous(); + if (breakLoc == offset1) + weight = View.BadBreakWeight; + else if(breakLoc == BreakIterator.DONE) + weight = View.GoodBreakWeight; + else + weight = View.ExcellentBreakWeight; + } + return weight; + } + + /** + * Receives notification that some text attributes have changed within the + * text fragment that this view is responsible for. This calls + * {@link View#preferenceChanged(View, boolean, boolean)} on the parent for + * both width and height. + * + * @param e the document event describing the change; not used here + * @param a the view allocation on screen; not used here + * @param vf the view factory; not used here + */ + public void changedUpdate(DocumentEvent e, Shape a, ViewFactory vf) + { + getParent().preferenceChanged(this, true, true); + } + + /** + * Receives notification that some text has been inserted within the + * text fragment that this view is responsible for. This calls + * {@link View#preferenceChanged(View, boolean, boolean)} on the parent for + * width. + * + * @param e the document event describing the change; not used here + * @param a the view allocation on screen; not used here + * @param vf the view factory; not used here + */ + public void insertUpdate(DocumentEvent e, Shape a, ViewFactory vf) + { + getParent().preferenceChanged(this, true, false); + } + + /** + * Receives notification that some text has been removed within the + * text fragment that this view is responsible for. This calls + * {@link View#preferenceChanged(View, boolean, boolean)} on the parent for + * width. + * + * @param e the document event describing the change; not used here + * @param a the view allocation on screen; not used here + * @param vf the view factory; not used here + */ + public void removeUpdate(DocumentEvent e, Shape a, ViewFactory vf) + { + getParent().preferenceChanged(this, true, false); + } + + /** + * Creates a fragment view of this view that starts at <code>p0</code> and + * ends at <code>p1</code>. + * + * @param p0 the start location for the fragment view + * @param p1 the end location for the fragment view + * + * @return the fragment view + */ + public View createFragment(int p0, int p1) + { + GlyphView fragment = (GlyphView) clone(); + fragment.startOffset = p0; + fragment.endOffset = p1; + return fragment; + } + + /** + * Returns the alignment of this view along the specified axis. For the Y + * axis this is <code>(height - descent) / height</code> for the used font, + * so that it is aligned along the baseline. + * For the X axis the superclass is called. + */ + public float getAlignment(int axis) + { + float align; + if (axis == Y_AXIS) + { + checkPainter(); + GlyphPainter painter = getGlyphPainter(); + float height = painter.getHeight(this); + float descent = painter.getDescent(this); + align = (height - descent) / height; + } + else + align = super.getAlignment(axis); + + return align; + } + + /** + * Returns the model location that should be used to place a caret when + * moving the caret through the document. + * + * @param pos the current model location + * @param bias the bias for <code>p</code> + * @param a the allocated region for the glyph view + * @param direction the direction from the current position; Must be one of + * {@link SwingConstants#EAST}, {@link SwingConstants#WEST}, + * {@link SwingConstants#NORTH} or {@link SwingConstants#SOUTH} + * @param biasRet filled with the bias of the resulting location when method + * returns + * + * @return the location within the document that should be used to place the + * caret when moving the caret around the document + * + * @throws BadLocationException if <code>pos</code> is an invalid model + * location + * @throws IllegalArgumentException if <code>d</code> is invalid + */ + public int getNextVisualPositionFrom(int pos, Position.Bias bias, Shape a, + int direction, Position.Bias[] biasRet) + throws BadLocationException + { + checkPainter(); + GlyphPainter painter = getGlyphPainter(); + return painter.getNextVisualPositionFrom(this, pos, bias, a, direction, + biasRet); + } } diff --git a/javax/swing/text/InternationalFormatter.java b/javax/swing/text/InternationalFormatter.java index cedaf59fe..86300a70d 100644 --- a/javax/swing/text/InternationalFormatter.java +++ b/javax/swing/text/InternationalFormatter.java @@ -57,9 +57,8 @@ import javax.swing.JFormattedTextField; public class InternationalFormatter extends DefaultFormatter { - - /** The serialVersoinUID. */ - private static final long serialVersionUID = 6941977820906408656L; + /** The serialization UID (compatible with JDK1.5). */ + private static final long serialVersionUID = 2436068675711756856L; /** The format that handles value to string conversion. */ Format format; diff --git a/javax/swing/text/JTextComponent.java b/javax/swing/text/JTextComponent.java index b3fad7912..63dbf2a4b 100644 --- a/javax/swing/text/JTextComponent.java +++ b/javax/swing/text/JTextComponent.java @@ -303,9 +303,7 @@ public abstract class JTextComponent extends JComponent /** * The timer that lets the caret blink. */ - private class CaretBlinkTimer - extends Timer - implements ActionListener + private class CaretBlinkTimer extends Timer implements ActionListener { /** * Creates a new CaretBlinkTimer object with a default delay of 1 second. @@ -604,8 +602,7 @@ public abstract class JTextComponent extends JComponent } } - class DefaultTransferHandler - extends TransferHandler + class DefaultTransferHandler extends TransferHandler { public boolean canImport(JComponent component, DataFlavor[] flavors) { @@ -1105,7 +1102,8 @@ public abstract class JTextComponent extends JComponent */ protected String paramString() { - return "JTextComponent"; + // TODO: Do something useful here. + return super.paramString(); } /** diff --git a/javax/swing/text/PlainView.java b/javax/swing/text/PlainView.java index 91d7547e7..b93d9a4f1 100644 --- a/javax/swing/text/PlainView.java +++ b/javax/swing/text/PlainView.java @@ -51,6 +51,12 @@ public class PlainView extends View { Color selectedColor; Color unselectedColor; + + /** + * The color that is used to draw disabled text fields. + */ + Color disabledColor; + Font font; protected FontMetrics metrics; @@ -145,7 +151,12 @@ public class PlainView extends View protected int drawUnselectedText(Graphics g, int x, int y, int p0, int p1) throws BadLocationException { - g.setColor(unselectedColor); + JTextComponent textComponent = (JTextComponent) getContainer(); + if (textComponent.isEnabled()) + g.setColor(unselectedColor); + else + g.setColor(disabledColor); + Segment segment = new Segment(); getDocument().getText(p0, p1 - p0, segment); return Utilities.drawTabbedText(segment, x, y, g, this, segment.offset); @@ -161,7 +172,8 @@ public class PlainView extends View g.setFont(textComponent.getFont()); selectedColor = textComponent.getSelectedTextColor(); unselectedColor = textComponent.getForeground(); - + disabledColor = textComponent.getDisabledTextColor(); + Rectangle rect = s.getBounds(); // FIXME: Text may be scrolled. diff --git a/javax/swing/text/SimpleAttributeSet.java b/javax/swing/text/SimpleAttributeSet.java index 3ef5db61d..61cf5e97c 100644 --- a/javax/swing/text/SimpleAttributeSet.java +++ b/javax/swing/text/SimpleAttributeSet.java @@ -45,6 +45,9 @@ import java.util.Hashtable; public class SimpleAttributeSet implements MutableAttributeSet, Serializable, Cloneable { + /** The serialization UID (compatible with JDK1.5). */ + private static final long serialVersionUID = 8267656273837665219L; + public static final AttributeSet EMPTY = new SimpleAttributeSet(); Hashtable tab; @@ -89,7 +92,7 @@ public class SimpleAttributeSet return tab.containsKey(name) && tab.get(name).equals(value); } - + public boolean containsAttributes(AttributeSet attributes) { Enumeration e = attributes.getAttributeNames(); @@ -110,9 +113,9 @@ public class SimpleAttributeSet public boolean equals(Object obj) { - return (obj != null) - && (obj instanceof SimpleAttributeSet) - && ((SimpleAttributeSet)obj).tab.equals(this.tab); + return + (obj instanceof AttributeSet) + && this.isEqual((AttributeSet) obj); } public Object getAttribute(Object name) @@ -160,7 +163,9 @@ public class SimpleAttributeSet public boolean isEqual(AttributeSet attr) { - return this.equals(attr); + return attr != null + && attr.containsAttributes(this) + && this.containsAttributes(attr); } public void removeAttribute(Object name) diff --git a/javax/swing/text/StringContent.java b/javax/swing/text/StringContent.java index bedf480d4..7db377a1c 100644 --- a/javax/swing/text/StringContent.java +++ b/javax/swing/text/StringContent.java @@ -56,6 +56,9 @@ import javax.swing.undo.UndoableEdit; */ public final class StringContent implements AbstractDocument.Content, Serializable { + /** The serialization UID (compatible with JDK1.5). */ + private static final long serialVersionUID = 4755994433709540381L; + // This is package-private to avoid an accessor method. char[] content; diff --git a/javax/swing/text/StyleConstants.java b/javax/swing/text/StyleConstants.java index 3f973f226..7d8f9bb63 100644 --- a/javax/swing/text/StyleConstants.java +++ b/javax/swing/text/StyleConstants.java @@ -109,7 +109,7 @@ public class StyleConstants if (a.isDefined(Background)) return (Color) a.getAttribute(Background); else - return Color.BLACK; + return Color.WHITE; } public static int getBidiLevel(AttributeSet a) diff --git a/javax/swing/text/StyleContext.java b/javax/swing/text/StyleContext.java index ae11622ff..eda13e744 100644 --- a/javax/swing/text/StyleContext.java +++ b/javax/swing/text/StyleContext.java @@ -57,9 +57,15 @@ import javax.swing.event.EventListenerList; public class StyleContext implements Serializable, AbstractDocument.AttributeContext { + /** The serialization UID (compatible with JDK1.5). */ + private static final long serialVersionUID = 8042858831190784241L; + public class NamedStyle implements Serializable, Style { + /** The serialization UID (compatible with JDK1.5). */ + private static final long serialVersionUID = -6690628971806226374L; + protected ChangeEvent changeEvent; protected EventListenerList listenerList; @@ -288,7 +294,7 @@ public class StyleContext public boolean equals(Object obj) { return - (obj instanceof SmallAttributeSet) + (obj instanceof AttributeSet) && this.isEqual((AttributeSet)obj); } diff --git a/javax/swing/text/StyledEditorKit.java b/javax/swing/text/StyledEditorKit.java index 89c4cf18e..e71f992b5 100644 --- a/javax/swing/text/StyledEditorKit.java +++ b/javax/swing/text/StyledEditorKit.java @@ -40,13 +40,9 @@ package javax.swing.text; import java.awt.Color; import java.awt.event.ActionEvent; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.io.Serializable; import javax.swing.Action; import javax.swing.JEditorPane; -import javax.swing.JTextPane; import javax.swing.event.CaretEvent; import javax.swing.event.CaretListener; @@ -460,11 +456,11 @@ public class StyledEditorKit extends DefaultEditorKit * <code>StyledEditorKit</code>, namely the following types of Elements: * * <ul> - * <li>{@link AbstractDocument.ContentElementName}</li> - * <li>{@link AbstractDocument.ParagraphElementName}</li> - * <li>{@link AbstractDocument.SectionElementName}</li> - * <li>{@link StyleContext.ComponentElementName}</li> - * <li>{@link StyleContext.IconElementName}</li> + * <li>{@link AbstractDocument#ContentElementName}</li> + * <li>{@link AbstractDocument#ParagraphElementName}</li> + * <li>{@link AbstractDocument#SectionElementName}</li> + * <li>{@link StyleConstants#ComponentElementName}</li> + * <li>{@link StyleConstants#IconElementName}</li> * </ul> */ static class StyledViewFactory @@ -667,11 +663,11 @@ public class StyledEditorKit extends DefaultEditorKit * namely the following types of <code>Element</code>s: * * <ul> - * <li>{@link AbstractDocument.ContentElementName}</li> - * <li>{@link AbstractDocument.ParagraphElementName}</li> - * <li>{@link AbstractDocument.SectionElementName}</li> - * <li>{@link StyleContext.ComponentElementName}</li> - * <li>{@link StyleContext.IconElementName}</li> + * <li>{@link AbstractDocument#ContentElementName}</li> + * <li>{@link AbstractDocument#ParagraphElementName}</li> + * <li>{@link AbstractDocument#SectionElementName}</li> + * <li>{@link StyleConstants#ComponentElementName}</li> + * <li>{@link StyleConstants#IconElementName}</li> * </ul> * * @return a {@link ViewFactory} that is able to create {@link View}s diff --git a/javax/swing/text/TabSet.java b/javax/swing/text/TabSet.java index 146f545aa..ecad9444e 100644 --- a/javax/swing/text/TabSet.java +++ b/javax/swing/text/TabSet.java @@ -41,6 +41,9 @@ import java.io.Serializable; public class TabSet implements Serializable { + /** The serialization UID (compatible with JDK1.5). */ + private static final long serialVersionUID = 2367703481999080593L; + TabStop[] tabs; public TabSet(TabStop[] t) diff --git a/javax/swing/text/TabStop.java b/javax/swing/text/TabStop.java index 032da8bca..56f862fda 100644 --- a/javax/swing/text/TabStop.java +++ b/javax/swing/text/TabStop.java @@ -41,6 +41,9 @@ import java.io.Serializable; public class TabStop implements Serializable { + /** The serialization UID (compatible with JDK1.5). */ + private static final long serialVersionUID = -5381995917363605058L; + public static final int ALIGN_LEFT = 0; public static final int ALIGN_RIGHT = 1; public static final int ALIGN_CENTER = 2; diff --git a/javax/swing/text/Utilities.java b/javax/swing/text/Utilities.java index d40408ddc..02d98c3b2 100644 --- a/javax/swing/text/Utilities.java +++ b/javax/swing/text/Utilities.java @@ -195,4 +195,89 @@ public class Utilities return maxWidth; } + + /** + * Provides a facility to map screen coordinates into a model location. For a + * given text fragment and start location within this fragment, this method + * determines the model location so that the resulting fragment fits best + * into the span <code>[x0, x]</code>. + * + * The parameter <code>round</code> controls which model location is returned + * if the view coordinates are on a character: If <code>round</code> is + * <code>true</code>, then the result is rounded up to the next character, so + * that the resulting fragment is the smallest fragment that is larger than + * the specified span. If <code>round</code> is <code>false</code>, then the + * resulting fragment is the largest fragment that is smaller than the + * specified span. + * + * @param s the text segment + * @param fm the font metrics to use + * @param x0 the starting screen location + * @param x the target screen location at which the requested fragment should + * end + * @param te the tab expander to use; if this is <code>null</code>, TABs are + * expanded to one space character + * @param p0 the starting model location + * @param round if <code>true</code> round up to the next location, otherwise + * round down to the current location + * + * @return the model location, so that the resulting fragment fits within the + * specified span + */ + public static final int getTabbedTextOffset(Segment s, FontMetrics fm, int x0, + int x, TabExpander te, int p0, + boolean round) + { + // At the end of the for loop, this holds the requested model location + int pos; + int currentX = x0; + for (pos = p0; pos < s.getEndIndex(); pos++) + { + char nextChar = s.array[pos]; + if (nextChar != '\n') + currentX += fm.charWidth(nextChar); + else + { + if (te == null) + currentX += fm.charWidth(' '); + else + currentX = (int) te.nextTabStop(currentX, pos); + } + if (currentX >= x) + { + if (! round) + pos--; + break; + } + } + return pos; + } + + /** + * Provides a facility to map screen coordinates into a model location. For a + * given text fragment and start location within this fragment, this method + * determines the model location so that the resulting fragment fits best + * into the span <code>[x0, x]</code>. + * + * This method rounds up to the next location, so that the resulting fragment + * will be the smallest fragment of the text, that is greater than the + * specified span. + * + * @param s the text segment + * @param fm the font metrics to use + * @param x0 the starting screen location + * @param x the target screen location at which the requested fragment should + * end + * @param te the tab expander to use; if this is <code>null</code>, TABs are + * expanded to one space character + * @param p0 the starting model location + * + * @return the model location, so that the resulting fragment fits within the + * specified span + */ + public static final int getTabbedTextOffset(Segment s, FontMetrics fm, int x0, + int x, TabExpander te, int p0) + { + return getTabbedTextOffset(s, fm, x0, x, te, p0, true); + } } diff --git a/javax/swing/text/View.java b/javax/swing/text/View.java index 24efba9a1..9cea4ecb0 100644 --- a/javax/swing/text/View.java +++ b/javax/swing/text/View.java @@ -43,7 +43,6 @@ import java.awt.Graphics; import java.awt.Rectangle; import java.awt.Shape; -import javax.swing.JComponent; import javax.swing.SwingConstants; import javax.swing.event.DocumentEvent; diff --git a/javax/swing/text/html/CSS.java b/javax/swing/text/html/CSS.java new file mode 100644 index 000000000..f02ceb89b --- /dev/null +++ b/javax/swing/text/html/CSS.java @@ -0,0 +1,426 @@ +/* CSS.java -- Provides CSS attributes + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ +package javax.swing.text.html; + +/** + * Provides CSS attributes to be used by the HTML view classes. The constants + * defined here are used as keys for text attributes for use in + * {@link javax.swing.text.AttributeSet}s of {@link javax.swing.text.Element}s. + * + * @author Roman Kennke (kennke@aicas.com) + */ +public class CSS +{ + + public static final class Attribute + { + /** + * The CSS attribute 'background'. + */ + public static final Attribute BACKGROUND = + new Attribute("background", false, null); + + /** + * The CSS attribute 'background-attachment'. + */ + public static final Attribute BACKGROUND_ATTACHMENT = + new Attribute("background-attachment", false, "scroll"); + + /** + * The CSS attribute 'background-color'. + */ + public static final Attribute BACKGROUND_COLOR = + new Attribute("background-color", false, "transparent"); + + /** + * The CSS attribute 'background-image'. + */ + public static final Attribute BACKGROUND_IMAGE = + new Attribute("background-image", false, "none"); + + /** + * The CSS attribute 'background-position'. + */ + public static final Attribute BACKGROUND_POSITION = + new Attribute("background-position", false, null); + + /** + * The CSS attribute 'background-repeat'. + */ + public static final Attribute BACKGROUND_REPEAT = + new Attribute("background-repeat", false, "repeat"); + + /** + * The CSS attribute 'border'. + */ + public static final Attribute BORDER = new Attribute("border", false, null); + + /** + * The CSS attribute 'border-bottom'. + */ + public static final Attribute BORDER_BOTTOM = + new Attribute("border-bottom", false, null); + + /** + * The CSS attribute 'border-bottom-width'. + */ + public static final Attribute BORDER_BOTTOM_WIDTH = + new Attribute("border-bottom-width", false, "medium"); + + /** + * The CSS attribute 'border-color'. + */ + public static final Attribute BORDER_COLOR = + new Attribute("border-color", false, "black"); + + /** + * The CSS attribute 'border-left'. + */ + public static final Attribute BORDER_LEFT = + new Attribute("border-left", false, null); + + /** + * The CSS attribute 'border-left-width'. + */ + public static final Attribute BORDER_LEFT_WIDTH = + new Attribute("border-left-width", false, "medium"); + + /** + * The CSS attribute 'border-right'. + */ + public static final Attribute BORDER_RIGHT = + new Attribute("border-right", false, null); + + /** + * The CSS attribute 'border-right-width'. + */ + public static final Attribute BORDER_RIGHT_WIDTH = + new Attribute("border-right-width", false, "medium"); + + /** + * The CSS attribute 'border-style'. + */ + public static final Attribute BORDER_STYLE = + new Attribute("border-style", false, "none"); + + /** + * The CSS attribute 'border-top'. + */ + public static final Attribute BORDER_TOP = + new Attribute("border-top", false, null); + + /** + * The CSS attribute 'border-top-width'. + */ + public static final Attribute BORDER_TOP_WIDTH = + new Attribute("border-top-width", false, "medium"); + + /** + * The CSS attribute 'border-width'. + */ + public static final Attribute BORDER_WIDTH = + new Attribute("border-width", false, "medium"); + + /** + * The CSS attribute 'clear'. + */ + public static final Attribute CLEAR = new Attribute("clear", false, "none"); + + /** + * The CSS attribute 'color'. + */ + public static final Attribute COLOR = new Attribute("color", true, "black"); + + /** + * The CSS attribute 'display'. + */ + public static final Attribute DISPLAY = + new Attribute("display", false, "block"); + + /** + * The CSS attribute 'float'. + */ + public static final Attribute FLOAT = new Attribute("float", false, "none"); + + /** + * The CSS attribute 'font'. + */ + public static final Attribute FONT = new Attribute("font", true, null); + + /** + * The CSS attribute 'font-family'. + */ + public static final Attribute FONT_FAMILY = + new Attribute("font-family", true, null); + + /** + * The CSS attribute 'font-size'. + */ + public static final Attribute FONT_SIZE = + new Attribute("font-size", true, "medium"); + + /** + * The CSS attribute 'font-style'. + */ + public static final Attribute FONT_STYLE = + new Attribute("font-style", true, "normal"); + + /** + * The CSS attribute 'font-variant'. + */ + public static final Attribute FONT_VARIANT = + new Attribute("font-variant", true, "normal"); + + /** + * The CSS attribute 'font-weight'. + */ + public static final Attribute FONT_WEIGHT = + new Attribute("font-weight", true, "normal"); + + /** + * The CSS attribute 'height'. + */ + public static final Attribute HEIGHT = + new Attribute("height", false, "auto"); + + /** + * The CSS attribute 'letter-spacing'. + */ + public static final Attribute LETTER_SPACING = + new Attribute("letter-spacing", true, "normal"); + + /** + * The CSS attribute 'line-height'. + */ + public static final Attribute LINE_HEIGHT = + new Attribute("line-height", true, "normal"); + + /** + * The CSS attribute 'list-style'. + */ + public static final Attribute LIST_STYLE = + new Attribute("list-style", true, null); + + /** + * The CSS attribute 'list-style-image'. + */ + public static final Attribute LIST_STYLE_IMAGE = + new Attribute("list-style-image", true, "none"); + + /** + * The CSS attribute 'list-style-position'. + */ + public static final Attribute LIST_STYLE_POSITION = + new Attribute("list-style-position", true, "outside"); + + /** + * The CSS attribute 'list-style-type'. + */ + public static final Attribute LIST_STYLE_TYPE = + new Attribute("list-style-type", true, "disc"); + + /** + * The CSS attribute 'margin'. + */ + public static final Attribute MARGIN = new Attribute("margin", false, null); + + /** + * The CSS attribute 'margin-bottom'. + */ + public static final Attribute MARGIN_BOTTOM = + new Attribute("margin-bottom", false, "0"); + + /** + * The CSS attribute 'margin-left'. + */ + public static final Attribute MARGIN_LEFT = + new Attribute("margin-left", false, "0"); + + /** + * The CSS attribute 'margin-right'. + */ + public static final Attribute MARGIN_RIGHT = + new Attribute("margin-right", false, "0"); + + /** + * The CSS attribute 'margin-top'. + */ + public static final Attribute MARGIN_TOP = + new Attribute("margin-top", false, "0"); + + /** + * The CSS attribute 'padding'. + */ + public static final Attribute PADDING = + new Attribute("padding", false, null); + + /** + * The CSS attribute 'padding-bottom'. + */ + public static final Attribute PADDING_BOTTOM = + new Attribute("padding-bottom", false, "0"); + + /** + * The CSS attribute 'padding-left'. + */ + public static final Attribute PADDING_LEFT = + new Attribute("padding-left", false, "0"); + + /** + * The CSS attribute 'padding-right'. + */ + public static final Attribute PADDING_RIGHT = + new Attribute("padding-right", false, "0"); + + /** + * The CSS attribute 'padding-top'. + */ + public static final Attribute PADDING_TOP = + new Attribute("padding-top", false, "0"); + + /** + * The CSS attribute 'text-align'. + */ + public static final Attribute TEXT_ALIGN = + new Attribute("text-align", true, null); + + /** + * The CSS attribute 'text-decoration'. + */ + public static final Attribute TEXT_DECORATION = + new Attribute("text-decoration", true, "none"); + + /** + * The CSS attribute 'text-indent'. + */ + public static final Attribute TEXT_INDENT = + new Attribute("text-indent", true, "0"); + + /** + * The CSS attribute 'text-transform'. + */ + public static final Attribute TEXT_TRANSFORM = + new Attribute("text-transform", true, "none"); + + /** + * The CSS attribute 'vertical-align'. + */ + public static final Attribute VERTICAL_ALIGN = + new Attribute("vertical-align", false, "baseline"); + + /** + * The CSS attribute 'white-space'. + */ + public static final Attribute WHITE_SPACE = + new Attribute("white-space", true, "normal"); + + /** + * The CSS attribute 'width'. + */ + public static final Attribute WIDTH = + new Attribute("width", false, "auto"); + + /** + * The CSS attribute 'word-spacing'. + */ + public static final Attribute WORD_SPACING = + new Attribute("word-spacing", true, "normal"); + + /** + * The attribute string. + */ + String attStr; + + /** + * Indicates if this attribute should be inherited from it's parent or + * not. + */ + boolean isInherited; + + /** + * A default value for this attribute if one exists, otherwise null. + */ + String defaultValue; + + /** + * Creates a new Attribute instance with the specified values. + * + * @param attr the attribute string + * @param inherited if the attribute should be inherited or not + * @param def a default value; may be <code>null</code> + */ + Attribute(String attr, boolean inherited, String def) + { + attStr = attr; + isInherited = inherited; + defaultValue = def; + } + + /** + * Returns the string representation of this attribute as specified + * in the CSS specification. + */ + public String toString() + { + return attStr; + } + + /** + * Returns <code>true</code> if the attribute should be inherited from + * the parent, <code>false</code> otherwise. + * + * @return <code>true</code> if the attribute should be inherited from + * the parent, <code>false</code> otherwise + */ + public boolean isInherited() + { + return isInherited; + } + + /** + * Returns the default value of this attribute if one exists, + * <code>null</code> otherwise. + * + * @return the default value of this attribute if one exists, + * <code>null</code> otherwise + */ + public String getDefaultValue() + { + return defaultValue; + } + } +} diff --git a/javax/swing/text/html/parser/DTD.java b/javax/swing/text/html/parser/DTD.java index f17ca011e..1ede342de 100644 --- a/javax/swing/text/html/parser/DTD.java +++ b/javax/swing/text/html/parser/DTD.java @@ -81,8 +81,9 @@ public class DTD { /** * The version of the persistent data format. + * @specnote This was made <code>final</code> in 1.5. */ - public static int FILE_VERSION = 1; + public static final int FILE_VERSION = 1; /** * The table of existing available DTDs. diff --git a/javax/swing/tree/DefaultTreeCellEditor.java b/javax/swing/tree/DefaultTreeCellEditor.java index 7a44e7383..91096ad19 100644 --- a/javax/swing/tree/DefaultTreeCellEditor.java +++ b/javax/swing/tree/DefaultTreeCellEditor.java @@ -513,6 +513,8 @@ public class DefaultTreeCellEditor // Cell may not be currently editable, but may need to start timer. if (shouldStartEditingTimer(event)) startEditingTimer(); + else if (timer.isRunning()) + timer.stop(); return false; } diff --git a/javax/xml/transform/TransformerConfigurationException.java b/javax/xml/transform/TransformerConfigurationException.java index b2153c2cb..81db3bed9 100644 --- a/javax/xml/transform/TransformerConfigurationException.java +++ b/javax/xml/transform/TransformerConfigurationException.java @@ -45,9 +45,8 @@ package javax.xml.transform; public class TransformerConfigurationException extends TransformerException { + private static final long serialVersionUID = 1285547467942875745L; - private SourceLocator locator; - /** * Constructor with no detail message. */ @@ -96,8 +95,7 @@ public class TransformerConfigurationException SourceLocator locator, Throwable e) { - super(message, e); - this.locator = locator; + super(message, locator, e); } } diff --git a/javax/xml/transform/TransformerException.java b/javax/xml/transform/TransformerException.java index a72ee1c2f..3d97eda1b 100644 --- a/javax/xml/transform/TransformerException.java +++ b/javax/xml/transform/TransformerException.java @@ -47,9 +47,11 @@ import java.io.PrintWriter; public class TransformerException extends Exception { + private static final long serialVersionUID = 975798773772956428L; + // Field names fixed by serialization spec. private SourceLocator locator; - private Throwable cause; + private Throwable containedException; /** * Constructor with a detail message. @@ -94,7 +96,7 @@ public class TransformerException if (cause != null) { initCause(cause); - this.cause = cause; + this.containedException = cause; } } @@ -119,7 +121,7 @@ public class TransformerException */ public Throwable getException() { - return cause; + return containedException; } /** @@ -127,7 +129,7 @@ public class TransformerException */ public Throwable getCause() { - return cause; + return containedException; } /** @@ -143,7 +145,7 @@ public class TransformerException */ public Throwable initCause(Throwable cause) { - if (this.cause != null) + if (this.containedException != null) { throw new IllegalStateException(); } @@ -151,7 +153,7 @@ public class TransformerException { throw new IllegalArgumentException(); } - this.cause = cause; + this.containedException = cause; return this; } @@ -221,20 +223,20 @@ public class TransformerException public void printStackTrace(PrintStream s) { super.printStackTrace(s); - if (cause != null) + if (containedException != null) { s.print("caused by "); - cause.printStackTrace(s); + containedException.printStackTrace(s); } } public void printStackTrace(PrintWriter s) { super.printStackTrace(s); - if (cause != null) + if (containedException != null) { s.print("caused by "); - cause.printStackTrace(s); + containedException.printStackTrace(s); } } diff --git a/javax/xml/transform/TransformerFactoryConfigurationError.java b/javax/xml/transform/TransformerFactoryConfigurationError.java index 9b16b2b2e..82afeeac7 100644 --- a/javax/xml/transform/TransformerFactoryConfigurationError.java +++ b/javax/xml/transform/TransformerFactoryConfigurationError.java @@ -44,7 +44,9 @@ package javax.xml.transform; public class TransformerFactoryConfigurationError extends Error { + private static final long serialVersionUID = -6527718720676281516L; + // Name is fixed by the serialization spec. private final Exception exception; /** diff --git a/javax/xml/xpath/XPathException.java b/javax/xml/xpath/XPathException.java index 030d0a9c1..cf004c179 100644 --- a/javax/xml/xpath/XPathException.java +++ b/javax/xml/xpath/XPathException.java @@ -49,7 +49,9 @@ import java.io.PrintWriter; public class XPathException extends Exception { + private static final long serialVersionUID = -1837080260374986980L; + // Name is fixed by serialization spec. Throwable cause; public XPathException(String message) diff --git a/javax/xml/xpath/XPathExpressionException.java b/javax/xml/xpath/XPathExpressionException.java index 91716f150..6257adb47 100644 --- a/javax/xml/xpath/XPathExpressionException.java +++ b/javax/xml/xpath/XPathExpressionException.java @@ -46,6 +46,7 @@ package javax.xml.xpath; public class XPathExpressionException extends XPathException { + private static final long serialVersionUID = -1837080260374986980L; public XPathExpressionException(String message) { diff --git a/javax/xml/xpath/XPathFactoryConfigurationException.java b/javax/xml/xpath/XPathFactoryConfigurationException.java index a89646336..0fc68a763 100644 --- a/javax/xml/xpath/XPathFactoryConfigurationException.java +++ b/javax/xml/xpath/XPathFactoryConfigurationException.java @@ -46,6 +46,7 @@ package javax.xml.xpath; public class XPathFactoryConfigurationException extends XPathException { + private static final long serialVersionUID = -1837080260374986980L; public XPathFactoryConfigurationException(String message) { diff --git a/javax/xml/xpath/XPathFunctionException.java b/javax/xml/xpath/XPathFunctionException.java index ebc8ce7d3..db680ae65 100644 --- a/javax/xml/xpath/XPathFunctionException.java +++ b/javax/xml/xpath/XPathFunctionException.java @@ -46,6 +46,7 @@ package javax.xml.xpath; public class XPathFunctionException extends XPathExpressionException { + private static final long serialVersionUID = -1837080260374986980L; public XPathFunctionException(String message) { diff --git a/lib/Makefile.am b/lib/Makefile.am index 949289b5e..9244bd142 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -32,7 +32,7 @@ if FOUND_GCJX JAVAC = $(GCJX) -encoding UTF-8 -classpath .:$(USER_CLASSLIB) -d . @classes else if FOUND_ECJ -JAVAC = $(ECJ) -encoding UTF-8 -warn:none -proceedOnError -bootclasspath '' -classpath $(compile_classpath) -d . @classes +JAVAC = $(ECJ) -source 1.4 -encoding UTF-8 -warn:none -proceedOnError -bootclasspath '' -classpath $(compile_classpath) -d . @classes endif # FOUND_ECJ endif # FOUND_GCJX endif # FOUND_KJC diff --git a/lib/gen-classlist.sh.in b/lib/gen-classlist.sh.in index 12845f2cc..b22deced4 100755 --- a/lib/gen-classlist.sh.in +++ b/lib/gen-classlist.sh.in @@ -2,6 +2,8 @@ # @configure_input@ # Make sure sorting is done the same on all configurations +# Note the use of sort -r below. This is done explicitly to work around +# a gcj bug (http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21418) LC_ALL=C; export LC_ALL LANG=C; export LANG @@ -12,7 +14,7 @@ echo "Adding java source files from srcdir '@top_srcdir@'." @FIND@ @top_srcdir@/java @top_srcdir@/javax @top_srcdir@/gnu \ @top_srcdir@/org \ @top_srcdir@/external/w3c_dom @top_srcdir@/external/sax \ - -follow -type f -print | sort | grep '\.java$' \ + -follow -type f -print | sort -r | grep '\.java$' \ > ${top_builddir}/lib/classes.1 # Generate files for the VM classes. diff --git a/lib/standard.omit b/lib/standard.omit index c95c4ed95..a518f7df8 100644 --- a/lib/standard.omit +++ b/lib/standard.omit @@ -1,4 +1 @@ ../gnu/test/.*$ -../gnu/classpath/jdwp/.*$ -../gnu/xml/stream/.*$ -../javax/xml/stream/.*$ diff --git a/m4/acinclude.m4 b/m4/acinclude.m4 index e05a2f8e7..e41321f89 100644 --- a/m4/acinclude.m4 +++ b/m4/acinclude.m4 @@ -63,48 +63,23 @@ AC_DEFUN([CLASSPATH_CHECK_GCJ], else AC_PATH_PROG(GCJ, "gcj") fi - + dnl Test the given GCJ, but use it as C (!) compiler to check version if test "x$GCJ" != x; then - ## GCC version 2 puts out version messages that looked like: - ## 2.95 - - ## GCC version 3 puts out version messages like: - ## gcj (GCC) 3.3.3 - ## Copyright (C) 2003 Free Software Foundation, Inc. - ## This is free software; see the source for copying conditions. There is NO - ## warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - AC_MSG_CHECKING(gcj version) - ## Take the output from gcj --version and extract just the version number - ## into GCJ_VERSION. - ## (we need to do this to be compatible with both GCC 2 and GCC 3 version - ## numbers) - ## - ## First, we get rid of everything before the first number on that line. - ## Assume that the first number on that line is the start of the - ## version. - ## - ## Second, while we're at it, go ahead and get rid of the first character - ## that is not part of a version number (i.e., is neither a digit nor - ## a dot). - ## - ## Third, quit, so that we won't process the second and subsequent lines. - GCJ_VERSION=`$GCJ --version | sed -e 's/^@<:@^0-9@:>@*//' -e 's/@<:@^.0-9@:>@@<:@^.0-9@:>@*//' -e 'q'` - GCJ_VERSION_MAJOR=`echo "$GCJ_VERSION" | cut -d '.' -f 1` - GCJ_VERSION_MINOR=`echo "$GCJ_VERSION" | cut -d '.' -f 2` - - if expr "$GCJ_VERSION_MAJOR" \< 3 > /dev/null; then - GCJ="" - fi - if expr "$GCJ_VERSION_MAJOR" = 3 > /dev/null; then - if expr "$GCJ_VERSION_MINOR" \< 3; then - GCJ="" - fi - fi - if test "x$GCJ" != x; then - AC_MSG_RESULT($GCJ_VERSION) + AC_MSG_CHECKING([gcj version 4.0]) + AC_LANG_PUSH([C]) + AC_LANG_CONFTEST( + [[#if __GNUC__ <= 3 + #error GCJ 4.0.0 or higher is required + #endif + ]]) + $GCJ -E conftest.c > /dev/null + gcj_4_result=$? + if test "x$gcj_4_result" = "x0"; then + AC_MSG_RESULT([4.0 or higher found]) else - AC_MSG_WARN($GCJ_VERSION: gcj 3.3 or higher required) + AC_MSG_WARN([4.0 or higher required]) fi + AC_LANG_POP fi ]) diff --git a/native/fdlibm/mprec.h b/native/fdlibm/mprec.h index d796b81de..f250619b0 100644 --- a/native/fdlibm/mprec.h +++ b/native/fdlibm/mprec.h @@ -291,7 +291,12 @@ extern double rnd_prod(double, double), rnd_quot(double, double); #define MAX_BIGNUMS 16 +#ifdef Pack_32 #define MAX_BIGNUM_WDS 32 +#else + /* Note that this is a workaround for */ +#define MAX_BIGNUM_WDS 128 +#endif struct _Jv_Bigint { diff --git a/native/jawt/jawt.c b/native/jawt/jawt.c index 6d26a0da9..a41786850 100644 --- a/native/jawt/jawt.c +++ b/native/jawt/jawt.c @@ -176,11 +176,11 @@ static void static void (JNICALL _Jv_AWTLock) (JNIEnv* env __attribute__((unused))) { - classpath_jawt_lock (); + /* FIXME: what is this supposed to do? */ } static void (JNICALL _Jv_AWTUnlock) (JNIEnv* env __attribute__((unused))) { - classpath_jawt_unlock (); + /* FIXME: what is this supposed to do? */ } diff --git a/native/jni/classpath/jcl.c b/native/jni/classpath/jcl.c index 4821770ed..aacbe8900 100644 --- a/native/jni/classpath/jcl.c +++ b/native/jni/classpath/jcl.c @@ -1,5 +1,5 @@ /* jcl.c - Copyright (C) 1998 Free Software Foundation, Inc. + Copyright (C) 1998, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -193,7 +193,8 @@ JCL_NewRawDataObject (JNIEnv * env, void *data) { if (rawDataClass == NULL) { -#ifdef POINTERS_ARE_64BIT + jclass tmp; +#if SIZEOF_VOID_P == 8 rawDataClass = (*env)->FindClass (env, "gnu/classpath/Pointer64"); if (rawDataClass == NULL) { @@ -243,17 +244,18 @@ JCL_NewRawDataObject (JNIEnv * env, void *data) } #endif - (*env)->DeleteLocalRef(env, rawDataClass); - rawDataClass = (*env)->NewGlobalRef (env, rawDataClass); - if (rawDataClass == NULL) + tmp = (*env)->NewGlobalRef (env, rawDataClass); + if (tmp == NULL) { JCL_ThrowException (env, "java/lang/InternalError", "unable to create an internal global ref"); return NULL; } + (*env)->DeleteLocalRef(env, rawDataClass); + rawDataClass = tmp; } -#ifdef POINTERS_ARE_64BIT +#if SIZEOF_VOID_P == 8 return (*env)->NewObject (env, rawDataClass, rawData_mid, (jlong) data); #else return (*env)->NewObject (env, rawDataClass, rawData_mid, (jint) data); @@ -263,7 +265,7 @@ JCL_NewRawDataObject (JNIEnv * env, void *data) JNIEXPORT void * JNICALL JCL_GetRawData (JNIEnv * env, jobject rawdata) { -#ifdef POINTERS_ARE_64BIT +#if SIZEOF_VOID_P == 8 return (void *) (*env)->GetLongField (env, rawdata, rawData_fid); #else return (void *) (*env)->GetIntField (env, rawdata, rawData_fid); diff --git a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkFontPeer.c b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkFontPeer.c index 6f2a1ae72..ce65a1994 100644 --- a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkFontPeer.c +++ b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkFontPeer.c @@ -98,7 +98,7 @@ Java_gnu_java_awt_peer_gtk_GdkFontPeer_dispose pfont = (struct peerfont *)NSA_DEL_FONT_PTR (env, self); g_assert (pfont != NULL); if (pfont->layout != NULL) - g_object_unref (pfont->font); + g_object_unref (pfont->layout); if (pfont->font != NULL) g_object_unref (pfont->font); if (pfont->ctx != NULL) diff --git a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c index f832da5a4..684deeb84 100644 --- a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c +++ b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c @@ -56,10 +56,6 @@ exception statement from your version. */ #define AWT_HAND_CURSOR 12 #define AWT_MOVE_CURSOR 13 -#define AWT_BUTTON1_DOWN_MASK (1 << 10) -#define AWT_BUTTON2_DOWN_MASK (1 << 11) -#define AWT_BUTTON3_DOWN_MASK (1 << 12) - /* FIXME: use gtk-double-click-time, gtk-double-click-distance */ #define MULTI_CLICK_TIME 250 /* as opposed to a MULTI_PASS_TIME :) */ @@ -135,11 +131,11 @@ button_to_awt_mods (int button) switch (button) { case 1: - return AWT_BUTTON1_MASK; + return AWT_BUTTON1_DOWN_MASK | AWT_BUTTON1_MASK; case 2: - return AWT_BUTTON2_MASK; + return AWT_BUTTON2_DOWN_MASK | AWT_BUTTON2_MASK; case 3: - return AWT_BUTTON3_MASK; + return AWT_BUTTON3_DOWN_MASK | AWT_BUTTON3_MASK; } return 0; @@ -151,11 +147,11 @@ cp_gtk_state_to_awt_mods (guint state) jint result = 0; if (state & GDK_SHIFT_MASK) - result |= AWT_SHIFT_DOWN_MASK; + result |= (AWT_SHIFT_DOWN_MASK | AWT_SHIFT_MASK); if (state & GDK_CONTROL_MASK) - result |= AWT_CTRL_DOWN_MASK; + result |= (AWT_CTRL_DOWN_MASK | AWT_CTRL_MASK); if (state & GDK_MOD1_MASK) - result |= AWT_ALT_DOWN_MASK; + result |= (AWT_ALT_DOWN_MASK | AWT_ALT_MASK); return result; } @@ -166,13 +162,13 @@ state_to_awt_mods_with_button_states (guint state) jint result = 0; if (state & GDK_SHIFT_MASK) - result |= AWT_SHIFT_DOWN_MASK; + result |= AWT_SHIFT_DOWN_MASK | AWT_SHIFT_MASK; if (state & GDK_CONTROL_MASK) - result |= AWT_CTRL_DOWN_MASK; + result |= AWT_CTRL_DOWN_MASK | AWT_CTRL_MASK; if (state & GDK_MOD1_MASK) - result |= AWT_ALT_DOWN_MASK; + result |= AWT_ALT_DOWN_MASK | AWT_ALT_MASK; if (state & GDK_BUTTON1_MASK) - result |= AWT_BUTTON1_DOWN_MASK; + result |= AWT_BUTTON1_DOWN_MASK | AWT_BUTTON1_MASK; if (state & GDK_BUTTON2_MASK) result |= AWT_BUTTON2_DOWN_MASK; if (state & GDK_BUTTON3_MASK) @@ -766,7 +762,10 @@ Java_gnu_java_awt_peer_gtk_GtkComponentPeer_isRealized ptr = NSA_GET_PTR (env, obj); if (ptr == NULL) - return FALSE; + { + gdk_threads_leave (); + return FALSE; + } ret_val = GTK_WIDGET_REALIZED (GTK_WIDGET (ptr)); diff --git a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c index 0f623d165..e5262957e 100644 --- a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c +++ b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c @@ -952,29 +952,29 @@ keyevent_state_to_awt_mods (GdkEventKey *event) if (event->keyval == GDK_Shift_L || event->keyval == GDK_Shift_R) - result |= AWT_SHIFT_DOWN_MASK; + result |= AWT_SHIFT_DOWN_MASK | AWT_SHIFT_MASK; else { if (state & GDK_SHIFT_MASK) - result |= AWT_SHIFT_DOWN_MASK; + result |= AWT_SHIFT_DOWN_MASK | AWT_SHIFT_MASK; } if (event->keyval == GDK_Control_L || event->keyval == GDK_Control_R) - result |= AWT_CTRL_DOWN_MASK; + result |= AWT_CTRL_DOWN_MASK | AWT_CTRL_MASK; else { if (state & GDK_CONTROL_MASK) - result |= AWT_CTRL_DOWN_MASK; + result |= AWT_CTRL_DOWN_MASK | AWT_CTRL_MASK; } if (event->keyval == GDK_Alt_L || event->keyval == GDK_Alt_R) - result |= AWT_ALT_DOWN_MASK; + result |= AWT_ALT_DOWN_MASK | AWT_ALT_MASK; else { if (state & GDK_MOD1_MASK) - result |= AWT_ALT_DOWN_MASK; + result |= AWT_ALT_DOWN_MASK | AWT_ALT_MASK; } } else if (event->type == GDK_KEY_RELEASE) @@ -985,20 +985,20 @@ keyevent_state_to_awt_mods (GdkEventKey *event) && event->keyval != GDK_Shift_R) { if (state & GDK_SHIFT_MASK) - result |= AWT_SHIFT_DOWN_MASK; + result |= AWT_SHIFT_DOWN_MASK | AWT_SHIFT_MASK; } if (event->keyval != GDK_Control_L && event->keyval != GDK_Control_R) { if (state & GDK_CONTROL_MASK) - result |= AWT_CTRL_DOWN_MASK; + result |= AWT_CTRL_DOWN_MASK | AWT_CTRL_MASK; } if (event->keyval != GDK_Alt_L && event->keyval != GDK_Alt_R) { if (state & GDK_MOD1_MASK) - result |= AWT_ALT_DOWN_MASK; + result |= AWT_ALT_DOWN_MASK | AWT_ALT_MASK; } } @@ -1028,9 +1028,6 @@ static gboolean window_delete_cb (GtkWidget *widget, GdkEvent *event, static void window_destroy_cb (GtkWidget *widget, GdkEvent *event, jobject peer); static void window_show_cb (GtkWidget *widget, jobject peer); -static void window_active_state_change_cb (GtkWidget *widget, - GParamSpec *pspec, - jobject peer); static void window_focus_state_change_cb (GtkWidget *widget, GParamSpec *pspec, jobject peer); @@ -1043,7 +1040,6 @@ static gboolean window_focus_out_cb (GtkWidget * widget, static gboolean window_window_state_cb (GtkWidget *widget, GdkEvent *event, jobject peer); -static jint window_get_new_state (GtkWidget *widget); static gboolean window_property_changed_cb (GtkWidget *widget, GdkEventProperty *event, jobject peer); @@ -1278,9 +1274,6 @@ Java_gnu_java_awt_peer_gtk_GtkWindowPeer_connectSignals g_signal_connect (G_OBJECT (ptr), "show", G_CALLBACK (window_show_cb), *gref); - g_signal_connect (G_OBJECT (ptr), "notify::is-active", - G_CALLBACK (window_active_state_change_cb), *gref); - g_signal_connect (G_OBJECT (ptr), "notify::has-toplevel-focus", G_CALLBACK (window_focus_state_change_cb), *gref); @@ -1592,31 +1585,6 @@ window_show_cb (GtkWidget *widget __attribute__((unused)), } static void -window_active_state_change_cb (GtkWidget *widget __attribute__((unused)), - GParamSpec *pspec __attribute__((unused)), - jobject peer __attribute__((unused))) -{ - /* FIXME: not sure if this is needed or not. */ - /* Remove the unused attributes if you fix the below. */ -#if 0 - gdk_threads_leave (); - - if (GTK_WINDOW (widget)->is_active) - (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, - postWindowEventID, - (jint) AWT_WINDOW_GAINED_FOCUS, - (jobject) NULL, (jint) 0); - else - (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, - postWindowEventID, - (jint) AWT_WINDOW_DEACTIVATED, - (jobject) NULL, (jint) 0); - - gdk_threads_enter (); -#endif -} - -static void window_focus_state_change_cb (GtkWidget *widget, GParamSpec *pspec __attribute__((unused)), jobject peer) @@ -1660,7 +1628,7 @@ window_focus_out_cb (GtkWidget * widget __attribute__((unused)), } static gboolean -window_window_state_cb (GtkWidget *widget, +window_window_state_cb (GtkWidget *widget __attribute__((unused)), GdkEvent *event, jobject peer) { @@ -1695,8 +1663,6 @@ window_window_state_cb (GtkWidget *widget, if (event->window_state.new_window_state & GDK_WINDOW_STATE_ICONIFIED) new_state |= AWT_FRAME_STATE_ICONIFIED; - new_state |= window_get_new_state (widget); - (*cp_gtk_gdk_env())->CallVoidMethod (cp_gtk_gdk_env(), peer, postWindowEventID, (jint) AWT_WINDOW_STATE_CHANGED, @@ -1705,47 +1671,6 @@ window_window_state_cb (GtkWidget *widget, return TRUE; } -static jint -window_get_new_state (GtkWidget *widget) -{ - GdkDisplay *display = gtk_widget_get_display(widget); - jint new_state = AWT_FRAME_STATE_NORMAL; - Atom type; - gint format; - gulong atom_count; - gulong bytes_after; - Atom *atom_list = NULL; - union atom_list_union alu; - gulong i; - - alu.atom_list = &atom_list; - XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), - GDK_WINDOW_XID (widget->window), - gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"), - 0, G_MAXLONG, False, XA_ATOM, &type, &format, &atom_count, - &bytes_after, alu.gu_extents); - - if (type != None) - { - Atom maxvert = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_MAXIMIZED_VERT"); - Atom maxhorz = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_MAXIMIZED_HORZ"); - - i = 0; - while (i < atom_count) - { - if (atom_list[i] == maxhorz) - new_state |= AWT_FRAME_STATE_MAXIMIZED_HORIZ; - else if (atom_list[i] == maxvert) - new_state |= AWT_FRAME_STATE_MAXIMIZED_VERT; - - ++i; - } - - XFree (atom_list); - } - return new_state; -} - static gboolean window_property_changed_cb (GtkWidget *widget __attribute__((unused)), GdkEventProperty *event, diff --git a/native/jni/gtk-peer/gtkpeer.h b/native/jni/gtk-peer/gtkpeer.h index 2b16d99b4..f332b62a1 100644 --- a/native/jni/gtk-peer/gtkpeer.h +++ b/native/jni/gtk-peer/gtkpeer.h @@ -111,15 +111,26 @@ struct graphics jint x_offset, y_offset; }; +/* New-style event masks. */ +#define AWT_BUTTON1_DOWN_MASK (1 << 10) +#define AWT_BUTTON2_DOWN_MASK (1 << 11) +#define AWT_BUTTON3_DOWN_MASK (1 << 12) + #define AWT_SHIFT_DOWN_MASK (1 << 6) #define AWT_CTRL_DOWN_MASK (1 << 7) #define AWT_META_DOWN_MASK (1 << 8) #define AWT_ALT_DOWN_MASK (1 << 9) +/* Old-style event masks. */ #define AWT_BUTTON1_MASK (1 << 4) #define AWT_BUTTON2_MASK (1 << 3) #define AWT_BUTTON3_MASK (1 << 2) +#define AWT_SHIFT_MASK (1 << 0) +#define AWT_CTRL_MASK (1 << 1) +#define AWT_META_MASK (1 << 2) +#define AWT_ALT_MASK (1 << 3) + #define AWT_ITEM_SELECTED 1 #define AWT_ITEM_DESELECTED 2 diff --git a/native/jni/java-net/java_net_VMInetAddress.c b/native/jni/java-net/java_net_VMInetAddress.c index d33265cff..0ba00d1c3 100644 --- a/native/jni/java-net/java_net_VMInetAddress.c +++ b/native/jni/java-net/java_net_VMInetAddress.c @@ -181,7 +181,8 @@ Java_java_net_VMInetAddress_getHostByAddr (JNIEnv * env, sizeof (hostname), result); if (result != TARGET_NATIVE_OK) { - JCL_ThrowException (env, UNKNOWN_HOST_EXCEPTION, "Bad IP address"); + JCL_ThrowException (env, UNKNOWN_HOST_EXCEPTION, + TARGET_NATIVE_LAST_ERROR_STRING ()); return (jstring) NULL; } diff --git a/native/jni/java-net/javanet.c b/native/jni/java-net/javanet.c index fdc1c22ec..51c58a921 100644 --- a/native/jni/java-net/javanet.c +++ b/native/jni/java-net/javanet.c @@ -857,7 +857,7 @@ _javanet_accept (JNIEnv * env, jobject this, jobject impl) != TARGET_NATIVE_ERROR_INTERRUPT_FUNCTION_CALL)) { JCL_ThrowException (env, IO_EXCEPTION, - "Internal error: _javanet_accept(): "); + TARGET_NATIVE_LAST_ERROR_STRING ()); return; } } @@ -1542,8 +1542,7 @@ _javanet_shutdownInput (JNIEnv * env, jobject this) /* Shutdown input stream of socket. */ if (shutdown (fd, SHUT_RD) == -1) { - JCL_ThrowException (env, SOCKET_EXCEPTION, - "Can't shutdown input of socket"); + JCL_ThrowException (env, SOCKET_EXCEPTION, strerror (errno)); return; } } @@ -1568,8 +1567,7 @@ _javanet_shutdownOutput (JNIEnv * env, jobject this) /* Shutdown output stream of socket. */ if (shutdown (fd, SHUT_WR) == -1) { - JCL_ThrowException (env, SOCKET_EXCEPTION, - "Can't shutdown output of socket"); + JCL_ThrowException (env, SOCKET_EXCEPTION, strerror (errno)); return; } } diff --git a/org/ietf/jgss/GSSException.java b/org/ietf/jgss/GSSException.java index 5443f766c..9c352e3e9 100644 --- a/org/ietf/jgss/GSSException.java +++ b/org/ietf/jgss/GSSException.java @@ -1,5 +1,5 @@ /* GSSException.java -- a general exception in GSS. - Copyright (C) 2004 Free Software Foundation, Inc. + Copyright (C) 2004, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -79,6 +79,9 @@ import java.util.ResourceBundle; * the caller, this class performs the mapping from their numeric values * to textual representations. All Java GSS-API methods are declared * throwing this exception. + * + * @specnote Some of the constant values defined in this class were + * chosen to be compatible with J2SE 1.4, and not with RFC 2853. */ public class GSSException extends Exception { @@ -90,28 +93,29 @@ public class GSSException extends Exception // Constants and fields. // ------------------------------------------------------------------------- - // These values do not jive with the "Constant Field Values" in the J2SE - // 1.4.1, but do follow RFC 2853. I trust the IETF, but not Sun. - /** * Channel bindings mismatch error. + * @specnote Should be 4 according to RFC 2853. */ - public static final int BAD_BINDINGS = 4; + public static final int BAD_BINDINGS = 1; /** * Unsupported mechanism requested error. + * @specnote Should be 1 according to RFC 2853. */ - public static final int BAD_MECH = 1; + public static final int BAD_MECH = 2; /** * Invalid name provided error. + * @specnote Should be 2 according to RFC 2853. */ - public static final int BAD_NAME = 2; + public static final int BAD_NAME = 3; /** * Name of unsupported type provided error. + * @specnote Should be 3 according to RFC 2853. */ - public static final int BAD_NAMETYPE = 3; + public static final int BAD_NAMETYPE = 4; /** * Invalid status code error - this is the default status value. @@ -125,38 +129,45 @@ public class GSSException extends Exception /** * Specified security context expired error. + * @specnote Should be 12 according to RFC 2853. */ - public static final int CONTEXT_EXPIRED = 12; + public static final int CONTEXT_EXPIRED = 7; /** * Expired credentials detected error. + * @specnote Should be 11 according to RFC 2853. */ - public static final int CREDENTIALS_EXPIRED = 11; + public static final int CREDENTIALS_EXPIRED = 8; /** * Defective credential error. + * @specnote Should be 10 according to RFC 2853. */ - public static final int DEFECTIVE_CREDENTIAL = 10; + public static final int DEFECTIVE_CREDENTIAL = 9; /** * Defective token error. + * @specnote Should be 9 according to RFC 2853. */ - public static final int DEFECTIVE_TOKEN = 9; + public static final int DEFECTIVE_TOKEN = 10; /** * General failure, unspecified at GSS-API level. + * @specnote Should be 13 according to RFC 2853. */ - public static final int FAILURE = 13; + public static final int FAILURE = 11; /** * Invalid security context error. + * @specnote Should be 8 according to RFC 2853. */ - public static final int NO_CONTEXT = 8; + public static final int NO_CONTEXT = 12; /** * Invalid credentials error. + * @specnote Should be 7 according to RFC 2853. */ - public static final int NO_CRED = 7; + public static final int NO_CRED = 13; /** * Unsupported QOP value error. @@ -188,16 +199,18 @@ public class GSSException extends Exception * code that may occur during context establishment. It is not used to * indicate supplementary status values. The MessageProp object is used * for that purpose. + * @specnote Should be 20 according to RFC 2853. */ - public static final int DUPLICATE_TOKEN = 20; + public static final int DUPLICATE_TOKEN = 19; /** * The token's validity period has expired. This is a fatal error code * that may occur during context establishment. It is not used to * indicate supplementary status values. The MessageProp object is used * for that purpose. + * @specnote Should be 19 according to RFC 2853. */ - public static final int OLD_TOKEN = 19; + public static final int OLD_TOKEN = 20; /** * A later token has already been processed. This is a fatal error code diff --git a/org/omg/CORBA/ORB.java b/org/omg/CORBA/ORB.java index 47fba002a..ba39b1610 100644 --- a/org/omg/CORBA/ORB.java +++ b/org/omg/CORBA/ORB.java @@ -89,7 +89,7 @@ import java.util.Properties; * </td></tr> * <tr><td>org.omg.CORBA.ORBInitRef</td><td>Specifies the * initial reference, accessible by name with the method - * {@link resolve_initial_references(String)}. + * {@link #resolve_initial_references(String)}. * </table> * The command line accepts the same properties as a keys. When specifying * in the command line, the prefix org.omg.CORBA can be omitted, @@ -100,8 +100,8 @@ import java.util.Properties; public abstract class ORB { /** - * By default, {@link init(String[], Properties)} and - * {@link init(Applet, Properties} return + * By default, {@link #init(String[], Properties)} and + * {@link #iinit(Applet, Properties)} return * the built-in fully functional ORB is returned. If the * <code>props</code> contains the property org.omg.CORBA.ORBClass, * the value of this property is used as a class name to instantiate @@ -210,7 +210,7 @@ public abstract class ORB /** * Create an instance of the CORBA {@link Any} with the type, intialised - * to {@link TCKind#tc_null} + * to {@link TCKind#tk_null} */ public abstract Any create_any(); @@ -432,7 +432,7 @@ public abstract class ORB * * @return the named value. */ - public abstract NamedValue create_named_value(String s, Any any, int flags); + public abstract NamedValue create_named_value(String name, Any any, int flags); /** * Send multiple prepared requests one way, do not caring about the answer. @@ -504,7 +504,7 @@ public abstract class ORB * However this method is oficially documented as not implemented at least * till v1.4 inclusive. * - * @param peration_definition the operation definition, must be + * @param operation_definition the operation definition, must be * CORBA <code>OperationDef</code>. * * @return never @@ -520,7 +520,7 @@ public abstract class ORB * <p>Creates the new policy of the specified type, having the given value. * This method looks for the policy factory that was previously registered * during ORB initialization by - * {@link org.omg.PortableInterceptor.ORBInitialiser}. + * {@link org.omg.PortableInterceptor#ORBInitialiser}. * * If the suitable factory is found, this factory creates the requested policy, * otherwise the PolicyError is thrown. @@ -570,7 +570,7 @@ public abstract class ORB * * The TypeCode object is initialized with the given id, name, and members. * @param id the Id of this type. - * @param the name of this type. + * @param name the name of this type. * @param members the member list. * * @return the typecode. @@ -586,7 +586,7 @@ public abstract class ORB * and members. * * @param id the Id of this type. - * @param the name of this type. + * @param name the name of this type. * @param discriminator the union discriminator. * @param members the member list. * @@ -742,7 +742,7 @@ public abstract class ORB * @return the default context of this ORB. * * @throws NO_IMPLEMENT for the Singleton ORB, returned by - * the parameterless {@link init()}. + * the parameterless {@link #init()}. */ public Context get_default_context() { @@ -752,7 +752,7 @@ public abstract class ORB /** * Return thg typecode, representing the given primitive object type. * - * @param the kind of the primitive typecode. + * @param tcKind the kind of the primitive typecode. * * @return the typecode of the primitve typecode. */ @@ -818,7 +818,7 @@ public abstract class ORB * By default the built-in fully functional ORB is returned. The ORB class * is found as described in the header of this class. * - * @param the parameters, passed to the applications + * @param args the parameters, passed to the applications * <code>main(String[] args)</code> method, may be <code>null</code>. * The parameter -org.omg.CORBA.ORBClass <class name> * if present, defines the used ORB implementation class. If this @@ -857,7 +857,7 @@ public abstract class ORB * * @return a list of services. * - * @see resolve_initial_references(String) + * @see #resolve_initial_references(String) */ public abstract String[] list_initial_services(); @@ -920,9 +920,9 @@ public abstract class ORB * (key) inside the server, the communication protocol version, * supported charsets and so on. * - * @param the CORBA object + * @param forObject the CORBA object * @return the object IOR representation. - * @see string_to_object(String) + * @see #string_to_object(String) */ public abstract String object_to_string(Object forObject); @@ -1017,7 +1017,7 @@ public abstract class ORB * @throws DATA_CONVERSION if the string being parsed contains unsupported * prefix or protocol. * - * @see object_to_string(org.omg.CORBA.Object) + * @see #object_to_string(org.omg.CORBA.Object) */ public abstract Object string_to_object(String IOR); @@ -1057,7 +1057,7 @@ public abstract class ORB * application. * * @param props application specific properties that were passed - * as a second parameter in {@link init(String[], Properties)}). + * as a second parameter in {@link #init(String[], Properties)}). * Can be <code>null</code>. */ protected abstract void set_parameters(String[] para, Properties props); diff --git a/org/omg/CORBA/PERSIST_STORE.java b/org/omg/CORBA/PERSIST_STORE.java index 8aae9b3bc..df17cefa9 100644 --- a/org/omg/CORBA/PERSIST_STORE.java +++ b/org/omg/CORBA/PERSIST_STORE.java @@ -57,7 +57,7 @@ public class PERSIST_STORE /** * Creates a PERSIST_STORE with the default minor code of 0, * completion state COMPLETED_NO and the given explaining message. - * @param reasom the explaining message. + * @param message the explaining message. */ public PERSIST_STORE(String message) { diff --git a/org/omg/CORBA/PolicyError.java b/org/omg/CORBA/PolicyError.java index 82ae4e45d..bd60fbe69 100644 --- a/org/omg/CORBA/PolicyError.java +++ b/org/omg/CORBA/PolicyError.java @@ -75,7 +75,7 @@ public class PolicyError /** * Constructs the policy error with the given reason code. - * @param reason a reason code, one of + * @param a_reason a reason code, one of * {@link BAD_POLICY}, {@link BAD_POLICY_TYPE}, * {@link BAD_POLICY_VALUE}, {@link UNSUPPORTED_POLICY}, * {@link UNSUPPORTED_POLICY_VALUE}. @@ -88,11 +88,11 @@ public class PolicyError /** * Constructs the policy error with the given reason code and the * detailed message. - * @param reason a reason code, one of + * @param a_details the detailed message. + * @param a_reason a reason code, one of * {@link BAD_POLICY}, {@link BAD_POLICY_TYPE}, * {@link BAD_POLICY_VALUE}, {@link UNSUPPORTED_POLICY}, * {@link UNSUPPORTED_POLICY_VALUE}. - * @param details the detailed message. */ public PolicyError(String a_details, short a_reason) { diff --git a/org/omg/CORBA/ValueBaseHolder.java b/org/omg/CORBA/ValueBaseHolder.java index c6efed5eb..6f57d17c3 100644 --- a/org/omg/CORBA/ValueBaseHolder.java +++ b/org/omg/CORBA/ValueBaseHolder.java @@ -79,7 +79,7 @@ public class ValueBaseHolder /** * Read fill in the value field by reading an instance from the - * given input stream. Uses {@link ValueBaseHelper.} + * given input stream. Uses {@link ValueBaseHelper} * * @param input a stream to read from. */ @@ -89,7 +89,7 @@ public class ValueBaseHolder } /** - * Get the typecode of the stored instance. Uses {@link ValueBaseHelper.} + * Get the typecode of the stored instance. Uses {@link ValueBaseHelper} */ public TypeCode _type() { @@ -97,10 +97,10 @@ public class ValueBaseHolder } /** - * Write the stored instance to the given input stream. - * Uses {@link ValueBaseHelper.} + * Write the stored instance to the given output stream. + * Uses {@link ValueBaseHelper} * - * @param input a stream to read from. + * @param output a stream to write to. */ public void _write(OutputStream output) { diff --git a/org/omg/CORBA/VisibilityHelper.java b/org/omg/CORBA/VisibilityHelper.java index f2ed32f63..71b572d99 100644 --- a/org/omg/CORBA/VisibilityHelper.java +++ b/org/omg/CORBA/VisibilityHelper.java @@ -59,7 +59,7 @@ public abstract class VisibilityHelper /** * Insert the Visibility into the given Any. - * Uses {@link Any.insert_short}. + * Uses {@link Any#insert_short}. */ public static void insert(Any any, short that) { @@ -68,7 +68,7 @@ public abstract class VisibilityHelper /** * Extract the Visibility from the given Any. - * Uses {@link Any.extract_short}. + * Uses {@link Any#extract_short}. */ public static short extract(Any any) { @@ -103,7 +103,7 @@ public abstract class VisibilityHelper /** * Read the visibility value (as short) from the CDR intput stream. * - * Uses {@link InputStream.read_short()}. + * Uses {@link InputStream#read_short()}. * * @param istream a stream to read from. */ @@ -115,7 +115,7 @@ public abstract class VisibilityHelper /** * Write the visibility value (as short) to the CDR output stream. * - * USes {@link OutputStream.write_short(short)}. + * USes {@link OutputStream#write_short(short)}. * * @param ostream a stream to write into. * @param value a value to write. diff --git a/org/omg/CosNaming/NameComponent.java b/org/omg/CosNaming/NameComponent.java index a2db313e6..1e06caaef 100644 --- a/org/omg/CosNaming/NameComponent.java +++ b/org/omg/CosNaming/NameComponent.java @@ -40,6 +40,8 @@ package org.omg.CosNaming; import org.omg.CORBA.portable.IDLEntity; +import java.util.zip.Adler32; + /** * The name component, a node in the multi-comonent name. * @@ -115,4 +117,14 @@ public final class NameComponent { return id + "." + kind; } -}
\ No newline at end of file + + /** + * Return the hashCode of this NameComponent. + */ + public int hashCode() + { + Adler32 adler = new Adler32(); + adler.update(toString().getBytes()); + return (int) adler.getValue() & Integer.MAX_VALUE; + } +} diff --git a/scripts/loc b/scripts/loc new file mode 100755 index 000000000..dc2f32703 --- /dev/null +++ b/scripts/loc @@ -0,0 +1,44 @@ +#!/bin/sh +# +# loc Find a class or package +# +# Usage: loc [-l] class-pattern [dirname] + +# -l Use system locate command instead of find. In that case, loc +# will ignore any directory to be searched. + +# Example: +# +# $ loc -l org.objectweb.jonas.common.JProp +# /var/lib/jonas/demoserver/ejbjars/autoload/mejb.jar +# /var/lib/jonas/lib/common/ow_jonas_bootstrap.jar +# /var/lib/jonas/eclipseserver/ejbjars/autoload/mejb.jar +# /var/lib/jonas/ejbjars/autoload/mejb.jar +# /var/cache/jonas/work/ejbjars/jonas/mejb_2005.09.15-17.01.52.jar +# /usr/src/redhat/BUILD/jonas-4.3.3/jonas/classes/common/org/objectweb/jonas/common/JProp.class + + +MODE=$1 +if test "$MODE" == "-l"; then + COMMAND='(locate \*.jar ; locate \*.war)' + shift +else + COMMAND='(find "$FOO" -name \*.jar -follow ; find "$FOO" -name \*.war -follow)' +fi + +FOO=$2 +if test "x$FOO" == "x"; then + FOO=/usr/share/java +fi + +eval "$COMMAND" 2>/dev/null | while read i; do + if (fastjar tf $i 2>/dev/null | grep $1) > /dev/null 2>&1 ; then + echo $i + fi +done + +if test "$MODE" != "-l"; then + find "$FOO" -name '*.class' 2>/dev/null | grep $1 +else + locate \*.class | grep $1 +fi diff --git a/vm/reference/gnu/classpath/jdwp/VMIdManager.java b/vm/reference/gnu/classpath/jdwp/VMIdManager.java index 09173fcf0..23cbb7b8e 100644 --- a/vm/reference/gnu/classpath/jdwp/VMIdManager.java +++ b/vm/reference/gnu/classpath/jdwp/VMIdManager.java @@ -138,6 +138,7 @@ public class VMIdManager { id.setId (++_lastId); } + id.setReference (obj); return id; } catch (InstantiationException ie) @@ -162,7 +163,7 @@ public class VMIdManager { id.setId (++_lastId); } - + id.setReference (obj); return id; } diff --git a/vm/reference/java/io/VMObjectInputStream.java b/vm/reference/java/io/VMObjectInputStream.java index 7cd97192e..93a42b1ca 100644 --- a/vm/reference/java/io/VMObjectInputStream.java +++ b/vm/reference/java/io/VMObjectInputStream.java @@ -39,6 +39,7 @@ exception statement from your version. */ package java.io; +import gnu.classpath.Configuration; import gnu.classpath.VMStackWalker; import java.lang.reflect.Constructor; import java.security.AccessController; @@ -46,8 +47,13 @@ import java.security.PrivilegedAction; final class VMObjectInputStream { - private static Class oisClass = ObjectInputStream.class; - private static Class vmoisClass = VMObjectInputStream.class; + static + { + if (Configuration.INIT_LOAD_LIBRARY) + { + System.loadLibrary("javaio"); + } + } // PrivilegedAction needed for Class.getClassLoader() private static PrivilegedAction loaderAction = new PrivilegedAction() diff --git a/vm/reference/java/io/VMObjectStreamClass.java b/vm/reference/java/io/VMObjectStreamClass.java index 2aee7a9e6..77470fa80 100644 --- a/vm/reference/java/io/VMObjectStreamClass.java +++ b/vm/reference/java/io/VMObjectStreamClass.java @@ -1,5 +1,5 @@ /* VMObjectStreamClass.java -- VM helper functions for ObjectStreamClass - Copyright (C) 2003 Free Software Foundation, Inc. + Copyright (C) 2003, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -38,10 +38,19 @@ exception statement from your version. */ package java.io; +import gnu.classpath.Configuration; import java.lang.reflect.Field; final class VMObjectStreamClass { + static + { + if (Configuration.INIT_LOAD_LIBRARY) + { + System.loadLibrary("javaio"); + } + } + /** * Returns true if CLAZZ has a static class initializer * (a.k.a. <clinit>). diff --git a/vm/reference/standard.omit b/vm/reference/standard.omit deleted file mode 100644 index c0499fe05..000000000 --- a/vm/reference/standard.omit +++ /dev/null @@ -1 +0,0 @@ -gnu/classpath/jdwp |