diff options
130 files changed, 14181 insertions, 4619 deletions
diff --git a/libjava/ChangeLog b/libjava/ChangeLog index 8c9abb7e127..9bf29a25aff 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,1144 @@ +2004-06-17 Michael Koch <konqueror@gmx.de> + + * javax/swing/JToolBar.java + (name): Removed. + (JToolBar): Use Component.setName(String) instead of doing it all + alone. + * javax/swing/Timer.java + (queueEvent): Added missing modifier. + +2004-06-17 Olga Rodimina <rodimina@redhat.coom> + + * Makefile.am: Added new file. + * Makefile.in: Re-generate. + * javax/swing/JMenu.java: + (insertSeparator): Implemented. + * javax/swing/JPopupMenu.java: + (JPopupMenu.Separator): Implemented. + * javax/swing/MenuSelectionManager.java: + (processMouseEvent): Use java.awt.Component + for event source instead of javax.swing.JComponent. + * javax/swing/plaf/basic/BasicPopupMenuSeparatorUI.java: + New File. Implemented. + +2004-06-16 David Jee <djee@redhat.com> + + * java/awt/GridBagLayout.java + (GetLayoutInfo): Adjust cell sizes iff parent size is not zero. + Make sure pos_x and pos_y are never negative. + +2004-04-16 Andrew Overholt <overholt@redhat.com> + + * Makefile.am: Add new file. + * Makefile.in: Re-generate. + * javax/swing/JToolBar.java + Partially implemented. + * javax/swing/plaf/basic/BasicToolBarUI.java + New file. Partially implemented. + +2004-06-16 Graydon Hoare <graydon@redhat.com> + + * gnu/java/awt/peer/gtk/GdkGraphics2D.java + (setComposite): Accept AlphaComposite arguments. + * gnu/java/awt/peer/gtk/GdkPixbufDecoder.java + (createBufferedImage): Add new overloads. + * gnu/java/awt/peer/gtk/GtkToolkit.java + (createImage): Use GdkPixbufDecoder.createBufferedImage + when useGraphics2D() is true. + (getImage): Delegate to createImage. + * javax/swing/JList.java + (isSelectionEmpty): + (getFirstVisibleIndex): + (getLastVisibleIndex): + (setSelectedValue): + (ensureIndexIsVisible): New methods. + * javax/swing/Timer.java: Reimplement. + +2004-06-16 Michael Koch <konqueror@gmx.de> + + * javax/swing/text/AbstractDocument.java + (AbstracElement): Made public, implements java.io.Serializable. + (AttributeContext): Made public. + (BranchElement): Likewise. + (Content): Likewise. + (DefaultDocumentEvent): Made public, extends + javax.swing.undo.CompoundEdit. + (ElementEdit): Made public, extends + javax.swing.undo.AbstractUndoableEdit. + (LeafElement): Made public. + (LeafElement.LeafElement): Made public. + +2004-06-16 Michael Koch <konqueror@gmx.de> + + * javax/swing/text/JTextComponent.java: Totally reworked. Removed many + methods (that were obviously never be intended to get included hi this + class. Added some methods too. + +2004-06-16 Michael Koch <konqueror@gmx.de> + + * javax/swing/text/PlainDocument.java + (serialVersionUID): New constant. + (lineLimitAttribute): Likewise. + (tabSizeAttribute): Likewise. + (tabSize): New field. + (PlainDocument): Made public. + (PlainDocument): New constructor. + +2004-06-16 Michael Koch <konqueror@gmx.de> + + * javax/swing/text/AbstractDocument.java + (insertString): Throws BadLocationException. + * javax/swing/text/Document.java + (insertString): Likewise. + * javax/swing/text/JTextComponent.java: + Javadocs and comments cleaned up. + +2004-06-16 Michael Koch <konqueror@gmx.de> + + * javax/swing/event/UndoableEditListener.java: Reformatted. + * javax/swing/text/AbstractDocument.java + (AbstractDocument): Implements java.io.Serializable. + (doc_list): Removed. + (undo_list): Removed. + (AbstractElement.serialVerionUID): New field. + (BranchElement.serialVerionUID): Likewise. + (DefaultDocumentEvent.serialVerionUID): Likewise. + (ElementEdit.serialVerionUID): Likewise. + (LeafElement.serialVerionUID): Likewise. + (serialVerionUID): Likewise. + (BAD_LOCATION): New constant. + (BidiElementName): Likewise. + (ContentElementName): Likewise. + (ParagraphElementName): Likewise. + (SectionElementName): Likewise. + (ElementNameAttribute): Likewise. + (AbstractDocument): Made protected. + (AbstractDocument): New construtor. + (listenerList): New field. + (fireChangedUpdate): Implemented. + (fireInsertUpdate): Likewise. + (fireRemoveUpdate): Likewise. + (fireUndoableEditUpdate): Likewise. + (getListeners): Likewise. + (addDocumentListener): Likewise. + (removeDocumentListener): Likewise. + (addUndoableEditListener): Likewise. + (removeUndoableEditListener): Likewise. + (getDocumentListeners): New method. + (getUndoableEditListeners): Likewise. + (getAsynchronousLoadPriority): Made public. + (getBidiRootElement): Likewise. + (setAsynchronousLoadPriority): Likewise. + (setDocumentProperties): Likewise. + * javax/swing/text/BadLocationException.java + (serialVerionUID): New field. + * javax/swing/text/DefaultCaret.java + (changeEvent): New field. + (listenerList): Likewise. + (changes): Removed. + (addChangeListener): Reimplemented. + (removeChangeListener): Likewise. + (getListeners): New method. + (getChangeListeners): Likwise. + (getComponent): Likewise. + * javax/swing/text/GapContent.java + (GapContent): Implements java.io.Serializable. + (serialVerionUID): New field. + +2004-06-16 Michael Koch <konqueror@gmx.de> + + * javax/swing/JTree.java + (treeModel): New field. + (JTree): New constructors, one existing one made public. + (createTreeModel): New method. + (addTreeExpansionListener): Likewise. + (removeTreeExpansionListener): Likewise. + (getTreeExpansionListeners): Likewise. + (fireTreeCollapsed): Likewise. + (fireTreeExpanded): Likewise. + (addTreeSelectionListener): Likewise. + (removeTreeSelectionListener): Likewise. + (getTreeSelectionListeners): Likewise. + (fireValueChanged): Likewise. + (addTreeWillExpandListener): Likewise. + (removeTreeWillExpandListener): Likewise. + (getTreeWillExpandListeners): Likewise. + (fireTreeWillCollapse): Likewise. + (fireTreeWillExpand): Likewise. + +2004-06-16 Michael Koch <konqueror@gmx.de> + + * javax/swing/JTree.java: Reformatted. + +2004-06-16 Michael Koch <konqueror@gmx.de> + + * javax/swing/JTextArea.java: New file. + * javax/swing/JTextField.java + (actions): Removed. + (notifyAction): New constant. + (columns): New field. + (JTextField): New constructors. + (createDefaultModel): New method. + (addActionListener): Reimplmemented. + (removeActionListener): Reimplemented. + (getActionListeners): New method. + (fireActionPerformed): New method. + (getColumns): New method. + (setColumne): New method. + * javax/swing/text/JTextComponent.java + (AccessibleJTextComponent.serialVersionUID): New field. + (serialVersionUID): Likewise. + (DEFAULT_KEYMAP): Likewise. + (FOCUS_ACCELERATOR_KEY): Likewise. + (doc): Made private. + (icon_gap): Likewise. + (icon): Likewise. + (align): Likewise. + (JTextComponent): Some constructors removed. + (getScrollableTracksViewportHeight): New method. + (getScrollableTracksViewportWidth): Likewise. + * Makefile.am: Added javax/swing/JTextArea.java. + * Makefile.in: Regenerated. + +2004-06-15 Graydon Hoare <graydon@redhat.com> + + * javax/swing/ImageIcon.java (ImageIcon): New constructor. + * javax/swing/JFrame.java (defaultLookAndFeelDecorated): New property. + * javax/swing/JViewport.java + (getExtentSize): Return size rather than preferred size. + (toViewCoordinates): New methods. + (getViewSize): Return size rather than preferred size. + (setViewSize): Note view size as set. + * javax/swing/ViewportLayout.java (layoutContainer): Reimplement. + * javax/swing/plaf/basic/BasicScrollBarUI.java + (getPreferredSize): Don't redo layout. + * javax/swing/plaf/basic/BasicViewportUI.java + (paint): Translate image properly and eat exceptions. + +2004-06-15 Kim Ho <kho@redhat.com> + + * javax/swing/JTabbedPane.java + (setComponent): Remove old component and + add new component. + (setSelectedIndex): Don't operate on the + components if they're null. Don't set index + on the model if the index is the same. + (insertTab): Don't add or hide the component + if it's null. Repaint the container. + * javax/swing/plaf/basic/BasicLookAndFeel.java + Change colors for TabbedPane. + * javax/swing/plaf/basic/BasicTabbedPaneUI.java + (mousePressed): Re-layout and paint the component. + (layoutContainer): Don't set location on the view. + (ScrollingViewport::paint): Remove. + +2004-06-14 Thomas Fitzsimmons <fitzsim@redhat.com> + + * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c + (gtkWidgetDispatchKeyEvent): Change warning message to comment. + + * jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics.c (drawString): + Wrap baseline y value in PANGO_PIXELS macro, rather than simply + dividing by PANGO_SCALE. Call gdk_flush before leaving GDK + critical region. + (drawLine): Call gdk_flush before leaving GDK critical region. + (fillRect): Likewise. + (drawRect): Likewise. + (copyArea): Likewise. + (copyPixmap): Likewise. + (clearRect): Likewise. + (drawArc): Likewise. + (drawPolyline): Likewise. + (drawPolygon): Likewise. + (fillPolygon): Likewise. + (fillArc): Likewise. + (drawOval): Likewise. + (fillOval): Likewise. + + * gnu/java/awt/peer/gtk/GdkFontMetrics.java (initState): Add + style parameter. + (GdkFontMetrics): Add style argument to initState call. + (stringWidth(String,int,int,String)): Add style parameter. + (stringWidth(String)): Add style argument to stringWidth call. + * jni/gtk-peer/gnu_java_awt_peer_gtk_GdkFontMetrics.c + (initState): Set pango font style and weight based on AWT style + parameter. Pass default GTK language to + pango_context_get_metrics. Use PANGO_PIXELS macro rather than + simply dividing by PANGO_SCALE. + (stringWidth): Set pango font style and weight based on AWT style + parameter. + + * java/awt/Button.java (next_button_number): New field. + (paramString): Change output. + (generateName): New method. + (getUniqueLong): New method. + +2004-06-14 Kim Ho <kho@redhat.com> + + * javax/swing/JTabbedPane.java: + (setComponentAt): Set the component, not + the enabled status. + * javax/swing/plaf/basic/BasicDesktopIconUI.java + (actionPerformed): Let deiconize catch exception. + +2004-06-14 Olga Rodimina <rodimina@redhat.com> + + * javax/swing/JPopupMenu.java: + (setVisible): Corrected location of a + heavyweight popup menu. + +2004-06-14 Olga Rodimina <rodimina@redhat.com> + + * javax/swing/MenuSelectionManager.java: + Ran through jalopy to fix formatting style. + +2004-06-14 Olga Rodimina <rodimina@redhat.com> + + * javax/swing/JLayeredPane.java: + (remove): Revalidate and repaint layered pane after + the component was removed. + javax/swing/JMenu.java: + (setVisible): Display popup menu at the user location, + if one was set by the user. + (setMenuLocation): Reimplemented. Fixed javadoc. + * javax/swing/JMenuBar.java: Added javadoc. + (BORDER_PAINTED_CHANGED_PROPERTY): New Property. + (MODEL_CHANGED_PROPERTY): New Property. + (isSelected): Implemented. + (setBorderPainted): Fire PropertyChangeEvent + if paintBorder property changes. + (setSelected): Implemented. + (setSelectionModel): Implemented. + * javax/swing/JPopupMenu.java: Added Javadoc + (pack): Implemented. + (setVisible): Reimplemented. + (show): Fixed location. + (JPopupMenu.LigthWeightPopup): Reimplemented to use + Container instead of JPanel. + * javax/swing/MenuSelectionManager.java: Added Javadocs. + (clearSelectedPath): Reimplemented to clear selectedPath + in reverse order. + (processMouseEvent): Reimplemented. + (setSelectedPath): Fire stateChange event indicating that + selected menu path has changed. + (getPath): Change to use ArrayList instead of Vector. + * javax/swing/plaf/basic/BasicMenuBarUI.java: + (installUI): call installKeyboardActions(). + (uninstallUI): call uninstallKeyboardActions(). + +2004-06-13 Michael Koch <konqueror@gmx.de> + + * javax/swing/text/DefaultCaret.java, + javax/swing/text/BadLocationException.java: + Reformatted. + +2004-06-12 Thomas Fitzsimmons <fitzsim@redhat.com> + + * gnu/java/awt/peer/gtk/GtkTextAreaPeer.java (DEFAULT_ROWS, + DEFAULT_COLS): New variables. + (create): Don't allow 0 rows or 0 columns. Instead, set the + values to DEFAULT_ROWS or DEFAULT_COLS. + (getMinimumSize): Likewise. + (getPreferredSize): Likewise. + (minimumSize): Likewise. + (preferredSize): Likewise. + (create): Set peer's editable state. + * java/awt/TextArea.java (TextArea()): Set rows and columns to + zero. Update javadocs. + (TextArea(String)): Likewise. + (TextArea(int,int)): Fix javadocs. + (TextArea(String,int,int,int)): Only throw exception if one of + rows or columns is zero. Fix javadocs. + +2004-06-11 Thomas Fitzsimmons <fitzsim@redhat.com> + + * java/awt/AWTEvent.java (toString): Handle MenuComponents in + addition to Components. + + * java/awt/MenuItem.java (dispatchEventImpl): If the event + wasn't consumed by normal processing, send it to the parent + menu. + + * gnu/java/awt/peer/gtk/GtkImagePainter.java + (setPixels(int,int,int,int,ColorModel,int[],int,int)): Remove + translation. + +2004-06-11 David Jee <djee@redhat.com> + + * java/awt/MediaTracker.java + (addImage(Image,int)): Call imageUpdate() to udpate image status. + (addImage(Image,int,int,int)): Likewise. + +2004-06-11 Michael Koch <konqueror@gmx.de> + + * javax/swing/text/AbstractDocument.java, + javax/swing/text/Document.java, + javax/swing/text/GapContent.java, + javax/swing/text/JTextComponent.java, + javax/swing/text/PlainDocument.java: + Reformatted. + +2004-06-11 Michael Koch <konqueror@gmx.de> + + * javax/swing/JRootPane.java + (AccessibleJRootPane.serialVersionUID): New field. + (AccessibleJRootPane.AccessibleJRootPane): New constructor. + (AccessibleJRootPane.getAccessibleRole): New method. + (RootLayout): Implements Serializable. + (RootLayout.serialVersionUID): New field. + (RootLayout.RootLayout): New constructor. + (setJMenuBar): Made public. + (getJMenuBar): Likewise. + (JRootPane): Likewise. + (createContentPane): Likewise. + (createGlassPane): Likewise. + (createLayeredPane): Likewise. + +2004-06-11 Michael Koch <konqueror@gmx.de> + + * javax/swing/SwingUtilities.java + (isLeftMouseButton): Fixed javadoc. + (isMiddleMouseButton): Likewise. + (isRightMouseButton): Likewise. + +2004-06-11 Michael Koch <konqueror@gmx.de> + + * javax/swing/JScrollPane.java + (serialVersionUID): New field. + (columnHeader): Made protected. + (rowHeader): Likewise. + (lowerLeft): Likewise. + (lowerRight): Likewise. + (upperLeft): Likewise. + (upperRight): Likewise. + (horizontalScrollBar): Likewise. + (horizontalScrollBarPolicy): Likewise. + (verticalScrollBar): Likewise. + (verticalScrollBarPolicy): Likewise. + (viewport): Likewise. + +2004-06-11 Michael Koch <konqueror@gmx.de> + + * javax/swing/LookAndFeel.java: Fixed javadocs. + +2004-06-11 Michael Koch <konqueror@gmx.de> + + * javax/swing/JEditorPane.java: Fixed javadocs. + (JEditorPane): Removed redundant call to to this(). + (fireHyperlinkUpdate): Implemented. + +2004-06-10 Olga Rodimina <rodimina@redhat.com> + + * javax/swing/JMenu.java: Fixed file name + in the file comment. + +2004-06-10 Olga Rodimina <rodimina@redhat.com> + + * javax/swing/JMenu.java: Added javadoc. + (JMenu): Added MenuChangeListener to listen to + ChangeEvents occuring in menu's model. + (insert): Throw IllegalArgumentException if + index is less than 0 + (setSelected): Reimplement. + (setPopupMenuVisible): Call menu's model isEnabled() + (setDelay): Throw IllegalArgumentException if + given amount of delay is less than 0. + (createActionComponent): Implemented. + (createActionChangeListener): Implemented. + (addSeparator): Implemented. + (getItem): Throw IllegalArgumentException if index is + less than 0. + (getItemCount): Implemented. + (fireMenuSelected): Changed to use menuEvent. + (fireMenuDeselected): Likewise. + (fireMenuCanceled): Likewise. + (setAccelerator): Changed to throw an error if this + method is used. + (doClick): Implemented. + (JMenu.ActionChangedListener): New inner class to handle + PropertyChangeEvents occuring in the actions associated with menu. + * javax/swing/plaf/basic/BasicMenuUI.java: Added javadoc. + (BasicMenuUI): Added PropertyChangeListener to the menu. + (createChangeListener): Implemented. + (createMenuDragMouseListener): Likewise. + (createMenuKeyListener): Likewise. + (createPropertyChangeListener): Likewise. + (uninstallListeners): Likewise. + (BasicMenuUI.MouseInputHandler): Reimplemented. + (BasicMenuUI.PropertyChangeHandler): New class. Not implemented yet. + (BasicMenuUI.ChangeHandler): Likewise. + (BasicMenuUI.MenuDragMouseHandler): Likewise. + (BasicMenuUI.MenuKeyHandler): Likewise. + +2004-06-10 David Jee <djee@redhat.com> + + * java/awt/MediaTracker.java + (imageUpdate): Only do notifyAll() if the image is complete. + +2004-06-10 Olga Rodimina <rodimina@redhat.com> + + * javax/swing/JApplet.java: + (getJMenuBar): Made public. + (setJMenuBar): Likewise. + * javax/swing/JFrame.java: + (getJMenuBar): Made public. + (setJMenuBar): Likewise. + * javax/swing/JWindow.java: + (getJMenuBar): Removed. + (setJMenuBar): Removed. + +2004-06-10 Michael Koch <konqueror@gmx.de> + + * javax/swing/JEditorPane.java + (createEditorKitForContentType): Fixed visibility. + (fireHyperlinkUpdate): Likewise. + (getContentType): Likewise. + (getEditorKit): Likewise. + (getEditorKitForContentType): Likewise. + (getPage): Likewise. + (read): Likewise. + (registerEditorKitForContentTyoe): Likewise. + (replaceSelection): Likewise. + (setContentType): Likewise. + (setEditorKit): Likewise. + (setPage): Likewise. + +2004-06-10 Michael Koch <konqueror@gmx.de> + + * javax/swing/Timer.java + (Timer): New constructor. + * javax/swing/plaf/basic/BasicProgressBarUI.java + (animationTimer): Don't initialize at construction. + (startAnimationTimer): Added since tag. + (stopAnimationTimer): Likewise. + (installUI): Use new Timer constructor. + * javax/swing/plaf/basic/BasicScrollBarUI.java + (installUI): Likewise. + * javax/swing/plaf/basic/BasicSliderUI.java + (installUI): Likewise. + +2004-06-10 Michael Koch <konqueror@gmx.de> + + * javax/swing/ButtonGroup.java + (serialVersionUID): Made private. + (buttons): Renamed from v, added javadoc. + (sel): Added javadoc. + (ButtonGroup): Likewise. + (add): Likewise. + (remove): Likewise. + (getElements): Likewise. + (getSelection): Likewise. + (setSelected): Likewise. + (isSelected): Likewise. + (getButtonCount): Likewise. + +2004-06-10 Michael Koch <konqueror@gmx.de> + + * javax/swing/ButtonGroup.java, + javax/swing/ImageIcon.java, + javax/swing/JEditorPane.java, + javax/swing/JRootPane.java, + javax/swing/JTextField.java, + javax/swing/LookAndFeel.java, + javax/swing/plaf/basic/BasicTextUI.java: + Reindented. + +2004-06-10 Michael Koch <konqueror@gmx.de> + + * javax/swing/text/Style.java: Added javadocs. + +2004-06-10 Michael Koch <konqueror@gmx.de> + + * javax/swing/JComponent.java + (fireVetoableChange): Removed redundant cast. + * javax/swing/JLabel.java + (getDisabledIcon): Save icon for next call. + +2004-06-10 Michael Koch <konqueror@gmx.de> + + * javax/swing/KeyStroke.java + (getKeyStroke(char,boolean)): Marked deprecated. + +2004-06-10 Michael Koch <konqueror@gmx.de> + + * javax/swing/DefaultCellEditor.java, + javax/swing/GrayFilter.java, + javax/swing/event/DocumentEvent.java, + javax/swing/text/JTextComponent.java, + javax/swing/text/MutableAttributeSet.java: + Reindented. + +2004-06-10 Michael Koch <konqueror@gmx.de> + + * javax/swing/plaf/BorderUIResource.java: + Added serialVersionUID all over. + +2004-06-10 Sascha Brawer <brawer@dandelis.ch> + + * javax/swing/undo/UndoManager.java: Re-written from scratch. + +2004-06-10 Michael Koch <konqueror@gmx.de> + + * javax/swing/table/DefaultTableCellRenderer.java + (noFocusBorder): Initialize directly. + +2004-06-10 Michael Koch <konqueror@gmx.de> + + * javax/swing/plaf/basic/BasicArrowButton.java + (setDirection): Use method argument. + +2004-06-10 Michael Koch <konqueror@gmx.de> + + * javax/swing/plaf/BorderUIResource.java, + javax/swing/plaf/ComponentUI.java, + javax/swing/undo/CompoundEdit.java, + javax/swing/undo/StateEdit.java: + Fixed javadocs all over. + +2004-06-10 Michael Koch <konqueror@gmx.de> + + * javax/swing/DefaultButtonModel.java + (ARMED): Made public final, fixed value. + (ENABLED): Likewise. + (PRESSED): Likewise. + (ROLLOVER): Likewise. + (SELECTED): Likewise. + (stateMask): Initialize directly. + (listenerList): Likewise. + (mnemonic): Likewise. + (fireStateChanged): Removed argument, use changeEvent as event. + All places where this method is called are fixed too. + (getActionCommant): Fixed javadoc. + (setGroup): Fixed javadoc. + (getGroup): New method. + +2004-06-09 Olga Rodimina <rodimina@redhat.com> + + * javax/swing/AbstractButton.java + (AbstractButton): Use init() to initialize the button. + (init): New Method. Initializes AbstractButton. + * javax/swing/JMenuItem.java: Documented. + (JMenuItem): Reimplemented. + (init): Implemented. + (setEnabled): Changed to call super.setEnabled() + (processMouseEvent): Reimplemented. + (fireMenuKeyPressed): Implemented. + (fireMenuKeyReleased): Implemented. + (fireMenuKeyTyped): Implemented. + (menuSelectionChanged): disarm the model if the menu item was + deselected. + * javax/swing/plaf/basic/BasicMenuItemUI.java:Documented. + (getPath): Change to use ArrayList instead of Vector. + (getPreferredSize): Renamed variable. + (paintMenuItem): Paint margin area of menu item. + (MouseInputHandler.mouseEntered): Set selection in MenuSelectionManager. + (MouseInputHandler.mouseReleased): Check if mouse was pressed inside + menu item's bounds before clearing the selection. + +2004-06-09 David Jee <djee@redhat.com> + + * gnu/java/awt/peer/gtk/GtkTextComponentPeer.java + (GtkTextComponentPeer): Set caret position to 0. + * java/awt/TextComponent.java + (setText): Set caret position to 0. + * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c + (Java_gnu_java_awt_peer_gtk_GtkComponentPeer_addExposeFilter): + Handle GtkScrolledWindow separately. Fix signal handler blocking. + (Java_gnu_java_awt_peer_gtk_GtkComponentPeer_removeExposeFilter): + Likewise. + * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextAreaPeer.c + (Java_gnu_java_awt_peer_gtk_GtkTextAreaPeer_create): Make cursor + visible. + +2004-06-09 Kim Ho <kho@redhat.com> + + * Makefile.am: New files + * Makefile.in: Regenerated + * java/awt/Container.java + (getComponentAt): Removed. + * javax/swing/AbstractAction.java + (ENABLED_PROPERTY): New property. + (putValue): Fire PropertyChangeEvents. + (setEnabled): ditto. + (firePropertyChange): Javadoc and implement + convenience method. + * javax/swing/AbstractButton.java + (setAction): Don't create PropertyChangeListener + if new Action is null. + (setIcon): Don't set icon till after comparing + it. + (configurePropertiesFromAction): Check mnemonic + key before calling intValue(). + (createActionPropertyChangeListener): Check + properties rather than bulk change. + * javax/swing/DefaultDesktopManager.java: + Implement. + * javax/swing/DesktopManager.java: + Jalopy and javadoc. + * javax/swing/JComponent.java + (fireVetoableChange): Implement. + (paintImmediately): Use root component. + * javax/swing/JDesktopPane.java: Implement + * javax/swing/JInternalFrame.java: Implement + * javax/swing/JLabel.java + (getDisabledIcon): Return grayscaled icon if + no disabled icon specified. + * javax/swing/JMenuBar.java + (getComponentAtIndex): Use getComponent + * javax/swing/JOptionPane.java + (getDesktopPaneForComponent): Use SwingUtilities' + getAncestorOfClass + (getFrameForComponent): ditto. + * javax/swing/JSplitPane.java + (remove): Use getComponent. + * javax/swing/SwingUtilities.java + (convertPoint): Implement. + * javax/swing/plaf/basic/BasicButtonUI.java + (paintButtonNormal): Check opaqueness before + filling background. + * javax/swing/plaf/basic/BasicDesktopIconUI.java: + Implement + * javax/swing/plaf/basic/BasicDesktopPaneUI.java: + Implement. + * javax/swing/plaf/basic/BasicInternalFrameTitlePane.java: + Implement. + * javax/swing/plaf/basic/BasicInternalFrameUI.java: + Implement. + * javax/swing/plaf/basic/BasicLookAndFeel.java: + Change InternalFrame and Desktop colors. + +2004-06-09 David Jee <djee@redhat.com> + + * java/awt/Container.java + (remove): Do not set component to invisible. + +2004-06-09 Michael Koch <konqueror@gmx.de> + + * javax/swing/tree/DefaultMutableTreeNode.java + (getLeafCount): Renamed enum to e. + +2004-06-09 Michael Koch <konqueror@gmx.de> + + * javax/swing/plaf/basic/BasicSplitPaneDivider.java + (positionForMouseEvent): Removed redundant semicolon. + (continueDrag): Use method arguments. + +2004-06-09 Michael Koch <konqueror@gmx.de> + + * javax/swing/border/TitledBorder.java, + javax/swing/filechooser/FileSystemView.java, + javax/swing/plaf/basic/BasicButtonListener.java, + javax/swing/plaf/basic/BasicGraphicsUtils.java, + javax/swing/plaf/basic/BasicLabelUI.java, + javax/swing/plaf/basic/BasicRadioButtonMenuItemUI.java, + javax/swing/plaf/basic/BasicScrollBarUI.java, + javax/swing/plaf/basic/BasicScrollPaneUI.java, + javax/swing/plaf/basic/BasicSliderUI.java, + javax/swing/plaf/basic/BasicTabbedPaneUI.java, + javax/swing/plaf/basic/BasicToggleButtonUI.java, + javax/swing/table/JTableHeader.java, + javax/swing/text/AbstractDocument.java, + javax/swing/text/DefaultCaret.java, + javax/swing/text/StyledEditorKit.java, + javax/swing/tree/DefaultTreeCellEditor.java: + Reworked import statements. + +2004-06-08 Graydon Hoare <graydon@redhat.com> + + * javax/swing/Box.java: Temporarily comment out code + broken due to visibility bug. + +2004-06-09 Michael Koch <konqueror@gmx.de> + + * javax/swing/ImageIcon.java + (ImageIcon): Added missing constructor. + +2004-06-08 Michael Koch <konqueror@gmx.de> + + * javax/swing/JToggleButton.java + (JToggleButton): New constructor. + (getAccessibleContext): Moved documentation into javadoc. + (getUIClassID): Likewise. + +2004-06-08 Michael Koch <konqueror@gmx.de> + + * javax/swing/AbstractButton.java + (getDisabledIcon): Create disabled icon if none exists yet. + +2004-06-08 Michael Koch <konqueror@gmx.de> + + * javax/swing/plaf/basic/BasicLookAndFeel.java + (initClassDefaults): Added FormattedTextFieldUI. + (loadResourceBundle): Renamed enum to e. + +2004-06-08 Michael Koch <konqueror@gmx.de> + + * javax/swing/plaf/basic/BasicButtonUI.java + (paintIcon): Simplified. + (paintText): Paint disabled button correctly. + +2004-06-08 Michael Koch <konqueror@gmx.de> + + * javax/swing/JComponent.java + (createToolTip): Use official JToolTip API. + +2004-06-08 Michael Koch <konqueror@gmx.de> + + * javax/swing/JToolTip.java + (JToolTip): No arguments in API. + (setTipText): New method. + +2004-06-08 Michael Koch <konqueror@gmx.de> + + * javax/swing/SwingUtilities.java + (isLeftMouseButton): New method. + (isMiddleMouseButton): New method. + (isRightMouseButton): New method. + +2004-06-08 Michael Koch <konqueror@gmx.de> + + * javax/swing/AbstractButton.java, + javax/swing/CellRendererPane.java, + javax/swing/JCheckBoxMenuItem.java, + javax/swing/JColorChooser.java, + javax/swing/JComboBox.java, + javax/swing/JComponent.java, + javax/swing/JDesktopPane.java, + javax/swing/JFileChooser.java, + javax/swing/JMenu.java, + javax/swing/JMenuItem.java, + javax/swing/JOptionPane.java, + javax/swing/JPasswordField.java, + javax/swing/JPopupMenu.java, + javax/swing/JProgressBar.java, + javax/swing/JRadioButtonMenuItem.java, + javax/swing/JScrollBar.java, + javax/swing/JSeparator.java, + javax/swing/JSlider.java, + javax/swing/JSplitPane.java, + javax/swing/JTabbedPane.java, + javax/swing/JTextField.java, + javax/swing/JToolBar.java, + javax/swing/text/JTextComponent.java: + Fixed all constructors of accessibility classes. + +2004-06-08 Michael Koch <konqueror@gmx.de> + + * javax/swing/ScrollPaneLayout.java: Renamed all memeber variables all + over. + +2004-06-08 Michael Koch <konqueror@gmx.de> + + * javax/swing/Box.java + (AccessibleBoxFiller): Extends AccessibleAWTComponent. + (AccessibleBoxFiller.serialVersionUID): New member variable. + * javax/swing/DefaultButtonModel.java + (stateMask): Made protected. + (listenerList): Likewise. + (changeEvent): Likewise. + (group): Likewise. + (mnemonic): Likewise. + (actionCommand): Likewise. + (getListeners): New method. + (getActionListeners): New method. + (getItemListeners): New method. + (getChangeListeners): New method. + (fireItemStateChanged): Simplified. + (fireActionPerformed): Simplified. + (fireStateChanged): Simplified. + * javax/swing/JFrame.java + (JFrame): Implements WindowContants. + (HIDE_ON_CLOSE): Removed. + (EXIT_ON_CLOSE): Removed. + (DISPOSE_ON_CLOSE): Removed. + (DO_NOTHING_ON_CLOSE): Removed. + (processWindowEvent): Exit with code 0. + (setDefaultCloseOperation): Do security check before setting value. + * javax/swing/JOptionPane.java + (message): Initialize only in constructor. + * javax/swing/JToolTip.java: Removed unused imports. + * javax/swing/JViewport.java + (serialVersionUID): New member variable. + (SIMPLE_SCROLL_MODE): Made final, fixed value. + (BLIT_SCROLL_MODE): Likewise. + (BACKINGSTORE_SCROLL_MODE): Likewise. + (scrollUnderway): Made protected. + (isViewSizeSet): Likewise. + * javax/swing/ListModel.java: Fixed javadoc. + * javax/swing/Popup.java: Likewise. + * javax/swing/RepaintManager.java + (paintDirtyRegions): Don't use internal classes of + java.util.AbstractMap. + * javax/swing/ScrollPaneConstants.java: Reindented. + * javax/swing/ScrollPaneLayout.java + (viewport): Made protected. + (verticalScrollBar): Made protected, renamed to vsb. + (horizontalScrollBar): Made protected, renamed to hsb. + (rowHeader): Made protected, renamed to rowHead. + (columnHeader): Made protected, renamed to colHead. + (lowerLeft): Made protected. + (lowerRight): Made protected. + (upperLeft): Made protected. + (upperRight): Made protected. + (verticalScrollBarPolicy): Made protected, renamed to vsbPolicy. + (horizontalScrollBarPolicy): Made protected, renamed to hsbPolicy. + +2004-06-07 Bernd Schmidt <bernds@btinternet.com> + + * java/awt/MediaTracker.java (imageUpdate): Only set status to + LOADING if flags has SOMEBITS set. + +2004-06-07 Michael Koch <konqueror@gmx.de> + + * javax/swing/AbstractButton.java: Reorganized imports. + * javax/swing/ActionMap.java: Likewise. + * javax/swing/DefaultButtonModel.java: Likewise. + * javax/swing/DefaultListModel.java: Likewise. + * javax/swing/ImageIcon.java: Likewise. + (serialVersionUID): New member variable. + * javax/swing/JComboBox.java: Reorganized imports. + * javax/swing/JComponent.java: Likewise. + (ui): Made protected. + (listenerList): Made protected. + (TOOL_TIP_TEXT_KEY): New constant. + (scrollRectToVisible): Removed redundant null check. + * javax/swing/JFrame.java: Reorganized imports. + * javax/swing/JInternalFrame.java: Reorganized imports. + * javax/swing/JProgressBar.java: Likewise. + * javax/swing/JRootPane.java: Likewise. + * javax/swing/JScrollBar.java: Likewise. + * javax/swing/JSeparator.java: Likewise. + * javax/swing/JSlider.java: Likewise. + * javax/swing/JTabbedPane.java: Likewise. + * javax/swing/JTextField.java: Likewise. + * javax/swing/JToolBar.java: Likewise. + * javax/swing/JTree.java: Likewise. + * javax/swing/JViewport.java: Likewise. + * javax/swing/JWindow.java: Likewise. + * javax/swing/KeyStroke.java: Likewise. + * javax/swing/LookAndFeel.java: Likewise. + * javax/swing/MenuSelectionManager.java: Likewise. + * javax/swing/SwingUtilities.java: Likewise. + * javax/swing/Timer.java: Likewise. + * javax/swing/DefaultBoundedRangeModel.java: Fixed javadoc. + * javax/swing/JList.java + (HORIZONTAL_WRAP): Made final, fixed value. + (VERTICAL): Likewise. + (VERTICAL_WRAP): Likewise. + +2004-06-07 Michael Koch <konqueror@gmx.de> + + * javax/swing/AbstractButton.java + (serialVersionUID): New member variable. + (AccessibleAbstractButton.serialVersionUID): Likewise. + (AbstractButton): Made public. + * javax/swing/Box.java + (AccessibleBox.serialVersionUID): New member variable. + (Filler.serialVersionUID): Likewise. + * javax/swing/DefaultListSelectionModel.java + (serialVersionUID): Likewise. + * javax/swing/JApplet.java + (serialVersionUID): Likewise. + * javax/swing/JCheckBox.java + (serialVersionUID): Likewise. + * javax/swing/JCheckBoxMenuItem.java + (serialVersionUID): Likewise. + (AccessibleJCheckBoxMenuItem.serialVersionUID): Likewise. + * javax/swing/JColorChooser.java + (serialVersionUID): Likewise. + (AccessibleJColorChooser.serialVersionUID): Likewise. + * javax/swing/JComponent.java + (serialVersionUID): Made private. + (AccessibleJComponent.serialVersionUID): New member variable. + * javax/swing/JDesktopPane.java + (serialVersionUID): Likewise. + * javax/swing/JDialog.java + (serialVersionUID): Likewise. + * javax/swing/JFormattedTextField.java + (serialVersionUID): Fixed value. + * javax/swing/JFrame.java + (serialVersionUID): New member variable. + (getDefaultCloseOpertation): Made public. + * javax/swing/JLayeredPane.java + (serialVersionUID): Likewise. + (LAYER_PROPERTY): Made final, fixed value. + (JLayeredPane): Made public. + * javax/swing/JMenu.java + (AccessibleJMenu.serialVersionUID): New member variable. + (WinListener.serialVersionUID): Likewise. + * javax/swing/JMenuBar.java + (serialVersionUID): Likewise. + (getComponentAtIndex): Added @deprecated tag. + * javax/swing/JMenuItem.java + (serialVersionUID): New member variable. + (AccessibleJMenuItem.serialVersionUID): Likewise. + * javax/swing/JOptionPane.java + (serialVersionUID): Likewise. + (AccessibleJOptionPane.serialVersionUID): Likewise. + * javax/swing/JPopupMenu.java + (serialVersionUID): Likewise. + (AccessibleJPopupMenu.serialVersionUID): Likewise. + (getPopupMenuListeners): New method. + (getComponentAtIndex): Added @deprecated tag. + * javax/swing/JProgressBar.java + (serialVersionUID): New member variable. + (AccessibleJProgressBar.serialVersionUID): Likewise. + * javax/swing/JRadioButton.java + (serialVersionUID): Likewise. + * javax/swing/JRadioButtonMenuItem.java + (serialVersionUID): Likewise. + (AccessibleJRadioButtonMenuItem.serialVersionUID): Likewise. + * javax/swing/JScrollBar.java + (serialVersionUID): Likewise. + (AccessibleJScrollBar.serialVersionUID): Likewise. + * javax/swing/JSeparator.java + (serialVersionUID): Likewise. + (AccessibleJSeparator.serialVersionUID): Likewise. + * javax/swing/JSlider.java: Fixed javadocs. + (AccessibleJSlider.serialVersionUID): New member variable. + * javax/swing/JSplitPane.java: Added copyright statement. + (serialVersionUID): New member variable. + (AccessibleJSplitPane.serialVersionUID): Likewise. + * javax/swing/JTabbedPane.java + (serialVersionUID): Likewise. + (AccessibleJTabbedPane.serialVersionUID): Likewise. + (ModelListener.serialVersionUID): Likewise. + (ModelListener.ModelListener): New constructor. + (SCROLL_TAB_LAYOUT): Made public final, fixed value. + (WRAP_TAB_LAYOUT): Likewise. + * javax/swing/JTable.java + (serialVersionUID): New member variable. + * javax/swing/JToggleButton.java + (serialVersionUID): Likewise. + (ToggleButtonModel): Made static. + (ToggleButtonModel.serialVersionUID): New member variable. + * javax/swing/JToolTip.java + (serialVersionUID): Likewise. + * javax/swing/JTree.java + (serialVersionUID): Likewise. + * javax/swing/JWindow.java + (serialVersionUID): Likewise. + * javax/swing/Timer.java + (serialVersionUID): Likewise. + +2004-06-06 Michael Koch <konqueror@gmx.de> + + * javax/swing/SwingConstants.java + (NEXT): New constant. + (PREVIOUS): Likewise. + * javax/swing/UIManager.java + (LookAndFeel): Made public. + (LookAndFeel.getClassName): Likewise. + (LookAndFeel.getName): Likewise. + +2004-06-02 Olga Rodimina <rodimina@redhat.com> + + * javax/swing/JCheckBoxMenuItem.java: + Removed CVS tags. + * javax/swing/JMenu.java: Likewise. + * javax/swing/JMenuBar.java: Likewise. + * javax/swing/JMenuItem.java: Likewise. + * javax/swing/JPopupMenu.java: Likewise. + * javax/swing/JRadioButtonMenuItem.java: Likewise. + * javax/swing/plaf/basic/BasicCheckBoxMenuItemUI.java:Likewise. + * javax/swing/plaf/basic/BasicMenuBarUI.java: Likewise. + * javax/swing/plaf/basic/BasicMenuItemUI.java: Likewise. + * javax/swing/plaf/basic/BasicMenuUI.java: Likewise. + * javax/swing/plaf/basic/BasicPopupMenuUI.java: Likewise. + * javax/swing/plaf/basic/BasicRadioButtonMenuItemUI.java: Likewise. + +2004-05-31 Olga Rodimina <rodimina@redhat.com> + + * javax/swing/plaf/basic/BasicMenuUI.java: + (MouseEntered): Do not call getPath() from MenuSelectionManager. + Call getPath() from super class instead. + +2004-05-31 David Jee <djee@redhat.com> + + * java/awt/Container.java + (remove): Set component visibility to false after removing it. + +2004-05-27 Thomas Fitzsimmons <fitzsim@redhat.com> + + * java/awt/Component.java (getForeground): Return SystemColor if + parent is null. + (getBackground): Likewise. + + * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkListPeer.c + (item_highlighted): New function. + (connectSignals): Set item_highlighted as list's select + function. + + * java/applet/Applet.java: Revert changes from 2004-04-29, + 2004-03-15 and 2004-03-14. + + * jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics.c (drawString): + Divide baseline y coordinate by PANGO_SCALE, not DPI conversion + factor. + + * gnu/java/awt/peer/gtk/GtkTextAreaPeer.java (create): Set + "Dialog" as the default font. + * gnu/java/awt/peer/gtk/GtkTextFieldPeer.java (create): + Likewise. + * java/awt/Component.java (getFont): Return "Dialog" font by + default. + * jni/gtk-peer/gnu_java_awt_peer_gtk_GdkClasspathFontPeer.c: + Multiply size argument to pango_font_description_set_size by the + DPI conversion factor rather than by PANGO_SCALE. + * jni/gtk-peer/gnu_java_awt_peer_gtk_GdkFontMetrics.c: Likewise. + * jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics.c: Likewise. + * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkButtonPeer.c: Likewise. + * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCheckboxPeer.c: Likewise. + * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c: Likewise. + * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkLabelPeer.c: Likewise. + * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkListPeer.c: Likewise. + * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextAreaPeer.c: Likewise. + * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextFieldPeer.c: Likewise. + * jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics.c (drawString): + Divide baseline y coordinate by DPI conversion factor rather + than by PANGO_SCALE. + * jni/gtk-peer/gnu_java_awt_peer_gtk_GdkPixbufDecoder.c + (area_prepared): Fix typo. + * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkLabelPeer.c + (gtkSetFont): Move gtk_bin_get_child inside GDK critical region. + * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMainThread.c + (dpi_conversion_factor): New global variable. + (init_dpi_conversion_factor): New function to calculate and + track DPI conversion factor. + (dpi_changed_cb): New callback. + * jni/gtk-peer/gtkpeer.h (dpi_conversion_factor): Declare. + +2004-05-27 David Jee <djee@redhat.com> + + * gnu/java/awt/peer/gtk/GtkComponentPeer.java + (getGraphics): Return a new GdkGraphics instance. + * gnu/java/awt/peer/gtk/GtkContainerPeer.java + (getGraphics): Call super.getGraphics(). + +2004-05-26 Thomas Fitzsimmons <fitzsim@redhat.com> + + * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c + (setNativeBounds): Clamp width and height values to >= 0. + + * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c + (find_fg_color_widget): Handle GtkOptionMenu specially. + + * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkEvents.c + (pre_event_handler): Only post configure events to visible + top-level windows. + +2004-05-26 David Jee <djee@redhat.com> + + * java/awt/BorderLayout.java + (layoutContainer): Fix size calculations. + +2004-05-26 Thomas Fitzsimmons <fitzsim@redhat.com> + + * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c + (window_wm_protocols_filter): Remove function. + (create): Remove filter that removes WM_TAKE_FOCUS client + messages. + 2004-06-17 Anthony Green <green@redhat.com> * java/util/zip/ZipFile.java (getInputStream): Return null if diff --git a/libjava/Makefile.am b/libjava/Makefile.am index 5a97d9b886f..cac32b47777 100644 --- a/libjava/Makefile.am +++ b/libjava/Makefile.am @@ -1322,7 +1322,11 @@ javax/swing/plaf/basic/BasicArrowButton.java \ javax/swing/plaf/basic/BasicButtonListener.java \ javax/swing/plaf/basic/BasicButtonUI.java \ javax/swing/plaf/basic/BasicCheckBoxUI.java \ +javax/swing/plaf/basic/BasicDesktopIconUI.java \ +javax/swing/plaf/basic/BasicDesktopPaneUI.java \ javax/swing/plaf/basic/BasicGraphicsUtils.java \ +javax/swing/plaf/basic/BasicInternalFrameTitlePane.java \ +javax/swing/plaf/basic/BasicInternalFrameUI.java \ javax/swing/plaf/basic/BasicLabelUI.java \ javax/swing/plaf/basic/BasicListUI.java \ javax/swing/plaf/basic/BasicMenuUI.java \ @@ -1331,6 +1335,7 @@ javax/swing/plaf/basic/BasicMenuItemUI.java \ javax/swing/plaf/basic/BasicOptionPaneUI.java \ javax/swing/plaf/basic/BasicPanelUI.java \ javax/swing/plaf/basic/BasicPopupMenuUI.java \ +javax/swing/plaf/basic/BasicPopupMenuSeparatorUI.java \ javax/swing/plaf/basic/BasicProgressBarUI.java \ javax/swing/plaf/basic/BasicRootPaneUI.java \ javax/swing/plaf/basic/BasicRadioButtonUI.java \ @@ -1345,6 +1350,7 @@ javax/swing/plaf/basic/BasicSplitPaneUI.java \ javax/swing/plaf/basic/BasicTabbedPaneUI.java \ javax/swing/plaf/basic/BasicTextUI.java \ javax/swing/plaf/basic/BasicToggleButtonUI.java \ +javax/swing/plaf/basic/BasicToolBarUI.java \ javax/swing/plaf/basic/BasicTreeUI.java \ javax/swing/plaf/basic/BasicViewportUI.java \ javax/swing/plaf/basic/BasicLookAndFeel.java \ @@ -1444,6 +1450,7 @@ javax/swing/JRootPane.java \ javax/swing/JScrollBar.java \ javax/swing/JScrollPane.java \ javax/swing/JTabbedPane.java \ +javax/swing/JTextArea.java \ javax/swing/JTextField.java \ javax/swing/JToggleButton.java \ javax/swing/JToolTip.java \ diff --git a/libjava/Makefile.in b/libjava/Makefile.in index cb924d58757..4177fd8ca03 100644 --- a/libjava/Makefile.in +++ b/libjava/Makefile.in @@ -1001,7 +1001,11 @@ javax/swing/plaf/basic/BasicArrowButton.java \ javax/swing/plaf/basic/BasicButtonListener.java \ javax/swing/plaf/basic/BasicButtonUI.java \ javax/swing/plaf/basic/BasicCheckBoxUI.java \ +javax/swing/plaf/basic/BasicDesktopIconUI.java \ +javax/swing/plaf/basic/BasicDesktopPaneUI.java \ javax/swing/plaf/basic/BasicGraphicsUtils.java \ +javax/swing/plaf/basic/BasicInternalFrameTitlePane.java \ +javax/swing/plaf/basic/BasicInternalFrameUI.java \ javax/swing/plaf/basic/BasicLabelUI.java \ javax/swing/plaf/basic/BasicListUI.java \ javax/swing/plaf/basic/BasicMenuUI.java \ @@ -1010,6 +1014,7 @@ javax/swing/plaf/basic/BasicMenuItemUI.java \ javax/swing/plaf/basic/BasicOptionPaneUI.java \ javax/swing/plaf/basic/BasicPanelUI.java \ javax/swing/plaf/basic/BasicPopupMenuUI.java \ +javax/swing/plaf/basic/BasicPopupMenuSeparatorUI.java \ javax/swing/plaf/basic/BasicProgressBarUI.java \ javax/swing/plaf/basic/BasicRootPaneUI.java \ javax/swing/plaf/basic/BasicRadioButtonUI.java \ @@ -1024,6 +1029,7 @@ javax/swing/plaf/basic/BasicSplitPaneUI.java \ javax/swing/plaf/basic/BasicTabbedPaneUI.java \ javax/swing/plaf/basic/BasicTextUI.java \ javax/swing/plaf/basic/BasicToggleButtonUI.java \ +javax/swing/plaf/basic/BasicToolBarUI.java \ javax/swing/plaf/basic/BasicTreeUI.java \ javax/swing/plaf/basic/BasicViewportUI.java \ javax/swing/plaf/basic/BasicLookAndFeel.java \ @@ -1123,6 +1129,7 @@ javax/swing/JRootPane.java \ javax/swing/JScrollBar.java \ javax/swing/JScrollPane.java \ javax/swing/JTabbedPane.java \ +javax/swing/JTextArea.java \ javax/swing/JTextField.java \ javax/swing/JToggleButton.java \ javax/swing/JToolTip.java \ @@ -4545,14 +4552,14 @@ DEP_FILES = .deps/$(srcdir)/$(CONVERT_DIR)/gen-from-JIS.P \ .deps/javax/swing/JScrollBar.P .deps/javax/swing/JScrollPane.P \ .deps/javax/swing/JSeparator.P .deps/javax/swing/JSlider.P \ .deps/javax/swing/JSplitPane.P .deps/javax/swing/JTabbedPane.P \ -.deps/javax/swing/JTable.P .deps/javax/swing/JTextField.P \ -.deps/javax/swing/JTextPane.P .deps/javax/swing/JToggleButton.P \ -.deps/javax/swing/JToolBar.P .deps/javax/swing/JToolTip.P \ -.deps/javax/swing/JTree.P .deps/javax/swing/JViewport.P \ -.deps/javax/swing/JWindow.P .deps/javax/swing/KeyStroke.P \ -.deps/javax/swing/ListCellRenderer.P .deps/javax/swing/ListModel.P \ -.deps/javax/swing/ListSelectionModel.P .deps/javax/swing/LookAndFeel.P \ -.deps/javax/swing/MenuElement.P \ +.deps/javax/swing/JTable.P .deps/javax/swing/JTextArea.P \ +.deps/javax/swing/JTextField.P .deps/javax/swing/JTextPane.P \ +.deps/javax/swing/JToggleButton.P .deps/javax/swing/JToolBar.P \ +.deps/javax/swing/JToolTip.P .deps/javax/swing/JTree.P \ +.deps/javax/swing/JViewport.P .deps/javax/swing/JWindow.P \ +.deps/javax/swing/KeyStroke.P .deps/javax/swing/ListCellRenderer.P \ +.deps/javax/swing/ListModel.P .deps/javax/swing/ListSelectionModel.P \ +.deps/javax/swing/LookAndFeel.P .deps/javax/swing/MenuElement.P \ .deps/javax/swing/MenuSelectionManager.P \ .deps/javax/swing/MutableComboBoxModel.P \ .deps/javax/swing/OverlayLayout.P .deps/javax/swing/Popup.P \ @@ -4667,8 +4674,12 @@ DEP_FILES = .deps/$(srcdir)/$(CONVERT_DIR)/gen-from-JIS.P \ .deps/javax/swing/plaf/basic/BasicButtonUI.P \ .deps/javax/swing/plaf/basic/BasicCheckBoxMenuItemUI.P \ .deps/javax/swing/plaf/basic/BasicCheckBoxUI.P \ +.deps/javax/swing/plaf/basic/BasicDesktopIconUI.P \ +.deps/javax/swing/plaf/basic/BasicDesktopPaneUI.P \ .deps/javax/swing/plaf/basic/BasicGraphicsUtils.P \ .deps/javax/swing/plaf/basic/BasicIconFactory.P \ +.deps/javax/swing/plaf/basic/BasicInternalFrameTitlePane.P \ +.deps/javax/swing/plaf/basic/BasicInternalFrameUI.P \ .deps/javax/swing/plaf/basic/BasicLabelUI.P \ .deps/javax/swing/plaf/basic/BasicListUI.P \ .deps/javax/swing/plaf/basic/BasicLookAndFeel.P \ @@ -4677,6 +4688,7 @@ DEP_FILES = .deps/$(srcdir)/$(CONVERT_DIR)/gen-from-JIS.P \ .deps/javax/swing/plaf/basic/BasicMenuUI.P \ .deps/javax/swing/plaf/basic/BasicOptionPaneUI.P \ .deps/javax/swing/plaf/basic/BasicPanelUI.P \ +.deps/javax/swing/plaf/basic/BasicPopupMenuSeparatorUI.P \ .deps/javax/swing/plaf/basic/BasicPopupMenuUI.P \ .deps/javax/swing/plaf/basic/BasicProgressBarUI.P \ .deps/javax/swing/plaf/basic/BasicRadioButtonMenuItemUI.P \ @@ -4691,6 +4703,7 @@ DEP_FILES = .deps/$(srcdir)/$(CONVERT_DIR)/gen-from-JIS.P \ .deps/javax/swing/plaf/basic/BasicTabbedPaneUI.P \ .deps/javax/swing/plaf/basic/BasicTextUI.P \ .deps/javax/swing/plaf/basic/BasicToggleButtonUI.P \ +.deps/javax/swing/plaf/basic/BasicToolBarUI.P \ .deps/javax/swing/plaf/basic/BasicTreeUI.P \ .deps/javax/swing/plaf/basic/BasicViewportUI.P \ .deps/javax/swing/plaf/metal/MetalLookAndFeel.P \ diff --git a/libjava/gnu/java/awt/peer/gtk/GdkFontMetrics.java b/libjava/gnu/java/awt/peer/gtk/GdkFontMetrics.java index ebca7ed0cea..c7a73a3f362 100644 --- a/libjava/gnu/java/awt/peer/gtk/GdkFontMetrics.java +++ b/libjava/gnu/java/awt/peer/gtk/GdkFontMetrics.java @@ -50,19 +50,21 @@ public class GdkFontMetrics extends FontMetrics MAX_ADVANCE = 4; private int[] metrics; - private native int[] initState (String fname, int size); + private native int[] initState (String fname, int style, int size); public GdkFontMetrics (Font font) { super (font); - metrics = initState (font.getName (), font.getSize ()); + metrics = initState (font.getName (), font.getStyle (), font.getSize ()); } - native public int stringWidth (String fname, int size, String str); + native public int stringWidth (String fname, int style, int size, + String str); public int stringWidth (String str) { - return stringWidth (font.getName (), font.getSize (), str); + return stringWidth (font.getName (), font.getStyle (), font.getSize (), + str); } public int charWidth (char ch) diff --git a/libjava/gnu/java/awt/peer/gtk/GdkGraphics2D.java b/libjava/gnu/java/awt/peer/gtk/GdkGraphics2D.java index 3e77047f72f..ebff68ef987 100644 --- a/libjava/gnu/java/awt/peer/gtk/GdkGraphics2D.java +++ b/libjava/gnu/java/awt/peer/gtk/GdkGraphics2D.java @@ -1260,7 +1260,18 @@ public class GdkGraphics2D extends Graphics2D public void setComposite(Composite comp) { - throw new java.lang.UnsupportedOperationException (); + if (comp instanceof AlphaComposite) + { + AlphaComposite a = (AlphaComposite) comp; + cairoSetOperator(a.getRule()); + Color c = getColor(); + setColor(new Color(c.getRed(), + c.getGreen(), + c.getBlue(), + (int) (a.getAlpha() * ((float) c.getAlpha())))); + } + else + throw new java.lang.UnsupportedOperationException (); } public void setRenderingHint(RenderingHints.Key hintKey, diff --git a/libjava/gnu/java/awt/peer/gtk/GdkPixbufDecoder.java b/libjava/gnu/java/awt/peer/gtk/GdkPixbufDecoder.java index 766ceb8fc3c..32c69871711 100644 --- a/libjava/gnu/java/awt/peer/gtk/GdkPixbufDecoder.java +++ b/libjava/gnu/java/awt/peer/gtk/GdkPixbufDecoder.java @@ -220,4 +220,31 @@ public class GdkPixbufDecoder extends gnu.java.awt.image.ImageDecoder dec.startProduction (bb); return bb.getBufferedImage (); } + + public static BufferedImage createBufferedImage (URL u) + { + BufferedImageBuilder bb = new BufferedImageBuilder (); + GdkPixbufDecoder dec = new GdkPixbufDecoder (u); + dec.startProduction (bb); + return bb.getBufferedImage (); + } + + public static BufferedImage createBufferedImage (byte[] imagedata, int imageoffset, + int imagelength) + { + BufferedImageBuilder bb = new BufferedImageBuilder (); + GdkPixbufDecoder dec = new GdkPixbufDecoder (imagedata, imageoffset, imagelength); + dec.startProduction (bb); + return bb.getBufferedImage (); + } + + public static BufferedImage createBufferedImage (ImageProducer producer) + { + BufferedImageBuilder bb = new BufferedImageBuilder (); + producer.startProduction(bb); + return bb.getBufferedImage (); + } + + + } diff --git a/libjava/gnu/java/awt/peer/gtk/GtkComponentPeer.java b/libjava/gnu/java/awt/peer/gtk/GtkComponentPeer.java index 7d80e3626c9..48e63f3d19a 100644 --- a/libjava/gnu/java/awt/peer/gtk/GtkComponentPeer.java +++ b/libjava/gnu/java/awt/peer/gtk/GtkComponentPeer.java @@ -199,7 +199,10 @@ public class GtkComponentPeer extends GtkGenericPeer public Graphics getGraphics () { - return null; + if (GtkToolkit.useGraphics2D ()) + return new GdkGraphics2D (this); + else + return new GdkGraphics (this); } public Point getLocationOnScreen () diff --git a/libjava/gnu/java/awt/peer/gtk/GtkContainerPeer.java b/libjava/gnu/java/awt/peer/gtk/GtkContainerPeer.java index 32ac02f5abd..8ac927cbae6 100644 --- a/libjava/gnu/java/awt/peer/gtk/GtkContainerPeer.java +++ b/libjava/gnu/java/awt/peer/gtk/GtkContainerPeer.java @@ -107,10 +107,7 @@ public class GtkContainerPeer extends GtkComponentPeer public Graphics getGraphics () { - if (GtkToolkit.useGraphics2D ()) - return new GdkGraphics2D (this); - else - return new GdkGraphics (this); + return super.getGraphics(); } public void beginLayout () { } diff --git a/libjava/gnu/java/awt/peer/gtk/GtkImagePainter.java b/libjava/gnu/java/awt/peer/gtk/GtkImagePainter.java index 0476c8cf00f..16f36d303f3 100644 --- a/libjava/gnu/java/awt/peer/gtk/GtkImagePainter.java +++ b/libjava/gnu/java/awt/peer/gtk/GtkImagePainter.java @@ -104,7 +104,7 @@ public class GtkImagePainter implements Runnable, ImageConsumer s_width = Math.abs (sx2 - sx1); s_height = Math.abs (sy2 - sy1); clip = new Rectangle (sx1, sy1, s_width, s_height); - + new Thread (this).start (); } @@ -170,8 +170,6 @@ public class GtkImagePainter implements Runnable, ImageConsumer offset += r.y * scansize + r.x; - r.translate (-Math.abs (clip.x - startX), -Math.abs (clip.y - startY)); - width = r.width; height = r.height; x = r.x; diff --git a/libjava/gnu/java/awt/peer/gtk/GtkTextAreaPeer.java b/libjava/gnu/java/awt/peer/gtk/GtkTextAreaPeer.java index 18e4d204897..b08728b2bff 100644 --- a/libjava/gnu/java/awt/peer/gtk/GtkTextAreaPeer.java +++ b/libjava/gnu/java/awt/peer/gtk/GtkTextAreaPeer.java @@ -47,6 +47,9 @@ import java.awt.peer.TextAreaPeer; public class GtkTextAreaPeer extends GtkTextComponentPeer implements TextAreaPeer { + private static transient int DEFAULT_ROWS = 10; + private static transient int DEFAULT_COLS = 80; + native void create (int width, int height, int scrollbarVisibility); native void gtkSetFont (String name, int style, int size); @@ -61,7 +64,7 @@ public class GtkTextAreaPeer extends GtkTextComponentPeer // GtkComponent.create. if (f == null) { - f = new Font ("Fixed", Font.PLAIN, 12); + f = new Font ("Dialog", Font.PLAIN, 12); awtComponent.setFont (f); } @@ -72,13 +75,17 @@ public class GtkTextAreaPeer extends GtkTextComponentPeer fm = new GdkFontMetrics (f); TextArea ta = ((TextArea) awtComponent); - int rows = ta.getRows (); - int cols = ta.getColumns (); + int sizeRows = ta.getRows (); + int sizeCols = ta.getColumns (); + + sizeRows = sizeRows == 0 ? DEFAULT_ROWS : sizeRows; + sizeCols = sizeCols == 0 ? DEFAULT_COLS : sizeCols; - int width = cols * fm.getMaxAdvance (); - int height = rows * (fm.getMaxDescent () + fm.getMaxAscent ()); + int width = sizeCols * fm.getMaxAdvance (); + int height = sizeRows * (fm.getMaxDescent () + fm.getMaxAscent ()); create (width, height, ta.getScrollbarVisibility ()); + setEditable (ta.isEditable ()); } public GtkTextAreaPeer (TextArea ta) @@ -91,12 +98,14 @@ public class GtkTextAreaPeer extends GtkTextComponentPeer public Dimension getMinimumSize (int rows, int cols) { - return minimumSize (rows, cols); + return minimumSize (rows == 0 ? DEFAULT_ROWS : rows, + cols == 0 ? DEFAULT_COLS : cols); } public Dimension getPreferredSize (int rows, int cols) { - return preferredSize (rows, cols); + return preferredSize (rows == 0 ? DEFAULT_ROWS : rows, + cols == 0 ? DEFAULT_COLS : cols); } native int getHScrollbarHeight (); @@ -127,8 +136,11 @@ public class GtkTextAreaPeer extends GtkTextComponentPeer else fm = new GdkFontMetrics (f); - width += cols * fm.getMaxAdvance (); - height += rows * (fm.getMaxDescent () + fm.getMaxAscent ()); + int sizeRows = rows == 0 ? DEFAULT_ROWS : rows; + int sizeCols = cols == 0 ? DEFAULT_COLS : cols; + + width += sizeCols * fm.getMaxAdvance (); + height += sizeRows * (fm.getMaxDescent () + fm.getMaxAscent ()); return new Dimension (width, height); } @@ -157,8 +169,11 @@ public class GtkTextAreaPeer extends GtkTextComponentPeer else fm = new GdkFontMetrics (f); - width += cols * fm.getMaxAdvance (); - height += rows * (fm.getMaxDescent () + fm.getMaxAscent ()); + int sizeRows = rows == 0 ? DEFAULT_ROWS : rows; + int sizeCols = cols == 0 ? DEFAULT_COLS : cols; + + width += sizeCols * fm.getMaxAdvance (); + height += sizeRows * (fm.getMaxDescent () + fm.getMaxAscent ()); return new Dimension (width, height); } diff --git a/libjava/gnu/java/awt/peer/gtk/GtkTextComponentPeer.java b/libjava/gnu/java/awt/peer/gtk/GtkTextComponentPeer.java index 8bc4bdf3eee..8893e36e838 100644 --- a/libjava/gnu/java/awt/peer/gtk/GtkTextComponentPeer.java +++ b/libjava/gnu/java/awt/peer/gtk/GtkTextComponentPeer.java @@ -54,6 +54,7 @@ public class GtkTextComponentPeer extends GtkComponentPeer super (tc); setText (tc.getText ()); + setCaretPosition(0); } public native void connectSignals (); diff --git a/libjava/gnu/java/awt/peer/gtk/GtkTextFieldPeer.java b/libjava/gnu/java/awt/peer/gtk/GtkTextFieldPeer.java index 5662336b193..111c1f96979 100644 --- a/libjava/gnu/java/awt/peer/gtk/GtkTextFieldPeer.java +++ b/libjava/gnu/java/awt/peer/gtk/GtkTextFieldPeer.java @@ -60,7 +60,7 @@ public class GtkTextFieldPeer extends GtkTextComponentPeer // GtkComponent.create. if (f == null) { - f = new Font ("Fixed", Font.PLAIN, 12); + f = new Font ("Dialog", Font.PLAIN, 12); awtComponent.setFont (f); } diff --git a/libjava/gnu/java/awt/peer/gtk/GtkToolkit.java b/libjava/gnu/java/awt/peer/gtk/GtkToolkit.java index c9739c359b1..c55001591c4 100644 --- a/libjava/gnu/java/awt/peer/gtk/GtkToolkit.java +++ b/libjava/gnu/java/awt/peer/gtk/GtkToolkit.java @@ -129,26 +129,58 @@ public class GtkToolkit extends gnu.java.awt.ClasspathToolkit public Image createImage (String filename) { - return new GtkImage (new GdkPixbufDecoder (filename), null); + if (useGraphics2D()) + return GdkPixbufDecoder.createBufferedImage (filename); + else + { + GdkPixbufDecoder d = new GdkPixbufDecoder (filename); + GtkImage image = new GtkImage (d, null); + d.startProduction (image); + return image; + } } public Image createImage (URL url) { - return new GtkImage (new GdkPixbufDecoder (url), null); + if (useGraphics2D()) + return GdkPixbufDecoder.createBufferedImage (url); + else + { + GdkPixbufDecoder d = new GdkPixbufDecoder (url); + GtkImage image = new GtkImage (d, null); + d.startProduction (image); + return image; + } } public Image createImage (ImageProducer producer) { - return new GtkImage (producer, null); + if (useGraphics2D()) + return GdkPixbufDecoder.createBufferedImage (producer); + else + { + GtkImage image = new GtkImage (producer, null); + producer.startProduction (image); + return image; + } } public Image createImage (byte[] imagedata, int imageoffset, int imagelength) { - return new GtkImage (new GdkPixbufDecoder (imagedata, - imageoffset, - imagelength), - null); + if (useGraphics2D()) + return GdkPixbufDecoder.createBufferedImage (imagedata, + imageoffset, + imagelength); + else + { + GdkPixbufDecoder d = new GdkPixbufDecoder (imagedata, + imageoffset, + imagelength); + GtkImage image = new GtkImage (d, null); + d.startProduction (image); + return image; + } } public ColorModel getColorModel () @@ -175,18 +207,12 @@ public class GtkToolkit extends gnu.java.awt.ClasspathToolkit public Image getImage (String filename) { - GdkPixbufDecoder d = new GdkPixbufDecoder (filename); - GtkImage image = new GtkImage (d, null); - d.startProduction (image); - return image; + return createImage (filename); } public Image getImage (URL url) { - GdkPixbufDecoder d = new GdkPixbufDecoder (url); - GtkImage image = new GtkImage (d, null); - d.startProduction (image); - return image; + return createImage (url); } public PrintJob getPrintJob (Frame frame, String jobtitle, Properties props) diff --git a/libjava/java/applet/Applet.java b/libjava/java/applet/Applet.java index 009b18cedc0..5990c6392da 100644 --- a/libjava/java/applet/Applet.java +++ b/libjava/java/applet/Applet.java @@ -78,11 +78,6 @@ public class Applet extends Panel private transient AppletStub stub; /** - * The dimensions passed to this applet through its HTML tag. - */ - private transient Dimension dimensions; - - /** * The accessibility context for this applet. * * @serial the accessibleContext for this @@ -462,41 +457,6 @@ public class Applet extends Panel s.defaultReadObject(); } - private Dimension getDimensions () - { - if (dimensions == null) - { - int width = Integer.parseInt(stub.getParameter("width")); - int height = Integer.parseInt(stub.getParameter("height")); - - dimensions = new Dimension(width, height); - } - - return dimensions; - } - - /** - * Returns an instance of {@link Dimension} representing the - * applet's width and height parameters. - * - * @return the applet's preferred size - */ - public Dimension preferredSize() - { - return stub == null ? super.preferredSize () : getDimensions (); - } - - /** - * Returns an instance of {@link Dimension} representing the - * applet's width and height parameters. - * - * @return the applet's minimum size - */ - public Dimension minimumSize() - { - return stub == null ? super.minimumSize () : getDimensions (); - } - /** * This class provides accessibility support for Applets, and is the * runtime type returned by {@link #getAccessibleContext()}. diff --git a/libjava/java/awt/AWTEvent.java b/libjava/java/awt/AWTEvent.java index a084dcf24a0..675c27f9511 100644 --- a/libjava/java/awt/AWTEvent.java +++ b/libjava/java/awt/AWTEvent.java @@ -238,8 +238,16 @@ public abstract class AWTEvent extends EventObject */ public String toString () { - return getClass ().getName () + "[" + paramString () + "] on " - + ((Component) source).getName (); + String string = null; + + if (source instanceof Component) + string = getClass ().getName () + "[" + paramString () + "] on " + + ((Component) source).getName (); + else if (source instanceof MenuComponent) + string = getClass ().getName () + "[" + paramString () + "] on " + + ((MenuComponent) source).getName (); + + return string; } /** diff --git a/libjava/java/awt/BorderLayout.java b/libjava/java/awt/BorderLayout.java index 38e4de742a0..a023cbb059b 100644 --- a/libjava/java/awt/BorderLayout.java +++ b/libjava/java/awt/BorderLayout.java @@ -592,13 +592,21 @@ layoutContainer(Container target) int x1 = i.left; int x2 = x1 + w.width + hgap; - int x3 = Math.max(x2 + w.width + hgap, t.width - i.right - e.width); + int x3; + if (t.width <= i.right + e.width) + x3 = x2 + w.width + hgap; + else + x3 = t.width - i.right - e.width; int ww = t.width - i.right - i.left; int y1 = i.top; int y2 = y1 + n.height + vgap; int midh = Math.max(e.height, Math.max(w.height, c.height)); - int y3 = Math.max(y2 + midh + vgap, t.height - i.bottom - s.height); + int y3; + if (t.height <= i.bottom + s.height) + y3 = y2 + midh + vgap; + else + y3 = t.height - i.bottom - s.height; int hh = y3-y2-vgap; setBounds(center, x2, y2, x3-x2-hgap, hh); diff --git a/libjava/java/awt/Button.java b/libjava/java/awt/Button.java index a521c8e4f3d..54b201ed1c4 100644 --- a/libjava/java/awt/Button.java +++ b/libjava/java/awt/Button.java @@ -81,6 +81,11 @@ private String label; // List of ActionListeners for this class. private transient ActionListener action_listeners; + /* + * The number used to generate the name returned by getName. + */ + private static transient long next_button_number = 0; + /*************************************************************************/ /* @@ -305,9 +310,24 @@ dispatchEventImpl(AWTEvent e) protected String paramString() { - return ("label=" + getLabel() + ",actionCommand=" + getActionCommand() - + "," + super.paramString()); + return getName () + "," + getX () + "," + getY () + "," + + getWidth () + "x" + getHeight () + ",label=" + getLabel (); } + /** + * Generate a unique name for this button. + * + * @return A unique name for this button. + */ + String generateName () + { + return "button" + getUniqueLong (); + } + + private static synchronized long getUniqueLong () + { + return next_button_number++; + } + } // class Button diff --git a/libjava/java/awt/Component.java b/libjava/java/awt/Component.java index 3ca2b4f7aae..f3153da5911 100644 --- a/libjava/java/awt/Component.java +++ b/libjava/java/awt/Component.java @@ -941,7 +941,7 @@ public abstract class Component { if (foreground != null) return foreground; - return parent == null ? null : parent.getForeground(); + return parent == null ? SystemColor.windowText : parent.getForeground(); } /** @@ -982,7 +982,7 @@ public abstract class Component { if (background != null) return background; - return parent == null ? null : parent.getBackground(); + return parent == null ? SystemColor.window : parent.getBackground(); } /** @@ -1031,7 +1031,7 @@ public abstract class Component if (parent != null) return parent.getFont (); else - return new Font ("Fixed", Font.PLAIN, 12); + return new Font ("Dialog", Font.PLAIN, 12); } /** diff --git a/libjava/java/awt/Container.java b/libjava/java/awt/Container.java index 0482e654736..ffd81b46802 100644 --- a/libjava/java/awt/Container.java +++ b/libjava/java/awt/Container.java @@ -876,11 +876,6 @@ public class Container extends Component { return locate (x, y); } - - public Component getComponentAt(int index) - { - return component[index]; - } /** * Returns the component located at the specified point. This is done diff --git a/libjava/java/awt/GridBagLayout.java b/libjava/java/awt/GridBagLayout.java index 301e71318ac..b98359c1bdb 100644 --- a/libjava/java/awt/GridBagLayout.java +++ b/libjava/java/awt/GridBagLayout.java @@ -790,13 +790,26 @@ public class GridBagLayout info.rowWeights); } // end of STEP 4 - calcCellSizes (info.colWidths, info.colWeights, parentDim.width); - calcCellSizes (info.rowHeights, info.rowWeights, parentDim.height); + // Adjust cell sizes iff parent size not zero. + if (parentDim.width > 0 && parentDim.height > 0) + { + calcCellSizes (info.colWidths, info.colWeights, parentDim.width); + calcCellSizes (info.rowHeights, info.rowWeights, parentDim.height); + } int totalWidth = sumIntArray(info.colWidths); int totalHeight = sumIntArray(info.rowHeights); - info.pos_x = parentInsets.left + (parentDim.width - totalWidth) / 2; - info.pos_y = parentInsets.top + (parentDim.height - totalHeight) / 2; + + // Make sure pos_x and pos_y are never negative. + if (totalWidth >= parentDim.width) + info.pos_x = parentInsets.left; + else + info.pos_x = parentInsets.left + (parentDim.width - totalWidth) / 2; + + if (totalHeight >= parentDim.height) + info.pos_y = parentInsets.top; + else + info.pos_y = parentInsets.top + (parentDim.height - totalHeight) / 2; // DEBUG //dumpLayoutInfo (info); diff --git a/libjava/java/awt/MediaTracker.java b/libjava/java/awt/MediaTracker.java index b1157349b5b..d1df8b38360 100644 --- a/libjava/java/awt/MediaTracker.java +++ b/libjava/java/awt/MediaTracker.java @@ -81,12 +81,17 @@ public class MediaTracker implements java.io.Serializable status = ERRORED | COMPLETE; else if ((flags & ALLBITS) != 0) status = COMPLETE; - else + else if ((flags & SOMEBITS) != 0) status = LOADING; - - synchronized (MediaTracker.this) + else + status = 0; + + if ((status & COMPLETE) == COMPLETE) { - MediaTracker.this.notifyAll(); + synchronized (MediaTracker.this) + { + MediaTracker.this.notifyAll(); + } } // If status is not COMPLETE then we need more updates. return (status & COMPLETE) == 0; @@ -106,7 +111,8 @@ public class MediaTracker implements java.io.Serializable e.next = head; head = e; // Start tracking image status. - target.checkImage(image, e); + int flags = target.checkImage(image, e); + e.imageUpdate(image, flags, -1, -1, -1, -1); } public void addImage(Image image, int id, int width, int height) @@ -119,7 +125,8 @@ public class MediaTracker implements java.io.Serializable e.height = height; head = e; // Start tracking image status. - target.checkImage(image, width, height, e); + int flags = target.checkImage(image, width, height, e); + e.imageUpdate(image, flags, -1, -1, width, height); } public boolean checkAll() diff --git a/libjava/java/awt/MenuItem.java b/libjava/java/awt/MenuItem.java index 4defc38279e..8511f698fad 100644 --- a/libjava/java/awt/MenuItem.java +++ b/libjava/java/awt/MenuItem.java @@ -424,6 +424,11 @@ dispatchEventImpl(AWTEvent e) && (action_listeners != null || (eventMask & AWTEvent.ACTION_EVENT_MASK) != 0)) processEvent(e); + + // Send the event to the parent menu if it has not yet been + // consumed. + if (!e.isConsumed ()) + ((Menu) getParent ()).processEvent (e); } /** diff --git a/libjava/java/awt/TextArea.java b/libjava/java/awt/TextArea.java index f27c29695f4..6355376df52 100644 --- a/libjava/java/awt/TextArea.java +++ b/libjava/java/awt/TextArea.java @@ -103,29 +103,33 @@ public class TextArea extends TextComponent implements java.io.Serializable private static transient long next_text_number = 0; /** - * Initialize a new instance of <code>TextArea</code> that is empty - * and is one row by one column. Both horizontal and vertical + * Initialize a new instance of <code>TextArea</code> that is empty. + * Conceptually the <code>TextArea</code> has 0 rows and 0 columns + * but its initial bounds are defined by its peer or by the + * container in which it is packed. Both horizontal and vertical * scrollbars will be displayed. * - * @exception HeadlessException If GraphicsEnvironment.isHeadless () is true, + * @exception HeadlessException if GraphicsEnvironment.isHeadless () is true */ public TextArea () { - this ("", 1, 1, SCROLLBARS_BOTH); + this ("", 0, 0, SCROLLBARS_BOTH); } /** - * Initialize a new instance of <code>TextArea</code> that initially - * contains the specified text. Both horizontal and veritcal - * scrollbars will be displayed. + * Initialize a new instance of <code>TextArea</code> that contains + * the specified text. Conceptually the <code>TextArea</code> has 0 + * rows and 0 columns but its initial bounds are defined by its peer + * or by the container in which it is packed. Both horizontal and + * veritcal scrollbars will be displayed. * * @param text The text to display in this text area. * - * @exception HeadlessException If GraphicsEnvironment.isHeadless () is true, + * @exception HeadlessException if GraphicsEnvironment.isHeadless () is true */ public TextArea (String text) { - this (text, 1, text.length (), SCROLLBARS_BOTH); + this (text, 0, 0, SCROLLBARS_BOTH); } /** @@ -137,7 +141,7 @@ public class TextArea extends TextComponent implements java.io.Serializable * @param rows The number of rows in this text area. * @param columns The number of columns in this text area. * - * @exception HeadlessException If GraphicsEnvironment.isHeadless () is true, + * @exception HeadlessException if GraphicsEnvironment.isHeadless () is true */ public TextArea (int rows, int columns) { @@ -154,7 +158,7 @@ public class TextArea extends TextComponent implements java.io.Serializable * @param rows The number of rows in this text area. * @param columns The number of columns in this text area. * - * @exception HeadlessException If GraphicsEnvironment.isHeadless () is true, + * @exception HeadlessException if GraphicsEnvironment.isHeadless () is true */ public TextArea (String text, int rows, int columns) { @@ -175,7 +179,7 @@ public class TextArea extends TextComponent implements java.io.Serializable * SCROLLBARS_BOTH, SCROLLBARS_VERTICAL_ONLY, * SCROLLBARS_HORIZONTAL_ONLY, SCROLLBARS_NONE. * - * @exception HeadlessException If GraphicsEnvironment.isHeadless () is true, + * @exception HeadlessException if GraphicsEnvironment.isHeadless () is true */ public TextArea (String text, int rows, int columns, int scrollbarVisibility) { @@ -184,7 +188,7 @@ public class TextArea extends TextComponent implements java.io.Serializable if (GraphicsEnvironment.isHeadless ()) throw new HeadlessException (); - if (rows < 1 || columns < 0) + if (rows < 0 || columns < 0) throw new IllegalArgumentException ("Bad row or column value"); if (scrollbarVisibility != SCROLLBARS_BOTH diff --git a/libjava/java/awt/TextComponent.java b/libjava/java/awt/TextComponent.java index 0a410a44b9f..9cdb507f30a 100644 --- a/libjava/java/awt/TextComponent.java +++ b/libjava/java/awt/TextComponent.java @@ -141,6 +141,7 @@ setText(String text) TextComponentPeer tcp = (TextComponentPeer)getPeer(); if (tcp != null) tcp.setText(text); + setCaretPosition(0); } /*************************************************************************/ diff --git a/libjava/javax/swing/AbstractAction.java b/libjava/javax/swing/AbstractAction.java index 889044938e9..d7518998273 100644 --- a/libjava/javax/swing/AbstractAction.java +++ b/libjava/javax/swing/AbstractAction.java @@ -60,6 +60,8 @@ public abstract class AbstractAction * enabled */ protected boolean enabled = true; + + public static final String ENABLED_PROPERTY = "enabled"; /** * changeSupport @@ -162,7 +164,12 @@ public abstract class AbstractAction */ public void putValue(String key, Object value) { - store.put(key, value); + Object old = getValue(key); + if (old != value) + { + store.put(key, value); + firePropertyChange(key, old, value); + } } /** @@ -182,7 +189,11 @@ public abstract class AbstractAction */ public void setEnabled(boolean enabled) { - this.enabled = enabled; + if (enabled != this.enabled) + { + this.enabled = enabled; + firePropertyChange(ENABLED_PROPERTY, !this.enabled, this.enabled); + } } /** @@ -195,17 +206,31 @@ public abstract class AbstractAction } /** - * firePropertyChange + * This method fires a PropertyChangeEvent given the propertyName + * and the old and new values. * - * @param propertyName TODO - * @param oldValue TODO - * @param newValue TODO + * @param propertyName The property that changed. + * @param oldValue The old value of the property. + * @param newValue The new value of the property. */ protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) { changeSupport.firePropertyChange(propertyName, oldValue, newValue); } + + /** + * This convenience method fires a PropertyChangeEvent given + * the propertyName and the old and new values. + * + * @param propertyName The property that changed. + * @param oldValue The old value of the property. + * @param newValue The new value of the property. + */ + private void firePropertyChange(String propertyName, boolean oldValue, boolean newValue) + { + changeSupport.firePropertyChange(propertyName, oldValue, newValue); + } /** * addPropertyChangeListener diff --git a/libjava/javax/swing/AbstractButton.java b/libjava/javax/swing/AbstractButton.java index b2d2c52b8c2..745afc92467 100644 --- a/libjava/javax/swing/AbstractButton.java +++ b/libjava/javax/swing/AbstractButton.java @@ -154,6 +154,8 @@ import javax.swing.text.AttributeSet; public abstract class AbstractButton extends JComponent implements ItemSelectable, SwingConstants { + private static final long serialVersionUID = -937921345538462020L; + /** The icon displayed by default. */ Icon default_icon; @@ -292,9 +294,10 @@ public abstract class AbstractButton extends JComponent extends AccessibleJComponent implements AccessibleAction, AccessibleValue, AccessibleText { - protected AccessibleAbstractButton(JComponent c) + private static final long serialVersionUID = -5673062525319836790L; + + protected AccessibleAbstractButton() { - super(c); } public AccessibleStateSet getAccessibleStateSet() @@ -459,7 +462,7 @@ public abstract class AbstractButton extends JComponent /** * Creates a new AbstractButton object. */ - AbstractButton() + public AbstractButton() { this("",null); } @@ -472,28 +475,7 @@ public abstract class AbstractButton extends JComponent */ AbstractButton(String txt, Icon icon) { - text = txt; - default_icon = icon; - model = new DefaultButtonModel(); - actionListener = createActionListener(); - changeListener = createChangeListener(); - itemListener = createItemListener(); - - model.addActionListener(actionListener); - model.addChangeListener(changeListener); - model.addItemListener(itemListener); - - hori_align = CENTER; - hori_text_pos = TRAILING; - vert_align = CENTER; - vert_text_pos = CENTER; - paint_border = true; - content_area_filled = true; - - setAlignmentX(LEFT_ALIGNMENT); - setAlignmentY(CENTER_ALIGNMENT); - - addFocusListener(new ButtonFocusListener()); + init (txt, icon); updateUI(); } @@ -538,6 +520,32 @@ public abstract class AbstractButton extends JComponent repaint(); } + protected void init(String text, Icon icon) + { + this.text = text; + default_icon = icon; + model = new DefaultButtonModel(); + actionListener = createActionListener(); + changeListener = createChangeListener(); + itemListener = createItemListener(); + + model.addActionListener(actionListener); + model.addChangeListener(changeListener); + model.addItemListener(itemListener); + + hori_align = CENTER; + hori_text_pos = TRAILING; + vert_align = CENTER; + vert_text_pos = CENTER; + paint_border = true; + content_area_filled = true; + + setAlignmentX(LEFT_ALIGNMENT); + setAlignmentY(CENTER_ALIGNMENT); + + addFocusListener(new ButtonFocusListener()); + } + /** * Get the action command string for this button's model. * @@ -1036,15 +1044,17 @@ public abstract class AbstractButton extends JComponent action.removePropertyChangeListener(actionPropertyChangeListener); actionPropertyChangeListener = null; } - actionPropertyChangeListener = createActionPropertyChangeListener(a); + + } + Action old = action; action = a; configurePropertiesFromAction(action); - if (action != null) { + actionPropertyChangeListener = createActionPropertyChangeListener(a); action.addPropertyChangeListener(actionPropertyChangeListener); addActionListener(action); } @@ -1067,15 +1077,15 @@ public abstract class AbstractButton extends JComponent * @param i The new default icon */ public void setIcon(Icon i) + { + if (default_icon != i) { - Icon old = default_icon; - default_icon = i; - if (old != i) - { - firePropertyChange(ICON_CHANGED_PROPERTY, old, i); + Icon old = default_icon; + default_icon = i; + firePropertyChange(ICON_CHANGED_PROPERTY, old, i); revalidate(); repaint(); - } + } } /** @@ -1204,6 +1214,10 @@ public abstract class AbstractButton extends JComponent */ public Icon getDisabledIcon() { + if (disabled_icon == null + && default_icon instanceof ImageIcon) + disabled_icon = new ImageIcon(GrayFilter.createDisabledImage(((ImageIcon) default_icon).getImage())); + return disabled_icon; } @@ -1375,7 +1389,8 @@ public abstract class AbstractButton extends JComponent setIcon((Icon)(a.getValue(Action.SMALL_ICON))); setEnabled(a.isEnabled()); setToolTipText((String)(a.getValue(Action.SHORT_DESCRIPTION))); - setMnemonic(((Integer)(a.getValue(Action.MNEMONIC_KEY))).intValue()); + if (a.getValue(Action.MNEMONIC_KEY) != null) + setMnemonic(((Integer)(a.getValue(Action.MNEMONIC_KEY))).intValue()); setActionCommand((String)(a.getValue(Action.ACTION_COMMAND_KEY))); } } @@ -1433,9 +1448,21 @@ public abstract class AbstractButton extends JComponent { public void propertyChange(PropertyChangeEvent e) { - Action act = (Action)(e.getSource()); - AbstractButton.this.configurePropertiesFromAction(act); - } + Action act = (Action) (e.getSource()); + if (e.getPropertyName().equals(AbstractAction.ENABLED_PROPERTY)) + setEnabled(act.isEnabled()); + else if (e.getPropertyName().equals(Action.NAME)) + setText((String)(act.getValue(Action.NAME))); + else if (e.getPropertyName().equals(Action.SMALL_ICON)) + setIcon((Icon)(act.getValue(Action.SMALL_ICON))); + else if (e.getPropertyName().equals(Action.SHORT_DESCRIPTION)) + setToolTipText((String)(act.getValue(Action.SHORT_DESCRIPTION))); + else if (e.getPropertyName().equals(Action.MNEMONIC_KEY)) + if (act.getValue(Action.MNEMONIC_KEY) != null) + setMnemonic(((Integer)(act.getValue(Action.MNEMONIC_KEY))).intValue()); + else if (e.getPropertyName().equals(Action.ACTION_COMMAND_KEY)) + setActionCommand((String)(act.getValue(Action.ACTION_COMMAND_KEY))); + } }; } diff --git a/libjava/javax/swing/Box.java b/libjava/javax/swing/Box.java index 6c3579c8ded..f5d090e0b9d 100644 --- a/libjava/javax/swing/Box.java +++ b/libjava/javax/swing/Box.java @@ -1,5 +1,5 @@ /* Box.java -- - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2004 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -55,8 +55,12 @@ public class Box extends JComponent implements Accessible { private static final long serialVersionUID = 1525417495883046342L; - protected class AccessibleBox extends AccessibleAWTContainer + protected class AccessibleBox + // FIXME: disable to make libjava compile; visibility rules are broken + // extends Container.AccessibleAWTContainer { + private static final long serialVersionUID = -7775079816389931944L; + protected AccessibleBox() { } @@ -69,8 +73,14 @@ public class Box extends JComponent implements Accessible public static class Filler extends JComponent implements Accessible { - protected class AccessibleBoxFiller// extends AccessibleAWTComponent + private static final long serialVersionUID = -1204263191910183998L; + + protected class AccessibleBoxFiller + // FIXME: disable to make libjava compile; visibility rules are broken + // extends Component.AccessibleAWTComponent { + private static final long serialVersionUID = 164963348357479321L; + protected AccessibleBoxFiller() { } @@ -99,8 +109,9 @@ public class Box extends JComponent implements Accessible public AccessibleContext getAccessibleContext() { -// if (accessibleContext == null) -// accessibleContext = new AccessibleBoxFiller(); + // FIXME: disable to make libjava compile; visibility rules are broken + // if (accessibleContext == null) + // accessibleContext = new AccessibleBoxFiller(); return accessibleContext; } @@ -172,8 +183,8 @@ public class Box extends JComponent implements Accessible public AccessibleContext getAccessibleContext() { - if (accessibleContext == null) - accessibleContext = new AccessibleBox(); + // if (accessibleContext == null) + // accessibleContext = new AccessibleBox(); return accessibleContext; } diff --git a/libjava/javax/swing/ButtonGroup.java b/libjava/javax/swing/ButtonGroup.java index b59d5659434..8202fa6cb82 100644 --- a/libjava/javax/swing/ButtonGroup.java +++ b/libjava/javax/swing/ButtonGroup.java @@ -1,4 +1,4 @@ -/* ButtonGroup.java -- +/* ButtonGroup.java -- Copyright (C) 2002 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -35,97 +35,145 @@ this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ - package javax.swing; import java.io.Serializable; import java.util.Enumeration; import java.util.Vector; -public class ButtonGroup implements Serializable -{ - static final long serialVersionUID = 4259076101881721375L; - - Vector v = new Vector(); - ButtonModel sel; - - public ButtonGroup() {} - - public void add(AbstractButton b) - { - b.getModel().setGroup(this); - v.addElement(b); - } - - public void remove(AbstractButton b) - { - b.getModel().setGroup(null); - v.removeElement(b); - } - - - public Enumeration getElements() { - return v.elements(); - } - - public ButtonModel getSelection() { - return sel; - } - - AbstractButton FindButton(ButtonModel m) - { - for (int i=0;i<v.size();i++) - { - AbstractButton a = (AbstractButton) v.get(i); - if (a.getModel()== m) - { - return a; - } - } - return null; - } - - public void setSelected(ButtonModel m, boolean b) - { - if ((m == sel) && - (b == true)) - { - // clicked on sam item twice. - System.out.println("PRESSED TWICE:" + m + ", sel="+sel); - return; - } - - if (sel != null) - { - - System.out.println("DESELECTING: " + sel); - sel.setSelected(!b); - - AbstractButton but = FindButton(sel); - if (but != null) - { - System.out.println("REPAINT-REQUIST: " + but.text); - //but.revalidate(); - but.repaint(); - } - } - else - { - System.out.println("NO SELECTION YET"); - } - - sel = m; - } - - public boolean isSelected(ButtonModel m) - { - return (m == sel); - } - - public int getButtonCount() - { - return v.size(); - } +public class ButtonGroup + implements Serializable +{ + private static final long serialVersionUID = 4259076101881721375L; + + /** + * The buttons added to this button group. + */ + protected Vector buttons = new Vector(); + + /** + * The currently selected button model. + */ + ButtonModel sel; + + /** + * Creates a new button group. + */ + public ButtonGroup() + { + } + + /** + * Adds a button to this group. + * + * @param b the button to add + */ + public void add(AbstractButton b) + { + b.getModel().setGroup(this); + buttons.addElement(b); + } + + /** + * Removed a given button from this group. + * + * @param b the button to remove + */ + public void remove(AbstractButton b) + { + b.getModel().setGroup(null); + buttons.removeElement(b); + } + + /** + * Returns the currently added buttons. + * + * @return <code>Enumeration</code> over all added buttons + */ + public Enumeration getElements() + { + return buttons.elements(); + } + + /** + * Returns the currently selected button model. + * + * @return the currently selected button model, + * null if none was selected yet + */ + public ButtonModel getSelection() + { + return sel; + } + + AbstractButton FindButton(ButtonModel m) + { + for (int i = 0;i < buttons.size(); i++) + { + AbstractButton a = (AbstractButton) buttons.get(i); + if (a.getModel() == m) + return a; + } + return null; + } + + /** + * Sets the currently selected button model. Only one button of a group + * can be selected at a time. + * + * @param m the model to select + * @param b true if this button is to be selected, false otherwise + */ + public void setSelected(ButtonModel m, boolean b) + { + if ((m == sel) && (b == true)) + { + // clicked on same item twice. + System.out.println("PRESSED TWICE:" + m + ", sel=" + sel); + return; + } + + if (sel != null) + { + System.out.println("DESELECTING: " + sel); + sel.setSelected(! b); + + AbstractButton but = FindButton(sel); + if (but != null) + { + System.out.println("REPAINT-REQUEST: " + but.text); + //but.revalidate(); + but.repaint(); + } + } + else + System.out.println("NO SELECTION YET"); + + sel = m; + } + + /** + * Checks if the given <code>ButtonModel</code> is selected + * in this button group. + * + * @return true of given <code>ButtonModel</code> is selected, + * false otherwise + */ + public boolean isSelected(ButtonModel m) + { + return m == sel; + } + + /** + * Return the number of buttons in this button group. + * + * @return the number of buttons + * + * @since 1.3 + */ + public int getButtonCount() + { + return buttons.size(); + } } - diff --git a/libjava/javax/swing/CellRendererPane.java b/libjava/javax/swing/CellRendererPane.java index 6e2ba210a64..246916d01d9 100644 --- a/libjava/javax/swing/CellRendererPane.java +++ b/libjava/javax/swing/CellRendererPane.java @@ -56,50 +56,30 @@ public class CellRendererPane extends Container implements Accessible { private static final long serialVersionUID = -7642183829532984273L; - //------------------------------------------------------------- - // Classes ---------------------------------------------------- - //------------------------------------------------------------- - - /** - * AccessibleCellRendererPane - */ - protected class AccessibleCellRendererPane extends AccessibleAWTContainer { - - private static final long serialVersionUID = 7300340301783504481L; - - //------------------------------------------------------------- - // Initialization --------------------------------------------- - //------------------------------------------------------------- - - /** - * Constructor AccessibleCellRendererPane - * @param component TODO - */ - protected AccessibleCellRendererPane(CellRendererPane component) { - super(); - // TODO - } // AccessibleCellRendererPane() - - - //------------------------------------------------------------- - // Methods ---------------------------------------------------- - //------------------------------------------------------------- - - /** - * getAccessibleRole - * @returns AccessibleRole - */ - public AccessibleRole getAccessibleRole() { - return AccessibleRole.PANEL; - } // getAccessibleRole() - - - } // AccessibleCellRendererPane - - - //------------------------------------------------------------- - // Variables -------------------------------------------------- - //------------------------------------------------------------- + /** + * AccessibleCellRendererPane + */ + protected class AccessibleCellRendererPane extends AccessibleAWTContainer + { + private static final long serialVersionUID = -8981090083147391074L; + + /** + * Constructor AccessibleCellRendererPane + * @param component TODO + */ + protected AccessibleCellRendererPane() + { + } + + /** + * getAccessibleRole + * @returns AccessibleRole + */ + public AccessibleRole getAccessibleRole() + { + return AccessibleRole.PANEL; + } + } /** * accessibleContext @@ -209,16 +189,15 @@ public class CellRendererPane extends Container implements Accessible // TODO } // paintComponent() - /** - * getAccessibleContext - * @returns AccessibleContext - */ - public AccessibleContext getAccessibleContext() { - if (accessibleContext == null) { - accessibleContext = new AccessibleCellRendererPane(this); - } // if - return accessibleContext; - } // getAccessibleContext() - - -} // CellRendererPane + /** + * getAccessibleContext + * @return AccessibleContext + */ + public AccessibleContext getAccessibleContext() + { + if (accessibleContext == null) + accessibleContext = new AccessibleCellRendererPane(); + + return accessibleContext; + } +} diff --git a/libjava/javax/swing/DefaultButtonModel.java b/libjava/javax/swing/DefaultButtonModel.java index a608de4488c..e9a1356e8a6 100644 --- a/libjava/javax/swing/DefaultButtonModel.java +++ b/libjava/javax/swing/DefaultButtonModel.java @@ -41,6 +41,7 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; +import java.awt.event.KeyEvent; import java.io.Serializable; import java.util.EventListener; @@ -80,56 +81,52 @@ public class DefaultButtonModel implements ButtonModel, Serializable /** Indicates that the button is <em>partially</em> committed to being pressed, but not entirely. This usually happens when a user has pressed but not yet released the mouse button. */ - static int ARMED = 1; + public static final int ARMED = 1; /** State constant indicating that the button is enabled. Buttons cannot be pressed or selected unless they are enabled. */ - static int ENABLED = 2; + public static final int ENABLED = 8; /** State constant indicating that the user is holding down the button. When this transitions from true to false, an ActionEvent may be fired, depending on the value of the "armed" property.*/ - static int PRESSED = 4; + public static final int PRESSED = 4; /** State constant indicating that the mouse is currently positioned over the button. */ - static int ROLLOVER = 8; + public static final int ROLLOVER = 16; /** State constant indicating that the button is selected. This constant is only meaningful for toggle-type buttons (radio buttons, checkboxes). */ - static int SELECTED = 16; + public static final int SELECTED = 2; /** Represents the "state properties" (armed, enabled, pressed, rollover and selected) by a bitwise combination of integer constants. */ - int stateMask; + protected int stateMask = ENABLED; /** List of ItemListeners, ChangeListeners, and ActionListeners registered on this model. */ - EventListenerList listenerList; + protected EventListenerList listenerList = new EventListenerList();; /** The single ChangeEvent this model (re)uses to call its ChangeListeners. */ - ChangeEvent changeEvent; + protected ChangeEvent changeEvent = new ChangeEvent(this); /** The group this model belongs to. Only one button in a group may be selected at any given time. */ - ButtonGroup group; + protected ButtonGroup group; /** The key code (one of {@link java.awt.event.KeyEvent} VK_*) used to press this button via a keyboard interface. */ - int mnemonic; + protected int mnemonic = KeyEvent.VK_UNDEFINED; /** The string used as the "command" property of any ActionEvent this model sends. */ - String actionCommand; + protected String actionCommand; public DefaultButtonModel() { - stateMask = ENABLED; - mnemonic = java.awt.event.KeyEvent.VK_UNDEFINED; - listenerList = new EventListenerList(); - changeEvent = new ChangeEvent(this); } /** @@ -144,6 +141,18 @@ public class DefaultButtonModel implements ButtonModel, Serializable } /** + * Returns a specified class of listeners. + * + * @param listenerType the type of listener to return + * + * @return array of listeners + */ + public EventListener[] getListeners(Class listenerType) + { + return listenerList.getListeners(listenerType); + } + + /** * Add an ActionListener to the model. Usually only called to subscribe * an AbstractButton's listener to the model. * @@ -166,6 +175,16 @@ public class DefaultButtonModel implements ButtonModel, Serializable } /** + * Returns all registered <code>ActionListener</code> objects. + * + * @return array of <code>ActionListener</code> objects + */ + public ActionListener[] getActionListeners() + { + return (ActionListener[]) listenerList.getListeners(ActionListener.class); + } + + /** * Add an ItemListener to the model. Usually only called to subscribe * an AbstractButton's listener to the model. * @@ -188,6 +207,16 @@ public class DefaultButtonModel implements ButtonModel, Serializable } /** + * Returns all registered <code>ItemListener</code> objects. + * + * @return array of <code>ItemListener</code> objects + */ + public ItemListener[] getItemListeners() + { + return (ItemListener[]) listenerList.getListeners(ItemListener.class); + } + + /** * Add a ChangeListener to the model. Usually only called to subscribe * an AbstractButton's listener to the model. * @@ -210,6 +239,16 @@ public class DefaultButtonModel implements ButtonModel, Serializable } /** + * Returns all registered <code>ChangeListener</code> objects. + * + * @return array of <code>ChangeListener</code> objects + */ + public ChangeListener[] getChangeListeners() + { + return (ChangeListener[]) listenerList.getListeners(ChangeListener.class); + } + + /** * Inform each ItemListener in the {@link listenerList} that an ItemEvent * has occurred. This happens in response to any change to the {@link * stateMask} field. @@ -218,9 +257,10 @@ public class DefaultButtonModel implements ButtonModel, Serializable */ public void fireItemStateChanged(ItemEvent e) { - EventListener[] ll = listenerList.getListeners(ItemListener.class); + ItemListener[] ll = getItemListeners(); + for (int i = 0; i < ll.length; i++) - ((ItemListener)ll[i]).itemStateChanged(e); + ll[i].itemStateChanged(e); } /** @@ -233,9 +273,10 @@ public class DefaultButtonModel implements ButtonModel, Serializable */ public void fireActionPerformed(ActionEvent e) { - EventListener[] ll = listenerList.getListeners(ActionListener.class); + ActionListener[] ll = getActionListeners(); + for (int i = 0; i < ll.length; i++) - ((ActionListener)ll[i]).actionPerformed(e); + ll[i].actionPerformed(e); } /** @@ -245,11 +286,12 @@ public class DefaultButtonModel implements ButtonModel, Serializable * * @param event The ChangeEvent to fire */ - public void fireStateChanged(ChangeEvent e) + public void fireStateChanged() { - EventListener[] ll = listenerList.getListeners(ChangeListener.class); + ChangeListener[] ll = getChangeListeners(); + for (int i = 0; i < ll.length; i++) - ((ChangeListener)ll[i]).stateChanged(e); + ll[i].stateChanged(changeEvent); } /** @@ -276,7 +318,7 @@ public class DefaultButtonModel implements ButtonModel, Serializable stateMask = newstate; - fireStateChanged(changeEvent); + fireStateChanged(); if ((oldstate & SELECTED) == 0 && (newstate & SELECTED) == SELECTED) @@ -418,7 +460,7 @@ public class DefaultButtonModel implements ButtonModel, Serializable if (mnemonic != key) { mnemonic = key; - fireStateChanged(changeEvent); + fireStateChanged(); } } @@ -434,14 +476,12 @@ public class DefaultButtonModel implements ButtonModel, Serializable if (actionCommand != s) { actionCommand = s; - fireStateChanged(changeEvent); + fireStateChanged(); } } /** - * Set the value of the model's "actionCommand" property. This property - * is used as the "command" property of the {@link ActionEvent} fired - * from the model. + * Returns the current value of the model's "actionCommand" property. * * @return The current "actionCommand" property */ @@ -453,7 +493,7 @@ public class DefaultButtonModel implements ButtonModel, Serializable /** * Set the value of the model's "group" property. The model is said to be * a member of the {@link ButtonGroup} held in its "group" property, and - * only one models in a given group can have their "selected" property be + * only one model in a given group can have their "selected" property be * <code>true</code> at a time. * * @param g The new "group" property @@ -463,7 +503,17 @@ public class DefaultButtonModel implements ButtonModel, Serializable if (group != g) { group = g; - fireStateChanged(changeEvent); + fireStateChanged(); } } + + /** + * Returns the current value of the model's "group" property. + * + * @return The value of the "group" property + */ + public ButtonGroup getGroup() + { + return group; + } } diff --git a/libjava/javax/swing/DefaultCellEditor.java b/libjava/javax/swing/DefaultCellEditor.java index 3c862bd5480..39da1fb9f8e 100644 --- a/libjava/javax/swing/DefaultCellEditor.java +++ b/libjava/javax/swing/DefaultCellEditor.java @@ -58,50 +58,34 @@ public class DefaultCellEditor { static final long serialVersionUID = 3564035141373880027L; - //------------------------------------------------------------- - // Classes ---------------------------------------------------- - //------------------------------------------------------------- - - /** - * EditorDelegate - */ - protected class EditorDelegate implements ActionListener, - ItemListener, Serializable { - - //------------------------------------------------------------- - // Variables -------------------------------------------------- - //------------------------------------------------------------- - - /** - * value - */ - protected Object value; - - - //------------------------------------------------------------- - // Initialization --------------------------------------------- - //------------------------------------------------------------- - - /** - * Constructor EditorDelegate - * @param value0 TODO - */ - protected EditorDelegate(DefaultCellEditor editor) { - // TODO - } // EditorDelegate() - - - //------------------------------------------------------------- - // Methods ---------------------------------------------------- - //------------------------------------------------------------- - - /** - * setValue - * @param event TODO - */ - public void setValue(Object event) { - // TODO - } // setValue() + /** + * EditorDelegate + */ + protected class EditorDelegate + implements ActionListener, ItemListener, Serializable + { + private static final long serialVersionUID = -1420007406015481933L; + + /** + * value + */ + protected Object value; + + /** + * Constructor EditorDelegate + * @param value0 TODO + */ + protected EditorDelegate() + { + } + + /** + * setValue + * @param event TODO + */ + public void setValue(Object event) + { + } /** * getCellEditorValue @@ -172,11 +156,6 @@ public class DefaultCellEditor } // EditorDelegate - - //------------------------------------------------------------- - // Variables -------------------------------------------------- - //------------------------------------------------------------- - /** * editorComponent */ @@ -192,11 +171,6 @@ public class DefaultCellEditor */ protected int clickCountToStart; - - //------------------------------------------------------------- - // Initialization --------------------------------------------- - //------------------------------------------------------------- - /** * Constructor DefaultCellEditor * @param textfield TODO @@ -221,11 +195,6 @@ public class DefaultCellEditor // TODO } // DefaultCellEditor() - - //------------------------------------------------------------- - // Methods ---------------------------------------------------- - //------------------------------------------------------------- - /** * getComponent * @returns Component @@ -320,6 +289,4 @@ public class DefaultCellEditor Object value, boolean isSelected, int row, int column) { return null; // TODO } // getTableCellEditorComponent() - - -} // DefaultCellEditor +} diff --git a/libjava/javax/swing/DefaultDesktopManager.java b/libjava/javax/swing/DefaultDesktopManager.java index f99abef54bb..40b78b87731 100644 --- a/libjava/javax/swing/DefaultDesktopManager.java +++ b/libjava/javax/swing/DefaultDesktopManager.java @@ -37,249 +37,618 @@ exception statement from your version. */ package javax.swing; +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.Rectangle; +import java.beans.PropertyVetoException; import java.io.Serializable; +import javax.swing.JDesktopPane; +import javax.swing.JInternalFrame; +import javax.swing.JInternalFrame.JDesktopIcon; + /** - * DefaultDesktopManager - * @author Andrew Selkirk - * @version 1.0 + * DefaultDesktopManager is the default implementation of DesktopManager for + * swing. It implements the basic beaviours for JInternalFrames in arbitrary + * parents. The methods provided by the class are not meant to be called by + * the user, instead, the JInternalFrame methods will call these methods. */ public class DefaultDesktopManager implements DesktopManager, Serializable { + /** DOCUMENT ME! */ static final long serialVersionUID = 4657624909838017887L; - //------------------------------------------------------------- - // Variables -------------------------------------------------- - //------------------------------------------------------------- - - /** - * HAS_BEEN_ICONIFIED_PROPERTY - */ - static final String HAS_BEEN_ICONIFIED_PROPERTY = ""; // TODO - - /** - * DEFAULT_DRAG_MODE - */ - static final int DEFAULT_DRAG_MODE = 0; // TODO - - /** - * OUTLINE_DRAG_MODE - */ - static final int OUTLINE_DRAG_MODE = 0; // TODO - - /** - * FASTER_DRAG_MODE - */ - static final int FASTER_DRAG_MODE = 0; // TODO - - /** - * dragMode - */ - int dragMode; - - - //------------------------------------------------------------- - // Initialization --------------------------------------------- - //------------------------------------------------------------- - - /** - * Constructor DefaultDesktopManager - */ - public DefaultDesktopManager() { - // TODO - } // DefaultDesktopManager() - - - //------------------------------------------------------------- - // Methods ---------------------------------------------------- - //------------------------------------------------------------- - - /** - * openFrame - * @param frame TODO - */ - public void openFrame(JInternalFrame frame) { - // TODO - } // openFrame() - - /** - * closeFrame - * @param frame TODO - */ - public void closeFrame(JInternalFrame frame) { - // TODO - } // closeFrame() - - /** - * maximizeFrame - * @param frame TODO - */ - public void maximizeFrame(JInternalFrame frame) { - // TODO - } // maximizeFrame() - - /** - * minimizeFrame - * @param frame TODO - */ - public void minimizeFrame(JInternalFrame frame) { - // TODO - } // minimizeFrame() - - /** - * iconifyFrame - * @param frame TODO - */ - public void iconifyFrame(JInternalFrame frame) { - // TODO - } // iconifyFrame() - - /** - * deiconifyFrame - * @param frame TODO - */ - public void deiconifyFrame(JInternalFrame frame) { - // TODO - } // deiconifyFrame() - - /** - * activateFrame - * @param frame TODO - */ - public void activateFrame(JInternalFrame frame) { - // TODO - } // activateFrame() - - /** - * deactivateFrame - * @param frame TODO - */ - public void deactivateFrame(JInternalFrame frame) { - // TODO - } // deactivateFrame() - - /** - * beginDraggingFrame - * @param component TODO - */ - public void beginDraggingFrame(JComponent component) { - // TODO - } // beginDraggingFrame() - - /** - * dragFrame - * @param component TODO - * @param newX TODO - * @param newY TODO - */ - public void dragFrame(JComponent component, int newX, int newY) { - // TODO - } // dragFrame() - - /** - * endDraggingFrame - * @param component TODO - */ - public void endDraggingFrame(JComponent component) { - // TODO - } // endDraggingFrame() - - /** - * beginResizingFrame - * @param component TODO - * @param direction TODO - */ - public void beginResizingFrame(JComponent component, int direction) { - // TODO - } // beginResizingFrame() - - /** - * resizeFrame - * @param component TODO - * @param newX TODO - * @param newY TODO - * @param newWidth TODO - * @param newHeight TODO - */ - public void resizeFrame(JComponent component, int newX, int newY, - int newWidth, int newHeight) { - // TODO - } // resizeFrame() - - /** - * endResizingFrame - * @param component TODO - */ - public void endResizingFrame(JComponent component) { - // TODO - } // endResizingFrame() - - /** - * setBoundsForFrame - * @param component TODO - * @param newX TODO - * @param newY TODO - * @param newWidth TODO - * @param newHeight TODO - */ - public void setBoundsForFrame(JComponent component, int newX, - int newY, int newWidth, int newHeight) { - // TODO - } // setBoundsForFrame() - - /** - * removeIconFor - * @param frame TODO - */ - protected void removeIconFor(JInternalFrame frame) { - // TODO - } // removeIconFor() - - /** - * getBoundsForIconOf - * @param frame TODO - * @returns Rectangle - */ - protected Rectangle getBoundsForIconOf(JInternalFrame frame) { - return null; // TODO - } // getBoundsForIconOf() - - /** - * setPreviousBounds - * @param frame TODO - * @param rect TODO - */ - protected void setPreviousBounds(JInternalFrame frame, Rectangle rect) { - // TODO - } // setPreviousBounds() - - /** - * getPreviousBounds - * @param frame TODO - * @returns Rectangle - */ - protected Rectangle getPreviousBounds(JInternalFrame frame) { - return null; // TODO - } // getPreviousBounds() - - /** - * setWasIcon - * @param frame TODO - * @param value TODO - */ - protected void setWasIcon(JInternalFrame frame, Boolean value) { - // TODO - } // setWasIcon() - - /** - * wasIcon - * @param frame TODO - * @returns boolean - */ - protected boolean wasIcon(JInternalFrame frame) { - return false; // TODO - } // wasIcon() - - + /** The property change event fired when the wasIcon property changes. */ + static final String WAS_ICON_ONCE_PROPERTY = "wasIconOnce"; + + /** + * The method of dragging used by the JDesktopPane that parents the + * JInternalFrame that is being dragged. + */ + private int currentDragMode = 0; + + /** + * The cache of the bounds used to draw the outline rectangle when + * OUTLINE_DRAG_MODE is used. + */ + private transient Rectangle dragCache = new Rectangle(); + + /** + * A cached JDesktopPane that is stored when the JInternalFrame is initially + * dragged. + */ + private transient Container pane; + + /** + * An array of Rectangles that holds the bounds of the JDesktopIcons in the + * JDesktopPane when looking for where to place a new icon. + */ + private transient Rectangle[] iconRects; + + /** + * This creates a new DefaultDesktopManager object. + */ + public DefaultDesktopManager() + { + } // DefaultDesktopManager() + + /** + * This method is not normally called since the user will typically add the + * JInternalFrame to a Container. If this is called, it will try to + * determine the parent of the JInternalFrame and remove any icon that + * represents this JInternalFrame and add this JInternalFrame. + * + * @param frame The JInternalFrame to open. + */ + public void openFrame(JInternalFrame frame) + { + Container c = frame.getParent(); + if (c == null) + c = frame.getDesktopIcon().getParent(); + if (c == null) + return; + + c.remove(frame.getDesktopIcon()); + c.add(frame); + frame.setVisible(true); + } // openFrame() + + /** + * This method removes the JInternalFrame and JDesktopIcon (if one is + * present) from their parents. + * + * @param frame The JInternalFrame to close. + */ + public void closeFrame(JInternalFrame frame) + { + Container c = frame.getParent(); + frame.doDefaultCloseAction(); + + if (c != null) + { + if (frame.isIcon()) + c.remove(frame.getDesktopIcon()); + else + c.remove(frame); + c.repaint(); + } + } // closeFrame() + + /** + * This method resizes the JInternalFrame to match its parent's bounds. + * + * @param frame The JInternalFrame to maximize. + */ + public void maximizeFrame(JInternalFrame frame) + { + // Can't maximize from iconified state. + // It can only return to maximized state, but that would fall under + // deiconify. + if (frame.isIcon()) + return; + frame.setNormalBounds(frame.getBounds()); + + Container p = frame.getParent(); + if (p != null) + { + Rectangle pBounds = p.getBounds(); + Insets insets = p.getInsets(); + pBounds.width -= insets.left + insets.right; + pBounds.height -= insets.top + insets.bottom; + + setBoundsForFrame(frame, 0, 0, pBounds.width, pBounds.height); + } + if (p instanceof JDesktopPane) + ((JDesktopPane) p).setSelectedFrame(frame); + else + { + try + { + frame.setSelected(true); + } + catch (PropertyVetoException e) + { + // Do nothing. + } + } + } // maximizeFrame() + + /** + * This method restores the JInternalFrame's bounds to what they were + * previous to the setMaximize call. + * + * @param frame The JInternalFrame to minimize. + */ + public void minimizeFrame(JInternalFrame frame) + { + Rectangle normalBounds = frame.getNormalBounds(); + + JDesktopPane p = frame.getDesktopPane(); + if (p != null) + p.setSelectedFrame(frame); + else + { + try + { + frame.setSelected(true); + } + catch (PropertyVetoException e) + { + // Do nothing. + } + } + + setBoundsForFrame(frame, normalBounds.x, normalBounds.y, + normalBounds.width, normalBounds.height); + } // minimizeFrame() + + /** + * This method removes the JInternalFrame from its parent and adds its + * JDesktopIcon representation. + * + * @param frame The JInternalFrame to iconify. + */ + public void iconifyFrame(JInternalFrame frame) + { + JDesktopPane p = frame.getDesktopPane(); + JDesktopIcon icon = frame.getDesktopIcon(); + if (p != null && p.getSelectedFrame() == frame) + p.setSelectedFrame(null); + else + { + try + { + frame.setSelected(false); + } + catch (PropertyVetoException e) + { + } + } + + Container c = frame.getParent(); + + if (! wasIcon(frame)) + { + Rectangle r = getBoundsForIconOf(frame); + icon.setBounds(r); + setWasIcon(frame, true); + } + + if (c != null) + { + if (icon != null) + { + c.add(icon); + icon.setVisible(true); + } + c.remove(frame); + } + } // iconifyFrame() + + /** + * This method removes the JInternalFrame's JDesktopIcon representation and + * adds the JInternalFrame back to its parent. + * + * @param frame The JInternalFrame to deiconify. + */ + public void deiconifyFrame(JInternalFrame frame) + { + JDesktopIcon icon = frame.getDesktopIcon(); + Container c = icon.getParent(); + + removeIconFor(frame); + c.add(frame); + frame.setVisible(true); + + if (! frame.isSelected()) + { + JDesktopPane p = frame.getDesktopPane(); + if (p != null) + p.setSelectedFrame(frame); + else + { + try + { + frame.setSelected(true); + } + catch (PropertyVetoException e) + { + // Do nothing. + } + } + } + + c.invalidate(); + } // deiconifyFrame() + + /** + * This method activates the JInternalFrame by moving it to the front and + * selecting it. + * + * @param frame The JInternalFrame to activate. + */ + public void activateFrame(JInternalFrame frame) + { + JDesktopPane p = frame.getDesktopPane(); + + if (p != null) + p.setSelectedFrame(frame); + else + { + try + { + frame.setSelected(true); + } + catch (PropertyVetoException e) + { + } + } + + frame.toFront(); + } // activateFrame() + + /** + * This method is called when the JInternalFrame loses focus. + * + * @param frame The JInternalFram to deactivate. + */ + public void deactivateFrame(JInternalFrame frame) + { + JDesktopPane p = frame.getDesktopPane(); + if (p != null) + { + if (p.getSelectedFrame() == frame) + p.setSelectedFrame(null); + } + else + { + try + { + frame.setSelected(false); + } + catch (PropertyVetoException e) + { + } + } + } // deactivateFrame() + + /** + * This method is called to indicate that the DesktopManager should prepare + * to drag the JInternalFrame. Any state information needed to drag the + * frame will be prepared now. + * + * @param component The JComponent to drag, usually a JInternalFrame. + */ + public void beginDraggingFrame(JComponent component) + { + if (component instanceof JDesktopIcon) + pane = ((JDesktopIcon) component).getInternalFrame().getDesktopPane(); + else + pane = ((JInternalFrame) component).getDesktopPane(); + if (pane == null) + return; + + dragCache = component.getBounds(); + + if (! (pane instanceof JDesktopPane)) + currentDragMode = JDesktopPane.LIVE_DRAG_MODE; + else + currentDragMode = ((JDesktopPane) pane).getDragMode(); + } // beginDraggingFrame() + + /** + * This method is called to drag the JInternalFrame to a new location. + * + * @param component The JComponent to drag, usually a JInternalFrame. + * @param newX The new x coordinate. + * @param newY The new y coordinate. + */ + public void dragFrame(JComponent component, int newX, int newY) + { + if (currentDragMode == JDesktopPane.OUTLINE_DRAG_MODE) + { + // FIXME: Do outline drag mode painting. + } + else + { + Rectangle b = component.getBounds(); + if (component instanceof JDesktopIcon) + component.setBounds(newX, newY, b.width, b.height); + else + setBoundsForFrame((JInternalFrame) component, newX, newY, b.width, + b.height); + } + } // dragFrame() + + /** + * This method indicates that the dragging is done. Any state information + * stored by the DesktopManager can be cleared. + * + * @param component The JComponent that has finished dragging. + */ + public void endDraggingFrame(JComponent component) + { + if (currentDragMode == JDesktopPane.OUTLINE_DRAG_MODE) + { + setBoundsForFrame((JInternalFrame) component, dragCache.x, + dragCache.y, dragCache.width, dragCache.height); + pane = null; + dragCache = null; + } + component.repaint(); + } // endDraggingFrame() + + /** + * This method is called to indicate that the given JComponent will be + * resized. Any state information necessary to resize the JComponent will + * be prepared now. + * + * @param component The JComponent to resize, usually a JInternalFrame. + * @param direction The direction to drag in (a SwingConstant). + */ + public void beginResizingFrame(JComponent component, int direction) + { + pane = ((JInternalFrame) component).getDesktopPane(); + if (pane == null) + return; + + dragCache = component.getBounds(); + if (! (pane instanceof JDesktopPane)) + currentDragMode = JDesktopPane.LIVE_DRAG_MODE; + else + currentDragMode = ((JDesktopPane) pane).getDragMode(); + } // beginResizingFrame() + + /** + * This method resizes the give JComponent. + * + * @param component The JComponent to resize. + * @param newX The new x coordinate. + * @param newY The new y coordinate. + * @param newWidth The new width. + * @param newHeight The new height. + */ + public void resizeFrame(JComponent component, int newX, int newY, + int newWidth, int newHeight) + { + dragCache.setBounds(newX, newY, newWidth, newHeight); + dragCache = findMinimum(dragCache, component); + + if (currentDragMode == JDesktopPane.OUTLINE_DRAG_MODE) + { + // FIXME: Do outline drag painting. + } + else + setBoundsForFrame(component, dragCache.x, dragCache.y, dragCache.width, + dragCache.height); + } // resizeFrame() + + /** + * This method is called to indicate that the given JComponent has finished + * dragging. Any state information stored by the DesktopManager can be + * cleared. + * + * @param component The JComponent that finished resizing. + */ + public void endResizingFrame(JComponent component) + { + if (currentDragMode == JDesktopPane.OUTLINE_DRAG_MODE) + { + setBoundsForFrame((JInternalFrame) component, dragCache.x, + dragCache.y, dragCache.width, dragCache.height); + pane = null; + dragCache = null; + } + component.repaint(); + } // endResizingFrame() + + /** + * This method calls setBounds with the given parameters and repaints the + * JComponent. + * + * @param component The JComponent to set bounds for. + * @param newX The new x coordinate. + * @param newY The new y coordinate. + * @param newWidth The new width. + * @param newHeight The new height. + */ + public void setBoundsForFrame(JComponent component, int newX, int newY, + int newWidth, int newHeight) + { + component.setBounds(newX, newY, newWidth, newHeight); + component.revalidate(); + + // If not null, I'd rather repaint the parent + if (component.getParent() != null) + component.getParent().repaint(); + else + component.repaint(); + } // setBoundsForFrame() + + /** + * This is a helper method that removes the JDesktopIcon of the given + * JInternalFrame from the parent. + * + * @param frame The JInternalFrame to remove an icon for. + */ + protected void removeIconFor(JInternalFrame frame) + { + JDesktopIcon icon = frame.getDesktopIcon(); + Container c = icon.getParent(); + if (c != null && icon != null) + c.remove(icon); + } // removeIconFor() + + /** + * This method is called by iconifyFrame to determine the bounds of the + * JDesktopIcon for the given JInternalFrame. + * + * @param frame The JInternalFrame to find the bounds of its JDesktopIcon + * for. + * + * @return The bounds of the JDesktopIcon. + */ + protected Rectangle getBoundsForIconOf(JInternalFrame frame) + { + // IconRects has no order to it. + // The icon _must_ be placed in the first free slot (working from + // the bottom left corner) + // The icon also must not be placed where another icon is placed + // (regardless whether that frame is an icon currently or not) + JDesktopPane desktopPane = frame.getDesktopPane(); + Rectangle paneBounds = desktopPane.getBounds(); + Insets insets = desktopPane.getInsets(); + Dimension pref = frame.getDesktopIcon().getPreferredSize(); + + if (desktopPane == null) + return frame.getDesktopIcon().getBounds(); + + Component[] frames = desktopPane.getComponents(); + + int count = 0; + for (int i = 0, j = 0; i < frames.length; i++) + if (frames[i] instanceof JDesktopIcon + || frames[i] instanceof JInternalFrame + && ((JInternalFrame) frames[i]).getWasIcon() && frames[i] != frame) + count++; + iconRects = new Rectangle[count]; + for (int i = 0, j = 0; i < frames.length; i++) + if (frames[i] instanceof JDesktopIcon) + iconRects[--count] = frames[i].getBounds(); + else if (frames[i] instanceof JInternalFrame + && ((JInternalFrame) frames[i]).getWasIcon() + && frames[i] != frame) + iconRects[--count] = ((JInternalFrame) frames[i]).getDesktopIcon() + .getBounds(); + + int startingX = insets.left; + int startingY = paneBounds.height - insets.bottom - pref.height; + Rectangle ideal = new Rectangle(startingX, startingY, pref.width, + pref.height); + boolean clear = true; + + while (iconRects.length > 0) + { + clear = true; + for (int i = 0; i < iconRects.length; i++) + { + if (iconRects[i] != null && iconRects[i].intersects(ideal)) + { + clear = false; + break; + } + } + if (clear) + return ideal; + + startingX += pref.width; + if (startingX + pref.width > paneBounds.width - insets.right) + { + startingX = insets.left; + startingY -= pref.height; + } + ideal.setBounds(startingX, startingY, pref.width, pref.height); + } + + return ideal; + } // getBoundsForIconOf() + + /** + * This method sets the bounds of the JInternalFrame right before the + * maximizeFrame call. + * + * @param frame The JInternalFrame being maximized. + * @param rect The normal bounds. + */ + protected void setPreviousBounds(JInternalFrame frame, Rectangle rect) + { + frame.setNormalBounds(rect); + } // setPreviousBounds() + + /** + * This method returns the normal bounds of the JInternalFrame from before + * the maximize call. + * + * @param frame The JInternalFrame that is being restored. + * + * @return The previous bounds of the JInternalFrame. + */ + protected Rectangle getPreviousBounds(JInternalFrame frame) + { + return frame.getNormalBounds(); + } // getPreviousBounds() + + /** + * This method sets the value to true if the given JInternalFrame has been + * iconized and the bounds of its DesktopIcon are valid. + * + * @param frame The JInternalFrame for the JDesktopIcon. + * @param value True if the JInternalFrame has been iconized and the bounds + * of the JDesktopIcon are valid. + */ + protected void setWasIcon(JInternalFrame frame, boolean value) + { + frame.setWasIcon(value, WAS_ICON_ONCE_PROPERTY); + } // setWasIcon() + + /** + * This method returns true if the given JInternalFrame has been iconized + * and the bounds of its DesktopIcon are valid. + * + * @param frame The JInternalFrame for the JDesktopIcon. + * + * @return True if the given JInternalFrame has been iconized and the bounds + * of its DesktopIcon are valid. + */ + protected boolean wasIcon(JInternalFrame frame) + { + return frame.getWasIcon(); + } // wasIcon() + + /** + * This is a helper method that determines the minimum size a + * JInternalFrame can be resized to. + * + * @param r The desired size. + * @param c The JComponent to find a minimum size for. + * + * @return The minimum size a JInternalFrame can be resized to. + */ + private Rectangle findMinimum(Rectangle r, JComponent c) + { + if (r != null && c != null) + { + Dimension d = c.getPreferredSize(); + if (d != null) + { + r.width = Math.max(d.width, r.width); + r.height = Math.max(d.height, r.height); + } + } + return r; + } } // DefaultDesktopManager diff --git a/libjava/javax/swing/DefaultListSelectionModel.java b/libjava/javax/swing/DefaultListSelectionModel.java index fb60b85d42f..67ad1df4173 100644 --- a/libjava/javax/swing/DefaultListSelectionModel.java +++ b/libjava/javax/swing/DefaultListSelectionModel.java @@ -62,6 +62,7 @@ public class DefaultListSelectionModel implements Cloneable, ListSelectionModel, Serializable { + private static final long serialVersionUID = -5718799865110415860L; /** The list of ListSelectionListeners subscribed to this selection model. */ protected EventListenerList listenerList = new EventListenerList(); diff --git a/libjava/javax/swing/DesktopManager.java b/libjava/javax/swing/DesktopManager.java index 222039d1d41..7fbc972c367 100644 --- a/libjava/javax/swing/DesktopManager.java +++ b/libjava/javax/swing/DesktopManager.java @@ -1,5 +1,5 @@ /* DesktopManager.java -- - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2004 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -38,118 +38,140 @@ exception statement from your version. */ package javax.swing; /** - * DesktopManager - * @author Andrew Selkirk - * @version 1.0 + * DesktopManagers are responsible for implementing the behaviours for the + * JInternalFrames that belong to JDesktopPanes. Actions such as maximizing, + * minimizing, iconifying, etc will be delegated to the DesktopManager. */ -public interface DesktopManager { - - //------------------------------------------------------------- - // Methods ---------------------------------------------------- - //------------------------------------------------------------- - - /** - * openFrame - * @param frame TODO - */ - void openFrame(JInternalFrame frame); - - /** - * closeFrame - * @param frame TODO - */ - void closeFrame(JInternalFrame frame); - - /** - * maximizeFrame - * @param frame TODO - */ - void maximizeFrame(JInternalFrame frame); - - /** - * minimizeFrame - * @param frame TODO - */ - void minimizeFrame(JInternalFrame frame); - - /** - * iconifyFrame - * @param frame TODO - */ - void iconifyFrame(JInternalFrame frame); - - /** - * deiconifyFrame - * @param frame TODO - */ - void deiconifyFrame(JInternalFrame frame); - - /** - * activateFrame - * @param frame TODO - */ - void activateFrame(JInternalFrame vframe); - - /** - * deactivateFrame - * @param frame TODO - */ - void deactivateFrame(JInternalFrame frame); - - /** - * beginDraggingFrame - * @param frame TODO - */ - void beginDraggingFrame(JComponent frame); - - /** - * dragFrame - * @param frame TODO - * @param x TODO - * @param y TODO - */ - void dragFrame(JComponent frame, int x, int y); - - /** - * endDraggingFrame - * @param frame TODO - */ - void endDraggingFrame(JComponent frame); - - /** - * beginResizingFrame - * @param frame TODO - * @param direction TODO - */ - void beginResizingFrame(JComponent frame, int direction); - - /** - * resizeFrame - * @param frame TODO - * @param x TODO - * @param y TODO - * @param width TODO - * @param height TODO - */ - void resizeFrame(JComponent frame, int x, int y, - int width, int height); - - /** - * endResizingFrame - * @param frame TODO - */ - void endResizingFrame(JComponent frame); - - /** - * setBoundsForFrame - * @param frame TODO - * @param x TODO - * @param y TODO - * @param width TODO - * @param height TODO - */ - void setBoundsForFrame(JComponent frame, int x, int y, - int width, int height); - - +public interface DesktopManager +{ + /** + * This method will cause the JInternalFrame to be displayed in the set + * location. This usually is not needed since the user will add the + * JInternalFrame to a Container separately. + * + * @param frame The JInternalFrame to open. + */ + void openFrame(JInternalFrame frame); + + /** + * This method should remove the JInternalFrame from its parent. + * + * @param frame The JInternalFrame to close. + */ + void closeFrame(JInternalFrame frame); + + /** + * This method should maximize the JInternalFrame to match its parent's + * bounds. + * + * @param frame The JInternalFrame to maximize. + */ + void maximizeFrame(JInternalFrame frame); + + /** + * This method should restore the JInternalFrame to its normal bounds. + * + * @param frame The JInternalFrame to minimize. + */ + void minimizeFrame(JInternalFrame frame); + + /** + * This method should remove the JInternalFrame from its parent and replace + * it with a JDesktopIcon. + * + * @param frame The JInternalFrame to iconify. + */ + void iconifyFrame(JInternalFrame frame); + + /** + * This method should remove the JDesktopIcon from its parent and replace it + * with the JInternalFrame that the JDesktopIcon represents. + * + * @param frame The JInternalFrame to deiconify. + */ + void deiconifyFrame(JInternalFrame frame); + + /** + * This method should give focus to the JInternalFrame and its default focus + * owner. + * + * @param frame The JInternalFrame to activate. + */ + void activateFrame(JInternalFrame vframe); + + /** + * This method should be called when the JInternalFrame gets deselected and + * subsequently loses focus. + * + * @param frame The JInternalFrame to deactivate. + */ + void deactivateFrame(JInternalFrame frame); + + /** + * This method should be called in preparation for dragging. This needs to + * be called prior to dragFrame calls so that the DesktopManager can + * prepare any state information. + * + * @param frame The JInternalFrame to prepare for dragging. + */ + void beginDraggingFrame(JComponent frame); + + /** + * This method drags the given JInternalFrame to the given x and y + * coordinates. + * + * @param frame The JInternalFrame to drag. + * @param x The new x coordinate. + * @param y The new y coordinate. + */ + void dragFrame(JComponent frame, int x, int y); + + /** + * This method should be called after dragFrame calls. Any information used + * by the DesktopManager for dragging the JInternalFrame can be cleared. + * + * @param frame The JInternalFrame that finished dragging. + */ + void endDraggingFrame(JComponent frame); + + /** + * This method should be called prior to any resizeFrame calls. Any state + * information needed by the DesktopManager to resize the JInternalFrame + * will be prepared here. + * + * @param frame The JInternalFrame to resize. + * @param direction One of eight directions specified by SwingConstants. + */ + void beginResizingFrame(JComponent frame, int direction); + + /** + * This method is called to resize the given JInternalFrame to the given + * bounds. + * + * @param frame The JInternalFrame to resize. + * @param x The new x coordinate. + * @param y The new y coordinate. + * @param width The new width. + * @param height The new height. + */ + void resizeFrame(JComponent frame, int x, int y, int width, int height); + + /** + * This method is called to signify that the resize is finished. Any + * information used to resize the JInternalFrame can now be cleared. + * + * @param frame The JInternalFrame that just finished dragging. + */ + void endResizingFrame(JComponent frame); + + /** + * This method does the actual work for reshaping the JInternalFrame. + * + * @param frame The JInternalFrame to resize. + * @param x The new x coordinate. + * @param y The new y coordinate. + * @param width The new width. + * @param height The new height. + */ + void setBoundsForFrame(JComponent frame, int x, int y, int width, int height); } // DesktopManager diff --git a/libjava/javax/swing/GrayFilter.java b/libjava/javax/swing/GrayFilter.java index 740653d1b9d..39ad4d35630 100644 --- a/libjava/javax/swing/GrayFilter.java +++ b/libjava/javax/swing/GrayFilter.java @@ -45,41 +45,41 @@ import java.awt.Toolkit; public class GrayFilter extends RGBImageFilter { - private boolean b; - private int p; + private boolean b; + private int p; - /** - Create a GrayFilter. If b is true then brighten. Also, indicate how much gray. - - @param b if brighten - @param p percent of gray, 0 - 100 - */ - public GrayFilter(boolean b, int p) - { - this.b = b; //FIXME - HANDLE THIS - this.p = p; - } + /** + * Create a GrayFilter. If b is true then brighten. Also, indicate how much gray. + * + * @param b if brighten + * @param p percent of gray, 0 - 100 + */ + public GrayFilter(boolean b, int p) + { + this.b = b; //FIXME - HANDLE THIS + this.p = p; + } - /** - Create grayed image - - @param i image to gray - - @return a grayed image - */ - public static Image createDisabledImage(Image src) - { - return Toolkit.getDefaultToolkit().createImage( new FilteredImageSource(src.getSource(), - new GrayFilter(false, 100))); - } - - /** - Filter RGB to gray - */ - public int filterRGB(int x, - int y, - int rgb) - { - return (int) ( ( p * ( 0.299 * ( (0xff0000 & rgb) >> 16) + 0.587 * ( (0xff00 & rgb) >> 8 ) + 0.114 * (0xff & rgb ) ) )); - } + /** + * Create grayed image + * + * @param src image to gray + * + * @return a grayed image + */ + public static Image createDisabledImage(Image src) + { + return (Toolkit.getDefaultToolkit(). + createImage(new FilteredImageSource(src.getSource(), + new GrayFilter(false, 100)))); + } + + /** + * Filter RGB to gray + */ + public int filterRGB(int x, int y, int rgb) + { + return (int) (p * (0.299 * ((0xff0000 & rgb) >> 16) + + 0.587 * ((0xff00 & rgb) >> 8) + 0.114 * (0xff & rgb))); + } } diff --git a/libjava/javax/swing/ImageIcon.java b/libjava/javax/swing/ImageIcon.java index da271a51d3f..f94d58a5f80 100644 --- a/libjava/javax/swing/ImageIcon.java +++ b/libjava/javax/swing/ImageIcon.java @@ -35,65 +35,86 @@ this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ - package javax.swing; import java.awt.Component; import java.awt.Graphics; import java.awt.Image; import java.awt.Toolkit; +import java.io.Serializable; +import java.net.URL; + -public class ImageIcon implements Icon +public class ImageIcon + implements Icon, Serializable { - Image image; - String file, descr; - Component observer; + private static final long serialVersionUID = 532615968316031794L; + Image image; + String file; + String descr; + Component observer; public ImageIcon(String s) - { - // if description is not specified, then file name becomes - // desciption for this icon - - this(s, s); - } - - public ImageIcon(String file, - String descr) - { - this.file = file; - this.descr = descr; - - image = Toolkit.getDefaultToolkit().getImage(file); - if (image == null) { - return; - } - //loadImage(image); - } - - // not in SUN's spec !!! - public void setParent(Component p) - { - observer = p; - } - - public Image getImage() - { return image; } - - public String getDescription() - { return descr; } - public void setDescription(String description) - { this.descr = description; } - - public int getIconHeight() - { return image.getHeight(observer); } - public int getIconWidth() - { return image.getWidth(observer); } - - public void paintIcon(Component c, - Graphics g, - int x, - int y) - { - g.drawImage(image, x, y, observer); - } + { + // if description is not specified, then file name becomes + // desciption for this icon + this(s, s); + } + + public ImageIcon(Image image) + { + } + + public ImageIcon(URL url) + { + image = Toolkit.getDefaultToolkit().getImage(url); + } + + public ImageIcon(String file, String descr) + { + this.file = file; + this.descr = descr; + + image = Toolkit.getDefaultToolkit().getImage(file); + if (image == null) + return; + + //loadImage(image); + } + + // not in SUN's spec !!! + public void setParent(Component p) + { + observer = p; + } + + public Image getImage() + { + return image; + } + + public String getDescription() + { + return descr; + } + + public void setDescription(String description) + { + this.descr = description; + } + + public int getIconHeight() + { + return image.getHeight(observer); + } + + public int getIconWidth() + { + return image.getWidth(observer); + } + + public void paintIcon(Component c, Graphics g, int x, int y) + { + g.drawImage(image, x, y, observer); + } } diff --git a/libjava/javax/swing/JApplet.java b/libjava/javax/swing/JApplet.java index 43ce3e2f107..f1c3e354ff8 100644 --- a/libjava/javax/swing/JApplet.java +++ b/libjava/javax/swing/JApplet.java @@ -1,5 +1,5 @@ /* JApplet.java -- - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2004 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -51,6 +51,7 @@ import javax.accessibility.AccessibleContext; public class JApplet extends Applet implements RootPaneContainer { + private static final long serialVersionUID = 7269359214497372587L; public final static int HIDE_ON_CLOSE = 0; public final static int EXIT_ON_CLOSE = 1; @@ -136,10 +137,10 @@ public class JApplet extends Applet implements RootPaneContainer { return close_action; } - JMenuBar getJMenuBar() + public JMenuBar getJMenuBar() { return getRootPane().getJMenuBar(); } - void setJMenuBar(JMenuBar menubar) + public void setJMenuBar(JMenuBar menubar) { getRootPane().setJMenuBar(menubar); } diff --git a/libjava/javax/swing/JButton.java b/libjava/javax/swing/JButton.java index 4ec9fd19cee..0eb5e448201 100644 --- a/libjava/javax/swing/JButton.java +++ b/libjava/javax/swing/JButton.java @@ -87,6 +87,7 @@ public class JButton extends AbstractButton implements Accessible protected void configurePropertiesFromAction(Action a) { //Factory method which sets the AbstractButton's properties according to values from the Action instance. + super.configurePropertiesFromAction(a); } public AccessibleContext getAccessibleContext() diff --git a/libjava/javax/swing/JCheckBox.java b/libjava/javax/swing/JCheckBox.java index b1a484d9a9b..94aba4a4733 100644 --- a/libjava/javax/swing/JCheckBox.java +++ b/libjava/javax/swing/JCheckBox.java @@ -1,5 +1,5 @@ /* JCheckBox.java -- - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2004 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -47,6 +47,8 @@ import javax.accessibility.AccessibleContext; */ public class JCheckBox extends JToggleButton { + private static final long serialVersionUID = -5246739313864538930L; + public JCheckBox() { this(null, null); diff --git a/libjava/javax/swing/JCheckBoxMenuItem.java b/libjava/javax/swing/JCheckBoxMenuItem.java index b252175dfe6..fcc7721008f 100644 --- a/libjava/javax/swing/JCheckBoxMenuItem.java +++ b/libjava/javax/swing/JCheckBoxMenuItem.java @@ -50,6 +50,8 @@ import javax.accessibility.AccessibleRole; public class JCheckBoxMenuItem extends JMenuItem implements SwingConstants, Accessible { + private static final long serialVersionUID = -6676402307973384715L; + private static final String uiClassID = "CheckBoxMenuItemUI"; private boolean state; private Object[] selectedObjects; @@ -207,7 +209,7 @@ public class JCheckBoxMenuItem extends JMenuItem implements SwingConstants, public AccessibleContext getAccessibleContext() { if (accessibleContext == null) - accessibleContext = new AccessibleJCheckBoxMenuItem(this); + accessibleContext = new AccessibleJCheckBoxMenuItem(); return accessibleContext; } @@ -217,16 +219,13 @@ public class JCheckBoxMenuItem extends JMenuItem implements SwingConstants, */ protected class AccessibleJCheckBoxMenuItem extends AccessibleJMenuItem { + private static final long serialVersionUID = 1079958073579370777L; + /** * Creates a new AccessibleJCheckBoxMenuItem object. - * - * @param component DOCUMENT ME! */ - protected AccessibleJCheckBoxMenuItem(JCheckBoxMenuItem component) + protected AccessibleJCheckBoxMenuItem() { - super(component); - - // TODO } /** diff --git a/libjava/javax/swing/JColorChooser.java b/libjava/javax/swing/JColorChooser.java index 8881dc3555d..70dde6a19b3 100644 --- a/libjava/javax/swing/JColorChooser.java +++ b/libjava/javax/swing/JColorChooser.java @@ -1,5 +1,5 @@ /* JColorChooser.java -- - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2004 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -57,6 +57,8 @@ import javax.swing.plaf.ColorChooserUI; */ public class JColorChooser extends JComponent implements Accessible { + private static final long serialVersionUID = 9168066781620640889L; + //------------------------------------------------------------- // Classes ---------------------------------------------------- //------------------------------------------------------------- @@ -66,6 +68,8 @@ public class JColorChooser extends JComponent implements Accessible { */ protected class AccessibleJColorChooser extends JComponent.AccessibleJComponent { + private static final long serialVersionUID = -2038297864782299082L; + //------------------------------------------------------------- // Variables -------------------------------------------------- //------------------------------------------------------------- @@ -79,15 +83,9 @@ public class JColorChooser extends JComponent implements Accessible { * Constructor AccessibleJColorChooser * @param component TODO */ - protected AccessibleJColorChooser(JColorChooser component) { - super(component); - // TODO - } // AccessibleJColorChooser() - - - //------------------------------------------------------------- - // Methods ---------------------------------------------------- - //------------------------------------------------------------- + protected AccessibleJColorChooser() + { + } /** * getAccessibleRole @@ -355,16 +353,15 @@ public class JColorChooser extends JComponent implements Accessible { return null; // TODO } // paramString() - /** - * getAccessibleContext - * @returns AccessibleContext - */ - public AccessibleContext getAccessibleContext() { - if (accessibleContext == null) { - accessibleContext = new AccessibleJColorChooser(this); - } // if - return accessibleContext; - } // getAccessibleContext() - - -} // JColorChooser + /** + * getAccessibleContext + * @return AccessibleContext + */ + public AccessibleContext getAccessibleContext() + { + if (accessibleContext == null) + accessibleContext = new AccessibleJColorChooser(); + + return accessibleContext; + } +} diff --git a/libjava/javax/swing/JComboBox.java b/libjava/javax/swing/JComboBox.java index acdbdc011e3..b66dcb3a9a8 100644 --- a/libjava/javax/swing/JComboBox.java +++ b/libjava/javax/swing/JComboBox.java @@ -69,39 +69,21 @@ public class JComboBox extends JComponent { private static final long serialVersionUID = 5654585963292734470L; + /** + * AccessibleJComboBox + */ + protected class AccessibleJComboBox extends AccessibleJComponent + implements AccessibleAction, AccessibleSelection + { + private static final long serialVersionUID = 8217828307256675666L; - //------------------------------------------------------------- - // Classes ---------------------------------------------------- - //------------------------------------------------------------- - - /** - * AccessibleJComboBox - */ - protected class AccessibleJComboBox extends AccessibleJComponent - implements AccessibleAction, AccessibleSelection { - - //------------------------------------------------------------- - // Variables -------------------------------------------------- - //------------------------------------------------------------- - - - //------------------------------------------------------------- - // Initialization --------------------------------------------- - //------------------------------------------------------------- - - /** - * Constructor AccessibleJComboBox - * @param component TODO - */ - protected AccessibleJComboBox(JComboBox component) { - super(component); - // TODO - } // AccessibleJComboBox() - - - //------------------------------------------------------------- - // Methods ---------------------------------------------------- - //------------------------------------------------------------- + /** + * Constructor AccessibleJComboBox + * @param component TODO + */ + protected AccessibleJComboBox() + { + } /** * getAccessibleChildrenCount @@ -804,16 +786,18 @@ public class JComboBox extends JComponent return null; // TODO } // paramString() - /** - * getAccessibleContext - * @returns AccessibleContext - */ - public AccessibleContext getAccessibleContext() { - if (accessibleContext == null) { - accessibleContext = new AccessibleJComboBox(this); - } // if - return accessibleContext; - } // getAccessibleContext() + /** + * getAccessibleContext + * @returns AccessibleContext + */ + public AccessibleContext getAccessibleContext() + { + if (accessibleContext == null) + accessibleContext = new AccessibleJComboBox(); + + return accessibleContext; + } + /** * addActionListener * @param listener TODO diff --git a/libjava/javax/swing/JComponent.java b/libjava/javax/swing/JComponent.java index e03c1c9dde4..de8bd76f27c 100644 --- a/libjava/javax/swing/JComponent.java +++ b/libjava/javax/swing/JComponent.java @@ -57,6 +57,7 @@ import java.awt.event.MouseEvent; import java.awt.geom.Rectangle2D; import java.awt.image.ImageObserver; import java.awt.peer.LightweightPeer; +import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.beans.PropertyVetoException; import java.beans.VetoableChangeListener; @@ -87,7 +88,7 @@ import javax.swing.plaf.ComponentUI; */ public abstract class JComponent extends Container implements Serializable { - static final long serialVersionUID = -5242478962609715464L; + private static final long serialVersionUID = -7908749299918704233L; /** * Accessibility support is currently missing. @@ -101,7 +102,7 @@ public abstract class JComponent extends Container implements Serializable protected class AccessibleFocusHandler implements FocusListener { - protected AccessibleFocusHandler(AccessibleJComponent component){} + protected AccessibleFocusHandler(){} public void focusGained(FocusEvent event){} public void focusLost(FocusEvent valevent){} } @@ -109,15 +110,17 @@ public abstract class JComponent extends Container implements Serializable protected class AccessibleContainerHandler implements ContainerListener { - protected AccessibleContainerHandler(AccessibleJComponent component) {} + protected AccessibleContainerHandler() {} public void componentAdded(ContainerEvent event) {} public void componentRemoved(ContainerEvent valevent) {} } + private static final long serialVersionUID = -7047089700479897799L; + protected ContainerListener accessibleContainerHandler; protected FocusListener accessibleFocusHandler; - protected AccessibleJComponent(JComponent component) {} + protected AccessibleJComponent() {} public void addPropertyChangeListener(PropertyChangeListener listener) {} public void removePropertyChangeListener(PropertyChangeListener listener) {} public int getAccessibleChildrenCount() { return 0; } @@ -273,7 +276,7 @@ public abstract class JComponent extends Container implements Serializable * @see #getUI * @see #updateUI */ - ComponentUI ui; + protected ComponentUI ui; /** * A hint to the focus system that this component should or should not @@ -343,6 +346,7 @@ public abstract class JComponent extends Container implements Serializable */ private static Locale defaultLocale; + public static final String TOOL_TIP_TEXT_KEY = "ToolTipText"; /** * Constant used to indicate that no condition has been assigned to a @@ -735,7 +739,12 @@ public abstract class JComponent extends Container implements Serializable Object newValue) throws PropertyVetoException { - // Support for reporting constrained property changes. + VetoableChangeListener[] listeners = getVetoableChangeListeners(); + + PropertyChangeEvent evt = new PropertyChangeEvent(this, propertyName, oldValue, newValue); + + for (int i = 0; i < listeners.length; i++) + listeners[i].vetoableChange(evt); } /** @@ -1105,7 +1114,11 @@ public abstract class JComponent extends Container implements Serializable public JToolTip createToolTip() { if (toolTip == null) - toolTip = new JToolTip(toolTipText); + { + toolTip = new JToolTip(); + toolTip.setTipText(toolTipText); + } + return toolTip; } @@ -1378,7 +1391,7 @@ public abstract class JComponent extends Container implements Serializable g2 = doubleBuffer.getGraphics(); g2.setClip(g.getClipBounds()); } - + g2 = getComponentGraphics(g2); paintComponent(g2); paintBorder(g2); @@ -1470,7 +1483,7 @@ public abstract class JComponent extends Container implements Serializable */ public void paintImmediately(Rectangle r) { - Component root = this.getRootPane(); + Component root = SwingUtilities.getRoot(this); if (root == null || ! root.isShowing()) return; Graphics g = root.getGraphics(); @@ -1624,7 +1637,7 @@ public abstract class JComponent extends Container implements Serializable public void scrollRectToVisible(Rectangle r) { Component p = getParent(); - if (p != null && p instanceof JComponent) + if (p instanceof JComponent) ((JComponent) p).scrollRectToVisible(r); } diff --git a/libjava/javax/swing/JDesktopPane.java b/libjava/javax/swing/JDesktopPane.java index d8301500fca..ce8085a99f0 100644 --- a/libjava/javax/swing/JDesktopPane.java +++ b/libjava/javax/swing/JDesktopPane.java @@ -37,6 +37,8 @@ exception statement from your version. */ package javax.swing; +import java.awt.Component; +import java.beans.PropertyVetoException; import java.io.IOException; import java.io.ObjectOutputStream; import javax.accessibility.Accessible; @@ -44,244 +46,281 @@ import javax.accessibility.AccessibleContext; import javax.accessibility.AccessibleRole; import javax.swing.plaf.DesktopPaneUI; + /** - * JDesktopPane - * @author Andrew Selkirk - * @version 1.0 + * JDesktopPane is a container (usually for JInternalFrames) that simulates a + * desktop. Typically, the user will create JInternalFrames and place thme in + * a JDesktopPane. The user can then interact with JInternalFrames like they + * usually would with JFrames. The actions (minimize, maximize, close, etc) + * are done by using a DesktopManager that is associated with the + * JDesktopPane. */ public class JDesktopPane extends JLayeredPane implements Accessible { - - //------------------------------------------------------------- - // Classes ---------------------------------------------------- - //------------------------------------------------------------- - - /** - * AccessibleJDesktopPane - */ - protected class AccessibleJDesktopPane extends AccessibleJComponent { - - //------------------------------------------------------------- - // Initialization --------------------------------------------- - //------------------------------------------------------------- - - /** - * Constructor AccessibleJDesktopPane - * @param component TODO - */ - protected AccessibleJDesktopPane(JDesktopPane component) { - super(component); - // TODO - } // AccessibleJDesktopPane() - - - //------------------------------------------------------------- - // Methods ---------------------------------------------------- - //------------------------------------------------------------- - - /** - * getAccessibleRole - * @returns AccessibleRole - */ - public AccessibleRole getAccessibleRole() { - return AccessibleRole.DESKTOP_PANE; - } // getAccessibleRole() - - - } // AccessibleJDesktopPane - - - //------------------------------------------------------------- - // Constants -------------------------------------------------- - //------------------------------------------------------------- - - /** - * LIVE_DRAG_MODE - */ - public static int LIVE_DRAG_MODE = 0; - - /** - * OUTLINE_DRAG_MODE - */ - public static int OUTLINE_DRAG_MODE = 1; - - /** - * uiClassID - */ - private static final String uiClassID = "DesktopPaneUI"; - - - //------------------------------------------------------------- - // Variables -------------------------------------------------- - //------------------------------------------------------------- - - /** - * selectedFrame - */ - private transient JInternalFrame selectedFrame; - - /** - * desktopManager - */ - private transient DesktopManager desktopManager; - - - /** - * dragMode - */ - private int dragMode; - - - //------------------------------------------------------------- - // Initialization --------------------------------------------- - //------------------------------------------------------------- - - /** - * Constructor JDesktopPane - */ - public JDesktopPane() { - // TODO - } // JDesktopPane() - - - //------------------------------------------------------------- - // Methods ---------------------------------------------------- - //------------------------------------------------------------- - - /** - * writeObject - * @param stream TODO - * @exception IOException TODO - */ - private void writeObject(ObjectOutputStream stream) throws IOException { - // TODO - } // writeObject() - - /** - * getUI - * @returns DesktopPaneUI - */ - public DesktopPaneUI getUI() { - return (DesktopPaneUI) ui; - } // getUI() - - /** - * setUI - * @param ui TODO - */ - public void setUI(DesktopPaneUI ui) { - super.setUI(ui); - } // setUI() - - /** - * setDragMode - * @param mode TODO - */ - public void setDragMode(int mode) { - this.dragMode = mode; - // TODO - } // setDragMode() - - /** - * getDragMode - * @returns int - */ - public int getDragMode() { - return dragMode; - } // getDragMode() - - /** - * getDesktopManager - * @returns DesktopManager - */ - public DesktopManager getDesktopManager() { - return desktopManager; - } // getDesktopManager() - - /** - * setDesktopManager - * @param manager TODO - */ - public void setDesktopManager(DesktopManager manager) { - this.desktopManager = manager; - // TODO - } // setDesktopManager() - - /** - * updateUI - */ - public void updateUI() { - setUI((DesktopPaneUI) UIManager.get(this)); - invalidate(); - } // updateUI() - - /** - * getUIClassID - * @returns String - */ - public String getUIClassID() { - return uiClassID; - } // getUIClassID() - - /** - * getAllFrames - * @returns JInternalFrame[] - */ - public JInternalFrame[] getAllFrames() { - return null; // TODO - } // getAllFrames() - - /** - * getSelectedFrame - * @returns JInternalFrame - */ - public JInternalFrame getSelectedFrame() { - return null; // TODO - } // getSelectedFrame() - - /** - * setSelectedFrame - * @param frame TODO - */ - public void setSelectedFrame(JInternalFrame frame) { - // TODO - } // setSelectedFrame() - - /** - * getAllFramesInLayer - * @param layer TODO - * @returns JInternalFrame[] - */ - public JInternalFrame[] getAllFramesInLayer(int layer) { - return null; // TODO - } // getAllFramesInLayer() - - /** - * isOpaque - * @returns boolean - */ - public boolean isOpaque() { - return true; - } // isOpaque() - - /** - * paramString - * @returns String - */ - protected String paramString() { - return null; // TODO - } // paramString() - - /** - * getAccessibleContext - * @returns AccessibleContext - */ - public AccessibleContext getAccessibleContext() { - if (accessibleContext == null) { - accessibleContext = new AccessibleJDesktopPane(this); - } // if - return accessibleContext; - } // getAccessibleContext() - - -} // JDesktopPane + /** DOCUMENT ME! */ + private static final long serialVersionUID = 766333777224038726L; + + /** + * This specifies that when dragged, a JInternalFrame should be completely + * visible. + */ + public static int LIVE_DRAG_MODE = 0; + + /** + * This specifies that when dragged, a JInternalFrame should only be visible + * as an outline. + */ + public static int OUTLINE_DRAG_MODE = 1; + + /** The selected frame in the JDesktopPane. */ + private transient JInternalFrame selectedFrame; + + /** The JDesktopManager to use for acting on JInternalFrames. */ + transient DesktopManager desktopManager; + + /** The drag mode used by the JDesktopPane. */ + private transient int dragMode = LIVE_DRAG_MODE; + + /** + * AccessibleJDesktopPane + */ + protected class AccessibleJDesktopPane extends AccessibleJComponent + { + /** DOCUMENT ME! */ + private static final long serialVersionUID = 6079388927946077570L; + + /** + * Constructor AccessibleJDesktopPane + */ + protected AccessibleJDesktopPane() + { + } + + /** + * getAccessibleRole + * + * @return AccessibleRole + */ + public AccessibleRole getAccessibleRole() + { + return AccessibleRole.DESKTOP_PANE; + } + } + + /** + * Creates a new JDesktopPane object. + */ + public JDesktopPane() + { + setLayout(null); + updateUI(); + } + + /** + * This method returns the UI used with the JDesktopPane. + * + * @return The UI used with the JDesktopPane. + */ + public DesktopPaneUI getUI() + { + return (DesktopPaneUI) ui; + } + + /** + * This method sets the UI used with the JDesktopPane. + * + * @param ui The UI to use with the JDesktopPane. + */ + public void setUI(DesktopPaneUI ui) + { + super.setUI(ui); + } + + /** + * This method sets the drag mode to use with the JDesktopPane. + * + * @param mode The drag mode to use. + * + * @throws IllegalArgumentException If the drag mode given is not + * LIVE_DRAG_MODE or OUTLINE_DRAG_MODE. + */ + public void setDragMode(int mode) + { + if ((mode != LIVE_DRAG_MODE) && (mode != OUTLINE_DRAG_MODE)) + throw new IllegalArgumentException("Drag mode not valid."); + + // FIXME: Unsupported mode. + if (mode == OUTLINE_DRAG_MODE) + throw new IllegalArgumentException("Outline drag modes are unsupported."); + + dragMode = mode; + } + + /** + * This method returns the drag mode used with the JDesktopPane. + * + * @return The drag mode used with the JDesktopPane. + */ + public int getDragMode() + { + return dragMode; + } + + /** + * This method returns the DesktopManager used with the JDesktopPane. + * + * @return The DesktopManager to use with the JDesktopPane. + */ + public DesktopManager getDesktopManager() + { + return desktopManager; + } + + /** + * This method sets the DesktopManager to use with the JDesktopPane. + * + * @param manager The DesktopManager to use with the JDesktopPane. + */ + public void setDesktopManager(DesktopManager manager) + { + desktopManager = manager; + } + + /** + * This method restores the UI used with the JDesktopPane to the default. + */ + public void updateUI() + { + setUI((DesktopPaneUI) UIManager.getUI(this)); + invalidate(); + } + + /** + * This method returns a String identifier that allows the UIManager to know + * which class will act as JDesktopPane's UI. + * + * @return A String identifier for the UI class to use. + */ + public String getUIClassID() + { + return "DesktopPaneUI"; + } + + /** + * This method returns all JInternalFrames that are in the JDesktopPane. + * + * @return All JInternalFrames that are in the JDesktopPane. + */ + public JInternalFrame[] getAllFrames() + { + return getFramesFromComponents(getComponents()); + } + + /** + * This method returns the currently selected frame in the JDesktopPane. + * + * @return The currently selected frame in the JDesktopPane. + */ + public JInternalFrame getSelectedFrame() + { + return selectedFrame; + } + + /** + * This method sets the selected frame in the JDesktopPane. + * + * @param frame The selected frame in the JDesktopPane. + */ + public void setSelectedFrame(JInternalFrame frame) + { + if (selectedFrame != null) + { + try + { + selectedFrame.setSelected(false); + } + catch (PropertyVetoException e) + { + } + } + selectedFrame = null; + + try + { + if (frame != null) + frame.setSelected(true); + + selectedFrame = frame; + } + catch (PropertyVetoException e) + { + } + } + + /** + * This method returns all the JInternalFrames in the given layer. + * + * @param layer The layer to grab frames in. + * + * @return All JInternalFrames in the given layer. + */ + public JInternalFrame[] getAllFramesInLayer(int layer) + { + return getFramesFromComponents(getComponentsInLayer(layer)); + } + + /** + * This method always returns true to indicate that it is not transparent. + * + * @return true. + */ + public boolean isOpaque() + { + return true; + } + + /** + * This method returns a String that describes the JDesktopPane. + * + * @return A String that describes the JDesktopPane. + */ + protected String paramString() + { + return "JDesktopPane"; + } + + /** + * This method returns all the JInternalFrames in the given Component array. + * + * @param components An array to search for JInternalFrames in. + * + * @return An array of JInternalFrames found in the Component array. + */ + private static JInternalFrame[] getFramesFromComponents(Component[] components) + { + int count = 0; + + for (int i = 0; i < components.length; i++) + if (components[i] instanceof JInternalFrame) + count++; + + JInternalFrame[] value = new JInternalFrame[count]; + for (int i = 0, j = 0; i < components.length && j != count; i++) + if (components[i] instanceof JInternalFrame) + value[j++] = (JInternalFrame) components[i]; + return value; + } + + /** + * getAccessibleContext + * + * @return AccessibleContext + */ + public AccessibleContext getAccessibleContext() + { + if (accessibleContext == null) + accessibleContext = new AccessibleJDesktopPane(); + + return accessibleContext; + } +} diff --git a/libjava/javax/swing/JDialog.java b/libjava/javax/swing/JDialog.java index b9f547e5542..598f4931cd3 100644 --- a/libjava/javax/swing/JDialog.java +++ b/libjava/javax/swing/JDialog.java @@ -62,6 +62,7 @@ import javax.accessibility.AccessibleContext; public class JDialog extends Dialog implements Accessible, WindowConstants, RootPaneContainer { + private static final long serialVersionUID = -864070866424508218L; /** DOCUMENT ME! */ protected AccessibleContext accessibleContext; diff --git a/libjava/javax/swing/JEditorPane.java b/libjava/javax/swing/JEditorPane.java index 4722e1e1ebc..b944a3d129d 100644 --- a/libjava/javax/swing/JEditorPane.java +++ b/libjava/javax/swing/JEditorPane.java @@ -1,4 +1,4 @@ -/* JEditorPane.java -- +/* JEditorPane.java -- Copyright (C) 2002, 2004 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -35,207 +35,280 @@ this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ - package javax.swing; import java.awt.Dimension; import java.awt.event.KeyEvent; -import java.io.InputStream; import java.io.IOException; +import java.io.InputStream; import java.net.URL; import javax.accessibility.AccessibleContext; +import javax.swing.event.HyperlinkEvent; +import javax.swing.event.HyperlinkListener; import javax.swing.text.EditorKit; import javax.swing.text.JTextComponent; import javax.swing.text.PlainEditorKit; -import javax.swing.event.HyperlinkEvent; -import javax.swing.event.HyperlinkListener; + public class JEditorPane extends JTextComponent { private static final long serialVersionUID = 3140472492599046285L; + + URL page_url; + EditorKit kit; + String ctype = "text/plain"; + boolean focus_root; + boolean manages_focus; + + public JEditorPane() + { + } + + public JEditorPane(String url) throws IOException + { + setPage(url); + } + + public JEditorPane(String type, String text) + { + ctype = text; + setText(text); + } - URL page_url; - EditorKit kit; - String ctype = "text/plain"; - boolean focus_root; - boolean manages_focus; - - - public JEditorPane() - { - } - - public JEditorPane(String url) - throws IOException - { - this(); - setPage(url); - } - - public JEditorPane(String type, String text) - { - ctype = text; - setText(text); - } - - public JEditorPane(URL url) - throws IOException - { - setPage(url); - } - - protected EditorKit createDefaultEditorKit() - { return new PlainEditorKit(); } - - static EditorKit createEditorKitForContentType(String type) - { return new PlainEditorKit(); } - - void fireHyperlinkUpdate(HyperlinkEvent e) + public JEditorPane(URL url) throws IOException { + setPage(url); + } + + protected EditorKit createDefaultEditorKit() + { + return new PlainEditorKit(); + } + + protected static EditorKit createEditorKitForContentType(String type) + { + return new PlainEditorKit(); + } + + /** + * Sends a given <code>HyperlinkEvent</code> to all registered listeners. + * + * @param event the event to send + */ + public void fireHyperlinkUpdate(HyperlinkEvent event) + { + HyperlinkListener[] listeners = getHyperlinkListeners(); + + for (int index = 0; index < listeners.length; ++index) + listeners[index].hyperlinkUpdate(event); } public AccessibleContext getAccessibleContext() - { return null; } + { + return null; + } - String getContentType() - { return ctype; } + public String getContentType() + { + return ctype; + } - EditorKit getEditorKit() - { return kit; } - - static String getEditorKitClassNameForContentType(String type) - { return "text/plain"; } - - EditorKit getEditorKitForContentType(String type) - { return kit; } - - public Dimension getPreferredSize() - { - //Returns the preferred size for the JEditorPane. - return super.getPreferredSize(); - } + public EditorKit getEditorKit() + { + return kit; + } + + public static String getEditorKitClassNameForContentType(String type) + { + return "text/plain"; + } + + public EditorKit getEditorKitForContentType(String type) + { + return kit; + } + + /** + * Returns the preferred size for the JEditorPane. + */ + public Dimension getPreferredSize() + { + return super.getPreferredSize(); + } public boolean getScrollableTracksViewportHeight() - { return false; } + { + return false; + } + public boolean getScrollableTracksViewportWidth() - { return false; } - - URL getPage() - { return page_url; } - - protected InputStream getStream(URL page) - { - try { - return page.openStream(); - } catch (Exception e) { - System.out.println("Hhmmm, failed to open stream: " + e); - } - return null; - } - - public String getText() - { return super.getText(); } - - public String getUIClassID() - { return "EditorPaneUI"; } - - public boolean isFocusCycleRoot() - { return focus_root; } - - public boolean isManagingFocus() - { return manages_focus; } - - protected String paramString() - { return "JEditorPane"; } - - protected void processComponentKeyEvent(KeyEvent e) - { - //Overridden to handle processing of tab/shift tab. - } - + { + return false; + } + + public URL getPage() + { + return page_url; + } + + protected InputStream getStream(URL page) + { + try + { + return page.openStream(); + } + catch (Exception e) + { + System.out.println("Hhmmm, failed to open stream: " + e); + } + return null; + } + + public String getText() + { + return super.getText(); + } + + public String getUIClassID() + { + return "EditorPaneUI"; + } + + public boolean isFocusCycleRoot() + { + return focus_root; + } + + public boolean isManagingFocus() + { + return manages_focus; + } + + protected String paramString() + { + return "JEditorPane"; + } + + /** + * Overridden to handle processing of tab/shift tab. + */ + protected void processComponentKeyEvent(KeyEvent e) + { + } + + /** + * Make sure that TAB and Shift-TAB events get consumed, so that awt doesn't attempt focus traversal. + */ protected void processKeyEvent(KeyEvent e) - { - //Make sure that TAB and Shift-TAB events get consumed, so that awt doesn't attempt focus traversal. - } - - void read(InputStream in, Object desc) - { - //This method initializes from a stream. - } - - static void registerEditorKitForContentType(String type, String classname) - { - //Establishes the default bindings of type to classname. - } - - static void registerEditorKitForContentType(String type, String classname, ClassLoader loader) - { - //Establishes the default bindings of type to classname. - } - - void replaceSelection(String content) - { - //Replaces the currently selected content with new content represented by the given string. - } - - protected void scrollToReference(String reference) - { - //Scrolls the view to the given reference location (that is, the value returned by the UL.getRef method for the URL being displayed). - } - - void setContentType(String type) - { - ctype = type; - invalidate(); - repaint(); - } - - void setEditorKit(EditorKit kit) - { - this.kit = kit; - invalidate(); - repaint(); - } - - void setEditorKitForContentType(String type, EditorKit k) - { - ctype = type; - setEditorKit(k); - } - - void setPage(String url) - throws IOException - { - // Sets the current URL being displayed. - } - - void setPage(URL page) - throws IOException - { - // Sets the current URL being displayed. - } - - public void setText(String t) - { - super.setText(t); - } + { + } + + /** + * This method initializes from a stream. + */ + public void read(InputStream in, Object desc) + { + } + + /** + * Establishes the default bindings of type to classname. + */ + public static void registerEditorKitForContentType(String type, + String classname) + { + } + + /** + * Establishes the default bindings of type to classname. + */ + public static void registerEditorKitForContentType(String type, + String classname, + ClassLoader loader) + { + } + + /** + * Replaces the currently selected content with new content represented by the given string. + */ + public void replaceSelection(String content) + { + } + + /** + * Scrolls the view to the given reference location (that is, the value returned by the UL.getRef method for the URL being displayed). + */ + protected void scrollToReference(String reference) + { + } + + public void setContentType(String type) + { + ctype = type; + invalidate(); + repaint(); + } + + public void setEditorKit(EditorKit kit) + { + this.kit = kit; + invalidate(); + repaint(); + } + + public void setEditorKitForContentType(String type, EditorKit k) + { + ctype = type; + setEditorKit(k); + } + + /** + * Sets the current URL being displayed. + */ + public void setPage(String url) throws IOException + { + } + + /** + * Sets the current URL being displayed. + */ + public void setPage(URL page) throws IOException + { + } + public void setText(String t) + { + super.setText(t); + } + + /** + * Add a <code>HyperlinkListener</code> object to this editor pane. + * + * @param listener the listener to add + */ public void addHyperlinkListener(HyperlinkListener listener) { - listenerList.add (HyperlinkListener.class, listener); + listenerList.add(HyperlinkListener.class, listener); } - - public void removeHyperlinkListener (HyperlinkListener listener) + + /** + * Removes a <code>HyperlinkListener</code> object to this editor pane. + * + * @param listener the listener to remove + */ + public void removeHyperlinkListener(HyperlinkListener listener) { - listenerList.remove (HyperlinkListener.class, listener); + listenerList.remove(HyperlinkListener.class, listener); } /** + * Returns all added <code>HyperlinkListener</code> objects. + * + * @return array of listeners + * * @since 1.4 */ public HyperlinkListener[] getHyperlinkListeners() { - return (HyperlinkListener[]) getListeners (HyperlinkListener.class); + return (HyperlinkListener[]) getListeners(HyperlinkListener.class); } - -} // class JEditorPane +} diff --git a/libjava/javax/swing/JFileChooser.java b/libjava/javax/swing/JFileChooser.java index 47b086180d1..2a23eff2556 100644 --- a/libjava/javax/swing/JFileChooser.java +++ b/libjava/javax/swing/JFileChooser.java @@ -61,55 +61,30 @@ public class JFileChooser extends JComponent implements Accessible { private static final long serialVersionUID = 3162921138695327837L; - //------------------------------------------------------------- - // Classes ---------------------------------------------------- - //------------------------------------------------------------- - - /** - * AccessibleJFileChooser - */ - protected class AccessibleJFileChooser extends AccessibleJComponent { - - private static final long serialVersionUID = 3318922050345221200L; - - //------------------------------------------------------------- - // Variables -------------------------------------------------- - //------------------------------------------------------------- - - - //------------------------------------------------------------- - // Initialization --------------------------------------------- - //------------------------------------------------------------- - - /** - * Constructor AccessibleJFileChooser - * @param component TODO - */ - protected AccessibleJFileChooser(JFileChooser component) { - super(component); - // TODO - } // AccessibleJFileChooser() - - - //------------------------------------------------------------- - // Methods ---------------------------------------------------- - //------------------------------------------------------------- - - /** - * getAccessibleRole - * @returns AccessibleRole - */ - public AccessibleRole getAccessibleRole() { - return AccessibleRole.FILE_CHOOSER; - } // getAccessibleRole() - - - } // AccessibleJFileChooser - - - //------------------------------------------------------------- - // Variables -------------------------------------------------- - //------------------------------------------------------------- + /** + * AccessibleJFileChooser + */ + protected class AccessibleJFileChooser extends AccessibleJComponent + { + private static final long serialVersionUID = 8205148454060169244L; + + /** + * Constructor AccessibleJFileChooser + * @param component TODO + */ + protected AccessibleJFileChooser() + { + } + + /** + * getAccessibleRole + * @return AccessibleRole + */ + public AccessibleRole getAccessibleRole() + { + return AccessibleRole.FILE_CHOOSER; + } + } /** * uiClassID @@ -969,16 +944,15 @@ public class JFileChooser extends JComponent implements Accessible { return null; // TODO } // paramString() - /** - * getAccessibleContext - * @returns AccessibleContext - */ - public AccessibleContext getAccessibleContext() { - if (accessibleContext == null) { - accessibleContext = new AccessibleJFileChooser(this); - } // if - return accessibleContext; - } // getAccessibleContext() - - -} // JFileChooser + /** + * getAccessibleContext + * @returns AccessibleContext + */ + public AccessibleContext getAccessibleContext() + { + if (accessibleContext == null) + accessibleContext = new AccessibleJFileChooser(); + + return accessibleContext; + } +} diff --git a/libjava/javax/swing/JFormattedTextField.java b/libjava/javax/swing/JFormattedTextField.java index 801ffac47be..8e10a7fc9a6 100644 --- a/libjava/javax/swing/JFormattedTextField.java +++ b/libjava/javax/swing/JFormattedTextField.java @@ -1,5 +1,5 @@ /* JFormattedTextField.java -- - Copyright (C) 2003 Free Software Foundation, Inc. + Copyright (C) 2003, 2004 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -52,7 +52,7 @@ import javax.swing.text.NavigationFilter; */ public class JFormattedTextField extends JTextField { - private static final long serialVersionUID = 2889768923115424035L; + private static final long serialVersionUID = 5464657870110180632L; public abstract static class AbstractFormatter implements Serializable { diff --git a/libjava/javax/swing/JFrame.java b/libjava/javax/swing/JFrame.java index 5c362cee7ab..3c254ab0448 100644 --- a/libjava/javax/swing/JFrame.java +++ b/libjava/javax/swing/JFrame.java @@ -59,10 +59,23 @@ import javax.accessibility.AccessibleContext; */ public class JFrame extends Frame implements WindowConstants, RootPaneContainer { - protected AccessibleContext accessibleContext; + private static final long serialVersionUID = -3362141868504252139L; + + protected AccessibleContext accessibleContext; + + private int close_action = HIDE_ON_CLOSE; + + private static boolean defaultLookAndFeelDecorated = false; - private int close_action = HIDE_ON_CLOSE; - + public static void setDefaultLookAndFeelDecorated(boolean d) + { + defaultLookAndFeelDecorated = d; + } + + public static boolean isDefaultLookAndFeelDecorated() + { + return defaultLookAndFeelDecorated; + } /*************************************************** * @@ -111,10 +124,10 @@ public class JFrame extends Frame implements WindowConstants, RootPaneContainer return d; } - JMenuBar getJMenuBar() + public JMenuBar getJMenuBar() { return getRootPane().getJMenuBar(); } - void setJMenuBar(JMenuBar menubar) + public void setJMenuBar(JMenuBar menubar) { getRootPane().setJMenuBar(menubar); } diff --git a/libjava/javax/swing/JInternalFrame.java b/libjava/javax/swing/JInternalFrame.java index f005c91e309..12c9d139db2 100644 --- a/libjava/javax/swing/JInternalFrame.java +++ b/libjava/javax/swing/JInternalFrame.java @@ -35,24 +35,1673 @@ this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ - package javax.swing; +import java.awt.Color; +import java.awt.Component; +import java.awt.Container; +import java.awt.Graphics; +import java.awt.KeyboardFocusManager; +import java.awt.LayoutManager; +import java.awt.Rectangle; +import java.beans.PropertyVetoException; +import javax.accessibility.Accessible; +import javax.accessibility.AccessibleContext; +import javax.accessibility.AccessibleRole; +import javax.accessibility.AccessibleValue; +import javax.swing.event.InternalFrameEvent; +import javax.swing.event.InternalFrameListener; +import javax.swing.plaf.DesktopIconUI; +import javax.swing.plaf.InternalFrameUI; + -public class JInternalFrame extends JComponent -/*implements Accessible, WindowConstants, RootPaneContainer*/ +/** + * This class implements a Swing widget that looks and acts like a native + * frame. The frame can be dragged, resized, closed, etc. Typically, + * JInternalFrames are placed in JDesktopPanes. The actions that the + * JInternalFrame performs (maximizing, minimizing, etc.) are performed by a + * DesktopManager. As with regular frames, components are added by calling + * frame.getContentPane().add. + */ +public class JInternalFrame extends JComponent implements Accessible, + WindowConstants, + RootPaneContainer { + /** DOCUMENT ME! */ private static final long serialVersionUID = -5425177187760785402L; - public static final String CONTENT_PANE_PROPERTY = "contentPane"; - public static final String MENU_BAR_PROPERTY = "JMenuBar"; - public static final String TITLE_PROPERTY = "title"; - public static final String LAYERED_PANE_PROPERTY = "layeredPane"; - public static final String ROOT_PANE_PROPERTY = "rootPane"; - public static final String GLASS_PANE_PROPERTY = "glassPane"; - public static final String FRAME_ICON_PROPERTY = "frameIcon"; - public static final String IS_SELECTED_PROPERTY = "selected"; - public static final String IS_CLOSED_PROPERTY = "closed"; - public static final String IS_MAXIMUM_PROPERTY = "maximum"; - public static final String IS_ICON_PROPERTY = "icon"; + /** + * DOCUMENT ME! + */ + protected class AccessibleJInternalFrame extends AccessibleJComponent + implements AccessibleValue + { + /** + * Creates a new AccessibleJInternalFrame object. + */ + protected AccessibleJInternalFrame() + { + super(); + } + + /** + * DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public String getAccessibleName() + { + return null; + } + + /** + * DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public AccessibleRole getAccessibleRole() + { + return null; + } + + /** + * DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public AccessibleValue getAccessibleValue() + { + return null; + } + + /** + * DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public Number getCurrentAccessibleValue() + { + return null; + } + + /** + * DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public Number getMaximumAccessibleValue() + { + return null; + } + + /** + * DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public Number getMinimumAccessibleValue() + { + return null; + } + + /** + * DOCUMENT ME! + * + * @param n DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public boolean setCurrentAccessibleValue(Number n) + { + return false; + } + } + + /** + * This class represents the JInternalFrame while it is iconified. + */ + public static class JDesktopIcon extends JComponent implements Accessible + { + /** + * DOCUMENT ME! + */ + protected class AccessibleJDesktopIcon extends AccessibleJComponent + implements AccessibleValue + { + /** + * Creates a new AccessibleJDesktopIcon object. + */ + protected AccessibleJDesktopIcon() + { + super(); + } + + /** + * DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public AccessibleRole getAccessibleRole() + { + return null; + } + + /** + * DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public AccessibleValue getAccessibleValue() + { + return null; + } + + /** + * DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public Number getCurrentAccessibleValue() + { + return null; + } + + /** + * DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public Number getMaximumAccessibleValue() + { + return null; + } + + /** + * DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public Number getMinimumAccessibleValue() + { + return null; + } + + /** + * DOCUMENT ME! + * + * @param n DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public boolean setCurrentAccessibleValue(Number n) + { + return false; + } + } + + /** The JInternalFrame this DesktopIcon represents. */ + JInternalFrame frame; + + /** + * Creates a new JDesktopIcon object for representing the given frame. + * + * @param f The JInternalFrame to represent. + */ + public JDesktopIcon(JInternalFrame f) + { + frame = f; + updateUI(); + } + + /** + * DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public AccessibleContext getAccessibleContext() + { + if (accessibleContext == null) + accessibleContext = new AccessibleJDesktopIcon(); + return accessibleContext; + } + + /** + * This method returns the JDesktopPane this JDesktopIcon is in. + * + * @return The JDesktopPane this JDesktopIcon is in. + */ + public JDesktopPane getDesktopPane() + { + JDesktopPane p = (JDesktopPane) SwingUtilities.getAncestorOfClass(JDesktopPane.class, + this); + return p; + } + + /** + * This method returns the JInternalFrame this JDesktopIcon represents. + * + * @return The JInternalFrame this JDesktopIcon represents. + */ + public JInternalFrame getInternalFrame() + { + return frame; + } + + /** + * This method returns the UI that is responsible for the JDesktopIcon. + * + * @return The UI that is responsible for the JDesktopIcon. + */ + public DesktopIconUI getUI() + { + return (DesktopIconUI) ui; + } + + /** + * This method returns the String identifier that is used to determine + * which class is used for JDesktopIcon's UI. + * + * @return A String identifier for the UI class. + */ + public String getUIClassID() + { + return "DesktopIconUI"; + } + + /** + * This method sets the JInternalFrame that this JDesktopIcon represents. + * + * @param f The JInternalFrame that this JDesktopIcon represents. + */ + public void setInternalFrame(JInternalFrame f) + { + frame = f; + } + + /** + * This method sets the UI used for this JDesktopIcon. + * + * @param ui The UI to use. + */ + public void setUI(DesktopIconUI ui) + { + super.setUI(ui); + } + + /** + * This method restores the UI property to the defaults. + */ + public void updateUI() + { + setUI((DesktopIconUI) UIManager.getUI(this)); + } + } + + /** + * The property fired in a PropertyChangeEvent when the contentPane property + * changes. + */ + public static String CONTENT_PANE_PROPERTY = "contentPane"; + + /** + * The property fired in a PropertyChangeEvent when the frameIcon property + * changes. + */ + public static String FRAME_ICON_PROPERTY = "frameIcon"; + + /** + * The property fired in a PropertyChangeEvent when the glassPane property + * changes. + */ + public static String GLASS_PANE_PROPERTY = "glassPane"; + + /** + * The property fired in a PropertyChangeEvent when the closed property + * changes. + */ + public static String IS_CLOSED_PROPERTY = "closed"; + + /** + * The property fired in a PropertyChangeEvent when the icon property + * changes. + */ + public static String IS_ICON_PROPERTY = "icon"; + + /** + * The property fired in a PropertyChangeEvent when the maximum property + * changes. + */ + public static String IS_MAXIMUM_PROPERTY = "maximum"; + + /** + * The property fired in a PropertyChangeEvent when the selected property + * changes. + */ + public static String IS_SELECTED_PROPERTY = "selected"; + + /** + * The property fired in a PropertyChangeEvent when the layeredPane property + * changes. + */ + public static String LAYERED_PANE_PROPERTY = "layeredPane"; + + /** + * The property fired in a PropertyChangeEvent when the jMenuBar property + * changes. + */ + public static String MENU_BAR_PROPERTY = "jMenuBar"; + + /** + * The property fired in a PropertyChangeEvent when the rootPane property + * changes. + */ + public static String ROOT_PANE_PROPERTY = "rootPane"; + + /** + * The property fired in a PropertyChangeEvent when the title property + * changes. + */ + public static String TITLE_PROPERTY = "title"; + + /** Whether the JInternalFrame is closable. */ + protected boolean closable; + + /** Whether the JInternalFrame can be iconified. */ + protected boolean iconable; + + /** Whether the JInternalFrame is closed. */ + protected boolean isClosed; + + /** Whether the JInternalFrame has been iconified. */ + protected boolean isIcon; + + /** Whether the JInternalFrame has been maximized. */ + protected boolean isMaximum; + + /** Whether the JInternalFrame is the active frame. */ + protected boolean isSelected; + + /** Whether the JInternalFrame can be maximized. */ + protected boolean maximizable; + + /** Whether the JInternalFrame has rootPaneChecking enabled. */ + protected boolean rootPaneCheckingEnabled = true; + + /** Whether the JInternalFrame is resizable. */ + protected boolean resizable; + + /** + * The JDesktopIcon that represents the JInternalFrame while it is + * iconified. + */ + protected JDesktopIcon desktopIcon; + + /** The icon used in the JMenuBar in the TitlePane. */ + protected Icon frameIcon; + + /** The rootPane of the JInternalFrame. */ + protected JRootPane rootPane; + + /** The title on the TitlePane of the JInternalFrame. */ + protected String title; + + /** The bounds of the JInternalFrame before it was maximized. */ + private transient Rectangle storedBounds; + + /** The Component that receives focus by default. */ + private transient Component defaultFocus; + + /** The default close action taken, */ + private transient int defaultCloseOperation = DISPOSE_ON_CLOSE; + + /** Whether the JInternalFrame has become visible for the very first time. */ + private transient boolean isFirstTimeVisible = true; + + /** + * Whether the JInternalFrame is in the transition from being a maximized + * frame back to a regular sized frame. + */ + private transient boolean maxTransition = false; + + /** DOCUMENT ME! */ + private transient boolean wasIcon = false; + + /** + * Creates a new JInternalFrame object that has no title, and is + * non-resizable, non-maximizable, non-iconifiable, and non-closable. + */ + public JInternalFrame() + { + this(null, false, false, false, false); + } + + /** + * Creates a new JInternalFrame object with the given title and is + * non-resizable, non-maximizable, non-iconifiable, and non-closable. + * + * @param title The title displayed in the JInternalFrame. + */ + public JInternalFrame(String title) + { + this(title, false, false, false, false); + } + + /** + * Creates a new JInternalFrame object with the given title and resizable + * properties. The JInternalFrame is non-maximizable, non-iconifiable, and + * non-closable. + * + * @param title The title displayed in the JInternalFrame. + * @param resizable Whether the JInternalFrame is resizable. + */ + public JInternalFrame(String title, boolean resizable) + { + this(title, resizable, false, false, false); + } + + /** + * Creates a new JInternalFrame object with the given title, resizable, and + * closable properties. The JInternalFrame is non-maximizable and + * non-iconifiable. + * + * @param title The title displayed in the JInternalFrame. + * @param resizable Whether the JInternalFrame is resizable. + * @param closable Whether the JInternalFrame is closable. + */ + public JInternalFrame(String title, boolean resizable, boolean closable) + { + this(title, resizable, closable, false, false); + } + + /** + * Creates a new JInternalFrame object with the given title, resizable, + * closable and maximizable properties. The JInternalFrame is + * non-iconifiable. + * + * @param title The title displayed in the JInternalFrame. + * @param resizable Whether the JInternalFrame is resizable. + * @param closable Whether the JInternalFrame is closable. + * @param maximizable Whether the JInternalFrame is maximizable. + */ + public JInternalFrame(String title, boolean resizable, boolean closable, + boolean maximizable) + { + this(title, resizable, closable, maximizable, false); + } + + /** + * Creates a new JInternalFrame object with the given title, resizable, + * closable, maximizable and iconifiable properties. + * + * @param title The title displayed in the JInternalFrame. + * @param resizable Whether the JInternalFrame is resizable. + * @param closable Whether the JInternalFrame is closable. + * @param maximizable Whether the JInternalFrame is maximizable. + * @param iconifiable Whether the JInternalFrame is iconifiable. + */ + public JInternalFrame(String title, boolean resizable, boolean closable, + boolean maximizable, boolean iconifiable) + { + this.title = title; + this.resizable = resizable; + this.closable = closable; + this.maximizable = maximizable; + this.iconable = iconifiable; + storedBounds = new Rectangle(); + + setRootPaneCheckingEnabled(false); + setRootPane(createRootPane()); + + updateUI(); + setRootPaneCheckingEnabled(true); + } + + /** + * This method adds Components to this Container. For JInternalFrames, + * instead of calling add directly on the JInternalFrame, it should be + * called with JInternalFrame.getContentPane().add. If root pane checking + * is enabled, calling this method will cause an exception to be thrown. + * + * @param comp The Component to add. + * @param constraints The constraints on the Component added. + * @param index The position to place the Component. + * + * @throws Error DOCUMENT ME! + */ + protected void addImpl(Component comp, Object constraints, int index) + { + if (isRootPaneCheckingEnabled()) + throw new Error("Do not use add() on JInternalPane directly. Use getContentPane().add() instead"); + + super.addImpl(comp, constraints, index); + } + + /** + * This method adds an InternalFrameListener to this JInternalFrame. + * + * @param l The listener to add. + */ + public void addInternalFrameListener(InternalFrameListener l) + { + listenerList.add(InternalFrameListener.class, l); + } + + /** + * This method is used to create a root pane for the JInternalFrame. This + * method is called by the constructors. + * + * @return A root pane for the JInternalFrame to use. + */ + protected JRootPane createRootPane() + { + return new JRootPane(); + } + + /** + * This method makes this JInternalFrame invisible, unselected and closed. + * If this JInternalFrame is not closed already, it will fire an + * INTERNAL_FRAME_CLoSED event. This method is similar to setClosed but it + * doesn't give vetoable listeners a chance to veto and it will not fire an + * INTERNAL_FRAME_CLOSING event. + */ + public void dispose() + { + hide(); + JDesktopPane pane = getDesktopPane(); + if (pane != null) + pane.setSelectedFrame(null); + else + { + try + { + setSelected(false); + } + catch (PropertyVetoException e) + { + // Do nothing if they don't want to be unselected. + } + } + isClosed = true; + fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_CLOSED); + removeNotify(); + } + + /** + * This method is used for closing this JInternalFrame. It fires an + * INTERNAL_FRAME_CLOSING event and then performs the action specified by + * the default close operation. + */ + public void doDefaultCloseAction() + { + fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_CLOSING); + switch (getDefaultCloseOperation()) + { + case HIDE_ON_CLOSE: + hide(); + break; + case DISPOSE_ON_CLOSE: + dispose(); + break; + } + } + + /** + * This method fires an InternalFrameEvent to the listeners. + * + * @param id The type of event being fired. See InternalFrameEvent. + */ + protected void fireInternalFrameEvent(int id) + { + Object[] ifListeners = listenerList.getListenerList(); + InternalFrameEvent evt = new InternalFrameEvent(this, id); + switch (id) + { + case InternalFrameEvent.INTERNAL_FRAME_CLOSING: + for (int i = ifListeners.length - 2; i >= 0; i -= 2) + { + if (ifListeners[i] == InternalFrameListener.class) + ((InternalFrameListener) ifListeners[i + 1]) + .internalFrameClosing(evt); + } + break; + case InternalFrameEvent.INTERNAL_FRAME_ACTIVATED: + for (int i = ifListeners.length - 2; i >= 0; i -= 2) + { + if (ifListeners[i] == InternalFrameListener.class) + ((InternalFrameListener) ifListeners[i + 1]) + .internalFrameActivated(evt); + } + break; + case InternalFrameEvent.INTERNAL_FRAME_CLOSED: + for (int i = ifListeners.length - 2; i >= 0; i -= 2) + { + if (ifListeners[i] == InternalFrameListener.class) + ((InternalFrameListener) ifListeners[i + 1]).internalFrameClosed(evt); + } + break; + case InternalFrameEvent.INTERNAL_FRAME_DEACTIVATED: + for (int i = ifListeners.length - 2; i >= 0; i -= 2) + { + if (ifListeners[i] == InternalFrameListener.class) + ((InternalFrameListener) ifListeners[i + 1]) + .internalFrameDeactivated(evt); + } + break; + case InternalFrameEvent.INTERNAL_FRAME_DEICONIFIED: + for (int i = ifListeners.length - 2; i >= 0; i -= 2) + { + if (ifListeners[i] == InternalFrameListener.class) + ((InternalFrameListener) ifListeners[i + 1]) + .internalFrameDeiconified(evt); + } + break; + case InternalFrameEvent.INTERNAL_FRAME_ICONIFIED: + for (int i = ifListeners.length - 2; i >= 0; i -= 2) + { + if (ifListeners[i] == InternalFrameListener.class) + ((InternalFrameListener) ifListeners[i + 1]) + .internalFrameIconified(evt); + } + break; + case InternalFrameEvent.INTERNAL_FRAME_OPENED: + for (int i = ifListeners.length - 2; i >= 0; i -= 2) + { + if (ifListeners[i] == InternalFrameListener.class) + ((InternalFrameListener) ifListeners[i + 1]).internalFrameOpened(evt); + } + break; + } + } + + /** + * DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public AccessibleContext getAccessibleContext() + { + if (accessibleContext == null) + accessibleContext = new AccessibleJInternalFrame(); + return accessibleContext; + } + + /** + * This method returns the Content Pane for this JInternalFrame. + * + * @return The Content Pane for this JInternalFrame. + */ + public Container getContentPane() + { + return getRootPane().getContentPane(); + } + + /** + * This method returns the default action taken when this JInternalFrame is + * closed. + * + * @return The default action taken when this JInternalFrame is closed. + */ + public int getDefaultCloseOperation() + { + return defaultCloseOperation; + } + + /** + * This method returns the JDesktopIcon that represents this JInternalFrame + * while it is iconified. + * + * @return The JDesktopIcon that represents this JInternalFrame while it is + * iconified. + */ + public JDesktopIcon getDesktopIcon() + { + if (desktopIcon == null) + desktopIcon = new JDesktopIcon(this); + return desktopIcon; + } + + /** + * This method searches this JInternalFrame ancestors for an instance of + * JDesktopPane. If one is found, it is returned. If none is found, then it + * will search the JDesktopIcon for a JDesktopPane. + * + * @return The JDesktopPane that this JInternalFrame belongs to. + */ + public JDesktopPane getDesktopPane() + { + JDesktopPane value = (JDesktopPane) SwingUtilities.getAncestorOfClass(JDesktopPane.class, + this); + if (value == null && desktopIcon != null) + value = desktopIcon.getDesktopPane(); + return value; + } + + /** + * This method returns null because this must always be the root of a focus + * traversal. + * + * @return null. + */ + public Container getFocusCycleRootAncestor() + { + // as defined. + return null; + } + + /** + * This method returns the child Component that will receive focus if this + * JInternalFrame is selected. + * + * @return The child Component that will receive focus. + */ + public Component getFocusOwner() + { + if (isSelected()) + { + Component focus = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); + if (SwingUtilities.isDescendingFrom(focus, this)) + { + defaultFocus = focus; + return focus; + } + } + return null; + } + + /** + * This method returns the Frame Icon (the icon used in the JInternalFrame + * TitlePane and iconified frame). + * + * @return The Frame Icon. + */ + public Icon getFrameIcon() + { + return frameIcon; + } + + /** + * This method returns the Glass Pane used with this JInternalFrame. + * + * @return The Glass Pane used with this JInternalFrame. + */ + public Component getGlassPane() + { + return getRootPane().getGlassPane(); + } + + /** + * This method returns an array of InternalFrameListeners that are listening + * to this JInternalFrame. + * + * @return An array of InternalFrameListeners that are listening to this + * JInternalFrame. + */ + public InternalFrameListener[] getInternalFrameListeners() + { + return (InternalFrameListener[]) listenerList.getListeners(InternalFrameListener.class); + } + + /** + * This method returns the JMenuBar for this JInternalFrame. + * + * @return The JMenuBar for this JInternalFrame. + */ + public JMenuBar getJMenuBar() + { + return getRootPane().getJMenuBar(); + } + + /** + * This method returns the layer that this JInternalFrame resides in. + * + * @return The layer that this JInternalFrame resides in. + */ + public int getLayer() + { + JDesktopPane pane = getDesktopPane(); + if (pane != null) + return pane.getLayer(this).intValue(); + return -1; + } + + /** + * This method returns the LayeredPane for this JInternalFrame. + * + * @return The LayeredPane for this JInternalFrame. + */ + public JLayeredPane getLayeredPane() + { + return getRootPane().getLayeredPane(); + } + + /** + * This method is deprecated. This method returns the JMenuBar for this + * JInternalFrame. + * + * @return The JMenuBar for this JInternalFrame. + */ + public JMenuBar getMenuBar() + { + return getJMenuBar(); + } + + /** + * This method returns the child Component that will receive focus when the + * JInternalFrame is selected. If the JInternalFrame is selected, this + * method returns getFocusOwner(). Otherwise, it will return the child + * Component that most recently requested focus. If that is null, then the + * initial focus Component is returned. If that is null, then the default + * focus component is returned. + * + * @return The most recent focus owner. + */ + public Component getMostRecentFocusOwner() + { + if (isSelected()) + return getFocusOwner(); + else + return defaultFocus; + } + + /** + * This method returns the bounds of the JInternalFrame if it is not + * maximized. If it is maximized, it returns the bounds of the + * JInternalFrame before it was maximized (the bounds that it will be + * restored to). + * + * @return A Rectangle that contains this JInternalFrame's normal bounds (or + * just its bounds if it is not maximized). + */ + public Rectangle getNormalBounds() + { + if (! isMaximum() && ! maxTransition) + return getBounds(); + else + return storedBounds; + } + + /** + * This method returns the Root Pane for this JInternalFrame. + * + * @return The Root Pane for this JInternalFrame. + */ + public JRootPane getRootPane() + { + return rootPane; + } + + /** + * This method sets the title of the JInternalFrame. + * + * @return The String displayed in the TitlePane of this JInternalFrame. + */ + public String getTitle() + { + return title; + } + + /** + * This method returns the UI used to represent the JInternalFrame. + * + * @return The UI used to represent the JInternalFrame. + */ + public InternalFrameUI getUI() + { + return (InternalFrameUI) ui; + } + + /** + * This method returns a String identifier that is used to determine which + * class acts as the JInternalFrame's UI. + * + * @return A String identifier to determine a UI class. + */ + public String getUIClassID() + { + return "InternalFrameUI"; + } + + /** + * This method returns null. + * + * @return null. + */ + public String getWarningString() + { + // as defined. + return null; + } + + /** + * This method deselects this JInternalFrame and hides it. + */ + public void hide() + { + JDesktopPane pane = getDesktopPane(); + if (pane != null) + pane.setSelectedFrame(null); + else + { + try + { + setSelected(false); + } + catch (PropertyVetoException e) + { + // Do nothing. + } + } + super.hide(); + } + + /** + * This method returns whether this JInternalFrame is closable. + * + * @return Whether this JInternalFrame is closable. + */ + public boolean isClosable() + { + return closable; + } + + /** + * This method returns whether this JInternalFrame has been closed. + * + * @return Whether this JInternalFrame is closed. + */ + public boolean isClosed() + { + return isClosed; + } + + /** + * This must always return true. + * + * @return True + */ + public boolean isFocusCycleRoot() + { + return true; + } + + /** + * This method returns whether this JInternalFrame is currently iconified. + * + * @return Whether this JInternalFrame is currently iconified. + */ + public boolean isIcon() + { + return isIcon; + } + + /** + * This method returns whether the JInternalFrame can be iconified. + * + * @return Whether the JInternalFrame can be iconified. + */ + public boolean isIconifiable() + { + return iconable; + } + + /** + * This method returns whether this JInternalFrame can be maximized. + * + * @return Whether this JInternalFrame can be maximized. + */ + public boolean isMaximizable() + { + return maximizable; + } + + /** + * This method returns whether this JInternalFrame is currently maximized. + * + * @return Whether this JInternalFrame is maximized. + */ + public boolean isMaximum() + { + return isMaximum; + } + + /** + * This method returns whether this JInternalFrame is resizable. + * + * @return Whether this JInternalFrame is resizable. + */ + public boolean isResizable() + { + return resizable; + } + + /** + * This method returns whether root pane checking is enabled. If root pane + * checking is enabled, then calls to addImpl and setLayout will throw + * exceptions. + * + * @return Whether root pane checking is enabled. + */ + protected boolean isRootPaneCheckingEnabled() + { + return rootPaneCheckingEnabled; + } + + /** + * This method returns whether this JInternalFrame is selected. + * + * @return Whether this JInternalFrame is selected. + */ + public boolean isSelected() + { + return isSelected; + } + + /** + * A helper method that moves this JInternalFrame to the back if the parent + * is a JLayeredPane. + */ + public void moveToBack() + { + if (getParent() instanceof JLayeredPane) + ((JLayeredPane) getParent()).moveToBack(this); + } + + /** + * A helper method that moves this JInternalFrame to the front if the parent + * is a JLayeredPane. + */ + public void moveToFront() + { + if (getParent() instanceof JLayeredPane) + ((JLayeredPane) getParent()).moveToFront(this); + } + + /** + * This method causes the children of this JInternalFrame to be laid out. + * Before it begins, if this JInternalFrame is an icon, then it will be + * deiconified. If it is maximized, then it will be restored. If either + * operation fails, then this method will return. + */ + public void pack() + { + try + { + if (isIcon()) + setIcon(false); + else if (isMaximum()) + setMaximum(false); + } + catch (PropertyVetoException e) + { + // Do nothing if they don't want to be restored first. + } + doLayout(); + } + + /** + * This method is overridden to allow for speedier painting while this + * JInternalFramme is being dragged. + * + * @param g The Graphics object to paint with. + */ + protected void paintComponent(Graphics g) + { + super.paintComponent(g); + } + + /** + * This method returns a String describing this JInternalFrame. + * + * @return A String describing this JInternalFrame. + */ + protected String paramString() + { + return "JInternalFrame"; + } + + /** + * This method removes the given Component from the Container. + * + * @param comp The Component to remove. + */ + public void remove(Component comp) + { + super.remove(comp); + } + + /** + * This method removes an InternalFrameListener from this JInternalFrame. + * + * @param l The listener to remove. + */ + public void removeInternalFrameListener(InternalFrameListener l) + { + listenerList.remove(InternalFrameListener.class, l); + } + + /** + * This method resizes and positions this JInternalFrame. It also forces a + * relayout of the Container. + * + * @param x The x position of this JInternalFrame. + * @param y The y position of this JInternalFrame. + * @param width The width of this JInternalFrame. + * @param height The height of this JInternalFrame. + */ + public void reshape(int x, int y, int width, int height) + { + super.reshape(x, y, width, height); + invalidate(); + doLayout(); + } + + /** + * This method gives focus to the last child Component that had focus. This + * is used by the UI when this JInternalFrame is activated. + */ + public void restoreSubcomponentFocus() + { + Component c = getMostRecentFocusOwner(); + if (c != null) + c.requestFocus(); + } + + /** + * This method sets whether this JInternalFrame can be closed. + * + * @param b Whether this JInternalFrame can be closed. + */ + public void setClosable(boolean b) + { + closable = b; + } + + /** + * This method closes the JInternalFrame if the given boolean is true. If it + * is false, then the result of this method is unspecified. If the + * JInternalFrame is closed, this method does nothing. This method will + * first fire an INTERNAL_FRAME_CLOSING event and give a chance for veto + * listeners to cancel the close. If no listener vetoes the change, the + * closed property is set to true and the JInternalFrame is hidden and + * unselected. The method will finish by firing an INTERNAL_FRAME_CLOSED + * event. + * + * @param b Whether the JInternalFrame will be closed. + * + * @throws PropertyVetoException If a VetoableChangeListener vetoes the change. + */ + public void setClosed(boolean b) throws PropertyVetoException + { + if (b && ! isClosed()) + { + fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_CLOSING); + fireVetoableChange(IS_CLOSED_PROPERTY, false, true); + + isClosed = b; + + firePropertyChange(IS_CLOSED_PROPERTY, false, true); + fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_CLOSED); + } + } + + /** + * This method sets the Container to be used as a Content Pane for this + * JInternalFrame. + * + * @param c The Container to use as a Content Pane. + */ + public void setContentPane(Container c) + { + if (c != getContentPane()) + { + Container old = getContentPane(); + getRootPane().setContentPane(c); + firePropertyChange(CONTENT_PANE_PROPERTY, old, c); + } + } + + /** + * This method sets the action taken when this JInternalFrame is closed. + * + * @param operation One of DO_NOTHING_ON_CLOSE, HIDE_ON_CLOSE or + * DISPOSE_ON_CLOSE. + * + * @throws Error If the given operation is not one of the allowed modes. + */ + public void setDefaultCloseOperation(int operation) + { + if (operation != DO_NOTHING_ON_CLOSE || operation != HIDE_ON_CLOSE + || operation != DISPOSE_ON_CLOSE) + throw new Error("Close operation must be one of DO_NOTHING_ON_CLOSE, HIDE_ON_CLOSE, or DISPOSE_ON_CLOSE"); + defaultCloseOperation = operation; + } + + /** + * This method sets the JDesktopIcon that represents this JInternalFrame + * while it is iconified. + * + * @param d The JDesktopIcon that represents this JInternalFrame while it is + * iconified. + */ + public void setDesktopIcon(JDesktopIcon d) + { + d.setInternalFrame(this); + desktopIcon = d; + } + + /** + * This method does nothing because this must be the root of a focus + * traversal cycle. + * + * @param focusCycleRoot Not used. + */ + public final void setFocusCycleRoot(boolean focusCycleRoot) + { + // Do nothing + } + + /** + * This method sets the Icon to be used in two places. The first is icon + * that is painted at the top left corner of the JInternalFrame when it is + * not iconified (clicking on that icon will activate the TitlePane + * JMenuBar). When the JInternalFrame is iconified, it will be the icon + * displayed in the JDesktopIcon. If no icon is set, the JInternalFrame + * will use a Look and Feel default. + * + * @param icon The Icon used in the TitlePane JMenuBar and iconified frames. + */ + public void setFrameIcon(Icon icon) + { + if (icon != frameIcon) + { + Icon old = frameIcon; + frameIcon = icon; + firePropertyChange(FRAME_ICON_PROPERTY, old, frameIcon); + } + } + + /** + * This method sets the Glass Pane used with this JInternalFrame. + * + * @param glass The Glass Pane to use with this JInternalFrame. + */ + public void setGlassPane(Component glass) + { + if (glass != getGlassPane()) + { + Component old = getGlassPane(); + getRootPane().setGlassPane(glass); + firePropertyChange(GLASS_PANE_PROPERTY, old, glass); + } + } + + /** + * This method iconifies or deiconifies this JInternalFrame given the + * boolean argument. If the JInternalFrame becomes iconified, it will fire + * an INTERNAL_FRAME_ICONIFIED event. If the JInternalFrame becomes + * deiconified, it will fire anINTERNAL_FRAME_DEICONIFIED event. + * + * @param b Whether this JInternalFrame is to be iconified or deiconified. + * + * @throws PropertyVetoException DOCUMENT ME! + */ + public void setIcon(boolean b) throws PropertyVetoException + { + if (b != isIcon()) + { + fireVetoableChange(IS_ICON_PROPERTY, b, isIcon); + + isIcon = b; + + firePropertyChange(IS_ICON_PROPERTY, ! isIcon, isIcon); + if (b) + fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_ICONIFIED); + else + fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_DEICONIFIED); + } + } + + /** + * This method sets whether the JInternalFrame can be iconified. (This means + * that the JInternalFrame can be turned into an icon if minimized). + * + * @param b Whether the JInternalFrame can be iconified. + */ + public void setIconifiable(boolean b) + { + iconable = b; + } + + /** + * This method sets the JMenuBar to be used with this JInternalFrame. + * + * @param b The JMenuBar to be used with this JInternalFrame. + */ + public void setJMenuBar(JMenuBar b) + { + getRootPane().setJMenuBar(b); + } + + /** + * A helper method that set the layer that this JInternalFrame resides in. + * Using this version of the method means that the user should not set it + * to values that are already defined in JLayeredPane. If predefined values + * are to be used, the user should use the setLayer(Integer) version. + * + * @param layer The layer to place this JInternalFrame in. + */ + public void setLayer(int layer) + { + setLayer(new Integer(layer)); + } + + /** + * A helper method that sets the layer that this JInternalFrame resides in. + * Calling this version of the method should use layer values that are + * already defined in JLayeredPane. + * + * @param layer The layer to place this JInternalFrame in. + */ + public void setLayer(Integer layer) + { + JDesktopPane p = getDesktopPane(); + if (p != null) + { + int pos = p.getPosition(this); + p.setLayer(this, layer.intValue(), pos); + } + } + + /** + * This method sets the JLayeredPane to use with this JInternalFrame. + * + * @param layered The JLayeredPane to use as a layeredPane. + */ + public void setLayeredPane(JLayeredPane layered) + { + if (layered != getLayeredPane()) + { + JLayeredPane old = getLayeredPane(); + getRootPane().setLayeredPane(layered); + firePropertyChange(LAYERED_PANE_PROPERTY, old, layered); + } + } + + /** + * This method sets whether the JInternalFrame can be maximized. + * + * @param b Whether this JInternalFrame can be maximized. + */ + public void setMaximizable(boolean b) + { + maximizable = b; + } + + /** + * This method sets the Layout Manager used in the JInternalFrame. SetLayout + * should not be called on the JInternalFrame directly. Instead, it should + * be called with JInternalFrame.getContentPane().setLayout. Calls to this + * method with root pane checking enabled will cause exceptions to be + * thrown. + * + * @param manager The Layout Manager to be used with the JInternalFrame. + * + * @throws Error If rootPaneChecking is enabled. + */ + public void setLayout(LayoutManager manager) + { + if (isRootPaneCheckingEnabled()) + throw new Error("Cannot set layout. Use getContentPane().setLayout() instead."); + super.setLayout(manager); + } + + /** + * This method sets the JInternalFrame to maximized (if the given argument + * is true) or restores the JInternalFrame to its normal bounds otherwise. + * + * @param b Whether this JInteralFrame will be maximized or restored. + * + * @throws PropertyVetoException If a VetoableChangeListener vetoes the change. + */ + public void setMaximum(boolean b) throws PropertyVetoException + { + if (b != isMaximum()) + { + fireVetoableChange(IS_MAXIMUM_PROPERTY, b, isMaximum); + isMaximum = b; + if (b) + setNormalBounds(getBounds()); + maxTransition = ! b; + firePropertyChange(IS_MAXIMUM_PROPERTY, ! isMaximum, isMaximum); + maxTransition = false; + } + } + + /** + * This method is deprecated. This method sets the JMenuBar used with this + * JInternalFrame. + * + * @param m The JMenuBar to use with this JInternalFrame. + */ + public void setMenuBar(JMenuBar m) + { + setJMenuBar(m); + } + + /** + * This method sets the bounds that this JInternalFrame will be restored to. + * + * @param r The bounds that this JInternalFrame will be restored to. + */ + public void setNormalBounds(Rectangle r) + { + storedBounds.setBounds(r.x, r.y, r.width, r.height); + } + + /** + * This method sets whether the JInternalFrame can be resized by a user + * action (like dragging at the frame borders). + * + * @param b Whether this JInternalFramer can be resized. + */ + public void setResizable(boolean b) + { + resizable = b; + } + + /** + * This method sets the Root Pane for this JInternalFrame. + * + * @param root The Root Pane for this JInternalFrame. + */ + protected void setRootPane(JRootPane root) + { + if (rootPane != null) + remove(rootPane); + + rootPane = root; + add(root); + } + + /** + * This method sets whether root pane checking is enabled. If root pane + * checking is enabled, then calls to addImpl and setLayout will throw + * exceptions. + * + * @param enabled Whether root pane checking is enabled. + */ + protected void setRootPaneCheckingEnabled(boolean enabled) + { + rootPaneCheckingEnabled = enabled; + } + + /** + * This method sets whether this JInternalFrame is the selected frame in the + * JDesktopPane (or other container). When selected, a JInternalFrame will + * have focus and paint its TitlePane differently (usually a different + * colour). If this method selects the frame, this JInternalFrame will fire + * an INTERNAL_FRAME_ACTIVATED event. If it deselects this frame, it will + * fire an INTERNAL_FRAME_DEACTIVATED event. + * + * @param selected Whether this JInternalFrame will become selected or + * deselected. + * + * @throws PropertyVetoException If a VetoableChangeListener vetoes the change. + */ + public void setSelected(boolean selected) throws PropertyVetoException + { + if (selected != isSelected()) + { + fireVetoableChange(IS_SELECTED_PROPERTY, selected, isSelected); + + if (! selected) + defaultFocus = getMostRecentFocusOwner(); + + isSelected = selected; + + if (selected) + restoreSubcomponentFocus(); + + firePropertyChange(IS_SELECTED_PROPERTY, ! isSelected, isSelected); + + if (isSelected) + fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_ACTIVATED); + else + fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_DEACTIVATED); + } + } + + /** + * This method sets the title displayed in the TitlePane of this + * JInternalFrame. + * + * @param title The title displayed. + */ + public void setTitle(String title) + { + if (title == null && this.title == null) + return; + if (title == null || this.title == null || ! this.title.equals(title)) + { + String old = title; + this.title = title; + firePropertyChange(TITLE_PROPERTY, old, this.title); + } + } + + /** + * This method displays the JInternalFrame. If it is not visible, this + * method will bring this JInternalFrame to the front, make it visible and + * select it. If this is the first time this JInternalFrame is made + * visible, an INTERNAL_FRAME_OPENED event will be fired. + */ + public void show() + { + if (! isVisible()) + { + moveToFront(); + super.show(); + + JDesktopPane pane = getDesktopPane(); + if (pane != null) + pane.setSelectedFrame(this); + else + { + try + { + setSelected(true); + } + catch (PropertyVetoException e) + { + // Do nothing. if they don't want to be selected. + } + } + if (isFirstTimeVisible) + { + isFirstTimeVisible = false; + fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_OPENED); + } + } + } + + /** + * This method is used to set the UI responsible for the JInternalFrame. + * + * @param ui The UI responsible for the JInternalFrame. + */ + public void setUI(InternalFrameUI ui) + { + super.setUI(ui); + } + + /** + * This method causes the JInternalFrame to be brough to back in the + * z-order. + */ + public void toBack() + { + moveToBack(); + } + + /** + * This method causes the JInternalFrame to be brought to front in the + * z-order. + */ + public void toFront() + { + moveToFront(); + } + + /** + * This method resets the UI to the Look and Feel defaults. + */ + public void updateUI() + { + setUI((InternalFrameUI) UIManager.getUI(this)); + } + + /** + * This helper method allows JInternalFrames to signal that they were + * iconned for the first time. + * + * @param b Whether the JInternalFrame was iconned. + * @param ID The identifier of the property change event to fire if the + * JInternalFrame is iconned for the first time. + */ + void setWasIcon(boolean b, String ID) + { + if (b && ! wasIcon) + { + wasIcon = b; + firePropertyChange(ID, ! b, b); + } + } + + /** + * This helper method returns whether the JInternalFrame has been iconned + * once already. + * + * @return Whether the JInternalFrame has been iconned once already. + */ + boolean getWasIcon() + { + return wasIcon; + } + + /** + * This method is a convenience method to fire vetoable property changes. + * + * @param name The identifier of the property change. + * @param oldValue The old value. + * @param newValue The new value. + * + * @throws PropertyVetoException Fired if a vetoable change listener vetoes + * the change. + */ + private void fireVetoableChange(String name, boolean oldValue, + boolean newValue) + throws PropertyVetoException + { + super.fireVetoableChange(name, new Boolean(oldValue), new Boolean(newValue)); + } } // class JInternalFrame diff --git a/libjava/javax/swing/JLabel.java b/libjava/javax/swing/JLabel.java index c6bc1bd3ca8..0a15cfc9c5f 100644 --- a/libjava/javax/swing/JLabel.java +++ b/libjava/javax/swing/JLabel.java @@ -331,9 +331,8 @@ public class JLabel extends JComponent implements Accessible, SwingConstants */ public Icon getDisabledIcon() { - //FIXME: We should be gray-scaling the active icon and then returning it if (disabledIcon == null && activeIcon instanceof ImageIcon) - setDisabledIcon(activeIcon); + disabledIcon = new ImageIcon(GrayFilter.createDisabledImage(((ImageIcon) activeIcon).getImage())); return disabledIcon; } diff --git a/libjava/javax/swing/JLayeredPane.java b/libjava/javax/swing/JLayeredPane.java index 37cd01221ce..78ff95e0b76 100644 --- a/libjava/javax/swing/JLayeredPane.java +++ b/libjava/javax/swing/JLayeredPane.java @@ -91,7 +91,9 @@ import javax.accessibility.Accessible; */ public class JLayeredPane extends JComponent implements Accessible { - public static String LAYER_PROPERTY = "LAYER_PROPERTY"; + private static final long serialVersionUID = 5534920399324590459L; + + public static final String LAYER_PROPERTY = "layeredContainerLayer"; public static Integer FRAME_CONTENT_LAYER = new Integer (-30000); @@ -104,7 +106,7 @@ public class JLayeredPane extends JComponent implements Accessible TreeMap layers; // Layer Number (Integer) -> Layer Size (Integer) Hashtable componentToLayer; // Component -> Layer Number (Integer) - JLayeredPane() + public JLayeredPane() { layers = new TreeMap (); componentToLayer = new Hashtable (); @@ -492,6 +494,8 @@ public class JLayeredPane extends JComponent implements Accessible decrLayer (layer); componentToLayer.remove (c); super.remove (index); + revalidate(); + repaint(); } /** diff --git a/libjava/javax/swing/JList.java b/libjava/javax/swing/JList.java index b20c450c256..732a0c077a0 100644 --- a/libjava/javax/swing/JList.java +++ b/libjava/javax/swing/JList.java @@ -39,6 +39,7 @@ package javax.swing; import java.awt.Color; import java.awt.Component; +import java.awt.ComponentOrientation; import java.awt.Dimension; import java.awt.Point; import java.awt.Rectangle; @@ -109,24 +110,24 @@ public class JList extends JComponent implements Accessible, Scrollable /** * Constant value used in "layoutOrientation" property. This value means - * that cells are laid out in multiple columns "newspaper style", - * filling horizontally first, then vertically. - */ - public static int HORIZONTAL_WRAP = 1; - - /** - * Constant value used in "layoutOrientation" property. This value means * that cells are laid out in a single vertical column. This is the default. */ - public static int VERTICAL = 2; + public static final int VERTICAL = 0; /** * Constant value used in "layoutOrientation" property. This value means * that cells are laid out in multiple columns "newspaper style", filling * vertically first, then horizontally. */ - public static int VERTICAL_WRAP = 3; + public static final int VERTICAL_WRAP = 1; + /** + * Constant value used in "layoutOrientation" property. This value means + * that cells are laid out in multiple columns "newspaper style", + * filling horizontally first, then vertically. + */ + public static final int HORIZONTAL_WRAP = 2; + /** Fired in a PropertyChangeEvent when the "cellRenderer" property changes. */ public static final String CELL_RENDERER_PROPERTY_CHANGED = "cellRenderer"; @@ -560,6 +561,52 @@ public class JList extends JComponent implements Accessible, Scrollable } /** + * Returns <code>true</code> if the model's selection is empty, otherwise + * <code>false</code>. + * + * @return The return value of {@link ListSelectionModel#isSelectionEmpty} + */ + public boolean isSelectionEmpty() + { + return selectionModel.isSelectionEmpty(); + } + + /** + * Returns the list index of the upper left or upper right corner of the + * {@link #visibleRect} property, depending on the {@link + * #componentOrientation} property. + * + * @return The index of the first visible list cell, or <code>-1</code> + * if none is visible. + */ + public int getFirstVisibleIndex() + { + ComponentOrientation or = getComponentOrientation(); + Rectangle r = getVisibleRect(); + if (or == ComponentOrientation.RIGHT_TO_LEFT) + r.translate((int) r.getWidth(), 0); + return getUI().locationToIndex(this, r.getLocation()); + } + + /** + * Returns the list index of the lower right or lower left corner of the + * {@link #visibleRect} property, depending on the {@link + * #componentOrientation} property. + * + * @return The index of the first visible list cell, or <code>-1</code> + * if none is visible. + */ + public int getLastVisibleIndex() + { + ComponentOrientation or = getComponentOrientation(); + Rectangle r = getVisibleRect(); + r.translate(0, (int) r.getHeight()); + if (or == ComponentOrientation.LEFT_TO_RIGHT) + r.translate((int) r.getWidth(), 0); + return getUI().locationToIndex(this, r.getLocation()); + } + + /** * Returns the indices of values in the {@link #model} property which are * selected. * @@ -682,6 +729,44 @@ public class JList extends JComponent implements Accessible, Scrollable } /** + * Sets the selection to cover only the specified value, if it + * exists in the model. + * + * @param obj The object to select + * @param scroll Whether to scroll the list to make the newly selected + * value visible + * + * @see #ensureIndexIsVisible + */ + + public void setSelectedValue(Object obj, boolean scroll) + { + for (int i = 0; i < model.getSize(); ++i) + { + if (model.getElementAt(i).equals(obj)) + { + setSelectedIndex(i); + if (scroll) + ensureIndexIsVisible(i); + break; + } + } + } + + /** + * Scrolls this list to make the specified cell visible. This + * only works if the list is contained within a viewport. + * + * @param i The list index to make visible + * + * @see JComponent#scrollRectToVisible + */ + public void ensureIndexIsVisible(int i) + { + scrollRectToVisible(getUI().getCellBounds(this, i, i)); + } + + /** * Sets the {@link #model} property of the list to a new anonymous * {@link AbstractListModel} subclass which accesses the provided Object * array directly. diff --git a/libjava/javax/swing/JMenu.java b/libjava/javax/swing/JMenu.java index e75b709bd98..430d5781eb1 100644 --- a/libjava/javax/swing/JMenu.java +++ b/libjava/javax/swing/JMenu.java @@ -1,5 +1,5 @@ /* JMenu.java -- - Copyright (C) 2002, 2004 Free Software Foundation, Inc. + Copyright (C) 2002, 2004 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -39,9 +39,11 @@ package javax.swing; import java.awt.Component; import java.awt.Point; +import java.awt.Window; import java.awt.event.KeyEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; +import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.io.IOException; import java.io.ObjectOutputStream; @@ -52,6 +54,7 @@ import javax.accessibility.Accessible; import javax.accessibility.AccessibleContext; import javax.accessibility.AccessibleRole; import javax.accessibility.AccessibleSelection; +import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import javax.swing.event.MenuEvent; import javax.swing.event.MenuListener; @@ -59,18 +62,35 @@ import javax.swing.plaf.MenuItemUI; /** - * DOCUMENT ME! + * This class represents a menu that can be added to a menu bar or + * to some other menu. When JMenu is selected it displays JPopupMenu + * containing its menu items. */ public class JMenu extends JMenuItem implements Accessible, MenuElement { static final long serialVersionUID = 4227225638931828014L; + + /** name for the UI delegate for this menu. */ private static final String uiClassID = "MenuUI"; - private static Hashtable listenerRegistry = null; + + /** A Popup menu associated with this menu, which pops up when menu is selected */ private JPopupMenu popupMenu = new JPopupMenu(); + + /** MenuChangeListener that listens to change events occuring in menu's model */ private ChangeListener menuChangeListener; - private MenuEvent menuEvent; + + /** MenuEvent */ + private MenuEvent menuEvent = new MenuEvent(this); + + /*Amount of time, in milliseconds, that should pass before popupMenu + associated with this menu appears or disappers */ private int delay; - protected JMenu.WinListener popupListener; + + /* PopupListener */ + protected WinListener popupListener; + + /** Location at which popup menu associated with this menu will be displayed*/ + private Point menuLocation; /** * Creates a new JMenu object. @@ -78,55 +98,57 @@ public class JMenu extends JMenuItem implements Accessible, MenuElement public JMenu() { super(); + menuChangeListener = createMenuChangeListener(); + getModel().addChangeListener(menuChangeListener); } /** - * Creates a new JMenu object. + * Creates a new JMenu with the spicified label * - * @param text DOCUMENT ME! + * @param text label for this menu */ public JMenu(String text) { super(text); + menuChangeListener = createMenuChangeListener(); + getModel().addChangeListener(menuChangeListener); } /** - * Creates a new JMenu object. + * Creates a new JMenu object * - * @param action DOCUMENT ME! + * @param action Action that is used to create menu item tha will be + * added to the menu. */ public JMenu(Action action) { super(action); + menuChangeListener = createMenuChangeListener(); + getModel().addChangeListener(menuChangeListener); } /** - * Creates a new JMenu object. + * Creates a new JMenu with specified label and an option + * for this menu to be tear-off menu * - * @param text DOCUMENT ME! - * @param tearoff DOCUMENT ME! + * @param text label for this menu + * @param tearoff true if this menu should be tear-off and false otherwise */ public JMenu(String text, boolean tearoff) { + throw new Error("not implemented"); } - /** - * DOCUMENT ME! - * - * @param stream DOCUMENT ME! - * - * @throws IOException DOCUMENT ME! - */ private void writeObject(ObjectOutputStream stream) throws IOException { } /** - * DOCUMENT ME! + * Adds specified menu item to this menu * - * @param item DOCUMENT ME! + * @param item Menu item to add to this menu * - * @return DOCUMENT ME! + * @return Menu item that was added */ public JMenuItem add(JMenuItem item) { @@ -134,11 +156,11 @@ public class JMenu extends JMenuItem implements Accessible, MenuElement } /** - * DOCUMENT ME! + * Adds specified component to this menu. * - * @param component DOCUMENT ME! + * @param component Component to add to this menu * - * @return DOCUMENT ME! + * @return Component that was added */ public Component add(Component component) { @@ -146,12 +168,12 @@ public class JMenu extends JMenuItem implements Accessible, MenuElement } /** - * DOCUMENT ME! + * Adds specified component to this menu at the given index * - * @param component DOCUMENT ME! - * @param index DOCUMENT ME! + * @param component Component to add + * @param index Position of this menu item in the menu * - * @return DOCUMENT ME! + * @return Component that was added */ public Component add(Component component, int index) { @@ -159,11 +181,11 @@ public class JMenu extends JMenuItem implements Accessible, MenuElement } /** - * DOCUMENT ME! + * Adds JMenuItem constructed with the specified label to this menu * - * @param text DOCUMENT ME! + * @param text label for the menu item that will be added * - * @return DOCUMENT ME! + * @return Menu Item that was added to this menu */ public JMenuItem add(String text) { @@ -171,11 +193,11 @@ public class JMenu extends JMenuItem implements Accessible, MenuElement } /** - * DOCUMENT ME! + * Adds JMenuItem constructed using properties from specified action. * - * @param action DOCUMENT ME! + * @param action action to construct the menu item with * - * @return DOCUMENT ME! + * @return Menu Item that was added to this menu */ public JMenuItem add(Action action) { @@ -183,9 +205,10 @@ public class JMenu extends JMenuItem implements Accessible, MenuElement } /** - * DOCUMENT ME! + * Removes given menu item from this menu. Nothing happens if + * this menu doesn't contain specified menu item. * - * @param item DOCUMENT ME! + * @param item Menu Item which needs to be removed */ public void remove(JMenuItem item) { @@ -193,9 +216,9 @@ public class JMenu extends JMenuItem implements Accessible, MenuElement } /** - * DOCUMENT ME! + * Removes component at the specified index from this menu * - * @param index DOCUMENT ME! + * @param index Position of the component that needs to be removed in the menu */ public void remove(int index) { @@ -203,9 +226,9 @@ public class JMenu extends JMenuItem implements Accessible, MenuElement } /** - * DOCUMENT ME! + * Removes given component from this menu. * - * @param component DOCUMENT ME! + * @param component Component to remove */ public void remove(Component component) { @@ -214,7 +237,7 @@ public class JMenu extends JMenuItem implements Accessible, MenuElement } /** - * DOCUMENT ME! + * Removes all menu items from the menu */ public void removeAll() { @@ -222,49 +245,56 @@ public class JMenu extends JMenuItem implements Accessible, MenuElement } /** - * DOCUMENT ME! + * Creates JMenuItem with the specified text and inserts it in the + * at the specified index * - * @param text DOCUMENT ME! - * @param index DOCUMENT ME! + * @param text label for the new menu item + * @param index index at which to insert newly created menu item. */ public void insert(String text, int index) { - popupMenu.insert(new JMenuItem(text), index); + this.insert(new JMenuItem(text), index); } /** - * DOCUMENT ME! - * - * @param item DOCUMENT ME! - * @param index DOCUMENT ME! + * Creates JMenuItem with the specified text and inserts it in the + * at the specified index. IllegalArgumentException is thrown + * if index is less than 0 * - * @return DOCUMENT ME! + * @param item menu item to insert + * @param index index at which to insert menu item. + * @return Menu item that was added to the menu */ public JMenuItem insert(JMenuItem item, int index) { + if (index < 0) + throw new IllegalArgumentException("index less than zero"); + popupMenu.insert(item, index); return item; } /** - * DOCUMENT ME! - * - * @param action DOCUMENT ME! - * @param index DOCUMENT ME! + * Creates JMenuItem with the associated action and inserts it to the menu + * at the specified index. IllegalArgumentException is thrown + * if index is less than 0 * - * @return DOCUMENT ME! + * @param action Action for the new menu item + * @param index index at which to insert newly created menu item. + * @return Menu item that was added to the menu */ public JMenuItem insert(Action action, int index) { JMenuItem item = new JMenuItem(action); - popupMenu.insert(item, index); + this.insert(item, index); return item; } /** - * DOCUMENT ME! + * This method sets this menuItem's UI to the UIManager's default for the + * current look and feel. */ public void updateUI() { @@ -273,9 +303,10 @@ public class JMenu extends JMenuItem implements Accessible, MenuElement } /** - * DOCUMENT ME! + * This method returns a name to identify which look and feel class will be + * the UI delegate for the menu. * - * @return DOCUMENT ME! + * @return The Look and Feel classID. "MenuUI" */ public String getUIClassID() { @@ -283,9 +314,9 @@ public class JMenu extends JMenuItem implements Accessible, MenuElement } /** - * DOCUMENT ME! + * Sets model for this menu. * - * @param model DOCUMENT ME! + * @param model model to set */ public void setModel(ButtonModel model) { @@ -293,29 +324,32 @@ public class JMenu extends JMenuItem implements Accessible, MenuElement } /** - * DOCUMENT ME! + * Returns true if the menu is selected and false otherwise * - * @return DOCUMENT ME! + * @return true if the menu is selected and false otherwise */ public boolean isSelected() { - return super.isSelected(); + return super.isArmed(); } /** - * DOCUMENT ME! + * Changes this menu selected state if selected is true and false otherwise + * This method fires menuEvents to model's registered listeners. * - * @param selected DOCUMENT ME! + * @param selected true if the menu should be selected and false otherwise */ public void setSelected(boolean selected) { - super.setSelected(selected); + super.setArmed(true); + fireMenuSelected(); } /** - * DOCUMENT ME! + * Checks if PopupMenu associated with this menu is visible * - * @return DOCUMENT ME! + * @return true if the popup associated with this menu is currently visible on the screen and + * false otherwise. */ public boolean isPopupMenuVisible() { @@ -323,20 +357,20 @@ public class JMenu extends JMenuItem implements Accessible, MenuElement } /** - * DOCUMENT ME! + * Sets popup menu visibility * - * @param popup DOCUMENT ME! + * @param popup true if popup should be visible and false otherwise */ public void setPopupMenuVisible(boolean popup) { - if (isEnabled()) + if (getModel().isEnabled()) popupMenu.setVisible(popup); } /** - * DOCUMENT ME! + * Returns origin point of the popup menu * - * @return DOCUMENT ME! + * @return Point containing */ protected Point getPopupMenuOrigin() { @@ -349,9 +383,11 @@ public class JMenu extends JMenuItem implements Accessible, MenuElement } /** - * DOCUMENT ME! + * Returns delay property. * - * @return DOCUMENT ME! + * @return delay property, indicating number of milliseconds before + * popup menu associated with the menu appears or disappears after + * menu was selected or deselected respectively */ public int getDelay() { @@ -359,75 +395,90 @@ public class JMenu extends JMenuItem implements Accessible, MenuElement } /** - * DOCUMENT ME! + * Sets delay property for this menu. If given time for the delay + * property is negative, then IllegalArgumentException is thrown * - * @param delay DOCUMENT ME! + * @param delay number of milliseconds before + * popup menu associated with the menu appears or disappears after + * menu was selected or deselected respectively */ public void setDelay(int delay) { + if (delay < 0) + throw new IllegalArgumentException("delay less than 0"); this.delay = delay; } /** - * DOCUMENT ME! + * Sets location at which popup menu should be displayed + * The location given is relative to this menu item * - * @param x DOCUMENT ME! - * @param y DOCUMENT ME! + * @param x x-coordinate of the menu location + * @param y y-coordinate of the menu location */ public void setMenuLocation(int x, int y) { - popupMenu.setLocation(x, y); + menuLocation = new Point(x, y); } /** - * DOCUMENT ME! + * Creates and returns JMenuItem associated with the given action * - * @param action DOCUMENT ME! + * @param action Action to use for creation of JMenuItem * - * @return DOCUMENT ME! + * @return JMenuItem that was creted with given action */ protected JMenuItem createActionComponent(Action action) { - return null; + return new JMenuItem(action); } /** - * DOCUMENT ME! + * Creates ActionChangeListener to listen for PropertyChangeEvents occuring + * in the action that is associated with this menu * - * @param item DOCUMENT ME! + * @param item menu that contains action to listen to * - * @return DOCUMENT ME! + * @return The PropertyChangeListener */ protected PropertyChangeListener createActionChangeListener(JMenuItem item) { - return null; + return new ActionChangedListener(item); } /** - * DOCUMENT ME! + * Adds separator to the end of the menu items in the menu. */ public void addSeparator() { + getPopupMenu().addSeparator(); } /** - * DOCUMENT ME! + * Inserts separator in the menu at the specified index. * - * @param index DOCUMENT ME! + * @param index Index at which separator should be inserted */ public void insertSeparator(int index) { + if (index < 0) + throw new IllegalArgumentException("index less than 0"); + + getPopupMenu().insert(new JPopupMenu.Separator(), index); } /** - * DOCUMENT ME! + * Returns menu item located at the specified index in the menu * - * @param index DOCUMENT ME! + * @param index Index at which to look for the menu item * - * @return DOCUMENT ME! + * @return menu item located at the specified index in the menu */ public JMenuItem getItem(int index) { + if (index < 0) + throw new IllegalArgumentException("index less than 0"); + Component c = popupMenu.getComponentAtIndex(index); if (c instanceof JMenuItem) @@ -437,29 +488,32 @@ public class JMenu extends JMenuItem implements Accessible, MenuElement } /** - * DOCUMENT ME! + * Returns number of items in the menu * - * @return DOCUMENT ME! + * @return number of items in the menu */ public int getItemCount() { - return 0; + // returns the number of items on + // the menu, including separators. + return getComponents().length; } /** - * DOCUMENT ME! + * Checks if this menu is a tear-off menu. * - * @return DOCUMENT ME! + * @return true if this menu is a tear-off menu and false otherwise */ public boolean isTearOff() { + // NOT YET IMPLEMENTED return false; } /** - * DOCUMENT ME! + * Returns number of menu components in this menu * - * @return DOCUMENT ME! + * @return number of menu components in this menu */ public int getMenuComponentCount() { @@ -467,11 +521,12 @@ public class JMenu extends JMenuItem implements Accessible, MenuElement } /** - * DOCUMENT ME! + * Returns menu component located at the givent index + * in the menu * - * @param index DOCUMENT ME! + * @param index index at which to get the menu component in the menu * - * @return DOCUMENT ME! + * @return Menu Component located in the menu at the specified index */ public Component getMenuComponent(int index) { @@ -479,9 +534,9 @@ public class JMenu extends JMenuItem implements Accessible, MenuElement } /** - * DOCUMENT ME! + * Return components belonging to this menu * - * @return DOCUMENT ME! + * @return components belonging to this menu */ public Component[] getMenuComponents() { @@ -489,9 +544,11 @@ public class JMenu extends JMenuItem implements Accessible, MenuElement } /** - * DOCUMENT ME! + * Checks if this menu is a top level menu. The menu is top + * level menu if it is inside the menu bar. While if the menu + * inside some other menu, it is considered to be a pull-right menu. * - * @return DOCUMENT ME! + * @return true if this menu is top level menu, and false otherwise */ public boolean isTopLevelMenu() { @@ -502,11 +559,12 @@ public class JMenu extends JMenuItem implements Accessible, MenuElement } /** - * DOCUMENT ME! + * Checks if given component exists in this menu. The submenus of + * this menu are checked as well * - * @param component DOCUMENT ME! + * @param component Component to look for * - * @return DOCUMENT ME! + * @return true if the given component exists in this menu, and false otherwise */ public boolean isMenuComponent(Component component) { @@ -514,9 +572,9 @@ public class JMenu extends JMenuItem implements Accessible, MenuElement } /** - * DOCUMENT ME! + * Returns popup menu associated with the menu. * - * @return DOCUMENT ME! + * @return popup menu associated with the menu. */ public JPopupMenu getPopupMenu() { @@ -524,9 +582,9 @@ public class JMenu extends JMenuItem implements Accessible, MenuElement } /** - * DOCUMENT ME! + * Adds MenuListener to the menu * - * @param listener DOCUMENT ME! + * @param listener MenuListener to add */ public void addMenuListener(MenuListener listener) { @@ -534,9 +592,9 @@ public class JMenu extends JMenuItem implements Accessible, MenuElement } /** - * DOCUMENT ME! + * Removes MenuListener from the menu * - * @param listener DOCUMENT ME! + * @param listener MenuListener to remove */ public void removeMenuListener(MenuListener listener) { @@ -544,73 +602,114 @@ public class JMenu extends JMenuItem implements Accessible, MenuElement } /** - * DOCUMENT ME! + * This method fires MenuEvents to all menu's MenuListeners. In this case + * menuSelected() method of MenuListeners is called to indicated that the menu + * was selected. */ protected void fireMenuSelected() { EventListener[] ll = listenerList.getListeners(MenuListener.class); for (int i = 0; i < ll.length; i++) - ((MenuListener) ll[i]).menuSelected(new MenuEvent(this)); + ((MenuListener) ll[i]).menuSelected(menuEvent); } /** - * DOCUMENT ME! + * This method fires MenuEvents to all menu's MenuListeners. In this case + * menuDeselected() method of MenuListeners is called to indicated that the menu + * was deselected. */ protected void fireMenuDeselected() { EventListener[] ll = listenerList.getListeners(MenuListener.class); for (int i = 0; i < ll.length; i++) - ((MenuListener) ll[i]).menuDeselected(new MenuEvent(this)); + ((MenuListener) ll[i]).menuDeselected(menuEvent); } /** - * DOCUMENT ME! + * This method fires MenuEvents to all menu's MenuListeners. In this case + * menuSelected() method of MenuListeners is called to indicated that the menu + * was cancelled. The menu is cancelled when it's popup menu is close without selection. */ protected void fireMenuCanceled() { EventListener[] ll = listenerList.getListeners(MenuListener.class); for (int i = 0; i < ll.length; i++) - ((MenuListener) ll[i]).menuCanceled(new MenuEvent(this)); + ((MenuListener) ll[i]).menuCanceled(menuEvent); } /** - * DOCUMENT ME! + * Creates MenuChangeListener to listen to change events occuring + * in the model * - * @return DOCUMENT ME! + * @return ChangeListener */ private ChangeListener createMenuChangeListener() { - return null; + return new MenuChangeListener(); } /** - * DOCUMENT ME! + * Creates WinListener that listens to the menu;s popup menu. * - * @param popup DOCUMENT ME! + * @param popup JPopupMenu to listen to * - * @return DOCUMENT ME! + * @return The WinListener */ - protected JMenu.WinListener createWinListener(JPopupMenu popup) + protected WinListener createWinListener(JPopupMenu popup) { - return null; + return new WinListener(popup); } /** - * DOCUMENT ME! + * Method of the MenuElementInterface. It reacts to the selection + * changes in the menu. If this menu was selected, then it + * displayes popup menu associated with it and if this menu was + * deselected it hides the popup menu. * - * @param changed DOCUMENT ME! + * @param changed true if the menu was selected and false otherwise */ public void menuSelectionChanged(boolean changed) { + // if this menu selection is true, then activate this menu and + // display popup associated with this menu + if (changed) + { + setArmed(true); + fireMenuSelected(); + + int x = 0; + int y = 0; + if (menuLocation == null) + { + // Calculate correct position of the popup. Note that location of the popup + // passed to show() should be relative to the popup's invoker + if (isTopLevelMenu()) + y = this.getHeight(); + else + x = this.getWidth(); + + getPopupMenu().show(this, x, y); + } + else + getPopupMenu().show(this, menuLocation.x, menuLocation.y); + } + + else + { + fireMenuDeselected(); + popupMenu.setVisible(false); + setArmed(false); + } } /** - * DOCUMENT ME! + * Method of MenuElement interface. Returns sub components of + * this menu. * - * @return DOCUMENT ME! + * @return array containing popupMenu that is associated with this menu */ public MenuElement[] getSubElements() { @@ -618,9 +717,7 @@ public class JMenu extends JMenuItem implements Accessible, MenuElement } /** - * DOCUMENT ME! - * - * @return DOCUMENT ME! + * @return Returns reference to itself */ public Component getComponent() { @@ -628,205 +725,174 @@ public class JMenu extends JMenuItem implements Accessible, MenuElement } /** - * DOCUMENT ME! + * This method is overriden with empty implementation, s.t the + * accelerator couldn't be set for the menu. The mnemonic should + * be used for the menu instead. * - * @param keystroke DOCUMENT ME! + * @param keystroke accelerator for this menu */ public void setAccelerator(KeyStroke keystroke) { - super.setAccelerator(keystroke); + throw new Error("setAccelerator() is not defined for JMenu. Use setMnemonic() instead."); } /** - * DOCUMENT ME! + * This method process KeyEvent occuring when the menu is visible * - * @param event DOCUMENT ME! + * @param event The KeyEvent */ protected void processKeyEvent(KeyEvent event) { } /** - * DOCUMENT ME! + * Programatically performs click * - * @param time DOCUMENT ME! + * @param time Number of milliseconds for which this menu stays pressed */ public void doClick(int time) { + getModel().setArmed(true); + getModel().setPressed(true); + try + { + java.lang.Thread.sleep(time); + } + catch (java.lang.InterruptedException e) + { + // probably harmless + } + + getModel().setPressed(false); + getModel().setArmed(false); + popupMenu.show(this, this.getWidth(), 0); } /** - * DOCUMENT ME! + * A string that describes this JMenu. Normally only used + * for debugging. * - * @return DOCUMENT ME! + * @return A string describing this JMenu */ protected String paramString() { return "JMenu"; } - /** - * DOCUMENT ME! - * - * @return DOCUMENT ME! - */ public AccessibleContext getAccessibleContext() { if (accessibleContext == null) - accessibleContext = new AccessibleJMenu(this); + accessibleContext = new AccessibleJMenu(); return accessibleContext; } - /** - * DOCUMENT ME! - */ protected class AccessibleJMenu extends AccessibleJMenuItem implements AccessibleSelection { - /** - * Creates a new AccessibleJMenu object. - * - * @param component DOCUMENT ME! - */ - protected AccessibleJMenu(JMenu component) + protected AccessibleJMenu() { - super(component); } - /** - * DOCUMENT ME! - * - * @return DOCUMENT ME! - */ public int getAccessibleChildrenCount() { return 0; } - /** - * DOCUMENT ME! - * - * @param value0 DOCUMENT ME! - * - * @return DOCUMENT ME! - */ public Accessible getAccessibleChild(int value0) { return null; } - /** - * DOCUMENT ME! - * - * @return DOCUMENT ME! - */ public AccessibleSelection getAccessibleSelection() { return null; } - /** - * DOCUMENT ME! - * - * @param value0 DOCUMENT ME! - * - * @return DOCUMENT ME! - */ public Accessible getAccessibleSelection(int value0) { return null; } - /** - * DOCUMENT ME! - * - * @param value0 DOCUMENT ME! - * - * @return DOCUMENT ME! - */ public boolean isAccessibleChildSelected(int value0) { return false; } - /** - * DOCUMENT ME! - * - * @return DOCUMENT ME! - */ public AccessibleRole getAccessibleRole() { return AccessibleRole.MENU; } - /** - * DOCUMENT ME! - * - * @return DOCUMENT ME! - */ public int getAccessibleSelectionCount() { return 0; } - /** - * DOCUMENT ME! - * - * @param value0 DOCUMENT ME! - */ public void addAccessibleSelection(int value0) { } - /** - * DOCUMENT ME! - * - * @param value0 DOCUMENT ME! - */ public void removeAccessibleSelection(int value0) { } - /** - * DOCUMENT ME! - */ public void clearAccessibleSelection() { } - /** - * DOCUMENT ME! - */ public void selectAllAccessibleSelection() { } } - /** - * DOCUMENT ME! - */ protected class WinListener extends WindowAdapter implements Serializable { JPopupMenu popupMenu; + private static final long serialVersionUID = -6415815570638474823L; + + public WinListener(JPopupMenu popup) + { + } + + public void windowClosing(WindowEvent event) + { + } + } + + /** This class listens to ChangeEvent fired by menu's model*/ + protected class MenuChangeListener implements ChangeListener + { + /** This method is invoked when there is change in menu's model property */ + public void stateChanged(ChangeEvent e) + { + revalidate(); + repaint(); + } + } + + /** + * This class listens to PropertyChangeEvents occuring in menu's action + */ + protected class ActionChangedListener implements PropertyChangeListener + { + /** menu item associated with the action */ + private JMenuItem menuItem; - /** - * Creates a new WinListener object. - * - * @param value0 DOCUMENT ME! - * @param value1 DOCUMENT ME! - */ - public WinListener(JMenu value0, JPopupMenu value1) + /** Creates new ActionChangedListener and adds it to menuItem's action */ + public ActionChangedListener(JMenuItem menuItem) { + this.menuItem = menuItem; + + Action a = menuItem.getAction(); + if (a != null) + a.addPropertyChangeListener(this); } - /** - * DOCUMENT ME! - * - * @param value0 DOCUMENT ME! - */ - public void windowClosing(WindowEvent value0) + /**This method is invoked when some change occures in menuItem's action*/ + public void propertyChange(PropertyChangeEvent evt) { + // FIXME: Need to implement } } } diff --git a/libjava/javax/swing/JMenuBar.java b/libjava/javax/swing/JMenuBar.java index e65c1bfecea..c4edcd1f897 100644 --- a/libjava/javax/swing/JMenuBar.java +++ b/libjava/javax/swing/JMenuBar.java @@ -66,12 +66,25 @@ import javax.swing.plaf.MenuItemUI; /** - * DOCUMENT ME! + * JMenuBar */ public class JMenuBar extends JComponent implements Accessible, MenuElement { + /** Fired in a PropertyChangeEvent when the "borderPainted" property changes. */ + public static final String BORDER_PAINTED_CHANGED_PROPERTY = "borderPainted"; + + /** Fired in a PropertyChangeEvent when the "model" changes. */ + public static final String MODEL_CHANGED_PROPERTY = "model"; + + private static final long serialVersionUID = -8191026883931977036L; + + /** JMenuBar's model. It keeps track of selected menu's index */ private transient SingleSelectionModel selectionModel; - private boolean paintBorder; + + /* borderPainted property indicating if the menuBar's border will be painted*/ + private boolean borderPainted; + + /* margin between menu bar's border and its menues*/ private Insets margin; /** @@ -80,16 +93,16 @@ public class JMenuBar extends JComponent implements Accessible, MenuElement public JMenuBar() { selectionModel = new DefaultSingleSelectionModel(); - paintBorder = true; + borderPainted = true; updateUI(); } /** - * DOCUMENT ME! + * Adds menu to the menu bar * - * @param c DOCUMENT ME! + * @param c menu to add * - * @return DOCUMENT ME! + * @return reference to the added menu */ public JMenu add(JMenu c) { @@ -107,20 +120,15 @@ public class JMenuBar extends JComponent implements Accessible, MenuElement super.addNotify(); } - /** - * DOCUMENT ME! - * - * @return DOCUMENT ME! - */ public AccessibleContext getAccessibleContext() { return null; } /** - * DOCUMENT ME! + * Returns reference to this menu bar * - * @return DOCUMENT ME! + * @return reference to this menu bar */ public Component getComponent() { @@ -128,23 +136,26 @@ public class JMenuBar extends JComponent implements Accessible, MenuElement } /** - * DOCUMENT ME! + * Returns component at the specified index. * - * @param i DOCUMENT ME! + * @param i index of the component to get * - * @return DOCUMENT ME! + * @return component at the specified index. Null is returned if + * component at the specified index doesn't exist. + * @deprecated Replaced by getComponent(int) */ public Component getComponentAtIndex(int i) { - return getComponentAt(i); + return getComponent(i); } /** - * DOCUMENT ME! + * Returns index of the specified component * - * @param c DOCUMENT ME! + * @param c Component to search for * - * @return DOCUMENT ME! + * @return index of the specified component. -1 is returned if + * specified component doesnt' exist in the menu bar. */ public int getComponentIndex(Component c) { @@ -175,9 +186,9 @@ public class JMenuBar extends JComponent implements Accessible, MenuElement } /** - * DOCUMENT ME! + * Returns margin betweeen menu bar's border and its menues * - * @return DOCUMENT ME! + * @return margin between menu bar's border and its menues */ public Insets getMargin() { @@ -188,11 +199,13 @@ public class JMenuBar extends JComponent implements Accessible, MenuElement } /** - * DOCUMENT ME! + * Return menu at the specified index. If component at the + * specified index is not a menu, then null is returned. * - * @param index DOCUMENT ME! + * @param index index to look for the menu * - * @return DOCUMENT ME! + * @return menu at specified index, or null if menu doesn't exist + * at the specified index. */ public JMenu getMenu(int index) { @@ -213,9 +226,9 @@ public class JMenuBar extends JComponent implements Accessible, MenuElement } /** - * DOCUMENT ME! + * Returns selection model for this menu bar. * - * @return DOCUMENT ME! + * @return selection mdoel for this menu bar. */ public SingleSelectionModel getSelectionModel() { @@ -223,9 +236,10 @@ public class JMenuBar extends JComponent implements Accessible, MenuElement } /** - * DOCUMENT ME! + * Method of MenuElement interface. It returns subcomponents + * of the menu bar, which are all the menues that it contains. * - * @return DOCUMENT ME! + * @return MenuElement[] array containing menues in this menu bar */ public MenuElement[] getSubElements() { @@ -238,19 +252,21 @@ public class JMenuBar extends JComponent implements Accessible, MenuElement } /** - * DOCUMENT ME! - * - * @return DOCUMENT ME! - */ + * Set the "UI" property of the menu bar, which is a look and feel class + * responsible for handling the menuBar's input events and painting it. + * + * @return The current "UI" property + */ public MenuBarUI getUI() { return (MenuBarUI) ui; } /** - * DOCUMENT ME! + * This method returns a name to identify which look and feel class will be + * the UI delegate for the menu bar. * - * @return DOCUMENT ME! + * @return The Look and Feel classID. "MenuItemUI" */ public String getUIClassID() { @@ -258,39 +274,31 @@ public class JMenuBar extends JComponent implements Accessible, MenuElement } /** - * DOCUMENT ME! + * Returns true if menu bar paints its border and false otherwise * - * @return DOCUMENT ME! + * @return true if menu bar paints its border and false otherwise */ public boolean isBorderPainted() { - return paintBorder; + return borderPainted; } /** - * DOCUMENT ME! + * Returns true if some menu in menu bar is selected. * - * @return DOCUMENT ME! - */ - public boolean isManagingFocus() - { - return true; - } - - /** - * DOCUMENT ME! - * - * @return DOCUMENT ME! + * @return true if some menu in menu bar is selected and false otherwise */ public boolean isSelected() { - return false; + return selectionModel.isSelected(); } /** - * DOCUMENT ME! + * This method does nothing by default. This method is need for the + * MenuElement interface to be implemented. * - * @param isIncluded DOCUMENT ME! + * @param isIncluded true if menuBar is included in the selection + * and false otherwise */ public void menuSelectionChanged(boolean isIncluded) { @@ -298,13 +306,14 @@ public class JMenuBar extends JComponent implements Accessible, MenuElement } /** - * DOCUMENT ME! + * Paints border of the menu bar, if its borderPainted property is set to + * true. * - * @param g DOCUMENT ME! + * @param g The graphics context with which to paint the border */ protected void paintBorder(Graphics g) { - if (paintBorder) + if (borderPainted) getBorder().paintBorder(this, g, 0, 0, getSize(null).width, getSize(null).height); } @@ -361,7 +370,14 @@ public class JMenuBar extends JComponent implements Accessible, MenuElement */ public void setBorderPainted(boolean b) { - paintBorder = b; + boolean old = borderPainted; + borderPainted = b; + if (b != old) + { + firePropertyChange(BORDER_PAINTED_CHANGED_PROPERTY, old, b); + revalidate(); + repaint(); + } } /** @@ -384,27 +400,42 @@ public class JMenuBar extends JComponent implements Accessible, MenuElement } /** - * DOCUMENT ME! + * Changes menu bar's selection to the specifies menu. + * This method updates selected index of menu bar's model, + * which results in a model firing change event. * - * @param sel DOCUMENT ME! + * @param sel menu to select */ public void setSelected(Component sel) { + int index = getComponentIndex(sel); + selectionModel.setSelectedIndex(index); } /** - * DOCUMENT ME! + * Sets menuBar's selection model to the one specified * - * @param model DOCUMENT ME! + * @param model SingleSelectionModel that needs to be set for this menu bar */ public void setSelectionModel(SingleSelectionModel model) { + selectionModel = model; + if (selectionModel != model) + { + SingleSelectionModel oldModel = selectionModel; + + selectionModel = model; + + firePropertyChange(MODEL_CHANGED_PROPERTY, oldModel, + this.selectionModel); + } } /** - * DOCUMENT ME! + * Set the "UI" property of the menu bar, which is a look and feel class + * responsible for handling menuBar's input events and painting it. * - * @param ui DOCUMENT ME! + * @param ui The new "UI" property */ public void setUI(MenuBarUI ui) { @@ -412,7 +443,8 @@ public class JMenuBar extends JComponent implements Accessible, MenuElement } /** - * DOCUMENT ME! + * Set the "UI" property to a class constructed, via the {@link + * UIManager}, from the current look and feel. */ public void updateUI() { diff --git a/libjava/javax/swing/JMenuItem.java b/libjava/javax/swing/JMenuItem.java index bc2ab344b02..65dfc3361fe 100644 --- a/libjava/javax/swing/JMenuItem.java +++ b/libjava/javax/swing/JMenuItem.java @@ -61,12 +61,26 @@ import javax.swing.plaf.MenuItemUI; /** - * DOCUMENT ME! + * <p> + * JMenuItem represents element in the menu. It inherits most of + * its functionality from AbstractButton, however its behavior somewhat + * varies from it. JMenuItem fire different kinds of events. + * PropertyChangeEvents are fired when menuItems properties are modified; + * ChangeEvents are fired when menuItem's state changes and actionEvents are + * fired when menu item is selected. In addition to this events menuItem also + * fire MenuDragMouseEvent and MenuKeyEvents when mouse is dragged over + * the menu item or associated key with menu item is invoked respectively. + * </p> */ public class JMenuItem extends AbstractButton implements Accessible, MenuElement { + private static final long serialVersionUID = -1681004643499461044L; + + /** name for the UI delegate for this menuItem. */ private static final String uiClassID = "MenuItemUI"; + + /** Combination of keyboard keys that can be used to activate this menu item */ private KeyStroke accelerator; /** @@ -74,44 +88,48 @@ public class JMenuItem extends AbstractButton implements Accessible, */ public JMenuItem() { - this(null, null); + super(null, null); } /** - * Creates a new JMenuItem object. + * Creates a new JMenuItem with the given icon. * - * @param icon DOCUMENT ME! + * @param icon Icon that will be displayed on the menu item */ public JMenuItem(Icon icon) { - this(null, icon); + // FIXME: The requestedFocusEnabled property should + // be set to false, when only icon is set for menu item. + super(null, icon); } /** - * Creates a new JMenuItem object. + * Creates a new JMenuItem with the given label. * - * @param text DOCUMENT ME! + * @param text label for the menu item */ public JMenuItem(String text) { - this(text, null); + super(text, null); } /** - * Creates a new JMenuItem object. + * Creates a new JMenuItem associated with the specified action. * - * @param action DOCUMENT ME! + * @param action action for this menu item */ public JMenuItem(Action action) { - // TODO + super(null, null); + super.setAction(action); } /** - * Creates a new JMenuItem object. + * Creates a new JMenuItem with specified text and icon. + * Text is displayed to the left of icon by default. * - * @param text DOCUMENT ME! - * @param icon DOCUMENT ME! + * @param text label for this menu item + * @param icon icon that will be displayed on this menu item */ public JMenuItem(String text, Icon icon) { @@ -121,8 +139,10 @@ public class JMenuItem extends AbstractButton implements Accessible, /** * Creates a new JMenuItem object. * - * @param text DOCUMENT ME! - * @param mnemonic DOCUMENT ME! + * @param text label for this menu item + * @param mnemonic - Single key that can be used with a + * look-and-feel meta key to activate this menu item. However + * menu item should be visible on the screen when mnemonic is used. */ public JMenuItem(String text, int mnemonic) { @@ -130,13 +150,17 @@ public class JMenuItem extends AbstractButton implements Accessible, setMnemonic(mnemonic); } - //------------------------------------------------------------- - // Methods ---------------------------------------------------- - //------------------------------------------------------------- + /** + * DOCUMENT ME! + * + * @param stream DOCUMENT ME! + * + * @throws IOException DOCUMENT ME! + * @throws ClassNotFoundException DOCUMENT ME! + */ private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { - // TODO } /** @@ -148,24 +172,31 @@ public class JMenuItem extends AbstractButton implements Accessible, */ private void writeObject(ObjectOutputStream stream) throws IOException { - // TODO } /** - * DOCUMENT ME! + * Initializes this menu item * - * @param text DOCUMENT ME! - * @param icon DOCUMENT ME! + * @param text label for this menu item + * @param icon icon to be displayed for this menu item */ protected void init(String text, Icon icon) { - // TODO + super.init(text, icon); + + // Initializes properties for this menu item, that are different + // from Abstract button properties. + paint_border = false; + paint_focus = false; + hori_align = JButton.LEFT; + hori_text_pos = JButton.LEFT; } /** - * DOCUMENT ME! + * Set the "UI" property of the menu item, which is a look and feel class + * responsible for handling menuItem's input events and painting it. * - * @param ui DOCUMENT ME! + * @param ui The new "UI" property */ public void setUI(MenuItemUI ui) { @@ -173,7 +204,8 @@ public class JMenuItem extends AbstractButton implements Accessible, } /** - * DOCUMENT ME! + * This method sets this menuItem's UI to the UIManager's default for the + * current look and feel. */ public void updateUI() { @@ -183,9 +215,10 @@ public class JMenuItem extends AbstractButton implements Accessible, } /** - * DOCUMENT ME! + * This method returns a name to identify which look and feel class will be + * the UI delegate for the menuItem. * - * @return $returnType$ DOCUMENT ME! + * @return The Look and Feel classID. "MenuItemUI" */ public String getUIClassID() { @@ -193,9 +226,10 @@ public class JMenuItem extends AbstractButton implements Accessible, } /** - * DOCUMENT ME! + * Returns true if button's model is armed and false otherwise. The + * button model is armed if menu item has focus or it is selected. * - * @return $returnType$ DOCUMENT ME! + * @return $boolean$ true if button's model is armed and false otherwise */ public boolean isArmed() { @@ -203,7 +237,7 @@ public class JMenuItem extends AbstractButton implements Accessible, } /** - * DOCUMENT ME! + * Sets menuItem's "ARMED" property * * @param armed DOCUMENT ME! */ @@ -213,19 +247,20 @@ public class JMenuItem extends AbstractButton implements Accessible, } /** - * DOCUMENT ME! + * Enable or disable menu item. When menu item is disabled, + * its text and icon are grayed out if they exist. * - * @param enabled DOCUMENT ME! + * @param enabled if true enable menu item, and disable otherwise. */ public void setEnabled(boolean enabled) { - setEnabled(enabled); + super.setEnabled(enabled); } /** - * DOCUMENT ME! + * Return accelerator for this menu item. * - * @return $returnType$ DOCUMENT ME! + * @return $KeyStroke$ accelerator for this menu item. */ public KeyStroke getAccelerator() { @@ -233,9 +268,9 @@ public class JMenuItem extends AbstractButton implements Accessible, } /** - * DOCUMENT ME! + * Sets accelerator for this menu item. * - * @param keystroke DOCUMENT ME! + * @param keystroke accelerator for this menu item. */ public void setAccelerator(KeyStroke keystroke) { @@ -243,9 +278,11 @@ public class JMenuItem extends AbstractButton implements Accessible, } /** - * DOCUMENT ME! + * Configures menu items' properties from properties of the specified action. + * This method overrides configurePropertiesFromAction from AbstractButton + * to also set accelerator property. * - * @param action DOCUMENT ME! + * @param action action to configure properties from */ protected void configurePropertiesFromAction(Action action) { @@ -258,11 +295,13 @@ public class JMenuItem extends AbstractButton implements Accessible, } /** - * DOCUMENT ME! + * Creates PropertyChangeListener to listen for the changes in action + * properties. * - * @param action DOCUMENT ME! + * @param action action to listen to for property changes * - * @return $returnType$ DOCUMENT ME! + * @return $PropertyChangeListener$ Listener that listens to changes in + * action properties. */ protected PropertyChangeListener createActionPropertyChangeListener(Action action) { @@ -277,11 +316,11 @@ public class JMenuItem extends AbstractButton implements Accessible, } /** - * DOCUMENT ME! + * Process mouse events forwarded from MenuSelectionManager. * - * @param event DOCUMENT ME! - * @param path DOCUMENT ME! - * @param manager DOCUMENT ME! + * @param event event forwarded from MenuSelectionManager + * @param path path to the menu element from which event was generated + * @param manager MenuSelectionManager for the current menu hierarchy */ public void processMouseEvent(MouseEvent event, MenuElement[] path, MenuSelectionManager manager) @@ -289,22 +328,15 @@ public class JMenuItem extends AbstractButton implements Accessible, switch (event.getID()) { case MouseEvent.MOUSE_CLICKED: - doClick(); break; case MouseEvent.MOUSE_ENTERED: if (event.getSource() instanceof JMenuItem) { JMenuItem item = (JMenuItem) event.getSource(); - ButtonModel model = item.getModel(); + ButtonModel model = item.getModel(); if (item.isRolloverEnabled()) model.setRollover(true); - - if (model.isPressed() - && (event.getModifiers() & InputEvent.BUTTON1_MASK) != 0) - model.setArmed(true); - else - model.setArmed(false); } break; case MouseEvent.MOUSE_EXITED: @@ -314,7 +346,6 @@ public class JMenuItem extends AbstractButton implements Accessible, ButtonModel model = item.getModel(); if (item.isRolloverEnabled()) model.setRollover(false); - model.setArmed(false); } break; case MouseEvent.MOUSE_PRESSED: @@ -328,17 +359,6 @@ public class JMenuItem extends AbstractButton implements Accessible, } break; case MouseEvent.MOUSE_RELEASED: - if (event.getSource() instanceof JMenuItem) - { - JMenuItem item = (JMenuItem) event.getSource(); - ButtonModel model = item.getModel(); - if ((event.getModifiers() & InputEvent.BUTTON1_MASK) != 0) - { - model.setPressed(false); - model.setArmed(false); - manager.clearSelectedPath(); - } - } break; case MouseEvent.MOUSE_MOVED: break; @@ -372,9 +392,11 @@ public class JMenuItem extends AbstractButton implements Accessible, } /** - * DOCUMENT ME! + * This method fires MenuDragMouseEvents to registered listeners. + * Different types of MenuDragMouseEvents are fired depending + * on the observed mouse event. * - * @param event DOCUMENT ME! + * @param event Mouse */ public void processMenuDragMouseEvent(MenuDragMouseEvent event) { @@ -396,7 +418,9 @@ public class JMenuItem extends AbstractButton implements Accessible, } /** - * DOCUMENT ME! + * This method fires MenuKeyEvent to registered listeners. + * Different types of MenuKeyEvents are fired depending + * on the observed key event. * * @param event DOCUMENT ME! */ @@ -406,9 +430,9 @@ public class JMenuItem extends AbstractButton implements Accessible, } /** - * DOCUMENT ME! + * Fires MenuDragMouseEvent to all of the menuItem's MouseInputListeners. * - * @param event DOCUMENT ME! + * @param event The event signifying that mouse entered menuItem while it was dragged */ protected void fireMenuDragMouseEntered(MenuDragMouseEvent event) { @@ -419,9 +443,9 @@ public class JMenuItem extends AbstractButton implements Accessible, } /** - * DOCUMENT ME! + * Fires MenuDragMouseEvent to all of the menuItem's MouseInputListeners. * - * @param event DOCUMENT ME! + * @param event The event signifying that mouse has exited menu item, while it was dragged */ protected void fireMenuDragMouseExited(MenuDragMouseEvent event) { @@ -432,9 +456,9 @@ public class JMenuItem extends AbstractButton implements Accessible, } /** - * DOCUMENT ME! + * Fires MenuDragMouseEvent to all of the menuItem's MouseInputListeners. * - * @param event DOCUMENT ME! + * @param event The event signifying that mouse is being dragged over the menuItem */ protected void fireMenuDragMouseDragged(MenuDragMouseEvent event) { @@ -445,9 +469,9 @@ public class JMenuItem extends AbstractButton implements Accessible, } /** - * DOCUMENT ME! + * This method fires a MenuDragMouseEvent to all the MenuItem's MouseInputListeners. * - * @param event DOCUMENT ME! + * @param event The event signifying that mouse was released while it was dragged over the menuItem */ protected void fireMenuDragMouseReleased(MenuDragMouseEvent event) { @@ -458,50 +482,70 @@ public class JMenuItem extends AbstractButton implements Accessible, } /** - * DOCUMENT ME! + * This method fires a MenuKeyEvent to all the MenuItem's MenuKeyListeners. * - * @param event DOCUMENT ME! + * @param event The event signifying that key associated with this menu was pressed */ protected void fireMenuKeyPressed(MenuKeyEvent event) { - // TODO + EventListener[] ll = listenerList.getListeners(MenuKeyListener.class); + + for (int i = 0; i < ll.length; i++) + ((MenuKeyListener) ll[i]).menuKeyPressed(event); } /** - * DOCUMENT ME! + * This method fires a MenuKeyEvent to all the MenuItem's MenuKeyListeners. * - * @param event DOCUMENT ME! + * @param event The event signifying that key associated with this menu was released */ protected void fireMenuKeyReleased(MenuKeyEvent event) { - // TODO + EventListener[] ll = listenerList.getListeners(MenuKeyListener.class); + + for (int i = 0; i < ll.length; i++) + ((MenuKeyListener) ll[i]).menuKeyTyped(event); } /** - * DOCUMENT ME! + * This method fires a MenuKeyEvent to all the MenuItem's MenuKeyListeners. * - * @param event DOCUMENT ME! + * @param event The event signifying that key associated with this menu was typed. + * The key is typed when it was pressed and then released */ protected void fireMenuKeyTyped(MenuKeyEvent event) { - // TODO + EventListener[] ll = listenerList.getListeners(MenuKeyListener.class); + + for (int i = 0; i < ll.length; i++) + ((MenuKeyListener) ll[i]).menuKeyTyped(event); } /** - * DOCUMENT ME! + * Method of the MenuElement interface. + * This method is invoked by MenuSelectionManager when selection of + * this menu item has changed. If this menu item was selected then + * arm it's model, and disarm the model otherwise. The menu item + * is considered to be selected, and thus highlighted when its model + * is armed. * - * @param changed DOCUMENT ME! + * @param changed indicates selection status of this menu item. If changed is + * true then menu item is selected and deselected otherwise. */ public void menuSelectionChanged(boolean changed) { if (changed) model.setArmed(true); + else + model.setArmed(false); } /** - * DOCUMENT ME! + * Method of the MenuElement interface. * - * @return $returnType$ DOCUMENT ME! + * @return $MenuElement[]$ Returns array of sub-components for this menu + * item. By default menuItem doesn't have any subcomponents and so + * empty array is returned instead. */ public MenuElement[] getSubElements() { @@ -509,9 +553,10 @@ public class JMenuItem extends AbstractButton implements Accessible, } /** - * DOCUMENT ME! + * Returns reference to the component that will paint this menu item. * - * @return $returnType$ DOCUMENT ME! + * @return $Component$ Component that will paint this menu item. + * Simply returns reference to this menu item. */ public Component getComponent() { @@ -519,9 +564,11 @@ public class JMenuItem extends AbstractButton implements Accessible, } /** - * DOCUMENT ME! + * Adds a MenuDragMouseListener to this menu item. When mouse + * is dragged over the menu item the MenuDragMouseEvents will be + * fired, and these listeners will be called. * - * @param listener DOCUMENT ME! + * @param listener The new listener to add */ public void addMenuDragMouseListener(MenuDragMouseListener listener) { @@ -529,9 +576,9 @@ public class JMenuItem extends AbstractButton implements Accessible, } /** - * DOCUMENT ME! + * Removes a MenuDragMouseListener from the menuItem's listener list. * - * @param listener DOCUMENT ME! + * @param listener The listener to remove */ public void removeMenuDragMouseListener(MenuDragMouseListener listener) { @@ -539,9 +586,10 @@ public class JMenuItem extends AbstractButton implements Accessible, } /** - * DOCUMENT ME! + * Adds an MenuKeyListener to this menu item. This listener will be + * invoked when MenuKeyEvents will be fired by this menu item. * - * @param listener DOCUMENT ME! + * @param listener The new listener to add */ public void addMenuKeyListener(MenuKeyListener listener) { @@ -549,9 +597,9 @@ public class JMenuItem extends AbstractButton implements Accessible, } /** - * DOCUMENT ME! + * Removes an MenuKeyListener from the menuItem's listener list. * - * @param listener DOCUMENT ME! + * @param listener The listener to remove */ public void removeMenuKeyListener(MenuKeyListener listener) { @@ -559,9 +607,10 @@ public class JMenuItem extends AbstractButton implements Accessible, } /** - * DOCUMENT ME! + * A string that describes this JMenuItem. Normally only used + * for debugging. * - * @return $returnType$ DOCUMENT ME! + * @return A string describing this JMenuItem */ protected String paramString() { @@ -571,49 +620,33 @@ public class JMenuItem extends AbstractButton implements Accessible, /** * DOCUMENT ME! * - * @return $returnType$ DOCUMENT ME! + * @return DOCUMENT ME! */ public AccessibleContext getAccessibleContext() { if (accessibleContext == null) - accessibleContext = new AccessibleJMenuItem(this); + accessibleContext = new AccessibleJMenuItem(); return accessibleContext; } - /** - * DOCUMENT ME! - */ protected class AccessibleJMenuItem extends AccessibleAbstractButton implements ChangeListener { + private static final long serialVersionUID = 6748924232082076534L; + /** * Creates a new AccessibleJMenuItem object. - * - * @param component DOCUMENT ME! */ - AccessibleJMenuItem(JMenuItem component) + AccessibleJMenuItem() { - super(component); - - // TODO + //super(component); } - /** - * DOCUMENT ME! - * - * @param event DOCUMENT ME! - */ public void stateChanged(ChangeEvent event) { - // TODO } - /** - * DOCUMENT ME! - * - * @return $returnType$ DOCUMENT ME! - */ public AccessibleRole getAccessibleRole() { return AccessibleRole.MENU_ITEM; diff --git a/libjava/javax/swing/JOptionPane.java b/libjava/javax/swing/JOptionPane.java index decd02c9213..df45a1a4882 100644 --- a/libjava/javax/swing/JOptionPane.java +++ b/libjava/javax/swing/JOptionPane.java @@ -60,12 +60,13 @@ public class JOptionPane extends JComponent implements Accessible */ protected class AccessibleJOptionPane extends JComponent.AccessibleJComponent { + private static final long serialVersionUID = 686071432213084821L; + /** * Creates a new AccessibleJOptionPane object. */ protected AccessibleJOptionPane() { - super(JOptionPane.this); } /** @@ -79,6 +80,8 @@ public class JOptionPane extends JComponent implements Accessible } } + private static final long serialVersionUID = 5231143276678566796L; + /** The value returned when cancel option is selected. */ public static final int CANCEL_OPTION = 2; @@ -418,21 +421,7 @@ public class JOptionPane extends JComponent implements Accessible */ public static JDesktopPane getDesktopPaneForComponent(Component parentComponent) { - if (parentComponent == null) - return null; - if (parentComponent instanceof JDesktopPane) - return (JDesktopPane) parentComponent; - JDesktopPane parent = null; - while (parentComponent.getParent() != null) - { - parentComponent = parentComponent.getParent(); - if (parentComponent instanceof JDesktopPane) - { - parent = (JDesktopPane) parentComponent; - break; - } - } - return parent; + return (JDesktopPane) SwingUtilities.getAncestorOfClass(JDesktopPane.class, parentComponent); } /** @@ -445,21 +434,7 @@ public class JOptionPane extends JComponent implements Accessible */ public static Frame getFrameForComponent(Component parentComponent) { - if (parentComponent == null) - return null; - if (parentComponent instanceof Frame) - return (Frame) parentComponent; - Frame parent = null; - while (parentComponent.getParent() != null) - { - parentComponent = parentComponent.getParent(); - if (parentComponent instanceof Frame) - { - parent = (Frame) parentComponent; - break; - } - } - return parent; + return (Frame) SwingUtilities.getAncestorOfClass(Frame.class, parentComponent); } /** diff --git a/libjava/javax/swing/JPasswordField.java b/libjava/javax/swing/JPasswordField.java index a67f33caffb..b8c88055fc4 100644 --- a/libjava/javax/swing/JPasswordField.java +++ b/libjava/javax/swing/JPasswordField.java @@ -49,55 +49,31 @@ import javax.swing.text.Document; * @author Andrew Selkirk * @version 1.0 */ -public class JPasswordField extends JTextField { - - //------------------------------------------------------------- - // Classes ---------------------------------------------------- - //------------------------------------------------------------- - - /** - * AccessibleJPasswordField - */ - protected class AccessibleJPasswordField extends AccessibleJTextField { - - //------------------------------------------------------------- - // Variables -------------------------------------------------- - //------------------------------------------------------------- - - - //------------------------------------------------------------- - // Initialization --------------------------------------------- - //------------------------------------------------------------- - - /** - * Constructor AccessibleJPasswordField - * @param component TODO - */ - protected AccessibleJPasswordField(JPasswordField component) { - super(component); - // TODO - } // AccessibleJPasswordField() - - - //------------------------------------------------------------- - // Methods ---------------------------------------------------- - //------------------------------------------------------------- - - /** - * getAccessibleRole - * @returns AccessibleRole - */ - public AccessibleRole getAccessibleRole() { - return AccessibleRole.PASSWORD_TEXT; - } // getAccessibleRole() - - - } // AccessibleJPasswordField - - - //------------------------------------------------------------- - // Variables -------------------------------------------------- - //------------------------------------------------------------- +public class JPasswordField extends JTextField +{ + /** + * AccessibleJPasswordField + */ + protected class AccessibleJPasswordField extends AccessibleJTextField + { + private static final long serialVersionUID = -8477039424200681086L; + + /** + * Constructor AccessibleJPasswordField + */ + protected AccessibleJPasswordField() + { + } + + /** + * getAccessibleRole + * @return AccessibleRole + */ + public AccessibleRole getAccessibleRole() + { + return AccessibleRole.PASSWORD_TEXT; + } + } /** * uiClassID @@ -254,16 +230,15 @@ public class JPasswordField extends JTextField { return null; // TODO } // paramString() - /** - * getAccessibleContext - * @returns AccessibleContext - */ - public AccessibleContext getAccessibleContext() { - if (accessibleContext == null) { - accessibleContext = new AccessibleJPasswordField(this); - } // if - return accessibleContext; - } // getAccessibleContext() - - -} // JPasswordField + /** + * getAccessibleContext + * @return AccessibleContext + */ + public AccessibleContext getAccessibleContext() + { + if (accessibleContext == null) + accessibleContext = new AccessibleJPasswordField(); + + return accessibleContext; + } +} diff --git a/libjava/javax/swing/JPopupMenu.java b/libjava/javax/swing/JPopupMenu.java index 9f493038230..54a820c33ad 100644 --- a/libjava/javax/swing/JPopupMenu.java +++ b/libjava/javax/swing/JPopupMenu.java @@ -52,6 +52,7 @@ import java.awt.Point; import java.awt.Window; import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; +import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.io.IOException; import java.io.ObjectInputStream; @@ -71,19 +72,54 @@ import javax.swing.plaf.PopupMenuUI; */ public class JPopupMenu extends JComponent implements Accessible, MenuElement { + private static final long serialVersionUID = -8336996630009646009L; + + /** name for the UI delegate for this menuItem. */ private static final String uiClassID = "PopupMenuUI"; - private static final Object defaultLWPopupEnabledKey = null; - private static boolean defaultLWPopupEnabled = true; + + /* indicates if popup's menu border should be painted*/ + private boolean borderPainted = true; + + /** Flag indicating whether lightweight, mediumweight or heavyweight popup + is used to display menu items. + + These are the possible cases: + + 1. if DefaultLightWeightPopupEnabled true + (i) use lightweight container if popup feets inside top-level window + (ii) only use heavyweight container (JWindow) if popup doesn't fit. + + 2. if DefaultLightWeightPopupEnabled false + (i) if popup fits, use awt.Panel (mediumWeight) + (ii) if popup doesn't fit, use JWindow (heavyWeight) + */ + private static boolean DefaultLightWeightPopupEnabled = true; + + /* Component that invokes popup menu. */ transient Component invoker; - private int locationX; - private int locationY; + + /* Label for this popup menu */ private String label; - private boolean paintBorder; + + /*Amount of space between menuItem's in JPopupMenu and JPopupMenu's border */ private Insets margin; + + /** Indicates whether ligthWeight container can be used to display popup + menu. This flag is the same as DefaultLightWeightPopupEnabled, but setting + this flag can change popup menu after creation of the object */ private boolean lightWeightPopupEnabled; + + /** SelectionModel that keeps track of menu selection. */ private SingleSelectionModel selectionModel; + + /* Popup that is used to display JPopupMenu */ private transient Popup popup; - private Point location; + + /* Location of the popup */ + private Point popupLocation; + + /* Bound Property indicating visibility of the popup menu*/ + public static final String VISIBLE_CHANGED_PROPERTY = "visible"; /** * Creates a new JPopupMenu object. @@ -91,15 +127,17 @@ public class JPopupMenu extends JComponent implements Accessible, MenuElement public JPopupMenu() { updateUI(); - - lightWeightPopupEnabled = defaultLWPopupEnabled; + + lightWeightPopupEnabled = DefaultLightWeightPopupEnabled; selectionModel = new DefaultSingleSelectionModel(); + + super.setVisible(false); } /** - * Creates a new JPopupMenu object. + * Creates a new JPopupMenu with specified label * - * @param label DOCUMENT ME! + * @param label Label for popup menu. */ public JPopupMenu(String label) { @@ -131,11 +169,11 @@ public class JPopupMenu extends JComponent implements Accessible, MenuElement } /** - * DOCUMENT ME! + * Adds given menu item to the popup menu * - * @param item DOCUMENT ME! + * @param item menu item to add to the popup menu * - * @return DOCUMENT ME! + * @return menu item that was added to the popup menu */ public JMenuItem add(JMenuItem item) { @@ -144,11 +182,12 @@ public class JPopupMenu extends JComponent implements Accessible, MenuElement } /** - * DOCUMENT ME! + * Constructs menu item with a specified label and adds it to + * popup menu * - * @param text DOCUMENT ME! + * @param text label for the menu item to be added * - * @return DOCUMENT ME! + * @return constructed menu item that was added to the popup menu */ public JMenuItem add(String text) { @@ -157,22 +196,27 @@ public class JPopupMenu extends JComponent implements Accessible, MenuElement } /** - * DOCUMENT ME! + * Constructs menu item associated with the specified action + * and adds it to the popup menu * - * @param action DOCUMENT ME! + * @param action Action for the new menu item * - * @return DOCUMENT ME! + * @return menu item that was added to the menu */ public JMenuItem add(Action action) { JMenuItem item = new JMenuItem(action); + + if (action != null) + action.addPropertyChangeListener(createActionChangeListener(item)); + return add(item); } /** - * DOCUMENT ME! + * Revomes component at the given index from the menu. * - * @param index DOCUMENT ME! + * @param index index of the component that will be removed in the menu */ public void remove(int index) { @@ -192,10 +236,11 @@ public class JPopupMenu extends JComponent implements Accessible, MenuElement } /** - * DOCUMENT ME! + * Create menu item associated with the given action + * and inserts it into the popup menu at the specified index * - * @param action DOCUMENT ME! - * @param index DOCUMENT ME! + * @param action Action for the new menu item + * @param index index in the popup menu at which to insert new menu item. */ public void insert(Action action, int index) { @@ -204,10 +249,11 @@ public class JPopupMenu extends JComponent implements Accessible, MenuElement } /** - * DOCUMENT ME! + * Insert given component to the popup menu at the + * specified index * - * @param component DOCUMENT ME! - * @param index DOCUMENT ME! + * @param component Component to insert + * @param index Index at which to insert given component */ public void insert(Component component, int index) { @@ -215,10 +261,10 @@ public class JPopupMenu extends JComponent implements Accessible, MenuElement constraints.fill = GridBagConstraints.HORIZONTAL; constraints.weightx = 100.0; constraints.weighty = 100.0; - + if (index == -1) - index = getComponents().length; - + index = getComponents().length; + constraints.gridy = index; super.add(component, constraints, index); @@ -237,41 +283,45 @@ public class JPopupMenu extends JComponent implements Accessible, MenuElement } /** - * DOCUMENT ME! + * Paints popup menu's border if borderPainted is true * - * @param graphics DOCUMENT ME! + * @param graphics graphics context used to paint this popup's menu border. */ - protected void paintBorder(Graphics graphics) + protected void borderPainted(Graphics graphics) { - if (paintBorder) + if (borderPainted) getBorder().paintBorder(this, graphics, 0, 0, getSize(null).width, getSize(null).height); } /** - * DOCUMENT ME! + * Returns flag indicating if newly created JPopupMenu will use + * heavyweight or lightweight container to display its menu items * - * @return DOCUMENT ME! + * @return true if JPopupMenu will use lightweight container to display + * menu items by default, and false otherwise. */ public static boolean getDefaultLightWeightPopupEnabled() { - return defaultLWPopupEnabled; + return DefaultLightWeightPopupEnabled; } /** - * DOCUMENT ME! + * Sets whether JPopupMenu should use ligthWeight container to + * display it menu items by default * - * @param enabled DOCUMENT ME! + * @param enabled true if JPopupMenu should use lightweight container + * for displaying its menu items, and false otherwise. */ public static void setDefaultLightWeightPopupEnabled(boolean enabled) { - defaultLWPopupEnabled = enabled; + DefaultLightWeightPopupEnabled = enabled; } /** - * DOCUMENT ME! + * This method returns the UI used to display the JPopupMenu. * - * @return DOCUMENT ME! + * @return The UI used to display the JPopupMenu. */ public PopupMenuUI getUI() { @@ -279,9 +329,10 @@ public class JPopupMenu extends JComponent implements Accessible, MenuElement } /** - * DOCUMENT ME! + * Set the "UI" property of the menu item, which is a look and feel class + * responsible for handling popupMenu's input events and painting it. * - * @param ui DOCUMENT ME! + * @param ui The new "UI" property */ public void setUI(PopupMenuUI ui) { @@ -289,7 +340,8 @@ public class JPopupMenu extends JComponent implements Accessible, MenuElement } /** - * DOCUMENT ME! + * This method sets this menuItem's UI to the UIManager's default for the + * current look and feel. */ public void updateUI() { @@ -298,9 +350,10 @@ public class JPopupMenu extends JComponent implements Accessible, MenuElement } /** - * DOCUMENT ME! + * This method returns a name to identify which look and feel class will be + * the UI delegate for the menuItem. * - * @return DOCUMENT ME! + * @return The Look and Feel classID. "PopupMenuUI" */ public String getUIClassID() { @@ -308,9 +361,10 @@ public class JPopupMenu extends JComponent implements Accessible, MenuElement } /** - * DOCUMENT ME! + * Returns selectionModel used by this popup menu to keep + * track of the selection. * - * @return DOCUMENT ME! + * @return popup menu's selection model */ public SingleSelectionModel getSelectionModel() { @@ -318,9 +372,9 @@ public class JPopupMenu extends JComponent implements Accessible, MenuElement } /** - * DOCUMENT ME! + * Sets selection model for this popup menu * - * @param model DOCUMENT ME! + * @param model new selection model of this popup menu */ public void setSelectionModel(SingleSelectionModel model) { @@ -355,9 +409,11 @@ public class JPopupMenu extends JComponent implements Accessible, MenuElement } /** - * DOCUMENT ME! + * Returns true if this popup menu will display its menu item in + * a lightweight container and false otherwise. * - * @return DOCUMENT ME! + * @return true if this popup menu will display its menu items + * in a lightweight container and false otherwise. */ public boolean isLightWeightPopupEnabled() { @@ -375,9 +431,9 @@ public class JPopupMenu extends JComponent implements Accessible, MenuElement } /** - * DOCUMENT ME! + * Returns label for this popup menu * - * @return DOCUMENT ME! + * @return label for this popup menu */ public String getLabel() { @@ -385,9 +441,9 @@ public class JPopupMenu extends JComponent implements Accessible, MenuElement } /** - * DOCUMENT ME! + * Sets label for this popup menu * - * @param label DOCUMENT ME! + * @param label label for this popup menu */ public void setLabel(String label) { @@ -395,16 +451,19 @@ public class JPopupMenu extends JComponent implements Accessible, MenuElement } /** - * DOCUMENT ME! + * Adds separator to this popup menu */ public void addSeparator() { + // insert separator at the end of the list of menu items + this.insert(new Separator(), -1); } /** - * DOCUMENT ME! + * Adds popupMenuListener to listen for PopupMenuEvents fired + * by the JPopupMenu * - * @param listener DOCUMENT ME! + * @param listener PopupMenuListener to add to JPopupMenu */ public void addPopupMenuListener(PopupMenuListener listener) { @@ -412,9 +471,9 @@ public class JPopupMenu extends JComponent implements Accessible, MenuElement } /** - * DOCUMENT ME! + * Removes PopupMenuListener from JPopupMenu's list of listeners * - * @param listener DOCUMENT ME! + * @param listener PopupMenuListener which needs to be removed */ public void removePopupMenuListener(PopupMenuListener listener) { @@ -422,7 +481,19 @@ public class JPopupMenu extends JComponent implements Accessible, MenuElement } /** - * DOCUMENT ME! + * Returns array of PopupMenuListeners that are listening to JPopupMenu + * + * @return Array of PopupMenuListeners that are listening to JPopupMenu + */ + public PopupMenuListener[] getPopupMenuListeners() + { + return ((PopupMenuListener[]) listenerList.getListeners(PopupMenuListener.class)); + } + + /** + * This method calls popupMenuWillBecomeVisible() of popup menu's + * PopupMenuListeners. This method is invoked just before popup menu + * will appear on the screen. */ protected void firePopupMenuWillBecomeVisible() { @@ -433,7 +504,9 @@ public class JPopupMenu extends JComponent implements Accessible, MenuElement } /** - * DOCUMENT ME! + * This method calls popupMenuWillBecomeInvisible() of popup + * menu's PopupMenuListeners. This method is invoked just before popup + * menu will disappear from the screen */ protected void firePopupMenuWillBecomeInvisible() { @@ -444,7 +517,10 @@ public class JPopupMenu extends JComponent implements Accessible, MenuElement } /** - * DOCUMENT ME! + * This method calls popupMenuCanceled() of popup menu's PopupMenuListeners. + * This method is invoked just before popup menu is cancelled. This happens + * when popup menu is closed without selecting any of its menu items. This + * usually happens when the top-level window is resized or moved. */ protected void firePopupMenuCanceled() { @@ -455,16 +531,18 @@ public class JPopupMenu extends JComponent implements Accessible, MenuElement } /** - * DOCUMENT ME! + * This methods sets popup menu's size to its' preferred size. If the + * popup menu's size is previously set it will be ignored. */ public void pack() { + super.setSize(null); } /** - * DOCUMENT ME! + * Return visibility of the popup menu * - * @return DOCUMENT ME! + * @return true if popup menu is visible on the screen and false otherwise. */ public boolean isVisible() { @@ -472,90 +550,103 @@ public class JPopupMenu extends JComponent implements Accessible, MenuElement } /** - * DOCUMENT ME! + * Sets visibility property of this popup menu. If the property is + * set to true then popup menu will be dispayed and popup menu will + * hide itself if visible property is set to false. * - * @param visible DOCUMENT ME! + * @param visible true if popup menu will become visible and false otherwise. */ public void setVisible(boolean visible) { + boolean old = isVisible(); super.setVisible(visible); - - firePopupMenuWillBecomeVisible(); - - if (visible) + if (old != isVisible()) { - Container rootContainer = (Container) SwingUtilities.getRoot(invoker); + firePropertyChange(VISIBLE_CHANGED_PROPERTY, old, (boolean) isVisible()); + if (visible) + { + firePopupMenuWillBecomeVisible(); + Container rootContainer = (Container) SwingUtilities.getRoot(invoker); - boolean fit = true; - Dimension size; + boolean fit = true; + Dimension size; - // Determine the size of the popup menu - if (this.getSize().width == 0 && this.getSize().width == 0) - size = this.getPreferredSize(); + // 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. + if (rootContainer.contains(popupLocation)) + { + Insets insets = rootContainer.getInsets(); + popup.show(popupLocation.x - insets.left, + popupLocation.y - insets.top, size.width, + size.height); + } + + else + popup.show(popupLocation.x, popupLocation.y, size.width, + size.height); + } + } else - size = this.getSize(); + { + // popup menu was cancelled without selection + if (! getSelectionModel().isSelected()) + firePopupMenuCanceled(); - if ((size.width > (rootContainer.getWidth() - locationX)) - || (size.height > (rootContainer.getHeight() - locationY))) - fit = false; + firePopupMenuWillBecomeInvisible(); - if (lightWeightPopupEnabled && fit) - popup = new LightWeightPopup(this); - else - { - if (fit) - popup = new MediumWeightPopup(this); - else - popup = new HeavyWeightPopup(this); + popup.hide(); } - - if (popup instanceof LightWeightPopup - || popup instanceof MediumWeightPopup) - { - JLayeredPane layeredPane; - layeredPane = SwingUtilities.getRootPane(invoker).getLayeredPane(); - Point lp = layeredPane.getLocationOnScreen(); - Point r = SwingUtilities.getRoot(invoker).getLocationOnScreen(); - int px = locationX - (lp.x - r.x); - int py = locationY - (lp.y - r.y); - popup.show(px, py, size.width, size.height); - } - else - popup.show(locationX, locationY, size.width, size.height); - } - else - { - firePopupMenuWillBecomeInvisible(); - popup.hide(); } } /** - * DOCUMENT ME! + * Sets location of the popup menu. * - * @param x DOCUMENT ME! - * @param y DOCUMENT ME! + * @param x X coordinate of the popup menu's location + * @param y Y coordinate of the popup menu's location */ public void setLocation(int x, int y) { - locationX = x; - locationY = y; - } + if (popupLocation == null) + popupLocation = new Point(); - /** - * DOCUMENT ME! - * - * @return DOCUMENT ME! - */ - private boolean isPopupMenu() - { - return true; + popupLocation.x = x; + popupLocation.y = y; } /** - * DOCUMENT ME! + * Returns popup menu's invoker. * - * @return DOCUMENT ME! + * @return popup menu's invoker */ public Component getInvoker() { @@ -563,9 +654,9 @@ public class JPopupMenu extends JComponent implements Accessible, MenuElement } /** - * DOCUMENT ME! + * Sets popup menu's invoker. * - * @param component DOCUMENT ME! + * @param component The new invoker of this popup menu */ public void setInvoker(Component component) { @@ -573,43 +664,31 @@ public class JPopupMenu extends JComponent implements Accessible, MenuElement } /** - * DOCUMENT ME! + * This method displays JPopupMenu on the screen at the specified + * location. Note that x and y coordinates given to this method + * should be expressed in terms of the popup menus' invoker. * - * @param component DOCUMENT ME! - * @param x DOCUMENT ME! - * @param y DOCUMENT ME! + * @param component Invoker for this popup menu + * @param x x-coordinate of the popup menu relative to the specified invoker + * @param y y-coordiate of the popup menu relative to the specified invoker */ public void show(Component component, int x, int y) { setInvoker(component); - - Point rootOnScreen; - rootOnScreen = SwingUtilities.getRoot(invoker).getLocationOnScreen(); - Point invokerOnScreen = invoker.getLocationOnScreen(); - - int popupX = (invokerOnScreen.x - rootOnScreen.x) + x; - int popupY = (invokerOnScreen.y - rootOnScreen.y) + y; - - setLocation(popupX , popupY); + Point p = new Point(x, y); + SwingUtilities.convertPointToScreen(p, component); + setLocation(p.x, p.y); setVisible(true); } /** - * DOCUMENT ME! + * Returns component located at the specified index in the popup menu * - * @return DOCUMENT ME! - */ - JPopupMenu getRootPopupMenu() - { - return null; - } - - /** - * DOCUMENT ME! + * @param index index of the component to return * - * @param index DOCUMENT ME! + * @return component located at the specified index in the popup menu * - * @return DOCUMENT ME! + * @deprecated Replaced by getComponent(int) */ public Component getComponentAtIndex(int index) { @@ -617,11 +696,11 @@ public class JPopupMenu extends JComponent implements Accessible, MenuElement } /** - * DOCUMENT ME! + * Returns index of the specified component in the popup menu * - * @param component DOCUMENT ME! + * @param component Component to look for * - * @return DOCUMENT ME! + * @return index of the specified component in the popup menu */ public int getComponentIndex(Component component) { @@ -637,9 +716,9 @@ public class JPopupMenu extends JComponent implements Accessible, MenuElement } /** - * DOCUMENT ME! + * Sets size of the popup * - * @param size DOCUMENT ME! + * @param size Dimensions representing new size of the popup menu */ public void setPopupSize(Dimension size) { @@ -647,20 +726,20 @@ public class JPopupMenu extends JComponent implements Accessible, MenuElement } /** - * DOCUMENT ME! + * Sets size of the popup menu * - * @param x DOCUMENT ME! - * @param y DOCUMENT ME! + * @param width width for the new size + * @param height height for the new size */ - public void setPopupSize(int x, int y) + public void setPopupSize(int width, int height) { - super.setSize(x, y); + super.setSize(width, height); } /** - * DOCUMENT ME! + * Selects specified component in this popup menu. * - * @param selected DOCUMENT ME! + * @param selected component to select */ public void setSelected(Component selected) { @@ -669,29 +748,30 @@ public class JPopupMenu extends JComponent implements Accessible, MenuElement } /** - * DOCUMENT ME! + * Checks if this popup menu paints its border. * - * @return DOCUMENT ME! + * @return true if this popup menu paints its border and false otherwise. */ public boolean isBorderPainted() { - return paintBorder; + return borderPainted; } /** - * DOCUMENT ME! + * Sets if the border of the popup menu should be + * painter or not. * - * @param painted DOCUMENT ME! + * @param painted true if the border should be painted and false otherwise */ public void setBorderPainted(boolean painted) { - paintBorder = painted; + borderPainted = painted; } /** - * DOCUMENT ME! + * Returns margin for this popup menu. * - * @return DOCUMENT ME! + * @return margin for this popup menu. */ public Insets getMargin() { @@ -699,9 +779,10 @@ public class JPopupMenu extends JComponent implements Accessible, MenuElement } /** - * DOCUMENT ME! + * A string that describes this JPopupMenu. Normally only used + * for debugging. * - * @return DOCUMENT ME! + * @return A string describing this JMenuItem */ protected String paramString() { @@ -709,12 +790,12 @@ public class JPopupMenu extends JComponent implements Accessible, MenuElement } /** - * DOCUMENT ME! - * - * @param event DOCUMENT ME! - * @param path DOCUMENT ME! - * @param manager DOCUMENT ME! - */ + * Process mouse events forwarded from MenuSelectionManager. + * + * @param event event forwarded from MenuSelectionManager + * @param path path to the menu element from which event was generated + * @param manager MenuSelectionManager for the current menu hierarchy + */ public void processMouseEvent(MouseEvent event, MenuElement[] path, MenuSelectionManager manager) { @@ -733,18 +814,20 @@ public class JPopupMenu extends JComponent implements Accessible, MenuElement } /** - * DOCUMENT ME! + * Method of MenuElement Interface. It is invoked when + * popupMenu's selection has changed * - * @param changed DOCUMENT ME! + * @param changed true if this popupMenu is part of current menu + * hierarchy and false otherwise. */ public void menuSelectionChanged(boolean changed) { } /** - * DOCUMENT ME! + * Return subcomonents of this popup menu. * - * @return DOCUMENT ME! + * @return Array containing menuItem's of belonging to this popup menu. */ public MenuElement[] getSubElements() { @@ -758,9 +841,9 @@ public class JPopupMenu extends JComponent implements Accessible, MenuElement } /** - * DOCUMENT ME! + * Method of the MenuElement interface. Returns reference to itself. * - * @return DOCUMENT ME! + * @return Returns reference to itself */ public Component getComponent() { @@ -768,16 +851,16 @@ public class JPopupMenu extends JComponent implements Accessible, MenuElement } /** - * DOCUMENT ME! + * Checks if observing mouse event should trigger popup + * menu to show on the screen. * - * @param event DOCUMENT ME! + * @param event MouseEvent to check * - * @return DOCUMENT ME! + * @return true if the observing mouse event is popup trigger and false otherwise */ public boolean isPopupTrigger(MouseEvent event) { - return ((PopupMenuUI)getUI()).isPopupTrigger(event); - + return ((PopupMenuUI) getUI()).isPopupTrigger(event); } /** @@ -788,98 +871,103 @@ public class JPopupMenu extends JComponent implements Accessible, MenuElement public AccessibleContext getAccessibleContext() { if (accessibleContext == null) - accessibleContext = new AccessibleJPopupMenu(this); + accessibleContext = new AccessibleJPopupMenu(); return accessibleContext; } /** - * DOCUMENT ME! + * This interface is used to display menu items of the JPopupMenu */ private interface Popup { /** - * DOCUMENT ME! + * Displays container on the screen * - * @param x DOCUMENT ME! - * @param y DOCUMENT ME! - * @param width DOCUMENT ME! - * @param height DOCUMENT ME! + * @param x x-coordinate of popup menu's location on the screen + * @param y y-coordinate of popup menu's location on the screen + * @param width width of the container that is used to display menu + * item's for popup menu + * @param height height of the container that is used to display menu + * item's for popup menu */ void show(int x, int y, int width, int height); /** - * DOCUMENT ME! + * Hides container used to display popup menu item's from the screen */ void hide(); } /** - * DOCUMENT ME! + * This class represents Popup menu that uses light weight container + * to display its contents. */ - private class LightWeightPopup extends JPanel implements Popup + private class LightWeightPopup extends Container implements Popup { /** - * Creates a new LightWeightPopup object. + * Creates a new LightWeightPopup menu * - * @param c DOCUMENT ME! + * @param c Container containing menu items */ + private Component c; + public LightWeightPopup(Container c) { - this.add(c); + this.c = c; } /** - * DOCUMENT ME! + * Displayes lightweight container with menu items to the screen * - * @param x DOCUMENT ME! - * @param y DOCUMENT ME! - * @param width DOCUMENT ME! - * @param height DOCUMENT ME! + * @param x x-coordinate of lightweight container on the screen + * @param y y-coordinate of lightweight container on the screen + * @param width width of the lightweight container + * @param height height of the lightweight container */ public void show(int x, int y, int width, int height) { JLayeredPane layeredPane; layeredPane = SwingUtilities.getRootPane(invoker).getLayeredPane(); - this.setBounds(x, y, width, height); - layeredPane.add(this, JLayeredPane.POPUP_LAYER, 0); + c.setBounds(x, y, width, height); + layeredPane.add(c, JLayeredPane.POPUP_LAYER, 0); } /** - * DOCUMENT ME! + * Hides lightweight container from the screen */ public void hide() { JLayeredPane layeredPane; layeredPane = SwingUtilities.getRootPane(invoker).getLayeredPane(); - int index = layeredPane.getIndexOf(this); + int index = layeredPane.getIndexOf(c); layeredPane.remove(index); } } /** - * DOCUMENT ME! + * MediumWeightPopup is an AWT Panel with JPopupMenu's menu items. + * It is used to display JPopupMenu's menu items on the screen */ private class MediumWeightPopup extends Panel implements Popup { - /** * Creates a new MediumWeightPopup object. * - * @param c DOCUMENT ME! + * @param c Container with JPopupMenu's menu items */ public MediumWeightPopup(Container c) { - this.add(c); + this.add(c); } /** - * DOCUMENT ME! + * Displays AWT Panel with its components on the screen * - * @param x DOCUMENT ME! - * @param y DOCUMENT ME! - * @param width DOCUMENT ME! - * @param heigth DOCUMENT ME! + * @param x x-coordinate of the upper-left corner of the panel's + * @param y y-coordinate of the upper-left corner of the panel's + * @param width width of the panel + * @param height height of the panel */ public void show(int x, int y, int width, int height) { @@ -890,26 +978,27 @@ public class JPopupMenu extends JComponent implements Accessible, MenuElement } /** - * DOCUMENT ME! + * Hides This panel from the screen */ public void hide() { JLayeredPane layeredPane; - layeredPane = SwingUtilities.getRootPane(invoker).getLayeredPane(); + layeredPane = SwingUtilities.getRootPane(invoker).getLayeredPane(); int index = layeredPane.getIndexOf(this); layeredPane.remove(index); } } /** - * DOCUMENT ME! + * HeavyWeightPopup is JWindow that is used to display JPopupMenu menu item's + * on the screen */ private class HeavyWeightPopup extends JWindow implements Popup { /** * Creates a new HeavyWeightPopup object. * - * @param c DOCUMENT ME! + * @param c Container containing menu items */ public HeavyWeightPopup(Container c) { @@ -917,12 +1006,12 @@ public class JPopupMenu extends JComponent implements Accessible, MenuElement } /** - * DOCUMENT ME! + * Displays JWindow container JPopupMenu's menu items to the screen * - * @param x DOCUMENT ME! - * @param y DOCUMENT ME! - * @param width DOCUMENT ME! - * @param height DOCUMENT ME! + * @param x x-coordinate of JWindow containing menu items + * @param y y-coordinate of JWindow containing menu items + * @param width width of the JWindow + * @param height height of the JWindow */ public void show(int x, int y, int width, int height) { @@ -931,57 +1020,34 @@ public class JPopupMenu extends JComponent implements Accessible, MenuElement } /** - * DOCUMENT ME! + * Hides JWindow with menu item's from the screen. */ public void hide() { - this.hide(); + super.hide(); } } - /** - * DOCUMENT ME! - */ public static class Separator extends JSeparator { - /** - * Creates a new Separator object. - */ public Separator() { } - /** - * DOCUMENT ME! - * - * @return DOCUMENT ME! - */ public String getUIClassID() { - return null; + return "PopupMenuSeparatorUI"; } } - /** - * DOCUMENT ME! - */ protected class AccessibleJPopupMenu extends AccessibleJComponent { - /** - * Creates a new AccessibleJPopupMenu object. - * - * @param component DOCUMENT ME! - */ - protected AccessibleJPopupMenu(JPopupMenu component) + private static final long serialVersionUID = 7423261328879849768L; + + protected AccessibleJPopupMenu() { - super(component); } - /** - * DOCUMENT ME! - * - * @return DOCUMENT ME! - */ public AccessibleRole getAccessibleRole() { return AccessibleRole.POPUP_MENU; diff --git a/libjava/javax/swing/JProgressBar.java b/libjava/javax/swing/JProgressBar.java index 79c5102fbfd..3c4084724f2 100644 --- a/libjava/javax/swing/JProgressBar.java +++ b/libjava/javax/swing/JProgressBar.java @@ -85,14 +85,15 @@ public class JProgressBar extends JComponent implements SwingConstants, protected class AccessibleJProgressBar extends AccessibleJComponent implements AccessibleValue { + private static final long serialVersionUID = -2938130009392721813L; + /** * Constructor AccessibleJProgressBar * * @param component TODO */ - protected AccessibleJProgressBar(JProgressBar component) + protected AccessibleJProgressBar() { - super(component); } /** @@ -168,6 +169,8 @@ public class JProgressBar extends JComponent implements SwingConstants, } } + private static final long serialVersionUID = 1980046021813598781L; + /** Fired in a PropertyChangeEvent when the "borderPainted" property changes. */ public static final String BORDER_PAINTED_CHANGED_PROPERTY = "borderPainted"; @@ -661,7 +664,8 @@ public class JProgressBar extends JComponent implements SwingConstants, public AccessibleContext getAccessibleContext() { if (accessibleContext == null) - accessibleContext = new AccessibleJProgressBar(this); + accessibleContext = new AccessibleJProgressBar(); + return accessibleContext; } } diff --git a/libjava/javax/swing/JRadioButton.java b/libjava/javax/swing/JRadioButton.java index 0f657300027..0802ac09ba4 100644 --- a/libjava/javax/swing/JRadioButton.java +++ b/libjava/javax/swing/JRadioButton.java @@ -1,5 +1,5 @@ /* JRadioButton.java -- - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2004 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -42,6 +42,8 @@ import javax.accessibility.AccessibleContext; public class JRadioButton extends JToggleButton { + private static final long serialVersionUID = 7751949583255506856L; + public JRadioButton() { this(null, null); diff --git a/libjava/javax/swing/JRadioButtonMenuItem.java b/libjava/javax/swing/JRadioButtonMenuItem.java index f3c0772b3e7..a1611879933 100644 --- a/libjava/javax/swing/JRadioButtonMenuItem.java +++ b/libjava/javax/swing/JRadioButtonMenuItem.java @@ -49,6 +49,8 @@ import javax.accessibility.AccessibleRole; */ public class JRadioButtonMenuItem extends JMenuItem implements Accessible { + private static final long serialVersionUID = 8482658191548521743L; + private static final String uiClassID = "RadioButtonMenuItemUI"; /** @@ -185,7 +187,7 @@ public class JRadioButtonMenuItem extends JMenuItem implements Accessible public AccessibleContext getAccessibleContext() { if (accessibleContext == null) - accessibleContext = new AccessibleJRadioButtonMenuItem(this); + accessibleContext = new AccessibleJRadioButtonMenuItem(); return accessibleContext; } @@ -195,16 +197,13 @@ public class JRadioButtonMenuItem extends JMenuItem implements Accessible */ protected class AccessibleJRadioButtonMenuItem extends AccessibleJMenuItem { + private static final long serialVersionUID = 4381471510145292179L; + /** * Creates a new AccessibleJRadioButtonMenuItem object. - * - * @param component DOCUMENT ME! */ - protected AccessibleJRadioButtonMenuItem(JRadioButtonMenuItem component) + protected AccessibleJRadioButtonMenuItem() { - super(component); - - // TODO } /** diff --git a/libjava/javax/swing/JRootPane.java b/libjava/javax/swing/JRootPane.java index 99907d09990..b1c24a207d9 100644 --- a/libjava/javax/swing/JRootPane.java +++ b/libjava/javax/swing/JRootPane.java @@ -35,7 +35,6 @@ this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ - package javax.swing; import java.awt.BorderLayout; @@ -44,282 +43,296 @@ import java.awt.Container; import java.awt.Dimension; import java.awt.LayoutManager; import java.awt.LayoutManager2; +import java.io.Serializable; +import javax.accessibility.AccessibleRole; import javax.swing.plaf.RootPaneUI; /** * This class is where JComponents are added to. * Unlike awt where you could just say frame.add(), - * with swing you need to say frame.getRootPane() + * with swing you need to say frame.getRootPane() * (which delivers an instance of this class) * and add your components to that. * - * It is implemented by several 'layers' (pane() should be read as plane()) + * It is implemented by several 'layers' (pane() should be read as plane()) * each on top of the others - * where you can add components to. + * where you can add components to. * (getContentPane(), getGlassPane(), getLayeredPane()) * * @author Ronald Veldema (rveldema@cs.vu.nl) */ public class JRootPane extends JComponent { - // The class used to obtain the accessible role for this object. - static protected class AccessibleJRootPane + // The class used to obtain the accessible role for this object. + protected static class AccessibleJRootPane + { + private static final long serialVersionUID = 1082432482784468088L; + + protected AccessibleJRootPane() { } - // Custom Layout Manager for JRootPane. It positions contentPane and - // menuBar withing its layeredPane. - protected class RootLayout extends Object implements LayoutManager2 + public AccessibleRole getAccessibleRole() { - public void addLayoutComponent(Component comp, Object constraints) - { - } - - public void addLayoutComponent(String name, Component comp) - { - } - - public float getLayoutAlignmentX(Container target) - { - return target.getAlignmentX(); - } - - public float getLayoutAlignmentY(Container target) - { - return target.getAlignmentY(); - } - - public void invalidateLayout(Container target) - { - } - - public void layoutContainer(Container c) - { - Dimension menuBarSize; - Dimension containerSize = c.getSize(null); - Dimension contentPaneSize = contentPane.getPreferredSize(); - - /* - if size of top-level window wasn't set then just set - contentPane and menuBar to its preferred sizes. - Otherwise, if the size of top-level window was specified then - set menuBar to its preferred size and make content pane - to fit into the remaining space - - - +-------------------------------+ - | JLayeredPane | - | +--------------------------+ | - | | menuBar | | - | +--------------------------+ | - | +--------------------------+ | - | |contentPane | | - | | | | - | | | | - | | | | - | +--------------------------+ | - +-------------------------------+ - - */ - if (containerSize.width == 0 && containerSize.height == 0) - { - if (menuBar != null) - { - int maxWidth; - menuBarSize = menuBar.getPreferredSize(); - maxWidth = Math.max(menuBarSize.width, contentPaneSize.width); - menuBar.setBounds(0, 0, maxWidth, menuBarSize.height); - contentPane.setBounds(0, menuBarSize.height, maxWidth, - contentPaneSize.height); - layeredPane.setSize(maxWidth, - menuBarSize.height + contentPaneSize.height); - } - else - { - contentPane.setBounds(0, 0, contentPaneSize.width, - contentPaneSize.height); - layeredPane.setSize(contentPaneSize.width, contentPaneSize.height); - } - } - else - { - 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; - contentPane.setBounds(0, menuBarSize.height, - containerSize.width, - (containerSize.height - menuBarSize.height)); - } - else - contentPane.setBounds(0, 0, containerSize.width, - containerSize.height); - - layeredPane.setSize(containerSize.width, containerSize.height); - } - } - - public Dimension maximumLayoutSize(Container target) - { - return preferredLayoutSize(target); - } - - public Dimension minimumLayoutSize(Container target) - { - return preferredLayoutSize(target); - } - - public Dimension preferredLayoutSize(Container c) - { - Dimension menuBarSize; - Dimension prefSize; - - Dimension containerSize = c.getSize(); - Dimension contentPaneSize = contentPane.getPreferredSize(); - - if (containerSize.width == 0 && containerSize.height == 0) - { - if (menuBar != null) - { - int maxWidth; - menuBarSize = menuBar.getPreferredSize(); - maxWidth = Math.max(menuBarSize.width, contentPaneSize.width); - prefSize = new Dimension(maxWidth, - contentPaneSize.height - + menuBarSize.height); - } - else - prefSize = contentPaneSize; - } - else - prefSize = c.getSize(); - - return prefSize; - } - - public void removeLayoutComponent(Component comp) - { - } + return AccessibleRole.ROOT_PANE; } - - protected Component glassPane; - protected JLayeredPane layeredPane; - protected JMenuBar menuBar; - protected Container contentPane; - - - void setJMenuBar(JMenuBar m) - { - menuBar = m; - getLayeredPane().add(menuBar, JLayeredPane.FRAME_CONTENT_LAYER); - } - - JMenuBar getJMenuBar() - { return menuBar; } + } - public boolean isValidateRoot() + // Custom Layout Manager for JRootPane. It positions contentPane and + // menuBar withing its layeredPane. + protected class RootLayout implements LayoutManager2, Serializable { - return true; - } - + private static final long serialVersionUID = -4100116998559815027L; - public Container getContentPane() + protected RootLayout() + { + } + + public void addLayoutComponent(Component comp, Object constraints) { - if (contentPane == null) - { - setContentPane(createContentPane()); - } - return contentPane; } - public void setContentPane(Container p) + public void addLayoutComponent(String name, Component comp) { - contentPane = p; - getLayeredPane().add(contentPane, JLayeredPane.FRAME_CONTENT_LAYER); } - protected void addImpl(Component comp, - Object constraints, - int index) + public float getLayoutAlignmentX(Container target) { - super.addImpl(comp, constraints, index); - } + return target.getAlignmentX(); + } - public Component getGlassPane() + public float getLayoutAlignmentY(Container target) { - if (glassPane == null) - setGlassPane(createGlassPane()); - return glassPane; + return target.getAlignmentY(); } - public void setGlassPane(Component f) + public void invalidateLayout(Container target) { - if (glassPane != null) - remove(glassPane); + } - glassPane = f; + public void layoutContainer(Container c) + { + Dimension menuBarSize; + Dimension containerSize = c.getSize(null); + Dimension contentPaneSize = contentPane.getPreferredSize(); + + /* + if size of top-level window wasn't set then just set + contentPane and menuBar to its preferred sizes. + Otherwise, if the size of top-level window was specified then + set menuBar to its preferred size and make content pane + to fit into the remaining space + + + +-------------------------------+ + | JLayeredPane | + | +--------------------------+ | + | | menuBar | | + | +--------------------------+ | + | +--------------------------+ | + | |contentPane | | + | | | | + | | | | + | | | | + | +--------------------------+ | + +-------------------------------+ + + */ + if (containerSize.width == 0 && containerSize.height == 0) + { + if (menuBar != null) + { + int maxWidth; + menuBarSize = menuBar.getPreferredSize(); + maxWidth = Math.max(menuBarSize.width, contentPaneSize.width); + menuBar.setBounds(0, 0, maxWidth, menuBarSize.height); + contentPane.setBounds(0, menuBarSize.height, maxWidth, + contentPaneSize.height); + layeredPane.setSize(maxWidth, + menuBarSize.height + contentPaneSize.height); + } + else + { + contentPane.setBounds(0, 0, contentPaneSize.width, + contentPaneSize.height); + layeredPane.setSize(contentPaneSize.width, contentPaneSize.height); + } + } + else + { + 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; + contentPane.setBounds(0, menuBarSize.height, + containerSize.width, + (containerSize.height - menuBarSize.height)); + } + else + contentPane.setBounds(0, 0, containerSize.width, + containerSize.height); - glassPane.setVisible(false); - add(glassPane, 0); + layeredPane.setSize(containerSize.width, containerSize.height); + } } - public JLayeredPane getLayeredPane() + public Dimension maximumLayoutSize(Container target) { - if (layeredPane == null) - setLayeredPane(createLayeredPane()); - return layeredPane; + return preferredLayoutSize(target); } - public void setLayeredPane(JLayeredPane f) + + public Dimension minimumLayoutSize(Container target) { - if (layeredPane != null) - remove(layeredPane); - - layeredPane = f; - add(f, -1); + return preferredLayoutSize(target); } - - JRootPane() + public Dimension preferredLayoutSize(Container c) { - setLayout(createRootLayout()); - getGlassPane(); - getLayeredPane(); - getContentPane(); - setDoubleBuffered(true); - updateUI(); - } + Dimension menuBarSize; + Dimension prefSize; - protected LayoutManager createRootLayout() { - return new RootLayout(); - } + Dimension containerSize = c.getSize(); + Dimension contentPaneSize = contentPane.getPreferredSize(); - JComponent createContentPane() - { - JPanel p = new JPanel(); - p.setName(this.getName()+".contentPane"); - p.setLayout(new BorderLayout()); - return p; + if (containerSize.width == 0 && containerSize.height == 0) + { + if (menuBar != null) + { + int maxWidth; + menuBarSize = menuBar.getPreferredSize(); + maxWidth = Math.max(menuBarSize.width, contentPaneSize.width); + prefSize = + new Dimension(maxWidth, + contentPaneSize.height + menuBarSize.height); + } + else + prefSize = contentPaneSize; + } + else + prefSize = c.getSize(); + + return prefSize; } - Component createGlassPane() + public void removeLayoutComponent(Component comp) { - JPanel p = new JPanel(); - p.setName(this.getName()+".glassPane"); - p.setLayout(new BorderLayout()); - p.setVisible(false); - return p; } + } - JLayeredPane createLayeredPane() - { - JLayeredPane l = new JLayeredPane(); - l.setLayout(null); - return l; - } + protected Component glassPane; + protected JLayeredPane layeredPane; + protected JMenuBar menuBar; + protected Container contentPane; + + public void setJMenuBar(JMenuBar m) + { + menuBar = m; + getLayeredPane().add(menuBar, JLayeredPane.FRAME_CONTENT_LAYER); + } + public JMenuBar getJMenuBar() + { + return menuBar; + } + + public boolean isValidateRoot() + { + return true; + } + + public Container getContentPane() + { + if (contentPane == null) + setContentPane(createContentPane()); + return contentPane; + } + + public void setContentPane(Container p) + { + contentPane = p; + getLayeredPane().add(contentPane, JLayeredPane.FRAME_CONTENT_LAYER); + } + + protected void addImpl(Component comp, Object constraints, int index) + { + super.addImpl(comp, constraints, index); + } + + public Component getGlassPane() + { + if (glassPane == null) + setGlassPane(createGlassPane()); + return glassPane; + } + + public void setGlassPane(Component f) + { + if (glassPane != null) + remove(glassPane); + + glassPane = f; + + glassPane.setVisible(false); + add(glassPane, 0); + } + + public JLayeredPane getLayeredPane() + { + if (layeredPane == null) + setLayeredPane(createLayeredPane()); + return layeredPane; + } + + public void setLayeredPane(JLayeredPane f) + { + if (layeredPane != null) + remove(layeredPane); + + layeredPane = f; + add(f, -1); + } + + public JRootPane() + { + setLayout(createRootLayout()); + getGlassPane(); + getLayeredPane(); + getContentPane(); + setDoubleBuffered(true); + updateUI(); + } + + protected LayoutManager createRootLayout() + { + return new RootLayout(); + } + + protected JComponent createContentPane() + { + JPanel p = new JPanel(); + p.setName(this.getName() + ".contentPane"); + p.setLayout(new BorderLayout()); + return p; + } + + protected Component createGlassPane() + { + JPanel p = new JPanel(); + p.setName(this.getName() + ".glassPane"); + p.setLayout(new BorderLayout()); + p.setVisible(false); + return p; + } + + protected JLayeredPane createLayeredPane() + { + JLayeredPane l = new JLayeredPane(); + l.setLayout(null); + return l; + } public RootPaneUI getUI() { diff --git a/libjava/javax/swing/JScrollBar.java b/libjava/javax/swing/JScrollBar.java index b8404b3a940..07fe5cc8501 100644 --- a/libjava/javax/swing/JScrollBar.java +++ b/libjava/javax/swing/JScrollBar.java @@ -67,14 +67,16 @@ public class JScrollBar extends JComponent implements Adjustable, Accessible protected class AccessibleJScrollBar extends JComponent.AccessibleJComponent implements AccessibleValue { + private static final long serialVersionUID = -7758162392045586663L; + /** * Creates a new AccessibleJSlider object. * * @param value0 DOCUMENT ME! */ - protected AccessibleJScrollBar(JScrollBar value0) + protected AccessibleJScrollBar() { - super(value0); + super(); } /** @@ -150,6 +152,8 @@ public class JScrollBar extends JComponent implements Adjustable, Accessible } } + private static final long serialVersionUID = -8195169869225066566L; + /** Fired in a PropertyChangeEvent when the "blockIncrement" changes. */ public static final String BLOCK_INCREMENT_CHANGED_PROPERTY = "blockIncrement"; @@ -725,7 +729,7 @@ public class JScrollBar extends JComponent implements Adjustable, Accessible public AccessibleContext getAccessibleContext() { if (accessibleContext == null) - accessibleContext = new AccessibleJScrollBar(this); + accessibleContext = new AccessibleJScrollBar(); return accessibleContext; } } diff --git a/libjava/javax/swing/JScrollPane.java b/libjava/javax/swing/JScrollPane.java index 1a2021e3332..7e8bdce1897 100644 --- a/libjava/javax/swing/JScrollPane.java +++ b/libjava/javax/swing/JScrollPane.java @@ -79,20 +79,23 @@ public class JScrollPane extends JComponent implements Accessible, ScrollPaneConstants { - JViewport columnHeader; - JViewport rowHeader; + private static final long serialVersionUID = 5203525440012340014L; + + protected JViewport columnHeader; + protected JViewport rowHeader; - Component lowerLeft; - Component lowerRight; - Component upperLeft; - Component upperRight; + protected Component lowerLeft; + protected Component lowerRight; + protected Component upperLeft; + protected Component upperRight; - JScrollBar horizontalScrollBar; - int horizontalScrollBarPolicy; - JScrollBar verticalScrollBar; - int verticalScrollBarPolicy; + protected JScrollBar horizontalScrollBar; + protected int horizontalScrollBarPolicy; + protected JScrollBar verticalScrollBar; + protected int verticalScrollBarPolicy; - JViewport viewport; + protected JViewport viewport; + Border viewportBorder; boolean wheelScrollingEnabled; ChangeListener scrollListener; diff --git a/libjava/javax/swing/JSeparator.java b/libjava/javax/swing/JSeparator.java index be0d205c7a0..5b99795a5cc 100644 --- a/libjava/javax/swing/JSeparator.java +++ b/libjava/javax/swing/JSeparator.java @@ -55,14 +55,15 @@ public class JSeparator extends JComponent implements SwingConstants, */ protected class AccessibleJSeparator extends AccessibleJComponent { + private static final long serialVersionUID = 916332890553201095L; + /** * Constructor AccessibleJSeparator * * @param component TODO */ - protected AccessibleJSeparator(JSeparator component) + protected AccessibleJSeparator() { - super(component); } /** @@ -76,6 +77,8 @@ public class JSeparator extends JComponent implements SwingConstants, } } + private static final long serialVersionUID = 125301223445282357L; + /** The orientation of the JSeparator. */ private transient int orientation = HORIZONTAL; @@ -198,7 +201,8 @@ public class JSeparator extends JComponent implements SwingConstants, public AccessibleContext getAccessibleContext() { if (accessibleContext == null) - accessibleContext = new AccessibleJSeparator(this); + accessibleContext = new AccessibleJSeparator(); + return accessibleContext; } } diff --git a/libjava/javax/swing/JSlider.java b/libjava/javax/swing/JSlider.java index b4db64180c3..0bc013cb128 100644 --- a/libjava/javax/swing/JSlider.java +++ b/libjava/javax/swing/JSlider.java @@ -122,14 +122,15 @@ public class JSlider extends JComponent implements SwingConstants, Accessible, protected class AccessibleJSlider extends JComponent.AccessibleJComponent implements AccessibleValue { + private static final long serialVersionUID = -6301740148041106789L; + /** * Creates a new AccessibleJSlider object. * * @param value0 DOCUMENT ME! */ - protected AccessibleJSlider(JSlider value0) + protected AccessibleJSlider() { - super(value0); } /** @@ -933,7 +934,8 @@ public class JSlider extends JComponent implements SwingConstants, Accessible, public AccessibleContext getAccessibleContext() { if (accessibleContext == null) - accessibleContext = new AccessibleJSlider(this); + accessibleContext = new AccessibleJSlider(); + return accessibleContext; } } diff --git a/libjava/javax/swing/JSplitPane.java b/libjava/javax/swing/JSplitPane.java index a8ef310708e..32b85e1da95 100644 --- a/libjava/javax/swing/JSplitPane.java +++ b/libjava/javax/swing/JSplitPane.java @@ -1,3 +1,40 @@ +/* JSplitPane.java -- + Copyright (C) 2004 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + package javax.swing; @@ -26,14 +63,15 @@ public class JSplitPane extends JComponent implements Accessible protected class AccessibleJSplitPane extends JComponent.AccessibleJComponent implements AccessibleValue { + private static final long serialVersionUID = -1788116871416305366L; + /** * Creates a new AccessibleJSplitPane object. * * @param value0 DOCUMENT ME! */ - protected AccessibleJSplitPane(JSplitPane value0) + protected AccessibleJSplitPane() { - super(value0); } /** @@ -109,6 +147,8 @@ public class JSplitPane extends JComponent implements Accessible } } + private static final long serialVersionUID = -5634142046175988380L; + /** The constraints string used to add components to the bottom. */ public static final String BOTTOM = "bottom"; @@ -311,7 +351,8 @@ public class JSplitPane extends JComponent implements Accessible public AccessibleContext getAccessibleContext() { if (accessibleContext == null) - accessibleContext = new AccessibleJSplitPane(this); + accessibleContext = new AccessibleJSplitPane(); + return accessibleContext; } @@ -522,7 +563,7 @@ public class JSplitPane extends JComponent implements Accessible */ public void remove(int index) { - Component component = getComponentAt(index); + Component component = getComponent(index); if (component == leftComponent) leftComponent = null; else if (component == rightComponent) diff --git a/libjava/javax/swing/JTabbedPane.java b/libjava/javax/swing/JTabbedPane.java index e0ca953e226..7cf91c30445 100644 --- a/libjava/javax/swing/JTabbedPane.java +++ b/libjava/javax/swing/JTabbedPane.java @@ -79,14 +79,16 @@ public class JTabbedPane extends JComponent implements Serializable, protected class AccessibleJTabbedPane extends JComponent.AccessibleJComponent implements AccessibleSelection, ChangeListener { + private static final long serialVersionUID = 7610530885966830483L; + /** * Creates a new AccessibleJTabbedPane object. * * @param c DOCUMENT ME! */ - public AccessibleJTabbedPane(JTabbedPane c) + public AccessibleJTabbedPane() { - super(c); + super(); } /** @@ -224,6 +226,12 @@ public class JTabbedPane extends JComponent implements Serializable, */ protected class ModelListener implements ChangeListener, Serializable { + private static final long serialVersionUID = 497359819958114132L; + + protected ModelListener() + { + } + /** * This method is called whenever the model is changed. * @@ -304,7 +312,9 @@ public class JTabbedPane extends JComponent implements Serializable, */ public void setComponent(Component c) { + JTabbedPane.this.remove(component); this.component = c; + JTabbedPane.this.add(c); } /** @@ -542,10 +552,10 @@ public class JTabbedPane extends JComponent implements Serializable, protected SingleSelectionModel model; /** Indicates that the TabbedPane is in scrolling mode. */ - public static int SCROLL_TAB_LAYOUT = 1; + public static final int SCROLL_TAB_LAYOUT = 1; /** Indicates that the TabbedPane is in wrap mode. */ - public static int WRAP_TAB_LAYOUT = 0; + public static final int WRAP_TAB_LAYOUT = 0; /** The current tabPlacement of the TabbedPane. */ protected int tabPlacement = SwingConstants.TOP; @@ -825,12 +835,12 @@ public class JTabbedPane extends JComponent implements Serializable, checkIndex(index, -1, tabs.size()); if (index != getSelectedIndex()) { - if (getSelectedIndex() != -1) + if (getSelectedIndex() != -1 && getSelectedComponent() != null) getSelectedComponent().hide(); - if (index != -1) + if (index != -1 && getComponentAt(index) != null) getComponentAt(index).show(); + model.setSelectedIndex(index); } - model.setSelectedIndex(index); } /** @@ -874,13 +884,17 @@ public class JTabbedPane extends JComponent implements Serializable, // Hide the component so we don't see it. Do it before we parent it // so we don't trigger a repaint. - component.hide(); - super.add(component); - + if (component != null) + { + component.hide(); + super.add(component); + } + if (getSelectedIndex() == -1) setSelectedIndex(0); layout(); + repaint(); } /** @@ -1474,7 +1488,7 @@ public class JTabbedPane extends JComponent implements Serializable, public AccessibleContext getAccessibleContext() { if (accessibleContext == null) - accessibleContext = new AccessibleJTabbedPane(this); + accessibleContext = new AccessibleJTabbedPane(); return accessibleContext; } } diff --git a/libjava/javax/swing/JTable.java b/libjava/javax/swing/JTable.java index 496ae99572c..73dac5e8bdd 100644 --- a/libjava/javax/swing/JTable.java +++ b/libjava/javax/swing/JTable.java @@ -58,6 +58,8 @@ public class JTable extends JComponent implements TableModelListener, Scrollable, TableColumnModelListener, ListSelectionListener, CellEditorListener, Accessible { + private static final long serialVersionUID = 3876025080382781659L; + public static final int AUTO_RESIZE_ALL_COLUMNS = 4; public static final int AUTO_RESIZE_LAST_COLUMN = 3; public static final int AUTO_RESIZE_NEXT_COLUMN = 1; diff --git a/libjava/javax/swing/JTextArea.java b/libjava/javax/swing/JTextArea.java new file mode 100644 index 00000000000..7a44e91c5ca --- /dev/null +++ b/libjava/javax/swing/JTextArea.java @@ -0,0 +1,231 @@ +/* JTextArea.java -- + Copyright (C) 2004 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.swing; + +import java.awt.Dimension; +import javax.swing.text.Document; +import javax.swing.text.JTextComponent; +import javax.swing.text.PlainDocument; + +public class JTextArea extends JTextComponent +{ + private static final long serialVersionUID = -6141680179310439825L; + + private int rows; + private int columns; + private boolean wrapping; + + /** + * Creates a new <code>JTextArea</code> object. + */ + public JTextArea() + { + this(null, null, 0, 0); + } + + /** + * Creates a new <code>JTextArea</code> object. + * + * @param text the initial text + */ + public JTextArea(String text) + { + this(null, text, 0, 0); + } + + /** + * Creates a new <code>JTextArea</code> object. + * + * @param rows the number of rows + * @param columns the number of cols + * + * @exception IllegalArgumentException if rows or columns are negative + */ + public JTextArea(int rows, int columns) + { + this(null, null, rows, columns); + } + + /** + * Creates a new <code>JTextArea</code> object. + * + * @param text the initial text + * @param rows the number of rows + * @param columns the number of cols + * + * @exception IllegalArgumentException if rows or columns are negative + */ + public JTextArea(String text, int rows, int columns) + { + this(null, text, rows, columns); + } + + /** + * Creates a new <code>JTextArea</code> object. + * + * @param the document model to use + */ + public JTextArea(Document doc) + { + this(doc, null, 0, 0); + } + + /** + * Creates a new <code>JTextArea</code> object. + * + * @param the document model to use + * @param text the initial text + * @param rows the number of rows + * @param columns the number of cols + * + * @exception IllegalArgumentException if rows or columns are negative + */ + public JTextArea(Document doc, String text, int rows, int columns) + { + setDocument(doc == null ? createDefaultModel() : doc); + setText(text); + setRows(rows); + setColumns(columns); + } + + /** + * Appends some text. + * + * @param toAppend the text to append + */ + public void append(String toAppend) + { + setText(getText() + toAppend); + } + + /** + * Creates the default document model. + * + * @return a new default model + */ + protected Document createDefaultModel() + { + return new PlainDocument(); + } + + + public boolean getScrollableTracksViewportWidth() + { + return wrapping ? true : super.getScrollableTracksViewportWidth(); + } + + /** + * Returns the UI class ID string. + * + * @return the string "TextAreaUI" + */ + public String getUIClassID() + { + return "TextAreaUI"; + } + + /** + * Returns the current number of columns. + * + * @return number of columns + */ + public int getColumns() + { + return columns; + } + + /** + * Sets the number of rows. + * + * @param columns number of columns + * + * @exception IllegalArgumentException if columns is negative + */ + public void setColumns(int columns) + { + if (columns < 0) + throw new IllegalArgumentException(); + + this.columns = columns; + } + + /** + * Returns the current number of rows. + * + * @return number of rows + */ + public int getRows() + { + return rows; + } + + /** + * Sets the number of rows. + * + * @param columns number of columns + * + * @exception IllegalArgumentException if rows is negative + */ + public void setRows(int rows) + { + if (rows < 0) + throw new IllegalArgumentException(); + + this.rows = rows; + } + + /** + * Checks whethet line wrapping is enabled. + * + * @return true if line wrapping is enabled, false otherwise + */ + public boolean getLineWrap() + { + return wrapping; + } + + /** + * Enables/disables line wrapping. + * + * @param wrapping true to enable line wrapping, false otherwise + */ + public void setLineWrap(boolean wrapping) + { + this.wrapping = wrapping; + } +} diff --git a/libjava/javax/swing/JTextField.java b/libjava/javax/swing/JTextField.java index 95fceaf50c6..46d35929a28 100644 --- a/libjava/javax/swing/JTextField.java +++ b/libjava/javax/swing/JTextField.java @@ -1,4 +1,4 @@ -/* JTextField.java -- +/* JTextField.java -- Copyright (C) 2002, 2004 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -35,73 +35,185 @@ this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ - package javax.swing; +import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.util.Vector; - import javax.accessibility.AccessibleStateSet; +import javax.swing.text.Document; +import javax.swing.text.JTextComponent; +import javax.swing.text.PlainDocument; + -public class JTextField extends JEditorPane +public class JTextField extends JTextComponent + implements SwingConstants { + /** + * AccessibleJTextField + */ + protected class AccessibleJTextField extends AccessibleJTextComponent + { + private static final long serialVersionUID = 8255147276740453036L; - /** - * AccessibleJTextField - */ - protected class AccessibleJTextField extends AccessibleJTextComponent { + /** + * Constructor AccessibleJTextField + */ + protected AccessibleJTextField() + { + } - //------------------------------------------------------------- - // Initialization --------------------------------------------- - //------------------------------------------------------------- + /** + * getAccessibleStateSet + * @return AccessibleStateSet + */ + public AccessibleStateSet getAccessibleStateSet() + { + return null; + } + } - /** - * Constructor AccessibleJTextField - * @param component TODO - */ - protected AccessibleJTextField(JTextField component) { - super(component); - // TODO - } // AccessibleJTextField() + private static final long serialVersionUID = 353853209832607592L; + public static final String notifyAction = "notify-field-accept"; + + private int columns; - //------------------------------------------------------------- - // Methods ---------------------------------------------------- - //------------------------------------------------------------- + /** + * Creates a new instance of <code>JTextField</code>. + */ + public JTextField() + { + this(null, null, 0); + } - /** - * getAccessibleStateSet - * @returns AccessibleStateSet - */ - public AccessibleStateSet getAccessibleStateSet() { - return null; // TODO - } // getAccessibleStateSet() + /** + * Creates a new instance of <code>JTextField</code>. + * + * @param text the initial text + */ + public JTextField(String text) + { + this(null, text, 0); + } + + /** + * Creates a new instance of <code>JTextField</code>. + * + * @param columns the number of columns + * + * @exception IllegalArgumentException if columns %lt; 0 + */ + public JTextField(int columns) + { + this(null, null, columns); + } + /** + * Creates a new instance of <code>JTextField</code>. + * + * @param text the initial text + * @param columns the number of columns + * + * @exception IllegalArgumentException if columns %lt; 0 + */ + public JTextField(String text, int columns) + { + this(null, text, columns); + } - } // AccessibleJTextField + /** + * Creates a new instance of <code>JTextField</code>. + * + * @param doc the document to use + * @param text the initial text + * @param columns the number of columns + * + * @exception IllegalArgumentException if columns %lt; 0 + */ + public JTextField(Document doc, String text, int columns) + { + if (doc == null) + doc = createDefaultModel(); + setDocument(doc); + setText(text); + setColumns(columns); + } - Vector actions = new Vector(); + /** + * Creates the default model for this text field. + * This implementation returns an instance of <code>PlainDocument</code>. + * + * @return a new instance of the default model + */ + protected Document createDefaultModel() + { + return new PlainDocument(); + } - public JTextField() + /** + * Adds a new listener object to this text field. + * + * @param listener the listener to add + */ + public void addActionListener(ActionListener listener) { + listenerList.add(ActionListener.class, listener); } - public JTextField(int a) - { - } + /** + * Removes a listener object from this text field. + * + * @param listener the listener to remove + */ + public void removeActionListener(ActionListener listener) + { + listenerList.remove(ActionListener.class, listener); + } - public void addActionListener(ActionListener l) - { - actions.addElement(l); - } + /** + * Returns all registered <code>ActionListener</code> objects. + * + * @return an array of listeners + */ + public ActionListener[] getActionListeners() + { + return (ActionListener[]) getListeners(ActionListener.class); + } - public void removeActionListener(ActionListener l) - { - actions.removeElement(l); - } + /** + * Sends an action event to all registered + * <code>ActionListener</code> objects. + */ + protected void fireActionPerformed() + { + ActionEvent event = new ActionEvent(this, 0, notifyAction); + ActionListener[] listeners = getActionListeners(); - public void selectAll() - { - } + for (int index = 0; index < listeners.length; ++index) + listeners[index].actionPerformed(event); + } + + /** + * Returns the number of columns of this text field. + * + * @return the number of columns + */ + public int getColumns() + { + return columns; + } + + public void setColumns(int columns) + { + if (columns < 0) + throw new IllegalArgumentException(); + + this.columns = columns; + // FIXME: Invalidate layout. + } + + public void selectAll() + { + } } diff --git a/libjava/javax/swing/JToggleButton.java b/libjava/javax/swing/JToggleButton.java index 0977b00c6fe..9f3395aa227 100644 --- a/libjava/javax/swing/JToggleButton.java +++ b/libjava/javax/swing/JToggleButton.java @@ -47,6 +47,8 @@ public class JToggleButton extends AbstractButton implements Accessible public static class ToggleButtonModel extends DefaultButtonModel { + private static final long serialVersionUID = -1589950750899943974L; + public void setPressed(boolean b) { if (! isEnabled()) @@ -62,6 +64,8 @@ public class JToggleButton extends AbstractButton implements Accessible } + private static final long serialVersionUID = -3128248873429850443L; + public JToggleButton() { this(null, null); @@ -82,6 +86,12 @@ public class JToggleButton extends AbstractButton implements Accessible this(text, null); } + public JToggleButton(String text, boolean selected) + { + this(text, null); + setSelected(selected); + } + public JToggleButton(String text, Icon icon) { this(text, icon, false); @@ -96,17 +106,20 @@ public class JToggleButton extends AbstractButton implements Accessible model.setSelected(selected); } - - + /** + * Gets the AccessibleContext associated with this JToggleButton. + */ public AccessibleContext getAccessibleContext() { - //Gets the AccessibleContext associated with this JToggleButton. return null; } + /** + * Returns a string that specifies the name of the L&F class that renders + * this component. + */ public String getUIClassID() { - //Returns a string that specifies the name of the L&F class that renders this component. return "ToggleButtonUI"; } diff --git a/libjava/javax/swing/JToolBar.java b/libjava/javax/swing/JToolBar.java index ebc469212c8..e6db8720c2c 100644 --- a/libjava/javax/swing/JToolBar.java +++ b/libjava/javax/swing/JToolBar.java @@ -40,7 +40,9 @@ package javax.swing; import java.awt.Component; import java.awt.Dimension; import java.awt.Graphics; +import java.awt.GridLayout; import java.awt.Insets; +import java.awt.LayoutManager; import java.beans.PropertyChangeListener; import java.io.IOException; import java.io.ObjectOutputStream; @@ -59,58 +61,46 @@ import javax.swing.plaf.ToolBarUI; public class JToolBar extends JComponent implements SwingConstants, Accessible { - - //------------------------------------------------------------- - // Classes ---------------------------------------------------- - //------------------------------------------------------------- - - /** - * AccessibleJToolBar - */ - protected class AccessibleJToolBar extends AccessibleJComponent { - - //------------------------------------------------------------- - // Initialization --------------------------------------------- - //------------------------------------------------------------- - - /** - * Constructor AccessibleJToolBar - * @param component TODO - */ - protected AccessibleJToolBar(JToolBar component) { - super(component); - // TODO - } // AccessibleJToolBar() - - - //------------------------------------------------------------- - // Methods ---------------------------------------------------- - //------------------------------------------------------------- - - /** - * getAccessibleStateSet - * @returns AccessibleStateSet - */ - public AccessibleStateSet getAccessibleStateSet() { - return null; // TODO - } // getAccessibleStateSet() - - /** - * getAccessibleRole - * @returns AccessibleRole - */ - public AccessibleRole getAccessibleRole() { - return AccessibleRole.TOOL_BAR; - } // getAccessibleRole() - - - } // AccessibleJToolBar + /** + * AccessibleJToolBar + */ + protected class AccessibleJToolBar extends AccessibleJComponent + { + private static final long serialVersionUID = -5516888265903814215L; + + /** + * Constructor AccessibleJToolBar + */ + protected AccessibleJToolBar() + { + } + + /** + * getAccessibleStateSet + * @return AccessibleStateSet + */ + public AccessibleStateSet getAccessibleStateSet() + { + return null; // TODO + } + + /** + * getAccessibleRole + * @return AccessibleRole + */ + public AccessibleRole getAccessibleRole() + { + return AccessibleRole.TOOL_BAR; + } + } /** * Separator */ public static class Separator extends JSeparator { + private static final long serialVersionUID = -1656745644823105219L; + //------------------------------------------------------------- // Variables -------------------------------------------------- //------------------------------------------------------------- @@ -196,7 +186,27 @@ public class JToolBar extends JComponent } // Separator - +// /** +// * DefaultJToolBarLayout +// */ +// private class DefaultJToolBarLayout { +// +// private void DefaultJToolBarLayout() { +// } +// +// private LayoutManager getLayout() { +// switch (JToolBar.this.getOrientation()) { +// case HORIZONTAL: setLayout(new GridLayout(1, 0, 4, 4)); +// break; +// case VERTICAL: setLayout(new GridLayout(0, 1, 4, 4)); +// break; +// } +// } +// } // DefaultJToolBarLayout + + + private static final long serialVersionUID = -1269915519555129643L; + //------------------------------------------------------------- // Variables -------------------------------------------------- //------------------------------------------------------------- @@ -224,8 +234,13 @@ public class JToolBar extends JComponent /** * orientation */ - private int orientation; + private int orientation = HORIZONTAL; + +// protected transient DefaultJToolBarLayout toolbarLayout; + /** Fired in a PropertyChangeEvent when the "orientation" property changes. + */ + public static final String ORIENTATION_CHANGED_PROPERTY = "orientation"; //------------------------------------------------------------- // Initialization --------------------------------------------- @@ -235,32 +250,37 @@ public class JToolBar extends JComponent * Constructor JToolBar */ public JToolBar() { - // TODO + this(null); } // JToolBar() /** * Constructor JToolBar - * @param orientation TODO + * @param orientation JToolBar orientation (HORIZONTAL or VERTICAL) */ public JToolBar(int orientation) { - // TODO + this(null, orientation); } // JToolBar() /** * Constructor JToolBar - * @param name TODO + * @param name Name assigned to undocked tool bar. */ public JToolBar(String name) { - // TODO + this(name, HORIZONTAL); } // JToolBar() /** * Constructor JToolBar - * @param name TODO - * @param orientation TODO + * @param name Name assigned to undocked tool bar. + * @param orientation JToolBar orientation (HORIZONTAL or VERTICAL) */ public JToolBar(String name, int orientation) { - // TODO + setName(name); + if (orientation != HORIZONTAL && orientation != VERTICAL) + throw new IllegalArgumentException(orientation + " is not a legal orientation"); + this.orientation = orientation; +// toolbarLayout = new DefaultJToolBarLayout(); + updateUI(); } // JToolBar() @@ -299,6 +319,7 @@ public class JToolBar extends JComponent * @returns ToolBarUI */ public ToolBarUI getUI() { + System.out.println("ui = " + ui); return (ToolBarUI) ui; } // getUI() @@ -314,8 +335,7 @@ public class JToolBar extends JComponent * updateUI */ public void updateUI() { - setUI((ToolBarUI) UIManager.get(this)); - invalidate(); + setUI((ToolBarUI)UIManager.getUI(this)); } // updateUI() /** @@ -397,15 +417,31 @@ public class JToolBar extends JComponent * @returns int */ public int getOrientation() { - return 0; // TODO + return this.orientation; } // getOrientation() /** + * setLayout + * @param mgr + */ + public void setLayout(LayoutManager mgr) { + super.setLayout(mgr); + } // setLayout() + + /** * setOrientation - * @param orientation TODO + * @param orientation */ public void setOrientation(int orientation) { - // TODO + if (orientation != HORIZONTAL && orientation != VERTICAL) + throw new IllegalArgumentException(orientation + " is not a legal orientation"); + if (orientation != this.orientation) + { + int oldOrientation = this.orientation; + this.orientation = orientation; + firePropertyChange(ORIENTATION_CHANGED_PROPERTY, oldOrientation, + this.orientation); + } } // setOrientation() /** @@ -447,10 +483,11 @@ public class JToolBar extends JComponent * @param constraints TODO * @param index TODO */ + /* protected void addImpl(Component component, Object constraints, int index) { // TODO } // addImpl() - + */ /** * paramString * @returns String @@ -459,16 +496,15 @@ public class JToolBar extends JComponent return null; // TODO } // paramString() - /** - * getAccessibleContext - * @returns AccessibleContext - */ - public AccessibleContext getAccessibleContext() { - if (accessibleContext == null) { - accessibleContext = new AccessibleJToolBar(this); - } // if - return accessibleContext; - } // getAccessibleContext() - - -} // JToolBar + /** + * getAccessibleContext + * @return AccessibleContext + */ + public AccessibleContext getAccessibleContext() + { + if (accessibleContext == null) + accessibleContext = new AccessibleJToolBar(); + + return accessibleContext; + } +} diff --git a/libjava/javax/swing/JToolTip.java b/libjava/javax/swing/JToolTip.java index 083bbad02da..87e4610db40 100644 --- a/libjava/javax/swing/JToolTip.java +++ b/libjava/javax/swing/JToolTip.java @@ -42,12 +42,18 @@ import javax.accessibility.Accessible; public class JToolTip extends JComponent implements Accessible { - String text; - - JToolTip(String text) - { - this.text = text; - } + private static final long serialVersionUID = -1138929898906751643L; + + String text; + + public JToolTip() + { + } + + public void setTipText(String newText) + { + this.text = newText; + } } diff --git a/libjava/javax/swing/JTree.java b/libjava/javax/swing/JTree.java index ca86679d707..765a0d996e6 100644 --- a/libjava/javax/swing/JTree.java +++ b/libjava/javax/swing/JTree.java @@ -1,4 +1,4 @@ -/* JTree.java -- +/* JTree.java -- Copyright (C) 2002, 2004 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -35,79 +35,323 @@ this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ - package javax.swing; import java.awt.Dimension; import java.awt.Rectangle; - +import java.util.Hashtable; +import java.util.Vector; import javax.accessibility.Accessible; import javax.accessibility.AccessibleContext; +import javax.swing.event.TreeExpansionEvent; +import javax.swing.event.TreeExpansionListener; +import javax.swing.event.TreeSelectionEvent; +import javax.swing.event.TreeSelectionListener; +import javax.swing.event.TreeWillExpandListener; import javax.swing.plaf.TreeUI; +import javax.swing.tree.ExpandVetoException; +import javax.swing.tree.TreeModel; +import javax.swing.tree.TreeNode; +import javax.swing.tree.TreePath; + -public class JTree extends JComponent implements Scrollable, Accessible +public class JTree extends JComponent + implements Scrollable, Accessible { - JTree() - { - updateUI(); - } - - public TreeUI getUI() - { - return (TreeUI) ui; - } - - public void setUI(TreeUI ui) - { - super.setUI(ui); - } - - public void updateUI() - { - setUI((TreeUI)UIManager.getUI(this)); - } - - - public String getUIClassID() - { - return "TreeUI"; - } - - - public AccessibleContext getAccessibleContext() - { - return null; - } - - public Dimension getPreferredScrollableViewportSize() - { - return null; - } - - 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() - { - return false; - } - - public boolean getScrollableTracksViewportHeight() - { - return false; - } -} + private static final long serialVersionUID = 7559816092864483649L; + + protected TreeModel treeModel; + + /** + * Creates a new <code>JTree</code> object. + */ + public JTree() + { + treeModel = createTreeModel(null); + } + + /** + * Creates a new <code>JTree</code> object. + * + * @param value the initial nodes in the tree + */ + public JTree(Hashtable value) + { + treeModel = createTreeModel(value); + } + + /** + * Creates a new <code>JTree</code> object. + * + * @param value the initial nodes in the tree + */ + public JTree(Object[] value) + { + treeModel = createTreeModel(value); + } + + /** + * Creates a new <code>JTree</code> object. + * + * @param model the model to use + */ + public JTree(TreeModel model) + { + treeModel = model; + } + + /** + * 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) + { + } + + /** + * Creates a new <code>JTree</code> object. + * + * @param value the initial nodes in the tree + */ + public JTree(Vector value) + { + treeModel = createTreeModel(value); + } + + /** + * Creates a new <code>TreeModel</code> object. + * + * @param value the values stored in the model + */ + protected static TreeModel createTreeModel(Object value) + { + // FIXME: Implement this. + return null; + } + + public TreeUI getUI() + { + return (TreeUI) ui; + } + + public void setUI(TreeUI ui) + { + super.setUI(ui); + } + + public void updateUI() + { + setUI((TreeUI) UIManager.getUI(this)); + } + + public String getUIClassID() + { + return "TreeUI"; + } + + public AccessibleContext getAccessibleContext() + { + return null; + } + + public Dimension getPreferredScrollableViewportSize() + { + return null; + } + + 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() + { + return false; + } + public boolean getScrollableTracksViewportHeight() + { + 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); + } +} diff --git a/libjava/javax/swing/JViewport.java b/libjava/javax/swing/JViewport.java index b164dc79045..bbb4d5cb683 100644 --- a/libjava/javax/swing/JViewport.java +++ b/libjava/javax/swing/JViewport.java @@ -45,6 +45,7 @@ import java.awt.Insets; import java.awt.Point; import java.awt.Rectangle; +import javax.accessibility.Accessible; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import javax.swing.plaf.ViewportUI; @@ -91,19 +92,20 @@ import javax.swing.plaf.ViewportUI; * the underlying child at position <code>(-VX,-VY)</code></p> * */ - public class JViewport extends JComponent { - public static int BACKINGSTORE_SCROLL_MODE = 1; - public static int BLIT_SCROLL_MODE = 2; - public static int SIMPLE_SCROLL_MODE = 3; + private static final long serialVersionUID = -6925142919680527970L; + + public static final int SIMPLE_SCROLL_MODE = 0; + public static final int BLIT_SCROLL_MODE = 1; + public static final int BACKINGSTORE_SCROLL_MODE = 2; ChangeEvent changeEvent = new ChangeEvent(this); int scrollMode; - boolean scrollUnderway; - boolean isViewSizeSet; + protected boolean scrollUnderway; + protected boolean isViewSizeSet; /** * The width and height of the Viewport's area in terms of view @@ -133,11 +135,23 @@ public class JViewport extends JComponent public Dimension getExtentSize() { if (extentSize == null) - return getPreferredSize(); + return toViewCoordinates(getSize()); else return extentSize; } + public Dimension toViewCoordinates(Dimension size) + { + return size; + } + + public Point toViewCoordinates(Point p) + { + Point pos = getViewPosition(); + return new Point(p.x + pos.x, + p.y + pos.y); + } + public void setExtentSize(Dimension newSize) { extentSize = newSize; @@ -146,10 +160,10 @@ public class JViewport extends JComponent public Dimension getViewSize() { - if (viewSize == null) - return getView().getPreferredSize(); - else + if (isViewSizeSet) return viewSize; + else + return getView().getSize(); } @@ -158,10 +172,17 @@ public class JViewport extends JComponent viewSize = newSize; Component view = getView(); if (view != null) - view.setSize(newSize); + view.setSize(viewSize); + isViewSizeSet = true; fireStateChanged(); } + /** + * Get the viewport's position in view space. Despite confusing name, + * this really does return the viewport's (0,0) position in view space, + * not the view's position. + */ + public Point getViewPosition() { Component view = getView(); diff --git a/libjava/javax/swing/JWindow.java b/libjava/javax/swing/JWindow.java index eb478eb4b72..81acd1138a7 100644 --- a/libjava/javax/swing/JWindow.java +++ b/libjava/javax/swing/JWindow.java @@ -60,6 +60,8 @@ import javax.accessibility.AccessibleContext; */ public class JWindow extends Window implements Accessible, RootPaneContainer { + private static final long serialVersionUID = 5420698392125238833L; + public final static int HIDE_ON_CLOSE = 0; public final static int EXIT_ON_CLOSE = 1; public final static int DISPOSE_ON_CLOSE = 2; @@ -114,13 +116,6 @@ public class JWindow extends Window implements Accessible, RootPaneContainer return d; } - JMenuBar getJMenuBar() - { return getRootPane().getJMenuBar(); } - - void setJMenuBar(JMenuBar menubar) - { getRootPane().setJMenuBar(menubar); } - - public void setLayout(LayoutManager manager) { super.setLayout(manager); } diff --git a/libjava/javax/swing/KeyStroke.java b/libjava/javax/swing/KeyStroke.java index 743d3069d37..b78be0c7392 100644 --- a/libjava/javax/swing/KeyStroke.java +++ b/libjava/javax/swing/KeyStroke.java @@ -149,6 +149,7 @@ public class KeyStroke implements Serializable * @param keyChar TODO * @param onKeyRelease TODO * @returns KeyStroke + * @deprecated Use getKeyStroke(char) */ public static KeyStroke getKeyStroke(char keyChar, boolean onKeyRelease) { KeyStroke key = getKeyStroke(keyChar); diff --git a/libjava/javax/swing/LookAndFeel.java b/libjava/javax/swing/LookAndFeel.java index 173d2fa825a..aa6b8a2ec6f 100644 --- a/libjava/javax/swing/LookAndFeel.java +++ b/libjava/javax/swing/LookAndFeel.java @@ -1,4 +1,4 @@ -/* LookAndFeel.java -- +/* LookAndFeel.java -- Copyright (C) 2002, 2004 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -35,92 +35,134 @@ this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ - package javax.swing; import javax.swing.text.JTextComponent; + public abstract class LookAndFeel { - public UIDefaults getDefaults() - { - //This method is called once by UIManager.setLookAndFeel to create the look and feel specific defaults table. - return null; - } - - public abstract String getDescription(); - public abstract String getID(); - public abstract String getName(); - - public void initialize() - { - //UIManager.setLookAndFeel calls this method before the first call (and typically the only call) to getDefaults(). - } - - static void installBorder(JComponent c, String defaultBorderName) - { - //Convenience method for installing a component's default Border object on the specified component if either the border is currently null or already an instance of UIResource. - } - - public static void installColors(JComponent c, String defaultBgName, String defaultFgName) - { - //Convenience method for initializing a component's foreground and background color properties with values from the current defaults table. - } - - public static void installColorsAndFont(JComponent c, String defaultBgName, String defaultFgName, String defaultFontName) - { - //Convenience method for initializing a components foreground background and font properties with values from the current defaults table. - } - - public abstract boolean isNativeLookAndFeel(); - public abstract boolean isSupportedLookAndFeel(); - - public static void loadKeyBindings(InputMap retMap, Object[] keys) - { - //Loads the bindings in keys into retMap. - } - - public static ComponentInputMap makeComponentInputMap(JComponent c, Object[] keys) - { - // Creates a ComponentInputMap from keys. - return null; - } - - public static Object makeIcon(Class baseClass, String gifFile) - { - //Utility method that creates a UIDefaults.LazyValue that creates an ImageIcon UIResource for the specified gifFile filename. - return null; - } - - public static InputMap makeInputMap(Object[] keys) - { - //Creates a InputMap from keys. - return null; - } - - public static JTextComponent.KeyBinding[] makeKeyBindings(Object[] keyBindingList) - { - // Convenience method for building lists of KeyBindings. - return null; - } - - - public String toString() - { - //Returns a string that displays and identifies this object's properties. - return "LookAndFeel"; - } - - public void uninitialize() - { - //UIManager.setLookAndFeel calls this method just before we're replaced by a new default look and feel. - } - - - public static void uninstallBorder(JComponent c) - { - //Convenience method for un-installing a component's default border on the specified component if the border is currently an instance of UIResource. - } - + /** + * This method is called once by UIManager.setLookAndFeel to create + * the look and feel specific defaults table. + * + * @return the UI defaults + */ + public UIDefaults getDefaults() + { + return null; + } + + public abstract String getDescription(); + + public abstract String getID(); + + public abstract String getName(); + + /** + * UIManager.setLookAndFeel calls this method before the first call + * (and typically the only call) to getDefaults(). + */ + public void initialize() + { + } + + /** + * Convenience method for installing a component's default Border object + * on the specified component if either the border is currently null + * or already an instance of UIResource. + */ + public static void installBorder(JComponent c, String defaultBorderName) + { + } + + /** + * Convenience method for initializing a component's foreground and + * background color properties with values from the current defaults table. + */ + public static void installColors(JComponent c, String defaultBgName, String defaultFgName) + { + } + + /** + * Convenience method for initializing a components foreground background + * and font properties with values from the current defaults table. + */ + public static void installColorsAndFont(JComponent component, + String defaultBgName, + String defaultFgName, + String defaultFontName) + { + } + + public abstract boolean isNativeLookAndFeel(); + + public abstract boolean isSupportedLookAndFeel(); + + /** + * Loads the bindings in keys into retMap. + */ + public static void loadKeyBindings(InputMap retMap, Object[] keys) + { + } + + /** + * Creates a ComponentInputMap from keys. + */ + public static ComponentInputMap makeComponentInputMap(JComponent c, + Object[] keys) + { + return null; + } + + /** + * Utility method that creates a UIDefaults.LazyValue that creates an + * ImageIcon UIResource for the specified gifFile filename. + */ + public static Object makeIcon(Class baseClass, String gifFile) + { + return null; + } + + /** + * Creates a InputMap from keys. + */ + public static InputMap makeInputMap(Object[] keys) + { + return null; + } + + /** + * Convenience method for building lists of KeyBindings. + */ + public static JTextComponent.KeyBinding[] makeKeyBindings(Object[] keyBindingList) + { + return null; + } + + /** + * Returns a string that displays and identifies this object's properties. + * + * @return the string "LookAndFeel" + */ + public String toString() + { + return "LookAndFeel"; + } + + /** + * UIManager.setLookAndFeel calls this method just before we're replaced by + * a new default look and feel. + */ + public void uninitialize() + { + } + + /** + * Convenience method for un-installing a component's default border on the + * specified component if the border is currently an instance of UIResource. + */ + public static void uninstallBorder(JComponent c) + { + } } - diff --git a/libjava/javax/swing/MenuSelectionManager.java b/libjava/javax/swing/MenuSelectionManager.java index d722b0b7275..33988003b47 100644 --- a/libjava/javax/swing/MenuSelectionManager.java +++ b/libjava/javax/swing/MenuSelectionManager.java @@ -1,4 +1,4 @@ -/* MenuSelectionManager.java -- +/* MenuSelectionManager.java -- Copyright (C) 2002, 2004 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -35,70 +35,111 @@ this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ - package javax.swing; import java.awt.Component; import java.awt.Point; import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; - +import java.util.ArrayList; import java.util.Vector; - import javax.swing.JMenu; import javax.swing.JMenuItem; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import javax.swing.event.EventListenerList; + +/** + * This class manages current menu selectection. It provides + * methods to clear and set current selected menu path. + * It also fires StateChange event to its registered + * listeners whenever selected path of the current menu hierarchy + * changes. + * + */ public class MenuSelectionManager { - protected ChangeEvent changeEvent; - - protected EventListenerList listenerList = new EventListenerList (); + /** ChangeEvent fired when selected path changes*/ + protected ChangeEvent changeEvent = new ChangeEvent(this); + + /** List of listeners for this MenuSelectionManager */ + protected EventListenerList listenerList = new EventListenerList(); + /** Default manager for the current menu hierarchy*/ private static final MenuSelectionManager manager = new MenuSelectionManager(); - - private Vector selection = new Vector(); - - protected void fireStateChanged () + + /** Path to the currently selected menu */ + private Vector selectedPath = new Vector(); + + /** + * Fires StateChange event to registered listeners + */ + protected void fireStateChanged() { - ChangeListener[] listeners = getChangeListeners (); + ChangeListener[] listeners = getChangeListeners(); for (int i = 0; i < listeners.length; i++) - { - listeners [i].stateChanged (new ChangeEvent (this)); - } + listeners[i].stateChanged(changeEvent); } - public void addChangeListener (ChangeListener listener) + /** + * Adds ChangeListener to this MenuSelectionManager + * + * @param listener ChangeListener to add + */ + public void addChangeListener(ChangeListener listener) { - listenerList.add (ChangeListener.class, listener); + listenerList.add(ChangeListener.class, listener); } - public void removeChangeListener (ChangeListener listener) + /** + * Removes ChangeListener from the list of registered listeners + * for this MenuSelectionManager. + * + * @param listener ChangeListner to remove + */ + public void removeChangeListener(ChangeListener listener) { - listenerList.remove (ChangeListener.class, listener); + listenerList.remove(ChangeListener.class, listener); } - /** @since 1.4 */ - public ChangeListener[] getChangeListeners () + /** + * Returns list of registered listeners with MenuSelectionManager + * + * @since 1.4 + */ + public ChangeListener[] getChangeListeners() { - return (ChangeListener[]) listenerList.getListeners (ChangeListener.class); + return (ChangeListener[]) listenerList.getListeners(ChangeListener.class); } - + /** - * Unselects all the menu elements on the selection path + * Unselects all the menu elements on the selection path */ - public void clearSelectedPath () + public void clearSelectedPath() { - for (int i = 0; i < selection.size (); i++) - ((MenuElement) selection.get (i)).menuSelectionChanged (false); + // Send events from the bottom most item in the menu - hierarchy to the + // top most + for (int i = selectedPath.size() - 1; i >= 0; i--) + ((MenuElement) selectedPath.get(i)).menuSelectionChanged(false); + + // notify all listeners that the selected path was changed + fireStateChanged(); - selection.clear (); + // clear selected path + selectedPath.clear(); } - - public Component componentForPoint (Component source, Point sourcePoint) + + /** + * DOCUMENT ME! + * + * @param source DOCUMENT ME! + * @param sourcePoint DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public Component componentForPoint(Component source, Point sourcePoint) { throw new UnsupportedOperationException("not implemented"); } @@ -108,7 +149,7 @@ public class MenuSelectionManager * * @return default Manager */ - public static MenuSelectionManager defaultManager () + public static MenuSelectionManager defaultManager() { return manager; } @@ -118,12 +159,12 @@ public class MenuSelectionManager * * @return Current selection path */ - public MenuElement[] getSelectedPath () + public MenuElement[] getSelectedPath() { - MenuElement[] path = new MenuElement[selection.size ()]; + MenuElement[] path = new MenuElement[selectedPath.size()]; for (int i = 0; i < path.length; i++) - path[i] = (MenuElement) selection.get (i); + path[i] = (MenuElement) selectedPath.get(i); return path; } @@ -135,17 +176,17 @@ public class MenuSelectionManager * @param c Component for which to check * @return True if specified component is part of current menu */ - boolean isComponentPartOfCurrentMenu (Component c) + boolean isComponentPartOfCurrentMenu(Component c) { MenuElement[] subElements; - for (int i = 0; i < selection.size (); i++) + for (int i = 0; i < selectedPath.size(); i++) { - subElements = ((MenuElement) selection.get (i)).getSubElements (); - for (int j = 0; j < subElements.length; j++) - { - if ((subElements[j].getComponent ()).equals (c)) - return true; - } + subElements = ((MenuElement) selectedPath.get(i)).getSubElements(); + for (int j = 0; j < subElements.length; j++) + { + if ((subElements[j].getComponent()).equals(c)) + return true; + } } return false; @@ -156,7 +197,7 @@ public class MenuSelectionManager * * @param e DOCUMENT ME! */ - public void processKeyEvent (KeyEvent e) + public void processKeyEvent(KeyEvent e) { throw new UnsupportedOperationException("not implemented"); } @@ -166,35 +207,20 @@ public class MenuSelectionManager * * @param event Mouse event */ - public void processMouseEvent (MouseEvent event) + public void processMouseEvent(MouseEvent event) { - - Component c = ((MenuElement) event.getSource ()).getComponent (); - if (selection.size () == 0) - { - ((MenuElement) event.getSource ()).processMouseEvent (event, - getPath (c), - manager); - return; - } + Component c = ((Component) event.getSource()); - // find the index of the source component in the current menu hierarchy - int i = 0; - for (i = 0; i < selection.size (); i++) - { - MenuElement me = (MenuElement) selection.get (i); - if (me.getComponent ().equals (c)) - break; - } + MenuElement[] path = getPath(c); + ((MenuElement) c).processMouseEvent(event, path, manager); + + // forward events to subcomponents + MenuElement[] subComponents = ((MenuElement) c).getSubElements(); - // Forward event to all subcomponents of the source - Component subComp; - for (int j = i; j < selection.size (); j++) + for (int i = 0; i < subComponents.length; i++) { - subComp = ((MenuElement)selection.get (j)).getComponent (); - ((MenuElement) selection.get (j)).processMouseEvent (event, - getPath (subComp), - manager); + if (subComponents[i] instanceof JMenuItem) + subComponents[i].processMouseEvent(event, path, manager); } } @@ -203,68 +229,66 @@ public class MenuSelectionManager * * @param path new selection path */ - public void setSelectedPath (MenuElement[] path) + public void setSelectedPath(MenuElement[] path) { if (path == null) { - clearSelectedPath (); - return; + clearSelectedPath(); + return; } + fireStateChanged(); + int i; int minSize = path.length; // size of the smaller path. - if (path.length > selection.size ()) + if (path.length > selectedPath.size()) { - // if new selected path contains more elements then current - // selection then first add all elements at - // the indexes > selection.size - - for (i = selection.size (); i < path.length; i++) - { - selection.add (path[i]); - path[i].menuSelectionChanged (true); - } - - minSize = selection.size (); + // if new selected path contains more elements then current + // selection then first add all elements at + // the indexes > selectedPath.size + for (i = selectedPath.size(); i < path.length; i++) + { + selectedPath.add(path[i]); + path[i].menuSelectionChanged(true); + } + + minSize = selectedPath.size(); } - else if (path.length < selection.size ()) + else if (path.length < selectedPath.size()) { - // if new selected path contains less elements then current - // selection then first remove all elements from the selection - // at the indexes > path.length - - for (i = selection.size () - 1; i >= path.length; i--) - { - ((MenuElement) selection.get (i)).menuSelectionChanged (false); - selection.remove (i); - } - - minSize = path.length; + // if new selected path contains less elements then current + // selection then first remove all elements from the selection + // at the indexes > path.length + for (i = selectedPath.size() - 1; i >= path.length; i--) + { + ((MenuElement) selectedPath.get(i)).menuSelectionChanged(false); + selectedPath.remove(i); + } + + minSize = path.length; } // Now compare elements in new and current selection path at the // same location and adjust selection until // same menu elements will be encountered at the // same index in both current and new selection path. - - MenuElement oldSelection; + MenuElement oldSelectedPath; for (i = minSize - 1; i >= 0; i--) { - oldSelection = (MenuElement) selection.get (i); + oldSelectedPath = (MenuElement) selectedPath.get(i); - if (path[i].equals (oldSelection)) - break; + if (path[i].equals(oldSelectedPath)) + break; - oldSelection.menuSelectionChanged (false); - path[i].menuSelectionChanged (true); - selection.setElementAt (path[i], i); + oldSelectedPath.menuSelectionChanged(false); + path[i].menuSelectionChanged(true); + selectedPath.setElementAt(path[i], i); } } - /** * Returns path to the specified component * @@ -272,27 +296,21 @@ public class MenuSelectionManager * * @return path to the specified component */ - private MenuElement[] getPath (Component c) + private MenuElement[] getPath(Component c) { - Vector path = new Vector(); - path.add (c); - - Component parent = c.getParent (); - - while (parent instanceof JMenu - || parent instanceof JPopupMenu - || parent instanceof JMenuItem - || parent instanceof JMenuBar) + ArrayList path = new ArrayList(); + while (c instanceof MenuElement) { - path.add (parent); - parent = parent.getParent (); - } + path.add(0, (MenuElement) c); - MenuElement[] pathArray = new MenuElement[path.size ()]; + if (c instanceof JPopupMenu) + c = ((JPopupMenu) c).getInvoker(); + else + c = c.getParent(); + } - for (int i = 0; i < path.size (); i++) - pathArray[i] = (MenuElement) path.get (path.size () - i - 1); + MenuElement[] pathArray = new MenuElement[path.size()]; + path.toArray(pathArray); return pathArray; } - -} // class MenuSelectionManager +} diff --git a/libjava/javax/swing/ScrollPaneConstants.java b/libjava/javax/swing/ScrollPaneConstants.java index e08fedb7a9c..b4e24be0136 100644 --- a/libjava/javax/swing/ScrollPaneConstants.java +++ b/libjava/javax/swing/ScrollPaneConstants.java @@ -1,5 +1,5 @@ /* ScrollPaneConstants.java -- - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2004 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -42,116 +42,110 @@ package javax.swing; * @author Andrew Selkirk * @version 1.0 */ -public interface ScrollPaneConstants { - - //------------------------------------------------------------- - // Variables -------------------------------------------------- - //------------------------------------------------------------- - - /** - * VIEWPORT - */ - String VIEWPORT = "VIEWPORT"; - - /** - * VERTICAL_SCROLLBAR - */ - String VERTICAL_SCROLLBAR = "VERTICAL_SCROLLBAR"; - - /** - * HORIZONTAL_SCROLLBAR - */ - String HORIZONTAL_SCROLLBAR = "HORIZONTAL_SCROLLBAR"; - - /** - * ROW_HEADER - */ - String ROW_HEADER = "ROW_HEADER"; - - /** - * COLUMN_HEADER - */ - String COLUMN_HEADER = "COLUMN_HEADER"; - - /** - * LOWER_LEFT_CORNER - */ - String LOWER_LEFT_CORNER = "LOWER_LEFT_CORNER"; - - /** - * LOWER_RIGHT_CORNER - */ - String LOWER_RIGHT_CORNER = "LOWER_RIGHT_CORNER"; - - /** - * UPPER_LEFT_CORNER - */ - String UPPER_LEFT_CORNER = "UPPER_LEFT_CORNER"; - - /** - * UPPER_RIGHT_CORNER - */ - String UPPER_RIGHT_CORNER = "UPPER_RIGHT_CORNER"; - - /** - * LOWER_LEADING_CORNER - */ - String LOWER_LEADING_CORNER = "LOWER_LEADING_CORNER"; - - /** - * LOWER_TRAILING_CORNER - */ - String LOWER_TRAILING_CORNER = "LOWER_TRAILING_CORNER"; - - /** - * UPPER_LEADING_CORNER - */ - String UPPER_LEADING_CORNER = "UPPER_LEADING_CORNER"; - - /** - * UPPER_TRAILING_CORNER - */ - String UPPER_TRAILING_CORNER = "UPPER_TRAILING_CORNER"; - - /** - * VERTICAL_SCROLLBAR_POLICY - */ - String VERTICAL_SCROLLBAR_POLICY = "VERTICAL_SCROLLBAR_POLICY"; - - /** - * HORIZONTAL_SCROLLBAR_POLICY - */ - String HORIZONTAL_SCROLLBAR_POLICY = "HORIZONTAL_SCROLLBAR_POLICY"; - - /** - * VERTICAL_SCROLLBAR_AS_NEEDED - */ - int VERTICAL_SCROLLBAR_AS_NEEDED = 20; - - /** - * VERTICAL_SCROLLBAR_NEVER - */ - int VERTICAL_SCROLLBAR_NEVER = 21; - - /** - * VERTICAL_SCROLLBAR_ALWAYS - */ - int VERTICAL_SCROLLBAR_ALWAYS = 22; - - /** - * HORIZONTAL_SCROLLBAR_AS_NEEDED - */ - int HORIZONTAL_SCROLLBAR_AS_NEEDED = 30; - - /** - * HORIZONTAL_SCROLLBAR_NEVER - */ - int HORIZONTAL_SCROLLBAR_NEVER = 31; - - /** - * HORIZONTAL_SCROLLBAR_ALWAYS - */ - int HORIZONTAL_SCROLLBAR_ALWAYS = 32; - - -} // ScrollPaneConstants +public interface ScrollPaneConstants +{ + /** + * VIEWPORT + */ + String VIEWPORT = "VIEWPORT"; + + /** + * VERTICAL_SCROLLBAR + */ + String VERTICAL_SCROLLBAR = "VERTICAL_SCROLLBAR"; + + /** + * HORIZONTAL_SCROLLBAR + */ + String HORIZONTAL_SCROLLBAR = "HORIZONTAL_SCROLLBAR"; + + /** + * ROW_HEADER + */ + String ROW_HEADER = "ROW_HEADER"; + + /** + * COLUMN_HEADER + */ + String COLUMN_HEADER = "COLUMN_HEADER"; + + /** + * LOWER_LEFT_CORNER + */ + String LOWER_LEFT_CORNER = "LOWER_LEFT_CORNER"; + + /** + * LOWER_RIGHT_CORNER + */ + String LOWER_RIGHT_CORNER = "LOWER_RIGHT_CORNER"; + + /** + * UPPER_LEFT_CORNER + */ + String UPPER_LEFT_CORNER = "UPPER_LEFT_CORNER"; + + /** + * UPPER_RIGHT_CORNER + */ + String UPPER_RIGHT_CORNER = "UPPER_RIGHT_CORNER"; + + /** + * LOWER_LEADING_CORNER + */ + String LOWER_LEADING_CORNER = "LOWER_LEADING_CORNER"; + + /** + * LOWER_TRAILING_CORNER + */ + String LOWER_TRAILING_CORNER = "LOWER_TRAILING_CORNER"; + + /** + * UPPER_LEADING_CORNER + */ + String UPPER_LEADING_CORNER = "UPPER_LEADING_CORNER"; + + /** + * UPPER_TRAILING_CORNER + */ + String UPPER_TRAILING_CORNER = "UPPER_TRAILING_CORNER"; + + /** + * VERTICAL_SCROLLBAR_POLICY + */ + String VERTICAL_SCROLLBAR_POLICY = "VERTICAL_SCROLLBAR_POLICY"; + + /** + * HORIZONTAL_SCROLLBAR_POLICY + */ + String HORIZONTAL_SCROLLBAR_POLICY = "HORIZONTAL_SCROLLBAR_POLICY"; + + /** + * VERTICAL_SCROLLBAR_AS_NEEDED + */ + int VERTICAL_SCROLLBAR_AS_NEEDED = 20; + + /** + * VERTICAL_SCROLLBAR_NEVER + */ + int VERTICAL_SCROLLBAR_NEVER = 21; + + /** + * VERTICAL_SCROLLBAR_ALWAYS + */ + int VERTICAL_SCROLLBAR_ALWAYS = 22; + + /** + * HORIZONTAL_SCROLLBAR_AS_NEEDED + */ + int HORIZONTAL_SCROLLBAR_AS_NEEDED = 30; + + /** + * HORIZONTAL_SCROLLBAR_NEVER + */ + int HORIZONTAL_SCROLLBAR_NEVER = 31; + + /** + * HORIZONTAL_SCROLLBAR_ALWAYS + */ + int HORIZONTAL_SCROLLBAR_ALWAYS = 32; +} diff --git a/libjava/javax/swing/ScrollPaneLayout.java b/libjava/javax/swing/ScrollPaneLayout.java index 16b6c0fae33..a249c277340 100644 --- a/libjava/javax/swing/ScrollPaneLayout.java +++ b/libjava/javax/swing/ScrollPaneLayout.java @@ -1,5 +1,5 @@ /* ScrollPaneLayout.java -- - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2004 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -63,17 +63,17 @@ public class ScrollPaneLayout } } - JViewport viewport; - JScrollBar verticalScrollBar; - JScrollBar horizontalScrollBar; - JViewport rowHeader; - JViewport columnHeader; - Component lowerLeft; - Component lowerRight; - Component upperLeft; - Component upperRight; - int verticalScrollBarPolicy; - int horizontalScrollBarPolicy; + protected JViewport viewport; + protected JScrollBar vsb; + protected JScrollBar hsb; + protected JViewport rowHead; + protected JViewport colHead; + protected Component lowerLeft; + protected Component lowerRight; + protected Component upperLeft; + protected Component upperRight; + protected int vsbPolicy; + protected int hsbPolicy; public ScrollPaneLayout() { @@ -81,10 +81,10 @@ public class ScrollPaneLayout public void syncWithScrollPane(JScrollPane scrollPane) { viewport = scrollPane.getViewport(); - verticalScrollBar = scrollPane.getVerticalScrollBar(); - horizontalScrollBar = scrollPane.getHorizontalScrollBar(); - verticalScrollBarPolicy = scrollPane.getVerticalScrollBarPolicy(); - horizontalScrollBarPolicy = scrollPane.getHorizontalScrollBarPolicy(); + vsb = scrollPane.getVerticalScrollBar(); + hsb = scrollPane.getHorizontalScrollBar(); + vsbPolicy = scrollPane.getVerticalScrollBarPolicy(); + hsbPolicy = scrollPane.getHorizontalScrollBarPolicy(); lowerLeft = scrollPane.getCorner(LOWER_LEFT_CORNER); lowerRight = scrollPane.getCorner(LOWER_RIGHT_CORNER); upperLeft = scrollPane.getCorner(UPPER_LEFT_CORNER); @@ -101,13 +101,13 @@ public class ScrollPaneLayout if (key == VIEWPORT) viewport = (JViewport) component; else if (key == VERTICAL_SCROLLBAR) - verticalScrollBar = (JScrollBar) component; + vsb = (JScrollBar) component; else if (key == HORIZONTAL_SCROLLBAR) - horizontalScrollBar = (JScrollBar) component; + hsb = (JScrollBar) component; else if (key == ROW_HEADER) - rowHeader = (JViewport) component; + rowHead = (JViewport) component; else if (key == COLUMN_HEADER) - columnHeader = (JViewport) component; + colHead = (JViewport) component; else if (key == LOWER_RIGHT_CORNER) lowerRight = component; else if (key == UPPER_RIGHT_CORNER) @@ -121,14 +121,14 @@ public class ScrollPaneLayout public void removeLayoutComponent(Component component) { if (component == viewport) viewport = null; - else if (component == verticalScrollBar) - verticalScrollBar = null; - else if (component == horizontalScrollBar) - horizontalScrollBar = null; - else if (component == rowHeader) - rowHeader = null; - else if (component == columnHeader) - columnHeader = null; + else if (component == vsb) + vsb = null; + else if (component == hsb) + hsb = null; + else if (component == rowHead) + rowHead = null; + else if (component == colHead) + colHead = null; else if (component == lowerRight) lowerRight = null; else if (component == upperRight) @@ -139,43 +139,53 @@ public class ScrollPaneLayout upperLeft = null; } - public int getVerticalScrollBarPolicy() { - return verticalScrollBarPolicy; + public int getVerticalScrollBarPolicy() + { + return vsbPolicy; } - public void setVerticalScrollBarPolicy(int policy) { - verticalScrollBarPolicy = policy; + public void setVerticalScrollBarPolicy(int policy) + { + vsbPolicy = policy; } - public int getHorizontalScrollBarPolicy() { - return horizontalScrollBarPolicy; + public int getHorizontalScrollBarPolicy() + { + return hsbPolicy; } - public void setHorizontalScrollBarPolicy(int policy) { - horizontalScrollBarPolicy = policy; + public void setHorizontalScrollBarPolicy(int policy) + { + hsbPolicy = policy; } - public JViewport getViewport() { + public JViewport getViewport() + { return viewport; } - public JScrollBar getHorizontalScrollBar() { - return horizontalScrollBar; + public JScrollBar getHorizontalScrollBar() + { + return hsb; } - public JScrollBar getVerticalScrollBar() { - return verticalScrollBar; + public JScrollBar getVerticalScrollBar() + { + return vsb; } - public JViewport getRowHeader() { - return rowHeader; + public JViewport getRowHeader() + { + return rowHead; } - public JViewport getColumnHeader() { - return columnHeader; + public JViewport getColumnHeader() + { + return colHead; } - public Component getCorner(String key) { + public Component getCorner(String key) + { if (key == LOWER_RIGHT_CORNER) return lowerRight; else if (key == UPPER_RIGHT_CORNER) @@ -216,17 +226,17 @@ public class ScrollPaneLayout if (viewport != null) viewportSize.setSize(viewport.getPreferredSize()); - if (columnHeader != null) - columnHeaderSize.setSize(columnHeader.getPreferredSize()); + if (colHead != null) + columnHeaderSize.setSize(colHead.getPreferredSize()); - if (rowHeader != null) - rowHeaderSize.setSize(rowHeader.getPreferredSize()); + if (rowHead != null) + rowHeaderSize.setSize(rowHead.getPreferredSize()); - if (verticalScrollBar != null) - verticalScrollBarSize.setSize(verticalScrollBar.getPreferredSize()); + if (vsb != null) + verticalScrollBarSize.setSize(vsb.getPreferredSize()); - if (horizontalScrollBar != null) - horizontalScrollBarSize.setSize(horizontalScrollBar.getPreferredSize()); + if (hsb != null) + horizontalScrollBarSize.setSize(hsb.getPreferredSize()); /* System.err.println("widths: [vp=" + viewportSize.width + @@ -285,19 +295,19 @@ public class ScrollPaneLayout if (viewport != null) viewportSize.setSize(viewport.getMinimumSize()); - if (columnHeader != null) - columnHeaderSize.setSize(columnHeader.getMinimumSize()); + if (colHead != null) + columnHeaderSize.setSize(colHead.getMinimumSize()); - if (rowHeader != null) - rowHeaderSize.setSize(rowHeader.getMinimumSize()); + if (rowHead != null) + rowHeaderSize.setSize(rowHead.getMinimumSize()); - if (verticalScrollBar != null - && verticalScrollBarPolicy != VERTICAL_SCROLLBAR_NEVER) - verticalScrollBarSize.setSize(verticalScrollBar.getMinimumSize()); + if (vsb != null + && vsbPolicy != VERTICAL_SCROLLBAR_NEVER) + verticalScrollBarSize.setSize(vsb.getMinimumSize()); - if (horizontalScrollBar != null - && horizontalScrollBarPolicy != HORIZONTAL_SCROLLBAR_NEVER) - horizontalScrollBarSize.setSize(horizontalScrollBar.getMinimumSize()); + if (hsb != null + && hsbPolicy != HORIZONTAL_SCROLLBAR_NEVER) + horizontalScrollBarSize.setSize(hsb.getMinimumSize()); return new Dimension(insetsSize.width + viewportSize.width @@ -338,8 +348,8 @@ public class ScrollPaneLayout * x1 x2 x3 x4 * */ - - public void layoutContainer(Container parent) { + public void layoutContainer(Container parent) + { if (parent instanceof JScrollPane) { JScrollPane sc = (JScrollPane) parent; @@ -358,13 +368,13 @@ public class ScrollPaneLayout x4 = scrollPaneBounds.x + scrollPaneBounds.width; y4 = scrollPaneBounds.y + scrollPaneBounds.height; - if (columnHeader != null) - y2 = columnHeader.getPreferredSize().height; + if (colHead != null) + y2 = colHead.getPreferredSize().height; else y2 = y1; - if (rowHeader != null) - x2 = rowHeader.getPreferredSize().width; + if (rowHead != null) + x2 = rowHead.getPreferredSize().width; else x2 = x1; @@ -372,24 +382,24 @@ public class ScrollPaneLayout int hsbPolicy = sc.getHorizontalScrollBarPolicy(); boolean showVsb = - (verticalScrollBar != null) + (vsb != null) && ((vsbPolicy == VERTICAL_SCROLLBAR_ALWAYS) || (vsbPolicy == VERTICAL_SCROLLBAR_AS_NEEDED && viewSize.height > viewportSize.height)); boolean showHsb = - (horizontalScrollBar != null) + (hsb != null) && ((hsbPolicy == HORIZONTAL_SCROLLBAR_ALWAYS) || (hsbPolicy == HORIZONTAL_SCROLLBAR_AS_NEEDED && viewSize.width > viewportSize.width)); if (showVsb) - x3 = x4 - verticalScrollBar.getPreferredSize().width; + x3 = x4 - vsb.getPreferredSize().width; else x3 = x4; if (showHsb) - y3 = y4 - horizontalScrollBar.getPreferredSize().height; + y3 = y4 - hsb.getPreferredSize().height; else y3 = y4; @@ -398,17 +408,17 @@ public class ScrollPaneLayout if (viewport != null) viewport.setBounds(new Rectangle(x2, y2, x3-x2, y3-y2)); - if (columnHeader != null) - columnHeader.setBounds(new Rectangle(x2, y1, x3-x2, y2-y1)); + if (colHead != null) + colHead.setBounds(new Rectangle(x2, y1, x3-x2, y2-y1)); - if (rowHeader != null) - rowHeader.setBounds(new Rectangle(x1, y2, x2-x1, y3-y2)); + if (rowHead != null) + rowHead.setBounds(new Rectangle(x1, y2, x2-x1, y3-y2)); if (showVsb) - verticalScrollBar.setBounds(new Rectangle(x3, y2, x4-x3, y3-y2)); + vsb.setBounds(new Rectangle(x3, y2, x4-x3, y3-y2)); if (showHsb) - horizontalScrollBar.setBounds(new Rectangle(x2, y3, x3-x2, y4-y3)); + hsb.setBounds(new Rectangle(x2, y3, x3-x2, y4-y3)); if (upperLeft != null) upperLeft.setBounds(new Rectangle(x1, y1, x2-x1, y2-y1)); diff --git a/libjava/javax/swing/SwingUtilities.java b/libjava/javax/swing/SwingUtilities.java index d543f0be48b..7162edbd75f 100644 --- a/libjava/javax/swing/SwingUtilities.java +++ b/libjava/javax/swing/SwingUtilities.java @@ -51,6 +51,7 @@ import java.awt.Rectangle; import java.awt.Shape; import java.awt.Toolkit; import java.awt.Window; +import java.awt.event.InputEvent; import java.awt.event.MouseEvent; import java.lang.reflect.InvocationTargetException; @@ -375,8 +376,12 @@ public class SwingUtilities implements SwingConstants return pt; } - + public static Point convertPoint(Component source, Point aPoint, Component destination) + { + return convertPoint(source, aPoint.x, aPoint.y, destination); + } + /** * Converts a rectangle from the coordinate space of one component to * another. This is equivalent to converting the rectangle from @@ -718,7 +723,6 @@ public class SwingUtilities implements SwingConstants iconR.y = centerLine - iconR.height/2; break; } - // The two rectangles are laid out correctly now, but only assuming // that their upper left corner is at (0,0). If we have any alignment other // than TOP and LEFT, we need to adjust them. @@ -845,6 +849,43 @@ public class SwingUtilities implements SwingConstants ownerFrame = new Frame(); return ownerFrame; } - + /** + * Checks if left mouse button was clicked. + * + * @param event the event to check + * + * @return true if left mouse was clicked, false otherwise. + */ + public static boolean isLeftMouseButton(MouseEvent event) + { + return ((event.getModifiers() & InputEvent.BUTTON1_DOWN_MASK) + == InputEvent.BUTTON1_DOWN_MASK); + } + + /** + * Checks if middle mouse button was clicked. + * + * @param event the event to check + * + * @return true if middle mouse was clicked, false otherwise. + */ + public static boolean isMiddleMouseButton(MouseEvent event) + { + return ((event.getModifiers() & InputEvent.BUTTON2_DOWN_MASK) + == InputEvent.BUTTON2_DOWN_MASK); + } + + /** + * Checks if right mouse button was clicked. + * + * @param event the event to check + * + * @return true if right mouse was clicked, false otherwise. + */ + public static boolean isRightMouseButton(MouseEvent event) + { + return ((event.getModifiers() & InputEvent.BUTTON3_DOWN_MASK) + == InputEvent.BUTTON3_DOWN_MASK); + } } diff --git a/libjava/javax/swing/Timer.java b/libjava/javax/swing/Timer.java index fd88351f417..57a412a1910 100644 --- a/libjava/javax/swing/Timer.java +++ b/libjava/javax/swing/Timer.java @@ -47,44 +47,107 @@ import javax.swing.event.EventListenerList; public class Timer implements Serializable { + private static final long serialVersionUID = -1116180831621385484L; + protected EventListenerList listenerList = new EventListenerList(); - int ticks; - static boolean verbose; + // This object manages a "queue" of virtual actionEvents, maintained as a + // simple long counter. When the timer expires, a new event is queued, + // and a dispatcher object is pushed into the system event queue. When + // the system thread runs the dispatcher, it will fire as many + // ActionEvents as have been queued, unless the timer is set to + // coalescing mode, in which case it will fire only one ActionEvent. + + private long queue; + private Object queueLock = new Object(); + private void queueEvent() + { + synchronized (queueLock) + { + queue++; + if (queue == 1) + SwingUtilities.invokeLater(new Runnable() { public void run() { drainEvents(); } }); + } + } + + private void drainEvents() + { + synchronized (queueLock) + { + if (isCoalesce()) + { + if (queue > 0) + fireActionPerformed(); + } + else + { + while(queue > 0) + { + fireActionPerformed(); + queue--; + } + } + queue = 0; + } + } + + + static boolean logTimers; + boolean coalesce = true; + boolean repeats = true; boolean running; - boolean repeat_ticks = true; - long interval, init_delay; + int ticks; + int delay; + int initialDelay; - class Waker extends Thread + private class Waker + extends Thread { public void run() { running = true; - try { - sleep(init_delay); - - while (running) - { - sleep(interval); - - if (verbose) - { - System.out.println("javax.swing.Timer -> clocktick"); - } - - ticks++; - fireActionPerformed(); - - if (! repeat_ticks) - break; - } - running = false; - } catch (Exception e) { - System.out.println("swing.Timer::" + e); - } + try + { + + sleep(initialDelay); + + while (running) + { + sleep(delay); + + if (logTimers) + System.out.println("javax.swing.Timer -> clocktick"); + + if (! repeats) + break; + } + running = false; + } + catch (Exception e) + { + System.out.println("swing.Timer::" + e); + } } } + public Timer(int d, ActionListener listener) + { + delay = d; + + if (listener != null) + addActionListener(listener); + } + + public void setCoalesce(boolean c) + { + coalesce = c; + } + + public boolean isCoalesce() + { + return coalesce; + } + public void addActionListener(ActionListener listener) { listenerList.add (ActionListener.class, listener); @@ -123,37 +186,47 @@ public class Timer implements Serializable void fireActionPerformed () { - fireActionPerformed (new ActionEvent (this, ticks, "Timer")); + fireActionPerformed (new ActionEvent (this, ticks++, "Timer")); } - public static void setLogTimers(boolean flag) + public static void setLogTimers(boolean lt) { - verbose = flag; + logTimers = lt; } public static boolean getLogTimers() { - return verbose; + return logTimers; } - public void setDelay(int delay) + public void setDelay(int d) { - interval = delay; + delay = d; } public int getDelay() { - return (int)interval; + return delay; } - public void setInitialDelay(int initialDelay) + public void setInitialDelay(int i) { - init_delay = initialDelay; + initialDelay = i; } - public void setRepeats(boolean flag) + public int getInitialDelay() { - repeat_ticks = flag; + return initialDelay; + } + + public void setRepeats(boolean r) + { + repeats = r; + } + + public boolean isRepeats() + { + return repeats; } public boolean isRunning() @@ -171,6 +244,15 @@ public class Timer implements Serializable new Waker().start(); } + public void restart() + { + synchronized (queueLock) + { + queue = 0; + } + start(); + } + public void stop() { running = false; diff --git a/libjava/javax/swing/ViewportLayout.java b/libjava/javax/swing/ViewportLayout.java index 91bcf9b5e60..d419c497956 100644 --- a/libjava/javax/swing/ViewportLayout.java +++ b/libjava/javax/swing/ViewportLayout.java @@ -71,7 +71,6 @@ public class ViewportLayout implements LayoutManager, Serializable { Scrollable sc = (Scrollable) view; Dimension d = sc.getPreferredScrollableViewportSize(); - // System.err.println(this + ".preferredLayoutSize() : scrollable -> " + d); return d; } else @@ -83,20 +82,84 @@ public class ViewportLayout implements LayoutManager, Serializable Component view = vp.getView(); return view.getMinimumSize(); } + + /** + * Layout the view and viewport to respect the following rules. These are + * not precisely the rules described in sun's javadocs, but they are the + * rules which sun's swing implementation follows, if you watch its + * behavior: + * + * <ol> + * + * <li>If the port is larger than the view's minimum size, put the port + * at view position <code>(0,0)</code> and make the view's size equal to + * the port's.</li> + * + * <li>If the port is smaller than the view, leave the view at its + * minimum size. also, do not move the port, <em>unless</em> the port + * extends into space <em>past</em> the edge of the view. If so, move the + * port up or to the left, in view space, by the amount of empty space + * (keep the lower and right edges lined up)</li> + * + * </ol> + * + * @see JViewport#getViewSize + * @see JViewport#setViewSize + * @see JViewport#getViewPosition + * @see JViewport#setViewPosition + */ + public void layoutContainer(Container parent) { - JViewport vp = (JViewport)parent; - Component view = vp.getView(); - Rectangle portBounds = vp.getBounds(); + // The way to interpret this function is basically to ignore the names + // of methods it calls, and focus on the variable names here. getViewRect + // doesn't, for example, return the view; it returns the port bounds in + // view space. Likwise setViewPosition doesn't reposition the view; it + // positions the port, in view coordinates. + + JViewport port = (JViewport) parent; + Component view = port.getView(); + + // These dimensions and positions are in *view space*. Do not mix + // variables in here from port space (eg. parent.getBounds()). This + // function should be entirely in view space, because the methods on + // the viewport require inputs in view space. + + Rectangle portBounds = port.getViewRect(); + Dimension viewSize = port.getViewSize(); Dimension viewMinimum = view.getMinimumSize(); - int width = Math.max(portBounds.width, - viewMinimum.width); - int height = Math.max(portBounds.height, - viewMinimum.height); - int x = Math.min(0, portBounds.width - width); - int y = Math.min(0, portBounds.height - height); - // System.err.println(this + ".layoutContainer() : width = " + width + ", height = " + height); - vp.setViewPosition(new Point(x, y)); - vp.setViewSize(new Dimension(width, height)); + Point portLowerRight = new Point(portBounds.x + portBounds.width, + portBounds.y + portBounds.height); + + // vertical implementation of the above rules + if (portBounds.height >= viewMinimum.height) + { + portBounds.y = 0; + viewSize.height = portBounds.height; + } + else + { + viewSize.height = viewMinimum.height; + int overextension = portLowerRight.y - viewSize.height; + if (overextension > 0) + portBounds.y -= overextension; + } + + // horizontal implementation of the above rules + if (portBounds.width >= viewMinimum.width) + { + portBounds.x = 0; + viewSize.width = portBounds.width; + } + else + { + viewSize.width = viewMinimum.width; + int overextension = portLowerRight.x - viewSize.width; + if (overextension > 0) + portBounds.x -= overextension; + } + + port.setViewPosition(portBounds.getLocation()); + port.setViewSize(viewSize); } } diff --git a/libjava/javax/swing/event/DocumentEvent.java b/libjava/javax/swing/event/DocumentEvent.java index a442a4a7770..eccc9d3e576 100644 --- a/libjava/javax/swing/event/DocumentEvent.java +++ b/libjava/javax/swing/event/DocumentEvent.java @@ -87,68 +87,49 @@ public interface DocumentEvent { } // ElementChange - /** - * EventType - */ - class EventType { - - //------------------------------------------------------------- - // Variables -------------------------------------------------- - //------------------------------------------------------------- - - /** - * INSERT - */ - EventType INSERT = new EventType("INSERT"); // TODO - - /** - * REMOVE - */ - EventType REMOVE = new EventType("REMOVE"); // TODO - - /** - * CHANGE - */ - EventType CHANGE = new EventType("CHANGE"); // TODO - - /** - * typeString - */ - private String type; - - - //------------------------------------------------------------- - // Initialization --------------------------------------------- - //------------------------------------------------------------- - - /** - * Constructor EventType - * @param type TODO - */ - private EventType(String type) { - this.type = type; - } // EventType() - - - //------------------------------------------------------------- - // Methods ---------------------------------------------------- - //------------------------------------------------------------- - - /** - * toString - * @returns String - */ - public String toString() { - return type; // TODO - } // toString() - - - } // EventType - - - //------------------------------------------------------------- - // Methods ---------------------------------------------------- - //------------------------------------------------------------- + /** + * EventType + */ + class EventType + { + /** + * INSERT + */ + public static final EventType INSERT = new EventType("INSERT"); // TODO + + /** + * REMOVE + */ + public static final EventType REMOVE = new EventType("REMOVE"); // TODO + + /** + * CHANGE + */ + public static final EventType CHANGE = new EventType("CHANGE"); // TODO + + /** + * typeString + */ + private String type; + + /** + * Constructor EventType + * @param type TODO + */ + private EventType(String type) + { + this.type = type; + } + + /** + * toString + * @returns String + */ + public String toString() + { + return type; + } + } /** * getType diff --git a/libjava/javax/swing/event/UndoableEditListener.java b/libjava/javax/swing/event/UndoableEditListener.java index 0e9cf5e6b96..9031afe621e 100644 --- a/libjava/javax/swing/event/UndoableEditListener.java +++ b/libjava/javax/swing/event/UndoableEditListener.java @@ -1,5 +1,5 @@ /* UndoableEditListener.java -- - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2004 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -37,21 +37,20 @@ exception statement from your version. */ package javax.swing.event; -// Imports import java.util.EventListener; + /** * UndoableEditListener public interface * @author Andrew Selkirk * @author Ronald Veldema */ -public interface UndoableEditListener extends EventListener { - - /** - * Undoable edit has happened - * @param event Undoable Edit Event - */ - void undoableEditHappened(UndoableEditEvent event); - - -} // UndoableEditListener +public interface UndoableEditListener extends EventListener +{ + /** + * Undoable edit has happened + * + * @param event Undoable Edit Event + */ + void undoableEditHappened(UndoableEditEvent event); +} diff --git a/libjava/javax/swing/plaf/BorderUIResource.java b/libjava/javax/swing/plaf/BorderUIResource.java index c0bb2402fe7..c9ed0111644 100644 --- a/libjava/javax/swing/plaf/BorderUIResource.java +++ b/libjava/javax/swing/plaf/BorderUIResource.java @@ -270,6 +270,8 @@ public class BorderUIResource extends BevelBorder implements UIResource, Serializable { + private static final long serialVersionUID = -1275542891108351642L; + /** * Constructs a BevelBorderUIResource whose colors will be derived * from the background of the enclosed component. The background @@ -399,6 +401,8 @@ public class BorderUIResource extends CompoundBorder implements UIResource, Serializable { + private static final long serialVersionUID = 7550017084975167341L; + /** * Constructs a CompoundBorderUIResource with the specified inside * and outside borders. @@ -441,6 +445,8 @@ public class BorderUIResource extends EmptyBorder implements UIResource, Serializable { + private static final long serialVersionUID = -4914187529340071708L; + /** * Constructs an empty border given the number of pixels required * on each side. @@ -496,6 +502,8 @@ public class BorderUIResource extends EtchedBorder implements UIResource, Serializable { + private static final long serialVersionUID = -8186391754165296656L; + /** * Constructs an EtchedBorderUIResource that appears lowered into * the surface. The colors will be derived from the background @@ -597,6 +605,8 @@ public class BorderUIResource extends LineBorder implements UIResource, Serializable { + private static final long serialVersionUID = -6171232338180172310L; + /** * Constructs a LineBorderUIResource given its color. The border * will be one pixel thick and have plain corners. @@ -652,6 +662,8 @@ public class BorderUIResource extends MatteBorder implements UIResource, Serializable { + private static final long serialVersionUID = -8107923147541851122L; + /** * Constructs a MatteBorderUIResource given the width on each side * and a fill color. @@ -731,6 +743,8 @@ public class BorderUIResource extends TitledBorder implements UIResource, Serializable { + private static final long serialVersionUID = 7667113547406407427L; + /** * Constructs a TitledBorderUIResource given the text of its title. * diff --git a/libjava/javax/swing/plaf/basic/BasicButtonUI.java b/libjava/javax/swing/plaf/basic/BasicButtonUI.java index 5ebde8f57fb..b766d387db9 100644 --- a/libjava/javax/swing/plaf/basic/BasicButtonUI.java +++ b/libjava/javax/swing/plaf/basic/BasicButtonUI.java @@ -304,11 +304,7 @@ public class BasicButtonUI extends ButtonUI Icon i = currentIcon(b); if (i != null) - { - int x = iconRect.x; - int y = iconRect.y; - i.paintIcon(c, g, x, y); - } + i.paintIcon(c, g, iconRect.x, iconRect.y); } /** @@ -340,7 +336,7 @@ public class BasicButtonUI extends ButtonUI */ protected void paintButtonNormal(Graphics g, Rectangle area, JComponent b) { - if (((AbstractButton)b).isContentAreaFilled()) + if (((AbstractButton)b).isContentAreaFilled() && b.isOpaque()) { g.setColor(b.getBackground()); g.fillRect(area.x, area.y, area.width, area.height); @@ -362,9 +358,18 @@ public class BasicButtonUI extends ButtonUI Font f = c.getFont(); g.setFont(f); FontMetrics fm = g.getFontMetrics(f); - g.setColor(c.getForeground()); - BasicGraphicsUtils.drawString(g, text, 0, - textRect.x, - textRect.y + fm.getAscent()); + + if (c.isEnabled()) + { + g.setColor(c.getForeground()); + g.drawString(text, textRect.x, textRect.y + fm.getAscent()); + } + else + { + g.setColor(c.getBackground().brighter()); + g.drawString(text, textRect.x, textRect.y + fm.getAscent()); + g.setColor(c.getBackground().darker()); + g.drawString(text, textRect.x + 1, textRect.y + fm.getAscent() + 1); + } } } diff --git a/libjava/javax/swing/plaf/basic/BasicDesktopIconUI.java b/libjava/javax/swing/plaf/basic/BasicDesktopIconUI.java new file mode 100644 index 00000000000..b37c2f1e839 --- /dev/null +++ b/libjava/javax/swing/plaf/basic/BasicDesktopIconUI.java @@ -0,0 +1,589 @@ +/* BasicDesktopIconUI.java -- + Copyright (C) 2004 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.swing.plaf.basic; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.Insets; +import java.awt.Rectangle; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseEvent; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.beans.PropertyVetoException; +import javax.swing.Icon; +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JDesktopPane; +import javax.swing.JInternalFrame; +import javax.swing.JInternalFrame.JDesktopIcon; +import javax.swing.SwingConstants; +import javax.swing.border.Border; +import javax.swing.event.MouseInputAdapter; +import javax.swing.event.MouseInputListener; +import javax.swing.plaf.ComponentUI; +import javax.swing.plaf.DesktopIconUI; +import javax.swing.plaf.DesktopPaneUI; + + +/** + * This class acts as the UI delegate for JDesktopIcons for the Basic look and feel. + */ +public class BasicDesktopIconUI extends DesktopIconUI +{ + /** + * This helper class handles mouse events that occur on the JDesktopIcon. + */ + public class MouseInputHandler extends MouseInputAdapter + { + /** The x offset from the MouseEvent coordinates to the top left corner. */ + private transient int xOffset; + + /** The y offset fromt he MouseEvent coordinates to the top left corner. */ + private transient int yOffset; + + /** A cached value of the JDesktopPane that parents this JDesktopIcon. */ + private transient JDesktopPane pane; + + /** + * This method is called when the mouse is dragged in the JDesktopIcon. + * + * @param e The MouseEvent. + */ + public void mouseDragged(MouseEvent e) + { + Rectangle b = desktopIcon.getBounds(); + + moveAndRepaint(desktopIcon, b.x + e.getX() - xOffset, + b.y + e.getY() - yOffset, b.width, b.height); + } + + /** + * This method is called when the mouse is moved in the JDesktopIcon. + * + * @param e The MouseEvent. + */ + public void mouseMoved(MouseEvent e) + { + // Nothing to do. + } + + /** + * This method is called when the mouse is pressed in the JDesktopIcon. + * + * @param e The MouseEvent. + */ + public void mousePressed(MouseEvent e) + { + xOffset = e.getX(); + yOffset = e.getY(); + pane = frame.getDesktopPane(); + if (pane != null) + pane.getDesktopManager().beginDraggingFrame(desktopIcon); + } + + /** + * This method is called when the mouse is released in the JDesktopIcon. + * + * @param e The MouseEvent. + */ + public void mouseReleased(MouseEvent e) + { + if (pane != null) + pane.getDesktopManager().endDraggingFrame(desktopIcon); + xOffset = 0; + yOffset = 0; + } + + /** + * This method moves and repaints the JDesktopIcon to the given bounds. + * + * @param f The JComponent to move and repaint. + * @param newX The new x coordinate. + * @param newY The new y coordinate. + * @param newWidth The new width. + * @param newHeight The new height. + */ + public void moveAndRepaint(JComponent f, int newX, int newY, int newWidth, + int newHeight) + { + if (pane != null) + pane.getDesktopManager().dragFrame(f, newX, newY); + else + desktopIcon.setBounds(newX, newY, newWidth, newHeight); + } + } + + /** + * This class acts as the border for the JDesktopIcon. + */ + private class DesktopIconBorder implements Border + { + /** The left inset value. */ + int left = 10; + + /** The top inset value. */ + int top = 4; + + /** The right inset value. */ + int right = top; + + /** The bottom inset value. */ + int bottom = top; + + /** + * This method returns the insets of the border. + * + * @param c The Component to find border insets for. + * + * @return The border insets. + */ + public Insets getBorderInsets(Component c) + { + return new Insets(top, left, bottom, right); + } + + /** + * This method returns whether the border is opaque. + * + * @return Whether the border is opaque. + */ + public boolean isBorderOpaque() + { + return true; + } + + /** + * This method paints the border. + * + * @param c The Component the border is in. + * @param g The Graphics object to paint with. + * @param x The x coordinate of the Component. + * @param y The y coordinate of the Component. + * @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) + { + g.translate(x, y); + Color saved = g.getColor(); + + g.setColor(Color.LIGHT_GRAY); + + g.fillRect(0, 0, left, height); + g.fillRect(0, 0, width, top); + g.fillRect(0, height - bottom, width, bottom); + g.fillRect(width - right, 0, right, height); + + g.setColor(Color.BLACK); + g.drawRect(0, 0, width - 1, height - 1); + + int fHeight = height / 4; + int hLeft = left / 2; + + g.setColor(Color.BLACK); + g.fillRect(hLeft, fHeight, 2, 2); + g.fillRect(hLeft, fHeight * 2, 2, 2); + g.fillRect(hLeft, fHeight * 3, 2, 2); + + g.setColor(saved); + g.translate(-x, -y); + } + } + + /** The static width and height of the iconSize. */ + private static final int iconSize = 16; + + /** + * This class represents the default frame icon when none + * is supplied by the JInternalFrame. + */ + static class InternalFrameDefaultMenuIcon implements Icon + { + /** + * This returns the icon height. + * + * @return The icon height. + */ + public int getIconHeight() + { + return iconSize; + } + + /** + * This returns the icon width. + * + * @return The icon width. + */ + public int getIconWidth() + { + return iconSize; + } + + /** + * This method paints the icon. + * + * @param c The Component this icon belongs to. + * @param g The Graphics object to paint with. + * @param x The x coordinate to paint at. + * @param y The y coordinate to paint at. + */ + public void paintIcon(Component c, Graphics g, int x, int y) + { + g.translate(x, y); + Color saved = g.getColor(); + + g.setColor(Color.BLUE); + g.fillRect(0, 0, iconSize, (int) ((double) iconSize / 3) + 1); + + g.setColor(Color.WHITE); + g.fillRect(0, (int) ((double) iconSize / 3), iconSize, iconSize * 5 / 6); + + g.setColor(Color.GRAY); + g.drawRect(0, 0, iconSize, iconSize); + + g.setColor(saved); + g.translate(-x, -y); + } + } + + /** The default JDesktopIcon width. */ + private static final int iconWidth = 160; + + /** The default JDesktopIcon height */ + private static final int iconHeight = 35; + + /** The JDesktopIcon this UI delegate represents. */ + protected JDesktopIcon desktopIcon; + + /** The JInternalFrame associated with the JDesktopIcon. */ + protected JInternalFrame frame; + + /** The MouseListener responsible for reacting to MouseEvents on the JDesktopIcon. */ + private transient MouseInputListener mouseHandler; + + /** The Button in the JDesktopIcon responsible for deiconifying it. */ + private transient BoundButton button; + + /** The PropertyChangeListener listening to the JDesktopIcon. */ + private transient PropertyChangeListener propertyHandler; + + /** The default icon used when no frame icon is given by the JInternalFrame. */ + static Icon defaultIcon = new InternalFrameDefaultMenuIcon(); + + /** + * This is a helper class that is used in JDesktopIcon and gives the Button a predetermined size. + */ + private class BoundButton extends JButton + { + /** + * Creates a new BoundButton object. + * + * @param title The title of the button. + */ + public BoundButton(String title) + { + super(title); + } + + /** + * This method returns a standard size (based on the defaults of the JDesktopIcon) and the insets. + * + * @return The preferred size of the JDesktopIcon. + */ + public Dimension getPreferredSize() + { + Insets insets = desktopIcon.getInsets(); + return new Dimension(iconWidth - insets.left - insets.right, + iconHeight - insets.top - insets.bottom); + } + + /** + * This method returns the minimum size of the button. + * + * @return The minimum size of the button. + */ + public Dimension getMinimumSize() + { + return getPreferredSize(); + } + + /** + * This method returns the maximum size of the button. + * + * @return The maximum size of the button. + */ + public Dimension getMaximumSize() + { + return getPreferredSize(); + } + } + + /** + * Creates a new BasicDesktopIconUI object. + */ + public BasicDesktopIconUI() + { + } + + /** + * This method creates a new BasicDesktopIconUI for the given JComponent. + * + * @param c The JComponent to create a UI for. + * + * @return A new BasicDesktopIconUI. + */ + public static ComponentUI createUI(JComponent c) + { + return new BasicDesktopIconUI(); + } + + /** + * This method installs the UI for the given JComponent. + * + * @param c The JComponent to install this UI for. + */ + public void installUI(JComponent c) + { + if (c instanceof JDesktopIcon) + { + desktopIcon = (JDesktopIcon) c; + desktopIcon.setLayout(new BorderLayout()); + frame = desktopIcon.getInternalFrame(); + + installDefaults(); + installComponents(); + installListeners(); + + desktopIcon.setOpaque(true); + } + } + + /** + * This method uninstalls the UI for the given JComponent. + * + * @param c The JComponent to uninstall this UI for. + */ + public void uninstallUI(JComponent c) + { + desktopIcon.setOpaque(false); + + uninstallListeners(); + uninstallComponents(); + uninstallDefaults(); + + frame = null; + desktopIcon.setLayout(null); + desktopIcon = null; + } + + /** + * This method installs the necessary sub components for the JDesktopIcon. + */ + protected void installComponents() + { + // Try to create a button based on what the frame's + // state is currently + button = new BoundButton(frame.getTitle()); + button.setHorizontalAlignment(SwingConstants.LEFT); + button.setHorizontalTextPosition(SwingConstants.TRAILING); + + Icon use = frame.getFrameIcon(); + if (use == null) + use = defaultIcon; + button.setIcon(use); + + desktopIcon.add(button, SwingConstants.CENTER); + } + + /** + * This method uninstalls the sub components for the JDesktopIcon. + */ + protected void uninstallComponents() + { + desktopIcon.remove(button); + + button = null; + } + + /** + * This method installs the listeners needed by this UI. + */ + protected void installListeners() + { + mouseHandler = createMouseInputListener(); + + desktopIcon.addMouseMotionListener(mouseHandler); + desktopIcon.addMouseListener(mouseHandler); + + propertyHandler = new PropertyChangeListener() + { + public void propertyChange(PropertyChangeEvent e) + { + if (e.getPropertyName().equals(JInternalFrame.TITLE_PROPERTY)) + button.setText(desktopIcon.getInternalFrame().getTitle()); + else if (e.getPropertyName().equals(JInternalFrame.FRAME_ICON_PROPERTY)) + { + Icon use = desktopIcon.getInternalFrame().getFrameIcon(); + if (use == null) + use = defaultIcon; + button.setIcon(use); + } + desktopIcon.revalidate(); + desktopIcon.repaint(); + } + }; + frame.addPropertyChangeListener(propertyHandler); + + button.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + deiconize(); + } + }); + } + + /** + * This method uninstalls the listeners needed by the UI. + */ + protected void uninstallListeners() + { + // button is nulled so no need to remove it. + + frame.removePropertyChangeListener(propertyHandler); + propertyHandler = null; + + desktopIcon.removeMouseMotionListener(mouseHandler); + desktopIcon.removeMouseListener(mouseHandler); + } + + /** + * This method installs the defaults for the JDesktopIcon. + */ + protected void installDefaults() + { + // FIXME: Move border to defaults. + desktopIcon.setBorder(new DesktopIconBorder()); + } + + /** + * This method uninstalls the defaults for the JDesktopIcon. + */ + protected void uninstallDefaults() + { + desktopIcon.setBorder(null); + } + + /** + * This method creates a new MouseInputListener for the JDesktopIcon. + * + * @return A new MouseInputListener. + */ + protected MouseInputListener createMouseInputListener() + { + return new MouseInputHandler(); + } + + /** + * This method returns the preferred size for the given JComponent. + * + * @param c The JComponent to find a preferred size for. + * + * @return The preferred size. + */ + public Dimension getPreferredSize(JComponent c) + { + return new Dimension(iconWidth, iconHeight); + } + + /** + * This method returns the minimum size for the given JComponent. + * + * @param c The JComponent to find a minimum size for. + * + * @return The minimum size. + */ + public Dimension getMinimumSize(JComponent c) + { + return getPreferredSize(c); + } + + /** + * This method returns the maximum size for the given JComponent. + * + * @param c The JComponent to find a maximum size for. + * + * @return The maximum size. + */ + public Dimension getMaximumSize(JComponent c) + { + return getPreferredSize(c); + } + + /** + * This method returns the insets of the given JComponent. + * + * @param c The JComponent to find insets for. + * + * @return The insets of the given JComponent. + */ + public Insets getInsets(JComponent c) + { + return c.getInsets(); + } + + /** + * This method deiconizes the JInternalFrame associated with the JDesktopIcon. + */ + public void deiconize() + { + try + { + frame.setIcon(false); + } + catch (PropertyVetoException pve) + { + } + } +} diff --git a/libjava/javax/swing/plaf/basic/BasicDesktopPaneUI.java b/libjava/javax/swing/plaf/basic/BasicDesktopPaneUI.java new file mode 100644 index 00000000000..3d43b362636 --- /dev/null +++ b/libjava/javax/swing/plaf/basic/BasicDesktopPaneUI.java @@ -0,0 +1,459 @@ +/* BasicDesktopPaneUI.java -- + Copyright (C) 2004 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.swing.plaf.basic; + +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.Insets; +import java.awt.event.ActionEvent; +import java.awt.event.MouseEvent; +import java.beans.PropertyVetoException; +import javax.swing.AbstractAction; +import javax.swing.DefaultDesktopManager; +import javax.swing.DesktopManager; +import javax.swing.JComponent; +import javax.swing.JDesktopPane; +import javax.swing.JInternalFrame; +import javax.swing.JInternalFrame.JDesktopIcon; +import javax.swing.KeyStroke; +import javax.swing.UIDefaults; +import javax.swing.UIManager; +import javax.swing.event.MouseInputAdapter; +import javax.swing.event.MouseInputListener; +import javax.swing.plaf.ComponentUI; +import javax.swing.plaf.DesktopIconUI; +import javax.swing.plaf.DesktopPaneUI; + + +/** + * This class is the UI delegate for JDesktopPane for the Basic look and feel. + */ +public class BasicDesktopPaneUI extends DesktopPaneUI +{ + /** + * This helper class is used to handle key events that cause JInternalFrames + * to be closed. + */ + protected class CloseAction extends AbstractAction + { + /** + * This method is called when the action is performed. + * + * @param e The ActionEvent. + */ + public void actionPerformed(ActionEvent e) + { + if (desktop.getSelectedFrame() != null) + { + try + { + desktop.getSelectedFrame().setClosed(true); + } + catch (PropertyVetoException pve) + { + } + } + } + + /** + * This method returns whether the action is enabled. + * + * @return Whether the action is enabled. + */ + public boolean isEnabled() + { + if (desktop.getSelectedFrame() != null) + return desktop.getSelectedFrame().isClosable(); + return false; + } + } + + /** + * This helper class is used to handle key events that cause JInternalFrames + * to be maximized. + */ + protected class MaximizeAction extends AbstractAction + { + /** + * This method is called when the action is performed. + * + * @param e The ActionEvent. + */ + public void actionPerformed(ActionEvent e) + { + if (desktop.getSelectedFrame() != null) + { + try + { + desktop.getSelectedFrame().setMaximum(true); + } + catch (PropertyVetoException pve) + { + } + } + } + + /** + * This method returns whether the action is enabled. + * + * @return Whether the action is enabled. + */ + public boolean isEnabled() + { + if (desktop.getSelectedFrame() != null) + return desktop.getSelectedFrame().isMaximizable(); + return false; + } + } + + /** + * This helper class is used to handle key events that cause JInternalFrames + * to be minimized. + */ + protected class MinimizeAction extends AbstractAction + { + /** + * This method is called when the action is performed. + * + * @param e The ActionEvent. + */ + public void actionPerformed(ActionEvent e) + { + if (desktop.getSelectedFrame() != null) + { + try + { + desktop.getSelectedFrame().setIcon(true); + } + catch (PropertyVetoException pve) + { + } + } + } + + /** + * This method returns whether the action is enabled. + * + * @return Whether the action is enabled. + */ + public boolean isEnabled() + { + if (desktop.getSelectedFrame() != null) + return desktop.getSelectedFrame().isIconifiable(); + return false; + } + } + + /** + * This helper class is used to handle key events that pass the SELECTED + * property to the next JInternalFrame in the JDesktopPane's list of + * children. + */ + protected class NavigateAction extends AbstractAction + { + /** + * This method is called when the action is performed. + * + * @param e The ActionEvent. + */ + public void actionPerformed(ActionEvent e) + { + // This is supposed to set the next selected frame. + JInternalFrame[] frames = desktop.getAllFrames(); + if (frames.length == 0) + return; + + JInternalFrame sFrame = frames[0]; + if (desktop.getSelectedFrame() != null) + sFrame = desktop.getSelectedFrame(); + + int i = 0; + for (; i < frames.length; i++) + if (frames[i] == sFrame) + break; + + // FIXME: Navigate actions go reverse too. + if (i == frames.length) + i = 0; + + desktop.setSelectedFrame(frames[i]); + } + + /** + * This method returns whether the action is enabled. + * + * @return Whether this action is enabled. + */ + public boolean isEnabled() + { + // Always true. + return true; + } + } + + /** + * This helper class is used to restore the JInternalFrame to its original + * size before maximizing or iconifying. + */ + protected class OpenAction extends AbstractAction + { + /** + * This method is called when the action is performed. + * + * @param e The ActionEvent. + */ + public void actionPerformed(ActionEvent e) + { + JInternalFrame frame = desktop.getSelectedFrame(); + if (frame != null) + { + try + { + if (frame.isIcon()) + frame.setIcon(false); + else if (frame.isMaximum()) + frame.setMaximum(false); + } + catch (PropertyVetoException pve) + { + } + } + } + + /** + * This method returns whether the action is enabled. + * + * @return Whether this action is enabled. + */ + public boolean isEnabled() + { + // JInternalFrames are always restorable. + return true; + } + } + + /** The KeyStroke associated with closing JInternalFrames. */ + protected KeyStroke closeKey; + + /** The KeyStroke associated with maximizing JInternalFrames. */ + protected KeyStroke maximizeKey; + + /** The KeyStroke associated with minimizing JInternalFrames. */ + protected KeyStroke minimizeKey; + + /** + * The KeyStroke associated with navigating (forward?) through + * JInternalFrames. + */ + protected KeyStroke navigateKey; + + /** + * The KeyStroke associated with navigating (backward?) through + * JInternalFrames. + */ + protected KeyStroke navigateKey2; + + /** The default desktop manager used with JDesktopPane. */ + protected DesktopManager desktopManager; + + /** The JDesktopPane this UI is used with. */ + protected JDesktopPane desktop; + + /** + * Creates a new BasicDesktopPaneUI object. + */ + public BasicDesktopPaneUI() + { + } + + /** + * This method creates a BasicDesktopPaneUI for the given JComponent. + * + * @param c The JComponent to create a UI for. + * + * @return A new BasicDesktopPaneUI. + */ + public static ComponentUI createUI(JComponent c) + { + return new BasicDesktopPaneUI(); + } + + /** + * This method returns the maximum size for the given JComponent. + * + * @param c The JComponent to find a maximum size for. + * + * @return The maximum size for the given JComponent. + */ + public Dimension getMaximumSize(JComponent c) + { + return getPreferredSize(c); + } + + /** + * This method returns the minimum size for the given JComponent. + * + * @param c The JComponent to find a minimum size for. + * + * @return The minimum size for the given JComponent. + */ + public Dimension getMinimumSize(JComponent c) + { + return getPreferredSize(c); + } + + /** + * This method returns the preferred size for the given JComponent. + * + * @param c The JComponent to find a preferred size for. + * + * @return The preferred size for the given JComponent. + */ + public Dimension getPreferredSize(JComponent c) + { + // return null because JDesktopPanes don't have preferred sizes. + return null; + } + + /** + * This method installs the defaults for the JDesktopPane provided by the + * current look and feel. + */ + protected void installDefaults() + { + UIDefaults defaults = UIManager.getLookAndFeelDefaults(); + + desktop.setBackground(defaults.getColor("Desktop.background")); + } + + /** + * This method installs the desktop manager for the JDesktopPane. + */ + protected void installDesktopManager() + { + desktopManager = new DefaultDesktopManager(); + desktop.setDesktopManager(desktopManager); + } + + /** + * This method installs the keyboard actions for the JDesktopPane. + */ + protected void installKeyboardActions() + { + // FIXME: create actions and keystrokes. + registerKeyboardAction(); + } + + /** + * This method installs the UI for the given JComponent. + * + * @param c The JComponent to install this UI for. + */ + public void installUI(JComponent c) + { + if (c instanceof JDesktopPane) + { + desktop = (JDesktopPane) c; + + installDefaults(); + installDesktopManager(); + installKeyboardActions(); + } + } + + /** + * This method registers the actions to the appropriate Action and Input + * maps. + */ + protected void registerKeyboardAction() + { + // FIXME: Do the binding. + // XXX: the gtk windows tend to intercept a lot of the + // key events for themselves. must figure a way past that + // before binding + } + + /** + * This method reverses the work done by the installDefaults method. + */ + protected void uninstallDefaults() + { + desktop.setBackground(null); + } + + /** + * This method reverses the work done by the installDesktopManager method. + */ + protected void uninstallDesktopManager() + { + desktopManager = null; + desktop.setDesktopManager(null); + } + + /** + * This method reverses the work done by the installKeyboardActions method. + */ + protected void uninstallKeyboardActions() + { + unregisterKeyboardActions(); + // FIXME: null the actions and keystrokes. + } + + /** + * This method reverses the work done by the registerKeyboardActions method. + */ + protected void unregisterKeyboardActions() + { + // FIXME: unmap the keystrokes + } + + /** + * This method uninstalls the UI for the given JComponent. It should reverse + * all the work done by the installUI method. + * + * @param c The JComponent to uninstall this UI for. + */ + public void uninstallUI(JComponent c) + { + uninstallKeyboardActions(); + uninstallDesktopManager(); + uninstallDefaults(); + + desktop = null; + } +} diff --git a/libjava/javax/swing/plaf/basic/BasicInternalFrameTitlePane.java b/libjava/javax/swing/plaf/basic/BasicInternalFrameTitlePane.java new file mode 100644 index 00000000000..3b8a2a20ca2 --- /dev/null +++ b/libjava/javax/swing/plaf/basic/BasicInternalFrameTitlePane.java @@ -0,0 +1,1004 @@ +/* BasicInternalFrameTitlePane.java -- + Copyright (C) 2004 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.swing.plaf.basic; + +import java.awt.Color; +import java.awt.Component; +import java.awt.Container; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.FontMetrics; +import java.awt.Graphics; +import java.awt.Insets; +import java.awt.LayoutManager; +import java.awt.Polygon; +import java.awt.Rectangle; +import java.awt.event.ActionEvent; +import java.awt.event.KeyEvent; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.beans.PropertyVetoException; +import javax.swing.AbstractAction; +import javax.swing.Action; +import javax.swing.Icon; +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JInternalFrame; +import javax.swing.JLabel; +import javax.swing.JMenu; +import javax.swing.JMenuBar; +import javax.swing.JMenuItem; +import javax.swing.SwingConstants; +import javax.swing.SwingUtilities; +import javax.swing.event.InternalFrameEvent; +import javax.swing.UIManager; +import javax.swing.UIDefaults; + + +/** + * This class acts as a titlebar for JInternalFrames. + */ +public class BasicInternalFrameTitlePane extends JComponent +{ + /** + * The Action responsible for closing the JInternalFrame. + */ + protected class CloseAction extends AbstractAction + { + /** + * This method is called when something closes the JInternalFrame. + * + * @param e The ActionEvent. + */ + public void actionPerformed(ActionEvent e) + { + if (frame.isClosable()) + { + try + { + frame.setClosed(true); + } + catch (PropertyVetoException pve) + { + } + } + } + } + + /** + * This Action is responsible for iconifying the JInternalFrame. + */ + protected class IconifyAction extends AbstractAction + { + /** + * This method is called when the user wants to iconify the + * JInternalFrame. + * + * @param e The ActionEvent. + */ + public void actionPerformed(ActionEvent e) + { + if (frame.isIconifiable() && ! frame.isIcon()) + { + try + { + frame.setIcon(true); + } + catch (PropertyVetoException pve) + { + } + } + } + } + + /** + * This Action is responsible for maximizing the JInternalFrame. + */ + protected class MaximizeAction extends AbstractAction + { + /** + * This method is called when the user wants to maximize the + * JInternalFrame. + * + * @param e The ActionEvent. + */ + public void actionPerformed(ActionEvent e) + { + try + { + if (frame.isMaximizable() && ! frame.isMaximum()) + frame.setMaximum(true); + else if (frame.isMaximum()) + frame.setMaximum(false); + } + catch (PropertyVetoException pve) + { + } + } + } + + /** + * This Action is responsible for dragging the JInternalFrame. + */ + protected class MoveAction extends AbstractAction + { + /** + * This method is called when the user wants to drag the JInternalFrame. + * + * @param e The ActionEvent. + */ + public void actionPerformed(ActionEvent e) + { + // FIXME: Implement keyboard driven? move actions. + } + } + + /** + * This Action is responsible for restoring the JInternalFrame. Restoring + * the JInternalFrame is the same as setting the maximum property to false. + */ + protected class RestoreAction extends AbstractAction + { + /** + * This method is called when the user wants to restore the + * JInternalFrame. + * + * @param e The ActionEvent. + */ + public void actionPerformed(ActionEvent e) + { + if (frame.isMaximum()) + { + try + { + frame.setMaximum(false); + } + catch (PropertyVetoException pve) + { + } + } + } + } + + /** + * This action is responsible for sizing the JInternalFrame. + */ + protected class SizeAction extends AbstractAction + { + /** + * This method is called when the user wants to resize the JInternalFrame. + * + * @param e The ActionEvent. + */ + public void actionPerformed(ActionEvent e) + { + // FIXME: Not sure how size actions should be handled. + } + } + + /** + * This class is responsible for handling property change events from the + * JInternalFrame and adjusting the Title Pane as necessary. + */ + protected class PropertyChangeHandler implements PropertyChangeListener + { + /** + * This method is called when a PropertyChangeEvent is received by the + * Title Pane. + * + * @param evt The PropertyChangeEvent. + */ + public void propertyChange(PropertyChangeEvent evt) + { + // The title and frameIcon are taken care of during painting time. + // The only other thing this will care about are the "is----izable" + // properties. So we call enable actions to properly handle the + // buttons and menu items for us. + enableActions(); + } + } + + /** + * This class acts as the MenuBar for the TitlePane. Clicking on the Frame + * Icon in the top left corner will activate it. + */ + protected class SystemMenuBar extends JMenuBar + { + /** + * This method returns true if it can receive focus. + * + * @return True if this Component can receive focus. + */ + public boolean isFocusTransversable() + { + return true; + } + + /** + * This method returns true if this Component is expected to paint all of + * itself. + * + * @return True if this Component is expect to paint all of itself. + */ + public boolean isOpaque() + { + return true; + } + + /** + * This method paints this Component. + * + * @param g The Graphics object to paint with. + */ + public void paint(Graphics g) + { + Icon frameIcon = frame.getFrameIcon(); + if (frameIcon == null) + frameIcon = BasicDesktopIconUI.defaultIcon; + frameIcon.paintIcon(this, g, 0, 0); + } + + /** + * This method requests that focus be given to this Component. + */ + public void requestFocus() + { + super.requestFocus(); + } + } + + /** + * This class acts as the Layout Manager for the TitlePane. + */ + protected class TitlePaneLayout implements LayoutManager + { + /** + * This method is called when adding 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) + { + enableActions(); + + Insets insets = c.getInsets(); + int width = c.getBounds().width - insets.left - insets.right; + int height = c.getBounds().height - insets.top - insets.bottom; + + // MenuBar is always present and located at the top left corner. + Dimension menupref = menuBar.getPreferredSize(); + menuBar.setBounds(insets.left, insets.top, menupref.width, height); + + int loc = width + insets.left; + + Insets i = closeButton.getInsets(); + Dimension prefs = new Dimension(iconSize + i.left + i.right, + iconSize + i.top + i.bottom); + int top = insets.top + (height - prefs.height) / 2; + if (closeAction.isEnabled()) + { + loc -= prefs.width; + closeButton.setVisible(true); + closeButton.setBounds(loc, top, prefs.width, prefs.height); + } + else + closeButton.setVisible(false); + + if (maximizeAction.isEnabled()) + { + loc -= prefs.width; + maxButton.setVisible(true); + maxButton.setBounds(loc, top, prefs.width, prefs.height); + } + else + maxButton.setVisible(false); + + if (iconifyAction.isEnabled()) + { + loc -= prefs.width; + iconButton.setVisible(true); + iconButton.setBounds(loc, top, prefs.width, prefs.height); + } + else + iconButton.setVisible(false); + + if (title != null) + title.setBounds(insets.left + menupref.width, insets.top, + loc - menupref.width - insets.left, 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); + } + + /** + * This method 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) + { + Insets frameInsets = frame.getInsets(); + + // Height is the max of the preferredHeights of all components + // inside the pane + int height = 0; + int width = 0; + Dimension d; + + Component[] components = BasicInternalFrameTitlePane.this.getComponents(); + for (int i = 0; i < components.length; i++) + { + d = components[i].getPreferredSize(); + height = Math.max(height, d.height); + width += d.width; + } + + Insets insets = BasicInternalFrameTitlePane.this.getInsets(); + height += insets.top + insets.bottom; + + return new Dimension(width, height); + } + + /** + * This method is called when removing a Component from the Container. + * + * @param c The Component to remove. + */ + public void removeLayoutComponent(Component c) + { + } + } + + /** + * This helper class is used to create the minimize, maximize and close + * buttons in the top right corner of the Title Pane. These buttons are + * special since they cannot be given focus and have no border. + */ + private class PaneButton extends JButton + { + /** + * Creates a new PaneButton object with the given Action. + * + * @param a The Action that the button uses. + */ + public PaneButton(Action a) + { + super(a); + setMargin(new Insets(0, 0, 0, 0)); + setBorder(null); + } + + /** + * This method returns true if the Component can be focused. + * + * @return false. + */ + public boolean isFocusable() + { + // These buttons cannot be given focus. + return false; + } + } + + /** The action command for the Close action. */ + protected static String CLOSE_CMD = "Close"; + + /** The action command for the Minimize action. */ + protected static String ICONIFY_CMD = "Minimize"; + + /** The action command for the Maximize action. */ + protected static String MAXIMIZE_CMD = "Maximize"; + + /** The action command for the Move action. */ + protected static String MOVE_CMD = "Move"; + + /** The action command for the Restore action. */ + protected static String RESTORE_CMD = "Restore"; + + /** The action command for the Size action. */ + protected static String SIZE_CMD = "Size"; + + /** The action associated with closing the JInternalFrame. */ + protected Action closeAction; + + /** The action associated with iconifying the JInternalFrame. */ + protected Action iconifyAction; + + /** The action associated with maximizing the JInternalFrame. */ + protected Action maximizeAction; + + /** The action associated with moving the JInternalFrame. */ + protected Action moveAction; + + /** The action associated with restoring the JInternalFrame. */ + protected Action restoreAction; + + /** The action associated with resizing the JInternalFrame. */ + protected Action sizeAction; + + /** The button that closes the JInternalFrame. */ + protected JButton closeButton; + + /** The button that iconifies the JInternalFrame. */ + protected JButton iconButton; + + /** The button that maximizes the JInternalFrame. */ + protected JButton maxButton; + + /** Active background color. */ + protected Color activeBGColor; + + /** Active foreground color. */ + protected Color activeFGColor; + + /** Inactive background color. */ + protected Color inactiveBGColor; + + /** Inactive foreground color. */ + protected Color inactiveFGColor; + + // FIXME: These icons need to be moved to MetalIconFactory. + + /** The size of the icons in the buttons. */ + private static final int iconSize = 16; + + /** The icon displayed in the close button. */ + protected Icon closeIcon = new Icon() + { + public int getIconHeight() + { + return iconSize; + } + + public int getIconWidth() + { + return iconSize; + } + + public void paintIcon(Component c, Graphics g, int x, int y) + { + g.translate(x, y); + Color saved = g.getColor(); + g.setColor(Color.BLACK); + + int four = iconSize / 4; + int six = iconSize * 6 / 16; + int ten = iconSize * 10 / 16; + int twelve = iconSize * 12 / 16; + + Polygon a = new Polygon(new int[] { four, six, ten, twelve }, + new int[] { six, four, twelve, ten }, 4); + Polygon b = new Polygon(new int[] { four, six, ten, twelve }, + new int[] { ten, twelve, four, six }, 4); + + g.fillPolygon(a); + g.fillPolygon(b); + + g.setColor(saved); + g.translate(-x, -y); + } + }; + + // FIXME: Create new icon. + + /** The icon displayed in the restore button. */ + protected Icon minIcon; + + /** The icon displayed in the maximize button. */ + protected Icon maxIcon = new Icon() + { + public int getIconHeight() + { + return iconSize; + } + + public int getIconWidth() + { + return iconSize; + } + + public void paintIcon(Component c, Graphics g, int x, int y) + { + g.translate(x, y); + Color saved = g.getColor(); + g.setColor(Color.BLACK); + + int four = iconSize / 4; + int two = four / 2; + int six = iconSize * 6 / 16; + int eight = four * 2; + + g.fillRect(four, four, eight, two); + g.drawRect(four, six, eight, six); + + g.setColor(saved); + g.translate(-x, -y); + } + }; + + /** The icon displayed in the iconify button. */ + protected Icon iconIcon = new Icon() + { + public int getIconHeight() + { + return iconSize; + } + + public int getIconWidth() + { + return iconSize; + } + + public void paintIcon(Component c, Graphics g, int x, int y) + { + g.translate(x, y); + Color saved = g.getColor(); + g.setColor(Color.BLACK); + + g.fillRect(iconSize / 4, iconSize * 10 / 16, iconSize / 2, iconSize / 8); + + g.setColor(saved); + g.translate(-x, -y); + } + }; + + /** The JInternalFrame that this TitlePane is used in. */ + protected JInternalFrame frame; + + /** The JMenuBar that is located at the top left of the Title Pane. */ + protected JMenuBar menuBar; + + /** The JMenu inside the menuBar. */ + protected JMenu windowMenu; + + /** + * The text color of the TitlePane when the JInternalFrame is not selected. + */ + protected Color notSelectedTextColor; + + /** + * The background color of the TitlePane when the JInternalFrame is not + * selected. + */ + protected Color notSelectedTitleColor; + + /** The text color of the titlePane when the JInternalFrame is selected. */ + protected Color selectedTextColor; + + /** + * The background color of the TitlePane when the JInternalFrame is + * selected. + */ + protected Color selectedTitleColor; + + /** The Property Change listener that listens to the JInternalFrame. */ + protected PropertyChangeListener propertyChangeListener; + + /** + * The label used to display the title. This label is not added to the + * TitlePane. + */ + private transient JLabel title; + + /** + * Creates a new BasicInternalFrameTitlePane object that is used in the + * given JInternalFrame. + * + * @param f The JInternalFrame this BasicInternalFrameTitlePane will be used + * in. + */ + public BasicInternalFrameTitlePane(JInternalFrame f) + { + frame = f; + setLayout(createLayout()); + title = new JLabel(); + title.setHorizontalAlignment(SwingConstants.LEFT); + title.setHorizontalTextPosition(SwingConstants.LEFT); + title.setOpaque(false); + setOpaque(true); + + setBackground(Color.LIGHT_GRAY); + + installTitlePane(); + } + + /** + * This method installs the TitlePane onto the JInternalFrameTitlePane. It + * also creates any children components that need to be created and adds + * listeners to the appropriate components. + */ + protected void installTitlePane() + { + installDefaults(); + installListeners(); + createActions(); + + assembleSystemMenu(); + + createButtons(); + setButtonIcons(); + addSubComponents(); + enableActions(); + } + + /** + * This method adds the sub components to the TitlePane. + */ + protected void addSubComponents() + { + add(menuBar); + + add(closeButton); + add(iconButton); + add(maxButton); + } + + /** + * This method creates the actions that are used to manipulate the + * JInternalFrame. + */ + protected void createActions() + { + closeAction = new CloseAction(); + closeAction.putValue(AbstractAction.ACTION_COMMAND_KEY, CLOSE_CMD); + + iconifyAction = new IconifyAction(); + iconifyAction.putValue(AbstractAction.ACTION_COMMAND_KEY, ICONIFY_CMD); + + maximizeAction = new MaximizeAction(); + maximizeAction.putValue(AbstractAction.ACTION_COMMAND_KEY, MAXIMIZE_CMD); + + sizeAction = new SizeAction(); + sizeAction.putValue(AbstractAction.ACTION_COMMAND_KEY, SIZE_CMD); + + restoreAction = new RestoreAction(); + restoreAction.putValue(AbstractAction.ACTION_COMMAND_KEY, RESTORE_CMD); + + moveAction = new MoveAction(); + moveAction.putValue(AbstractAction.ACTION_COMMAND_KEY, MOVE_CMD); + } + + /** + * This method is used to install the listeners. + */ + protected void installListeners() + { + propertyChangeListener = new PropertyChangeHandler(); + frame.addPropertyChangeListener(propertyChangeListener); + } + + /** + * This method is used to uninstall the listeners. + */ + protected void uninstallListeners() + { + frame.removePropertyChangeListener(propertyChangeListener); + propertyChangeListener = null; + } + + /** + * This method installs the defaults determined by the look and feel. + */ + protected void installDefaults() + { + // FIXME: move icons to defaults. + UIDefaults defaults = UIManager.getLookAndFeelDefaults(); + + setFont(defaults.getFont("InternalFrame.titleFont")); + activeFGColor = defaults.getColor("InternalFrame.activeTitleForeground"); + activeBGColor = defaults.getColor("InternalFrame.activeTitleBackground"); + inactiveFGColor = defaults.getColor("InternalFrame.inactiveTitleForeground"); + inactiveBGColor = defaults.getColor("InternalFrame.inactiveTitleBackground"); + } + + /** + * This method uninstalls the defaults. + */ + protected void uninstallDefaults() + { + setFont(null); + activeFGColor = null; + activeBGColor = null; + inactiveFGColor = null; + inactiveBGColor = null; + } + + /** + * This method creates the buttons used in the TitlePane. + */ + protected void createButtons() + { + closeButton = new PaneButton(closeAction); + closeButton.setOpaque(false); + + iconButton = new PaneButton(iconifyAction); + iconButton.setOpaque(false); + + maxButton = new PaneButton(maximizeAction); + maxButton.setOpaque(false); + } + + /** + * This method sets the icons in the buttons. + */ + protected void setButtonIcons() + { + closeButton.setIcon(closeIcon); + iconButton.setIcon(iconIcon); + maxButton.setIcon(maxIcon); + } + + /** + * This method creates the MenuBar used in the TitlePane. + */ + protected void assembleSystemMenu() + { + menuBar = createSystemMenuBar(); + windowMenu = createSystemMenu(); + + menuBar.add(windowMenu); + + addSystemMenuItems(windowMenu); + enableActions(); + } + + /** + * This method adds the MenuItems to the given JMenu. + * + * @param systemMenu The JMenu to add MenuItems to. + */ + protected void addSystemMenuItems(JMenu systemMenu) + { + JMenuItem tmp; + + tmp = new JMenuItem(RESTORE_CMD); + tmp.addActionListener(restoreAction); + tmp.setMnemonic(KeyEvent.VK_R); + systemMenu.add(tmp); + + tmp = new JMenuItem(MOVE_CMD); + tmp.addActionListener(moveAction); + tmp.setMnemonic(KeyEvent.VK_M); + systemMenu.add(tmp); + + tmp = new JMenuItem(SIZE_CMD); + tmp.addActionListener(sizeAction); + tmp.setMnemonic(KeyEvent.VK_S); + systemMenu.add(tmp); + + tmp = new JMenuItem(ICONIFY_CMD); + tmp.addActionListener(iconifyAction); + tmp.setMnemonic(KeyEvent.VK_N); + systemMenu.add(tmp); + + tmp = new JMenuItem(MAXIMIZE_CMD); + tmp.addActionListener(maximizeAction); + tmp.setMnemonic(KeyEvent.VK_X); + systemMenu.add(tmp); + + systemMenu.addSeparator(); + + tmp = new JMenuItem(CLOSE_CMD); + tmp.addActionListener(closeAction); + tmp.setMnemonic(KeyEvent.VK_C); + systemMenu.add(tmp); + } + + /** + * This method creates a new JMenubar. + * + * @return A new JMenuBar. + */ + protected JMenuBar createSystemMenuBar() + { + if (menuBar == null) + menuBar = new SystemMenuBar(); + menuBar.removeAll(); + return menuBar; + } + + /** + * This method creates a new JMenu. + * + * @return A new JMenu. + */ + protected JMenu createSystemMenu() + { + if (windowMenu == null) + windowMenu = new JMenu(); + windowMenu.removeAll(); + return windowMenu; + } + + /** + * This method programmatically shows the JMenu. + */ + protected void showSystemMenu() + { + // FIXME: Untested as KeyEvents are not hooked up. + menuBar.getMenu(1).getPopupMenu().show(); + } + + /** + * This method paints the TitlePane. + * + * @param g The Graphics object to paint with. + */ + 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(); + if (frame.isSelected()) + g.setColor(activeFGColor); + else + g.setColor(inactiveFGColor); + title.setText(getTitle(frame.getTitle(), fm, title.getBounds().width)); + SwingUtilities.paintComponent(g, title, null, title.getBounds()); + g.setColor(saved); + } + } + + /** + * This method paints the TitlePane's background. + * + * @param g The Graphics object to paint with. + */ + protected void paintTitleBackground(Graphics g) + { + Color saved = g.getColor(); + Dimension dims = getSize(); + + Color bg = getBackground(); + if (frame.isSelected()) + bg = activeBGColor; + else + bg = inactiveBGColor; + g.setColor(bg); + g.fillRect(0, 0, dims.width, dims.height); + g.setColor(saved); + } + + /** + * This method returns the title string based on the available width and the + * font metrics. + * + * @param text The desired title. + * @param fm The FontMetrics of the font used. + * @param availableWidth The available width. + * + * @return The allowable string. + */ + protected String getTitle(String text, FontMetrics fm, int availableWidth) + { + Rectangle vr = new Rectangle(0, 0, availableWidth, fm.getHeight()); + Rectangle ir = new Rectangle(); + Rectangle tr = new Rectangle(); + String value = SwingUtilities.layoutCompoundLabel(this, fm, text, null, + SwingConstants.CENTER, + SwingConstants.LEFT, + SwingConstants.CENTER, + SwingConstants.LEFT, vr, + ir, tr, 0); + return value; + } + + /** + * This method fires something similar to a WINDOW_CLOSING event. + * + * @param frame The JInternalFrame that is being closed. + */ + protected void postClosingEvent(JInternalFrame frame) + { + // FIXME: Implement postClosingEvent when I figure out what + // it's supposed to do. + // It says that this fires an WINDOW_CLOSING like event. + // So the closest thing is some kind of InternalFrameEvent. + // But none is fired. + // Can't see it called or anything. + } + + /** + * This method enables the actions for the TitlePane given the frame's + * properties. + */ + protected void enableActions() + { + closeAction.setEnabled(frame.isClosable()); + + iconifyAction.setEnabled(frame.isIconifiable()); + // The maximize action is responsible for restoring it + // as well, if clicked from the button + maximizeAction.setEnabled(frame.isMaximizable()); + + // The restoring action is only active when selected + // from the menu. + restoreAction.setEnabled(frame.isMaximum()); + + sizeAction.setEnabled(frame.isResizable()); + + // FIXME: Tie MoveAction enabled status to a variable. + moveAction.setEnabled(false); + } + + /** + * This method creates a new PropertyChangeListener. + * + * @return A new PropertyChangeListener. + */ + protected PropertyChangeListener createPropertyChangeListener() + { + return new PropertyChangeHandler(); + } + + /** + * This method creates a new LayoutManager for the TitlePane. + * + * @return A new LayoutManager. + */ + protected LayoutManager createLayout() + { + return new TitlePaneLayout(); + } +} diff --git a/libjava/javax/swing/plaf/basic/BasicInternalFrameUI.java b/libjava/javax/swing/plaf/basic/BasicInternalFrameUI.java new file mode 100644 index 00000000000..5c598b763ce --- /dev/null +++ b/libjava/javax/swing/plaf/basic/BasicInternalFrameUI.java @@ -0,0 +1,1488 @@ +/* BasicInternalFrameUI.java -- + Copyright (C) 2004 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.swing.plaf.basic; + +import java.awt.Color; +import java.awt.Component; +import java.awt.Container; +import java.awt.Dimension; +import java.awt.FontMetrics; +import java.awt.Graphics; +import java.awt.Insets; +import java.awt.LayoutManager; +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.event.ActionEvent; +import java.awt.event.ComponentEvent; +import java.awt.event.ComponentListener; +import java.awt.event.KeyEvent; +import java.awt.event.MouseEvent; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import javax.swing.AbstractAction; +import javax.swing.Action; +import javax.swing.DefaultDesktopManager; +import javax.swing.DesktopManager; +import javax.swing.Icon; +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JDesktopPane; +import javax.swing.JInternalFrame; +import javax.swing.JLabel; +import javax.swing.KeyStroke; +import javax.swing.SwingConstants; +import javax.swing.SwingUtilities; +import javax.swing.border.AbstractBorder; +import javax.swing.event.InternalFrameEvent; +import javax.swing.event.InternalFrameListener; +import javax.swing.event.MouseInputAdapter; +import javax.swing.event.MouseInputListener; +import javax.swing.plaf.ComponentUI; +import javax.swing.plaf.InternalFrameUI; +import javax.swing.plaf.UIResource; + + +/** + * This is the UI delegate for the Basic look and feel for JInternalFrames. + */ +public class BasicInternalFrameUI extends InternalFrameUI +{ + /** + * This is a helper class that listens to the JInternalFrame for + * InternalFrameEvents. + */ + protected class BasicInternalFrameListener implements InternalFrameListener + { + /** + * This method is called when the JInternalFrame is activated. + * + * @param e The InternalFrameEvent. + */ + public void internalFrameActivated(InternalFrameEvent e) + { + // FIXME: Implement. + } + + /** + * This method is called when the JInternalFrame is closed. + * + * @param e The InternalFrameEvent. + */ + public void internalFrameClosed(InternalFrameEvent e) + { + // FIXME: Implement. + } + + /** + * This method is called when the JInternalFrame is closing. + * + * @param e The InternalFrameEvent. + */ + public void internalFrameClosing(InternalFrameEvent e) + { + // FIXME: Implement. + } + + /** + * This method is called when the JInternalFrame is deactivated. + * + * @param e The InternalFrameEvent. + */ + public void internalFrameDeactivated(InternalFrameEvent e) + { + // FIXME: Implement. + } + + /** + * This method is called when the JInternalFrame is deiconified. + * + * @param e The InternalFrameEvent. + */ + public void internalFrameDeiconified(InternalFrameEvent e) + { + // FIXME: Implement. + } + + /** + * This method is called when the JInternalFrame is iconified. + * + * @param e The InternalFrameEvent. + */ + public void internalFrameIconified(InternalFrameEvent e) + { + // FIXME: Implement. + } + + /** + * This method is called when the JInternalFrame is opened. + * + * @param e The InternalFrameEvent. + */ + public void internalFrameOpened(InternalFrameEvent e) + { + // FIXME: Implement. + } + } + + /** + * This helper class listens to the edges of the JInternalFrame and the + * TitlePane for mouse events. It is responsible for dragging and resizing + * the JInternalFrame in response to the MouseEvents. + */ + protected class BorderListener extends MouseInputAdapter + implements SwingConstants + { + /** FIXME: Use for something. */ + protected int RESIZE_NONE; + + /** The x offset from the top left corner of the JInternalFrame. */ + private transient int xOffset = 0; + + /** The y offset from the top left corner of the JInternalFrame. */ + private transient int yOffset = 0; + + /** The direction that the resize is occuring in. */ + private transient int direction = -1; + + /** + * This method is called when the mouse is clicked. + * + * @param e The MouseEvent. + */ + public void mouseClicked(MouseEvent e) + { + // There is nothing to do when the mouse is clicked + // on the border. + } + + /** + * This method is called when the mouse is dragged. This method is + * responsible for resizing or dragging the JInternalFrame. + * + * @param e The MouseEvent. + */ + public void mouseDragged(MouseEvent e) + { + // If the frame is maximized, there is nothing that + // can be dragged around. + if (frame.isMaximum()) + return; + DesktopManager dm = getDesktopManager(); + Rectangle b = frame.getBounds(); + Insets insets = frame.getInsets(); + int x = e.getX(); + int y = e.getY(); + if (e.getSource() == frame && frame.isResizable()) + { + switch (direction) + { + case NORTH: + dm.resizeFrame(frame, b.x, b.y + y, b.width, b.height - y); + break; + case NORTH_EAST: + dm.resizeFrame(frame, b.x, b.y + y, x, b.height - y); + break; + case EAST: + dm.resizeFrame(frame, b.x, b.y, x, b.height); + break; + case SOUTH_EAST: + dm.resizeFrame(frame, b.x, b.y, x, y); + break; + case SOUTH: + dm.resizeFrame(frame, b.x, b.y, b.width, y); + break; + case SOUTH_WEST: + dm.resizeFrame(frame, b.x + x, b.y, b.width - x, y); + break; + case WEST: + dm.resizeFrame(frame, b.x + x, b.y, b.width - x, b.height); + break; + case NORTH_WEST: + dm.resizeFrame(frame, b.x + x, b.y + y, b.width - x, b.height + - y); + break; + } + } + else if (e.getSource() == titlePane) + { + Rectangle fBounds = frame.getBounds(); + + dm.dragFrame(frame, e.getX() - xOffset + b.x, + e.getY() - yOffset + b.y); + } + } + + /** + * This method is called when the mouse exits the JInternalFrame. + * + * @param e The MouseEvent. + */ + public void mouseExited(MouseEvent e) + { + // There is nothing to do when the mouse exits + // the border area. + } + + /** + * This method is called when the mouse is moved inside the + * JInternalFrame. + * + * @param e The MouseEvent. + */ + public void mouseMoved(MouseEvent e) + { + // There is nothing to do when the mouse moves + // over the border area. + } + + /** + * This method is called when the mouse is pressed. + * + * @param e The MouseEvent. + */ + public void mousePressed(MouseEvent e) + { + activateFrame(frame); + DesktopManager dm = getDesktopManager(); + int x = e.getX(); + int y = e.getY(); + Insets insets = frame.getInsets(); + + if (e.getSource() == frame && frame.isResizable()) + { + direction = sectionOfClick(x, y); + dm.beginResizingFrame(frame, direction); + } + else if (e.getSource() == titlePane) + { + Rectangle tBounds = titlePane.getBounds(); + + xOffset = e.getX() - tBounds.x + insets.left; + yOffset = e.getY() - tBounds.y + insets.top; + + dm.beginDraggingFrame(frame); + } + } + + /** + * This method is called when the mouse is released. + * + * @param e The MouseEvent. + */ + public void mouseReleased(MouseEvent e) + { + DesktopManager dm = getDesktopManager(); + xOffset = 0; + yOffset = 0; + if (e.getSource() == frame && frame.isResizable()) + dm.endResizingFrame(frame); + else if (e.getSource() == titlePane) + dm.endDraggingFrame(frame); + } + + /** + * This method determines the direction of the resize based on the + * coordinates and the size of the JInternalFrame. + * + * @param x The x coordinate of the MouseEvent. + * @param y The y coordinate of the MouseEvent. + * + * @return The direction of the resize (a SwingConstant direction). + */ + private int sectionOfClick(int x, int y) + { + Insets insets = frame.getInsets(); + Rectangle b = frame.getBounds(); + if (x < insets.left && y < insets.top) + return NORTH_WEST; + else if (x > b.width - insets.right && y < insets.top) + return NORTH_EAST; + else if (x > b.width - insets.right && y > b.height - insets.bottom) + return SOUTH_EAST; + else if (x < insets.left && y > b.height - insets.bottom) + return SOUTH_WEST; + else if (y < insets.top) + return NORTH; + else if (x < insets.left) + return WEST; + else if (y > b.height - insets.bottom) + return SOUTH; + else if (x > b.width - insets.right) + return EAST; + + return -1; + } + } + + /** + * This helper class listens to the JDesktopPane that parents this + * JInternalFrame and listens for resize events and resizes the + * JInternalFrame appropriately. + */ + protected class ComponentHandler implements ComponentListener + { + /** + * This method is called when the JDesktopPane is hidden. + * + * @param e The ComponentEvent fired. + */ + public void componentHidden(ComponentEvent e) + { + // Do nothing. + } + + /** + * This method is called when the JDesktopPane is moved. + * + * @param e The ComponentEvent fired. + */ + public void componentMoved(ComponentEvent e) + { + // Do nothing. + } + + /** + * This method is called when the JDesktopPane is resized. + * + * @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(); + } + + // Sun also resizes the icons. but it doesn't seem to do anything. + } + + /** + * This method is called when the JDesktopPane is shown. + * + * @param e The ComponentEvent fired. + */ + public void componentShown(ComponentEvent e) + { + // Do nothing. + } + } + + /** + * This helper class acts as the LayoutManager for JInternalFrames. + */ + public class InternalFrameLayout implements LayoutManager + { + /** + * 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. + */ + public void addLayoutComponent(String name, Component c) + { + } + + /** + * This method is used to set the bounds of the children of the + * JInternalFrame. + * + * @param c The Container to lay out. + */ + public void layoutContainer(Container c) + { + Dimension dims = frame.getSize(); + Insets insets = frame.getInsets(); + + dims.width -= insets.left + insets.right; + dims.height -= insets.top + insets.bottom; + + frame.getRootPane().getGlassPane().setBounds(0, 0, dims.width, + dims.height); + int nh = 0; + int sh = 0; + int ew = 0; + int ww = 0; + + if (northPane != null) + { + Dimension nDims = northPane.getPreferredSize(); + nh = Math.min(nDims.height, dims.height); + + northPane.setBounds(insets.left, insets.top, dims.width, nh); + } + + if (southPane != null) + { + Dimension sDims = southPane.getPreferredSize(); + sh = Math.min(sDims.height, dims.height - nh); + + 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); + + westPane.setBounds(insets.left, insets.top + nh, ww, remHeight); + } + + if (eastPane != null) + { + Dimension eDims = eastPane.getPreferredSize(); + ew = Math.min(eDims.width, dims.width - ww); + + eastPane.setBounds(insets.left + dims.width - ew, insets.top + nh, + ew, remHeight); + } + + int remWidth = dims.width - ww - ew; + + frame.getRootPane().setBounds(insets.left + ww, insets.top + nh, + remWidth, remHeight); + } + + /** + * This method returns the minimum layout size. + * + * @param c The Container to find a minimum layout size for. + * + * @return The minimum dimensions for the JInternalFrame. + */ + public Dimension minimumLayoutSize(Container c) + { + return preferredLayoutSize(c); + } + + /** + * This method returns the maximum layout size. + * + * @param c The Container to find a maximum layout size for. + * + * @return The maximum dimensions for the JInternalFrame. + */ + public Dimension maximumLayoutSize(Container c) + { + return preferredLayoutSize(c); + } + + /** + * Th8is method returns the preferred layout size. + * + * @param c The Container to find a preferred layout size for. + * + * @return The preferred dimensions for the JInternalFrame. + */ + public Dimension preferredLayoutSize(Container c) + { + Insets insets = frame.getInsets(); + + Dimension contentDims = frame.getContentPane().getPreferredSize(); + int nWidth = 0; + int nHeight = 0; + int sWidth = 0; + int sHeight = 0; + int eWidth = 0; + int eHeight = 0; + int wWidth = 0; + int wHeight = 0; + Dimension dims; + + if (northPane != null) + { + 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; + } + } + + if (eastPane != null) + { + 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; + } + } + + int width = Math.max(sWidth, nWidth); + width = Math.max(width, contentDims.width + eWidth + wWidth); + + int height = Math.max(contentDims.height, eHeight); + height = Math.max(height, wHeight); + height += nHeight + sHeight; + + width += insets.left + insets.right; + height += insets.top + insets.bottom; + + return new Dimension(width, height); + } + + /** + * This method is called when a Component is removed from the + * JInternalFrame. + * + * @param c The Component that was removed. + */ + public void removeLayoutComponent(Component c) + { + } + } + + /** + * This helper class is used to listen to the JDesktopPane's glassPane for + * MouseEvents. The JInternalFrame can then be selected if a click is + * detected on its children. + */ + protected class GlassPaneDispatcher implements MouseInputListener + { + /** + * This method is called when the mouse enters the glass pane. + * + * @param e The MouseEvent. + */ + public void mouseEntered(MouseEvent e) + { + dispatchFor(e); + } + + /** + * This method is called when the mouse is clicked on the glass pane. + * + * @param e The MouseEvent. + */ + public void mouseClicked(MouseEvent e) + { + dispatchFor(e); + } + + /** + * This method is called when the mouse is dragged in the glass pane. + * + * @param e The MouseEvent. + */ + public void mouseDragged(MouseEvent e) + { + dispatchFor(e); + } + + /** + * This method is called when the mouse exits the glass pane. + * + * @param e The MouseEvent. + */ + public void mouseExited(MouseEvent e) + { + dispatchFor(e); + } + + /** + * This method is called when the mouse is moved in the glass pane. + * + * @param e The MouseEvent. + */ + public void mouseMoved(MouseEvent e) + { + dispatchFor(e); + } + + /** + * This method is called when the mouse is pressed in the glass pane. + * + * @param e The MouseEvent. + */ + public void mousePressed(MouseEvent e) + { + activateFrame(frame); + dispatchFor(e); + } + + /** + * This method is called when the mouse is released in the glass pane. + * + * @param e The MouseEvent. + */ + public void mouseReleased(MouseEvent e) + { + dispatchFor(e); + } + + /** + * This helper method redispatches the MouseEvent to the proper sub + * component. + * + * @param e The MouseEvent. + */ + private void dispatchFor(MouseEvent e) + { + Component candidate = SwingUtilities.getDeepestComponentAt(frame.getRootPane() + .getContentPane(), + e.getX(), + e.getY()); + if (candidate == null || candidate == frame.getRootPane().getGlassPane()) + return; + MouseEvent newevt = SwingUtilities.convertMouseEvent(frame.getRootPane() + .getGlassPane(), + e, candidate); + candidate.dispatchEvent(newevt); + } + } + + /** + * This helper class listens for PropertyChangeEvents from the + * JInternalFrame. + */ + public class InternalFramePropertyChangeListener + implements PropertyChangeListener + { + /** + * 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); + } + else if (evt.getPropertyName().equals(JInternalFrame.IS_CLOSED_PROPERTY)) + closeFrame(frame); + else if (evt.getPropertyName().equals(JInternalFrame.IS_ICON_PROPERTY)) + { + 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); + } + else if (evt.getPropertyName().equals(JInternalFrame.ROOT_PANE_PROPERTY) + || evt.getPropertyName().equals(JInternalFrame.GLASS_PANE_PROPERTY)) + { + Component old = (Component) evt.getOldValue(); + old.removeMouseListener(glassPaneDispatcher); + old.removeMouseMotionListener(glassPaneDispatcher); + + Component newPane = (Component) evt.getNewValue(); + newPane.addMouseListener(glassPaneDispatcher); + newPane.addMouseMotionListener(glassPaneDispatcher); + + 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); + } + */ + } + } + + /** + * This helper class is the border for the JInternalFrame. + */ + private class InternalFrameBorder extends AbstractBorder + implements UIResource + { + /** The width of the border. */ + private static final int bSize = 5; + + /** The size of the corners. */ + private static final int offset = 10; + + /** + * This method returns whether the border is opaque. + * + * @return Whether the border is opaque. + */ + public boolean isBorderOpaque() + { + return true; + } + + /** + * This method returns the insets of the border. + * + * @param c The Component to find border insets for. + * + * @return The border insets. + */ + public Insets getBorderInsets(Component c) + { + return new Insets(bSize, bSize, bSize, bSize); + } + + /** + * 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. + */ + public void paintBorder(Component c, Graphics g, int x, int y, int width, + int height) + { + g.translate(x, y); + Color saved = g.getColor(); + Rectangle b = frame.getBounds(); + + Color d = c.getBackground(); + g.setColor(d); + g.fillRect(0, 0, bSize, b.height); + g.fillRect(0, 0, b.width, bSize); + g.fillRect(0, b.height - bSize, b.width, bSize); + g.fillRect(b.width - bSize, 0, bSize, b.height); + + int x1 = 0; + int x2 = bSize; + int x3 = b.width - bSize; + int x4 = b.width; + + int y1 = 0; + int y2 = bSize; + int y3 = b.height - bSize; + int y4 = b.height; + + g.setColor(Color.GRAY); + g.fillRect(0, 0, bSize, y4); + g.fillRect(0, 0, x4, bSize); + g.fillRect(0, y3, b.width, bSize); + g.fillRect(x3, 0, bSize, b.height); + + g.fill3DRect(0, offset, bSize, b.height - 2 * offset, false); + g.fill3DRect(offset, 0, b.width - 2 * offset, bSize, false); + g.fill3DRect(offset, b.height - bSize, b.width - 2 * offset, bSize, false); + g.fill3DRect(b.width - bSize, offset, bSize, b.height - 2 * offset, false); + + g.translate(-x, -y); + g.setColor(saved); + } + } + + /** + * The MouseListener that is responsible for dragging and resizing the + * JInternalFrame in response to MouseEvents. + */ + protected MouseInputAdapter borderListener; + + /** + * The ComponentListener that is responsible for resizing the JInternalFrame + * in response to ComponentEvents from the JDesktopPane. + */ + protected ComponentListener componentListener; + + /** + * The MouseListener that is responsible for activating the JInternalFrame + * when the mouse press activates one of its descendents. + */ + protected MouseInputListener glassPaneDispatcher; + + /** + * The PropertyChangeListener that is responsible for listening to + * PropertyChangeEvents from the JInternalFrame. + */ + protected PropertyChangeListener propertyChangeListener; + + /** The InternalFrameListener that listens to the JInternalFrame. */ + private transient BasicInternalFrameListener internalFrameListener; + + /** The JComponent placed at the east region of the JInternalFrame. */ + protected JComponent eastPane; + + /** The JComponent placed at the north region of the JInternalFrame. */ + protected JComponent northPane; + + /** The JComponent placed at the south region of the JInternalFrame. */ + protected JComponent southPane; + + /** The JComponent placed at the west region of the JInternalFrame. */ + protected JComponent westPane; + + /** The Keystroke bound to open the menu. */ + protected KeyStroke openMenuKey; + + /** The TitlePane displayed at the top of the JInternalFrame. */ + protected BasicInternalFrameTitlePane titlePane; + + /** The JInternalFrame this UI is responsible for. */ + protected JInternalFrame frame; + + /** The LayoutManager used in the JInternalFrame. */ + protected LayoutManager internalFrameLayout; + + /** The JDesktopPane that is the parent of the JInternalFrame. */ + private transient JDesktopPane desktopPane; + + /** + * Creates a new BasicInternalFrameUI object. + * + * @param b The JInternalFrame this UI will represent. + */ + public BasicInternalFrameUI(JInternalFrame b) + { + } + + /** + * This method will create a new BasicInternalFrameUI for the given + * JComponent. + * + * @param b The JComponent to create a BasicInternalFrameUI for. + * + * @return A new BasicInternalFrameUI. + */ + public static ComponentUI createUI(JComponent b) + { + return new BasicInternalFrameUI((JInternalFrame) b); + } + + /** + * This method installs a UI for the JInternalFrame. + * + * @param c The JComponent to install this UI on. + */ + public void installUI(JComponent c) + { + if (c instanceof JInternalFrame) + { + frame = (JInternalFrame) c; + + internalFrameLayout = createLayoutManager(); + frame.setLayout(internalFrameLayout); + + ((JComponent) frame.getRootPane().getGlassPane()).setOpaque(false); + frame.getRootPane().getGlassPane().setVisible(true); + + installDefaults(); + installListeners(); + installComponents(); + installKeyboardActions(); + + frame.setOpaque(true); + titlePane.setOpaque(true); + frame.invalidate(); + } + } + + /** + * This method reverses the work done by installUI. + * + * @param c The JComponent to uninstall this UI for. + */ + public void uninstallUI(JComponent c) + { + uninstallKeyboardActions(); + uninstallComponents(); + uninstallListeners(); + uninstallDefaults(); + + frame.setLayout(null); + ((JComponent) frame.getRootPane().getGlassPane()).setOpaque(true); + frame.getRootPane().getGlassPane().setVisible(false); + + frame = null; + } + + /** + * This method installs the defaults specified by the look and feel. + */ + protected void installDefaults() + { + // FIXME: Move border to MetalBorders + frame.setBorder(new InternalFrameBorder()); + } + + /** + * This method installs the keyboard actions for the JInternalFrame. + */ + protected void installKeyboardActions() + { + // FIXME: Implement. + } + + /** + * This method installs the Components for the JInternalFrame. + */ + protected void installComponents() + { + setNorthPane(createNorthPane(frame)); + setSouthPane(createSouthPane(frame)); + setEastPane(createEastPane(frame)); + setWestPane(createWestPane(frame)); + } + + /** + * This method installs the listeners for the JInternalFrame. + */ + protected void installListeners() + { + glassPaneDispatcher = createGlassPaneDispatcher(); + createInternalFrameListener(); + borderListener = createBorderListener(frame); + componentListener = createComponentListener(); + propertyChangeListener = createPropertyChangeListener(); + + frame.addMouseListener(borderListener); + frame.addMouseMotionListener(borderListener); + frame.addInternalFrameListener(internalFrameListener); + frame.addPropertyChangeListener(propertyChangeListener); + + frame.getRootPane().getGlassPane().addMouseListener(glassPaneDispatcher); + frame.getRootPane().getGlassPane().addMouseMotionListener(glassPaneDispatcher); + } + + /** + * This method uninstalls the defaults for the JInternalFrame. + */ + protected void uninstallDefaults() + { + frame.setBorder(null); + } + + /** + * This method uninstalls the Components for the JInternalFrame. + */ + protected void uninstallComponents() + { + setNorthPane(null); + setSouthPane(null); + setEastPane(null); + setWestPane(null); + } + + /** + * This method uninstalls the listeners for the JInternalFrame. + */ + protected void uninstallListeners() + { + if (desktopPane != null) + desktopPane.removeComponentListener(componentListener); + + frame.getRootPane().getGlassPane().removeMouseMotionListener(glassPaneDispatcher); + frame.getRootPane().getGlassPane().removeMouseListener(glassPaneDispatcher); + + frame.removePropertyChangeListener(propertyChangeListener); + frame.removeInternalFrameListener(internalFrameListener); + frame.removeMouseMotionListener(borderListener); + frame.removeMouseListener(borderListener); + + propertyChangeListener = null; + componentListener = null; + borderListener = null; + internalFrameListener = null; + glassPaneDispatcher = null; + } + + /** + * This method uninstalls the keyboard actions for the JInternalFrame. + */ + protected void uninstallKeyboardActions() + { + // FIXME: Implement. + } + + /** + * This method creates a new LayoutManager for the JInternalFrame. + * + * @return A new LayoutManager for the JInternalFrame. + */ + protected LayoutManager createLayoutManager() + { + return new InternalFrameLayout(); + } + + /** + * This method creates a new PropertyChangeListener for the JInternalFrame. + * + * @return A new PropertyChangeListener for the JInternalFrame. + */ + protected PropertyChangeListener createPropertyChangeListener() + { + return new InternalFramePropertyChangeListener(); + } + + /** + * This method returns the preferred size of the given JComponent. + * + * @param x The JComponent to find a preferred size for. + * + * @return The preferred size. + */ + public Dimension getPreferredSize(JComponent x) + { + return internalFrameLayout.preferredLayoutSize(x); + } + + /** + * This method returns the minimum size of the given JComponent. + * + * @param x The JComponent to find a minimum size for. + * + * @return The minimum size. + */ + public Dimension getMinimumSize(JComponent x) + { + return getPreferredSize(x); + } + + /** + * This method returns the maximum size of the given JComponent. + * + * @param x The JComponent to find a maximum size for. + * + * @return The maximum size. + */ + public Dimension getMaximumSize(JComponent x) + { + return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE); + } + + /** + * This method replaces the currentPane with the newPane. When replacing it + * also removes the MouseHandlers for the old pane and installs them on + * the new pane. + * + * @param currentPane The old pane to remove. + * @param newPane The new pane to install. + */ + protected void replacePane(JComponent currentPane, JComponent newPane) + { + if (currentPane != null) + { + deinstallMouseHandlers(currentPane); + frame.remove(currentPane); + } + + if (newPane != null) + { + installMouseHandlers(newPane); + frame.add(newPane); + } + } + + /** + * This method removes the necessary MouseListeners from the given + * JComponent. + * + * @param c The JComponent to remove MouseListeners from. + */ + protected void deinstallMouseHandlers(JComponent c) + { + c.removeMouseListener(borderListener); + c.removeMouseMotionListener(borderListener); + } + + /** + * This method installs the necessary MouseListeners from the given + * JComponent. + * + * @param c The JComponent to install MouseListeners on. + */ + protected void installMouseHandlers(JComponent c) + { + c.addMouseListener(borderListener); + c.addMouseMotionListener(borderListener); + } + + /** + * This method creates the north pane used in the JInternalFrame. + * + * @param w The JInternalFrame to create a north pane for. + * + * @return The north pane. + */ + protected JComponent createNorthPane(JInternalFrame w) + { + titlePane = new BasicInternalFrameTitlePane(w); + return titlePane; + } + + /** + * This method creates the west pane used in the JInternalFrame. + * + * @param w The JInternalFrame to create a west pane for. + * + * @return The west pane. + */ + protected JComponent createWestPane(JInternalFrame w) + { + return null; + } + + /** + * This method creates the south pane used in the JInternalFrame. + * + * @param w The JInternalFrame to create a south pane for. + * + * @return The south pane. + */ + protected JComponent createSouthPane(JInternalFrame w) + { + return null; + } + + /** + * This method creates the east pane used in the JInternalFrame. + * + * @param w The JInternalFrame to create an east pane for. + * + * @return The east pane. + */ + protected JComponent createEastPane(JInternalFrame w) + { + return null; + } + + /** + * This method returns a new BorderListener for the given JInternalFrame. + * + * @param w The JIntenalFrame to create a BorderListener for. + * + * @return A new BorderListener. + */ + protected MouseInputAdapter createBorderListener(JInternalFrame w) + { + return new BorderListener(); + } + + /** + * This method creates a new InternalFrameListener for the JInternalFrame. + */ + protected void createInternalFrameListener() + { + internalFrameListener = new BasicInternalFrameListener(); + } + + /** + * DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + protected final boolean isKeyBindingRegistered() + { + // FIXME: Implement. + return false; + } + + /** + * DOCUMENT ME! + * + * @param b DOCUMENT ME! + */ + protected final void setKeyBindingRegistered(boolean b) + { + // FIXME: Implement. + } + + /** + * DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public final boolean isKeyBindingActive() + { + // FIXME: Implement. + return false; + } + + /** + * DOCUMENT ME! + * + * @param b DOCUMENT ME! + */ + protected final void setKeyBindingActive(boolean b) + { + // FIXME: Implement. + } + + /** + * DOCUMENT ME! + */ + protected void setupMenuOpenKey() + { + // FIXME: Implement. + } + + /** + * DOCUMENT ME! + */ + protected void setupMenuCloseKey() + { + // FIXME: Implement. + } + + /** + * This method returns the north pane. + * + * @return The north pane. + */ + public JComponent getNorthPane() + { + return northPane; + } + + /** + * This method sets the north pane to be the given JComponent. + * + * @param c The new north pane. + */ + public void setNorthPane(JComponent c) + { + replacePane(northPane, c); + northPane = c; + } + + /** + * This method returns the south pane. + * + * @return The south pane. + */ + public JComponent getSouthPane() + { + return southPane; + } + + /** + * This method sets the south pane to be the given JComponent. + * + * @param c The new south pane. + */ + public void setSouthPane(JComponent c) + { + replacePane(southPane, c); + southPane = c; + } + + /** + * This method sets the east pane to be the given JComponent. + * + * @param c The new east pane. + */ + public void setEastPane(JComponent c) + { + replacePane(eastPane, c); + eastPane = c; + } + + /** + * This method returns the east pane. + * + * @return The east pane. + */ + public JComponent getEastPane() + { + return eastPane; + } + + /** + * This method sets the west pane to be the given JComponent. + * + * @param c The new west pane. + */ + public void setWestPane(JComponent c) + { + replacePane(westPane, c); + westPane = c; + } + + /** + * This method returns the west pane. + * + * @return The west pane. + */ + public JComponent getWestPane() + { + return westPane; + } + + /** + * This method returns the DesktopManager to use with the JInternalFrame. + * + * @return The DesktopManager to use with the JInternalFrame. + */ + protected DesktopManager getDesktopManager() + { + DesktopManager value = frame.getDesktopPane().getDesktopManager(); + if (value == null) + value = createDesktopManager(); + return value; + } + + /** + * This method returns a default DesktopManager that can be used with this + * JInternalFrame. + * + * @return A default DesktopManager that can be used with this + * JInternalFrame. + */ + protected DesktopManager createDesktopManager() + { + return new DefaultDesktopManager(); + } + + /** + * This is a convenience method that closes the JInternalFrame. + * + * @param f The JInternalFrame to close. + */ + protected void closeFrame(JInternalFrame f) + { + getDesktopManager().closeFrame(f); + } + + /** + * This is a convenience method that maximizes the JInternalFrame. + * + * @param f The JInternalFrame to maximize. + */ + protected void maximizeFrame(JInternalFrame f) + { + getDesktopManager().maximizeFrame(f); + } + + /** + * This is a convenience method that minimizes the JInternalFrame. + * + * @param f The JInternalFrame to minimize. + */ + protected void minimizeFrame(JInternalFrame f) + { + getDesktopManager().minimizeFrame(f); + } + + /** + * This is a convenience method that iconifies the JInternalFrame. + * + * @param f The JInternalFrame to iconify. + */ + protected void iconifyFrame(JInternalFrame f) + { + getDesktopManager().iconifyFrame(f); + } + + /** + * This is a convenience method that deiconifies the JInternalFrame. + * + * @param f The JInternalFrame to deiconify. + */ + protected void deiconifyFrame(JInternalFrame f) + { + getDesktopManager().deiconifyFrame(f); + } + + /** + * This is a convenience method that activates the JInternalFrame. + * + * @param f The JInternalFrame to activate. + */ + protected void activateFrame(JInternalFrame f) + { + getDesktopManager().activateFrame(f); + } + + /** + * This method returns a new ComponentListener for the JDesktopPane. + * + * @return A new ComponentListener. + */ + protected ComponentListener createComponentListener() + { + return new ComponentHandler(); + } + + /** + * This method returns a new GlassPaneDispatcher. + * + * @return A new GlassPaneDispatcher. + */ + protected MouseInputListener createGlassPaneDispatcher() + { + return new GlassPaneDispatcher(); + } +} diff --git a/libjava/javax/swing/plaf/basic/BasicLookAndFeel.java b/libjava/javax/swing/plaf/basic/BasicLookAndFeel.java index f4466ef5083..0da43dd9a39 100644 --- a/libjava/javax/swing/plaf/basic/BasicLookAndFeel.java +++ b/libjava/javax/swing/plaf/basic/BasicLookAndFeel.java @@ -110,6 +110,7 @@ public abstract class BasicLookAndFeel extends LookAndFeel "DesktopIconUI", "javax.swing.plaf.basic.BasicDesktopIconUI", "DesktopPaneUI", "javax.swing.plaf.basic.BasicDesktopPaneUI", "EditorPaneUI", "javax.swing.plaf.basic.BasicEditorPaneUI", + "FormattedTextFieldUI", "javax.swing.plaf.basic.BasicFormattedTextFieldUI", "InternalFrameUI", "javax.swing.plaf.basic.BasicInternalFrameUI", "LabelUI", "javax.swing.plaf.basic.BasicLabelUI", "ListUI", "javax.swing.plaf.basic.BasicListUI", @@ -205,15 +206,15 @@ public abstract class BasicLookAndFeel extends LookAndFeel private void loadResourceBundle(UIDefaults defaults) { ResourceBundle bundle; - Enumeration enum; + Enumeration e; String key; String value; bundle = ResourceBundle.getBundle("resources/basic"); // Process Resources - enum = bundle.getKeys(); - while (enum.hasMoreElements()) + e = bundle.getKeys(); + while (e.hasMoreElements()) { - key = (String) enum.nextElement(); + key = (String) e.nextElement(); value = bundle.getString(key); defaults.put(key, value); } @@ -346,7 +347,7 @@ public abstract class BasicLookAndFeel extends LookAndFeel "ctrl F10", "maximize", "ctrl alt shift F6","selectPreviousFrame" }), - "Desktop.background", new ColorUIResource(0, 92, 92), + "Desktop.background", new ColorUIResource(175, 163, 236), "DesktopIcon.border", new BorderUIResource.CompoundBorderUIResource(null, null), "EditorPane.background", new ColorUIResource(Color.white), @@ -419,7 +420,7 @@ public abstract class BasicLookAndFeel extends LookAndFeel "FocusManagerClassName", "TODO", "FormView.resetButtonText", "Reset", "FormView.submitButtonText", "Submit Query", - "InternalFrame.activeTitleBackground", new ColorUIResource(lightPurple), + "InternalFrame.activeTitleBackground", new ColorUIResource(162, 167, 241), "InternalFrame.activeTitleForeground", new ColorUIResource(Color.black), "InternalFrame.border", new BorderUIResource.CompoundBorderUIResource(null, null), @@ -427,8 +428,8 @@ public abstract class BasicLookAndFeel extends LookAndFeel // XXX Don't use gif "InternalFrame.icon", new IconUIResource(new ImageIcon("icons/JavaCup.gif")), "InternalFrame.iconifyIcon", BasicIconFactory.createEmptyFrameIcon(), - "InternalFrame.inactiveTitleBackground", new ColorUIResource(Color.gray), - "InternalFrame.inactiveTitleForeground", new ColorUIResource(Color.lightGray), + "InternalFrame.inactiveTitleBackground", new ColorUIResource(Color.lightGray), + "InternalFrame.inactiveTitleForeground", new ColorUIResource(Color.black), "InternalFrame.maximizeIcon", BasicIconFactory.createEmptyFrameIcon(), "InternalFrame.minimizeIcon", BasicIconFactory.createEmptyFrameIcon(), "InternalFrame.titleFont", new FontUIResource("Dialog", Font.PLAIN, 12), @@ -703,7 +704,7 @@ public abstract class BasicLookAndFeel extends LookAndFeel "ctrl UP", "requestFocus", "ctrl KP_UP", "requestFocus" }), - "TabbedPane.background", new ColorUIResource(Color.GRAY), + "TabbedPane.background", new ColorUIResource(Color.LIGHT_GRAY), "TabbedPane.contentBorderInsets", new InsetsUIResource(2, 2, 3, 3), "TabbedPane.darkShadow", new ColorUIResource(Color.darkGray), "TabbedPane.focus", new ColorUIResource(Color.black), diff --git a/libjava/javax/swing/plaf/basic/BasicMenuBarUI.java b/libjava/javax/swing/plaf/basic/BasicMenuBarUI.java index 05faa58fe72..cff8a011cbc 100644 --- a/libjava/javax/swing/plaf/basic/BasicMenuBarUI.java +++ b/libjava/javax/swing/plaf/basic/BasicMenuBarUI.java @@ -1,5 +1,5 @@ -/* BasicMenuUI.java - Copyright (C) 2002, 2004 Free Software Foundation, Inc. +/* BasicMenuBarUI.java -- + Copyright (C) 2002, 2004 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -37,11 +37,13 @@ exception statement from your version. */ package javax.swing.plaf.basic; +import java.awt.Dimension; +import java.awt.GridLayout; +import java.awt.Insets; import java.awt.event.ContainerEvent; import java.awt.event.ContainerListener; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; -import java.awt.Dimension; import javax.swing.BoxLayout; import javax.swing.ButtonModel; import javax.swing.Icon; @@ -70,18 +72,22 @@ import javax.swing.event.MouseInputListener; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.MenuBarUI; import javax.swing.plaf.MenuItemUI; -import java.awt.Insets; -import java.awt.GridLayout; /** - * DOCUMENT ME! + * UI Delegate for JMenuBar. */ public class BasicMenuBarUI extends MenuBarUI { protected ChangeListener changeListener; + + /*ContainerListener that listens to the ContainerEvents fired from menu bar*/ protected ContainerListener containerListener; + + /*Property change listeners that listener to PropertyChangeEvent from menu bar*/ protected PropertyChangeListener propertyChangeListener; + + /* menu bar for which this UI delegate is for*/ protected JMenuBar menuBar; /** @@ -105,21 +111,23 @@ public class BasicMenuBarUI extends MenuBarUI } /** - * DOCUMENT ME! + * Creates ContainerListener() to listen for ContainerEvents + * fired by JMenuBar * - * @return DOCUMENT ME! + * @return The ContainerListener */ - protected ContainerListener createContainerListener() + protected ContainerListener createContainerListener() { return new ContainerHandler(); } /** - * DOCUMENT ME! + * Factory method to create a BasicMenuBarUI for the given {@link + * JComponent}, which should be a {@link JMenuBar}. * - * @param x DOCUMENT ME! + * @param b The {@link JComponent} a UI is being created for. * - * @return DOCUMENT ME! + * @return A BasicMenuBarUI for the {@link JComponent}. */ public static ComponentUI createUI(JComponent x) { @@ -127,11 +135,11 @@ public class BasicMenuBarUI extends MenuBarUI } /** - * DOCUMENT ME! + * Returns maximum size for the specified menu bar * - * @param c DOCUMENT ME! + * @param c component for which to get maximum size * - * @return DOCUMENT ME! + * @return Maximum size for the specified menu bar */ public Dimension getMaximumSize(JComponent c) { @@ -140,11 +148,11 @@ public class BasicMenuBarUI extends MenuBarUI } /** - * DOCUMENT ME! + * Returns maximum allowed size of JMenuBar. * - * @param c DOCUMENT ME! + * @param c menuBar for which to return maximum size * - * @return DOCUMENT ME! + * @return Maximum size of the give menu bar. */ public Dimension getMinimumSize(JComponent c) { @@ -153,11 +161,11 @@ public class BasicMenuBarUI extends MenuBarUI } /** - * DOCUMENT ME! + * Returns preferred size of JMenuBar. * - * @param c DOCUMENT ME! + * @param c menuBar for which to return preferred size * - * @return DOCUMENT ME! + * @return Preferred size of the give menu bar. */ public Dimension getPreferredSize(JComponent c) { @@ -166,7 +174,8 @@ public class BasicMenuBarUI extends MenuBarUI } /** - * DOCUMENT ME! + * Initializes any default properties that this UI has from the defaults for + * the Basic look and feel. */ protected void installDefaults() { @@ -179,26 +188,29 @@ public class BasicMenuBarUI extends MenuBarUI } /** - * DOCUMENT ME! + * This method installs the keyboard actions for the JMenuBar. */ protected void installKeyboardActions() { + // FIXME: implement } /** - * DOCUMENT ME! + * This method installs the listeners needed for this UI to function. */ protected void installListeners() - { + { menuBar.addContainerListener(containerListener); - menuBar.addPropertyChangeListener(propertyChangeListener); + menuBar.addPropertyChangeListener(propertyChangeListener); } /** - * DOCUMENT ME! - * - * @param c DOCUMENT ME! - */ + * Installs and initializes all fields for this UI delegate. Any properties + * of the UI that need to be initialized and/or set to defaults will be + * done now. It will also install any listeners necessary. + * + * @param c The {@link JComponent} that is having this UI installed. + */ public void installUI(JComponent c) { super.installUI(c); @@ -206,10 +218,12 @@ public class BasicMenuBarUI extends MenuBarUI menuBar.setLayout(new BoxLayout(menuBar, BoxLayout.X_AXIS)); installDefaults(); installListeners(); + installKeyboardActions(); } /** - * DOCUMENT ME! + * This method uninstalls the defaults and nulls any objects created during + * install. */ protected void uninstallDefaults() { @@ -220,10 +234,11 @@ public class BasicMenuBarUI extends MenuBarUI } /** - * DOCUMENT ME! + * This method reverses the work done in installKeyboardActions. */ protected void uninstallKeyboardActions() { + // FIXME: implement. } /** @@ -236,15 +251,18 @@ public class BasicMenuBarUI extends MenuBarUI } /** - * DOCUMENT ME! + * Performs the opposite of installUI. Any properties or resources that need + * to be cleaned up will be done now. It will also uninstall any listeners + * it has. In addition, any properties of this UI will be nulled. * - * @param c DOCUMENT ME! + * @param c The {@link JComponent} that is having this UI uninstalled. */ public void uninstallUI(JComponent c) { uninstallDefaults(); - uninstallListeners(); - menuBar= null; + uninstallListeners(); + uninstallKeyboardActions(); + menuBar = null; } protected class ChangeHandler implements ChangeListener @@ -254,21 +272,47 @@ public class BasicMenuBarUI extends MenuBarUI } } + /** + * This class handles ContainerEvents fired by JMenuBar + */ protected class ContainerHandler implements ContainerListener { + /** + * This method is called whenever menu is added to the menu bar + * + * @param e The ContainerEvent. + */ public void componentAdded(ContainerEvent e) { + System.out.println("BasicMenuBar...componentAdded.. listener"); } + /** + * This method is called whenever menu is removed from the menu bar + * + * @param e The ContainerEvent. + */ public void componentRemoved(ContainerEvent e) { + System.out.println("BasicMenuBar...componentRemoved.. listener"); } } + /** + * This class handles PropertyChangeEvents fired from the JMenuBar + */ protected class PropertyChangeHandler implements PropertyChangeListener { + /** + * This method is called whenever one of the properties of the MenuBar + * changes. + * + * @param e The PropertyChangeEvent. + */ public void propertyChange(PropertyChangeEvent e) { + if (e.getPropertyName().equals(JMenuBar.BORDER_PAINTED_CHANGED_PROPERTY)) + menuBar.repaint(); } } } diff --git a/libjava/javax/swing/plaf/basic/BasicMenuItemUI.java b/libjava/javax/swing/plaf/basic/BasicMenuItemUI.java index 886034af205..e5e407a55bb 100644 --- a/libjava/javax/swing/plaf/basic/BasicMenuItemUI.java +++ b/libjava/javax/swing/plaf/basic/BasicMenuItemUI.java @@ -1,5 +1,5 @@ -/* BasicMenuItemUI.java - Copyright (C) 2002, 2004 Free Software Foundation, Inc. +/* BasicMenuItemUI.java -- + Copyright (C) 2002, 2004 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -35,6 +35,7 @@ this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ + package javax.swing.plaf.basic; import java.awt.Color; @@ -43,12 +44,15 @@ import java.awt.Dimension; import java.awt.Font; import java.awt.FontMetrics; import java.awt.Graphics; +import java.awt.Insets; import java.awt.Rectangle; +import java.awt.Stroke; import java.awt.event.InputEvent; import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; +import java.util.ArrayList; import java.util.Vector; import javax.swing.AbstractButton; import javax.swing.ButtonModel; @@ -75,7 +79,7 @@ import javax.swing.plaf.MenuItemUI; /** - * DOCUMENT ME! + * UI Delegate for JMenuItem. */ public class BasicMenuItemUI extends MenuItemUI { @@ -156,6 +160,10 @@ public class BasicMenuItemUI extends MenuItemUI * String that separates description of the modifiers and the key */ private String acceleratorDelimiter; + + /** + * PropertyChangeListener to listen for property changes in the menu item + */ private PropertyChangeListener propertyChangeListener; /** @@ -163,6 +171,9 @@ public class BasicMenuItemUI extends MenuItemUI */ private int defaultAcceleratorLabelGap = 4; + /** + * Creates a new BasicMenuItemUI object. + */ public BasicMenuItemUI() { mouseInputListener = createMouseInputListener(menuItem); @@ -171,17 +182,25 @@ public class BasicMenuItemUI extends MenuItemUI propertyChangeListener = new PropertyChangeHandler(); } + /** + * Create MenuDragMouseListener to listen for mouse dragged events. + * + * @param c menu item to listen to + * + * @return The MenuDragMouseListener + */ protected MenuDragMouseListener createMenuDragMouseListener(JComponent c) { return new MenuDragMouseHandler(); } /** - * DOCUMENT ME! + * Creates MenuKeyListener to listen to key events occuring when menu item + * is visible on the screen. * - * @param c DOCUMENT ME! + * @param c menu item to listen to * - * @return $returnType$ DOCUMENT ME! + * @return The MenuKeyListener */ protected MenuKeyListener createMenuKeyListener(JComponent c) { @@ -189,11 +208,11 @@ public class BasicMenuItemUI extends MenuItemUI } /** - * DOCUMENT ME! + * Handles mouse input events occuring for this menu item * - * @param c DOCUMENT ME! + * @param c menu item to listen to * - * @return $returnType$ DOCUMENT ME! + * @return The MouseInputListener */ protected MouseInputListener createMouseInputListener(JComponent c) { @@ -201,11 +220,12 @@ public class BasicMenuItemUI extends MenuItemUI } /** - * DOCUMENT ME! + * Factory method to create a BasicMenuItemUI for the given {@link + * JComponent}, which should be a {@link JMenuItem}. * - * @param c DOCUMENT ME! + * @param c The {@link JComponent} a UI is being created for. * - * @return $returnType$ DOCUMENT ME! + * @return A BasicMenuItemUI for the {@link JComponent}. */ public static ComponentUI createUI(JComponent c) { @@ -213,9 +233,9 @@ public class BasicMenuItemUI extends MenuItemUI } /** - * DOCUMENT ME! + * Programatically clicks menu item. * - * @param msm DOCUMENT ME! + * @param msm MenuSelectionManager for the menu hierarchy */ protected void doClick(MenuSelectionManager msm) { @@ -224,11 +244,11 @@ public class BasicMenuItemUI extends MenuItemUI } /** - * DOCUMENT ME! + * Returns maximum size for the specified menu item * - * @param c DOCUMENT ME! + * @param c component for which to get maximum size * - * @return $returnType$ DOCUMENT ME! + * @return Maximum size for the specified menu item. */ public Dimension getMaximumSize(JComponent c) { @@ -236,11 +256,11 @@ public class BasicMenuItemUI extends MenuItemUI } /** - * DOCUMENT ME! + * Returns minimum size for the specified menu item * - * @param c DOCUMENT ME! + * @param c component for which to get minimum size * - * @return $returnType$ DOCUMENT ME! + * @return Minimum size for the specified menu item. */ public Dimension getMinimumSize(JComponent c) { @@ -248,17 +268,18 @@ public class BasicMenuItemUI extends MenuItemUI } /** - * DOCUMENT ME! + * Returns path to this menu item. * - * @return $returnType$ DOCUMENT ME! + * @return $MenuElement[]$ Returns array of menu elements + * that constitute a path to this menu item. */ public MenuElement[] getPath() { - Vector path = new Vector(); + ArrayList path = new ArrayList(); Component c = menuItem; while (c instanceof MenuElement) { - path.add(c); + path.add(0, (MenuElement) c); if (c instanceof JPopupMenu) c = ((JPopupMenu) c).getInvoker(); @@ -266,54 +287,51 @@ public class BasicMenuItemUI extends MenuItemUI c = c.getParent(); } - // convert from vector to array MenuElement[] pathArray = new MenuElement[path.size()]; - for (int i = 0; i < path.size(); i++) - pathArray[i] = (MenuElement) path.get(path.size() - i - 1); - + path.toArray(pathArray); return pathArray; } /** - * DOCUMENT ME! + * Returns preferred size for the given menu item. * - * @param c DOCUMENT ME! - * @param checkIcon DOCUMENT ME! - * @param arrowIcon DOCUMENT ME! - * @param defaultTextIconGap DOCUMENT ME! + * @param c menu item for which to get preferred size + * @param checkIcon chech icon displayed in the given menu item + * @param arrowIcon arrow icon displayed in the given menu item + * @param defaultTextIconGap space between icon and text in the given menuItem * - * @return $returnType$ DOCUMENT ME! + * @return $Dimension$ preferred size for the given menu item */ protected Dimension getPreferredMenuItemSize(JComponent c, Icon checkIcon, Icon arrowIcon, int defaultTextIconGap) { - // TODO + // FIXME: Need to implement. return null; } /** - * DOCUMENT ME! + * Returns preferred size of the given component * - * @param c DOCUMENT ME! + * @param c component for which to return preferred size * - * @return $returnType$ DOCUMENT ME! + * @return $Dimension$ preferred size for the given component */ public Dimension getPreferredSize(JComponent c) { - AbstractButton b = (AbstractButton) c; - Dimension d = BasicGraphicsUtils.getPreferredButtonSize(b, + JMenuItem m = (JMenuItem) c; + Dimension d = BasicGraphicsUtils.getPreferredButtonSize(m, defaultTextIconGap); // if menu item has accelerator then take accelerator's size into account // when calculating preferred size. - KeyStroke accelerator = ((JMenuItem) c).getAccelerator(); + KeyStroke accelerator = m.getAccelerator(); Rectangle rect; if (accelerator != null) { rect = getAcceleratorRect(accelerator, - b.getToolkit().getFontMetrics(acceleratorFont)); + m.getToolkit().getFontMetrics(acceleratorFont)); // add width of accelerator's text d.width = d.width + rect.width + defaultAcceleratorLabelGap; @@ -349,22 +367,22 @@ public class BasicMenuItemUI extends MenuItemUI */ protected String getPropertyPrefix() { - // TODO return null; } /** - * DOCUMENT ME! + * This method installs the components for this {@link JMenuItem}. * - * @param menuItem DOCUMENT ME! + * @param menuItem The {@link JMenuItem} to install components for. */ protected void installComponents(JMenuItem menuItem) { - // TODO + // FIXME: Need to implement } /** - * DOCUMENT ME! + * This method installs the defaults that are defined in the Basic look and + * feel for this {@link JMenuItem}. */ protected void installDefaults() { @@ -376,7 +394,6 @@ public class BasicMenuItemUI extends MenuItemUI menuItem.setForeground(defaults.getColor("MenuItem.foreground")); menuItem.setMargin(defaults.getInsets("MenuItem.margin")); menuItem.setOpaque(true); - acceleratorFont = defaults.getFont("MenuItem.acceleratorFont"); acceleratorForeground = defaults.getColor("MenuItem.acceleratorForeground"); acceleratorSelectionForeground = defaults.getColor("MenuItem.acceleratorSelectionForeground"); @@ -386,15 +403,15 @@ public class BasicMenuItemUI extends MenuItemUI } /** - * DOCUMENT ME! + * This method installs the keyboard actions for this {@link JMenuItem}. */ protected void installKeyboardActions() { - // TODO + // FIXME: Need to implement } /** - * DOCUMENT ME! + * This method installs the listeners for the {@link JMenuItem}. */ protected void installListeners() { @@ -405,9 +422,11 @@ public class BasicMenuItemUI extends MenuItemUI } /** - * DOCUMENT ME! + * Installs and initializes all fields for this UI delegate. Any properties + * of the UI that need to be initialized and/or set to defaults will be + * done now. It will also install any listeners necessary. * - * @param c DOCUMENT ME! + * @param c The {@link JComponent} that is having this UI installed. */ public void installUI(JComponent c) { @@ -418,10 +437,10 @@ public class BasicMenuItemUI extends MenuItemUI } /** - * DOCUMENT ME! + * Paints given menu item using specified graphics context * - * @param g DOCUMENT ME! - * @param c DOCUMENT ME! + * @param g The graphics context used to paint this menu item + * @param c Menu Item to paint */ public void paint(Graphics g, JComponent c) { @@ -430,11 +449,11 @@ public class BasicMenuItemUI extends MenuItemUI } /** - * DOCUMENT ME! + * Paints background of the menu item * - * @param g DOCUMENT ME! - * @param menuItem DOCUMENT ME! - * @param bgColor DOCUMENT ME! + * @param g The graphics context used to paint this menu item + * @param menuItem menu item to paint + * @param bgColor Background color to use when painting menu item */ protected void paintBackground(Graphics g, JMenuItem menuItem, Color bgColor) { @@ -446,21 +465,22 @@ public class BasicMenuItemUI extends MenuItemUI } /** - * DOCUMENT ME! + * Paints specified menu item * - * @param g DOCUMENT ME! - * @param c DOCUMENT ME! - * @param checkIcon DOCUMENT ME! - * @param arrowIcon DOCUMENT ME! - * @param background DOCUMENT ME! - * @param foreground DOCUMENT ME! - * @param defaultTextIconGap DOCUMENT ME! + * @param g The graphics context used to paint this menu item + * @param c menu item to paint + * @param checkIcon check icon to use when painting menu item + * @param arrowIcon arrow icon to use when painting menu item + * @param background Background color of the menu item + * @param foreground Foreground color of the menu item + * @param defaultTextIconGap space to use between icon and + * text when painting menu item */ protected void paintMenuItem(Graphics g, JComponent c, Icon checkIcon, Icon arrowIcon, Color background, Color foreground, int defaultTextIconGap) { - AbstractButton b = (AbstractButton) c; + JMenuItem m = (JMenuItem) c; Rectangle tr = new Rectangle(); // text rectangle Rectangle ir = new Rectangle(); // icon rectangle Rectangle vr = new Rectangle(); // view rectangle @@ -468,41 +488,53 @@ public class BasicMenuItemUI extends MenuItemUI Rectangle ar = new Rectangle(); // accelerator rectangle Rectangle cr = new Rectangle(); // checkIcon rectangle - int vertAlign = b.getVerticalAlignment(); - int horAlign = b.getHorizontalAlignment(); - int vertTextPos = b.getVerticalTextPosition(); - int horTextPos = b.getHorizontalTextPosition(); + int vertAlign = m.getVerticalAlignment(); + int horAlign = m.getHorizontalAlignment(); + int vertTextPos = m.getVerticalTextPosition(); + int horTextPos = m.getHorizontalTextPosition(); - Font f = c.getFont(); + Font f = m.getFont(); g.setFont(f); FontMetrics fm = g.getFontMetrics(f); - SwingUtilities.calculateInnerArea(b, br); - SwingUtilities.calculateInsetArea(br, b.getMargin(), vr); - paintBackground(g, (JMenuItem) c, c.getBackground()); - - if ((b.getModel().isArmed() && b.getModel().isPressed())) + SwingUtilities.calculateInnerArea(m, br); + SwingUtilities.calculateInsetArea(br, m.getInsets(), vr); + paintBackground(g, m, m.getBackground()); + + /* MenuItems insets are equal to menuItems margin, space between text and + menuItems border. We need to paint insets region as well. */ + Insets insets = m.getInsets(); + br.x -= insets.left; + br.y -= insets.top; + br.width += insets.right + insets.left; + br.height += insets.top + insets.bottom; + + /* Menu item is considered to be highlighted when it is selected. + It is considered to be selected if menu item is inside some menu + and is armed or if it is both armed and pressed */ + if (m.getModel().isArmed() + && (m.getParent() instanceof MenuElement || m.getModel().isPressed())) { - if (((AbstractButton) b).isContentAreaFilled()) + if (m.isContentAreaFilled()) { - g.setColor(b.getBackground().darker()); + g.setColor(m.getBackground().darker()); g.fillRect(br.x, br.y, br.width, br.height); } } else { - if (((AbstractButton) b).isContentAreaFilled()) + if (m.isContentAreaFilled()) { - g.setColor(b.getBackground()); + g.setColor(m.getBackground()); g.fillRect(br.x, br.y, br.width, br.height); } } if (checkIcon != null) { - SwingUtilities.layoutCompoundLabel(c, fm, null, checkIcon, vertAlign, + SwingUtilities.layoutCompoundLabel(m, fm, null, checkIcon, vertAlign, horAlign, vertTextPos, horTextPos, vr, cr, tr, defaultTextIconGap); - checkIcon.paintIcon(c, g, cr.x, cr.y); + checkIcon.paintIcon(m, g, cr.x, cr.y); // We need to calculate position of the menu text and position of // user menu icon if there exists one relative to the check icon. @@ -518,25 +550,25 @@ public class BasicMenuItemUI extends MenuItemUI int width = arrowIcon.getIconWidth(); int height = arrowIcon.getIconHeight(); - arrowIcon.paintIcon(c, g, vr.width - width + defaultTextIconGap, + arrowIcon.paintIcon(m, g, vr.width - width + defaultTextIconGap, vr.y + 2); } } // paint text and user menu icon if it exists - SwingUtilities.layoutCompoundLabel(c, fm, b.getText(), b.getIcon(), + SwingUtilities.layoutCompoundLabel(c, fm, m.getText(), m.getIcon(), vertAlign, horAlign, vertTextPos, horTextPos, vr, ir, tr, defaultTextIconGap); - paintText(g, (JMenuItem) c, tr, b.getText()); + paintText(g, m, tr, m.getText()); // paint icon // FIXME: should paint different icon at different button state's. // i.e disabled icon when button is disabled.. etc. /* - Icon i = b.getIcon(); + Icon i = m.getIcon(); if (i != null) { int x = ir.x; @@ -548,30 +580,31 @@ public class BasicMenuItemUI extends MenuItemUI // paint accelerator String acceleratorText = ""; - if (((JMenuItem) c).getAccelerator() != null) + if (m.getAccelerator() != null) { - acceleratorText = getAcceleratorText(((JMenuItem) c).getAccelerator()); + acceleratorText = getAcceleratorText(m.getAccelerator()); fm = g.getFontMetrics(acceleratorFont); ar.width = fm.stringWidth(acceleratorText); ar.x = br.width - ar.width; vr.x = br.width - ar.width; - SwingUtilities.layoutCompoundLabel(c, fm, acceleratorText, null, + SwingUtilities.layoutCompoundLabel(m, fm, acceleratorText, null, vertAlign, horAlign, vertTextPos, horTextPos, vr, ir, ar, defaultTextIconGap); - paintAccelerator(g, (JMenuItem) c, ar, acceleratorText); + paintAccelerator(g, m, ar, acceleratorText); } } /** - * DOCUMENT ME! + * Paints label for the given menu item * - * @param g DOCUMENT ME! - * @param menuItem DOCUMENT ME! - * @param textRect DOCUMENT ME! - * @param text DOCUMENT ME! + * @param g The graphics context used to paint this menu item + * @param menuItem menu item for which to draw its label + * @param textRect rectangle specifiying position of the text relative to + * the given menu item + * @param text label of the menu item */ protected void paintText(Graphics g, JMenuItem menuItem, Rectangle textRect, String text) @@ -586,17 +619,18 @@ public class BasicMenuItemUI extends MenuItemUI } /** - * DOCUMENT ME! + * This method uninstalls the components for this {@link JMenuItem}. * - * @param menuItem DOCUMENT ME! + * @param menuItem The {@link JMenuItem} to uninstall components for. */ protected void uninstallComponents(JMenuItem menuItem) { - // TODO + // FIXME: need to implement } /** - * DOCUMENT ME! + * This method uninstalls the defaults and sets any objects created during + * install to null */ protected void uninstallDefaults() { @@ -619,15 +653,15 @@ public class BasicMenuItemUI extends MenuItemUI } /** - * DOCUMENT ME! + * Uninstalls any keyboard actions. */ protected void uninstallKeyboardActions() { - // TODO + // FIXME: need to implement } /** - * DOCUMENT ME! + * Unregisters all the listeners that this UI delegate was using. */ protected void uninstallListeners() { @@ -638,9 +672,11 @@ public class BasicMenuItemUI extends MenuItemUI } /** - * DOCUMENT ME! + * Performs the opposite of installUI. Any properties or resources that need + * to be cleaned up will be done now. It will also uninstall any listeners + * it has. In addition, any properties of this UI will be nulled. * - * @param c DOCUMENT ME! + * @param c The {@link JComponent} that is having this UI uninstalled. */ public void uninstallUI(JComponent c) { @@ -650,10 +686,10 @@ public class BasicMenuItemUI extends MenuItemUI } /** - * DOCUMENT ME! + * This method calls paint. * - * @param g DOCUMENT ME! - * @param c DOCUMENT ME! + * @param g The graphics context used to paint this menu item + * @param c The menu item to paint */ public void update(Graphics g, JComponent c) { @@ -661,11 +697,11 @@ public class BasicMenuItemUI extends MenuItemUI } /** - * DOCUMENT ME! + * Return text representation of the specified accelerator * - * @param accelerator DOCUMENT ME! + * @param accelerator Accelerator for which to return string representation * - * @return $returnType$ DOCUMENT ME! + * @return $String$ Text representation of the given accelerator */ private String getAcceleratorText(KeyStroke accelerator) { @@ -686,12 +722,12 @@ public class BasicMenuItemUI extends MenuItemUI } /** - * DOCUMENT ME! + * Calculates and return rectange in which accelerator should be displayed * - * @param accelerator DOCUMENT ME! - * @param fm DOCUMENT ME! + * @param accelerator accelerator for which to return the display rectangle + * @param fm The font metrics used to measure the text * - * @return $returnType$ DOCUMENT ME! + * @return $Rectangle$ reactangle which will be used to display accelerator */ private Rectangle getAcceleratorRect(KeyStroke accelerator, FontMetrics fm) { @@ -701,12 +737,13 @@ public class BasicMenuItemUI extends MenuItemUI } /** - * DOCUMENT ME! + * Paints accelerator inside menu item * - * @param g DOCUMENT ME! - * @param menuItem DOCUMENT ME! - * @param acceleratorRect DOCUMENT ME! - * @param acceleratorText DOCUMENT ME! + * @param g The graphics context used to paint the border + * @param menuItem Menu item for which to draw accelerator + * @param acceleratorRect rectangle representing position + * of the accelerator relative to the menu item + * @param acceleratorText accelerator's text */ private void paintAccelerator(Graphics g, JMenuItem menuItem, Rectangle acceleratorRect, @@ -720,7 +757,10 @@ public class BasicMenuItemUI extends MenuItemUI } /** - * DOCUMENT ME! + * This class handles mouse events occuring inside the menu item. + * Most of the events are forwarded for processing to MenuSelectionManager + * of the current menu hierarchy. + * */ protected class MouseInputHandler implements MouseInputListener { @@ -732,9 +772,10 @@ public class BasicMenuItemUI extends MenuItemUI } /** - * DOCUMENT ME! + * This method is called when mouse is clicked on the menu item. + * It forwards this event to MenuSelectionManager. * - * @param e DOCUMENT ME! + * @param e A {@link MouseEvent}. */ public void mouseClicked(MouseEvent e) { @@ -743,9 +784,10 @@ public class BasicMenuItemUI extends MenuItemUI } /** - * DOCUMENT ME! + * This method is called when mouse is dragged inside the menu item. + * It forwards this event to MenuSelectionManager. * - * @param e DOCUMENT ME! + * @param e A {@link MouseEvent}. */ public void mouseDragged(MouseEvent e) { @@ -754,20 +796,29 @@ public class BasicMenuItemUI extends MenuItemUI } /** - * DOCUMENT ME! + * This method is called when mouse enters menu item. + * When this happens menu item is considered to be selected and selection path + * in MenuSelectionManager is set. This event is also forwarded to MenuSelection + * Manager for further processing. * - * @param e DOCUMENT ME! + * @param e A {@link MouseEvent}. */ public void mouseEntered(MouseEvent e) { - MenuSelectionManager manager = MenuSelectionManager.defaultManager(); - manager.processMouseEvent(e); + Component source = (Component) e.getSource(); + if (source.getParent() instanceof MenuElement) + { + MenuSelectionManager manager = MenuSelectionManager.defaultManager(); + manager.setSelectedPath(getPath()); + manager.processMouseEvent(e); + } } /** - * DOCUMENT ME! + * This method is called when mouse exits menu item. The event is + * forwarded to MenuSelectionManager for processing. * - * @param e DOCUMENT ME! + * @param e A {@link MouseEvent}. */ public void mouseExited(MouseEvent e) { @@ -776,9 +827,10 @@ public class BasicMenuItemUI extends MenuItemUI } /** - * DOCUMENT ME! + * This method is called when mouse is inside the menu item. + * This event is forwarder to MenuSelectionManager for further processing. * - * @param e DOCUMENT ME! + * @param e A {@link MouseEvent}. */ public void mouseMoved(MouseEvent e) { @@ -787,9 +839,10 @@ public class BasicMenuItemUI extends MenuItemUI } /** - * DOCUMENT ME! + * This method is called when mouse is pressed. This event is forwarded to + * MenuSelectionManager for further processing. * - * @param e DOCUMENT ME! + * @param e A {@link MouseEvent}. */ public void mousePressed(MouseEvent e) { @@ -798,57 +851,64 @@ public class BasicMenuItemUI extends MenuItemUI } /** - * DOCUMENT ME! + * This method is called when mouse is released. If the mouse is released + * inside this menuItem, then this menu item is considered to be chosen and + * the menu hierarchy should be closed. * - * @param e DOCUMENT ME! + * @param e A {@link MouseEvent}. */ public void mouseReleased(MouseEvent e) { - // FIXME: Should check if the mouse released while mouse cursor - // was indeed over the menu item. If this wasn't the case we probably - // should sent this event to MenuSelectionManager. - MenuSelectionManager manager = MenuSelectionManager.defaultManager(); - manager.clearSelectedPath(); - menuItem.doClick(0); + Rectangle size = menuItem.getBounds(); //this.getParent().getSize(); + if (e.getX() > 0 && e.getX() < size.width && e.getY() > 0 + && e.getY() < size.height) + { + MenuSelectionManager manager = MenuSelectionManager.defaultManager(); + manager.clearSelectedPath(); + menuItem.doClick(0); + } } } /** - * DOCUMENT ME! + * This class handles mouse dragged events. */ protected class MenuDragMouseHandler implements MenuDragMouseListener { /** - * DOCUMENT ME! + * Tbis method is invoked when mouse is dragged over the menu item. * - * @param e DOCUMENT ME! + * @param e The MenuDragMouseEvent */ public void menuDragMouseDragged(MenuDragMouseEvent e) { } /** - * DOCUMENT ME! + * Tbis method is invoked when mouse enters the menu item while it is + * being dragged. * - * @param e DOCUMENT ME! + * @param e The MenuDragMouseEvent */ public void menuDragMouseEntered(MenuDragMouseEvent e) { } /** - * DOCUMENT ME! + * Tbis method is invoked when mouse exits the menu item while + * it is being dragged * - * @param e DOCUMENT ME! + * @param e The MenuDragMouseEvent */ public void menuDragMouseExited(MenuDragMouseEvent e) { } /** - * DOCUMENT ME! + * Tbis method is invoked when mouse was dragged and released + * inside the menu item. * - * @param e DOCUMENT ME! + * @param e The MenuDragMouseEvent */ public void menuDragMouseReleased(MenuDragMouseEvent e) { @@ -856,32 +916,34 @@ public class BasicMenuItemUI extends MenuItemUI } /** - * DOCUMENT ME! + * This class handles key events occuring when menu item is visible on the + * screen. */ protected class MenuKeyHandler implements MenuKeyListener { /** - * DOCUMENT ME! + * This method is invoked when key has been pressed * - * @param e DOCUMENT ME! + * @param e A {@link MenuKeyEvent}. */ public void menuKeyPressed(MenuKeyEvent e) { } /** - * DOCUMENT ME! + * This method is invoked when key has been pressed * - * @param e DOCUMENT ME! + * @param e A {@link MenuKeyEvent}. */ public void menuKeyReleased(MenuKeyEvent e) { } /** - * DOCUMENT ME! + * This method is invoked when key has been typed + * It handles the mnemonic key for the menu item. * - * @param e DOCUMENT ME! + * @param e A {@link MenuKeyEvent}. */ public void menuKeyTyped(MenuKeyEvent e) { @@ -889,14 +951,15 @@ public class BasicMenuItemUI extends MenuItemUI } /** - * DOCUMENT ME! + * Helper class that listens for changes to the properties of the {@link + * JMenuItem}. */ protected class PropertyChangeHandler implements PropertyChangeListener { /** - * DOCUMENT ME! + * This method is called when one of the menu item's properties change. * - * @param evt DOCUMENT ME! + * @param evt A {@link PropertyChangeEvent}. */ public void propertyChange(PropertyChangeEvent evt) { diff --git a/libjava/javax/swing/plaf/basic/BasicMenuUI.java b/libjava/javax/swing/plaf/basic/BasicMenuUI.java index 97f64fea0a0..1953f480a8e 100644 --- a/libjava/javax/swing/plaf/basic/BasicMenuUI.java +++ b/libjava/javax/swing/plaf/basic/BasicMenuUI.java @@ -1,5 +1,5 @@ /* BasicMenuUI.java - Copyright (C) 2002, 2004 Free Software Foundation, Inc. + Copyright (C) 2002, 2004 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -53,6 +53,7 @@ import javax.swing.JComponent; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; +import javax.swing.JPopupMenu; import javax.swing.MenuElement; import javax.swing.MenuSelectionManager; import javax.swing.UIDefaults; @@ -71,12 +72,16 @@ import javax.swing.plaf.MenuItemUI; /** - * DOCUMENT ME! + * UI Delegate for JMenu */ public class BasicMenuUI extends BasicMenuItemUI { protected ChangeListener changeListener; + + /* MenuListener listens to MenuEvents fired by JMenu */ protected MenuListener menuListener; + + /* PropertyChangeListner that listens to propertyChangeEvents occuring in JMenu*/ protected PropertyChangeListener propertyChangeListener; /** @@ -84,52 +89,53 @@ public class BasicMenuUI extends BasicMenuItemUI */ public BasicMenuUI() { - mouseInputListener = createMouseInputListener(menuItem); - menuListener = createMenuListener(menuItem); + mouseInputListener = createMouseInputListener((JMenu) menuItem); + menuListener = createMenuListener((JMenu) menuItem); + propertyChangeListener = createPropertyChangeListener((JMenu) menuItem); } /** - * DOCUMENT ME! - * - * @param c DOCUMENT ME! + * This method creates a new ChangeListener. * - * @return DOCUMENT ME! + * @return A new ChangeListener. */ protected ChangeListener createChangeListener(JComponent c) { - return null; + return new ChangeHandler(); } /** - * DOCUMENT ME! + * This method creates new MenuDragMouseListener to listen to mouse dragged events + * occuring in the Menu * - * @param c DOCUMENT ME! + * @param c the menu to listen to * - * @return DOCUMENT ME! + * @return The MenuDrageMouseListener */ protected MenuDragMouseListener createMenuDragMouseListener(JComponent c) { - return null; + return new MenuDragMouseHandler(); } /** - * DOCUMENT ME! + * This method creates new MenuDragKeyListener to listen to key events * - * @param c DOCUMENT ME! + * @param c the menu to listen to * - * @return DOCUMENT ME! + * @return The MenuKeyListener */ protected MenuKeyListener createMenuKeyListener(JComponent c) { - return null; + return new MenuKeyHandler(); } /** - * DOCUMENT ME! + * This method creates new MenuListener to listen to menu events + * occuring in the Menu * - * @param c DOCUMENT ME! + * @param c the menu to listen to * - * @return DOCUMENT ME! + * @return The MenuListener */ protected MenuListener createMenuListener(JComponent c) { @@ -137,11 +143,12 @@ public class BasicMenuUI extends BasicMenuItemUI } /** - * DOCUMENT ME! + * This method creates new MouseInputListener to listen to mouse input events + * occuring in the Menu * - * @param c DOCUMENT ME! + * @param c the menu to listen to * - * @return DOCUMENT ME! + * @return The MouseInputListener */ protected MouseInputListener createMouseInputListener(JComponent c) { @@ -149,53 +156,50 @@ public class BasicMenuUI extends BasicMenuItemUI } /** - * DOCUMENT ME! + * This method creates newPropertyChangeListener to listen to property changes + * occuring in the Menu * - * @param c DOCUMENT ME! + * @param c the menu to listen to * - * @return DOCUMENT ME! + * @return The PropertyChangeListener */ protected PropertyChangeListener createPropertyChangeListener(JComponent c) { - return null; + return new PropertyChangeHandler(); } /** - * DOCUMENT ME! + * This method creates a new BasicMenuUI. * - * @param x DOCUMENT ME! + * @param c The JComponent to create a UI for. * - * @return DOCUMENT ME! + * @return A new BasicMenuUI. */ - public static ComponentUI createUI(JComponent x) + public static ComponentUI createUI(JComponent c) { return new BasicMenuUI(); } /** - * DOCUMENT ME! + * Get the component's maximum size. * - * @param c DOCUMENT ME! + * @param c The JComponent for which to get maximum size * - * @return DOCUMENT ME! + * @return The maximum size of the component */ public Dimension getMaximumSize(JComponent c) { return null; } - /** - * DOCUMENT ME! - * - * @return DOCUMENT ME! - */ protected String getPropertyPrefix() { return null; } /** - * DOCUMENT ME! + * Initializes any default properties that this UI has from the defaults for + * the Basic look and feel. */ protected void installDefaults() { @@ -214,14 +218,17 @@ public class BasicMenuUI extends BasicMenuItemUI } /** - * DOCUMENT ME! + * Installs any keyboard actions. The list of keys that need to be bound are + * listed in Basic look and feel's defaults. + * */ protected void installKeyboardActions() { + // FIXME: Need to implement } /** - * DOCUMENT ME! + * Creates and registers all the listeners for this UI delegate. */ protected void installListeners() { @@ -229,17 +236,13 @@ public class BasicMenuUI extends BasicMenuItemUI ((JMenu) menuItem).addMenuListener(menuListener); } - /** - * DOCUMENT ME! - * - * @param menu DOCUMENT ME! - */ protected void setupPostTimer(JMenu menu) { } /** - * DOCUMENT ME! + * This method uninstalls the defaults and sets any objects created during + * install to null */ protected void uninstallDefaults() { @@ -255,30 +258,35 @@ public class BasicMenuUI extends BasicMenuItemUI } /** - * DOCUMENT ME! + * Uninstalls any keyboard actions. The list of keys used are listed in + * Basic look and feel's defaults. */ protected void uninstallKeyboardActions() { + // FIXME: Need to implement } /** - * DOCUMENT ME! + * Unregisters all the listeners that this UI delegate was using. In + * addition, it will also null any listeners that it was using. */ protected void uninstallListeners() { + ((JMenu) menuItem).removeMouseListener(mouseInputListener); + ((JMenu) menuItem).removeMenuListener(menuListener); + ((JMenu) menuItem).removePropertyChangeListener(propertyChangeListener); } /** - * DOCUMENT ME! + * This class is used by menus to handle mouse events occuring in the + * menu. */ protected class MouseInputHandler implements MouseInputListener { - protected MouseInputHandler() - { - } - public void mouseClicked(MouseEvent e) { + MenuSelectionManager manager = MenuSelectionManager.defaultManager(); + manager.processMouseEvent(e); } public void mouseDragged(MouseEvent e) @@ -289,34 +297,30 @@ public class BasicMenuUI extends BasicMenuItemUI public void mouseEntered(MouseEvent e) { - MenuSelectionManager manager = MenuSelectionManager.defaultManager(); - manager.setSelectedPath(getPath()); - manager.processMouseEvent(e); - - JMenu subMenu = (JMenu) menuItem; - - int x = 0; - int y = 0; - - // location of the popup menu is relative to the invoker - if (subMenu.isTopLevelMenu()) + /* When mouse enters menu item, it should be considered selected + + if (i) if this menu is a submenu in some other menu + (ii) or if this menu is in a menu bar and some other menu in a menu bar was just + selected. (If nothing was selected, menu should be pressed before + it will be selected) + */ + + JMenu menu = (JMenu) menuItem; + if (! menu.isTopLevelMenu() + || (menu.isTopLevelMenu() + && (((JMenuBar) menu.getParent()).isSelected()))) { - JMenuBar mb = (JMenuBar) subMenu.getParent(); - - // Subtract menuBar's insets.bottom and popupMenu's insets.top, - // s.t. the space between menu bar and its popup menu is equal to - // menuBar's margin. By default menuBar's margin is Insets(0,0,0,0). - y = subMenu.getHeight() - mb.getInsets().bottom - - subMenu.getPopupMenu().getInsets().top + mb.getMargin().bottom; + // set new selection and forward this event to MenuSelectionManager + MenuSelectionManager manager = MenuSelectionManager.defaultManager(); + manager.setSelectedPath(getPath()); + manager.processMouseEvent(e); } - else - x = subMenu.getWidth(); - - subMenu.getPopupMenu().show(subMenu, x, y); } public void mouseExited(MouseEvent e) { + MenuSelectionManager manager = MenuSelectionManager.defaultManager(); + manager.processMouseEvent(e); } public void mouseMoved(MouseEvent e) @@ -325,6 +329,37 @@ public class BasicMenuUI extends BasicMenuItemUI public void mousePressed(MouseEvent e) { + + MenuSelectionManager manager = MenuSelectionManager.defaultManager(); + JMenu menu = (JMenu) menuItem; + manager.processMouseEvent(e); + + // Menu should be displayed when the menu is pressed only if + // it is top-level menu + if (menu.isTopLevelMenu()) + { + if (menu.getPopupMenu().isVisible()) + { + // If menu is visible and menu button was pressed.. + // then need to cancel the menu + menu.fireMenuCanceled(); + manager.clearSelectedPath(); + } + else + { + // Display the menu + int x = 0; + int y = menu.getHeight(); + + menu.fireMenuSelected(); + manager.setSelectedPath(getPath()); + + JMenuBar mb = (JMenuBar) menu.getParent(); + + // set selectedIndex of the selectionModel of a menuBar + mb.getSelectionModel().setSelectedIndex(mb.getComponentIndex(menu)); + } + } } public void mouseReleased(MouseEvent e) @@ -334,18 +369,141 @@ public class BasicMenuUI extends BasicMenuItemUI } } + /** + * This class handles MenuEvents fired by the JMenu + */ protected class MenuHandler implements MenuListener { + /** + * This method is called when menu is cancelled. The menu is cancelled + * when its popup menu is closed without selection. + * + * @param e The MenuEvent. + */ public void menuCanceled(MenuEvent e) { } + /** + * This method is called when menu is deselected. + * + * @param e The MenuEvent. + */ public void menuDeselected(MenuEvent e) { } + /** + * This method is called when menu is selected. + * + * @param e The MenuEvent. + */ public void menuSelected(MenuEvent e) { } } + + /** + * This class handles PropertyChangeEvents fired from the JMenu + */ + protected class PropertyChangeHandler implements PropertyChangeListener + { + /** + * This method is called whenever one of the properties of the menu item + * changes. + * + * @param e The PropertyChangeEvent. + */ + public void propertyChange(PropertyChangeEvent evt) + { + } + } + + protected class ChangeHandler implements ChangeListener + { + public void stateChanged(ChangeEvent e) + { + // FIXME: It seems that this class is not used anywhere + } + } + + /** + * This class handles mouse dragged events. + */ + protected class MenuDragMouseHandler implements MenuDragMouseListener + { + /** + * Tbis method is invoked when mouse is dragged over the menu item. + * + * @param e The MenuDragMouseEvent + */ + public void menuDragMouseDragged(MenuDragMouseEvent e) + { + } + + /** + * Tbis method is invoked when mouse enters the menu item while it is + * being dragged. + * + * @param e The MenuDragMouseEvent + */ + public void menuDragMouseEntered(MenuDragMouseEvent e) + { + } + + /** + * Tbis method is invoked when mouse exits the menu item while + * it is being dragged + * + * @param e The MenuDragMouseEvent + */ + public void menuDragMouseExited(MenuDragMouseEvent e) + { + } + + /** + * Tbis method is invoked when mouse was dragged and released + * inside the menu item. + * + * @param e The MenuDragMouseEvent + */ + public void menuDragMouseReleased(MenuDragMouseEvent e) + { + } + } + + /** + * This class handles key events occuring when menu item is visible on the + * screen. + */ + protected class MenuKeyHandler implements MenuKeyListener + { + /** + * This method is invoked when key has been pressed + * + * @param e A {@link MenuKeyEvent}. + */ + public void menuKeyPressed(MenuKeyEvent e) + { + } + + /** + * This method is invoked when key has been pressed + * + * @param e A {@link MenuKeyEvent}. + */ + public void menuKeyReleased(MenuKeyEvent e) + { + } + + /** + * This method is invoked when key has been typed + * It handles the mnemonic key for the menu item. + * + * @param e A {@link MenuKeyEvent}. + */ + public void menuKeyTyped(MenuKeyEvent e) + { + } + } } diff --git a/libjava/javax/swing/plaf/basic/BasicPopupMenuSeparatorUI.java b/libjava/javax/swing/plaf/basic/BasicPopupMenuSeparatorUI.java new file mode 100644 index 00000000000..a1adf01731c --- /dev/null +++ b/libjava/javax/swing/plaf/basic/BasicPopupMenuSeparatorUI.java @@ -0,0 +1,118 @@ +/* BasicPopupMenuSeparatorUI.java + Copyright (C) 2004 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.swing.plaf.basic; + +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.Insets; +import java.awt.Rectangle; +import javax.swing.JComponent; +import javax.swing.JPopupMenu; +import javax.swing.JSeparator; +import javax.swing.SwingUtilities; +import javax.swing.UIDefaults; +import javax.swing.UIManager; +import javax.swing.plaf.ComponentUI; +import javax.swing.plaf.SeparatorUI; + + +/** + * The Basic L&F UI delegate for JPopupMenu.Separator. + */ +public class BasicPopupMenuSeparatorUI extends BasicSeparatorUI +{ + /** + * Creates a new BasicPopupMenuSeparatorUI object. + */ + public BasicPopupMenuSeparatorUI() + { + super(); + } + + /** + * Creates a new UI delegate for the given JComponent. + * + * @param c The JComponent to create a delegate for. + * + * @return A new BasicPopupMenuSeparatorUI + */ + public static ComponentUI createUI(JComponent c) + { + return new BasicPopupMenuSeparatorUI(); + } + + /** + * The Popup Menu Separator has two lines. The top line will be + * painted using highlight color and the bottom using shadow color. + * + * @param g The Graphics object to paint with + * @param c The JComponent to paint. + */ + public void paint(Graphics g, JComponent c) + { + if (! (c instanceof JPopupMenu.Separator)) + return; + + Rectangle r = new Rectangle(); + SwingUtilities.calculateInnerArea(c, r); + Color saved = g.getColor(); + + int midAB = r.width / 2 + r.x; + int midAD = r.height / 2 + r.y; + + g.setColor(highlight); + g.drawLine(r.x, midAD, r.x + r.width, midAD); + + g.setColor(shadow); + g.drawLine(r.x, midAD + 1, r.x + r.width, midAD + 1); + } + + /** + * This method returns the preferred size of the + * JComponent. + * + * @param c The JComponent to measure. + * + * @return The preferred size. + */ + public Dimension getPreferredSize(JComponent c) + { + return super.getPreferredSize(c); + } +} diff --git a/libjava/javax/swing/plaf/basic/BasicProgressBarUI.java b/libjava/javax/swing/plaf/basic/BasicProgressBarUI.java index 4a74617726d..d171917172f 100644 --- a/libjava/javax/swing/plaf/basic/BasicProgressBarUI.java +++ b/libjava/javax/swing/plaf/basic/BasicProgressBarUI.java @@ -134,8 +134,7 @@ public class BasicProgressBarUI extends ProgressBarUI } /** The timer used to move the bouncing box. */ - private transient Timer animationTimer = new Timer(); - + private transient Timer animationTimer; // The total number of frames must be an even number. // The total number of frames is calculated from @@ -681,6 +680,8 @@ public class BasicProgressBarUI extends ProgressBarUI * This method starts the animation timer. It is called * when the propertyChangeListener detects that the progressBar * has changed to indeterminate mode. + * + * @since 1.4 */ protected void startAnimationTimer() { @@ -692,6 +693,8 @@ public class BasicProgressBarUI extends ProgressBarUI * This method stops the animation timer. It is called when * the propertyChangeListener detects that the progressBar * has changed to determinate mode. + * + * @since 1.4 */ protected void stopAnimationTimer() { @@ -794,7 +797,7 @@ public class BasicProgressBarUI extends ProgressBarUI { progressBar = (JProgressBar) c; - animationTimer = new Timer(); + animationTimer = new Timer(200, null); animationTimer.setRepeats(true); installDefaults(); diff --git a/libjava/javax/swing/plaf/basic/BasicScrollBarUI.java b/libjava/javax/swing/plaf/basic/BasicScrollBarUI.java index c52ca00409c..b16f2a733e2 100644 --- a/libjava/javax/swing/plaf/basic/BasicScrollBarUI.java +++ b/libjava/javax/swing/plaf/basic/BasicScrollBarUI.java @@ -791,7 +791,7 @@ public class BasicScrollBarUI extends ScrollBarUI implements LayoutManager, */ public Dimension getPreferredSize(JComponent c) { - layoutContainer(scrollbar); + calculatePreferredSize(); return preferredSize; } @@ -957,8 +957,7 @@ public class BasicScrollBarUI extends ScrollBarUI implements LayoutManager, trackRect = new Rectangle(); thumbRect = new Rectangle(); - scrollTimer = new Timer(); - scrollTimer.setDelay(200); + scrollTimer = new Timer(200, null); scrollTimer.setRepeats(true); installComponents(); diff --git a/libjava/javax/swing/plaf/basic/BasicSliderUI.java b/libjava/javax/swing/plaf/basic/BasicSliderUI.java index 7b5a52f832c..073e42c0fc1 100644 --- a/libjava/javax/swing/plaf/basic/BasicSliderUI.java +++ b/libjava/javax/swing/plaf/basic/BasicSliderUI.java @@ -618,8 +618,7 @@ public class BasicSliderUI extends SliderUI insetCache = slider.getInsets(); leftToRightCache = ! slider.getInverted(); - scrollTimer = new Timer(); - scrollTimer.setDelay(200); + scrollTimer = new Timer(200, null); scrollTimer.setRepeats(true); installDefaults(slider); diff --git a/libjava/javax/swing/plaf/basic/BasicTabbedPaneUI.java b/libjava/javax/swing/plaf/basic/BasicTabbedPaneUI.java index a0100558be5..b1929aa36d3 100644 --- a/libjava/javax/swing/plaf/basic/BasicTabbedPaneUI.java +++ b/libjava/javax/swing/plaf/basic/BasicTabbedPaneUI.java @@ -160,6 +160,8 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants // e.g. in the inset area. if (index != -1 && tabPane.isEnabledAt(index)) tabPane.setSelectedIndex(index); + tabPane.layout(); + tabPane.repaint(); } } @@ -1085,7 +1087,7 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants // we want to cover that entire space so that borders that run under // the tab area don't show up when we move the viewport around. - panel.setBounds(0, 0, w + p.x, h + p.y); + panel.setSize(w + p.x, h + p.y); } viewport.setViewPosition(findPointForIndex(currentScrollLocation)); } @@ -1154,31 +1156,6 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants */ private class ScrollingViewport extends JViewport implements UIResource { - /** - * This method is temporary until the viewport layouts are implemented. - * Need it because the flow layout it currently moves our panel around. - * - * @param g The graphics object to paint with. - */ - public void paint(Graphics g) - { - // FIXME: Remove this as well. - int tabC = tabPane.getTabCount() - 1; - if (tabC + 1 > 0) - { - int w = Math.max(rects[tabC].width + rects[tabC].x, tabAreaRect.width); - int h = Math.max(rects[tabC].height, tabAreaRect.height); - Point p = findPointForIndex(currentScrollLocation); - - // we want to cover that entire space so that borders that run under - // the tab area don't show up when we move the viewport around. - panel.setBounds(0, 0, w + p.x, h + p.y); - } - - // FIXME: Remove when ViewportLayout is done. - setViewPosition(findPointForIndex(currentScrollLocation)); - super.paint(g); - } } /** @@ -1998,7 +1975,7 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants int x, int y, int w, int h, boolean isSelected) { Color saved = g.getColor(); - + if (! isSelected || tabPlacement != SwingConstants.TOP) { g.setColor(shadow); diff --git a/libjava/javax/swing/plaf/basic/BasicTextUI.java b/libjava/javax/swing/plaf/basic/BasicTextUI.java index 321889c5124..af7ab7e3a9b 100644 --- a/libjava/javax/swing/plaf/basic/BasicTextUI.java +++ b/libjava/javax/swing/plaf/basic/BasicTextUI.java @@ -35,7 +35,6 @@ this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ - package javax.swing.plaf.basic; import java.awt.Color; @@ -55,133 +54,129 @@ import javax.swing.text.Position; import javax.swing.text.View; import javax.swing.text.ViewFactory; + public class BasicTextUI extends TextUI implements ViewFactory { - int gap = 3; - View view = null; // was: new RootView(); - Color textColor, disabledTextColor, normalBackgroundColor; - EditorKit kit = new DefaultEditorKit(); - - /* ***************************************************************** - * This View is way too incomplete to be of any use. To avoid errors - * when compiling with the Sun JDK, it has been commented out. - * -- Sascha Brawer (brawer@dandelis.ch) - * - * (begin of commented out section) - class RootView extends View - { - RootView() - { - super(null); - } - public void paint(Graphics g, Shape s) - { - if (view != null) - { - Rectangle r = s.getBounds(); - - view.setSize((int)r.getWidth(), - (int)r.getHeight()); - view.paint(g, s); - } - } - } - * (end of commented out section) - *************************************************************** */ - - public BasicTextUI() - { - } - - public static ComponentUI createUI(final JComponent c) - { - return new BasicTextUI(); - } - - - public void installUI(final JComponent c) - { - super.installUI(c); - - textColor = new Color(0,0,0); - disabledTextColor = new Color(130, 130, 130); - normalBackgroundColor = new Color(192,192,192); - } - - public Dimension getPreferredSize(JComponent c) - { - JTextComponent b = (JTextComponent) c; - - View v = getRootView(b); - - float w = v.getPreferredSpan(View.X_AXIS); - float h = v.getPreferredSpan(View.Y_AXIS); - - return new Dimension((int)w, (int) h); - } - - - public void paint(Graphics g, JComponent c) - { - // view.paint( - } - - public void damageRange(JTextComponent t, int p0, int p1) - { - damageRange(t, p0, p1, null, null); - } - - public void damageRange(JTextComponent t, - int p0, int p1, - Position.Bias firstBias, - Position.Bias secondBias) - { - } - - public EditorKit getEditorKit(JTextComponent t) - { - return kit; - } - - public int getNextVisualPositionFrom(JTextComponent t, - int pos, - Position.Bias b, - int direction, - Position.Bias[] biasRet) - throws BadLocationException - { - return 0; - } - - public View getRootView(JTextComponent t) - { - return view; - } - - public Rectangle modelToView(JTextComponent t, int pos) - throws BadLocationException - { - return modelToView(t, pos, null); - } - - public Rectangle modelToView(JTextComponent t, int pos, Position.Bias bias) - throws BadLocationException - { - return null; - } - - public int viewToModel(JTextComponent t, Point pt) - { - return viewToModel(t, pt, null); - } - - public int viewToModel(JTextComponent t, Point pt, Position.Bias[] biasReturn) - { - return 0; - } - - public View create (Element elem) + int gap = 3; + View view = null; // was: new RootView(); + Color textColor; + Color disabledTextColor; + Color normalBackgroundColor; + EditorKit kit = new DefaultEditorKit(); + + /* ***************************************************************** + * This View is way too incomplete to be of any use. To avoid errors + * when compiling with the Sun JDK, it has been commented out. + * -- Sascha Brawer (brawer@dandelis.ch) + * + * (begin of commented out section) + class RootView extends View + { + RootView() + { + super(null); + } + public void paint(Graphics g, Shape s) + { + if (view != null) + { + Rectangle r = s.getBounds(); + + view.setSize((int)r.getWidth(), + (int)r.getHeight()); + view.paint(g, s); + } + } + } + * (end of commented out section) + *************************************************************** */ + public BasicTextUI() + { + } + + public static ComponentUI createUI(final JComponent c) + { + return new BasicTextUI(); + } + + public void installUI(final JComponent c) + { + super.installUI(c); + + textColor = new Color(0, 0, 0); + disabledTextColor = new Color(130, 130, 130); + normalBackgroundColor = new Color(192, 192, 192); + } + + public Dimension getPreferredSize(JComponent c) + { + JTextComponent b = (JTextComponent) c; + + View v = getRootView(b); + + float w = v.getPreferredSpan(View.X_AXIS); + float h = v.getPreferredSpan(View.Y_AXIS); + + return new Dimension((int) w, (int) h); + } + + public void paint(Graphics g, JComponent c) + { + // view.paint( + } + + public void damageRange(JTextComponent t, int p0, int p1) + { + damageRange(t, p0, p1, null, null); + } + + public void damageRange(JTextComponent t, int p0, int p1, + Position.Bias firstBias, Position.Bias secondBias) + { + } + + public EditorKit getEditorKit(JTextComponent t) + { + return kit; + } + + public int getNextVisualPositionFrom(JTextComponent t, int pos, + Position.Bias b, int direction, + Position.Bias[] biasRet) + throws BadLocationException + { + return 0; + } + + public View getRootView(JTextComponent t) + { + return view; + } + + public Rectangle modelToView(JTextComponent t, int pos) + throws BadLocationException + { + return modelToView(t, pos, null); + } + + public Rectangle modelToView(JTextComponent t, int pos, Position.Bias bias) + throws BadLocationException + { + return null; + } + + public int viewToModel(JTextComponent t, Point pt) + { + return viewToModel(t, pt, null); + } + + public int viewToModel(JTextComponent t, Point pt, Position.Bias[] biasReturn) + { + return 0; + } + + public View create(Element elem) { // subclasses have to implement this to get this functionality return null; diff --git a/libjava/javax/swing/plaf/basic/BasicToolBarUI.java b/libjava/javax/swing/plaf/basic/BasicToolBarUI.java new file mode 100644 index 00000000000..9e935a2766d --- /dev/null +++ b/libjava/javax/swing/plaf/basic/BasicToolBarUI.java @@ -0,0 +1,340 @@ +/* BasicToolBarUI.java + Copyright (C) 2004 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.swing.plaf.basic; + +import java.awt.Component; +import java.awt.ComponentOrientation; +import java.awt.Container; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.GridLayout; +import java.awt.Point; +import java.util.Enumeration; +import javax.swing.JFrame; +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JToolBar; +import javax.swing.RootPaneContainer; +import javax.swing.UIDefaults; +import javax.swing.UIManager; +import javax.swing.border.Border; +import javax.swing.event.MouseInputListener; + +import java.beans.PropertyChangeListener; +import java.awt.event.ContainerListener; +import java.awt.event.FocusListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.event.WindowListener; + +import javax.swing.plaf.ComponentUI; +import javax.swing.plaf.ToolBarUI; + +public class BasicToolBarUI extends ToolBarUI +{ + + public class DragWindow + {} + + protected String constraintBeforeFloating; + protected Color dockingBorderColor; + protected Color dockingColor; + protected MouseInputListener dockingListener; + //protected KeyStroke downKey + // Deprecated. As of Java 2 platform v1.3. + protected BasicToolBarUI.DragWindow dragWindow; + protected Color floatingBorderColor; + protected Color floatingColor; + protected int focusedCompIndex; + //protected KeyStroke leftKey; + // Deprecated. As of Java 2 platform v1.3. + protected PropertyChangeListener propertyListener; + //protected KeyStroke rightKey; + // Deprecated. As of Java 2 platform v1.3. + protected JToolBar toolBar; + protected ContainerListener toolBarContListener; + protected FocusListener toolBarFocusListener; + // protected KeyStroke upKey; + // Deprecated. As of Java 2 platform v1.3. + + private Dimension maximumSize; + private Dimension minimumSize; + private Dimension preferredSize; + private boolean floating; + private boolean rolloverBorders; + + BasicToolBarUI(JToolBar b) + { + super(); + } + + /* Can Component c dock at Point p? */ + boolean canDock(Component c, Point p) + { + return false; + } + + protected MouseInputListener createDockingListener() + { + return null; + } + + protected BasicToolBarUI.DragWindow createDragWindow(JToolBar toolbar) + { + return null; + } + + protected JFrame createFloatingFrame(JToolBar toolbar) + { + return null; + } + + protected RootPaneContainer createFloatingWindow(JToolBar toolbar) + { + return null; + } + + protected WindowListener createFrameListener() + { + return null; + } + + protected Border createNonRolloverBorder() + { + return null; + } + + protected PropertyChangeListener createPropertyListener() + { + return null; + } + + protected Border createRolloverBorder() + { + return null; + } + + protected ContainerListener createToolBarContListener() + { + return null; + } + + protected FocusListener createToolBarFocusListener() + { + return null; + } + + public static ComponentUI createUI(JComponent c) + { + return new BasicToolBarUI((JToolBar) c); + } + + protected void dragTo(Point position, Point origin) + { + } + + protected void floatAt(Point position, Point origin) + { + } + + /* Return the Color which is displayed when over a docking area */ + Color getDockingColor() + { + return dockingColor; + } + + /* Return the Color which is displayed when over a floating area */ + Color getFloatingColor() + { + return floatingColor; + } + + /* See ComponentUI */ + public Dimension getMaximumSize(JComponent c) + { + return null; + } + + /* See ComponentUI */ + public Dimension getMinimumSize(JComponent c) + { + return null; + } + + /* See ComponentUI */ + public Dimension getPreferredSize(JComponent c) + { + return null; + } + + protected void installComponents() + { + } + + protected void installDefaults() + { + } + + protected void installKeyboardActions() + { + } + + protected void installListeners(JToolBar toolbar) + { + toolbar.addMouseListener(new MouseAdapter() { + public void mouseClicked(MouseEvent event) { + System.err.println("toolbar clicked"); + } + } ); + } + + /* Call setBorderToNonRollover for each child component of c */ + protected void installNonRolloverBorders(JComponent c) + { + } + + /* Call setBorderToNormal for each child component of c */ + protected void installNormalBorders(JComponent c) + { + } + + /* Call setBorderToRollover for each child component of c */ + protected void installRolloverBorders(JComponent c) + { + } + + public void installUI(JComponent c) + { + super.installUI(c); + if (c instanceof JToolBar) + { + toolBar = (JToolBar) c; + toolBar.setOpaque(true); + switch (toolBar.getOrientation()) { + case 0: toolBar.setLayout(new GridLayout(1, 0, 4, 4)); + break; + case 1: toolBar.setLayout(new GridLayout(0, 1, 4, 4)); + break; + } + installListeners(toolBar); + } + } + + boolean isFloating() + { + return false; + } + + boolean isRolloverBorders() + { + return false; + } + + protected void navigateFocusedComp(int direction) + { + } + + /* Make Component c have a non-rollover border (created by + createNonRolloverBorder). */ + protected void setBorderToNonRollover(Component c) + { + } + + /* Make Component c have the border that it originally had before being + added to the toolbar. */ + protected void setBorderToNormal(Component c) + { + } + + /* Make Component c have a rollover border (created by + createRolloverBorder). */ + protected void setBorderToRollover(Component c) + { + } + + /* Display in Color c when over a docking area */ + void setDockingColor(Color c) + { + dockingColor = c; + } + + void setFloating(boolean b, Point p) + { + } + + /* Display in Color c when over a floating area */ + void setFloatingColor(Color c) + { + floatingColor = c; + } + + void setFloatingLocation(int x, int y) + { + } + + void setOrientation(int orientation) + { + } + + /* Set flag to enable rollover borders for the toolbar */ + void setRolloverBorders(boolean rollover) + { + rolloverBorders = rollover; + } + + protected void uninstallComponents() + { + } + + protected void uninstallDefaults() + { + } + + protected void uninstallKeyboardActions() + { + } + + protected void uninstallListeners() + { + } + + public void uninstallUI(JComponent c) + { + } + +} diff --git a/libjava/javax/swing/plaf/basic/BasicViewportUI.java b/libjava/javax/swing/plaf/basic/BasicViewportUI.java index c1adad1853c..715c11a6845 100644 --- a/libjava/javax/swing/plaf/basic/BasicViewportUI.java +++ b/libjava/javax/swing/plaf/basic/BasicViewportUI.java @@ -173,10 +173,18 @@ public class BasicViewportUI extends ViewportUI g.clearRect(0, 0, portBounds.width, portBounds.height); } - view.paint(g2); + g2.translate(-pos.x, -pos.y); + try + { + view.paint(g2); + } + finally + { + g2.translate(pos.x, pos.y); + } g2 = null; g.drawImage(backingStoreImage, - -pos.x, -pos.y, + 0, 0, (ImageObserver)null); } } diff --git a/libjava/javax/swing/text/AbstractDocument.java b/libjava/javax/swing/text/AbstractDocument.java index 6408b22cdfb..18a8ea9e541 100644 --- a/libjava/javax/swing/text/AbstractDocument.java +++ b/libjava/javax/swing/text/AbstractDocument.java @@ -1,4 +1,4 @@ -/* AbstractDocument.java -- +/* AbstractDocument.java -- Copyright (C) 2002, 2004 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -37,6 +37,7 @@ exception statement from your version. */ package javax.swing.text; +import java.io.Serializable; import java.util.Dictionary; import java.util.Enumeration; import java.util.EventListener; @@ -47,321 +48,520 @@ import javax.swing.event.DocumentListener; import javax.swing.event.UndoableEditEvent; import javax.swing.event.UndoableEditListener; import javax.swing.tree.TreeNode; +import javax.swing.undo.AbstractUndoableEdit; +import javax.swing.undo.CompoundEdit; import javax.swing.undo.UndoableEdit; -public abstract class AbstractDocument implements Document -{ - Vector doc_list = new Vector(); - Vector undo_list = new Vector(); - // these still need to be implemented by a derived class: - public abstract Element getParagraphElement(int pos); - public abstract Element getDefaultRootElement(); +public abstract class AbstractDocument + implements Document, Serializable +{ + public abstract class AbstractElement + implements Element, TreeNode, Serializable + { + private static final long serialVersionUID = 1265312733007397733L; + + int count; + int offset; + AttributeSet attr; + Vector elts = new Vector(); + String name; + Element parent; + Vector kids = new Vector(); + TreeNode tree_parent; - // some inner classes sun says I should have: - abstract class AbstractElement implements Element, TreeNode + public AbstractElement(Element p, AttributeSet s) { - int count, offset; - AttributeSet attr; - Vector elts = new Vector(); - String name; - Element parent; - Vector kids = new Vector(); - TreeNode tree_parent; - - public AbstractElement(Element p, AttributeSet s) - { parent = p; attr = s; } - - public Enumeration children() { return kids.elements(); } - public boolean getAllowsChildren() { return true; } - public TreeNode getChildAt(int index) { return (TreeNode) kids.elementAt(index); } - public int getChildCount() { return kids.size(); } - public int getIndex(TreeNode node) { return kids.indexOf(node); } - public TreeNode getParent() { return tree_parent; } - - public AttributeSet getAttributes() { return attr; } - public Document getDocument() { return AbstractDocument.this; } - public Element getElement(int index) { return (Element)elts.elementAt(index); } - public String getName() { return name; } - public Element getParentElement() { return parent; } - - public abstract boolean isLeaf(); - public abstract int getEndOffset(); - public abstract int getElementCount(); - public abstract int getElementIndex(int offset); - public abstract int getStartOffset(); + parent = p; + attr = s; } - interface AttributeContext + public Enumeration children() { + return kids.elements(); } - - class BranchElement extends AbstractElement + public boolean getAllowsChildren() { - public BranchElement(Element e, AttributeSet a, int s, int end) - { super(e, a); } - - public boolean isLeaf() { return false; } - public int getEndOffset() { return 0; } - public int getElementCount() { return 0; } - public int getElementIndex(int offset) { return 0; } - public int getStartOffset() { return 0; } + return true; } - - interface Content - { - Position createPosition(int offset) throws BadLocationException; - int length(); - UndoableEdit insertString(int where, String str) throws BadLocationException; - UndoableEdit remove(int where, int nitems) throws BadLocationException; - String getString(int where, int len) throws BadLocationException; - void getChars(int where, int len, Segment txt) throws BadLocationException; - } - - class DefaultDocumentEvent implements DocumentEvent - { - public int len, off; - public Document getDocument() { return AbstractDocument.this; } - public int getLength() { return len; } - public int getOffset() { return off; } - public DocumentEvent.EventType getType() { return null; } - public DocumentEvent.ElementChange getChange(Element elem) { return null; } - } - - static class ElementEdit - { - } - - class LeafElement extends AbstractElement + + public TreeNode getChildAt(int index) { - LeafElement(Element e, AttributeSet a, int s, int end) - { super(e, a); } - - public boolean isLeaf() { return true; } - public int getEndOffset() { return 0; } - public int getElementCount() { return 0; } - public int getElementIndex(int offset) { return 0; } - public int getStartOffset() { return 0; } + return (TreeNode) kids.elementAt(index); } - - Content content; - - AbstractDocument(Content doc) + public int getChildCount() { - content = doc; + return kids.size(); } - - /******************************************************** - * - * the meat: - * - ***********/ - - public void addDocumentListener(DocumentListener listener) + public int getIndex(TreeNode node) { - doc_list.addElement(listener); + return kids.indexOf(node); } - - public void addUndoableEditListener(UndoableEditListener listener) + + public TreeNode getParent() { - undo_list.addElement(listener); - } - - protected Element createBranchElement(Element parent, AttributeSet a) - { - return new BranchElement(parent, a, 0, 0); + return tree_parent; } - - protected Element createLeafElement(Element parent, AttributeSet a, int p0, int p1) + + public AttributeSet getAttributes() { - return new LeafElement(parent, a, p0, p1-p0); + return attr; } - public Position createPosition(int offs) + public Document getDocument() { - final int a = offs; - return new Position() - { - public int getOffset() - { - return a; - } - }; + return AbstractDocument.this; } - - protected void fireChangedUpdate(DocumentEvent e) + + public Element getElement(int index) { + return (Element) elts.elementAt(index); } - - protected void fireInsertUpdate(DocumentEvent e) + + public String getName() { + return name; } - - protected void fireRemoveUpdate(DocumentEvent e) + + public Element getParentElement() { + return parent; } - - protected void fireUndoableEditUpdate(UndoableEditEvent e) + + public abstract boolean isLeaf(); + + public abstract int getEndOffset(); + + public abstract int getElementCount(); + + public abstract int getElementIndex(int offset); + + public abstract int getStartOffset(); + } + + public interface AttributeContext + { + } + + public class BranchElement extends AbstractElement + { + private static final long serialVersionUID = -8595176318868717313L; + + public BranchElement(Element e, AttributeSet a, int s, int end) { + super(e, a); } - int getAsynchronousLoadPriority() + + public boolean isLeaf() { - return 0; + return false; } - - protected AttributeContext getAttributeContext() + + public int getEndOffset() { - return null; + return 0; } - - Element getBidiRootElement() + + public int getElementCount() { - return null; + return 0; } - - protected Content getContent() + + public int getElementIndex(int offset) { - return content; + return 0; } - - protected Thread getCurrentWriter() + + public int getStartOffset() { - return null; + return 0; } + } + public interface Content + { + Position createPosition(int offset) throws BadLocationException; - public Dictionary getDocumentProperties() - { - return null; - } + int length(); + + UndoableEdit insertString(int where, String str) + throws BadLocationException; + + UndoableEdit remove(int where, int nitems) throws BadLocationException; + + String getString(int where, int len) throws BadLocationException; + + void getChars(int where, int len, Segment txt) throws BadLocationException; + } + + public class DefaultDocumentEvent extends CompoundEdit + implements DocumentEvent + { + private static final long serialVersionUID = -7406103236022413522L; + + public int len; + public int off; - public Position getEndPosition() + public Document getDocument() { - return null; + return AbstractDocument.this; } public int getLength() { - return content.length(); + return len; } - - public EventListener[] getListeners(Class listenerType) + + public int getOffset() { - return null; + return off; } - - public Object getProperty(Object key) + + public DocumentEvent.EventType getType() { - return null; + return null; } - public Element[] getRootElements() + public DocumentEvent.ElementChange getChange(Element elem) { - return null; + return null; } + } + + public static class ElementEdit extends AbstractUndoableEdit + { + private static final long serialVersionUID = -1216620962142928304L; + } + + public class LeafElement extends AbstractElement + { + private static final long serialVersionUID = 5115368706941283802L; - public Position getStartPosition() + public LeafElement(Element e, AttributeSet a, int s, int end) { - return null; + super(e, a); } - public String getText(int offset, int length) - { - try { - return content.getString(offset, length); - } catch (Exception e) { - System.out.println("Hmmm, fail to getText: " + offset + " -> " + length); - return null; - } - } - - public void getText(int offset, int length, Segment txt) - { - String a = getText(offset, length); - - if (a == null) - { - txt.offset = 0; - txt.count = 0; - txt.array = new char[0]; - return; - } - - txt.offset = offset; - txt.count = length; - - char chars[] = new char[ a.length() ]; - - a.getChars(0, a.length(), chars, 0); - - txt.array = chars; - } - - public void insertString(int offs, String str, AttributeSet a) - { - try { - content.insertString(offs, str); - } catch (Exception e) { - System.err.println("FAILED TO INSERT-STRING: " + e + ", at:"+offs); - } - } - - protected void insertUpdate(DefaultDocumentEvent chng, AttributeSet attr) - { - } - - protected void postRemoveUpdate(DefaultDocumentEvent chng) - { - } - - public void putProperty(Object key, Object value) - { - } - - public void readLock() - { - } - - public void readUnlock() - { - } - - public void remove(int offs, int len) + public boolean isLeaf() { + return true; } - - public void removeDocumentListener(DocumentListener listener) - { - } - - public void removeUndoableEditListener(UndoableEditListener listener) + + public int getEndOffset() { + return 0; } - - protected void removeUpdate(DefaultDocumentEvent chng) + + public int getElementCount() { + return 0; } - - public void render(Runnable r) + + public int getElementIndex(int offset) { + return 0; } - - void setAsynchronousLoadPriority(int p) + + public int getStartOffset() { + return 0; } + } + + private static final long serialVersionUID = -116069779446114664L; + + protected static final String BAD_LOCATION = "document location failure"; + + public static final String BidiElementName = "bidi level"; + public static final String ContentElementName = "content"; + public static final String ParagraphElementName = "paragraph"; + public static final String SectionElementName = "section"; + public static final String ElementNameAttribute = "$ename"; - void setDocumentProperties(Dictionary x) - { - } - - protected void writeLock() - { - } - - protected void writeUnlock() - { - } + Content content; + + protected AbstractDocument(Content doc) + { + this(doc, null); + } + + protected AbstractDocument(Content doc, AttributeContext context) + { + content = doc; + } + + protected EventListenerList listenerList = new EventListenerList(); + + // these still need to be implemented by a derived class: + public abstract Element getParagraphElement(int pos); + + public abstract Element getDefaultRootElement(); + + protected Element createBranchElement(Element parent, AttributeSet a) + { + return new BranchElement(parent, a, 0, 0); + } + + protected Element createLeafElement(Element parent, AttributeSet a, int p0, + int p1) + { + return new LeafElement(parent, a, p0, p1 - p0); + } + + public Position createPosition(int offs) + { + final int a = offs; + return new Position() + { + public int getOffset() + { + return a; + } + }; + } + + protected void fireChangedUpdate(DocumentEvent event) + { + DocumentListener[] listeners = getDocumentListeners(); + + for (int index = 0; index < listeners.length; ++index) + listeners[index].changedUpdate(event); + } + + protected void fireInsertUpdate(DocumentEvent event) + { + DocumentListener[] listeners = getDocumentListeners(); + + for (int index = 0; index < listeners.length; ++index) + listeners[index].insertUpdate(event); + } + + protected void fireRemoveUpdate(DocumentEvent event) + { + DocumentListener[] listeners = getDocumentListeners(); + + for (int index = 0; index < listeners.length; ++index) + listeners[index].removeUpdate(event); + } + + protected void fireUndoableEditUpdate(UndoableEditEvent event) + { + UndoableEditListener[] listeners = getUndoableEditListeners(); + + for (int index = 0; index < listeners.length; ++index) + listeners[index].undoableEditHappened(event); + } + + public int getAsynchronousLoadPriority() + { + return 0; + } + + protected AttributeContext getAttributeContext() + { + return null; + } + + public Element getBidiRootElement() + { + return null; + } + + protected Content getContent() + { + return content; + } + + protected Thread getCurrentWriter() + { + return null; + } + + public Dictionary getDocumentProperties() + { + return null; + } + + public Position getEndPosition() + { + return null; + } + + public int getLength() + { + return content.length(); + } + + public EventListener[] getListeners(Class listenerType) + { + return listenerList.getListeners(listenerType); + } + + public Object getProperty(Object key) + { + return null; + } + + public Element[] getRootElements() + { + return null; + } + + public Position getStartPosition() + { + return null; + } + + public String getText(int offset, int length) + { + try + { + return content.getString(offset, length); + } + catch (Exception e) + { + System.out.println("Hmmm, fail to getText: " + offset + " -> " + + length); + return null; + } + } + + public void getText(int offset, int length, Segment txt) + { + String a = getText(offset, length); + + if (a == null) + { + txt.offset = 0; + txt.count = 0; + txt.array = new char[0]; + return; + } + + txt.offset = offset; + txt.count = length; + + char[] chars = new char[a.length()]; + + a.getChars(0, a.length(), chars, 0); + + txt.array = chars; + } + + public void insertString(int offs, String str, AttributeSet a) + throws BadLocationException + { + content.insertString(offs, str); + } + + protected void insertUpdate(DefaultDocumentEvent chng, AttributeSet attr) + { + } + + protected void postRemoveUpdate(DefaultDocumentEvent chng) + { + } + + public void putProperty(Object key, Object value) + { + } + + public void readLock() + { + } + + public void readUnlock() + { + } + + public void remove(int offs, int len) + { + } + + /** + * Adds a <code>DocumentListener</code> object to this document. + * + * @param listener the listener to add + */ + public void addDocumentListener(DocumentListener listener) + { + listenerList.add(DocumentListener.class, listener); + } + + /** + * Removes a <code>DocumentListener</code> object from this document. + * + * @param listener the listener to remove + */ + public void removeDocumentListener(DocumentListener listener) + { + listenerList.remove(DocumentListener.class, listener); + } + + /** + * Returns add added <code>DocumentListener</code> objects. + * + * @return an array of listeners + */ + public DocumentListener[] getDocumentListeners() + { + return (DocumentListener[]) getListeners(DocumentListener.class); + } + + /** + * Adds a <code>UndoableEditListener</code> object to this document. + * + * @param listener the listener to add + */ + public void addUndoableEditListener(UndoableEditListener listener) + { + listenerList.add(UndoableEditListener.class, listener); + } + + /** + * Removes a <code>UndoableEditListener</code> object from this document. + * + * @param listener the listener to remove + */ + public void removeUndoableEditListener(UndoableEditListener listener) + { + listenerList.remove(UndoableEditListener.class, listener); + } + + /** + * Returns add added <code>UndoableEditListener</code> objects. + * + * @return an array of listeners + */ + public UndoableEditListener[] getUndoableEditListeners() + { + return (UndoableEditListener[]) getListeners(UndoableEditListener.class); + } + + protected void removeUpdate(DefaultDocumentEvent chng) + { + } + + public void render(Runnable r) + { + } + + public void setAsynchronousLoadPriority(int p) + { + } + + public void setDocumentProperties(Dictionary x) + { + } + + protected void writeLock() + { + } + + protected void writeUnlock() + { + } } diff --git a/libjava/javax/swing/text/BadLocationException.java b/libjava/javax/swing/text/BadLocationException.java index d62ad5465f9..01463d139bd 100644 --- a/libjava/javax/swing/text/BadLocationException.java +++ b/libjava/javax/swing/text/BadLocationException.java @@ -1,5 +1,5 @@ -/* BadLocationException.java -- - Copyright (C) 2002 Free Software Foundation, Inc. +/* BadLocationException.java -- + Copyright (C) 2002, 2004 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -37,27 +37,28 @@ exception statement from your version. */ package javax.swing.text; - public class BadLocationException extends Exception -{ - int offset; +{ + private static final long serialVersionUID = -7712259886815656766L; + int offset; + /** * Constructs a <code>BadLocationException</code> * * @param str A string indicating what was wrong with the arguments * @param offset Offset within the document that was requested >= 0 */ - public BadLocationException (String str, int offset) + public BadLocationException(String str, int offset) { - super (str); + super(str); this.offset = offset; } /** * Returns the offset into the document that was not legal */ - public int offsetRequested () + public int offsetRequested() { return offset; } diff --git a/libjava/javax/swing/text/DefaultCaret.java b/libjava/javax/swing/text/DefaultCaret.java index 1c4607fce9f..d79e920aa94 100644 --- a/libjava/javax/swing/text/DefaultCaret.java +++ b/libjava/javax/swing/text/DefaultCaret.java @@ -1,4 +1,4 @@ -/* DefaultCaret.java -- +/* DefaultCaret.java -- Copyright (C) 2002, 2004 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -44,132 +44,184 @@ import java.awt.Rectangle; import java.awt.event.FocusListener; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; -import java.util.Vector; +import java.util.EventListener; +import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; -public class DefaultCaret extends Rectangle implements Caret, FocusListener, MouseListener, MouseMotionListener +public class DefaultCaret extends Rectangle + implements Caret, FocusListener, MouseListener, MouseMotionListener { - Color color = new Color(0,0,0); - JTextComponent parent; - - public void mouseDragged(java.awt.event.MouseEvent evt) - { - } - - public void mouseMoved(java.awt.event.MouseEvent evt) - { - } - - public void mouseClicked(java.awt.event.MouseEvent evt) - { - } - - public void mouseEntered(java.awt.event.MouseEvent evt) - { - } - - public void mouseExited(java.awt.event.MouseEvent evt) - { - } - - public void mousePressed(java.awt.event.MouseEvent evt) - { - } - - public void mouseReleased(java.awt.event.MouseEvent evt) - { - } - - public void focusGained(java.awt.event.FocusEvent evt) - { - } - - public void focusLost(java.awt.event.FocusEvent evt) - { - } - - // caret methods: - - public void deinstall(JTextComponent c) - { - parent.removeFocusListener(this); - parent.removeMouseListener(this); - - parent = null; - } - public void install(JTextComponent c) - { - parent.addFocusListener(this); - parent.addMouseListener(this); - parent = c; - repaint(); - } - - Point magic = null; - public void setMagicCaretPosition(Point p) - { magic = p; } - public Point getMagicCaretPosition() - { return magic; } - - - int mark = 0; - public int getMark() - { return mark; } - - boolean vis_sel = true; - public void setSelectionVisible(boolean v) - { vis_sel = v; repaint(); } - public boolean isSelectionVisible() - { return vis_sel; } - - private void repaint() - { - if (parent != null) - { - parent.repaint(); - } - } - - public void paint(Graphics g) - { - g.setColor(color); - g.drawLine(x,y, - x,y+height); - } - - - Vector changes = new Vector(); - public void addChangeListener(ChangeListener l) - { changes.addElement(l); } - public void removeChangeListener(ChangeListener l) - { changes.removeElement(l); } - - - int blink = 500; - public int getBlinkRate() - { return blink; } - public void setBlinkRate(int rate) - { blink = rate; } - - int dot = 0; - public int getDot() - { return dot; } - public void moveDot(int dot) - { setDot(dot); } - public void setDot(int dot) - { - this.dot = dot; - repaint(); - } - - boolean vis = true; - public boolean isVisible() - { return vis; } - public void setVisible(boolean v) - { - vis = v; - repaint(); - } + protected ChangeEvent changeEvent = new ChangeEvent(this); + protected EventListenerList listenerList = new EventListenerList(); + + Color color = new Color(0, 0, 0); + JTextComponent parent; + Point magic = null; + int mark = 0; + boolean vis_sel = true; + int blink = 500; + int dot = 0; + boolean vis = true; + + + public void mouseDragged(java.awt.event.MouseEvent evt) + { + } + + public void mouseMoved(java.awt.event.MouseEvent evt) + { + } + + public void mouseClicked(java.awt.event.MouseEvent evt) + { + } + + public void mouseEntered(java.awt.event.MouseEvent evt) + { + } + + public void mouseExited(java.awt.event.MouseEvent evt) + { + } + + public void mousePressed(java.awt.event.MouseEvent evt) + { + } + + public void mouseReleased(java.awt.event.MouseEvent evt) + { + } + + public void focusGained(java.awt.event.FocusEvent evt) + { + } + + public void focusLost(java.awt.event.FocusEvent evt) + { + } + + public void deinstall(JTextComponent c) + { + parent.removeFocusListener(this); + parent.removeMouseListener(this); + parent = null; + } + + public void install(JTextComponent c) + { + parent.addFocusListener(this); + parent.addMouseListener(this); + parent = c; + repaint(); + } + + public void setMagicCaretPosition(Point p) + { + magic = p; + } + + public Point getMagicCaretPosition() + { + return magic; + } + + public int getMark() + { + return mark; + } + + public void setSelectionVisible(boolean v) + { + vis_sel = v; + repaint(); + } + + public boolean isSelectionVisible() + { + return vis_sel; + } + + private void repaint() + { + if (parent != null) + parent.repaint(); + } + + public void paint(Graphics g) + { + g.setColor(color); + g.drawLine(x, y, x, y + height); + } + + public EventListener[] getListeners(Class listenerType) + { + return listenerList.getListeners(listenerType); + } + + public void addChangeListener(ChangeListener listener) + { + listenerList.add(ChangeListener.class, listener); + } + + public void removeChangeListener(ChangeListener listener) + { + listenerList.remove(ChangeListener.class, listener); + } + + public ChangeListener[] getChangeListeners() + { + return (ChangeListener[]) getListeners(ChangeListener.class); + } + + protected void fireStateChanged() + { + ChangeListener[] listeners = getChangeListeners(); + + for (int index = 0; index < listeners.length; ++index) + listeners[index].stateChanged(changeEvent); + } + + protected final JTextComponent getComponent() + { + return parent; + } + + public int getBlinkRate() + { + return blink; + } + + public void setBlinkRate(int rate) + { + blink = rate; + } + + public int getDot() + { + return dot; + } + + public void moveDot(int dot) + { + setDot(dot); + } + + public void setDot(int dot) + { + this.dot = dot; + repaint(); + } + + public boolean isVisible() + { + return vis; + } + + public void setVisible(boolean v) + { + vis = v; + repaint(); + } } diff --git a/libjava/javax/swing/text/Document.java b/libjava/javax/swing/text/Document.java index 351b0aa6066..6ecb7ca21db 100644 --- a/libjava/javax/swing/text/Document.java +++ b/libjava/javax/swing/text/Document.java @@ -1,4 +1,4 @@ -/* Document.java -- +/* Document.java -- Copyright (C) 2002, 2004 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -40,27 +40,44 @@ package javax.swing.text; import javax.swing.event.DocumentListener; import javax.swing.event.UndoableEditListener; + public interface Document -{ +{ String StreamDescriptionProperty = "stream"; - String TitleProperty = "text"; void addDocumentListener(DocumentListener listener); + void addUndoableEditListener(UndoableEditListener listener); + Position createPosition(int offs); + Element getDefaultRootElement(); + Position getEndPosition(); + int getLength(); + Object getProperty(Object key); + Element[] getRootElements(); + Position getStartPosition(); + String getText(int offset, int length); + void getText(int offset, int length, Segment txt); - void insertString(int offset, String str, AttributeSet a); + + void insertString(int offset, String str, AttributeSet a) + throws BadLocationException; + void putProperty(Object key, Object value); + void remove(int offs, int len); + void removeDocumentListener(DocumentListener listener); + void removeUndoableEditListener(UndoableEditListener listener); + void render(Runnable r); } diff --git a/libjava/javax/swing/text/GapContent.java b/libjava/javax/swing/text/GapContent.java index 50165437716..93446826868 100644 --- a/libjava/javax/swing/text/GapContent.java +++ b/libjava/javax/swing/text/GapContent.java @@ -1,4 +1,4 @@ -/* GapContent.java -- +/* GapContent.java -- Copyright (C) 2002, 2004 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -35,69 +35,75 @@ 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; +package javax.swing.text; + +import java.io.Serializable; // too lazy to make a real gapcontent. // lets just use a stringbuffer instead. - import javax.swing.undo.UndoableEdit; -public class GapContent implements AbstractDocument.Content +public class GapContent + implements AbstractDocument.Content, Serializable { - StringBuffer buf = new StringBuffer(); - - public GapContent() - { - this(10); - } + private static final long serialVersionUID = 8374645204155842629L; - public GapContent(int size) - { - } - - public Position createPosition(final int offset) throws BadLocationException - { - return new Position() - { - int off = offset; - public int getOffset() - { - return off; - } - }; - } - - public int length() - { - return buf.length(); - } - - public UndoableEdit insertString(int where, String str) throws BadLocationException - { - buf.insert(where, str); - return null; - } - - public UndoableEdit remove(int where, int nitems) throws BadLocationException - { - buf.delete(where, where + nitems); - return null; - } - - public String getString(int where, int len) throws BadLocationException - { - return buf.toString(); - } - - public void getChars(int where, int len, Segment txt) throws BadLocationException - { - txt.array = new char[len]; - - System.arraycopy(buf.toString().toCharArray(), where, - txt.array, 0, - len); - - txt.count = len; - txt.offset = 0; - } + StringBuffer buf = new StringBuffer(); + + public GapContent() + { + this(10); + } + + public GapContent(int size) + { + } + + public Position createPosition(final int offset) throws BadLocationException + { + return new Position() + { + int off = offset; + + public int getOffset() + { + return off; + } + }; + } + + public int length() + { + return buf.length(); + } + + public UndoableEdit insertString(int where, String str) + throws BadLocationException + { + buf.insert(where, str); + return null; + } + + public UndoableEdit remove(int where, int nitems) + throws BadLocationException + { + buf.delete(where, where + nitems); + return null; + } + + public String getString(int where, int len) throws BadLocationException + { + return buf.toString(); + } + + public void getChars(int where, int len, Segment txt) + throws BadLocationException + { + txt.array = new char[len]; + + System.arraycopy(buf.toString().toCharArray(), where, txt.array, 0, len); + + txt.count = len; + txt.offset = 0; + } } diff --git a/libjava/javax/swing/text/JTextComponent.java b/libjava/javax/swing/text/JTextComponent.java index 48bb0c03ce6..6451ef5c31f 100644 --- a/libjava/javax/swing/text/JTextComponent.java +++ b/libjava/javax/swing/text/JTextComponent.java @@ -1,5 +1,5 @@ -/* JTextComponent.java -- - Copyright (C) 2002 Free Software Foundation, Inc. +/* JTextComponent.java -- + Copyright (C) 2002, 2004 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -42,8 +42,10 @@ import java.awt.Component; import java.awt.Dimension; import java.awt.Image; import java.awt.Insets; -import java.awt.Rectangle; import java.awt.Point; +import java.awt.Rectangle; +import java.awt.event.InputMethodListener; + import javax.accessibility.Accessible; import javax.accessibility.AccessibleContext; import javax.accessibility.AccessibleRole; @@ -51,6 +53,7 @@ import javax.accessibility.AccessibleStateSet; import javax.accessibility.AccessibleText; import javax.swing.Icon; import javax.swing.JComponent; +import javax.swing.JViewport; import javax.swing.KeyStroke; import javax.swing.Scrollable; import javax.swing.UIManager; @@ -60,6 +63,7 @@ import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; import javax.swing.plaf.TextUI; + public abstract class JTextComponent extends JComponent implements Scrollable, Accessible { @@ -67,410 +71,323 @@ public abstract class JTextComponent extends JComponent // implements AccessibleText, CaretListener, DocumentListener, // AccessibleAction, AccessibleEditableText // { -// } // class AccessibleJTextComponent - - /** - * AccessibleJTextComponent - */ - public class AccessibleJTextComponent extends AccessibleJComponent - implements AccessibleText, CaretListener, DocumentListener { - - //------------------------------------------------------------- - // Variables -------------------------------------------------- - //------------------------------------------------------------- - - /** - * caretPos - */ - int caretPos; - - - //------------------------------------------------------------- - // Initialization --------------------------------------------- - //------------------------------------------------------------- - - /** - * Constructor AccessibleJTextComponent - * @param component TODO - */ - public AccessibleJTextComponent(JTextComponent component) { - super(component); - // TODO - } // AccessibleJTextComponent() - - - //------------------------------------------------------------- - // Methods ---------------------------------------------------- - //------------------------------------------------------------- - - /** - * getCaretPosition - * @returns int - */ - public int getCaretPosition() { - return 0; // TODO - } // getCaretPosition() - - /** - * getSelectedText - * @returns String - */ - public String getSelectedText() { - return null; // TODO - } // getSelectedText() - - /** - * getSelectionStart - * @returns int - */ - public int getSelectionStart() { - return 0; // TODO - } // getSelectionStart() - - /** - * getSelectionEnd - * @returns int - */ - public int getSelectionEnd() { - return 0; // TODO - } // getSelectionEnd() - - /** - * caretUpdate - * @param value0 TODO - */ - public void caretUpdate(CaretEvent value0) { - // TODO - } // caretUpdate() - - /** - * getAccessibleStateSet - * @returns AccessibleStateSet - */ - public AccessibleStateSet getAccessibleStateSet() { - return null; // TODO - } // getAccessibleStateSet() - - /** - * getAccessibleRole - * @returns AccessibleRole - */ - public AccessibleRole getAccessibleRole() { - return null; // TODO - } // getAccessibleRole() - - /** - * getAccessibleText - * @returns AccessibleText - */ - public AccessibleText getAccessibleText() { - return null; // TODO - } // getAccessibleText() - - /** - * insertUpdate - * @param value0 TODO - */ - public void insertUpdate(DocumentEvent value0) { - // TODO - } // insertUpdate() - - /** - * removeUpdate - * @param value0 TODO - */ - public void removeUpdate(DocumentEvent value0) { - // TODO - } // removeUpdate() - - /** - * changedUpdate - * @param value0 TODO - */ - public void changedUpdate(DocumentEvent value0) { - // TODO - } // changedUpdate() - - /** - * getIndexAtPoint - * @param value0 TODO - * @returns int - */ - public int getIndexAtPoint(Point value0) { - return 0; // TODO - } // getIndexAtPoint() - - /** - * getRootEditorRect - * @returns Rectangle - */ - Rectangle getRootEditorRect() { - return null; // TODO - } // getRootEditorRect() - - /** - * getCharacterBounds - * @param value0 TODO - * @returns Rectangle - */ - public Rectangle getCharacterBounds(int value0) { - return null; // TODO - } // getCharacterBounds() - - /** - * getCharCount - * @returns int - */ - public int getCharCount() { - return 0; // TODO - } // getCharCount() - - /** - * getCharacterAttribute - * @param value0 TODO - * @returns AttributeSet - */ - public AttributeSet getCharacterAttribute(int value0) { - return null; // TODO - } // getCharacterAttribute() - - /** - * getAtIndex - * @param value0 TODO - * @param value1 TODO - * @returns String - */ - public String getAtIndex(int value0, int value1) { - return null; // TODO - } // getAtIndex() - - /** - * getAfterIndex - * @param value0 TODO - * @param value1 TODO - * @returns String - */ - public String getAfterIndex(int value0, int value1) { - return null; // TODO - } // getAfterIndex() - - /** - * getBeforeIndex - * @param value0 TODO - * @param value1 TODO - * @returns String - */ - public String getBeforeIndex(int value0, int value1) { - return null; // TODO - } // getBeforeIndex() - - - } // AccessibleJTextComponent - +// } - - public static class KeyBinding + /** + * AccessibleJTextComponent + */ + public class AccessibleJTextComponent extends AccessibleJComponent + implements AccessibleText, CaretListener, DocumentListener { - public KeyStroke key; - public String actionName; - public KeyBinding(KeyStroke key, String actionName) - { - this.key = key; - this.actionName = actionName; - } - } // class KeyBinding + private static final long serialVersionUID = 7664188944091413696L; - int icon_gap; - Icon icon; - int align; - Document doc; + /** + * caretPos + */ + int caretPos; - public JTextComponent() + /** + * Constructor AccessibleJTextComponent + * @param component TODO + */ + public AccessibleJTextComponent() { - this("", null, 0); } - public JTextComponent(Icon image) + /** + * getCaretPosition + * @return int + */ + public int getCaretPosition() { - this("", image, 0); + return 0; // TODO } - public JTextComponent(Icon image, int horizontalAlignment) + /** + * getSelectedText + * @return String + */ + public String getSelectedText() { - this("", image, horizontalAlignment); + return null; // TODO } - public JTextComponent(String text) + /** + * getSelectionStart + * @return int + */ + public int getSelectionStart() { - this(text, null, 0); + return 0; // TODO } - public JTextComponent(String text, int horizontalAlignment) + /** + * getSelectionEnd + * @return int + */ + public int getSelectionEnd() { - this(text, null, horizontalAlignment); + return 0; // TODO } - public JTextComponent(String text, Icon icon, int horizontalAlignment) + /** + * caretUpdate + * @param value0 TODO + */ + public void caretUpdate(CaretEvent value0) { - setDocument(new PlainDocument()); - - // do the work..... - setText(text); - this.icon = icon; - this.align = horizontalAlignment; - - // its an editor, so: - enableEvents(AWTEvent.KEY_EVENT_MASK); - updateUI(); + // TODO } - public void setDocument(Document s) + /** + * getAccessibleStateSet + * @return AccessibleStateSet + */ + public AccessibleStateSet getAccessibleStateSet() { - doc = s; - revalidate(); - repaint(); + return null; // TODO } - public Document getDocument() + /** + * getAccessibleRole + * @return AccessibleRole + */ + public AccessibleRole getAccessibleRole() { - if (doc == null) - System.out.println("doc == null !!!"); - return doc; + return null; // TODO } - protected int checkHorizontalKey(int key, String message) - { - // Verify that key is a legal value for the horizontalAlignment properties. - return 0; - } - protected int checkVerticalKey(int key, String message) - { - // Verify that key is a legal value for the verticalAlignment or verticalTextPosition properties. - return 0; - } - public AccessibleContext getAccessibleContext() - { - // Get the AccessibleContext of this object - return null; - } - public Icon getDisabledIcon() + /** + * getAccessibleText + * @return AccessibleText + */ + public AccessibleText getAccessibleText() { - return null; + return null; // TODO } - public int getDisplayedMnemonic() - { - // Return the keycode that indicates a mnemonic key. - return 0; - } - public int getHorizontalAlignment() - { - // Returns the alignment of the label's contents along the X axis. - return 0; - } - public int getHorizontalTextPosition() - { - // Returns the horizontal position of the label's text, relative to its image. - return 0; - } - - public Icon getIcon() - { return icon; } - public int getIconTextGap() - { return icon_gap; } - - Component getLabelFor() + /** + * insertUpdate + * @param value0 TODO + */ + public void insertUpdate(DocumentEvent value0) { - // Get the component this is labelling. - return null; + // TODO } - public Insets getMargin() + /** + * removeUpdate + * @param value0 TODO + */ + public void removeUpdate(DocumentEvent value0) { - // FIXME: Not implemented. - return null; + // TODO } - public void setText(String text) - { - getDocument().remove(0,doc.getLength()); - getDocument().insertString(0, text, null); - } - - public String getText() + /** + * changedUpdate + * @param value0 TODO + */ + public void changedUpdate(DocumentEvent value0) { - return getDocument().getText(0, - getDocument().getLength()); + // TODO } - public String getUIClassID() - { - // Returns a string that specifies the name of the l&f class that renders this component. - return "TextComponentUI"; - } - public int getVerticalAlignment() - { - // Returns the alignment of the label's contents along the Y axis. - return 0; - } - public int getVerticalTextPosition() + /** + * getIndexAtPoint + * @param value0 TODO + * @return int + */ + public int getIndexAtPoint(Point value0) { - // Returns the vertical position of the label's text, relative to its image. - return 0; + return 0; // TODO } - public boolean imageUpdate(Image img, int infoflags, int x, int y, int w, int h) - { - // This is overriden to return false if the current Icon's Image is not equal to the passed in Image img. - return (img == icon); - } - protected String paramString() + /** + * getRootEditorRect + * @return Rectangle + */ + Rectangle getRootEditorRect() { - // Returns a string representation of this JTextComponent. - return "JTextComponent"; + return null; } - void setDisabledIcon(Icon disabledIcon) + + /** + * getCharacterBounds + * @param value0 TODO + * @return Rectangle + */ + public Rectangle getCharacterBounds(int value0) { - // Set the icon to be displayed if this JTextComponent is "disabled" (JTextComponent.setEnabled(false)). + return null; // TODO } - void setDisplayedMnemonic(char aChar) + + /** + * getCharCount + * @return int + */ + public int getCharCount() { - // Specifies the displayedMnemonic as a char value. + return 0; // TODO } - void setDisplayedMnemonic(int key) + + /** + * getCharacterAttribute + * @param value0 TODO + * @return AttributeSet + */ + public AttributeSet getCharacterAttribute(int value0) { - // Specify a keycode that indicates a mnemonic key. + return null; // TODO } - void setHorizontalAlignment(int alignment) + + /** + * getAtIndex + * @param value0 TODO + * @param value1 TODO + * @return String + */ + public String getAtIndex(int value0, int value1) { - // Sets the alignment of the label's contents along the X axis. + return null; // TODO } - void setHorizontalTextPosition(int textPosition) + + /** + * getAfterIndex + * @param value0 TODO + * @param value1 TODO + * @return String + */ + public String getAfterIndex(int value0, int value1) { - // Sets the horizontal position of the label's text, relative to its image. + return null; // TODO } - void setIcon(Icon icon) + + /** + * getBeforeIndex + * @param value0 TODO + * @param value1 TODO + * @return String + */ + public String getBeforeIndex(int value0, int value1) { - // Defines the icon this component will display. + return null; // TODO } - public void setIconTextGap(int iconTextGap) + } + + public static class KeyBinding + { + public KeyStroke key; + public String actionName; + + public KeyBinding(KeyStroke key, String actionName) { - // If both the icon and text properties are set, this property defines the space between them. + this.key = key; + this.actionName = actionName; } + } + + private static final long serialVersionUID = -8796518220218978795L; - public void setLabelFor(Component c) - { - // Set the component this is labelling. - } - - public void setVerticalAlignment(int alignment) - { - // Sets the alignment of the label's contents along the Y axis. - } - public void setVerticalTextPosition(int textPosition) - { - // Sets the vertical position of the label's text, relative to its image. - } + public static final String DEFAULT_KEYMAP = "default"; + public static final String FOCUS_ACCELERATOR_KEY = "focusAcceleratorKey"; + + private Document doc; + private Caret caret; + private boolean editable; + + public JTextComponent() + { + enableEvents(AWTEvent.KEY_EVENT_MASK); + updateUI(); + } + + public void setDocument(Document s) + { + doc = s; + revalidate(); + repaint(); + } + + public Document getDocument() + { + if (doc == null) + System.out.println("doc == null !!!"); + return doc; + } + + /** + * Get the AccessibleContext of this object + */ + public AccessibleContext getAccessibleContext() + { + return null; + } + + public Insets getMargin() + { + // FIXME: Not implemented. + return null; + } + + public void setText(String text) + { + try + { + getDocument().remove(0, doc.getLength()); + getDocument().insertString(0, text, null); + } + catch (BadLocationException e) + { + } + } + + /** + * Retrieves the current text in this text document. + * + * @return the text + * + * @exception NullPointerException if the underlaying document is null + */ + public String getText() + { + return getDocument().getText(0, getDocument().getLength()); + } + + /** + * Retrieves a part of the current text in this document. + * + * @param offset the postion of the first character + * @param length the length of the text to retrieve + * + * @return the text + * + * @exception BadLocationException if arguments do not hold pre-conditions + */ + public String getText(int offset, int length) + throws BadLocationException + { + return getDocument().getText(offset, length); + } + + /** + * Returns a string that specifies the name of the l&f class + * that renders this component. + * + * @return the string "TextComponentUI" + */ + public String getUIClassID() + { + return "TextComponentUI"; + } + + /** + * Returns a string representation of this JTextComponent. + */ + protected String paramString() + { + return "JTextComponent"; + } public TextUI getUI() { @@ -486,26 +403,246 @@ public abstract class JTextComponent extends JComponent { return null; } + public int getScrollableUnitIncrement(Rectangle visible, int orientation, int direction) { return 0; } + public int getScrollableBlockIncrement(Rectangle visible, int orientation, int direction) { return 0; } -} // class JTextComponent + /** + * Checks whether this text component it editable. + * + * @return true if editable, false otherwise + */ + public boolean isEditable() + { + return editable; + } + + /** + * Enables/disabled this text component's editability. + * + * @param editable true to make it editable, false otherwise. + */ + public void setEditable(boolean editable) + { + firePropertyChange("editable", this.editable, editable); + this.editable = editable; + } + + /** + * The <code>Caret</code> object used in this text component. + * + * @return the caret object + */ + public Caret getCaret() + { + return caret; + } + + /** + * Retrisves the current caret position. + * + * @return the current position + */ + public int getCaretPosition() + { + return caret.getDot(); + } + + /** + * Sets the caret to a new position. + * + * @param position the new position + */ + public void setCaretPosition(int position) + { + if (doc == null) + return; + + if (position < 0 || position > doc.getLength()) + throw new IllegalArgumentException(); + + caret.setDot(position); + } + + /** + * Moves the caret to a given position. This selects the text between + * the old and the new position of the caret. + */ + public void moveCaretPosition(int position) + { + if (doc == null) + return; + + if (position < 0 || position > doc.getLength()) + throw new IllegalArgumentException(); + + caret.moveDot(position); + } + + /** + * Returns the start postion of the currently selected text. + * + * @return the start postion + */ + public int getSelectionStart() + { + return Math.min(caret.getDot(), caret.getMark()); + } + + /** + * Selects the text from the given postion to the selection end position. + * + * @param end the start positon of the selected text. + */ + public void setSelectionStart(int start) + { + select(start, getSelectionEnd()); + } + + /** + * Returns the end postion of the currently selected text. + * + * @return the end postion + */ + public int getSelectionEnd() + { + return Math.max(caret.getDot(), caret.getMark()); + } + + /** + * Selects the text from the selection start postion to the given position. + * + * @param end the end positon of the selected text. + */ + public void setSelectionEnd(int end) + { + select(getSelectionStart(), end); + } + + /** + * Selects a part of the content of the text component. + * + * @param start the start position of the selected text + * @param ent the end position of the selected text + */ + public void select(int start, int end) + { + int length = doc.getLength(); + + start = Math.max(start, 0); + start = Math.min(start, length); + + end = Math.max(end, 0); + end = Math.min(end, length); + + setCaretPosition(start); + moveCaretPosition(end); + } + + /** + * Selects the whole content of the text component. + */ + public void selectAll() + { + select(0, doc.getLength()); + } + + public boolean getScrollableTracksViewportHeight() + { + if (getParent() instanceof JViewport) + return ((JViewport) getParent()).getHeight() > getPreferredSize().height; + return false; + } + public boolean getScrollableTracksViewportWidth() + { + if (getParent() instanceof JViewport) + return ((JViewport) getParent()).getWidth() > getPreferredSize().width; + return false; + } + /** + * Adds a <code>CaretListener</code> object to this text component. + * + * @param listener the listener to add + */ + public void addCaretListener(CaretListener listener) + { + listenerList.add(CaretListener.class, listener); + } + /** + * Removed a <code>CaretListener</code> object from this text component. + * + * @param listener the listener to remove + */ + public void removeCaretListener(CaretListener listener) + { + listenerList.remove(CaretListener.class, listener); + } + /** + * Returns all added <code>CaretListener</code> objects. + * + * @return an array of listeners + */ + public CaretListener[] getCaretListeners() + { + return (CaretListener[]) getListeners(CaretListener.class); + } + /** + * Notifies all registered <code>CaretListener</code> objects that the caret + * was updated. + * + * @param event the event to send + */ + protected void fireCaretUpdate(CaretEvent event) + { + CaretListener[] listeners = getCaretListeners(); + for (int index = 0; index < listeners.length; ++index) + listeners[index].caretUpdate(event); + } + /** + * Adds an <code>InputListener</code> object to this text component. + * + * @param listener the listener to add + */ + public void addInputMethodListener(InputMethodListener listener) + { + listenerList.add(InputMethodListener.class, listener); + } + /** + * Removes an <code>InputListener</code> object from this text component. + * + * @param listener the listener to remove + */ + public void removeInputMethodListener(InputMethodListener listener) + { + listenerList.remove(InputMethodListener.class, listener); + } + /** + * Returns all added <code>InputMethodListener</code> objects. + * + * @return an array of listeners + */ + public InputMethodListener[] getInputMethodListeners() + { + return (InputMethodListener[]) getListeners(InputMethodListener.class); + } +} diff --git a/libjava/javax/swing/text/MutableAttributeSet.java b/libjava/javax/swing/text/MutableAttributeSet.java index 6bc18df1cbc..d8cb62a7b26 100644 --- a/libjava/javax/swing/text/MutableAttributeSet.java +++ b/libjava/javax/swing/text/MutableAttributeSet.java @@ -44,48 +44,42 @@ import java.util.Enumeration; * @author Andrew Selkirk * @version 1.0 */ -public interface MutableAttributeSet extends AttributeSet { - - //------------------------------------------------------------- - // Methods ---------------------------------------------------- - //------------------------------------------------------------- - - /** - * addAttribute - * @param name TODO - * @param value TODO - */ - void addAttribute(Object name, Object value); - - /** - * addAttributes - * @param attributes TODO - */ - void addAttributes(AttributeSet attributes); - - /** - * removeAttribute - * @param name TODO - */ - void removeAttribute(Object name); - - /** - * removeAttributes - * @param names TODO - */ - void removeAttributes(Enumeration names); - - /** - * removeAttributes - * @param attributes TODO - */ - void removeAttributes(AttributeSet attributes); - - /** - * setResolveParent - * @param parent TODO - */ - void setResolveParent(AttributeSet parent); - - -} // MutableAttributeSet +public interface MutableAttributeSet extends AttributeSet +{ + /** + * addAttribute + * @param name TODO + * @param value TODO + */ + void addAttribute(Object name, Object value); + + /** + * addAttributes + * @param attributes TODO + */ + void addAttributes(AttributeSet attributes); + + /** + * removeAttribute + * @param name TODO + */ + void removeAttribute(Object name); + + /** + * removeAttributes + * @param names TODO + */ + void removeAttributes(Enumeration names); + + /** + * removeAttributes + * @param attributes TODO + */ + void removeAttributes(AttributeSet attributes); + + /** + * setResolveParent + * @param parent TODO + */ + void setResolveParent(AttributeSet parent); +} diff --git a/libjava/javax/swing/text/PlainDocument.java b/libjava/javax/swing/text/PlainDocument.java index 45fe5ef01be..930e5d3cb56 100644 --- a/libjava/javax/swing/text/PlainDocument.java +++ b/libjava/javax/swing/text/PlainDocument.java @@ -1,5 +1,5 @@ -/* PlainDocument.java -- - Copyright (C) 2002 Free Software Foundation, Inc. +/* PlainDocument.java -- + Copyright (C) 2002, 2004 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -37,22 +37,33 @@ exception statement from your version. */ package javax.swing.text; - public class PlainDocument extends AbstractDocument { - PlainDocument() - { - super(new GapContent()); - } - - public Element getDefaultRootElement() - { - return null; - } - - public Element getParagraphElement(int pos) - { - return null; - } -} + private static final long serialVersionUID = 4758290289196893664L; + + public static final String lineLimitAttribute = "lineLimit"; + public static final String tabSizeAttribute = "tabSize"; + + private int tabSize; + + public PlainDocument() + { + this(new GapContent()); + } + public PlainDocument(AbstractDocument.Content content) + { + super(content); + tabSize = 8; + } + + public Element getDefaultRootElement() + { + return null; + } + + public Element getParagraphElement(int pos) + { + return null; + } +} diff --git a/libjava/javax/swing/text/Style.java b/libjava/javax/swing/text/Style.java index f6c8723b03a..d8553c02c92 100644 --- a/libjava/javax/swing/text/Style.java +++ b/libjava/javax/swing/text/Style.java @@ -39,9 +39,26 @@ package javax.swing.text; import javax.swing.event.ChangeListener; -public interface Style +public interface Style extends MutableAttributeSet { - void addChangeListener(ChangeListener l); - String getName(); - void removeChangeListener(ChangeListener l); + /** + * Returns the name of the style. + * + * @return the name + */ + String getName(); + + /** + * Adds a <code>ChangeListener</code> object to the style. + * + * @param listener the listener object to add + */ + void addChangeListener(ChangeListener listener); + + /** + * Removes a <code>ChangeListener</code> from to the style. + * + * @param listener the listener object to remove, + */ + void removeChangeListener(ChangeListener listener); } diff --git a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkClasspathFontPeer.c b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkClasspathFontPeer.c index a56e7d27d5b..34d557131ec 100644 --- a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkClasspathFontPeer.c +++ b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkClasspathFontPeer.c @@ -136,7 +136,7 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkClasspathFontPeer_setFont pango_font_description_set_family (pfont->desc, family_name); (*env)->ReleaseStringUTFChars(env, family_name_str, family_name); - pango_font_description_set_size (pfont->desc, size * PANGO_SCALE); + pango_font_description_set_size (pfont->desc, size * dpi_conversion_factor); if (style & java_awt_font_BOLD) pango_font_description_set_weight (pfont->desc, PANGO_WEIGHT_BOLD); diff --git a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkFontMetrics.c b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkFontMetrics.c index 6036db7c776..bb406c50c49 100644 --- a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkFontMetrics.c +++ b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkFontMetrics.c @@ -47,7 +47,8 @@ exception statement from your version. */ #define NUM_METRICS 5 JNIEXPORT jintArray JNICALL Java_gnu_java_awt_peer_gtk_GdkFontMetrics_initState - (JNIEnv *env, jobject obj __attribute__((unused)), jstring fname, jint size) + (JNIEnv *env, jobject obj __attribute__((unused)), + jstring fname, jint style, jint size) { jintArray array; jint *metrics; @@ -64,21 +65,28 @@ JNIEXPORT jintArray JNICALL Java_gnu_java_awt_peer_gtk_GdkFontMetrics_initState gdk_threads_enter (); font_desc = pango_font_description_from_string (font_name); - pango_font_description_set_size (font_desc, size * PANGO_SCALE); + pango_font_description_set_size (font_desc, size * dpi_conversion_factor); + + if (style & AWT_STYLE_BOLD) + pango_font_description_set_weight (font_desc, PANGO_WEIGHT_BOLD); + + if (style & AWT_STYLE_ITALIC) + pango_font_description_set_style (font_desc, PANGO_STYLE_OBLIQUE); context = gdk_pango_context_get(); pango_context_set_font_description (context, font_desc); - pango_metrics = pango_context_get_metrics (context, font_desc, NULL); + pango_metrics = pango_context_get_metrics (context, font_desc, + gtk_get_default_language ()); metrics[ASCENT] = - pango_font_metrics_get_ascent (pango_metrics) / PANGO_SCALE; + PANGO_PIXELS (pango_font_metrics_get_ascent (pango_metrics)); metrics[MAX_ASCENT] = metrics[ASCENT]; metrics[DESCENT] = - pango_font_metrics_get_descent (pango_metrics) / PANGO_SCALE; + PANGO_PIXELS (pango_font_metrics_get_descent (pango_metrics)); metrics[MAX_DESCENT] = metrics[DESCENT]; metrics[MAX_ADVANCE] = - pango_font_metrics_get_approximate_char_width (pango_metrics) / PANGO_SCALE; + PANGO_PIXELS (pango_font_metrics_get_approximate_char_width (pango_metrics)); pango_font_metrics_unref (pango_metrics); @@ -94,7 +102,7 @@ JNIEXPORT jintArray JNICALL Java_gnu_java_awt_peer_gtk_GdkFontMetrics_initState JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_gtk_GdkFontMetrics_stringWidth (JNIEnv *env, jobject obj __attribute__((unused)), - jstring fname, jint size, jstring str) + jstring fname, jint style, jint size, jstring str) { PangoFontDescription *font_desc; PangoContext *context; @@ -109,7 +117,13 @@ JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_gtk_GdkFontMetrics_stringWidth gdk_threads_enter (); font_desc = pango_font_description_from_string (font_name); - pango_font_description_set_size (font_desc, size * PANGO_SCALE); + pango_font_description_set_size (font_desc, size * dpi_conversion_factor); + + if (style & AWT_STYLE_BOLD) + pango_font_description_set_weight (font_desc, PANGO_WEIGHT_BOLD); + + if (style & AWT_STYLE_ITALIC) + pango_font_description_set_style (font_desc, PANGO_STYLE_OBLIQUE); context = gdk_pango_context_get(); pango_context_set_font_description (context, font_desc); @@ -117,6 +131,7 @@ JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_gtk_GdkFontMetrics_stringWidth layout = pango_layout_new (context); pango_layout_set_text (layout, cstr, -1); + pango_layout_get_pixel_size (layout, &width, NULL); pango_font_description_free (font_desc); diff --git a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics.c b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics.c index 9c370e936cc..864e465871b 100644 --- a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics.c +++ b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics.c @@ -207,7 +207,8 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics_drawString gdk_threads_enter (); font_desc = pango_font_description_from_string (font_name); - pango_font_description_set_size (font_desc, size * PANGO_SCALE); + + pango_font_description_set_size (font_desc, size * dpi_conversion_factor); if (style & AWT_STYLE_BOLD) pango_font_description_set_weight (font_desc, PANGO_WEIGHT_BOLD); @@ -225,12 +226,15 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics_drawString baseline_y = pango_layout_iter_get_baseline (iter); - gdk_draw_layout (g->drawable, g->gc, - x + g->x_offset, y + g->y_offset - (baseline_y / PANGO_SCALE), layout); + gdk_draw_layout (g->drawable, g->gc, + x + g->x_offset, + y + g->y_offset - PANGO_PIXELS (baseline_y), + layout); pango_font_description_free (font_desc); pango_layout_iter_free (iter); + gdk_flush (); gdk_threads_leave (); (*env)->ReleaseStringUTFChars (env, fname, font_name); @@ -248,6 +252,7 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics_drawLine gdk_draw_line (g->drawable, g->gc, x + g->x_offset, y + g->y_offset, x2 + g->x_offset, y2 + g->y_offset); + gdk_flush (); gdk_threads_leave (); } @@ -259,8 +264,10 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics_fillRect g = (struct graphics *) NSA_GET_PTR (env, obj); gdk_threads_enter (); + gdk_draw_rectangle (g->drawable, g->gc, TRUE, x + g->x_offset, y + g->y_offset, width, height); + gdk_flush (); gdk_threads_leave (); } @@ -274,6 +281,7 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics_drawRect gdk_threads_enter (); gdk_draw_rectangle (g->drawable, g->gc, FALSE, x + g->x_offset, y + g->y_offset, width, height); + gdk_flush (); gdk_threads_leave (); } @@ -292,6 +300,7 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics_copyArea (GdkWindow *)g->drawable, x + g->x_offset, y + g->y_offset, width, height); + gdk_flush (); gdk_threads_leave (); } @@ -311,6 +320,7 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics_copyPixmap (GdkWindow *)g2->drawable, 0 + g2->x_offset, 0 + g2->y_offset, width, height); + gdk_flush (); gdk_threads_leave (); } @@ -340,6 +350,7 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics_clearRect x + g->x_offset, y + g->y_offset, width, height); gdk_gc_set_foreground (g->gc, &(saved.foreground)); } + gdk_flush (); gdk_threads_leave (); } @@ -370,6 +381,7 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics_setFGColor gdk_threads_enter (); gdk_color_alloc (g->cm, &color); gdk_gc_set_foreground (g->gc, &color); + gdk_threads_leave (); } @@ -385,6 +397,7 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics_drawArc gdk_draw_arc (g->drawable, g->gc, FALSE, x + g->x_offset, y + g->y_offset, width, height, angle1 << 6, angle2 << 6); + gdk_flush (); gdk_threads_leave (); } @@ -428,6 +441,7 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics_drawPolyline gdk_threads_enter (); gdk_draw_lines (g->drawable, g->gc, points, npoints); + gdk_flush (); gdk_threads_leave (); g_free (points); @@ -451,6 +465,7 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics_drawPolygon gdk_threads_enter (); gdk_draw_lines (g->drawable, g->gc, points, npoints); + gdk_flush (); gdk_threads_leave (); g_free (points); @@ -468,6 +483,7 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics_fillPolygon g->x_offset, g->y_offset); gdk_threads_enter (); gdk_draw_polygon (g->drawable, g->gc, TRUE, points, npoints); + gdk_flush (); gdk_threads_leave (); g_free (points); @@ -485,6 +501,7 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics_fillArc gdk_draw_arc (g->drawable, g->gc, TRUE, x + g->x_offset, y + g->y_offset, width, height, angle1 << 6, angle2 << 6); + gdk_flush (); gdk_threads_leave (); } @@ -499,6 +516,7 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics_drawOval gdk_draw_arc (g->drawable, g->gc, FALSE, x + g->x_offset, y + g->y_offset, width, height, 0, 23040); + gdk_flush (); gdk_threads_leave (); } @@ -513,8 +531,9 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics_fillOval gdk_draw_arc (g->drawable, g->gc, TRUE, x + g->x_offset, y + g->y_offset, width, height, 0, 23040); + gdk_flush (); gdk_threads_leave (); -} +} JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics_setClipRectangle (JNIEnv *env, jobject obj, jint x, jint y, jint width, jint height) diff --git a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkPixbufDecoder.c b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkPixbufDecoder.c index 222c7cedef3..97e49625cb7 100644 --- a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkPixbufDecoder.c +++ b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkPixbufDecoder.c @@ -72,7 +72,7 @@ area_prepared (GdkPixbufLoader *loader, return; width = gdk_pixbuf_get_width (pixbuf); - height = gdk_pixbuf_get_height (pixbuf), + height = gdk_pixbuf_get_height (pixbuf); gdk_threads_leave (); diff --git a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkButtonPeer.c b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkButtonPeer.c index 9877a45fe58..d9647e9ba10 100644 --- a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkButtonPeer.c +++ b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkButtonPeer.c @@ -130,7 +130,7 @@ Java_gnu_java_awt_peer_gtk_GtkButtonPeer_gtkSetFont return; font_desc = pango_font_description_from_string (font_name); - pango_font_description_set_size (font_desc, size * PANGO_SCALE); + pango_font_description_set_size (font_desc, size * dpi_conversion_factor); if (style & AWT_STYLE_BOLD) pango_font_description_set_weight (font_desc, PANGO_WEIGHT_BOLD); diff --git a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCheckboxPeer.c b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCheckboxPeer.c index b4654bb2e29..f5d7cfb89aa 100644 --- a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCheckboxPeer.c +++ b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCheckboxPeer.c @@ -153,7 +153,7 @@ Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_gtkSetFont gdk_threads_enter(); font_desc = pango_font_description_from_string (font_name); - pango_font_description_set_size (font_desc, size * PANGO_SCALE); + pango_font_description_set_size (font_desc, size * dpi_conversion_factor); if (style & AWT_STYLE_BOLD) pango_font_description_set_weight (font_desc, PANGO_WEIGHT_BOLD); diff --git a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c index 09711726cd6..6f070f68b74 100644 --- a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c +++ b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c @@ -565,8 +565,10 @@ Java_gnu_java_awt_peer_gtk_GtkComponentPeer_gtkWidgetDispatchKeyEvent return; } - if (n_keys > 1) - g_printerr ("warning: using hardware keycode from first keymap entry, though multiple entries were found\n"); + /* Note: if n_keys > 1 then there are multiple hardware keycodes + that translate to lookup_keyval. We arbitrarily choose the first + hardware keycode from the list returned by + gdk_keymap_get_entries_for_keyval. */ event->key.hardware_keycode = keymap_keys[0].keycode; event->key.group = keymap_keys[0].group; @@ -707,10 +709,14 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkComponentPeer_setNativeBoun gdk_threads_enter (); widget = GTK_WIDGET (ptr); + + /* We assume that -1 is a width or height and not a request for the + widget's natural size. */ + width = width < 0 ? 0 : width; + height = height < 0 ? 0 : height; + if (GTK_IS_VIEWPORT (widget->parent)) - { - gtk_widget_set_size_request (widget, width, height); - } + gtk_widget_set_size_request (widget, width, height); else { gtk_widget_set_size_request (widget, width, height); @@ -844,7 +850,7 @@ Java_gnu_java_awt_peer_gtk_GtkComponentPeer_gtkSetFont gdk_threads_enter(); font_desc = pango_font_description_from_string (font_name); - pango_font_description_set_size (font_desc, size * PANGO_SCALE); + pango_font_description_set_size (font_desc, size * dpi_conversion_factor); if (style & AWT_STYLE_BOLD) pango_font_description_set_weight (font_desc, PANGO_WEIGHT_BOLD); @@ -1111,12 +1117,23 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkComponentPeer_addExposeFilt filterobj = GTK_OBJECT(layout); } + else if (GTK_IS_SCROLLED_WINDOW(ptr)) + { + // The event will go to the parent GtkLayout. + filterobj = GTK_OBJECT(GTK_WIDGET(ptr)->parent); + } else { filterobj = GTK_OBJECT(ptr); } - g_signal_handlers_block_by_func (filterobj, *pre_event_handler, *gref); + gulong hid = g_signal_handler_find(filterobj, + G_SIGNAL_MATCH_FUNC, + 0, 0, NULL, *pre_event_handler, NULL); + if (hid > 0) + { + g_signal_handler_block(filterobj, hid); + } g_signal_connect( filterobj, "event", G_CALLBACK(filter_expose_event_handler), *gref); @@ -1155,6 +1172,11 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkComponentPeer_removeExposeF filterobj = GTK_OBJECT(layout); } + else if (GTK_IS_SCROLLED_WINDOW(ptr)) + { + // The event will go to the parent GtkLayout. + filterobj = GTK_OBJECT(GTK_WIDGET(ptr)->parent); + } else { filterobj = GTK_OBJECT(ptr); @@ -1162,7 +1184,13 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkComponentPeer_removeExposeF g_signal_handlers_disconnect_by_func (filterobj, *filter_expose_event_handler, *gref); - g_signal_handlers_unblock_by_func (filterobj, *pre_event_handler, *gref); + gulong hid = g_signal_handler_find(filterobj, + G_SIGNAL_MATCH_FUNC, + 0, 0, NULL, *pre_event_handler, NULL); + if (hid > 0) + { + g_signal_handler_unblock(filterobj, hid); + } gdk_threads_leave (); } @@ -1240,7 +1268,9 @@ find_fg_color_widget (GtkWidget *widget) { GtkWidget *fg_color_widget; - if (GTK_IS_EVENT_BOX (widget) || GTK_IS_BUTTON (widget)) + if (GTK_IS_EVENT_BOX (widget) + || (GTK_IS_BUTTON (widget) + && !GTK_IS_OPTION_MENU (widget))) fg_color_widget = gtk_bin_get_child (GTK_BIN(widget)); else fg_color_widget = widget; diff --git a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkEvents.c b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkEvents.c index b3858fb3970..8fb619e2563 100644 --- a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkEvents.c +++ b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkEvents.c @@ -989,11 +989,9 @@ pre_event_handler (GtkWidget *widget, GdkEvent *event, jobject peer) break; case GDK_CONFIGURE: { - /* GtkWidget *widget; - - gdk_window_get_user_data (event->any.window, (void **) &widget); */ - - if (widget && GTK_WIDGET_TOPLEVEL (widget)) + /* Only send configure events to visible top-level windows. */ + if (widget && GTK_WIDGET_TOPLEVEL (widget) + && GTK_WIDGET_VISIBLE (widget)) { /* Configure events are not posted to the AWT event queue, and as such, the gdk/gtk peer functions will diff --git a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkLabelPeer.c b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkLabelPeer.c index c5848baa130..93d30cb6976 100644 --- a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkLabelPeer.c +++ b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkLabelPeer.c @@ -54,7 +54,7 @@ Java_gnu_java_awt_peer_gtk_GtkLabelPeer_create str = (*env)->GetStringUTFChars (env, text, 0); gdk_threads_enter (); - + ebox = gtk_event_box_new (); ebox_container = GTK_CONTAINER (ebox); label = gtk_label_new (str); @@ -80,17 +80,17 @@ Java_gnu_java_awt_peer_gtk_GtkLabelPeer_gtkSetFont ptr = NSA_GET_PTR (env, obj); - label = gtk_bin_get_child (GTK_BIN(ptr)); + font_name = (*env)->GetStringUTFChars (env, name, NULL); - if (!label) - return; + gdk_threads_enter (); - font_name = (*env)->GetStringUTFChars (env, name, NULL); + label = gtk_bin_get_child (GTK_BIN (ptr)); - gdk_threads_enter(); + if (!label) + return; font_desc = pango_font_description_from_string (font_name); - pango_font_description_set_size (font_desc, size * PANGO_SCALE); + pango_font_description_set_size (font_desc, size * dpi_conversion_factor); if (style & AWT_STYLE_BOLD) pango_font_description_set_weight (font_desc, PANGO_WEIGHT_BOLD); @@ -98,11 +98,11 @@ Java_gnu_java_awt_peer_gtk_GtkLabelPeer_gtkSetFont if (style & AWT_STYLE_ITALIC) pango_font_description_set_style (font_desc, PANGO_STYLE_OBLIQUE); - gtk_widget_modify_font (GTK_WIDGET(label), font_desc); + gtk_widget_modify_font (GTK_WIDGET (label), font_desc); pango_font_description_free (font_desc); - gdk_threads_leave(); + gdk_threads_leave (); (*env)->ReleaseStringUTFChars (env, name, font_name); } diff --git a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkListPeer.c b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkListPeer.c index 9f8301bf7d5..7cefd8dad07 100644 --- a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkListPeer.c +++ b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkListPeer.c @@ -44,6 +44,13 @@ enum N_COLUMNS }; +gboolean item_highlighted (GtkTreeSelection *selection, + GtkTreeModel *model, + GtkTreePath *path, + gboolean path_currently_selected, + jobject peer); + + #define TREE_VIEW_FROM_SW(obj) \ (GTK_TREE_VIEW (GTK_SCROLLED_WINDOW (obj)->container.child)) @@ -130,21 +137,28 @@ Java_gnu_java_awt_peer_gtk_GtkListPeer_connectSignals (JNIEnv *env, jobject obj) { void *ptr; - GtkTreeView *list; jobject *gref; - - gref = NSA_GET_GLOBAL_REF (env, obj); - g_assert (gref); + GtkTreeView *list; + GtkTreeSelection *selection; ptr = NSA_GET_PTR (env, obj); + gref = NSA_GET_GLOBAL_REF (env, obj); gdk_threads_enter (); + g_assert (gref); + gtk_widget_realize (GTK_WIDGET (ptr)); + list = TREE_VIEW_FROM_SW (ptr); + g_signal_connect (G_OBJECT (list), "event", G_CALLBACK (pre_event_handler), *gref); + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (list)); + gtk_tree_selection_set_select_function (selection, item_highlighted, + *gref, NULL); + gdk_threads_leave (); } @@ -166,7 +180,7 @@ Java_gnu_java_awt_peer_gtk_GtkListPeer_gtkSetFont font_name = (*env)->GetStringUTFChars (env, name, NULL); font_desc = pango_font_description_from_string (font_name); - pango_font_description_set_size (font_desc, size * PANGO_SCALE); + pango_font_description_set_size (font_desc, size * dpi_conversion_factor); if (style & AWT_STYLE_BOLD) pango_font_description_set_weight (font_desc, PANGO_WEIGHT_BOLD); @@ -484,3 +498,34 @@ Java_gnu_java_awt_peer_gtk_GtkListPeer_setMultipleMode gdk_threads_leave (); } + +gboolean +item_highlighted (GtkTreeSelection *selection __attribute__((unused)), + GtkTreeModel *model, + GtkTreePath *path, + gboolean path_currently_selected, + jobject peer) +{ + GtkTreeIter iter; + jint row; + gint *indices; + + if (gtk_tree_model_get_iter (model, &iter, path)) + { + indices = gtk_tree_path_get_indices (path); + row = indices ? indices[0] : -1; + + if (!path_currently_selected) + (*gdk_env)->CallVoidMethod (gdk_env, peer, + postListItemEventID, + row, + (jint) AWT_ITEM_SELECTED); + else + (*gdk_env)->CallVoidMethod (gdk_env, peer, + postListItemEventID, + row, + (jint) AWT_ITEM_DESELECTED); + } + + return TRUE; +} diff --git a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMainThread.c b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMainThread.c index 0b4c6fee452..817bee75200 100644 --- a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMainThread.c +++ b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMainThread.c @@ -69,6 +69,12 @@ JavaVM *gdk_vm; GtkWindowGroup *global_gtk_window_group; +double dpi_conversion_factor; + +static void init_dpi_conversion_factor (); +static void dpi_changed_cb (GtkSettings *settings, + GParamSpec *pspec); + /* * Call gtk_init. It is very important that this happen before any other * gtk calls. @@ -166,7 +172,7 @@ Java_gnu_java_awt_peer_gtk_GtkMainThread_gtkInit (JNIEnv *env, jclass clazz) "postMenuActionEvent", "()V"); postMouseEventID = (*env)->GetMethodID (env, gtkcomponentpeer, - "postMouseEvent", "(IJIIIIZ)V"); + "postMouseEvent", "(IJIIIIZ)V"); postConfigureEventID = (*env)->GetMethodID (env, gtkwindowpeer, "postConfigureEvent", "(IIII)V"); postWindowEventID = (*env)->GetMethodID (env, gtkwindowpeer, @@ -194,6 +200,8 @@ Java_gnu_java_awt_peer_gtk_GtkMainThread_gtkInit (JNIEnv *env, jclass clazz) "postTextEvent", "()V"); global_gtk_window_group = gtk_window_group_new (); + + init_dpi_conversion_factor (); } /* @@ -207,3 +215,36 @@ Java_gnu_java_awt_peer_gtk_GtkMainThread_gtkMain gtk_main (); gdk_threads_leave (); } + +/* This is a big hack, needed until this pango bug is resolved: + http://bugzilla.gnome.org/show_bug.cgi?id=119081. + See: http://www.geocrawler.com/archives/3/522/2003/8/0/10579352/ + for details. */ +static void +init_dpi_conversion_factor () +{ + GtkSettings *settings = gtk_settings_get_default (); + GObjectClass *klass; + + klass = G_OBJECT_CLASS (GTK_SETTINGS_GET_CLASS (settings)); + if (g_object_class_find_property (klass, "gtk-xft-dpi")) + { + int int_dpi; + g_object_get (settings, "gtk-xft-dpi", &int_dpi, NULL); + dpi_conversion_factor = PANGO_SCALE * 72.0 / (int_dpi / PANGO_SCALE); + g_signal_connect (settings, "notify::gtk-xft-dpi", + G_CALLBACK (dpi_changed_cb), NULL); + } + else + /* Approximate. */ + dpi_conversion_factor = PANGO_SCALE * 72.0 / 96.; +} + +static void +dpi_changed_cb (GtkSettings *settings, + GParamSpec *pspec) +{ + int int_dpi; + g_object_get (settings, "gtk-xft-dpi", &int_dpi, NULL); + dpi_conversion_factor = PANGO_SCALE * 72.0 / (int_dpi / PANGO_SCALE); +} diff --git a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextAreaPeer.c b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextAreaPeer.c index f9baa296459..c9427d49dff 100644 --- a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextAreaPeer.c +++ b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextAreaPeer.c @@ -54,6 +54,8 @@ Java_gnu_java_awt_peer_gtk_GtkTextAreaPeer_create text = gtk_text_view_new (); gtk_widget_set_size_request (text, textview_width, textview_height); + gtk_text_view_set_cursor_visible(text, TRUE); + gtk_widget_show (text); sw = gtk_scrolled_window_new (NULL, NULL); @@ -156,7 +158,7 @@ Java_gnu_java_awt_peer_gtk_GtkTextAreaPeer_gtkSetFont gdk_threads_enter(); font_desc = pango_font_description_from_string (font_name); - pango_font_description_set_size (font_desc, size * PANGO_SCALE); + pango_font_description_set_size (font_desc, size * dpi_conversion_factor); if (style & AWT_STYLE_BOLD) pango_font_description_set_weight (font_desc, PANGO_WEIGHT_BOLD); diff --git a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextFieldPeer.c b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextFieldPeer.c index e2429bcd1d0..5bea49a3f3c 100644 --- a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextFieldPeer.c +++ b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextFieldPeer.c @@ -150,7 +150,7 @@ Java_gnu_java_awt_peer_gtk_GtkTextFieldPeer_gtkSetFont gdk_threads_enter(); font_desc = pango_font_description_from_string (font_name); - pango_font_description_set_size (font_desc, size * PANGO_SCALE); + pango_font_description_set_size (font_desc, size * dpi_conversion_factor); if (style & AWT_STYLE_BOLD) pango_font_description_set_weight (font_desc, PANGO_WEIGHT_BOLD); diff --git a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c index c696a3fa6a2..29ff203d4e9 100644 --- a/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c +++ b/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c @@ -44,11 +44,9 @@ exception statement from your version. */ #include <gdk/gdkx.h> #include <X11/Xatom.h> -static int filter_added = 0; - -static GdkFilterReturn window_wm_protocols_filter (GdkXEvent *xev, - GdkEvent *event, - gpointer data); +/* FIXME: we're currently seeing the double-activation that occurs + with metacity and GTK. See + http://bugzilla.gnome.org/show_bug.cgi?id=140977 for details. */ static void window_get_frame_extents (GtkWidget *window, int *top, int *left, @@ -150,20 +148,6 @@ Java_gnu_java_awt_peer_gtk_GtkWindowPeer_create insets[2] = bottom; insets[3] = right; - /* We must filter out WM_TAKE_FOCUS messages. Otherwise we get two - focus in events when a window becomes active and two focus out - events when a window becomes inactive. */ - if (!filter_added) - { - GdkAtom wm_protocols_atom = - gdk_x11_xatom_to_atom (gdk_x11_get_xatom_by_name ("WM_PROTOCOLS")); - - gdk_add_client_message_filter (wm_protocols_atom, - window_wm_protocols_filter, - NULL); - filter_added = 1; - } - gdk_threads_leave (); (*env)->ReleaseIntArrayElements (env, jinsets, insets, 0); @@ -824,16 +808,3 @@ window_property_changed_cb (GtkWidget *widget __attribute__((unused)), return FALSE; } - -static GdkFilterReturn -window_wm_protocols_filter (GdkXEvent *xev, - GdkEvent *event __attribute__((unused)), - gpointer data __attribute__((unused))) -{ - XEvent *xevent = (XEvent *)xev; - - if ((Atom) xevent->xclient.data.l[0] == gdk_x11_get_xatom_by_name ("WM_TAKE_FOCUS")) - return GDK_FILTER_REMOVE; - - return GDK_FILTER_CONTINUE; -} diff --git a/libjava/jni/gtk-peer/gtkpeer.h b/libjava/jni/gtk-peer/gtkpeer.h index a913986c1db..18c95102472 100644 --- a/libjava/jni/gtk-peer/gtkpeer.h +++ b/libjava/jni/gtk-peer/gtkpeer.h @@ -435,6 +435,8 @@ extern jclass gdkColor; extern jmethodID gdkColorID; extern JNIEnv *gdk_env; +extern double dpi_conversion_factor; + extern GtkWindowGroup *global_gtk_window_group; void awt_event_handler (GdkEvent *event); |