diff options
author | Graydon Hoare <graydon@gcc.gnu.org> | 2004-09-02 06:58:08 +0000 |
---|---|---|
committer | Graydon Hoare <graydon@gcc.gnu.org> | 2004-09-02 06:58:08 +0000 |
commit | 61341707b3db764c90f954097bf89b0811f92965 (patch) | |
tree | 57dc5b899889b3288ee8c497478f985857cfcd2e /libjava/javax/swing/plaf | |
parent | 9969aaf67e4c806bc58a5b110f6a0849365eee05 (diff) | |
download | gcc-61341707b3db764c90f954097bf89b0811f92965.zip gcc-61341707b3db764c90f954097bf89b0811f92965.tar.gz gcc-61341707b3db764c90f954097bf89b0811f92965.tar.bz2 |
missing added files from merge
From-SVN: r86958
Diffstat (limited to 'libjava/javax/swing/plaf')
-rw-r--r-- | libjava/javax/swing/plaf/basic/BasicColorChooserUI.java | 338 | ||||
-rw-r--r-- | libjava/javax/swing/plaf/basic/BasicComboBoxEditor.java | 170 | ||||
-rw-r--r-- | libjava/javax/swing/plaf/basic/BasicComboBoxRenderer.java | 143 | ||||
-rw-r--r-- | libjava/javax/swing/plaf/basic/BasicComboBoxUI.java | 1227 | ||||
-rw-r--r-- | libjava/javax/swing/plaf/basic/BasicComboPopup.java | 933 | ||||
-rw-r--r-- | libjava/javax/swing/plaf/basic/BasicFormattedTextFieldUI.java | 62 | ||||
-rw-r--r-- | libjava/javax/swing/plaf/basic/BasicPasswordFieldUI.java | 61 | ||||
-rw-r--r-- | libjava/javax/swing/plaf/basic/BasicSpinnerUI.java | 572 | ||||
-rw-r--r-- | libjava/javax/swing/plaf/basic/BasicTableHeaderUI.java | 301 | ||||
-rw-r--r-- | libjava/javax/swing/plaf/basic/BasicTableUI.java | 374 | ||||
-rw-r--r-- | libjava/javax/swing/plaf/basic/BasicTextAreaUI.java | 69 | ||||
-rw-r--r-- | libjava/javax/swing/plaf/basic/BasicToolTipUI.java | 287 | ||||
-rw-r--r-- | libjava/javax/swing/plaf/basic/ComboPopup.java | 103 |
13 files changed, 4640 insertions, 0 deletions
diff --git a/libjava/javax/swing/plaf/basic/BasicColorChooserUI.java b/libjava/javax/swing/plaf/basic/BasicColorChooserUI.java new file mode 100644 index 0000000..1c2dcd6 --- /dev/null +++ b/libjava/javax/swing/plaf/basic/BasicColorChooserUI.java @@ -0,0 +1,338 @@ +/* BasicColorChooserUI.java + Copyright (C) 2004 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.swing.plaf.basic; + +import java.awt.BorderLayout; +import java.awt.Component; +import java.awt.Container; +import java.awt.Dimension; +import java.awt.Insets; +import java.awt.LayoutManager; +import java.awt.Rectangle; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import javax.swing.JColorChooser; +import javax.swing.JComponent; +import javax.swing.JPanel; +import javax.swing.JTabbedPane; +import javax.swing.UIDefaults; +import javax.swing.UIManager; +import javax.swing.colorchooser.AbstractColorChooserPanel; +import javax.swing.colorchooser.ColorChooserComponentFactory; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import javax.swing.plaf.ColorChooserUI; +import javax.swing.plaf.ComponentUI; + + +/** + * This is the UI Class for the JColorChooser in the Basic Look and Feel. + */ +public class BasicColorChooserUI extends ColorChooserUI +{ + /** + * This helper class handles property changes from the JColorChooser. + */ + public class PropertyHandler implements PropertyChangeListener + { + /** + * This method is called when any of the properties of the JColorChooser + * change. + * + * @param e The PropertyChangeEvent. + */ + public void propertyChange(PropertyChangeEvent e) + { + if (e.getPropertyName() == JColorChooser.CHOOSER_PANELS_PROPERTY) + makeTabs(chooser.getChooserPanels()); + else if (e.getPropertyName() == JColorChooser.PREVIEW_PANEL_PROPERTY) + updatePreviewPanel(chooser.getPreviewPanel()); + else if (e.getPropertyName() == JColorChooser.SELECTION_MODEL_PROPERTY) + ((AbstractColorChooserPanel) pane.getSelectedComponent()) + .updateChooser(); + + chooser.repaint(); + } + } + + /** + * This is a helper class that listens to the Model of the JColorChooser for + * color change events so it can update the preview panel. + */ + private class PreviewListener implements ChangeListener + { + /** + * This method is called whenever the JColorChooser's color changes. + * + * @param e The ChangeEvent. + */ + public void stateChanged(ChangeEvent e) + { + if (pane != null) + { + AbstractColorChooserPanel panel = (AbstractColorChooserPanel) pane + .getSelectedComponent(); + if (panel != null) + panel.updateChooser(); + } + chooser.repaint(); + } + } + + /** + * This helper class listens to the JTabbedPane that is used for tab + * changes. + */ + private class TabPaneListener implements ChangeListener + { + /** + * This method is called whenever a different tab is selected in the + * JTabbedPane. + * + * @param e The ChangeEvent. + */ + public void stateChanged(ChangeEvent e) + { + // Need to do this because we don't update all the tabs when they're not + // visible, so they are not informed of new colors when they're hidden. + AbstractColorChooserPanel comp = (AbstractColorChooserPanel) pane + .getSelectedComponent(); + comp.updateChooser(); + } + } + + /** An array of default choosers to use in the JColorChooser. */ + protected AbstractColorChooserPanel[] defaultChoosers; + + /** The listener for the preview panel. */ + protected ChangeListener previewListener; + + /** The PropertyChangeListener for the JColorChooser. */ + protected PropertyChangeListener propertyChangeListener; + + /** The JColorChooser. */ + private JColorChooser chooser; + + /** The JTabbedPane that is used. */ + private JTabbedPane pane; + + /** The Container that holds the preview panel. */ + private Container prevContainer; + + /** + * Creates a new BasicColorChooserUI object. + */ + public BasicColorChooserUI() + { + super(); + } + + /** + * This method creates a new UI Component for the given JComponent. + * + * @param c The JComponent to create an UI for. + * + * @return A new BasicColorChooserUI. + */ + public static ComponentUI createUI(JComponent c) + { + return new BasicColorChooserUI(); + } + + /** + * This method creates the default chooser panels for the JColorChooser. + * + * @return The default chooser panels. + */ + protected AbstractColorChooserPanel[] createDefaultChoosers() + { + return ColorChooserComponentFactory.getDefaultChooserPanels(); + } + + /** + * This method installs the UI Component for the given JComponent. + * + * @param c The JComponent to install this UI for. + */ + public void installUI(JComponent c) + { + if (c instanceof JColorChooser) + { + chooser = (JColorChooser) c; + chooser.setLayout(new BorderLayout()); + + // Do this first, so we avoid doing work for property change events. + defaultChoosers = createDefaultChoosers(); + chooser.setChooserPanels(defaultChoosers); + pane = new JTabbedPane(); + + pane.addChangeListener(new ChangeListener() + { + public void stateChanged(ChangeEvent e) + { + pane.repaint(); + } + }); + + makeTabs(defaultChoosers); + + chooser.add(pane, BorderLayout.NORTH); + + installPreviewPanel(); + + installDefaults(); + installListeners(); + } + } + + /** + * This method adds tabs to the JTabbedPane for the chooserPanels defined in + * the JColorChooser. + * + * @param panels The Panels that need tabs to be made for them. + */ + private void makeTabs(AbstractColorChooserPanel[] panels) + { + pane.removeAll(); + for (int i = 0; i < panels.length; i++) + pane.addTab(panels[i].getDisplayName(), panels[i].getSmallDisplayIcon(), + panels[i]); + } + + /** + * This method uninstalls this UI for the given JComponent. + * + * @param c The JComponent that will have this UI removed. + */ + public void uninstallUI(JComponent c) + { + uninstallListeners(); + uninstallDefaults(); + + pane = null; + chooser = null; + } + + /** + * This method installs the preview panel for the JColorChooser. + */ + protected void installPreviewPanel() + { + updatePreviewPanel(ColorChooserComponentFactory.getPreviewPanel()); + } + + /** + * This is a helper method that swaps the existing preview panel with the + * given panel. + * + * @param preview The new preview panel. + */ + private void updatePreviewPanel(JComponent preview) + { + if (prevContainer == null) + { + prevContainer = new JPanel(); + prevContainer.setLayout(new BorderLayout()); + chooser.add(prevContainer, BorderLayout.CENTER); + } + prevContainer.removeAll(); + prevContainer.add(preview, BorderLayout.CENTER); + } + + /** + * This method installs the default properties given by the Basic Look and + * Feel. + */ + protected void installDefaults() + { + UIDefaults defaults = UIManager.getLookAndFeelDefaults(); + + chooser.setFont(defaults.getFont("ColorChooser.font")); + chooser.setForeground(defaults.getColor("ColorChooser.foreground")); + chooser.setBackground(defaults.getColor("ColorChooser.background")); + } + + /** + * This method uninstalls the default properties given by the Basic Look and + * Feel. + */ + protected void uninstallDefaults() + { + chooser.setBackground(null); + chooser.setForeground(null); + chooser.setFont(null); + } + + /** + * This method installs any listeners required for this UI to function. + */ + protected void installListeners() + { + propertyChangeListener = createPropertyChangeListener(); + previewListener = new PreviewListener(); + + chooser.addPropertyChangeListener(propertyChangeListener); + chooser.getSelectionModel().addChangeListener(previewListener); + + pane.addChangeListener(new TabPaneListener()); + } + + /** + * This method creates the PropertyChangeListener used for listening to the + * JColorChooser. + * + * @return A PropertyChangeListener. + */ + protected PropertyChangeListener createPropertyChangeListener() + { + return new PropertyHandler(); + } + + /** + * This method uninstalls any listeners that were previously installed by + * the UI. + */ + protected void uninstallListeners() + { + chooser.removePropertyChangeListener(propertyChangeListener); + chooser.getSelectionModel().removeChangeListener(previewListener); + + previewListener = null; + propertyChangeListener = null; + } +} diff --git a/libjava/javax/swing/plaf/basic/BasicComboBoxEditor.java b/libjava/javax/swing/plaf/basic/BasicComboBoxEditor.java new file mode 100644 index 0000000..a465ff9 --- /dev/null +++ b/libjava/javax/swing/plaf/basic/BasicComboBoxEditor.java @@ -0,0 +1,170 @@ +/* BasicComboBoxEditor.java -- + Copyright (C) 2004 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.swing.plaf.basic; + +import java.awt.Component; +import java.awt.event.ActionListener; +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; +import javax.swing.ComboBoxEditor; +import javax.swing.JTextField; +import javax.swing.border.EmptyBorder; +import javax.swing.plaf.UIResource; + + +/** + * This is a component that is responsible for displaying/editting selected + * item in comboBox. By default, the JTextField is returned as + * BasicComboBoxEditor. + * + * @author Olga Rodimina + */ +public class BasicComboBoxEditor extends Object implements ComboBoxEditor, + FocusListener +{ + protected JTextField editor; + + /** + * Creates a new BasicComboBoxEditor object. + */ + public BasicComboBoxEditor() + { + editor = new JTextField(); + editor.setBorder(new EmptyBorder(1, 1, 1, 1)); + } + + /** + * This method returns textfield that will be used by the combo box to + * display/edit currently selected item in the combo box. + * + * @return textfield that will be used by the combo box to display/edit + * currently selected item + */ + public Component getEditorComponent() + { + return editor; + } + + /** + * Sets item that should be editted when any editting operation is performed + * by the user. The value is always equal to the currently selected value + * in the combo box. Thus whenever a different value is selected from the + * combo box list then this method should be called to change editting + * item to the new selected item. + * + * @param selectedItem item that is currently selected in the combo box + */ + public void setItem(Object item) + { + editor.setText(item.toString()); + } + + /** + * This method returns item that is currently editable. + * + * @return item in the combo box that is currently editable + */ + public Object getItem() + { + return editor.getText(); + } + + public void selectAll() + { + editor.selectAll(); + } + + /** + * This method is called when textfield gains focus. This will enable + * editing of the selected item. + * + * @param e the FocusEvent describing change in focus. + */ + public void focusGained(FocusEvent e) + { + // FIXME: Need to implement + } + + /** + * This method is called when textfield loses focus. If during this time any + * editting operation was performed by the user, then it will be cancelled + * and selected item will not be changed. + * + * @param e the FocusEvent describing change in focus + */ + public void focusLost(FocusEvent e) + { + // FIXME: Need to implement + } + + /** + * This method adds actionListener to the editor. If the user will edit + * currently selected item in the textfield and pressEnter, then action + * will be performed. The actionPerformed of this ActionListener should + * change the selected item of the comboBox to the newly editted selected + * item. + * + * @param l the ActionListener responsible for changing selected item of the + * combo box when it is editted by the user. + */ + public void addActionListener(ActionListener l) + { + // FIXME: Need to implement + } + + /** + * This method removes actionListener from the textfield. + * + * @param l the ActionListener to remove from the textfield. + */ + public void removeActionListener(ActionListener l) + { + // FIXME: Need to implement + } + + public static class UIResource extends BasicComboBoxEditor + implements javax.swing.plaf.UIResource + { + /** + * Creates a new UIResource object. + */ + public UIResource() + { + } + } +} diff --git a/libjava/javax/swing/plaf/basic/BasicComboBoxRenderer.java b/libjava/javax/swing/plaf/basic/BasicComboBoxRenderer.java new file mode 100644 index 0000000..6bf6a74 --- /dev/null +++ b/libjava/javax/swing/plaf/basic/BasicComboBoxRenderer.java @@ -0,0 +1,143 @@ +/* BasicComboBoxRenderer.java -- + Copyright (C) 2004 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.swing.plaf.basic; + +import java.awt.Color; +import java.awt.Component; +import java.awt.Dimension; +import java.io.Serializable; +import javax.swing.JLabel; +import javax.swing.JList; +import javax.swing.ListCellRenderer; +import javax.swing.SwingConstants; +import javax.swing.UIDefaults; +import javax.swing.UIManager; +import javax.swing.border.Border; +import javax.swing.border.EmptyBorder; +import javax.swing.plaf.UIResource; + + +/** + * This class is renderer for the combo box. + * + * @author Olga Rodimina + */ +public class BasicComboBoxRenderer extends JLabel implements ListCellRenderer, + Serializable +{ + /** + * This border is used whenever renderer doesn't have a focus. + */ + protected static Border noFocusBorder = new EmptyBorder(0, 0, 0, 0); + + /** + * Creates a new BasicComboBoxRenderer object. + */ + public BasicComboBoxRenderer() + { + setHorizontalAlignment(SwingConstants.LEFT); + } + + /** + * Returns preferredSize of the renderer + * + * @return preferredSize of the renderer + */ + public Dimension getPreferredSize() + { + return super.getPreferredSize(); + } + + /** + * getListCellRendererComponent + * + * @param list List of items for which to the background and foreground + * colors + * @param value object that should be rendered in the cell + * @param index index of the cell in the list of items. + * @param isSelected draw cell highlighted if isSelected is true + * @param cellHasFocus draw focus rectangle around cell if the cell has + * focus + * + * @return Component that will be used to draw the desired cell. + */ + public Component getListCellRendererComponent(JList list, Object value, + int index, boolean isSelected, + boolean cellHasFocus) + { + String s = value.toString(); + setText(s); + setOpaque(true); + + UIDefaults defaults = UIManager.getLookAndFeelDefaults(); + + if (isSelected) + { + setBackground(list.getSelectionBackground()); + setForeground(list.getSelectionForeground()); + } + else + { + setBackground(list.getBackground()); + setForeground(list.getForeground()); + } + + setEnabled(list.isEnabled()); + setFont(list.getFont()); + + // Use focusCellHighlightBorder when renderer has focus and + // noFocusBorder otherwise + if (cellHasFocus) + setBorder(UIManager.getBorder("List.focusCellHighlightBorder")); + else + setBorder(noFocusBorder); + + return this; + } + + public static class UIResource extends BasicComboBoxRenderer + implements javax.swing.plaf.UIResource + { + /** + * Creates a new UIResource object. + */ + public UIResource() + { + } + } +} diff --git a/libjava/javax/swing/plaf/basic/BasicComboBoxUI.java b/libjava/javax/swing/plaf/basic/BasicComboBoxUI.java new file mode 100644 index 0000000..851392a --- /dev/null +++ b/libjava/javax/swing/plaf/basic/BasicComboBoxUI.java @@ -0,0 +1,1227 @@ +/* BasicComboBoxUI.java -- + Copyright (C) 2004 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.swing.plaf.basic; + +import java.awt.Color; +import java.awt.Component; +import java.awt.Container; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.Insets; +import java.awt.LayoutManager; +import java.awt.Rectangle; +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.awt.event.MouseMotionListener; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.util.EventListener; +import javax.accessibility.Accessible; +import javax.swing.CellRendererPane; +import javax.swing.ComboBoxEditor; +import javax.swing.ComboBoxModel; +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JComponent; +import javax.swing.JLabel; +import javax.swing.JList; +import javax.swing.ListCellRenderer; +import javax.swing.SwingConstants; +import javax.swing.UIDefaults; +import javax.swing.UIManager; +import javax.swing.event.ListDataEvent; +import javax.swing.event.ListDataListener; +import javax.swing.event.PopupMenuEvent; +import javax.swing.event.PopupMenuListener; +import javax.swing.plaf.ComboBoxUI; +import javax.swing.plaf.ComponentUI; +import javax.swing.plaf.basic.BasicComboPopup; +import javax.swing.plaf.basic.BasicGraphicsUtils; + + +/** + * UI Delegate for JComboBox + * + * @author Olga Rodimina + */ +public class BasicComboBoxUI extends ComboBoxUI +{ + /** + * This arrow button that is displayed in the rigth side of JComboBox. This + * button is used to hide and show combo box's list of items + */ + protected JButton arrowButton; + + /** + * The combo box for which this UI delegate is for + */ + protected JComboBox comboBox; + + /** + * Component that is responsible for displaying/editting selected item of + * the combo box. By default JTextField is used as an editor for the + * JComboBox + */ + protected Component editor; + + /** + * Listener listening to focus events occuring in the JComboBox + */ + protected FocusListener focusListener; + + /** + * tells whether JComboBox currently has focus + */ + protected boolean hasFocus; + + /** + * Listener listening to item events fired by the JComboBox + */ + protected ItemListener itemListener; + + /** + * KeyListener listening to key events that occur while JComboBox has focus + */ + protected KeyListener keyListener; + + /** + * MouseListener listening to mouse events occuring in the combo box + */ + private MouseListener mouseListener; + + /** + * List used when rendering selected item of the combo box. The selection + * and foreground colors for combo box renderer are configured from this + * list + */ + protected JList listBox; + + /** + * ListDataListener listening to JComboBox model + */ + protected ListDataListener listDataListener; + + /** + * Popup list containing combo box's menu items + */ + protected ComboPopup popup; + protected KeyListener popupKeyListener; + protected MouseListener popupMouseListener; + protected MouseMotionListener popupMouseMotionListener; + + /** + * Listener listening to changes in the bound properties of JComboBox + */ + protected PropertyChangeListener propertyChangeListener; + + /** + * Colors that are used to render selected item in the combo box. + */ + private Color shadow; + private Color darkShadow; + private Color highlight; + private Color lightHighlight; + + /* Size of the largest item in the comboBox */ + private Dimension largestItemSize; + + // It seems that JComboBox doesn't have a border set explicitely. So we just + // paint the border everytime combo box is displayed. + + /* border insets for this JComboBox*/ + private static final Insets borderInsets = new Insets(2, 2, 2, 2); + + // Width of the arrow button + private static int arrowButtonWidth = 15; + + // FIXME: This fields aren't used anywhere at this moment. + protected Dimension cachedMinimumSize; + protected CellRendererPane currentValuePane; + protected boolean isMinimumSizeDirty; + + /** + * Creates a new BasicComboBoxUI object. + */ + public BasicComboBoxUI() + { + } + + /** + * Factory method to create a BasicComboBoxUI for the given {@link + * JComponent}, which should be a {@link JComboBox}. + * + * @param c The {@link JComponent} a UI is being created for. + * + * @return A BasicComboBoxUI for the {@link JComponent}. + */ + public static ComponentUI createUI(JComponent c) + { + return new BasicComboBoxUI(); + } + + /** + * 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 JComboBox) + { + comboBox = (JComboBox) c; + comboBox.setOpaque(true); + comboBox.setLayout(createLayoutManager()); + installDefaults(); + installComponents(); + installListeners(); + installKeyboardActions(); + } + } + + /** + * This method uninstalls the UI. + * + * @param c The JComponent that is having this UI removed. + */ + public void uninstallUI(JComponent c) + { + uninstallKeyboardActions(); + uninstallListeners(); + uninstallComponents(); + uninstallDefaults(); + comboBox = null; + } + + /** + * This method installs the defaults that are defined in the Basic look and + * feel for this {@link JComboBox}. + */ + protected void installDefaults() + { + UIDefaults defaults = UIManager.getLookAndFeelDefaults(); + + comboBox.setBackground(defaults.getColor("ComboBox.background")); + comboBox.setFont(defaults.getFont("ComboBox.font")); + comboBox.setForeground(defaults.getColor("ComboBox.foreground")); + + // Set default color that should be used to to render selected item + // of the combo box. + shadow = defaults.getColor("Button.shadow"); + darkShadow = defaults.getColor("Button.darkShadow"); + lightHighlight = defaults.getColor("Button.light"); + highlight = defaults.getColor("Button.highlight"); + } + + /** + * This method creates and installs the listeners for this UI. + */ + protected void installListeners() + { + // install combo box's listeners + propertyChangeListener = createPropertyChangeListener(); + comboBox.addPropertyChangeListener(propertyChangeListener); + + focusListener = createFocusListener(); + comboBox.addFocusListener(focusListener); + + itemListener = createItemListener(); + comboBox.addItemListener(itemListener); + + keyListener = createKeyListener(); + comboBox.addKeyListener(keyListener); + + mouseListener = createMouseListener(); + comboBox.addMouseListener(mouseListener); + + // install listeners that listen to combo box model + listDataListener = createListDataListener(); + comboBox.getModel().addListDataListener(listDataListener); + + configureArrowButton(); + } + + /** + * This method uninstalls the defaults and sets any objects created during + * install to null + */ + protected void uninstallDefaults() + { + UIDefaults defaults = UIManager.getLookAndFeelDefaults(); + + comboBox.setBackground(null); + comboBox.setFont(null); + comboBox.setForeground(null); + + shadow = null; + darkShadow = null; + lightHighlight = null; + highlight = null; + } + + /** + * Detaches all the listeners we attached in {@link #installListeners}. + */ + protected void uninstallListeners() + { + comboBox.removePropertyChangeListener(propertyChangeListener); + propertyChangeListener = null; + + comboBox.removeFocusListener(focusListener); + focusListener = null; + + comboBox.removeItemListener(itemListener); + itemListener = null; + + comboBox.removeKeyListener(keyListener); + keyListener = null; + + comboBox.removeMouseListener(mouseListener); + mouseListener = null; + + comboBox.getModel().removeListDataListener(listDataListener); + listDataListener = null; + + unconfigureArrowButton(); + } + + /** + * This method creates popup that will contain list of combo box's items + * + * @return popup containing list of combo box's items + */ + protected ComboPopup createPopup() + { + return new BasicComboPopup(comboBox); + } + + /** + * Creates KeyListener to listen to key events. + * + * @return KeyListener that listens to key events. + */ + protected KeyListener createKeyListener() + { + return new KeyHandler(); + } + + /** + * This method create MouseListener that will listen to mouse event occuring + * in combo box. + * + * @return the MouseListener + */ + private MouseListener createMouseListener() + { + return new MouseHandler(); + } + + /** + * This method create FocusListener that will listen to changes in this + * JComboBox's focus. + * + * @return theFocusListener + */ + protected FocusListener createFocusListener() + { + return new FocusHandler(); + } + + /** + * This method create ListDataListener to listen to ComboBox's data model + * + * @return ListDataListener + */ + protected ListDataListener createListDataListener() + { + return new ListDataHandler(); + } + + /** + * This method creates ItemListener that will listen to to the changes in + * the JComboBox's selection. + * + * @return the ItemListener + */ + protected ItemListener createItemListener() + { + return new ItemHandler(); + } + + /** + * This method creates PropertyChangeListener to listen to the changes in + * the JComboBox's bound properties. + * + * @return the PropertyChangeListener + */ + protected PropertyChangeListener createPropertyChangeListener() + { + return new PropertyChangeHandler(); + } + + /** + * This method returns layout manager for the combo box. + * + * @return layout manager for the combo box + */ + protected LayoutManager createLayoutManager() + { + return new ComboBoxLayoutManager(); + } + + /** + * This method creates component that will be responsible for rendering the + * selected component in the combo box. + * + * @return render for the combo box + */ + protected ListCellRenderer createRenderer() + { + return new BasicComboBoxRenderer(); + } + + /** + * Creates component that will be responsible for displaying/editting + * selected item in the combo box. This editor is used only when combo box + * is editable. + * + * @return component that will be responsible for displaying/editting + * selected item in the combo box. + */ + protected ComboBoxEditor createEditor() + { + return new BasicComboBoxEditor(); + } + + /** + * This method installs components for this JComboBox. ArrowButton, main + * part of combo box (upper part) and popup list of items are created and + * configured here. + */ + protected void installComponents() + { + // create and install arrow button + arrowButton = createArrowButton(); + + comboBox.add(arrowButton); + + // Set list that will be used by BasicComboBoxRender + // in order to determine the right colors when rendering + listBox = new JList(); + + Color background = arrowButton.getBackground(); + listBox.setBackground(background); + listBox.setSelectionBackground(background.darker()); + + Color foreground = arrowButton.getForeground(); + listBox.setForeground(foreground); + listBox.setSelectionForeground(foreground); + + // set editor and renderer for the combo box. Editor is used + // only if combo box becomes editable, otherwise renderer is used + // to paint the selected item; combobox is not editable by default. + comboBox.setRenderer(createRenderer()); + + comboBox.setEditor(createEditor()); + editor = comboBox.getEditor().getEditorComponent(); + + // create drop down list of items + popup = createPopup(); + + comboBox.revalidate(); + } + + /** + * This method uninstalls components from this JComboBox + */ + protected void uninstallComponents() + { + // uninstall arrow button + unconfigureArrowButton(); + comboBox.remove(arrowButton); + arrowButton = null; + + listBox = null; + popup = null; + + comboBox.setRenderer(null); + + comboBox.setEditor(null); + editor = null; + } + + /** + * This method adds editor to the combo box + */ + public void addEditor() + { + comboBox.add(editor); + } + + /** + * This method removes editor from the combo box + */ + public void removeEditor() + { + comboBox.remove(editor); + } + + /** + * This method configures editor for this combo box. + */ + protected void configureEditor() + { + // FIXME: Need to implement. Set font and add listeners. + } + + /** + * This method removes all the listeners for the editor. + */ + protected void unconfigureEditor() + { + // FIXME: Need to implement + } + + /** + * This method adds listeners to the arrow button part of the combo box. + */ + public void configureArrowButton() + { + arrowButton.addMouseListener(mouseListener); + } + + /** + * This method removes listeners from the arrow button part of the combo + * box. + */ + public void unconfigureArrowButton() + { + arrowButton.removeMouseListener(mouseListener); + } + + /** + * This method create arrow button for this JComboBox. Arrow button is + * responsible for displaying / hiding drop down list of items when it is + * clicked. + * + * @return JButton arrow button for this JComboBox. + */ + protected JButton createArrowButton() + { + return new BasicArrowButton(BasicArrowButton.SOUTH); + } + + /** + * This method checks if popup part of the combo box is visible on the + * screen + * + * @param c The JComboBox to check + * + * @return true if popup part of the JComboBox is visible and false + * otherwise. + */ + public boolean isPopupVisible(JComboBox c) + { + return popup.isVisible(); + } + + /** + * Displays/Hides JComboBox's list of items on the screen. + * + * @param c The combo box, for which list of items should be + * displayed/hidden + * @param v true if show popup part of the jcomboBox and false to hide. + */ + public void setPopupVisible(JComboBox c, boolean v) + { + if (v) + popup.show(); + else + popup.hide(); + } + + /** + * JComboBox is focus traversable if it is editable and not otherwise. + * + * @param c combo box for which to check whether it is focus traversable + * + * @return true if focus tranversable and false otherwise + */ + public boolean isFocusTraversable(JComboBox c) + { + if (comboBox.isEditable()) + return true; + + return false; + } + + /** + * Paints given menu item using specified graphics context + * + * @param g The graphics context used to paint this combo box + * @param c comboBox which needs to be painted. + */ + public void paint(Graphics g, JComponent c) + { + if (c instanceof JComboBox) + { + JComboBox cb = (JComboBox) c; + + paintBorder(g, comboBox.getBounds(), hasFocus); + + Rectangle rect = rectangleForCurrentValue(); + paintCurrentValueBackground(g, rect, hasFocus); + paintCurrentValue(g, rect, hasFocus); + } + } + + private void paintBorder(Graphics g, Rectangle bounds, boolean hasFocus) + { + int x = 0; + int y = 0; + int width = bounds.width; + int height = bounds.height; + + Color oldColor = g.getColor(); + + if (! arrowButton.getModel().isPressed()) + BasicGraphicsUtils.drawEtchedRect(g, x, y, width, height, Color.gray, + Color.white, Color.gray, Color.white); + else + { + g.setColor(darkShadow); + g.drawRect(x, y, width, height); + g.setColor(shadow); + g.drawRect(x + 1, y + 1, width - 3, height - 3); + } + g.setColor(oldColor); + } + + /** + * Returns preferred size for the given menu item. + * + * @param c comboBox for which to get preferred size + * + * @return $Dimension$ preferred size for the given combo box + */ + public Dimension getPreferredSize(JComponent c) + { + // return null to indicate that combo box's layout will determin its + // preferred size + return null; + } + + /** + * This method returns the minimum size for this {@link JComboBox} for this + * look and feel. + * + * @param c The {@link JComponent} to find the minimum size for. + * + * @return The dimensions of the minimum size. + */ + public Dimension getMinimumSize(JComponent c) + { + return null; + } + + /** + * This method returns the maximum size for this {@link JComboBox} for this + * look and feel. + * + * @param c The {@link JComponent} to find the maximum size for + * + * @return The dimensions of the minimum size. + */ + public Dimension getMaximumSize(JComponent c) + { + return null; + } + + public int getAccessibleChildrenCount(JComponent c) + { + // FIXME: Need to implement + return 0; + } + + public Accessible getAccessibleChild(JComponent c, int i) + { + // FIXME: Need to implement + return null; + } + + /** + * Returns true if the specified key is a navigation key and false otherwise + * + * @param keyCode a key for which to check whether it is navigation key or + * not. + * + * @return true if the specified key is a navigation key and false otherwis + */ + protected boolean isNavigationKey(int keyCode) + { + return false; + } + + /** + * This method selects next possible item relative to the current selection + * to be next selected item in the combo box. + */ + protected void selectNextPossibleValue() + { + int index = comboBox.getSelectedIndex(); + if (index != comboBox.getItemCount() - 1) + comboBox.setSelectedIndex(index + 1); + } + + /** + * This method selects previous item relative to current selection to be + * next selected item. + */ + protected void selectPreviousPossibleValue() + { + int index = comboBox.getSelectedIndex(); + if (index != 0) + comboBox.setSelectedIndex(index - 1); + } + + /** + * This method displays combo box popup if the popup is not currently shown + * on the screen and hides it if it is currently shown + */ + protected void toggleOpenClose() + { + setPopupVisible(comboBox, ! isPopupVisible(comboBox)); + } + + /** + * This method returns bounds in which comboBox's selected Item will be + * displayed + * + * @return rectangle bounds in which comboBox's selected Item will be + * displayed + */ + protected Rectangle rectangleForCurrentValue() + { + Rectangle cbBounds = comboBox.getBounds(); + + // Subtract width or the arrow button and border insets + Rectangle rectForCurrentValue = new Rectangle(cbBounds.x + + borderInsets.left, + cbBounds.y + + borderInsets.top, + cbBounds.width + - arrowButtonWidth + - borderInsets.left + - borderInsets.right, + cbBounds.height + - borderInsets.top + - borderInsets.bottom); + + return rectForCurrentValue; + } + + /** + * This method returns insets of the current border. + * + * @return Insets representing space between combo box and its border + */ + protected Insets getInsets() + { + return new Insets(0, 0, 0, 0); + } + + /** + * This method paints currently selected value in the main part of the combo + * box (part without popup). + * + * @param g graphics context + * @param bounds Rectangle representing the size of the area in which + * selected item should be drawn + * @param hasFocus true if combo box has focus and false otherwise + */ + public void paintCurrentValue(Graphics g, Rectangle bounds, boolean hasFocus) + { + if (! comboBox.isEditable()) + { + Object currentValue = comboBox.getSelectedItem(); + boolean isPressed = arrowButton.getModel().isPressed(); + if (currentValue != null) + { + Component comp = comboBox.getRenderer() + .getListCellRendererComponent(listBox, + currentValue, + -1, + isPressed, + isPressed); + if (! comboBox.isEnabled()) + comp.setEnabled(false); + + g.translate(borderInsets.left, borderInsets.top); + comp.setBounds(0, 0, bounds.width, bounds.height); + comp.paint(g); + g.translate(-borderInsets.left, -borderInsets.top); + } + comboBox.revalidate(); + } + else + comboBox.getEditor().setItem(comboBox.getSelectedItem()); + } + + /** + * This method paints background of part of the combo box, where currently + * selected value is displayed. If the combo box has focus this method + * should also paint focus rectangle around the combo box. + * + * @param g graphics context + * @param bounds Rectangle representing the size of the largest item in the + * comboBox + * @param hasFocus true if combo box has fox and false otherwise + */ + public void paintCurrentValueBackground(Graphics g, Rectangle bounds, + boolean hasFocus) + { + // background is painted by renderer, so it seems that nothing + // should be done here. + } + + /** + * Returns default size for the combo box that doesn't contain any elements + * in it + * + * @return Default size of the combo box with no elements in it. + */ + protected Dimension getDefaultSize() + { + return new Dimension(6, 17); + } + + /** + * Returns size of the largest item in the combo box. This size will be the + * size of the combo box, not including the arrowButton. + * + * @return dimensions of the largest item in the combo box. + */ + protected Dimension getLargestItemSize() + { + ComboBoxModel model = comboBox.getModel(); + int numItems = model.getSize(); + + // if combo box doesn't have any items then simply + // return its default size + if (numItems == 0) + { + largestItemSize = getDefaultSize(); + return largestItemSize; + } + + Dimension size = new Dimension(0, 0); + + // ComboBox's display size should be equal to the + // size of the largest item in the combo box. + ListCellRenderer renderer = comboBox.getRenderer(); + + for (int i = 0; i < numItems; i++) + { + Object item = model.getElementAt(i); + String s = item.toString(); + Component comp = renderer.getListCellRendererComponent(listBox, item, + -1, false, false); + + if (comp.getPreferredSize().getWidth() > size.getWidth()) + size = comp.getPreferredSize(); + } + + largestItemSize = size; + return largestItemSize; + } + + /** + * This method installs the keyboard actions for the JComboBox as specified + * by the look and feel. + */ + protected void installKeyboardActions() + { + // FIXME: Need to implement. + } + + /** + * This method uninstalls the keyboard actions for the JComboBox there were + * installed by in {@link #installListeners}. + */ + protected void uninstallKeyboardActions() + { + // FIXME: Need to implement. + } + + /** + * This class is Layout Manager for this combo box. + */ + public class ComboBoxLayoutManager extends Object implements LayoutManager + { + /** + * Creates a new ComboBoxLayoutManager object. + */ + public ComboBoxLayoutManager() + { + } + + public void addLayoutComponent(String name, Component comp) + { + // Do nothing + } + + public void removeLayoutComponent(Component comp) + { + // Do nothing + } + + /** + * Returns preferred layout size of the JComboBox. + * + * @param parent Container for which preferred size should be calculated + * + * @return preferred size for the given container + */ + public Dimension preferredLayoutSize(Container parent) + { + Dimension d = new Dimension(0, 0); + + if (largestItemSize == null) + largestItemSize = getLargestItemSize(); + + // add size for the area that will display selected item + d.width += largestItemSize.getWidth(); + d.height += largestItemSize.getHeight(); + + // add size of the arrow button + d.width += arrowButtonWidth; + + // add width and height of the border + d.width += borderInsets.left + borderInsets.right; + d.height += borderInsets.left + borderInsets.right; + + // Add combo box's insets + Insets insets = parent.getInsets(); + d.width += insets.left + insets.right; + d.width += insets.left + insets.right; + + return d; + } + + public Dimension minimumLayoutSize(Container parent) + { + return preferredLayoutSize(parent); + } + + /** + * This method layouts out the components in the container. It puts arrow + * button right end part of the comboBox. If the comboBox is editable + * then editor is placed to the left of arrow button, starting from the + * beginning. + * + * @param parent Container that should be layed out. + */ + public void layoutContainer(Container parent) + { + // Position editor component to the left of arrow button if combo box is + // editable + int editorWidth = comboBox.getBounds().width - arrowButtonWidth - 2; + + if (comboBox.isEditable()) + editor.setBounds(borderInsets.left, borderInsets.top, editorWidth, + comboBox.getBounds().height - borderInsets.left + - borderInsets.top); + + arrowButton.setBounds(editorWidth, 2, arrowButtonWidth, + comboBox.getBounds().height - 4); + comboBox.revalidate(); + } + } + + /** + * This class handles focus changes occuring in the combo box. This class is + * responsible for repainting combo box whenever focus is gained or lost + * and also for hiding popup list of items whenever combo box loses its + * focus. + */ + public class FocusHandler extends Object implements FocusListener + { + /** + * Creates a new FocusHandler object. + */ + public FocusHandler() + { + } + + /** + * This mehtod is invoked when combo box gains focus. It repaints main + * part of combo box accordingally. + * + * @param e the FocusEvent + */ + public void focusGained(FocusEvent e) + { + hasFocus = true; + comboBox.repaint(); + } + + /** + * This method is invoked when combo box loses focus It repaint main part + * of combo box accordingally and hides popup list of items. + * + * @param e the FocusEvent + */ + public void focusLost(FocusEvent e) + { + hasFocus = false; + comboBox.repaint(); + popup.hide(); + } + } + + /** + * This class handles ItemEvent fired by the JComboBox when its selected + * item changes. + */ + public class ItemHandler extends Object implements ItemListener + { + /** + * Creates a new ItemHandler object. + */ + public ItemHandler() + { + } + + /** + * This method is invoked when selected item becomes deselected or when + * new item becomes selected. + * + * @param e the ItemEvent representing item's state change. + */ + public void itemStateChanged(ItemEvent e) + { + comboBox.repaint(); + } + } + + /** + * KeyHandler handles key events occuring while JComboBox has focus. + */ + public class KeyHandler extends KeyAdapter + { + public KeyHandler() + { + } + + /* + * This method is invoked whenever key is pressed while JComboBox is in + * focus. + */ + public void keyPressed(KeyEvent e) + { + // FIXME: This method calls JComboBox.selectWithKeyChar if the key that was + // pressed is not a navigation key. + } + } + + /** + * This class handles to the changes occuring in the JComboBox's data model + */ + public class ListDataHandler extends Object implements ListDataListener + { + /** + * Creates a new ListDataHandler object. + */ + public ListDataHandler() + { + } + + /** + * This method is invoked content's of JComboBox's data model are changed + * + * @param e ListDataEvent describing the change. + */ + public void contentsChanged(ListDataEvent e) + { + // if the item is selected or deselected + } + + /** + * This method is invoked when items were added to the JComboBox's data + * model. + * + * @param e ListDataEvent describing the change. + */ + public void intervalAdded(ListDataEvent e) + { + // must determine if the size of the combo box should change + int start = e.getIndex0(); + int end = e.getIndex1(); + + ComboBoxModel model = comboBox.getModel(); + ListCellRenderer renderer = comboBox.getRenderer(); + + if (largestItemSize == null) + largestItemSize = new Dimension(0, 0); + + for (int i = start - 1; i < end; i++) + { + Object item = model.getElementAt(i); + Component comp = renderer.getListCellRendererComponent(new JList(), + item, -1, + false, false); + if (comp.getPreferredSize().getWidth() > largestItemSize.getWidth()) + largestItemSize = comp.getPreferredSize(); + } + } + + /** + * This method is invoked when items were removed from the JComboBox's + * data model. + * + * @param e ListDataEvent describing the change. + */ + public void intervalRemoved(ListDataEvent e) + { + // must determine if the size of the combo box should change + // FIXME: need to implement + } + } + + /** + * This class handles PropertyChangeEvents fired by JComboBox. + */ + public class PropertyChangeHandler extends Object + implements PropertyChangeListener + { + public PropertyChangeHandler() + { + } + + public void propertyChange(PropertyChangeEvent e) + { + if (e.getPropertyName().equals(JComboBox.ENABLED_CHANGED_PROPERTY)) + { + // disable arrow button + arrowButton.setEnabled(comboBox.isEnabled()); + + if (comboBox.isEditable()) + comboBox.getEditor().getEditorComponent().setEnabled(comboBox + .isEnabled()); + } + else if (e.getPropertyName().equals(JComboBox.EDITABLE_CHANGED_PROPERTY)) + { + if (comboBox.isEditable()) + { + configureEditor(); + addEditor(); + } + else + { + unconfigureEditor(); + removeEditor(); + } + + comboBox.revalidate(); + comboBox.repaint(); + } + + // FIXME: Need to handle changes in other bound properties. + } + } + + /** + * MouseHandler listens to mouse events occuring in the combo box. This + * class is responsible for repainting this JComboBox whenever the mouse is + * being pressed or released over it. + */ + private class MouseHandler extends MouseAdapter + { + /** + * This method is invoked when mouse is pressed over the combo box. It + * repaints the combo box accordinglly + * + * @param e the MouseEvent + */ + public void mousePressed(MouseEvent e) + { + if (comboBox.isEnabled()) + { + if (e.getSource() instanceof JComboBox) + { + arrowButton.getModel().setPressed(true); + arrowButton.getModel().setArmed(true); + } + + comboBox.repaint(); + + if (e.getSource() instanceof BasicArrowButton) + toggleOpenClose(); + } + } + + /** + * This method is invoked when mouse is released over the combo box. It + * repaints the combo box accordinglly + * + * @param e the MouseEvent + */ + public void mouseReleased(MouseEvent e) + { + if (comboBox.isEnabled()) + { + if (e.getSource() instanceof JComboBox) + { + arrowButton.getModel().setPressed(false); + arrowButton.getModel().setArmed(false); + } + + comboBox.repaint(); + } + } + } +} diff --git a/libjava/javax/swing/plaf/basic/BasicComboPopup.java b/libjava/javax/swing/plaf/basic/BasicComboPopup.java new file mode 100644 index 0000000..61d2dfb --- /dev/null +++ b/libjava/javax/swing/plaf/basic/BasicComboPopup.java @@ -0,0 +1,933 @@ +/* BasicComboPopup.java -- + Copyright (C) 2004 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.swing.plaf.basic; + +import java.awt.Component; +import java.awt.Dimension; +import java.awt.Rectangle; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.awt.event.MouseMotionAdapter; +import java.awt.event.MouseMotionListener; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import javax.swing.ComboBoxModel; +import javax.swing.JComboBox; +import javax.swing.JComponent; +import javax.swing.JLabel; +import javax.swing.JList; +import javax.swing.JPopupMenu; +import javax.swing.JScrollPane; +import javax.swing.ListCellRenderer; +import javax.swing.ListSelectionModel; +import javax.swing.SwingConstants; +import javax.swing.Timer; +import javax.swing.event.ListDataEvent; +import javax.swing.event.ListDataListener; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; +import javax.swing.event.PopupMenuEvent; +import javax.swing.event.PopupMenuListener; + + +/** + * UI Delegate for ComboPopup + * + * @author Olga Rodimina + */ +public class BasicComboPopup extends JPopupMenu implements ComboPopup +{ + protected Timer autoscrollTimer; + + /** + * ComboBox associated with this popup + */ + protected JComboBox comboBox; + + /* + * FIXME: Document fields below + */ + protected boolean hasEntered; + protected boolean isAutoScrolling; + + /** + * ItemListener listening to the selection changes in the combo box + */ + protected ItemListener itemListener; + + /** + * This listener is not used + */ + protected KeyListener keyListener; + + /** + * JList which is used to display item is the combo box + */ + protected JList list; + + /** + * This listener is not used + */ + protected ListDataListener listDataListener; + + /** + * MouseListener listening to mouse events occuring in the combo box's + * list. + */ + protected MouseListener listMouseListener; + + /** + * MouseMotionListener listening to mouse motion events occuring in the + * combo box's list + */ + protected MouseMotionListener listMouseMotionListener; + + /** + * This listener is not used + */ + protected ListSelectionListener listSelectionListener; + + /** + * MouseListener listening to mouse events occuring in the combo box + */ + protected MouseListener mouseListener; + + /** + * MouseMotionListener listening to mouse motion events occuring in the + * combo box + */ + protected MouseMotionListener mouseMotionListener; + + /** + * PropertyChangeListener listening to changes occuring in the bound + * properties of the combo box + */ + protected PropertyChangeListener propertyChangeListener; + + /* + * FIXME: Document fields below + */ + protected static int SCROLL_DOWN = 1; + protected static int SCROLL_UP = 0; + protected int scrollDirection; + + /** + * JScrollPane that contains list portion of the combo box + */ + protected JScrollPane scroller; + + /** + * This field is not used + */ + protected boolean valueIsAdjusting; + + /** + * Creates a new BasicComboPopup object. + * + * @param comboBox the combo box with which this popup should be associated + */ + public BasicComboPopup(JComboBox comboBox) + { + this.comboBox = comboBox; + installComboBoxListeners(); + + // initialize list that will be used to display elements of the combo box + this.list = createList(); + ((JLabel) list.getCellRenderer()).setHorizontalAlignment(SwingConstants.LEFT); + configureList(); + + // initialize scroller. Add list to the scroller. + scroller = createScroller(); + configureScroller(); + + // add scroller with list inside of it to JPopupMenu + super.add(scroller); + + setLightWeightPopupEnabled(comboBox.isLightWeightPopupEnabled()); + } + + /** + * This method displays drow down list of combo box items on the screen. + */ + public void show() + { + Rectangle cbBounds = comboBox.getBounds(); + + // popup should have same width as the comboBox and should be hight anough + // to display number of rows equal to 'maximumRowCount' property + int popupHeight = getPopupHeightForRowCount(comboBox.getMaximumRowCount()) + + 4; + + super.setPopupSize(cbBounds.width, popupHeight); + + // location specified is relative to comboBox + super.show(comboBox, 0, cbBounds.height); + } + + /** + * This method hides drop down list of items + */ + public void hide() + { + super.setVisible(false); + } + + /** + * Return list cointaining JComboBox's items + * + * @return list cointaining JComboBox's items + */ + public JList getList() + { + return list; + } + + /** + * Returns MouseListener that is listening to mouse events occuring in the + * combo box. + * + * @return MouseListener + */ + public MouseListener getMouseListener() + { + return mouseListener; + } + + /** + * Returns MouseMotionListener that is listening to mouse motion events + * occuring in the combo box. + * + * @return MouseMotionListener + */ + public MouseMotionListener getMouseMotionListener() + { + return mouseMotionListener; + } + + /** + * Returns KeyListener listening to key events occuring in the combo box. + * This method returns null because KeyHandler is not longer used. + * + * @return KeyListener + */ + public KeyListener getKeyListener() + { + return keyListener; + } + + /** + * This method uninstalls the UI for the given JComponent. + */ + public void uninstallingUI() + { + uninstallComboBoxModelListeners(comboBox.getModel()); + + uninstallListeners(); + uninstallKeyboardActions(); + } + + /** + * This method uninstalls listeners that were listening to changes occuring + * in the comb box's data model + * + * @param model data model for the combo box from which to uninstall + * listeners + */ + protected void uninstallComboBoxModelListeners(ComboBoxModel model) + { + model.removeListDataListener(listDataListener); + } + + /** + * This method uninstalls keyboard actions installed by the UI. + */ + protected void uninstallKeyboardActions() + { + // FIXME: Need to implement + } + + /** + * This method fires PopupMenuEvent indicating that combo box's popup list + * of items will become visible + */ + protected void firePopupMenuWillBecomeVisible() + { + // FIXME: Need to implement + } + + /** + * This method fires PopupMenuEvent indicating that combo box's popup list + * of items will become invisible. + */ + protected void firePopupMenuWillBecomeInvisible() + { + // FIXME: Need to implement + } + + /** + * This method fires PopupMenuEvent indicating that combo box's popup list + * of items was closed without selection. + */ + protected void firePopupMenuCanceled() + { + // FIXME: Need to implement + } + + /** + * Creates MouseListener to listen to mouse events occuring in the combo + * box. Note that this listener doesn't listen to mouse events occuring in + * the popup portion of the combo box, it only listens to main combo box + * part. + * + * @return new MouseMotionListener that listens to mouse events occuring in + * the combo box + */ + protected MouseListener createMouseListener() + { + return new InvocationMouseHandler(); + } + + /** + * Create Mouse listener that listens to mouse dragging events occuring in + * the combo box. This listener is responsible for changing the selection + * in the combo box list to the component over which mouse is being + * currently dragged + * + * @return new MouseMotionListener that listens to mouse dragging events + * occuring in the combo box + */ + protected MouseMotionListener createMouseMotionListener() + { + return new InvocationMouseMotionHandler(); + } + + /** + * KeyListener created in this method is not used anymore. + * + * @return KeyListener that does nothing + */ + protected KeyListener createKeyListener() + { + return new InvocationKeyHandler(); + } + + /** + * ListSelectionListener created in this method is not used anymore + * + * @return ListSelectionListener that does nothing + */ + protected ListSelectionListener createListSelectionListener() + { + return new ListSelectionHandler(); + } + + /** + * Creates ListDataListener. This method returns null, because + * ListDataHandler class is obsolete and is no longer used. + * + * @return null + */ + protected ListDataListener createListDataListener() + { + return null; + } + + /** + * This method creates ListMouseListener to listen to mouse events occuring + * in the combo box's item list. + * + * @return MouseListener to listen to mouse events occuring in the combo + * box's items list. + */ + protected MouseListener createListMouseListener() + { + return new ListMouseHandler(); + } + + /** + * Creates ListMouseMotionlistener to listen to mouse motion events occuring + * in the combo box's list. This listener is responsible for highlighting + * items in the list when mouse is moved over them. + * + * @return MouseMotionListener that handles mouse motion events occuring in + * the list of the combo box. + */ + protected MouseMotionListener createListMouseMotionListener() + { + return new ListMouseMotionHandler(); + } + + /** + * Creates PropertyChangeListener to handle changes in the JComboBox's bound + * properties. + * + * @return PropertyChangeListener to handle changes in the JComboBox's bound + * properties. + */ + protected PropertyChangeListener createPropertyChangeListener() + { + return new PropertyChangeHandler(); + } + + /** + * Creates new ItemListener that will listen to ItemEvents occuring in the + * combo box. + * + * @return ItemListener to listen to ItemEvents occuring in the combo box. + */ + protected ItemListener createItemListener() + { + return new ItemHandler(); + } + + /** + * Creates JList that will be used to display items in the combo box. + * + * @return JList that will be used to display items in the combo box. + */ + protected JList createList() + { + JList l = new JList(comboBox.getModel()); + l.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); + return l; + } + + /** + * This method configures the list of comboBox's items by setting default + * properties and installing listeners. + */ + protected void configureList() + { + list.setModel(comboBox.getModel()); + + if (comboBox.getItemCount() < comboBox.getMaximumRowCount()) + list.setVisibleRowCount(comboBox.getItemCount()); + else + list.setVisibleRowCount(comboBox.getMaximumRowCount()); + installListListeners(); + } + + /** + * This method installs list listeners. + */ + protected void installListListeners() + { + // mouse listener listening to mouse events occuring in the + // combo box's list of items. + listMouseListener = createListMouseListener(); + list.addMouseListener(listMouseListener); + + // mouse listener listening to mouse motion events occuring in the + // combo box's list of items + listMouseMotionListener = createListMouseMotionListener(); + list.addMouseMotionListener(listMouseMotionListener); + + listSelectionListener = createListSelectionListener(); + list.addListSelectionListener(listSelectionListener); + } + + /** + * This method creates scroll pane that will contain the list of comboBox's + * items inside of it. + * + * @return JScrollPane + */ + protected JScrollPane createScroller() + { + return new JScrollPane(); + } + + /** + * This method configures scroll pane to contain list of comboBox's items + */ + protected void configureScroller() + { + scroller.getViewport().setView(list); + scroller.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); + } + + /** + * This method configures popup menu that will be used to display Scrollpane + * with list of items inside of it. + */ + protected void configurePopup() + { + // FIXME: Need to implement + } + + /* + * This method installs listeners that will listen to changes occuring + * in the combo box. + */ + protected void installComboBoxListeners() + { + // mouse listener that listens to mouse event in combo box + mouseListener = createMouseListener(); + comboBox.addMouseListener(mouseListener); + + // mouse listener that listens to mouse dragging events in the combo box + mouseMotionListener = createMouseMotionListener(); + comboBox.addMouseMotionListener(mouseMotionListener); + + // item listener listenening to selection events in the combo box + itemListener = createItemListener(); + comboBox.addItemListener(itemListener); + + propertyChangeListener = createPropertyChangeListener(); + comboBox.addPropertyChangeListener(propertyChangeListener); + } + + /** + * This method installs listeners that will listen to changes occuring in + * the comb box's data model + * + * @param model data model for the combo box for which to install listeners + */ + protected void installComboBoxModelListeners(ComboBoxModel model) + { + // list data listener to listen for ListDataEvents in combo box. + // This listener is now obsolete and nothing is done here + listDataListener = createListDataListener(); + comboBox.getModel().addListDataListener(listDataListener); + } + + /** + * DOCUMENT ME! + */ + protected void installKeyboardActions() + { + // FIXME: Need to implement + } + + /** + * This method always returns false to indicate that items in the combo box + * list are not focus traversable. + * + * @return false + */ + public boolean isFocusTraversable() + { + return false; + } + + /** + * DOCUMENT ME! + * + * @param direction DOCUMENT ME! + */ + protected void startAutoScrolling(int direction) + { + // FIXME: Need to implement + } + + /** + * DOCUMENT ME! + */ + protected void stopAutoScrolling() + { + // FIXME: Need to implement + } + + /** + * DOCUMENT ME! + */ + protected void autoScrollUp() + { + // FIXME: Need to implement + } + + /** + * DOCUMENT ME! + */ + protected void autoScrollDown() + { + // FIXME: Need to implement + } + + /** + * This method helps to delegate focus to the right component in the + * JComboBox. If the comboBox is editable then focus is sent to + * ComboBoxEditor, otherwise it is delegated to JComboBox. + * + * @param e MouseEvent + */ + protected void delegateFocus(MouseEvent e) + { + // FIXME: Need to implement + } + + /** + * This method displays combo box popup if the popup is not currently shown + * on the screen and hides it if it is currently visible + */ + protected void togglePopup() + { + if (BasicComboPopup.this.isVisible()) + hide(); + else + show(); + } + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + protected MouseEvent convertMouseEvent(MouseEvent e) + { + return null; + } + + /** + * Returns required height of the popup such that number of items visible in + * it are equal to the maximum row count. By default + * comboBox.maximumRowCount=8 + * + * @param maxRowCount number of maximum visible rows in the combo box's + * popup list of items + * + * @return height of the popup required to fit number of items equal to + * JComboBox.maximumRowCount. + */ + protected int getPopupHeightForRowCount(int maxRowCount) + { + int totalHeight = 0; + ListCellRenderer rend = list.getCellRenderer(); + + if (comboBox.getItemCount() < maxRowCount) + maxRowCount = comboBox.getItemCount(); + + for (int i = 0; i < maxRowCount; i++) + { + Component comp = rend.getListCellRendererComponent(list, + list.getModel() + .getElementAt(i), + -1, false, false); + Dimension dim = comp.getPreferredSize(); + totalHeight += dim.height; + } + + return totalHeight; + } + + /** + * DOCUMENT ME! + * + * @param px DOCUMENT ME! + * @param py DOCUMENT ME! + * @param pw DOCUMENT ME! + * @param ph DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + protected Rectangle computePopupBounds(int px, int py, int pw, int ph) + { + return new Rectangle(px, py, pw, ph); + } + + /** + * This method changes the selection in the list to the item over which the + * mouse is currently located. + * + * @param anEvent MouseEvent + * @param shouldScroll DOCUMENT ME! + */ + protected void updateListBoxSelectionForEvent(MouseEvent anEvent, + boolean shouldScroll) + { + // FIXME: Need to implement + } + + /** + * InvocationMouseHandler is a listener that listens to mouse events + * occuring in the combo box. Note that this listener doesn't listen to + * mouse events occuring in the popup portion of the combo box, it only + * listens to main combo box part(area that displays selected item). This + * listener is responsible for showing and hiding popup portion of the + * combo box. + */ + protected class InvocationMouseHandler extends MouseAdapter + { + /** + * Creates a new InvocationMouseHandler object. + */ + protected InvocationMouseHandler() + { + } + + /** + * This method is invoked whenever mouse is being pressed over the main + * part of the combo box. This method will show popup if the popup is + * not shown on the screen right now, and it will hide popup otherwise. + * + * @param e MouseEvent that should be handled + */ + public void mousePressed(MouseEvent e) + { + if (comboBox.isEnabled()) + togglePopup(); + } + + /** + * This method is invoked whenever mouse is released + * + * @param e MouseEvent that should be handled + */ + public void mouseReleased(MouseEvent e) + { + // FIXME: should handle dragging events here, if + // mouse was dragged and released over the list of combobox's items, + // then item over which it was released should be selected. + } + } + + /** + * InvocationMouseMotionListener is a mouse listener that listens to mouse + * dragging events occuring in the combo box. + */ + protected class InvocationMouseMotionHandler extends MouseMotionAdapter + { + /** + * Creates a new InvocationMouseMotionHandler object. + */ + protected InvocationMouseMotionHandler() + { + } + + public void mouseDragged(MouseEvent e) + { + } + } + + /** + * ItemHandler is an item listener that listens to selection event occuring + * in the combo box. FIXME: should specify here what it does when item is + * selected or deselected in the combo box list. + */ + protected class ItemHandler extends Object implements ItemListener + { + /** + * Creates a new ItemHandler object. + */ + protected ItemHandler() + { + } + + /** + * This method responds to the selection events occuring in the combo box. + * + * @param e ItemEvent specifying the combo box's selection + */ + public void itemStateChanged(ItemEvent e) + { + } + } + + /** + * ListMouseHandler is a listener that listens to mouse events occuring in + * the combo box's list of items. This class is responsible for hiding + * popup portion of the combo box if the mouse is released inside the combo + * box's list. + */ + protected class ListMouseHandler extends MouseAdapter + { + protected ListMouseHandler() + { + } + + public void mousePressed(MouseEvent e) + { + } + + public void mouseReleased(MouseEvent anEvent) + { + int index = list.locationToIndex(anEvent.getPoint()); + comboBox.setSelectedIndex(index); + hide(); + } + } + + /** + * ListMouseMotionHandler listens to mouse motion events occuring in the + * combo box's list. This class is responsible for highlighting items in + * the list when mouse is moved over them + */ + protected class ListMouseMotionHandler extends MouseMotionAdapter + { + protected ListMouseMotionHandler() + { + } + + public void mouseMoved(MouseEvent anEvent) + { + // FIXME: Need to implement + // NOTE: the change isn't reflected in data model of the combo box. + // The items are only highlited, but not selected + } + } + + /** + * This class listens to changes occuring in the bound properties of the + * combo box + */ + protected class PropertyChangeHandler extends Object + implements PropertyChangeListener + { + protected PropertyChangeHandler() + { + } + + public void propertyChange(PropertyChangeEvent e) + { + if (e.getPropertyName().equals(JComboBox.RENDERER_CHANGED_PROPERTY)) + { + list.setCellRenderer((ListCellRenderer) e.getNewValue()); + revalidate(); + repaint(); + } + } + } + + // ------ private helper methods -------------------- + + /** + * This method uninstalls listeners installed by the UI + */ + private void uninstallListeners() + { + uninstallListListeners(); + uninstallComboBoxListeners(); + uninstallComboBoxModelListeners(comboBox.getModel()); + } + + /** + * This method uninstalls Listeners registered with combo boxes list of + * items + */ + private void uninstallListListeners() + { + list.removeMouseListener(listMouseListener); + listMouseListener = null; + + list.removeMouseMotionListener(listMouseMotionListener); + listMouseMotionListener = null; + } + + /** + * This method uninstalls listeners listening to combo box associated with + * this popup menu + */ + private void uninstallComboBoxListeners() + { + comboBox.removeMouseListener(mouseListener); + mouseListener = null; + + comboBox.removeMouseMotionListener(mouseMotionListener); + mouseMotionListener = null; + + comboBox.removeItemListener(itemListener); + itemListener = null; + + comboBox.removePropertyChangeListener(propertyChangeListener); + propertyChangeListener = null; + } + + // -------------------------------------------------------------------- + // The following classes are here only for backwards API compatibility + // They aren't used. + // -------------------------------------------------------------------- + + /** + * This class is not used any more. + */ + public class ListDataHandler extends Object implements ListDataListener + { + public ListDataHandler() + { + } + + public void contentsChanged(ListDataEvent e) + { + } + + public void intervalAdded(ListDataEvent e) + { + } + + public void intervalRemoved(ListDataEvent e) + { + } + } + + /** + * This class is not used anymore + */ + protected class ListSelectionHandler extends Object + implements ListSelectionListener + { + protected ListSelectionHandler() + { + } + + public void valueChanged(ListSelectionEvent e) + { + } + } + + /** + * This class is not used anymore + */ + public class InvocationKeyHandler extends KeyAdapter + { + public InvocationKeyHandler() + { + } + + public void keyReleased(KeyEvent e) + { + } + } +} diff --git a/libjava/javax/swing/plaf/basic/BasicFormattedTextFieldUI.java b/libjava/javax/swing/plaf/basic/BasicFormattedTextFieldUI.java new file mode 100644 index 0000000..c61dc40 --- /dev/null +++ b/libjava/javax/swing/plaf/basic/BasicFormattedTextFieldUI.java @@ -0,0 +1,62 @@ +/* BasicFormattedTextFieldUI.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 javax.swing.JComponent; +import javax.swing.plaf.ComponentUI; + +/** + * @since 1.4 + */ +public class BasicFormattedTextFieldUI extends BasicTextFieldUI +{ + public BasicFormattedTextFieldUI() + { + } + + public static ComponentUI createUI(JComponent c) + { + return new BasicFormattedTextFieldUI(); + } + + protected String getPropertyPrefix() + { + return "FormattedTextField"; + } +}
\ No newline at end of file diff --git a/libjava/javax/swing/plaf/basic/BasicPasswordFieldUI.java b/libjava/javax/swing/plaf/basic/BasicPasswordFieldUI.java new file mode 100644 index 0000000..fe1c490 --- /dev/null +++ b/libjava/javax/swing/plaf/basic/BasicPasswordFieldUI.java @@ -0,0 +1,61 @@ +/* BasicPasswordFieldUI.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 javax.swing.JComponent; +import javax.swing.plaf.ComponentUI; +import javax.swing.text.Element; +import javax.swing.text.View; + +public class BasicPasswordFieldUI extends BasicTextFieldUI +{ + public BasicPasswordFieldUI() + { + } + + public static ComponentUI createUI(JComponent c) + { + return new BasicPasswordFieldUI(); + } + + protected String getPropertyPrefix() + { + return "PasswordField"; + } +} diff --git a/libjava/javax/swing/plaf/basic/BasicSpinnerUI.java b/libjava/javax/swing/plaf/basic/BasicSpinnerUI.java new file mode 100644 index 0000000..0f5e761 --- /dev/null +++ b/libjava/javax/swing/plaf/basic/BasicSpinnerUI.java @@ -0,0 +1,572 @@ +/* SpinnerUI.java -- + Copyright (C) 2003 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.swing.plaf.basic; + +import java.awt.Component; +import java.awt.Container; +import java.awt.Dimension; +import java.awt.Insets; +import java.awt.LayoutManager; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JSpinner; +import javax.swing.Timer; +import javax.swing.UIDefaults; +import javax.swing.UIManager; +import javax.swing.plaf.ComponentUI; +import javax.swing.plaf.SpinnerUI; + + +/** + * DOCUMENT ME! + * + * @author Ka-Hing Cheung + * + * @see javax.swing.JSpinner + * @since 1.4 + */ +public class BasicSpinnerUI extends SpinnerUI +{ + /** + * Creates a new <code>ComponentUI</code> for the specified + * <code>JComponent</code> + * + * @param c DOCUMENT ME! + * + * @return a ComponentUI + */ + public static ComponentUI createUI(JComponent c) + { + return new BasicSpinnerUI(); + } + + /** + * Creates an editor component. Really, it just returns + * <code>JSpinner.getEditor()</code> + * + * @return a JComponent as an editor + * + * @see javax.swing.JSpinner#getEditor + */ + protected JComponent createEditor() + { + return spinner.getEditor(); + } + + /** + * Creates a <code>LayoutManager</code> that layouts the sub components. The + * subcomponents are identifies by the constraint "Next", "Previous" and + * "Editor" + * + * @return a LayoutManager + * + * @see java.awt.LayoutManager + */ + protected LayoutManager createLayout() + { + return new DefaultLayoutManager(); + } + + /** + * Creates the "Next" button + * + * @return the next button component + */ + protected Component createNextButton() + { + JButton button = new BasicArrowButton(BasicArrowButton.NORTH); + return button; + } + + /** + * Creates the "Previous" button + * + * @return the previous button component + */ + protected Component createPreviousButton() + { + JButton button = new BasicArrowButton(BasicArrowButton.SOUTH); + return button; + } + + /** + * Creates the <code>PropertyChangeListener</code> that will be attached by + * <code>installListeners</code>. It should watch for the "editor" + * property, when it's changed, replace the old editor with the new one, + * probably by calling <code>replaceEditor</code> + * + * @return a PropertyChangeListener + * + * @see #replaceEditor + */ + protected PropertyChangeListener createPropertyChangeListener() + { + return new PropertyChangeListener() + { + public void propertyChange(PropertyChangeEvent evt) + { + // FIXME: Add check for enabled property change. Need to + // disable the buttons. + if ("editor".equals(evt.getPropertyName())) + BasicSpinnerUI.this.replaceEditor((JComponent) evt.getOldValue(), + (JComponent) evt.getNewValue()); + } + }; + } + + /** + * Called by <code>installUI</code>. This should set various defaults + * obtained from <code>UIManager.getLookAndFeelDefaults</code>, as well as + * set the layout obtained from <code>createLayout</code> + * + * @see #javax.swing.UIManager#getLookAndFeelDefaults + * @see #createLayout + * @see #installUI + */ + protected void installDefaults() + { + /* most of it copied from BasicLabelUI, I don't know what keys are + available, so someone may want to update this. Hence: TODO + */ + UIDefaults defaults = UIManager.getLookAndFeelDefaults(); + /* + spinner.setForeground(defaults.getColor("Spinner.foreground")); + spinner.setBackground(defaults.getColor("Spinner.background")); + spinner.setFont(defaults.getFont("Spinner.font")); + spinner.setBorder(defaults.getBorder("Spinner.border")); + */ + spinner.setLayout(createLayout()); + } + + /* + * Called by <code>installUI</code>, which basically adds the + * <code>PropertyChangeListener</code> created by + * <code>createPropertyChangeListener</code> + * + * @see #createPropertyChangeListener + * @see #installUI + */ + protected void installListeners() + { + spinner.addPropertyChangeListener(listener); + } + + /* + * Install listeners to the next button so that it increments the model + */ + protected void installNextButtonListeners(Component c) + { + c.addMouseListener(new MouseAdapter() + { + public void mousePressed(MouseEvent evt) + { + if (! spinner.isEnabled()) + return; + increment(); + timer.setInitialDelay(500); + timer.start(); + } + + public void mouseReleased(MouseEvent evt) + { + timer.stop(); + } + + void increment() + { + Object next = BasicSpinnerUI.this.spinner.getNextValue(); + if (next != null) + BasicSpinnerUI.this.spinner.getModel().setValue(next); + } + + volatile boolean mouseDown = false; + Timer timer = new Timer(50, + new ActionListener() + { + public void actionPerformed(ActionEvent event) + { + increment(); + } + }); + }); + } + + /* + * Install listeners to the previous button so that it decrements the model + */ + protected void installPreviousButtonListeners(Component c) + { + c.addMouseListener(new MouseAdapter() + { + public void mousePressed(MouseEvent evt) + { + if (! spinner.isEnabled()) + return; + decrement(); + timer.setInitialDelay(500); + timer.start(); + } + + public void mouseReleased(MouseEvent evt) + { + timer.stop(); + } + + void decrement() + { + Object prev = BasicSpinnerUI.this.spinner.getPreviousValue(); + if (prev != null) + BasicSpinnerUI.this.spinner.getModel().setValue(prev); + } + + volatile boolean mouseDown = false; + Timer timer = new Timer(50, + new ActionListener() + { + public void actionPerformed(ActionEvent event) + { + decrement(); + } + }); + }); + } + + /** + * Install this UI to the <code>JComponent</code>, which in reality, is a + * <code>JSpinner</code>. Calls <code>installDefaults</code>, + * <code>installListeners</code>, and also adds the buttons and editor. + * + * @param c DOCUMENT ME! + * + * @see #installDefaults + * @see #installListeners + * @see #createNextButton + * @see #createPreviousButton + * @see #createEditor + */ + public void installUI(JComponent c) + { + super.installUI(c); + + spinner = (JSpinner) c; + + installDefaults(); + installListeners(); + + Component next = createNextButton(); + Component previous = createPreviousButton(); + + installNextButtonListeners(next); + installPreviousButtonListeners(previous); + + c.add(createEditor(), "Editor"); + c.add(next, "Next"); + c.add(previous, "Previous"); + } + + /** + * Replace the old editor with the new one + * + * @param oldEditor the old editor + * @param newEditor the new one to replace with + */ + protected void replaceEditor(JComponent oldEditor, JComponent newEditor) + { + spinner.remove(oldEditor); + spinner.add(newEditor); + } + + /** + * The reverse of <code>installDefaults</code>. Called by + * <code>uninstallUI</code> + */ + protected void uninstallDefaults() + { + spinner.setLayout(null); + } + + /** + * The reverse of <code>installListeners</code>, called by + * <code>uninstallUI</code> + */ + protected void uninstallListeners() + { + spinner.removePropertyChangeListener(listener); + } + + /** + * Called when the current L&F is replaced with another one, should call + * <code>uninstallDefaults</code> and <code>uninstallListeners</code> as + * well as remove the next/previous buttons and the editor + * + * @param c DOCUMENT ME! + */ + public void uninstallUI(JComponent c) + { + super.uninstallUI(c); + + uninstallDefaults(); + uninstallListeners(); + c.removeAll(); + } + + /** The spinner for this UI */ + protected JSpinner spinner; + + /** DOCUMENT ME! */ + private PropertyChangeListener listener = createPropertyChangeListener(); + + /** + * DOCUMENT ME! + */ + private class DefaultLayoutManager implements LayoutManager + { + /** + * DOCUMENT ME! + * + * @param parent DOCUMENT ME! + */ + public void layoutContainer(Container parent) + { + synchronized (parent.getTreeLock()) + { + Insets i = parent.getInsets(); + boolean l2r = parent.getComponentOrientation().isLeftToRight(); + /* + -------------- -------------- + | | n | | n | | + | e | - | or | - | e | + | | p | | p | | + -------------- -------------- + */ + Dimension e = minSize(editor); + Dimension n = minSize(next); + Dimension p = minSize(previous); + Dimension s = spinner.getPreferredSize(); + + int x = l2r ? i.left : i.right; + int y = i.top; + int w = Math.max(p.width, n.width); + int h = Math.max(p.height, n.height); + h = Math.max(h, e.height / 2); + int e_width = s.width - w; + + if (l2r) + { + setBounds(editor, x, y + (s.height - e.height) / 2, e_width, + e.height); + x += e_width; + + setBounds(next, x, y, w, h); + y += h; + + setBounds(previous, x, y, w, h); + } + else + { + setBounds(next, x, y + (s.height - e.height) / 2, w, h); + y += h; + + setBounds(previous, x, y, w, h); + x += w; + y -= h; + + setBounds(editor, x, y, e_width, e.height); + } + } + } + + /** + * DOCUMENT ME! + * + * @param parent DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public Dimension minimumLayoutSize(Container parent) + { + Dimension d = new Dimension(); + + if (editor != null) + { + Dimension tmp = editor.getMinimumSize(); + d.width += tmp.width; + d.height = tmp.height; + } + + int nextWidth = 0; + int previousWidth = 0; + int otherHeight = 0; + + if (next != null) + { + Dimension tmp = next.getMinimumSize(); + nextWidth = tmp.width; + otherHeight += tmp.height; + } + if (previous != null) + { + Dimension tmp = previous.getMinimumSize(); + previousWidth = tmp.width; + otherHeight += tmp.height; + } + + d.height = Math.max(d.height, otherHeight); + d.width += Math.max(nextWidth, previousWidth); + + return d; + } + + /** + * DOCUMENT ME! + * + * @param parent DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public Dimension preferredLayoutSize(Container parent) + { + Dimension d = new Dimension(); + + if (editor != null) + { + Dimension tmp = editor.getPreferredSize(); + d.width += Math.max(tmp.width, 40); + d.height = tmp.height; + } + + int nextWidth = 0; + int previousWidth = 0; + int otherHeight = 0; + + if (next != null) + { + Dimension tmp = next.getPreferredSize(); + nextWidth = tmp.width; + otherHeight += tmp.height; + } + if (previous != null) + { + Dimension tmp = previous.getPreferredSize(); + previousWidth = tmp.width; + otherHeight += tmp.height; + } + + d.height = Math.max(d.height, otherHeight); + d.width += Math.max(nextWidth, previousWidth); + + return d; + } + + /** + * DOCUMENT ME! + * + * @param child DOCUMENT ME! + */ + public void removeLayoutComponent(Component child) + { + if (child == editor) + editor = null; + else if (child == next) + next = null; + else if (previous == child) + previous = null; + } + + /** + * DOCUMENT ME! + * + * @param name DOCUMENT ME! + * @param child DOCUMENT ME! + */ + public void addLayoutComponent(String name, Component child) + { + if ("Editor".equals(name)) + editor = child; + else if ("Next".equals(name)) + next = child; + else if ("Previous".equals(name)) + previous = child; + } + + /** + * DOCUMENT ME! + * + * @param c DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + private Dimension minSize(Component c) + { + if (c == null) + return new Dimension(); + else + return c.getMinimumSize(); + } + + /** + * DOCUMENT ME! + * + * @param c DOCUMENT ME! + * @param x DOCUMENT ME! + * @param y DOCUMENT ME! + * @param w DOCUMENT ME! + * @param h DOCUMENT ME! + */ + private void setBounds(Component c, int x, int y, int w, int h) + { + if (c != null) + c.setBounds(x, y, w, h); + } + + /** DOCUMENT ME! */ + private Component editor; + + /** DOCUMENT ME! */ + private Component next; + + /** DOCUMENT ME! */ + private Component previous; + } +} diff --git a/libjava/javax/swing/plaf/basic/BasicTableHeaderUI.java b/libjava/javax/swing/plaf/basic/BasicTableHeaderUI.java new file mode 100644 index 0000000..c55c940 --- /dev/null +++ b/libjava/javax/swing/plaf/basic/BasicTableHeaderUI.java @@ -0,0 +1,301 @@ +/* BasicTableHeaderUI.java + Copyright (C) 2004 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.swing.plaf.basic; + +import java.awt.Component; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.Rectangle; +import java.awt.event.MouseEvent; +import javax.swing.CellRendererPane; +import javax.swing.JComponent; +import javax.swing.UIDefaults; +import javax.swing.UIManager; +import javax.swing.border.Border; +import javax.swing.event.MouseInputListener; +import javax.swing.plaf.ComponentUI; +import javax.swing.plaf.TableHeaderUI; +import javax.swing.table.JTableHeader; +import javax.swing.table.TableCellRenderer; +import javax.swing.table.TableColumn; +import javax.swing.table.TableColumnModel; + + +public class BasicTableHeaderUI + extends TableHeaderUI +{ + + public static ComponentUI createUI(JComponent h) + { + return new BasicTableHeaderUI(); + } + + protected JTableHeader header; + protected MouseInputListener mouseInputListener; + protected CellRendererPane rendererPane; + protected Border cellBorder; + + class MouseInputHandler + implements MouseInputListener + { + public void mouseClicked(MouseEvent e) {} + public void mouseDragged(MouseEvent e) {} + public void mouseEntered(MouseEvent e) {} + public void mouseExited(MouseEvent e) {} + public void mouseMoved(MouseEvent e) {} + public void mousePressed(MouseEvent e) {} + public void mouseReleased(MouseEvent e) {} + } + + protected MouseInputListener createMouseInputListener() + { + return new MouseInputHandler(); + } + + public BasicTableHeaderUI() + { + mouseInputListener = createMouseInputListener(); + } + + protected void installDefaults() + { + UIDefaults defaults = UIManager.getLookAndFeelDefaults(); + header.setBackground(defaults.getColor("TableHeader.background")); + header.setForeground(defaults.getColor("TableHeader.foreground")); + header.setFont(defaults.getFont("TableHeader.font")); + cellBorder = defaults.getBorder("TableHeader.cellBorder"); + } + + protected void installKeyboardActions() + { + } + + protected void installListeners() + { + header.addMouseListener(mouseInputListener); + } + + public void installUI(JComponent c) + { + header = (JTableHeader) c; + installDefaults(); + installKeyboardActions(); + installListeners(); + } + + protected void uninstallDefaults() + { + header.setBackground(null); + header.setForeground(null); + header.setFont(null); + } + + protected void uninstallKeyboardActions() + { + } + + protected void uninstallListeners() + { + header.removeMouseListener(mouseInputListener); + } + + public void uninstallUI(JComponent c) + { + uninstallListeners(); + uninstallKeyboardActions(); + uninstallDefaults(); + } + + public void paint(Graphics gfx, JComponent c) + { + TableColumnModel cmod = header.getColumnModel(); + int ncols = cmod.getColumnCount(); + if (ncols == 0) + return; + + Rectangle clip = gfx.getClipBounds(); + TableCellRenderer defaultRend = header.getDefaultRenderer(); + + for (int i = 0; i < ncols; ++i) + { + Rectangle bounds = header.getHeaderRect(i); + if (bounds.intersects(clip)) + { + TableColumn col = cmod.getColumn(i); + TableCellRenderer rend = col.getHeaderRenderer(); + if (rend == null) + rend = defaultRend; + Object val = col.getHeaderValue(); + Component comp = rend.getTableCellRendererComponent(header.getTable(), + val, + false, // isSelected + false, // isFocused + -1, i); + comp.setFont(header.getFont()); + comp.setBackground(header.getBackground()); + comp.setForeground(header.getForeground()); + if (comp instanceof JComponent) + ((JComponent)comp).setBorder(cellBorder); + gfx.translate(bounds.x, bounds.y); + comp.setSize(bounds.width, bounds.height); + comp.setLocation(0,0); + comp.paint(gfx); + gfx.translate(-bounds.x, -bounds.y); + } + } + + } + + public Dimension getMaximumSize(JComponent c) + { + TableColumnModel cmod = header.getColumnModel(); + TableCellRenderer defaultRend = header.getDefaultRenderer(); + int ncols = cmod.getColumnCount(); + int spacing = 0; + Dimension ret = getPreferredSize(c); + + if (header.getTable() != null + && header.getTable().getInterCellSpacing() != null) + spacing = header.getTable().getInterCellSpacing().width; + + ret.width = 0; + for (int i = 0; i < ncols; ++i) + { + TableColumn col = cmod.getColumn(i); + TableCellRenderer rend = col.getHeaderRenderer(); + if (rend == null) + rend = defaultRend; + Object val = col.getHeaderValue(); + Component comp = rend.getTableCellRendererComponent(header.getTable(), + val, + false, // isSelected + false, // isFocused + -1, i); + comp.setFont(header.getFont()); + comp.setBackground(header.getBackground()); + comp.setForeground(header.getForeground()); + if (comp instanceof JComponent) + ((JComponent)comp).setBorder(cellBorder); + + Dimension d = comp.getMaximumSize(); + ret.width += col.getMaxWidth(); + ret.height = Math.max(ret.height, d.height); + ret.width += spacing; + } + return ret; + } + + public Dimension getMinimumSize(JComponent c) + { + TableColumnModel cmod = header.getColumnModel(); + TableCellRenderer defaultRend = header.getDefaultRenderer(); + int ncols = cmod.getColumnCount(); + int spacing = 0; + Dimension ret = getPreferredSize(c); + + if (header.getTable() != null + && header.getTable().getInterCellSpacing() != null) + spacing = header.getTable().getInterCellSpacing().width; + + ret.width = 0; + for (int i = 0; i < ncols; ++i) + { + TableColumn col = cmod.getColumn(i); + TableCellRenderer rend = col.getHeaderRenderer(); + if (rend == null) + rend = defaultRend; + Object val = col.getHeaderValue(); + Component comp = rend.getTableCellRendererComponent(header.getTable(), + val, + false, // isSelected + false, // isFocused + -1, i); + comp.setFont(header.getFont()); + comp.setBackground(header.getBackground()); + comp.setForeground(header.getForeground()); + if (comp instanceof JComponent) + ((JComponent)comp).setBorder(cellBorder); + + Dimension d = comp.getMinimumSize(); + ret.width += col.getMinWidth(); + ret.width += spacing; + ret.height = Math.max(ret.height, d.height); + } + return ret; + } + + public Dimension getPreferredSize(JComponent c) + { + TableColumnModel cmod = header.getColumnModel(); + TableCellRenderer defaultRend = header.getDefaultRenderer(); + int ncols = cmod.getColumnCount(); + Dimension ret = new Dimension(0,0); + int spacing = 0; + + if (header.getTable() != null + && header.getTable().getInterCellSpacing() != null) + spacing = header.getTable().getInterCellSpacing().width; + + for (int i = 0; i < ncols; ++i) + { + TableColumn col = cmod.getColumn(i); + TableCellRenderer rend = col.getHeaderRenderer(); + if (rend == null) + rend = defaultRend; + Object val = col.getHeaderValue(); + Component comp = rend.getTableCellRendererComponent(header.getTable(), + val, + false, // isSelected + false, // isFocused + -1, i); + comp.setFont(header.getFont()); + comp.setBackground(header.getBackground()); + comp.setForeground(header.getForeground()); + if (comp instanceof JComponent) + ((JComponent)comp).setBorder(cellBorder); + + Dimension d = comp.getPreferredSize(); + ret.width += d.width; + ret.width += spacing; + ret.height = Math.max(d.height, ret.height); + } + return ret; + } + + +} diff --git a/libjava/javax/swing/plaf/basic/BasicTableUI.java b/libjava/javax/swing/plaf/basic/BasicTableUI.java new file mode 100644 index 0000000..5fa8fb7 --- /dev/null +++ b/libjava/javax/swing/plaf/basic/BasicTableUI.java @@ -0,0 +1,374 @@ +/* BasicTableUI.java + Copyright (C) 2004 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.swing.plaf.basic; + +import java.awt.Color; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; +import java.awt.event.MouseEvent; +import javax.swing.CellRendererPane; +import javax.swing.JComponent; +import javax.swing.JTable; +import javax.swing.ListSelectionModel; +import javax.swing.event.MouseInputListener; +import javax.swing.plaf.ComponentUI; +import javax.swing.plaf.TableUI; +import javax.swing.table.TableCellRenderer; +import javax.swing.table.TableColumn; +import javax.swing.table.TableColumnModel; +import javax.swing.UIDefaults; +import javax.swing.UIManager; + + +public class BasicTableUI + extends TableUI +{ + + public static ComponentUI createUI(JComponent comp) + { + return new BasicTableUI(); + } + + protected FocusListener focusListener; + protected KeyListener keyListener; + protected MouseInputListener mouseInputListener; + protected CellRendererPane rendererPane; + protected JTable table; + + class FocusHandler implements FocusListener + { + public void focusGained(FocusEvent e) + { + } + public void focusLost(FocusEvent e) + { + } + } + + class KeyHandler implements KeyListener + { + public void keyPressed(KeyEvent e) + { + } + public void keyReleased(KeyEvent e) + { + } + public void keyTyped(KeyEvent e) + { + } + } + + class MouseInputHandler implements MouseInputListener + { + Point begin, curr; + + private int getRowForPoint(Point p) + { + int y0 = table.getLocation().y; + int nrows = table.getRowCount(); + Dimension gap = table.getInterCellSpacing(); + int height = table.getRowHeight() + (gap == null ? 0 : gap.height); + int y = p.y; + for (int i = 0; i < nrows; ++i) + { + if (0 <= y && y < height) + return i; + y -= height; + } + return -1; + } + + private int getColForPoint(Point p) + { + int x0 = table.getLocation().x; + int ncols = table.getColumnCount(); + Dimension gap = table.getInterCellSpacing(); + TableColumnModel cols = table.getColumnModel(); + int x = p.x; + for (int i = 0; i < ncols; ++i) + { + int width = cols.getColumn(i).getWidth() + (gap == null ? 0 : gap.width); + if (0 <= x && x < width) + return i; + x -= width; + } + return -1; + } + + private void updateSelection() + { + if (table.getRowSelectionAllowed()) + { + int lo_row = getRowForPoint(begin); + int hi_row = getRowForPoint(curr); + ListSelectionModel rowModel = table.getSelectionModel(); + if (lo_row != -1 && hi_row != -1) + rowModel.setSelectionInterval(lo_row, hi_row); + } + + if (table.getColumnSelectionAllowed()) + { + int lo_col = getColForPoint(begin); + int hi_col = getColForPoint(curr); + ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); + if (lo_col != -1 && hi_col != -1) + colModel.setSelectionInterval(lo_col, hi_col); + } + } + + public void mouseClicked(MouseEvent e) + { + } + public void mouseDragged(MouseEvent e) + { + curr = new Point(e.getX(), e.getY()); + updateSelection(); + } + public void mouseEntered(MouseEvent e) + { + } + public void mouseExited(MouseEvent e) + { + } + public void mouseMoved(MouseEvent e) + { + } + public void mousePressed(MouseEvent e) + { + begin = new Point(e.getX(), e.getY()); + curr = new Point(e.getX(), e.getY()); + updateSelection(); + } + public void mouseReleased(MouseEvent e) + { + begin = null; + curr = null; + } + } + + protected FocusListener createFocusListener() + { + return new FocusHandler(); + } + protected KeyListener createKeyListener() + { + return new KeyHandler(); + } + protected MouseInputListener createMouseInputListener() + { + return new MouseInputHandler(); + } + + public Dimension getMaximumSize(JComponent comp) + { + return getPreferredSize(comp); + } + + public Dimension getMinimumSize(JComponent comp) + { + return getPreferredSize(comp); + } + + public Dimension getPreferredSize(JComponent comp) + { + int width = table.getColumnModel().getTotalColumnWidth(); + int height = table.getRowCount() * table.getRowHeight(); + return new Dimension(width, height); + } + + protected void installDefaults() + { + UIDefaults defaults = UIManager.getLookAndFeelDefaults(); + table.setFont(defaults.getFont("Table.font")); + table.setGridColor(defaults.getColor("Table.gridColor")); + table.setForeground(defaults.getColor("Table.foreground")); + table.setBackground(defaults.getColor("Table.background")); + table.setSelectionForeground(defaults.getColor("Table.selectionForeground")); + table.setSelectionBackground(defaults.getColor("Table.selectionBackground")); + table.setOpaque(true); + } + protected void installKeyboardActions() + { + } + + protected void installListeners() + { + table.addFocusListener(focusListener); + table.addKeyListener(keyListener); + table.addMouseListener(mouseInputListener); + } + + protected void uninstallDefaults() + { + table.setFont(null); + table.setGridColor(null); + table.setForeground(null); + table.setBackground(null); + table.setSelectionForeground(null); + table.setSelectionBackground(null); + } + + protected void uninstallKeyboardActions() + { + } + + protected void uninstallListeners() + { + table.removeFocusListener(focusListener); + table.removeKeyListener(keyListener); + table.removeMouseListener(mouseInputListener); + } + + public void installUI(JComponent comp) + { + table = (JTable)comp; + focusListener = createFocusListener(); + keyListener = createKeyListener(); + mouseInputListener = createMouseInputListener(); + installDefaults(); + installKeyboardActions(); + installListeners(); + } + + public void uninstallUI(JComponent c) + { + uninstallListeners(); + uninstallKeyboardActions(); + uninstallDefaults(); + } + + public void paint(Graphics gfx, JComponent ignored) + { + int ncols = table.getColumnCount(); + int nrows = table.getRowCount(); + if (nrows == 0 || ncols == 0) + return; + + Rectangle clip = gfx.getClipBounds(); + TableColumnModel cols = table.getColumnModel(); + + int height = table.getRowHeight(); + int x0 = 0, y0 = 0; + int x = x0; + int y = y0; + + Dimension gap = table.getInterCellSpacing(); + int ymax = clip.y + clip.height; + int xmax = clip.x + clip.width; + + // paint the cell contents + for (int c = 0; c < ncols && x < xmax; ++c) + { + y = y0; + TableColumn col = cols.getColumn(c); + int width = col.getWidth(); + int modelCol = col.getModelIndex(); + + for (int r = 0; r < nrows && y < ymax; ++r) + { + Rectangle bounds = new Rectangle(x, y, width, height); + if (bounds.intersects(clip)) + { + TableCellRenderer rend = table.getCellRenderer(r, c); + Component comp = table.prepareRenderer(rend, r, c); + gfx.translate(x, y); + comp.setBounds(new Rectangle(0, 0, width, height)); + comp.paint(gfx); + gfx.translate(-x, -y); + } + y += height; + if (gap != null) + y += gap.height; + } + x += width; + if (gap != null) + x += gap.width; + } + + // tighten up the x and y max bounds + ymax = y; + xmax = x; + + Color grid = table.getGridColor(); + + // paint vertical grid lines + if (grid != null && table.getShowVerticalLines()) + { + x = x0; + Color save = gfx.getColor(); + gfx.setColor(grid); + boolean paintedLine = false; + for (int c = 0; c < ncols && x < xmax; ++c) + { + x += cols.getColumn(c).getWidth();; + if (gap != null) + x += gap.width; + gfx.drawLine(x, y0, x, ymax); + paintedLine = true; + } + gfx.setColor(save); + } + + // paint horizontal grid lines + if (grid != null && table.getShowHorizontalLines()) + { + y = y0; + Color save = gfx.getColor(); + gfx.setColor(grid); + boolean paintedLine = false; + for (int r = 0; r < nrows && y < ymax; ++r) + { + y += height; + if (gap != null) + y += gap.height; + gfx.drawLine(x0, y, xmax, y); + paintedLine = true; + } + gfx.setColor(save); + } + + } + +} diff --git a/libjava/javax/swing/plaf/basic/BasicTextAreaUI.java b/libjava/javax/swing/plaf/basic/BasicTextAreaUI.java new file mode 100644 index 0000000..f1714c2 --- /dev/null +++ b/libjava/javax/swing/plaf/basic/BasicTextAreaUI.java @@ -0,0 +1,69 @@ +/* BasicTextAreaUI.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.plaf.ComponentUI; +import javax.swing.text.Element; +import javax.swing.text.PlainView; +import javax.swing.text.View; + +public class BasicTextAreaUI extends BasicTextUI +{ + public static ComponentUI createUI(JComponent comp) + { + return new BasicTextAreaUI(); + } + + public BasicTextAreaUI() + { + } + + public View create(Element elem) + { + return new PlainView(elem); + } + + protected String getPropertyPrefix() + { + return "TextArea"; + } +} diff --git a/libjava/javax/swing/plaf/basic/BasicToolTipUI.java b/libjava/javax/swing/plaf/basic/BasicToolTipUI.java new file mode 100644 index 0000000..3b5941f --- /dev/null +++ b/libjava/javax/swing/plaf/basic/BasicToolTipUI.java @@ -0,0 +1,287 @@ +/* BasicToolTipUI.java -- + Copyright (C) 2004 Free Software Foundation, Inc. + + This file is part of GNU Classpath. + + GNU Classpath is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + GNU Classpath is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNU Classpath; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. + + Linking this library statically or dynamically with other modules is + making a combined work based on this library. Thus, the terms and + conditions of the GNU General Public License cover the whole + combination. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent + modules, and to copy and distribute the resulting executable under + terms of your choice, provided that you also meet, for each linked + independent module, the terms and conditions of the license of that + module. An independent module is a module which is not derived from + or based on this library. If you modify this library, you may extend + this exception to your version of the library, but you are not + obligated to do so. If you do not wish to do so, delete this + exception statement from your version. */ + +package javax.swing.plaf.basic; + +import java.awt.Color; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.FontMetrics; +import java.awt.Graphics; +import java.awt.Insets; +import java.awt.Rectangle; +import javax.swing.JComponent; +import javax.swing.JToolTip; +import javax.swing.SwingConstants; +import javax.swing.SwingUtilities; +import javax.swing.UIDefaults; +import javax.swing.UIManager; +import javax.swing.border.Border; +import javax.swing.plaf.ComponentUI; +import javax.swing.plaf.ToolTipUI; + + +/** + * This is the Basic Look and Feel UI class for JToolTip. + */ +public class BasicToolTipUI extends ToolTipUI +{ + /** The default Border around the JToolTip. */ + private static Border defaultBorder = new Border() + { + // FIXME: This needs to go into Basic Look and Feel + // defaults. + + /** + * This method returns the border insets. + * + * @param c The Component to find Border insets for. + * + * @return The Border insets. + */ + public Insets getBorderInsets(Component c) + { + return new Insets(4, 4, 4, 4); + } + + /** + * This method returns whether the border is opaque. + * + * @return Whether the border is opaque. + */ + public boolean isBorderOpaque() + { + return false; + } + + /** + * This method paints the border. + * + * @param c The Component to paint this border around. + * @param g The Graphics object to paint with. + * @param x The x coordinate to start painting at. + * @param y The y coordinate to start painting at. + * @param w The width of the Component. + * @param y The height of the Component. + */ + public void paintBorder(Component c, Graphics g, int x, int y, int w, + int h) + { + Color saved = g.getColor(); + g.setColor(Color.BLACK); + + g.drawRect(0, 0, w - 1, h - 1); + + g.setColor(saved); + } + }; + + /** The shared instance of BasicToolTipUI used for all ToolTips. */ + private static BasicToolTipUI shared; + + /** + * Creates a new BasicToolTipUI object. + */ + public BasicToolTipUI() + { + super(); + } + + /** + * This method creates a new BasicToolTip UI for the given + * JComponent. + * + * @param c The JComponent to create a UI for. + * + * @return A BasicToolTipUI that can be used by the given JComponent. + */ + public static ComponentUI createUI(JComponent c) + { + if (shared == null) + shared = new BasicToolTipUI(); + return shared; + } + + /** + * This method returns the msximum size of the given JComponent. + * + * @param c The JComponent to find a maximum size for. + * + * @return The maximum size. + */ + public Dimension getMaximumSize(JComponent c) + { + return getPreferredSize(c); + } + + /** + * This method returns the minimum size of the given JComponent. + * + * @param c The JComponent to find a minimum size for. + * + * @return The minimum size. + */ + public Dimension getMinimumSize(JComponent c) + { + return getPreferredSize(c); + } + + /** + * This method returns the preferred size of the given JComponent. + * + * @param c The JComponent to find a preferred size for. + * + * @return The preferred size. + */ + public Dimension getPreferredSize(JComponent c) + { + JToolTip tip = (JToolTip) c; + Rectangle vr = new Rectangle(); + Rectangle ir = new Rectangle(); + Rectangle tr = new Rectangle(); + Insets insets = tip.getInsets(); + FontMetrics fm = tip.getToolkit().getFontMetrics(tip.getFont()); + SwingUtilities.layoutCompoundLabel(tip, fm, tip.getTipText(), null, + SwingConstants.CENTER, + SwingConstants.CENTER, + SwingConstants.CENTER, + SwingConstants.CENTER, vr, ir, tr, 0); + return new Dimension(insets.left + tr.width + insets.right, + insets.top + tr.height + insets.bottom); + } + + /** + * This method installs the defaults for the given JComponent. + * + * @param c The JComponent to install defaults for. + */ + protected void installDefaults(JComponent c) + { + UIDefaults defaults = UIManager.getLookAndFeelDefaults(); + c.setBackground(defaults.getColor("ToolTip.background")); + c.setForeground(defaults.getColor("ToolTip.foreground")); + c.setFont(defaults.getFont("ToolTip.font")); + c.setBorder(defaultBorder); + } + + /** + * This method installs the listeners for the given JComponent. + * + * @param c The JComponent to install listeners for. + */ + protected void installListeners(JComponent c) + { + } + + /** + * This method installs the UI for the given JComponent. + * + * @param c The JComponent to install the UI for. + */ + public void installUI(JComponent c) + { + c.setOpaque(true); + installDefaults(c); + installListeners(c); + } + + /** + * This method paints the given JComponent with the given Graphics object. + * + * @param g The Graphics object to paint with. + * @param c The JComponent to paint. + */ + public void paint(Graphics g, JComponent c) + { + JToolTip tip = (JToolTip) c; + + String text = tip.getTipText(); + if (text == null) + return; + + Rectangle vr = new Rectangle(); + vr = SwingUtilities.calculateInnerArea(tip, vr); + Rectangle ir = new Rectangle(); + Rectangle tr = new Rectangle(); + FontMetrics fm = tip.getToolkit().getFontMetrics(tip.getFont()); + SwingUtilities.layoutCompoundLabel(tip, fm, tip.getTipText(), null, + SwingConstants.CENTER, + SwingConstants.CENTER, + SwingConstants.CENTER, + SwingConstants.CENTER, vr, ir, tr, 0); + + Color saved = g.getColor(); + g.setColor(Color.BLACK); + + g.drawString(text, vr.x, vr.y + fm.getAscent()); + + g.setColor(saved); + } + + /** + * This method uninstalls the defaults for the given JComponent. + * + * @param c The JComponent to uninstall defaults for. + */ + protected void uninstallDefaults(JComponent c) + { + c.setForeground(null); + c.setBackground(null); + c.setFont(null); + c.setBorder(null); + } + + /** + * This method uninstalls listeners for the given JComponent. + * + * @param c The JComponent to uninstall listeners for. + */ + protected void uninstallListeners(JComponent c) + { + } + + /** + * This method uninstalls the UI for the given JComponent. + * + * @param c The JComponent to uninstall. + */ + public void uninstallUI(JComponent c) + { + uninstallDefaults(c); + uninstallListeners(c); + } +} diff --git a/libjava/javax/swing/plaf/basic/ComboPopup.java b/libjava/javax/swing/plaf/basic/ComboPopup.java new file mode 100644 index 0000000..d4ef1f2 --- /dev/null +++ b/libjava/javax/swing/plaf/basic/ComboPopup.java @@ -0,0 +1,103 @@ +/* ComboPopup.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.event.KeyListener; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.awt.event.MouseMotionListener; +import javax.swing.JList; + + +public interface ComboPopup +{ + /** + * This method display popup menu containing list of JComboBox's items to + * the screen + */ + void show(); + + /** + * This method hides popup menu with list of JComboBox's item from the + * screen + */ + void hide(); + + /** + * Retursn true if popup menu with JComboBOx's item is currently visible on + * the screen and false otherwise + * + * @return true if JComboBox's popup menu with list of items is currently + * visible on the screen and false otherwise. + */ + boolean isVisible(); + + /** + * Return JList that is used to draw cells of the JComboBox. + * + * @return JList that is used to draw cells of the JcomboBox + */ + JList getList(); + + /** + * This method returns MouseListener that listen's to mouse events occuring + * in the combo box + * + * @return MouseListenere + */ + MouseListener getMouseListener(); + + /** + * This method returns MouseListener that listen's to mouse events occuring + * in the combo box. + * + * @return MouseMotionListener + */ + MouseMotionListener getMouseMotionListener(); + + /** + * This method returns KeyListener that listen's to key events occuring in + * the combo box. + * + * @return KeyListener + */ + KeyListener getKeyListener(); + + /* This method removes any listeners that were installed */ + void uninstallingUI(); +} |