2002-08-09 04:26:17 +00:00
|
|
|
/* JLayeredPane.java --
|
|
|
|
Copyright (C) 2002 Free Software Foundation, Inc.
|
|
|
|
|
2004-01-06 18:02:23 +00:00
|
|
|
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.
|
|
|
|
*/
|
2002-08-09 04:26:17 +00:00
|
|
|
|
AbstractAction.java, [...]: New versions from classpath.
2003-06-11 Michael Koch <konqueror@gmx.de>
* javax/swing/AbstractAction.java,
javax/swing/AbstractButton.java,
javax/swing/AbstractCellEditor.java,
javax/swing/AbstractListModel.java,
javax/swing/BorderFactory.java,
javax/swing/Box.java,
javax/swing/BoxLayout.java,
javax/swing/ButtonGroup.java,
javax/swing/DefaultButtonModel.java,
javax/swing/DefaultListModel.java,
javax/swing/DefaultListSelectionModel.java,
javax/swing/FocusManager.java,
javax/swing/ImageIcon.java,
javax/swing/InputMap.java,
javax/swing/JApplet.java,
javax/swing/JButton.java,
javax/swing/JCheckBox.java,
javax/swing/JCheckBoxMenuItem.java,
javax/swing/JColorChooser.java,
javax/swing/JComboBox.java,
javax/swing/JComponent.java,
javax/swing/JDesktopPane.java,
javax/swing/JDialog.java,
javax/swing/JEditorPane.java,
javax/swing/JFileChooser.java,
javax/swing/JFormattedTextField.java,
javax/swing/JFrame.java,
javax/swing/JLabel.java,
javax/swing/JLayeredPane.java,
javax/swing/JList.java,
javax/swing/JMenuBar.java,
javax/swing/JMenuItem.java,
javax/swing/JOptionPane.java,
javax/swing/JPanel.java,
javax/swing/JPasswordField.java,
javax/swing/JPopupMenu.java,
javax/swing/JProgressBar.java,
javax/swing/JRadioButton.java,
javax/swing/JRadioButtonMenuItem.java,
javax/swing/JRootPane.java,
javax/swing/JScrollBar.java,
javax/swing/JScrollPane.java,
javax/swing/JSeparator.java,
javax/swing/JSlider.java,
javax/swing/JTabbedPane.java,
javax/swing/JTable.java,
javax/swing/JTextField.java,
javax/swing/JToggleButton.java,
javax/swing/JToolBar.java,
javax/swing/JToolTip.java,
javax/swing/JTree.java,
javax/swing/JViewport.java,
javax/swing/JWindow.java,
javax/swing/KeyStroke.java,
javax/swing/ListSelectionModel.java,
javax/swing/LookAndFeel.java,
javax/swing/RepaintManager.java,
javax/swing/ScrollPaneLayout.java,
javax/swing/SizeRequirements.java,
javax/swing/SwingConstants.java,
javax/swing/Timer.java,
javax/swing/UIDefaults.java,
javax/swing/UIManager.java,
javax/swing/border/AbstractBorder.java,
javax/swing/border/CompoundBorder.java,
javax/swing/colorchooser/AbstractColorChooserPanel.java,
javax/swing/colorchooser/ColorChooserComponentFactory.java,
javax/swing/colorchooser/ColorSelectionModel.java,
javax/swing/colorchooser/DefaultColorSelectionModel.java,
javax/swing/event/AncestorEvent.java,
javax/swing/event/HyperlinkEvent.java,
javax/swing/event/InternalFrameAdapter.java,
javax/swing/event/InternalFrameEvent.java,
javax/swing/event/ListDataEvent.java,
javax/swing/event/MouseInputAdapter.java,
javax/swing/event/SwingPropertyChangeSupport.java,
javax/swing/event/TableModelEvent.java,
javax/swing/event/TreeWillExpandListener.java,
javax/swing/event/UndoableEditEvent.java,
javax/swing/filechooser/FileFilter.java,
javax/swing/filechooser/FileSystemView.java,
javax/swing/filechooser/FileView.java,
javax/swing/plaf/BorderUIResource.java,
javax/swing/plaf/basic/BasicDefaults.java,
javax/swing/table/AbstractTableModel.java,
javax/swing/table/DefaultTableCellRenderer.java,
javax/swing/table/DefaultTableColumnModel.java,
javax/swing/table/DefaultTableModel.java,
javax/swing/table/TableColumn.java,
javax/swing/text/JTextComponent.java,
javax/swing/tree/AbstractLayoutCache.java,
javax/swing/tree/DefaultMutableTreeNode.java,
javax/swing/tree/DefaultTreeCellEditor.java,
javax/swing/tree/DefaultTreeCellRenderer.java,
javax/swing/tree/DefaultTreeModel.java,
javax/swing/tree/DefaultTreeSelectionModel.java,
javax/swing/tree/FixedHeightLayoutCache.java,
javax/swing/tree/TreeCellEditor.java,
javax/swing/tree/TreeModel.java,
javax/swing/tree/TreeNode.java,
javax/swing/tree/TreePath.java,
javax/swing/tree/TreeSelectionModel.java,
javax/swing/tree/VariableHeightLayoutCache.java,
javax/swing/undo/AbstractUndoableEdit.java,
javax/swing/undo/CompoundEdit.java,
javax/swing/undo/StateEdit.java,
javax/swing/undo/UndoManager.java,
javax/swing/undo/UndoableEditSupport.java:
New versions from classpath.
* javax/swing/table/JTableHeader.java:
New file from classpath.
* Makefile.am
(java_awt_sources): Added javax/swing/table/JTableHeader.java.
* Makefile.in: Regenerated.
From-SVN: r67769
2003-06-11 13:20:41 +00:00
|
|
|
|
2002-08-09 04:26:17 +00:00
|
|
|
package javax.swing;
|
|
|
|
|
2003-11-22 00:03:35 +00:00
|
|
|
import java.awt.Component;
|
|
|
|
import java.util.*;
|
AbstractAction.java, [...]: New versions from classpath.
2003-06-11 Michael Koch <konqueror@gmx.de>
* javax/swing/AbstractAction.java,
javax/swing/AbstractButton.java,
javax/swing/AbstractCellEditor.java,
javax/swing/AbstractListModel.java,
javax/swing/BorderFactory.java,
javax/swing/Box.java,
javax/swing/BoxLayout.java,
javax/swing/ButtonGroup.java,
javax/swing/DefaultButtonModel.java,
javax/swing/DefaultListModel.java,
javax/swing/DefaultListSelectionModel.java,
javax/swing/FocusManager.java,
javax/swing/ImageIcon.java,
javax/swing/InputMap.java,
javax/swing/JApplet.java,
javax/swing/JButton.java,
javax/swing/JCheckBox.java,
javax/swing/JCheckBoxMenuItem.java,
javax/swing/JColorChooser.java,
javax/swing/JComboBox.java,
javax/swing/JComponent.java,
javax/swing/JDesktopPane.java,
javax/swing/JDialog.java,
javax/swing/JEditorPane.java,
javax/swing/JFileChooser.java,
javax/swing/JFormattedTextField.java,
javax/swing/JFrame.java,
javax/swing/JLabel.java,
javax/swing/JLayeredPane.java,
javax/swing/JList.java,
javax/swing/JMenuBar.java,
javax/swing/JMenuItem.java,
javax/swing/JOptionPane.java,
javax/swing/JPanel.java,
javax/swing/JPasswordField.java,
javax/swing/JPopupMenu.java,
javax/swing/JProgressBar.java,
javax/swing/JRadioButton.java,
javax/swing/JRadioButtonMenuItem.java,
javax/swing/JRootPane.java,
javax/swing/JScrollBar.java,
javax/swing/JScrollPane.java,
javax/swing/JSeparator.java,
javax/swing/JSlider.java,
javax/swing/JTabbedPane.java,
javax/swing/JTable.java,
javax/swing/JTextField.java,
javax/swing/JToggleButton.java,
javax/swing/JToolBar.java,
javax/swing/JToolTip.java,
javax/swing/JTree.java,
javax/swing/JViewport.java,
javax/swing/JWindow.java,
javax/swing/KeyStroke.java,
javax/swing/ListSelectionModel.java,
javax/swing/LookAndFeel.java,
javax/swing/RepaintManager.java,
javax/swing/ScrollPaneLayout.java,
javax/swing/SizeRequirements.java,
javax/swing/SwingConstants.java,
javax/swing/Timer.java,
javax/swing/UIDefaults.java,
javax/swing/UIManager.java,
javax/swing/border/AbstractBorder.java,
javax/swing/border/CompoundBorder.java,
javax/swing/colorchooser/AbstractColorChooserPanel.java,
javax/swing/colorchooser/ColorChooserComponentFactory.java,
javax/swing/colorchooser/ColorSelectionModel.java,
javax/swing/colorchooser/DefaultColorSelectionModel.java,
javax/swing/event/AncestorEvent.java,
javax/swing/event/HyperlinkEvent.java,
javax/swing/event/InternalFrameAdapter.java,
javax/swing/event/InternalFrameEvent.java,
javax/swing/event/ListDataEvent.java,
javax/swing/event/MouseInputAdapter.java,
javax/swing/event/SwingPropertyChangeSupport.java,
javax/swing/event/TableModelEvent.java,
javax/swing/event/TreeWillExpandListener.java,
javax/swing/event/UndoableEditEvent.java,
javax/swing/filechooser/FileFilter.java,
javax/swing/filechooser/FileSystemView.java,
javax/swing/filechooser/FileView.java,
javax/swing/plaf/BorderUIResource.java,
javax/swing/plaf/basic/BasicDefaults.java,
javax/swing/table/AbstractTableModel.java,
javax/swing/table/DefaultTableCellRenderer.java,
javax/swing/table/DefaultTableColumnModel.java,
javax/swing/table/DefaultTableModel.java,
javax/swing/table/TableColumn.java,
javax/swing/text/JTextComponent.java,
javax/swing/tree/AbstractLayoutCache.java,
javax/swing/tree/DefaultMutableTreeNode.java,
javax/swing/tree/DefaultTreeCellEditor.java,
javax/swing/tree/DefaultTreeCellRenderer.java,
javax/swing/tree/DefaultTreeModel.java,
javax/swing/tree/DefaultTreeSelectionModel.java,
javax/swing/tree/FixedHeightLayoutCache.java,
javax/swing/tree/TreeCellEditor.java,
javax/swing/tree/TreeModel.java,
javax/swing/tree/TreeNode.java,
javax/swing/tree/TreePath.java,
javax/swing/tree/TreeSelectionModel.java,
javax/swing/tree/VariableHeightLayoutCache.java,
javax/swing/undo/AbstractUndoableEdit.java,
javax/swing/undo/CompoundEdit.java,
javax/swing/undo/StateEdit.java,
javax/swing/undo/UndoManager.java,
javax/swing/undo/UndoableEditSupport.java:
New versions from classpath.
* javax/swing/table/JTableHeader.java:
New file from classpath.
* Makefile.am
(java_awt_sources): Added javax/swing/table/JTableHeader.java.
* Makefile.in: Regenerated.
From-SVN: r67769
2003-06-11 13:20:41 +00:00
|
|
|
import java.awt.Component;
|
|
|
|
import javax.accessibility.Accessible;
|
2002-08-09 04:26:17 +00:00
|
|
|
|
2003-11-22 00:03:35 +00:00
|
|
|
|
|
|
|
/**
|
2004-01-06 18:02:23 +00:00
|
|
|
* <p>The "Layered Pane" is a container which divides its children into 6 (or
|
|
|
|
* more) disjoint sets. the pre-defined sets are:</p>
|
2003-11-22 00:03:35 +00:00
|
|
|
*
|
2004-01-06 18:02:23 +00:00
|
|
|
* <ul>
|
|
|
|
* <li>"Frame Content"</li>
|
|
|
|
* <li>"Default"</li>
|
|
|
|
* <li>"Palette"</li>
|
|
|
|
* <li>"Modal"</li>
|
|
|
|
* <li>"Popup"</li>
|
|
|
|
* <li>"Drag"</li>
|
|
|
|
* </ul>
|
2003-11-22 00:03:35 +00:00
|
|
|
*
|
2004-01-06 18:02:23 +00:00
|
|
|
* <p>A child is in exactly one of these layers at any time, though there may
|
|
|
|
* be other layers if someone creates them.</p>
|
2003-11-22 00:03:35 +00:00
|
|
|
*
|
2004-01-06 18:02:23 +00:00
|
|
|
* <p>The purpose of this class is to translate this view of "layers" into a
|
2003-11-22 00:03:35 +00:00
|
|
|
* contiguous array of components: the one held in our ancestor,
|
2004-01-06 18:02:23 +00:00
|
|
|
* {@link java.awt.Container}.</p>
|
2003-11-22 00:03:35 +00:00
|
|
|
*
|
2004-01-06 18:02:23 +00:00
|
|
|
* <p>There is a precise set of words we will use to refer to numbers within
|
|
|
|
* this class:</p>
|
2003-11-22 00:03:35 +00:00
|
|
|
*
|
2004-01-06 18:02:23 +00:00
|
|
|
* <dl>
|
|
|
|
* <dt>Internal Component Index:</dt>
|
|
|
|
* <dd>An offset into the <code>component</code> array held in our ancestor,
|
|
|
|
* {@link java.awt.Container}, from <code>[0 .. component.length)</code>. The drawing
|
|
|
|
* rule with internal indices is that 0 is drawn first.</dd>
|
2003-11-22 00:03:35 +00:00
|
|
|
*
|
2004-01-06 18:02:23 +00:00
|
|
|
* <dt>External Component Index:</dt>
|
|
|
|
* <dd>An offset into the "logical drawing order" of this container. If <code>I</code>
|
|
|
|
* is the internal index of a component, the external index <tt>E =
|
|
|
|
* component.length - I</tt>. The rule with external indices is that 0 is
|
|
|
|
* drawn last.</dd>
|
2003-11-22 00:03:35 +00:00
|
|
|
*
|
2004-01-06 18:02:23 +00:00
|
|
|
* <dt>Layer Number:</dt>
|
|
|
|
* <dd>A general <code>int</code> specifying a layer within this component. Negative
|
|
|
|
* numbers are drawn first, then layer 0, then positive numbered layers, in
|
|
|
|
* ascending order.</dd>
|
2003-11-22 00:03:35 +00:00
|
|
|
*
|
2004-01-06 18:02:23 +00:00
|
|
|
* <dt>Position:</dt>
|
|
|
|
* <dd>An offset into a layer's "logical drawing order". Layer position 0
|
|
|
|
* is drawn last. Layer position -1 is a synonym for the first layer
|
|
|
|
* position (the logical "bottom").</dd>
|
|
|
|
*
|
|
|
|
* @author Graydon Hoare <graydon@redhat.com>
|
2003-11-22 00:03:35 +00:00
|
|
|
*/
|
|
|
|
|
AbstractAction.java, [...]: New versions from classpath.
2003-06-11 Michael Koch <konqueror@gmx.de>
* javax/swing/AbstractAction.java,
javax/swing/AbstractButton.java,
javax/swing/AbstractCellEditor.java,
javax/swing/AbstractListModel.java,
javax/swing/BorderFactory.java,
javax/swing/Box.java,
javax/swing/BoxLayout.java,
javax/swing/ButtonGroup.java,
javax/swing/DefaultButtonModel.java,
javax/swing/DefaultListModel.java,
javax/swing/DefaultListSelectionModel.java,
javax/swing/FocusManager.java,
javax/swing/ImageIcon.java,
javax/swing/InputMap.java,
javax/swing/JApplet.java,
javax/swing/JButton.java,
javax/swing/JCheckBox.java,
javax/swing/JCheckBoxMenuItem.java,
javax/swing/JColorChooser.java,
javax/swing/JComboBox.java,
javax/swing/JComponent.java,
javax/swing/JDesktopPane.java,
javax/swing/JDialog.java,
javax/swing/JEditorPane.java,
javax/swing/JFileChooser.java,
javax/swing/JFormattedTextField.java,
javax/swing/JFrame.java,
javax/swing/JLabel.java,
javax/swing/JLayeredPane.java,
javax/swing/JList.java,
javax/swing/JMenuBar.java,
javax/swing/JMenuItem.java,
javax/swing/JOptionPane.java,
javax/swing/JPanel.java,
javax/swing/JPasswordField.java,
javax/swing/JPopupMenu.java,
javax/swing/JProgressBar.java,
javax/swing/JRadioButton.java,
javax/swing/JRadioButtonMenuItem.java,
javax/swing/JRootPane.java,
javax/swing/JScrollBar.java,
javax/swing/JScrollPane.java,
javax/swing/JSeparator.java,
javax/swing/JSlider.java,
javax/swing/JTabbedPane.java,
javax/swing/JTable.java,
javax/swing/JTextField.java,
javax/swing/JToggleButton.java,
javax/swing/JToolBar.java,
javax/swing/JToolTip.java,
javax/swing/JTree.java,
javax/swing/JViewport.java,
javax/swing/JWindow.java,
javax/swing/KeyStroke.java,
javax/swing/ListSelectionModel.java,
javax/swing/LookAndFeel.java,
javax/swing/RepaintManager.java,
javax/swing/ScrollPaneLayout.java,
javax/swing/SizeRequirements.java,
javax/swing/SwingConstants.java,
javax/swing/Timer.java,
javax/swing/UIDefaults.java,
javax/swing/UIManager.java,
javax/swing/border/AbstractBorder.java,
javax/swing/border/CompoundBorder.java,
javax/swing/colorchooser/AbstractColorChooserPanel.java,
javax/swing/colorchooser/ColorChooserComponentFactory.java,
javax/swing/colorchooser/ColorSelectionModel.java,
javax/swing/colorchooser/DefaultColorSelectionModel.java,
javax/swing/event/AncestorEvent.java,
javax/swing/event/HyperlinkEvent.java,
javax/swing/event/InternalFrameAdapter.java,
javax/swing/event/InternalFrameEvent.java,
javax/swing/event/ListDataEvent.java,
javax/swing/event/MouseInputAdapter.java,
javax/swing/event/SwingPropertyChangeSupport.java,
javax/swing/event/TableModelEvent.java,
javax/swing/event/TreeWillExpandListener.java,
javax/swing/event/UndoableEditEvent.java,
javax/swing/filechooser/FileFilter.java,
javax/swing/filechooser/FileSystemView.java,
javax/swing/filechooser/FileView.java,
javax/swing/plaf/BorderUIResource.java,
javax/swing/plaf/basic/BasicDefaults.java,
javax/swing/table/AbstractTableModel.java,
javax/swing/table/DefaultTableCellRenderer.java,
javax/swing/table/DefaultTableColumnModel.java,
javax/swing/table/DefaultTableModel.java,
javax/swing/table/TableColumn.java,
javax/swing/text/JTextComponent.java,
javax/swing/tree/AbstractLayoutCache.java,
javax/swing/tree/DefaultMutableTreeNode.java,
javax/swing/tree/DefaultTreeCellEditor.java,
javax/swing/tree/DefaultTreeCellRenderer.java,
javax/swing/tree/DefaultTreeModel.java,
javax/swing/tree/DefaultTreeSelectionModel.java,
javax/swing/tree/FixedHeightLayoutCache.java,
javax/swing/tree/TreeCellEditor.java,
javax/swing/tree/TreeModel.java,
javax/swing/tree/TreeNode.java,
javax/swing/tree/TreePath.java,
javax/swing/tree/TreeSelectionModel.java,
javax/swing/tree/VariableHeightLayoutCache.java,
javax/swing/undo/AbstractUndoableEdit.java,
javax/swing/undo/CompoundEdit.java,
javax/swing/undo/StateEdit.java,
javax/swing/undo/UndoManager.java,
javax/swing/undo/UndoableEditSupport.java:
New versions from classpath.
* javax/swing/table/JTableHeader.java:
New file from classpath.
* Makefile.am
(java_awt_sources): Added javax/swing/table/JTableHeader.java.
* Makefile.in: Regenerated.
From-SVN: r67769
2003-06-11 13:20:41 +00:00
|
|
|
public class JLayeredPane extends JComponent implements Accessible
|
2002-08-09 04:26:17 +00:00
|
|
|
{
|
2003-11-22 00:03:35 +00:00
|
|
|
|
2004-01-06 18:02:23 +00:00
|
|
|
public static String LAYER_PROPERTY = "LAYER_PROPERTY";
|
|
|
|
|
|
|
|
public static Integer FRAME_CONTENT_LAYER = new Integer (-30000);
|
|
|
|
|
|
|
|
public static Integer DEFAULT_LAYER = new Integer (0);
|
|
|
|
public static Integer PALETTE_LAYER = new Integer (100);
|
|
|
|
public static Integer MODAL_LAYER = new Integer (200);
|
|
|
|
public static Integer POPUP_LAYER = new Integer (300);
|
|
|
|
public static Integer DRAG_LAYER = new Integer (400);
|
|
|
|
|
|
|
|
TreeMap layers; // Layer Number (Integer) -> Layer Size (Integer)
|
|
|
|
Hashtable componentToLayer; // Component -> Layer Number (Integer)
|
2003-11-22 00:03:35 +00:00
|
|
|
|
2004-01-06 18:02:23 +00:00
|
|
|
JLayeredPane()
|
|
|
|
{
|
|
|
|
layers = new TreeMap ();
|
|
|
|
componentToLayer = new Hashtable ();
|
|
|
|
}
|
2003-11-22 00:03:35 +00:00
|
|
|
|
|
|
|
|
2004-01-06 18:02:23 +00:00
|
|
|
/**
|
|
|
|
* Looks up the layer a child component is currently assigned to.
|
|
|
|
*
|
|
|
|
* @param c the component to look up.
|
|
|
|
* @return the layer the component is currently assigned to, in this container.
|
|
|
|
* @throws IllegalArgumentException if the component is not a child of this container.
|
|
|
|
*/
|
2003-11-22 00:03:35 +00:00
|
|
|
|
2004-01-06 18:02:23 +00:00
|
|
|
protected Integer getLayer (Component c)
|
|
|
|
{
|
|
|
|
if (! componentToLayer.containsKey (c))
|
2003-11-22 00:03:35 +00:00
|
|
|
throw new IllegalArgumentException ();
|
2004-01-06 18:02:23 +00:00
|
|
|
return (Integer) componentToLayer.get (c);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a pair of ints representing a half-open interval
|
|
|
|
* <code>[bottom, top)</code>, which is the range of internal component
|
|
|
|
* indices the provided layer number corresponds to.
|
|
|
|
*
|
|
|
|
* Note that "top" is <em>not</em> included in the interval of
|
|
|
|
* component indices in this layer: a layer with 0 elements in it has
|
|
|
|
* <code>ret[0] == ret[1]</code>.
|
|
|
|
*
|
|
|
|
* @param layer the layer to look up.
|
|
|
|
* @return the half-open range of internal indices this layer spans.
|
|
|
|
* @throws IllegalArgumentException if layer does not refer to an active layer
|
|
|
|
* in this container.
|
|
|
|
*/
|
|
|
|
|
|
|
|
protected int[] layerToRange (Integer layer)
|
|
|
|
{
|
|
|
|
int[] ret = new int[2];
|
|
|
|
Iterator i = layers.entrySet ().iterator ();
|
|
|
|
while (i.hasNext())
|
2003-11-22 00:03:35 +00:00
|
|
|
{
|
2004-01-06 18:02:23 +00:00
|
|
|
Map.Entry pair = (Map.Entry) i.next();
|
|
|
|
Integer layerNum = (Integer) pair.getKey ();
|
|
|
|
Integer layerSz = (Integer) pair.getValue ();
|
|
|
|
if (layerNum == layer)
|
|
|
|
{
|
|
|
|
ret[1] = ret[0] + layerSz.intValue ();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret[0] += layerSz.intValue ();
|
|
|
|
}
|
2003-11-22 00:03:35 +00:00
|
|
|
}
|
2004-01-06 18:02:23 +00:00
|
|
|
// should have found the layer during iteration
|
|
|
|
throw new IllegalArgumentException ();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Increments the recorded size of a given layer.
|
|
|
|
*
|
|
|
|
* @param layer the layer number to increment.
|
|
|
|
* @see #incrLayer()
|
|
|
|
*/
|
|
|
|
|
|
|
|
protected void incrLayer(Integer layer)
|
|
|
|
{
|
|
|
|
int sz = 1;
|
|
|
|
if (layers.containsKey (layer))
|
2003-11-22 00:03:35 +00:00
|
|
|
sz += ((Integer)(layers.get (layer))).intValue ();
|
2004-01-06 18:02:23 +00:00
|
|
|
layers.put (layer, new Integer(sz));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Decrements the recorded size of a given layer.
|
|
|
|
*
|
|
|
|
* @param layer the layer number to decrement.
|
|
|
|
* @see #decrLayer()
|
|
|
|
*/
|
|
|
|
|
|
|
|
protected void decrLayer(Integer layer)
|
|
|
|
{
|
|
|
|
int sz = 0;
|
|
|
|
if (layers.containsKey (layer))
|
2003-11-22 00:03:35 +00:00
|
|
|
sz = ((Integer)(layers.get (layer))).intValue () - 1;
|
2004-01-06 18:02:23 +00:00
|
|
|
layers.put (layer, new Integer(sz));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the greatest layer number currently in use, in this container.
|
|
|
|
* This number may legally be positive <em>or</em> negative.
|
|
|
|
*
|
|
|
|
* @return the least layer number.
|
|
|
|
* @see #lowestLayer()
|
|
|
|
*/
|
|
|
|
|
|
|
|
public int highestLayer()
|
|
|
|
{
|
|
|
|
if (layers.size() == 0)
|
2003-11-22 00:03:35 +00:00
|
|
|
return 0;
|
2004-01-06 18:02:23 +00:00
|
|
|
return ((Integer)(layers.lastKey ())).intValue ();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the least layer number currently in use, in this container.
|
|
|
|
* This number may legally be positive <em>or</em> negative.
|
|
|
|
*
|
|
|
|
* @return the least layer number.
|
|
|
|
* @see #highestLayer()
|
|
|
|
*/
|
2003-11-22 00:03:35 +00:00
|
|
|
|
2004-01-06 18:02:23 +00:00
|
|
|
public int lowestLayer()
|
|
|
|
{
|
|
|
|
if (layers.size() == 0)
|
2003-11-22 00:03:35 +00:00
|
|
|
return 0;
|
2004-01-06 18:02:23 +00:00
|
|
|
return ((Integer)(layers.firstKey ())).intValue ();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Moves a component to the "front" of its layer. The "front" is a
|
|
|
|
* synonym for position 0, which is also the last position drawn in each
|
|
|
|
* layer, so is usually the component which occludes the most other
|
|
|
|
* components in its layer.
|
|
|
|
*
|
|
|
|
* @param c the component to move to the front of its layer.
|
|
|
|
* @throws IllegalArgumentException if the component is not a child of
|
|
|
|
* this container.
|
|
|
|
* @see #moveToBack()
|
|
|
|
*/
|
|
|
|
|
|
|
|
public void moveToFront(Component c)
|
|
|
|
{
|
|
|
|
setPosition (c, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* <p>Moves a component to the "back" of its layer. The "back" is a
|
|
|
|
* synonym for position N-1 (also known as position -1), where N is the
|
|
|
|
* size of the layer.</p>
|
|
|
|
*
|
|
|
|
* <p>The "back" of a layer is the first position drawn, so the component at
|
|
|
|
* the "back" is usually the component which is occluded by the most
|
|
|
|
* other components in its layer.</p>
|
|
|
|
*
|
|
|
|
* @param c the component to move to the back of its layer.
|
|
|
|
* @throws IllegalArgumentException if the component is not a child of
|
|
|
|
* this container.
|
|
|
|
* @see #moveToFront()
|
|
|
|
*/
|
|
|
|
|
|
|
|
public void moveToBack(Component c)
|
|
|
|
{
|
|
|
|
setPosition (c, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the position of a component within its layer. Positions are assigned
|
|
|
|
* from the "front" (position 0) to the "back" (position N-1), and drawn from
|
|
|
|
* the back towards the front.
|
|
|
|
*
|
|
|
|
* @param c the component to get the position of.
|
|
|
|
* @throws IllegalArgumentException if the component is not a child of
|
|
|
|
* this container.
|
|
|
|
* @see #setPosition()
|
|
|
|
*/
|
2002-08-09 04:26:17 +00:00
|
|
|
|
2004-01-06 18:02:23 +00:00
|
|
|
public int getPosition(Component c)
|
|
|
|
{
|
|
|
|
Integer layer = getLayer (c);
|
|
|
|
int[] range = layerToRange (layer);
|
|
|
|
int top = (range[1] - 1);
|
|
|
|
Component[] comps = getComponents ();
|
|
|
|
for (int i = range[0]; i < range[1]; ++i)
|
2003-11-22 00:03:35 +00:00
|
|
|
{
|
2004-01-06 18:02:23 +00:00
|
|
|
if (comps[i] == c)
|
|
|
|
return top - i;
|
2003-11-22 00:03:35 +00:00
|
|
|
}
|
2004-01-06 18:02:23 +00:00
|
|
|
// should have found it
|
|
|
|
throw new IllegalArgumentException ();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Change the position of a component within its layer. Positions are assigned
|
|
|
|
* from the "front" (position 0) to the "back" (position N-1), and drawn from
|
|
|
|
* the back towards the front.
|
|
|
|
*
|
|
|
|
* @param c the component to change the position of.
|
|
|
|
* @param position the position to assign the component to.
|
|
|
|
* @throws IllegalArgumentException if the component is not a child of
|
|
|
|
* this container.
|
|
|
|
* @see #getPosition()
|
|
|
|
*/
|
|
|
|
|
|
|
|
public void setPosition(Component c, int position)
|
|
|
|
{
|
|
|
|
Integer layer = getLayer (c);
|
|
|
|
int[] range = layerToRange (layer);
|
|
|
|
if (range[0] == range[1])
|
2003-11-22 00:03:35 +00:00
|
|
|
throw new IllegalArgumentException ();
|
|
|
|
|
2004-01-06 18:02:23 +00:00
|
|
|
int top = (range[1] - 1);
|
|
|
|
if (position == -1)
|
2003-11-22 00:03:35 +00:00
|
|
|
position = top - range[0];
|
2004-01-06 18:02:23 +00:00
|
|
|
int targ = top - position;
|
|
|
|
int curr = -1;
|
2003-11-22 00:03:35 +00:00
|
|
|
|
2004-01-06 18:02:23 +00:00
|
|
|
Component[] comps = getComponents();
|
|
|
|
for (int i = range[0]; i < range[1]; ++i)
|
2003-11-22 00:03:35 +00:00
|
|
|
{
|
2004-01-06 18:02:23 +00:00
|
|
|
if (comps[i] == c)
|
|
|
|
{
|
|
|
|
curr = i;
|
|
|
|
break;
|
|
|
|
}
|
2003-11-22 00:03:35 +00:00
|
|
|
}
|
2004-01-06 18:02:23 +00:00
|
|
|
if (curr == -1)
|
2003-11-22 00:03:35 +00:00
|
|
|
// should have found it
|
|
|
|
throw new IllegalArgumentException ();
|
|
|
|
|
2004-01-06 18:02:23 +00:00
|
|
|
super.swapComponents (curr, targ);
|
|
|
|
validate();
|
|
|
|
repaint();
|
|
|
|
}
|
2003-11-22 00:03:35 +00:00
|
|
|
|
2004-01-06 18:02:23 +00:00
|
|
|
/**
|
|
|
|
* Return an array of all components within a layer of this
|
|
|
|
* container. Components are ordered back-to-front, with the "back"
|
|
|
|
* element (which draws first) at position 0 of the returned array.
|
|
|
|
*
|
|
|
|
* @param layer the layer to return components from.
|
|
|
|
* @return the components in the layer.
|
|
|
|
*/
|
|
|
|
|
|
|
|
public Component[] getComponentsInLayer(int layer)
|
|
|
|
{
|
|
|
|
int[] range = layerToRange (getObjectForLayer (layer));
|
|
|
|
if (range[0] == range[1])
|
2003-11-22 00:03:35 +00:00
|
|
|
return new Component[0];
|
2004-01-06 18:02:23 +00:00
|
|
|
else
|
2003-11-22 00:03:35 +00:00
|
|
|
{
|
2004-01-06 18:02:23 +00:00
|
|
|
Component[] comps = getComponents ();
|
|
|
|
int sz = (range[1] - 1) - range[0];
|
|
|
|
Component[] nc = new Component[sz];
|
|
|
|
for (int i = 0; i < sz; ++i)
|
|
|
|
nc[i] = comps[range[0] + i];
|
|
|
|
return nc;
|
2003-11-22 00:03:35 +00:00
|
|
|
}
|
2004-01-06 18:02:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the number of components within a layer of this
|
|
|
|
* container.
|
|
|
|
*
|
|
|
|
* @param layer the layer count components in.
|
|
|
|
* @return the number of components in the layer.
|
|
|
|
*/
|
|
|
|
|
|
|
|
public int getComponentCountInLayer(int layer)
|
|
|
|
{
|
|
|
|
int[] range = layerToRange (getObjectForLayer (layer));
|
|
|
|
if (range[0] == range[1])
|
2003-11-22 00:03:35 +00:00
|
|
|
return 0;
|
2004-01-06 18:02:23 +00:00
|
|
|
else
|
|
|
|
return (range[1] - range[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a hashtable mapping child components of this container to
|
|
|
|
* Integer objects representing the component's layer assignments.
|
|
|
|
*/
|
|
|
|
|
|
|
|
protected Hashtable getComponentToLayer()
|
|
|
|
{
|
|
|
|
return componentToLayer;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the index of a component within the underlying (contiguous)
|
|
|
|
* array of children. This is a "raw" number which does not represent the
|
|
|
|
* child's position in a layer, but rather its position in the
|
|
|
|
* concatenation of <em>all</em> layers within the container.
|
|
|
|
*
|
|
|
|
* @param c the component to look up.
|
|
|
|
* @return the internal index of the component.
|
|
|
|
* @throws IllegalArgumentException if the component is not a child of
|
|
|
|
* this container.
|
|
|
|
*/
|
|
|
|
|
|
|
|
protected int getInternalIndexOf(Component c)
|
|
|
|
{
|
|
|
|
Integer layer = getLayer (c);
|
|
|
|
int[] range = layerToRange (layer);
|
|
|
|
Component[] comps = getComponents();
|
|
|
|
for (int i = range[0]; i < range[1]; ++i)
|
2003-11-22 00:03:35 +00:00
|
|
|
{
|
2004-01-06 18:02:23 +00:00
|
|
|
if (comps[i] == c)
|
|
|
|
return i;
|
2003-11-22 00:03:35 +00:00
|
|
|
}
|
2004-01-06 18:02:23 +00:00
|
|
|
// should have found the component during iteration
|
|
|
|
throw new IllegalArgumentException ();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the external index of a component within the underlying
|
|
|
|
* (contiguous) array of children. This is a "raw" number which does not
|
|
|
|
* represent the child's position in a layer, but rather its position in
|
|
|
|
* the logical drawing order of all children of the container.
|
|
|
|
*
|
|
|
|
* @param c the component to look up.
|
|
|
|
* @return the external index of the component.
|
|
|
|
* @throws IllegalArgumentException if the component is not a child of
|
|
|
|
* this container.
|
|
|
|
*/
|
|
|
|
|
|
|
|
public int getIndexOf(Component c)
|
|
|
|
{
|
|
|
|
// returns the *external* index of the component.
|
|
|
|
int top = getComponentCount() - 1;
|
|
|
|
return top - getIndexOf (c);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return an Integer object which holds the same int value as the
|
|
|
|
* parameter. This is strictly an optimization to minimize the number of
|
|
|
|
* identical Integer objects which we allocate.
|
|
|
|
*
|
|
|
|
* @param layer the layer number as an int.
|
|
|
|
* @return the layer number as an Integer, possibly shared.
|
|
|
|
*/
|
|
|
|
|
|
|
|
protected Integer getObjectForLayer(int layer)
|
|
|
|
{
|
|
|
|
switch (layer)
|
2003-11-22 00:03:35 +00:00
|
|
|
{
|
|
|
|
case -30000:
|
2004-01-06 18:02:23 +00:00
|
|
|
return FRAME_CONTENT_LAYER;
|
2003-11-22 00:03:35 +00:00
|
|
|
|
|
|
|
case 0:
|
2004-01-06 18:02:23 +00:00
|
|
|
return DEFAULT_LAYER;
|
2003-11-22 00:03:35 +00:00
|
|
|
|
|
|
|
case 100:
|
2004-01-06 18:02:23 +00:00
|
|
|
return PALETTE_LAYER;
|
2003-11-22 00:03:35 +00:00
|
|
|
|
|
|
|
case 200:
|
2004-01-06 18:02:23 +00:00
|
|
|
return MODAL_LAYER;
|
2003-11-22 00:03:35 +00:00
|
|
|
|
|
|
|
case 300:
|
2004-01-06 18:02:23 +00:00
|
|
|
return POPUP_LAYER;
|
2003-11-22 00:03:35 +00:00
|
|
|
|
|
|
|
case 400:
|
2004-01-06 18:02:23 +00:00
|
|
|
return DRAG_LAYER;
|
2003-11-22 00:03:35 +00:00
|
|
|
|
|
|
|
default:
|
2004-01-06 18:02:23 +00:00
|
|
|
break;
|
2003-11-22 00:03:35 +00:00
|
|
|
}
|
|
|
|
|
2004-01-06 18:02:23 +00:00
|
|
|
return new Integer(layer);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Computes an internal index at which to request the superclass {@link
|
|
|
|
* java.awt.Container} inserts a component, given an abstract layer and
|
|
|
|
* position number.
|
|
|
|
*
|
|
|
|
* @param layer the layer in which to insert a component.
|
|
|
|
* @param position the position in the layer at which to insert a component.
|
|
|
|
* @return the internal index at which to insert the component.
|
|
|
|
*/
|
2003-11-22 00:03:35 +00:00
|
|
|
|
2004-01-06 18:02:23 +00:00
|
|
|
protected int insertIndexForLayer(int layer, int position)
|
|
|
|
{
|
|
|
|
|
|
|
|
Integer lobj = getObjectForLayer (layer);
|
|
|
|
if (! layers.containsKey(lobj))
|
|
|
|
layers.put (lobj, new Integer (0));
|
|
|
|
int[] range = layerToRange (lobj);
|
|
|
|
if (range[0] == range[1])
|
2003-11-22 00:03:35 +00:00
|
|
|
return range[0];
|
2002-08-09 04:26:17 +00:00
|
|
|
|
2004-01-06 18:02:23 +00:00
|
|
|
int bottom = range[0];
|
|
|
|
int top = range[1] - 1;
|
2003-11-22 00:03:35 +00:00
|
|
|
|
2004-01-06 18:02:23 +00:00
|
|
|
if (position == -1 || position > (top - bottom))
|
2003-11-22 00:03:35 +00:00
|
|
|
return bottom;
|
2004-01-06 18:02:23 +00:00
|
|
|
else
|
2003-11-22 00:03:35 +00:00
|
|
|
return top - position;
|
2004-01-06 18:02:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes a child from this container. The child is specified by
|
|
|
|
* internal index. After removal, the child no longer occupies a layer.
|
|
|
|
*
|
|
|
|
* @param index the internal index of the child component to remove.
|
|
|
|
*/
|
2002-08-09 04:26:17 +00:00
|
|
|
|
2004-01-06 18:02:23 +00:00
|
|
|
public void remove (int index)
|
|
|
|
{
|
|
|
|
Component c = getComponent (index);
|
|
|
|
Integer layer = getLayer (c);
|
|
|
|
decrLayer (layer);
|
|
|
|
componentToLayer.remove (c);
|
|
|
|
super.remove (index);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes a child from this container. The child is specified directly.
|
|
|
|
* After removal, the child no longer occupies a layer.
|
|
|
|
*
|
|
|
|
* @param comp the child to remove.
|
|
|
|
*/
|
2003-11-22 00:03:35 +00:00
|
|
|
|
2004-01-06 18:02:23 +00:00
|
|
|
public void remove (Component comp)
|
|
|
|
{
|
|
|
|
remove (getInternalIndexOf (comp));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* <p>Set the layer property for a component, within this container. The
|
|
|
|
* component will be implicitly mapped to the bottom-most position in the
|
|
|
|
* layer, but only if added <em>after</em> calling this method.</p>
|
|
|
|
*
|
|
|
|
* <p>Read that carefully: this method should be called <em>before</em> the
|
|
|
|
* component is added to the container.</p>
|
|
|
|
*
|
|
|
|
* @param c the component to set the layer property for.
|
|
|
|
* @param layer the layer number to assign to the component.
|
|
|
|
*/
|
|
|
|
|
|
|
|
public void setLayer(Component c, int layer)
|
|
|
|
{
|
|
|
|
componentToLayer.put (c, getObjectForLayer (layer));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the layer and position of a component, within this container.
|
|
|
|
*
|
|
|
|
* @param c the child component to set the layer property for.
|
|
|
|
* @param layer the layer number to assign to the component.
|
|
|
|
* @param position the position number to assign to the component.
|
|
|
|
*/
|
|
|
|
|
|
|
|
public void setLayer(Component c,
|
|
|
|
int layer,
|
|
|
|
int position)
|
|
|
|
{
|
|
|
|
componentToLayer.put (c, getObjectForLayer (layer));
|
|
|
|
setPosition(c, position);
|
|
|
|
validate();
|
|
|
|
repaint();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Overrides the default implementation from {@link java.awt.Container}
|
|
|
|
* such that <code>layerConstraint</code> is interpreted as an {@link
|
|
|
|
* Integer}, specifying the layer to which the component will be added
|
|
|
|
* (at the bottom position).
|
|
|
|
*
|
|
|
|
* @param comp the component to add.
|
|
|
|
* @param layerConstraint an integer specifying the layer to add the component to.
|
|
|
|
* @param index an ignored parameter, for compatibility.
|
|
|
|
*/
|
|
|
|
|
|
|
|
protected void addImpl(Component comp, Object layerConstraint, int index)
|
|
|
|
{
|
|
|
|
Integer layer;
|
|
|
|
if (layerConstraint != null && layerConstraint instanceof Integer)
|
|
|
|
layer = (Integer) layerConstraint;
|
|
|
|
else if (componentToLayer.containsKey (comp))
|
2003-11-22 00:03:35 +00:00
|
|
|
layer = (Integer) componentToLayer.remove (comp);
|
2004-01-06 18:02:23 +00:00
|
|
|
else
|
2003-11-22 00:03:35 +00:00
|
|
|
layer = DEFAULT_LAYER;
|
|
|
|
|
2004-01-06 18:02:23 +00:00
|
|
|
int newIdx = insertIndexForLayer(layer.intValue (), -1);
|
|
|
|
componentToLayer.put (comp, layer);
|
|
|
|
incrLayer (layer);
|
2003-11-22 00:03:35 +00:00
|
|
|
|
2004-01-06 18:02:23 +00:00
|
|
|
super.addImpl(comp, null, newIdx);
|
|
|
|
validate();
|
|
|
|
repaint();
|
|
|
|
}
|
2002-08-09 04:26:17 +00:00
|
|
|
}
|