+2004-07-21 Michael Koch <konqueror@gmx.de>
+
+ * javax/swing/JTextArea.java
+ (setLineWrap): Fire property change event after new value is set.
+ (setTabSize): Likewise.
+
+2004-07-21 Michael Koch <konqueror@gmx.de>
+
+ * javax/swing/JTable.java
+ (autoCreateColumnsFromModel): New field.
+ (autoResizeMode): Likewise.
+ (cellEditor): Likewise.
+ (cellSelectionEnabled): Likewise.
+ (columnModel): Likewise.
+ (dataModel): Likewise.
+ (defaultEditorsByColumnClass): Likewise.
+ (defaultRenderersByColumnClass): Likewise.
+ (editingColumn): Likewise.
+ (editingRow): Likewise.
+ (gridColor): Likewise.
+ (preferredViewportSize): Likewise.
+ (rowHeight): Likewise.
+ (rowMargin): Likewise.
+ (rowSelectionAllowed): Likewise.
+ (selectionBackground): Likewise.
+ (selectionForeground): Likewise.
+ (selectionModel): Likewise.
+ (showHorizontalLines): Likewise.
+ (showVerticalLines): Likewise.
+ (tableHeader): Likewise.
+ (JTable): Implemented.
+ (getColumnModel): Likewise.
+ (getSelectedRow): Likewise.
+ (getSelectionModel): Likewise.
+ (setModel): Likewise.
+ (setSelectionModel): Likewise.
+ (createScrollPaneForTable): New method.
+ (createDefaultDataModel): Likewise.
+ (createDefaultListSelectionModel): Likewise.
+ (getModel): Likewise.
+ (getTableHeader): Likewise.
+ (setTableHeader): Likewise.
+ (getColumnSelectionAllowed): Likewise.
+ (setColumnSelectionAllowed): Likewise.
+ (getRowSelectionAllowed): Likewise.
+ (setRowSelectionAllowed): Likewise.
+ (getAutoResizeMode): Likewise.
+ (setAutoResizeMode): Likewise.
+ (getColumnCount): Likewise.
+ (getRowCount): Likewise.
+ (getCellRenderer): Likewise.
+ * javax/swing/JTree.java
+ (cellRenderer): New field.
+ (editable): Likewise.
+ (rootVisible): Likewise.
+ (showsRootHandles): Likewise.
+ (getModel): New method.
+ (setModel): Likewise.
+ (isEditable): Likewise.
+ (setEditable): Likewise.
+ (isRootVisbile): Likewise.
+ (setRootVisible): Likewise.
+ (getShowsRootHandles): Likewise.
+ (setShowRootHandles): Likewise.
+ (getCellRenderer): Likewise.
+ (setCellRenderer): Likewise.
+
+2004-07-21 Michael Koch <konqueror@gmx.de>
+
+ * javax/swing/JFormattedTextField.java
+ (setDocument): Implemented.
+ * javax/swing/JRootPane.java:
+ Fixed javadocs.
+ * javax/swing/JTable.java
+ (getDefaultRenderer): New method.
+ * javax/swing/JTextField.java
+ (setFont): Likewise.
+ (getPreferredSize): Likewise.
+ * javax/swing/JToggleButton.java
+ (getAccessibleContext): Fix javadoc.
+ * javax/swing/JTree.java:
+ Add some javadocs.
+ * javax/swing/JViewport.java:
+ Likewise.
+
+2004-07-21 David Jee <djee@redhat.com>
+
+ * gnu/java/awt/peer/gtk/GtkFileDialogPeer.java:
+ Collect all native method declaration at the top.
+ (create): Set the filename filter if necessary.
+ (setDirectory): Call nativeSetDirectory().
+ (setFilenameFilter): Implement.
+ (filenameFilterCallback): New method.
+ * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkFileDialogPeer.c
+ (create): Configure dialog to show hidden files.
+ (filenameFilterCallback): New function.
+ (nativeSetFilenameFilter): New function.
+ (nativeSetDirectory): New function.
+
+2004-07-21 Kim Ho <kho@redhat.com>
+
+ * javax/swing/plaf/basic/BasicSliderUI.java:
+ Ran Jalopy.
+ (paintTrack): Fill the track before painting
+ the borders.
+
+2004-07-21 Graydon Hoare <graydon@redhat.com>
+
+ patch from Roman Kennke <roman@ontographics.com>
+ * javax/swing/Spring.java: New file.
+ * javax/swing/SpringLayout.java: New file.
+ * Makefile.am: Add new files.
+ * Makefile.in: Regenerate.
+
+2004-07-21 Graydon Hoare <graydon@redhat.com>
+
+ * javax/swing/plaf/basic/BasicSplitPaneUI.java: Minor layout fixes.
+ * javax/swing/plaf/basic/BasicTabbedPaneUI.java: Likewise.
+ * javax/swing/ScrollPaneLayout.java: Likewise.
+
+2004-07-21 Kim Ho <kho@redhat.com>
+
+ * javax/swing/DefaultDesktopManager.java:
+ (findMinimum): Removed.
+ (resizeFrame): Trust the UI to pass valid
+ bounds.
+ * javax/swing/JOptionPane.java:
+ Implemented showInternalXXXDialog methods.
+ (startModal): New method.
+ * javax/swing/plaf/basic/BasicInternalFrameUI.java:
+ (BorderListener::mouseDragged): Verify that the new
+ bounds are valid before passing them to the DesktopManager.
+ (preferredLayoutSize): Delegate
+ to getSize.
+ (minimumLayoutSize): Ditto.
+ (getSize): New method.
+ (GlassPaneDispatcher): Reimplemented by copying
+ a stripped down LightweightDispatcher from Container.
+ (getMinimumSize): Call minimumLayoutSize.
+ * javax/swing/plaf/basic/BasicOptionPaneUI.java:
+ Ran Jalopy.
+ (mousePressed): Add ability to properly close
+ JInternalFrames.
+ * javax/swing/plaf/basic/BasicToolBarUI.java:
+ (DragWindow): Set owner for DragWindow.
+
+2004-07-21 Jerry Quinn <jlquinn@optonline.net>
+
+ * java/awt/image/ShortLookupTable.java: New file.
+ * java/awt/image/ByteLookupTable.java: New file.
+ * Makefile.am: Added new files.
+ * Makefile.in: Regenerated.
+
+2004-07-21 David Jee <djee@redhat.com>
+
+ * gnu/java/awt/peer/gtk/GtkFileDialogPeer.java
+ (create(GtkContainerPeer)): New native method.
+ (create()): Call native create(), passing in the parent frame
+ as the paramter. Natively set the current file and directory.
+ (setFile): Construct an absolute filename before passing it to
+ the native peer.
+ (nativeGetDirectory): New method.
+ * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkFileDialogPeer.c
+ (window_closed): Removed.
+ (ok_clicked): Likewise.
+ (cancel_clicked): Likewise.
+ (handle_response): New method.
+ (create): Use GtkFileChooserDialog.
+ (connectSignals): Connect to handle_response.
+ (nativeGetDirectory): New method.
+ (nativeSetFile): Use GtkFileChooserDialog.
+
+2004-07-21 Jerry Quinn <jlquinn@optonline.net>
+
+ * java/awt/image/LookupTable.java: New file.
+ * Makefile.am: Added new file.
+ * Makefile.in: Regenerated.
+
+2004-07-21 Jerry Quinn <jlquinn@optonline.net>
+
+ * java/awt/image/Kernel.java: New file.
+ * Makefile.am: Added new file.
+ * Makefile.in: Regenerated.
+
+2004-07-21 Olga Rodimina <rodimina@redhat.com>
+
+ * javax/swing/JCheckBoxMenuItem.java: Fixed Javadocs.
+ * javax/swing/JMenu.java: Likewise.
+ * javax/swing/JMenuBar.java: Likewise.
+ (MARGIN_CHANGED_PROPERTY): New property.
+ (setMargin): Implemented.
+ * javax/swing/JMenuItem.java: Fixed javadocs.
+ * javax/swing/JPopupMenuUI.java: Fixed javadocs.
+ (LABEL_CHANGED_PROPERTY): New property.
+ (add): changed to use createActionComponent.
+ (createActionComponent): Implemented.
+ (setLabel): Fire PropertyChangeEvent if label property
+ changes.
+ * javax/swing/JRadioButtonMenuItem.java: Fixed javadocs.
+ * javax/swing/plaf/basic/BasicMenuBarUI.java: Likewise.
+ (ContainerHandler): Repaint if margin property has changed.
+ * javax/swing/plaf/basic/BasicMenuItemUI.java:
+ (installUI): Call installComponents().
+ (uninstallUI): Call uinstallComponents().
+ * javax/swing/plaf/basic/BasicMenuUI.java:
+ Fixed javadocs.
+ * javax/swing/plaf/basic/BasicPopupMenuUI.java:
+ Likewise.
+
+2004-07-21 Kim Ho <kho@redhat.com>
+
+ * javax/swing/plaf/basic/BasicToolBarUI.java:
+ (DragWindow): Use the right constructor.
+
+2004-07-21 Kim Ho <kho@redhat.com>
+
+ * javax/swing/JToolBar.java:
+ (layoutContainer): Use getComponents.
+ * javax/swing/plaf/basic/BasicToolBarUI.java:
+ (DragWindow): Don't use SwingUtilities'
+ getOwnerFrame
+ (ToolBarDialog): ditto.
+
+2004-07-21 Kim Ho <kho@redhat.com>
+
+ * javax/swing/JRootPane.java:
+ Ran jalopy.
+ (layoutContainer): Set the glasspane's size to
+ be the same as the content pane.
+ (createGlassPane): Set opaque property to false.
+
+2004-07-21 Thomas Fitzsimmons <fitzsim@redhat.com>
+
+ * java/awt/Component.java (requestFocus()): Don't handle Panels
+ specially.
+ (requestFocus(boolean)): Likewise.
+ (requestFocusInWindow(boolean)): Likewise.
+ * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkPanelPeer.c (create):
+ Set GTK_CAN_FOCUS flag.
+
+2004-07-21 Kim Ho <kho@redhat.com>
+
+ * Makefile.am: Added new file.
+ * Makefile.in: Regenerated.
+ * gcj/Makefile.in: Regenerated.
+ * include/Makefile.in: Regenerated.
+ * javax/swing/AbstractButton.java:
+ Add rollOverEnabled property.
+ (setRolloverEnabled): Use new property.
+ (isRolloverEnabled): Use new property.
+ * javax/swing/JTabbedPane.java:
+ (setComponent): Remove useless JTabbedPane.this.
+ * javax/swing/JToolBar.java: Finish implementation.
+ * javax/swing/plaf/basic/BasicArrowButton.java:
+ (paint): Moved border painting to a border.
+ * javax/swing/plaf/basic/BasicLookAndFeel.java:
+ Change JToolBar look and feel defaults.
+ * javax/swing/plaf/basic/BasicOptionPaneUI.java
+ (actionPerformed): Return Integer index instead of name.
+ (addButtonComponents): Check to see if component is
+ JButton last.
+ (createMessageArea): Don't use components that are not
+ completed yet.
+ (getIconForType): Use temporary icons.
+ * javax/swing/plaf/basic/BasicSliderUI.java:
+ (mousePressed): Do not return if it's on thumb.
+ (paintMinorTickForHorizSlider): Use BLACK to paint ticks.
+ (paintMinorTickForVertSlider): ditto.
+ (paintMajorTickForHorizSlider): ditto.
+ (paintMajorTickForVertSlider): ditto.
+ * javax/swing/plaf/basic/BasicSplitPaneDivider.java:
+ Add a border around the SplitPaneDivider.
+ * javax/swing/plaf/basic/BasicSplitPaneUI.java:
+ Remove comments.
+ * javax/swing/plaf/basic/BasicToolBarSeparatorUI.java:
+ New file. Implemented.
+ * javax/swing/plaf/basic/BasicToolBarUI.java:
+ Implemented.
+ * testsuite/Makefile.in: Regenerated.
+
+2004-07-21 Graydon Hoare <graydon@redhat.com>
+
+ * javax/swing/Timer.java (run): Queue events each time cycle.
+
+2004-07-21 David Jee <djee@redhat.com>
+
+ * gnu/java/awt/peer/gtk/GtkImagePainter.java
+ (imageComplete): Call image.imageComplete().
+ * java/awt/image/MemoryImageSource.java:
+ Reimplement consumers as a Vector instead of a Hashtable. This is
+ because enumeration on a Hashtable is not thread-safe.
+ (addConsumer): Adapt to Vector consumers.
+ (isConsumer): Adapt to Vector consumers.
+ (removeConsumer): Adapt to Vector consumers.
+ (startProduction): Adapt to Vector consumers. Call imageComplete()
+ with STATICIMAGEDONE flag instead of SINGLEFRAME flag.
+ (newPixels): Adapt to Vector consumers.
+ (sendPicture): Set the color model of the image consumer.
+ (newPixels(IIII)): Adapt to Vector consumers.
+ (newPixels(IIIIB)): Adapt to Vector consumers.
+
+2004-07-21 Thomas Fitzsimmons <fitzsim@redhat.com>
+
+ * java/awt/Component.java (deliverEvent): Implement.
+ (postEvent): Implement.
+ (handleEvent): Implement.
+ (translateEvent): New method.
+ (dispatchEventImpl): Document. Add AWT 1.0 event handling.
+ * java/awt/Container.java (deliverEvent): Implement.
+ * java/awt/Event.java (paramString): Fix formatting.
+ * java/awt/Font.java (toString): Likewise.
+ * java/awt/Window.java (postEvent): Implement.
+
+2004-07-21 Thomas Fitzsimmons <fitzsim@redhat.com>
+
+ * java/awt/DefaultKeyboardFocusManager.java (dispatchEvent):
+ Set window's focus owner upon receiving a FOCUS_LOST event.
+ * java/awt/Window.java (Window()): Refocus the previously
+ focused component within the window when the window regains the
+ top-level focus.
+ (setFocusOwner): New method.
+ * java/awt/Component.java (requestFocus): Add FIXME.
+
+ * libgcj.pc.in: Remove library flags.
+
+2004-07-21 Thomas Fitzsimmons <fitzsim@redhat.com>
+
+ * gnu/java/awt/peer/gtk/GtkPanelPeer.java (handleEvent): Handle
+ MOUSE_PRESSED event.
+ * java/awt/Component.java (requestFocus()): Handle Panel
+ specially. Post FOCUS_LOST event on opposite component.
+ (requestFocus(boolean)): Likewise.
+ (requestFocusInWindow(boolean)): Likewise.
+ (paramString): Reorder dimension fields.
+ * java/awt/Container.java (paramString): Fix string format.
+ * java/awt/DefaultKeyboardFocusManager.java (dispatchEvent):
+ Handle FOCUS_LOST events. Don't handle Windows specially. Only
+ process key events if the focus owner is non-null.
+ (dispatchKeyEvent): Likewise.
+ * java/awt/Frame.java (paramString): Fix formatting.
+ (generateName): New method.
+ (getUniqueLong): Likewise.
+ * java/awt/KeyboardFocusManager.java (getFocusOwner): Check if
+ the temporary focus owner is null. If so, return the permanent
+ focus owner.
+ * java/awt/Panel.java (generateName): New method.
+ (getUniqueLong): Likewise.
+ * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c: Rework
+ signal handling to make callbacks more specific.
+
+2004-07-21 Michael Koch <konqueror@gmx.de>
+
+ * javax/swing/text/Position.java
+ (Bias): Implemented.
+
+2004-07-21 Michael Koch <konqueror@gmx.de>
+
+ * javax/swing/LookAndFeel.java
+ (provideErrorFeedback): New method.
+
+2004-07-21 Michael Koch <konqueror@gmx.de>
+
+ * javax/swing/JTextArea.java
+ (tabSize): New field.
+ (getTabSize): New method.
+ (setTabSize): Likewise.
+
+2004-07-21 Michael Koch <konqueror@gmx.de>
+
+ * javax/swing/ActionMap.java:
+ Fixed javadocs all over.
+ (serialVersionUID): Made private.
+ (parent): Don't explicitely initialize with default value.
+ (get): SImplified.
+ (keys): Reimplemented.
+ (allKeys): Likewise.
+ (convertSet): Removed.
+ * javax/swing/ComponentInputMap.java:
+ Fixed javadocs all over.
+ (ComponentInputMap): Implemented.
+ (put): Likewise.
+ (clear): Likewise.
+ (remove): Likewise.
+ (SetParent): Likewise.
+ (getComponent): Likewise.
+ * javax/swing/InputMap.java:
+ Fixed javadocs all over.
+ (serialVersionUID): Made private.
+ (parent): Don't explicitely initialize with default value.
+ (get): SImplified.
+ (keys): Reimplemented.
+ (allKeys): Likewise.
+ (convertSet): Removed.
+
+2004-07-21 Michael Koch <konqueror@gmx.de>
+
+ * javax/swing/ActionMap.java,
+ javax/swing/ComponentInputMap.java,
+ javax/swing/InputMap.java,
+ javax/swing/table/DefaultTableColumnModel.java,
+ javax/swing/table/TableColumn.java,
+ javax/swing/table/TableColumnModel.java,
+ javax/swing/table/TableModel.java,
+ javax/swing/text/AbstractDocument.java,
+ javax/swing/text/TextAction.java:
+ Reformated.
+
+2004-07-21 Graydon Hoare <graydon@redhat.com>
+
+ * gnu/java/awt/peer/gtk/GtkToolkit.java (bufferedImageOrError):
+ Make method non-static.
+ * javax/swing/AbstractButton.java:
+ Rename fields to match property names where possible.
+ (iconTextGap): New property.
+ * javax/swing/JCheckBox.java: Match AbstractButton changes.
+ (init) New method, call from after various constructors.
+ * javax/swing/JComponent.java (revalidate):
+ Invalidate before queueing repair.
+ * javax/swing/JList.java (getPreferredScrollableViewportSize):
+ Reimplement in terms of visibleRowCount property.
+ * javax/swing/JMenuButton.java: Match AbstractButton changes.
+ * javax/swing/JScrollPane.java (createScrollListener):
+ Remove tracing chatter.
+ * javax/swing/JToggleButton.java: Match AbstractButton changes.
+ * javax/swing/RepaintManager.java (addInvalidComponent):
+ Don't invalidate.
+ * javax/swing/ScrollPaneLayout.java: Various corrections to layout
+ calculations.
+ * javax/swing/SwingUtilities.java (layoutCompoundLabel):
+ Mimic sun behavior on top left/right positioning.
+ * javax/swing/ViewportLayout.java (preferredLayoutSize):
+ Remove mistaken use of preferredScrollableViewportSize here.
+ (layoutContainer): Use view's preferred size as basis.
+ * javax/swing/plaf/basic/BasicButtonUI.java:
+ Set, get, and use textIconGap property.
+ (paint) Paint text returned from layout (with ellipsis).
+ * javax/swing/plaf/basic/BasicListUI.java:
+ Remove tracing chatter, correct various minor calculations.
+ (getCellBounds): Update layout state before calculating.
+ * javax/swing/plaf/basic/BasicLookAndFeel.java (Button.Margin):
+ Use margin default similar to sun's.
+ * javax/swing/plaf/basic/BasicScrollBarUI.java (ArrowIcon):
+ (createIncreaseIcon): Center icon, minimize margins.
+ (createDecreaseIcon): Likewise.
+ * javax/swing/plaf/basic/BasicScrollPaneUI.java (installDefaults):
+ Implement.
+ (installUI): Call it.
+ (uninstallDefaults): Implement.
+ (uninstallUI): Call it.
+ * javax/swing/plaf/basic/BasicToolBarUI.java (DragWindow):
+ Call existing Window constructor.
+ * javax/swing/plaf/basic/BasicViewportUI.java (paint):
+ Set clip before painting.
+
+2004-07-21 Olga Rodimina <rodimina@redhat.com>
+
+ * javax/swing/JMenuItem.java:
+ (processMouseEvent): Reimplemented to deal with
+ mouse drag events.
+ (createMenuDragMouseEvent): New private helper method.
+ Creates MenuDragMouseEvent.
+ * javax/swing/MenuSelectionManager.java
+ (componentForPoint): Implemented.
+ (isComponentPartOfCurrentMenu): Made public.
+ (processMouseEvent): Reimplemented to deal with
+ mouse drag events.
+ (setSelectedPath): Corrected small mistake that caused
+ path to be set incorrectly.
+ (getPath): If given component is JMenu then also add this
+ menu's popup menu to the selected path.
+ * javax/swing/plaf/basic/BasicMenuItemUI.java:
+ (getPath): Ditto.
+ (getPreferredSize): Call getPreferredMenuItemSize().
+ (getPreferredItemSize): Moved code from getPreferredSize to here.
+ (installListeners): Install MouseMotionListeners.
+ (MouseInputHandler): Pass mouse release event to MenuSelectionManager
+ if mouse wasn't released in the bounds of this menu item.
+ (MenuDragMouseHandler): Implemented.
+ * javax/swing/plaf/basic/BasicMenuUI.java:
+ (installListeners): Install MouseMotionListener and
+ MenuDrageMouseListener.
+ (MenuDragMouseHandler): Implemented.
+ * javax/swing/plaf/basic/BasicPopupMenuUI.java:
+ (uninstallListeners): Implemented.
+
+2004-07-21 Michael Koch <konqueror@gmx.de>
+
+ * javax/swing/JCheckBox.java: Reformated.
+ (JCheckBox): Fixed all constructors.
+ (isBorderPaintedFlat): New method.
+ (setBorderPaintedFlat): New method.
+ * javax/swing/JEditorPane.java
+ (createEditorKitForContentType): Made public.
+ (scrollToReference): Likewise.
+ * javax/swing/JTextArea.java
+ (setLineWrap): Fire property change.
+ * javax/swing/JToggleButton.java
+ (JToggleButton): New constructor.
+ (JToggleButton): Simplified.
+ * javax/swing/text/AttributeSet.java
+ (FontAttribute): Renamed from FontCharacterAttribute.
+ * javax/swing/text/JTextComponent.java
+ (KeyBinBinding): Added javadoc.
+ (JTextComponent): Likewise.
+ (getAccessibleContext): Fixed javadoc.
+ * javax/swing/text/View.java
+ (View): Added javadoc.
+ * javax/swing/text/TabableView.java: New file.
+ * Makefile.am: Added javax/swing/text/TabableView.java.
+ * Makefile.in: Regenerated.
+
+2004-07-21 Graydon Hoare <graydon@redhat.com>
+
+ * java/awt/image/BufferedImage.java (getSource): Remove tracing chatter.
+ * gnu/java/awt/peer/gtk/GtkToolkit.java
+ (GtkErrorImage): New helper class.
+ (bufferedImageOrError): New helper method.
+ (createImage): Use it.
+
+2004-07-21 David Jee <djee@redhat.com>
+
+ * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextComponentPeer.c
+ (setCaretPosition): Scroll the text view so the new caret position
+ is visible on screen.
+
+2004-07-21 David Jee <djee@redhat.com>
+
+ * gnu/java/awt/peer/gtk/GtkContainerPeer.java
+ (setBounds): Do not validate awtComponent here.
+ * gnu/java/awt/peer/gtk/GtkScrollPanePeer.java
+ (getPreferredSize): New method.
+ * java/awt/ScrollPane.java
+ (ScrollPane): Set default size to 100x100.
+ (addNotify): If child is not a Panel, wrap it with a new Panel.
+ (paramString): Implement.
+
+2004-07-21 Olga Rodimina <rodimina@redhat.com>
+
+ * javax/swing/JMenu.java:
+ (setSelected): Display popup menu only if this menu
+ is showing on the screen.
+ * javax/swing/JPopupMenu.java:
+ (processMouseEvent): Added comment.
+ (processKeyEvent): Likewise.
+ * javax/swing/MenuSelectionManager.java:
+ (clearSelectedPath): Only fireStateChanged() after
+ selected path was changed, not before.
+ (setSelectedPath): Likewise.
+ * javax/swing/plaf/basic/BasicMenuItemUI.java:
+ (paintMenuItem): Corrected position of menu item's
+ icon.
+ * javax/swing/plaf/basic/BasicPopupMenuUI.java:
+ (installUI): Correct setDefaultLightWeightPopupEnabled call.
+ (popupMenuCanceled): Reimplemented.
+ (popupMenuWillBecomeVisible): Select first menu item by default
+ when displaying free floating popup menus.
+ (TopWindowListener): Reimplemented.
+
+2004-07-21 Thomas Fitzsimmons <fitzsim@redhat.com>
+
+ * java/awt/Panel.java (dispatchEventImpl): Override to prevent
+ Panel from being painted twice when it is first shown.
+
+2004-07-21 Olga Rodimina <rodimina@redhat.com>
+
+ * java/awt/Window.java: Reverted changes from my
+ previous patch for creating window without an owner.
+ * javax/swing/SwingUtilities.java:
+ (SwingUtilities.OwnerFrame): made static.
+ (OwnerFrame.setVisible): New method. Overridden with
+ empty implementation.
+ (OwnerFrame.isShowing): New method. Ovverridden
+ to return always true.
+
+2004-07-21 Thomas Fitzsimmons <fitzsim@redhat.com>
+
+ * gnu/java/awt/peer/gtk/GtkComponentPeer.java,
+ jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c
+ (GtkComponentPeer): Remove temporary try/catch block.
+ (setVisible): Call show and hide.
+ (show): Make native.
+ (hide): Likewise.
+ (getArgs): Don't add "visible" argument.
+ * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c
+ (property_notify_predicate): Return Bool instead of int.
+ (find_layout): New function.
+ (connectJObject): Call find_layout.
+ (connectSignals): Likewise.
+ (moveLayout): Likewise.
+ (gtkLayoutSetVisible): Likewise.
+
+2004-07-21 Mark Wielaard <mark@klomp.org>
+
+ * java/awt/event/InvocationEvent.java (dispatch): Synchronize
+ on notifier object before calling notifyAll().
+
+2004-07-21 Olga Rodimina <rodimina@redhat.com>
+
+ * java/awt/Window.java: Changed constructors to use new
+ method that is described below. Constructors call this
+ methods only if newly created window should have an owner.
+ (setWindowOwner): New method. Implementation for
+ this method is moved from this(owner,configuration).
+ * javax/swing/JWindow.java:
+ (JWindow): Reimplement to use SwingUtilities.ownerFrame
+ instead of owner.
+ * javax/swing/SwingUtilities.java:
+ (ownerFrame): Change type of this field to OwnerFrame.
+ (getOwnerFrame): Changed to return object of type OwnerFrame.
+ (SwingUtilities.OwnerFrame): New class. Represents owner
+ of a Window that is not provided with one.
+
+2004-07-21 Olga Rodimina <rodimina@redhat.com>
+
+ * javax/swing/AbstractButton.java:
+ (configurePropertiesFromAction): Set action command
+ to button's text by default if action command is not
+ explicitely specified.
+ * javax/swing/JMenu.java: Remove unnecessary listener
+ and methods relevant to it.
+ (setSelected): Reimplemented.
+ (menuSelectionChanged): Moved most part of implementation to
+ setSelected() and call it instead.
+ * javax/swing/JMenuItem.java:
+ (init): Comment out statement that sets paint_border to false.
+ (configurePropertiesFromAction): Do not set accelerator
+ for JMenu.
+ (menuSelectionChanged): Change selected index in the selection
+ model of menu item's parent.
+ * javax/swing/JPopupMenu.java:
+ (remove): Set constraints.fill field to GridBagConstraints.BOTH
+ instead of GridBagConstraints.HORIZONTAL.
+ (insert): Likewise.
+ (createActionChangeListener): Implemented.
+ (setVisible): Correct location of HeavyWeightMenu and
+ don't firePopupMenuCanceled().
+ (menuSelectionChanged): Implemented.
+ (ActionChangeListener): New Listener. Implemented.
+ * javax/swing/plaf/basic/BasicMenuBarUI.java:
+ (BasicMenuBarUI.ContainerHandler): Implemented.
+ * javax/swing/plaf/basic/BasicMenuItemUI.java:
+ (paintMenuItem): Uncommented out code that paints
+ icon, now that icons are working properly.
+ (PropertyChangeListener): Implemented.
+ * javax/swing/plaf/basic/BasicPopupMenuUI.java:
+ Added javadocs.
+ (topWindowListener): New field.
+ (Constructor): initialize topWindowListener.
+ (BasicPopupMenuUI.TopWindowListener): Implemented.
+ (BasicPopupMenuUI.PopupMenuHandler): Implemented.
+ (BasicPopupMenuUI.TopWindowListener): New ComponentListener.
+ Implemented.
+
+
+
+2004-07-21 Michael Koch <konqueror@gmx.de>
+
+ * javax/swing/plaf/basic/BasicButtonUI.java
+ (paintFocus): Fixed method signature.
+ (paintButtonPressed): Likewise.
+ (paintButtonNormal): Likewise.
+ (paintText): New method.
+ * javax/swing/plaf/basic/BasicLabelUI.java
+ (paint): Re-indented.
+ * javax/swing/plaf/basic/BasicTextUI.java
+ (installUI): Set parent textComponent to opaque.
+ * javax/swing/text/DefaultHighlighter.java
+ (checkPositions): New helper method.
+ (addHighlight): Throws BadLocationException, check positions.
+ (changeHighlight): Likewise.
+ * javax/swing/text/EditorKit.java
+ (EditorKit): Implements Serializable.
+ * javax/swing/text/JTextComponent.java
+ (getUI): Added javadoc.
+ (setUI): Likewise.
+ (upadteUI): Added javadoc, don't revalidate and repaint.
+
+2004-07-21 David Jee <djee@redhat.com>
+
+ * java/awt/GridBagLayout.java
+ (ArrangeGrid): Use PREFERREDSIZE instead of MINSIZE.
+ * javax/swing/AbstractButton.java
+ (setText): Reindent.
+ * javax/swing/RepaintManager.java
+ (addInvalidComponent): Find the first ancestor that isValidateRoot().
+
+2004-07-21 Michael Koch <konqueror@gmx.de>
+
+ * javax/swing/JFormattedTextField.java
+ (value): New field.
+ (JFormattedTextField): Implemented.
+ (getValue): Likewise.
+ (setValue): Likewise.
+ * javax/swing/LookAndFeel.java
+ (getSupportsWindowDecorations): New method.
+ * javax/swing/UIDefaults.java:
+ Use java.beans.PropertyChangeSupport instead of doing all ourself.
+ (addPropertyChangeListener): Made public.
+ (addResourceBundle): Likewise.
+ (removeResourceBundle): Likewise.
+ (setDefaultLocale): Likewise.
+ * javax/swing/plaf/basic/BasicRootPaneUI.java
+ (BasicRootPaneUI): Implements PropertyChangeListener.
+ (propertyChange): New method.
+ * javax/swing/plaf/basic/BasicTextUI.java
+ (BasicHighlighter): New inner class.
+ (createHighlighter): New method.
+ * javax/swing/plaf/basic/BasicToolBarUI.java
+ (DragWindow): Extends java.awt.Window.
+ * javax/swing/text/JTextComponent.java
+ (getDocument): Removed debug output.
+ * javax/swing/plaf/basic/BasicTextFieldUI.java,
+ javax/swing/text/DefaultHighlighter.java,
+ javax/swing/text/FieldView.java,
+ javax/swing/text/PlainView.java: New files.
+ * Makefile.am: Added new files.
+ * Makefile.in: Regenerated.
+
+2004-07-21 Michael Koch <konqueror@gmx.de>
+
+ * javax/swing/JEditorPane.java
+ (createDefaultEditorKit): Use javax.swing.text.DefaultEditorKit.
+ (createEditorKitForContentType): Likewise.
+ * javax/swing/text/DefaultEditorKit.java
+ (serialVersionUID): Added constant field.
+ (EndOfLineStringPropery): Fixed typo.
+ (DefaultEditorKit): New constructor.
+ * javax/swing/text/Segment.java:
+ Import java.text.CharacterIterator.
+ * javax/swing/text/CharacterIterator.java,
+ javax/swing/text/PlainEditorKit.java: Removed.
+ * Makefile.am: Removed javax/swing/text/CharacterIterator.java and
+ javax/swing/text/PlainEditorKit.java.
+ * Makefile.in: Regenerated.
+
+2004-07-21 Michael Koch <konqueror@gmx.de>
+
+ * javax/swing/JButton.java,
+ javax/swing/text/DefaultEditorKit.java,
+ javax/swing/text/EditorKit.java,
+ javax/swing/text/Segment.java,
+ javax/swing/text/StyledEditorKit.java:
+ Reformatted.
+
+2004-07-21 Michael Koch <konqueror@gmx.de>
+
+ * javax/swing/ImageIcon.java
+ (file): Removed.
+ (description): Renamed from descr.
+ (ImageIcon): Added missing constructors.
+ (setParent): Removed.
+ (setImageObserver): New method.
+ (getImageObserver): New method.
+ (paintIcon): Handle observer = null.
+ * javax/swing/JButton.java
+ (removeNotify): Fixed javadoc.
+ (updateUI): Simplified.
+ * javax/swing/JRootPane.java
+ (serialVersionUID): New constant field.
+ * javax/swing/UIManager.java:
+ Fixed javadocs all over.
+ (setLookAndFeel): Throws UnsupportedLookAndFeelException.
+ * javax/swing/text/AbstractDocument.java
+ (createPosition): Throws BadLocationException.
+ (getText): Likewise.
+ (remove): Likewise.
+ * javax/swing/text/ComponentView.java
+ (modelToView): Likewise.
+ * javax/swing/text/DefaultEditorKit.java:
+ Made all public methods public.
+ (read): Throws BadLocationException and IOException.
+ (write): Likewise.
+ * javax/swing/text/EditorKit.java:
+ Made all public methods public.
+ (serialVersionUID): New constant field.
+ (clone): New method.
+ (read): Throws BadLocationException and IOException.
+ (write): Likewise.
+ * javax/swing/text/Segment.java
+ (array): Made public.
+ (count): Likewise.
+ (offset): Likewise.
+ (Segment): New constructors.
+ (clone): Reimplemented.
+ * javax/swing/text/StyledEditorKit.java
+ (serialVersionUID): New constant field.
+
+2004-07-21 Graydon Hoare <graydon@redhat.com>
+
+ * java/awt/image/BufferedImage.java
+ (getSource): Implement.
+ * javax/swing/ImageIcon.java
+ (ImageIcon): Implement ctor.
+ * javax/swing/ScrollPaneLayout.java
+ (preferredLayoutSize): Be more careful about nulls.
+
+2004-07-21 Michael Koch <konqueror@gmx.de>
+
+ * javax/swing/text/AttributeSet.java
+ (CharacterAttribute): New interface
+ (ColorAttribute): Likewise.
+ (FontCharacterAttribute): Likewise.
+ (ParagraphAttribute): Likewise.
+ * javax/swing/text/DefaultCaret.java
+ (moveCaret): New method.
+ (positionCaret): Likewise.
+ (repaint): Made protected.
+ * javax/swing/text/JTextComponent.java
+ (KeyBinding): Made it static.
+ * javax/swing/text/View.java
+ (getContainer): Honor parent == null.
+
+2004-07-21 Michael Koch <konqueror@gmx.de>
+
+ * javax/swing/text/AbstractDocument.java:
+ Reformatted.
+
+2004-07-21 Michael Koch <konqueror@gmx.de>
+
+ * javax/swing/plaf/basic/BasicRootPaneUI.java:
+ Import javax.swing.UIManager explicitely.
+ * javax/swing/plaf/basic/BasicTabbedPaneUI.java
+ (ScrollingButton): Made it static.
+
+2004-07-21 Michael Koch <konqueror@gmx.de>
+
+ * javax/swing/UIDefaults.java
+ (ActiveValue): Made public.
+ (LazyValue): Likewise.
+ * javax/swing/plaf/basic/BasicTextUI.java
+ (RootView): Reintroduced.
+ (view): Removed.
+ (rootView): New field.
+ (installUI): Create document if needed, initialize rootView.
+ (uninstallUI): Hanle rootView.
+ (paint): Likewise.
+ (getRootView): Likewise.
+ (setView): Likewise.
+ * javax/swing/text/DefaultCaret.java:
+ Renamed all "evt" variables to "event".
+
+2004-07-21 Thomas Fitzsimmons <fitzsim@redhat.com>
+
+ * libgcj.spec.in: Add -l-java-util-logging.
+
+2004-07-21 Andreas Tobler <a.tobler@schweiz.ch>
+
+ * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMainThread.c
+ (init_dpi_conversion_factor): Check for int_dpi < 0 in case
+ gtk-xft-dpi can no calculate the right value.
+ (dpi_changed_cb): Mark *pspec as unsused.
+
+2004-07-21 David Jee <djee@redhat.com>
+
+ * java/awt/Component.java
+ (move): Delegate to setBounds().
+ (resize): Likewise.
+ (reshape): Fix so it repaints parent and self only when necessary.
+
+2004-07-21 David Jee <djee@redhat.com>
+
+ * gnu/java/awt/peer/gtk/GtkComponentPeer.java,
+ jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c
+ (GtkComponentPeer): Revert previous patch from 2004-06-22.
+ (setVisible): Likewise.
+ (show): Likewise.
+ (hide): Likewise.
+ (getArgs): Likewise.
+ * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c
+ (property_notify_predicate): Likewise.
+ (find_layout): Likewise.
+ (connectJObject): Likewise.
+ (connectSignals): Likewise.
+ (moveLayout): Likewise.
+ (gtkLayoutSetVisible): Likewise.
+
+2004-07-21 Graydon Hoare <graydon@redhat.com>
+
+ * Makefile.am
+ (jv_convert_LDADD):
+ (gij_LDADD):
+ (rmic_LDADD):
+ (rmiregistry_LDADD): Add lib-java-util-logging.la
+ * Makefile.in: Regenerate.
+
+2004-07-21 Michael Koch <konqueror@gmx.de>
+
+ * javax/swing/text/AbstractDocument.java
+ (replace): Dont use protected method of java.util.Vector directly.
+
+2004-07-21 Michael Koch <konqueror@gmx.de>
+
+ * javax/swing/plaf/basic/BasicTextUI.java
+ (installUI): Call specialized install methods.
+ (installDefaults): New method.
+ (installListeners): Likewise.
+ (installKeyboardActions): Likewise.
+ (uninstallUI): Likewise.
+ (uninstallDefaults): New method.
+ (uninstallListeners): Likewise.
+ (uninstallKeyboardActions): Likewise.
+ (getPropertyPrefix): New abstract method.
+ (paint): Made final, just call paintSafely().
+ (paintSavely): New method.
+ (paintBackground): Likewise.
+ (getVisibleEditorRect): Likewise.
+ * javax/swing/text/LayeredHighlighter.java,
+ javax/swing/text/TabExpander.java: New files.
+ * Makefile.am: Added javax/swing/text/LayeredHighlighter.java
+ and javax/swing/text/TabExpander.java.
+ * Makefile.in: Regenerated.
+
+2004-07-21 Michael Koch <konqueror@gmx.de>
+
+ * javax/swing/plaf/basic/BasicTextUI.java
+ (BasicTextUI): Made abstract.
+ (BasicCaret): New inner class.
+ (view): Don't explicitely initialize with "null".
+ (textComponent): New field.
+ (textColor): Removed.
+ (disabledTextColor): Removed.
+ (normalBackgroundColor): Removed.
+ (RootView): Removed commented out inner class.
+ (createUI): Removed.
+ (createCaret): New method.
+ (getComponent): Likewise.
+ (installUI): Initialize textComponent only.
+ (getPreferredSize): Use installed JTextComponent.
+ (setView): New method.
+ (create): Likewise.
+ * javax/swing/text/JTextComponent.java
+ (highlighter): New field.
+ (caretColor): Likewise.
+ (disabledTextColor): Likewise.
+ (seletedTextColor): Likewise.
+ (selectionColor): Likewise.
+ (setUI): New method.
+ (getCaretColor): Likewise.
+ (setCaretColor): Likewise.
+ (getDisabledColor): Likewise.
+ (setDisabledColor): Likewise.
+ (getSelectedTextColor): Likewise.
+ (setSelectedTextColor): Likewise.
+ (getSelectionColor): Likewise.
+ (setSelectionColor): Likewise.
+ (getHighlighter): Likewise.
+ (setHighlighter): Likewise.
+ (replaceSelection): Likewise.
+
+2004-07-21 Michael Koch <konqueror@gmx.de>
+
+ * javax/swing/plaf/basic/BasicScrollPaneUI.java
+ (BasicScrollPaneUI): Implements ScrollPaneConstants.
+ * javax/swing/plaf/basic/BasicToolBarUI.java
+ (BasicToolBarUI): Implements SwingConstants.
+
+2004-07-21 Michael Koch <konqueror@gmx.de>
+
+ * javax/swing/JPopupMenu.java: Removed CVS tags.
+ * javax/swing/UIDefaults.java: Reformatted.
+ * javax/swing/plaf/basic/BasicRootPaneUI.java:
+ Explicitely import used classes.
+
+2004-07-21 Thomas Fitzsimmons <fitzsim@redhat.com>
+
+ * gnu/java/awt/peer/gtk/GtkComponentPeer.java,
+ jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c
+ (GtkComponentPeer): Remove temporary try/catch block.
+ (setVisible): Call show and hide.
+ (show): Make native.
+ (hide): Likewise.
+ (getArgs): Don't add "visible" argument.
+ * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c
+ (property_notify_predicate): Return Bool instead of int.
+ (find_layout): New function.
+ (connectJObject): Call find_layout.
+ (connectSignals): Likewise.
+ (moveLayout): Likewise.
+ (gtkLayoutSetVisible): Likewise.
+
+2004-07-21 Olga Rodimina <rodimina@redhat.com>
+
+ * javax/swing/AbstractButton.java:
+ (setDisplayedMnemonicIndex): Check if button
+ text is not null before checking its length.
+ * javax/swing/JMenuItem.java:
+ (processMouseEvent): Disarm menu item if mouse has
+ exited it.
+ * javax/swing/plaf/basic/BasicMenuUI.java:
+ (MouseInputHandler.mouseEntered): Do not raise
+ popup menu if this menu is already selected.
+ (MouseInputHandler.mousePressed): Do not fire
+ MenuEvents.
+ (MenuHandler): Implemented.
+
+2004-07-21 Olga Rodimina <rodimina@redhat.com>
+
+ * javax/swing/JCheckBoxMenuItem.java: Added Javadoc.
+ (getSelectedObjects): Implemented.
+ * javax/swing/JRadioButtonMenuItem.java: Added Javadoc.
+ * javax/swing/plaf/basic/BasicCheckBoxMenuItemUI.java:
+ Added javadoc for few methods.
+ (processMouseEvent): Made public.
+ * javax/swing/plaf/basic/BasicRadioButtonMenuItemUI.java
+ (processMouseEvent): Likewise.
+
+2004-07-21 Olga Rodimina <rodimina@redhat.com>
+
+ * javax/swing/AbstractButton.java:
+ (init): Set display mnemonic index to -1.
+ (setMnemonic(char)): Use setMnemonic(int).
+ (setMnemonic(int)): Set display mnemonic index.
+ (getDisplayedMnemonicIndex): Change method signature
+ by removing 'index' parameter.
+ * javax/swing/plaf/basic/BasicLookAndFeel.java:
+ Added default for Menu.selectionBackground.
+ * javax/swing/plaf/basic/BasicMenuItemUI.java:
+ (paintMenuItem): Change background color of the selected
+ menu item.
+ (paintText): Paint differently when menu item is disabled.
+ Also paint mnemonic if it appears in the menu item's label.
+ (paintAccelerator): Paint accelerator differently
+ if menu item is disabled.
+ * javax/swing/plaf/basic/BasicMenuUI.java:
+ (installDefaults): Install defaults for
+ selectionForeground and selectionBackground.
+ (uninstallDefaults): Uninstall defauls for
+ selectionForeground and selectionBackground.
+
+2004-07-21 Michael Koch <konqueror@gmx.de>
+
+ * javax/swing/text/AbstractDocument.java
+ (BranchElement): Implemented.
+ (LeafElement): Implemented.
+ * javax/swing/text/DefaultCaret.java:
+ Import used classes.
+ (serialVersionUID): New constant.
+ * javax/swing/text/JTextComponent.java
+ (AccessibleJTextComponent): Removed dead declaration.
+ (caretPos): Removed.
+ (setCaret): New method.
+ * javax/swing/text/PlainDocument.java
+ (rootElement): New field.
+ (PlainDocument): Initialize rootElement.
+ (createDefaultRoot): New method.
+ (getDefaultRootElement): Implemented.
+ * javax/swing/text/View.java: Reformatted.
+ * javax/swing/text/ViewFactory.java
+ (create): Added javadoc.
+
+2004-07-21 Michael Koch <konqueror@gmx.de>
+
+ * javax/swing/ToolTipManager.java: Reformatted.
+
+2004-07-21 Rodimina Olga <rodimina@redhat.com>
+
+ * javax/swing/AbstractButton.java
+ (changeEvent): New field.
+ (fireItemStateChanged): Change source of the event
+ to 'this' before firing it to button listeners.
+ (fireActionPerformed): Likewise.
+ (fireStateChanged): Likewise.
+ (createActionListener): Do not set source
+ of the event to AbstractButton.
+ * javax/swing/plaf/basic/BasicMenuBarUI.java:
+ (ContainerHandler.componentAdded): Removed
+ print out statement.
+ (ContainerHandler.componentRemoved): Likewise.
+
+2004-07-21 Michael Koch <konqueror@gmx.de>
+
+ * javax/swing/text/Highlighter.java: New file.
+ * Makefile.am: Added javax/swing/text/Highlighter.java.
+ * Makefile.in: Regenerated.
+
+2004-07-21 Michael Koch <konqueror@gmx.de>
+
+ * javax/swing/ToolTipManager.java
+ (stillInsideTimerAction): Fixed constructor arguments.
+ (outsideTimerAction): Likewise.
+ (insideTimerAction): Likewise.
+
+2004-07-21 Michael Koch <konqueror@gmx.de>
+
+ * javax/swing/JButton.java: Reformatted.
+ * javax/swing/JFormattedTextField.java
+ (getUIClassID): Implemented.
+ * javax/swing/JRootPane.java
+ (serialVersionUID): New constant.
+ * javax/swing/JTextField.java
+ (align): New field.
+ (JTextField): Simplified.
+ (getUIClassID): New method.
+ (getActionListeners): Added @since tag.
+ (setColumns): Invalidate layout and repaint.
+ (getHorizontalAlignment): New method.
+ (setHorizontalAlignment): New method.
+ (selectAll): Removed.
+ * javax/swing/SwingUtilities.java
+ (getAncestorOfClass): Removed redundant @see tag.
+ (isLeftMouseButton): Fixed implementation.
+ (isMiddleMouseButton): Likewise.
+ (isRightMouseButton): Likewise.
+ * javax/swing/text/AbstractDocument.java
+ (AttributeContext.addAttribute): New method.
+ (AttributeContext.addAttributes): New method.
+ (AttributeContext.getEmptySet): New method.
+ (AttributeContext.reclaim): New method.
+ (AttributeContext.removeAttribute): New method.
+ (AttributeContext.removeAttributes): New method.
+ * javax/swing/text/Document.java
+ (createPosition): Throws BadLocationException.
+ (getText): Likewise.
+ (remove): Likewise.
+ * javax/swing/text/JTextComponent.java
+ (getText): Return null if no document is set. Catch
+ BadLocationException.
+ (getUI): Return ui.
+ (updateUI): Simplified.
+
+2004-07-21 Michael Koch <konqueror@gmx.de>
+
+ * javax/swing/JButton.java
+ (removeNotify): Fixed javadoc.
+ (updateUI): Simplified.
+
+2004-07-21 David Jee <djee@redhat.com>
+
+ * gnu/java/awt/image/ImageDecoder.java
+ (startProduction): Only add consumer if it's not added yet.
+ * gnu/java/awt/peer/gtk/GdkPixbufDecoder.java
+ (GdkPixbufDecoder): Don't call initState() here.
+ (produce): Call initState() here, to ensure area_prepared and
+ area_updated signals are properly connected.
+ * gnu/java/awt/peer/gtk/GtkImage.java
+ (setColorModel): Use equals() to compare ColorModel objects.
+ (setPixels): Likewise.
+ * java/awt/image/ColorModel.java
+ (equals): Fix typo. Use Arrays.equals() to compare int arrays.
+ * java/awt/image/RGBImageFilter.java
+ (setColorModel): Set consumer's color model.
+ (setPixels): Use equals() to compare ColorModel objects.
+
2004-07-21 Bryce McKinlay <mckinlay@redhat.com>
* java/net/URLConnection.java (position): New field.
java/awt/geom/QuadCurve2D.java \
java/awt/image/AffineTransformOp.java \
java/awt/image/BufferedImage.java \
+java/awt/image/ByteLookupTable.java \
java/awt/image/ColorModel.java \
java/awt/image/ComponentColorModel.java \
java/awt/image/ComponentSampleModel.java \
java/awt/image/ImageObserver.java \
java/awt/image/ImageProducer.java \
java/awt/image/IndexColorModel.java \
+java/awt/image/Kernel.java \
+java/awt/image/LookupTable.java \
java/awt/image/PackedColorModel.java \
java/awt/image/PixelInterleavedSampleModel.java \
java/awt/image/Raster.java \
java/awt/image/RasterOp.java \
java/awt/image/SampleModel.java \
+java/awt/image/ShortLookupTable.java \
java/awt/image/SinglePixelPackedSampleModel.java \
java/awt/image/WritableRaster.java \
java/awt/image/AreaAveragingScaleFilter.java \
javax/swing/plaf/basic/BasicSplitPaneDivider.java \
javax/swing/plaf/basic/BasicSplitPaneUI.java \
javax/swing/plaf/basic/BasicTabbedPaneUI.java \
+javax/swing/plaf/basic/BasicTextFieldUI.java \
javax/swing/plaf/basic/BasicTextUI.java \
javax/swing/plaf/basic/BasicToggleButtonUI.java \
+javax/swing/plaf/basic/BasicToolBarSeparatorUI.java \
javax/swing/plaf/basic/BasicToolBarUI.java \
javax/swing/plaf/basic/BasicTreeUI.java \
javax/swing/plaf/basic/BasicViewportUI.java \
javax/swing/ListSelectionModel.java \
javax/swing/LookAndFeel.java \
javax/swing/Scrollable.java \
+javax/swing/Spring.java \
+javax/swing/SpringLayout.java \
javax/swing/SwingConstants.java \
javax/swing/SwingUtilities.java \
javax/swing/Timer.java \
javax/swing/text/AttributeSet.java \
javax/swing/text/BadLocationException.java \
javax/swing/text/Caret.java \
-javax/swing/text/CharacterIterator.java \
javax/swing/text/ComponentView.java \
javax/swing/text/DefaultCaret.java \
javax/swing/text/DefaultEditorKit.java \
+javax/swing/text/DefaultHighlighter.java \
javax/swing/text/Document.java \
javax/swing/text/DocumentFilter.java \
javax/swing/text/EditorKit.java \
javax/swing/text/Element.java \
+javax/swing/text/FieldView.java \
javax/swing/text/GapContent.java \
+javax/swing/text/Highlighter.java \
javax/swing/text/JTextComponent.java \
javax/swing/text/Keymap.java \
+javax/swing/text/LayeredHighlighter.java \
+javax/swing/text/MutableAttributeSet.java \
+javax/swing/text/NavigationFilter.java \
javax/swing/text/PlainDocument.java \
-javax/swing/text/PlainEditorKit.java \
+javax/swing/text/PlainView.java \
javax/swing/text/Position.java \
javax/swing/text/Segment.java \
javax/swing/text/Style.java \
-javax/swing/text/View.java \
-javax/swing/text/ViewFactory.java \
-javax/swing/text/MutableAttributeSet.java \
-javax/swing/text/NavigationFilter.java \
javax/swing/text/StyledDocument.java \
javax/swing/text/StyledEditorKit.java \
+javax/swing/text/TabExpander.java \
+javax/swing/text/TabableView.java \
javax/swing/text/TextAction.java \
+javax/swing/text/View.java \
+javax/swing/text/ViewFactory.java \
javax/swing/text/html/HTML.java \
javax/swing/text/html/parser/ParserDelegator.java \
javax/swing/tree/TreeNode.java \
java/awt/geom/QuadCurve2D.java \
java/awt/image/AffineTransformOp.java \
java/awt/image/BufferedImage.java \
+java/awt/image/ByteLookupTable.java \
java/awt/image/ColorModel.java \
java/awt/image/ComponentColorModel.java \
java/awt/image/ComponentSampleModel.java \
java/awt/image/ImageObserver.java \
java/awt/image/ImageProducer.java \
java/awt/image/IndexColorModel.java \
+java/awt/image/Kernel.java \
+java/awt/image/LookupTable.java \
java/awt/image/PackedColorModel.java \
java/awt/image/PixelInterleavedSampleModel.java \
java/awt/image/Raster.java \
java/awt/image/RasterOp.java \
java/awt/image/SampleModel.java \
+java/awt/image/ShortLookupTable.java \
java/awt/image/SinglePixelPackedSampleModel.java \
java/awt/image/WritableRaster.java \
java/awt/image/AreaAveragingScaleFilter.java \
javax/swing/plaf/basic/BasicSplitPaneDivider.java \
javax/swing/plaf/basic/BasicSplitPaneUI.java \
javax/swing/plaf/basic/BasicTabbedPaneUI.java \
+javax/swing/plaf/basic/BasicTextFieldUI.java \
javax/swing/plaf/basic/BasicTextUI.java \
javax/swing/plaf/basic/BasicToggleButtonUI.java \
+javax/swing/plaf/basic/BasicToolBarSeparatorUI.java \
javax/swing/plaf/basic/BasicToolBarUI.java \
javax/swing/plaf/basic/BasicTreeUI.java \
javax/swing/plaf/basic/BasicViewportUI.java \
javax/swing/ListSelectionModel.java \
javax/swing/LookAndFeel.java \
javax/swing/Scrollable.java \
+javax/swing/Spring.java \
+javax/swing/SpringLayout.java \
javax/swing/SwingConstants.java \
javax/swing/SwingUtilities.java \
javax/swing/Timer.java \
javax/swing/text/AttributeSet.java \
javax/swing/text/BadLocationException.java \
javax/swing/text/Caret.java \
-javax/swing/text/CharacterIterator.java \
javax/swing/text/ComponentView.java \
javax/swing/text/DefaultCaret.java \
javax/swing/text/DefaultEditorKit.java \
+javax/swing/text/DefaultHighlighter.java \
javax/swing/text/Document.java \
javax/swing/text/DocumentFilter.java \
javax/swing/text/EditorKit.java \
javax/swing/text/Element.java \
+javax/swing/text/FieldView.java \
javax/swing/text/GapContent.java \
+javax/swing/text/Highlighter.java \
javax/swing/text/JTextComponent.java \
javax/swing/text/Keymap.java \
+javax/swing/text/LayeredHighlighter.java \
+javax/swing/text/MutableAttributeSet.java \
+javax/swing/text/NavigationFilter.java \
javax/swing/text/PlainDocument.java \
-javax/swing/text/PlainEditorKit.java \
+javax/swing/text/PlainView.java \
javax/swing/text/Position.java \
javax/swing/text/Segment.java \
javax/swing/text/Style.java \
-javax/swing/text/View.java \
-javax/swing/text/ViewFactory.java \
-javax/swing/text/MutableAttributeSet.java \
-javax/swing/text/NavigationFilter.java \
javax/swing/text/StyledDocument.java \
javax/swing/text/StyledEditorKit.java \
+javax/swing/text/TabExpander.java \
+javax/swing/text/TabableView.java \
javax/swing/text/TextAction.java \
+javax/swing/text/View.java \
+javax/swing/text/ViewFactory.java \
javax/swing/text/html/HTML.java \
javax/swing/text/html/parser/ParserDelegator.java \
javax/swing/tree/TreeNode.java \
DATA = $(jar_DATA) $(pkgconfig_DATA) $(toolexecmainlib_DATA)
DIST_COMMON = README COPYING ChangeLog Makefile.am Makefile.in NEWS \
-THANKS TODO acinclude.m4 aclocal.m4 configure configure.in \
+THANKS acinclude.m4 aclocal.m4 configure configure.in \
libgcj-test.spec.in libgcj.pc.in libgcj.spec.in
.deps/java/awt/image/BufferStrategy.P \
.deps/java/awt/image/BufferedImage.P \
.deps/java/awt/image/BufferedImageOp.P \
+.deps/java/awt/image/ByteLookupTable.P \
.deps/java/awt/image/ColorModel.P \
.deps/java/awt/image/ComponentColorModel.P \
.deps/java/awt/image/ComponentSampleModel.P \
.deps/java/awt/image/ImageObserver.P \
.deps/java/awt/image/ImageProducer.P \
.deps/java/awt/image/ImagingOpException.P \
-.deps/java/awt/image/IndexColorModel.P \
+.deps/java/awt/image/IndexColorModel.P .deps/java/awt/image/Kernel.P \
+.deps/java/awt/image/LookupTable.P \
.deps/java/awt/image/MemoryImageSource.P \
.deps/java/awt/image/PackedColorModel.P \
.deps/java/awt/image/PixelGrabber.P \
.deps/java/awt/image/RasterOp.P .deps/java/awt/image/RenderedImage.P \
.deps/java/awt/image/ReplicateScaleFilter.P \
.deps/java/awt/image/SampleModel.P \
+.deps/java/awt/image/ShortLookupTable.P \
.deps/java/awt/image/SinglePixelPackedSampleModel.P \
.deps/java/awt/image/TileObserver.P \
.deps/java/awt/image/VolatileImage.P \
.deps/javax/swing/ScrollPaneLayout.P .deps/javax/swing/Scrollable.P \
.deps/javax/swing/SingleSelectionModel.P \
.deps/javax/swing/SizeRequirements.P .deps/javax/swing/SizeSequence.P \
+.deps/javax/swing/Spring.P .deps/javax/swing/SpringLayout.P \
.deps/javax/swing/SwingConstants.P .deps/javax/swing/SwingUtilities.P \
.deps/javax/swing/Timer.P .deps/javax/swing/ToolTipManager.P \
.deps/javax/swing/UIDefaults.P .deps/javax/swing/UIManager.P \
.deps/javax/swing/plaf/basic/BasicSplitPaneDivider.P \
.deps/javax/swing/plaf/basic/BasicSplitPaneUI.P \
.deps/javax/swing/plaf/basic/BasicTabbedPaneUI.P \
+.deps/javax/swing/plaf/basic/BasicTextFieldUI.P \
.deps/javax/swing/plaf/basic/BasicTextUI.P \
.deps/javax/swing/plaf/basic/BasicToggleButtonUI.P \
+.deps/javax/swing/plaf/basic/BasicToolBarSeparatorUI.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/text/AbstractDocument.P \
.deps/javax/swing/text/AttributeSet.P \
.deps/javax/swing/text/BadLocationException.P \
-.deps/javax/swing/text/Caret.P \
-.deps/javax/swing/text/CharacterIterator.P \
-.deps/javax/swing/text/ComponentView.P \
+.deps/javax/swing/text/Caret.P .deps/javax/swing/text/ComponentView.P \
.deps/javax/swing/text/DefaultCaret.P \
.deps/javax/swing/text/DefaultEditorKit.P \
+.deps/javax/swing/text/DefaultHighlighter.P \
.deps/javax/swing/text/Document.P \
.deps/javax/swing/text/DocumentFilter.P \
.deps/javax/swing/text/EditorKit.P .deps/javax/swing/text/Element.P \
-.deps/javax/swing/text/GapContent.P \
+.deps/javax/swing/text/FieldView.P .deps/javax/swing/text/GapContent.P \
+.deps/javax/swing/text/Highlighter.P \
.deps/javax/swing/text/JTextComponent.P .deps/javax/swing/text/Keymap.P \
+.deps/javax/swing/text/LayeredHighlighter.P \
.deps/javax/swing/text/MutableAttributeSet.P \
.deps/javax/swing/text/NavigationFilter.P \
.deps/javax/swing/text/PlainDocument.P \
-.deps/javax/swing/text/PlainEditorKit.P \
-.deps/javax/swing/text/Position.P .deps/javax/swing/text/Segment.P \
-.deps/javax/swing/text/Style.P .deps/javax/swing/text/StyledDocument.P \
+.deps/javax/swing/text/PlainView.P .deps/javax/swing/text/Position.P \
+.deps/javax/swing/text/Segment.P .deps/javax/swing/text/Style.P \
+.deps/javax/swing/text/StyledDocument.P \
.deps/javax/swing/text/StyledEditorKit.P \
+.deps/javax/swing/text/TabExpander.P \
+.deps/javax/swing/text/TabableView.P \
.deps/javax/swing/text/TextAction.P .deps/javax/swing/text/View.P \
.deps/javax/swing/text/ViewFactory.P .deps/javax/swing/text/html/HTML.P \
.deps/javax/swing/text/html/parser/ParserDelegator.P \
public void startProduction (ImageConsumer ic)
{
+ if (!isConsumer(ic))
addConsumer (ic);
+
Vector list = (Vector) consumers.clone ();
try
{
public GdkPixbufDecoder (String filename)
{
super (filename);
- initState ();
}
public GdkPixbufDecoder (URL url)
{
super (url);
- initState ();
}
public GdkPixbufDecoder (byte[] imagedata, int imageoffset, int imagelength)
{
super (imagedata, imageoffset, imagelength);
- initState ();
}
// called back by native side
byte bytes[] = new byte[4096];
int len = 0;
+ initState();
while ((len = is.read (bytes)) != -1)
pumpBytes (bytes, len);
this.awtComponent = awtComponent;
insets = new Insets (0, 0, 0, 0);
- /* temporary try/catch block until all peers use this creation method */
- try {
create ();
GtkArgList args = new GtkArgList ();
Rectangle bounds = awtComponent.getBounds ();
setBounds (bounds.x, bounds.y, bounds.width, bounds.height);
- } catch (RuntimeException ex) { ; }
+ setVisible (awtComponent.isVisible ());
}
public int checkImage (Image image, int width, int height,
public void setVisible (boolean b)
{
- set ("visible", b);
- }
-
- public void hide ()
- {
- setVisible (false);
+ if (b)
+ show ();
+ else
+ hide ();
}
- public void show ()
- {
- setVisible (true);
- }
+ public native void hide ();
+ public native void show ();
protected void postMouseEvent(int id, long when, int mods, int x, int y,
int clickCount, boolean popupTrigger)
public void getArgs (Component component, GtkArgList args)
{
- args.add ("visible", component.isVisible ());
args.add ("sensitive", component.isEnabled ());
ComponentPeer p;
public void setBounds (int x, int y, int width, int height)
{
super.setBounds (x, y, width, height);
- awtComponent.validate ();
}
public void setFont(Font f)
import java.awt.event.WindowEvent;
import java.awt.peer.FileDialogPeer;
import java.io.FilenameFilter;
+import java.io.File;
public class GtkFileDialogPeer extends GtkDialogPeer implements FileDialogPeer
{
private String currentFile = null;
private String currentDirectory = null;
+ private FilenameFilter filter;
- native void create ();
+ native void create (GtkContainerPeer parent);
+ native void connectJObject ();
+ native void connectSignals ();
+ native void nativeSetFile (String file);
+ native public String nativeGetDirectory();
+ native public void nativeSetDirectory(String directory);
+ native void nativeSetFilenameFilter (FilenameFilter filter);
+
+ public void create() {
+ create((GtkContainerPeer) awtComponent.getParent().getPeer());
+
+ FileDialog fd = (FileDialog) awtComponent;
+
+ setDirectory(fd.getDirectory());
+ setFile(fd.getFile());
+
+ FilenameFilter filter = fd.getFilenameFilter();
+ if (filter != null)
+ setFilenameFilter(filter);
+ }
public GtkFileDialogPeer (FileDialog fd)
{
super (fd);
}
- native void connectJObject ();
- native void connectSignals ();
- native void nativeSetFile (String file);
-
public void setFile (String fileName)
{
/* If nothing changed do nothing. This usually happens because
return;
}
- // Remove any directory path from the filename
- int sepIndex = fileName.lastIndexOf (FS);
- if (sepIndex < 0)
- {
+ // GtkFileChooser requires absolute filenames. If the given filename
+ // is not absolute, let's construct it based on current directory.
currentFile = fileName;
+ if (fileName.indexOf(FS) == 0)
+ {
nativeSetFile (fileName);
}
else
{
- if (fileName.length() > (sepIndex + 1))
- {
- String fn = fileName.substring (sepIndex + 1);
- currentFile = fn;
- nativeSetFile (fn);
- }
- else
- {
- currentFile = "";
- nativeSetFile ("");
- }
+ nativeSetFile (nativeGetDirectory() + FS + fileName);
}
}
}
currentDirectory = directory;
-
- // Gtk expects the directory to end with a file separator
- if (directory.substring (directory.length () - 1).equals (FS))
- nativeSetFile (directory);
- else
- nativeSetFile (directory + FS);
+ nativeSetDirectory (directory);
}
public void setFilenameFilter (FilenameFilter filter)
{
- /* GTK has no filter callbacks yet. It works by setting a pattern
- * (see gtk_file_selection_complete), which we can't convert
- * to the callback paradigm. With GTK-2.4 there will be a
- * gtk_file_filter_add_custom function that we can use. */
+ this.filter = filter;
+ nativeSetFilenameFilter(filter);
+ }
+
+ /* This method interacts with the native callback function of the
+ same name. The native function will extract the filename from the
+ GtkFileFilterInfo object and send it to this method, which will
+ in turn call the filter's accept() method and give back the return
+ value. */
+ boolean filenameFilterCallback (String fullname) {
+ String filename = fullname.substring(fullname.lastIndexOf(FS) + 1);
+ String dirname = fullname.substring(0, fullname.lastIndexOf(FS));
+ File dir = new File(dirname);
+ return filter.accept(dir, filename);
}
public Graphics getGraphics ()
public synchronized void
setColorModel (ColorModel model)
{
- if (this.model == null || this.model == model)
+ if (this.model == null || this.model.equals(model))
this.model = model;
else
isCacheable = false;
if (!isCacheable)
return;
- if (cm != model || pixelCache == null)
+ if (!cm.equals(model) || pixelCache == null)
{
isCacheable = false;
return;
public void
imageComplete (int status)
{
+ image.imageComplete(status);
}
}
package gnu.java.awt.peer.gtk;
+import java.awt.AWTEvent;
import java.awt.Panel;
+import java.awt.event.MouseEvent;
import java.awt.peer.PanelPeer;
public class GtkPanelPeer extends GtkContainerPeer
{
super (p);
}
+
+ public void handleEvent (AWTEvent event)
+ {
+ int id = event.getID();
+
+ switch (id)
+ {
+ case MouseEvent.MOUSE_PRESSED:
+ awtComponent.requestFocusInWindow ();
+ break;
+ }
+ super.handleEvent (event);
+ }
}
package gnu.java.awt.peer.gtk;
import java.awt.Adjustable;
+import java.awt.Dimension;
import java.awt.ScrollPane;
import java.awt.peer.ComponentPeer;
import java.awt.peer.ScrollPanePeer;
native public int getVScrollbarWidth ();
native public void setScrollPosition (int x, int y);
-// public Dimension getPreferredSize ()
-// {
-// return new Dimension (60, 60);
-// }
+ public Dimension getPreferredSize ()
+ {
+ return awtComponent.getSize();
+ }
public void setUnitIncrement (Adjustable adj, int u)
{
import java.awt.dnd.peer.DragSourceContextPeer;
import java.awt.font.TextAttribute;
import java.awt.im.InputMethodHighlight;
+import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import java.awt.image.ImageObserver;
+import java.awt.image.ImageConsumer;
import java.awt.image.ImageProducer;
import java.awt.GraphicsEnvironment;
import java.awt.peer.*;
import java.net.URL;
+import java.util.HashSet;
import java.util.Hashtable;
+import java.util.Iterator;
import java.util.Map;
import java.util.MissingResourceException;
import java.util.Properties;
return status;
}
+ /**
+ * A helper class to return to clients in cases where a BufferedImage is
+ * desired but its construction fails.
+ */
+ private class GtkErrorImage extends Image
+ {
+ public GtkErrorImage()
+ {
+ }
+
+ public int getWidth(ImageObserver observer)
+ {
+ return -1;
+ }
+
+ public int getHeight(ImageObserver observer)
+ {
+ return -1;
+ }
+
+ public ImageProducer getSource()
+ {
+
+ return new ImageProducer()
+ {
+ HashSet consumers = new HashSet();
+ public void addConsumer(ImageConsumer ic)
+ {
+ consumers.add(ic);
+ }
+
+ public boolean isConsumer(ImageConsumer ic)
+ {
+ return consumers.contains(ic);
+ }
+
+ public void removeConsumer(ImageConsumer ic)
+ {
+ consumers.remove(ic);
+ }
+
+ public void startProduction(ImageConsumer ic)
+ {
+ consumers.add(ic);
+ Iterator i = consumers.iterator();
+ while(i.hasNext())
+ {
+ ImageConsumer c = (ImageConsumer) i.next();
+ c.imageComplete(ImageConsumer.IMAGEERROR);
+ }
+ }
+ public void requestTopDownLeftRightResend(ImageConsumer ic)
+ {
+ startProduction(ic);
+ }
+ };
+ }
+
+ public Graphics getGraphics()
+ {
+ return null;
+ }
+
+ public Object getProperty(String name, ImageObserver observer)
+ {
+ return null;
+ }
+ public Image getScaledInstance(int width, int height, int flags)
+ {
+ return new GtkErrorImage();
+ }
+
+ public void flush()
+ {
+ }
+ }
+
+
+ /**
+ * Helper to return either a BufferedImage -- the argument -- or a
+ * GtkErrorImage if the argument is null.
+ */
+
+ private Image bufferedImageOrError(BufferedImage b)
+ {
+ if (b == null)
+ return new GtkErrorImage();
+ else
+ return b;
+ }
+
+
public Image createImage (String filename)
{
if (useGraphics2D())
- return GdkPixbufDecoder.createBufferedImage (filename);
+ return bufferedImageOrError(GdkPixbufDecoder.createBufferedImage (filename));
else
{
GdkPixbufDecoder d = new GdkPixbufDecoder (filename);
public Image createImage (URL url)
{
if (useGraphics2D())
- return GdkPixbufDecoder.createBufferedImage (url);
+ return bufferedImageOrError(GdkPixbufDecoder.createBufferedImage (url));
else
{
GdkPixbufDecoder d = new GdkPixbufDecoder (url);
public Image createImage (ImageProducer producer)
{
if (useGraphics2D())
- return GdkPixbufDecoder.createBufferedImage (producer);
+ return bufferedImageOrError(GdkPixbufDecoder.createBufferedImage (producer));
else
{
GtkImage image = new GtkImage (producer, null);
int imagelength)
{
if (useGraphics2D())
- return GdkPixbufDecoder.createBufferedImage (imagedata,
+ return bufferedImageOrError(GdkPixbufDecoder.createBufferedImage (imagedata,
imageoffset,
- imagelength);
+ imagelength));
else
{
GdkPixbufDecoder d = new GdkPixbufDecoder (imagedata,
package java.awt;
import java.awt.dnd.DropTarget;
+import java.awt.event.ActionEvent;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.FocusEvent;
import java.awt.event.HierarchyListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
+import java.awt.event.InputEvent;
import java.awt.event.InputMethodEvent;
import java.awt.event.InputMethodListener;
import java.awt.event.MouseEvent;
*/
public void move(int x, int y)
{
- int oldx = this.x;
- int oldy = this.y;
-
- if (this.x == x && this.y == y)
- return;
- invalidate ();
- this.x = x;
- this.y = y;
- if (peer != null)
- peer.setBounds (x, y, width, height);
-
- // Erase old bounds and repaint new bounds for lightweights.
- if (isLightweight() && width != 0 && height !=0)
- {
- parent.repaint(oldx, oldy, width, height);
- repaint();
- }
-
- if (oldx != x || oldy != y)
- {
- ComponentEvent ce = new ComponentEvent(this,
- ComponentEvent.COMPONENT_MOVED);
- getToolkit().getSystemEventQueue().postEvent(ce);
- }
+ setBounds(x, y, this.width, this.height);
}
/**
*/
public void resize(int width, int height)
{
- int oldwidth = this.width;
- int oldheight = this.height;
-
- if (this.width == width && this.height == height)
- return;
- invalidate ();
- this.width = width;
- this.height = height;
- if (peer != null)
- peer.setBounds (x, y, width, height);
-
- // Erase old bounds and repaint new bounds for lightweights.
- if (isLightweight())
- {
- if (oldwidth != 0 && oldheight != 0 && parent != null)
- parent.repaint(x, y, oldwidth, oldheight);
- if (width != 0 && height != 0)
- repaint();
- }
-
- if (oldwidth != width || oldheight != height)
- {
- ComponentEvent ce =
- new ComponentEvent(this, ComponentEvent.COMPONENT_RESIZED);
- getToolkit().getSystemEventQueue().postEvent(ce);
- }
+ setBounds(this.x, this.y, width, height);
}
/**
// Erase old bounds and repaint new bounds for lightweights.
if (isLightweight())
{
- if (oldwidth != 0 && oldheight != 0 && parent != null)
+ boolean shouldRepaintParent = false;
+ boolean shouldRepaintSelf = false;
+
+ if (parent != null)
+ {
+ Rectangle parentBounds = parent.getBounds();
+ Rectangle oldBounds = new Rectangle(parent.getX() + oldx,
+ parent.getY() + oldy,
+ oldwidth, oldheight);
+ Rectangle newBounds = new Rectangle(parent.getX() + x,
+ parent.getY() + y,
+ width, height);
+ shouldRepaintParent = parentBounds.intersects(oldBounds);
+ shouldRepaintSelf = parentBounds.intersects(newBounds);
+ }
+
+ if (shouldRepaintParent)
parent.repaint(oldx, oldy, oldwidth, oldheight);
- if (width != 0 && height != 0)
+ if (shouldRepaintSelf)
repaint();
}
}
/**
- * AWT 1.0 event dispatcher.
+ * AWT 1.0 event delivery.
*
- * @param e the event to dispatch
+ * Deliver an AWT 1.0 event to this Component. This method simply
+ * calls {@link #postEvent}.
+ *
+ * @param e the event to deliver
* @deprecated use {@link #dispatchEvent(AWTEvent)} instead
*/
public void deliverEvent(Event e)
{
- // XXX Add backward compatibility handling.
+ postEvent (e);
}
/**
}
/**
- * AWT 1.0 event dispatcher.
+ * AWT 1.0 event handler.
*
- * @param e the event to dispatch
- * @return false: since the method was deprecated, the return has no meaning
+ * This method simply calls handleEvent and returns the result.
+ *
+ * @param e the event to handle
+ * @return the result of handling <code>e</code>
* @deprecated use {@link #dispatchEvent(AWTEvent)} instead
*/
public boolean postEvent(Event e)
{
- // XXX Add backward compatibility handling.
- return false;
+ boolean handled = handleEvent (e);
+
+ if (!handled)
+ // FIXME: need to translate event coordinates to parent's
+ // coordinate space.
+ handled = getParent ().postEvent (e);
+
+ return handled;
}
/**
}
/**
- * AWT 1.0 event processor.
+ * AWT 1.0 event handler.
+ *
+ * This method calls one of the event-specific handler methods. For
+ * example for key events, either {@link #keyDown (Event evt, int
+ * key)} or {@link keyUp (Event evt, int key)} is called. A derived
+ * component can override one of these event-specific methods if it
+ * only needs to handle certain event types. Otherwise it can
+ * override handleEvent itself and handle any event.
*
* @param evt the event to handle
- * @return false: since the method was deprecated, the return has no meaning
+ * @return true if the event was handled, false otherwise
* @deprecated use {@link #processEvent(AWTEvent)} instead
*/
public boolean handleEvent(Event evt)
{
- // XXX Add backward compatibility handling.
+ switch (evt.id)
+ {
+ // Handle key events.
+ case Event.KEY_ACTION:
+ case Event.KEY_PRESS:
+ return keyDown (evt, evt.key);
+ case Event.KEY_ACTION_RELEASE:
+ case Event.KEY_RELEASE:
+ return keyUp (evt, evt.key);
+
+ // Handle mouse events.
+ case Event.MOUSE_DOWN:
+ return mouseDown (evt, evt.x, evt.y);
+ case Event.MOUSE_UP:
+ return mouseUp (evt, evt.x, evt.y);
+ case Event.MOUSE_MOVE:
+ return mouseMove (evt, evt.x, evt.y);
+ case Event.MOUSE_DRAG:
+ return mouseDrag (evt, evt.x, evt.y);
+ case Event.MOUSE_ENTER:
+ return mouseEnter (evt, evt.x, evt.y);
+ case Event.MOUSE_EXIT:
+ return mouseExit (evt, evt.x, evt.y);
+
+ // Handle focus events.
+ case Event.GOT_FOCUS:
+ return gotFocus (evt, evt.arg);
+ case Event.LOST_FOCUS:
+ return lostFocus (evt, evt.arg);
+
+ // Handle action event.
+ case Event.ACTION_EVENT:
+ return action (evt, evt.arg);
+ }
+ // Unknown event.
return false;
}
/**
- * AWT 1.0 mouse event.
+ * AWT 1.0 mouse event handler.
*
* @param evt the event to handle
* @param x the x coordinate, ignored
// lightweight component. In either case we want to
// post a FOCUS_GAINED event.
EventQueue eq = Toolkit.getDefaultToolkit ().getSystemEventQueue ();
- eq.postEvent (new FocusEvent(this, FocusEvent.FOCUS_GAINED));
+ synchronized (eq)
+ {
+ KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager ();
+ Component currentFocusOwner = manager.getGlobalPermanentFocusOwner ();
+ if (currentFocusOwner != null)
+ {
+ eq.postEvent (new FocusEvent(currentFocusOwner, FocusEvent.FOCUS_LOST,
+ false, this));
+ eq.postEvent (new FocusEvent(this, FocusEvent.FOCUS_GAINED, false,
+ currentFocusOwner));
+ }
+ else
+ eq.postEvent (new FocusEvent(this, FocusEvent.FOCUS_GAINED, false));
+ }
}
}
else
// lightweight component. In either case we want to
// post a FOCUS_GAINED event.
EventQueue eq = Toolkit.getDefaultToolkit ().getSystemEventQueue ();
+ synchronized (eq)
+ {
+ KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager ();
+ Component currentFocusOwner = manager.getGlobalPermanentFocusOwner ();
+ if (currentFocusOwner != null)
+ {
+ eq.postEvent (new FocusEvent(currentFocusOwner,
+ FocusEvent.FOCUS_LOST,
+ temporary, this));
+ eq.postEvent (new FocusEvent(this,
+ FocusEvent.FOCUS_GAINED,
+ temporary,
+ currentFocusOwner));
+ }
+ else
eq.postEvent (new FocusEvent(this, FocusEvent.FOCUS_GAINED, temporary));
}
}
+ }
else
// FIXME: need to add a focus listener to our top-level
// ancestor, so that we can post this event when it becomes
// Check if top-level ancestor is currently focused window.
if (focusedWindow == toplevel)
{
- if (peer != null)
+ if (peer != null
+ && !(this instanceof Window))
// This call will cause a FOCUS_GAINED event to be
// posted to the system event queue if the native
// windowing system grants the focus request.
// lightweight component. In either case we want to
// post a FOCUS_GAINED event.
EventQueue eq = Toolkit.getDefaultToolkit ().getSystemEventQueue ();
+ synchronized (eq)
+ {
+ Component currentFocusOwner = manager.getGlobalPermanentFocusOwner ();
+ if (currentFocusOwner != null)
+ {
+ eq.postEvent (new FocusEvent(currentFocusOwner, FocusEvent.FOCUS_LOST,
+ temporary, this));
+ eq.postEvent (new FocusEvent(this, FocusEvent.FOCUS_GAINED, temporary,
+ currentFocusOwner));
+ }
+ else
eq.postEvent (new FocusEvent(this, FocusEvent.FOCUS_GAINED, temporary));
}
}
+ }
else
return false;
}
String name = getName();
if (name != null)
param.append(name).append(",");
- param.append(width).append("x").append(height).append("+").append(x)
- .append("+").append(y);
+ param.append(x).append(",").append(y).append(",").append(width)
+ .append("x").append(height);
if (! isValid())
param.append(",invalid");
if (! isVisible())
}
/**
- * Implementation of dispatchEvent. Allows trusted package classes to
- * dispatch additional events first.
+ * Translate an AWT 1.1 event ({@link AWTEvent}) into an AWT 1.0
+ * event ({@link Event}).
+ *
+ * @param e an AWT 1.1 event to translate
+ *
+ * @return an AWT 1.0 event representing e
+ */
+ private Event translateEvent (AWTEvent e)
+ {
+ Component target = (Component) e.getSource ();
+ Event translated = null;
+
+ if (e instanceof InputEvent)
+ {
+ InputEvent ie = (InputEvent) e;
+ long when = ie.getWhen ();
+
+ int oldID = 0;
+ int id = e.getID ();
+
+ int oldMods = 0;
+ int mods = ie.getModifiers ();
+
+ if ((mods & InputEvent.BUTTON2_MASK) != 0)
+ oldMods |= Event.META_MASK;
+ else if ((mods & InputEvent.BUTTON3_MASK) != 0)
+ oldMods |= Event.ALT_MASK;
+
+ if ((mods & (InputEvent.SHIFT_MASK | InputEvent.SHIFT_DOWN_MASK)) != 0)
+ oldMods |= Event.SHIFT_MASK;
+
+ if ((mods & (InputEvent.CTRL_MASK | InputEvent.CTRL_DOWN_MASK)) != 0)
+ oldMods |= Event.CTRL_MASK;
+
+ if ((mods & (InputEvent.META_MASK | InputEvent.META_DOWN_MASK)) != 0)
+ oldMods |= Event.META_MASK;
+
+ if ((mods & (InputEvent.ALT_MASK | InputEvent.ALT_DOWN_MASK)) != 0)
+ oldMods |= Event.ALT_MASK;
+
+ if (e instanceof MouseEvent)
+ {
+ if (id == MouseEvent.MOUSE_PRESSED)
+ oldID = Event.MOUSE_DOWN;
+ else if (id == MouseEvent.MOUSE_RELEASED)
+ oldID = Event.MOUSE_UP;
+ else if (id == MouseEvent.MOUSE_MOVED)
+ oldID = Event.MOUSE_MOVE;
+ else if (id == MouseEvent.MOUSE_DRAGGED)
+ oldID = Event.MOUSE_DRAG;
+ else if (id == MouseEvent.MOUSE_ENTERED)
+ oldID = Event.MOUSE_ENTER;
+ else if (id == MouseEvent.MOUSE_EXITED)
+ oldID = Event.MOUSE_EXIT;
+ else
+ // No analogous AWT 1.0 mouse event.
+ return null;
+
+ MouseEvent me = (MouseEvent) e;
+
+ translated = new Event (target, when, oldID,
+ me.getX (), me.getY (), 0, oldMods);
+ }
+ else if (e instanceof KeyEvent)
+ {
+ if (id == KeyEvent.KEY_PRESSED)
+ oldID = Event.KEY_PRESS;
+ else if (e.getID () == KeyEvent.KEY_RELEASED)
+ oldID = Event.KEY_RELEASE;
+ else
+ // No analogous AWT 1.0 key event.
+ return null;
+
+ int oldKey = 0;
+ int newKey = ((KeyEvent) e).getKeyCode ();
+ switch (newKey)
+ {
+ case KeyEvent.VK_BACK_SPACE:
+ oldKey = Event.BACK_SPACE;
+ break;
+ case KeyEvent.VK_CAPS_LOCK:
+ oldKey = Event.CAPS_LOCK;
+ break;
+ case KeyEvent.VK_DELETE:
+ oldKey = Event.DELETE;
+ break;
+ case KeyEvent.VK_DOWN:
+ case KeyEvent.VK_KP_DOWN:
+ oldKey = Event.DOWN;
+ break;
+ case KeyEvent.VK_END:
+ oldKey = Event.END;
+ break;
+ case KeyEvent.VK_ENTER:
+ oldKey = Event.ENTER;
+ break;
+ case KeyEvent.VK_ESCAPE:
+ oldKey = Event.ESCAPE;
+ break;
+ case KeyEvent.VK_F1:
+ oldKey = Event.F1;
+ break;
+ case KeyEvent.VK_F10:
+ oldKey = Event.F10;
+ break;
+ case KeyEvent.VK_F11:
+ oldKey = Event.F11;
+ break;
+ case KeyEvent.VK_F12:
+ oldKey = Event.F12;
+ break;
+ case KeyEvent.VK_F2:
+ oldKey = Event.F2;
+ break;
+ case KeyEvent.VK_F3:
+ oldKey = Event.F3;
+ break;
+ case KeyEvent.VK_F4:
+ oldKey = Event.F4;
+ break;
+ case KeyEvent.VK_F5:
+ oldKey = Event.F5;
+ break;
+ case KeyEvent.VK_F6:
+ oldKey = Event.F6;
+ break;
+ case KeyEvent.VK_F7:
+ oldKey = Event.F7;
+ break;
+ case KeyEvent.VK_F8:
+ oldKey = Event.F8;
+ break;
+ case KeyEvent.VK_F9:
+ oldKey = Event.F9;
+ break;
+ case KeyEvent.VK_HOME:
+ oldKey = Event.HOME;
+ break;
+ case KeyEvent.VK_INSERT:
+ oldKey = Event.INSERT;
+ break;
+ case KeyEvent.VK_LEFT:
+ case KeyEvent.VK_KP_LEFT:
+ oldKey = Event.LEFT;
+ break;
+ case KeyEvent.VK_NUM_LOCK:
+ oldKey = Event.NUM_LOCK;
+ break;
+ case KeyEvent.VK_PAUSE:
+ oldKey = Event.PAUSE;
+ break;
+ case KeyEvent.VK_PAGE_DOWN:
+ oldKey = Event.PGDN;
+ break;
+ case KeyEvent.VK_PAGE_UP:
+ oldKey = Event.PGUP;
+ break;
+ case KeyEvent.VK_PRINTSCREEN:
+ oldKey = Event.PRINT_SCREEN;
+ break;
+ case KeyEvent.VK_RIGHT:
+ case KeyEvent.VK_KP_RIGHT:
+ oldKey = Event.RIGHT;
+ break;
+ case KeyEvent.VK_SCROLL_LOCK:
+ oldKey = Event.SCROLL_LOCK;
+ break;
+ case KeyEvent.VK_TAB:
+ oldKey = Event.TAB;
+ break;
+ case KeyEvent.VK_UP:
+ case KeyEvent.VK_KP_UP:
+ oldKey = Event.UP;
+ break;
+ default:
+ oldKey = newKey;
+ }
+
+ translated = new Event (target, when, oldID,
+ 0, 0, oldKey, oldMods);
+ }
+ }
+ else if (e instanceof ActionEvent)
+ translated = new Event (target, Event.ACTION_EVENT,
+ ((ActionEvent) e).getActionCommand ());
+
+ return translated;
+ }
+
+ /**
+ * Implementation of dispatchEvent. Allows trusted package classes
+ * to dispatch additional events first. This implementation first
+ * translates <code>e</code> to an AWT 1.0 event and sends the
+ * result to {@link #postEvent}. If the AWT 1.0 event is not
+ * handled, and events of type <code>e</code> are enabled for this
+ * component, e is passed on to {@link #processEvent}.
*
* @param e the event to dispatch
*/
void dispatchEventImpl(AWTEvent e)
{
+ Event oldEvent = translateEvent (e);
+
+ if (oldEvent != null)
+ postEvent (oldEvent);
+
if (eventTypeEnabled (e.id))
processEvent(e);
}
*/
public void deliverEvent(Event e)
{
+ if (!handleEvent (e))
+ {
+ synchronized (getTreeLock ())
+ {
+ Component parent = getParent ();
+
+ if (parent != null)
+ parent.deliverEvent (e);
+ }
+ }
}
/**
{
String param = super.paramString();
if (layoutMgr != null)
- param = param + "," + layoutMgr.getClass().getName();
+ param = param + ",layout=" + layoutMgr.getClass().getName();
return param;
}
{
Component target = (Component) e.getSource ();
- if (e.id == FocusEvent.FOCUS_GAINED
- && !(target instanceof Window))
+ if (e.id == FocusEvent.FOCUS_GAINED)
{
if (((FocusEvent) e).isTemporary ())
setGlobalFocusOwner (target);
else
setGlobalPermanentFocusOwner (target);
}
+ else if (e.id == FocusEvent.FOCUS_LOST)
+ {
+ // We need to set the window's focus owner here; we can't
+ // set it when the window loses focus because by that time
+ // the previous focus owner has already lost focus
+ // (FOCUS_LOST events are delivered before
+ // WINDOW_LOST_FOCUS events).
+
+ // Find the target Component's top-level ancestor.
+ Container parent = target.getParent ();
+
+ while (parent != null
+ && !(parent instanceof Window))
+ parent = parent.getParent ();
+
+ Window toplevel = parent == null ?
+ (Window) target : (Window) parent;
+
+ Component focusOwner = getFocusOwner ();
+ if (focusOwner != null)
+ toplevel.setFocusOwner (focusOwner);
+
+ if (((FocusEvent) e).isTemporary ())
+ setGlobalFocusOwner (null);
+ else
+ setGlobalPermanentFocusOwner (null);
+ }
- if (!(target instanceof Window))
target.dispatchEvent (e);
return true;
// processKeyEvent checks if this event represents a focus
// traversal key stroke.
Component focusOwner = getGlobalPermanentFocusOwner ();
+
+ if (focusOwner != null)
processKeyEvent (focusOwner, (KeyEvent) e);
if (e.isConsumed ())
{
Component focusOwner = getGlobalPermanentFocusOwner ();
+ if (focusOwner != null)
focusOwner.dispatchEvent (e);
// Loop through all registered KeyEventPostProcessors, giving
protected String paramString ()
{
- return "id=" + id + ",x=" + x + ",y=" + y + "target=" + target;
+ return "id=" + id + ",x=" + x + ",y=" + y
+ + ",target=" + target + ",arg=" + arg;
}
public boolean shiftDown()
return(getClass().getName()
+ "(logical=" + getName ()
+ ",family=" + getFamily ()
- + ",face=" + getFontName ()
+ + ",name=" + getFontName ()
+ ",style=" + getStyle ()
- + ",size=" + getSize ()
- + ",transform=" + getTransform () + ")");
+ + ",size=" + getSize ());
}
*/
public class Frame extends Window implements MenuContainer
{
-
-/*
- * Static Variables
- */
-
/**
* Constant for the default cursor.
* @deprecated Replaced by <code>Cursor.DEFAULT_CURSOR</code> instead.
// Serialization version constant
private static final long serialVersionUID = 2673458971256075116L;
-/*************************************************************************/
-
-/*
- * Instance Variables
- */
-
/**
* @serial The version of the class data being serialized
* // FIXME: what is this value?
*/
private boolean undecorated = false;
-/*************************************************************************/
-
/*
- * Constructors
+ * The number used to generate the name returned by getName.
*/
+ private static transient long next_frame_number = 0;
/**
* Initializes a new instance of <code>Frame</code> that is not visible
this("");
}
-/*************************************************************************/
-
/**
* Initializes a new instance of <code>Frame</code> that is not visible
* and has the specified title.
visible = false;
}
-/*************************************************************************/
-
-/*
- * Instance Methods
- */
-
/**
* Returns this frame's title string.
*
return(title);
}
-/*************************************************************************/
-
/*
* Sets this frame's title to the specified value.
*
((FramePeer) peer).setTitle(title);
}
-/*************************************************************************/
-
/**
* Returns this frame's icon.
*
return(icon);
}
-/*************************************************************************/
-
/**
* Sets this frame's icon to the specified value.
*
((FramePeer) peer).setIconImage(icon);
}
-/*************************************************************************/
-
/**
* Returns this frame's menu bar.
*
return(menuBar);
}
-/*************************************************************************/
-
/**
* Sets this frame's menu bar.
*
this.menuBar = menuBar;
}
-/*************************************************************************/
-
/**
* Tests whether or not this frame is resizable. This will be
* <code>true</code> by default.
return(resizable);
}
-/*************************************************************************/
-
/**
* Sets the resizability of this frame to the specified value.
*
((FramePeer) peer).setResizable(resizable);
}
-/*************************************************************************/
-
/**
* Returns the cursor type of the cursor for this window. This will
* be one of the constants in this class.
return(getCursor().getType());
}
-/*************************************************************************/
-
/**
* Sets the cursor for this window to the specified type. The specified
* type should be one of the constants in this class.
setCursor(new Cursor(type));
}
-/*************************************************************************/
-
/**
* Removes the specified component from this frame's menu.
*
menuBar.remove(menu);
}
-/*************************************************************************/
-
/**
* Notifies this frame that it should create its native peer.
*/
super.removeNotify();
}
-/*************************************************************************/
-
/**
* Returns a debugging string describing this window.
*
* @return A debugging string describing this window.
*/
-protected String
-paramString()
+ protected String paramString ()
{
- return(getClass().getName());
+ String title = getTitle ();
+
+ String resizable = "";
+ if (isResizable ())
+ resizable = ",resizable";
+
+ String state = "";
+ switch (getState ())
+ {
+ case NORMAL:
+ state = ",normal";
+ break;
+ case ICONIFIED:
+ state = ",iconified";
+ break;
+ case MAXIMIZED_BOTH:
+ state = ",maximized-both";
+ break;
+ case MAXIMIZED_HORIZ:
+ state = ",maximized-horiz";
+ break;
+ case MAXIMIZED_VERT:
+ state = ",maximized-vert";
+ break;
+ }
+
+ return super.paramString () + ",title=" + title + resizable + state;
}
public static Frame[]
this.undecorated = undecorated;
}
-} // class Frame
+ /**
+ * Generate a unique name for this frame.
+ *
+ * @return A unique name for this frame.
+ */
+ String generateName ()
+ {
+ return "frame" + getUniqueLong ();
+ }
+
+ private static synchronized long getUniqueLong ()
+ {
+ return next_frame_number++;
+ }
+}
if (components.length == 0)
return;
- GridBagLayoutInfo info = getLayoutInfo (parent, MINSIZE);
+ GridBagLayoutInfo info = getLayoutInfo (parent, PREFERREDSIZE);
if (info.cols == 0 && info.rows == 0)
return;
layoutInfo = info;
*/
public Component getFocusOwner ()
{
- return (Component) getObject (currentFocusOwners);
+ Component owner = (Component) getObject (currentFocusOwners);
+ if (owner == null)
+ owner = (Component) getObject (currentPermanentFocusOwners);
+ return owner;
}
/**
package java.awt;
+import java.awt.event.PaintEvent;
import javax.accessibility.Accessible;
import javax.accessibility.AccessibleContext;
import javax.accessibility.AccessibleRole;
/** The cached accessible context. */
private transient AccessibleContext context;
+ /** Flag set when the first system-requested paint event is
+ dispatched. */
+ private transient boolean initialSystemUpdateDone;
+
+ /** Flag set when the first application-requested paint event is
+ consumed. */
+ private transient boolean initialUpdateConsumed;
+
+ /*
+ * The number used to generate the name returned by getName.
+ */
+ private static transient long next_panel_number = 0;
+
/**
* Initializes a new instance of <code>Panel</code> that has a default
* layout manager of <code>FlowLayout</code>.
setLayout(layoutManager);
}
+ /**
+ * Consume initial application-requested paint event if it has not
+ * already been consumed, and if the initial system-requested paint
+ * event has not already been handled. Otherwise, call
+ * super.dispatchEventImpl. These extra steps are required to
+ * prevent a Panel from being painted twice when it is initially
+ * shown.
+ *
+ * @param e the event to dispatch
+ */
+ void dispatchEventImpl (AWTEvent e)
+ {
+ if (e instanceof PaintEvent)
+ {
+ if (e.id == PaintEvent.UPDATE)
+ {
+ if (!initialUpdateConsumed
+ && !initialSystemUpdateDone)
+ {
+ e.consume ();
+ initialUpdateConsumed = true;
+ }
+ }
+ else if (e.id == PaintEvent.PAINT)
+ initialSystemUpdateDone = true;
+ }
+ else
+ super.dispatchEventImpl (e);
+ }
+
/**
* Notifies this object to create its native peer.
*
{
return AccessibleRole.PANEL;
}
- } // class AccessibleAWTPanel
-} // class Panel
+ }
+
+ /**
+ * Generate a unique name for this panel.
+ *
+ * @return A unique name for this panel.
+ */
+ String generateName ()
+ {
+ return "panel" + getUniqueLong ();
+ }
+
+ private static synchronized long getUniqueLong ()
+ {
+ return next_panel_number++;
+ }
+}
}
wheelScrollingEnabled = true;
+
+ // Default size.
+ setSize(100,100);
}
/*************************************************************************/
setPeer((ComponentPeer)getToolkit().createScrollPane(this));
super.addNotify();
+
+ Component[] list = getComponents();
+ if (list != null && list.length > 0 && ! (list[0] instanceof Panel))
+ {
+ Panel panel = new Panel();
+ panel.setLayout(new BorderLayout());
+ panel.add(list[0], BorderLayout.CENTER);
+ add(panel);
+ }
}
/*************************************************************************/
public String
paramString()
{
- return(getClass().getName());
+ Insets insets = getInsets();
+ return getName() + ","
+ + getX() + ","
+ + getY() + ","
+ + getWidth() + "x" + getHeight() + ","
+ + "ScrollPosition=(" + scrollPosition.getX() + ","
+ + scrollPosition.getY() + "),"
+ + "Insets=(" + insets.top + ","
+ + insets.left + ","
+ + insets.bottom + ","
+ + insets.right + "),"
+ + "ScrollbarDisplayPolicy=" + getScrollbarDisplayPolicy() + ","
+ + "wheelScrollingEnabled=" + isWheelScrollingEnabled();
}
/**
package java.awt;
import java.awt.event.ComponentEvent;
+import java.awt.event.FocusEvent;
+import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowFocusListener;
import java.awt.event.WindowListener;
private transient boolean shown;
+ private transient Component windowFocusOwner;
+
/**
* This (package access) constructor is used by subclasses that want
* to build windows that do not have parents. Eg. toplevel
// cycle roots.
focusCycleRoot = true;
setLayout(new BorderLayout());
+
+ addWindowFocusListener (new WindowAdapter ()
+ {
+ public void windowGainedFocus (WindowEvent event)
+ {
+ if (windowFocusOwner != null)
+ {
+ // FIXME: move this section and the other similar
+ // sections in Component into a separate method.
+ EventQueue eq = Toolkit.getDefaultToolkit ().getSystemEventQueue ();
+ synchronized (eq)
+ {
+ KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager ();
+ Component currentFocusOwner = manager.getGlobalPermanentFocusOwner ();
+ if (currentFocusOwner != null)
+ {
+ eq.postEvent (new FocusEvent (currentFocusOwner, FocusEvent.FOCUS_LOST,
+ false, windowFocusOwner));
+ eq.postEvent (new FocusEvent (windowFocusOwner, FocusEvent.FOCUS_GAINED,
+ false, currentFocusOwner));
+ }
+ else
+ eq.postEvent (new FocusEvent (windowFocusOwner, FocusEvent.FOCUS_GAINED, false));
+ }
+ }
+ }
+ });
}
Window(GraphicsConfiguration gc)
// The currently-focused Component belongs to the active Window.
if (activeWindow == this)
return manager.getFocusOwner ();
+ else
+ return windowFocusOwner;
+ }
- return null;
+ /**
+ * Set the focus owner for this window. This method is used to
+ * remember which component was focused when this window lost
+ * top-level focus, so that when it regains top-level focus the same
+ * child component can be refocused.
+ *
+ * @param windowFocusOwner the component in this window that owns
+ * the focus.
+ */
+ void setFocusOwner (Component windowFocusOwner)
+ {
+ this.windowFocusOwner = windowFocusOwner;
}
/**
*/
public boolean postEvent(Event e)
{
- // FIXME
- return false;
+ return handleEvent (e);
}
/**
import java.awt.color.ColorSpace;
import java.util.Hashtable;
import java.util.Vector;
+import java.util.HashSet;
+import java.util.Iterator;
import gnu.java.awt.ComponentDataBlitOp;
/**
public ImageProducer getSource()
{
- throw new UnsupportedOperationException("not implemented");
+ return new ImageProducer() {
+
+ HashSet consumers = new HashSet();
+
+ public void addConsumer(ImageConsumer ic)
+ {
+ consumers.add(ic);
+ }
+
+ public boolean isConsumer(ImageConsumer ic)
+ {
+ return consumers.contains(ic);
+ }
+
+ public void removeConsumer(ImageConsumer ic)
+ {
+ consumers.remove(ic);
+ }
+
+ public void startProduction(ImageConsumer ic)
+ {
+ int x = 0;
+ int y = 0;
+ int width = getWidth();
+ int height = getHeight();
+ int stride = width;
+ int offset = 0;
+ int[] pixels = getRGB(x, y,
+ width, height,
+ (int[])null, offset, stride);
+ ColorModel model = getColorModel();
+
+ consumers.add(ic);
+
+ Iterator i = consumers.iterator();
+ while(i.hasNext())
+ {
+ ImageConsumer c = (ImageConsumer) i.next();
+ c.setHints(ImageConsumer.SINGLEPASS);
+ c.setDimensions(getWidth(), getHeight());
+ c.setPixels(x, y, width, height, model, pixels, offset, stride);
+ c.imageComplete(ImageConsumer.STATICIMAGEDONE);
+ }
+ }
+
+ public void requestTopDownLeftRightResend(ImageConsumer ic)
+ {
+ startProduction(ic);
+ }
+
+ };
}
public Vector getSources()
--- /dev/null
+/* ByteLookupTable.java -- Java class for a pixel translation table.
+ 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 java.awt.image;
+
+/**
+ * ByteLookupTable represents translation arrays for pixel values. It wraps
+ * one or more data arrays for each layer (or component) in an image, such as
+ * Alpha, R, G, and B. When doing translation, the offset is subtracted from
+ * the pixel values to allow a subset of an array to be used.
+ *
+ * @author <a href="mailto:jlquinn@optonline.net">Jerry Quinn</a>
+ * @version 1.0
+ */
+public class ByteLookupTable extends LookupTable
+{
+ // Array of translation tables.
+ private byte data[][];
+
+ /**
+ * Creates a new <code>ByteLookupTable</code> instance.
+ *
+ * Offset is subtracted from pixel values when looking up in the translation
+ * tables. If data.length is one, the same table is applied to all pixel
+ * components.
+ *
+ * @param offset Offset to be subtracted.
+ * @param data Array of lookup tables.
+ * @exception IllegalArgumentException if offset < 0 or data.length < 1.
+ */
+ public ByteLookupTable(int offset, byte[][] data)
+ throws IllegalArgumentException
+ {
+ super(offset, data.length);
+ this.data = data;
+ }
+
+ /**
+ * Creates a new <code>ByteLookupTable</code> instance.
+ *
+ * Offset is subtracted from pixel values when looking up in the translation
+ * table. The same table is applied to all pixel components.
+ *
+ * @param offset Offset to be subtracted.
+ * @param data Lookup table for all components.
+ * @exception IllegalArgumentException if offset < 0.
+ */
+ public ByteLookupTable(int offset, byte[] data)
+ throws IllegalArgumentException
+ {
+ super(offset, 1);
+ this.data = new byte[][] {data};
+ }
+
+ /** Return the lookup tables. */
+ public final byte[][] getTable()
+ {
+ return data;
+ }
+
+ /**
+ * Return translated values for a pixel.
+ *
+ * For each value in the pixel src, use the value minus offset as an index
+ * in the component array and copy the value there to the output for the
+ * component. If dest is null, the output is a new array, otherwise the
+ * translated values are written to dest. Dest can be the same array as
+ * src.
+ *
+ * For example, if the pixel src is [2, 4, 3], and offset is 1, the output
+ * is [comp1[1], comp2[3], comp3[2]], where comp1, comp2, and comp3 are the
+ * translation arrays.
+ *
+ * @param src Component values of a pixel.
+ * @param dest Destination array for values, or null.
+ * @return Translated values for the pixel.
+ */
+ public int[] lookupPixel(int[] src, int[] dst)
+ throws ArrayIndexOutOfBoundsException
+ {
+ if (dst == null)
+ dst = new int[numComponents];
+
+ if (data.length == 1)
+ for (int i=0; i < src.length; i++)
+ dst[i] = data[0][src[i] - offset];
+ else
+ for (int i=0; i < src.length; i++)
+ dst[i] = data[i][src[i] - offset];
+
+ return dst;
+ }
+
+ /**
+ * Return translated values for a pixel.
+ *
+ * For each value in the pixel src, use the value minus offset as an index
+ * in the component array and copy the value there to the output for the
+ * component. If dest is null, the output is a new array, otherwise the
+ * translated values are written to dest. Dest can be the same array as
+ * src.
+ *
+ * For example, if the pixel src is [2, 4, 3], and offset is 1, the output
+ * is [comp1[1], comp2[3], comp3[2]], where comp1, comp2, and comp3 are the
+ * translation arrays.
+ *
+ * @param src Component values of a pixel.
+ * @param dest Destination array for values, or null.
+ * @return Translated values for the pixel.
+ */
+ public byte[] lookupPixel(byte[] src, byte[] dst)
+ throws ArrayIndexOutOfBoundsException
+ {
+ if (dst == null)
+ dst = new byte[numComponents];
+
+ if (data.length == 1)
+ for (int i=0; i < src.length; i++)
+ dst[i] = data[0][((int)src[i]) - offset];
+ else
+ for (int i=0; i < src.length; i++)
+ dst[i] = data[i][((int)src[i]) - offset];
+
+ return dst;
+
+ }
+}
package java.awt.image;
+import java.util.Arrays;
import java.awt.Point;
import java.awt.Transparency;
import java.awt.color.ColorSpace;
(transferType == o.transferType) &&
(transparency == o.transparency) &&
(hasAlpha == o.hasAlpha) &&
- (isAlphaPremultiplied == isAlphaPremultiplied) &&
- (bits.equals(o.bits)) &&
+ (isAlphaPremultiplied == o.isAlphaPremultiplied) &&
+ Arrays.equals(bits, o.bits) &&
(cspace.equals(o.cspace));
}
--- /dev/null
+/* Kernel.java -- Java class for an image processing kernel
+ 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 java.awt.image;
+
+/**
+ * Kernel represents an image processing kernel. It gets used to hold
+ * convolution filters among other purposes. It stores an array of float
+ * values representing a 2-dimensional array in row-major order.
+ *
+ * @author <a href="mailto:jlquinn@optonline.net">Jerry Quinn</a>
+ * @version 1.0
+ */
+public class Kernel implements Cloneable
+{
+ private final int width;
+ private final int height;
+ private final float[] data;
+
+ /**
+ * Creates a new <code>Kernel</code> instance.
+ *
+ * @param width The 2D width of data.
+ * @param height The 2D height of data.
+ * @param data The source data array.
+ * @exception IllegalArgumentException if width * height < data.length.
+ */
+ public Kernel(int width, int height, float[] data)
+ throws IllegalArgumentException
+ {
+ this.width = width;
+ this.height = height;
+ if (data.length < width * height || width < 0 || height < 0)
+ throw new IllegalArgumentException();
+ this.data = new float[width * height];
+ System.arraycopy(data, 0, this.data, 0, width * height);
+ }
+
+ /**
+ * Return the X origin: (width - 1) / 2
+ */
+ public final int getXOrigin()
+ {
+ return (width - 1) / 2;
+ }
+
+ /**
+ * Return the Y origin: (height - 1) / 2
+ */
+ public final int getYOrigin()
+ {
+ return (height - 1) / 2;
+ }
+
+ /**
+ * @return The kernel width.
+ */
+ public final int getWidth()
+ {
+ return width;
+ }
+
+ /**
+ * @return The kernel height.
+ */
+ public final int getHeight()
+ {
+ return height;
+ }
+
+ /**
+ * Return the kernel data.
+ *
+ * If data is null, allocates a new array and returns it. Otherwise, the
+ * kernel values are copied into data.
+ *
+ * @param data Array to copy values into, or null.
+ * @return The array with copied values.
+ * @exception IllegalArgumentException if data != null and too small.
+ */
+ public final float[] getKernelData(float[] data)
+ throws IllegalArgumentException
+ {
+ if (data == null)
+ return (float[])this.data.clone();
+
+ if (data.length < this.data.length)
+ throw new IllegalArgumentException();
+
+ System.arraycopy(this.data, 0, data, 0, this.data.length);
+ return data;
+ }
+
+ /**
+ * @return a clone of this Kernel.
+ */
+ public Object clone()
+ {
+ return new Kernel(width, height, data);
+ }
+}
--- /dev/null
+/* LookupTable.java -- Java class for a pixel translation table.
+ 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 java.awt.image;
+
+/**
+ * LookupTable represents translation arrays for pixel values. It wraps one
+ * or more data arrays for each layer (or component) in an image, such as
+ * Alpha, R, G, and B. When doing translation, the offset is subtracted from
+ * the pixel values to allow a subset of an array to be used.
+ *
+ * @see ByteLookupTable
+ * @see ShortLookupTable
+ *
+ * @author <a href="mailto:jlquinn@optonline.net">Jerry Quinn</a>
+ * @version 1.0
+ */
+public abstract class LookupTable
+{
+ // Not protected since that's part of the public API.
+ int offset;
+ int numComponents;
+
+ /**
+ * Creates a new <code>LookupTable</code> instance.
+ *
+ * If numComponents is 1, the same translation table is used for all pixel
+ * components.
+ *
+ * @param offset Offset to be subtracted.
+ * @param numComponents Number of image components.
+ * @exception IllegalArgumentException if offset < 0 or numComponents < 1.
+ */
+ protected LookupTable(int offset, int numComponents)
+ throws IllegalArgumentException
+ {
+ if (offset < 0 || numComponents < 1)
+ throw new IllegalArgumentException();
+ this.offset = offset;
+ this.numComponents = numComponents;
+ }
+
+ /** Return the number of components. */
+ public int getNumComponents()
+ {
+ return numComponents;
+ }
+
+ /** Return the offset. */
+ public int getOffset()
+ {
+ return offset;
+ }
+
+
+ /**
+ * Return translated values for a pixel.
+ *
+ * For each value in the pixel src, use the value minus offset as an index
+ * in the component array and copy the value there to the output for the
+ * component. If dest is null, the output is a new array, otherwise the
+ * translated values are written to dest. Dest can be the same array as
+ * src.
+ *
+ * For example, if the pixel src is [2, 4, 3], and offset is 1, the output
+ * is [comp1[1], comp2[3], comp3[2]], where comp1, comp2, and comp3 are the
+ * translation arrays.
+ *
+ * @param src Component values of a pixel.
+ * @param dest Destination array for values, or null.
+ * @return Translated values for the pixel.
+ */
+ public abstract int[] lookupPixel(int[] src, int[] dest);
+}
import java.awt.Image;
import java.util.Enumeration;
import java.util.Hashtable;
+import java.util.Vector;
public class MemoryImageSource implements ImageProducer
{
private int pixeli[], width, height, offset, scansize;
private byte pixelb[];
private ColorModel cm;
- private Hashtable props, consumers = new Hashtable();
+ private Hashtable props = new Hashtable();
+ private Vector consumers = new Vector();
/**
Constructs an ImageProducer from memory
* <code>ImageProducer</code>.
*/
public synchronized void addConsumer(ImageConsumer ic) {
- if (consumers.containsKey(ic))
+ if (consumers.contains(ic))
return;
- consumers.put(ic, ic);
+ consumers.addElement(ic);
}
/**
* already registered with this <code>ImageProducer</code>.
*/
public synchronized boolean isConsumer(ImageConsumer ic) {
- if (consumers.containsKey(ic))
+ if (consumers.contains(ic))
return true;
return false;
}
* registered consumers for this <code>ImageProducer</code>.
*/
public synchronized void removeConsumer(ImageConsumer ic) {
- consumers.remove(ic);
+ consumers.removeElement(ic);
}
/**
* registered consumers.
*/
public void startProduction(ImageConsumer ic) {
- if (!(consumers.containsKey(ic))) {
- consumers.put(ic, ic);
+ if (!(consumers.contains(ic))) {
+ consumers.addElement(ic);
}
- Enumeration e = consumers.elements();
- for( ; e.hasMoreElements(); ) {
- ic = (ImageConsumer)e.nextElement();
+
+ Vector list = (Vector) consumers.clone();
+ for(int i = 0; i < list.size(); i++) {
+ ic = (ImageConsumer) list.elementAt(i);
sendPicture( ic );
- ic.imageComplete( ImageConsumer.SINGLEFRAME );
+ ic.imageComplete( ImageConsumer.STATICIMAGEDONE );
}
-
}
/**
{
if( animated == true ) {
ImageConsumer ic;
- Enumeration e = consumers.elements();
- for( ; e.hasMoreElements(); ) {
- ic = (ImageConsumer)e.nextElement();
+ Vector list = (Vector) consumers.clone();
+ for(int i = 0; i < list.size(); i++) {
+ ic = (ImageConsumer) list.elementAt(i);
sendPicture( ic );
ic.imageComplete( ImageConsumer.SINGLEFRAME );
}
ic.setProperties( props );
}
ic.setDimensions(width, height);
+ ic.setColorModel(cm);
if( pixeli != null ) {
ic.setPixels( 0, 0, width, height, cm, pixeli, offset, scansize );
} else {
newPixels();
} else {
ImageConsumer ic;
- Enumeration e = consumers.elements();
- for( ; e.hasMoreElements(); ) {
- ic = (ImageConsumer)e.nextElement();
+ Vector list = (Vector) consumers.clone();
+ for(int i = 0; i < list.size(); i++) {
+ ic = (ImageConsumer) list.elementAt(i);
ic.setHints( ImageConsumer.TOPDOWNLEFTRIGHT );
if( props != null ) {
ic.setProperties( props );
newPixels();
} else {
ImageConsumer ic;
- Enumeration e = consumers.elements();
- for( ; e.hasMoreElements(); ) {
- ic = (ImageConsumer)e.nextElement();
+ Vector list = (Vector) consumers.clone();
+ for(int i = 0; i < list.size(); i++) {
+ ic = (ImageConsumer) list.elementAt(i);
ic.setHints( ImageConsumer.TOPDOWNLEFTRIGHT );
if( props != null ) {
ic.setProperties( props );
if( ( model instanceof IndexColorModel) && canFilterIndexColorModel ) {
newmodel = filterIndexColorModel( (IndexColorModel) model );
+ consumer.setColorModel(newmodel);
+ }
+ else {
+ consumer.setColorModel(ColorModel.getRGBdefault());
}
}
--- /dev/null
+/* ShortLookupTable.java -- Java class for a pixel translation table.
+ 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 java.awt.image;
+
+/**
+ * ShortLookupTable represents translation arrays for pixel values. It wraps
+ * one or more data arrays for each layer (or component) in an image, such as
+ * Alpha, R, G, and B. When doing translation, the offset is subtracted from
+ * the pixel values to allow a subset of an array to be used.
+ *
+ * @author <a href="mailto:jlquinn@optonline.net">Jerry Quinn</a>
+ * @version 1.0
+ */
+public class ShortLookupTable extends LookupTable
+{
+ // Array of translation tables.
+ private short data[][];
+
+ /**
+ * Creates a new <code>ShortLookupTable</code> instance.
+ *
+ * Offset is subtracted from pixel values when looking up in the translation
+ * tables. If data.length is one, the same table is applied to all pixel
+ * components.
+ *
+ * @param offset Offset to be subtracted.
+ * @param data Array of lookup tables.
+ * @exception IllegalArgumentException if offset < 0 or data.length < 1.
+ */
+ public ShortLookupTable(int offset, short[][] data)
+ throws IllegalArgumentException
+ {
+ super(offset, data.length);
+ this.data = data;
+ }
+
+ /**
+ * Creates a new <code>ShortLookupTable</code> instance.
+ *
+ * Offset is subtracted from pixel values when looking up in the translation
+ * table. The same table is applied to all pixel components.
+ *
+ * @param offset Offset to be subtracted.
+ * @param data Lookup table for all components.
+ * @exception IllegalArgumentException if offset < 0.
+ */
+ public ShortLookupTable(int offset, short[] data)
+ throws IllegalArgumentException
+ {
+ super(offset, 1);
+ this.data = new short[][] {data};
+ }
+
+ /** Return the lookup tables. */
+ public final short[][] getTable()
+ {
+ return data;
+ }
+
+ /**
+ * Return translated values for a pixel.
+ *
+ * For each value in the pixel src, use the value minus offset as an index
+ * in the component array and copy the value there to the output for the
+ * component. If dest is null, the output is a new array, otherwise the
+ * translated values are written to dest. Dest can be the same array as
+ * src.
+ *
+ * For example, if the pixel src is [2, 4, 3], and offset is 1, the output
+ * is [comp1[1], comp2[3], comp3[2]], where comp1, comp2, and comp3 are the
+ * translation arrays.
+ *
+ * @param src Component values of a pixel.
+ * @param dest Destination array for values, or null.
+ * @return Translated values for the pixel.
+ */
+ public int[] lookupPixel(int[] src, int[] dst)
+ throws ArrayIndexOutOfBoundsException
+ {
+ if (dst == null)
+ dst = new int[numComponents];
+
+ if (data.length == 1)
+ for (int i=0; i < src.length; i++)
+ dst[i] = data[0][src[i] - offset];
+ else
+ for (int i=0; i < src.length; i++)
+ dst[i] = data[i][src[i] - offset];
+
+ return dst;
+ }
+
+ /**
+ * Return translated values for a pixel.
+ *
+ * For each value in the pixel src, use the value minus offset as an index
+ * in the component array and copy the value there to the output for the
+ * component. If dest is null, the output is a new array, otherwise the
+ * translated values are written to dest. Dest can be the same array as
+ * src.
+ *
+ * For example, if the pixel src is [2, 4, 3], and offset is 1, the output
+ * is [comp1[1], comp2[3], comp3[2]], where comp1, comp2, and comp3 are the
+ * translation arrays.
+ *
+ * @param src Component values of a pixel.
+ * @param dest Destination array for values, or null.
+ * @return Translated values for the pixel.
+ */
+ public short[] lookupPixel(short[] src, short[] dst)
+ throws ArrayIndexOutOfBoundsException
+ {
+ if (dst == null)
+ dst = new short[numComponents];
+
+ if (data.length == 1)
+ for (int i=0; i < src.length; i++)
+ dst[i] = data[0][((int)src[i]) - offset];
+ else
+ for (int i=0; i < src.length; i++)
+ dst[i] = data[i][((int)src[i]) - offset];
+
+ return dst;
+
+ }
+}
Icon pressed_icon;
/** The icon displayed when the button is disabled. */
- Icon disabled_icon;
+ Icon disabeldIcon;
/** The icon displayed when the button is selected. */
- Icon selected_icon;
+ Icon selectedIcon;
/** The icon displayed when the button is selected but disabled. */
- Icon disabled_selected_icon;
+ Icon disabledSelectedIcon;
/** The icon displayed when the button is rolled over. */
- Icon rollover_icon;
+ Icon rolloverIcon;
/** The icon displayed when the button is selected and rolled over. */
- Icon rollover_selected_icon;
+ Icon rolloverSelectedIcon;
/** The icon currently displayed. */
Icon current_icon;
/** The text displayed in the button. */
String text;
+ /** The gap between icon and text, if both icon and text are non-<code>null</code>. */
+ int iconTextGap;
+
/** The vertical alignment of the button's text and icon. */
- int vert_align;
+ int verticalAlignment;
/** The horizontal alignment of the button's text and icon. */
- int hori_align;
+ int horizontalAlignment;
/** The horizontal position of the button's text relative to its icon. */
- int hori_text_pos;
+ int horizontalTextPosition;
/** The vertical position of the button's text relative to its icon. */
- int vert_text_pos;
+ int verticalTextPosition;
/** Whether or not the button paints its border. */
- boolean paint_border;
+ boolean borderPainted;
/** Whether or not the button paints its focus state. */
- boolean paint_focus;
+ boolean focusPainted;
/** Whether or not the button fills its content area. */
- boolean content_area_filled;
+ boolean contentAreaFilled;
+
+ /** Whether rollover is enabled. */
+ boolean rollOverEnabled;
/** The action taken when the button is clicked. */
Action action;
Action. */
PropertyChangeListener actionPropertyChangeListener;
+ /** ChangeEvent that is fired to button's ChangeEventListeners */
+ private ChangeEvent changeEvent = new ChangeEvent(this);
+
/** Fired in a PropertyChangeEvent when the "borderPainted" property changes. */
public static final String BORDER_PAINTED_CHANGED_PROPERTY = "borderPainted";
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;
+ horizontalAlignment = CENTER;
+ horizontalTextPosition = TRAILING;
+ verticalAlignment = CENTER;
+ verticalTextPosition = CENTER;
+ borderPainted = true;
+ contentAreaFilled = true;
+
+ iconTextGap = 4;
setAlignmentX(LEFT_ALIGNMENT);
setAlignmentY(CENTER_ALIGNMENT);
addFocusListener(new ButtonFocusListener());
+ setDisplayedMnemonicIndex(-1);
}
/**
*/
public void fireItemStateChanged(ItemEvent e)
{
+ e.setSource(this);
EventListener[] ll = listenerList.getListeners(ItemListener.class);
for (int i = 0; i < ll.length; i++)
((ItemListener)ll[i]).itemStateChanged(e);
*/
public void fireActionPerformed(ActionEvent e)
{
+ e.setSource(this);
EventListener[] ll = listenerList.getListeners(ActionListener.class);
for (int i = 0; i < ll.length; i++)
((ActionListener)ll[i]).actionPerformed(e);
{
EventListener[] ll = listenerList.getListeners(ChangeListener.class);
for (int i = 0; i < ll.length; i++)
- ((ChangeListener)ll[i]).stateChanged(e);
+ ((ChangeListener)ll[i]).stateChanged(changeEvent);
}
/**
*/
public void setMnemonic(char mne)
{
- int old = getModel().getMnemonic();
- getModel().setMnemonic(mne);
- if (old != getModel().getMnemonic())
- {
- firePropertyChange(MNEMONIC_CHANGED_PROPERTY, old, (int) mne);
- revalidate();
- repaint();
- }
+ setMnemonic((int) mne);
}
/**
*/
public void setMnemonic(int mne)
{
- int old = mne;
+ int old = getModel().getMnemonic();
+
+ if (old != mne)
+ {
getModel().setMnemonic(mne);
- if (old != getModel().getMnemonic())
+
+ if (text != null && ! text.equals(""))
{
+ // Since lower case char = upper case char for
+ // mnemonic, we will convert both text and mnemonic
+ // to upper case before checking if mnemonic character occurs
+ // in the menu item text.
+ int upperCaseMne = Character.toUpperCase((char) mne);
+ String upperCaseText = text.toUpperCase();
+ setDisplayedMnemonicIndex(upperCaseText.indexOf(upperCaseMne));
+ }
+
firePropertyChange(MNEMONIC_CHANGED_PROPERTY, old, mne);
revalidate();
repaint();
public void setDisplayedMnemonicIndex(int index)
{
- if (index < -1 || index >= text.length())
+ if (index < -1 || (text != null && index >= text.length()))
throw new IllegalArgumentException();
else
mnemonicIndex = index;
*
* @return An index into the button's "text" property
*/
- public int getDisplayedMnemonicIndex(int index)
+ public int getDisplayedMnemonicIndex()
{
return mnemonicIndex;
}
/**
* Set the "rolloverEnabled" property. When rollover is enabled, and the
* look and feel supports it, the button will change its icon to
- * rollover_icon, when the mouse passes over it.
+ * rolloverIcon, when the mouse passes over it.
*
* @param r Whether or not to enable rollover icon changes
*/
public void setRolloverEnabled(boolean r)
{
- boolean old = getModel().isRollover();
- getModel().setRollover(r);
- if (old != getModel().isRollover())
+ if (rollOverEnabled != r)
{
- firePropertyChange(ROLLOVER_ENABLED_CHANGED_PROPERTY, old, r);
+ rollOverEnabled = r;
+ firePropertyChange(ROLLOVER_ENABLED_CHANGED_PROPERTY, !r, r);
revalidate();
repaint();
}
*/
public boolean isRolloverEnabled()
{
- return getModel().isRollover();
+ return rollOverEnabled;
}
/**
*/
public int getHorizontalAlignment()
{
- return hori_align;
+ return horizontalAlignment;
}
/**
*/
public void setHorizontalAlignment(int a)
{
- int old = hori_align;
- hori_align = a;
+ int old = horizontalAlignment;
+ horizontalAlignment = a;
if (old != a)
{
firePropertyChange(HORIZONTAL_ALIGNMENT_CHANGED_PROPERTY, old, a);
*/
public int getHorizontalTextPosition()
{
- return hori_text_pos;
+ return horizontalTextPosition;
}
/**
*/
public void setHorizontalTextPosition(int t)
{
- int old = hori_text_pos;
- hori_text_pos = t;
+ int old = horizontalTextPosition;
+ horizontalTextPosition = t;
if (old != t)
{
firePropertyChange(HORIZONTAL_TEXT_POSITION_CHANGED_PROPERTY, old, t);
*/
public int getVerticalAlignment()
{
- return vert_align;
+ return verticalAlignment;
}
/**
*/
public void setVerticalAlignment(int a)
{
- int old = vert_align;
- vert_align = a;
+ int old = verticalAlignment;
+ verticalAlignment = a;
if (old != a)
{
firePropertyChange(VERTICAL_ALIGNMENT_CHANGED_PROPERTY, old, a);
*/
public int getVerticalTextPosition()
{
- return vert_text_pos;
+ return verticalTextPosition;
}
/**
*/
public void setVerticalTextPosition(int t)
{
- int old = vert_text_pos;
- vert_text_pos = t;
+ int old = verticalTextPosition;
+ verticalTextPosition = t;
if (old != t)
{
firePropertyChange(VERTICAL_TEXT_POSITION_CHANGED_PROPERTY, old, t);
*/
public boolean isBorderPainted()
{
- return paint_border;
+ return borderPainted;
}
/**
*/
public void setBorderPainted(boolean b)
{
- boolean old = paint_border;
- paint_border = b;
+ boolean old = borderPainted;
+ borderPainted = b;
if (b != old)
{
firePropertyChange(BORDER_PAINTED_CHANGED_PROPERTY, old, b);
}
}
+ /**
+ * Set the value of the {@link #iconTextGap} property.
+ *
+ * @param i The new value of the property
+ */
+ public void setIconTextGap(int i)
+ {
+ int old = iconTextGap;
+ iconTextGap = i;
+ if (old != i)
+ {
+ fireStateChanged(new ChangeEvent(this));
+ revalidate();
+ repaint();
+ }
+ }
+
+ /**
+ * Get the value of the {@link #iconTextGap} property.
+ *
+ * @return The current value of the property
+ */
+ public int getIconTextGap()
+ {
+ return iconTextGap;
+ }
+
/**
* Return the button's "margin" property, which is an {@link Insets} object
* describing the distance between the button's border and its text and
*/
public Icon getDisabledIcon()
{
- if (disabled_icon == null
+ if (disabeldIcon == null
&& default_icon instanceof ImageIcon)
- disabled_icon = new ImageIcon(GrayFilter.createDisabledImage(((ImageIcon) default_icon).getImage()));
+ disabeldIcon = new ImageIcon(GrayFilter.createDisabledImage(((ImageIcon) default_icon).getImage()));
- return disabled_icon;
+ return disabeldIcon;
}
/**
*
* @param disabledIcon The new "disabledIcon" property
*/
- public void setDisabledIcon(Icon disabledIcon)
+ public void setDisabledIcon(Icon d)
{
- disabled_icon = disabledIcon;
+ disabeldIcon = d;
revalidate();
repaint();
}
*/
public boolean isFocusPainted()
{
- return paint_focus;
+ return focusPainted;
}
/**
*
* @param b The new "paintFocus" property
*/
- public void setFocusPainted(boolean b)
+ public void setFocusPainted(boolean p)
{
- boolean old = paint_focus;
- paint_focus = b;
+ boolean old = focusPainted;
+ focusPainted = p;
- if (old != b)
+ if (old != focusPainted)
{
- firePropertyChange(FOCUS_PAINTED_CHANGED_PROPERTY, old, b);
+ firePropertyChange(FOCUS_PAINTED_CHANGED_PROPERTY, old, p);
revalidate();
repaint();
}
setToolTipText((String)(a.getValue(Action.SHORT_DESCRIPTION)));
if (a.getValue(Action.MNEMONIC_KEY) != null)
setMnemonic(((Integer)(a.getValue(Action.MNEMONIC_KEY))).intValue());
+ String actionCommand = (String)(a.getValue(Action.ACTION_COMMAND_KEY));
+
+ // Set actionCommand to button's text by default if it is not specified
+ if (actionCommand != null)
setActionCommand((String)(a.getValue(Action.ACTION_COMMAND_KEY)));
+ else
+ setActionCommand(getText());
}
}
{
public void actionPerformed(ActionEvent e)
{
- e.setSource(AbstractButton.this);
AbstractButton.this.fireActionPerformed(e);
}
};
public void stateChanged(ChangeEvent e)
{
AbstractButton.this.fireStateChanged(e);
- AbstractButton.this.revalidate();
AbstractButton.this.repaint();
}
};
*/
public Icon getDisabledSelectedIcon()
{
- return disabled_selected_icon;
+ return disabledSelectedIcon;
}
/**
*/
public void setDisabledSelectedIcon(Icon disabledSelectedIcon)
{
- Icon old = disabled_selected_icon;
- disabled_selected_icon = disabledSelectedIcon;
+ Icon old = disabledSelectedIcon;
+ disabledSelectedIcon = disabledSelectedIcon;
if (old != disabledSelectedIcon)
{
firePropertyChange(DISABLED_SELECTED_ICON_CHANGED_PROPERTY, old,
*/
public Icon getRolloverIcon()
{
- return rollover_icon;
+ return rolloverIcon;
}
/**
*
* @param rolloverIcon The new rollover icon
*/
- public void setRolloverIcon(Icon rolloverIcon)
+ public void setRolloverIcon(Icon r)
{
- Icon old = rollover_icon;
- rollover_icon = rolloverIcon;
+ Icon old = rolloverIcon;
+ rolloverIcon = r;
if (old != rolloverIcon)
{
firePropertyChange(ROLLOVER_ICON_CHANGED_PROPERTY, old,
*/
public Icon getRolloverSelectedIcon()
{
- return rollover_selected_icon;
+ return rolloverSelectedIcon;
}
/**
*
* @param rolloverSelectedIcon The new rollover selected icon
*/
- public void setRolloverSelectedIcon(Icon rolloverSelectedIcon)
+ public void setRolloverSelectedIcon(Icon r)
{
- Icon old = rollover_selected_icon;
- rollover_selected_icon = rolloverSelectedIcon;
+ Icon old = rolloverSelectedIcon;
+ rolloverSelectedIcon = r;
if (old != rolloverSelectedIcon)
{
firePropertyChange(ROLLOVER_SELECTED_ICON_CHANGED_PROPERTY, old,
*/
public Icon getSelectedIcon()
{
- return selected_icon;
+ return selectedIcon;
}
/**
*
* @param selectedIcon The new selected icon
*/
- public void setSelectedIcon(Icon selectedIcon)
+ public void setSelectedIcon(Icon s)
{
- Icon old = selected_icon;
- selected_icon = selectedIcon;
+ Icon old = selectedIcon;
+ selectedIcon = s;
if (old != selectedIcon)
{
firePropertyChange(SELECTED_ICON_CHANGED_PROPERTY, old,
*/
public boolean isContentAreaFilled()
{
- return content_area_filled;
+ return contentAreaFilled;
}
/**
*/
public void setContentAreaFilled(boolean b)
{
- boolean old = content_area_filled;
- content_area_filled = b;
+ boolean old = contentAreaFilled;
+ contentAreaFilled = b;
if (b != old)
{
firePropertyChange(CONTENT_AREA_FILLED_CHANGED_PROPERTY, old, b);
import java.util.Map;
import java.util.Set;
+
/**
- * ActionMap
* @author Andrew Selkirk
- * @version 1.0
+ * @author Michael Koch
*/
-public class ActionMap implements Serializable
+public class ActionMap
+ implements Serializable
{
- static final long serialVersionUID = -6277518704513986346L;
-
- //-------------------------------------------------------------
- // Variables --------------------------------------------------
- //-------------------------------------------------------------
+ private static final long serialVersionUID = -6277518704513986346L;
/**
* actionMap
/**
* parent
*/
- private ActionMap parent = null;
-
-
- //-------------------------------------------------------------
- // Initialization ---------------------------------------------
- //-------------------------------------------------------------
+ private ActionMap parent;
/**
- * Constructor ActionMap
+ * Creates a new <code>ActionMap</code> instance.
*/
- public ActionMap() {
- } // ActionMap()
-
-
- //-------------------------------------------------------------
- // Methods ----------------------------------------------------
- //-------------------------------------------------------------
+ public ActionMap()
+ {
+ }
/**
- * get
- * @param key TODO
- * @returns Action
+ * Returns an action associated with an object.
+ *
+ * @param key the key of the enty
+ *
+ * @return the action associated with key, may be null
*/
- public Action get(Object key) {
+ public Action get(Object key)
+ {
+ Object result = actionMap.get(key);
- // Variables
- Object result;
-
- // Check Local store
- result = actionMap.get(key);
-
- // Check Parent
- if (result == null) {
+ if (result == null)
result = parent.get(key);
- } // if
return (Action) result;
-
- } // get()
+ }
/**
- * put
- * @param key TODO
- * @param action TODO
+ * Puts a new <code>Action</code> into the <code>ActionMap</code>.
+ * If action is null an existing entry will be removed.
+ *
+ * @param key the key for the entry
+ * @param action the action.
*/
- public void put(Object key, Action action) {
- if (action == null) {
+ public void put(Object key, Action action)
+ {
+ if (action == null)
actionMap.remove(key);
- } else {
+ else
actionMap.put(key, action);
- } // if
- } // put()
+ }
/**
- * remove
- * @param key TODO
+ * Remove an entry from the <code>ActionMap</code>.
+ *
+ * @param key the key of the entry to remove
*/
- public void remove(Object key) {
+ public void remove(Object key)
+ {
actionMap.remove(key);
- } // remove()
+ }
/**
- * getParent
- * @returns ActionMap
+ * Returns the parent of this <code>ActionMap</code>.
+ *
+ * @return the parent, may be null.
*/
- public ActionMap getParent() {
+ public ActionMap getParent()
+ {
return parent;
- } // getParent()
+ }
/**
- * setParent
- * @param parentMap TODO
+ * Sets a parent for this <code>ActionMap</code>.
+ *
+ * @param parentMap the new parent
*/
- public void setParent(ActionMap parentMap) {
+ public void setParent(ActionMap parentMap)
+ {
parent = parentMap;
- } // setParent()
+ }
/**
- * size
- * @returns int
+ * Returns the number of entries in this <code>ActionMap</code>.
+ *
+ * @return the number of entries
*/
- public int size() {
+ public int size()
+ {
return actionMap.size();
- } // size()
+ }
/**
- * clear
+ * Clears the <code>ActionMap</code>.
*/
- public void clear() {
+ public void clear()
+ {
actionMap.clear();
- } // clear()
+ }
/**
- * keys
- * @returns Object[]
+ * Returns all keys of entries in this <code>ActionMap</code>.
+ *
+ * @return an array of keys
*/
- public Object[] keys() {
- return convertSet(actionMap.keySet());
- } // keys()
+ public Object[] keys()
+ {
+ return actionMap.keySet().toArray();
+ }
/**
- * allKeys
- * @returns Object[]
+ * Returns all keys of entries in this <code>ActionMap</code>
+ * and all its parents.
+ *
+ * @return an array of keys
*/
- public Object[] allKeys() {
-
- // Variables
- Set set;
-
- // Initialize
- set = new HashSet();
+ public Object[] allKeys()
+ {
+ Set set = new HashSet();
- // Get Key Sets
- if (parent != null) {
+ if (parent != null)
set.addAll(Arrays.asList(parent.allKeys()));
- } // if
- set.addAll(actionMap.keySet());
- return convertSet(set);
-
- } // allKeys()
-
- private Object[] convertSet(Set set) {
-
- // Variables
- int index;
- Iterator iterator;
- Object[] keys;
-
- // Create Final array
- keys = new Object[set.size()];
- iterator = set.iterator();
- index = 0;
- while (iterator.hasNext()) {
- keys[index++] = iterator.next();
- } // while
-
- return keys;
-
- } // convertSet()
-
-
- //-------------------------------------------------------------
- // Interface: Serializable ------------------------------------
- //-------------------------------------------------------------
+ set.addAll(actionMap.keySet());
+ return set.toArray();
+ }
/**
* writeObject
- * @param stream TODO
- * @exception IOException TODO
+ *
+ * @param stream the stream to write to
+ *
+ * @exception IOException If an error occurs
*/
- private void writeObject(ObjectOutputStream value0) throws IOException {
+ private void writeObject(ObjectOutputStream stream)
+ throws IOException
+ {
// TODO
- } // writeObject()
+ }
/**
* readObject
- * @param stream TODO
- * @exception ClassNotFoundException TODO
- * @exception IOException TODO
+ *
+ * @param stream the stream to read from
+ *
+ * @exception ClassNotFoundException If the serialized class cannot be found
+ * @exception IOException If an error occurs
*/
- private void readObject(ObjectInputStream value0) throws ClassNotFoundException, IOException {
+ private void readObject(ObjectInputStream stream)
+ throws ClassNotFoundException, IOException
+ {
// TODO
- } // readObject()
-
-
-} // ActionMap
+ }
+}
/* ComponentInputMap.java --
- Copyright (C) 2002 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
package javax.swing;
+
/**
- * ComponentInputMap
* @author Andrew Selkirk
- * @version 1.0
+ * @author Michael Koch
*/
-public class ComponentInputMap extends InputMap {
-
- //-------------------------------------------------------------
- // Variables --------------------------------------------------
- //-------------------------------------------------------------
-
+public class ComponentInputMap extends InputMap
+{
/**
- * component
+ * The component to notify.
*/
private JComponent component;
-
- //-------------------------------------------------------------
- // Initialization ---------------------------------------------
- //-------------------------------------------------------------
-
- /**
- * Constructor ComponentInputMap
- * @param value0 TODO
- */
- public ComponentInputMap(JComponent value0) {
- // TODO
- } // ComponentInputMap()
-
-
- //-------------------------------------------------------------
- // Methods ----------------------------------------------------
- //-------------------------------------------------------------
-
- /**
- * put
- * @param keystroke TODO
- * @param value TODO
- */
- public void put(KeyStroke keystroke, Object value) {
- // TODO
- } // put()
-
/**
- * clear
- */
- public void clear() {
- // TODO
- } // clear()
-
- /**
- * remove
- * @param keystroke TODO
- */
- public void remove(KeyStroke keystroke) {
- // TODO
- } // remove()
-
- /**
- * setParent
- * @param parent TODO
- */
- public void setParent(InputMap parent) {
- // TODO
- } // setParent()
-
- /**
- * getComponent
- * @returns JComponent
- */
- public JComponent getComponent() {
- return null; // TODO
- } // getComponent()
-
-
-} // ComponentInputMap
+ * Creates <code>ComponentInputMap</code> object that notifies the given
+ * component about changes to it.
+ *
+ * @param comp the component to notify
+ *
+ * @exception IllegalArgumentException if comp is null
+ */
+ public ComponentInputMap(JComponent comp)
+ {
+ if (comp == null)
+ throw new IllegalArgumentException();
+
+ this.component = comp;
+ }
+
+ /**
+ * Puts a new entry into the <code>InputMap</code>.
+ * If actionMapKey is null an existing entry will be removed.
+ *
+ * @param keystroke the keystroke for the entry
+ * @param actionMapKey the action.
+ */
+ public void put(KeyStroke keystroke, Object value)
+ {
+ super.put(keystroke, value);
+ // FIXME: Notify component.
+ }
+
+ /**
+ * Clears the <code>InputMap</code>.
+ */
+ public void clear()
+ {
+ super.clear();
+ // FIXME: Notify component.
+ }
+
+ /**
+ * Remove an entry from the <code>InputMap</code>.
+ *
+ * @param key the key of the entry to remove
+ */
+ public void remove(KeyStroke keystroke)
+ {
+ super.remove(keystroke);
+ // FIXME: Notify component.
+ }
+
+ /**
+ * Sets a parent for this <code>ComponentInputMap</code>.
+ *
+ * @param parentMap the new parent
+ *
+ * @exception IllegalArgument if parentMap is not a
+ * <code>ComponentInputMap</code> or not associated with the same component
+ */
+ public void setParent(InputMap parentMap)
+ {
+ if (! (parentMap instanceof ComponentInputMap))
+ throw new IllegalArgumentException();
+
+ if (((ComponentInputMap) parentMap).getComponent() != component)
+ throw new IllegalArgumentException();
+
+ super.setParent(parentMap);
+ // FIXME: Notify component.
+ }
+
+ /**
+ * Returns the component to notify about changes.
+ *
+ * @return a <code>JComponent</code> object
+ */
+ public JComponent getComponent()
+ {
+ return component;
+ }
+}
int newWidth, int newHeight)
{
dragCache.setBounds(newX, newY, newWidth, newHeight);
- dragCache = findMinimum(dragCache, component);
if (currentDragMode == JDesktopPane.OUTLINE_DRAG_MODE)
{
{
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
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
+import java.awt.image.ImageObserver;
import java.io.Serializable;
import java.net.URL;
{
private static final long serialVersionUID = 532615968316031794L;
Image image;
- String file;
- String descr;
- Component observer;
+ String description;
+ ImageObserver observer;
- public ImageIcon(String s)
+ public ImageIcon()
{
- // if description is not specified, then file name becomes
- // desciption for this icon
- this(s, s);
}
- public ImageIcon(Image image)
+ public ImageIcon(String file)
+ {
+ this(file, file);
+ }
+
+ public ImageIcon(String file, String description)
+ {
+ this(Toolkit.getDefaultToolkit().getImage(file), description);
+ }
+
+ public ImageIcon(byte[] imageData)
+ {
+ this(imageData, null);
+ }
+
+ public ImageIcon(byte[] imageData, String description)
{
+ this(Toolkit.getDefaultToolkit().createImage(imageData), description);
}
public ImageIcon(URL url)
{
- image = Toolkit.getDefaultToolkit().getImage(url);
+ this(url, null);
}
- public ImageIcon(String file, String descr)
+ public ImageIcon(URL url, String description)
{
- this.file = file;
- this.descr = descr;
+ this(Toolkit.getDefaultToolkit().getImage(url), description);
+ }
+
+ public ImageIcon(Image image)
+ {
+ this(image, null);
+ }
- image = Toolkit.getDefaultToolkit().getImage(file);
- if (image == null)
- return;
+ public ImageIcon(Image image, String description)
+ {
+ this.image = Toolkit.getDefaultToolkit().createImage(image.getSource());
+ this.description = description;
+ }
- //loadImage(image);
+ public ImageObserver getImageObserver()
+ {
+ return observer;
}
- // not in SUN's spec !!!
- public void setParent(Component p)
+ public void setImageObserver(ImageObserver newObserver)
{
- observer = p;
+ observer = newObserver;
}
public Image getImage()
public String getDescription()
{
- return descr;
+ return description;
}
public void setDescription(String description)
{
- this.descr = description;
+ this.description = description;
}
public int getIconHeight()
public void paintIcon(Component c, Graphics g, int x, int y)
{
- g.drawImage(image, x, y, observer);
+ g.drawImage(image, x, y, observer != null ? observer : c);
}
}
/* InputMap.java --
- Copyright (C) 2002 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
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.IOException;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.Arrays;
-import java.util.Iterator;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.Map;
import java.util.Set;
+
/**
- * InputMap
* @author Andrew Selkirk
- * @version 1.0
+ * @author Michael Koch
+ *
+ * @since 1.3
*/
-public class InputMap implements Serializable
+public class InputMap
+ implements Serializable
{
- static final long serialVersionUID = -5429059542008604257L;
-
- //-------------------------------------------------------------
- // Variables --------------------------------------------------
- //-------------------------------------------------------------
+ private static final long serialVersionUID = -5429059542008604257L;
/**
* inputMap
/**
* parent
*/
- private InputMap parent = null;
-
-
- //-------------------------------------------------------------
- // Initialization ---------------------------------------------
- //-------------------------------------------------------------
+ private InputMap parent;
/**
- * Constructor InputMap
+ * Creates a new <code>InputMap</code> instance.
*/
- public InputMap() {
+ public InputMap()
+ {
// TODO
- } // InputMap()
-
-
- //-------------------------------------------------------------
- // Methods ----------------------------------------------------
- //-------------------------------------------------------------
+ }
/**
- * get
- * @param value0 TODO
- * @returns Object
+ * Returns the binding for keystroke.
+ *
+ * @param key the key of the enty
+ *
+ * @return the binding associated with keystroke may be null
*/
- public Object get(KeyStroke keystroke) {
-
- // Variables
- Object result;
+ public Object get(KeyStroke keystroke)
+ {
+ Object result = inputMap.get(keystroke);
- // Check Local store
- result = inputMap.get(keystroke);
-
- // Check Parent
- if (result == null) {
+ if (result == null)
result = parent.get(keystroke);
- } // if
-
return result;
-
- } // get()
+ }
/**
- * put
- * @param keystroke TODO
- * @param actionMapKey TODO
+ * Puts a new entry into the <code>InputMap</code>.
+ * If actionMapKey is null an existing entry will be removed.
+ *
+ * @param keystroke the keystroke for the entry
+ * @param actionMapKey the action.
*/
- public void put(KeyStroke keystroke, Object actionMapKey) {
- if (actionMapKey == null) {
+ public void put(KeyStroke keystroke, Object actionMapKey)
+ {
+ if (actionMapKey == null)
inputMap.remove(keystroke);
- } else {
+ else
inputMap.put(keystroke, actionMapKey);
- } // if
- } // put()
+ }
/**
- * remove
- * @param keystroke TODO
+ * Remove an entry from the <code>InputMap</code>.
+ *
+ * @param key the key of the entry to remove
*/
- public void remove(KeyStroke keystroke) {
+ public void remove(KeyStroke keystroke)
+ {
inputMap.remove(keystroke);
- } // remove()
+ }
/**
- * getParent
- * @returns InputMap
+ * Returns the parent of this <code>InputMap</code>.
+ *
+ * @return the parent, may be null.
*/
- public InputMap getParent() {
+ public InputMap getParent()
+ {
return parent;
- } // getParent()
+ }
/**
- * setParent
- * @param parentMap TODO
+ * Sets a parent for this <code>InputMap</code>.
+ *
+ * @param parentMap the new parent
*/
- public void setParent(InputMap parentMap) {
+ public void setParent(InputMap parentMap)
+ {
parent = parentMap;
- } // setParent()
+ }
/**
- * size
- * @returns int
+ * Returns the number of entries in this <code>InputMap</code>.
+ *
+ * @return the number of entries
*/
- public int size() {
+ public int size()
+ {
return inputMap.size();
- } // size()
+ }
/**
- * clear
+ * Clears the <code>InputMap</code>.
*/
- public void clear() {
+ public void clear()
+ {
inputMap.clear();
- } // clear()
+ }
/**
- * keys
- * @returns KeyStroke[]
+ * Returns all keys of entries in this <code>InputMap</code>.
+ *
+ * @return an array of keys
*/
- public KeyStroke[] keys() {
- return convertSet(inputMap.keySet());
- } // keys()
+ public KeyStroke[] keys()
+ {
+ KeyStroke[] array = new KeyStroke[size()];
+ return (KeyStroke[]) inputMap.keySet().toArray(array);
+ }
/**
- * allKeys
- * @returns KeyStroke[]
+ * Returns all keys of entries in this <code>InputMap</code>
+ * and all its parents.
+ *
+ * @return an array of keys
*/
- public KeyStroke[] allKeys() {
+ public KeyStroke[] allKeys()
+ {
+ Set set = new HashSet();
- // Variables
- Set set;
-
- // Initialize
- set = new HashSet();
-
- // Get Key Sets
- if (parent != null) {
+ if (parent != null)
set.addAll(Arrays.asList(parent.allKeys()));
- } // if
- set.addAll(inputMap.keySet());
-
- return convertSet(set);
-
- } // allKeys()
-
- private KeyStroke[] convertSet(Set set) {
-
- // Variables
- int index;
- Iterator iterator;
- KeyStroke[] keys;
- // Create Final array
- keys = new KeyStroke[set.size()];
- iterator = set.iterator();
- index = 0;
- while (iterator.hasNext()) {
- keys[index++] = (KeyStroke) iterator.next();
- } // while
-
- return keys;
-
- } // convertSet()
-
-
- //-------------------------------------------------------------
- // Interface: Serializable ------------------------------------
- //-------------------------------------------------------------
+ set.addAll(inputMap.keySet());
+ KeyStroke[] array = new KeyStroke[size()];
+ return (KeyStroke[]) set.toArray(array);
+ }
/**
* writeObject
- * @param stream TODO
- * @exception IOException TODO
+ *
+ * @param stream the stream to write to
+ *
+ * @exception IOException If an error occurs
*/
- private void writeObject(ObjectOutputStream stream) throws IOException {
+ private void writeObject(ObjectOutputStream stream) throws IOException
+ {
// TODO
- } // writeObject()
+ }
/**
* readObject
- * @param stream TODO
- * @exception ClassNotFoundException TODO
- * @exception IOException TODO
+ *
+ * @param stream the stream to read from
+ *
+ * @exception ClassNotFoundException If the serialized class cannot be found
+ * @exception IOException If an error occurs
*/
- private void readObject(ObjectInputStream stream) throws ClassNotFoundException, IOException {
+ private void readObject(ObjectInputStream stream)
+ throws ClassNotFoundException, IOException
+ {
// TODO
- } // readObject()
-
-
-} // InputMap
+ }
+}
import javax.accessibility.AccessibleContext;
import javax.swing.plaf.ButtonUI;
+
/**
* An instance of JButton can be added to a panel, frame etc
*
* @author Ronald Veldema (rveldema@cs.vu.nl)
*/
-public class JButton extends AbstractButton implements Accessible
+public class JButton extends AbstractButton
+ implements Accessible
{
private static final long serialVersionUID = -1907255238954382202L;
-
- boolean def, is_def;
-
+ boolean def;
+ boolean is_def;
public JButton()
{
public String getUIClassID()
{
- //Returns a string that specifies the name of the Look and Feel
- //class that renders this component.
+ //Returns a string that specifies the name of the L&F class that renders this component.
return "ButtonUI";
}
return "JButton";
}
+ /**
+ * Overrides JComponent.removeNotify to check if this button is currently
+ * set as the default button on the RootPane, and if so, sets the RootPane's
+ * default button to null to ensure the RootPane doesn't hold onto an invalid
+ * button reference.
+ */
public void removeNotify()
{
- //Overrides JComponent.removeNotify to check if this button is currently set as the default button on the RootPane, and if so, sets the RootPane's default button to null to ensure the RootPane doesn't hold onto an invalid button reference.
}
public void setDefaultCapable(boolean defaultCapable)
- { def = defaultCapable; }
+ {
+ def = defaultCapable;
+ }
public void updateUI()
{
- ButtonUI b = (ButtonUI)UIManager.getUI(this);
- setUI(b);
+ setUI((ButtonUI) UIManager.getUI(this));
}
}
{
private static final long serialVersionUID = -5246739313864538930L;
+ private boolean borderPaintedFlat;
+
+ private void init()
+ {
+ borderPainted = false;
+ contentAreaFilled = false;
+ }
+
public JCheckBox()
{
- this(null, null);
+ super();
+ init();
}
- public JCheckBox(Action a)
+
+ public JCheckBox(Action action)
{
- this();
- setAction(a);
+ super(action);
+ init();
}
public JCheckBox(Icon icon)
{
- this(null, icon);
+ super(icon);
+ init();
+ }
+
+ public JCheckBox(Icon icon, boolean selected)
+ {
+ super(icon, selected);
+ init();
}
public JCheckBox(String text)
{
- this(text, null);
+ super(text);
+ init();
+ }
+
+ public JCheckBox(String text, boolean selected)
+ {
+ super(text, selected);
+ init();
}
public JCheckBox(String text, Icon icon)
{
super(text, icon);
- paint_border = false;
- content_area_filled = false;
+ init();
}
+ public JCheckBox(String text, Icon icon, boolean selected)
+ {
+ super(text, icon, selected);
+ init();
+ }
+ /**
+ * Gets the AccessibleContext associated with this JCheckBox.
+ */
public AccessibleContext getAccessibleContext()
{
- //Gets the AccessibleContext associated with this JCheckBox.
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 Look and Feel
- //class that renders this component.
return "CheckBoxUI";
}
{
return "JCheckBox";
}
+
+ public boolean isBorderPaintedFlat()
+ {
+ return borderPaintedFlat;
+ }
+
+ public void setBorderPaintedFlat(boolean newValue)
+ {
+ firePropertyChange("borderPaintedFlat", borderPaintedFlat, newValue);
+ borderPaintedFlat = newValue;
+ }
}
/**
- * DOCUMENT ME!
+ * This class represents JCheckBoxMenuItem. Its behaviour is very similar
+ * to JCheckBoxButton. Just like the JCheckBoxButton, user can check and
+ * uncheck this menu item by clicking on it. Also setSelected()/setState()
+ * can be use used for the same purpose. JCheckBoxMenuItem uses
+ * ToggleButtonModel to keep track of its selection.
*/
public class JCheckBoxMenuItem extends JMenuItem implements SwingConstants,
Accessible
{
private static final long serialVersionUID = -6676402307973384715L;
+ /** name for the UI delegate for this menuItem. */
private static final String uiClassID = "CheckBoxMenuItemUI";
+
+ /** Indicates whether this menu item is checked. */
private boolean state;
- private Object[] selectedObjects;
+
+ /**
+ * This array contains text of this menu item if this menu item is in
+ * checked state and null it is not.
+ */
+ private Object[] selectedObjects = new Object[1];
/**
* Creates a new JCheckBoxMenuItem object.
}
/**
- * Creates a new JCheckBoxMenuItem object.
+ * Creates a new JCheckBoxMenuItem with given icon
*
- * @param icon DOCUMENT ME!
+ * @param icon Icon for this menu item
*/
public JCheckBoxMenuItem(Icon icon)
{
}
/**
- * Creates a new JCheckBoxMenuItem object.
+ * Creates a new JCheckBoxMenuItem with given label
*
- * @param text DOCUMENT ME!
+ * @param text Label for this menu item
*/
public JCheckBoxMenuItem(String text)
{
}
/**
- * Creates a new JCheckBoxMenuItem object.
+ * Creates a new JCheckBoxMenuItem using given action
*
- * @param action DOCUMENT ME!
+ * @param action Action for this menu item.
*/
public JCheckBoxMenuItem(Action action)
{
}
/**
- * Creates a new JCheckBoxMenuItem object.
+ * Creates a new JCheckBoxMenuItem object with given label and icon
*
- * @param text DOCUMENT ME!
- * @param icon DOCUMENT ME!
+ * @param text Label for this menu item
+ * @param icon Icon for this menu item
*/
public JCheckBoxMenuItem(String text, Icon icon)
{
}
/**
- * Creates a new JCheckBoxMenuItem object.
+ * Creates a new JCheckBoxMenuItem object using specified label and
+ * marked as checked if given 'state' is true
*
- * @param text DOCUMENT ME!
- * @param state DOCUMENT ME!
+ * @param text Label for this menu item
+ * @param state True if this item should be in checked state and false otherwise
*/
public JCheckBoxMenuItem(String text, boolean state)
{
}
/**
- * Creates a new JCheckBoxMenuItem object.
+ * Creates a new JCheckBoxMenuItem object with given label, icon,
+ * and marked as checked if given 'state' is true
*
- * @param text DOCUMENT ME!
- * @param icon DOCUMENT ME!
- * @param state DOCUMENT ME!
+ * @param text Label for this menu item
+ * @param icon icon for this menu item
+ * @param state True if this item should be in checked state and false otherwise
*/
public JCheckBoxMenuItem(String text, Icon icon, boolean state)
{
this.state = state;
}
- /**
- * DOCUMENT ME!
- *
- * @param stream DOCUMENT ME!
- *
- * @throws IOException DOCUMENT ME!
- */
private void writeObject(ObjectOutputStream stream) throws IOException
{
- // TODO
}
/**
- * 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. "JCheckBoxMenuItemUI"
*/
public String getUIClassID()
{
}
/**
- * DOCUMENT ME!
+ * Returns checked state for this check box menu item.
*
- * @return $returnType$ DOCUMENT ME!
+ * @return Returns true if this menu item is in checked state
+ * and false otherwise.
*/
public boolean getState()
{
}
/**
- * DOCUMENT ME!
+ * Sets state for this check box menu item. If
+ * given 'state' is true, then mark menu item as checked,
+ * and uncheck this menu item otherwise.
+ *
+ * @param state new state for this menu item
*
- * @param state DOCUMENT ME!
*/
public synchronized void setState(boolean state)
{
}
/**
- * DOCUMENT ME!
+ * This method returns array containing label of this
+ * menu item if it is selected and null otherwise.
*
- * @return $returnType$ DOCUMENT ME!
+ * @return Array containing label of this
+ * menu item if this menu item is selected or null otherwise.
*/
public Object[] getSelectedObjects()
{
+ if (state == true)
+ selectedObjects[0] = this.getText();
+ else
+ selectedObjects[0] = null;
+
return selectedObjects;
}
/**
- * DOCUMENT ME!
+ * This method overrides JComponent.requestFocus with an empty
+ * implementation, since JCheckBoxMenuItems should not
+ * receve focus in general.
*/
public void requestFocus()
{
- // TODO
+ // Should do nothing here
}
/**
- * DOCUMENT ME!
+ * A string that describes this JCheckBoxMenuItem. Normally only used
+ * for debugging.
*
- * @return $returnType$ DOCUMENT ME!
+ * @return A string describing this JCheckBoxMenuItem
*/
protected String paramString()
{
return "JCheckBoxMenuItem";
}
- /**
- * DOCUMENT ME!
- *
- * @return $returnType$ DOCUMENT ME!
- */
public AccessibleContext getAccessibleContext()
{
if (accessibleContext == null)
return accessibleContext;
}
- /**
- * DOCUMENT ME!
- */
protected class AccessibleJCheckBoxMenuItem extends AccessibleJMenuItem
{
private static final long serialVersionUID = 1079958073579370777L;
{
}
- /**
- * DOCUMENT ME!
- *
- * @return $returnType$ DOCUMENT ME!
- */
public AccessibleRole getAccessibleRole()
{
return AccessibleRole.CHECK_BOX;
*/
public void revalidate()
{
+ invalidate();
RepaintManager.currentManager(this).addInvalidComponent(this);
}
import java.awt.Dimension;
import java.awt.event.KeyEvent;
-import java.io.IOException;
import java.io.InputStream;
+import java.io.IOException;
import java.net.URL;
+
import javax.accessibility.AccessibleContext;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
+import javax.swing.text.DefaultEditorKit;
import javax.swing.text.EditorKit;
import javax.swing.text.JTextComponent;
-import javax.swing.text.PlainEditorKit;
public class JEditorPane extends JTextComponent
protected EditorKit createDefaultEditorKit()
{
- return new PlainEditorKit();
+ return new DefaultEditorKit();
}
- protected static EditorKit createEditorKitForContentType(String type)
+ public static EditorKit createEditorKitForContentType(String type)
{
- return new PlainEditorKit();
+ return new DefaultEditorKit();
}
/**
}
/**
- * Make sure that TAB and Shift-TAB events get consumed, so that awt doesn't attempt focus traversal.
+ * Make sure that TAB and Shift-TAB events get consumed,
+ * so that awt doesn't attempt focus traversal.
*/
protected void processKeyEvent(KeyEvent e)
{
}
/**
- * Replaces the currently selected content with new content represented by the given string.
+ * 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).
+ * 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 scrollToReference(String reference)
{
}
public static final int REVERT = 2;
public static final int PERSIST = 3;
+ private Object value;
+
public JFormattedTextField ()
{
throw new InternalError ("not implemented");
public JFormattedTextField (Object value)
{
- throw new InternalError ("not implemented");
+ this.value = value;
}
public void commitEdit ()
public String getUIClassID ()
{
- throw new InternalError ("not implemented");
+ return "FormattedTextFieldUI";
}
public Object getValue ()
{
- throw new InternalError ("not implemented");
+ return value;
}
protected void invalidEdit ()
throw new InternalError ("not implemented");
}
- public void setDocument (Document document)
+ public void setDocument(Document newdoc)
{
- throw new InternalError ("not implemented");
+ Document document = getDocument();
+
+ if (document == newdoc)
+ return;
+
+ setDocument(newdoc);
+ firePropertyChange("document", document, newdoc);
}
public void setLostFocusBehavior (int behavior)
throw new InternalError ("not implemented");
}
- public void setValue (Object value)
+ public void setValue (Object newValue)
{
- throw new InternalError ("not implemented");
+ value = newValue;
}
}
*/
public Dimension getPreferredScrollableViewportSize()
{
- return getPreferredSize();
+ int vis = getVisibleRowCount();
+ int nrows = getModel() == null ? 0 : getModel().getSize();
+ // FIXME: this is a somewhat arbitrary default, but.. ?
+ Dimension single = new Dimension(10, 10);;
+ Rectangle bounds = null;
+
+ if (vis > nrows)
+ {
+ if (fixedCellWidth != -1 &&
+ fixedCellHeight != -1)
+ {
+ single = new Dimension(fixedCellWidth, fixedCellHeight);
+ }
+ else if (nrows != 0 && getUI() != null)
+ {
+ Rectangle tmp = getUI().getCellBounds(this, 0, 0);
+ if (tmp != null)
+ single = tmp.getSize();
+ }
+ }
+ else if (getUI() != null)
+ {
+ return getUI().getCellBounds(this, 0, vis - 1).getSize();
+ }
+
+ return new Dimension(single.width, single.height * vis);
}
/**
/**
+ * <p>
* 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.
+ * can be a submenu in some other menu. When JMenu is selected it
+ * displays JPopupMenu containing its menu items.
+ * </p>
+ *
+ * <p>
+ * JMenu's fires MenuEvents when this menu's selection changes. If this menu
+ * is selected, then fireMenuSelectedEvent() is invoked. In case when menu is
+ * deselected or cancelled, then fireMenuDeselectedEvent() or
+ * fireMenuCancelledEvent() is invoked, respectivelly.
+ * </p>
+ *
*/
public class JMenu extends JMenuItem implements Accessible, MenuElement
{
/** 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;
-
- /** MenuEvent */
+ /** Whenever menu is selected or deselected the MenuEvent is fired to
+ menu's registered listeners. */
private MenuEvent menuEvent = new MenuEvent(this);
/*Amount of time, in milliseconds, that should pass before popupMenu
/* PopupListener */
protected WinListener popupListener;
- /** Location at which popup menu associated with this menu will be displayed*/
+ /** Location at which popup menu associated with this menu will be
+ displayed */
private Point menuLocation;
/**
public JMenu()
{
super();
- menuChangeListener = createMenuChangeListener();
- getModel().addChangeListener(menuChangeListener);
}
/**
public JMenu(String text)
{
super(text);
- menuChangeListener = createMenuChangeListener();
- getModel().addChangeListener(menuChangeListener);
}
/**
public JMenu(Action action)
{
super(action);
- menuChangeListener = createMenuChangeListener();
- getModel().addChangeListener(menuChangeListener);
+ createActionChangeListener(this);
}
/**
/**
* Changes this menu selected state if selected is true and false otherwise
- * This method fires menuEvents to model's registered listeners.
+ * This method fires menuEvents to menu's registered listeners.
*
* @param selected true if the menu should be selected and false otherwise
*/
public void setSelected(boolean selected)
{
+ // if this menu selection is true, then activate this menu and
+ // display popup associated with this menu
+ if (selected)
+ {
super.setArmed(true);
+ super.setSelected(true);
+
+ // FIXME: The popup menu should be shown on the screen after certain
+ // number of seconds pass. The 'delay' property of this menu indicates
+ // this amount of seconds. 'delay' property is 0 by default.
+ if (this.isShowing())
+ {
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
+ {
+ super.setSelected(false);
+ super.setArmed(false);
+ fireMenuDeselected();
+ popupMenu.setVisible(false);
+ }
}
/**
((MenuListener) ll[i]).menuCanceled(menuEvent);
}
- /**
- * Creates MenuChangeListener to listen to change events occuring
- * in the model
- *
- * @return ChangeListener
- */
- private ChangeListener createMenuChangeListener()
- {
- return new MenuChangeListener();
- }
-
/**
* Creates WinListener that listens to the menu;s popup menu.
*
{
// 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);
- }
+ setSelected(changed);
}
/**
}
}
- /** 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
*/
/**
- * JMenuBar
+ * <p>
+ * JMenuBar is a container for menu's. For a menu bar to be seen on the
+ * screen, at least one menu should be added to it. Just like adding
+ * components to container, one can use add() to add menu's to the menu bar.
+ * Menu's will be displayed in the menu bar in the order they were added.
+ * The JMenuBar uses selectionModel to keep track of selected menu index.
+ * JMenuBar's selectionModel will fire ChangeEvents to its registered
+ * listeners when the selected index changes.
+ * </p>
*/
public class JMenuBar extends JComponent implements Accessible, MenuElement
{
/** Fired in a PropertyChangeEvent when the "model" changes. */
public static final String MODEL_CHANGED_PROPERTY = "model";
+ /** Fired in a PropertyChangeEvent when the "margin" changes. */
+ public static final String MARGIN_CHANGED_PROPERTY = "margin";
private static final long serialVersionUID = -8191026883931977036L;
/** JMenuBar's model. It keeps track of selected menu's index */
}
/**
- * DOCUMENT ME!
+ * This method overrides addNotify() in the Container to register
+ * this menu bar with the current keyboard manager.
*/
public void addNotify()
{
}
/**
- * DOCUMENT ME!
+ * Returns number of menu's in this menu bar
*
- * @return DOCUMENT ME!
+ * @return number of menu's in this menu bar
*/
public int getMenuCount()
{
}
/**
- * Returns selection model for this menu bar.
+ * Returns selection model for this menu bar. SelectionModel
+ * keeps track of the selected menu in the menu bar. Whenever
+ * selected property of selectionModel changes, the ChangeEvent
+ * will be fired its ChangeListeners.
*
- * @return selection mdoel for this menu bar.
+ * @return selection model for this menu bar.
*/
public SingleSelectionModel getSelectionModel()
{
}
/**
- * DOCUMENT ME!
+ * A string that describes this JMenuBar. Normally only used
+ * for debugging.
*
- * @return DOCUMENT ME!
+ * @return A string describing this JMenuBar
*/
protected String paramString()
{
}
/**
- * DOCUMENT ME!
+ * Process key events forwarded from MenuSelectionManager. This method
+ * doesn't do anything. It is here to conform to the MenuElement interface.
+ *
+ * @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
*
- * @param e DOCUMENT ME!
- * @param path DOCUMENT ME!
- * @param manager DOCUMENT ME!
*/
public void processKeyEvent(KeyEvent e, MenuElement[] path,
MenuSelectionManager manager)
}
/**
- * DOCUMENT ME!
+ * Process mouse events forwarded from MenuSelectionManager. This method
+ * doesn't do anything. It is here to conform to the MenuElement interface.
+ *
+ * @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
*
- * @param event DOCUMENT ME!
- * @param path DOCUMENT ME!
- * @param manager DOCUMENT ME!
*/
public void processMouseEvent(MouseEvent event, MenuElement[] path,
MenuSelectionManager manager)
}
/**
- * DOCUMENT ME!
+ * This method overrides removeNotify() in the Container to
+ * unregister this menu bar from the current keyboard manager.
*/
public void removeNotify()
{
}
/**
- * DOCUMENT ME!
+ * Sets painting status of the border. If 'b' is true then menu bar's
+ * border will be painted, and it will not be painted otherwise.
*
- * @param b DOCUMENT ME!
+ * @param b indicates if menu bar's border should be painted.
*/
public void setBorderPainted(boolean b)
{
}
/**
- * DOCUMENT ME!
+ * Sets help menu for this menu bar
*
- * @param menu DOCUMENT ME!
+ * @param menu help menu
*/
public void setHelpMenu(JMenu menu)
{
}
/**
- * DOCUMENT ME!
+ * Sets the menu bar's "margin" bound property, which represents
+ * distance between the menubar's border and its menus.
+ * icon. When marging property is modified, PropertyChangeEvent will
+ * be fired to menuBar's PropertyChangeListener's.
+ *
+ * @param m distance between the menubar's border and its menus.
*
- * @param m DOCUMENT ME!
*/
public void setMargin(Insets m)
{
+ if (m.equals(this.margin))
+ {
+ Insets oldMargin = this.margin;
+ this.margin = m;
+ firePropertyChange(MARGIN_CHANGED_PROPERTY, oldMargin, margin);
+ }
+
this.margin = m;
}
/**
- * Changes menu bar's selection to the specifies menu.
- * This method updates selected index of menu bar's model,
+ * Changes menu bar's selection to the specified menu.
+ * This method updates selected index of menu bar's selection model,
* which results in a model firing change event.
*
* @param sel menu to select
setMnemonic(mnemonic);
}
- /**
- * DOCUMENT ME!
- *
- * @param stream DOCUMENT ME!
- *
- * @throws IOException DOCUMENT ME!
- * @throws ClassNotFoundException DOCUMENT ME!
- */
private void readObject(ObjectInputStream stream)
throws IOException, ClassNotFoundException
{
}
- /**
- * DOCUMENT ME!
- *
- * @param stream DOCUMENT ME!
- *
- * @throws IOException DOCUMENT ME!
- */
private void writeObject(ObjectOutputStream stream) throws IOException
{
}
// 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;
+ /* NOTE: According to java specifications paint_border should be set to false,
+ since menu item should not have a border. However running few java programs
+ it seems that menu items and menues can have a border. Commenting
+ out statement below for now. */
+ //borderPainted = false;
+ focusPainted = false;
+ horizontalAlignment = JButton.LEFT;
+ horizontalTextPosition = JButton.LEFT;
}
/**
{
super.configurePropertiesFromAction(action);
- if (action == null)
- setAccelerator(null);
- else
+ if (! (this instanceof JMenu) && action != null)
setAccelerator((KeyStroke) (action.getValue(Action.ACCELERATOR_KEY)));
}
public void processMouseEvent(MouseEvent event, MenuElement[] path,
MenuSelectionManager manager)
{
+ // Fire MenuDragMouseEvents if mouse is being dragged.
+ boolean dragged = (event.getModifiers() & InputEvent.BUTTON1_MASK) != 0;
+ if (dragged)
+ processMenuDragMouseEvent(createMenuDragMouseEvent(event, path, manager));
+
switch (event.getID())
{
case MouseEvent.MOUSE_CLICKED:
break;
case MouseEvent.MOUSE_ENTERED:
- if (event.getSource() instanceof JMenuItem)
- {
- JMenuItem item = (JMenuItem) event.getSource();
-
- ButtonModel model = item.getModel();
- if (item.isRolloverEnabled())
+ if (isRolloverEnabled())
model.setRollover(true);
- }
break;
case MouseEvent.MOUSE_EXITED:
- if (event.getSource() instanceof JMenuItem)
- {
- JMenuItem item = (JMenuItem) event.getSource();
- ButtonModel model = item.getModel();
- if (item.isRolloverEnabled())
+ if (isRolloverEnabled())
model.setRollover(false);
- }
+
+ // for JMenu last element on the path is its popupMenu.
+ // JMenu shouldn't me disarmed.
+ if (! (path[path.length - 1] instanceof JPopupMenu) && ! dragged)
+ setArmed(false);
break;
case MouseEvent.MOUSE_PRESSED:
- if (event.getSource() instanceof JMenuItem)
- {
if ((event.getModifiers() & InputEvent.BUTTON1_MASK) != 0)
{
model.setArmed(true);
model.setPressed(true);
}
- }
break;
case MouseEvent.MOUSE_RELEASED:
break;
case MouseEvent.MOUSE_MOVED:
break;
case MouseEvent.MOUSE_DRAGGED:
- MenuDragMouseEvent e = new MenuDragMouseEvent((Component) event
- .getSource(),
- event.getID(),
- event.getWhen(),
- event.getModifiers(),
- event.getX(),
- event.getY(),
- event.getClickCount(),
- event.isPopupTrigger(),
- path, manager);
- processMenuDragMouseEvent(e);
break;
}
}
/**
- * DOCUMENT ME!
+ * Creates MenuDragMouseEvent.
*
- * @param event DOCUMENT ME!
- * @param path DOCUMENT ME!
- * @param manager DOCUMENT ME!
+ * @param event MouseEvent that occured while mouse was pressed.
+ * @param path Path the the menu element where the dragging event was
+ * originated
+ * @param manager MenuSelectionManager for the current menu hierarchy.
+ *
+ * @return new MenuDragMouseEvent
+ */
+ private MenuDragMouseEvent createMenuDragMouseEvent(MouseEvent event,
+ MenuElement[] path,
+ MenuSelectionManager manager)
+ {
+ return new MenuDragMouseEvent((Component) event.getSource(),
+ event.getID(), event.getWhen(),
+ event.getModifiers(), event.getX(),
+ event.getY(), event.getClickCount(),
+ event.isPopupTrigger(), path, manager);
+ }
+
+ /**
+ * Process key 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 processKeyEvent(KeyEvent event, MenuElement[] path,
MenuSelectionManager manager)
{
- // TODO
+ // Need to implement.
}
/**
*/
public void processMenuKeyEvent(MenuKeyEvent event)
{
- // TODO
+ // Need to implement.
}
/**
public void menuSelectionChanged(boolean changed)
{
if (changed)
+ {
model.setArmed(true);
+
+ if (this.getParent() instanceof JPopupMenu)
+ ((JPopupMenu) this.getParent()).setSelected(this);
+ }
else
+ {
model.setArmed(false);
+
+ if (this.getParent() instanceof JPopupMenu)
+ ((JPopupMenu) this.getParent()).getSelectionModel().clearSelection();
+ }
}
/**
return "JMenuItem";
}
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
public AccessibleContext getAccessibleContext()
{
if (accessibleContext == null)
import java.awt.Component;
import java.awt.Dialog;
+import java.awt.Dimension;
import java.awt.Frame;
import javax.accessibility.Accessible;
import javax.accessibility.AccessibleContext;
import javax.accessibility.AccessibleRole;
import javax.swing.Icon;
+import javax.swing.JInternalFrame;
+import javax.swing.event.InternalFrameAdapter;
+import javax.swing.event.InternalFrameEvent;
import javax.swing.plaf.OptionPaneUI;
*/
protected class AccessibleJOptionPane extends JComponent.AccessibleJComponent
{
+ /** DOCUMENT ME! */
private static final long serialVersionUID = 686071432213084821L;
/**
}
}
+ /** DOCUMENT ME! */
private static final long serialVersionUID = 5231143276678566796L;
/** The value returned when cancel option is selected. */
dialog.getContentPane().add(this);
dialog.setModal(true);
dialog.setResizable(false);
+ dialog.invalidate();
+ dialog.repaint();
return dialog;
}
String title)
throws RuntimeException
{
- // FIXME: implement.
- return null;
+ JDesktopPane toUse = getDesktopPaneForComponent(parentComponent);
+ if (toUse == null)
+ throw new RuntimeException("parentComponent does not have a valid parent");
+
+ JInternalFrame frame = new JInternalFrame(title);
+
+ inputValue = UNINITIALIZED_VALUE;
+ value = UNINITIALIZED_VALUE;
+
+ frame.setClosable(true);
+ toUse.add(frame);
+
+ // FIXME: JLayeredPane broken? See bug # 16576
+ // frame.setLayer(JLayeredPane.MODAL_LAYER);
+ return frame;
}
/**
*/
public static JDesktopPane getDesktopPaneForComponent(Component parentComponent)
{
- return (JDesktopPane) SwingUtilities.getAncestorOfClass(JDesktopPane.class, parentComponent);
+ return (JDesktopPane) SwingUtilities.getAncestorOfClass(JDesktopPane.class,
+ parentComponent);
}
/**
*/
public static Frame getFrameForComponent(Component parentComponent)
{
- return (Frame) SwingUtilities.getAncestorOfClass(Frame.class, parentComponent);
+ return (Frame) SwingUtilities.getAncestorOfClass(Frame.class,
+ parentComponent);
}
/**
{
JOptionPane pane = new JOptionPane(message);
JDialog dialog = pane.createDialog(parentComponent, "Select an Option");
+
dialog.pack();
dialog.show();
}
/**
- * DOCUMENT ME!
+ * This method shows an internal confirmation dialog with the given message.
+ * The internal frame dialog will be placed in the first JDesktopPane
+ * ancestor of the given parentComponent. This method will return the value
+ * selected.
*
- * @param parentComponent DOCUMENT ME!
- * @param message DOCUMENT ME!
+ * @param parentComponent The parent to find a JDesktopPane in.
+ * @param message The message to display.
*
- * @return DOCUMENT ME!
+ * @return The value selected.
*/
public static int showInternalConfirmDialog(Component parentComponent,
Object message)
{
- // FIXME: implement
- return 0;
+ JOptionPane pane = new JOptionPane(message);
+ JInternalFrame frame = pane.createInternalFrame(parentComponent, null);
+
+ startModal(frame, pane);
+
+ return ((Integer) pane.getValue()).intValue();
}
/**
- * DOCUMENT ME!
+ * This method shows an internal confirmation dialog with the given message,
+ * optionType and title. The internal frame dialog will be placed in the
+ * first JDesktopPane ancestor of the given parentComponent. This method
+ * will return the selected value.
*
- * @param parentComponent DOCUMENT ME!
- * @param message DOCUMENT ME!
- * @param title DOCUMENT ME!
- * @param optionType DOCUMENT ME!
+ * @param parentComponent The parent to find a JDesktopPane in.
+ * @param message The message to display.
+ * @param title The title to display.
+ * @param optionType The option type.
*
- * @return DOCUMENT ME!
+ * @return The selected value.
*/
public static int showInternalConfirmDialog(Component parentComponent,
Object message, String title,
int optionType)
{
- // FIXME: implement
- return 0;
+ JOptionPane pane = new JOptionPane(message, PLAIN_MESSAGE, optionType);
+ JInternalFrame frame = pane.createInternalFrame(parentComponent, title);
+
+ startModal(frame, pane);
+
+ return ((Integer) pane.getValue()).intValue();
}
/**
- * DOCUMENT ME!
+ * This method shows an internal confirmation dialog with the given message,
+ * title, optionTypes and icon for the given message type. The internal
+ * confirmation dialog will be placed in the first instance of
+ * JDesktopPane ancestor of the given parentComponent.
*
- * @param parentComponent DOCUMENT ME!
- * @param message DOCUMENT ME!
- * @param title DOCUMENT ME!
- * @param optionType DOCUMENT ME!
- * @param messageType DOCUMENT ME!
+ * @param parentComponent The component to find a JDesktopPane in.
+ * @param message The message to display.
+ * @param title The title of the dialog.
+ * @param optionType The option type.
+ * @param messageType The message type.
*
- * @return DOCUMENT ME!
+ * @return The selected value.
*/
public static int showInternalConfirmDialog(Component parentComponent,
Object message, String title,
int optionType, int messageType)
{
- // FIXME: implement
- return 0;
+ JOptionPane pane = new JOptionPane(message, messageType, optionType);
+ JInternalFrame frame = pane.createInternalFrame(parentComponent, title);
+
+ startModal(frame, pane);
+
+ return ((Integer) pane.getValue()).intValue();
}
/**
- * DOCUMENT ME!
+ * This method shows an internal confirmation dialog with the given message,
+ * title, option type, message type, and icon. The internal frame dialog
+ * will be placed in the first JDesktopPane ancestor that is found in the
+ * given parentComponent. This method returns the selected value.
*
- * @param parentComponent DOCUMENT ME!
- * @param message DOCUMENT ME!
- * @param title DOCUMENT ME!
- * @param optionType DOCUMENT ME!
- * @param messageType DOCUMENT ME!
- * @param icon DOCUMENT ME!
+ * @param parentComponent The parent to find a JDesktopPane in.
+ * @param message The message to display.
+ * @param title The title to display.
+ * @param optionType The option type.
+ * @param messageType The message type.
+ * @param icon The icon to display.
*
- * @return DOCUMENT ME!
+ * @return The selected value.
*/
public static int showInternalConfirmDialog(Component parentComponent,
Object message, String title,
int optionType, int messageType,
Icon icon)
{
- // FIXME: implement
- return 0;
+ JOptionPane pane = new JOptionPane(message, messageType, optionType, icon);
+ JInternalFrame frame = pane.createInternalFrame(parentComponent, title);
+
+ startModal(frame, pane);
+
+ return ((Integer) pane.getValue()).intValue();
}
/**
- * DOCUMENT ME!
+ * This method shows an internal input dialog with the given message. The
+ * internal frame dialog will be placed in the first JDesktopPane ancestor
+ * of the given parent component. This method returns the value input by
+ * the user.
*
- * @param parentComponent DOCUMENT ME!
- * @param message DOCUMENT ME!
+ * @param parentComponent The parent to find a JDesktopPane in.
+ * @param message The message to display.
*
- * @return DOCUMENT ME!
+ * @return The user selected value.
*/
public static String showInternalInputDialog(Component parentComponent,
Object message)
{
- // FIXME: implement
- return null;
+ JOptionPane pane = new JOptionPane(message);
+ pane.setWantsInput(true);
+ JInternalFrame frame = pane.createInternalFrame(parentComponent, null);
+
+ startModal(frame, pane);
+
+ return (String) pane.getInputValue();
}
/**
- * DOCUMENT ME!
+ * This method shows an internal input dialog with the given message, title
+ * and message type. The internal input dialog will be placed in the first
+ * JDesktopPane ancestor found in the given parent component. This method
+ * will return the input value given by the user.
*
- * @param parentComponent DOCUMENT ME!
- * @param message DOCUMENT ME!
- * @param title DOCUMENT ME!
- * @param messageType DOCUMENT ME!
+ * @param parentComponent The component to find a JDesktopPane in.
+ * @param message The message to display.
+ * @param title The title to display.
+ * @param messageType The message type.
*
- * @return DOCUMENT ME!
+ * @return The user input value.
*/
public static String showInternalInputDialog(Component parentComponent,
Object message, String title,
int messageType)
{
- // FIXME: implement
- return null;
+ JOptionPane pane = new JOptionPane(message, messageType);
+ pane.setWantsInput(true);
+ JInternalFrame frame = pane.createInternalFrame(parentComponent, title);
+
+ startModal(frame, pane);
+
+ return (String) pane.getInputValue();
}
/**
- * DOCUMENT ME!
+ * This method shows an internal input dialog with the given message, title
+ * message type, icon, selection value list and initial selection value.
+ * The internal frame dialog will be placed in the first JDesktopPane
+ * ancestor found in the given parent component. This method returns the
+ * input value from the user.
*
- * @param parentComponent DOCUMENT ME!
- * @param message DOCUMENT ME!
- * @param title DOCUMENT ME!
- * @param messageType DOCUMENT ME!
- * @param icon DOCUMENT ME!
- * @param selectionValues DOCUMENT ME!
- * @param initialSelectionValue DOCUMENT ME!
+ * @param parentComponent The parent to find a JDesktopPane in.
+ * @param message The message to display.
+ * @param title The title to display.
+ * @param messageType The message type.
+ * @param icon The icon to display.
+ * @param selectionValues The selection value list.
+ * @param initialSelectionValue The initial selection value.
*
- * @return DOCUMENT ME!
+ * @return The user input value.
*/
public static Object showInternalInputDialog(Component parentComponent,
Object message, String title,
Object[] selectionValues,
Object initialSelectionValue)
{
- // FIXME: implement
- return null;
+ JOptionPane pane = new JOptionPane(message, messageType);
+ pane.setWantsInput(true);
+ pane.setIcon(icon);
+ pane.setSelectionValues(selectionValues);
+ pane.setInitialSelectionValue(initialSelectionValue);
+ JInternalFrame frame = pane.createInternalFrame(parentComponent, title);
+
+ startModal(frame, pane);
+
+ return (String) pane.getInputValue();
}
/**
- * DOCUMENT ME!
+ * This method shows an internal message dialog with the given message. The
+ * internal frame dialog will be placed in the first JDesktopPane ancestor
+ * found in the given parent component.
*
- * @param parentComponent DOCUMENT ME!
- * @param message DOCUMENT ME!
+ * @param parentComponent The component to find a JDesktopPane in.
+ * @param message The message to display.
*/
public static void showInternalMessageDialog(Component parentComponent,
Object message)
{
- // FIXME: implement
+ JOptionPane pane = new JOptionPane(message);
+ JInternalFrame frame = pane.createInternalFrame(parentComponent, null);
+
+ startModal(frame, pane);
}
/**
- * DOCUMENT ME!
+ * This method shows an internal message dialog with the given message,
+ * title and message type. The internal message dialog is placed in the
+ * first JDesktopPane ancestor found in the given parent component.
*
- * @param parentComponent DOCUMENT ME!
- * @param message DOCUMENT ME!
- * @param title DOCUMENT ME!
- * @param messageType DOCUMENT ME!
+ * @param parentComponent The parent component to find a JDesktopPane in.
+ * @param message The message to display.
+ * @param title The title to display.
+ * @param messageType The message type.
*/
public static void showInternalMessageDialog(Component parentComponent,
Object message, String title,
int messageType)
{
- // FIXME: implement
+ JOptionPane pane = new JOptionPane(message, messageType);
+ JInternalFrame frame = pane.createInternalFrame(parentComponent, title);
+
+ startModal(frame, pane);
}
/**
- * DOCUMENT ME!
+ * This method shows an internal message dialog with the given message,
+ * title, message type and icon. The internal message dialog is placed in
+ * the first JDesktopPane ancestor found in the given parent component.
*
- * @param parentComponent DOCUMENT ME!
- * @param message DOCUMENT ME!
- * @param title DOCUMENT ME!
- * @param messageType DOCUMENT ME!
- * @param icon DOCUMENT ME!
+ * @param parentComponent The component to find a JDesktopPane in.
+ * @param message The message to display.
+ * @param title The title to display.
+ * @param messageType The message type.
+ * @param icon The icon to display.
*/
public static void showInternalMessageDialog(Component parentComponent,
Object message, String title,
int messageType, Icon icon)
{
- // FIXME: implement
+ JOptionPane pane = new JOptionPane(message, messageType);
+ pane.setIcon(icon);
+ JInternalFrame frame = pane.createInternalFrame(parentComponent, title);
+
+ startModal(frame, pane);
}
/**
- * DOCUMENT ME!
+ * This method displays an internal option dialog with the given message,
+ * title, option type, message type, icon, option list, and initial option
+ * value. The internal option dialog is placed in the first JDesktopPane
+ * ancestor found in the parent component. This method returns the option
+ * selected.
*
- * @param parentComponent DOCUMENT ME!
- * @param message DOCUMENT ME!
- * @param title DOCUMENT ME!
- * @param optionType DOCUMENT ME!
- * @param messageType DOCUMENT ME!
- * @param icon DOCUMENT ME!
- * @param options DOCUMENT ME!
- * @param initialValue DOCUMENT ME!
+ * @param parentComponent The parent to find a JDesktopPane in.
+ * @param message The message displayed.
+ * @param title The title displayed.
+ * @param optionType The option type.
+ * @param messageType The message type.
+ * @param icon The icon to display.
+ * @param options The array of options.
+ * @param initialValue The initial value selected.
*
- * @return DOCUMENT ME!
+ * @return The option that was selected.
*/
public static int showInternalOptionDialog(Component parentComponent,
Object message, String title,
Icon icon, Object[] options,
Object initialValue)
{
- // FIXME: implement
- return 0;
+ JOptionPane pane = new JOptionPane(message, messageType, optionType, icon,
+ options, initialValue);
+
+ JInternalFrame frame = pane.createInternalFrame(parentComponent, title);
+
+ startModal(frame, pane);
+
+ return ((Integer) pane.getValue()).intValue();
}
/**
{
JOptionPane pane = new JOptionPane(message, messageType, optionType, icon,
options, initialValue);
+
JDialog dialog = pane.createDialog(parentComponent, title);
dialog.pack();
dialog.show();
}
return false;
}
+
+ /**
+ * This helper method makes the JInternalFrame wait until it is notified by
+ * an InternalFrameClosing event. This method also adds the given
+ * JOptionPane to the JInternalFrame and sizes it according to the
+ * JInternalFrame's preferred size.
+ *
+ * @param f The JInternalFrame to make modal.
+ * @param pane The JOptionPane to add to the JInternalFrame.
+ */
+ private static void startModal(JInternalFrame f, JOptionPane pane)
+ {
+ f.getContentPane().add(pane);
+ f.pack();
+ f.show();
+
+ Dimension pref = f.getPreferredSize();
+ f.setBounds(0, 0, pref.width, pref.height);
+
+ synchronized (f)
+ {
+ final JInternalFrame tmp = f;
+ tmp.toFront();
+
+ f.addInternalFrameListener(new InternalFrameAdapter()
+ {
+ public void internalFrameClosed(InternalFrameEvent e)
+ {
+ synchronized (tmp)
+ {
+ tmp.removeInternalFrameListener(this);
+ tmp.notifyAll();
+ }
+ }
+ });
+ try
+ {
+ while (! f.isClosed())
+ f.wait();
+ }
+ catch (InterruptedException ignored)
+ {
+ }
+ }
+ }
}
/**
- * DOCUMENT ME!
+ * JPopupMenu is a container that is used to display popup menu's menu
+ * items. By default JPopupMenu is a lightweight container, however if it
+ * is the case that JPopupMenu's bounds are outside of main window, then
+ * heawyweight container will be used to display menu items. It is also
+ * possible to change JPopupMenu's default behavior and set JPopupMenu
+ * to always use heavyweight container.
+ *
+ * JPopupMenu can be displayed anywhere; it is a floating free popup menu.
+ * However before JPopupMenu is diplayed, its invoker property should be set.
+ * JPopupMenu's invoker is a component relative to which popup menu is
+ * displayed.
+ *
+ * JPopupMenu fires PopupMenuEvents to its registered listeners. Whenever
+ * JPopupMenu becomes visible on the screen then PopupMenuEvent indicating
+ * that popup menu became visible will be fired. In the case when
+ * JPopupMenu becomes invisible or cancelled without selection, then
+ * popupMenuBecomeInvisible() or popupMenuCancelled() methods of
+ * PopupMenuListeners will be invoked.
+ *
+ * JPopupMenu also fires PropertyChangeEvents when its bound properties
+ * change.In addittion to inheritted bound properties, JPopupMenu has
+ * 'visible' bound property. When JPopupMenu becomes visible/invisible on
+ * the screen it fires PropertyChangeEvents to its registered
+ * PropertyChangeListeners.
*/
public class JPopupMenu extends JComponent implements Accessible, MenuElement
{
/** name for the UI delegate for this menuItem. */
private static final String uiClassID = "PopupMenuUI";
+ /** Fire a PropertyChangeEvent when the "borderPainted" property changes. */
+ public static final String LABEL_CHANGED_PROPERTY = "label";
+
/* indicates if popup's menu border should be painted*/
private boolean borderPainted = true;
/* Component that invokes popup menu. */
transient Component invoker;
- /* Label for this popup menu */
+ /* Label for this popup menu. It is not used in most of the look and feel themes. */
private String label;
/*Amount of space between menuItem's in JPopupMenu and JPopupMenu's border */
lightWeightPopupEnabled = DefaultLightWeightPopupEnabled;
selectionModel = new DefaultSingleSelectionModel();
-
super.setVisible(false);
}
*/
public JPopupMenu(String label)
{
- this.label = label;
+ setLabel(label);
}
- /**
- * DOCUMENT ME!
- *
- * @param stream DOCUMENT ME!
- *
- * @throws IOException DOCUMENT ME!
- * @throws ClassNotFoundException DOCUMENT ME!
- */
private void readObject(ObjectInputStream stream)
throws IOException, ClassNotFoundException
{
}
- /**
- * DOCUMENT ME!
- *
- * @param stream DOCUMENT ME!
- *
- * @throws IOException DOCUMENT ME!
- */
private void writeObject(ObjectOutputStream stream) throws IOException
{
}
*/
public JMenuItem add(Action action)
{
- JMenuItem item = new JMenuItem(action);
+ JMenuItem item = createActionComponent(action);
if (action != null)
action.addPropertyChangeListener(createActionChangeListener(item));
super.remove(index);
GridBagConstraints constraints = new GridBagConstraints();
- constraints.fill = GridBagConstraints.HORIZONTAL;
+ constraints.fill = GridBagConstraints.BOTH;
constraints.weightx = 100.0;
constraints.weighty = 100.0;
public void insert(Component component, int index)
{
GridBagConstraints constraints = new GridBagConstraints();
- constraints.fill = GridBagConstraints.HORIZONTAL;
+ constraints.fill = GridBagConstraints.BOTH;
constraints.weightx = 100.0;
constraints.weighty = 100.0;
}
/**
- * DOCUMENT ME!
+ * Creates new menu item associated with a given action.
*
- * @param action DOCUMENT ME!
+ * @param action Action used to create new menu item
*
- * @return DOCUMENT ME!
+ * @return new created menu item associated with a given action.
*/
protected JMenuItem createActionComponent(Action action)
{
- return null;
+ return new JMenuItem(action);
}
/**
- * DOCUMENT ME!
+ * Creates PropertyChangeListener that listens to PropertyChangeEvents
+ * occuring in the Action associated with given menu item in this popup menu.
*
- * @param item DOCUMENT ME!
+ * @param item MenuItem
*
- * @return DOCUMENT ME!
+ * @return The PropertyChangeListener
*/
protected PropertyChangeListener createActionChangeListener(JMenuItem item)
{
- return null;
+ return new ActionChangeListener();
}
/**
}
/**
- * Sets label for this popup menu
+ * Sets label for this popup menu. This method fires PropertyChangeEvent
+ * when the label property is changed. Please note that most
+ * of the Look & Feel will ignore this property.
*
* @param label label for this popup menu
*/
public void setLabel(String label)
{
+ if (label != this.label)
+ {
+ String oldLabel = this.label;
this.label = label;
+ firePropertyChange(LABEL_CHANGED_PROPERTY, oldLabel, label);
+ }
}
/**
size = this.getPreferredSize();
else
size = this.getSize();
+
if ((size.width > (rootContainer.getWidth() - popupLocation.x))
|| (size.height > (rootContainer.getHeight() - popupLocation.y)))
fit = false;
{
// 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
{
- // popup menu was cancelled without selection
- if (! getSelectionModel().isSelected())
- firePopupMenuCanceled();
-
firePopupMenuWillBecomeInvisible();
-
popup.hide();
}
}
}
/**
- * Process mouse events forwarded from MenuSelectionManager.
+ * Process mouse events forwarded from MenuSelectionManager. This method
+ * doesn't do anything. It is here to conform to the MenuElement interface.
*
* @param event event forwarded from MenuSelectionManager
* @param path path to the menu element from which event was generated
public void processMouseEvent(MouseEvent event, MenuElement[] path,
MenuSelectionManager manager)
{
+ // Empty Implementation. This method is needed for the implementation
+ // of MenuElement interface
}
/**
- * DOCUMENT ME!
+ * Process key events forwarded from MenuSelectionManager. This method
+ * doesn't do anything. It is here to conform to the MenuElement interface.
+ *
+ * @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
*
- * @param event DOCUMENT ME!
- * @param path DOCUMENT ME!
- * @param manager DOCUMENT ME!
*/
public void processKeyEvent(KeyEvent event, MenuElement[] path,
MenuSelectionManager manager)
{
+ // Empty Implementation. This method is needed for the implementation
+ // of MenuElement interface
}
/**
*/
public void menuSelectionChanged(boolean changed)
{
+ if (! changed)
+ setVisible(false);
}
/**
*/
public void hide()
{
+ // FIXME: Right now the lightweight container is removed from JLayered
+ // pane. It is probably would be better in order to improve performance
+ // to make the container invisible instead of removing it everytime.
JLayeredPane layeredPane;
layeredPane = SwingUtilities.getRootPane(invoker).getLayeredPane();
int index = layeredPane.getIndexOf(c);
*/
public void hide()
{
+ // FIXME: Right now the lightweight container is removed from JLayered
+ // pane. It is probably would be better in order to improve performance
+ // to make the container invisible instead of removing it everytime.
JLayeredPane layeredPane;
layeredPane = SwingUtilities.getRootPane(invoker).getLayeredPane();
int index = layeredPane.getIndexOf(this);
}
}
+ /**
+ * This is the separator that can be used in popup menu.
+ */
public static class Separator extends JSeparator
{
public Separator()
return AccessibleRole.POPUP_MENU;
}
}
+
+ /* This class resizes popup menu and repaints popup menu appropriately if one
+ of item's action has changed */
+ protected class ActionChangeListener implements PropertyChangeListener
+ {
+ public void propertyChange(PropertyChangeEvent evt)
+ {
+ JPopupMenu.this.revalidate();
+ JPopupMenu.this.repaint();
+ }
+ }
}
public JRadioButton(String text, Icon icon)
{
super(text, icon);
- paint_border = false;
- content_area_filled = false;
+ borderPainted = false;
+ contentAreaFilled = false;
}
import javax.accessibility.Accessible;
import javax.accessibility.AccessibleContext;
import javax.accessibility.AccessibleRole;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
/**
- * DOCUMENT ME!
+ * This class represents JRadioButtonMenuItem. Its behaviour is very similar
+ * to JRadioButton. Just like JRadioButton, user can check and uncheck this
+ * menu item by clicking on it. JRadioButtonMenuItem uses ToggleButtonModel
+ * to keep track of its selection. If the JRadioButtonMenuItem is included in
+ * the button group, then only one JRadioButtonMenuItem can be selected at
+ * one time.
*/
public class JRadioButtonMenuItem extends JMenuItem implements Accessible
{
private static final long serialVersionUID = 8482658191548521743L;
+ /** name for the UI delegate for this radio button menu item. */
private static final String uiClassID = "RadioButtonMenuItemUI";
/**
}
/**
- * Creates a new JRadioButtonMenuItem object.
+ * Creates a new JRadioButtonMenuItem with specified icon
*
- * @param icon DOCUMENT ME!
+ * @param icon Icon to be used for this menu item
*/
public JRadioButtonMenuItem(Icon icon)
{
}
/**
- * Creates a new JRadioButtonMenuItem object.
+ * Creates a new JRadioButtonMenuItem with specified label
*
- * @param text DOCUMENT ME!
+ * @param text Label for this menu item
*/
public JRadioButtonMenuItem(String text)
{
}
/**
- * Creates a new JRadioButtonMenuItem object.
+ * Creates a new JRadioButtonMenuItem using specified action
*
- * @param action DOCUMENT ME!
+ * @param action Action for this menu item
*/
public JRadioButtonMenuItem(Action action)
{
}
/**
- * Creates a new JRadioButtonMenuItem object.
+ * Creates a new JRadioButtonMenuItem with specified label and icon
*
- * @param text DOCUMENT ME!
- * @param icon DOCUMENT ME!
+ * @param text Label for this menu item
+ * @param icon Icon for this menu item
*/
public JRadioButtonMenuItem(String text, Icon icon)
{
}
/**
- * Creates a new JRadioButtonMenuItem object.
+ * Creates a new JRadioButtonMenuItem with specified label
+ * and marked selected if 'selected' is true.
*
- * @param text DOCUMENT ME!
- * @param selected DOCUMENT ME!
+ * @param text Text for this menu item
+ * @param selected Selected state of this menu item
*/
public JRadioButtonMenuItem(String text, boolean selected)
{
}
/**
- * Creates a new JRadioButtonMenuItem object.
+ * Creates a new JRadioButtonMenuItem with specified icon
+ * and given selected state
*
- * @param icon DOCUMENT ME!
- * @param selected DOCUMENT ME!
+ * @param icon Icon for this menu item
+ * @param selected Selected state for this menu item
*/
public JRadioButtonMenuItem(Icon icon, boolean selected)
{
}
/**
- * Creates a new JRadioButtonMenuItem object.
+ * Creates a new JRadioButtonMenuItem with specified label,
+ * icon and selected state.
*
- * @param text DOCUMENT ME!
- * @param icon DOCUMENT ME!
- * @param selected DOCUMENT ME!
+ * @param text Label for this menu item
+ * @param icon Icon to be use for this menu item
+ * @param selected selected state of this menu item
*/
public JRadioButtonMenuItem(String text, Icon icon, boolean selected)
{
model.setSelected(selected);
}
- /**
- * DOCUMENT ME!
- *
- * @param stream DOCUMENT ME!
- *
- * @throws IOException DOCUMENT ME!
- */
private void writeObject(ObjectOutputStream stream) throws IOException
{
- // TODO
}
/**
- * 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. "JRadioButtonMenuItemUI"
*/
public String getUIClassID()
{
}
/**
- * DOCUMENT ME!
+ * This method overrides JComponent.requestFocus with an empty
+ * implementation, since JRadioButtonMenuItems should not
+ * receve focus in general.
*/
public void requestFocus()
{
- // TODO
+ // Should do nothing here
}
/**
- * DOCUMENT ME!
+ * A string that describes this JRadioButtonMenuItem. Normally only used
+ * for debugging.
*
- * @return $returnType$ DOCUMENT ME!
+ * @return A string describing this JRadioButtonMenuItem
*/
protected String paramString()
{
return "JRadioButtonMenuItem";
}
- /**
- * DOCUMENT ME!
- *
- * @return $returnType$ DOCUMENT ME!
- */
public AccessibleContext getAccessibleContext()
{
if (accessibleContext == null)
return accessibleContext;
}
- /**
- * DOCUMENT ME!
- */
protected class AccessibleJRadioButtonMenuItem extends AccessibleJMenuItem
{
private static final long serialVersionUID = 4381471510145292179L;
{
}
- /**
- * DOCUMENT ME!
- *
- * @return $returnType$ DOCUMENT ME!
- */
public AccessibleRole getAccessibleRole()
{
return AccessibleRole.RADIO_BUTTON;
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()
- * (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())
- * each on top of the others
- * where you can add components to.
+ * 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()
+ * (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()) each on top of the others where you can add components to.
* (getContentPane(), getGlassPane(), getLayeredPane())
*
* @author Ronald Veldema (rveldema@cs.vu.nl)
// The class used to obtain the accessible role for this object.
protected static class AccessibleJRootPane
{
+ /** DOCUMENT ME! */
private static final long serialVersionUID = 1082432482784468088L;
+ /**
+ * Creates a new <code>AccessibleJRootPane</code> object.
+ */
protected AccessibleJRootPane()
{
}
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
public AccessibleRole getAccessibleRole()
{
return AccessibleRole.ROOT_PANE;
// menuBar withing its layeredPane.
protected class RootLayout implements LayoutManager2, Serializable
{
+ /** DOCUMENT ME! */
private static final long serialVersionUID = -4100116998559815027L;
+ /**
+ * Creates a new <code>RootLayout</code> object.
+ */
protected RootLayout()
{
}
+ /**
+ * DOCUMENT ME!
+ *
+ * @param comp DOCUMENT ME!
+ * @param constraints DOCUMENT ME!
+ */
public void addLayoutComponent(Component comp, Object constraints)
{
}
+ /**
+ * DOCUMENT ME!
+ *
+ * @param name DOCUMENT ME!
+ * @param comp DOCUMENT ME!
+ */
public void addLayoutComponent(String name, Component comp)
{
}
+ /**
+ * DOCUMENT ME!
+ *
+ * @param target DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
public float getLayoutAlignmentX(Container target)
{
return target.getAlignmentX();
}
+ /**
+ * DOCUMENT ME!
+ *
+ * @param target DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
public float getLayoutAlignmentY(Container target)
{
return target.getAlignmentY();
}
+ /**
+ * DOCUMENT ME!
+ *
+ * @param target DOCUMENT ME!
+ */
public void invalidateLayout(Container target)
{
}
+ /**
+ * DOCUMENT ME!
+ *
+ * @param c DOCUMENT ME!
+ */
public void layoutContainer(Container c)
{
Dimension menuBarSize;
menuBarSize = menuBar.getPreferredSize();
maxWidth = Math.max(menuBarSize.width, contentPaneSize.width);
menuBar.setBounds(0, 0, maxWidth, menuBarSize.height);
+ glassPane.setBounds(0, menuBarSize.height, maxWidth,
+ contentPaneSize.height);
contentPane.setBounds(0, menuBarSize.height, maxWidth,
contentPaneSize.height);
layeredPane.setSize(maxWidth,
}
else
{
+ glassPane.setBounds(0, 0, contentPaneSize.width,
+ contentPaneSize.height);
contentPane.setBounds(0, 0, contentPaneSize.width,
contentPaneSize.height);
layeredPane.setSize(contentPaneSize.width, contentPaneSize.height);
menuBarSize.height = containerSize.height;
menuBar.setBounds(0, 0, containerSize.width, menuBarSize.height);
int remainingHeight = containerSize.height - menuBarSize.height;
+ glassPane.setBounds(0, menuBarSize.height, containerSize.width,
+ containerSize.height - menuBarSize.height);
contentPane.setBounds(0, menuBarSize.height,
containerSize.width,
(containerSize.height - menuBarSize.height));
}
else
+ {
+ glassPane.setBounds(0, 0, containerSize.width,
+ containerSize.height);
contentPane.setBounds(0, 0, containerSize.width,
containerSize.height);
+ }
layeredPane.setSize(containerSize.width, containerSize.height);
}
}
+ /**
+ * DOCUMENT ME!
+ *
+ * @param target DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
public Dimension maximumLayoutSize(Container target)
{
return preferredLayoutSize(target);
}
+ /**
+ * DOCUMENT ME!
+ *
+ * @param target DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
public Dimension minimumLayoutSize(Container target)
{
return preferredLayoutSize(target);
}
+ /**
+ * DOCUMENT ME!
+ *
+ * @param c DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
public Dimension preferredLayoutSize(Container c)
{
Dimension menuBarSize;
int maxWidth;
menuBarSize = menuBar.getPreferredSize();
maxWidth = Math.max(menuBarSize.width, contentPaneSize.width);
- prefSize =
- new Dimension(maxWidth,
- contentPaneSize.height + menuBarSize.height);
+ prefSize = new Dimension(maxWidth,
+ contentPaneSize.height
+ + menuBarSize.height);
}
else
prefSize = contentPaneSize;
return prefSize;
}
+ /**
+ * DOCUMENT ME!
+ *
+ * @param comp DOCUMENT ME!
+ */
public void removeLayoutComponent(Component comp)
{
}
}
+ /** DOCUMENT ME! */
+ private static final long serialVersionUID = 8690748000348575668L;
+
+ /** DOCUMENT ME! */
protected Component glassPane;
+
+ /** DOCUMENT ME! */
protected JLayeredPane layeredPane;
+
+ /** DOCUMENT ME! */
protected JMenuBar menuBar;
+
+ /** DOCUMENT ME! */
protected Container contentPane;
+ /**
+ * DOCUMENT ME!
+ *
+ * @param m DOCUMENT ME!
+ */
public void setJMenuBar(JMenuBar m)
{
menuBar = m;
getLayeredPane().add(menuBar, JLayeredPane.FRAME_CONTENT_LAYER);
}
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
public JMenuBar getJMenuBar()
{
return menuBar;
}
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
public boolean isValidateRoot()
{
return true;
}
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
public Container getContentPane()
{
if (contentPane == null)
return contentPane;
}
+ /**
+ * DOCUMENT ME!
+ *
+ * @param p DOCUMENT ME!
+ */
public void setContentPane(Container p)
{
contentPane = p;
getLayeredPane().add(contentPane, JLayeredPane.FRAME_CONTENT_LAYER);
}
+ /**
+ * DOCUMENT ME!
+ *
+ * @param comp DOCUMENT ME!
+ * @param constraints DOCUMENT ME!
+ * @param index DOCUMENT ME!
+ */
protected void addImpl(Component comp, Object constraints, int index)
{
super.addImpl(comp, constraints, index);
}
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
public Component getGlassPane()
{
if (glassPane == null)
return glassPane;
}
+ /**
+ * DOCUMENT ME!
+ *
+ * @param f DOCUMENT ME!
+ */
public void setGlassPane(Component f)
{
if (glassPane != null)
add(glassPane, 0);
}
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
public JLayeredPane getLayeredPane()
{
if (layeredPane == null)
return layeredPane;
}
+ /**
+ * DOCUMENT ME!
+ *
+ * @param f DOCUMENT ME!
+ */
public void setLayeredPane(JLayeredPane f)
{
if (layeredPane != null)
add(f, -1);
}
+ /**
+ * Creates a new <code>JRootPane</code> object.
+ */
public JRootPane()
{
setLayout(createRootLayout());
updateUI();
}
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
protected LayoutManager createRootLayout()
{
return new RootLayout();
}
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
protected JComponent createContentPane()
{
JPanel p = new JPanel();
return p;
}
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
protected Component createGlassPane()
{
JPanel p = new JPanel();
p.setName(this.getName() + ".glassPane");
p.setLayout(new BorderLayout());
p.setVisible(false);
+ p.setOpaque(false);
return p;
}
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
protected JLayeredPane createLayeredPane()
{
JLayeredPane l = new JLayeredPane();
return l;
}
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
public RootPaneUI getUI()
{
return (RootPaneUI) ui;
}
+ /**
+ * DOCUMENT ME!
+ *
+ * @param ui DOCUMENT ME!
+ */
public void setUI(RootPaneUI ui)
{
super.setUI(ui);
}
+ /**
+ * DOCUMENT ME!
+ */
public void updateUI()
{
setUI((RootPaneUI) UIManager.getUI(this));
}
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
public String getUIClassID()
{
return "RootPaneUI";
{
// if the viewport changed, we should update the VSB / HSB
// models according to the new vertical and horizontal sizes
+
Rectangle vr = vp.getViewRect();
Dimension vs = vp.getViewSize();
- // System.err.println("got change from viewport, vr=" + vr + ", vs=" + vs);
if (vsb != null
&& (vsb.getMinimum() != 0
|| vsb.getMaximum() != vs.height
|| vsb.getValue() != vr.y
|| vsb.getVisibleAmount() != vr.height))
- {
- // System.err.println("setting vsb to "
- // + "pos=" + vr.y
- // + ", ext=" + vr.height
- // + ", min=0"
- // + ", max=" + vs.height);
vsb.setValue(vr.y, vr.height, 0, vs.height);
- }
if (hsb != null
&& (hsb.getMinimum() != 0
*/
public void setComponent(Component c)
{
- JTabbedPane.this.remove(component);
+ remove(component);
this.component = c;
- JTabbedPane.this.add(c);
+ add(c);
}
/**
package javax.swing;
+import java.awt.Color;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.util.Vector;
+import java.util.Hashtable;
import javax.accessibility.Accessible;
import javax.swing.event.CellEditorListener;
import javax.swing.event.TableColumnModelListener;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
+import javax.swing.table.DefaultTableColumnModel;
+import javax.swing.table.DefaultTableModel;
+import javax.swing.table.JTableHeader;
+import javax.swing.table.TableCellEditor;
+import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumnModel;
import javax.swing.table.TableModel;
public static final int AUTO_RESIZE_OFF = 0;
public static final int AUTO_RESIZE_SUBSEQUENT_COLUMNS = 2;
+ protected boolean autoCreateColumnsFromModel;
+ protected int autoResizeMode;
+ protected TableCellEditor cellEditor;
+ protected boolean cellSelectionEnabled;
+ protected TableColumnModel columnModel;
+ protected TableModel dataModel;
+ protected Hashtable defaultEditorsByColumnClass;
+ protected Hashtable defaultRenderersByColumnClass;
+ protected int editingColumn;
+ protected int editingRow;
+ protected Color gridColor;
+ protected Dimension preferredViewportSize;
+ protected int rowHeight;
+ protected int rowMargin;
+ protected boolean rowSelectionAllowed;
+ protected Color selectionBackground;
+ protected Color selectionForeground;
+ protected ListSelectionModel selectionModel;
+ protected boolean showHorizontalLines;
+ protected boolean showVerticalLines;
+ protected JTableHeader tableHeader;
+
+ /**
+ * Creates a new <code>JTable</code> instance.
+ */
public JTable ()
{
- throw new Error ("Not implemented");
+ this(null, null, null);
}
+ /**
+ * Creates a new <code>JTable</code> instance.
+ *
+ * @param numRows an <code>int</code> value
+ * @param numColumns an <code>int</code> value
+ */
public JTable (int numRows, int numColumns)
{
- throw new Error ("Not implemented");
+ this(new DefaultTableModel(numRows, numColumns));
}
- public JTable (Object[][] rowData, Object[] columnNames)
+ /**
+ * Creates a new <code>JTable</code> instance.
+ *
+ * @param data an <code>Object[][]</code> value
+ * @param columnNames an <code>Object[]</code> value
+ */
+ public JTable(Object[][] data, Object[] columnNames)
{
- throw new Error ("Not implemented");
+ this(new DefaultTableModel(data, columnNames));
}
+ /**
+ * Creates a new <code>JTable</code> instance.
+ *
+ * @param dm a <code>TableModel</code> value
+ */
public JTable (TableModel dm)
{
- throw new Error ("Not implemented");
+ this(dm, null, null);
}
+ /**
+ * Creates a new <code>JTable</code> instance.
+ *
+ * @param dm a <code>TableModel</code> value
+ * @param cm a <code>TableColumnModel</code> value
+ */
public JTable (TableModel dm, TableColumnModel cm)
{
- throw new Error ("Not implemented");
+ this(dm, cm, null);
}
+ /**
+ * Creates a new <code>JTable</code> instance.
+ *
+ * @param dm a <code>TableModel</code> value
+ * @param cm a <code>TableColumnModel</code> value
+ * @param sm a <code>ListSelectionModel</code> value
+ */
public JTable (TableModel dm, TableColumnModel cm, ListSelectionModel sm)
{
- throw new Error ("Not implemented");
+ this.dataModel = dm == null ? createDefaultDataModel() : dm;
+ this.columnModel = cm == null ? createDefaultColumnModel() : cm;
+ this.selectionModel = sm == null ? createDefaultListSelectionModel() : sm;
}
- public JTable (Vector rowData, Vector columnNames)
+ /**
+ * Creates a new <code>JTable</code> instance.
+ *
+ * @param data a <code>Vector</code> value
+ * @param columnNames a <code>Vector</code> value
+ */
+ public JTable(Vector data, Vector columnNames)
{
- throw new Error ("Not implemented");
+ this(new DefaultTableModel(data, columnNames));
+ }
+
+ /**
+ * @deprecated 1.0.2, replaced by <code>new JScrollPane(JTable)</code>
+ */
+ public static JScrollPane createScrollPaneForTable(JTable table)
+ {
+ return new JScrollPane(table);
+ }
+
+ public void clearSelection()
+ {
+ selectionModel.clearSelection();
}
public void columnAdded (TableColumnModelEvent event)
throw new Error ("Not implemented");
}
+ protected TableColumnModel createDefaultColumnModel()
+ {
+ return new DefaultTableColumnModel();
+ }
+
+ protected TableModel createDefaultDataModel()
+ {
+ return new DefaultTableModel();
+ }
+
+ protected ListSelectionModel createDefaultListSelectionModel()
+ {
+ return new DefaultListSelectionModel();
+ }
+
public void editingCanceled (ChangeEvent event)
{
throw new Error ("Not implemented");
public TableColumnModel getColumnModel ()
{
- throw new Error ("Not implemented");
+ return columnModel;
+ }
+
+ public TableModel getModel()
+ {
+ return dataModel;
}
public Dimension getPreferredScrollableViewportSize ()
public int getSelectedRow ()
{
- throw new Error ("Not implemented");
+ return selectionModel.getMinSelectionIndex();
}
public ListSelectionModel getSelectionModel ()
{
- throw new Error ("Not implemented");
+ if (! rowSelectionAllowed)
+ return null;
+
+ return selectionModel;
}
public void tableChanged (TableModelEvent event)
public void setModel (TableModel model)
{
- throw new Error ("Not implemented");
+ if (model == null)
+ throw new IllegalArgumentException();
+
+ // FIXME: Should we deregister from old model ?
+
+ dataModel = model;
+ dataModel.addTableModelListener(this);
}
public void setSelectionMode (int selectionMode)
public void setSelectionModel (ListSelectionModel model)
{
- throw new Error ("Not implemented");
+ if (model == null)
+ throw new IllegalArgumentException();
+
+ // FIXME: Should we deregister from old model ?
+
+ selectionModel = model;
+ selectionModel.addListSelectionListener(this);
}
public void setShowGrid (boolean showGrid)
{
throw new Error ("Not implemented");
}
-} // class JTable
+
+ public JTableHeader getTableHeader()
+ {
+ return tableHeader;
+ }
+
+ public void setTableHeader(JTableHeader newHeader)
+ {
+ tableHeader = newHeader;
+ }
+
+ public boolean getColumnSelectionAllowed()
+ {
+ return columnModel.getColumnSelectionAllowed();
+ }
+
+ public void setColumnSelectionAllowed(boolean flag)
+ {
+ columnModel.setColumnSelectionAllowed(flag);
+ }
+
+ public boolean getRowSelectionAllowed()
+ {
+ return rowSelectionAllowed;
+ }
+
+ public void setRowSelectionAllowed(boolean flag)
+ {
+ rowSelectionAllowed = flag;
+ }
+
+ public int getAutoResizeMode()
+ {
+ return autoResizeMode;
+ }
+
+ public void setAutoResizeMode(int mode)
+ {
+ autoResizeMode = mode;
+ }
+
+ public int getColumnCount()
+ {
+ return dataModel.getColumnCount();
+ }
+
+ public int getRowCount()
+ {
+ return dataModel.getRowCount();
+ }
+
+ public TableCellRenderer getCellRenderer(int row, int column)
+ {
+ TableCellRenderer renderer =
+ columnModel.getColumn(column).getCellRenderer();
+
+ if (renderer == null)
+ renderer = getDefaultRenderer(dataModel.getColumnClass(column));
+
+ return renderer;
+ }
+
+ public TableCellRenderer getDefaultRenderer(Class columnClass)
+ {
+ // FIXME:
+ return null;
+ }
+}
private int rows;
private int columns;
private boolean wrapping;
+ private int tabSize = 8;
/**
* Creates a new <code>JTextArea</code> object.
*
* @param wrapping true to enable line wrapping, false otherwise
*/
- public void setLineWrap(boolean wrapping)
+ public void setLineWrap(boolean flag)
{
- this.wrapping = wrapping;
+ if (wrapping == flag)
+ return;
+
+ boolean oldValue = wrapping;
+ wrapping = flag;
+ firePropertyChange("lineWrap", oldValue, wrapping);
+ }
+
+ public int getTabSize()
+ {
+ return tabSize;
+ }
+
+ public void setTabSize(int newSize)
+ {
+ if (tabSize == newSize)
+ return;
+
+ int oldValue = tabSize;
+ tabSize = newSize;
+ firePropertyChange("tabSize", oldValue, tabSize);
}
}
package javax.swing;
+import java.awt.Dimension;
+import java.awt.Font;
+import java.awt.FontMetrics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.accessibility.AccessibleStateSet;
private int columns;
+ private int align;
+
/**
* Creates a new instance of <code>JTextField</code>.
*/
*/
public JTextField(Document doc, String text, int columns)
{
- if (doc == null)
- doc = createDefaultModel();
-
- setDocument(doc);
+ setDocument(doc == null ? createDefaultModel() : doc);
setText(text);
setColumns(columns);
}
return new PlainDocument();
}
+ /**
+ * Returns the class ID for the UI.
+ *
+ * @return "TextFieldUI";
+ */
+ public String getUIClassID()
+ {
+ return "TextFieldUI";
+ }
+
/**
* Adds a new listener object to this text field.
*
* Returns all registered <code>ActionListener</code> objects.
*
* @return an array of listeners
+ *
+ * @since 1.4
*/
public ActionListener[] getActionListeners()
{
throw new IllegalArgumentException();
this.columns = columns;
- // FIXME: Invalidate layout.
+ invalidate();
+ repaint();
}
- public void selectAll()
+ public int getHorizontalAlignment()
{
+ return align;
+ }
+
+ public void setHorizontalAlignment(int newAlign)
+ {
+ int oldAlign = align;
+ align = newAlign;
+ invalidate();
+ repaint();
+ firePropertyChange("horizontalAlignment", oldAlign, newAlign);
+ }
+
+ public void setFont(Font newFont)
+ {
+ super.setFont(newFont);
+ revalidate();
+ }
+
+ public Dimension getPreferredSize()
+ {
+ Dimension size;
+ FontMetrics fm = getFontMetrics(getFont());
+ int fontHeight = fm.getMaxAscent() + fm.getMaxDescent();
+ int columnWidth = fm.charWidth('m');
+
+ if (columns != 0)
+ {
+ size = new Dimension(columns * columnWidth + 4, fontHeight + 4);
+ }
+ else
+ {
+ size = new Dimension(10, 10);
+ }
+
+ return size;
}
}
this(null, icon);
}
+ public JToggleButton (Icon icon, boolean selected)
+ {
+ this(null, icon, selected);
+ }
+
public JToggleButton(String text)
{
this(text, null);
public JToggleButton(String text, boolean selected)
{
- this(text, null);
- setSelected(selected);
+ this(text, null, selected);
}
public JToggleButton(String text, Icon icon)
{
super(text, icon);
- hori_align = LEADING;
+ horizontalAlignment = LEADING;
setModel(new ToggleButtonModel());
model.setSelected(selected);
}
/**
- * Gets the AccessibleContext associated with this JToggleButton.
+ * Gets the AccessibleContext associated with this <code>JToggleButton</code>.
+ *
+ * @return the associated context
*/
public AccessibleContext getAccessibleContext()
{
package javax.swing;
import java.awt.Component;
+import java.awt.Container;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.beans.PropertyChangeListener;
import java.io.IOException;
import java.io.ObjectOutputStream;
-
import javax.accessibility.Accessible;
import javax.accessibility.AccessibleContext;
import javax.accessibility.AccessibleRole;
import javax.accessibility.AccessibleStateSet;
import javax.swing.plaf.ToolBarUI;
+
/**
- * JToolBar
- * @author Andrew Selkirk
- * @version 1.0
+ * JToolBar is a component that provides a toolbar to Swing programs. Users
+ * can add buttons (or actions that will be represented by JButtons) as well
+ * as other components to the JToolBar. JToolBars can be dragged in and out
+ * of their parent components. If the JToolBar is dragged out of the parent,
+ * then it will be displayed in its own RootPaneContainer. For dragging to
+ * work properly, JToolBars need to be placed in a Container that has a
+ * BorderLayout. That parent Container cannot have components in the NORTH,
+ * EAST, SOUTH, or WEST components (that is not the JToolBar).
*/
-public class JToolBar extends JComponent
- implements SwingConstants, Accessible
+public class JToolBar extends JComponent implements SwingConstants, Accessible
{
/**
* AccessibleJToolBar
*/
protected class AccessibleJToolBar extends AccessibleJComponent
{
+ /** DOCUMENT ME! */
private static final long serialVersionUID = -5516888265903814215L;
/**
/**
* getAccessibleStateSet
+ *
* @return AccessibleStateSet
*/
public AccessibleStateSet getAccessibleStateSet()
/**
* getAccessibleRole
+ *
* @return AccessibleRole
*/
public AccessibleRole getAccessibleRole()
}
/**
- * Separator
+ * This is the private JToolBar layout manager.
+ */
+ private class DefaultToolBarLayout implements LayoutManager
+ {
+ /**
+ * This method is called when a new component is added to the container.
+ *
+ * @param name The name of the component added.
+ * @param comp The component that was added.
*/
- public static class Separator extends JSeparator {
+ public void addLayoutComponent(String name, Component comp)
+ {
+ // Do nothing.
+ }
- private static final long serialVersionUID = -1656745644823105219L;
+ /**
+ * This method is called to lay out the given container to position and
+ * size the child components.
+ *
+ * @param c The container to lay out.
+ *
+ * @throws Error DOCUMENT ME!
+ */
+ public void layoutContainer(Container c)
+ {
+ if (! (c instanceof JToolBar))
+ throw new Error("DefaultToolBarLayout can only be used on JToolBars.");
+ Insets insets = getInsets();
+ Insets margin = getMargin();
+ int middle;
+ if (margin != null)
+ {
+ insets.left += margin.left;
+ insets.top += margin.top;
+ insets.bottom += margin.bottom;
+ insets.right += margin.right;
+ }
+ Component[] components = c.getComponents();
+ Dimension tdims = c.getSize();
+ int start = 0;
+ Dimension pref;
- //-------------------------------------------------------------
- // Variables --------------------------------------------------
- //-------------------------------------------------------------
+ if (getOrientation() == SwingUtilities.HORIZONTAL)
+ {
+ start += insets.left;
+ for (int i = 0; i < components.length; i++)
+ {
+ if (components[i] != null && components[i].isVisible())
+ {
+ pref = components[i].getPreferredSize();
+ if (pref != null)
+ {
+ middle = (tdims.height - pref.height) / 2;
+ components[i].setBounds(start, middle, pref.width,
+ pref.height);
+ start += pref.width;
+ }
+ }
+ }
+ }
+ else
+ {
+ start += insets.top;
+ for (int i = 0; i < components.length; i++)
+ {
+ if (components[i] != null && components[i].isVisible())
+ {
+ pref = components[i].getPreferredSize();
+ if (pref != null)
+ {
+ middle = (tdims.width - pref.width) / 2;
+ components[i].setBounds(middle, start, pref.width,
+ pref.height);
+ start += pref.height;
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * This method returns the minimum size of the given container given the
+ * child components.
+ *
+ * @param parent The container to measure.
+ *
+ * @return The minimum size of the given container.
+ */
+ public Dimension minimumLayoutSize(Container parent)
+ {
+ return preferredLayoutSize(parent);
+ }
/**
- * separatorSize
+ * This method returns the preferred size of the given container given the
+ * child components.
+ *
+ * @param parent The container to measure.
+ *
+ * @return The preferred size of the given container.
*/
- private Dimension size;
+ public Dimension preferredLayoutSize(Container parent)
+ {
+ int orientation = getOrientation();
+ Component[] components = getComponents();
+ int limit = 0;
+ int total = 0;
+ Dimension dims;
- //-------------------------------------------------------------
- // Initialization ---------------------------------------------
- //-------------------------------------------------------------
+ int w = 0;
+ int h = 0;
+
+ if (orientation == SwingConstants.HORIZONTAL)
+ {
+ for (int i = 0; i < components.length; i++)
+ {
+ dims = components[i].getPreferredSize();
+ if (dims != null)
+ {
+ if (dims.height > limit)
+ limit = dims.height;
+ total += dims.width;
+ }
+ }
+ w = total;
+ h = limit;
+ }
+ else
+ {
+ for (int i = 0; i < components.length; i++)
+ {
+ dims = components[i].getPreferredSize();
+ if (dims != null)
+ {
+ if (dims.width > limit)
+ limit = dims.width;
+ total += dims.height;
+ }
+ }
+ w = limit;
+ h = total;
+ }
+
+ Insets insets = getInsets();
+ w += insets.left + insets.right;
+ h += insets.top + insets.bottom;
+
+ Insets margin = getMargin();
+ if (margin != null)
+ {
+ w += margin.left + margin.right;
+ h += margin.top + margin.bottom;
+ }
+
+ return new Dimension(w, h);
+ }
/**
- * Constructor Separator
+ * This method is called when the given component is removed from the
+ * container.
+ *
+ * @param comp The component removed.
*/
- public Separator() {
- // TODO
- } // Separator()
+ public void removeLayoutComponent(Component comp)
+ {
+ // Do nothing.
+ }
+ }
/**
- * Constructor Separator
- * @param size TODO
+ * This is an extension of JSeparator used in toolbars. Unlike JSeparator,
+ * nothing is painted for this Separator, it is only blank space that
+ * separates components.
*/
- public Separator(Dimension size) {
- // TODO
- } // Separator()
+ public static class Separator extends JSeparator
+ {
+ /** DOCUMENT ME! */
+ private static final long serialVersionUID = -1656745644823105219L;
+ /**
+ * Creates a new Separator object.
+ */
+ public Separator()
+ {
+ super();
+ } // Separator()
- //-------------------------------------------------------------
- // Methods ----------------------------------------------------
- //-------------------------------------------------------------
+ /**
+ * Creates a new Separator object with the given size.
+ *
+ * @param size The size of the separator.
+ */
+ public Separator(Dimension size)
+ {
+ setPreferredSize(size);
+ } // Separator()
/**
- * getUIClassID
- * @returns String
+ * This method returns the String ID of the UI class of Separator.
+ *
+ * @return The UI class' String ID.
*/
- public String getUIClassID() {
- return null; // TODO
+ public String getUIClassID()
+ {
+ return "ToolBarSeparatorUI";
} // getUIClassID()
/**
- * getPreferredSize
- * @returns Dimension
+ * This method returns the preferred size of the Separator.
+ *
+ * @return The preferred size of the Separator.
*/
- public Dimension getPreferredSize() {
- return null; // TODO
+ public Dimension getPreferredSize()
+ {
+ return super.getPreferredSize();
} // getPreferredSize()
/**
- * getMaximumSize
- * @returns Dimension
+ * This method returns the maximum size of the Separator.
+ *
+ * @return The maximum size of the Separator.
*/
- public Dimension getMaximumSize() {
- return null; // TODO
+ public Dimension getMaximumSize()
+ {
+ return super.getPreferredSize();
} // getMaximumSize()
/**
- * getMinimumSize
- * @returns Dimension
+ * This method returns the minimum size of the Separator.
+ *
+ * @return The minimum size of the Separator.
*/
- public Dimension getMinimumSize() {
- return null; // TODO
+ public Dimension getMinimumSize()
+ {
+ return super.getPreferredSize();
} // getMinimumSize()
/**
- * getSeparatorSize
- * @returns Dimension
+ * This method returns the size of the Separator.
+ *
+ * @return The size of the Separator.
*/
- public Dimension getSeparatorSize() {
- return null; // TODO
+ public Dimension getSeparatorSize()
+ {
+ return super.getPreferredSize();
} // getSeparatorSize()
/**
- * setSeparatorSize
- * @param size TODO
+ * This method sets the size of the Separator.
+ *
+ * @param size The new size of the Separator.
*/
- public void setSeparatorSize(Dimension size) {
- // TODO
+ public void setSeparatorSize(Dimension size)
+ {
+ setPreferredSize(size);
} // setSeparatorSize()
-
-
} // 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
-
-
+ /** DOCUMENT ME! */
private static final long serialVersionUID = -1269915519555129643L;
- //-------------------------------------------------------------
- // Variables --------------------------------------------------
- //-------------------------------------------------------------
+ /** Whether the JToolBar paints its border. */
+ private transient boolean paintBorder = true;
- /**
- * uiClassID
- */
- private static final String uiClassID = "ToolBarUI";
+ /** The extra insets around the JToolBar. */
+ private transient Insets margin;
- /**
- * paintBorder
- */
- private boolean paintBorder;
-
- /**
- * margin
- */
- private Insets margin;
+ /** Whether the JToolBar can float (and be dragged around). */
+ private transient boolean floatable = true;
- /**
- * floatable
- */
- private boolean floatable;
+ /** Whether the buttons will have rollover borders. */
+ private transient boolean rollover;
- /**
- * orientation
- */
+ /** The orientation of the JToolBar. */
private int orientation = HORIZONTAL;
-// protected transient DefaultJToolBarLayout toolbarLayout;
-
- /** Fired in a PropertyChangeEvent when the "orientation" property changes.
- */
+ /** Fired in a PropertyChangeEvent when the orientation property changes. */
public static final String ORIENTATION_CHANGED_PROPERTY = "orientation";
- //-------------------------------------------------------------
- // Initialization ---------------------------------------------
- //-------------------------------------------------------------
+ /** Fired in a PropertyChangeEvent when the floatable property changes. */
+ public static final String FLOATABLE_CHANGED_PROPERTY = "floatable";
+
+ /** Fired in a PropertyChangeEvent when the borderPainted property changes. */
+ public static final String BORDER_PAINTED_CHANGED_PROPERTY = "borderPainted";
+
+ /** Fired in a PropertyChangeEvent when the margin property changes. */
+ public static final String MARGIN_CHANGED_PROPERTY = "margin";
+
+ /** Fired in a PropertyChangeEvent when the rollover property changes. */
+ public static final String ROLLOVER_CHANGED_PROPERTY = "rollover";
/**
- * Constructor JToolBar
+ * This method creates a new JToolBar object with horizontal orientation
+ * and no name.
*/
- public JToolBar() {
- this(null);
+ public JToolBar()
+ {
+ this(null, HORIZONTAL);
} // JToolBar()
/**
- * Constructor JToolBar
+ * This method creates a new JToolBar with the given orientation and no
+ * name.
+ *
* @param orientation JToolBar orientation (HORIZONTAL or VERTICAL)
*/
- public JToolBar(int orientation) {
+ public JToolBar(int orientation)
+ {
this(null, orientation);
} // JToolBar()
/**
- * Constructor JToolBar
+ * This method creates a new JToolBar object with the given name and
+ * horizontal orientation.
+ *
* @param name Name assigned to undocked tool bar.
*/
- public JToolBar(String name) {
+ public JToolBar(String name)
+ {
this(name, HORIZONTAL);
} // JToolBar()
/**
- * Constructor JToolBar
+ * This method creates a new JToolBar object with the given name and
+ * orientation.
+ *
* @param name Name assigned to undocked tool bar.
* @param orientation JToolBar orientation (HORIZONTAL or VERTICAL)
*/
- public JToolBar(String name, int orientation) {
+ public JToolBar(String name, int orientation)
+ {
setName(name);
- if (orientation != HORIZONTAL && orientation != VERTICAL)
- throw new IllegalArgumentException(orientation + " is not a legal orientation");
- this.orientation = orientation;
-// toolbarLayout = new DefaultJToolBarLayout();
+ setOrientation(orientation);
+ setLayout(new DefaultToolBarLayout());
+ revalidate();
updateUI();
} // JToolBar()
-
- //-------------------------------------------------------------
- // Methods ----------------------------------------------------
- //-------------------------------------------------------------
-
- /**
- * writeObject
- * @param stream TODO
- * @exception IOException TODO
- */
- private void writeObject(ObjectOutputStream stream) throws IOException {
- // TODO
- } // writeObject()
-
/**
- * add
- * @param action TODO
- * @returns JButton
+ * This method adds a new JButton that performs the given Action to the
+ * JToolBar.
+ *
+ * @param action The Action to add to the JToolBar.
+ *
+ * @return The JButton that wraps the Action.
*/
- public JButton add(Action action) {
- return null; // TODO
+ public JButton add(Action action)
+ {
+ JButton b = createActionComponent(action);
+ add(b);
+ return b;
} // add()
/**
- * paintBorder
- * @param graphics TODO
+ * This method paints the border if the borderPainted property is true.
+ *
+ * @param graphics The graphics object to paint with.
*/
- protected void paintBorder(Graphics graphics) {
- // TODO
+ protected void paintBorder(Graphics graphics)
+ {
+ if (paintBorder && isFloatable())
+ super.paintBorder(graphics);
} // paintBorder()
/**
- * getUI
- * @returns ToolBarUI
+ * This method returns the UI class used to paint this JToolBar.
+ *
+ * @return The UI class for this JToolBar.
*/
- public ToolBarUI getUI() {
- System.out.println("ui = " + ui);
+ public ToolBarUI getUI()
+ {
return (ToolBarUI) ui;
} // getUI()
/**
- * setUI
- * @param ui TODO
+ * This method sets the UI used with the JToolBar.
+ *
+ * @param ui The UI used with the JToolBar.
*/
- public void setUI(ToolBarUI ui) {
+ public void setUI(ToolBarUI ui)
+ {
super.setUI(ui);
} // setUI()
/**
- * updateUI
+ * This method resets the UI used to the Look and Feel defaults.
*/
- public void updateUI() {
+ public void updateUI()
+ {
setUI((ToolBarUI)UIManager.getUI(this));
+ revalidate();
+ repaint();
} // updateUI()
/**
- * getUIClassID
- * @returns String
+ * This method returns the String identifier for the UI class to the used
+ * with the JToolBar.
+ *
+ * @return The String identifier for the UI class.
*/
- public String getUIClassID() {
- return uiClassID;
+ public String getUIClassID()
+ {
+ return "ToolBarUI";
} // getUIClassID()
/**
- * getComponentIndex
- * @param component TODO
- * @returns int
+ * This method sets the rollover property for the JToolBar. In rollover
+ * mode, JButtons inside the JToolBar will only display their borders when
+ * the mouse is moving over them.
+ *
+ * @param b The new rollover property.
*/
- public int getComponentIndex(Component component) {
- return 0; // TODO
+ public void setRollover(boolean b)
+ {
+ if (b != rollover)
+ {
+ rollover = b;
+ firePropertyChange(ROLLOVER_CHANGED_PROPERTY, ! rollover, rollover);
+ revalidate();
+ repaint();
+ }
+ }
+
+ /**
+ * This method returns the rollover property.
+ *
+ * @return The rollover property.
+ */
+ public boolean isRollover()
+ {
+ return rollover;
+ }
+
+ /**
+ * This method returns the index of the given component.
+ *
+ * @param component The component to find.
+ *
+ * @return The index of the given component.
+ */
+ public int getComponentIndex(Component component)
+ {
+ Component[] components = getComponents();
+ if (components == null)
+ return -1;
+
+ for (int i = 0; i < components.length; i++)
+ if (components[i] == component)
+ return i;
+
+ return -1;
} // getComponentIndex()
/**
- * getComponentAtIndex
- * @param index TODO
- * @returns Component
+ * This method returns the component at the given index.
+ *
+ * @param index The index of the component.
+ *
+ * @return The component at the given index.
*/
- public Component getComponentAtIndex(int index) {
- return null; // TODO
+ public Component getComponentAtIndex(int index)
+ {
+ return getComponent(index);
} // getComponentAtIndex()
/**
- * getMargin
- * @returns Insets
+ * This method returns the margin property.
+ *
+ * @return The margin property.
*/
- public Insets getMargin() {
- return null; // TODO
+ public Insets getMargin()
+ {
+ return margin;
} // getMargin()
/**
- * setMargin
- * @param margin TODO
+ * This method sets the margin property. The margin property determines the
+ * extra space between the children components of the JToolBar and the
+ * border.
+ *
+ * @param margin The margin property.
*/
- public void setMargin(Insets margin) {
- // TODO
+ public void setMargin(Insets margin)
+ {
+ if ((this.margin != null && margin == null)
+ || (this.margin == null && margin != null)
+ || (margin != null && this.margin != null
+ && (margin.left != this.margin.left
+ || margin.right != this.margin.right || margin.top != this.margin.top
+ || margin.bottom != this.margin.bottom)))
+ {
+ Insets oldMargin = this.margin;
+ this.margin = margin;
+ firePropertyChange(MARGIN_CHANGED_PROPERTY, oldMargin, this.margin);
+ revalidate();
+ repaint();
+ }
} // setMargin()
/**
- * isBorderPainted
- * @returns boolean
+ * This method returns the borderPainted property.
+ *
+ * @return The borderPainted property.
*/
- public boolean isBorderPainted() {
- return false; // TODO
+ public boolean isBorderPainted()
+ {
+ return paintBorder;
} // isBorderPainted()
/**
- * setBorderPainted
- * @param painted TODO
+ * This method sets the borderPainted property. If set to false, the border
+ * will not be painted.
+ *
+ * @param painted Whether the border will be painted.
*/
- public void setBorderPainted(boolean painted) {
- // TODO
+ public void setBorderPainted(boolean painted)
+ {
+ if (painted != paintBorder)
+ {
+ paintBorder = painted;
+ firePropertyChange(BORDER_PAINTED_CHANGED_PROPERTY, ! paintBorder,
+ paintBorder);
+ repaint();
+ }
} // setBorderPainted()
/**
- * isFloatable
- * @returns boolean
+ * This method returns the floatable property.
+ *
+ * @return The floatable property.
*/
- public boolean isFloatable() {
- return false; // TODO
+ public boolean isFloatable()
+ {
+ return floatable;
} // isFloatable()
/**
- * setFloatable
- * @param floatable TODO
+ * This method sets the floatable property. If set to false, the JToolBar
+ * cannot be dragged.
+ *
+ * @param floatable Whether the JToolBar can be dragged.
*/
- public void setFloatable(boolean floatable) {
- // TODO
+ public void setFloatable(boolean floatable)
+ {
+ if (floatable != this.floatable)
+ {
+ this.floatable = floatable;
+ firePropertyChange(FLOATABLE_CHANGED_PROPERTY, ! floatable, floatable);
+ }
} // setFloatable()
/**
- * getOrientation
- * @returns int
+ * This method returns the orientation of the JToolBar.
+ *
+ * @return The orientation of the JToolBar.
*/
- public int getOrientation() {
- return this.orientation;
+ public int getOrientation()
+ {
+ return orientation;
} // getOrientation()
/**
- * setLayout
- * @param mgr
+ * This method sets the layout manager to be used with the JToolBar.
+ *
+ * @param mgr The Layout Manager used with the JToolBar.
*/
- public void setLayout(LayoutManager mgr) {
+ public void setLayout(LayoutManager mgr)
+ {
super.setLayout(mgr);
+ revalidate();
+ repaint();
} // setLayout()
/**
- * setOrientation
- * @param orientation
+ * This method sets the orientation property for JToolBar.
+ *
+ * @param orientation The new orientation for JToolBar.
+ *
+ * @throws IllegalArgumentException If the orientation is not HORIZONTAL or
+ * VERTICAL.
*/
- public void setOrientation(int orientation) {
+ public void setOrientation(int orientation)
+ {
if (orientation != HORIZONTAL && orientation != VERTICAL)
- throw new IllegalArgumentException(orientation + " is not a legal orientation");
+ 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);
+ revalidate();
+ repaint();
}
} // setOrientation()
/**
- * addSeparator
+ * This method adds a Separator of default size to the JToolBar.
*/
- public void addSeparator() {
- // TODO
+ public void addSeparator()
+ {
+ add(new Separator());
} // addSeparator()
/**
- * addSeparator
- * @param size TODO
+ * This method adds a Separator with the given size to the JToolBar.
+ *
+ * @param size The size of the Separator.
*/
- public void addSeparator(Dimension size) {
- // TODO
+ public void addSeparator(Dimension size)
+ {
+ add(new Separator(size));
} // addSeparator()
/**
- * createActionComponent
- * @param action TODO
- * @returns JButton
+ * This method is used to create JButtons which can be added to the JToolBar
+ * for the given action.
+ *
+ * @param action The action to create a JButton for.
+ *
+ * @return The JButton created from the action.
*/
- protected JButton createActionComponent(Action action) {
- return null; // TODO
+ protected JButton createActionComponent(Action action)
+ {
+ return new JButton(action);
} // createActionComponent()
/**
- * createActionChangeListener
- * @param button TODO
- * @returns PropertyChangeListener
+ * This method creates a pre-configured PropertyChangeListener which updates
+ * the control as changes are made to the Action. However, this is no
+ * longer the recommended way of adding Actions to Containers. As such,
+ * this method returns null.
+ *
+ * @param button The JButton to configure a PropertyChangeListener for.
+ *
+ * @return null.
*/
- protected PropertyChangeListener createActionChangeListener(JButton button) {
- return null; // TODO
+ protected PropertyChangeListener createActionChangeListener(JButton button)
+ {
+ // XXX: As specified, this returns null. But seems kind of strange, usually deprecated methods don't just return null, verify!
+ return null;
} // createActionChangeListener()
/**
- * addImpl
- * @param component TODO
- * @param constraints TODO
- * @param index TODO
- */
- /*
- protected void addImpl(Component component, Object constraints, int index) {
- // TODO
- } // addImpl()
+ * This method overrides Container's addImpl method. If a JButton is added,
+ * it is disabled.
+ *
+ * @param component The Component to add.
+ * @param constraints The Constraints placed on the component.
+ * @param index The index to place the Component at.
*/
+ protected void addImpl(Component component, Object constraints, int index)
+ {
+ // XXX: Sun says disable button but test cases show otherwise.
+ super.addImpl(component, constraints, index);
+ } // addImpl()
+
/**
- * paramString
- * @returns String
+ * This method returns a String description of the JToolBar.
+ *
+ * @return A String description of the JToolBar.
*/
- protected String paramString() {
- return null; // TODO
+ protected String paramString()
+ {
+ return "JToolBar";
} // paramString()
/**
* getAccessibleContext
+ *
* @return AccessibleContext
*/
public AccessibleContext getAccessibleContext()
import javax.swing.event.TreeWillExpandListener;
import javax.swing.plaf.TreeUI;
import javax.swing.tree.ExpandVetoException;
+import javax.swing.tree.TreeCellRenderer;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;
{
private static final long serialVersionUID = 7559816092864483649L;
+ protected TreeCellRenderer cellRenderer;
+ protected boolean editable;
+ protected boolean rootVisible;
+ protected boolean showsRootHandles;
protected TreeModel treeModel;
/**
return null;
}
+ /**
+ * Return the UI associated with this <code>JTree</code> object.
+ *
+ * @return the associated <code>TreeUI</code> object
+ */
public TreeUI getUI()
{
return (TreeUI) ui;
}
+ /**
+ * Sets the UI associated with this <code>JTree</code> object.
+ *
+ * @param ui the <code>TreeUI</code> to associate
+ */
public void setUI(TreeUI ui)
{
super.setUI(ui);
}
+ /**
+ * This method resets the UI used to the Look and Feel defaults..
+ */
public void updateUI()
{
setUI((TreeUI) UIManager.getUI(this));
}
+ /**
+ * This method returns the String ID of the UI class of Separator.
+ *
+ * @return The UI class' String ID.
+ */
public String getUIClassID()
{
return "TreeUI";
}
+ /**
+ * Gets the AccessibleContext associated with this <code>JToggleButton</code>.
+ *
+ * @return the associated context
+ */
public AccessibleContext getAccessibleContext()
{
return null;
}
+ /**
+ * Returns the preferred viewport size..
+ *
+ * @return the preferred size
+ */
public Dimension getPreferredScrollableViewportSize()
{
return null;
for (int index = 0; index < listeners.length; ++index)
listeners[index].treeWillExpand(event);
}
+
+ /**
+ * Returns the model of this <code>JTree</code> object.
+ *
+ * @return the associated <code>TreeModel</code>
+ */
+ public TreeModel getModel()
+ {
+ return treeModel;
+ }
+
+ /**
+ * Sets the model to use in <code>JTree</object>.
+ *
+ * @param model the <code>TreeModel</code> to use
+ */
+ public void setModel(TreeModel model)
+ {
+ treeModel = model;
+ }
+
+ /**
+ * Checks if this <code>JTree</code> object is editable.
+ *
+ * @return <code>true</code> if this tree object is editable,
+ * <code>false</code> otherwise
+ */
+ public boolean isEditable()
+ {
+ return editable;
+ }
+
+ /**
+ * Sets the <code>editable</code> property.
+ *
+ * @param flag <code>true</code> to make this tree object editable,
+ * <code>false</code> otherwise
+ */
+ public void setEditable(boolean flag)
+ {
+ if (editable == flag)
+ return;
+
+ boolean oldValue = editable;
+ editable = flag;
+ firePropertyChange("editable", oldValue, editable);
+ }
+
+ /**
+ * Checks if the root element is visible.
+ *
+ * @return <code>true</code> if the root element is visible,
+ * <code>false</code> otherwise
+ */
+ public boolean isRootVisbile()
+ {
+ return rootVisible;
+ }
+
+ public void setRootVisible(boolean flag)
+ {
+ rootVisible = flag;
+ }
+
+ public boolean getShowsRootHandles()
+ {
+ return showsRootHandles;
+ }
+
+ public void setShowRootHandles(boolean flag)
+ {
+ showsRootHandles = flag;
+ }
+
+ public TreeCellRenderer getCellRenderer()
+ {
+ return cellRenderer;
+ }
+
+ public void setCellRenderer(TreeCellRenderer newRenderer)
+ {
+ cellRenderer = newRenderer;
+ }
}
listenerList.remove(ChangeListener.class, listener);
}
+ /**
+ * This method returns the String ID of the UI class of Separator.
+ *
+ * @return The UI class' String ID.
+ */
public String getUIClassID()
{
return "ViewportUI";
}
+ /**
+ * This method resets the UI used to the Look and Feel defaults..
+ */
public void updateUI()
{
setUI((ViewportUI) UIManager.getUI(this));
public JWindow()
{
- super(null); // FIXME: This throws an exception.
+ super(SwingUtilities.getOwnerFrame());
}
// huuu ?
package javax.swing;
+import java.awt.Component;
+import java.awt.Toolkit;
import javax.swing.text.JTextComponent;
public abstract String getName();
+ /**
+ * Returns true when the Look and Feel supports window decorations,
+ * false others. This method returns always false and needs to be overwritten
+ * when the derived Look and Feel supports this.
+ *
+ * @return false
+ *
+ * @since 1.4
+ */
+ public boolean getSupportsWindowDecorations()
+ {
+ return false;
+ }
+
/**
* UIManager.setLookAndFeel calls this method before the first call
* (and typically the only call) to getDefaults().
return null;
}
+ /**
+ * Invoked when the user attempts an invalid operation. The default implement
+ * just beeps. Subclasses that wish to change this need to override this
+ * method.
+ *
+ * @param component the component the error occured in
+ */
+ public void provideErrorFeedback(Component component)
+ {
+ Toolkit.getDefaultToolkit().beep();
+ }
+
/**
* Returns a string that displays and identifies this object's properties.
*
package javax.swing;
import java.awt.Component;
+import java.awt.Dimension;
import java.awt.Point;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
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();
-
// clear selected path
selectedPath.clear();
+
+ // notify all listeners that the selected path was changed
+ fireStateChanged();
}
/**
- * DOCUMENT ME!
+ * This method returns menu element on the selected path that contains
+ * given source point. If no menu element on the selected path contains this
+ * point, then null is returned.
*
- * @param source DOCUMENT ME!
- * @param sourcePoint DOCUMENT ME!
+ * @param source Component relative to which sourcePoint is given
+ * @param sourcePoint point for which we want to find menu element that contains it
*
- * @return DOCUMENT ME!
+ * @return Returns menu element that contains given source point and belongs
+ * to the currently selected path. Null is return if no such menu element found.
*/
public Component componentForPoint(Component source, Point sourcePoint)
{
- throw new UnsupportedOperationException("not implemented");
+ // Convert sourcePoint to screen coordinates.
+ Point sourcePointOnScreen = sourcePoint;
+ SwingUtilities.convertPointToScreen(sourcePointOnScreen, source);
+
+ Point compPointOnScreen;
+ Component resultComp = null;
+
+ // For each menu element on the selected path, express its location
+ // in terms of screen coordinates and check if there is any
+ // menu element on the selected path that contains given source point.
+ for (int i = 0; i < selectedPath.size(); i++)
+ {
+ Component comp = ((Component) selectedPath.get(i));
+ Dimension size = comp.getSize();
+
+ // convert location of this menu item to screen coordinates
+ compPointOnScreen = comp.getLocationOnScreen();
+
+ if (compPointOnScreen.x <= sourcePointOnScreen.x
+ && sourcePointOnScreen.x < compPointOnScreen.x + size.width
+ && compPointOnScreen.y <= sourcePointOnScreen.y
+ && sourcePointOnScreen.y < compPointOnScreen.y + size.height)
+ {
+ Point p = sourcePointOnScreen;
+ SwingUtilities.convertPointFromScreen(p, comp);
+ resultComp = SwingUtilities.getDeepestComponentAt(comp, p.x, p.y);
+ break;
+ }
+ }
+ return resultComp;
}
/**
* @param c Component for which to check
* @return True if specified component is part of current menu
*/
- boolean isComponentPartOfCurrentMenu(Component c)
+ public boolean isComponentPartOfCurrentMenu(Component c)
{
MenuElement[] subElements;
for (int i = 0; i < selectedPath.size(); i++)
*/
public void processMouseEvent(MouseEvent event)
{
- Component c = ((Component) event.getSource());
+ Component source = ((Component) event.getSource());
+
+ // In the case of drag event, event.getSource() returns component
+ // where drag event originated. However menu element processing this
+ // event should be the one over which mouse is currently located,
+ // which is not necessary the source of the drag event.
+ Component mouseOverMenuComp;
+
+ // find over which menu element the mouse is currently located
+ if (event.getID() == MouseEvent.MOUSE_DRAGGED
+ || event.getID() == MouseEvent.MOUSE_RELEASED)
+ mouseOverMenuComp = componentForPoint(source, event.getPoint());
+ else
+ mouseOverMenuComp = source;
+
+ // Process this event only if mouse is located over some menu element
+ if (mouseOverMenuComp != null && (mouseOverMenuComp instanceof MenuElement))
+ {
+ MenuElement[] path = getPath(mouseOverMenuComp);
+ ((MenuElement) mouseOverMenuComp).processMouseEvent(event, path,
+ manager);
- MenuElement[] path = getPath(c);
- ((MenuElement) c).processMouseEvent(event, path, manager);
+ // FIXME: Java specification says that mouse events should be
+ // forwarded to subcomponents. The code below does it, but
+ // menu's work fine without it. This code is commented for now.
- // forward events to subcomponents
- MenuElement[] subComponents = ((MenuElement) c).getSubElements();
+ /*
+ MenuElement[] subComponents = ((MenuElement) mouseOverMenuComp)
+ .getSubElements();
for (int i = 0; i < subComponents.length; i++)
{
- if (subComponents[i] instanceof JMenuItem)
subComponents[i].processMouseEvent(event, path, manager);
}
+ */
+ }
}
/**
return;
}
- fireStateChanged();
-
int i;
int minSize = path.length; // size of the smaller path.
if (path.length > selectedPath.size())
{
+ minSize = selectedPath.size();
+
// if new selected path contains more elements then current
// selection then first add all elements at
// the indexes > selectedPath.size
selectedPath.add(path[i]);
path[i].menuSelectionChanged(true);
}
-
- minSize = selectedPath.size();
}
else if (path.length < selectedPath.size())
// same location and adjust selection until
// same menu elements will be encountered at the
// same index in both current and new selection path.
- MenuElement oldSelectedPath;
+ MenuElement oldSelectedItem;
for (i = minSize - 1; i >= 0; i--)
{
- oldSelectedPath = (MenuElement) selectedPath.get(i);
+ oldSelectedItem = (MenuElement) selectedPath.get(i);
- if (path[i].equals(oldSelectedPath))
+ if (path[i].equals(oldSelectedItem))
break;
- oldSelectedPath.menuSelectionChanged(false);
+ oldSelectedItem.menuSelectionChanged(false);
path[i].menuSelectionChanged(true);
selectedPath.setElementAt(path[i], i);
}
+
+ fireStateChanged();
}
/**
*/
private MenuElement[] getPath(Component c)
{
+ // FIXME: There is the same method in BasicMenuItemUI. However I
+ // cannot use it here instead of this method, since I cannot assume that
+ // all the menu elements on the selected path are JMenuItem or JMenu.
+ // For now I've just duplicated it here. Please
+ // fix me or delete me if another better approach will be found, and
+ // this method will not be necessary.
ArrayList path = new ArrayList();
+
+ // if given component is JMenu, we also need to include
+ // it's popup menu in the path
+ if (c instanceof JMenu)
+ path.add(((JMenu) c).getPopupMenu());
while (c instanceof MenuElement)
{
path.add(0, (MenuElement) c);
*/
public synchronized void addInvalidComponent(JComponent component)
{
- while ((component.getParent() != null)
- && (component.getParent() instanceof JComponent)
- && (component.isValidateRoot()))
- component = (JComponent) component.getParent();
+ Component ancestor = component.getParent();
+
+ while (ancestor != null
+ && (! (ancestor instanceof JComponent)
+ || ! ((JComponent) ancestor).isValidateRoot() ))
+ ancestor = ancestor.getParent();
+
+ if (ancestor != null
+ && ancestor instanceof JComponent
+ && ((JComponent) ancestor).isValidateRoot())
+ component = (JComponent) ancestor;
if (invalidComponents.contains(component))
return;
invalidComponents.add(component);
- component.invalidate();
if (! repaintWorker.isLive())
{
import java.awt.Insets;
import java.awt.LayoutManager;
import java.awt.Rectangle;
+import java.awt.Point;
import java.io.Serializable;
import javax.swing.border.Border;
return null;
}
+ private static void maybeSetPreferredSize(JComponent src, Dimension dim)
+ {
+ Dimension tmp = null;
+ if (src != null)
+ tmp = src.getPreferredSize();
+ if (tmp != null)
+ dim.setSize(tmp);
+ }
+
+ private static void maybeSetMinimumSize(JComponent src, Dimension dim)
+ {
+ Dimension tmp = null;
+ if (src != null)
+ tmp = src.getMinimumSize();
+ if (tmp != null)
+ dim.setSize(tmp);
+ }
+
public Dimension preferredLayoutSize(Container parent)
{
- if (parent instanceof JScrollPane)
+ if (parent != null && parent instanceof JScrollPane)
{
JScrollPane sc = (JScrollPane) parent;
synchronized (sc.getTreeLock ())
Insets viewportInsets = null;
if (viewportBorder != null)
+ {
viewportInsets = viewportBorder.getBorderInsets(parent);
+ if (viewportInsets != null)
+ viewportInsetsSize.setSize(viewportInsets.left + viewportInsets.right,
+ viewportInsets.top + viewportInsets.bottom);
+ }
if (insets != null)
insetsSize.setSize(insets.left + insets.right,
insets.top + insets.bottom);
if (viewport != null)
- viewportSize.setSize(viewport.getPreferredSize());
-
- if (colHead != null)
- columnHeaderSize.setSize(colHead.getPreferredSize());
-
- if (rowHead != null)
- rowHeaderSize.setSize(rowHead.getPreferredSize());
-
- if (vsb != null)
- verticalScrollBarSize.setSize(vsb.getPreferredSize());
-
- if (hsb != null)
- horizontalScrollBarSize.setSize(hsb.getPreferredSize());
-
- /*
- System.err.println("widths: [vp=" + viewportSize.width +
- ", h=" + columnHeaderSize.width +
- ", sc=" + horizontalScrollBarSize.width + "]");
-
- System.err.println("heights: [vp=" + viewportSize.height +
- ", h=" + rowHeaderSize.height +
- ", sc=" + verticalScrollBarSize.height + "]");
- */
+ {
+ Component view = null;
+ Scrollable scr = null;
+ Dimension pref = null;
+
+ view = viewport.getView();
+ if (view != null && view instanceof Scrollable)
+ scr = (Scrollable) view;
+ if (scr != null)
+ pref = scr.getPreferredScrollableViewportSize();
+ if (pref == null)
+ pref = viewport.getPreferredSize();
+ if (pref != null)
+ viewportSize.setSize(pref);
+ }
+
+ maybeSetPreferredSize(colHead, columnHeaderSize);
+ maybeSetPreferredSize(rowHead, rowHeaderSize);
+ maybeSetPreferredSize(vsb, verticalScrollBarSize);
+ maybeSetPreferredSize(hsb, horizontalScrollBarSize);
return new Dimension(insetsSize.width
+ viewportSize.width
Insets viewportInsets = null;
if (viewportBorder != null)
+ {
viewportInsets = viewportBorder.getBorderInsets(parent);
+ if (viewportInsets != null)
+ viewportInsetsSize.setSize(viewportInsets.left + viewportInsets.right,
+ viewportInsets.top + viewportInsets.bottom);
+ }
if (insets != null)
insetsSize.setSize(insets.left + insets.right,
insets.top + insets.bottom);
- if (viewport != null)
- viewportSize.setSize(viewport.getMinimumSize());
-
- if (colHead != null)
- columnHeaderSize.setSize(colHead.getMinimumSize());
-
- if (rowHead != null)
- rowHeaderSize.setSize(rowHead.getMinimumSize());
+ maybeSetMinimumSize(viewport, viewportSize);
+ maybeSetMinimumSize(colHead, columnHeaderSize);
+ maybeSetMinimumSize(rowHead, rowHeaderSize);
- if (vsb != null
- && vsbPolicy != VERTICAL_SCROLLBAR_NEVER)
- verticalScrollBarSize.setSize(vsb.getMinimumSize());
+ if (vsbPolicy != VERTICAL_SCROLLBAR_NEVER)
+ maybeSetMinimumSize(vsb, verticalScrollBarSize);
- if (hsb != null
- && hsbPolicy != HORIZONTAL_SCROLLBAR_NEVER)
- horizontalScrollBarSize.setSize(hsb.getMinimumSize());
+ if (hsbPolicy != HORIZONTAL_SCROLLBAR_NEVER)
+ maybeSetMinimumSize(hsb, horizontalScrollBarSize);
return new Dimension(insetsSize.width
+ viewportSize.width
JScrollPane sc = (JScrollPane) parent;
synchronized (sc.getTreeLock ())
{
- Rectangle scrollPaneBounds = sc.getBounds();
JViewport viewport = sc.getViewport();
- Dimension viewportSize = viewport.getSize();
- Dimension viewSize = viewport.getView().getSize();
+ Dimension viewSize = viewport.getViewSize();
+ Point viewPos = viewport.getViewPosition();
int x1 = 0, x2 = 0, x3 = 0, x4 = 0;
int y1 = 0, y2 = 0, y3 = 0, y4 = 0;
+ Rectangle scrollPaneBounds = SwingUtilities.calculateInnerArea(sc, null);
+
x1 = scrollPaneBounds.x;
y1 = scrollPaneBounds.y;
x4 = scrollPaneBounds.x + scrollPaneBounds.width;
int vsbPolicy = sc.getVerticalScrollBarPolicy();
int hsbPolicy = sc.getHorizontalScrollBarPolicy();
+ x3 = x4 - vsb.getPreferredSize().width;
+ y3 = y4 - hsb.getPreferredSize().height;
+
boolean showVsb =
(vsb != null)
&& ((vsbPolicy == VERTICAL_SCROLLBAR_ALWAYS)
|| (vsbPolicy == VERTICAL_SCROLLBAR_AS_NEEDED
- && viewSize.height > viewportSize.height));
+ && viewSize.height > (y3 - y2)));
boolean showHsb =
(hsb != null)
&& ((hsbPolicy == HORIZONTAL_SCROLLBAR_ALWAYS)
|| (hsbPolicy == HORIZONTAL_SCROLLBAR_AS_NEEDED
- && viewSize.width > viewportSize.width));
+ && viewSize.width > (x3 - x2)));
- if (showVsb)
- x3 = x4 - vsb.getPreferredSize().width;
- else
+ if (!showVsb)
x3 = x4;
- if (showHsb)
- y3 = y4 - hsb.getPreferredSize().height;
- else
+ if (!showHsb)
y3 = y4;
// now set the layout
rowHead.setBounds(new Rectangle(x1, y2, x2-x1, y3-y2));
if (showVsb)
+ {
+ vsb.setVisible(true);
vsb.setBounds(new Rectangle(x3, y2, x4-x3, y3-y2));
+ }
+ else if (vsb != null)
+ vsb.setVisible(false);
if (showHsb)
+ {
+ hsb.setVisible(true);
hsb.setBounds(new Rectangle(x2, y3, x3-x2, y4-y3));
+ }
+ else if (hsb != null)
+ hsb.setVisible(false);
if (upperLeft != null)
upperLeft.setBounds(new Rectangle(x1, y1, x2-x1, y2-y1));
--- /dev/null
+/* Spring.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;
+
+/**
+ * Calculates the space between component edges, that are layed out by
+ * {@link SpringLayout}.
+ * <p>
+ * A Spring defines a minimum, preferred and maximum distance for each edge
+ * (north, east, south, west) of a component.
+ * </p>
+ * However, springs are not static, their actual values are computed at
+ * runtime. That means, if a Spring C is defined as the sum of Spring A and
+ * Spring B, then the values (min, pref and max) are not calculated at
+ * creation of Spring C, but instead always when {@link #getValue} is
+ * called. So, when Spring A or Spring B changes, this is reflected in
+ * Spring C.
+ *
+ * @author Roman Kennke (roman@ontographics.com)
+ */
+public abstract class Spring
+{
+
+ /** Indicates a not-set value. **/
+ public static final int UNSET = -2147483648;
+
+ /**
+ * Creates a new Spring object. This constructor is used by the static
+ * methods which create Springs.
+ */
+ protected Spring()
+ {
+ }
+
+ /**
+ * Creates a Spring which min, pref and max values are all the same.
+ * These kind of Springs are 'struts'.
+ *
+ * @param val the constant for min, pref and max values.
+ * @return a Spring object with constant values for min, pref and max.
+ */
+ public static Spring constant(int val)
+ {
+ return new SimpleSpring(val, val, val);
+ }
+
+ /** Creates a Spring which min, pref and max values are constants.
+ * @param min the constant for the minimum value.
+ * @param pref the constant for the preferred value.
+ * @param max the constant for the maximum value.
+ * @return a Spring object with constant values for min, pref and max.
+ */
+ public static Spring constant(int min, int pref, int max)
+ {
+ return new SimpleSpring(min, pref, max);
+ }
+
+ /**
+ * Returns the maximum value of the Spring.
+ *
+ * @return the maximum value.
+ */
+ public abstract int getMaximumValue();
+
+ /**
+ * Returns the minimum value of this Spring.
+ *
+ * @return the minimum value.
+ */
+ public abstract int getMinimumValue();
+
+ /**
+ * Return the preferred value of this Spring.
+ *
+ * @return the preferred value.
+ */
+ public abstract int getPreferredValue();
+
+ /**
+ * Return the actual value of this Spring.
+ *
+ * @return the actual value of this Spring.
+ */
+ public abstract int getValue();
+
+ /**
+ * Creates and returns a Spring, which always has the maximum values
+ * min = max(min_s1, min_s2), pref = max(pref_s1, pref_s2), max =
+ * max(max_s1, max_s2).
+ *
+ * @param s1 the first summand of the max Spring.
+ * @param s2 the second summand of the max Spring.
+ * @return a Spring which is max(s1, s2).
+ */
+ public static Spring max(Spring s1, Spring s2)
+ {
+ return new MaxSpring(s1, s2);
+ }
+
+ /**
+ * Creates and returns a Spring, which is always the negation of s.
+ * min = -min_s, pref = -pref_s, max = -max_pref.
+ *
+ * @param s the Spring to be negated.
+ * @return the negative of <code>s</code>.
+ */
+ public static Spring minus(Spring s)
+ {
+ return new MinusSpring(s);
+ }
+
+ /**
+ * Sets the actual value. If <code>value</code> is out of the (min, max)
+ * bounds, then the value is adjusted, so that is inside these bounds.
+ *
+ * @param value the value to be set.
+ */
+ public abstract void setValue(int value);
+
+ /**
+ * Creates and returns a Spring, which is always the sum of s1 and s2.
+ * min_sum = min_s1 + min_s2, pref_sum = pref_s1 + pref_s2, max_sum =
+ * max_s1 + max_s2.
+ *
+ * @param s1 the 1st summand of the sum Spring.
+ * @param s2 the 2nd summand of the sum Spring.
+ * @return a sum which is <code>s1 + s2</code>.
+ */
+ public static Spring sum(Spring s1, Spring s2)
+ {
+ return new AddSpring(s1, s2);
+ }
+
+ /**
+ * A simple Spring, that holds constant values for min, pref and max.
+ *
+ * @author Roman Kennke (roman@ontographics.com)
+ */
+ private static final class SimpleSpring extends Spring
+ {
+
+ /** The constant value for min. */
+ private final int min;
+
+ /** The constant value for pref. */
+ private final int pref;
+
+ /** The constant value for max. */
+ private final int max;
+
+ /** The actual value of the spring. */
+ private int value;
+
+ /**
+ * Creates a new SimpleSpring object.
+ *
+ * @param min the constant minimum value.
+ * @param pref the constant preferred value.
+ * @param max the constant maximum value.
+ */
+ public SimpleSpring(int newMin, int newPref, int newMax)
+ {
+ min = newMin;
+ pref = newPref;
+ max = newMax;
+ value = Spring.UNSET;
+ }
+
+ /**
+ * Returns the maximum value of this Spring.
+ *
+ * @return the maximum value.
+ */
+ public int getMaximumValue()
+ {
+ return max;
+ }
+
+ /**
+ * Returns the minimum value of this Spring.
+ *
+ * @return the minimum value.
+ */
+ public int getMinimumValue()
+ {
+ return min;
+ }
+
+ /**
+ * Returns the preferred value of this Spring.
+ *
+ * @return the preferred value.
+ */
+ public int getPreferredValue()
+ {
+ return pref;
+ }
+
+ /**
+ * Return the actual current value of this Spring.
+ *
+ * @return the current value.
+ */
+ public int getValue()
+ {
+
+ if (value == Spring.UNSET)
+ {
+ value = pref;
+ }
+
+ return value;
+ }
+
+ /**
+ * Sets the current value.
+ *
+ * @param val the value to be set.
+ */
+ public void setValue(int val)
+ {
+
+ if (val > max)
+ {
+ value = max;
+ }
+ else if (val < min)
+ {
+ value = min;
+ }
+ else
+ {
+ value = val;
+ }
+ }
+
+ }
+
+
+ /**
+ * A Spring, that is the sum of two other Springs.
+ *
+ * @author Roman Kennke (roman@ontographics.com)
+ */
+ private static final class AddSpring extends Spring
+ {
+
+ /** The springs, that are the 'operands' of this Spring. */
+ private final Spring s1;
+ private final Spring s2;
+
+ /** The current value for this Spring. */
+ private int value;
+
+ /**
+ * Creates a new AddSpring object.
+ *
+ * @param s1 the first operand.
+ * @param s2 the second operand.
+ */
+ protected AddSpring(Spring s1, Spring s2)
+ {
+ super();
+ this.s1 = s1;
+ this.s2 = s2;
+ value = Spring.UNSET;
+ }
+
+ /**
+ * Returns the maximum value of this Spring.
+ *
+ * @return the maximum value.
+ */
+ public int getMaximumValue()
+ {
+ int max1 = s1.getMaximumValue();
+ int max2 = s2.getMaximumValue();
+ return max1 + max2;
+ }
+
+ /**
+ * Return the minimum value of this Spring.
+ *
+ * @return the minimum value.
+ */
+ public int getMinimumValue()
+ {
+ int min1 = s1.getMinimumValue();
+ int min2 = s2.getMinimumValue();
+ return min1 + min2;
+ }
+
+ /**
+ * Returns the preferred value of this Spring.
+ *
+ * @return the preferred value.
+ */
+ public int getPreferredValue()
+ {
+ int pref1 = s1.getPreferredValue();
+ int pref2 = s2.getPreferredValue();
+ return pref1 + pref2;
+ }
+
+ /**
+ * Returns the actual current value of this Spring.
+ *
+ * @return the current value of this Spring.
+ */
+ public int getValue()
+ {
+ if (value == Spring.UNSET)
+ {
+ int val1 = s1.getValue();
+ int val2 = s2.getValue();
+ value = val1 + val2;
+ }
+ return value;
+ }
+
+ /**
+ * Sets the current value.
+ *
+ * @param val the value to be set.
+ */
+ public void setValue(int val)
+ {
+
+ if (val > getMaximumValue())
+ {
+ value = getMaximumValue();
+ }
+ else if (val < getMinimumValue())
+ {
+ value = getMinimumValue();
+ }
+ else
+ {
+ value = val;
+ }
+
+ }
+
+ }
+
+
+ /**
+ * A Spring that is calculated as the negation of another Spring.
+ *
+ * @author Roman Kennke (roman@ontographics.com)
+ */
+ private static final class MinusSpring extends Spring
+ {
+
+ /** The Spring from which to calculate the negation. */
+ private final Spring s;
+
+ /** The current value of this Spring. */
+ private int value;
+
+ /**
+ * Creates a new MinusSpring object.
+ * @param s the Spring from which to calculate the negation.
+ */
+ protected MinusSpring(Spring s)
+ {
+ super();
+ this.s = s;
+ value = Spring.UNSET;
+ }
+
+ /** Returns the maximum value of this Spring.
+ *
+ * @return the maximum value.
+ */
+ public int getMaximumValue()
+ {
+ return -s.getMinimumValue();
+ }
+
+ /**
+ * Returns the minimum value of this Spring.
+ *
+ * @return the minimum value.
+ */
+ public int getMinimumValue()
+ {
+ return -s.getMaximumValue();
+ }
+
+ /**
+ * Returns the preferred value of this Spring.
+ *
+ * @return the preferred value.
+ */
+ public int getPreferredValue()
+ {
+ return -s.getPreferredValue();
+ }
+
+ /**
+ * Returns the current value of this Spring.
+ *
+ * @return the current value.
+ */
+ public int getValue()
+ {
+ if (value == Spring.UNSET)
+ {
+ value = -s.getValue();
+ }
+ return value;
+ }
+
+ /**
+ * Sets the current value.
+ *
+ * @param val the value to be set.
+ */
+ public void setValue(int val)
+ {
+
+ if (val > getMaximumValue())
+ {
+ value = getMaximumValue();
+ }
+ else if (val < getMinimumValue())
+ {
+ value = getMinimumValue();
+ }
+ else
+ {
+ value = val;
+ }
+
+ }
+
+ }
+
+
+ /**
+ * A Spring, that is calculated as the maximum of two Springs.
+ *
+ * @author Roman Kennke (roman@ontographics.com)
+ */
+ private static final class MaxSpring extends Spring
+ {
+
+ /** The two other Springs from which to calculate the maximum. */
+ private final Spring s1;
+ private final Spring s2;
+
+ /** The current value of this Spring. */
+ private int value;
+
+ /**
+ * Creates a new MaxSpring object.
+ *
+ * @param s1 the 1st operand.
+ * @param s2 the 2nd operand.
+ */
+ protected MaxSpring(Spring s1, Spring s2)
+ {
+ super();
+ this.s1 = s1;
+ this.s2 = s2;
+ value = Spring.UNSET;
+ }
+
+
+ /**
+ * Returns the maximum value of this Spring.
+ *
+ * @return the maximum value.
+ */
+ public int getMaximumValue()
+ {
+ int max1 = s1.getMaximumValue();
+ int max2 = s2.getMaximumValue();
+ return Math.max(max1, max2);
+ }
+
+ /**
+ * Returns the minimum value of this Spring.
+ *
+ * @return the minimum value.
+ */
+ public int getMinimumValue()
+ {
+ int min1 = s1.getMinimumValue();
+ int min2 = s2.getMinimumValue();
+ return Math.max(min1, min2);
+ }
+
+ /**
+ * Returns the preferred value of this Spring.
+ *
+ * @return the preferred value.
+ */
+ public int getPreferredValue()
+ {
+ int pref1 = s1.getPreferredValue();
+ int pref2 = s2.getPreferredValue();
+ return Math.max(pref1, pref2);
+ }
+
+ /**
+ * Returns the actual value of this Spring.
+ *
+ * @return the current value.
+ */
+ public int getValue()
+ {
+ if (value == Spring.UNSET)
+ {
+ int val1 = s1.getValue();
+ int val2 = s2.getValue();
+ value = Math.max(val1, val2);
+ }
+ return value;
+ }
+
+ /**
+ * Sets the current value.
+ *
+ * @param val the value to be set.
+ */
+ public void setValue(int val)
+ {
+
+ if (val > getMaximumValue())
+ {
+ value = getMaximumValue();
+ }
+ else if (val < getMinimumValue())
+ {
+ value = getMinimumValue();
+ }
+ else
+ {
+ value = val;
+ }
+ }
+ }
+}
--- /dev/null
+/* SpringLayout.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.Component;
+import java.awt.Container;
+import java.awt.Dimension;
+import java.awt.LayoutManager2;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.swing.Spring;
+
+/**
+ * A very flexible layout manager. Components are laid out by defining the
+ * relationships between them. The relationships are expressed as
+ * {@link Spring}s. You can attach a Spring for each edge of a component and
+ * link it to an edge of a different component. For example, you can say,
+ * the northern edge of component A should be attached to the southern edge
+ * of component B, and the space between them should be something between
+ * x and y pixels, and preferably z pixels.
+ * <p>While quite simple, this layout manager can be used to emulate most other
+ * layout managers, and can also be used to solve some layout problems, which
+ * would be hard to solve with other layout managers.</p>
+ *
+ * @author Roman Kennke (roman@ontographics.com)
+ */
+public class SpringLayout implements LayoutManager2
+{
+
+ /** The right edge of a component. */
+ public static final String EAST = "East";
+
+ /** The top edge of a component. */
+ public static final String NORTH = "North";
+
+ /** The bottom edge of a component. */
+ public static final String SOUTH = "South";
+
+ /** The left edge of a component. */
+ public static final String WEST = "West";
+
+ /** maps components to their constraints. */
+ private Map constraintsMap;
+
+ /**
+ * The constraints that define the relationships between components.
+ * Each Constraints object can hold 4 Springs: one for each edge of the
+ * component. Additionally it can hold Springs for the components width
+ * and the components height. Since the height and width constraints are
+ * dependend on the other constraints, a component can be over-constraint.
+ * In this case (like when all of NORTH, SOUTH and HEIGHT are constraint),
+ * the values are adjusted, so that the mathematics still hold true.
+ *
+ * @author Roman Kennke (roman@ontographics.com)
+ */
+ public final static class Constraints
+ {
+
+ // The constraints for each edge, and width and height.
+ /** The Spring for the left edge. */
+ private Spring x;
+
+ /** The Spring for the upper edge. */
+ private Spring y;
+
+ /** The Spring for the height. */
+ private Spring height;
+
+ /** The Spring for the width. */
+ private Spring width;
+
+ /** The Spring for the right edge. */
+ private Spring east;
+
+ /** The Spring for the bottom edge. */
+ private Spring south;
+
+ /**
+ * Creates a new Constraints object.
+ * There is no constraint set.
+ */
+ public Constraints()
+ {
+ x = y = height = width = east = south = null;
+ }
+
+ /**
+ * Creates a new Constraints object.
+ *
+ * @param x the constraint for the left edge of the component.
+ * @param y the constraint for the upper edge of the component.
+ */
+ public Constraints(Spring x, Spring y)
+ {
+ this.x = x;
+ this.y = y;
+ width = height = east = south = null;
+ }
+
+ /**
+ * Creates a new Constraints object.
+ *
+ * @param x the constraint for the left edge of the component.
+ * @param y the constraint for the upper edge of the component.
+ * @param width the constraint for the width of the component.
+ * @param height the constraint for the height of the component.
+ */
+ public Constraints(Spring x, Spring y, Spring width, Spring height)
+ {
+ this.x = x;
+ this.y = y;
+ this.width = width;
+ this.height = height;
+ east = south = null;
+ }
+
+ /**
+ * Returns the constraint for the edge with the <code>edgeName</code>.
+ * This is expected to be one of
+ * {@link #EAST}, {@link #WEST}, {@link NORTH} or {@link SOUTH}.
+ *
+ * @param edgeName the name of the edge.
+ * @return the constraint for the specified edge.
+ */
+ public Spring getConstraint(String edgeName)
+ {
+ Spring retVal = null;
+ if (edgeName.equals(SpringLayout.NORTH))
+ retVal = y;
+ else if (edgeName.equals(SpringLayout.WEST))
+ retVal = x;
+ else if (edgeName.equals(SpringLayout.SOUTH))
+ {
+ retVal = south;
+ if ((retVal == null) && (y != null) && (height != null))
+ retVal = Spring.sum(y, height);
+ }
+ else if (edgeName.equals(SpringLayout.EAST))
+ {
+ retVal = east;
+ if ((retVal == null) && (x != null) && (width != null))
+ retVal = Spring.sum(x, width);
+ }
+
+ return retVal;
+ }
+
+ /**
+ * Returns the constraint for the height of the component.
+ *
+ * @return the height constraint.
+ */
+ public Spring getHeight()
+ {
+ Spring retVal = height;
+ if ((retVal == null) && (y != null) && (south != null))
+ {
+ retVal = Spring.sum(south, Spring.minus(y));
+ }
+ return retVal;
+ }
+
+ /**
+ * Returns the constraint for the width of the component.
+ *
+ * @return the width constraint.
+ */
+ public Spring getWidth()
+ {
+ Spring retVal = width;
+ if ((retVal == null) && (x != null) && (east != null))
+ {
+ retVal = Spring.sum(east, Spring.minus(x));
+ }
+ return retVal;
+ }
+
+ /**
+ * Returns the constraint for the left edge of the component.
+ *
+ * @return the left-edge constraint (== WEST).
+ */
+ public Spring getX()
+ {
+ Spring retVal = x;
+ if ((retVal == null) && (width != null) && (east != null))
+ {
+ retVal = Spring.sum(east, Spring.minus(width));
+ }
+ return retVal;
+ }
+
+ /**
+ * Returns the constraint for the upper edge of the component.
+ *
+ * @return the upper-edge constraint (== NORTH).
+ */
+ public Spring getY()
+ {
+ Spring retVal = y;
+ if ((retVal == null) && (height != null) && (south != null))
+ {
+ retVal = Spring.sum(south, Spring.minus(height));
+ }
+ return retVal;
+ }
+
+ /**
+ * Sets a constraint for the specified edge. If this leads to an
+ * over-constrained situation, the constraints get adjusted, so that
+ * the mathematics still hold true.
+ *
+ * @param edgeName the name of the edge, one of {@link #EAST},
+ * {@link #WEST}, {@link NORTH} or {@link SOUTH}.
+ * @param s the constraint to be set.
+ */
+ public void setConstraint(String edgeName, Spring s)
+ {
+
+ if (edgeName.equals(SpringLayout.WEST))
+ {
+ x = s;
+ if ((width != null) && (east != null))
+ width = Spring.sum(east, Spring.minus(x));
+ }
+ else if (edgeName.equals(SpringLayout.NORTH))
+ {
+ y = s;
+ if ((height != null) && (south != null))
+ height = Spring.sum(south, Spring.minus(y));
+ }
+ else if (edgeName.equals(SpringLayout.EAST))
+ {
+ east = s;
+ if ((x != null) && (width != null))
+ x = Spring.sum(east, Spring.minus(width));
+ }
+ else if (edgeName.equals(SpringLayout.SOUTH))
+ {
+ south = s;
+ if ((height != null) && (y != null))
+ y = Spring.sum(south, Spring.minus(height));
+ }
+
+ }
+
+ /**
+ * Sets the height-constraint.
+ *
+ * @param s the constraint to be set.
+ */
+ public void setHeight(Spring s)
+ {
+ height = s;
+ if ((south != null) && (y != null))
+ south = Spring.sum(y, height);
+
+ }
+
+ /**
+ * Sets the width-constraint.
+ *
+ * @param s the constraint to be set.
+ */
+ public void setWidth(Spring s)
+ {
+ width = s;
+ if ((east != null) && (x != null))
+ east = Spring.sum(x, width);
+
+ }
+
+ /**
+ * Sets the WEST-constraint.
+ *
+ * @param s the constraint to be set.
+ */
+ public void setX(Spring s)
+ {
+ x = s;
+ if ((width != null) && (east != null))
+ width = Spring.sum(east, Spring.minus(x));
+
+ }
+
+ /**
+ * Sets the NORTH-constraint.
+ *
+ * @param s the constraint to be set.
+ */
+ public void setY(Spring s)
+ {
+ y = s;
+ if ((height != null) && (south != null))
+ height = Spring.sum(south, Spring.minus(y));
+
+ }
+ }
+
+ /**
+ * Creates a new SpringLayout.
+ */
+ public SpringLayout()
+ {
+
+ constraintsMap = new HashMap();
+ }
+
+ /**
+ * Adds a layout component and a constraint object to this layout.
+ * This method is usually only called by a {@java.awt.Container}s add
+ * Method.
+ *
+ * @param component the component to be added.
+ * @param constraint the constraint to be set.
+ */
+ public void addLayoutComponent(Component component, Object constraint)
+ {
+ constraintsMap.put(component, constraint);
+ }
+
+
+ /**
+ * Adds a layout component and a constraint object to this layout.
+ * This method is usually only called by a {@java.awt.Container}s add
+ * Method. This method does nothing, since SpringLayout does not manage
+ * String-indexed components.
+ *
+ * @param component the component to be added.
+ * @param constraint the constraint to be set.
+ */
+ public void addLayoutComponent(String name, Component c)
+ {
+ // do nothing here.
+ }
+
+ /**
+ * Returns the constraint of the edge named by <code>edgeName</code>.
+ *
+ * @param c the component from which to get the constraint.
+ * @param edgeName the name of the edge, one of {@link #EAST},
+ * {@link #WEST}, {@link NORTH} or {@link SOUTH}.
+ * @return the constraint of the edge <code>edgeName</code> of the
+ * component c.
+ */
+ public Spring getConstraint(String edgeName, Component c)
+ {
+ Constraints constraints = getConstraints(c);
+ return constraints.getConstraint(edgeName);
+ }
+
+ /**
+ * Returns the {@link Constraints} object associated with the specified
+ * component.
+ *
+ * @param c the component for which to determine the constraint.
+ * @return the {@link Constraints} object associated with the specified
+ * component.
+ */
+ public SpringLayout.Constraints getConstraints(Component c)
+ {
+ Constraints constraints = (Constraints) constraintsMap.get(c);
+ if (constraints == null)
+ {
+ Container parent = c.getParent();
+ constraints = new Constraints();
+ if (parent != null)
+ {
+ constraints.setX
+ (Spring.constant(parent.getInsets().left));
+ constraints.setY
+ (Spring.constant(parent.getInsets().top));
+ }
+ else
+ {
+ constraints.setX
+ (Spring.constant(0));
+ constraints.setY
+ (Spring.constant(0));
+
+ }
+ constraints.setWidth
+ (Spring.constant(c.getMinimumSize().width,
+ c.getPreferredSize().width,
+ c.getMaximumSize().width));
+ constraints.setHeight
+ (Spring.constant(c.getMinimumSize().height,
+ c.getPreferredSize().height,
+ c.getMaximumSize().height));
+
+ constraintsMap.put(c, constraints);
+
+ }
+
+ return constraints;
+ }
+
+ /**
+ * Returns the X alignment of the Container <code>p</code>.
+ *
+ * @param p the {@link java.awt.Container} for which to determine the X
+ * alignment.
+ * @return always 0.0
+ */
+ public float getLayoutAlignmentX(Container p)
+ {
+ return 0.0F;
+ }
+
+ /**
+ * Returns the Y alignment of the Container <code>p</code>.
+ *
+ * @param p the {@link java.awt.Container} for which to determine the Y
+ * alignment.
+ * @return always 0.0
+ */
+ public float getLayoutAlignmentY(Container p)
+ {
+ return 0.0F;
+ }
+
+ /**
+ * Recalculate a possibly cached layout.
+ */
+ public void invalidateLayout(Container p)
+ {
+ // nothing to do here yet
+ }
+
+ /**
+ * Lays out the container <code>p</code>.
+ *
+ * @param p the container to be laid out.
+ */
+ public void layoutContainer(Container p)
+ {
+
+ addLayoutComponent(p, new Constraints(Spring.constant(0),
+ Spring.constant(0)));
+
+ int offsetX = p.getInsets().left;
+ int offsetY = p.getInsets().right;
+
+ Component[] components = p.getComponents();
+ for (int index = 0; index < components.length; index++)
+ {
+ Component c = components[index];
+ Constraints constraints = getConstraints(c);
+ int x = constraints.getX().getValue();
+ int y = constraints.getY().getValue();
+ int width = constraints.getWidth().getValue();
+ int height = constraints.getHeight().getValue();
+
+ c.setLocation(x + offsetX, y + offsetY);
+ c.setSize(width, height);
+ }
+
+ }
+
+ /**
+ * Calculates the maximum size of the layed out container. This
+ * respects the maximum sizes of all contained components.
+ *
+ * @param p the container to be laid out.
+ * @return the maximum size of the container.
+ */
+ public Dimension maximumLayoutSize(Container p)
+ {
+ int maxX = 0;
+ int maxY = 0;
+
+ int offsetX = p.getInsets().left;
+ int offsetY = p.getInsets().right;
+
+ Component[] components = p.getComponents();
+ for (int index = 0; index < components.length; index++)
+ {
+ Component c = components[index];
+ Constraints constraints = getConstraints(c);
+ int x = constraints.getX().getMaximumValue();
+ int y = constraints.getY().getMaximumValue();
+ int width = constraints.getWidth().getMaximumValue();
+ int height = constraints.getHeight().getMaximumValue();
+
+ int rightEdge = offsetX + x + width;
+ if (rightEdge > maxX)
+ maxX = rightEdge;
+ int bottomEdge = offsetY + y + height;
+ if (bottomEdge > maxY)
+ maxY = bottomEdge;
+ }
+
+ return new Dimension(maxX, maxY);
+ }
+
+
+ /**
+ * Calculates the minimum size of the layed out container. This
+ * respects the minimum sizes of all contained components.
+ *
+ * @param p the container to be laid out.
+ * @return the minimum size of the container.
+ */
+ public Dimension minimumLayoutSize(Container p)
+ {
+ int maxX = 0;
+ int maxY = 0;
+
+ int offsetX = p.getInsets().left;
+ int offsetY = p.getInsets().right;
+
+ Component[] components = p.getComponents();
+ for (int index = 0; index < components.length; index++)
+ {
+ Component c = components[index];
+ Constraints constraints = getConstraints(c);
+ int x = constraints.getX().getMinimumValue();
+ int y = constraints.getY().getMinimumValue();
+ int width = constraints.getWidth().getMinimumValue();
+ int height = constraints.getHeight().getMinimumValue();
+
+ int rightEdge = offsetX + x + width;
+ if (rightEdge > maxX)
+ maxX = rightEdge;
+ int bottomEdge = offsetY + y + height;
+ if (bottomEdge > maxY)
+ maxY = bottomEdge;
+ }
+
+ return new Dimension(maxX, maxY);
+ }
+
+ /**
+ * Calculates the preferred size of the layed out container. This
+ * respects the preferred sizes of all contained components.
+ *
+ * @param p the container to be laid out.
+ * @return the preferred size of the container.
+ */
+ public Dimension preferredLayoutSize(Container p)
+ {
+ int maxX = 0;
+ int maxY = 0;
+
+ int offsetX = p.getInsets().left;
+ int offsetY = p.getInsets().right;
+
+ Component[] components = p.getComponents();
+ for (int index = 0; index < components.length; index++)
+ {
+ Component c = components[index];
+ Constraints constraints = getConstraints(c);
+ int x = constraints.getX().getPreferredValue();
+ int y = constraints.getY().getPreferredValue();
+ int width = constraints.getWidth().getPreferredValue();
+ int height = constraints.getHeight().getPreferredValue();
+
+ int rightEdge = offsetX + x + width;
+ if (rightEdge > maxX)
+ maxX = rightEdge;
+ int bottomEdge = offsetY + y + height;
+ if (bottomEdge > maxY)
+ maxY = bottomEdge;
+ }
+
+ return new Dimension(maxX, maxY);
+ }
+
+ /**
+ * Attaches the edge <code>e1</code> of component <code>c1</code> to
+ * the edge <code>e2</code> of component <code>c2</code> width the
+ * fixed strut <code>pad</code>.
+ *
+ * @param e1 the edge of component 1.
+ * @param c1 the component 1.
+ * @param pad the space between the components in pixels.
+ * @param e2 the edge of component 2.
+ * @param c2 the component 2.
+ */
+ public void putConstraint(String e1, Component c1, int pad, String e2,
+ Component c2)
+ {
+ Constraints constraints1 = getConstraints(c1);
+ Constraints constraints2 = getConstraints(c2);
+
+ Spring strut = Spring.constant(pad);
+ Spring otherEdge = constraints2.getConstraint(e2);
+ constraints1.setConstraint(e1, Spring.sum(strut, otherEdge));
+
+ }
+
+ /**
+ * Attaches the edge <code>e1</code> of component <code>c1</code> to
+ * the edge <code>e2</code> of component <code>c2</code> width the
+ * {@link Spring} <code>s</code>.
+ *
+ * @param e1 the edge of component 1.
+ * @param c1 the component 1.
+ * @param s the space between the components as a {@link Spring} object.
+ * @param e2 the edge of component 2.
+ * @param c2 the component 2.
+ */
+ public void putConstraint(String e1, Component c1, Spring s, String e2,
+ Component c2)
+ {
+ Constraints constraints1 = getConstraints(c1);
+ Constraints constraints2 = getConstraints(c2);
+
+ Spring otherEdge = constraints2.getConstraint(e2);
+ constraints1.setConstraint(e1, Spring.sum(s, otherEdge));
+
+ }
+
+ /**
+ * Removes a layout component.
+ * @param c the layout component to remove.
+ */
+ public void removeLayoutComponent(Component c)
+ {
+ // do nothing here
+ }
+}
*/
public class SwingUtilities implements SwingConstants
{
-
- private static Frame ownerFrame;
+ /**
+ * This frame should be used as parent for JWindow or JDialog
+ * that doesn't an owner
+ */
+ private static OwnerFrame ownerFrame;
/**
* Calculates the portion of the base rectangle which is inside the
*
* @see #getAncestorOfClass
* @see #windowForComponent
- * @see
- *
*/
public static Container getAncestorOfClass(Class c, Component comp)
{
{
case TOP:
textR.y = 0;
- iconR.y = textR.height + textIconGap;
+ iconR.y = (horizontalTextPosition == CENTER
+ ? textR.height + textIconGap : 0);
break;
case BOTTOM:
iconR.y = 0;
- textR.y = iconR.height + textIconGap;
+ textR.y = (horizontalTextPosition == CENTER
+ ? iconR.height + textIconGap
+ : iconR.height - textR.height);
break;
case CENTER:
int centerLine = Math.max(textR.height, iconR.height) / 2;
}
/**
- * This method returns the common Frame owner used in JDialogs
- * when no owner is provided.
+ * This method returns the common Frame owner used in JDialogs or
+ * JWindow when no owner is provided.
*
* @return The common Frame
*/
static Frame getOwnerFrame()
{
if (ownerFrame == null)
- ownerFrame = new Frame();
+ ownerFrame = new OwnerFrame();
return ownerFrame;
}
return ((event.getModifiers() & InputEvent.BUTTON3_DOWN_MASK)
== InputEvent.BUTTON3_DOWN_MASK);
}
+
+ /**
+ * This frame should be used when constructing a Window/JDialog without
+ * a parent. In this case, we are forced to use this frame as a window's
+ * parent, because we simply cannot pass null instead of parent to Window
+ * constructor, since doing it will result in NullPointerException.
+ */
+ private static class OwnerFrame extends Frame
+ {
+ public void setVisible(boolean b)
+ {
+ // Do nothing here.
+ }
+
+ public boolean isShowing()
+ {
+ return true;
+ }
+ }
}
while (running)
{
sleep(delay);
+ queueEvent();
if (logTimers)
System.out.println("javax.swing.Timer -> clocktick");
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
+
/**
* ToolTipManager
+ *
* @author Andrew Selkirk
- * @version 1.0
*/
-public class ToolTipManager extends MouseAdapter implements MouseMotionListener {
-
- //-------------------------------------------------------------
- // Classes ----------------------------------------------------
- //-------------------------------------------------------------
-
+public class ToolTipManager extends MouseAdapter
+ implements MouseMotionListener
+{
/**
* stillInsideTimerAction
*/
- protected class stillInsideTimerAction implements ActionListener {
-
- //-------------------------------------------------------------
- // Variables --------------------------------------------------
- //-------------------------------------------------------------
-
-
- //-------------------------------------------------------------
- // Initialization ---------------------------------------------
- //-------------------------------------------------------------
-
+ protected class stillInsideTimerAction
+ implements ActionListener
+ {
/**
* Constructor stillInsideTimerAction
- * @param manager TODO
*/
- protected stillInsideTimerAction(ToolTipManager manager) {
+ protected stillInsideTimerAction()
+ {
// TODO
- } // stillInsideTimerAction()
-
-
- //-------------------------------------------------------------
- // Methods ----------------------------------------------------
- //-------------------------------------------------------------
+ }
/**
* actionPerformed
* @param event TODO
*/
- public void actionPerformed(ActionEvent event) {
+ public void actionPerformed(ActionEvent event)
+ {
// TODO
- } // actionPerformed()
-
-
- } // stillInsideTimerAction
+ }
+ }
/**
* outsideTimerAction
*/
- protected class outsideTimerAction implements ActionListener {
-
- //-------------------------------------------------------------
- // Variables --------------------------------------------------
- //-------------------------------------------------------------
-
-
- //-------------------------------------------------------------
- // Initialization ---------------------------------------------
- //-------------------------------------------------------------
-
+ protected class outsideTimerAction
+ implements ActionListener
+ {
/**
* Constructor outsideTimerAction
- * @param manager TODO
*/
- protected outsideTimerAction(ToolTipManager manager) {
+ protected outsideTimerAction()
+ {
// TODO
- } // outsideTimerAction()
-
-
- //-------------------------------------------------------------
- // Methods ----------------------------------------------------
- //-------------------------------------------------------------
+ }
/**
* actionPerformed
* @param value0 TODO
*/
- public void actionPerformed(ActionEvent event) {
+ public void actionPerformed(ActionEvent event)
+ {
// TODO
- } // actionPerformed()
-
-
- } // outsideTimerAction
+ }
+ }
/**
* insideTimerAction
*/
- protected class insideTimerAction implements ActionListener {
-
- //-------------------------------------------------------------
- // Variables --------------------------------------------------
- //-------------------------------------------------------------
-
-
- //-------------------------------------------------------------
- // Initialization ---------------------------------------------
- //-------------------------------------------------------------
-
+ protected class insideTimerAction
+ implements ActionListener
+ {
/**
* Constructor insideTimerAction
- * @param manager TODO
*/
- protected insideTimerAction(ToolTipManager manager) {
+ protected insideTimerAction()
+ {
// TODO
- } // insideTimerAction()
-
-
- //-------------------------------------------------------------
- // Methods ----------------------------------------------------
- //-------------------------------------------------------------
+ }
/**
* actionPerformed
* @param event TODO
*/
- public void actionPerformed(ActionEvent event) {
+ public void actionPerformed(ActionEvent event)
+ {
// TODO
- } // actionPerformed()
-
-
- } // insideTimerAction
-
-
- //-------------------------------------------------------------
- // Variables --------------------------------------------------
- //-------------------------------------------------------------
+ }
+ }
/**
* enterTimer
*/
protected boolean heavyWeightPopupEnabled;
-
- //-------------------------------------------------------------
- // Initialization ---------------------------------------------
- //-------------------------------------------------------------
-
/**
* Constructor ToolTipManager
*/
- ToolTipManager() {
+ ToolTipManager()
+ {
// TODO
- } // ToolTipManager()
-
-
- //-------------------------------------------------------------
- // Methods ----------------------------------------------------
- //-------------------------------------------------------------
+ }
/**
* sharedInstance
- * @returns ToolTipManager
+ * @return ToolTipManager
*/
- public static ToolTipManager sharedInstance() {
+ public static ToolTipManager sharedInstance()
+ {
return null; // TODO
- } // sharedInstance()
+ }
/**
* setEnabled
* @param enabled TODO
*/
- public void setEnabled(boolean enabled) {
+ public void setEnabled(boolean enabled)
+ {
// TODO
- } // setEnabled()
+ }
/**
* isEnabled
- * @returns boolean
+ * @return boolean
*/
- public boolean isEnabled() {
+ public boolean isEnabled()
+ {
return false; // TODO
- } // isEnabled()
+ }
/**
* isLightWeightPopupEnabled
- * @returns boolean
+ * @return boolean
*/
- public boolean isLightWeightPopupEnabled() {
+ public boolean isLightWeightPopupEnabled()
+ {
return false; // TODO
- } // isLightWeightPopupEnabled()
+ }
/**
* setLightWeightPopupEnabled
* @param enabled TODO
*/
- public void setLightWeightPopupEnabled(boolean enabled) {
+ public void setLightWeightPopupEnabled(boolean enabled)
+ {
// TODO
- } // setLightWeightPopupEnabled()
+ }
/**
* getInitialDelay
- * @returns int
+ * @return int
*/
- public int getInitialDelay() {
+ public int getInitialDelay()
+ {
return 0; // TODO
- } // getInitialDelay()
+ }
/**
* setInitialDelay
* @param delay TODO
*/
- public void setInitialDelay(int delay) {
+ public void setInitialDelay(int delay)
+ {
// TODO
- } // setInitialDelay()
+ }
/**
* getDismissDelay
- * @returns int
+ * @return int
*/
- public int getDismissDelay() {
+ public int getDismissDelay()
+ {
return 0; // TODO
- } // getDismissDelay()
+ }
/**
* setDismissDelay
* @param delay TODO
*/
- public void setDismissDelay(int delay) {
+ public void setDismissDelay(int delay)
+ {
// TODO
- } // setDismissDelay()
+ }
/**
* getReshowDelay
- * @returns int
+ * @return int
*/
- public int getReshowDelay() {
+ public int getReshowDelay()
+ {
return 0; // TODO
- } // getReshowDelay()
+ }
/**
* setReshowDelay
* @param delay TODO
*/
- public void setReshowDelay(int delay) {
+ public void setReshowDelay(int delay)
+ {
// TODO
- } // setReshowDelay()
+ }
/**
* registerComponent
* @param component TODO
*/
- public void registerComponent(JComponent component) {
+ public void registerComponent(JComponent component)
+ {
// TODO
- } // registerComponent()
+ }
/**
* unregisterComponent
* @param component TODO
*/
- public void unregisterComponent(JComponent component) {
+ public void unregisterComponent(JComponent component)
+ {
// TODO
- } // unregisterComponent()
+ }
/**
* mouseEntered
* @param event TODO
*/
- public void mouseEntered(MouseEvent event) {
+ public void mouseEntered(MouseEvent event)
+ {
// TODO
- } // mouseEntered()
+ }
/**
* mouseExited
* @param event TODO
*/
- public void mouseExited(MouseEvent event) {
+ public void mouseExited(MouseEvent event)
+ {
// TODO
- } // mouseExited()
+ }
/**
* mousePressed
* @param event TODO
*/
- public void mousePressed(MouseEvent event) {
+ public void mousePressed(MouseEvent event)
+ {
// TODO
- } // mousePressed()
+ }
/**
* mouseDragged
* @param event TODO
*/
- public void mouseDragged(MouseEvent event) {
+ public void mouseDragged(MouseEvent event)
+ {
// TODO
- } // mouseDragged()
+ }
/**
* mouseMoved
* @param event TODO
*/
- public void mouseMoved(MouseEvent event) {
+ public void mouseMoved(MouseEvent event)
+ {
// TODO
- } // mouseMoved()
-
-
-} // ToolTipManager
+ }
+}
import java.awt.Insets;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
import java.lang.reflect.Method;
-import java.util.HashSet;
import java.util.Hashtable;
-import java.util.Iterator;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Locale;
*/
public class UIDefaults extends Hashtable
{
+ private LinkedList bundles;
+ private Locale defaultLocale;
+ private PropertyChangeSupport propertyChangeSupport;
- LinkedList bundles;
- Set listeners;
- Locale defaultLocale;
-
- interface ActiveValue
+ public interface ActiveValue
{
Object createValue(UIDefaults table);
- } // interface ActiveValue
+ }
public static class LazyInputMap implements LazyValue
{
}
return im;
}
- } // class LazyInputMap
+ }
- interface LazyValue
+ public interface LazyValue
{
Object createValue(UIDefaults table);
- } // interface LazyValue
+ }
public static class ProxyLazyValue implements LazyValue
{
{
return inner.createValue (table);
}
- } // class ProxyLazyValue
+ }
private static final long serialVersionUID = 7341222528856548117L;
public UIDefaults()
{
bundles = new LinkedList ();
- listeners = new HashSet ();
defaultLocale = Locale.getDefault ();
+ propertyChangeSupport = new PropertyChangeSupport(this);
}
public UIDefaults(Object[] entries)
{
- bundles = new LinkedList ();
- listeners = new HashSet ();
- defaultLocale = Locale.getDefault ();
+ this();
for (int i = 0; (2*i+1) < entries.length; ++i)
- {
put (entries[2*i], entries[2*i+1]);
}
- }
public Object get(Object key)
{
getUIError ("InvocationTargetException ("+ ite.getTargetException()
+") calling createUI(...) on " + cls.toString ());
return null;
-
}
catch (Exception e)
{
}
}
- void addPropertyChangeListener(PropertyChangeListener listener)
+ public void addPropertyChangeListener(PropertyChangeListener listener)
{
- listeners.add (listener);
+ propertyChangeSupport.addPropertyChangeListener(listener);
}
void removePropertyChangeListener(PropertyChangeListener listener)
{
- listeners.remove (listener);
+ propertyChangeSupport.removePropertyChangeListener(listener);
}
public PropertyChangeListener[] getPropertyChangeListeners()
{
- return (PropertyChangeListener[]) listeners.toArray ();
+ return propertyChangeSupport.getPropertyChangeListeners();
}
- protected void firePropertyChange(String property, Object o, Object n)
+ protected void firePropertyChange(String property,
+ Object oldValue, Object newValue)
{
- Iterator i = listeners.iterator ();
- PropertyChangeEvent pce = new PropertyChangeEvent (this, property, o, n);
- while (i.hasNext ())
- {
- PropertyChangeListener pcl = (PropertyChangeListener) i.next ();
- pcl.propertyChange (pce);
- }
+ propertyChangeSupport.firePropertyChange(property, oldValue, newValue);
}
- void addResourceBundle(String name)
+ public void addResourceBundle(String name)
{
bundles.addFirst (name);
}
- void removeResourceBundle(String name)
+ public void removeResourceBundle(String name)
{
bundles.remove (name);
}
- void setDefaultLocale(Locale loc)
+ public void setDefaultLocale(Locale loc)
{
defaultLocale = loc;
}
{
return defaultLocale;
}
-} // class UIDefaults
+}
// Do nothing here.
}
+ /**
+ * Add a <code>PropertyChangeListener</code> to the listener list.
+ *
+ * @param listener the listener to add
+ */
public static void addPropertyChangeListener (PropertyChangeListener listener)
{
// FIXME
}
+ /**
+ * Remove a <code>PropertyChangeListener</code> from the listener list.
+ *
+ * @param listener the listener to remove
+ */
public static void removePropertyChangeListener (PropertyChangeListener listener)
- // Remove a PropertyChangeListener from the listener list.
{
// FIXME
}
/**
+ * Returns an array of all added <code>PropertyChangeListener</code> objects.
+ *
+ * @return an array of listeners
+ *
* @since 1.4
*/
public static PropertyChangeListener[] getPropertyChangeListeners ()
throw new Error ("Not implemented");
}
+ /**
+ * Add a LookAndFeel to the list of auxiliary look and feels.
+ */
public static void addAuxiliaryLookAndFeel (LookAndFeel l)
{
- // Add a LookAndFeel to the list of auxiliary look and feels.
if (aux_installed == null)
{
aux_installed = new LookAndFeel[1];
return (Font) getLookAndFeel().getDefaults().get(key);
}
+ /**
+ * Returns an Icon from the defaults table.
+ */
public static Icon getIcon(Object key)
- // Returns an Icon from the defaults table.
{
return (Icon) getLookAndFeel().getDefaults().get(key);
}
+ /**
+ * Returns an Insets object from the defaults table.
+ */
public static Insets getInsets(Object key)
- // Returns an Insets object from the defaults table.
{
return (Insets) getLookAndFeel().getDefaults().getInsets(key);
}
return getLookAndFeel().getDefaults();
}
+ /**
+ * Returns a string from the defaults table.
+ */
public static String getString(Object key)
- // Returns a string from the defaults table.
{
return (String) getLookAndFeel().getDefaults().get(key);
}
+ /**
+ * Returns the name of the LookAndFeel class that implements the
+ * native systems look and feel if there is one, otherwise the name
+ * of the default cross platform LookAndFeel class.
+ */
public static String getSystemLookAndFeelClassName()
- // Returns the name of the LookAndFeel class that implements the native systems look and feel if there is one, otherwise the name of the default cross platform LookAndFeel class.
{
return getCrossPlatformLookAndFeelClassName();
}
+ /**
+ * Returns the L&F object that renders the target component.
+ */
public static ComponentUI getUI(JComponent target)
- // Returns the Look and Feel object that renders the target component.
{
- ComponentUI ui = getDefaults().getUI(target);
- //System.out.println("GET-UI-> " + ui + ", for " + target);
- return ui;
+ return getDefaults().getUI(target);
}
+ /**
+ * Creates a new look and feel and adds it to the current array.
+ */
public static void installLookAndFeel(String name, String className)
- // Creates a new look and feel and adds it to the current array.
{
}
+ /**
+ * Adds the specified look and feel to the current array and then calls
+ * setInstalledLookAndFeels(javax.swing.UIManager.LookAndFeelInfo[]).
+ */
public static void installLookAndFeel(LookAndFeelInfo info)
- // Adds the specified look and feel to the current array and then calls setInstalledLookAndFeels(javax.swing.UIManager.LookAndFeelInfo[]).
{
}
+ /**
+ * Stores an object in the defaults table.
+ */
public static Object put(Object key, Object value)
- // Stores an object in the defaults table.
{
return getLookAndFeel().getDefaults().put(key,value);
}
+ /**
+ * Replaces the current array of installed LookAndFeelInfos.
+ */
public static void setInstalledLookAndFeels(UIManager.LookAndFeelInfo[] infos)
- // Replaces the current array of installed LookAndFeelInfos.
{
}
+ /**
+ * Set the current default look.
+ */
public static void setLookAndFeel(LookAndFeel newLookAndFeel)
+ throws UnsupportedLookAndFeelException
{
+ if (! newLookAndFeel.isSupportedLookAndFeel())
+ throw new UnsupportedLookAndFeelException(newLookAndFeel.getName());
+
if (look_and_feel != null)
look_and_feel.uninitialize();
//repaint();
}
+ /**
+ * Set the current default look and feel using a class name.
+ */
public static void setLookAndFeel (String className)
throws ClassNotFoundException, InstantiationException, IllegalAccessException,
UnsupportedLookAndFeelException
{
- // Set the current default look and feel using a class name.
Class c = Class.forName(className);
LookAndFeel a = (LookAndFeel) c.newInstance(); // throws class-cast-exception
setLookAndFeel(a);
{
JViewport vp = (JViewport)parent;
Component view = vp.getView();
- if (view instanceof Scrollable)
- {
- Scrollable sc = (Scrollable) view;
- Dimension d = sc.getPreferredScrollableViewportSize();
- return d;
- }
- else
return view.getPreferredSize();
}
public Dimension minimumLayoutSize(Container parent)
// the viewport require inputs in view space.
Rectangle portBounds = port.getViewRect();
- Dimension viewSize = port.getViewSize();
+ Dimension viewPref = view.getPreferredSize();
Dimension viewMinimum = view.getMinimumSize();
Point portLowerRight = new Point(portBounds.x + portBounds.width,
portBounds.y + portBounds.height);
if (portBounds.height >= viewMinimum.height)
{
portBounds.y = 0;
- viewSize.height = portBounds.height;
+ viewPref.height = portBounds.height;
}
else
{
- viewSize.height = viewMinimum.height;
- int overextension = portLowerRight.y - viewSize.height;
+ viewPref.height = viewMinimum.height;
+ int overextension = portLowerRight.y - viewPref.height;
if (overextension > 0)
portBounds.y -= overextension;
}
if (portBounds.width >= viewMinimum.width)
{
portBounds.x = 0;
- viewSize.width = portBounds.width;
+ viewPref.width = portBounds.width;
}
else
{
- viewSize.width = viewMinimum.width;
- int overextension = portLowerRight.x - viewSize.width;
+ viewPref.width = viewMinimum.width;
+ int overextension = portLowerRight.x - viewPref.width;
if (overextension > 0)
portBounds.x -= overextension;
}
port.setViewPosition(portBounds.getLocation());
- port.setViewSize(viewSize);
+ port.setViewSize(viewPref);
}
}
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
+import java.awt.Insets;
import java.awt.Graphics;
import java.awt.Polygon;
import java.awt.Rectangle;
+import javax.swing.border.Border;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.SwingConstants;
/** The top and left edges of the button. */
private transient Color highlight = Color.BLACK;
+ /** The border around the ArrowButton. */
+ private transient Border tmpBorder = new Border()
+ {
+ public Insets getBorderInsets(Component c)
+ {
+ return new Insets(0, 0, 0, 0);
+ }
+
+ public boolean isBorderOpaque()
+ {
+ return false;
+ }
+
+ public void paintBorder(Component c, Graphics g, int x, int y, int w, int h)
+ {
+ Rectangle bounds = getBounds();
+
+ Color saved = g.getColor();
+ g.setColor(highlight);
+
+ g.drawLine(bounds.x, bounds.y, bounds.x, bounds.y + bounds.height);
+ g.drawLine(bounds.x, bounds.y, bounds.x + bounds.width, bounds.y);
+
+ g.setColor(shadow);
+
+ g.drawLine(bounds.x + 1, bounds.y + bounds.height - 1,
+ bounds.x + bounds.width - 1, bounds.y + bounds.height - 1);
+ g.drawLine(bounds.x + bounds.width - 1, bounds.y + 1,
+ bounds.x + bounds.width - 1, bounds.y + bounds.height - 1);
+
+ g.setColor(darkShadow);
+
+ g.drawLine(bounds.x, bounds.y + bounds.height, bounds.x + bounds.width,
+ bounds.y + bounds.height);
+ g.drawLine(bounds.x + bounds.width, bounds.y, bounds.x + bounds.width,
+ bounds.y + bounds.height);
+
+ g.setColor(saved);
+ }
+ };
+
/**
* Creates a new BasicArrowButton object.
*
{
super();
setDirection(direction);
+ setBorder(tmpBorder);
}
/**
public void paint(Graphics g)
{
super.paint(g);
- Rectangle bounds = getBounds();
-
- Color saved = g.getColor();
- g.setColor(highlight);
-
- g.drawLine(bounds.x, bounds.y, bounds.x, bounds.y + bounds.height);
- g.drawLine(bounds.x, bounds.y, bounds.x + bounds.width, bounds.y);
-
- g.setColor(shadow);
-
- g.drawLine(bounds.x + 1, bounds.y + bounds.height - 1,
- bounds.x + bounds.width - 1, bounds.y + bounds.height - 1);
- g.drawLine(bounds.x + bounds.width - 1, bounds.y + 1,
- bounds.x + bounds.width - 1, bounds.y + bounds.height - 1);
-
- g.setColor(darkShadow);
-
- g.drawLine(bounds.x, bounds.y + bounds.height, bounds.x + bounds.width,
- bounds.y + bounds.height);
- g.drawLine(bounds.x + bounds.width, bounds.y, bounds.x + bounds.width,
- bounds.y + bounds.height);
-
- g.setColor(saved);
}
/**
{
/** A constant used to pad out elements in the button's layout and
preferred size calculations. */
- int defaultTextIconGap = 3;
+ int defaultTextIconGap = 4;
/** A constant added to the defaultTextIconGap to adjust the text
within this particular button. */
b.setBackground(defaults.getColor("Button.background"));
b.setMargin(defaults.getInsets("Button.margin"));
b.setBorder(defaults.getBorder("Button.border"));
+ b.setIconTextGap(defaults.getInt("Button.textIconGap"));
b.setOpaque(true);
}
b.setForeground(null);
b.setBackground(null);
b.setBorder(null);
+ b.setIconTextGap(defaultTextIconGap);
b.setMargin(null);
}
b.getVerticalTextPosition(),
b.getHorizontalTextPosition(),
vr, ir, tr,
- defaultTextIconGap
+ b.getIconTextGap()
+ defaultTextShiftOffset);
if ((b.getModel().isArmed() && b.getModel().isPressed())
|| b.isSelected())
- paintButtonPressed(g, br, c);
+ paintButtonPressed(g, b);
else
paintButtonNormal(g, br, c);
paintIcon(g, c, ir);
if (text != null)
- paintText(g, c, tr, b.getText());
- paintFocus(g, c, vr, tr, ir);
+ paintText(g, b, tr, text);
+ paintFocus(g, b, vr, tr, ir);
}
/**
* "focusPainted" property is <code>true</code>.
*
* @param g Graphics context to paint with
- * @param c Component to paint the focus of
+ * @param b Button to paint the focus of
* @param vr Visible rectangle, the area in which to paint
* @param tr Text rectangle, contained in visible rectangle
* @param ir Icon rectangle, contained in visible rectangle
* @see AbstractButton.isFocusPainted()
* @see JComponent.hasFocus()
*/
- protected void paintFocus(Graphics g, JComponent c, Rectangle vr,
+ protected void paintFocus(Graphics g, AbstractButton b, Rectangle vr,
Rectangle tr, Rectangle ir)
{
- AbstractButton b = (AbstractButton) c;
if (b.hasFocus() && b.isFocusPainted())
{
Graphics2D g2 = (Graphics2D) g;
* pressedBackgroundColor}.
*
* @param g The graphics context to paint with
- * @param area The area in which to paint
- * @param b The component to paint the state of
+ * @param b The button to paint the state of
*/
- protected void paintButtonPressed(Graphics g, Rectangle area, JComponent b)
+ protected void paintButtonPressed(Graphics g, AbstractButton b)
{
- if (((AbstractButton)b).isContentAreaFilled())
+ if (b.isContentAreaFilled())
{
+ Rectangle area = new Rectangle();
+ SwingUtilities.calculateInnerArea(b, area);
g.setColor(b.getBackground().darker());
g.fillRect(area.x, area.y, area.width, area.height);
}
* @param area The area in which to paint
* @param b The component to paint the state of
*/
- protected void paintButtonNormal(Graphics g, Rectangle area, JComponent b)
+ private void paintButtonNormal(Graphics g, Rectangle area, JComponent b)
{
if (((AbstractButton)b).isContentAreaFilled() && b.isOpaque())
{
protected void paintText(Graphics g, JComponent c, Rectangle textRect,
String text)
{
- Font f = c.getFont();
+ paintText(g, (AbstractButton) c, textRect, text);
+ }
+
+ /**
+ * Paints the "text" property of an {@link AbstractButton}, using the
+ * {@link textColor} color.
+ *
+ * @param g The graphics context to paint with
+ * @param b The button to paint the state of
+ * @param textRect The area in which to paint the text
+ * @param text The text to paint
+ *
+ * @since 1.4
+ */
+ protected void paintText(Graphics g, AbstractButton b, Rectangle textRect,
+ String text)
+ {
+ Font f = b.getFont();
g.setFont(f);
FontMetrics fm = g.getFontMetrics(f);
- if (c.isEnabled())
+ if (b.isEnabled())
{
- g.setColor(c.getForeground());
+ g.setColor(b.getForeground());
g.drawString(text, textRect.x, textRect.y + fm.getAscent());
}
else
{
- g.setColor(c.getBackground().brighter());
+ g.setColor(b.getBackground().brighter());
g.drawString(text, textRect.x, textRect.y + fm.getAscent());
- g.setColor(c.getBackground().darker());
+ g.setColor(b.getBackground().darker());
g.drawString(text, textRect.x + 1, textRect.y + fm.getAscent() + 1);
}
}
public class BasicCheckBoxMenuItemUI extends BasicMenuItemUI
{
/**
- * DOCUMENT ME!
+ * Factory method to create a BasicCheckBoxMenuItemUI for the given {@link
+ * JComponent}, which should be a JCheckBoxMenuItem
*
- * @param c DOCUMENT ME!
+ * @param c The {@link JComponent} a UI is being created for.
*
- * @return $returnType$ DOCUMENT ME!
+ * @return A BasicCheckBoxMenuItemUI for the {@link JComponent}.
*/
public static ComponentUI createUI(final JComponent c)
{
*/
protected String getPropertyPrefix()
{
- return null; // TODO
+ return null;
}
/**
- * DOCUMENT ME!
+ * This method installs the defaults that are defined in the Basic look and
+ * feel for this JRadioButtonMenuItem
*/
protected void installDefaults()
{
* @param path DOCUMENT ME!
* @param manager DOCUMENT ME!
*/
- void processMouseEvent(JMenuItem item, MouseEvent e, MenuElement[] path,
+ public void processMouseEvent(JMenuItem item, MouseEvent e,
+ MenuElement[] path,
MenuSelectionManager manager)
{
}
package javax.swing.plaf.basic;
+import java.awt.AWTEvent;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
/** The direction that the resize is occuring in. */
private transient int direction = -1;
+ /** Cache rectangle that can be reused. */
+ private transient Rectangle cacheRect = new Rectangle();
+
/**
* This method is called when the mouse is clicked.
*
return;
DesktopManager dm = getDesktopManager();
Rectangle b = frame.getBounds();
+ Dimension min = frame.getMinimumSize();
+ if (min == null)
+ min = new Dimension(0, 0);
Insets insets = frame.getInsets();
int x = e.getX();
int y = e.getY();
switch (direction)
{
case NORTH:
- dm.resizeFrame(frame, b.x, b.y + y, b.width, b.height - y);
+ cacheRect.setBounds(b.x,
+ Math.min(b.y + y, b.y + b.height
+ - min.height), b.width, b.height
+ - y);
break;
case NORTH_EAST:
- dm.resizeFrame(frame, b.x, b.y + y, x, b.height - y);
+ cacheRect.setBounds(b.x,
+ Math.min(b.y + y, b.y + b.height
+ - min.height), x, b.height - y);
break;
case EAST:
- dm.resizeFrame(frame, b.x, b.y, x, b.height);
+ cacheRect.setBounds(b.x, b.y, x, b.height);
break;
case SOUTH_EAST:
- dm.resizeFrame(frame, b.x, b.y, x, y);
+ cacheRect.setBounds(b.x, b.y, x, y);
break;
case SOUTH:
- dm.resizeFrame(frame, b.x, b.y, b.width, y);
+ cacheRect.setBounds(b.x, b.y, b.width, y);
break;
case SOUTH_WEST:
- dm.resizeFrame(frame, b.x + x, b.y, b.width - x, y);
+ cacheRect.setBounds(Math.min(b.x + x, b.x + b.width - min.width),
+ b.y, b.width - x, y);
break;
case WEST:
- dm.resizeFrame(frame, b.x + x, b.y, b.width - x, b.height);
+ cacheRect.setBounds(Math.min(b.x + x, b.x + b.width - min.width),
+ 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);
+ cacheRect.setBounds(Math.min(b.x + x, b.x + b.width - min.width),
+ Math.min(b.y + y, b.y + b.height
+ - min.height), b.width - x,
+ b.height - y);
break;
}
+ dm.resizeFrame(frame, cacheRect.x, cacheRect.y,
+ Math.max(min.width, cacheRect.width),
+ Math.max(min.height, cacheRect.height));
}
else if (e.getSource() == titlePane)
{
*/
public Dimension minimumLayoutSize(Container c)
{
- return preferredLayoutSize(c);
+ return getSize(c, true);
}
/**
* @return The preferred dimensions for the JInternalFrame.
*/
public Dimension preferredLayoutSize(Container c)
+ {
+ return getSize(c, false);
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param c DOCUMENT ME!
+ * @param min DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ private Dimension getSize(Container c, boolean min)
{
Insets insets = frame.getInsets();
Dimension contentDims = frame.getContentPane().getPreferredSize();
+ if (min)
+ contentDims.width = contentDims.height = 0;
int nWidth = 0;
int nHeight = 0;
int sWidth = 0;
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);
+ int height = Math.max(eHeight, wHeight);
+ height = Math.max(height, contentDims.height);
height += nHeight + sHeight;
width += insets.left + insets.right;
*/
protected class GlassPaneDispatcher implements MouseInputListener
{
+ /** The MouseEvent target. */
+ private transient Component mouseEventTarget;
+
+ /** The component pressed. */
+ private transient Component pressedComponent;
+
+ /** The last component entered. */
+ private transient Component lastComponentEntered;
+
+ /** The number of presses. */
+ private transient int pressCount;
+
/**
* This method is called when the mouse enters the glass pane.
*
*/
public void mouseEntered(MouseEvent e)
{
- dispatchFor(e);
+ handleEvent(e);
}
/**
*/
public void mouseClicked(MouseEvent e)
{
- dispatchFor(e);
+ handleEvent(e);
}
/**
*/
public void mouseDragged(MouseEvent e)
{
- dispatchFor(e);
+ handleEvent(e);
}
/**
*/
public void mouseExited(MouseEvent e)
{
- dispatchFor(e);
+ handleEvent(e);
}
/**
*/
public void mouseMoved(MouseEvent e)
{
- dispatchFor(e);
+ handleEvent(e);
}
/**
public void mousePressed(MouseEvent e)
{
activateFrame(frame);
- dispatchFor(e);
+ handleEvent(e);
}
/**
*/
public void mouseReleased(MouseEvent e)
{
- dispatchFor(e);
+ handleEvent(e);
}
/**
- * This helper method redispatches the MouseEvent to the proper sub
- * component.
+ * This method acquires a candidate component to dispatch the MouseEvent
+ * to.
*
- * @param e The MouseEvent.
+ * @param me The MouseEvent to acquire a component for.
*/
- private void dispatchFor(MouseEvent e)
+ private void acquireComponentForMouseEvent(MouseEvent me)
{
- Component candidate = SwingUtilities.getDeepestComponentAt(frame.getRootPane()
- .getContentPane(),
- e.getX(),
- e.getY());
- if (candidate == null || candidate == frame.getRootPane().getGlassPane())
+ int x = me.getX();
+ int y = me.getY();
+
+ // Find the candidate which should receive this event.
+ Component parent = frame.getContentPane();
+ if (parent == null)
return;
- MouseEvent newevt = SwingUtilities.convertMouseEvent(frame.getRootPane()
+ Component candidate = null;
+ Point p = me.getPoint();
+ while (candidate == null && parent != null)
+ {
+ candidate = SwingUtilities.getDeepestComponentAt(parent, p.x, p.y);
+ if (candidate == null)
+ {
+ p = SwingUtilities.convertPoint(parent, p.x, p.y,
+ parent.getParent());
+ parent = parent.getParent();
+ }
+ }
+
+ // If the only candidate we found was the native container itself,
+ // don't dispatch any event at all. We only care about the lightweight
+ // children here.
+ if (candidate == frame.getContentPane())
+ candidate = null;
+
+ // If our candidate is new, inform the old target we're leaving.
+ if (lastComponentEntered != null && lastComponentEntered.isShowing()
+ && lastComponentEntered != candidate)
+ {
+ Point tp = SwingUtilities.convertPoint(frame.getContentPane(), x, y,
+ lastComponentEntered);
+ MouseEvent exited = new MouseEvent(lastComponentEntered,
+ MouseEvent.MOUSE_EXITED,
+ me.getWhen(), me.getModifiers(),
+ tp.x, tp.y, me.getClickCount(),
+ me.isPopupTrigger(),
+ me.getButton());
+ lastComponentEntered.dispatchEvent(exited);
+ lastComponentEntered = null;
+ }
+
+ // If we have a candidate, maybe enter it.
+ if (candidate != null)
+ {
+ mouseEventTarget = candidate;
+ if (candidate.isLightweight() && candidate.isShowing()
+ && candidate != frame.getContentPane()
+ && candidate != lastComponentEntered)
+ {
+ lastComponentEntered = mouseEventTarget;
+ Point cp = SwingUtilities.convertPoint(frame.getContentPane(),
+ x, y, lastComponentEntered);
+ MouseEvent entered = new MouseEvent(lastComponentEntered,
+ MouseEvent.MOUSE_ENTERED,
+ me.getWhen(),
+ me.getModifiers(), cp.x,
+ cp.y, me.getClickCount(),
+ me.isPopupTrigger(),
+ me.getButton());
+ lastComponentEntered.dispatchEvent(entered);
+ }
+ }
+
+ if (me.getID() == MouseEvent.MOUSE_RELEASED
+ || me.getID() == MouseEvent.MOUSE_PRESSED && pressCount > 0
+ || me.getID() == MouseEvent.MOUSE_DRAGGED)
+ // If any of the following events occur while a button is held down,
+ // they should be dispatched to the same component to which the
+ // original MOUSE_PRESSED event was dispatched:
+ // - MOUSE_RELEASED
+ // - MOUSE_PRESSED: another button pressed while the first is held down
+ // - MOUSE_DRAGGED
+ mouseEventTarget = pressedComponent;
+ else if (me.getID() == MouseEvent.MOUSE_CLICKED)
+ {
+ // Don't dispatch CLICKED events whose target is not the same as the
+ // target for the original PRESSED event.
+ if (candidate != pressedComponent)
+ mouseEventTarget = null;
+ else if (pressCount == 0)
+ pressedComponent = null;
+ }
+ }
+
+ /**
+ * This is a helper method that dispatches the GlassPane MouseEvents to
+ * the proper component.
+ *
+ * @param e The AWTEvent to be dispatched. Usually an instance of
+ * MouseEvent.
+ */
+ private void handleEvent(AWTEvent e)
+ {
+ if (e instanceof MouseEvent)
+ {
+ MouseEvent me = SwingUtilities.convertMouseEvent(frame.getRootPane()
.getGlassPane(),
- e, candidate);
- candidate.dispatchEvent(newevt);
+ (MouseEvent) e,
+ frame.getRootPane()
+ .getGlassPane());
+
+ acquireComponentForMouseEvent(me);
+
+ // Avoid dispatching ENTERED and EXITED events twice.
+ if (mouseEventTarget != null && mouseEventTarget.isShowing()
+ && e.getID() != MouseEvent.MOUSE_ENTERED
+ && e.getID() != MouseEvent.MOUSE_EXITED)
+ {
+ MouseEvent newEvt = SwingUtilities.convertMouseEvent(frame
+ .getContentPane(),
+ me,
+ mouseEventTarget);
+ mouseEventTarget.dispatchEvent(newEvt);
+
+ switch (e.getID())
+ {
+ case MouseEvent.MOUSE_PRESSED:
+ if (pressCount++ == 0)
+ pressedComponent = mouseEventTarget;
+ break;
+ case MouseEvent.MOUSE_RELEASED:
+ // Clear our memory of the original PRESSED event, only if
+ // we're not expecting a CLICKED event after this. If
+ // there is a CLICKED event after this, it will do clean up.
+ if (--pressCount == 0
+ && mouseEventTarget != pressedComponent)
+ pressedComponent = null;
+ break;
+ }
+ }
+ }
}
}
*/
public Dimension getMinimumSize(JComponent x)
{
- return getPreferredSize(x);
+ return internalFrameLayout.minimumLayoutSize(x);
}
/**
*/
public void contentsChanged(ListDataEvent e)
{
- // System.err.println(this + ".contentsChanged(" + e + ")");
BasicListUI.this.damageLayout();
}
*/
public void intervalAdded(ListDataEvent e)
{
- // System.err.println(this + ".intervalAdded(" + e + ")");
BasicListUI.this.damageLayout();
}
*/
public void intervalRemoved(ListDataEvent e)
{
- // System.err.println(this + ".intervalRemoved(" + e + ")");
BasicListUI.this.damageLayout();
}
}
*/
public void valueChanged(ListSelectionEvent e)
{
- // System.err.println(this + ".valueChanged(" + e + ")");
}
}
*/
public void mousePressed(MouseEvent event)
{
- // System.err.println("got mouse click event " + event);
int row = BasicListUI.this.convertYToRow(event.getY());
if (row == -1)
return;
- // System.err.println("clicked on row " + row);
BasicListUI.this.list.setSelectedIndex(row);
}
*/
public void propertyChange(PropertyChangeEvent e)
{
- // System.err.println(this + ".propertyChange(" + e + ")");
if (e.getSource() == BasicListUI.this.list)
{
if (e.getOldValue() != null && e.getOldValue() instanceof ListModel)
*/
public Rectangle getCellBounds(JList l, int index1, int index2)
{
+ maybeUpdateLayoutState();
+
if (l != list || cellWidth == -1)
return null;
getRowHeight(lo));
Rectangle hibounds = new Rectangle(0, convertRowToY(hi), cellWidth,
getRowHeight(hi));
+
return lobounds.union(hibounds);
}
{
int h = getRowHeight(row);
- // System.err.println("convertYToRow(" + y0 + ") vs. " + h);
if (y0 < h)
return row;
y0 -= h;
*/
void maybeUpdateLayoutState()
{
- // System.err.println(this + ".maybeUpdateLayoutState()");
if (updateLayoutStateNeeded != 0)
{
updateLayoutState();
installDefaults();
installListeners();
installKeyboardActions();
- // System.err.println(this + ".installUI()");
maybeUpdateLayoutState();
}
*/
public Dimension getPreferredSize(JComponent c)
{
- maybeUpdateLayoutState();
if (list.getModel().getSize() == 0)
return new Dimension(0, 0);
- int nrows = Math.min(list.getVisibleRowCount(), list.getModel().getSize());
- Rectangle bounds = getCellBounds(list, 0, nrows - 1);
+ Rectangle bounds = getCellBounds(list, 0, list.getModel().getSize() - 1);
return bounds.getSize();
}
*/
public void paint(Graphics g, JComponent c)
{
- int nrows = Math.min(list.getVisibleRowCount(), list.getModel().getSize());
+ int nrows = list.getModel().getSize();
if (nrows == 0)
return;
ListModel model = list.getModel();
ListSelectionModel sel = list.getSelectionModel();
int lead = sel.getLeadSelectionIndex();
+ Rectangle clip = g.getClipBounds();
paintBackground(g, list);
for (int row = 0; row < nrows; ++row)
{
Rectangle bounds = getCellBounds(list, row, row);
+ if (bounds.intersects(clip))
paintCell(g, row, bounds, render, model, sel, lead);
}
}
"Button.foreground", new ColorUIResource(Color.black),
"Button.highlight", new ColorUIResource(Color.white),
"Button.light", new ColorUIResource(Color.lightGray.brighter()),
- "Button.margin", new InsetsUIResource(2, 2, 2, 2),
+ "Button.margin", new InsetsUIResource(2, 14, 2, 14),
"Button.shadow", new ColorUIResource(Color.gray),
"Button.textIconGap", new Integer(4),
"Button.textShiftOffset", new Integer(0),
"ENTER", "return",
"SPACE", "return"
},
- "Menutext.selectionBackground", new ColorUIResource(lightPurple),
+ "Menu.selectionBackground", new ColorUIResource(lightPurple),
"Menu.selectionForeground", new ColorUIResource(Color.black),
"MenuBar.background", new ColorUIResource(Color.lightGray),
"MenuBar.border", new BasicBorders.MenuBarBorder(null, null),
"ToolBar.background", new ColorUIResource(Color.lightGray),
"ToolBar.border", new BorderUIResource.EtchedBorderUIResource(),
"ToolBar.dockingBackground", new ColorUIResource(Color.lightGray),
- "ToolBar.dockingForeground", new ColorUIResource(Color.red),
+ "ToolBar.dockingForeground", new ColorUIResource(11, 30, 143),
"ToolBar.floatingBackground", new ColorUIResource(Color.lightGray),
- "ToolBar.floatingForeground", new ColorUIResource(Color.darkGray),
+ "ToolBar.floatingForeground", new ColorUIResource(113, 171, 212),
"ToolBar.font", new FontUIResource("Dialog", Font.PLAIN, 12),
"ToolBar.foreground", new ColorUIResource(Color.black),
- "ToolBar.separatorSize", new DimensionUIResource(10, 10),
+ "ToolBar.separatorSize", new DimensionUIResource(20, 20),
"ToolTip.background", new ColorUIResource(Color.white),
"ToolTip.border", new BorderUIResource.LineBorderUIResource(Color.lightGray),
"ToolTip.font", new FontUIResource("SansSerif", Font.PLAIN, 12),
}
/**
- * DOCUMENT ME!
+ * Creates ChangeListener
*
- * @return DOCUMENT ME!
+ * @return The ChangeListener
*/
protected ChangeListener createChangeListener()
{
/**
* Creates ContainerListener() to listen for ContainerEvents
- * fired by JMenuBar
+ * fired by JMenuBar.
*
* @return The ContainerListener
*/
}
/**
- * DOCUMENT ME!
+ * Unregisters all the listeners that this UI delegate was using.
*/
protected void uninstallListeners()
{
}
/**
- * This class handles ContainerEvents fired by JMenuBar
+ * This class handles ContainerEvents fired by JMenuBar. It revalidates
+ * and repaints menu bar whenever menu is added or removed from it.
*/
protected class ContainerHandler implements ContainerListener
{
*/
public void componentAdded(ContainerEvent e)
{
- System.out.println("BasicMenuBar...componentAdded.. listener");
+ menuBar.revalidate();
+ menuBar.repaint();
}
/**
- * This method is called whenever menu is removed from the menu bar
+ * 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");
+ menuBar.revalidate();
+ menuBar.repaint();
}
}
{
if (e.getPropertyName().equals(JMenuBar.BORDER_PAINTED_CHANGED_PROPERTY))
menuBar.repaint();
+ if (e.getPropertyName().equals(JMenuBar.MARGIN_CHANGED_PROPERTY))
+ menuBar.repaint();
}
}
}
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;
protected Color selectionBackground;
/**
- * Color of the background that is used when menu item is selected.
+ * Color of the text that is used when menu item is selected.
*/
protected Color selectionForeground;
public MenuElement[] getPath()
{
ArrayList path = new ArrayList();
+
+ // Path to menu should also include its popup menu.
+ if (menuItem instanceof JMenu)
+ path.add(((JMenu) menuItem).getPopupMenu());
+
Component c = menuItem;
while (c instanceof MenuElement)
{
protected Dimension getPreferredMenuItemSize(JComponent c, Icon checkIcon,
Icon arrowIcon,
int defaultTextIconGap)
- {
- // FIXME: Need to implement.
- return null;
- }
-
- /**
- * Returns preferred size of the given component
- *
- * @param c component for which to return preferred size
- *
- * @return $Dimension$ preferred size for the given component
- */
- public Dimension getPreferredSize(JComponent c)
{
JMenuItem m = (JMenuItem) c;
Dimension d = BasicGraphicsUtils.getPreferredButtonSize(m,
}
/**
- * DOCUMENT ME!
+ * Returns preferred size of the given component
+ *
+ * @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)
+ {
+ return getPreferredMenuItemSize(c, checkIcon, arrowIcon, defaultTextIconGap);
+ }
+
protected String getPropertyPrefix()
{
return null;
protected void installListeners()
{
menuItem.addMouseListener(mouseInputListener);
+ menuItem.addMouseMotionListener(mouseInputListener);
menuItem.addMenuDragMouseListener(menuDragMouseListener);
menuItem.addMenuKeyListener(menuKeyListener);
menuItem.addPropertyChangeListener(propertyChangeListener);
super.installUI(c);
menuItem = (JMenuItem) c;
installDefaults();
+ installComponents(menuItem);
installListeners();
}
{
if (m.isContentAreaFilled())
{
- g.setColor(m.getBackground().darker());
+ g.setColor(selectionBackground);
g.fillRect(br.x, br.y, br.width, br.height);
}
}
}
}
+ // If this menu item is a JCheckBoxMenuItem then paint check icon
if (checkIcon != null)
{
SwingUtilities.layoutCompoundLabel(m, fm, null, checkIcon, vertAlign,
vr.x = cr.x + cr.width + defaultTextIconGap;
}
+ // if this is a submenu, then paint arrow icon to indicate it.
if (arrowIcon != null && (c instanceof JMenu))
{
if (! ((JMenu) c).isTopLevelMenu())
}
}
- // paint text and user menu icon if it exists
- SwingUtilities.layoutCompoundLabel(c, fm, m.getText(), m.getIcon(),
- vertAlign, horAlign, vertTextPos,
- horTextPos, vr, ir, tr,
- defaultTextIconGap);
-
- 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 = m.getIcon();
if (i != null)
{
- int x = ir.x;
- int y = ir.y;
- i.paintIcon(c, g, x, y);
+ i.paintIcon(c, g, vr.x, vr.y);
+
+ // Adjust view rectangle, s.t text would be drawn after menu item's icon.
+ vr.x += i.getIconWidth() + defaultTextIconGap;
}
- */
+
+ // paint text and user menu icon if it exists
+ SwingUtilities.layoutCompoundLabel(c, fm, m.getText(), m.getIcon(),
+ vertAlign, horAlign, vertTextPos,
+ horTextPos, vr, ir, tr,
+ defaultTextIconGap);
+
+ paintText(g, m, tr, m.getText());
// paint accelerator
String acceleratorText = "";
Font f = menuItem.getFont();
g.setFont(f);
FontMetrics fm = g.getFontMetrics(f);
- g.setColor(menuItem.getForeground());
+ if (text != null && ! text.equals(""))
+ {
+ if (menuItem.isEnabled())
+ g.setColor(menuItem.getForeground());
+ else
+ // FIXME: should fix this to use 'disabledForeground', but its
+ // default value in BasicLookAndFeel is null.
+ g.setColor(Color.gray);
+
+ int mnemonicIndex = menuItem.getDisplayedMnemonicIndex();
+
+ if (mnemonicIndex != -1)
+ BasicGraphicsUtils.drawStringUnderlineCharAt(g, text, mnemonicIndex,
+ textRect.x,
+ textRect.y
+ + fm.getAscent());
+ else
BasicGraphicsUtils.drawString(g, text, 0, textRect.x,
textRect.y + fm.getAscent());
}
+ }
/**
* This method uninstalls the components for this {@link JMenuItem}.
{
uninstallListeners();
uninstallDefaults();
+ uninstallComponents(menuItem);
menuItem = null;
}
{
g.setFont(acceleratorFont);
FontMetrics fm = g.getFontMetrics(acceleratorFont);
+
+ if (menuItem.isEnabled())
g.setColor(acceleratorForeground);
+ else
+ // FIXME: should fix this to use 'disabledForeground', but its
+ // default value in BasicLookAndFeel is null.
+ g.setColor(Color.gray);
+
BasicGraphicsUtils.drawString(g, acceleratorText, 0, acceleratorRect.x,
acceleratorRect.y + fm.getAscent());
}
*/
public void mouseReleased(MouseEvent e)
{
- Rectangle size = menuItem.getBounds(); //this.getParent().getSize();
+ Rectangle size = menuItem.getBounds();
+ MenuSelectionManager manager = MenuSelectionManager.defaultManager();
if (e.getX() > 0 && e.getX() < size.width && e.getY() > 0
&& e.getY() < size.height)
{
- MenuSelectionManager manager = MenuSelectionManager.defaultManager();
manager.clearSelectedPath();
- menuItem.doClick(0);
+ menuItem.doClick();
}
+
+ else
+ manager.processMouseEvent(e);
}
}
*/
public void menuDragMouseDragged(MenuDragMouseEvent e)
{
+ MenuSelectionManager manager = MenuSelectionManager.defaultManager();
+ manager.setSelectedPath(e.getPath());
}
/**
*/
public void menuDragMouseEntered(MenuDragMouseEvent e)
{
+ MenuSelectionManager manager = MenuSelectionManager.defaultManager();
+ manager.setSelectedPath(e.getPath());
}
/**
*/
public void menuDragMouseReleased(MenuDragMouseEvent e)
{
+ MenuElement[] path = e.getPath();
+
+ if (path[path.length - 1] instanceof JMenuItem)
+ ((JMenuItem) path[path.length - 1]).doClick();
+
+ MenuSelectionManager manager = MenuSelectionManager.defaultManager();
+ manager.clearSelectedPath();
}
}
*/
public void propertyChange(PropertyChangeEvent evt)
{
+ menuItem.revalidate();
+ menuItem.repaint();
}
}
}
acceleratorFont = defaults.getFont("Menu.acceleratorFont");
acceleratorForeground = defaults.getColor("Menu.acceleratorForeground");
acceleratorSelectionForeground = defaults.getColor("Menu.acceleratorSelectionForeground");
+ selectionBackground = defaults.getColor("Menu.selectionBackground");
+ selectionForeground = defaults.getColor("Menu.selectionForeground");
arrowIcon = defaults.getIcon("Menu.arrowIcon");
oldBorderPainted = defaults.getBoolean("Menu.borderPainted");
+ menuItem.setOpaque(true);
}
/**
protected void installListeners()
{
((JMenu) menuItem).addMouseListener(mouseInputListener);
+ ((JMenu) menuItem).addMouseMotionListener(mouseInputListener);
((JMenu) menuItem).addMenuListener(menuListener);
+ ((JMenu) menuItem).addMenuDragMouseListener(menuDragMouseListener);
}
protected void setupPostTimer(JMenu menu)
acceleratorFont = null;
acceleratorForeground = null;
acceleratorSelectionForeground = null;
+ selectionBackground = null;
+ selectionForeground = null;
arrowIcon = null;
}
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) menu.getParent()).isSelected() && ! menu.isArmed())))
{
// set new selection and forward this event to MenuSelectionManager
MenuSelectionManager manager = MenuSelectionManager.defaultManager();
public void mousePressed(MouseEvent e)
{
-
MenuSelectionManager manager = MenuSelectionManager.defaultManager();
JMenu menu = (JMenu) menuItem;
manager.processMouseEvent(e);
if (menu.isTopLevelMenu())
{
if (menu.getPopupMenu().isVisible())
- {
// If menu is visible and menu button was pressed..
// then need to cancel the menu
manager.clearSelectedPath();
- }
else
{
// Display the menu
{
/**
* This method is called when menu is cancelled. The menu is cancelled
- * when its popup menu is closed without selection.
+ * when its popup menu is closed without selection. It clears selected index
+ * in the selectionModel of the menu parent.
*
* @param e The MenuEvent.
*/
public void menuCanceled(MenuEvent e)
{
+ menuDeselected(e);
}
/**
- * This method is called when menu is deselected.
+ * This method is called when menu is deselected. It clears selected index
+ * in the selectionModel of the menu parent.
*
* @param e The MenuEvent.
*/
public void menuDeselected(MenuEvent e)
{
+ JMenu menu = (JMenu) menuItem;
+ if (menu.isTopLevelMenu())
+ ((JMenuBar) menu.getParent()).getSelectionModel().clearSelection();
+ else
+ ((JPopupMenu) menu.getParent()).getSelectionModel().clearSelection();
}
/**
- * This method is called when menu is selected.
+ * This method is called when menu is selected. It sets selected index
+ * in the selectionModel of the menu parent.
*
* @param e The MenuEvent.
*/
public void menuSelected(MenuEvent e)
{
+ JMenu menu = (JMenu) menuItem;
+ if (menu.isTopLevelMenu())
+ ((JMenuBar) menu.getParent()).setSelected(menu);
+ else
+ ((JPopupMenu) menu.getParent()).setSelected(menu);
}
}
}
/**
- * This class handles mouse dragged events.
+ * This class handles mouse dragged events occuring in the menu.
*/
protected class MenuDragMouseHandler implements MenuDragMouseListener
{
/**
- * Tbis method is invoked when mouse is dragged over the menu item.
+ * This method is invoked when mouse is dragged over the menu item.
*
* @param e The MenuDragMouseEvent
*/
public void menuDragMouseDragged(MenuDragMouseEvent e)
{
+ MenuSelectionManager manager = MenuSelectionManager.defaultManager();
+ manager.setSelectedPath(e.getPath());
}
/**
- * Tbis method is invoked when mouse enters the menu item while it is
+ * This method is invoked when mouse enters the menu item while it is
* being dragged.
*
* @param e The MenuDragMouseEvent
*/
public void menuDragMouseEntered(MenuDragMouseEvent e)
{
+ MenuSelectionManager manager = MenuSelectionManager.defaultManager();
+ manager.setSelectedPath(e.getPath());
}
/**
- * Tbis method is invoked when mouse exits the menu item while
+ * This method is invoked when mouse exits the menu item while
* it is being dragged
*
* @param e The MenuDragMouseEvent
}
/**
- * Tbis method is invoked when mouse was dragged and released
+ * This method is invoked when mouse was dragged and released
* inside the menu item.
*
* @param e The MenuDragMouseEvent
import java.awt.event.ActionListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
+import java.beans.PropertyVetoException;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.Icon;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JDialog;
+import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
Object value = new Integer(JOptionPane.CLOSED_OPTION);
Object[] options = optionPane.getOptions();
if (options != null)
- value = options[buttonIndex];
+ value = new Integer(buttonIndex);
else
{
String text = ((JButton) e.getSource()).getText();
if (owner instanceof JDialog)
((JDialog) owner).dispose();
+
+ //else we probably have some kind of internal frame.
+ JInternalFrame inf = (JInternalFrame) SwingUtilities.getAncestorOfClass(JInternalFrame.class,
+ optionPane);
+ if (inf != null)
+ {
+ try
+ {
+ inf.setClosed(true);
+ }
+ catch (PropertyVetoException pve)
+ {
+ }
+ }
}
}
toAdd = new JButton((Icon) buttons[i]);
else
toAdd = new JButton(buttons[i].toString());
- ((JButton) toAdd).addActionListener(createButtonActionListener(i));
hasCustomComponents = true;
}
-
+ if (toAdd instanceof JButton)
+ ((JButton) toAdd).addActionListener(createButtonActionListener(i));
if (i == initialIndex)
initialFocusComponent = toAdd;
container.add(toAdd);
{
public Dimension getPreferredSize()
{
- int w = Math.max(optionPane.getSize().width,
- minimumWidth);
+ int w = Math.max(optionPane.getSize().width, minimumWidth);
Insets i = optionPane.getInsets();
Dimension orig = super.getPreferredSize();
Dimension value = new Dimension(w - i.left - i.right - iconSize,
{
Object[] selection = optionPane.getSelectionValues();
+// if (selection == null)
+// inputComponent = new JTextField();
+// else if (selection.length < 20)
+// inputComponent = new JComboBox(selection);
+ // FIXME: Uncomment when the widgets are done.
if (selection == null)
- inputComponent = new JTextField();
- else if (selection.length < 20)
- inputComponent = new JComboBox(selection);
+ inputComponent = null;
else
inputComponent = new JList(selection);
if (inputComponent != null)
tmp = questionIcon;
break;
}
- return new IconUIResource(tmp);
+ return tmp;
+ // FIXME: Don't cast till the default icons are in.
+ // return new IconUIResource(tmp);
}
/**
import java.awt.AWTKeyStroke;
import java.awt.BasicStroke;
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.Graphics2D;
import java.awt.GridBagLayout;
+import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.Rectangle;
import java.awt.Stroke;
+import java.awt.event.ComponentEvent;
+import java.awt.event.ComponentListener;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
/**
- * DOCUMENT ME!
+ * UI Delegate for JPopupMenu
*/
public class BasicPopupMenuUI extends PopupMenuUI
{
+ /* popupMenu for which this UI delegate is for*/
protected JPopupMenu popupMenu;
+
+ /* MouseInputListener listens to mouse events */
private static transient MouseInputListener mouseInputListener;
+
+ /* PopupMenuListener listens to popup menu events fired by JPopupMenu*/
private transient PopupMenuListener popupMenuListener;
+ /* ComponentListener listening to popupMenu's invoker. */
+ private TopWindowListener topWindowListener;
+
/**
* Creates a new BasicPopupMenuUI object.
*/
{
popupMenuListener = new PopupMenuHandler();
mouseInputListener = new MouseInputHandler();
+ topWindowListener = new TopWindowListener();
}
/**
- * DOCUMENT ME!
+ * Factory method to create a BasicPopupMenuUI for the given {@link
+ * JComponent}, which should be a {@link JMenuItem}.
*
- * @param x DOCUMENT ME!
+ * @param x The {@link JComponent} a UI is being created for.
*
- * @return DOCUMENT ME!
+ * @return A BasicPopupMenuUI for the {@link JComponent}.
*/
public static ComponentUI createUI(JComponent x)
{
}
/**
- * 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)
{
popupMenu = (JPopupMenu) c;
popupMenu.setLayout(new GridBagLayout());
popupMenu.setBorderPainted(true);
- popupMenu.setDefaultLightWeightPopupEnabled(true);
+ JPopupMenu.setDefaultLightWeightPopupEnabled(true);
installDefaults();
installListeners();
}
/**
- * DOCUMENT ME!
+ * This method installs the defaults that are defined in the Basic look and
+ * feel for this {@link JPopupMenu}.
*/
public void installDefaults()
{
}
/**
- * DOCUMENT ME!
+ * This method installs the listeners for the {@link JMenuItem}.
*/
protected void installListeners()
{
}
/**
- * DOCUMENT ME!
+ * This method installs the keyboard actions for this {@link JPopupMenu}.
*/
protected void installKeyboardActions()
{
+ // FIXME: Need to implement
}
/**
- * 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)
{
}
/**
- * DOCUMENT ME!
+ * This method uninstalls the defaults and sets any objects created during
+ * install to null
*/
protected void uninstallDefaults()
{
}
/**
- * DOCUMENT ME!
+ * Unregisters all the listeners that this UI delegate was using.
*/
protected void uninstallListeners()
{
+ popupMenu.removeMouseListener(mouseInputListener);
+ popupMenu.removeMouseMotionListener(mouseInputListener);
+ popupMenu.removePopupMenuListener(popupMenuListener);
}
/**
- * DOCUMENT ME!
+ * Uninstalls any keyboard actions.
*/
protected void uninstallKeyboardActions()
{
+ // FIXME: Need to implement
}
/**
- * DOCUMENT ME!
+ * This method returns the minimum size of the JPopupMenu.
*
- * @param c DOCUMENT ME!
+ * @param c The JComponent to find a size for.
*
- * @return DOCUMENT ME!
+ * @return The minimum size.
*/
public Dimension getMinimumSize(JComponent c)
{
}
/**
- * DOCUMENT ME!
+ * This method returns the preferred size of the JPopupMenu.
*
- * @param c DOCUMENT ME!
+ * @param c The JComponent to find a size for.
*
- * @return DOCUMENT ME!
+ * @return The preferred size.
*/
public Dimension getPreferredSize(JComponent c)
{
}
/**
- * DOCUMENT ME!
+ * This method returns the minimum size of the JPopupMenu.
*
- * @param c DOCUMENT ME!
+ * @param c The JComponent to find a size for.
*
- * @return DOCUMENT ME!
+ * @return The minimum size.
*/
public Dimension getMaximumSize(JComponent c)
{
}
/**
- * DOCUMENT ME!
+ * Return true if given mouse event is a platform popup trigger,
+ * and false otherwise
*
- * @param e DOCUMENT ME!
+ * @param e MouseEvent that is to be checked for popup trigger event
*
- * @return DOCUMENT ME!
+ * @return true if given mouse event is a platform popup trigger,
+ * and false otherwise
*/
public boolean isPopupTrigger(MouseEvent e)
{
}
/**
- * DOCUMENT ME!
+ * This listener handles PopupMenuEvents fired by JPopupMenu
*/
- protected class PopupMenuHandler implements PopupMenuListener
+ private class PopupMenuHandler implements PopupMenuListener
{
/**
- * DOCUMENT ME!
+ * This method is invoked when JPopupMenu is cancelled.
*
- * @param event DOCUMENT ME!
+ * @param event the PopupMenuEvent
*/
public void popupMenuCanceled(PopupMenuEvent event)
{
+ MenuSelectionManager manager = MenuSelectionManager.defaultManager();
+ manager.clearSelectedPath();
}
/**
- * DOCUMENT ME!
+ * This method is invoked when JPopupMenu becomes invisible
*
- * @param event DOCUMENT ME!
+ * @param event the PopupMenuEvent
*/
public void popupMenuWillBecomeInvisible(PopupMenuEvent event)
{
+ // remove listener that listens to component events fired
+ // by the top - level window that this popup belongs to.
+ Component invoker = popupMenu.getInvoker();
+
+ Container rootContainer = (Container) SwingUtilities.getRoot(invoker);
+ rootContainer.removeComponentListener(topWindowListener);
}
/**
- * DOCUMENT ME!
+ * This method is invoked when JPopupMenu becomes visible
*
- * @param event DOCUMENT ME!
+ * @param event the PopupMenuEvent
*/
public void popupMenuWillBecomeVisible(PopupMenuEvent event)
{
+ // Adds topWindowListener to top-level window to listener to
+ // ComponentEvents fired by it. We need to cancel this popup menu
+ // if topWindow to which this popup belongs was resized or moved.
+ Component invoker = popupMenu.getInvoker();
+ Container rootContainer = (Container) SwingUtilities.getRoot(invoker);
+ rootContainer.addComponentListener(topWindowListener);
+
+ // if this popup menu is a free floating popup menu,
+ // then by default its first element should be always selected when
+ // this popup menu becomes visible.
+ MenuSelectionManager manager = MenuSelectionManager.defaultManager();
+
+ if (manager.getSelectedPath().length == 0)
+ {
+ // Set selected path to point to the first item in the popup menu
+ MenuElement[] path = new MenuElement[2];
+ path[0] = popupMenu;
+ Component[] comps = popupMenu.getComponents();
+ if (comps.length != 0 && comps[0] instanceof MenuElement)
+ path[1] = (MenuElement) comps[0];
+ manager.setSelectedPath(path);
+ }
}
}
/**
- * DOCUMENT ME!
+ * ComponentListener that listens to Component Events fired by the
+ * top - level window to which popup menu belongs. If top-level
+ * window was resized, moved or hidded then popup menu will
+ * be hidded and selected path of current menu hierarchy will be set
+ * to null.
+ *
*/
- protected class MouseInputHandler implements MouseInputListener
+ private class TopWindowListener implements ComponentListener
{
/**
- * DOCUMENT ME!
+ * This method is invoked when top-level window is resized.
+ * This method closes current menu hierarchy.
*
- * @param e DOCUMENT ME!
+ * @param e The ComponentEvent
*/
- public void mouseClicked(MouseEvent e)
+ public void componentResized(ComponentEvent e)
{
+ MenuSelectionManager manager = MenuSelectionManager.defaultManager();
+ manager.clearSelectedPath();
}
/**
- * DOCUMENT ME!
+ * This method is invoked when top-level window is moved.
+ * This method closes current menu hierarchy.
*
- * @param e DOCUMENT ME!
+ * @param e The ComponentEvent
*/
- public void mouseDragged(MouseEvent e)
+ public void componentMoved(ComponentEvent e)
{
+ MenuSelectionManager manager = MenuSelectionManager.defaultManager();
+ manager.clearSelectedPath();
}
/**
- * DOCUMENT ME!
+ * This method is invoked when top-level window is shown
+ * This method does nothing by default.
*
- * @param e DOCUMENT ME!
+ * @param e The ComponentEvent
*/
- public void mouseEntered(MouseEvent e)
+ public void componentShown(ComponentEvent e)
{
+ MenuSelectionManager manager = MenuSelectionManager.defaultManager();
+ manager.clearSelectedPath();
}
/**
- * DOCUMENT ME!
+ * This method is invoked when top-level window is hidden
+ * This method closes current menu hierarchy.
*
- * @param e DOCUMENT ME!
+ * @param e The ComponentEvent
*/
+ public void componentHidden(ComponentEvent e)
+ {
+ MenuSelectionManager manager = MenuSelectionManager.defaultManager();
+ manager.clearSelectedPath();
+ }
+ }
+
+ private class MouseInputHandler implements MouseInputListener
+ {
+ public void mouseClicked(MouseEvent e)
+ {
+ }
+
+ public void mouseDragged(MouseEvent e)
+ {
+ }
+
+ public void mouseEntered(MouseEvent e)
+ {
+ }
+
public void mouseExited(MouseEvent e)
{
}
- /**
- * DOCUMENT ME!
- *
- * @param e DOCUMENT ME!
- */
public void mouseMoved(MouseEvent e)
{
}
- /**
- * DOCUMENT ME!
- *
- * @param e DOCUMENT ME!
- */
public void mousePressed(MouseEvent e)
{
}
- /**
- * DOCUMENT ME!
- *
- * @param e DOCUMENT ME!
- */
public void mouseReleased(MouseEvent e)
{
}
package javax.swing.plaf.basic;
import java.awt.event.MouseEvent;
-
import javax.swing.JComponent;
import javax.swing.JMenuItem;
import javax.swing.MenuElement;
/**
- * DOCUMENT ME!
+ * UI Delegator for JRadioButtonMenuItem
*/
public class BasicRadioButtonMenuItemUI extends BasicMenuItemUI
{
}
/**
- * DOCUMENT ME!
+ * Factory method to create a BasicRadioButtonMenuItemUI for the given {@link
+ * JComponent}, which should be a JRadioButtonMenuItem.
*
- * @param b DOCUMENT ME!
+ * @param b The {@link JComponent} a UI is being created for.
*
- * @return $returnType$ DOCUMENT ME!
+ * @return A BasicRadioButtonMenuItemUI for the {@link JComponent}.
*/
public static ComponentUI createUI(JComponent b)
{
protected String getPropertyPrefix()
{
return null;
- // TODO
}
/**
* @param path DOCUMENT ME!
* @param manager DOCUMENT ME!
*/
- void processMouseEvent(JMenuItem item, MouseEvent e, MenuElement[] path,
+ public void processMouseEvent(JMenuItem item, MouseEvent e,
+ MenuElement[] path,
MenuSelectionManager manager)
{
}
package javax.swing.plaf.basic;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
import javax.swing.JComponent;
+import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.RootPaneUI;
public class BasicRootPaneUI extends RootPaneUI
+ implements PropertyChangeListener
{
public static ComponentUI createUI(JComponent x)
{
public void installUI(JComponent c)
{
c.setOpaque(true);
- c.setBackground(javax.swing.UIManager.getColor("control"));
+ c.setBackground(UIManager.getColor("control"));
super.installUI(c);
}
+
+ public void propertyChange(PropertyChangeEvent event)
+ {
+ }
}
3));
/** The Icon that points right. */
- private static Icon rightIcon = new arrowIcon(new Polygon(new int[]
- {
- 3, 7, 3
- },
- new int[]
- {
- 2, 5, 8
- }, 3));
+ private static Icon rightIcon = new arrowIcon(new Polygon(new int[] { 3, 7, 3},
+ new int[] { 2, 5, 8},
+ 3));
/**
* This method adds a component to the layout.
protected JButton createIncreaseButton(int orientation)
{
if (incrButton == null)
+ {
incrButton = new JButton();
+ incrButton.setMargin(new Insets(0,0,0,0));
+ incrButton.setHorizontalAlignment(SwingConstants.CENTER);
+ incrButton.setHorizontalTextPosition(SwingConstants.CENTER);
+ incrButton.setVerticalAlignment(SwingConstants.CENTER);
+ incrButton.setVerticalTextPosition(SwingConstants.CENTER);
+ }
+
if (orientation == SwingConstants.HORIZONTAL)
incrButton.setIcon(rightIcon);
else
protected JButton createDecreaseButton(int orientation)
{
if (decrButton == null)
+ {
decrButton = new JButton();
+ decrButton.setMargin(new Insets(0,0,0,0));
+ decrButton.setHorizontalAlignment(SwingConstants.CENTER);
+ decrButton.setHorizontalTextPosition(SwingConstants.CENTER);
+ decrButton.setVerticalAlignment(SwingConstants.CENTER);
+ decrButton.setVerticalTextPosition(SwingConstants.CENTER);
+ }
+
if (orientation == SwingConstants.HORIZONTAL)
decrButton.setIcon(leftIcon);
else
import javax.swing.JComponent;
import javax.swing.JScrollPane;
+import javax.swing.ScrollPaneConstants;
import javax.swing.ScrollPaneLayout;
+import javax.swing.UIDefaults;
+import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.ScrollPaneUI;
public class BasicScrollPaneUI extends ScrollPaneUI
+ implements ScrollPaneConstants
{
public static ComponentUI createUI(final JComponent c)
return new BasicScrollPaneUI();
}
+ protected void installDefaults(JScrollPane p)
+ {
+ UIDefaults defaults = UIManager.getLookAndFeelDefaults();
+ p.setForeground(defaults.getColor("ScrollPane.foreground"));
+ p.setBackground(defaults.getColor("ScrollPane.background"));
+ p.setFont(defaults.getFont("ScrollPane.font"));
+ p.setBorder(defaults.getBorder("ScrollPane.border"));
+ p.setOpaque(true);
+ }
+
+ protected void uninstallDefaults(JScrollPane p)
+ {
+ p.setForeground(null);
+ p.setBackground(null);
+ p.setFont(null);
+ p.setBorder(null);
+ }
public void installUI(final JComponent c)
{
super.installUI(c);
+ this.installDefaults((JScrollPane)c);
+ }
+
+ public void uninstallUI(final JComponent c)
+ {
+ super.uninstallUI(c);
+ this.uninstallDefaults((JScrollPane)c);
}
+
public Dimension getMinimumSize(JComponent c)
{
JScrollPane p = (JScrollPane ) c;
import java.beans.PropertyChangeListener;
import java.util.Dictionary;
import java.util.Enumeration;
-
import javax.swing.BoundedRangeModel;
import javax.swing.JComponent;
import javax.swing.JLabel;
{
// Maximum, minimum, and extent values will be taken
// care of automatically when the slider is repainted.
-
// Only thing that needs recalculation is the thumb.
calculateThumbLocation();
slider.repaint();
slider.getModel().addChangeListener(changeListener);
calculateThumbLocation();
}
+
// elif the componentOrientation changes (this is a bound property,
// just undocumented) we change leftToRightCache. In Sun's
// implementation, the LTR cache changes on a repaint. This is strange
// since there is no need to do so. We could events here and
// update the cache.
-
// elif the border/insets change, we recalculateInsets.
slider.repaint();
}
/** The current Y position of the mouse. */
protected int currentMouseY;
- /** The offset between the current slider value
- and the cursor's position. */
+ /**
+ * The offset between the current slider value and the cursor's position.
+ */
protected int offset;
/**
if (slider.getSnapToTicks())
value = findClosestTick(value);
- if (value == slider.getValue())
- return;
-
// If the thumb is hit, then we don't need to set the timers to move it.
if (!thumbRect.contains(e.getPoint()))
{
*/
/**
- * This method returns the preferred size when the slider is
- * horizontally oriented.
+ * This method returns the preferred size when the slider is horizontally
+ * oriented.
*
* @return The dimensions of the preferred horizontal size.
*/
// The width should cover all the labels (which are usually the
// deciding factor of the width)
- int width = getWidthOfWidestLabel() * (slider.getLabelTable() == null ?
- 0 : slider.getLabelTable().size());
+ int width = getWidthOfWidestLabel() * (slider.getLabelTable() == null ? 0
+ : slider.getLabelTable()
+ .size());
// If there are not enough labels.
// This number is pretty much arbitrary, but it looks nice.
// We can only draw inside of the focusRectangle, so we have to
// pad it with insets.
- width += insets.left + insets.right + focusInsets.left +
- focusInsets.right;
+ width += insets.left + insets.right + focusInsets.left + focusInsets.right;
// Height is determined by the thumb, the ticks and the labels.
int height = thumbHeight;
- if (slider.getPaintTicks() && slider.getMajorTickSpacing() > 0 ||
- slider.getMinorTickSpacing() > 0)
+ if (slider.getPaintTicks() && slider.getMajorTickSpacing() > 0
+ || slider.getMinorTickSpacing() > 0)
height += tickHeight;
if (slider.getPaintLabels())
height += getHeightOfTallestLabel();
- height += insets.top + insets.bottom + focusInsets.top +
- focusInsets.bottom;
+ height += insets.top + insets.bottom + focusInsets.top
+ + focusInsets.bottom;
return new Dimension(width, height);
}
/**
- * This method returns the preferred size when the slider is
- * vertically oriented.
+ * This method returns the preferred size when the slider is vertically
+ * oriented.
*
* @return The dimensions of the preferred vertical size.
*/
{
Insets insets = slider.getInsets();
- int height = getHeightOfTallestLabel() * (slider.getLabelTable() == null ?
- 0 : slider.getLabelTable().size());
+ int height = getHeightOfTallestLabel() * (slider.getLabelTable() == null
+ ? 0 : slider.getLabelTable()
+ .size());
if (height < 200)
height = 200;
- height += insets.top + insets.bottom + focusInsets.top +
- focusInsets.bottom;
+ height += insets.top + insets.bottom + focusInsets.top
+ + focusInsets.bottom;
int width = thumbHeight;
- if (slider.getPaintTicks() && slider.getMajorTickSpacing() > 0 ||
- slider.getMinorTickSpacing() > 0)
+ if (slider.getPaintTicks() && slider.getMajorTickSpacing() > 0
+ || slider.getMinorTickSpacing() > 0)
width += tickHeight;
if (slider.getPaintLabels())
width += getWidthOfWidestLabel();
- width += insets.left + insets.right + focusInsets.left +
- focusInsets.right;
+ width += insets.left + insets.right + focusInsets.left + focusInsets.right;
return new Dimension(width, height);
}
/**
- * This method returns the minimum size when the slider is
- * horizontally oriented.
+ * This method returns the minimum size when the slider is horizontally
+ * oriented.
*
* @return The dimensions of the minimum horizontal size.
*/
}
/**
- * This method returns the minimum size of the slider when it
- * is vertically oriented.
+ * This method returns the minimum size of the slider when it is vertically
+ * oriented.
*
* @return The dimensions of the minimum vertical size.
*/
}
/**
- * This method calculates all the sizes of the rectangles by delegating
- * to the helper methods calculateXXXRect.
+ * This method calculates all the sizes of the rectangles by delegating to
+ * the helper methods calculateXXXRect.
*/
protected void calculateGeometry()
{
c.translate((trackRect.width / 2) + (width / 2), trackRect.height);
d.translate((trackRect.width / 2) + (width / 2), 0);
}
- high = new Polygon(new int[] { b.x, c.x, d.x },
- new int[] { b.y, c.y, d.y }, 3);
- shadow = new Polygon(new int[] { b.x, a.x, d.x },
- new int[] { b.y, a.y, d.y }, 3);
+ g.setColor(Color.GRAY);
+ g.fillRect(a.x, a.y, width, height);
g.setColor(getHighlightColor());
- g.drawPolygon(high);
+ g.drawLine(b.x, b.y, c.x, c.y);
+ g.drawLine(c.x, c.y, d.x, d.y);
+
g.setColor(getShadowColor());
- g.drawPolygon(shadow);
+ g.drawLine(b.x, b.y, a.x, a.y);
+ g.drawLine(a.x, a.y, d.x, d.y);
- g.setColor(Color.GRAY);
- g.fillRect(a.x + 1, a.y + 1, width - 2, height - 2);
g.setColor(saved_color);
}
Rectangle tickBounds, int x)
{
int y = tickRect.y + tickRect.height / 4;
+ Color saved = g.getColor();
+ g.setColor(Color.BLACK);
g.drawLine(x, y, x, y + tickRect.height / 4);
+ g.setColor(saved);
}
/**
Rectangle tickBounds, int x)
{
int y = tickRect.y + tickRect.height / 4;
+ Color saved = g.getColor();
+ g.setColor(Color.BLACK);
g.drawLine(x, y, x, y + tickRect.height / 2);
+ g.setColor(saved);
}
/**
int y)
{
int x = tickRect.x + tickRect.width / 4;
+ Color saved = g.getColor();
+ g.setColor(Color.BLACK);
g.drawLine(x, y, x + tickRect.width / 4, y);
+ g.setColor(saved);
}
/**
int y)
{
int x = tickRect.x + tickRect.width / 4;
+ Color saved = g.getColor();
+ g.setColor(Color.BLACK);
g.drawLine(x, y, x + tickRect.width / 2, y);
+ g.setColor(saved);
}
/**
// the labels may not fit inside the slider's bounds. Rather than mucking
// with font sizes and possible icon sizes, we'll set the bounds for
// the label and let it get clipped.
-
Dimension dim = label.getPreferredSize();
int w = (int) dim.getWidth();
int h = (int) dim.getHeight();
// | |
// | |
// The label must move w/2 to the right to fit directly under the value.
-
-
int xpos = xPositionForValue(value) - w / 2;
int ypos = labelRect.y;
* buttons. */
private transient int currentDividerLocation = 1;
+ private transient Border tmpBorder = new Border()
+ {
+ public Insets getBorderInsets(Component c)
+ {
+ return new Insets(2, 2, 2, 2);
+ }
+
+ public boolean isBorderOpaque()
+ {
+ return false;
+ }
+
+ public void paintBorder(Component c, Graphics g, int x, int y, int width, int height)
+ {
+ Color saved = g.getColor();
+ g.setColor(Color.BLACK);
+
+ g.drawRect(x + 2, y + 2, width - 4, height - 4);
+
+ g.setColor(saved);
+ }
+ };
+
/**
* Constructs a new divider.
*
setLayout(new DividerLayout());
setBasicSplitPaneUI(ui);
setDividerSize(splitPane.getDividerSize());
+ setBorder(tmpBorder);
}
/**
throw new IllegalArgumentException("Illegal placement in JSplitPane");
components[i] = component;
resetSizeAt(i);
- layoutContainer(splitPane);
+ splitPane.revalidate();
splitPane.repaint();
}
tmpSizes[1] = layoutManager.getAvailableSize(splitPane.getSize(),
splitPane.getInsets())
- tmpSizes[0] - tmpSizes[1];
- Point p = divider.getLocation();
-// if (getOrientation() == JSplitPane.HORIZONTAL_SPLIT)
- // setLastDragLocation(p.x);
-// else
-// setLastDragLocation(p.y);
layoutManager.setSizes(tmpSizes);
- layoutManager.layoutContainer(splitPane);
-
+ splitPane.revalidate();
splitPane.repaint();
}
getSplitPane().setLayout(layoutManager);
// invalidating by itself does not invalidate the layout.
- getSplitPane().invalidate();
+ getSplitPane().revalidate();
}
/**
nonContinuousLayoutDivider.setVisible(true);
nonContinuousLayoutDivider.setBounds(divider.getBounds());
}
- splitPane.invalidate();
+ splitPane.revalidate();
splitPane.repaint();
}
{
selectedRun = getRunForTab(tabPane.getTabCount(),
tabPane.getSelectedIndex());
- tabPane.layout();
+ tabPane.revalidate();
tabPane.repaint();
}
}
--- /dev/null
+/* BasicTextFieldUI.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.beans.PropertyChangeEvent;
+
+import javax.swing.JComponent;
+import javax.swing.JTextField;
+import javax.swing.plaf.ComponentUI;
+import javax.swing.text.Element;
+import javax.swing.text.FieldView;
+import javax.swing.text.PlainDocument;
+import javax.swing.text.View;
+
+public class BasicTextFieldUI extends BasicTextUI
+{
+ public BasicTextFieldUI()
+ {
+ super();
+ }
+
+ public View create(Element elem)
+ {
+ return new FieldView(elem);
+ }
+
+ public static ComponentUI createUI(JComponent c)
+ {
+ return new BasicTextFieldUI();
+ }
+
+ protected String getPropertyPrefix()
+ {
+ return "TextField";
+ }
+
+ public void installUI(JComponent c)
+ {
+ super.installUI(c);
+ }
+
+ protected void propertyChange(PropertyChangeEvent event)
+ {
+ // Does nothing by default.
+ }
+}
/* BasicTextUI.java
- Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
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.Container;
import java.awt.Dimension;
import java.awt.Graphics;
+import java.awt.Insets;
import java.awt.Point;
import java.awt.Rectangle;
+import java.awt.Shape;
+
import javax.swing.JComponent;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.TextUI;
+import javax.swing.plaf.UIResource;
import javax.swing.text.BadLocationException;
+import javax.swing.text.Caret;
+import javax.swing.text.DefaultCaret;
import javax.swing.text.DefaultEditorKit;
+import javax.swing.text.DefaultHighlighter;
+import javax.swing.text.Document;
import javax.swing.text.EditorKit;
import javax.swing.text.Element;
+import javax.swing.text.Highlighter;
import javax.swing.text.JTextComponent;
+import javax.swing.text.PlainDocument;
import javax.swing.text.Position;
import javax.swing.text.View;
import javax.swing.text.ViewFactory;
-public class BasicTextUI extends TextUI
+public abstract class BasicTextUI extends TextUI
implements ViewFactory
{
- int gap = 3;
- View view = null; // was: new RootView();
- Color textColor;
- Color disabledTextColor;
- Color normalBackgroundColor;
- EditorKit kit = new DefaultEditorKit();
+ public static class BasicCaret extends DefaultCaret
+ implements UIResource
+ {
+ public BasicCaret()
+ {
+ }
+ }
+
+ public static class BasicHighlighter extends DefaultHighlighter
+ implements UIResource
+ {
+ public BasicHighlighter()
+ {
+ }
+ }
- /* *****************************************************************
- * 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
+ private class RootView extends View
{
- RootView()
+ private JTextComponent textComponent;
+ private View view;
+
+ public RootView(JTextComponent parent)
{
super(null);
+ textComponent = parent;
}
- public void paint(Graphics g, Shape s)
+
+ public void setView(View v)
{
if (view != null)
+ view.setParent(null);
+
+ if (v != null)
+ v.setParent(null);
+
+ view = v;
+ }
+
+ public Container getContainer()
{
- Rectangle r = s.getBounds();
+ return textComponent;
+ }
+
+ public float getPreferredSpan(int axis)
+ {
+ if (view != null)
+ return view.getPreferredSpan(axis);
- view.setSize((int)r.getWidth(),
- (int)r.getHeight());
- view.paint(g, s);
+ return Integer.MAX_VALUE;
}
+
+ public void paint(Graphics g, Shape s)
+ {
+ System.out.println("Michael: BasicTextUI.RootView.paint");
+
+ if (view != null)
+ view.paint(g, s);
}
}
- * (end of commented out section)
- *************************************************************** */
+
+ RootView rootView;
+ JTextComponent textComponent;
+ int gap = 3;
+ EditorKit kit = new DefaultEditorKit();
+
public BasicTextUI()
{
}
- public static ComponentUI createUI(final JComponent c)
+ protected Caret createCaret()
{
- return new BasicTextUI();
+ return new BasicCaret();
+ }
+
+ protected Highlighter createHighlighter()
+ {
+ return new BasicHighlighter();
+ }
+
+ protected final JTextComponent getComponent()
+ {
+ return textComponent;
}
public void installUI(final JComponent c)
{
super.installUI(c);
+ c.setOpaque(true);
- textColor = new Color(0, 0, 0);
- disabledTextColor = new Color(130, 130, 130);
- normalBackgroundColor = new Color(192, 192, 192);
+ textComponent = (JTextComponent) c;
+
+ Document doc = textComponent.getDocument();
+ if (doc == null)
+ {
+ doc = new PlainDocument();
+ textComponent.setDocument(doc);
}
- public Dimension getPreferredSize(JComponent c)
+ rootView = new RootView(textComponent);
+ setView(create(doc.getDefaultRootElement()));
+
+ installDefaults();
+ installListeners();
+ installKeyboardActions();
+ }
+
+ protected void installDefaults()
+ {
+ }
+
+ protected void installListeners()
{
- JTextComponent b = (JTextComponent) c;
+ }
- View v = getRootView(b);
+ protected void installKeyboardActions()
+ {
+ }
+
+ public void uninstallUI(final JComponent c)
+ {
+ super.uninstallUI(c);
+ rootView = null;
+
+ uninstallDefaults();
+ uninstallListeners();
+ uninstallKeyboardActions();
+ }
+
+ protected void uninstallDefaults()
+ {
+ }
+
+ protected void uninstallListeners()
+ {
+ }
+
+ protected void uninstallKeyboardActions()
+ {
+ }
+
+ protected abstract String getPropertyPrefix();
+
+ public Dimension getPreferredSize(JComponent c)
+ {
+ View v = getRootView(textComponent);
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)
+ public final void paint(Graphics g, JComponent c)
{
- // view.paint(
+ paintSafely(g);
+ }
+
+ protected void paintSafely(Graphics g)
+ {
+ Caret caret = textComponent.getCaret();
+ Highlighter highlighter = textComponent.getHighlighter();
+
+ if (textComponent.isOpaque())
+ paintBackground(g);
+
+ rootView.paint(g, getVisibleEditorRect());
+
+ if (highlighter != null)
+ highlighter.paint(g);
+
+ if (caret != null)
+ caret.paint(g);
+ }
+
+ protected void paintBackground(Graphics g)
+ {
+ g.setColor(Color.WHITE); // FIXME: set background color
+ g.fillRect(0, 0, textComponent.getWidth(), textComponent.getHeight());
}
public void damageRange(JTextComponent t, int p0, int p1)
public View getRootView(JTextComponent t)
{
- return view;
+ return rootView;
}
public Rectangle modelToView(JTextComponent t, int pos)
// subclasses have to implement this to get this functionality
return null;
}
+
+ public View create(Element elem, int p0, int p1)
+ {
+ // subclasses have to implement this to get this functionality
+ return null;
+ }
+
+ protected Rectangle getVisibleEditorRect()
+ {
+ int width = textComponent.getWidth();
+ int height = textComponent.getHeight();
+
+ if (width <= 0 || height <= 0)
+ return null;
+
+ Insets insets = textComponent.getInsets();
+ return new Rectangle(insets.left, insets.top,
+ width - insets.left + insets.right,
+ height - insets.top + insets.bottom);
+ }
+
+ protected final void setView(View view)
+ {
+ rootView.setView(view);
+ view.setParent(rootView);
+ }
}
--- /dev/null
+/* BasicToolBarSeparatorUI.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.JToolBar.Separator;
+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 Look and Feel UI delegate for Separator.
+ */
+public class BasicToolBarSeparatorUI extends BasicSeparatorUI
+{
+ private transient Dimension size;
+
+ /**
+ * Creates a new UI delegate for the given JComponent.
+ *
+ * @param c The JComponent to create a delegate for.
+ *
+ * @return A new BasicToolBarSeparatorUI.
+ */
+ public static ComponentUI createUI(JComponent c)
+ {
+ return new BasicToolBarSeparatorUI();
+ }
+
+ /**
+ * This method installs the defaults that are given by the Basic L&F.
+ *
+ * @param s The Separator that is being installed.
+ */
+ protected void installDefaults(JSeparator s)
+ {
+ UIDefaults defaults = UIManager.getLookAndFeelDefaults();
+
+ size = defaults.getDimension("ToolBar.separatorSize");
+ }
+
+ /**
+ * This method does nothing as a Separator is just blank space.
+ *
+ * @param g The Graphics object to paint with
+ * @param c The JComponent to paint.
+ */
+ public void paint(Graphics g, JComponent c)
+ {
+ // Do nothing.
+ }
+
+ /**
+ * 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 size;
+ }
+
+ /**
+ * This method returns the minimum size of the JComponent.
+ *
+ * @param c The JComponent to measure.
+ *
+ * @return The minimum size.
+ */
+ public Dimension getMinimumSize(JComponent c)
+ {
+ return size;
+ }
+
+ /**
+ * This method returns the maximum size of the JComponent.
+ *
+ * @param c The JComponent to measure.
+ *
+ * @return The maximum size.
+ */
+ public Dimension getMaximumSize(JComponent c)
+ {
+ return size;
+ }
+}
package javax.swing.plaf.basic;
+import java.awt.BorderLayout;
+import java.awt.Color;
import java.awt.Component;
import java.awt.ComponentOrientation;
import java.awt.Container;
-import java.awt.Color;
import java.awt.Dimension;
+import java.awt.Graphics;
import java.awt.GridLayout;
+import java.awt.Insets;
import java.awt.Point;
+import java.awt.Rectangle;
+import java.awt.Window;
+import java.awt.event.ContainerEvent;
+import java.awt.event.ContainerListener;
+import java.awt.event.FocusEvent;
+import java.awt.event.FocusListener;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.awt.event.WindowListener;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
import java.util.Enumeration;
-import javax.swing.JFrame;
+import java.util.Hashtable;
import javax.swing.JButton;
import javax.swing.JComponent;
+import javax.swing.JDialog;
+import javax.swing.JFrame;
import javax.swing.JToolBar;
import javax.swing.RootPaneContainer;
+import javax.swing.SwingConstants;
+import javax.swing.SwingUtilities;
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.BorderUIResource;
+import javax.swing.plaf.BorderUIResource.EtchedBorderUIResource;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.ToolBarUI;
+import javax.swing.plaf.UIResource;
-public class BasicToolBarUI extends ToolBarUI
+
+/**
+ * This is the Basic Look and Feel UI class for JToolBar.
+ */
+public class BasicToolBarUI extends ToolBarUI implements SwingConstants
{
+ /** Static owner of all DragWindows. */
+ private static JFrame owner = new JFrame();
+
+ /** The border used when the JToolBar is in nonrollover mode. */
+ private static Border nonRolloverBorder;
- public class DragWindow
- {}
+ /** The border used when the JToolBar is in rollover mode. */
+ private static Border rolloverBorder;
+ /** The last known BorderLayout constraint before floating. */
protected String constraintBeforeFloating;
+
+ /** The last known orientation of the JToolBar before floating. */
+ private int lastGoodOrientation;
+
+ /** The color of the border when it is dockable. */
protected Color dockingBorderColor;
+
+ /** The background color of the JToolBar when it is dockable. */
protected Color dockingColor;
+
+ /** The docking listener responsible for mouse events on the JToolBar. */
protected MouseInputListener dockingListener;
- //protected KeyStroke downKey
- // Deprecated. As of Java 2 platform v1.3.
+
+ /** The window used for dragging the JToolBar. */
protected BasicToolBarUI.DragWindow dragWindow;
+
+ /** The color of the border when it is not dockable. */
protected Color floatingBorderColor;
+
+ /** The background color of the JToolBar when it is not dockable. */
protected Color floatingColor;
+
+ /** The index of the focused component. */
protected int focusedCompIndex;
- //protected KeyStroke leftKey;
- // Deprecated. As of Java 2 platform v1.3.
+
+ /** The PropertyChangeListener for the JToolBar. */
protected PropertyChangeListener propertyListener;
- //protected KeyStroke rightKey;
- // Deprecated. As of Java 2 platform v1.3.
+
+ /** The JToolBar this UI delegate is responsible for. */
protected JToolBar toolBar;
+
+ /** The Container listener for the JToolBar. */
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;
+ /** The Focus listener for the JToolBar. */
+ protected FocusListener toolBarFocusListener;
+
+ /**
+ * The floating window that is responsible for holding the JToolBar when it
+ * is dragged outside of its original parent.
+ */
+ private transient Window floatFrame;
+
+ /** The original parent of the JToolBar. */
+ private transient Container origParent;
+
+ /** A hashtable of components and their original borders. */
+ private transient Hashtable borders;
+
+ /** A window listener for the floatable frame. */
+ private transient WindowListener windowListener;
- BasicToolBarUI(JToolBar b)
+ /** A set of cached bounds of the JToolBar. */
+ private transient Dimension cachedBounds;
+
+ /** The cached orientation of the JToolBar. */
+ private transient int cachedOrientation;
+
+ /**
+ * This method creates a new BasicToolBarUI object for the given JToolBar.
+ *
+ * @param b The JToolBar to represent with this UI.
+ */
+ public BasicToolBarUI(JToolBar b)
{
super();
}
- /* Can Component c dock at Point p? */
- boolean canDock(Component c, Point p)
+ /**
+ * This method returns whether the JToolBar can dock at the given position.
+ *
+ * @param c The component to try to dock in.
+ * @param p The position of the mouse cursor relative to the given
+ * component.
+ *
+ * @return Whether the JToolBar can dock.
+ */
+ protected boolean canDock(Component c, Point p)
{
+ if (areaOfClick(c, p) != -1)
+ return true;
+
return false;
}
+ /**
+ * This helper method returns the position of the JToolBar if it can dock.
+ *
+ * @param c The component to try to dock in.
+ * @param p The position of the mouse cursor relative to the given
+ * component.
+ *
+ * @return One of the SwingConstants directions or -1 if the JToolBar can't
+ * dock.
+ */
+ private int areaOfClick(Component c, Point p)
+ {
+ // Has to dock in immediate parent, not eventual root container.
+ Rectangle pBounds = c.getBounds();
+
+ // XXX: In Sun's implementation, the space the toolbar has to dock is dependent on the size it had last.
+ Dimension d = toolBar.getSize();
+ int limit = Math.min(d.width, d.height);
+
+ // The order of checking is 1. top 2. bottom 3. left 4. right
+ if (! pBounds.contains(p))
+ return -1;
+
+ if (p.y < limit)
+ return SwingConstants.NORTH;
+
+ if (p.y > (pBounds.height - limit))
+ return SwingConstants.SOUTH;
+
+ if (p.x < limit)
+ return SwingConstants.WEST;
+
+ if (p.x > (pBounds.width - limit))
+ return SwingConstants.EAST;
+
+ return -1;
+ }
+
+ /**
+ * This method creates a new DockingListener for the JToolBar.
+ *
+ * @return A new DockingListener for the JToolBar.
+ */
protected MouseInputListener createDockingListener()
{
- return null;
+ return new DockingListener(toolBar);
}
+ /**
+ * This method creates a new DragWindow for the given JToolBar.
+ *
+ * @param toolbar The JToolBar to create a DragWindow for.
+ *
+ * @return A new DragWindow.
+ */
protected BasicToolBarUI.DragWindow createDragWindow(JToolBar toolbar)
{
- return null;
+ return new DragWindow();
}
+ /**
+ * This method creates a new floating frame for the JToolBar. By default,
+ * this UI uses createFloatingWindow instead. This method of creating a
+ * floating frame is deprecated.
+ *
+ * @param toolbar The JToolBar to create a floating frame for.
+ *
+ * @return A new floating frame.
+ */
protected JFrame createFloatingFrame(JToolBar toolbar)
{
+ // FIXME: Though deprecated, this should still work.
return null;
}
+ /**
+ * This method creates a new floating window for the JToolBar. This is the
+ * method used by default to create a floating container for the JToolBar.
+ *
+ * @param toolbar The JToolBar to create a floating window for.
+ *
+ * @return A new floating window.
+ */
protected RootPaneContainer createFloatingWindow(JToolBar toolbar)
{
- return null;
+ // This one is used by default though.
+ return new ToolBarDialog();
}
+ /**
+ * This method creates a new WindowListener for the JToolBar.
+ *
+ * @return A new WindowListener.
+ */
protected WindowListener createFrameListener()
{
- return null;
+ return new FrameListener();
}
+ /**
+ * This method creates a new nonRolloverBorder for JButtons when the
+ * JToolBar's rollover property is set to false.
+ *
+ * @return A new NonRolloverBorder.
+ */
protected Border createNonRolloverBorder()
{
- return null;
+ return new EtchedBorderUIResource();
}
+ /**
+ * This method creates a new PropertyChangeListener for the JToolBar.
+ *
+ * @return A new PropertyChangeListener.
+ */
protected PropertyChangeListener createPropertyListener()
{
- return null;
+ return new PropertyListener();
}
+ /**
+ * This method creates a new rollover border for JButtons when the
+ * JToolBar's rollover property is set to true.
+ *
+ * @return A new rollover border.
+ */
protected Border createRolloverBorder()
{
- return null;
+ return new EtchedBorderUIResource()
+ {
+ public void paintBorder(Component c, Graphics g, int x, int y,
+ int width, int height)
+ {
+ if (c instanceof JButton)
+ {
+ if (((JButton) c).getModel().isRollover())
+ super.paintBorder(c, g, x, y, width, height);
+ }
+ }
+ };
}
+ /**
+ * This method creates a new Container listener for the JToolBar.
+ *
+ * @return A new Container listener.
+ */
protected ContainerListener createToolBarContListener()
{
- return null;
+ return new ToolBarContListener();
}
+ /**
+ * This method creates a new FocusListener for the JToolBar.
+ *
+ * @return A new FocusListener for the JToolBar.
+ */
protected FocusListener createToolBarFocusListener()
{
- return null;
+ return new ToolBarFocusListener();
}
+ /**
+ * This method creates a new UI delegate for the given JComponent.
+ *
+ * @param c The JComponent to create a UI delegate for.
+ *
+ * @return A new UI delegate.
+ */
public static ComponentUI createUI(JComponent c)
{
return new BasicToolBarUI((JToolBar) c);
}
+ /**
+ * This method is called to drag the DragWindow around when the JToolBar is
+ * being dragged around.
+ *
+ * @param position The mouse cursor coordinates relative to the JToolBar.
+ * @param origin The screen position of the JToolBar.
+ */
protected void dragTo(Point position, Point origin)
{
+ int loc = areaOfClick(origParent,
+ SwingUtilities.convertPoint(toolBar, position,
+ origParent));
+
+ if (loc != -1)
+ {
+ dragWindow.setBorderColor(dockingBorderColor);
+ dragWindow.setBackground(dockingColor);
+ }
+ else
+ {
+ dragWindow.setBorderColor(floatingBorderColor);
+ dragWindow.setBackground(floatingColor);
+ }
+
+ int w = 0;
+ int h = 0;
+
+ boolean tmp = ((loc == SwingConstants.NORTH)
+ || (loc == SwingConstants.SOUTH) || (loc == -1));
+
+ if (((cachedOrientation == SwingConstants.HORIZONTAL) && tmp)
+ || ((cachedOrientation == VERTICAL) && ! tmp))
+ {
+ w = cachedBounds.width;
+ h = cachedBounds.height;
+ }
+ else
+ {
+ w = cachedBounds.height;
+ h = cachedBounds.width;
}
+ Point p = dragWindow.getOffset();
+ Insets insets = toolBar.getInsets();
+
+ dragWindow.setBounds((origin.x + position.x) - p.x
+ - ((insets.left + insets.right) / 2),
+ (origin.y + position.y) - p.y
+ - ((insets.top + insets.bottom) / 2), w, h);
+
+ if (! dragWindow.isVisible())
+ dragWindow.show();
+ }
+
+ /**
+ * This method is used at the end of a drag session to place the frame in
+ * either its original parent as a docked JToolBar or in its floating
+ * frame.
+ *
+ * @param position The position of the mouse cursor relative to the
+ * JToolBar.
+ * @param origin The screen position of the JToolBar before the drag session
+ * started.
+ */
protected void floatAt(Point position, Point origin)
{
+ Point p = new Point(position);
+ int aoc = areaOfClick(origParent,
+ SwingUtilities.convertPoint(toolBar, p, origParent));
+
+ Container oldParent = toolBar.getParent();
+
+ oldParent.remove(toolBar);
+ oldParent.doLayout();
+ oldParent.repaint();
+
+ Container newParent;
+
+ if (aoc == -1)
+ newParent = ((RootPaneContainer) floatFrame).getContentPane();
+ else
+ {
+ floatFrame.hide();
+ newParent = origParent;
}
- /* Return the Color which is displayed when over a docking area */
- Color getDockingColor()
+ String constraint;
+ switch (aoc)
+ {
+ case SwingConstants.EAST:
+ constraint = BorderLayout.EAST;
+ break;
+ case SwingConstants.NORTH:
+ constraint = BorderLayout.NORTH;
+ break;
+ case SwingConstants.SOUTH:
+ constraint = BorderLayout.SOUTH;
+ break;
+ case SwingConstants.WEST:
+ constraint = BorderLayout.WEST;
+ break;
+ default:
+ constraint = BorderLayout.CENTER;
+ break;
+ }
+
+ int newOrientation = SwingConstants.HORIZONTAL;
+ if ((aoc != -1)
+ && ((aoc == SwingConstants.EAST) || (aoc == SwingConstants.WEST)))
+ newOrientation = SwingConstants.VERTICAL;
+
+ if (aoc != -1)
+ {
+ constraintBeforeFloating = constraint;
+ lastGoodOrientation = newOrientation;
+ }
+
+ newParent.add(toolBar, constraint);
+
+ setFloating(aoc == -1, null);
+ toolBar.setOrientation(newOrientation);
+
+ Insets insets = floatFrame.getInsets();
+ Dimension dims = toolBar.getPreferredSize();
+ p = dragWindow.getOffset();
+ setFloatingLocation((position.x + origin.x) - p.x
+ - ((insets.left + insets.right) / 2),
+ (position.y + origin.y) - p.y
+ - ((insets.top + insets.bottom) / 2));
+
+ if (aoc == -1)
+ {
+ floatFrame.pack();
+ floatFrame.setSize(dims.width + insets.left + insets.right,
+ dims.height + insets.top + insets.bottom);
+ floatFrame.show();
+ }
+
+ newParent.invalidate();
+ newParent.validate();
+ newParent.repaint();
+ }
+
+ /**
+ * This method returns the docking color.
+ *
+ * @return The docking color.
+ */
+ public Color getDockingColor()
{
return dockingColor;
}
- /* Return the Color which is displayed when over a floating area */
- Color getFloatingColor()
+ /**
+ * This method returns the Color which is displayed when over a floating
+ * area.
+ *
+ * @return The color which is displayed when over a floating area.
+ */
+ public Color getFloatingColor()
{
return floatingColor;
}
- /* See ComponentUI */
+ /**
+ * This method returns the maximum size of the given JComponent for this UI.
+ *
+ * @param c The JComponent to find the maximum size for.
+ *
+ * @return The maximum size for this UI.
+ */
public Dimension getMaximumSize(JComponent c)
{
- return null;
+ return getPreferredSize(c);
}
- /* See ComponentUI */
+ /**
+ * This method returns the minimum size of the given JComponent for this UI.
+ *
+ * @param c The JComponent to find a minimum size for.
+ *
+ * @return The minimum size for this UI.
+ */
public Dimension getMinimumSize(JComponent c)
{
- return null;
+ return getPreferredSize(c);
}
- /* See ComponentUI */
+ /**
+ * This method returns the preferred size of the given JComponent for this
+ * UI.
+ *
+ * @param c The JComponent to find a preferred size for.
+ *
+ * @return The preferred size for this UI.
+ */
public Dimension getPreferredSize(JComponent c)
{
- return null;
+ return toolBar.getLayout().preferredLayoutSize(c);
}
+ /**
+ * This method installs the needed components for the JToolBar.
+ */
protected void installComponents()
{
+ floatFrame = (Window) createFloatingWindow(toolBar);
+
+ dragWindow = createDragWindow(toolBar);
+
+ cachedBounds = toolBar.getPreferredSize();
+ cachedOrientation = toolBar.getOrientation();
+
+ nonRolloverBorder = createNonRolloverBorder();
+ rolloverBorder = createRolloverBorder();
+
+ borders = new Hashtable();
+
+ fillHashtable();
}
+ /**
+ * This method installs the defaults as specified by the look and feel.
+ */
protected void installDefaults()
{
+ UIDefaults defaults = UIManager.getLookAndFeelDefaults();
+
+ toolBar.setBorder(new ToolBarBorder());
+ toolBar.setBackground(defaults.getColor("ToolBar.background"));
+ toolBar.setForeground(defaults.getColor("ToolBar.foreground"));
+ toolBar.setFont(defaults.getFont("ToolBar.font"));
+
+ dockingBorderColor = defaults.getColor("ToolBar.dockingForeground");
+ dockingColor = defaults.getColor("ToolBar.dockingBackground");
+
+ floatingBorderColor = defaults.getColor("ToolBar.floatingForeground");
+ floatingColor = defaults.getColor("ToolBar.floatingBackground");
}
+ /**
+ * This method installs the keyboard actions for the JToolBar as specified
+ * by the look and feel.
+ */
protected void installKeyboardActions()
{
+ // FIXME: implement.
}
+ /**
+ * This method installs listeners for the JToolBar.
+ *
+ * @param toolbar The JToolBar to register listeners for.
+ */
protected void installListeners(JToolBar toolbar)
{
- toolbar.addMouseListener(new MouseAdapter() {
- public void mouseClicked(MouseEvent event) {
- System.err.println("toolbar clicked");
- }
- } );
- }
+ dockingListener = createDockingListener();
+ toolBar.addMouseListener(dockingListener);
+ toolBar.addMouseMotionListener(dockingListener);
- /* Call setBorderToNonRollover for each child component of c */
+ propertyListener = createPropertyListener();
+ toolBar.addPropertyChangeListener(propertyListener);
+
+ toolBarContListener = createToolBarContListener();
+ toolBar.addContainerListener(toolBarContListener);
+
+ windowListener = createFrameListener();
+ floatFrame.addWindowListener(windowListener);
+
+ toolBarFocusListener = createToolBarFocusListener();
+ toolBar.addFocusListener(toolBarFocusListener);
+ }
+
+ /**
+ * This method installs non rollover borders for each component inside the
+ * given JComponent.
+ *
+ * @param c The JComponent whose children need to have non rollover borders
+ * installed.
+ */
protected void installNonRolloverBorders(JComponent c)
{
+ Component[] components = toolBar.getComponents();
+
+ for (int i = 0; i < components.length; i++)
+ setBorderToNonRollover(components[i]);
}
- /* Call setBorderToNormal for each child component of c */
+ /**
+ * This method installs normal (or their original) borders for each
+ * component inside the given JComponent.
+ *
+ * @param c The JComponent whose children need to have their original
+ * borders installed.
+ */
protected void installNormalBorders(JComponent c)
{
+ Component[] components = toolBar.getComponents();
+
+ for (int i = 0; i < components.length; i++)
+ setBorderToNormal(components[i]);
}
- /* Call setBorderToRollover for each child component of c */
+ /**
+ * This method install rollover borders for each component inside the given
+ * JComponent.
+ *
+ * @param c The JComponent whose children need to have rollover borders
+ * installed.
+ */
protected void installRolloverBorders(JComponent c)
{
+ Component[] components = toolBar.getComponents();
+
+ for (int i = 0; i < components.length; i++)
+ setBorderToRollover(components[i]);
}
+ /**
+ * This method fills the borders hashtable with a list of components that
+ * are JButtons and their borders.
+ */
+ private void fillHashtable()
+ {
+ Component[] c = toolBar.getComponents();
+
+ for (int i = 0; i < c.length; i++)
+ {
+ if (c[i] instanceof JButton)
+ {
+ // Don't really care about anything other than JButtons
+ JButton b = (JButton) c[i];
+
+ if (b.getBorder() != null)
+ borders.put(b, b.getBorder());
+ }
+ }
+ }
+
+ /**
+ * This method installs the UI for the given JComponent.
+ *
+ * @param c The JComponent to install a UI for.
+ */
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;
- }
+ installDefaults();
+ installComponents();
installListeners(toolBar);
+ installKeyboardActions();
}
}
- boolean isFloating()
+ /**
+ * This method returns whether the JToolBar is floating.
+ *
+ * @return Whether the JToolBar is floating.
+ */
+ public boolean isFloating()
{
- return false;
+ return floatFrame.isVisible();
}
- boolean isRolloverBorders()
+ /**
+ * This method returns whether rollover borders have been set.
+ *
+ * @return Whether rollover borders have been set.
+ */
+ public boolean isRolloverBorders()
{
- return false;
+ return toolBar.isRollover();
}
+ /**
+ * This method navigates in the given direction giving focus to the next
+ * component in the given direction.
+ *
+ * @param direction The direction to give focus to.
+ */
protected void navigateFocusedComp(int direction)
{
+ // FIXME: Implement.
}
- /* Make Component c have a non-rollover border (created by
- createNonRolloverBorder). */
+ /**
+ * This method sets the border of the given component to a non rollover
+ * border.
+ *
+ * @param c The Component whose border needs to be set.
+ */
protected void setBorderToNonRollover(Component c)
{
+ if (c instanceof JButton)
+ {
+ JButton b = (JButton) c;
+ b.setRolloverEnabled(false);
+ b.setBorder(nonRolloverBorder);
+ }
}
- /* Make Component c have the border that it originally had before being
- added to the toolbar. */
+ /**
+ * This method sets the border of the given component to its original value.
+ *
+ * @param c The Component whose border needs to be set.
+ */
protected void setBorderToNormal(Component c)
{
+ if (c instanceof JButton)
+ {
+ JButton b = (JButton) c;
+ Border border = (Border) borders.get(b);
+ b.setBorder(border);
+ }
}
- /* Make Component c have a rollover border (created by
- createRolloverBorder). */
+ /**
+ * This method sets the border of the given component to a rollover border.
+ *
+ * @param c The Component whose border needs to be set.
+ */
protected void setBorderToRollover(Component c)
{
+ if (c instanceof JButton)
+ {
+ JButton b = (JButton) c;
+ b.setRolloverEnabled(true);
+ b.setBorder(rolloverBorder);
+ }
}
- /* Display in Color c when over a docking area */
- void setDockingColor(Color c)
+ /**
+ * This method sets the docking color.
+ *
+ * @param c The docking color.
+ */
+ public void setDockingColor(Color c)
{
dockingColor = c;
}
- void setFloating(boolean b, Point p)
+ /**
+ * This method sets the floating property for the JToolBar.
+ *
+ * @param b Whether the JToolBar is floating.
+ * @param p FIXME
+ */
+ public void setFloating(boolean b, Point p)
+ {
+ // FIXME: use p for something. It's not location
+ // since we already have setFloatingLocation.
+ floatFrame.setVisible(b);
+ }
+
+ /**
+ * This method sets the color displayed when the JToolBar is not in a
+ * dockable area.
+ *
+ * @param c The floating color.
+ */
+ public void setFloatingColor(Color c)
{
+ floatingColor = c;
}
- /* Display in Color c when over a floating area */
- void setFloatingColor(Color c)
+ /**
+ * This method sets the floating location of the JToolBar.
+ *
+ * @param x The x coordinate for the floating frame.
+ * @param y The y coordinate for the floating frame.
+ */
+ public void setFloatingLocation(int x, int y)
+ {
+ // x,y are the coordinates of the new JFrame created to store the toolbar
+ // XXX: The floating location is bogus is not floating.
+ floatFrame.setLocation(x, y);
+ floatFrame.invalidate();
+ floatFrame.validate();
+ floatFrame.repaint();
+ }
+
+ /**
+ * This is a convenience method for changing the orientation of the
+ * JToolBar.
+ *
+ * @param orientation The new orientation.
+ */
+ public void setOrientation(int orientation)
+ {
+ toolBar.setOrientation(orientation);
+ }
+
+ /**
+ * This method changes the child components to have rollover borders if the
+ * given parameter is true. Otherwise, the components are set to have non
+ * rollover borders.
+ *
+ * @param rollover Whether the children will have rollover borders.
+ */
+ public void setRolloverBorders(boolean rollover)
+ {
+ if (rollover)
+ installRolloverBorders(toolBar);
+ else
+ installNonRolloverBorders(toolBar);
+ }
+
+ /**
+ * This method uninstall UI installed components from the JToolBar.
+ */
+ protected void uninstallComponents()
{
- floatingColor = c;
+ installNormalBorders(toolBar);
+ borders = null;
+ rolloverBorder = null;
+ nonRolloverBorder = null;
+ cachedBounds = null;
+
+ floatFrame = null;
+ dragWindow = null;
+ }
+
+ /**
+ * This method removes the defaults installed by the Look and Feel.
+ */
+ protected void uninstallDefaults()
+ {
+ toolBar.setBackground(null);
+ toolBar.setForeground(null);
+ toolBar.setFont(null);
+
+ dockingBorderColor = null;
+ dockingColor = null;
+ floatingBorderColor = null;
+ floatingColor = null;
}
- void setFloatingLocation(int x, int y)
+ /**
+ * This method uninstalls keyboard actions installed by the UI.
+ */
+ protected void uninstallKeyboardActions()
{
+ // FIXME: implement.
}
- void setOrientation(int orientation)
+ /**
+ * This method uninstalls listeners installed by the UI.
+ */
+ protected void uninstallListeners()
{
+ toolBar.removeFocusListener(toolBarFocusListener);
+ toolBarFocusListener = null;
+
+ floatFrame.removeWindowListener(windowListener);
+ windowListener = null;
+
+ toolBar.removeContainerListener(toolBarContListener);
+ toolBarContListener = null;
+
+ toolBar.removeMouseMotionListener(dockingListener);
+ toolBar.removeMouseListener(dockingListener);
+ dockingListener = null;
}
- /* Set flag to enable rollover borders for the toolbar */
- void setRolloverBorders(boolean rollover)
+ /**
+ * This method uninstalls the UI.
+ *
+ * @param c The JComponent that is having this UI removed.
+ */
+ public void uninstallUI(JComponent c)
+ {
+ uninstallKeyboardActions();
+ uninstallListeners();
+ uninstallComponents();
+ uninstallDefaults();
+ toolBar = null;
+ }
+
+ /**
+ * This is the MouseHandler class that allows the user to drag the JToolBar
+ * in and out of the parent and dock it if it can.
+ */
+ protected class DockingListener implements MouseInputListener
+ {
+ /** Whether the JToolBar is being dragged. */
+ protected boolean isDragging;
+
+ /**
+ * The origin point. This point is saved from the beginning press and is
+ * used until the end of the drag session.
+ */
+ protected Point origin;
+
+ /** The JToolBar being dragged. */
+ protected JToolBar toolBar;
+
+ /**
+ * Creates a new DockingListener object.
+ *
+ * @param t The JToolBar this DockingListener is being used for.
+ */
+ public DockingListener(JToolBar t)
{
- rolloverBorders = rollover;
+ toolBar = t;
}
- protected void uninstallComponents()
+ /**
+ * This method is called when the mouse is clicked.
+ *
+ * @param e The MouseEvent.
+ */
+ public void mouseClicked(MouseEvent e)
{
+ // Don't care.
}
- protected void uninstallDefaults()
+ /**
+ * This method is called when the mouse is dragged. It delegates the drag
+ * painting to the dragTo method.
+ *
+ * @param e The MouseEvent.
+ */
+ public void mouseDragged(MouseEvent e)
{
+ if (isDragging)
+ dragTo(e.getPoint(), origin);
}
- protected void uninstallKeyboardActions()
+ /**
+ * This method is called when the mouse enters the JToolBar.
+ *
+ * @param e The MouseEvent.
+ */
+ public void mouseEntered(MouseEvent e)
{
+ // Don't care (yet).
}
- protected void uninstallListeners()
+ /**
+ * This method is called when the mouse exits the JToolBar.
+ *
+ * @param e The MouseEvent.
+ */
+ public void mouseExited(MouseEvent e)
{
+ // Don't care (yet).
}
- public void uninstallUI(JComponent c)
+ /**
+ * This method is called when the mouse is moved in the JToolBar.
+ *
+ * @param e The MouseEvent.
+ */
+ public void mouseMoved(MouseEvent e)
+ {
+ }
+
+ /**
+ * This method is called when the mouse is pressed in the JToolBar. If the
+ * press doesn't occur in a place where it causes the JToolBar to be
+ * dragged, it returns. Otherwise, it starts a drag session.
+ *
+ * @param e The MouseEvent.
+ */
+ public void mousePressed(MouseEvent e)
+ {
+ if (! toolBar.isFloatable())
+ return;
+
+ Point ssd = e.getPoint();
+ Insets insets = toolBar.getInsets();
+
+ // Verify that this click occurs in the top inset.
+ if (toolBar.getOrientation() == SwingConstants.HORIZONTAL)
+ {
+ if (e.getX() > insets.left)
+ return;
+ }
+ else
+ {
+ if (e.getY() > insets.top)
+ return;
+ }
+
+ origin = new Point(0, 0);
+ SwingUtilities.convertPointToScreen(ssd, toolBar);
+
+ if (! (SwingUtilities.getAncestorOfClass(Window.class, toolBar) instanceof UIResource))
+ // Need to know who keeps the toolBar if it gets dragged back into it.
+ origParent = toolBar.getParent();
+
+ SwingUtilities.convertPointToScreen(origin, toolBar);
+
+ isDragging = true;
+
+ if (dragWindow != null)
+ dragWindow.setOffset(new Point(e.getX(), e.getY()));
+
+ dragTo(e.getPoint(), origin);
+ }
+
+ /**
+ * This method is called when the mouse is released from the JToolBar.
+ *
+ * @param e The MouseEvent.
+ */
+ public void mouseReleased(MouseEvent e)
+ {
+ if (! isDragging || ! toolBar.isFloatable())
+ return;
+
+ isDragging = false;
+ floatAt(e.getPoint(), origin);
+ dragWindow.hide();
+ }
+ }
+
+ /**
+ * This is the window that appears when the JToolBar is being dragged
+ * around.
+ */
+ protected class DragWindow extends Window
+ {
+ /**
+ * The current border color. It changes depending on whether the JToolBar
+ * is over a place that allows it to dock.
+ */
+ private Color borderColor;
+
+ /** The between the mouse and the top left corner of the window. */
+ private Point offset;
+
+ /**
+ * Creates a new DragWindow object.
+ */
+ private DragWindow()
+ {
+ super(owner);
+ }
+
+ /**
+ * The color that the border should be.
+ *
+ * @return The border color.
+ */
+ public Color getBorderColor()
+ {
+ if (borderColor == null)
+ return Color.BLACK;
+
+ return borderColor;
+ }
+
+ /**
+ * This method returns the insets for the DragWindow.
+ *
+ * @return The insets for the DragWindow.
+ */
+ public Insets getInsets()
+ {
+ // This window has no decorations, so insets are empty.
+ return new Insets(0, 0, 0, 0);
+ }
+
+ /**
+ * This method returns the mouse offset from the top left corner of the
+ * DragWindow.
+ *
+ * @return The mouse offset.
+ */
+ public Point getOffset()
+ {
+ return offset;
+ }
+
+ /**
+ * This method paints the DragWindow.
+ *
+ * @param g The Graphics object to paint with.
+ */
+ public void paint(Graphics g)
+ {
+ // No visiting children necessary.
+ Color saved = g.getColor();
+ Rectangle b = getBounds();
+
+ g.setColor(getBorderColor());
+ g.drawRect(0, 0, b.width - 1, b.height - 1);
+
+ g.setColor(saved);
+ }
+
+ /**
+ * This method changes the border color.
+ *
+ * @param c The new border color.
+ */
+ public void setBorderColor(Color c)
+ {
+ borderColor = c;
+ }
+
+ /**
+ * This method changes the mouse offset.
+ *
+ * @param p The new mouse offset.
+ */
+ public void setOffset(Point p)
{
+ offset = p;
}
+ /**
+ * FIXME: Do something.
+ *
+ * @param o DOCUMENT ME!
+ */
+ public void setOrientation(int o)
+ {
+ // FIXME: implement.
+ }
+ }
+
+ /**
+ * This helper class listens for Window events from the floatable window and
+ * if it is closed, returns the JToolBar to the last known good location.
+ */
+ protected class FrameListener extends WindowAdapter
+ {
+ /**
+ * This method is called when the floating window is closed.
+ *
+ * @param e The WindowEvent.
+ */
+ public void windowClosing(WindowEvent e)
+ {
+ Container parent = toolBar.getParent();
+ parent.remove(toolBar);
+
+ if (origParent != null)
+ {
+ origParent.add(toolBar,
+ (constraintBeforeFloating != null)
+ ? constraintBeforeFloating : BorderLayout.NORTH);
+ toolBar.setOrientation(lastGoodOrientation);
+ }
+
+ origParent.invalidate();
+ origParent.validate();
+ origParent.repaint();
+ }
+ }
+
+ /**
+ * This helper class listens for PropertyChangeEvents from the JToolBar.
+ */
+ protected class PropertyListener implements PropertyChangeListener
+ {
+ /**
+ * This method is called when a property from the JToolBar is changed.
+ *
+ * @param e The PropertyChangeEvent.
+ */
+ public void propertyChange(PropertyChangeEvent e)
+ {
+ // FIXME: need name properties so can change floatFrame title.
+ if (e.getPropertyName().equals(JToolBar.ROLLOVER_CHANGED_PROPERTY))
+ setRolloverBorders(toolBar.isRollover());
+ }
+ }
+
+ /**
+ * This helper class listens for components added to and removed from the
+ * JToolBar.
+ */
+ protected class ToolBarContListener implements ContainerListener
+ {
+ /**
+ * This method is responsible for setting rollover or non rollover for new
+ * buttons added to the JToolBar.
+ *
+ * @param e The ContainerEvent.
+ */
+ public void componentAdded(ContainerEvent e)
+ {
+ if (e.getChild() instanceof JButton)
+ {
+ JButton b = (JButton) e.getChild();
+
+ if (b.getBorder() != null)
+ borders.put(b, b.getBorder());
+ }
+
+ if (isRolloverBorders())
+ setBorderToRollover(e.getChild());
+ else
+ setBorderToNonRollover(e.getChild());
+
+ cachedBounds = toolBar.getPreferredSize();
+ cachedOrientation = toolBar.getOrientation();
+ }
+
+ /**
+ * This method is responsible for giving the child components their
+ * original borders when they are removed.
+ *
+ * @param e The ContainerEvent.
+ */
+ public void componentRemoved(ContainerEvent e)
+ {
+ setBorderToNormal(e.getChild());
+ cachedBounds = toolBar.getPreferredSize();
+ cachedOrientation = toolBar.getOrientation();
+ }
+ }
+
+ /**
+ * This is the floating window that is returned when getFloatingWindow is
+ * called.
+ */
+ private class ToolBarDialog extends JDialog implements UIResource
+ {
+ /**
+ * Creates a new ToolBarDialog object with the name given by the JToolBar.
+ */
+ public ToolBarDialog()
+ {
+ super();
+ setName((toolBar.getName() != null) ? toolBar.getName() : "");
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ */
+ protected class ToolBarFocusListener implements FocusListener
+ {
+ /**
+ * Creates a new ToolBarFocusListener object.
+ */
+ protected ToolBarFocusListener()
+ {
+ // FIXME: implement.
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void focusGained(FocusEvent e)
+ {
+ // FIXME: implement.
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void focusLost(FocusEvent e)
+ {
+ // FIXME: implement.
+ }
+ }
+
+ /**
+ * This helper class acts as the border for the JToolBar.
+ */
+ private static class ToolBarBorder implements Border
+ {
+ /** The size of the larger, draggable side of the border. */
+ private static int offset = 10;
+
+ /** The other sides. */
+ private static int regular = 2;
+
+ /**
+ * This method returns the border insets for the JToolBar.
+ *
+ * @param c The Component to find insets for.
+ *
+ * @return The border insets.
+ */
+ public Insets getBorderInsets(Component c)
+ {
+ if (c instanceof JToolBar)
+ {
+ JToolBar tb = (JToolBar) c;
+ int orientation = tb.getOrientation();
+
+ if (! tb.isFloatable())
+ return new Insets(regular, regular, regular, regular);
+ else if (orientation == SwingConstants.HORIZONTAL)
+ return new Insets(regular, offset, regular, regular);
+ else
+ return new Insets(offset, regular, regular, regular);
+ }
+
+ return new Insets(0, 0, 0, 0);
+ }
+
+ /**
+ * This method returns whether the border is opaque.
+ *
+ * @return Whether the border is opaque.
+ */
+ public boolean isBorderOpaque()
+ {
+ return false;
+ }
+
+ /**
+ * This method paints the ribbed area of the border.
+ *
+ * @param g The Graphics object to paint with.
+ * @param x The x coordinate of the area.
+ * @param y The y coordinate of the area.
+ * @param w The width of the area.
+ * @param h The height of the area.
+ * @param size The size of the bump.
+ * @param c The color of the bumps.
+ */
+ private void paintBumps(Graphics g, int x, int y, int w, int h, int size,
+ Color c)
+ {
+ Color saved = g.getColor();
+ g.setColor(c);
+
+ int hgap = 2 * size;
+ int vgap = 4 * size;
+ int count = 0;
+
+ for (int i = x; i < (w + x); i += hgap)
+ for (int j = ((count++ % 2) == 0) ? y : (y + (2 * size)); j < (h + y);
+ j += vgap)
+ g.fillRect(i, j, size, size);
+
+ g.setColor(saved);
+ }
+
+ /**
+ * This method paints the border around the given Component.
+ *
+ * @param c The Component whose border is being painted.
+ * @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)
+ {
+ if (c instanceof JToolBar)
+ {
+ JToolBar tb = (JToolBar) c;
+
+ int orientation = tb.getOrientation();
+
+ if (orientation == SwingConstants.HORIZONTAL)
+ {
+ paintBumps(g, x, y, offset, height, 1, Color.WHITE);
+ paintBumps(g, x + 1, y + 1, offset - 1, height - 1, 1, Color.GRAY);
+ }
+ else
+ {
+ paintBumps(g, x, y, width, offset, 1, Color.WHITE);
+ paintBumps(g, x + 1, y + 1, width - 1, offset - 1, 1, Color.GRAY);
+ }
+ }
+ }
+ }
}
g.clearRect(0, 0, portBounds.width, portBounds.height);
}
+ g2.setClip(g.getClipBounds());
g2.translate(-pos.x, -pos.y);
try
{
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
-
package javax.swing.table;
import java.beans.PropertyChangeEvent;
import javax.swing.event.TableColumnModelEvent;
import javax.swing.event.TableColumnModelListener;
+
/**
* DefaultTableColumnModel
* @author Andrew Selkirk
* @version 1.0
*/
public class DefaultTableColumnModel
- implements TableColumnModel, PropertyChangeListener,
- ListSelectionListener, Serializable
+ implements TableColumnModel, PropertyChangeListener, ListSelectionListener,
+ Serializable
{
static final long serialVersionUID = 6580012493508960512L;
- //-------------------------------------------------------------
- // Variables --------------------------------------------------
- //-------------------------------------------------------------
-
/**
* tableColumns
*/
*/
protected int totalColumnWidth;
-
- //-------------------------------------------------------------
- // Initialization ---------------------------------------------
- //-------------------------------------------------------------
-
/**
* Constructor DefaultTableColumnModel
*/
- public DefaultTableColumnModel() {
+ public DefaultTableColumnModel()
+ {
// TODO
- } // DefaultTableColumnModel()
-
-
- //-------------------------------------------------------------
- // Methods ----------------------------------------------------
- //-------------------------------------------------------------
+ }
/**
* addColumn
* @param value0 TODO
*/
- public void addColumn(TableColumn value0) {
+ public void addColumn(TableColumn value0)
+ {
// TODO
- } // addColumn()
+ }
/**
* removeColumn
* @param value0 TODO
*/
- public void removeColumn(TableColumn value0) {
+ public void removeColumn(TableColumn value0)
+ {
// TODO
- } // removeColumn()
+ }
/**
* moveColumn
* @param value0 TODO
* @param value1 TODO
*/
- public void moveColumn(int value0, int value1) {
+ public void moveColumn(int value0, int value1)
+ {
// TODO
- } // moveColumn()
+ }
/**
* setColumnMargin
* @param value0 TODO
*/
- public void setColumnMargin(int value0) {
+ public void setColumnMargin(int value0)
+ {
// TODO
- } // setColumnMargin()
+ }
/**
* getColumnCount
- * @returns int
+ * @return int
*/
- public int getColumnCount() {
+ public int getColumnCount()
+ {
return 0; // TODO
- } // getColumnCount()
+ }
/**
* getColumns
- * @returns Enumeration
+ * @return Enumeration
*/
- public Enumeration getColumns() {
+ public Enumeration getColumns()
+ {
return null; // TODO
- } // getColumns()
+ }
/**
* getColumnIndex
* @param value0 TODO
- * @returns int
+ * @return int
*/
- public int getColumnIndex(Object value0) {
+ public int getColumnIndex(Object value0)
+ {
return 0; // TODO
- } // getColumnIndex()
+ }
/**
* getColumn
* @param value0 TODO
- * @returns TableColumn
+ * @return TableColumn
*/
- public TableColumn getColumn(int value0) {
+ public TableColumn getColumn(int value0)
+ {
return null; // TODO
- } // getColumn()
+ }
/**
* getColumnMargin
- * @returns int
+ * @return int
*/
- public int getColumnMargin() {
+ public int getColumnMargin()
+ {
return 0; // TODO
- } // getColumnMargin()
+ }
/**
* getColumnIndexAtX
* @param value0 TODO
- * @returns int
+ * @return int
*/
- public int getColumnIndexAtX(int value0) {
+ public int getColumnIndexAtX(int value0)
+ {
return 0; // TODO
- } // getColumnIndexAtX()
+ }
/**
* getTotalColumnWidth
- * @returns int
+ * @return int
*/
- public int getTotalColumnWidth() {
+ public int getTotalColumnWidth()
+ {
return 0; // TODO
- } // getTotalColumnWidth()
+ }
/**
* setSelectionModel
* @param value0 TODO
*/
- public void setSelectionModel(ListSelectionModel value0) {
+ public void setSelectionModel(ListSelectionModel value0)
+ {
// TODO
- } // setSelectionModel()
+ }
/**
* getSelectionModel
- * @returns ListSelectionModel
+ * @return ListSelectionModel
*/
- public ListSelectionModel getSelectionModel() {
+ public ListSelectionModel getSelectionModel()
+ {
return null; // TODO
- } // getSelectionModel()
+ }
/**
* setColumnSelectionAllowed
* @param value0 TODO
*/
- public void setColumnSelectionAllowed(boolean value0) {
+ public void setColumnSelectionAllowed(boolean value0)
+ {
// TODO
- } // setColumnSelectionAllowed()
+ }
/**
* getColumnSelectionAllowed
- * @returns boolean
+ * @return boolean
*/
- public boolean getColumnSelectionAllowed() {
+ public boolean getColumnSelectionAllowed()
+ {
return false; // TODO
- } // getColumnSelectionAllowed()
+ }
/**
* getSelectedColumns
- * @returns int[]
+ * @return int[]
*/
- public int[] getSelectedColumns() {
+ public int[] getSelectedColumns()
+ {
return null; // TODO
- } // getSelectedColumns()
+ }
/**
* getSelectedColumnCount
- * @returns int
+ * @return int
*/
- public int getSelectedColumnCount() {
+ public int getSelectedColumnCount()
+ {
return 0; // TODO
- } // getSelectedColumnCount()
+ }
/**
* addColumnModelListener
* @param value0 TODO
*/
- public void addColumnModelListener(TableColumnModelListener value0) {
+ public void addColumnModelListener(TableColumnModelListener value0)
+ {
// TODO
- } // addColumnModelListener()
+ }
/**
* removeColumnModelListener
* @param value0 TODO
*/
- public void removeColumnModelListener(TableColumnModelListener value0) {
+ public void removeColumnModelListener(TableColumnModelListener value0)
+ {
// TODO
- } // removeColumnModelListener()
+ }
/**
* fireColumnAdded
* @param value0 TODO
*/
- protected void fireColumnAdded(TableColumnModelEvent value0) {
+ protected void fireColumnAdded(TableColumnModelEvent value0)
+ {
// TODO
- } // fireColumnAdded()
+ }
/**
* fireColumnRemoved
* @param value0 TODO
*/
- protected void fireColumnRemoved(TableColumnModelEvent value0) {
+ protected void fireColumnRemoved(TableColumnModelEvent value0)
+ {
// TODO
- } // fireColumnRemoved()
+ }
/**
* fireColumnMoved
* @param value0 TODO
*/
- protected void fireColumnMoved(TableColumnModelEvent value0) {
+ protected void fireColumnMoved(TableColumnModelEvent value0)
+ {
// TODO
- } // fireColumnMoved()
+ }
/**
* fireColumnSelectionChanged
* @param value0 TODO
*/
- protected void fireColumnSelectionChanged(ListSelectionEvent value0) {
+ protected void fireColumnSelectionChanged(ListSelectionEvent value0)
+ {
// TODO
- } // fireColumnSelectionChanged()
+ }
/**
* fireColumnMarginChanged
*/
- protected void fireColumnMarginChanged() {
+ protected void fireColumnMarginChanged()
+ {
// TODO
- } // fireColumnMarginChanged()
+ }
/**
* getListeners
* @param value0 TODO
- * @returns EventListener[]
+ * @return EventListener[]
*/
- public EventListener[] getListeners(Class value0) {
+ public EventListener[] getListeners(Class value0)
+ {
return null; // TODO
- } // getListeners()
+ }
/**
* propertyChange
* @param value0 TODO
*/
- public void propertyChange(PropertyChangeEvent value0) {
+ public void propertyChange(PropertyChangeEvent value0)
+ {
// TODO
- } // propertyChange()
+ }
/**
* valueChanged
* @param value0 TODO
*/
- public void valueChanged(ListSelectionEvent value0) {
+ public void valueChanged(ListSelectionEvent value0)
+ {
// TODO
- } // valueChanged()
+ }
/**
* createSelectionModel
- * @returns ListSelectionModel
+ * @return ListSelectionModel
*/
- protected ListSelectionModel createSelectionModel() {
+ protected ListSelectionModel createSelectionModel()
+ {
return null; // TODO
- } // createSelectionModel()
+ }
/**
* recalcWidthCache
*/
- protected void recalcWidthCache() {
+ protected void recalcWidthCache()
+ {
// TODO
- } // recalcWidthCache()
+ }
/**
* invalidateWidthCache
*/
- private void invalidateWidthCache() {
+ private void invalidateWidthCache()
+ {
// TODO
- } // invalidateWidthCache()
-
-
-} // DefaultTableColumnModel
-
+ }
+}
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
-
package javax.swing.table;
import java.beans.PropertyChangeListener;
import java.io.Serializable;
import javax.swing.event.SwingPropertyChangeSupport;
+
/**
* TableColumn
* @author Andrew Selkirk
* @version 1.0
*/
-public class TableColumn implements Serializable
+public class TableColumn
+ implements Serializable
{
static final long serialVersionUID = -6113660025878112608L;
- //-------------------------------------------------------------
- // Variables --------------------------------------------------
- //-------------------------------------------------------------
-
/**
* COLUMN_WIDTH_PROPERTY
*/
/**
* changeSupport
*/
- private SwingPropertyChangeSupport changeSupport = new SwingPropertyChangeSupport(this);
-
-
- //-------------------------------------------------------------
- // Initialization ---------------------------------------------
- //-------------------------------------------------------------
+ private SwingPropertyChangeSupport changeSupport =
+ new SwingPropertyChangeSupport(this);
/**
* Constructor TableColumn
*/
- public TableColumn() {
+ public TableColumn()
+ {
this(0, 75, null, null);
- } // TableColumn()
+ }
/**
* Constructor TableColumn
* @param modelIndex TODO
*/
- public TableColumn(int modelIndex) {
+ public TableColumn(int modelIndex)
+ {
this(modelIndex, 75, null, null);
- } // TableColumn()
+ }
/**
* Constructor TableColumn
* @param modelIndex TODO
* @param width TODO
*/
- public TableColumn(int modelIndex, int width) {
+ public TableColumn(int modelIndex, int width)
+ {
this(modelIndex, width, null, null);
- } // TableColumn()
+ }
/**
* Constructor TableColumn
* @param cellEditor TODO
*/
public TableColumn(int modelIndex, int width,
- TableCellRenderer cellRenderer, TableCellEditor cellEditor) {
+ TableCellRenderer cellRenderer, TableCellEditor cellEditor)
+ {
this.modelIndex = modelIndex;
this.width = width;
this.preferredWidth = width;
this.cellEditor = cellEditor;
this.headerValue = null;
this.identifier = null;
- } // TableColumn()
-
-
- //-------------------------------------------------------------
- // Methods ----------------------------------------------------
- //-------------------------------------------------------------
+ }
/**
* firePropertyChange
* @param oldValue TODO
* @param newValue TODO
*/
- private void firePropertyChange(String property, Object oldValue, Object newValue) {
+ private void firePropertyChange(String property, Object oldValue,
+ Object newValue)
+ {
changeSupport.firePropertyChange(property, oldValue, newValue);
- } // firePropertyChange()
+ }
/**
* firePropertyChange
* @param oldValue TODO
* @param newValue TODO
*/
- private void firePropertyChange(String property, int oldValue, int newValue) {
+ private void firePropertyChange(String property, int oldValue, int newValue)
+ {
firePropertyChange(property, new Integer(oldValue), new Integer(newValue));
- } // firePropertyChange()
+ }
/**
* firePropertyChange
* @param oldValue TODO
* @param newValue TODO
*/
- private void firePropertyChange(String property, boolean oldValue, boolean newValue)
+ private void firePropertyChange(String property, boolean oldValue,
+ boolean newValue)
{
firePropertyChange(property, new Boolean(oldValue), new Boolean(newValue));
}
* setModelIndex
* @param modelIndex TODO
*/
- public void setModelIndex(int modelIndex) {
+ public void setModelIndex(int modelIndex)
+ {
this.modelIndex = modelIndex;
- } // setModelIndex()
+ }
/**
* getModelIndex
- * @returns int
+ * @return int
*/
- public int getModelIndex() {
+ public int getModelIndex()
+ {
return modelIndex;
- } // getModelIndex()
+ }
/**
* setIdentifier
* @param identifier TODO
*/
- public void setIdentifier(Object identifier) {
+ public void setIdentifier(Object identifier)
+ {
this.identifier = identifier;
- } // setIdentifier()
+ }
/**
* getIdentifier
- * @returns Object
+ * @return Object
*/
- public Object getIdentifier() {
- if (identifier == null) {
+ public Object getIdentifier()
+ {
+ if (identifier == null)
return getHeaderValue();
- } // if
return identifier;
- } // getIdentifier()
+ }
/**
* setHeaderValue
* @param headerValue TODO
*/
- public void setHeaderValue(Object headerValue) {
-
+ public void setHeaderValue(Object headerValue)
+ {
// Variables
Object oldValue;
this.headerValue = headerValue;
// Notify Listeners of change
- firePropertyChange(HEADER_VALUE_PROPERTY,
- oldValue, headerValue);
-
- } // setHeaderValue()
+ firePropertyChange(HEADER_VALUE_PROPERTY, oldValue, headerValue);
+ }
/**
* getHeaderValue
- * @returns Object
+ * @return Object
*/
- public Object getHeaderValue() {
+ public Object getHeaderValue()
+ {
return headerValue;
- } // getHeaderValue()
+ }
/**
* setHeaderRenderer
* @param headerRenderer TODO
*/
- public void setHeaderRenderer(TableCellRenderer headerRenderer) {
-
+ public void setHeaderRenderer(TableCellRenderer headerRenderer)
+ {
// Variables
TableCellRenderer oldRenderer;
this.headerRenderer = headerRenderer;
// Notify Listeners of change
- firePropertyChange(HEADER_RENDERER_PROPERTY,
- oldRenderer, headerRenderer);
-
- } // setHeaderRenderer()
+ firePropertyChange(HEADER_RENDERER_PROPERTY, oldRenderer, headerRenderer);
+ }
/**
* getHeaderRenderer
- * @returns TableCellRenderer
+ * @return TableCellRenderer
*/
- public TableCellRenderer getHeaderRenderer() {
+ public TableCellRenderer getHeaderRenderer()
+ {
return headerRenderer;
- } // getHeaderRenderer()
+ }
/**
* setCellRenderer
* @param cellRenderer TODO
*/
- public void setCellRenderer(TableCellRenderer cellRenderer) {
-
+ public void setCellRenderer(TableCellRenderer cellRenderer)
+ {
// Variables
TableCellRenderer oldRenderer;
this.cellRenderer = cellRenderer;
// Notify Listeners of change
- firePropertyChange(CELL_RENDERER_PROPERTY,
- oldRenderer, cellRenderer);
-
- } // setCellRenderer()
+ firePropertyChange(CELL_RENDERER_PROPERTY, oldRenderer, cellRenderer);
+ }
/**
* getCellRenderer
- * @returns TableCellRenderer
+ * @return TableCellRenderer
*/
- public TableCellRenderer getCellRenderer() {
+ public TableCellRenderer getCellRenderer()
+ {
return cellRenderer;
- } // getCellRenderer()
+ }
/**
* setCellEditor
* @param cellEditor TODO
*/
- public void setCellEditor(TableCellEditor cellEditor) {
+ public void setCellEditor(TableCellEditor cellEditor)
+ {
this.cellEditor = cellEditor;
- } // setCellEditor()
+ }
/**
* getCellEditor
- * @returns TableCellEditor
+ * @return TableCellEditor
*/
- public TableCellEditor getCellEditor() {
+ public TableCellEditor getCellEditor()
+ {
return cellEditor;
- } // getCellEditor()
+ }
/**
* setWidth
* @param width TODO
*/
- public void setWidth(int width) {
-
+ public void setWidth(int width)
+ {
// Variables
int oldWidth;
oldWidth = this.width;
// Adjust Width within Limits
- if (width < minWidth) {
+ if (width < minWidth)
this.width = minWidth;
- } else if (width > maxWidth) {
+ else if (width > maxWidth)
this.width = maxWidth;
- } else {
+ else
this.width = width;
- } // if
- // Fire Property Change
firePropertyChange(COLUMN_WIDTH_PROPERTY, oldWidth, this.width);
-
- } // setWidth()
+ }
/**
* getWidth
- * @returns int
+ * @return int
*/
- public int getWidth() {
+ public int getWidth()
+ {
return width;
- } // getWidth()
+ }
/**
* setPreferredWidth
* @param preferredWidth TODO
*/
- public void setPreferredWidth(int preferredWidth) {
- if (preferredWidth < minWidth) {
+ public void setPreferredWidth(int preferredWidth)
+ {
+ if (preferredWidth < minWidth)
this.preferredWidth = minWidth;
- } else if (preferredWidth > maxWidth) {
+ else if (preferredWidth > maxWidth)
this.preferredWidth = maxWidth;
- } else {
+ else
this.preferredWidth = preferredWidth;
- } // if
- } // setPreferredWidth()
+ }
/**
* getPreferredWidth
- * @returns int
+ * @return int
*/
- public int getPreferredWidth() {
+ public int getPreferredWidth()
+ {
return preferredWidth;
- } // getPreferredWidth()
+ }
/**
* setMinWidth
* @param minWidth TODO
*/
- public void setMinWidth(int minWidth) {
+ public void setMinWidth(int minWidth)
+ {
this.minWidth = minWidth;
setWidth(getWidth());
setPreferredWidth(getPreferredWidth());
- } // setMinWidth()
+ }
/**
* getMinWidth
- * @returns int
+ * @return int
*/
- public int getMinWidth() {
+ public int getMinWidth()
+ {
return minWidth;
- } // getMinWidth()
+ }
/**
* setMaxWidth
* @param maxWidth TODO
*/
- public void setMaxWidth(int maxWidth) {
+ public void setMaxWidth(int maxWidth)
+ {
this.maxWidth = maxWidth;
setWidth(getWidth());
setPreferredWidth(getPreferredWidth());
- } // setMaxWidth()
+ }
/**
* getMaxWidth
- * @returns int
+ * @return int
*/
- public int getMaxWidth() {
+ public int getMaxWidth()
+ {
return maxWidth;
- } // getMaxWidth()
+ }
/**
* setResizable
* @param isResizable TODO
*/
- public void setResizable(boolean isResizable) {
+ public void setResizable(boolean isResizable)
+ {
this.isResizable = isResizable;
- } // setResizable()
+ }
/**
* getResizable
- * @returns boolean
+ * @return boolean
*/
- public boolean getResizable() {
+ public boolean getResizable()
+ {
return isResizable;
- } // getResizable()
+ }
/**
* sizeWidthToFit
*/
- public void sizeWidthToFit() {
+ public void sizeWidthToFit()
+ {
// TODO
- } // sizeWidthToFit()
+ }
/**
* disableResizedPosting
*/
- public void disableResizedPosting() {
+ public void disableResizedPosting()
+ {
// Does nothing
- } // disableResizedPosting()
+ }
/**
* enableResizedPosting
*/
- public void enableResizedPosting() {
+ public void enableResizedPosting()
+ {
// Does nothing
- } // enableResizedPosting()
+ }
/**
* addPropertyChangeListener
- * @param listener TODO
+ * @param listener the listener to all
*/
- public synchronized void addPropertyChangeListener(PropertyChangeListener listener) {
+ public synchronized void addPropertyChangeListener(PropertyChangeListener listener)
+ {
changeSupport.addPropertyChangeListener(listener);
- } // addPropertyChangeListener()
+ }
/**
* removePropertyChangeListener
- * @param listener TODO
+ * @param listener the listener to remove
*/
- public synchronized void removePropertyChangeListener(PropertyChangeListener listener) {
+ public synchronized void removePropertyChangeListener(PropertyChangeListener listener)
+ {
changeSupport.removePropertyChangeListener(listener);
- } // removePropertyChangeListener()
+ }
/**
* createDefaultHeaderRenderer
- * @returns TableCellRenderer
+ * @return TableCellRenderer
*/
- protected TableCellRenderer createDefaultHeaderRenderer() {
+ protected TableCellRenderer createDefaultHeaderRenderer()
+ {
return new DefaultTableCellRenderer();
- } // createDefaultHeaderRenderer()
-
-
-} // TableColumn
+ }
+}
package javax.swing.table;
-// Imports
import java.util.Enumeration;
import javax.swing.ListSelectionModel;
import javax.swing.event.TableColumnModelListener;
+
/**
* TableColumnModel public interface
* @author Andrew Selkirk
*/
-public interface TableColumnModel {
-
+public interface TableColumnModel
+{
/**
* addColumn
* @param column TableColumn
/**
* getColumnCount
- * @returns Column count
+ * @return Column count
*/
int getColumnCount();
/**
* getColumns
- * @returns Enumeration of columns
+ * @return Enumeration of columns
*/
Enumeration getColumns();
/**
* getColumnMargin
- * @returns Column margin
+ * @return Column margin
*/
int getColumnMargin();
/**
* getColumnIndexAtX
- * @returns Column index as position x
+ * @return Column index as position x
*/
int getColumnIndexAtX(int xPosition);
/**
* getTotalColumnWidth
- * @returns Total column width
+ * @return Total column width
*/
int getTotalColumnWidth();
/**
* getColumnSelectionAllowed
- * @returns true if column selection allowed, false otherwise
+ * @return true if column selection allowed, false otherwise
*/
boolean getColumnSelectionAllowed();
/**
* getSelectedColumns
- * @returns Selected columns
+ * @return Selected columns
*/
int[] getSelectedColumns();
/**
* getSelectedColumnCount
- * @returns Count of selected columns
+ * @return Count of selected columns
*/
int getSelectedColumnCount();
* @param listener TableColumnModelListener
*/
void removeColumnModelListener(TableColumnModelListener listener);
-
-
-} // TableColumnModel
+}
package javax.swing.table;
-// Imports
import javax.swing.event.TableModelListener;
+
/**
* TableModel public interface
* @author Andrew Selkirk
*/
-public interface TableModel {
-
+public interface TableModel
+{
/**
* getRowCount
- * @returns row count
+ * @return row count
*/
int getRowCount();
/**
* getColumnCount
- * @returns column count
+ * @return column count
*/
int getColumnCount();
/**
* getColumnName
* @param columnIndex Column index
- * @returns Column name
+ * @return Column name
*/
String getColumnName(int columnIndex);
/**
* getColumnClass
* @param columnIndex Column index
- * @returns Column class
+ * @return Column class
*/
Class getColumnClass(int columnIndex);
* isCellEditable
* @param rowIndex Row index
* @param columnIndex Column index
- * @returns true if editable, false otherwise
+ * @return true if editable, false otherwise
*/
boolean isCellEditable(int rowIndex, int columnIndex);
* getValueAt
* @param rowIndex Row index
* @param columnIndex Column index
- * @returns Value at specified indices
+ * @return Value at specified indices
*/
Object getValueAt(int rowIndex, int columnIndex);
* @param listener TableModelListener
*/
void removeTableModelListener(TableModelListener listener);
-
-
-} // TableModel
+}
import java.util.Enumeration;
import java.util.EventListener;
import java.util.Vector;
-
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.event.EventListenerList;
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;
-
- 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();
- }
-
- 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);
- }
-
- 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;
- }
- }
-
- public 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;
- }
-
- public class DefaultDocumentEvent extends CompoundEdit
- implements DocumentEvent
- {
- private static final long serialVersionUID = -7406103236022413522L;
-
- public int len;
- public int 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;
- }
- }
-
- public static class ElementEdit extends AbstractUndoableEdit
- {
- private static final long serialVersionUID = -1216620962142928304L;
- }
-
- public class LeafElement extends AbstractElement
- {
- private static final long serialVersionUID = 5115368706941283802L;
-
- public 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;
- }
- }
-
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";
-
Content content;
+ protected EventListenerList listenerList = new EventListenerList();
protected AbstractDocument(Content doc)
{
content = doc;
}
- protected EventListenerList listenerList = new EventListenerList();
-
// these still need to be implemented by a derived class:
public abstract Element getParagraphElement(int pos);
return new LeafElement(parent, a, p0, p1 - p0);
}
- public Position createPosition(int offs)
+ public Position createPosition(final int offset) throws BadLocationException
{
- final int a = offs;
+ if (offset < 0 || offset > getLength())
+ throw new BadLocationException(getText(0, getLength()), offset);
+
return new Position()
{
public int getOffset()
{
- return a;
+ return offset;
}
};
}
return null;
}
- public String getText(int offset, int length)
- {
- try
+ public String getText(int offset, int length) throws BadLocationException
{
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)
+ throws BadLocationException
{
String a = getText(offset, length);
txt.offset = 0;
txt.count = 0;
txt.array = new char[0];
+
return;
}
{
}
- public void remove(int offs, int len)
+ public void remove(int offset, int length) throws BadLocationException
{
}
protected void writeUnlock()
{
}
+
+ public interface AttributeContext
+ {
+ AttributeSet addAttribute(AttributeSet old, Object name, Object value);
+
+ AttributeSet addAttributes(AttributeSet old, AttributeSet attributes);
+
+ AttributeSet getEmptySet();
+
+ void reclaim(AttributeSet attributes);
+
+ AttributeSet removeAttribute(AttributeSet old, Object name);
+
+ AttributeSet removeAttributes(AttributeSet old, AttributeSet attributes);
+
+ AttributeSet removeAttributes(AttributeSet old, Enumeration names);
+ }
+
+ public 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;
+ }
+
+ 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;
+
+ 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();
+ }
+
+ public class BranchElement extends AbstractElement
+ {
+ private static final long serialVersionUID = -8595176318868717313L;
+ private int start;
+ private int end;
+ private Vector children = new Vector();
+
+ public BranchElement(Element parent, AttributeSet attributes, int start,
+ int end)
+ {
+ super(parent, attributes);
+ this.start = start;
+ this.end = end;
+ }
+
+ public Enumeration children()
+ {
+ return children.elements();
+ }
+
+ public boolean getAllowsChildren()
+ {
+ return true;
+ }
+
+ public Element getElement(int index)
+ {
+ return (Element) children.get(index);
+ }
+
+ public int getElementCount()
+ {
+ return children.size();
+ }
+
+ public int getElementIndex(int offset)
+ {
+ return children.indexOf(positionToElement(offset));
+ }
+
+ public int getEndOffset()
+ {
+ return end;
+ }
+
+ public String getName()
+ {
+ return "AbstractDocument.BranchElement";
+ }
+
+ public int getStartOffset()
+ {
+ return start;
+ }
+
+ public boolean isLeaf()
+ {
+ return false;
+ }
+
+ public Element positionToElement(int position)
+ {
+ // XXX: There is surely a better algorithm
+ // as beginning from first element each time.
+ for (int index = 0; index < children.size(); ++index)
+ {
+ Element elem = (Element) children.get(index);
+
+ if ((elem.getStartOffset() <= position)
+ && (position < elem.getEndOffset()))
+ return elem;
+ }
+
+ return null;
+ }
+
+ public void replace(int offset, int length, Element[] elems)
+ {
+ for (int index = 0; index < length; ++index)
+ children.removeElementAt(offset);
+
+ for (int index = 0; index < elems.length; ++index)
+ children.add(offset + index, elems[index]);
+ }
+
+ public String toString()
+ {
+ return getName() + ": " + "content";
+ }
+ }
+
+ public class DefaultDocumentEvent extends CompoundEdit
+ implements DocumentEvent
+ {
+ private static final long serialVersionUID = -7406103236022413522L;
+ public int len;
+ public int 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;
+ }
+ }
+
+ public static class ElementEdit extends AbstractUndoableEdit
+ {
+ private static final long serialVersionUID = -1216620962142928304L;
+ }
+
+ public class LeafElement extends AbstractElement
+ {
+ private static final long serialVersionUID = 5115368706941283802L;
+ private int start;
+ private int end;
+
+ public LeafElement(Element parent, AttributeSet attributes, int start,
+ int end)
+ {
+ super(parent, attributes);
+ this.start = start;
+ this.end = end;
+ }
+
+ public Enumeration children()
+ {
+ return null;
+ }
+
+ public boolean getAllowsChildren()
+ {
+ return false;
+ }
+
+ public Element getElement()
+ {
+ return null;
+ }
+
+ public int getElementCount()
+ {
+ return 0;
+ }
+
+ public int getElementIndex(int offset)
+ {
+ return -1;
+ }
+
+ public int getEndOffset()
+ {
+ return end;
+ }
+
+ public String getName()
+ {
+ return "AbstractDocument.LeafElement";
+ }
+
+ public int getStartOffset()
+ {
+ return start;
+ }
+
+ public boolean isLeaf()
+ {
+ return true;
+ }
+
+ public String toString()
+ {
+ return getName() + ": " + "content";
+ }
+ }
}
public interface AttributeSet
{
+ static interface CharacterAttribute
+ {
+ }
+
+ static interface ColorAttribute
+ {
+ }
+
+ static interface FontAttribute
+ {
+ }
+
+ static interface ParagraphAttribute
+ {
+ }
+
boolean containsAttribute(Object name, Object value);
boolean containsAttributes(AttributeSet attributes);
AttributeSet copyAttributes();
+++ /dev/null
-/* CharacterIterator.java --
- Copyright (C) 2002 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.text;
-
-
-public interface CharacterIterator extends Cloneable
-{
- Object clone();
- char current();
- char first();
- int getBeginIndex();
- int getEndIndex();
- int getIndex();
- char last();
- char next();
- char previous();
- char setIndex(int position);
-}
}
public Shape modelToView(int pos, Shape a, Position.Bias b)
+ throws BadLocationException
{
return null;
}
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Rectangle;
+import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
+import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.util.EventListener;
public class DefaultCaret extends Rectangle
implements Caret, FocusListener, MouseListener, MouseMotionListener
{
+ private static final long serialVersionUID = 228155774675466193L;
+
protected ChangeEvent changeEvent = new ChangeEvent(this);
protected EventListenerList listenerList = new EventListenerList();
boolean vis = true;
- public void mouseDragged(java.awt.event.MouseEvent evt)
+ public void mouseDragged(MouseEvent event)
+ {
+ }
+
+ public void mouseMoved(MouseEvent event)
+ {
+ }
+
+ public void mouseClicked(MouseEvent event)
{
}
- public void mouseMoved(java.awt.event.MouseEvent evt)
+ public void mouseEntered(MouseEvent event)
{
}
- public void mouseClicked(java.awt.event.MouseEvent evt)
+ public void mouseExited(MouseEvent event)
{
}
- public void mouseEntered(java.awt.event.MouseEvent evt)
+ public void mousePressed(MouseEvent event)
{
}
- public void mouseExited(java.awt.event.MouseEvent evt)
+ public void mouseReleased(MouseEvent event)
{
}
- public void mousePressed(java.awt.event.MouseEvent evt)
+ public void focusGained(FocusEvent event)
{
}
- public void mouseReleased(java.awt.event.MouseEvent evt)
+ public void focusLost(FocusEvent event)
{
}
- public void focusGained(java.awt.event.FocusEvent evt)
+ protected void moveCaret(MouseEvent event)
{
}
- public void focusLost(java.awt.event.FocusEvent evt)
+ protected void positionCaret(MouseEvent event)
{
}
return vis_sel;
}
- private void repaint()
+ protected final void repaint()
{
if (parent != null)
parent.repaint();
package javax.swing.text;
import java.io.InputStream;
+import java.io.IOException;
import java.io.OutputStream;
import java.io.Reader;
import java.io.Writer;
import javax.swing.Action;
import javax.swing.JEditorPane;
+
public class DefaultEditorKit extends EditorKit
{
+ private static final long serialVersionUID = 9017245433028523428L;
public static final String backwardAction = "caret-backward";
public static final String beepAction = "beep";
public static final String beginAction = "caret-begin";
public static final String downAction = "caret-down";
public static final String endAction = "caret-end";
public static final String endLineAction = "caret-end-line";
- public static final String endOfLineStringProperty = "__EndOfLine__";
+ public static final String EndOfLineStringProperty = "__EndOfLine__";
public static final String endParagraphAction = "caret-end-paragraph";
public static final String endWordAction = "caret-end-word";
public static final String forwardAction = "caret-forward";
public static final String selectionBackwardAction = "selection-backward";
public static final String selectionBeginAction = "selection-begin";
public static final String selectionBeginLineAction = "selection-begin-line";
- public static final String selectionBeginParagraphAction = "selection-begin-paragraph";
+ public static final String selectionBeginParagraphAction =
+ "selection-begin-paragraph";
public static final String selectionBeginWordAction = "selection-begin-word";
public static final String selectionDownAction = "selection-down";
public static final String selectionEndAction = "selection-end";
public static final String selectionEndLineAction = "selection-end-line";
- public static final String selectionEndParagraphAction = "selection-end-paragraph";
+ public static final String selectionEndParagraphAction =
+ "selection-end-paragraph";
public static final String selectionEndWordAction = "selection-end-word";
public static final String selectionForwardAction = "selection-forward";
public static final String selectionNextWordAction = "selection-next-word";
- public static final String selectionPreviousWordAction = "selection-previous-word";
+ public static final String selectionPreviousWordAction =
+ "selection-previous-word";
public static final String selectionUpAction = "selection-up";
public static final String selectLineAction = "select-line";
public static final String selectParagraphAction = "select-paragraph";
public static final String upAction = "caret-up";
public static final String writableAction = "set-writable";
- void deinstall(JEditorPane c)
+ public DefaultEditorKit()
+ {
+ }
+
+ /**
+ * Called when the kit is being removed from the JEditorPane.
+ */
+ public void deinstall(JEditorPane c)
{
- // Called when the kit is being removed from the JEditorPane.
}
- void install(JEditorPane c)
+
+ public void install(JEditorPane c)
{
}
- Caret createCaret()
+ public Caret createCaret()
{
return null;
}
- Document createDefaultDocument()
+
+ public Document createDefaultDocument()
{
return new PlainDocument();
}
- Action[] getActions()
+ public Action[] getActions()
{
return null;
}
- String getContentType()
+ public String getContentType()
{
return "text/plain";
}
- ViewFactory getViewFactory()
+ public ViewFactory getViewFactory()
{
return null;
}
- void read(InputStream in, Document doc, int pos)
+
+ public void read(InputStream in, Document doc, int pos)
+ throws BadLocationException, IOException
{
}
- void read(Reader in, Document doc, int pos)
+
+ public void read(Reader in, Document doc, int pos)
+ throws BadLocationException, IOException
{
}
- void write(OutputStream out, Document doc, int pos, int len)
+
+ public void write(OutputStream out, Document doc, int pos, int len)
+ throws BadLocationException, IOException
{
}
- void write(Writer out, Document doc, int pos, int len)
+
+ public void write(Writer out, Document doc, int pos, int len)
+ throws BadLocationException, IOException
{
}
}
-
--- /dev/null
+/* DefaultHighlighter.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.text;
+
+import java.awt.Graphics;
+import java.awt.Shape;
+import java.util.Vector;
+
+import javax.swing.text.JTextComponent;
+import javax.swing.text.View;
+
+
+public class DefaultHighlighter extends LayeredHighlighter
+{
+ private class HighlightEntry
+ {
+ int p0;
+ int p1;
+ Highlighter.HighlightPainter painter;
+
+ public HighlightEntry(int p0, int p1, Highlighter.HighlightPainter painter)
+ {
+ this.p0 = p0;
+ this.p1 = p1;
+ this.painter = painter;
+ }
+
+ public int getStartPosition()
+ {
+ return p0;
+ }
+
+ public int getEndPosition()
+ {
+ return p1;
+ }
+
+ public Highlighter.HighlightPainter getPainter()
+ {
+ return painter;
+ }
+ }
+
+ private JTextComponent textComponent;
+ private Vector highlights = new Vector();
+
+ public DefaultHighlighter()
+ {
+ }
+
+ private void checkPositions(int p0, int p1)
+ throws BadLocationException
+ {
+ if (p0 < 0)
+ throw new BadLocationException("DefaultHighlighter", p0);
+
+ if (p1 < p0)
+ throw new BadLocationException("DefaultHighlighter", p1);
+ }
+
+ public void install(JTextComponent c)
+ {
+ textComponent = c;
+ removeAllHighlights();
+ }
+
+ public void deinstall(JTextComponent c)
+ {
+ textComponent = null;
+ }
+
+ public Object addHighlight(int p0, int p1, Highlighter.HighlightPainter painter)
+ throws BadLocationException
+ {
+ checkPositions(p0, p1);
+ HighlightEntry entry = new HighlightEntry(p0, p1, painter);
+ highlights.add(entry);
+ return entry;
+ }
+
+ public void removeHighlight(Object tag)
+ {
+ highlights.remove(tag);
+ }
+
+ public void removeAllHighlights()
+ {
+ highlights.clear();
+ }
+
+ public Highlighter.Highlight[] getHighlights()
+ {
+ return null;
+ }
+
+ public void changeHighlight(Object tag, int p0, int p1)
+ throws BadLocationException
+ {
+ checkPositions(p0, p1);
+ HighlightEntry entry = (HighlightEntry) tag;
+ entry.p0 = p0;
+ entry.p1 = p1;
+ }
+
+ public void paintLayeredHighlights(Graphics g, int p0, int p1,
+ Shape viewBounds, JTextComponent editor,
+ View view)
+ {
+ }
+
+ public void paint(Graphics g)
+ {
+ }
+}
void addUndoableEditListener(UndoableEditListener listener);
- Position createPosition(int offs);
+ Position createPosition(int offs)
+ throws BadLocationException;
Element getDefaultRootElement();
Position getStartPosition();
- String getText(int offset, int length);
+ String getText(int offset, int length)
+ throws BadLocationException;
- void getText(int offset, int length, Segment txt);
+ void getText(int offset, int length, Segment txt)
+ throws BadLocationException;
void insertString(int offset, String str, AttributeSet a)
throws BadLocationException;
void putProperty(Object key, Object value);
- void remove(int offs, int len);
+ void remove(int offs, int len)
+ throws BadLocationException;
void removeDocumentListener(DocumentListener listener);
package javax.swing.text;
import java.io.InputStream;
+import java.io.IOException;
import java.io.OutputStream;
import java.io.Reader;
+import java.io.Serializable;
import java.io.Writer;
import javax.swing.Action;
import javax.swing.JEditorPane;
-public abstract class EditorKit implements Cloneable
+
+public abstract class EditorKit
+ implements Cloneable, Serializable
{
- EditorKit()
+ private static final long serialVersionUID = -5044124649345887822L;
+
+ public EditorKit()
{
}
- EditorKit(EditorKit kit)
+ public Object clone()
{
+ try
+ {
+ return super.clone();
}
-
- void deinstall(JEditorPane c)
+ catch (CloneNotSupportedException e)
{
- // Called when the kit is being removed from the JEditorPane.
+ return null;
}
- void install(JEditorPane c)
+ }
+
+ /**
+ * Called when the kit is being removed from the JEditorPane.
+ */
+ public void deinstall(JEditorPane c)
{
}
- abstract Caret createCaret();
- abstract Document createDefaultDocument();
- abstract Action[] getActions();
- abstract String getContentType();
- abstract ViewFactory getViewFactory();
- abstract void read(InputStream in, Document doc, int pos);
- abstract void read(Reader in, Document doc, int pos);
- abstract void write(OutputStream out, Document doc, int pos, int len);
- abstract void write(Writer out, Document doc, int pos, int len);
+ public void install(JEditorPane c)
+ {
}
+ public abstract Caret createCaret();
+ public abstract Document createDefaultDocument();
+ public abstract Action[] getActions();
+ public abstract String getContentType();
+ public abstract ViewFactory getViewFactory();
+ public abstract void read(InputStream in, Document doc, int pos)
+ throws BadLocationException, IOException;
+ public abstract void read(Reader in, Document doc, int pos)
+ throws BadLocationException, IOException;
+ public abstract void write(OutputStream out, Document doc, int pos, int len)
+ throws BadLocationException, IOException;
+ public abstract void write(Writer out, Document doc, int pos, int len)
+ throws BadLocationException, IOException;
+}
--- /dev/null
+/* FieldView.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.text;
+
+import java.awt.Component;
+import java.awt.FontMetrics;
+import java.awt.Graphics;
+import java.awt.Shape;
+
+
+public class FieldView extends PlainView
+{
+ public FieldView(Element elem)
+ {
+ super(elem);
+ }
+
+ protected FontMetrics getFontMetrics()
+ {
+ Component container = getContainer();
+ return container.getFontMetrics(container.getFont());
+ }
+
+ public float getPreferredSpan(int axis)
+ {
+ if (axis != X_AXIS && axis != Y_AXIS)
+ throw new IllegalArgumentException();
+
+ FontMetrics fm = getFontMetrics();
+
+ if (axis == Y_AXIS)
+ return fm.getHeight();
+
+ String text;
+ Element elem = getElement();
+
+ try
+ {
+ text = elem.getDocument().getText(elem.getStartOffset(),
+ elem.getEndOffset());
+ }
+ catch (BadLocationException e)
+ {
+ // This should never happen.
+ text = "";
+ System.out.println("Michael: FieldView.getPreferredSpan: Error");
+ }
+
+ return fm.stringWidth(text);
+ }
+
+ public int getResizeWeight(int axis)
+ {
+ return axis = axis == X_AXIS ? 1 : 0;
+ }
+
+ public void paint(Graphics g, Shape s)
+ {
+ drawLine(0, g, 0, 0);
+ }
+}
--- /dev/null
+/* Highlighter.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.text;
+
+import java.awt.Graphics;
+import java.awt.Shape;
+
+
+public interface Highlighter
+{
+ public interface Highlight
+ {
+ int getEndOffset();
+
+ int getStartOffset();
+
+ HighlightPainter getPainter();
+ }
+
+ public interface HighlightPainter
+ {
+ public void paint(Graphics g, int p0, int p1, Shape bounds,
+ JTextComponent c);
+ }
+
+ void install(JTextComponent c);
+
+ void deinstall(JTextComponent c);
+
+ Object addHighlight(int p0, int p1, HighlightPainter p)
+ throws BadLocationException;
+
+ void removeAllHighlights();
+
+ void removeHighlight(Object tag);
+
+ void changeHighlight(Object tag, int p0, int p1)
+ throws BadLocationException;
+
+ Highlight[] getHighlights();
+
+ void paint(Graphics g);
+}
+
package javax.swing.text;
import java.awt.AWTEvent;
+import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Image;
public abstract class JTextComponent extends JComponent
implements Scrollable, Accessible
{
-// public class AccessibleJTextComponent extends AccessibleJComponent
-// implements AccessibleText, CaretListener, DocumentListener,
-// AccessibleAction, AccessibleEditableText
-// {
-// }
-
/**
* AccessibleJTextComponent
*/
{
private static final long serialVersionUID = 7664188944091413696L;
- /**
- * caretPos
- */
- int caretPos;
-
/**
* Constructor AccessibleJTextComponent
* @param component TODO
public KeyStroke key;
public String actionName;
+ /**
+ * Creates a new <code>KeyBinding</code> instance.
+ *
+ * @param key a <code>KeyStroke</code> value
+ * @param actionName a <code>String</code> value
+ */
public KeyBinding(KeyStroke key, String actionName)
{
this.key = key;
private Document doc;
private Caret caret;
+ private Highlighter highlighter;
+ private Color caretColor;
+ private Color disabledTextColor;
+ private Color selectedTextColor;
+ private Color selectionColor;
private boolean editable;
+ /**
+ * Creates a new <code>JTextComponent</code> instance.
+ */
public JTextComponent()
{
enableEvents(AWTEvent.KEY_EVENT_MASK);
public Document getDocument()
{
- if (doc == null)
- System.out.println("doc == null !!!");
return doc;
}
/**
- * Get the AccessibleContext of this object
+ * Get the <code>AccessibleContext<code> of this object.
+ *
+ * @return an <code>AccessibleContext</code> object
*/
public AccessibleContext getAccessibleContext()
{
*/
public String getText()
{
- return getDocument().getText(0, getDocument().getLength());
+ if (doc == null)
+ return null;
+
+ try
+ {
+ return doc.getText(0, doc.getLength());
+ }
+ catch (BadLocationException e)
+ {
+ // This should never happen.
+ return "";
+ }
}
/**
return "JTextComponent";
}
+ /**
+ * This method returns the label's UI delegate.
+ *
+ * @return The label's UI delegate.
+ */
public TextUI getUI()
{
- return (TextUI) UIManager.getUI(this);
+ return (TextUI) ui;
+ }
+
+ /**
+ * This method sets the label's UI delegate.
+ *
+ * @param ui The label's UI delegate.
+ */
+ public void setUI(TextUI newUI)
+ {
+ super.setUI(newUI);
}
+ /**
+ * This method resets the label's UI delegate to the default UI for the
+ * current look and feel.
+ */
public void updateUI()
{
- setUI(getUI());
+ setUI((TextUI) UIManager.getUI(this));
}
public Dimension getPreferredScrollableViewportSize()
return caret;
}
+ /**
+ * Sets a new <code>Caret</code> for this text component.
+ *
+ * @param newCaret the new <code>Caret</code> to set
+ */
+ public void setCaret(Caret newCaret)
+ {
+ firePropertyChange("caret", caret, newCaret);
+ caret = newCaret;
+ }
+
+ public Color getCaretColor()
+ {
+ return caretColor;
+ }
+
+ public void setCaretColor(Color newColor)
+ {
+ firePropertyChange("caretColor", caretColor, newColor);
+ caretColor = newColor;
+ }
+
+ public Color getDisabledTextColor()
+ {
+ return disabledTextColor;
+ }
+
+ public void setDisabledTextColor(Color newColor)
+ {
+ firePropertyChange("disabledTextColor", caretColor, newColor);
+ disabledTextColor = newColor;
+ }
+
+ public Color getSelectedTextColor()
+ {
+ return selectedTextColor;
+ }
+
+ public void setSelectedTextColor(Color newColor)
+ {
+ firePropertyChange("selectedTextColor", caretColor, newColor);
+ selectedTextColor = newColor;
+ }
+
+ public Color getSelectionColor()
+ {
+ return selectionColor;
+ }
+
+ public void setSelectionColor(Color newColor)
+ {
+ firePropertyChange("selectionColor", caretColor, newColor);
+ selectionColor = newColor;
+ }
+
/**
* Retrisves the current caret position.
*
caret.moveDot(position);
}
+ public Highlighter getHighlighter()
+ {
+ return highlighter;
+ }
+
+ public void setHighlighter(Highlighter newHighlighter)
+ {
+ firePropertyChange("highlighter", highlighter, newHighlighter);
+ highlighter = newHighlighter;
+ }
+
/**
* Returns the start postion of the currently selected text.
*
select(0, doc.getLength());
}
+ public synchronized void replaceSelection(String content)
+ {
+ int dot = caret.getDot();
+ int mark = caret.getMark();
+
+ // If content is empty delete selection.
+ if (content == null)
+ {
+ caret.setDot(dot);
+ return;
+ }
+
+ try
+ {
+ // Remove selected text.
+ if (dot != mark)
+ doc.remove(Math.min(dot, mark), Math.max(dot, mark));
+
+ // Insert new text.
+ doc.insertString(Math.min(dot, mark), content, null);
+ }
+ catch (BadLocationException e)
+ {
+ // This should never happen.
+ System.out.println("Michael: JTextComponent.replaceSelection: Error");
+ }
+ }
+
public boolean getScrollableTracksViewportHeight()
{
if (getParent() instanceof JViewport)
--- /dev/null
+/* LayeredHighlighter.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.text;
+
+import java.awt.Graphics;
+import java.awt.Shape;
+
+import javax.swing.text.JTextComponent;
+import javax.swing.text.View;
+
+
+public abstract class LayeredHighlighter
+ implements Highlighter
+{
+ public abstract static class LayerPainter
+ implements Highlighter.HighlightPainter
+ {
+ public abstract Shape paintLayer(Graphics g, int p0, int p1,
+ Shape viewBounds, JTextComponent editor,
+ View view);
+ }
+
+ public abstract void paintLayeredHighlights(Graphics g, int p0, int p1,
+ Shape viewBounds,
+ JTextComponent editor, View view);
+}
public static final String lineLimitAttribute = "lineLimit";
public static final String tabSizeAttribute = "tabSize";
+ private Element rootElement;
private int tabSize;
public PlainDocument()
{
super(content);
tabSize = 8;
+ rootElement = createDefaultRoot();
+ }
+
+ protected AbstractDocument.AbstractElement createDefaultRoot()
+ {
+ BranchElement rootElement =
+ (BranchElement) createBranchElement(null, null);
+ Element[] lines = new Element[1];
+ lines[0] = createLeafElement(rootElement, null, 0, 1);
+ rootElement.replace(0, 0, lines);
+ return rootElement;
}
public Element getDefaultRootElement()
{
- return null;
+ return rootElement;
}
public Element getParagraphElement(int pos)
+++ /dev/null
-/* PlainEditorKit.java --
- Copyright (C) 2002, 2004 Free Software Foundation, Inc.
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-02111-1307 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-package javax.swing.text;
-
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.Reader;
-import java.io.Writer;
-import javax.swing.Action;
-import javax.swing.JEditorPane;
-
-public class PlainEditorKit extends EditorKit
-{
- public PlainEditorKit()
- {
- }
-
- public PlainEditorKit(PlainEditorKit kit)
- {
- super(kit);
- }
-
- protected Object clone()
- {
- return new PlainEditorKit(this);
- }
- void deinstall(JEditorPane c)
- {
- // Called when the kit is being removed from the JEditorPane.
- }
- void install(JEditorPane c)
- {
- }
-
- Caret createCaret()
- {
- return null;
- }
- Document createDefaultDocument()
- {
- return null;
- }
- Action[] getActions()
- {
- return null;
- }
- String getContentType()
- {
- return null;
- }
- ViewFactory getViewFactory()
- {
- return null;
- }
- void read(InputStream in, Document doc, int pos)
- {
- }
- void read(Reader in, Document doc, int pos)
- {
- }
- void write(OutputStream out, Document doc, int pos, int len)
- {
- }
- void write(Writer out, Document doc, int pos, int len)
- {
- }
-}
-
--- /dev/null
+/* PlainView.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.text;
+
+import java.awt.Color;
+import java.awt.FontMetrics;
+import java.awt.Graphics;
+import java.awt.Rectangle;
+import java.awt.Shape;
+
+
+public class PlainView extends View
+ implements TabExpander
+{
+ protected FontMetrics metrics;
+
+ public PlainView(Element elem)
+ {
+ super(elem);
+ }
+
+ public void drawLine(int lineIndex, Graphics g, int x, int y)
+ {
+ try
+ {
+ metrics = g.getFontMetrics();
+ // FIXME: Selected text are not drawn yet.
+ drawUnselectedText(g, x, y, 0, getDocument().getLength());
+ //drawSelectedText(g, , , , );
+ }
+ catch (BadLocationException e)
+ {
+ // This should never happen.
+ }
+ }
+
+ public int drawSelectedText(Graphics g, int x, int y, int p0, int p1)
+ throws BadLocationException
+ {
+ String text = getDocument().getText(p0, p1);
+ g.setColor(Color.WHITE);
+ g.drawString(text, x, y);
+ return metrics.stringWidth(text);
+ }
+
+ public int drawUnselectedText(Graphics g, int x, int y, int p0, int p1)
+ throws BadLocationException
+ {
+ String text = getDocument().getText(p0, p1);
+ g.setColor(Color.BLACK);
+ g.drawString(text, x, y);
+ return metrics.stringWidth(text);
+ }
+
+ public void paint(Graphics g, Shape s)
+ {
+ System.out.println("Michael: PlainView.paint");
+
+ Rectangle rect = s.getBounds();
+
+ g.setColor(Color.WHITE);
+ g.fillRect(rect.x, rect.y, rect.width, rect.height);
+
+ // FIXME: Text may be scrolled.
+ drawLine(0, g, rect.x, rect.y);
+ }
+
+ public int getTabSize()
+ {
+ return 8;
+ }
+
+ public float nextTabStop(float x, int tabStop)
+ {
+ System.out.println("Michael: PlainView.nextTabpStop: missing implementation");
+ return x;
+ }
+
+ public float getPreferredSpan(int axis)
+ {
+ if (axis != X_AXIS && axis != Y_AXIS)
+ throw new IllegalArgumentException();
+
+ return 10;
+ }
+}
\ No newline at end of file
/* Position.java --
- Copyright (C) 2002 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
{
static class Bias
{
+ public static final Bias Backward = new Bias("backward");
+ public static final Bias Forward = new Bias("forward");
+
+ private String name;
+
+ private Bias(String n)
+ {
+ name = n;
+ }
+
+ public String toString()
+ {
+ return name;
+ }
}
int getOffset();
package javax.swing.text;
-public class Segment implements Cloneable, CharacterIterator
+import java.text.CharacterIterator;
+
+
+public class Segment
+ implements Cloneable, CharacterIterator
{
- char[] array;
- int count;
- int offset;
+ public char[] array;
+ public int count;
+ public int offset;
+
+ public Segment()
+ {
+ }
+
+ public Segment(char[] array, int offset, int count)
+ {
+ this.array = array;
+ this.offset = offset;
+ this.count = count;
+ }
public Object clone()
{
- try {
+ try
+ {
return super.clone();
- } catch (Exception e) {
- System.err.println("Huuuhhh, this class implements cloneable !!!!!!");
- System.err.println("I think there is a bug in this JVM somewhere");
}
+ catch (CloneNotSupportedException e)
+ {
return null;
}
+ }
public char current()
{
{
return offset + count;
}
+
public int getIndex()
{
return offset;
}
+
public char last()
{
offset = getEndIndex() - 1;
return array[offset];
}
+
public char next()
{
offset++;
return array[offset];
}
+
public char previous()
{
offset--;
return array[offset];
}
+
public char setIndex(int position)
{
offset = position;
return new String(array, offset, count);
}
}
-
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.Serializable;
-
import javax.swing.Action;
import javax.swing.JEditorPane;
import javax.swing.event.CaretEvent;
import javax.swing.event.CaretListener;
+
/**
* StyledEditorKit
+ *
* @author Andrew Selkirk
- * @version 1.0
*/
public class StyledEditorKit extends DefaultEditorKit
{
- static final long serialVersionUID = 7002391892985555948L;
-
- //-------------------------------------------------------------
- // Classes ----------------------------------------------------
- //-------------------------------------------------------------
+ private static final long serialVersionUID = 7002391892985555948L;
/**
* UnderlineAction
*/
- public static class UnderlineAction extends StyledEditorKit.StyledTextAction {
-
- //-------------------------------------------------------------
- // Initialization ---------------------------------------------
- //-------------------------------------------------------------
-
+ public static class UnderlineAction extends StyledEditorKit.StyledTextAction
+ {
/**
* Constructor UnderlineAction
*/
- public UnderlineAction() {
+ public UnderlineAction()
+ {
super("TODO");
// TODO
- } // UnderlineAction()
-
-
- //-------------------------------------------------------------
- // Methods ----------------------------------------------------
- //-------------------------------------------------------------
+ }
/**
* actionPerformed
* @param event TODO
*/
- public void actionPerformed(ActionEvent event) {
+ public void actionPerformed(ActionEvent event)
+ {
// TODO
- } // actionPerformed()
-
-
- } // UnderlineAction
+ }
+ }
/**
* ItalicAction
*/
- public static class ItalicAction extends StyledEditorKit.StyledTextAction {
-
- //-------------------------------------------------------------
- // Initialization ---------------------------------------------
- //-------------------------------------------------------------
-
+ public static class ItalicAction extends StyledEditorKit.StyledTextAction
+ {
/**
* Constructor ItalicAction
*/
- public ItalicAction() {
+ public ItalicAction()
+ {
super("TODO");
// TODO
- } // ItalicAction()
-
-
- //-------------------------------------------------------------
- // Methods ----------------------------------------------------
- //-------------------------------------------------------------
+ }
/**
* actionPerformed
* @param event TODO
*/
- public void actionPerformed(ActionEvent event) {
+ public void actionPerformed(ActionEvent event)
+ {
// TODO
- } // actionPerformed()
-
-
- } // ItalicAction
+ }
+ }
/**
* BoldAction
*/
- public static class BoldAction extends StyledEditorKit.StyledTextAction {
-
- //-------------------------------------------------------------
- // Initialization ---------------------------------------------
- //-------------------------------------------------------------
-
+ public static class BoldAction extends StyledEditorKit.StyledTextAction
+ {
/**
* Constructor BoldAction
*/
- public BoldAction() {
+ public BoldAction()
+ {
super("TODO");
// TODO
- } // BoldAction()
-
-
- //-------------------------------------------------------------
- // Methods ----------------------------------------------------
- //-------------------------------------------------------------
+ }
/**
* actionPerformed
* @param event TODO
*/
- public void actionPerformed(ActionEvent event) {
+ public void actionPerformed(ActionEvent event)
+ {
// TODO
- } // actionPerformed()
-
-
- } // BoldAction
+ }
+ }
/**
* AlignmentAction
*/
- public static class AlignmentAction extends StyledEditorKit.StyledTextAction {
-
- //-------------------------------------------------------------
- // Variables --------------------------------------------------
- //-------------------------------------------------------------
-
+ public static class AlignmentAction extends StyledEditorKit.StyledTextAction
+ {
/**
* a
*/
private int a;
-
- //-------------------------------------------------------------
- // Initialization ---------------------------------------------
- //-------------------------------------------------------------
-
/**
* Constructor AlignmentAction
* @param nm TODO
* @param a TODO
*/
- public AlignmentAction(String nm, int a) {
+ public AlignmentAction(String nm, int a)
+ {
super("TODO");
// TODO
- } // AlignmentAction()
-
-
- //-------------------------------------------------------------
- // Methods ----------------------------------------------------
- //-------------------------------------------------------------
+ }
/**
* actionPerformed
* @param event TODO
*/
- public void actionPerformed(ActionEvent event) {
+ public void actionPerformed(ActionEvent event)
+ {
// TODO
- } // actionPerformed()
-
-
- } // AlignmentAction
+ }
+ }
/**
* ForegroundAction
*/
- public static class ForegroundAction extends StyledEditorKit.StyledTextAction {
-
- //-------------------------------------------------------------
- // Variables --------------------------------------------------
- //-------------------------------------------------------------
-
+ public static class ForegroundAction extends StyledEditorKit.StyledTextAction
+ {
/**
* fg
*/
private Color fg;
-
- //-------------------------------------------------------------
- // Initialization ---------------------------------------------
- //-------------------------------------------------------------
-
/**
* Constructor ForegroundAction
* @param nm TODO
* @param fg TODO
*/
- public ForegroundAction(String nm, Color fg) {
+ public ForegroundAction(String nm, Color fg)
+ {
super("TODO");
// TODO
- } // ForegroundAction()
-
-
- //-------------------------------------------------------------
- // Methods ----------------------------------------------------
- //-------------------------------------------------------------
+ }
/**
* actionPerformed
* @param event TODO
*/
- public void actionPerformed(ActionEvent event) {
+ public void actionPerformed(ActionEvent event)
+ {
// TODO
- } // actionPerformed()
-
-
- } // ForegroundAction
+ }
+ }
/**
* FontSizeAction
*/
- public static class FontSizeAction extends StyledEditorKit.StyledTextAction {
-
- //-------------------------------------------------------------
- // Variables --------------------------------------------------
- //-------------------------------------------------------------
-
+ public static class FontSizeAction extends StyledEditorKit.StyledTextAction
+ {
/**
* size
*/
private int size;
-
- //-------------------------------------------------------------
- // Initialization ---------------------------------------------
- //-------------------------------------------------------------
-
/**
* Constructor FontSizeAction
* @param nm TODO
* @param size TODO
*/
- public FontSizeAction(String nm, int size) {
+ public FontSizeAction(String nm, int size)
+ {
super("TODO");
// TODO
- } // FontSizeAction()
-
-
- //-------------------------------------------------------------
- // Methods ----------------------------------------------------
- //-------------------------------------------------------------
+ }
/**
* actionPerformed
* @param event TODO
*/
- public void actionPerformed(ActionEvent event) {
+ public void actionPerformed(ActionEvent event)
+ {
// TODO
- } // actionPerformed()
-
-
- } // FontSizeAction
+ }
+ }
/**
* FontFamilyAction
*/
- public static class FontFamilyAction extends StyledEditorKit.StyledTextAction {
-
- //-------------------------------------------------------------
- // Variables --------------------------------------------------
- //-------------------------------------------------------------
-
+ public static class FontFamilyAction extends StyledEditorKit.StyledTextAction
+ {
/**
* family
*/
private String family;
-
- //-------------------------------------------------------------
- // Initialization ---------------------------------------------
- //-------------------------------------------------------------
-
/**
* Constructor FontFamilyAction
* @param nm TODO
* @param family TODO
*/
- public FontFamilyAction(String nm, String family) {
+ public FontFamilyAction(String nm, String family)
+ {
super("TODO");
// TODO
- } // FontFamilyAction()
-
-
- //-------------------------------------------------------------
- // Methods ----------------------------------------------------
- //-------------------------------------------------------------
+ }
/**
* actionPerformed
* @param event TODO
*/
- public void actionPerformed(ActionEvent event) {
+ public void actionPerformed(ActionEvent event)
+ {
// TODO
- } // actionPerformed()
-
-
- } // FontFamilyAction
+ }
+ }
/**
* StyledTextAction
*/
- public abstract static class StyledTextAction extends TextAction {
-
- //-------------------------------------------------------------
- // Initialization ---------------------------------------------
- //-------------------------------------------------------------
-
+ public abstract static class StyledTextAction extends TextAction
+ {
/**
* Constructor StyledTextAction
* @param nm TODO
*/
- public StyledTextAction(String nm) {
+ public StyledTextAction(String nm)
+ {
super(nm);
// TODO
- } // StyledTextAction()
-
-
- //-------------------------------------------------------------
- // Methods ----------------------------------------------------
- //-------------------------------------------------------------
+ }
/**
* getEditor
* @param event TODO
* @returns JEditorPane
*/
- protected final JEditorPane getEditor(ActionEvent event) {
+ protected final JEditorPane getEditor(ActionEvent event)
+ {
return null; // TODO
- } // getEditor()
+ }
/**
* setCharacterAttributes
* @param value1 TODO
* @param value2 TODO
*/
- protected final void setCharacterAttributes(JEditorPane value0, AttributeSet value1, boolean value2) {
+ protected final void setCharacterAttributes(JEditorPane value0,
+ AttributeSet value1,
+ boolean value2)
+ {
// TODO
- } // setCharacterAttributes()
+ }
/**
* getStyledDocument
* @param value0 TODO
* @returns StyledDocument
*/
- protected final StyledDocument getStyledDocument(JEditorPane value0) {
+ protected final StyledDocument getStyledDocument(JEditorPane value0)
+ {
return null; // TODO
- } // getStyledDocument()
+ }
/**
* getStyledEditorKit
* @param value0 TODO
* @returns StyledEditorKit
*/
- protected final StyledEditorKit getStyledEditorKit(JEditorPane value0) {
+ protected final StyledEditorKit getStyledEditorKit(JEditorPane value0)
+ {
return null; // TODO
- } // getStyledEditorKit()
+ }
/**
* setParagraphAttributes
* @param value1 TODO
* @param value2 TODO
*/
- protected final void setParagraphAttributes(JEditorPane value0, AttributeSet value1, boolean value2) {
+ protected final void setParagraphAttributes(JEditorPane value0,
+ AttributeSet value1,
+ boolean value2)
+ {
// TODO
- } // setParagraphAttributes()
-
-
- } // StyledTextAction
+ }
+ }
/**
* StyledViewFactory
*/
- static class StyledViewFactory implements ViewFactory {
-
- //-------------------------------------------------------------
- // Initialization ---------------------------------------------
- //-------------------------------------------------------------
-
+ static class StyledViewFactory
+ implements ViewFactory
+ {
/**
* Constructor StyledViewFactory
*/
- StyledViewFactory() {
+ StyledViewFactory()
+ {
// TODO
- } // StyledViewFactory()
-
-
- //-------------------------------------------------------------
- // Methods ----------------------------------------------------
- //-------------------------------------------------------------
+ }
/**
* create
* @param value0 TODO
* @returns View
*/
- public View create(Element value0) {
+ public View create(Element value0)
+ {
return null; // TODO
- } // create()
-
-
- } // StyledViewFactory
+ }
+ }
/**
* AttributeTracker
*/
- class AttributeTracker implements CaretListener, PropertyChangeListener, Serializable {
-
- //-------------------------------------------------------------
- // Variables --------------------------------------------------
- //-------------------------------------------------------------
-
-
- //-------------------------------------------------------------
- // Initialization ---------------------------------------------
- //-------------------------------------------------------------
-
+ class AttributeTracker
+ implements CaretListener, PropertyChangeListener, Serializable
+ {
/**
* Constructor AttributeTracker
* @param value0 TODO
*/
- AttributeTracker(StyledEditorKit value0) {
+ AttributeTracker(StyledEditorKit value0)
+ {
// TODO
- } // AttributeTracker()
-
-
- //-------------------------------------------------------------
- // Methods ----------------------------------------------------
- //-------------------------------------------------------------
+ }
/**
* updateInputAttributes
* @param value1 TODO
* @param value2 TODO
*/
- void updateInputAttributes(int value0, int value1, JTextComponent value2) {
+ void updateInputAttributes(int value0, int value1, JTextComponent value2)
+ {
// TODO
- } // updateInputAttributes()
+ }
/**
* propertyChange
* @param value0 TODO
*/
- public void propertyChange(PropertyChangeEvent value0) {
+ public void propertyChange(PropertyChangeEvent value0)
+ {
// TODO
- } // propertyChange()
+ }
/**
* caretUpdate
* @param value0 TODO
*/
- public void caretUpdate(CaretEvent value0) {
+ public void caretUpdate(CaretEvent value0)
+ {
// TODO
- } // caretUpdate()
-
-
- } // AttributeTracker
-
-
- //-------------------------------------------------------------
- // Variables --------------------------------------------------
- //-------------------------------------------------------------
+ }
+ }
/**
* currentRun
*/
MutableAttributeSet inputAttributes;
-
- //-------------------------------------------------------------
- // Initialization ---------------------------------------------
- //-------------------------------------------------------------
-
/**
* Constructor StyledEditorKit
*/
- public StyledEditorKit() {
+ public StyledEditorKit()
+ {
// TODO
- } // StyledEditorKit()
-
-
- //-------------------------------------------------------------
- // Methods ----------------------------------------------------
- //-------------------------------------------------------------
+ }
/**
* clone
* @returns Object
*/
- public Object clone() {
+ public Object clone()
+ {
return null; // TODO
- } // clone()
+ }
/**
* getActions
* @returns Action[]
*/
- public Action[] getActions() {
+ public Action[] getActions()
+ {
return null; // TODO
- } // getActions()
+ }
/**
* getInputAttributes
* @returns MutableAttributeSet
*/
- public MutableAttributeSet getInputAttributes() {
+ public MutableAttributeSet getInputAttributes()
+ {
return null; // TODO
- } // getInputAttributes()
+ }
/**
* getCharacterAttributeRun
* @returns Element
*/
- public Element getCharacterAttributeRun() {
+ public Element getCharacterAttributeRun()
+ {
return null; // TODO
- } // getCharacterAttributeRun()
+ }
/**
* createDefaultDocument
* @returns Document
*/
- public Document createDefaultDocument() {
+ public Document createDefaultDocument()
+ {
return null; // TODO
- } // createDefaultDocument()
+ }
/**
* install
* @param component TODO
*/
- public void install(JEditorPane component) {
+ public void install(JEditorPane component)
+ {
// TODO
- } // install()
+ }
/**
* deinstall
* @param component TODO
*/
- public void deinstall(JEditorPane component) {
+ public void deinstall(JEditorPane component)
+ {
// TODO
- } // deinstall()
+ }
/**
* getViewFactory
* @returns ViewFactory
*/
- public ViewFactory getViewFactory() {
+ public ViewFactory getViewFactory()
+ {
return null; // TODO
- } // getViewFactory()
+ }
/**
* createInputAttributes
* @param element TODO
* @param set TODO
*/
- protected void createInputAttributes(Element element,
- MutableAttributeSet set) {
+ protected void createInputAttributes(Element element, MutableAttributeSet set)
+ {
// TODO
- } // createInputAttributes()
-
-
-} // StyledEditorKit
+ }
+}
--- /dev/null
+/* TabExpander.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.text;
+
+public interface TabExpander
+{
+ float nextTabStop(float x, int tabOffset);
+}
\ No newline at end of file
--- /dev/null
+/* TabableView.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.text;
+
+public interface TabableView
+{
+ float getPartialSpan(int p0, int p1);
+ float getTabbedSpan(float x, TabExpander expander);
+}
import javax.swing.AbstractAction;
import javax.swing.Action;
+
/**
* TextAction
* @author Andrew Selkirk
- * @version 1.0
*/
-public abstract class TextAction extends AbstractAction {
-
- //-------------------------------------------------------------
- // Initialization ---------------------------------------------
- //-------------------------------------------------------------
-
+public abstract class TextAction extends AbstractAction
+{
/**
* Constructor TextAction
* @param name TODO
*/
- public TextAction(String name) {
+ public TextAction(String name)
+ {
// TODO
- } // TextAction()
-
-
- //-------------------------------------------------------------
- // Methods ----------------------------------------------------
- //-------------------------------------------------------------
+ }
/**
* getTextComponent
* @param event TODO
- * @returns JTextComponent
+ * @return JTextComponent
*/
- protected final JTextComponent getTextComponent(ActionEvent event) {
+ protected final JTextComponent getTextComponent(ActionEvent event)
+ {
return null; // TODO
- } // getTextComponent()
+ }
/**
* augmentList
* @param list1 TODO
* @param list2 TODO
- * @returns Action[]
+ * @return Action[]
*/
- public static final Action[] augmentList(Action[] list1, Action[] list2) {
+ public static final Action[] augmentList(Action[] list1, Action[] list2)
+ {
return null; // TODO
- } // augmentList()
+ }
/**
* getFocusedComponent
- * @returns JTextComponent
+ * @return JTextComponent
*/
- protected final JTextComponent getFocusedComponent() {
+ protected final JTextComponent getFocusedComponent()
+ {
return null; // TODO
- } // getFocusedComponent()
-
-
-} // TextAction
+ }
+}
package javax.swing.text;
+import java.awt.Container;
import java.awt.Graphics;
import java.awt.Shape;
import java.util.Vector;
public abstract class View implements SwingConstants
{
- static int BadBreakWeight;
- static int ExcellentBreakWeight;
- static int ForcedBreakWeight;
- static int GoodBreakWeight;
+ public static final int BadBreakWeight = 0;
+ public static final int ExcellentBreakWeight = 2000;
+ public static final int ForcedBreakWeight = 3000;
+ public static final int GoodBreakWeight = 1000;
- public final static int X_AXIS = 0;
- public final static int Y_AXIS = 1;
+ public static final int X_AXIS = 0;
+ public static final int Y_AXIS = 1;
- float width, height;
- Element elt;
- View parent;
+ private float width, height;
+ private Element elt;
+ private View parent;
/**
- * this vector contains the views ordered at offsets...
+ * Creates a new <code>View</code> instance.
+ *
+ * @param elem an <code>Element</code> value
*/
- Vector v = new Vector();
-
-
public View(Element elem)
{
elt = elem;
}
- public int getViewCount()
+ public abstract void paint(Graphics g, Shape s);
+
+ public void setParent(View a)
{
- return v.size();
+ parent = a;
}
- public View getView(int a)
+ public View getParent()
{
- return (View) v.get(a);
+ return parent;
}
- public void remove(int i)
+ public void setSize(int w, int h)
{
- v.removeElementAt(i);
+ width = w;
+ height = h;
}
- public void insert(int off, View view)
+ public Container getContainer()
{
- v.insertElementAt(view, off);
+ return parent != null ? parent.getContainer() : null;
}
- public void append(View view)
+ public Document getDocument()
{
- v.addElement(view);
+ return getElement().getDocument();
}
- public void paint(Graphics g, Shape allocation)
+ public Element getElement()
{
- System.out.println("view.paint() !!!!");
+ return elt;
}
- public void setParent(View a)
+ public abstract float getPreferredSpan(int axis);
+
+ public float getAlignment(int axis)
{
- parent = a;
+ return 0.5f;
}
- public View getParent()
+ public AttributeSet getAttributes()
{
- return parent;
+ return elt.getAttributes();
}
- public void setSize(int w, int h)
+ public boolean isVisible()
{
- width = w;
- height = h;
+ return true;
}
- public Document getDocument()
+ public int getViewCount()
{
- return getElement().getDocument();
+ return 0;
}
- public Element getElement()
+ public View getView(int index)
{
- return elt;
+ return null;
}
- public float getPreferredSpan(int a)
+ public ViewFactory getViewFactory()
{
- switch (a)
+ return parent != null ? parent.getViewFactory() : null;
+ }
+
+ public void replace(int offset, int length, View[] views)
{
- case X_AXIS: return width;
- case Y_AXIS: return height;
- default:
+ // Default implementation does nothing.
+ }
+
+ public void insert(int offset, View view)
{
- System.err.println("I sure wish Java had enums !!! ");
- return 0;
+ View[] array = { view };
+ replace(offset, 1, array);
}
+
+ public void append(View view)
+ {
+ View[] array = { view };
+ replace(getViewCount(), 1, array);
+ }
+
+ public void removeAll()
+ {
+ replace(0, getViewCount(), null);
}
+
+ public void remove(int index)
+ {
+ replace(index, 1, null);
+ }
+
+ public View createFragment(int p0, int p1)
+ {
+ // The default implementation doesnt support fragmentation.
+ return this;
}
}
/* ViewFactory.java --
- Copyright (C) 2002 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
public interface ViewFactory
{
+ /**
+ * Creates a view for a given element.
+ *
+ * @param elem them element to create view for
+ *
+ * @return a new created view
+ */
View create (Element elem);
}
}
}
+
JNIEXPORT void JNICALL
Java_gnu_java_awt_peer_gtk_GtkComponentPeer_gtkWidgetSetCursor
(JNIEnv *env, jobject obj, jint type)
(*env)->ReleaseStringUTFChars (env, name, font_name);
}
-void
-set_visible (GtkWidget *widget, jboolean visible)
+JNIEXPORT void JNICALL
+Java_gnu_java_awt_peer_gtk_GtkComponentPeer_show
+ (JNIEnv *env, jobject obj)
{
- if (visible)
- gtk_widget_show (widget);
- else
- gtk_widget_hide (widget);
+ void *ptr;
+
+ ptr = NSA_GET_PTR (env, obj);
+
+ gdk_threads_enter();
+ gtk_widget_show (GTK_WIDGET (ptr));
+ gdk_threads_leave();
+}
+
+JNIEXPORT void JNICALL
+Java_gnu_java_awt_peer_gtk_GtkComponentPeer_hide
+ (JNIEnv *env, jobject obj)
+{
+ void *ptr;
+
+ ptr = NSA_GET_PTR (env, obj);
+
+ gdk_threads_enter();
+ gtk_widget_hide (GTK_WIDGET (ptr));
+ gdk_threads_leave();
}
GtkLayout *
#include "gnu_java_awt_peer_gtk_GtkComponentPeer.h"
#include "gnu_java_awt_peer_gtk_GtkFileDialogPeer.h"
-static void window_closed (GtkDialog *dialog,
+static void handle_response (GtkDialog *dialog,
gint responseId,
jobject peer_obj);
-static void ok_clicked (GtkButton *button,
- jobject peer_obj);
-static void cancel_clicked (GtkButton *button,
- jobject peer_obj);
/*
* Make a new file selection dialog
JNIEXPORT void JNICALL
Java_gnu_java_awt_peer_gtk_GtkFileDialogPeer_create
- (JNIEnv *env, jobject obj)
+ (JNIEnv *env, jobject obj, jobject parent)
{
+ void *parentp;
gpointer widget;
/* Create global reference and save it for future use */
NSA_SET_GLOBAL_REF (env, obj);
+ parentp = NSA_GET_PTR(env, parent);
+
gdk_threads_enter ();
- widget = gtk_file_selection_new ("");
+ widget = gtk_file_chooser_dialog_new("",
+ GTK_WINDOW(parentp),
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ GTK_STOCK_OK, GTK_RESPONSE_OK,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ NULL);
+
+ /* GtkFileChooser doesn't show hidden files by default. */
+ g_object_set(GTK_FILE_CHOOSER(widget), "show_hidden", TRUE);
+
/* GtkFileSelect is not modal by default */
gtk_window_set_modal (GTK_WINDOW (widget), TRUE);
gtk_widget_realize (GTK_WIDGET (ptr));
- /* connect buttons to handlers */
-
g_signal_connect (G_OBJECT (GTK_DIALOG (ptr)),
"response",
- GTK_SIGNAL_FUNC (window_closed), *gref);
-
- g_signal_connect (G_OBJECT (GTK_FILE_SELECTION (ptr)->ok_button),
- "clicked",
- GTK_SIGNAL_FUNC (ok_clicked), *gref);
-
- g_signal_connect (G_OBJECT (GTK_FILE_SELECTION (ptr)->cancel_button),
- "clicked",
- GTK_SIGNAL_FUNC (cancel_clicked), *gref);
+ GTK_SIGNAL_FUNC (handle_response), *gref);
gdk_threads_leave ();
Java_gnu_java_awt_peer_gtk_GtkComponentPeer_connectSignals (env, obj);
}
-/*
- * Set the filename in the file selection dialog.
- */
-
-JNIEXPORT void JNICALL
-Java_gnu_java_awt_peer_gtk_GtkFileDialogPeer_nativeSetFile
- (JNIEnv *env, jobject obj, jstring filename)
+JNIEXPORT jstring JNICALL
+Java_gnu_java_awt_peer_gtk_GtkFileDialogPeer_nativeGetDirectory
+ (JNIEnv *env, jobject obj)
{
void *ptr;
const char *str;
ptr = NSA_GET_PTR (env, obj);
- str = (*env)->GetStringUTFChars (env, filename, 0);
-
gdk_threads_enter ();
- gtk_file_selection_set_filename (GTK_FILE_SELECTION (ptr), str);
+ str = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER(ptr));
gdk_threads_leave ();
- (*env)->ReleaseStringUTFChars (env, filename, str);
+ return (*env)->NewStringUTF(env, str);
}
-static void
-window_closed (GtkDialog *dialog __attribute__((unused)),
- gint responseId,
- jobject peer_obj)
+
+/* This function interfaces with the Java callback method of the same name.
+ This function extracts the filename from the GtkFileFilterInfo object,
+ and passes it to the Java method. The Java method will call the filter's
+ accept() method and will give back the return value. */
+gboolean filenameFilterCallback (const GtkFileFilterInfo *filter_info,
+ gpointer obj)
{
- static int isIDSet = 0;
- static jmethodID disposeID;
- void *ptr;
+ gchar* dirname;
+ jclass cx;
+ jmethodID id;
+ jstring *filename;
- /* We only need this for the case when the user closed the window. */
- if (responseId != GTK_RESPONSE_DELETE_EVENT)
- return;
+ cx = (*gdk_env)->GetObjectClass (gdk_env, (jobject) obj);
+ id = (*gdk_env)->GetMethodID (gdk_env, cx, "filenameFilterCallback",
+ "(Ljava/lang/String;)Z");
- ptr = NSA_GET_PTR (gdk_env, peer_obj);
+ filename = (*gdk_env)->NewStringUTF(gdk_env, filter_info->filename);
- if (!isIDSet)
+ gdk_threads_leave();
+ gboolean accepted = (*gdk_env)->CallBooleanMethod(gdk_env, obj, id, filename);
+ gdk_threads_enter();
+
+ return accepted;
+}
+
+JNIEXPORT void JNICALL
+Java_gnu_java_awt_peer_gtk_GtkFileDialogPeer_nativeSetFilenameFilter
+ (JNIEnv *env, jobject obj, jobject filter_obj)
{
- jclass cx = (*gdk_env)->GetObjectClass (gdk_env, peer_obj);
- disposeID = (*gdk_env)->GetMethodID (gdk_env, cx, "gtkDisposeFileDialog", "()V");
- isIDSet = 1;
+ void *ptr;
+ GtkFileFilter *filter;
+
+ ptr = NSA_GET_PTR (env, obj);
+
+ gdk_threads_enter ();
+
+ filter = gtk_file_filter_new();
+ gtk_file_filter_add_custom(filter,
+ GTK_FILE_FILTER_FILENAME,
+ G_CALLBACK(filenameFilterCallback),
+ obj,
+ NULL);
+
+ gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(ptr), filter);
+
+ gdk_threads_leave ();
}
+JNIEXPORT void JNICALL
+Java_gnu_java_awt_peer_gtk_GtkFileDialogPeer_nativeSetDirectory
+ (JNIEnv *env, jobject obj, jstring directory)
+{
+ void *ptr;
+ const char *str;
+
+ ptr = NSA_GET_PTR (env, obj);
+
+ str = (*env)->GetStringUTFChars (env, directory, 0);
+
+ gdk_threads_enter ();
+ gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER(ptr), str);
gdk_threads_leave ();
- /* We can dispose of the dialog now (and unblock show) */
- (*gdk_env)->CallVoidMethod (gdk_env, peer_obj, disposeID);
+ (*env)->ReleaseStringUTFChars (env, directory, str);
+}
+
+JNIEXPORT void JNICALL
+Java_gnu_java_awt_peer_gtk_GtkFileDialogPeer_nativeSetFile
+ (JNIEnv *env, jobject obj, jstring filename)
+{
+ void *ptr;
+ const char *str;
+
+ ptr = NSA_GET_PTR (env, obj);
+
+ str = (*env)->GetStringUTFChars (env, filename, 0);
gdk_threads_enter ();
+ gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (ptr), str);
+ gdk_threads_leave ();
+
+ (*env)->ReleaseStringUTFChars (env, filename, str);
}
static void
-ok_clicked (GtkButton *button __attribute__((unused)),
+handle_response (GtkDialog *dialog __attribute__((unused)),
+ gint responseId,
jobject peer_obj)
{
+ static int isDisposeIDSet = 0;
static int isIDSet = 0;
static jmethodID gtkSetFilenameID;
static jmethodID hideID;
+ static jmethodID disposeID;
void *ptr;
G_CONST_RETURN gchar *fileName;
jstring str_fileName;
- ptr = NSA_GET_PTR (gdk_env, peer_obj);
+ /* We only need this for the case when the user closed the window,
+ or clicked ok or cancel. */
+ if (responseId != GTK_RESPONSE_DELETE_EVENT
+ && responseId != GTK_RESPONSE_OK
+ && responseId != GTK_RESPONSE_CANCEL)
+ return;
- fileName = gtk_file_selection_get_filename (
- GTK_FILE_SELECTION (GTK_WIDGET (ptr)));
+ ptr = NSA_GET_PTR (gdk_env, peer_obj);
- if (!isIDSet)
+ if (responseId == GTK_RESPONSE_DELETE_EVENT)
+ {
+ if (!isDisposeIDSet)
{
jclass cx = (*gdk_env)->GetObjectClass (gdk_env, peer_obj);
- hideID = (*gdk_env)->GetMethodID (gdk_env, cx, "gtkHideFileDialog", "()V");
- gtkSetFilenameID = (*gdk_env)->GetMethodID (gdk_env, cx,
- "gtkSetFilename", "(Ljava/lang/String;)V");
- isIDSet = 1;
+ disposeID = (*gdk_env)->GetMethodID (gdk_env, cx, "gtkDisposeFileDialog", "()V");
+ isDisposeIDSet = 1;
}
gdk_threads_leave ();
- /* Set the Java object field 'file' with this value. */
- str_fileName = (*gdk_env)->NewStringUTF (gdk_env, fileName);
- (*gdk_env)->CallVoidMethod (gdk_env, peer_obj, gtkSetFilenameID, str_fileName);
-
- /* We can hide the dialog now (and unblock show) */
- (*gdk_env)->CallVoidMethod (gdk_env, peer_obj, hideID);
+ /* We can dispose of the dialog now (and unblock show) */
+ (*gdk_env)->CallVoidMethod (gdk_env, peer_obj, disposeID);
gdk_threads_enter ();
+ return;
}
-static void
-cancel_clicked (GtkButton *button __attribute__((unused)),
- jobject peer_obj)
-{
- static int isIDSet = 0;
- static jmethodID gtkSetFilenameID;
- static jmethodID hideID;
- void *ptr;
-
- ptr = NSA_GET_PTR (gdk_env, peer_obj);
+ if (responseId == GTK_RESPONSE_OK) {
+ fileName = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (GTK_WIDGET (ptr)));
+ str_fileName = (*gdk_env)->NewStringUTF (gdk_env, fileName);
+ } else if (responseId == GTK_RESPONSE_CANCEL) {
+ str_fileName = NULL;
+ }
if (!isIDSet)
{
gdk_threads_leave ();
- /* Set the Java object field 'file' with the null value. */
- (*gdk_env)->CallVoidMethod (gdk_env, peer_obj, gtkSetFilenameID, NULL);
+ /* Set the Java object field 'file' with this value. */
+ (*gdk_env)->CallVoidMethod (gdk_env, peer_obj, gtkSetFilenameID, str_fileName);
/* We can hide the dialog now (and unblock show) */
(*gdk_env)->CallVoidMethod (gdk_env, peer_obj, hideID);
gdk_threads_enter ();
}
-
/* 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/
+ See: http://mail.gnome.org/archives/gtk-i18n-list/2003-August/msg00001.html
for details. */
static void
init_dpi_conversion_factor ()
widget = gtk_layout_new (NULL, NULL);
+ GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_FOCUS);
+
gdk_threads_leave ();
NSA_SET_PTR (env, obj, widget);
GtkWidget *text = NULL;
GtkTextBuffer *buf;
GtkTextIter iter;
+ GtkTextMark *mark;
+ GtkTextMark *oldmark;
+ GtkTextIter olditer;
+ int oldpos;
ptr = NSA_GET_PTR (env, obj);
if (text)
{
buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text));
+
+ /* Save old position. */
+ oldmark = gtk_text_buffer_get_insert (buf);
+ gtk_text_buffer_get_iter_at_mark (buf, &olditer, oldmark);
+ oldpos = gtk_text_iter_get_offset (&olditer);
+
+ /* Move to new position. */
gtk_text_buffer_get_iter_at_offset (buf, &iter, pos);
gtk_text_buffer_place_cursor (buf, &iter);
+
+ /* Scroll to new position. Alignment is determined
+ comparing the new position to the old position. */
+ if (oldpos > pos)
+ gtk_text_view_scroll_to_iter (GTK_TEXT_VIEW (text),
+ &iter, 0, TRUE, 0, 0);
+ else if (oldpos < pos)
+ gtk_text_view_scroll_to_iter (GTK_TEXT_VIEW (text),
+ &iter, 0, TRUE, 1, 1);
}
}
static void request_frame_extents (GtkWidget *window);
-static int property_notify_predicate (Display *xdisplay,
- XEvent *event,
- XPointer window_id);
+static Bool property_notify_predicate (Display *display,
+ XEvent *xevent,
+ XPointer arg);
+
+static GtkLayout *find_layout (GtkWindow *window);
static void window_delete_cb (GtkWidget *widget, GdkEvent *event,
jobject peer);
static void window_destroy_cb (GtkWidget *widget, GdkEvent *event,
jobject peer);
static void window_show_cb (GtkWidget *widget, jobject peer);
-static void window_focus_or_active_state_change_cb (GtkWidget *widget,
+static void window_active_state_change_cb (GtkWidget *widget,
+ GParamSpec *pspec,
+ jobject peer);
+static void window_focus_state_change_cb (GtkWidget *widget,
GParamSpec *pspec,
jobject peer);
+static gboolean window_focus_in_cb (GtkWidget * widget,
+ GdkEventFocus *event,
+ jobject peer);
+static gboolean window_focus_out_cb (GtkWidget * widget,
+ GdkEventFocus *event,
+ jobject peer);
static gboolean window_window_state_cb (GtkWidget *widget,
GdkEvent *event,
jobject peer);
GdkEventProperty *event,
jobject peer);
-/*
- * Make a new window.
- */
-
JNIEXPORT void JNICALL
Java_gnu_java_awt_peer_gtk_GtkWindowPeer_create
(JNIEnv *env, jobject obj, jint type, jboolean decorated,
(JNIEnv *env, jobject obj)
{
void *ptr;
- GtkWidget* vbox, *layout;
- GList* children;
+ GtkLayout *layout;
ptr = NSA_GET_PTR (env, obj);
gdk_threads_enter ();
- children = gtk_container_get_children(GTK_CONTAINER(ptr));
- vbox = children->data;
- g_assert (GTK_IS_VBOX(vbox));
+ layout = find_layout (GTK_WINDOW (ptr));
- children = gtk_container_get_children(GTK_CONTAINER(vbox));
- do
- {
- layout = children->data;
- children = children->next;
- }
- while (!GTK_IS_LAYOUT (layout) && children != NULL);
- g_assert (GTK_IS_LAYOUT(layout));
+ gtk_widget_realize (GTK_WIDGET (layout));
- gtk_widget_realize (layout);
-
- connect_awt_hook (env, obj, 1, GTK_LAYOUT (layout)->bin_window);
+ connect_awt_hook (env, obj, 1, layout->bin_window);
gtk_widget_realize (ptr);
Java_gnu_java_awt_peer_gtk_GtkWindowPeer_connectSignals
(JNIEnv *env, jobject obj)
{
- void *ptr = NSA_GET_PTR (env, obj);
- jobject *gref = NSA_GET_GLOBAL_REF (env, obj);
- GtkWidget* vbox, *layout;
- GList* children;
- g_assert (gref);
+ void *ptr;
+ jobject *gref;
+ GtkLayout *layout;
+
+ ptr = NSA_GET_PTR (env, obj);
+
+ gref = NSA_GET_GLOBAL_REF (env, obj);
gdk_threads_enter ();
gtk_widget_realize (ptr);
/* Receive events from the GtkLayout too */
- children = gtk_container_get_children(GTK_CONTAINER(ptr));
- vbox = children->data;
- g_assert (GTK_IS_VBOX (vbox));
-
- children = gtk_container_get_children(GTK_CONTAINER(vbox));
- do
- {
- layout = children->data;
- children = children->next;
- }
- while (!GTK_IS_LAYOUT (layout) && children != NULL);
- g_assert (GTK_IS_LAYOUT (layout));
+ layout = find_layout (GTK_WINDOW (ptr));
- g_signal_connect (GTK_OBJECT (layout), "event",
+ g_signal_connect (G_OBJECT (layout), "event",
G_CALLBACK (pre_event_handler), *gref);
/* Connect signals for window event support. */
g_signal_connect (G_OBJECT (ptr), "show",
G_CALLBACK (window_show_cb), *gref);
- g_signal_connect (G_OBJECT (ptr), "notify",
- G_CALLBACK (window_focus_or_active_state_change_cb), *gref);
+ g_signal_connect (G_OBJECT (ptr), "notify::is-active",
+ G_CALLBACK (window_active_state_change_cb), *gref);
+
+ g_signal_connect (G_OBJECT (ptr), "notify::has-toplevel-focus",
+ G_CALLBACK (window_focus_state_change_cb), *gref);
+
+ g_signal_connect (G_OBJECT (ptr), "focus-in-event",
+ G_CALLBACK (window_focus_in_cb), *gref);
+
+ g_signal_connect (G_OBJECT (ptr), "focus-out-event",
+ G_CALLBACK (window_focus_out_cb), *gref);
g_signal_connect (G_OBJECT (ptr), "window-state-event",
G_CALLBACK (window_window_state_cb), *gref);
{
void* ptr;
GList* children;
- GtkBox* vbox;
GtkLayout* layout;
GtkWidget* widget;
gdk_threads_enter ();
- children = gtk_container_get_children (GTK_CONTAINER (ptr));
- vbox = children->data;
- g_assert (GTK_IS_VBOX (vbox));
+ layout = find_layout (GTK_WINDOW (ptr));
- children = gtk_container_get_children (GTK_CONTAINER (vbox));
- do
- {
- layout = children->data;
- children = children->next;
- }
- while (!GTK_IS_LAYOUT (layout) && children != NULL);
- g_assert (GTK_IS_LAYOUT (layout));
children = gtk_container_get_children (GTK_CONTAINER (layout));
while (children != NULL)
JNIEXPORT void JNICALL
Java_gnu_java_awt_peer_gtk_GtkFramePeer_gtkLayoutSetVisible
- (JNIEnv *env, jobject obj, jboolean vis)
+ (JNIEnv *env, jobject obj, jboolean visible)
{
void* ptr;
- GList* children;
- GtkBox* vbox;
GtkLayout* layout;
ptr = NSA_GET_PTR (env, obj);
gdk_threads_enter ();
- children = gtk_container_get_children (GTK_CONTAINER (ptr));
- vbox = children->data;
- g_assert (GTK_IS_VBOX (vbox));
-
- children = gtk_container_get_children (GTK_CONTAINER (vbox));
- do
- {
- layout = children->data;
- children = children->next;
- }
- while (!GTK_IS_LAYOUT (layout) && children != NULL);
- g_assert (GTK_IS_LAYOUT (layout));
+ layout = find_layout (GTK_WINDOW (ptr));
- if (vis)
+ if (visible)
gtk_widget_show (GTK_WIDGET (layout));
else
gtk_widget_hide (GTK_WIDGET (layout));
+
gdk_threads_leave ();
}
+
static void
window_get_frame_extents (GtkWidget *window,
int *top, int *left, int *bottom, int *right)
}
}
-static int
+static Bool
property_notify_predicate (Display *xdisplay __attribute__((unused)),
XEvent *event,
XPointer window_id)
&& event->xany.window == *window
&& event->xproperty.atom == extents_atom)
return True;
-
+ else
return False;
}
}
static void
-window_focus_or_active_state_change_cb (GtkWidget *widget,
+window_active_state_change_cb (GtkWidget *widget,
GParamSpec *pspec,
jobject peer)
{
- if (!strcmp (g_param_spec_get_name (pspec), "is-active"))
- {
+ /* FIXME: not sure if this is needed or not. */
+#if 0
if (GTK_WINDOW (widget)->is_active)
(*gdk_env)->CallVoidMethod (gdk_env, peer,
postWindowEventID,
postWindowEventID,
(jint) AWT_WINDOW_DEACTIVATED,
(jobject) NULL, (jint) 0);
+#endif
}
- else if (!strcmp (g_param_spec_get_name (pspec), "has-toplevel-focus"))
+
+static void
+window_focus_state_change_cb (GtkWidget *widget,
+ GParamSpec *pspec,
+ jobject peer)
{
if (GTK_WINDOW (widget)->has_toplevel_focus)
(*gdk_env)->CallVoidMethod (gdk_env, peer,
else
(*gdk_env)->CallVoidMethod (gdk_env, peer,
postWindowEventID,
- (jint) AWT_WINDOW_LOST_FOCUS,
+ (jint) AWT_WINDOW_DEACTIVATED,
(jobject) NULL, (jint) 0);
}
+
+static gboolean
+window_focus_in_cb (GtkWidget * widget,
+ GdkEventFocus *event,
+ jobject peer)
+{
+ (*gdk_env)->CallVoidMethod (gdk_env, peer,
+ postWindowEventID,
+ (jint) AWT_WINDOW_GAINED_FOCUS,
+ (jobject) NULL, (jint) 0);
+ return FALSE;
+}
+
+static gboolean
+window_focus_out_cb (GtkWidget * widget,
+ GdkEventFocus *event,
+ jobject peer)
+{
+ (*gdk_env)->CallVoidMethod (gdk_env, peer,
+ postWindowEventID,
+ (jint) AWT_WINDOW_LOST_FOCUS,
+ (jobject) NULL, (jint) 0);
+ return FALSE;
}
static gboolean
return FALSE;
}
+
+static GtkLayout *
+find_layout (GtkWindow *window)
+{
+ GList* children;
+ GtkBox* vbox;
+ GtkLayout* layout;
+
+ children = gtk_container_get_children (GTK_CONTAINER (window));
+ vbox = children->data;
+ g_assert (GTK_IS_VBOX (vbox));
+
+ children = gtk_container_get_children (GTK_CONTAINER (vbox));
+ do
+ {
+ layout = children->data;
+ children = children->next;
+ }
+ while (!GTK_IS_LAYOUT (layout) && children != NULL);
+ g_assert (GTK_IS_LAYOUT (layout));
+
+ return layout;
+}