diff options
author | Tom Tromey <tromey@gcc.gnu.org> | 2005-09-23 19:36:46 +0000 |
---|---|---|
committer | Tom Tromey <tromey@gcc.gnu.org> | 2005-09-23 19:36:46 +0000 |
commit | 9b044d19517541c95681d35a92dbc81e6e21d94f (patch) | |
tree | b2c2abf473309eac532cafbad81b20f3270ff45f /libjava/classpath/javax | |
parent | acff2da93c917c21aca570e2a41ee613c2b32c2e (diff) | |
download | gcc-9b044d19517541c95681d35a92dbc81e6e21d94f.zip gcc-9b044d19517541c95681d35a92dbc81e6e21d94f.tar.gz gcc-9b044d19517541c95681d35a92dbc81e6e21d94f.tar.bz2 |
Initial revision
From-SVN: r104578
Diffstat (limited to 'libjava/classpath/javax')
80 files changed, 20073 insertions, 0 deletions
diff --git a/libjava/classpath/javax/swing/plaf/metal/MetalInternalFrameTitlePane.java b/libjava/classpath/javax/swing/plaf/metal/MetalInternalFrameTitlePane.java new file mode 100644 index 0000000..20526eb --- /dev/null +++ b/libjava/classpath/javax/swing/plaf/metal/MetalInternalFrameTitlePane.java @@ -0,0 +1,171 @@ +/* MetalInternalFrameTitlePane.java + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package javax.swing.plaf.metal; + +import java.awt.Container; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.LayoutManager; + +import javax.swing.Icon; +import javax.swing.JInternalFrame; +import javax.swing.JMenu; +import javax.swing.plaf.basic.BasicInternalFrameTitlePane; + +/** + * The title pane for a {@link JInternalFrame}. + */ +public class MetalInternalFrameTitlePane extends BasicInternalFrameTitlePane +{ + + protected boolean isPalette; + + protected Icon paletteCloseIcon = MetalIconFactory.getInternalFrameCloseIcon(16); + + protected int paletteTitleHeight = 12; + + /** + * Creates a new title pane. + * + * @param f the internal frame. + */ + public MetalInternalFrameTitlePane(JInternalFrame f) + { + super(f); + isPalette = false; + } + + /** + * Fetches the colors used in the title pane. + */ + protected void installDefaults() + { + super.installDefaults(); + selectedTextColor = MetalLookAndFeel.getControlTextColor(); + selectedTitleColor = MetalLookAndFeel.getWindowTitleBackground(); + notSelectedTextColor = MetalLookAndFeel.getInactiveControlTextColor(); + notSelectedTitleColor = MetalLookAndFeel.getWindowTitleInactiveBackground(); + } + + /** + * Clears the colors used for the title pane. + */ + protected void uninstallDefaults() + { + super.uninstallDefaults(); + selectedTextColor = null; + selectedTitleColor = null; + notSelectedTextColor = null; + notSelectedTitleColor = null; + } + + /** + * Calls the super class to create the buttons, then calls + * <code>setBorderPainted(false)</code> and + * <code>setContentAreaFilled(false)</code> for each button. + */ + protected void createButtons() + { + super.createButtons(); + closeButton.setBorderPainted(false); + closeButton.setContentAreaFilled(false); + iconButton.setBorderPainted(false); + iconButton.setContentAreaFilled(false); + maxButton.setBorderPainted(false); + maxButton.setContentAreaFilled(false); + } + + /** + * Overridden to do nothing. + */ + protected void addSystemMenuItems(JMenu systemMenu) + { + // do nothing + } + + /** + * Overridden to do nothing. + */ + protected void showSystemMenu() + { + // do nothing + } + + /** + * Creates a layout manager for the components in the title pane. + * + * @return A layout manager. + */ + protected LayoutManager createLayout() + { + return new TitlePaneLayout() + { + public Dimension preferredLayoutSize(Container c) + { + return new Dimension(24, 24); + } + }; + } + + public void paintPalette(Graphics g) + { + // FIXME: needs implementing + // most likely this is equivalent to paintComponent(g) when the isPalette + // flag is true + } + + public void paintComponent(Graphics g) + { + // probably need to check the isPalette flag here, if true pass over to + // paintPalette(Graphics) + super.paintComponent(g); + Dimension d = getSize(); + if (frame.isSelected()) + g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow()); + else + g.setColor(MetalLookAndFeel.getControlDarkShadow()); + g.drawLine(0, d.height - 1, d.width - 1, d.height - 1); + } + + public void setPalette(boolean b) + { + isPalette = b; + } +} + diff --git a/libjava/classpath/javax/swing/plaf/multi/MultiButtonUI.java b/libjava/classpath/javax/swing/plaf/multi/MultiButtonUI.java new file mode 100644 index 0000000..ac2a5fa --- /dev/null +++ b/libjava/classpath/javax/swing/plaf/multi/MultiButtonUI.java @@ -0,0 +1,352 @@ +/* MultiButtonUI.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.swing.plaf.multi; + +import java.awt.Dimension; +import java.awt.Graphics; +import java.util.Iterator; +import java.util.Vector; + +import javax.accessibility.Accessible; +import javax.swing.JComponent; +import javax.swing.LookAndFeel; +import javax.swing.UIManager; +import javax.swing.plaf.ButtonUI; +import javax.swing.plaf.ComponentUI; + +/** + * A UI delegate that that coordinates multiple {@link ButtonUI} instances, one + * from the primary look and feel, and one or more from the auxiliary look and + * feel(s). + * + * @see UIManager#addAuxiliaryLookAndFeel(LookAndFeel) + */ +public class MultiButtonUI extends ButtonUI +{ + + /** A list of references to the actual component UIs. */ + protected Vector uis; + + /** + * Creates a new <code>MultiButtonUI</code> instance. + * + * @see #createUI(JComponent) + */ + public MultiButtonUI() + { + uis = new Vector(); + } + + /** + * Creates a delegate object for the specified component. If any auxiliary + * look and feels support this component, a <code>MultiButtonUI</code> is + * returned, otherwise the UI from the default look and feel is returned. + * + * @param target the component. + * + * @see MultiLookAndFeel#createUIs(ComponentUI, Vector, JComponent) + */ + public static ComponentUI createUI(JComponent target) + { + MultiButtonUI mui = new MultiButtonUI(); + return MultiLookAndFeel.createUIs(mui, mui.uis, target); + } + + /** + * Calls the {@link ComponentUI#installUI(JComponent)} method for all + * the UI delegates managed by this <code>MultiButtonUI</code>. + * + * @param c the component. + */ + public void installUI(JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.installUI(c); + } + } + + /** + * Calls the {@link ComponentUI#uninstallUI(JComponent)} method for all + * the UI delegates managed by this <code>MultiButtonUI</code>. + * + * @param c the component. + */ + public void uninstallUI(JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.uninstallUI(c); + } + } + + /** + * Returns an array containing the UI delegates managed by this + * <code>MultiButtonUI</code>. The first item in the array is always + * the UI delegate from the installed default look and feel. + * + * @return An array of UI delegates. + */ + public ComponentUI[] getUIs() + { + return MultiLookAndFeel.uisToArray(uis); + } + + /** + * Calls the {@link ComponentUI#contains(JComponent, int, int)} method for all + * the UI delegates managed by this <code>MultiButtonUI</code>, + * returning the result for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * @param x the x-coordinate. + * @param y the y-coordinate. + * + * @return <code>true</code> if the specified (x, y) coordinate falls within + * the bounds of the component as rendered by the UI delegate in the + * primary look and feel, and <code>false</code> otherwise. + */ + public boolean contains(JComponent c, int x, int y) + { + boolean result = false; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.contains(c, x, y); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* boolean ignored = */ ui.contains(c, x, y); + } + return result; + } + + /** + * Calls the {@link ComponentUI#update(Graphics, JComponent)} method for all + * the UI delegates managed by this <code>MultiButtonUI</code>. + * + * @param g the graphics device. + * @param c the component. + */ + public void update(Graphics g, JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.update(g, c); + } + } + + /** + * Calls the <code>paint(Graphics, JComponent)</code> method for all the UI + * delegates managed by this <code>MultiButtonUI</code>. + * + * @param g the graphics device. + * @param c the component. + */ + public void paint(Graphics g, JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.paint(g, c); + } + } + + /** + * Calls the {@link ComponentUI#getPreferredSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiButtonUI</code>, + * returning the preferred size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The preferred size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getPreferredSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getPreferredSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getPreferredSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getMinimumSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiButtonUI</code>, + * returning the minimum size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The minimum size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getMinimumSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getMinimumSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getMinimumSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getMaximumSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiButtonUI</code>, + * returning the maximum size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The maximum size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getMaximumSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getMaximumSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getMaximumSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getAccessibleChildrenCount(JComponent)} method + * for all the UI delegates managed by this <code>MultiButtonUI</code>, + * returning the count for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The count returned by the UI delegate from the primary + * look and feel. + */ + public int getAccessibleChildrenCount(JComponent c) + { + int result = 0; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getAccessibleChildrenCount(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* int ignored = */ ui.getAccessibleChildrenCount(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getAccessibleChild(JComponent, int)} method + * for all the UI delegates managed by this <code>MultiButtonUI</code>, + * returning the child for the UI delegate from the primary look and + * feel. + * + * @param c the component + * @param i the child index. + * + * @return The child returned by the UI delegate from the primary + * look and feel. + */ + public Accessible getAccessibleChild(JComponent c, int i) + { + Accessible result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getAccessibleChild(c, i); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Accessible ignored = */ ui.getAccessibleChild(c, i); + } + return result; + } + +}
\ No newline at end of file diff --git a/libjava/classpath/javax/swing/plaf/multi/MultiColorChooserUI.java b/libjava/classpath/javax/swing/plaf/multi/MultiColorChooserUI.java new file mode 100644 index 0000000..8adb950 --- /dev/null +++ b/libjava/classpath/javax/swing/plaf/multi/MultiColorChooserUI.java @@ -0,0 +1,352 @@ +/* MultiColorChooserUI.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.swing.plaf.multi; + +import java.awt.Dimension; +import java.awt.Graphics; +import java.util.Iterator; +import java.util.Vector; + +import javax.accessibility.Accessible; +import javax.swing.JComponent; +import javax.swing.LookAndFeel; +import javax.swing.UIManager; +import javax.swing.plaf.ColorChooserUI; +import javax.swing.plaf.ComponentUI; + +/** + * A UI delegate that that coordinates multiple {@link ColorChooserUI} + * instances, one from the primary look and feel, and one or more from the + * auxiliary look and feel(s). + * + * @see UIManager#addAuxiliaryLookAndFeel(LookAndFeel) + */ +public class MultiColorChooserUI extends ColorChooserUI +{ + + /** A list of references to the actual component UIs. */ + protected Vector uis; + + /** + * Creates a new <code>MultiColorChooserUI</code> instance. + * + * @see #createUI(JComponent) + */ + public MultiColorChooserUI() + { + uis = new Vector(); + } + + /** + * Creates a delegate object for the specified component. If any auxiliary + * look and feels support this component, a <code>MultiColorChooserUI</code> + * is returned, otherwise the UI from the default look and feel is returned. + * + * @param target the component. + * + * @see MultiLookAndFeel#createUIs(ComponentUI, Vector, JComponent) + */ + public static ComponentUI createUI(JComponent target) + { + MultiColorChooserUI mui = new MultiColorChooserUI(); + return MultiLookAndFeel.createUIs(mui, mui.uis, target); + } + + /** + * Calls the {@link ComponentUI#installUI(JComponent)} method for all + * the UI delegates managed by this <code>MultiColorChooserUI</code>. + * + * @param c the component. + */ + public void installUI(JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.installUI(c); + } + } + + /** + * Calls the {@link ComponentUI#uninstallUI(JComponent)} method for all + * the UI delegates managed by this <code>MultiColorChooserUI</code>. + * + * @param c the component. + */ + public void uninstallUI(JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.uninstallUI(c); + } + } + + /** + * Returns an array containing the UI delegates managed by this + * <code>MultiColorChooserUI</code>. The first item in the array is always + * the UI delegate from the installed default look and feel. + * + * @return An array of UI delegates. + */ + public ComponentUI[] getUIs() + { + return MultiLookAndFeel.uisToArray(uis); + } + + /** + * Calls the {@link ComponentUI#contains(JComponent, int, int)} method for all + * the UI delegates managed by this <code>MultiColorChooserUI</code>, + * returning the result for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * @param x the x-coordinate. + * @param y the y-coordinate. + * + * @return <code>true</code> if the specified (x, y) coordinate falls within + * the bounds of the component as rendered by the UI delegate in the + * primary look and feel, and <code>false</code> otherwise. + */ + public boolean contains(JComponent c, int x, int y) + { + boolean result = false; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.contains(c, x, y); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* boolean ignored = */ ui.contains(c, x, y); + } + return result; + } + + /** + * Calls the {@link ComponentUI#update(Graphics, JComponent)} method for all + * the UI delegates managed by this <code>MultiColorChooserUI</code>. + * + * @param g the graphics device. + * @param c the component. + */ + public void update(Graphics g, JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.update(g, c); + } + } + + /** + * Calls the <code>paint(Graphics, JComponent)</code> method for all the UI + * delegates managed by this <code>MultiColorChooserUI</code>. + * + * @param g the graphics device. + * @param c the component. + */ + public void paint(Graphics g, JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.paint(g, c); + } + } + + /** + * Calls the {@link ComponentUI#getPreferredSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiColorChooserUI</code>, + * returning the preferred size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The preferred size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getPreferredSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getPreferredSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getPreferredSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getMinimumSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiColorChooserUI</code>, + * returning the minimum size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The minimum size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getMinimumSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getMinimumSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getMinimumSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getMaximumSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiColorChooserUI</code>, + * returning the maximum size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The maximum size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getMaximumSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getMaximumSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getMaximumSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getAccessibleChildrenCount(JComponent)} method + * for all the UI delegates managed by this <code>MultiColorChooserUI</code>, + * returning the count for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The count returned by the UI delegate from the primary + * look and feel. + */ + public int getAccessibleChildrenCount(JComponent c) + { + int result = 0; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getAccessibleChildrenCount(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* int ignored = */ ui.getAccessibleChildrenCount(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getAccessibleChild(JComponent, int)} method + * for all the UI delegates managed by this <code>MultiColorChooserUI</code>, + * returning the child for the UI delegate from the primary look and + * feel. + * + * @param c the component + * @param i the child index. + * + * @return The child returned by the UI delegate from the primary + * look and feel. + */ + public Accessible getAccessibleChild(JComponent c, int i) + { + Accessible result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getAccessibleChild(c, i); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Accessible ignored = */ ui.getAccessibleChild(c, i); + } + return result; + } + +} diff --git a/libjava/classpath/javax/swing/plaf/multi/MultiComboBoxUI.java b/libjava/classpath/javax/swing/plaf/multi/MultiComboBoxUI.java new file mode 100644 index 0000000..05279d7 --- /dev/null +++ b/libjava/classpath/javax/swing/plaf/multi/MultiComboBoxUI.java @@ -0,0 +1,427 @@ +/* MultiComboBoxUI.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.swing.plaf.multi; + +import java.awt.Dimension; +import java.awt.Graphics; +import java.util.Iterator; +import java.util.Vector; + +import javax.accessibility.Accessible; +import javax.swing.JComboBox; +import javax.swing.JComponent; +import javax.swing.LookAndFeel; +import javax.swing.UIManager; +import javax.swing.plaf.ComboBoxUI; +import javax.swing.plaf.ComponentUI; + +/** + * A UI delegate that that coordinates multiple {@link ComboBoxUI} + * instances, one from the primary look and feel, and one or more from the + * auxiliary look and feel(s). + * + * @see UIManager#addAuxiliaryLookAndFeel(LookAndFeel) + */ +public class MultiComboBoxUI extends ComboBoxUI +{ + + /** A list of references to the actual component UIs. */ + protected Vector uis; + + /** + * Creates a new <code>MultiComboBoxUI</code> instance. + * + * @see #createUI(JComponent) + */ + public MultiComboBoxUI() + { + uis = new Vector(); + } + + /** + * Creates a delegate object for the specified component. If any auxiliary + * look and feels support this component, a <code>MultiComboBoxUI</code> + * is returned, otherwise the UI from the default look and feel is returned. + * + * @param target the component. + * + * @see MultiLookAndFeel#createUIs(ComponentUI, Vector, JComponent) + */ + public static ComponentUI createUI(JComponent target) + { + MultiComboBoxUI mui = new MultiComboBoxUI(); + return MultiLookAndFeel.createUIs(mui, mui.uis, target); + } + + /** + * Calls the {@link ComponentUI#installUI(JComponent)} method for all + * the UI delegates managed by this <code>MultiComboBoxUI</code>. + * + * @param c the component. + */ + public void installUI(JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.installUI(c); + } + } + + /** + * Calls the {@link ComponentUI#uninstallUI(JComponent)} method for all + * the UI delegates managed by this <code>MultiComboBoxUI</code>. + * + * @param c the component. + */ + public void uninstallUI(JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.uninstallUI(c); + } + } + + /** + * Returns an array containing the UI delegates managed by this + * <code>MultiComboBoxUI</code>. The first item in the array is always + * the UI delegate from the installed default look and feel. + * + * @return An array of UI delegates. + */ + public ComponentUI[] getUIs() + { + return MultiLookAndFeel.uisToArray(uis); + } + + /** + * Calls the {@link ComponentUI#contains(JComponent, int, int)} method for all + * the UI delegates managed by this <code>MultiComboBoxUI</code>, + * returning the result for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * @param x the x-coordinate. + * @param y the y-coordinate. + * + * @return <code>true</code> if the specified (x, y) coordinate falls within + * the bounds of the component as rendered by the UI delegate in the + * primary look and feel, and <code>false</code> otherwise. + */ + public boolean contains(JComponent c, int x, int y) + { + boolean result = false; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.contains(c, x, y); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* boolean ignored = */ ui.contains(c, x, y); + } + return result; + } + + /** + * Calls the {@link ComponentUI#update(Graphics, JComponent)} method for all + * the UI delegates managed by this <code>MultiComboBoxUI</code>. + * + * @param g the graphics device. + * @param c the component. + */ + public void update(Graphics g, JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.update(g, c); + } + } + + /** + * Calls the <code>paint(Graphics, JComponent)</code> method for all the UI + * delegates managed by this <code>MultiComboBoxUI</code>. + * + * @param g the graphics device. + * @param c the component. + */ + public void paint(Graphics g, JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.paint(g, c); + } + } + + /** + * Calls the {@link ComponentUI#getPreferredSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiComboBoxUI</code>, + * returning the preferred size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The preferred size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getPreferredSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getPreferredSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getPreferredSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getMinimumSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiComboBoxUI</code>, + * returning the minimum size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The minimum size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getMinimumSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getMinimumSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getMinimumSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getMaximumSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiComboBoxUI</code>, + * returning the maximum size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The maximum size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getMaximumSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getMaximumSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getMaximumSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getAccessibleChildrenCount(JComponent)} method + * for all the UI delegates managed by this <code>MultiComboBoxUI</code>, + * returning the count for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The count returned by the UI delegate from the primary + * look and feel. + */ + public int getAccessibleChildrenCount(JComponent c) + { + int result = 0; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getAccessibleChildrenCount(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* int ignored = */ ui.getAccessibleChildrenCount(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getAccessibleChild(JComponent, int)} method + * for all the UI delegates managed by this <code>MultiComboBoxUI</code>, + * returning the child for the UI delegate from the primary look and + * feel. + * + * @param c the component + * @param i the child index. + * + * @return The child returned by the UI delegate from the primary + * look and feel. + */ + public Accessible getAccessibleChild(JComponent c, int i) + { + Accessible result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getAccessibleChild(c, i); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Accessible ignored = */ ui.getAccessibleChild(c, i); + } + return result; + } + + /** + * Calls the {@link ComboBoxUI#setPopupVisible(JComboBox, boolean)} method + * for all the UI delegates managed by this <code>MultiComboBoxUI</code>. + * + * @param c the component. + * @param visible the visible state. + */ + public void setPopupVisible(JComboBox c, boolean visible) { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComboBoxUI ui = (ComboBoxUI) iterator.next(); + ui.setPopupVisible(c, visible); + } + } + + /** + * Calls the {@link ComboBoxUI#isPopupVisible(JComboBox)} method for all + * the UI delegates managed by this <code>MultiComboBoxUI</code>, + * returning the result for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The result for the UI delegate from the primary look and feel. + */ + public boolean isPopupVisible(JComboBox c) { + boolean result = false; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComboBoxUI ui = (ComboBoxUI) iterator.next(); + result = ui.isPopupVisible(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComboBoxUI ui = (ComboBoxUI) iterator.next(); + /* boolean ignored = */ ui.isPopupVisible(c); + } + return result; + } + + /** + * Calls the {@link ComboBoxUI#isFocusTraversable(JComboBox)} method for all + * the UI delegates managed by this <code>MultiComboBoxUI</code>, + * returning the result for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return <code>true</code> if the combo box is traversable according to the + * UI delegate in the primary look and feel, and <code>false</code> + * otherwise. + */ + public boolean isFocusTraversable(JComboBox c) { + boolean result = false; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComboBoxUI ui = (ComboBoxUI) iterator.next(); + result = ui.isFocusTraversable(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComboBoxUI ui = (ComboBoxUI) iterator.next(); + /* boolean ignored = */ ui.isFocusTraversable(c); + } + return result; + } + +} diff --git a/libjava/classpath/javax/swing/plaf/multi/MultiDesktopIconUI.java b/libjava/classpath/javax/swing/plaf/multi/MultiDesktopIconUI.java new file mode 100644 index 0000000..186ce32 --- /dev/null +++ b/libjava/classpath/javax/swing/plaf/multi/MultiDesktopIconUI.java @@ -0,0 +1,352 @@ +/* MultiDesktopIconUI.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.swing.plaf.multi; + +import java.awt.Dimension; +import java.awt.Graphics; +import java.util.Iterator; +import java.util.Vector; + +import javax.accessibility.Accessible; +import javax.swing.JComponent; +import javax.swing.LookAndFeel; +import javax.swing.UIManager; +import javax.swing.plaf.ComponentUI; +import javax.swing.plaf.DesktopIconUI; + +/** + * A UI delegate that that coordinates multiple {@link DesktopIconUI} + * instances, one from the primary look and feel, and one or more from the + * auxiliary look and feel(s). + * + * @see UIManager#addAuxiliaryLookAndFeel(LookAndFeel) + */ +public class MultiDesktopIconUI extends DesktopIconUI +{ + + /** A list of references to the actual component UIs. */ + protected Vector uis; + + /** + * Creates a new <code>MultiDesktopIconUI</code> instance. + * + * @see #createUI(JComponent) + */ + public MultiDesktopIconUI() + { + uis = new Vector(); + } + + /** + * Creates a delegate object for the specified component. If any auxiliary + * look and feels support this component, a <code>MultiDesktopIconUI</code> is + * returned, otherwise the UI from the default look and feel is returned. + * + * @param target the component. + * + * @see MultiLookAndFeel#createUIs(ComponentUI, Vector, JComponent) + */ + public static ComponentUI createUI(JComponent target) + { + MultiDesktopIconUI mui = new MultiDesktopIconUI(); + return MultiLookAndFeel.createUIs(mui, mui.uis, target); + } + + /** + * Calls the {@link ComponentUI#installUI(JComponent)} method for all + * the UI delegates managed by this <code>MultiDesktopIconUI</code>. + * + * @param c the component. + */ + public void installUI(JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.installUI(c); + } + } + + /** + * Calls the {@link ComponentUI#uninstallUI(JComponent)} method for all + * the UI delegates managed by this <code>MultiDesktopIconUI</code>. + * + * @param c the component. + */ + public void uninstallUI(JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.uninstallUI(c); + } + } + + /** + * Returns an array containing the UI delegates managed by this + * <code>MultiDesktopIconUI</code>. The first item in the array is always + * the UI delegate from the installed default look and feel. + * + * @return An array of UI delegates. + */ + public ComponentUI[] getUIs() + { + return MultiLookAndFeel.uisToArray(uis); + } + + /** + * Calls the {@link ComponentUI#contains(JComponent, int, int)} method for all + * the UI delegates managed by this <code>MultiDesktopIconUI</code>, + * returning the result for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * @param x the x-coordinate. + * @param y the y-coordinate. + * + * @return <code>true</code> if the specified (x, y) coordinate falls within + * the bounds of the component as rendered by the UI delegate in the + * primary look and feel, and <code>false</code> otherwise. + */ + public boolean contains(JComponent c, int x, int y) + { + boolean result = false; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.contains(c, x, y); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* boolean ignored = */ ui.contains(c, x, y); + } + return result; + } + + /** + * Calls the {@link ComponentUI#update(Graphics, JComponent)} method for all + * the UI delegates managed by this <code>MultiDesktopIconUI</code>. + * + * @param g the graphics device. + * @param c the component. + */ + public void update(Graphics g, JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.update(g, c); + } + } + + /** + * Calls the <code>paint(Graphics, JComponent)</code> method for all the UI + * delegates managed by this <code>MultiDesktopIconUI</code>. + * + * @param g the graphics device. + * @param c the component. + */ + public void paint(Graphics g, JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.paint(g, c); + } + } + + /** + * Calls the {@link ComponentUI#getPreferredSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiDesktopIconUI</code>, + * returning the preferred size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The preferred size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getPreferredSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getPreferredSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getPreferredSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getMinimumSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiDesktopIconUI</code>, + * returning the minimum size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The minimum size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getMinimumSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getMinimumSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getMinimumSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getMaximumSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiDesktopIconUI</code>, + * returning the maximum size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The maximum size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getMaximumSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getMaximumSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getMaximumSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getAccessibleChildrenCount(JComponent)} method + * for all the UI delegates managed by this <code>MultiDesktopIconUI</code>, + * returning the count for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The count returned by the UI delegate from the primary + * look and feel. + */ + public int getAccessibleChildrenCount(JComponent c) + { + int result = 0; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getAccessibleChildrenCount(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* int ignored = */ ui.getAccessibleChildrenCount(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getAccessibleChild(JComponent, int)} method + * for all the UI delegates managed by this <code>MultiDesktopIconUI</code>, + * returning the child for the UI delegate from the primary look and + * feel. + * + * @param c the component + * @param i the child index. + * + * @return The child returned by the UI delegate from the primary + * look and feel. + */ + public Accessible getAccessibleChild(JComponent c, int i) + { + Accessible result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getAccessibleChild(c, i); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Accessible ignored = */ ui.getAccessibleChild(c, i); + } + return result; + } + +} diff --git a/libjava/classpath/javax/swing/plaf/multi/MultiDesktopPaneUI.java b/libjava/classpath/javax/swing/plaf/multi/MultiDesktopPaneUI.java new file mode 100644 index 0000000..d48fb2b --- /dev/null +++ b/libjava/classpath/javax/swing/plaf/multi/MultiDesktopPaneUI.java @@ -0,0 +1,352 @@ +/* MultiDesktopIconUI.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.swing.plaf.multi; + +import java.awt.Dimension; +import java.awt.Graphics; +import java.util.Iterator; +import java.util.Vector; + +import javax.accessibility.Accessible; +import javax.swing.JComponent; +import javax.swing.LookAndFeel; +import javax.swing.UIManager; +import javax.swing.plaf.ComponentUI; +import javax.swing.plaf.DesktopPaneUI; + +/** + * A UI delegate that that coordinates multiple {@link DesktopPaneUI} + * instances, one from the primary look and feel, and one or more from the + * auxiliary look and feel(s). + * + * @see UIManager#addAuxiliaryLookAndFeel(LookAndFeel) + */ +public class MultiDesktopPaneUI extends DesktopPaneUI +{ + + /** A list of references to the actual component UIs. */ + protected Vector uis; + + /** + * Creates a new <code>MultiDesktopPaneUI</code> instance. + * + * @see #createUI(JComponent) + */ + public MultiDesktopPaneUI() + { + uis = new Vector(); + } + + /** + * Creates a delegate object for the specified component. If any auxiliary + * look and feels support this component, a <code>MultiDesktopPaneUI</code> is + * returned, otherwise the UI from the default look and feel is returned. + * + * @param target the component. + * + * @see MultiLookAndFeel#createUIs(ComponentUI, Vector, JComponent) + */ + public static ComponentUI createUI(JComponent target) + { + MultiDesktopPaneUI mui = new MultiDesktopPaneUI(); + return MultiLookAndFeel.createUIs(mui, mui.uis, target); + } + + /** + * Calls the {@link ComponentUI#installUI(JComponent)} method for all + * the UI delegates managed by this <code>MultiDesktopPaneUI</code>. + * + * @param c the component. + */ + public void installUI(JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.installUI(c); + } + } + + /** + * Calls the {@link ComponentUI#uninstallUI(JComponent)} method for all + * the UI delegates managed by this <code>MultiDesktopPaneUI</code>. + * + * @param c the component. + */ + public void uninstallUI(JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.uninstallUI(c); + } + } + + /** + * Returns an array containing the UI delegates managed by this + * <code>MultiDesktopPaneUI</code>. The first item in the array is always + * the UI delegate from the installed default look and feel. + * + * @return An array of UI delegates. + */ + public ComponentUI[] getUIs() + { + return MultiLookAndFeel.uisToArray(uis); + } + + /** + * Calls the {@link ComponentUI#contains(JComponent, int, int)} method for all + * the UI delegates managed by this <code>MultiDesktopPaneUI</code>, + * returning the result for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * @param x the x-coordinate. + * @param y the y-coordinate. + * + * @return <code>true</code> if the specified (x, y) coordinate falls within + * the bounds of the component as rendered by the UI delegate in the + * primary look and feel, and <code>false</code> otherwise. + */ + public boolean contains(JComponent c, int x, int y) + { + boolean result = false; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.contains(c, x, y); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* boolean ignored = */ ui.contains(c, x, y); + } + return result; + } + + /** + * Calls the {@link ComponentUI#update(Graphics, JComponent)} method for all + * the UI delegates managed by this <code>MultiDesktopPaneUI</code>. + * + * @param g the graphics device. + * @param c the component. + */ + public void update(Graphics g, JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.update(g, c); + } + } + + /** + * Calls the <code>paint(Graphics, JComponent)</code> method for all the UI + * delegates managed by this <code>MultiDesktopPaneUI</code>. + * + * @param g the graphics device. + * @param c the component. + */ + public void paint(Graphics g, JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.paint(g, c); + } + } + + /** + * Calls the {@link ComponentUI#getPreferredSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiDesktopPaneUI</code>, + * returning the preferred size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The preferred size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getPreferredSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getPreferredSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getPreferredSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getMinimumSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiDesktopPaneUI</code>, + * returning the minimum size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The minimum size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getMinimumSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getMinimumSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getMinimumSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getMaximumSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiDesktopPaneUI</code>, + * returning the maximum size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The maximum size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getMaximumSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getMaximumSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getMaximumSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getAccessibleChildrenCount(JComponent)} method + * for all the UI delegates managed by this <code>MultiDesktopPaneUI</code>, + * returning the count for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The count returned by the UI delegate from the primary + * look and feel. + */ + public int getAccessibleChildrenCount(JComponent c) + { + int result = 0; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getAccessibleChildrenCount(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* int ignored = */ ui.getAccessibleChildrenCount(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getAccessibleChild(JComponent, int)} method + * for all the UI delegates managed by this <code>MultiDesktopPaneUI</code>, + * returning the child for the UI delegate from the primary look and + * feel. + * + * @param c the component + * @param i the child index. + * + * @return The child returned by the UI delegate from the primary + * look and feel. + */ + public Accessible getAccessibleChild(JComponent c, int i) + { + Accessible result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getAccessibleChild(c, i); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Accessible ignored = */ ui.getAccessibleChild(c, i); + } + return result; + } + +} diff --git a/libjava/classpath/javax/swing/plaf/multi/MultiFileChooserUI.java b/libjava/classpath/javax/swing/plaf/multi/MultiFileChooserUI.java new file mode 100644 index 0000000..6f88260 --- /dev/null +++ b/libjava/classpath/javax/swing/plaf/multi/MultiFileChooserUI.java @@ -0,0 +1,505 @@ +/* MultiFileChooserUI.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.swing.plaf.multi; + +import java.awt.Dimension; +import java.awt.Graphics; +import java.io.File; +import java.util.Iterator; +import java.util.Vector; + +import javax.accessibility.Accessible; +import javax.swing.JComponent; +import javax.swing.JFileChooser; +import javax.swing.LookAndFeel; +import javax.swing.UIManager; +import javax.swing.filechooser.FileFilter; +import javax.swing.filechooser.FileView; +import javax.swing.plaf.ComponentUI; +import javax.swing.plaf.FileChooserUI; + +/** + * A UI delegate that that coordinates multiple {@link FileChooserUI} + * instances, one from the primary look and feel, and one or more from the + * auxiliary look and feel(s). + * + * @see UIManager#addAuxiliaryLookAndFeel(LookAndFeel) + */ +public class MultiFileChooserUI extends FileChooserUI +{ + + /** A list of references to the actual component UIs. */ + protected Vector uis; + + /** + * Creates a new <code>MultiFileChooserUI</code> instance. + * + * @see #createUI(JComponent) + */ + public MultiFileChooserUI() + { + uis = new Vector(); + } + + /** + * Creates a delegate object for the specified component. If any auxiliary + * look and feels support this component, a <code>MultiFileChooserUI</code> is + * returned, otherwise the UI from the default look and feel is returned. + * + * @param target the component. + * + * @see MultiLookAndFeel#createUIs(ComponentUI, Vector, JComponent) + */ + public static ComponentUI createUI(JComponent target) + { + MultiFileChooserUI mui = new MultiFileChooserUI(); + return MultiLookAndFeel.createUIs(mui, mui.uis, target); + } + + /** + * Calls the {@link ComponentUI#installUI(JComponent)} method for all + * the UI delegates managed by this <code>MultiFileChooserUI</code>. + * + * @param c the component. + */ + public void installUI(JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.installUI(c); + } + } + + /** + * Calls the {@link ComponentUI#uninstallUI(JComponent)} method for all + * the UI delegates managed by this <code>MultiFileChooserUI</code>. + * + * @param c the component. + */ + public void uninstallUI(JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.uninstallUI(c); + } + } + + /** + * Returns an array containing the UI delegates managed by this + * <code>MultiFileChooserUI</code>. The first item in the array is always + * the UI delegate from the installed default look and feel. + * + * @return An array of UI delegates. + */ + public ComponentUI[] getUIs() + { + return MultiLookAndFeel.uisToArray(uis); + } + + /** + * Calls the {@link ComponentUI#contains(JComponent, int, int)} method for all + * the UI delegates managed by this <code>MultiFileChooserUI</code>, + * returning the result for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * @param x the x-coordinate. + * @param y the y-coordinate. + * + * @return <code>true</code> if the specified (x, y) coordinate falls within + * the bounds of the component as rendered by the UI delegate in the + * primary look and feel, and <code>false</code> otherwise. + */ + public boolean contains(JComponent c, int x, int y) + { + boolean result = false; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.contains(c, x, y); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* boolean ignored = */ ui.contains(c, x, y); + } + return result; + } + + /** + * Calls the {@link ComponentUI#update(Graphics, JComponent)} method for all + * the UI delegates managed by this <code>MultiFileChooserUI</code>. + * + * @param g the graphics device. + * @param c the component. + */ + public void update(Graphics g, JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.update(g, c); + } + } + + /** + * Calls the <code>paint(Graphics, JComponent)</code> method for all the UI + * delegates managed by this <code>MultiFileChooserUI</code>. + * + * @param g the graphics device. + * @param c the component. + */ + public void paint(Graphics g, JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.paint(g, c); + } + } + + /** + * Calls the {@link ComponentUI#getPreferredSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiFileChooserUI</code>, + * returning the preferred size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The preferred size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getPreferredSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getPreferredSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getPreferredSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getMinimumSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiFileChooserUI</code>, + * returning the minimum size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The minimum size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getMinimumSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getMinimumSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getMinimumSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getMaximumSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiFileChooserUI</code>, + * returning the maximum size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The maximum size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getMaximumSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getMaximumSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getMaximumSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getAccessibleChildrenCount(JComponent)} method + * for all the UI delegates managed by this <code>MultiFileChooserUI</code>, + * returning the count for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The count returned by the UI delegate from the primary + * look and feel. + */ + public int getAccessibleChildrenCount(JComponent c) + { + int result = 0; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getAccessibleChildrenCount(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* int ignored = */ ui.getAccessibleChildrenCount(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getAccessibleChild(JComponent, int)} method + * for all the UI delegates managed by this <code>MultiFileChooserUI</code>, + * returning the child for the UI delegate from the primary look and + * feel. + * + * @param c the component + * @param i the child index. + * + * @return The child returned by the UI delegate from the primary + * look and feel. + */ + public Accessible getAccessibleChild(JComponent c, int i) + { + Accessible result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getAccessibleChild(c, i); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Accessible ignored = */ ui.getAccessibleChild(c, i); + } + return result; + } + + /** + * Calls the {@link FileChooserUI#getAcceptAllFileFilter(JFileChooser)} method + * for all the UI delegates managed by this <code>MultiFileChooserUI</code>, + * returning the filter for the UI delegate from the primary look and + * feel. + * + * @param chooser the file chooser. + * + * @return The filter returned by the UI delegate from the primary + * look and feel. + */ + public FileFilter getAcceptAllFileFilter(JFileChooser chooser) { + FileFilter result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + FileChooserUI ui = (FileChooserUI) iterator.next(); + result = ui.getAcceptAllFileFilter(chooser); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + FileChooserUI ui = (FileChooserUI) iterator.next(); + /* FileFilter ignored = */ ui.getAcceptAllFileFilter(chooser); + } + return result; + } + + /** + * Calls the {@link FileChooserUI#getFileView(JFileChooser)} method + * for all the UI delegates managed by this <code>MultiFileChooserUI</code>, + * returning the view for the UI delegate from the primary look and + * feel. + * + * @param chooser the file chooser. + * + * @return The view returned by the UI delegate from the primary + * look and feel. + */ + public FileView getFileView(JFileChooser chooser) { + FileView result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + FileChooserUI ui = (FileChooserUI) iterator.next(); + result = ui.getFileView(chooser); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + FileChooserUI ui = (FileChooserUI) iterator.next(); + /* FileView ignored = */ ui.getFileView(chooser); + } + return result; + } + + /** + * Calls the {@link FileChooserUI#getApproveButtonText(JFileChooser)} method + * for all the UI delegates managed by this <code>MultiFileChooserUI</code>, + * returning the text for the UI delegate from the primary look and + * feel. + * + * @param chooser the file chooser. + * + * @return The text returned by the UI delegate from the primary + * look and feel. + */ + public String getApproveButtonText(JFileChooser chooser) { + String result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + FileChooserUI ui = (FileChooserUI) iterator.next(); + result = ui.getApproveButtonText(chooser); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + FileChooserUI ui = (FileChooserUI) iterator.next(); + /* String ignored = */ ui.getApproveButtonText(chooser); + } + return result; + } + + /** + * Calls the {@link FileChooserUI#getDialogTitle(JFileChooser)} method + * for all the UI delegates managed by this <code>MultiFileChooserUI</code>, + * returning the title for the UI delegate from the primary look and + * feel. + * + * @param chooser the file chooser. + * + * @return The title returned by the UI delegate from the primary + * look and feel. + */ + public String getDialogTitle(JFileChooser chooser) { + String result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + FileChooserUI ui = (FileChooserUI) iterator.next(); + result = ui.getDialogTitle(chooser); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + FileChooserUI ui = (FileChooserUI) iterator.next(); + /* String ignored = */ ui.getDialogTitle(chooser); + } + return result; + } + + /** + * Calls the {@link FileChooserUI#rescanCurrentDirectory(JFileChooser)} + * method for all the UI delegates managed by this + * <code>MultiFileChooserUI</code>. + * + * @param chooser the file chooser. + */ + public void rescanCurrentDirectory(JFileChooser chooser) { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + FileChooserUI ui = (FileChooserUI) iterator.next(); + ui.rescanCurrentDirectory(chooser); + } + } + + /** + * Calls the {@link FileChooserUI#ensureFileIsVisible(JFileChooser, File)} + * method for all the UI delegates managed by this + * <code>MultiFileChooserUI</code>. + * + * @param chooser the file chooser. + * @param file the file. + */ + public void ensureFileIsVisible(JFileChooser chooser, File file) { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + FileChooserUI ui = (FileChooserUI) iterator.next(); + ui.ensureFileIsVisible(chooser, file); + } + } + +} diff --git a/libjava/classpath/javax/swing/plaf/multi/MultiInternalFrameUI.java b/libjava/classpath/javax/swing/plaf/multi/MultiInternalFrameUI.java new file mode 100644 index 0000000..01d1df6 --- /dev/null +++ b/libjava/classpath/javax/swing/plaf/multi/MultiInternalFrameUI.java @@ -0,0 +1,353 @@ +/* MultiInternalFrameUI.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.swing.plaf.multi; + +import java.awt.Dimension; +import java.awt.Graphics; +import java.util.Iterator; +import java.util.Vector; + +import javax.accessibility.Accessible; +import javax.swing.JComponent; +import javax.swing.LookAndFeel; +import javax.swing.UIManager; +import javax.swing.plaf.ComponentUI; +import javax.swing.plaf.InternalFrameUI; + +/** + * A UI delegate that that coordinates multiple {@link InternalFrameUI} + * instances, one from the primary look and feel, and one or more from the + * auxiliary look and feel(s). + * + * @see UIManager#addAuxiliaryLookAndFeel(LookAndFeel) + */ +public class MultiInternalFrameUI extends InternalFrameUI +{ + + /** A list of references to the actual component UIs. */ + protected Vector uis; + + /** + * Creates a new <code>MultiInternalFrameUI</code> instance. + * + * @see #createUI(JComponent) + */ + public MultiInternalFrameUI() + { + uis = new Vector(); + } + + /** + * Creates a delegate object for the specified component. If any auxiliary + * look and feels support this component, a <code>MultiInternalFrameUI</code> + * is returned, otherwise the UI from the default look and feel is returned. + * + * @param target the component. + * + * @see MultiLookAndFeel#createUIs(ComponentUI, Vector, JComponent) + */ + public static ComponentUI createUI(JComponent target) + { + MultiInternalFrameUI mui = new MultiInternalFrameUI(); + return MultiLookAndFeel.createUIs(mui, mui.uis, target); + } + + + /** + * Calls the {@link ComponentUI#installUI(JComponent)} method for all + * the UI delegates managed by this <code>MultiInternalFrameUI</code>. + * + * @param c the component. + */ + public void installUI(JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.installUI(c); + } + } + + /** + * Calls the {@link ComponentUI#uninstallUI(JComponent)} method for all + * the UI delegates managed by this <code>MultiInternalFrameUI</code>. + * + * @param c the component. + */ + public void uninstallUI(JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.uninstallUI(c); + } + } + + /** + * Returns an array containing the UI delegates managed by this + * <code>MultiInternalFrameUI</code>. The first item in the array is always + * the UI delegate from the installed default look and feel. + * + * @return An array of UI delegates. + */ + public ComponentUI[] getUIs() + { + return MultiLookAndFeel.uisToArray(uis); + } + + /** + * Calls the {@link ComponentUI#contains(JComponent, int, int)} method for all + * the UI delegates managed by this <code>MultiInternalFrameUI</code>, + * returning the result for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * @param x the x-coordinate. + * @param y the y-coordinate. + * + * @return <code>true</code> if the specified (x, y) coordinate falls within + * the bounds of the component as rendered by the UI delegate in the + * primary look and feel, and <code>false</code> otherwise. + */ + public boolean contains(JComponent c, int x, int y) + { + boolean result = false; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.contains(c, x, y); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* boolean ignored = */ ui.contains(c, x, y); + } + return result; + } + + /** + * Calls the {@link ComponentUI#update(Graphics, JComponent)} method for all + * the UI delegates managed by this <code>MultiInternalFrameUI</code>. + * + * @param g the graphics device. + * @param c the component. + */ + public void update(Graphics g, JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.update(g, c); + } + } + + /** + * Calls the <code>paint(Graphics, JComponent)</code> method for all the UI + * delegates managed by this <code>MultiInternalFrameUI</code>. + * + * @param g the graphics device. + * @param c the component. + */ + public void paint(Graphics g, JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.paint(g, c); + } + } + + /** + * Calls the {@link ComponentUI#getPreferredSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiInternalFrameUI</code>, + * returning the preferred size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The preferred size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getPreferredSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getPreferredSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getPreferredSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getMinimumSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiInternalFrameUI</code>, + * returning the minimum size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The minimum size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getMinimumSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getMinimumSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getMinimumSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getMaximumSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiInternalFrameUI</code>, + * returning the maximum size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The maximum size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getMaximumSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getMaximumSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getMaximumSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getAccessibleChildrenCount(JComponent)} method + * for all the UI delegates managed by this <code>MultiInternalFrameUI</code>, + * returning the count for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The count returned by the UI delegate from the primary + * look and feel. + */ + public int getAccessibleChildrenCount(JComponent c) + { + int result = 0; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getAccessibleChildrenCount(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* int ignored = */ ui.getAccessibleChildrenCount(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getAccessibleChild(JComponent, int)} method + * for all the UI delegates managed by this <code>MultiInternalFrameUI</code>, + * returning the child for the UI delegate from the primary look and + * feel. + * + * @param c the component + * @param i the child index. + * + * @return The child returned by the UI delegate from the primary + * look and feel. + */ + public Accessible getAccessibleChild(JComponent c, int i) + { + Accessible result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getAccessibleChild(c, i); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Accessible ignored = */ ui.getAccessibleChild(c, i); + } + return result; + } + +} diff --git a/libjava/classpath/javax/swing/plaf/multi/MultiLabelUI.java b/libjava/classpath/javax/swing/plaf/multi/MultiLabelUI.java new file mode 100644 index 0000000..ba5b9d4 --- /dev/null +++ b/libjava/classpath/javax/swing/plaf/multi/MultiLabelUI.java @@ -0,0 +1,352 @@ +/* MultiLabelUI.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.swing.plaf.multi; + +import java.awt.Dimension; +import java.awt.Graphics; +import java.util.Iterator; +import java.util.Vector; + +import javax.accessibility.Accessible; +import javax.swing.JComponent; +import javax.swing.LookAndFeel; +import javax.swing.UIManager; +import javax.swing.plaf.ComponentUI; +import javax.swing.plaf.LabelUI; + +/** + * A UI delegate that that coordinates multiple {@link LabelUI} + * instances, one from the primary look and feel, and one or more from the + * auxiliary look and feel(s). + * + * @see UIManager#addAuxiliaryLookAndFeel(LookAndFeel) + */ +public class MultiLabelUI extends LabelUI +{ + + /** A list of references to the actual component UIs. */ + protected Vector uis; + + /** + * Creates a new <code>MultiLabelUI</code> instance. + * + * @see #createUI(JComponent) + */ + public MultiLabelUI() + { + uis = new Vector(); + } + + /** + * Creates a delegate object for the specified component. If any auxiliary + * look and feels support this component, a <code>MultiLabelUI</code> is + * returned, otherwise the UI from the default look and feel is returned. + * + * @param target the component. + * + * @see MultiLookAndFeel#createUIs(ComponentUI, Vector, JComponent) + */ + public static ComponentUI createUI(JComponent target) + { + MultiLabelUI mui = new MultiLabelUI(); + return MultiLookAndFeel.createUIs(mui, mui.uis, target); + } + + /** + * Calls the {@link ComponentUI#installUI(JComponent)} method for all + * the UI delegates managed by this <code>MultiLabelUI</code>. + * + * @param c the component. + */ + public void installUI(JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.installUI(c); + } + } + + /** + * Calls the {@link ComponentUI#uninstallUI(JComponent)} method for all + * the UI delegates managed by this <code>MultiLabelUI</code>. + * + * @param c the component. + */ + public void uninstallUI(JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.uninstallUI(c); + } + } + + /** + * Returns an array containing the UI delegates managed by this + * <code>MultiLabelUI</code>. The first item in the array is always + * the UI delegate from the installed default look and feel. + * + * @return An array of UI delegates. + */ + public ComponentUI[] getUIs() + { + return MultiLookAndFeel.uisToArray(uis); + } + + /** + * Calls the {@link ComponentUI#contains(JComponent, int, int)} method for all + * the UI delegates managed by this <code>MultiLabelUI</code>, + * returning the result for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * @param x the x-coordinate. + * @param y the y-coordinate. + * + * @return <code>true</code> if the specified (x, y) coordinate falls within + * the bounds of the component as rendered by the UI delegate in the + * primary look and feel, and <code>false</code> otherwise. + */ + public boolean contains(JComponent c, int x, int y) + { + boolean result = false; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.contains(c, x, y); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* boolean ignored = */ ui.contains(c, x, y); + } + return result; + } + + /** + * Calls the {@link ComponentUI#update(Graphics, JComponent)} method for all + * the UI delegates managed by this <code>MultiLabelUI</code>. + * + * @param g the graphics device. + * @param c the component. + */ + public void update(Graphics g, JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.update(g, c); + } + } + + /** + * Calls the <code>paint(Graphics, JComponent)</code> method for all the UI + * delegates managed by this <code>MultiLabelUI</code>. + * + * @param g the graphics device. + * @param c the component. + */ + public void paint(Graphics g, JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.paint(g, c); + } + } + + /** + * Calls the {@link ComponentUI#getPreferredSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiLabelUI</code>, + * returning the preferred size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The preferred size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getPreferredSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getPreferredSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getPreferredSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getMinimumSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiLabelUI</code>, + * returning the minimum size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The minimum size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getMinimumSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getMinimumSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getMinimumSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getMaximumSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiLabelUI</code>, + * returning the maximum size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The maximum size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getMaximumSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getMaximumSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getMaximumSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getAccessibleChildrenCount(JComponent)} method + * for all the UI delegates managed by this <code>MultiLabelUI</code>, + * returning the count for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The count returned by the UI delegate from the primary + * look and feel. + */ + public int getAccessibleChildrenCount(JComponent c) + { + int result = 0; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getAccessibleChildrenCount(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* int ignored = */ ui.getAccessibleChildrenCount(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getAccessibleChild(JComponent, int)} method + * for all the UI delegates managed by this <code>MultiLabelUI</code>, + * returning the child for the UI delegate from the primary look and + * feel. + * + * @param c the component + * @param i the child index. + * + * @return The child returned by the UI delegate from the primary + * look and feel. + */ + public Accessible getAccessibleChild(JComponent c, int i) + { + Accessible result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getAccessibleChild(c, i); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Accessible ignored = */ ui.getAccessibleChild(c, i); + } + return result; + } + +} diff --git a/libjava/classpath/javax/swing/plaf/multi/MultiListUI.java b/libjava/classpath/javax/swing/plaf/multi/MultiListUI.java new file mode 100644 index 0000000..7350b45 --- /dev/null +++ b/libjava/classpath/javax/swing/plaf/multi/MultiListUI.java @@ -0,0 +1,446 @@ +/* MultiListUI.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.swing.plaf.multi; + +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.Point; +import java.awt.Rectangle; +import java.util.Iterator; +import java.util.Vector; + +import javax.accessibility.Accessible; +import javax.swing.JComponent; +import javax.swing.JList; +import javax.swing.LookAndFeel; +import javax.swing.UIManager; +import javax.swing.plaf.ComponentUI; +import javax.swing.plaf.ListUI; + +/** + * A UI delegate that that coordinates multiple {@link ListUI} + * instances, one from the primary look and feel, and one or more from the + * auxiliary look and feel(s). + * + * @see UIManager#addAuxiliaryLookAndFeel(LookAndFeel) + */ +public class MultiListUI extends ListUI +{ + + /** A list of references to the actual component UIs. */ + protected Vector uis; + + /** + * Creates a new <code>MultiListUI</code> instance. + * + * @see #createUI(JComponent) + */ + public MultiListUI() + { + uis = new Vector(); + } + + /** + * Creates a delegate object for the specified component. If any auxiliary + * look and feels support this component, a <code>MultiListUI</code> is + * returned, otherwise the UI from the default look and feel is returned. + * + * @param target the component. + * + * @see MultiLookAndFeel#createUIs(ComponentUI, Vector, JComponent) + */ + public static ComponentUI createUI(JComponent target) + { + MultiListUI mui = new MultiListUI(); + return MultiLookAndFeel.createUIs(mui, mui.uis, target); + } + + /** + * Calls the {@link ComponentUI#installUI(JComponent)} method for all + * the UI delegates managed by this <code>MultiListUI</code>. + * + * @param c the component. + */ + public void installUI(JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.installUI(c); + } + } + + /** + * Calls the {@link ComponentUI#uninstallUI(JComponent)} method for all + * the UI delegates managed by this <code>MultiListUI</code>. + * + * @param c the component. + */ + public void uninstallUI(JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.uninstallUI(c); + } + } + + /** + * Returns an array containing the UI delegates managed by this + * <code>MultiListUI</code>. The first item in the array is always + * the UI delegate from the installed default look and feel. + * + * @return An array of UI delegates. + */ + public ComponentUI[] getUIs() + { + return MultiLookAndFeel.uisToArray(uis); + } + + /** + * Calls the {@link ComponentUI#contains(JComponent, int, int)} method for all + * the UI delegates managed by this <code>MultiListUI</code>, + * returning the result for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * @param x the x-coordinate. + * @param y the y-coordinate. + * + * @return <code>true</code> if the specified (x, y) coordinate falls within + * the bounds of the component as rendered by the UI delegate in the + * primary look and feel, and <code>false</code> otherwise. + */ + public boolean contains(JComponent c, int x, int y) + { + boolean result = false; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.contains(c, x, y); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* boolean ignored = */ ui.contains(c, x, y); + } + return result; + } + + /** + * Calls the {@link ComponentUI#update(Graphics, JComponent)} method for all + * the UI delegates managed by this <code>MultiListUI</code>. + * + * @param g the graphics device. + * @param c the component. + */ + public void update(Graphics g, JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.update(g, c); + } + } + + /** + * Calls the <code>paint(Graphics, JComponent)</code> method for all the UI + * delegates managed by this <code>MultiListUI</code>. + * + * @param g the graphics device. + * @param c the component. + */ + public void paint(Graphics g, JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.paint(g, c); + } + } + + /** + * Calls the {@link ComponentUI#getPreferredSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiListUI</code>, + * returning the preferred size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The preferred size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getPreferredSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getPreferredSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getPreferredSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getMinimumSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiListUI</code>, + * returning the minimum size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The minimum size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getMinimumSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getMinimumSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getMinimumSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getMaximumSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiListUI</code>, + * returning the maximum size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The maximum size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getMaximumSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getMaximumSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getMaximumSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getAccessibleChildrenCount(JComponent)} method + * for all the UI delegates managed by this <code>MultiListUI</code>, + * returning the count for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The count returned by the UI delegate from the primary + * look and feel. + */ + public int getAccessibleChildrenCount(JComponent c) + { + int result = 0; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getAccessibleChildrenCount(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* int ignored = */ ui.getAccessibleChildrenCount(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getAccessibleChild(JComponent, int)} method + * for all the UI delegates managed by this <code>MultiListUI</code>, + * returning the child for the UI delegate from the primary look and + * feel. + * + * @param c the component + * @param i the child index. + * + * @return The child returned by the UI delegate from the primary + * look and feel. + */ + public Accessible getAccessibleChild(JComponent c, int i) + { + Accessible result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getAccessibleChild(c, i); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Accessible ignored = */ ui.getAccessibleChild(c, i); + } + return result; + } + + /** + * Calls the {@link ListUI#locationToIndex(JList, Point)} method for all + * the UI delegates managed by this <code>MultiListUI</code>, + * returning the index for the UI delegate from the primary look and + * feel. + * + * @param list the list. + * @param location the location. + * + * @return The index returned by the UI delegate from the primary + * look and feel. + */ + public int locationToIndex(JList list, Point location) { + int result = 0; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ListUI ui = (ListUI) iterator.next(); + result = ui.locationToIndex(list, location); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ListUI ui = (ListUI) iterator.next(); + /* int ignored = */ ui.locationToIndex(list, location); + } + return result; + } + + /** + * Calls the {@link ListUI#indexToLocation(JList, int)} method for all + * the UI delegates managed by this <code>MultiListUI</code>, + * returning the location for the UI delegate from the primary look and + * feel. + * + * @param list the list. + * @param index the index. + * + * @return The location returned by the UI delegate from the primary + * look and feel. + */ + public Point indexToLocation(JList list, int index) { + Point result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ListUI ui = (ListUI) iterator.next(); + result = ui.indexToLocation(list, index); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ListUI ui = (ListUI) iterator.next(); + /* Point ignored = */ ui.indexToLocation(list, index); + } + return result; + } + + /** + * Calls the {@link ListUI#getCellBounds(JList, int, int)} method for all + * the UI delegates managed by this <code>MultiListUI</code>, + * returning the bounds for the UI delegate from the primary look and + * feel. + * + * @param list the list. + * @param index1 the first index. + * @param index2 the second index. + * + * @return The bounds returned by the UI delegate from the primary + * look and feel. + */ + public Rectangle getCellBounds(JList list, int index1, int index2) { + Rectangle result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ListUI ui = (ListUI) iterator.next(); + result = ui.getCellBounds(list, index1, index2); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ListUI ui = (ListUI) iterator.next(); + /* Rectangle ignored = */ ui.getCellBounds(list, index1, index2); + } + return result; + } + +} diff --git a/libjava/classpath/javax/swing/plaf/multi/MultiLookAndFeel.java b/libjava/classpath/javax/swing/plaf/multi/MultiLookAndFeel.java new file mode 100644 index 0000000..a70a8ff --- /dev/null +++ b/libjava/classpath/javax/swing/plaf/multi/MultiLookAndFeel.java @@ -0,0 +1,241 @@ +/* MultiLookAndFeel.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.swing.plaf.multi; + +import java.util.Vector; + +import javax.swing.JComponent; +import javax.swing.LookAndFeel; +import javax.swing.UIDefaults; +import javax.swing.UIManager; +import javax.swing.plaf.ComponentUI; + +/** + * A look and feel that provides the ability to use auxiliary look and feels + * in addition to the primary look and feel. + */ +public class MultiLookAndFeel extends LookAndFeel { + + /** + * Creates a new instance of the look and feel. + */ + public MultiLookAndFeel() + { + } + + /** + * Returns the name for the look and feel. + * + * @return "Multiplexing Look and Feel". + */ + public String getName() + { + return "Multiplexing Look and Feel"; + } + + /** + * Returns an identifier for the look and feel. + * + * @return "Multiplex". + */ + public String getID() + { + return "Multiplex"; + } + + /** + * Returns a description of the look and feel. + * + * @return A description of the look and feel. + */ + public String getDescription() + { + return "Allows multiple UI instances per component instance"; + } + + /** + * Returns <code>false</code> to indicate that this look and feel is not + * native to any platform. + * + * @return <code>false</code>. + */ + public boolean isNativeLookAndFeel() + { + return false; + } + + /** + * Returns <code>true</code> always, since this look and feel is supported on + * all platforms. + * + * @return <code>true</code>. + */ + public boolean isSupportedLookAndFeel() + { + return true; + } + + /** + * Creates and returns the UI defaults for this look and feel. + * + * @return The UI defaults. + */ + public UIDefaults getDefaults() + { + UIDefaults defaults = new UIDefaults(); + defaults.put("ButtonUI", "javax.swing.plaf.multi.MultiButtonUI"); + defaults.put("CheckBoxUI", "javax.swing.plaf.multi.MultiButtonUI"); + defaults.put("CheckBoxMenuItemUI", "javax.swing.plaf.multi.MultiMenuItemUI"); + defaults.put("ColorChooserUI", + "javax.swing.plaf.multi.MultiColorChooserUI"); + defaults.put("ComboBoxUI", "javax.swing.plaf.multi.MultiComboBoxUI"); + defaults.put("DesktopPaneUI", "javax.swing.plaf.multi.MultiDesktopPaneUI"); + defaults.put("DesktopIconUI", "javax.swing.plaf.multi.MultiDesktopIconUI"); + defaults.put("EditorPaneUI", "javax.swing.plaf.multi.MultiTextUI"); + defaults.put("FileChooserUI", "javax.swing.plaf.multi.MultiFileChooserUI"); + defaults.put("FormattedTextFieldUI", "javax.swing.plaf.multi.MultiTextUI"); + defaults.put("InternalFrameUI", + "javax.swing.plaf.multi.MultiInternalFrameUI"); + defaults.put("LabelUI", "javax.swing.plaf.multi.MultiLabelUI"); + defaults.put("ListUI", "javax.swing.plaf.multi.MultiListUI"); + defaults.put("MenuItemUI", "javax.swing.plaf.multi.MultiMenuItemUI"); + defaults.put("MenuUI", "javax.swing.plaf.multi.MultiMenuItemUI"); + defaults.put("MenuBarUI", "javax.swing.plaf.multi.MultiMenuBarUI"); + defaults.put("OptionPaneUI", "javax.swing.plaf.multi.MultiOptionPaneUI"); + defaults.put("PanelUI", "javax.swing.plaf.multi.MultiPanelUI"); + defaults.put("PasswordFieldUI", "javax.swing.plaf.multi.MultiTextUI"); + defaults.put("PopupMenuUI", "javax.swing.plaf.multi.MultiPopupMenuUI"); + defaults.put("PopupMenuSeparatorUI", + "javax.swing.plaf.multi.MultiSeparatorUI"); + defaults.put("ProgressBarUI", "javax.swing.plaf.multi.MultiProgressBarUI"); + defaults.put("RadioButtonUI", "javax.swing.plaf.multi.MultiButtonUI"); + defaults.put("RadioButtonMenuItemUI", + "javax.swing.plaf.multi.MultiMenuItemUI"); + defaults.put("RootPaneUI", "javax.swing.plaf.multi.MultiRootPaneUI"); + defaults.put("ScrollBarUI", "javax.swing.plaf.multi.MultiScrollBarUI"); + defaults.put("ScrollPaneUI", "javax.swing.plaf.multi.MultiScrollPaneUI"); + defaults.put("SeparatorUI", "javax.swing.plaf.multi.MultiSeparatorUI"); + defaults.put("SliderUI", "javax.swing.plaf.multi.MultiSliderUI"); + defaults.put("SpinnerUI", "javax.swing.plaf.multi.MultiSpinnerUI"); + defaults.put("SplitPaneUI", "javax.swing.plaf.multi.MultiSplitPaneUI"); + defaults.put("TabbedPaneUI", "javax.swing.plaf.multi.MultiTabbedPaneUI"); + defaults.put("TableHeaderUI", "javax.swing.plaf.multi.MultiTableHeaderUI"); + defaults.put("TableUI", "javax.swing.plaf.multi.MultiTableUI"); + defaults.put("TextAreaUI", "javax.swing.plaf.multi.MultiTextUI"); + defaults.put("TextFieldUI", "javax.swing.plaf.multi.MultiTextUI"); + defaults.put("TextPaneUI", "javax.swing.plaf.multi.MultiTextUI"); + defaults.put("ToggleButtonUI", "javax.swing.plaf.multi.MultiButtonUI"); + defaults.put("ToolBarSeparatorUI", + "javax.swing.plaf.multi.MultiSeparatorUI"); + defaults.put("ToolBarUI", "javax.swing.plaf.multi.MultiToolBarUI"); + defaults.put("ToolTipUI", "javax.swing.plaf.multi.MultiToolTipUI"); + defaults.put("ViewportUI", "javax.swing.plaf.multi.MultiViewportUI"); + return defaults; + } + + /** + * Creates the UI delegates for the <code>target</code> component and + * returns a multiplexing UI delegate (<code>mui</code>) if there are + * multiple delegates. + * + * @param mui a multiplexing UI delegate appropriate for the component. + * @param uis a vector into which the UI delegates will be added. + * @param target the target component. + * + * @return A UI delegate. + */ + public static ComponentUI createUIs(ComponentUI mui, Vector uis, + JComponent target) + { + // get primary UI delegate for 'target', and add it to uis + ComponentUI ui = null; + LookAndFeel primary = UIManager.getLookAndFeel(); + if (primary != null) + { + ui = UIManager.getUI(target); + uis.add(ui); + } + // for any auxiliary look and feels in use, get the UI delegate and add + // it to uis + LookAndFeel[] auxlafs = UIManager.getAuxiliaryLookAndFeels(); + for (int i = 0; i < auxlafs.length; i++) + { + LookAndFeel auxlaf = auxlafs[i]; + // FIXME: here I call getDefaults() to get the UI delegate from the + // auxiliary look and feel. But getDefaults() creates a new set of + // defaults every time it is called, which is wasteful. Unfortunately + // I cannot find another way to get the UI delegate, so I'm doing it + // anyway... + UIDefaults defaults = auxlaf.getDefaults(); + ui = defaults.getUI(target); + if (ui != null) + uis.add(ui); + } + // if uis contains more than 1 delegate, return mui, otherwise return + // the primary delegate + if (uis.size() > 1) + return mui; + else + return ui; + } + + /** + * Returns an array containing the same {@link ComponentUI} instances as + * <code>uis</code>. If <code>uis</code> is <code>null</code>, a zero-length + * array is returned. + * + * @param uis a list of {@link ComponentUI} references (<code>null</code> + * permitted). + * + * @return An array containing the same {@link ComponentUI} instances as + * <code>uis</code>, or <code>null</code> if <code>uis</code> is + * empty. + */ + protected static ComponentUI[] uisToArray(Vector uis) + { + if (uis == null) + return new ComponentUI[0]; + int size = uis.size(); + if (size == 0) + return null; + ComponentUI[] result = new ComponentUI[size]; + uis.copyInto(result); + return result; + } + +} diff --git a/libjava/classpath/javax/swing/plaf/multi/MultiMenuBarUI.java b/libjava/classpath/javax/swing/plaf/multi/MultiMenuBarUI.java new file mode 100644 index 0000000..a8e805a --- /dev/null +++ b/libjava/classpath/javax/swing/plaf/multi/MultiMenuBarUI.java @@ -0,0 +1,352 @@ +/* MultiMenuBarUI.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.swing.plaf.multi; + +import java.awt.Dimension; +import java.awt.Graphics; +import java.util.Iterator; +import java.util.Vector; + +import javax.accessibility.Accessible; +import javax.swing.JComponent; +import javax.swing.LookAndFeel; +import javax.swing.UIManager; +import javax.swing.plaf.ComponentUI; +import javax.swing.plaf.MenuBarUI; + +/** + * A UI delegate that that coordinates multiple {@link MenuBarUI} + * instances, one from the primary look and feel, and one or more from the + * auxiliary look and feel(s). + * + * @see UIManager#addAuxiliaryLookAndFeel(LookAndFeel) + */ +public class MultiMenuBarUI extends MenuBarUI +{ + + /** A list of references to the actual component UIs. */ + protected Vector uis; + + /** + * Creates a new <code>MultiMenuBarUI</code> instance. + * + * @see #createUI(JComponent) + */ + public MultiMenuBarUI() + { + uis = new Vector(); + } + + /** + * Creates a delegate object for the specified component. If any auxiliary + * look and feels support this component, a <code>MultiMenuBarUI</code> is + * returned, otherwise the UI from the default look and feel is returned. + * + * @param target the component. + * + * @see MultiLookAndFeel#createUIs(ComponentUI, Vector, JComponent) + */ + public static ComponentUI createUI(JComponent target) + { + MultiMenuBarUI mui = new MultiMenuBarUI(); + return MultiLookAndFeel.createUIs(mui, mui.uis, target); + } + + /** + * Calls the {@link ComponentUI#installUI(JComponent)} method for all + * the UI delegates managed by this <code>MultiMenuBarUI</code>. + * + * @param c the component. + */ + public void installUI(JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.installUI(c); + } + } + + /** + * Calls the {@link ComponentUI#uninstallUI(JComponent)} method for all + * the UI delegates managed by this <code>MultiMenuBarUI</code>. + * + * @param c the component. + */ + public void uninstallUI(JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.uninstallUI(c); + } + } + + /** + * Returns an array containing the UI delegates managed by this + * <code>MultiMenuBarUI</code>. The first item in the array is always + * the UI delegate from the installed default look and feel. + * + * @return An array of UI delegates. + */ + public ComponentUI[] getUIs() + { + return MultiLookAndFeel.uisToArray(uis); + } + + /** + * Calls the {@link ComponentUI#contains(JComponent, int, int)} method for all + * the UI delegates managed by this <code>MultiMenuBarUI</code>, + * returning the result for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * @param x the x-coordinate. + * @param y the y-coordinate. + * + * @return <code>true</code> if the specified (x, y) coordinate falls within + * the bounds of the component as rendered by the UI delegate in the + * primary look and feel, and <code>false</code> otherwise. + */ + public boolean contains(JComponent c, int x, int y) + { + boolean result = false; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.contains(c, x, y); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* boolean ignored = */ ui.contains(c, x, y); + } + return result; + } + + /** + * Calls the {@link ComponentUI#update(Graphics, JComponent)} method for all + * the UI delegates managed by this <code>MultiMenuBarUI</code>. + * + * @param g the graphics device. + * @param c the component. + */ + public void update(Graphics g, JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.update(g, c); + } + } + + /** + * Calls the <code>paint(Graphics, JComponent)</code> method for all the UI + * delegates managed by this <code>MultiMenuBarUI</code>. + * + * @param g the graphics device. + * @param c the component. + */ + public void paint(Graphics g, JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.paint(g, c); + } + } + + /** + * Calls the {@link ComponentUI#getPreferredSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiMenuBarUI</code>, + * returning the preferred size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The preferred size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getPreferredSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getPreferredSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getPreferredSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getMinimumSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiMenuBarUI</code>, + * returning the minimum size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The minimum size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getMinimumSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getMinimumSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getMinimumSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getMaximumSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiMenuBarUI</code>, + * returning the maximum size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The maximum size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getMaximumSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getMaximumSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getMaximumSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getAccessibleChildrenCount(JComponent)} method + * for all the UI delegates managed by this <code>MultiMenuBarUI</code>, + * returning the count for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The count returned by the UI delegate from the primary + * look and feel. + */ + public int getAccessibleChildrenCount(JComponent c) + { + int result = 0; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getAccessibleChildrenCount(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* int ignored = */ ui.getAccessibleChildrenCount(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getAccessibleChild(JComponent, int)} method + * for all the UI delegates managed by this <code>MultiMenuBarUI</code>, + * returning the child for the UI delegate from the primary look and + * feel. + * + * @param c the component + * @param i the child index. + * + * @return The child returned by the UI delegate from the primary + * look and feel. + */ + public Accessible getAccessibleChild(JComponent c, int i) + { + Accessible result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getAccessibleChild(c, i); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Accessible ignored = */ ui.getAccessibleChild(c, i); + } + return result; + } + +} diff --git a/libjava/classpath/javax/swing/plaf/multi/MultiMenuItemUI.java b/libjava/classpath/javax/swing/plaf/multi/MultiMenuItemUI.java new file mode 100644 index 0000000..ccab5fe --- /dev/null +++ b/libjava/classpath/javax/swing/plaf/multi/MultiMenuItemUI.java @@ -0,0 +1,352 @@ +/* MultiMenuItemUI.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.swing.plaf.multi; + +import java.awt.Dimension; +import java.awt.Graphics; +import java.util.Iterator; +import java.util.Vector; + +import javax.accessibility.Accessible; +import javax.swing.JComponent; +import javax.swing.LookAndFeel; +import javax.swing.UIManager; +import javax.swing.plaf.ComponentUI; +import javax.swing.plaf.MenuItemUI; + +/** + * A UI delegate that that coordinates multiple {@link MenuItemUI} + * instances, one from the primary look and feel, and one or more from the + * auxiliary look and feel(s). + * + * @see UIManager#addAuxiliaryLookAndFeel(LookAndFeel) + */ +public class MultiMenuItemUI extends MenuItemUI +{ + + /** A list of references to the actual component UIs. */ + protected Vector uis; + + /** + * Creates a new <code>MultiMenuItemUI</code> instance. + * + * @see #createUI(JComponent) + */ + public MultiMenuItemUI() + { + uis = new Vector(); + } + + /** + * Creates a delegate object for the specified component. If any auxiliary + * look and feels support this component, a <code>MultiItemUI</code> is + * returned, otherwise the UI from the default look and feel is returned. + * + * @param target the component. + * + * @see MultiLookAndFeel#createUIs(ComponentUI, Vector, JComponent) + */ + public static ComponentUI createUI(JComponent target) + { + MultiMenuItemUI mui = new MultiMenuItemUI(); + return MultiLookAndFeel.createUIs(mui, mui.uis, target); + } + + /** + * Calls the {@link ComponentUI#installUI(JComponent)} method for all + * the UI delegates managed by this <code>MultiMenuItemUI</code>. + * + * @param c the component. + */ + public void installUI(JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.installUI(c); + } + } + + /** + * Calls the {@link ComponentUI#uninstallUI(JComponent)} method for all + * the UI delegates managed by this <code>MultiMenuItemUI</code>. + * + * @param c the component. + */ + public void uninstallUI(JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.uninstallUI(c); + } + } + + /** + * Returns an array containing the UI delegates managed by this + * <code>MultiMenuItemUI</code>. The first item in the array is always + * the UI delegate from the installed default look and feel. + * + * @return An array of UI delegates. + */ + public ComponentUI[] getUIs() + { + return MultiLookAndFeel.uisToArray(uis); + } + + /** + * Calls the {@link ComponentUI#contains(JComponent, int, int)} method for all + * the UI delegates managed by this <code>MultiMenuItemUI</code>, + * returning the result for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * @param x the x-coordinate. + * @param y the y-coordinate. + * + * @return <code>true</code> if the specified (x, y) coordinate falls within + * the bounds of the component as rendered by the UI delegate in the + * primary look and feel, and <code>false</code> otherwise. + */ + public boolean contains(JComponent c, int x, int y) + { + boolean result = false; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.contains(c, x, y); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* boolean ignored = */ ui.contains(c, x, y); + } + return result; + } + + /** + * Calls the {@link ComponentUI#update(Graphics, JComponent)} method for all + * the UI delegates managed by this <code>MultiMenuItemUI</code>. + * + * @param g the graphics device. + * @param c the component. + */ + public void update(Graphics g, JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.update(g, c); + } + } + + /** + * Calls the <code>paint(Graphics, JComponent)</code> method for all the UI + * delegates managed by this <code>MultiMenuItemUI</code>. + * + * @param g the graphics device. + * @param c the component. + */ + public void paint(Graphics g, JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.paint(g, c); + } + } + + /** + * Calls the {@link ComponentUI#getPreferredSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiMenuItemUI</code>, + * returning the preferred size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The preferred size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getPreferredSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getPreferredSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getPreferredSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getMinimumSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiMenuItemUI</code>, + * returning the minimum size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The minimum size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getMinimumSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getMinimumSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getMinimumSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getMaximumSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiMenuItemUI</code>, + * returning the maximum size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The maximum size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getMaximumSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getMaximumSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getMaximumSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getAccessibleChildrenCount(JComponent)} method + * for all the UI delegates managed by this <code>MultiMenuItemUI</code>, + * returning the count for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The count returned by the UI delegate from the primary + * look and feel. + */ + public int getAccessibleChildrenCount(JComponent c) + { + int result = 0; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getAccessibleChildrenCount(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* int ignored = */ ui.getAccessibleChildrenCount(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getAccessibleChild(JComponent, int)} method + * for all the UI delegates managed by this <code>MultiMenuItemUI</code>, + * returning the child for the UI delegate from the primary look and + * feel. + * + * @param c the component + * @param i the child index. + * + * @return The child returned by the UI delegate from the primary + * look and feel. + */ + public Accessible getAccessibleChild(JComponent c, int i) + { + Accessible result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getAccessibleChild(c, i); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Accessible ignored = */ ui.getAccessibleChild(c, i); + } + return result; + } + +} diff --git a/libjava/classpath/javax/swing/plaf/multi/MultiOptionPaneUI.java b/libjava/classpath/javax/swing/plaf/multi/MultiOptionPaneUI.java new file mode 100644 index 0000000..c5cb913 --- /dev/null +++ b/libjava/classpath/javax/swing/plaf/multi/MultiOptionPaneUI.java @@ -0,0 +1,396 @@ +/* MultiOptionPaneUI.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.swing.plaf.multi; + +import java.awt.Dimension; +import java.awt.Graphics; +import java.util.Iterator; +import java.util.Vector; + +import javax.accessibility.Accessible; +import javax.swing.JComponent; +import javax.swing.JOptionPane; +import javax.swing.LookAndFeel; +import javax.swing.UIManager; +import javax.swing.plaf.ComponentUI; +import javax.swing.plaf.OptionPaneUI; + +/** + * A UI delegate that that coordinates multiple {@link OptionPaneUI} + * instances, one from the primary look and feel, and one or more from the + * auxiliary look and feel(s). + * + * @see UIManager#addAuxiliaryLookAndFeel(LookAndFeel) + */ +public class MultiOptionPaneUI extends OptionPaneUI +{ + + /** A list of references to the actual component UIs. */ + protected Vector uis; + + /** + * Creates a new <code>MultiOptionPaneUI</code> instance. + * + * @see #createUI(JComponent) + */ + public MultiOptionPaneUI() + { + uis = new Vector(); + } + + /** + * Creates a delegate object for the specified component. If any auxiliary + * look and feels support this component, a <code>MultiOptionPaneUI</code> is + * returned, otherwise the UI from the default look and feel is returned. + * + * @param target the component. + * + * @see MultiLookAndFeel#createUIs(ComponentUI, Vector, JComponent) + */ + public static ComponentUI createUI(JComponent target) + { + MultiOptionPaneUI mui = new MultiOptionPaneUI(); + return MultiLookAndFeel.createUIs(mui, mui.uis, target); + } + + /** + * Calls the {@link ComponentUI#installUI(JComponent)} method for all + * the UI delegates managed by this <code>MultiOptionPaneUI</code>. + * + * @param c the component. + */ + public void installUI(JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.installUI(c); + } + } + + /** + * Calls the {@link ComponentUI#uninstallUI(JComponent)} method for all + * the UI delegates managed by this <code>MultiOptionPaneUI</code>. + * + * @param c the component. + */ + public void uninstallUI(JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.uninstallUI(c); + } + } + + /** + * Returns an array containing the UI delegates managed by this + * <code>MultiOptionPaneUI</code>. The first item in the array is always + * the UI delegate from the installed default look and feel. + * + * @return An array of UI delegates. + */ + public ComponentUI[] getUIs() + { + return MultiLookAndFeel.uisToArray(uis); + } + + /** + * Calls the {@link ComponentUI#contains(JComponent, int, int)} method for all + * the UI delegates managed by this <code>MultiOptionPaneUI</code>, + * returning the result for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * @param x the x-coordinate. + * @param y the y-coordinate. + * + * @return <code>true</code> if the specified (x, y) coordinate falls within + * the bounds of the component as rendered by the UI delegate in the + * primary look and feel, and <code>false</code> otherwise. + */ + public boolean contains(JComponent c, int x, int y) + { + boolean result = false; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.contains(c, x, y); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* boolean ignored = */ ui.contains(c, x, y); + } + return result; + } + + /** + * Calls the {@link ComponentUI#update(Graphics, JComponent)} method for all + * the UI delegates managed by this <code>MultiOptionPaneUI</code>. + * + * @param g the graphics device. + * @param c the component. + */ + public void update(Graphics g, JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.update(g, c); + } + } + + /** + * Calls the <code>paint(Graphics, JComponent)</code> method for all the UI + * delegates managed by this <code>MultiOptionPaneUI</code>. + * + * @param g the graphics device. + * @param c the component. + */ + public void paint(Graphics g, JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.paint(g, c); + } + } + + /** + * Calls the {@link ComponentUI#getPreferredSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiOptionPaneUI</code>, + * returning the preferred size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The preferred size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getPreferredSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getPreferredSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getPreferredSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getMinimumSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiOptionPaneUI</code>, + * returning the minimum size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The minimum size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getMinimumSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getMinimumSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getMinimumSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getMaximumSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiOptionPaneUI</code>, + * returning the maximum size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The maximum size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getMaximumSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getMaximumSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getMaximumSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getAccessibleChildrenCount(JComponent)} method + * for all the UI delegates managed by this <code>MultiOptionPaneUI</code>, + * returning the count for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The count returned by the UI delegate from the primary + * look and feel. + */ + public int getAccessibleChildrenCount(JComponent c) + { + int result = 0; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getAccessibleChildrenCount(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* int ignored = */ ui.getAccessibleChildrenCount(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getAccessibleChild(JComponent, int)} method + * for all the UI delegates managed by this <code>MultiOptionPaneUI</code>, + * returning the child for the UI delegate from the primary look and + * feel. + * + * @param c the component + * @param i the child index. + * + * @return The child returned by the UI delegate from the primary + * look and feel. + */ + public Accessible getAccessibleChild(JComponent c, int i) + { + Accessible result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getAccessibleChild(c, i); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Accessible ignored = */ ui.getAccessibleChild(c, i); + } + return result; + } + + /** + * Calls the {@link OptionPaneUI#selectInitialValue(JOptionPane)} method for + * all the UI delegates managed by this <code>MultiOptionPaneUI</code>. + * + * @param pane the option pane. + */ + public void selectInitialValue(JOptionPane pane) { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + OptionPaneUI ui = (OptionPaneUI) iterator.next(); + ui.selectInitialValue(pane); + } + } + + /** + * Calls the {@link OptionPaneUI#containsCustomComponents(JOptionPane)} + * method for all the UI delegates managed by this + * <code>MultiOptionPaneUI</code>, returning the result for the UI delegate + * from the primary look and feel. + * + * @param pane the option pane. + * + * @return The result for the UI delegate from the primary look and feel. + */ + public boolean containsCustomComponents(JOptionPane pane) { + boolean result = false; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + OptionPaneUI ui = (OptionPaneUI) iterator.next(); + result = ui.containsCustomComponents(pane); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + OptionPaneUI ui = (OptionPaneUI) iterator.next(); + /* boolean ignored = */ ui.containsCustomComponents(pane); + } + return result; + } + +} diff --git a/libjava/classpath/javax/swing/plaf/multi/MultiPanelUI.java b/libjava/classpath/javax/swing/plaf/multi/MultiPanelUI.java new file mode 100644 index 0000000..67629b2 --- /dev/null +++ b/libjava/classpath/javax/swing/plaf/multi/MultiPanelUI.java @@ -0,0 +1,352 @@ +/* MultiPanelUI.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.swing.plaf.multi; + +import java.awt.Dimension; +import java.awt.Graphics; +import java.util.Iterator; +import java.util.Vector; + +import javax.accessibility.Accessible; +import javax.swing.JComponent; +import javax.swing.LookAndFeel; +import javax.swing.UIManager; +import javax.swing.plaf.ComponentUI; +import javax.swing.plaf.PanelUI; + +/** + * A UI delegate that that coordinates multiple {@link PanelUI} + * instances, one from the primary look and feel, and one or more from the + * auxiliary look and feel(s). + * + * @see UIManager#addAuxiliaryLookAndFeel(LookAndFeel) + */ +public class MultiPanelUI extends PanelUI +{ + + /** A list of references to the actual component UIs. */ + protected Vector uis; + + /** + * Creates a new <code>MultiPanelUI</code> instance. + * + * @see #createUI(JComponent) + */ + public MultiPanelUI() + { + uis = new Vector(); + } + + /** + * Creates a delegate object for the specified component. If any auxiliary + * look and feels support this component, a <code>MultiPanelUI</code> is + * returned, otherwise the UI from the default look and feel is returned. + * + * @param target the component. + * + * @see MultiLookAndFeel#createUIs(ComponentUI, Vector, JComponent) + */ + public static ComponentUI createUI(JComponent target) + { + MultiPanelUI mui = new MultiPanelUI(); + return MultiLookAndFeel.createUIs(mui, mui.uis, target); + } + + /** + * Calls the {@link ComponentUI#installUI(JComponent)} method for all + * the UI delegates managed by this <code>MultiPanelUI</code>. + * + * @param c the component. + */ + public void installUI(JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.installUI(c); + } + } + + /** + * Calls the {@link ComponentUI#uninstallUI(JComponent)} method for all + * the UI delegates managed by this <code>MultiPanelUI</code>. + * + * @param c the component. + */ + public void uninstallUI(JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.uninstallUI(c); + } + } + + /** + * Returns an array containing the UI delegates managed by this + * <code>MultiPanelUI</code>. The first item in the array is always + * the UI delegate from the installed default look and feel. + * + * @return An array of UI delegates. + */ + public ComponentUI[] getUIs() + { + return MultiLookAndFeel.uisToArray(uis); + } + + /** + * Calls the {@link ComponentUI#contains(JComponent, int, int)} method for all + * the UI delegates managed by this <code>MultiPanelUI</code>, + * returning the result for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * @param x the x-coordinate. + * @param y the y-coordinate. + * + * @return <code>true</code> if the specified (x, y) coordinate falls within + * the bounds of the component as rendered by the UI delegate in the + * primary look and feel, and <code>false</code> otherwise. + */ + public boolean contains(JComponent c, int x, int y) + { + boolean result = false; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.contains(c, x, y); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* boolean ignored = */ ui.contains(c, x, y); + } + return result; + } + + /** + * Calls the {@link ComponentUI#update(Graphics, JComponent)} method for all + * the UI delegates managed by this <code>MultiPanelUI</code>. + * + * @param g the graphics device. + * @param c the component. + */ + public void update(Graphics g, JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.update(g, c); + } + } + + /** + * Calls the <code>paint(Graphics, JComponent)</code> method for all the UI + * delegates managed by this <code>MultiPanelUI</code>. + * + * @param g the graphics device. + * @param c the component. + */ + public void paint(Graphics g, JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.paint(g, c); + } + } + + /** + * Calls the {@link ComponentUI#getPreferredSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiPanelUI</code>, + * returning the preferred size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The preferred size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getPreferredSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getPreferredSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getPreferredSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getMinimumSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiPanelUI</code>, + * returning the minimum size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The minimum size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getMinimumSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getMinimumSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getMinimumSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getMaximumSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiPanelUI</code>, + * returning the maximum size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The maximum size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getMaximumSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getMaximumSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getMaximumSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getAccessibleChildrenCount(JComponent)} method + * for all the UI delegates managed by this <code>MultiPanelUI</code>, + * returning the count for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The count returned by the UI delegate from the primary + * look and feel. + */ + public int getAccessibleChildrenCount(JComponent c) + { + int result = 0; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getAccessibleChildrenCount(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* int ignored = */ ui.getAccessibleChildrenCount(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getAccessibleChild(JComponent, int)} method + * for all the UI delegates managed by this <code>MultiPanelUI</code>, + * returning the child for the UI delegate from the primary look and + * feel. + * + * @param c the component + * @param i the child index. + * + * @return The child returned by the UI delegate from the primary + * look and feel. + */ + public Accessible getAccessibleChild(JComponent c, int i) + { + Accessible result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getAccessibleChild(c, i); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Accessible ignored = */ ui.getAccessibleChild(c, i); + } + return result; + } + +} diff --git a/libjava/classpath/javax/swing/plaf/multi/MultiPopupMenuUI.java b/libjava/classpath/javax/swing/plaf/multi/MultiPopupMenuUI.java new file mode 100644 index 0000000..161429d --- /dev/null +++ b/libjava/classpath/javax/swing/plaf/multi/MultiPopupMenuUI.java @@ -0,0 +1,352 @@ +/* MultiPopupMenuUI.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.swing.plaf.multi; + +import java.awt.Dimension; +import java.awt.Graphics; +import java.util.Iterator; +import java.util.Vector; + +import javax.accessibility.Accessible; +import javax.swing.JComponent; +import javax.swing.LookAndFeel; +import javax.swing.UIManager; +import javax.swing.plaf.ComponentUI; +import javax.swing.plaf.PopupMenuUI; + +/** + * A UI delegate that that coordinates multiple {@link PopupMenuUI} + * instances, one from the primary look and feel, and one or more from the + * auxiliary look and feel(s). + * + * @see UIManager#addAuxiliaryLookAndFeel(LookAndFeel) + */ +public class MultiPopupMenuUI extends PopupMenuUI +{ + + /** A list of references to the actual component UIs. */ + protected Vector uis; + + /** + * Creates a new <code>MultiPopupMenuUI</code> instance. + * + * @see #createUI(JComponent) + */ + public MultiPopupMenuUI() + { + uis = new Vector(); + } + + /** + * Creates a delegate object for the specified component. If any auxiliary + * look and feels support this component, a <code>MultiPopupMenuUI</code> is + * returned, otherwise the UI from the default look and feel is returned. + * + * @param target the component. + * + * @see MultiLookAndFeel#createUIs(ComponentUI, Vector, JComponent) + */ + public static ComponentUI createUI(JComponent target) + { + MultiPopupMenuUI mui = new MultiPopupMenuUI(); + return MultiLookAndFeel.createUIs(mui, mui.uis, target); + } + + /** + * Calls the {@link ComponentUI#installUI(JComponent)} method for all + * the UI delegates managed by this <code>MultiPopupMenuUI</code>. + * + * @param c the component. + */ + public void installUI(JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.installUI(c); + } + } + + /** + * Calls the {@link ComponentUI#uninstallUI(JComponent)} method for all + * the UI delegates managed by this <code>MultiPopupMenuUI</code>. + * + * @param c the component. + */ + public void uninstallUI(JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.uninstallUI(c); + } + } + + /** + * Returns an array containing the UI delegates managed by this + * <code>MultiPopupMenuUI</code>. The first item in the array is always + * the UI delegate from the installed default look and feel. + * + * @return An array of UI delegates. + */ + public ComponentUI[] getUIs() + { + return MultiLookAndFeel.uisToArray(uis); + } + + /** + * Calls the {@link ComponentUI#contains(JComponent, int, int)} method for all + * the UI delegates managed by this <code>MultiPopupMenuUI</code>, + * returning the result for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * @param x the x-coordinate. + * @param y the y-coordinate. + * + * @return <code>true</code> if the specified (x, y) coordinate falls within + * the bounds of the component as rendered by the UI delegate in the + * primary look and feel, and <code>false</code> otherwise. + */ + public boolean contains(JComponent c, int x, int y) + { + boolean result = false; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.contains(c, x, y); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* boolean ignored = */ ui.contains(c, x, y); + } + return result; + } + + /** + * Calls the {@link ComponentUI#update(Graphics, JComponent)} method for all + * the UI delegates managed by this <code>MultiPopupMenuUI</code>. + * + * @param g the graphics device. + * @param c the component. + */ + public void update(Graphics g, JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.update(g, c); + } + } + + /** + * Calls the <code>paint(Graphics, JComponent)</code> method for all the UI + * delegates managed by this <code>MultiPopupMenuUI</code>. + * + * @param g the graphics device. + * @param c the component. + */ + public void paint(Graphics g, JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.paint(g, c); + } + } + + /** + * Calls the {@link ComponentUI#getPreferredSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiPopupMenuUI</code>, + * returning the preferred size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The preferred size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getPreferredSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getPreferredSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getPreferredSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getMinimumSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiPopupMenuUI</code>, + * returning the minimum size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The minimum size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getMinimumSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getMinimumSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getMinimumSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getMaximumSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiPopupMenuUI</code>, + * returning the maximum size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The maximum size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getMaximumSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getMaximumSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getMaximumSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getAccessibleChildrenCount(JComponent)} method + * for all the UI delegates managed by this <code>MultiPopupMenuUI</code>, + * returning the count for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The count returned by the UI delegate from the primary + * look and feel. + */ + public int getAccessibleChildrenCount(JComponent c) + { + int result = 0; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getAccessibleChildrenCount(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* int ignored = */ ui.getAccessibleChildrenCount(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getAccessibleChild(JComponent, int)} method + * for all the UI delegates managed by this <code>MultiPopupMenuUI</code>, + * returning the child for the UI delegate from the primary look and + * feel. + * + * @param c the component + * @param i the child index. + * + * @return The child returned by the UI delegate from the primary + * look and feel. + */ + public Accessible getAccessibleChild(JComponent c, int i) + { + Accessible result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getAccessibleChild(c, i); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Accessible ignored = */ ui.getAccessibleChild(c, i); + } + return result; + } + +} diff --git a/libjava/classpath/javax/swing/plaf/multi/MultiProgressBarUI.java b/libjava/classpath/javax/swing/plaf/multi/MultiProgressBarUI.java new file mode 100644 index 0000000..c5dbbe8 --- /dev/null +++ b/libjava/classpath/javax/swing/plaf/multi/MultiProgressBarUI.java @@ -0,0 +1,352 @@ +/* MultiProgressBarUI.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.swing.plaf.multi; + +import java.awt.Dimension; +import java.awt.Graphics; +import java.util.Iterator; +import java.util.Vector; + +import javax.accessibility.Accessible; +import javax.swing.JComponent; +import javax.swing.LookAndFeel; +import javax.swing.UIManager; +import javax.swing.plaf.ComponentUI; +import javax.swing.plaf.ProgressBarUI; + +/** + * A UI delegate that that coordinates multiple {@link ProgressBarUI} + * instances, one from the primary look and feel, and one or more from the + * auxiliary look and feel(s). + * + * @see UIManager#addAuxiliaryLookAndFeel(LookAndFeel) + */ +public class MultiProgressBarUI extends ProgressBarUI +{ + + /** A list of references to the actual component UIs. */ + protected Vector uis; + + /** + * Creates a new <code>MultiProgressBarUI</code> instance. + * + * @see #createUI(JComponent) + */ + public MultiProgressBarUI() + { + uis = new Vector(); + } + + /** + * Creates a delegate object for the specified component. If any auxiliary + * look and feels support this component, a <code>MultiProgressBarUI</code> is + * returned, otherwise the UI from the default look and feel is returned. + * + * @param target the component. + * + * @see MultiLookAndFeel#createUIs(ComponentUI, Vector, JComponent) + */ + public static ComponentUI createUI(JComponent target) + { + MultiProgressBarUI mui = new MultiProgressBarUI(); + return MultiLookAndFeel.createUIs(mui, mui.uis, target); + } + + /** + * Calls the {@link ComponentUI#installUI(JComponent)} method for all + * the UI delegates managed by this <code>MultiProgressBarUI</code>. + * + * @param c the component. + */ + public void installUI(JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.installUI(c); + } + } + + /** + * Calls the {@link ComponentUI#uninstallUI(JComponent)} method for all + * the UI delegates managed by this <code>MultiProgressBarUI</code>. + * + * @param c the component. + */ + public void uninstallUI(JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.uninstallUI(c); + } + } + + /** + * Returns an array containing the UI delegates managed by this + * <code>MultiProgressBarUI</code>. The first item in the array is always + * the UI delegate from the installed default look and feel. + * + * @return An array of UI delegates. + */ + public ComponentUI[] getUIs() + { + return MultiLookAndFeel.uisToArray(uis); + } + + /** + * Calls the {@link ComponentUI#contains(JComponent, int, int)} method for all + * the UI delegates managed by this <code>MultiProgressBarUI</code>, + * returning the result for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * @param x the x-coordinate. + * @param y the y-coordinate. + * + * @return <code>true</code> if the specified (x, y) coordinate falls within + * the bounds of the component as rendered by the UI delegate in the + * primary look and feel, and <code>false</code> otherwise. + */ + public boolean contains(JComponent c, int x, int y) + { + boolean result = false; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.contains(c, x, y); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* boolean ignored = */ ui.contains(c, x, y); + } + return result; + } + + /** + * Calls the {@link ComponentUI#update(Graphics, JComponent)} method for all + * the UI delegates managed by this <code>MultiProgressBarUI</code>. + * + * @param g the graphics device. + * @param c the component. + */ + public void update(Graphics g, JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.update(g, c); + } + } + + /** + * Calls the <code>paint(Graphics, JComponent)</code> method for all the UI + * delegates managed by this <code>MultiProgressBarUI</code>. + * + * @param g the graphics device. + * @param c the component. + */ + public void paint(Graphics g, JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.paint(g, c); + } + } + + /** + * Calls the {@link ComponentUI#getPreferredSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiProgressBarUI</code>, + * returning the preferred size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The preferred size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getPreferredSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getPreferredSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getPreferredSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getMinimumSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiProgressBarUI</code>, + * returning the minimum size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The minimum size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getMinimumSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getMinimumSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getMinimumSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getMaximumSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiProgressBarUI</code>, + * returning the maximum size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The maximum size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getMaximumSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getMaximumSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getMaximumSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getAccessibleChildrenCount(JComponent)} method + * for all the UI delegates managed by this <code>MultiProgressBarUI</code>, + * returning the count for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The count returned by the UI delegate from the primary + * look and feel. + */ + public int getAccessibleChildrenCount(JComponent c) + { + int result = 0; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getAccessibleChildrenCount(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* int ignored = */ ui.getAccessibleChildrenCount(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getAccessibleChild(JComponent, int)} method + * for all the UI delegates managed by this <code>MultiProgressBarUI</code>, + * returning the child for the UI delegate from the primary look and + * feel. + * + * @param c the component + * @param i the child index. + * + * @return The child returned by the UI delegate from the primary + * look and feel. + */ + public Accessible getAccessibleChild(JComponent c, int i) + { + Accessible result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getAccessibleChild(c, i); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Accessible ignored = */ ui.getAccessibleChild(c, i); + } + return result; + } + +} diff --git a/libjava/classpath/javax/swing/plaf/multi/MultiRootPaneUI.java b/libjava/classpath/javax/swing/plaf/multi/MultiRootPaneUI.java new file mode 100644 index 0000000..bd0cb5c --- /dev/null +++ b/libjava/classpath/javax/swing/plaf/multi/MultiRootPaneUI.java @@ -0,0 +1,352 @@ +/* MultiRootPaneUI.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.swing.plaf.multi; + +import java.awt.Dimension; +import java.awt.Graphics; +import java.util.Iterator; +import java.util.Vector; + +import javax.accessibility.Accessible; +import javax.swing.JComponent; +import javax.swing.LookAndFeel; +import javax.swing.UIManager; +import javax.swing.plaf.ComponentUI; +import javax.swing.plaf.RootPaneUI; + +/** + * A UI delegate that that coordinates multiple {@link RootPaneUI} + * instances, one from the primary look and feel, and one or more from the + * auxiliary look and feel(s). + * + * @see UIManager#addAuxiliaryLookAndFeel(LookAndFeel) + */ +public class MultiRootPaneUI extends RootPaneUI +{ + + /** A list of references to the actual component UIs. */ + protected Vector uis; + + /** + * Creates a new <code>MultiRootPanelUI</code> instance. + * + * @see #createUI(JComponent) + */ + public MultiRootPaneUI() + { + uis = new Vector(); + } + + /** + * Creates a delegate object for the specified component. If any auxiliary + * look and feels support this component, a <code>MultiRootPaneUI</code> is + * returned, otherwise the UI from the default look and feel is returned. + * + * @param target the component. + * + * @see MultiLookAndFeel#createUIs(ComponentUI, Vector, JComponent) + */ + public static ComponentUI createUI(JComponent target) + { + MultiRootPaneUI mui = new MultiRootPaneUI(); + return MultiLookAndFeel.createUIs(mui, mui.uis, target); + } + + /** + * Calls the {@link ComponentUI#installUI(JComponent)} method for all + * the UI delegates managed by this <code>MultiRootPaneUI</code>. + * + * @param c the component. + */ + public void installUI(JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.installUI(c); + } + } + + /** + * Calls the {@link ComponentUI#uninstallUI(JComponent)} method for all + * the UI delegates managed by this <code>MultiRootPaneUI</code>. + * + * @param c the component. + */ + public void uninstallUI(JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.uninstallUI(c); + } + } + + /** + * Returns an array containing the UI delegates managed by this + * <code>MultiRootPaneUI</code>. The first item in the array is always + * the UI delegate from the installed default look and feel. + * + * @return An array of UI delegates. + */ + public ComponentUI[] getUIs() + { + return MultiLookAndFeel.uisToArray(uis); + } + + /** + * Calls the {@link ComponentUI#contains(JComponent, int, int)} method for all + * the UI delegates managed by this <code>MultiRootPaneUI</code>, + * returning the result for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * @param x the x-coordinate. + * @param y the y-coordinate. + * + * @return <code>true</code> if the specified (x, y) coordinate falls within + * the bounds of the component as rendered by the UI delegate in the + * primary look and feel, and <code>false</code> otherwise. + */ + public boolean contains(JComponent c, int x, int y) + { + boolean result = false; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.contains(c, x, y); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* boolean ignored = */ ui.contains(c, x, y); + } + return result; + } + + /** + * Calls the {@link ComponentUI#update(Graphics, JComponent)} method for all + * the UI delegates managed by this <code>MultiRootPaneUI</code>. + * + * @param g the graphics device. + * @param c the component. + */ + public void update(Graphics g, JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.update(g, c); + } + } + + /** + * Calls the <code>paint(Graphics, JComponent)</code> method for all the UI + * delegates managed by this <code>MultiRootPaneUI</code>. + * + * @param g the graphics device. + * @param c the component. + */ + public void paint(Graphics g, JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.paint(g, c); + } + } + + /** + * Calls the {@link ComponentUI#getPreferredSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiRootPaneUI</code>, + * returning the preferred size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The preferred size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getPreferredSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getPreferredSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getPreferredSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getMinimumSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiRootPaneUI</code>, + * returning the minimum size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The minimum size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getMinimumSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getMinimumSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getMinimumSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getMaximumSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiRootPaneUI</code>, + * returning the maximum size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The maximum size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getMaximumSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getMaximumSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getMaximumSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getAccessibleChildrenCount(JComponent)} method + * for all the UI delegates managed by this <code>MultiRootPaneUI</code>, + * returning the count for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The count returned by the UI delegate from the primary + * look and feel. + */ + public int getAccessibleChildrenCount(JComponent c) + { + int result = 0; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getAccessibleChildrenCount(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* int ignored = */ ui.getAccessibleChildrenCount(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getAccessibleChild(JComponent, int)} method + * for all the UI delegates managed by this <code>MultiRootPaneUI</code>, + * returning the child for the UI delegate from the primary look and + * feel. + * + * @param c the component + * @param i the child index. + * + * @return The child returned by the UI delegate from the primary + * look and feel. + */ + public Accessible getAccessibleChild(JComponent c, int i) + { + Accessible result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getAccessibleChild(c, i); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Accessible ignored = */ ui.getAccessibleChild(c, i); + } + return result; + } + +} diff --git a/libjava/classpath/javax/swing/plaf/multi/MultiScrollBarUI.java b/libjava/classpath/javax/swing/plaf/multi/MultiScrollBarUI.java new file mode 100644 index 0000000..1a993b8 --- /dev/null +++ b/libjava/classpath/javax/swing/plaf/multi/MultiScrollBarUI.java @@ -0,0 +1,352 @@ +/* MultiScrollBarUI.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.swing.plaf.multi; + +import java.awt.Dimension; +import java.awt.Graphics; +import java.util.Iterator; +import java.util.Vector; + +import javax.accessibility.Accessible; +import javax.swing.JComponent; +import javax.swing.LookAndFeel; +import javax.swing.UIManager; +import javax.swing.plaf.ComponentUI; +import javax.swing.plaf.ScrollBarUI; + +/** + * A UI delegate that that coordinates multiple {@link ScrollBarUI} + * instances, one from the primary look and feel, and one or more from the + * auxiliary look and feel(s). + * + * @see UIManager#addAuxiliaryLookAndFeel(LookAndFeel) + */ +public class MultiScrollBarUI extends ScrollBarUI +{ + + /** A list of references to the actual component UIs. */ + protected Vector uis; + + /** + * Creates a new <code>MultiScrollBarUI</code> instance. + * + * @see #createUI(JComponent) + */ + public MultiScrollBarUI() + { + uis = new Vector(); + } + + /** + * Creates a delegate object for the specified component. If any auxiliary + * look and feels support this component, a <code>MultiScrollBarUI</code> is + * returned, otherwise the UI from the default look and feel is returned. + * + * @param target the component. + * + * @see MultiLookAndFeel#createUIs(ComponentUI, Vector, JComponent) + */ + public static ComponentUI createUI(JComponent target) + { + MultiScrollBarUI mui = new MultiScrollBarUI(); + return MultiLookAndFeel.createUIs(mui, mui.uis, target); + } + + /** + * Calls the {@link ComponentUI#installUI(JComponent)} method for all + * the UI delegates managed by this <code>MultiScrollBarUI</code>. + * + * @param c the component. + */ + public void installUI(JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.installUI(c); + } + } + + /** + * Calls the {@link ComponentUI#uninstallUI(JComponent)} method for all + * the UI delegates managed by this <code>MultiScrollBarUI</code>. + * + * @param c the component. + */ + public void uninstallUI(JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.uninstallUI(c); + } + } + + /** + * Returns an array containing the UI delegates managed by this + * <code>MultiScrollBarUI</code>. The first item in the array is always + * the UI delegate from the installed default look and feel. + * + * @return An array of UI delegates. + */ + public ComponentUI[] getUIs() + { + return MultiLookAndFeel.uisToArray(uis); + } + + /** + * Calls the {@link ComponentUI#contains(JComponent, int, int)} method for all + * the UI delegates managed by this <code>MultiScrollBarUI</code>, + * returning the result for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * @param x the x-coordinate. + * @param y the y-coordinate. + * + * @return <code>true</code> if the specified (x, y) coordinate falls within + * the bounds of the component as rendered by the UI delegate in the + * primary look and feel, and <code>false</code> otherwise. + */ + public boolean contains(JComponent c, int x, int y) + { + boolean result = false; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.contains(c, x, y); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* boolean ignored = */ ui.contains(c, x, y); + } + return result; + } + + /** + * Calls the {@link ComponentUI#update(Graphics, JComponent)} method for all + * the UI delegates managed by this <code>MultiScrollBarUI</code>. + * + * @param g the graphics device. + * @param c the component. + */ + public void update(Graphics g, JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.update(g, c); + } + } + + /** + * Calls the <code>paint(Graphics, JComponent)</code> method for all the UI + * delegates managed by this <code>MultiScrollBarUI</code>. + * + * @param g the graphics device. + * @param c the component. + */ + public void paint(Graphics g, JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.paint(g, c); + } + } + + /** + * Calls the {@link ComponentUI#getPreferredSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiScrollBarUI</code>, + * returning the preferred size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The preferred size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getPreferredSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getPreferredSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getPreferredSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getMinimumSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiScrollBarUI</code>, + * returning the minimum size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The minimum size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getMinimumSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getMinimumSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getMinimumSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getMaximumSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiScrollBarUI</code>, + * returning the maximum size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The maximum size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getMaximumSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getMaximumSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getMaximumSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getAccessibleChildrenCount(JComponent)} method + * for all the UI delegates managed by this <code>MultiScrollBarUI</code>, + * returning the count for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The count returned by the UI delegate from the primary + * look and feel. + */ + public int getAccessibleChildrenCount(JComponent c) + { + int result = 0; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getAccessibleChildrenCount(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* int ignored = */ ui.getAccessibleChildrenCount(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getAccessibleChild(JComponent, int)} method + * for all the UI delegates managed by this <code>MultiScrollBarUI</code>, + * returning the child for the UI delegate from the primary look and + * feel. + * + * @param c the component + * @param i the child index. + * + * @return The child returned by the UI delegate from the primary + * look and feel. + */ + public Accessible getAccessibleChild(JComponent c, int i) + { + Accessible result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getAccessibleChild(c, i); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Accessible ignored = */ ui.getAccessibleChild(c, i); + } + return result; + } + +} diff --git a/libjava/classpath/javax/swing/plaf/multi/MultiScrollPaneUI.java b/libjava/classpath/javax/swing/plaf/multi/MultiScrollPaneUI.java new file mode 100644 index 0000000..a50c3ba --- /dev/null +++ b/libjava/classpath/javax/swing/plaf/multi/MultiScrollPaneUI.java @@ -0,0 +1,352 @@ +/* MultiScrollPaneUI.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.swing.plaf.multi; + +import java.awt.Dimension; +import java.awt.Graphics; +import java.util.Iterator; +import java.util.Vector; + +import javax.accessibility.Accessible; +import javax.swing.JComponent; +import javax.swing.LookAndFeel; +import javax.swing.UIManager; +import javax.swing.plaf.ComponentUI; +import javax.swing.plaf.ScrollPaneUI; + +/** + * A UI delegate that that coordinates multiple {@link ScrollPaneUI} + * instances, one from the primary look and feel, and one or more from the + * auxiliary look and feel(s). + * + * @see UIManager#addAuxiliaryLookAndFeel(LookAndFeel) + */ +public class MultiScrollPaneUI extends ScrollPaneUI +{ + + /** A list of references to the actual component UIs. */ + protected Vector uis; + + /** + * Creates a new <code>MultiScrollPaneUI</code> instance. + * + * @see #createUI(JComponent) + */ + public MultiScrollPaneUI() + { + uis = new Vector(); + } + + /** + * Creates a delegate object for the specified component. If any auxiliary + * look and feels support this component, a <code>MultiScrollPaneUI</code> is + * returned, otherwise the UI from the default look and feel is returned. + * + * @param target the component. + * + * @see MultiLookAndFeel#createUIs(ComponentUI, Vector, JComponent) + */ + public static ComponentUI createUI(JComponent target) + { + MultiScrollPaneUI mui = new MultiScrollPaneUI(); + return MultiLookAndFeel.createUIs(mui, mui.uis, target); + } + + /** + * Calls the {@link ComponentUI#installUI(JComponent)} method for all + * the UI delegates managed by this <code>MultiScrollPaneUI</code>. + * + * @param c the component. + */ + public void installUI(JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.installUI(c); + } + } + + /** + * Calls the {@link ComponentUI#uninstallUI(JComponent)} method for all + * the UI delegates managed by this <code>MultiScrollPaneUI</code>. + * + * @param c the component. + */ + public void uninstallUI(JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.uninstallUI(c); + } + } + + /** + * Returns an array containing the UI delegates managed by this + * <code>MultiScrollPaneUI</code>. The first item in the array is always + * the UI delegate from the installed default look and feel. + * + * @return An array of UI delegates. + */ + public ComponentUI[] getUIs() + { + return MultiLookAndFeel.uisToArray(uis); + } + + /** + * Calls the {@link ComponentUI#contains(JComponent, int, int)} method for all + * the UI delegates managed by this <code>MultiScrollPaneUI</code>, + * returning the result for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * @param x the x-coordinate. + * @param y the y-coordinate. + * + * @return <code>true</code> if the specified (x, y) coordinate falls within + * the bounds of the component as rendered by the UI delegate in the + * primary look and feel, and <code>false</code> otherwise. + */ + public boolean contains(JComponent c, int x, int y) + { + boolean result = false; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.contains(c, x, y); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* boolean ignored = */ ui.contains(c, x, y); + } + return result; + } + + /** + * Calls the {@link ComponentUI#update(Graphics, JComponent)} method for all + * the UI delegates managed by this <code>MultiScrollPaneUI</code>. + * + * @param g the graphics device. + * @param c the component. + */ + public void update(Graphics g, JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.update(g, c); + } + } + + /** + * Calls the <code>paint(Graphics, JComponent)</code> method for all the UI + * delegates managed by this <code>MultiScrollPaneUI</code>. + * + * @param g the graphics device. + * @param c the component. + */ + public void paint(Graphics g, JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.paint(g, c); + } + } + + /** + * Calls the {@link ComponentUI#getPreferredSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiScrollPaneUI</code>, + * returning the preferred size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The preferred size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getPreferredSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getPreferredSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getPreferredSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getMinimumSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiScrollPaneUI</code>, + * returning the minimum size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The minimum size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getMinimumSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getMinimumSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getMinimumSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getMaximumSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiScrollPaneUI</code>, + * returning the maximum size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The maximum size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getMaximumSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getMaximumSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getMaximumSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getAccessibleChildrenCount(JComponent)} method + * for all the UI delegates managed by this <code>MultiScrollPaneUI</code>, + * returning the count for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The count returned by the UI delegate from the primary + * look and feel. + */ + public int getAccessibleChildrenCount(JComponent c) + { + int result = 0; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getAccessibleChildrenCount(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* int ignored = */ ui.getAccessibleChildrenCount(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getAccessibleChild(JComponent, int)} method + * for all the UI delegates managed by this <code>MultiScrollPaneUI</code>, + * returning the child for the UI delegate from the primary look and + * feel. + * + * @param c the component + * @param i the child index. + * + * @return The child returned by the UI delegate from the primary + * look and feel. + */ + public Accessible getAccessibleChild(JComponent c, int i) + { + Accessible result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getAccessibleChild(c, i); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Accessible ignored = */ ui.getAccessibleChild(c, i); + } + return result; + } + +} diff --git a/libjava/classpath/javax/swing/plaf/multi/MultiSeparatorUI.java b/libjava/classpath/javax/swing/plaf/multi/MultiSeparatorUI.java new file mode 100644 index 0000000..f8e4fea --- /dev/null +++ b/libjava/classpath/javax/swing/plaf/multi/MultiSeparatorUI.java @@ -0,0 +1,352 @@ +/* MultiSeparatorUI.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.swing.plaf.multi; + +import java.awt.Dimension; +import java.awt.Graphics; +import java.util.Iterator; +import java.util.Vector; + +import javax.accessibility.Accessible; +import javax.swing.JComponent; +import javax.swing.LookAndFeel; +import javax.swing.UIManager; +import javax.swing.plaf.ComponentUI; +import javax.swing.plaf.SeparatorUI; + +/** + * A UI delegate that that coordinates multiple {@link MultiSeparatorUI} + * instances, one from the primary look and feel, and one or more from the + * auxiliary look and feel(s). + * + * @see UIManager#addAuxiliaryLookAndFeel(LookAndFeel) + */ +public class MultiSeparatorUI extends SeparatorUI +{ + + /** A list of references to the actual component UIs. */ + protected Vector uis; + + /** + * Creates a new <code>MultiSeparatorUI</code> instance. + * + * @see #createUI(JComponent) + */ + public MultiSeparatorUI() + { + uis = new Vector(); + } + + /** + * Creates a delegate object for the specified component. If any auxiliary + * look and feels support this component, a <code>MultiSeparatorUI</code> is + * returned, otherwise the UI from the default look and feel is returned. + * + * @param target the component. + * + * @see MultiLookAndFeel#createUIs(ComponentUI, Vector, JComponent) + */ + public static ComponentUI createUI(JComponent target) + { + MultiSeparatorUI mui = new MultiSeparatorUI(); + return MultiLookAndFeel.createUIs(mui, mui.uis, target); + } + + /** + * Calls the {@link ComponentUI#installUI(JComponent)} method for all + * the UI delegates managed by this <code>MultiSeparatorUI</code>. + * + * @param c the component. + */ + public void installUI(JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.installUI(c); + } + } + + /** + * Calls the {@link ComponentUI#uninstallUI(JComponent)} method for all + * the UI delegates managed by this <code>MultiSeparatorUI</code>. + * + * @param c the component. + */ + public void uninstallUI(JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.uninstallUI(c); + } + } + + /** + * Returns an array containing the UI delegates managed by this + * <code>MultiSeparatorUI</code>. The first item in the array is always + * the UI delegate from the installed default look and feel. + * + * @return An array of UI delegates. + */ + public ComponentUI[] getUIs() + { + return MultiLookAndFeel.uisToArray(uis); + } + + /** + * Calls the {@link ComponentUI#contains(JComponent, int, int)} method for all + * the UI delegates managed by this <code>MultiSeparatorUI</code>, + * returning the result for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * @param x the x-coordinate. + * @param y the y-coordinate. + * + * @return <code>true</code> if the specified (x, y) coordinate falls within + * the bounds of the component as rendered by the UI delegate in the + * primary look and feel, and <code>false</code> otherwise. + */ + public boolean contains(JComponent c, int x, int y) + { + boolean result = false; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.contains(c, x, y); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* boolean ignored = */ ui.contains(c, x, y); + } + return result; + } + + /** + * Calls the {@link ComponentUI#update(Graphics, JComponent)} method for all + * the UI delegates managed by this <code>MultiSeparatorUI</code>. + * + * @param g the graphics device. + * @param c the component. + */ + public void update(Graphics g, JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.update(g, c); + } + } + + /** + * Calls the <code>paint(Graphics, JComponent)</code> method for all the UI + * delegates managed by this <code>MultiSeparatorUI</code>. + * + * @param g the graphics device. + * @param c the component. + */ + public void paint(Graphics g, JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.paint(g, c); + } + } + + /** + * Calls the {@link ComponentUI#getPreferredSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiSeparatorUI</code>, + * returning the preferred size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The preferred size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getPreferredSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getPreferredSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getPreferredSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getMinimumSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiSeparatorUI</code>, + * returning the minimum size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The minimum size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getMinimumSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getMinimumSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getMinimumSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getMaximumSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiSeparatorUI</code>, + * returning the maximum size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The maximum size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getMaximumSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getMaximumSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getMaximumSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getAccessibleChildrenCount(JComponent)} method + * for all the UI delegates managed by this <code>MultiSeparatorUI</code>, + * returning the count for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The count returned by the UI delegate from the primary + * look and feel. + */ + public int getAccessibleChildrenCount(JComponent c) + { + int result = 0; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getAccessibleChildrenCount(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* int ignored = */ ui.getAccessibleChildrenCount(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getAccessibleChild(JComponent, int)} method + * for all the UI delegates managed by this <code>MultiSeparatorUI</code>, + * returning the child for the UI delegate from the primary look and + * feel. + * + * @param c the component + * @param i the child index. + * + * @return The child returned by the UI delegate from the primary + * look and feel. + */ + public Accessible getAccessibleChild(JComponent c, int i) + { + Accessible result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getAccessibleChild(c, i); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Accessible ignored = */ ui.getAccessibleChild(c, i); + } + return result; + } + +} diff --git a/libjava/classpath/javax/swing/plaf/multi/MultiSliderUI.java b/libjava/classpath/javax/swing/plaf/multi/MultiSliderUI.java new file mode 100644 index 0000000..8a4aab6 --- /dev/null +++ b/libjava/classpath/javax/swing/plaf/multi/MultiSliderUI.java @@ -0,0 +1,352 @@ +/* MultiSliderUI.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.swing.plaf.multi; + +import java.awt.Dimension; +import java.awt.Graphics; +import java.util.Iterator; +import java.util.Vector; + +import javax.accessibility.Accessible; +import javax.swing.JComponent; +import javax.swing.LookAndFeel; +import javax.swing.UIManager; +import javax.swing.plaf.ComponentUI; +import javax.swing.plaf.SliderUI; + +/** + * A UI delegate that that coordinates multiple {@link SliderUI} + * instances, one from the primary look and feel, and one or more from the + * auxiliary look and feel(s). + * + * @see UIManager#addAuxiliaryLookAndFeel(LookAndFeel) + */ +public class MultiSliderUI extends SliderUI +{ + + /** A list of references to the actual component UIs. */ + protected Vector uis; + + /** + * Creates a new <code>MultiSliderUI</code> instance. + * + * @see #createUI(JComponent) + */ + public MultiSliderUI() + { + uis = new Vector(); + } + + /** + * Creates a delegate object for the specified component. If any auxiliary + * look and feels support this component, a <code>MultiSliderUI</code> is + * returned, otherwise the UI from the default look and feel is returned. + * + * @param target the component. + * + * @see MultiLookAndFeel#createUIs(ComponentUI, Vector, JComponent) + */ + public static ComponentUI createUI(JComponent target) + { + MultiSliderUI mui = new MultiSliderUI(); + return MultiLookAndFeel.createUIs(mui, mui.uis, target); + } + + /** + * Calls the {@link ComponentUI#installUI(JComponent)} method for all + * the UI delegates managed by this <code>MultiSliderUI</code>. + * + * @param c the component. + */ + public void installUI(JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.installUI(c); + } + } + + /** + * Calls the {@link ComponentUI#uninstallUI(JComponent)} method for all + * the UI delegates managed by this <code>MultiSliderUI</code>. + * + * @param c the component. + */ + public void uninstallUI(JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.uninstallUI(c); + } + } + + /** + * Returns an array containing the UI delegates managed by this + * <code>MultiSliderUI</code>. The first item in the array is always + * the UI delegate from the installed default look and feel. + * + * @return An array of UI delegates. + */ + public ComponentUI[] getUIs() + { + return MultiLookAndFeel.uisToArray(uis); + } + + /** + * Calls the {@link ComponentUI#contains(JComponent, int, int)} method for all + * the UI delegates managed by this <code>MultiSliderUI</code>, + * returning the result for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * @param x the x-coordinate. + * @param y the y-coordinate. + * + * @return <code>true</code> if the specified (x, y) coordinate falls within + * the bounds of the component as rendered by the UI delegate in the + * primary look and feel, and <code>false</code> otherwise. + */ + public boolean contains(JComponent c, int x, int y) + { + boolean result = false; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.contains(c, x, y); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* boolean ignored = */ ui.contains(c, x, y); + } + return result; + } + + /** + * Calls the {@link ComponentUI#update(Graphics, JComponent)} method for all + * the UI delegates managed by this <code>MultiSliderUI</code>. + * + * @param g the graphics device. + * @param c the component. + */ + public void update(Graphics g, JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.update(g, c); + } + } + + /** + * Calls the <code>paint(Graphics, JComponent)</code> method for all the UI + * delegates managed by this <code>MultiSliderUI</code>. + * + * @param g the graphics device. + * @param c the component. + */ + public void paint(Graphics g, JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.paint(g, c); + } + } + + /** + * Calls the {@link ComponentUI#getPreferredSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiSliderUI</code>, + * returning the preferred size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The preferred size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getPreferredSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getPreferredSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getPreferredSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getMinimumSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiSliderUI</code>, + * returning the minimum size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The minimum size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getMinimumSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getMinimumSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getMinimumSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getMaximumSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiSliderUI</code>, + * returning the maximum size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The maximum size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getMaximumSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getMaximumSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getMaximumSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getAccessibleChildrenCount(JComponent)} method + * for all the UI delegates managed by this <code>MultiSliderUI</code>, + * returning the count for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The count returned by the UI delegate from the primary + * look and feel. + */ + public int getAccessibleChildrenCount(JComponent c) + { + int result = 0; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getAccessibleChildrenCount(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* int ignored = */ ui.getAccessibleChildrenCount(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getAccessibleChild(JComponent, int)} method + * for all the UI delegates managed by this <code>MultiSliderUI</code>, + * returning the child for the UI delegate from the primary look and + * feel. + * + * @param c the component + * @param i the child index. + * + * @return The child returned by the UI delegate from the primary + * look and feel. + */ + public Accessible getAccessibleChild(JComponent c, int i) + { + Accessible result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getAccessibleChild(c, i); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Accessible ignored = */ ui.getAccessibleChild(c, i); + } + return result; + } + +} diff --git a/libjava/classpath/javax/swing/plaf/multi/MultiSpinnerUI.java b/libjava/classpath/javax/swing/plaf/multi/MultiSpinnerUI.java new file mode 100644 index 0000000..70068e8 --- /dev/null +++ b/libjava/classpath/javax/swing/plaf/multi/MultiSpinnerUI.java @@ -0,0 +1,352 @@ +/* MultiSpinnerUI.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.swing.plaf.multi; + +import java.awt.Dimension; +import java.awt.Graphics; +import java.util.Iterator; +import java.util.Vector; + +import javax.accessibility.Accessible; +import javax.swing.JComponent; +import javax.swing.LookAndFeel; +import javax.swing.UIManager; +import javax.swing.plaf.ComponentUI; +import javax.swing.plaf.SpinnerUI; + +/** + * A UI delegate that that coordinates multiple {@link SpinnerUI} + * instances, one from the primary look and feel, and one or more from the + * auxiliary look and feel(s). + * + * @see UIManager#addAuxiliaryLookAndFeel(LookAndFeel) + */ +public class MultiSpinnerUI extends SpinnerUI +{ + + /** A list of references to the actual component UIs. */ + protected Vector uis; + + /** + * Creates a new <code>MultiSpinnerUI</code> instance. + * + * @see #createUI(JComponent) + */ + public MultiSpinnerUI() + { + uis = new Vector(); + } + + /** + * Creates a delegate object for the specified component. If any auxiliary + * look and feels support this component, a <code>MultiSpinnerUI</code> is + * returned, otherwise the UI from the default look and feel is returned. + * + * @param target the component. + * + * @see MultiLookAndFeel#createUIs(ComponentUI, Vector, JComponent) + */ + public static ComponentUI createUI(JComponent target) + { + MultiSpinnerUI mui = new MultiSpinnerUI(); + return MultiLookAndFeel.createUIs(mui, mui.uis, target); + } + + /** + * Calls the {@link ComponentUI#installUI(JComponent)} method for all + * the UI delegates managed by this <code>MultiSpinnerUI</code>. + * + * @param c the component. + */ + public void installUI(JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.installUI(c); + } + } + + /** + * Calls the {@link ComponentUI#uninstallUI(JComponent)} method for all + * the UI delegates managed by this <code>MultiSpinnerUI</code>. + * + * @param c the component. + */ + public void uninstallUI(JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.uninstallUI(c); + } + } + + /** + * Returns an array containing the UI delegates managed by this + * <code>MultiSpinnerUI</code>. The first item in the array is always + * the UI delegate from the installed default look and feel. + * + * @return An array of UI delegates. + */ + public ComponentUI[] getUIs() + { + return MultiLookAndFeel.uisToArray(uis); + } + + /** + * Calls the {@link ComponentUI#contains(JComponent, int, int)} method for all + * the UI delegates managed by this <code>MultiSpinnerUI</code>, + * returning the result for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * @param x the x-coordinate. + * @param y the y-coordinate. + * + * @return <code>true</code> if the specified (x, y) coordinate falls within + * the bounds of the component as rendered by the UI delegate in the + * primary look and feel, and <code>false</code> otherwise. + */ + public boolean contains(JComponent c, int x, int y) + { + boolean result = false; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.contains(c, x, y); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* boolean ignored = */ ui.contains(c, x, y); + } + return result; + } + + /** + * Calls the {@link ComponentUI#update(Graphics, JComponent)} method for all + * the UI delegates managed by this <code>MultiSpinnerUI</code>. + * + * @param g the graphics device. + * @param c the component. + */ + public void update(Graphics g, JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.update(g, c); + } + } + + /** + * Calls the <code>paint(Graphics, JComponent)</code> method for all the UI + * delegates managed by this <code>MultiSpinnerUI</code>. + * + * @param g the graphics device. + * @param c the component. + */ + public void paint(Graphics g, JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.paint(g, c); + } + } + + /** + * Calls the {@link ComponentUI#getPreferredSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiSpinnerUI</code>, + * returning the preferred size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The preferred size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getPreferredSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getPreferredSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getPreferredSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getMinimumSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiSpinnerUI</code>, + * returning the minimum size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The minimum size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getMinimumSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getMinimumSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getMinimumSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getMaximumSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiSpinnerUI</code>, + * returning the maximum size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The maximum size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getMaximumSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getMaximumSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getMaximumSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getAccessibleChildrenCount(JComponent)} method + * for all the UI delegates managed by this <code>MultiSpinnerUI</code>, + * returning the count for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The count returned by the UI delegate from the primary + * look and feel. + */ + public int getAccessibleChildrenCount(JComponent c) + { + int result = 0; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getAccessibleChildrenCount(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* int ignored = */ ui.getAccessibleChildrenCount(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getAccessibleChild(JComponent, int)} method + * for all the UI delegates managed by this <code>MultiSpinnerUI</code>, + * returning the child for the UI delegate from the primary look and + * feel. + * + * @param c the component + * @param i the child index. + * + * @return The child returned by the UI delegate from the primary + * look and feel. + */ + public Accessible getAccessibleChild(JComponent c, int i) + { + Accessible result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getAccessibleChild(c, i); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Accessible ignored = */ ui.getAccessibleChild(c, i); + } + return result; + } + +} diff --git a/libjava/classpath/javax/swing/plaf/multi/MultiSplitPaneUI.java b/libjava/classpath/javax/swing/plaf/multi/MultiSplitPaneUI.java new file mode 100644 index 0000000..f481f81 --- /dev/null +++ b/libjava/classpath/javax/swing/plaf/multi/MultiSplitPaneUI.java @@ -0,0 +1,488 @@ +/* MultiSplitPaneUI.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.swing.plaf.multi; + +import java.awt.Dimension; +import java.awt.Graphics; +import java.util.Iterator; +import java.util.Vector; + +import javax.accessibility.Accessible; +import javax.swing.JComponent; +import javax.swing.JSplitPane; +import javax.swing.LookAndFeel; +import javax.swing.UIManager; +import javax.swing.plaf.ComponentUI; +import javax.swing.plaf.SplitPaneUI; + +/** + * A UI delegate that that coordinates multiple {@link SplitPaneUI} + * instances, one from the primary look and feel, and one or more from the + * auxiliary look and feel(s). + * + * @see UIManager#addAuxiliaryLookAndFeel(LookAndFeel) + */ +public class MultiSplitPaneUI extends SplitPaneUI +{ + + /** A list of references to the actual component UIs. */ + protected Vector uis; + + /** + * Creates a new <code>MultiSplitPaneUI</code> instance. + * + * @see #createUI(JComponent) + */ + public MultiSplitPaneUI() + { + uis = new Vector(); + } + + /** + * Creates a delegate object for the specified component. If any auxiliary + * look and feels support this component, a <code>MultiSplitPaneUI</code> is + * returned, otherwise the UI from the default look and feel is returned. + * + * @param target the component. + * + * @see MultiLookAndFeel#createUIs(ComponentUI, Vector, JComponent) + */ + public static ComponentUI createUI(JComponent target) + { + MultiSplitPaneUI mui = new MultiSplitPaneUI(); + return MultiLookAndFeel.createUIs(mui, mui.uis, target); + } + + /** + * Calls the {@link ComponentUI#installUI(JComponent)} method for all + * the UI delegates managed by this <code>MultiSplitPaneUI</code>. + * + * @param c the component. + */ + public void installUI(JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.installUI(c); + } + } + + /** + * Calls the {@link ComponentUI#uninstallUI(JComponent)} method for all + * the UI delegates managed by this <code>MultiSplitPaneUI</code>. + * + * @param c the component. + */ + public void uninstallUI(JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.uninstallUI(c); + } + } + + /** + * Returns an array containing the UI delegates managed by this + * <code>MultiSplitPaneUI</code>. The first item in the array is always + * the UI delegate from the installed default look and feel. + * + * @return An array of UI delegates. + */ + public ComponentUI[] getUIs() + { + return MultiLookAndFeel.uisToArray(uis); + } + + /** + * Calls the {@link ComponentUI#contains(JComponent, int, int)} method for all + * the UI delegates managed by this <code>MultiSplitPaneUI</code>, + * returning the result for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * @param x the x-coordinate. + * @param y the y-coordinate. + * + * @return <code>true</code> if the specified (x, y) coordinate falls within + * the bounds of the component as rendered by the UI delegate in the + * primary look and feel, and <code>false</code> otherwise. + */ + public boolean contains(JComponent c, int x, int y) + { + boolean result = false; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.contains(c, x, y); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* boolean ignored = */ ui.contains(c, x, y); + } + return result; + } + + /** + * Calls the {@link ComponentUI#update(Graphics, JComponent)} method for all + * the UI delegates managed by this <code>MultiSplitPaneUI</code>. + * + * @param g the graphics device. + * @param c the component. + */ + public void update(Graphics g, JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.update(g, c); + } + } + + /** + * Calls the <code>paint(Graphics, JComponent)</code> method for all the UI + * delegates managed by this <code>MultiSplitPaneUI</code>. + * + * @param g the graphics device. + * @param c the component. + */ + public void paint(Graphics g, JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.paint(g, c); + } + } + + /** + * Calls the {@link ComponentUI#getPreferredSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiSplitPaneUI</code>, + * returning the preferred size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The preferred size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getPreferredSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getPreferredSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getPreferredSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getMinimumSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiSplitPaneUI</code>, + * returning the minimum size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The minimum size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getMinimumSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getMinimumSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getMinimumSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getMaximumSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiSplitPaneUI</code>, + * returning the maximum size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The maximum size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getMaximumSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getMaximumSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getMaximumSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getAccessibleChildrenCount(JComponent)} method + * for all the UI delegates managed by this <code>MultiSplitPaneUI</code>, + * returning the count for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The count returned by the UI delegate from the primary + * look and feel. + */ + public int getAccessibleChildrenCount(JComponent c) + { + int result = 0; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getAccessibleChildrenCount(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* int ignored = */ ui.getAccessibleChildrenCount(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getAccessibleChild(JComponent, int)} method + * for all the UI delegates managed by this <code>MultiSplitPaneUI</code>, + * returning the child for the UI delegate from the primary look and + * feel. + * + * @param c the component + * @param i the child index. + * + * @return The child returned by the UI delegate from the primary + * look and feel. + */ + public Accessible getAccessibleChild(JComponent c, int i) + { + Accessible result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getAccessibleChild(c, i); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Accessible ignored = */ ui.getAccessibleChild(c, i); + } + return result; + } + + /** + * Calls the {@link SplitPaneUI#resetToPreferredSizes(JSplitPane)} method + * for all the UI delegates managed by this <code>MultiSplitPaneUI</code>. + * + * @param pane the component. + */ + public void resetToPreferredSizes(JSplitPane pane) { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + SplitPaneUI ui = (SplitPaneUI) iterator.next(); + ui.resetToPreferredSizes(pane); + } + } + + /** + * Calls the {@link SplitPaneUI#setDividerLocation(JSplitPane, int)} method + * for all the UI delegates managed by this <code>MultiSplitPaneUI</code>. + * + * @param pane the component. + * @param location the location. + */ + public void setDividerLocation(JSplitPane pane, int location) { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + SplitPaneUI ui = (SplitPaneUI) iterator.next(); + ui.setDividerLocation(pane, location); + } + } + + /** + * Calls the {@link SplitPaneUI#getDividerLocation(JSplitPane)} method for all + * the UI delegates managed by this <code>MultiSplitPaneUI</code>, + * returning the location for the UI delegate from the primary look and + * feel. + * + * @param pane the component. + * + * @return The location returned by the UI delegate from the primary + * look and feel. + */ + public int getDividerLocation(JSplitPane pane) { + int result = 0; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + SplitPaneUI ui = (SplitPaneUI) iterator.next(); + result = ui.getDividerLocation(pane); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + SplitPaneUI ui = (SplitPaneUI) iterator.next(); + /* int ignored = */ ui.getDividerLocation(pane); + } + return result; + } + + /** + * Calls the {@link SplitPaneUI#getMinimumDividerLocation(JSplitPane)} method + * for all the UI delegates managed by this <code>MultiSplitPaneUI</code>, + * returning the location for the UI delegate from the primary look and + * feel. + * + * @param pane the component. + * + * @return The location returned by the UI delegate from the primary + * look and feel. + */ + public int getMinimumDividerLocation(JSplitPane pane) { + int result = 0; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + SplitPaneUI ui = (SplitPaneUI) iterator.next(); + result = ui.getMinimumDividerLocation(pane); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + SplitPaneUI ui = (SplitPaneUI) iterator.next(); + /* int ignored = */ ui.getMinimumDividerLocation(pane); + } + return result; + } + + /** + * Calls the {@link SplitPaneUI#getMaximumDividerLocation(JSplitPane)} method + * for all the UI delegates managed by this <code>MultiSplitPaneUI</code>, + * returning the location for the UI delegate from the primary look and + * feel. + * + * @param pane the component. + * + * @return The location returned by the UI delegate from the primary + * look and feel. + */ + public int getMaximumDividerLocation(JSplitPane pane) { + int result = 0; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + SplitPaneUI ui = (SplitPaneUI) iterator.next(); + result = ui.getMaximumDividerLocation(pane); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + SplitPaneUI ui = (SplitPaneUI) iterator.next(); + /* int ignored = */ ui.getMaximumDividerLocation(pane); + } + return result; + } + + /** + * Calls the {@link SplitPaneUI#finishedPaintingChildren(JSplitPane, + * Graphics)} method for all the UI delegates managed by this + * <code>MultiSplitPaneUI</code>. + * + * @param pane the component. + * @param g the graphics device. + */ + public void finishedPaintingChildren(JSplitPane pane, Graphics g) { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + SplitPaneUI ui = (SplitPaneUI) iterator.next(); + ui.finishedPaintingChildren(pane, g); + } + } + +} diff --git a/libjava/classpath/javax/swing/plaf/multi/MultiTabbedPaneUI.java b/libjava/classpath/javax/swing/plaf/multi/MultiTabbedPaneUI.java new file mode 100644 index 0000000..575de19 --- /dev/null +++ b/libjava/classpath/javax/swing/plaf/multi/MultiTabbedPaneUI.java @@ -0,0 +1,444 @@ +/* MultiTabbedPaneUI.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.swing.plaf.multi; + +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.Rectangle; +import java.util.Iterator; +import java.util.Vector; + +import javax.accessibility.Accessible; +import javax.swing.JComponent; +import javax.swing.JTabbedPane; +import javax.swing.LookAndFeel; +import javax.swing.UIManager; +import javax.swing.plaf.ComponentUI; +import javax.swing.plaf.TabbedPaneUI; + +/** + * A UI delegate that that coordinates multiple {@link TabbedPaneUI} + * instances, one from the primary look and feel, and one or more from the + * auxiliary look and feel(s). + * + * @see UIManager#addAuxiliaryLookAndFeel(LookAndFeel) + */ +public class MultiTabbedPaneUI extends TabbedPaneUI +{ + + /** A list of references to the actual component UIs. */ + protected Vector uis; + + /** + * Creates a new <code>MultiTabbedPaneUI</code> instance. + * + * @see #createUI(JComponent) + */ + public MultiTabbedPaneUI() + { + uis = new Vector(); + } + + /** + * Creates a delegate object for the specified component. If any auxiliary + * look and feels support this component, a <code>MultiTabbedPaneUI</code> is + * returned, otherwise the UI from the default look and feel is returned. + * + * @param target the component. + * + * @see MultiLookAndFeel#createUIs(ComponentUI, Vector, JComponent) + */ + public static ComponentUI createUI(JComponent target) + { + MultiTabbedPaneUI mui = new MultiTabbedPaneUI(); + return MultiLookAndFeel.createUIs(mui, mui.uis, target); + } + + /** + * Calls the {@link ComponentUI#installUI(JComponent)} method for all + * the UI delegates managed by this <code>MultiTabbedPaneUI</code>. + * + * @param c the component. + */ + public void installUI(JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.installUI(c); + } + } + + /** + * Calls the {@link ComponentUI#uninstallUI(JComponent)} method for all + * the UI delegates managed by this <code>MultiTabbedPaneUI</code>. + * + * @param c the component. + */ + public void uninstallUI(JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.uninstallUI(c); + } + } + + /** + * Returns an array containing the UI delegates managed by this + * <code>MultiTabbedPaneUI</code>. The first item in the array is always + * the UI delegate from the installed default look and feel. + * + * @return An array of UI delegates. + */ + public ComponentUI[] getUIs() + { + return MultiLookAndFeel.uisToArray(uis); + } + + /** + * Calls the {@link ComponentUI#contains(JComponent, int, int)} method for all + * the UI delegates managed by this <code>MultiTabbedPaneUI</code>, + * returning the result for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * @param x the x-coordinate. + * @param y the y-coordinate. + * + * @return <code>true</code> if the specified (x, y) coordinate falls within + * the bounds of the component as rendered by the UI delegate in the + * primary look and feel, and <code>false</code> otherwise. + */ + public boolean contains(JComponent c, int x, int y) + { + boolean result = false; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.contains(c, x, y); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* boolean ignored = */ ui.contains(c, x, y); + } + return result; + } + + /** + * Calls the {@link ComponentUI#update(Graphics, JComponent)} method for all + * the UI delegates managed by this <code>MultiTabbedPaneUI</code>. + * + * @param g the graphics device. + * @param c the component. + */ + public void update(Graphics g, JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.update(g, c); + } + } + + /** + * Calls the <code>paint(Graphics, JComponent)</code> method for all the UI + * delegates managed by this <code>MultiTabbedPaneUI</code>. + * + * @param g the graphics device. + * @param c the component. + */ + public void paint(Graphics g, JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.paint(g, c); + } + } + + /** + * Calls the {@link ComponentUI#getPreferredSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiTabbedPaneUI</code>, + * returning the preferred size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The preferred size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getPreferredSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getPreferredSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getPreferredSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getMinimumSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiTabbedPaneUI</code>, + * returning the minimum size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The minimum size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getMinimumSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getMinimumSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getMinimumSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getMaximumSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiTabbedPaneUI</code>, + * returning the maximum size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The maximum size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getMaximumSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getMaximumSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getMaximumSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getAccessibleChildrenCount(JComponent)} method + * for all the UI delegates managed by this <code>MultiTabbedPaneUI</code>, + * returning the count for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The count returned by the UI delegate from the primary + * look and feel. + */ + public int getAccessibleChildrenCount(JComponent c) + { + int result = 0; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getAccessibleChildrenCount(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* int ignored = */ ui.getAccessibleChildrenCount(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getAccessibleChild(JComponent, int)} method + * for all the UI delegates managed by this <code>MultiTabbedPaneUI</code>, + * returning the child for the UI delegate from the primary look and + * feel. + * + * @param c the component + * @param i the child index. + * + * @return The child returned by the UI delegate from the primary + * look and feel. + */ + public Accessible getAccessibleChild(JComponent c, int i) + { + Accessible result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getAccessibleChild(c, i); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Accessible ignored = */ ui.getAccessibleChild(c, i); + } + return result; + } + + /** + * Calls the {@link TabbedPaneUI#tabForCoordinate(JTabbedPane, int, int)} + * method for all the UI delegates managed by this + * <code>MultiTabbedPaneUI</code>, returning the tab index for the UI + * delegate from the primary look and feel. + * + * @param pane the tabbed pane. + * @param x the x-coordinate. + * @param y the y-coordinate. + * + * @return The tab index returned by the UI delegate from the primary + * look and feel. + */ + public int tabForCoordinate(JTabbedPane pane, int x, int y) { + int result = 0; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + TabbedPaneUI ui = (TabbedPaneUI) iterator.next(); + result = ui.tabForCoordinate(pane, x, y); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + TabbedPaneUI ui = (TabbedPaneUI) iterator.next(); + /* int ignored = */ ui.tabForCoordinate(pane, x, y); + } + return result; + } + + /** + * Calls the {@link TabbedPaneUI#getTabBounds(JTabbedPane, int)} + * method for all the UI delegates managed by this + * <code>MultiTabbedPaneUI</code>, returning the bounds for the UI + * delegate from the primary look and feel. + * + * @param pane the tabbed pane. + * @param index the index. + * + * @return The bounds returned by the UI delegate from the primary + * look and feel. + */ + public Rectangle getTabBounds(JTabbedPane pane, int index) { + Rectangle result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + TabbedPaneUI ui = (TabbedPaneUI) iterator.next(); + result = ui.getTabBounds(pane, index); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + TabbedPaneUI ui = (TabbedPaneUI) iterator.next(); + /* int ignored = */ ui.getTabRunCount(pane); + } + return result; + } + + /** + * Calls the {@link TabbedPaneUI#getTabRunCount(JTabbedPane)} + * method for all the UI delegates managed by this + * <code>MultiTabbedPaneUI</code>, returning the nt for the UI + * delegate from the primary look and feel. + * + * @param pane the tabbed pane. + * + * @return The count returned by the UI delegate from the primary + * look and feel. + */ + public int getTabRunCount(JTabbedPane pane) { + int result = 0; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + TabbedPaneUI ui = (TabbedPaneUI) iterator.next(); + result = ui.getTabRunCount(pane); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + TabbedPaneUI ui = (TabbedPaneUI) iterator.next(); + /* int ignored = */ ui.getTabRunCount(pane); + } + return result; + } + +} diff --git a/libjava/classpath/javax/swing/plaf/multi/MultiTableHeaderUI.java b/libjava/classpath/javax/swing/plaf/multi/MultiTableHeaderUI.java new file mode 100644 index 0000000..6c59cef --- /dev/null +++ b/libjava/classpath/javax/swing/plaf/multi/MultiTableHeaderUI.java @@ -0,0 +1,352 @@ +/* MultiTableHeaderUI.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.swing.plaf.multi; + +import java.awt.Dimension; +import java.awt.Graphics; +import java.util.Iterator; +import java.util.Vector; + +import javax.accessibility.Accessible; +import javax.swing.JComponent; +import javax.swing.LookAndFeel; +import javax.swing.UIManager; +import javax.swing.plaf.ComponentUI; +import javax.swing.plaf.TableHeaderUI; + +/** + * A UI delegate that that coordinates multiple {@link TableHeaderUI} + * instances, one from the primary look and feel, and one or more from the + * auxiliary look and feel(s). + * + * @see UIManager#addAuxiliaryLookAndFeel(LookAndFeel) + */ +public class MultiTableHeaderUI extends TableHeaderUI +{ + + /** A list of references to the actual component UIs. */ + protected Vector uis; + + /** + * Creates a new <code>MultiTableHeaderUI</code> instance. + * + * @see #createUI(JComponent) + */ + public MultiTableHeaderUI() + { + uis = new Vector(); + } + + /** + * Creates a delegate object for the specified component. If any auxiliary + * look and feels support this component, a <code>MultiTableHeaderUI</code> is + * returned, otherwise the UI from the default look and feel is returned. + * + * @param target the component. + * + * @see MultiLookAndFeel#createUIs(ComponentUI, Vector, JComponent) + */ + public static ComponentUI createUI(JComponent target) + { + MultiTableHeaderUI mui = new MultiTableHeaderUI(); + return MultiLookAndFeel.createUIs(mui, mui.uis, target); + } + + /** + * Calls the {@link ComponentUI#installUI(JComponent)} method for all + * the UI delegates managed by this <code>MultiTableHeaderUI</code>. + * + * @param c the component. + */ + public void installUI(JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.installUI(c); + } + } + + /** + * Calls the {@link ComponentUI#uninstallUI(JComponent)} method for all + * the UI delegates managed by this <code>MultiTableHeaderUI</code>. + * + * @param c the component. + */ + public void uninstallUI(JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.uninstallUI(c); + } + } + + /** + * Returns an array containing the UI delegates managed by this + * <code>MultiTableHeaderUI</code>. The first item in the array is always + * the UI delegate from the installed default look and feel. + * + * @return An array of UI delegates. + */ + public ComponentUI[] getUIs() + { + return MultiLookAndFeel.uisToArray(uis); + } + + /** + * Calls the {@link ComponentUI#contains(JComponent, int, int)} method for all + * the UI delegates managed by this <code>MultiTableHeaderUI</code>, + * returning the result for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * @param x the x-coordinate. + * @param y the y-coordinate. + * + * @return <code>true</code> if the specified (x, y) coordinate falls within + * the bounds of the component as rendered by the UI delegate in the + * primary look and feel, and <code>false</code> otherwise. + */ + public boolean contains(JComponent c, int x, int y) + { + boolean result = false; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.contains(c, x, y); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* boolean ignored = */ ui.contains(c, x, y); + } + return result; + } + + /** + * Calls the {@link ComponentUI#update(Graphics, JComponent)} method for all + * the UI delegates managed by this <code>MultiTableHeaderUI</code>. + * + * @param g the graphics device. + * @param c the component. + */ + public void update(Graphics g, JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.update(g, c); + } + } + + /** + * Calls the <code>paint(Graphics, JComponent)</code> method for all the UI + * delegates managed by this <code>MultiTableHeaderUI</code>. + * + * @param g the graphics device. + * @param c the component. + */ + public void paint(Graphics g, JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.paint(g, c); + } + } + + /** + * Calls the {@link ComponentUI#getPreferredSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiTableHeaderUI</code>, + * returning the preferred size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The preferred size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getPreferredSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getPreferredSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getPreferredSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getMinimumSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiTableHeaderUI</code>, + * returning the minimum size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The minimum size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getMinimumSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getMinimumSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getMinimumSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getMaximumSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiTableHeaderUI</code>, + * returning the maximum size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The maximum size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getMaximumSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getMaximumSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getMaximumSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getAccessibleChildrenCount(JComponent)} method + * for all the UI delegates managed by this <code>MultiTableHeaderUI</code>, + * returning the count for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The count returned by the UI delegate from the primary + * look and feel. + */ + public int getAccessibleChildrenCount(JComponent c) + { + int result = 0; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getAccessibleChildrenCount(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* int ignored = */ ui.getAccessibleChildrenCount(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getAccessibleChild(JComponent, int)} method + * for all the UI delegates managed by this <code>MultiTableHeaderUI</code>, + * returning the child for the UI delegate from the primary look and + * feel. + * + * @param c the component + * @param i the child index. + * + * @return The child returned by the UI delegate from the primary + * look and feel. + */ + public Accessible getAccessibleChild(JComponent c, int i) + { + Accessible result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getAccessibleChild(c, i); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Accessible ignored = */ ui.getAccessibleChild(c, i); + } + return result; + } + +} diff --git a/libjava/classpath/javax/swing/plaf/multi/MultiTableUI.java b/libjava/classpath/javax/swing/plaf/multi/MultiTableUI.java new file mode 100644 index 0000000..2e5b5bc --- /dev/null +++ b/libjava/classpath/javax/swing/plaf/multi/MultiTableUI.java @@ -0,0 +1,352 @@ +/* MultiTableUI.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.swing.plaf.multi; + +import java.awt.Dimension; +import java.awt.Graphics; +import java.util.Iterator; +import java.util.Vector; + +import javax.accessibility.Accessible; +import javax.swing.JComponent; +import javax.swing.LookAndFeel; +import javax.swing.UIManager; +import javax.swing.plaf.ComponentUI; +import javax.swing.plaf.TableUI; + +/** + * A UI delegate that that coordinates multiple {@link TableUI} + * instances, one from the primary look and feel, and one or more from the + * auxiliary look and feel(s). + * + * @see UIManager#addAuxiliaryLookAndFeel(LookAndFeel) + */ +public class MultiTableUI extends TableUI +{ + + /** A list of references to the actual component UIs. */ + protected Vector uis; + + /** + * Creates a new <code>MultiTableUI</code> instance. + * + * @see #createUI(JComponent) + */ + public MultiTableUI() + { + uis = new Vector(); + } + + /** + * Creates a delegate object for the specified component. If any auxiliary + * look and feels support this component, a <code>MultiTableUI</code> is + * returned, otherwise the UI from the default look and feel is returned. + * + * @param target the component. + * + * @see MultiLookAndFeel#createUIs(ComponentUI, Vector, JComponent) + */ + public static ComponentUI createUI(JComponent target) + { + MultiTableUI mui = new MultiTableUI(); + return MultiLookAndFeel.createUIs(mui, mui.uis, target); + } + + /** + * Calls the {@link ComponentUI#installUI(JComponent)} method for all + * the UI delegates managed by this <code>MultiTableUI</code>. + * + * @param c the component. + */ + public void installUI(JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.installUI(c); + } + } + + /** + * Calls the {@link ComponentUI#uninstallUI(JComponent)} method for all + * the UI delegates managed by this <code>MultiTableUI</code>. + * + * @param c the component. + */ + public void uninstallUI(JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.uninstallUI(c); + } + } + + /** + * Returns an array containing the UI delegates managed by this + * <code>MultiTableUI</code>. The first item in the array is always + * the UI delegate from the installed default look and feel. + * + * @return An array of UI delegates. + */ + public ComponentUI[] getUIs() + { + return MultiLookAndFeel.uisToArray(uis); + } + + /** + * Calls the {@link ComponentUI#contains(JComponent, int, int)} method for all + * the UI delegates managed by this <code>MultiTableUI</code>, + * returning the result for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * @param x the x-coordinate. + * @param y the y-coordinate. + * + * @return <code>true</code> if the specified (x, y) coordinate falls within + * the bounds of the component as rendered by the UI delegate in the + * primary look and feel, and <code>false</code> otherwise. + */ + public boolean contains(JComponent c, int x, int y) + { + boolean result = false; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.contains(c, x, y); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* boolean ignored = */ ui.contains(c, x, y); + } + return result; + } + + /** + * Calls the {@link ComponentUI#update(Graphics, JComponent)} method for all + * the UI delegates managed by this <code>MultiTableUI</code>. + * + * @param g the graphics device. + * @param c the component. + */ + public void update(Graphics g, JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.update(g, c); + } + } + + /** + * Calls the <code>paint(Graphics, JComponent)</code> method for all the UI + * delegates managed by this <code>MultiTableUI</code>. + * + * @param g the graphics device. + * @param c the component. + */ + public void paint(Graphics g, JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.paint(g, c); + } + } + + /** + * Calls the {@link ComponentUI#getPreferredSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiTableUI</code>, + * returning the preferred size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The preferred size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getPreferredSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getPreferredSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getPreferredSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getMinimumSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiTableUI</code>, + * returning the minimum size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The minimum size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getMinimumSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getMinimumSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getMinimumSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getMaximumSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiTableUI</code>, + * returning the maximum size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The maximum size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getMaximumSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getMaximumSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getMaximumSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getAccessibleChildrenCount(JComponent)} method + * for all the UI delegates managed by this <code>MultiTableUI</code>, + * returning the count for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The count returned by the UI delegate from the primary + * look and feel. + */ + public int getAccessibleChildrenCount(JComponent c) + { + int result = 0; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getAccessibleChildrenCount(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* int ignored = */ ui.getAccessibleChildrenCount(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getAccessibleChild(JComponent, int)} method + * for all the UI delegates managed by this <code>MultiTableUI</code>, + * returning the child for the UI delegate from the primary look and + * feel. + * + * @param c the component + * @param i the child index. + * + * @return The child returned by the UI delegate from the primary + * look and feel. + */ + public Accessible getAccessibleChild(JComponent c, int i) + { + Accessible result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getAccessibleChild(c, i); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Accessible ignored = */ ui.getAccessibleChild(c, i); + } + return result; + } + +} diff --git a/libjava/classpath/javax/swing/plaf/multi/MultiTextUI.java b/libjava/classpath/javax/swing/plaf/multi/MultiTextUI.java new file mode 100644 index 0000000..c5dee24 --- /dev/null +++ b/libjava/classpath/javax/swing/plaf/multi/MultiTextUI.java @@ -0,0 +1,617 @@ +/* MultiTextUI.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.swing.plaf.multi; + +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.Point; +import java.awt.Rectangle; +import java.util.Iterator; +import java.util.Vector; + +import javax.accessibility.Accessible; +import javax.swing.JComponent; +import javax.swing.LookAndFeel; +import javax.swing.UIManager; +import javax.swing.plaf.ComponentUI; +import javax.swing.plaf.TextUI; +import javax.swing.text.BadLocationException; +import javax.swing.text.EditorKit; +import javax.swing.text.JTextComponent; +import javax.swing.text.Position; +import javax.swing.text.View; +import javax.swing.text.Position.Bias; + +/** + * A UI delegate that that coordinates multiple {@link TextUI} + * instances, one from the primary look and feel, and one or more from the + * auxiliary look and feel(s). + * + * @see UIManager#addAuxiliaryLookAndFeel(LookAndFeel) + */ +public class MultiTextUI extends TextUI +{ + + /** A list of references to the actual component UIs. */ + protected Vector uis; + + /** + * Creates a new <code>MultiTextUI</code> instance. + * + * @see #createUI(JComponent) + */ + public MultiTextUI() + { + uis = new Vector(); + } + + /** + * Creates a delegate object for the specified component. If any auxiliary + * look and feels support this component, a <code>MultiTextUI</code> is + * returned, otherwise the UI from the default look and feel is returned. + * + * @param target the component. + * + * @see MultiLookAndFeel#createUIs(ComponentUI, Vector, JComponent) + */ + public static ComponentUI createUI(JComponent target) + { + MultiTextUI mui = new MultiTextUI(); + return MultiLookAndFeel.createUIs(mui, mui.uis, target); + } + + /** + * Calls the {@link ComponentUI#installUI(JComponent)} method for all + * the UI delegates managed by this <code>MultiTextUI</code>. + * + * @param c the component. + */ + public void installUI(JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.installUI(c); + } + } + + /** + * Calls the {@link ComponentUI#uninstallUI(JComponent)} method for all + * the UI delegates managed by this <code>MultiTextUI</code>. + * + * @param c the component. + */ + public void uninstallUI(JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.uninstallUI(c); + } + } + + /** + * Returns an array containing the UI delegates managed by this + * <code>MultiTextUI</code>. The first item in the array is always + * the UI delegate from the installed default look and feel. + * + * @return An array of UI delegates. + */ + public ComponentUI[] getUIs() + { + return MultiLookAndFeel.uisToArray(uis); + } + + /** + * Calls the {@link ComponentUI#contains(JComponent, int, int)} method for all + * the UI delegates managed by this <code>MultiTextUI</code>, + * returning the result for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * @param x the x-coordinate. + * @param y the y-coordinate. + * + * @return <code>true</code> if the specified (x, y) coordinate falls within + * the bounds of the component as rendered by the UI delegate in the + * primary look and feel, and <code>false</code> otherwise. + */ + public boolean contains(JComponent c, int x, int y) + { + boolean result = false; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.contains(c, x, y); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* boolean ignored = */ ui.contains(c, x, y); + } + return result; + } + + /** + * Calls the {@link ComponentUI#update(Graphics, JComponent)} method for all + * the UI delegates managed by this <code>MultiTextUI</code>. + * + * @param g the graphics device. + * @param c the component. + */ + public void update(Graphics g, JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.update(g, c); + } + } + + /** + * Calls the <code>paint(Graphics, JComponent)</code> method for all the UI + * delegates managed by this <code>MultiTextUI</code>. + * + * @param g the graphics device. + * @param c the component. + */ + public void paint(Graphics g, JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.paint(g, c); + } + } + + /** + * Calls the {@link ComponentUI#getPreferredSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiTextUI</code>, + * returning the preferred size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The preferred size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getPreferredSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getPreferredSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getPreferredSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getMinimumSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiTextUI</code>, + * returning the minimum size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The minimum size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getMinimumSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getMinimumSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getMinimumSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getMaximumSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiTextUI</code>, + * returning the maximum size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The maximum size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getMaximumSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getMaximumSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getMaximumSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getAccessibleChildrenCount(JComponent)} method + * for all the UI delegates managed by this <code>MultiTextUI</code>, + * returning the count for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The count returned by the UI delegate from the primary + * look and feel. + */ + public int getAccessibleChildrenCount(JComponent c) + { + int result = 0; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getAccessibleChildrenCount(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* int ignored = */ ui.getAccessibleChildrenCount(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getAccessibleChild(JComponent, int)} method + * for all the UI delegates managed by this <code>MultiTextUI</code>, + * returning the child for the UI delegate from the primary look and + * feel. + * + * @param c the component + * @param i the child index. + * + * @return The child returned by the UI delegate from the primary + * look and feel. + */ + public Accessible getAccessibleChild(JComponent c, int i) + { + Accessible result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getAccessibleChild(c, i); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Accessible ignored = */ ui.getAccessibleChild(c, i); + } + return result; + } + + /** + * Calls the {@link TextUI#modelToView(JTextComponent, int)} method for all + * the UI delegates managed by this <code>MultiTextUI</code>, + * returning the bounds for the UI delegate from the primary look and + * feel. + * + * @param tc the text component. + * + * @return The bounds returned by the UI delegate from the primary + * look and feel. + */ + public Rectangle modelToView(JTextComponent tc, int pos) + throws BadLocationException + { + Rectangle result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + TextUI ui = (TextUI) iterator.next(); + result = ui.modelToView(tc, pos); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + TextUI ui = (TextUI) iterator.next(); + /* Rectangle ignored = */ ui.modelToView(tc, pos); + } + return result; + } + + /** + * Calls the {@link TextUI#modelToView(JTextComponent, int, Position.Bias)} + * method for all the UI delegates managed by this <code>MultiTextUI</code>, + * returning the bounds for the UI delegate from the primary look and + * feel. + * + * @param tc the text component. + * + * @return The bounds returned by the UI delegate from the primary + * look and feel. + */ + public Rectangle modelToView(JTextComponent tc, int pos, Bias bias) + throws BadLocationException + { + Rectangle result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + TextUI ui = (TextUI) iterator.next(); + result = ui.modelToView(tc, pos, bias); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + TextUI ui = (TextUI) iterator.next(); + /* Rectangle ignored = */ ui.modelToView(tc, pos, bias); + } + return result; + } + + /** + * Calls the {@link TextUI#viewToModel(JTextComponent, Point)} method for all + * the UI delegates managed by this <code>MultiTextUI</code>, + * returning the position for the UI delegate from the primary look and + * feel. + * + * @param t the text component. + * @param pt the point. + * + * @return The position returned by the UI delegate from the primary + * look and feel. + */ + public int viewToModel(JTextComponent t, Point pt) + { + int result = 0; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + TextUI ui = (TextUI) iterator.next(); + result = ui.viewToModel(t, pt); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + TextUI ui = (TextUI) iterator.next(); + /* int ignored = */ ui.viewToModel(t, pt); + } + return result; + } + + /** + * Calls the {@link TextUI#viewToModel(JTextComponent, Point, Bias[])} method + * for all the UI delegates managed by this <code>MultiTextUI</code>, + * returning the position for the UI delegate from the primary look and + * feel. + * + * @param tc the text component. + * + * @return The position returned by the UI delegate from the primary + * look and feel. + */ + public int viewToModel(JTextComponent tc, Point loc, Bias[] outBias) + { + int result = 0; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + TextUI ui = (TextUI) iterator.next(); + result = ui.viewToModel(tc, loc, outBias); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + TextUI ui = (TextUI) iterator.next(); + /* int ignored = */ ui.viewToModel(tc, loc, outBias); + } + return result; + } + + /** + * Calls the {@link TextUI#getNextVisualPositionFrom(JTextComponent, int, + * Position.Bias, int, Position.Bias[])} method for all + * the UI delegates managed by this <code>MultiTextUI</code>, + * returning the position for the UI delegate from the primary look and + * feel. + * + * @param tc the text component. + * + * @return The position returned by the UI delegate from the primary + * look and feel. + */ + public int getNextVisualPositionFrom(JTextComponent tc, int pos, Bias bias, + int direction, Bias[] outBias) throws BadLocationException + { + int result = 0; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + TextUI ui = (TextUI) iterator.next(); + result = ui.getNextVisualPositionFrom(tc, pos, bias, direction, + outBias); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + TextUI ui = (TextUI) iterator.next(); + /* int ignored = */ ui.getNextVisualPositionFrom(tc, pos, bias, + direction, outBias); + } + return result; + } + + /** + * Calls the {@link TextUI#damageRange(JTextComponent, int, int)} method for + * all the UI delegates managed by this <code>MultiTextUI</code>. + * + * @param tc the component. + * @param start the start position. + * @param end the end position. + */ + public void damageRange(JTextComponent tc, int start, int end) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + TextUI ui = (TextUI) iterator.next(); + ui.damageRange(tc, start, end); + } + } + + /** + * Calls the {@link TextUI#damageRange(JTextComponent, int, int, + * Position.Bias, Position.Bias)} method for all the UI delegates managed by + * this <code>MultiTextUI</code>. + * + * @param tc the component. + * @param start the start position. + * @param end the end position. + * @param startBias the start bias. + * @param endBias the end bias. + */ + public void damageRange(JTextComponent tc, int start, int end, + Bias startBias, Bias endBias) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + TextUI ui = (TextUI) iterator.next(); + ui.damageRange(tc, start, end, startBias, endBias); + } + } + + /** + * Calls the {@link TextUI#getEditorKit(JTextComponent)} method for all + * the UI delegates managed by this <code>MultiTextUI</code>, + * returning the editor kit for the UI delegate from the primary look and + * feel. + * + * @param tc the text component. + * + * @return The editor kit returned by the UI delegate from the primary + * look and feel. + */ + public EditorKit getEditorKit(JTextComponent tc) + { + EditorKit result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + TextUI ui = (TextUI) iterator.next(); + result = ui.getEditorKit(tc); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + TextUI ui = (TextUI) iterator.next(); + /* EditorKit ignored = */ ui.getEditorKit(tc); + } + return result; + } + + /** + * Calls the {@link TextUI#getRootView(JTextComponent)} method for all + * the UI delegates managed by this <code>MultiTextUI</code>, + * returning the view for the UI delegate from the primary look and + * feel. + * + * @param tc the text component. + * + * @return The view returned by the UI delegate from the primary + * look and feel. + */ + public View getRootView(JTextComponent tc) + { + View result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + TextUI ui = (TextUI) iterator.next(); + result = ui.getRootView(tc); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + TextUI ui = (TextUI) iterator.next(); + /* View ignored = */ ui.getRootView(tc); + } + return result; + } + +} diff --git a/libjava/classpath/javax/swing/plaf/multi/MultiToolBarUI.java b/libjava/classpath/javax/swing/plaf/multi/MultiToolBarUI.java new file mode 100644 index 0000000..afe63bf --- /dev/null +++ b/libjava/classpath/javax/swing/plaf/multi/MultiToolBarUI.java @@ -0,0 +1,352 @@ +/* MultiToolBarUI.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.swing.plaf.multi; + +import java.awt.Dimension; +import java.awt.Graphics; +import java.util.Iterator; +import java.util.Vector; + +import javax.accessibility.Accessible; +import javax.swing.JComponent; +import javax.swing.LookAndFeel; +import javax.swing.UIManager; +import javax.swing.plaf.ComponentUI; +import javax.swing.plaf.ToolBarUI; + +/** + * A UI delegate that that coordinates multiple {@link ToolBarUI} + * instances, one from the primary look and feel, and one or more from the + * auxiliary look and feel(s). + * + * @see UIManager#addAuxiliaryLookAndFeel(LookAndFeel) + */ +public class MultiToolBarUI extends ToolBarUI +{ + + /** A list of references to the actual component UIs. */ + protected Vector uis; + + /** + * Creates a new <code>MultiToolBarUI</code> instance. + * + * @see #createUI(JComponent) + */ + public MultiToolBarUI() + { + uis = new Vector(); + } + + /** + * Creates a delegate object for the specified component. If any auxiliary + * look and feels support this component, a <code>MultiToolBarUI</code> is + * returned, otherwise the UI from the default look and feel is returned. + * + * @param target the component. + * + * @see MultiLookAndFeel#createUIs(ComponentUI, Vector, JComponent) + */ + public static ComponentUI createUI(JComponent target) + { + MultiToolBarUI mui = new MultiToolBarUI(); + return MultiLookAndFeel.createUIs(mui, mui.uis, target); + } + + /** + * Calls the {@link ComponentUI#installUI(JComponent)} method for all + * the UI delegates managed by this <code>MultiToolBarUI</code>. + * + * @param c the component. + */ + public void installUI(JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.installUI(c); + } + } + + /** + * Calls the {@link ComponentUI#uninstallUI(JComponent)} method for all + * the UI delegates managed by this <code>MultiToolBarUI</code>. + * + * @param c the component. + */ + public void uninstallUI(JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.uninstallUI(c); + } + } + + /** + * Returns an array containing the UI delegates managed by this + * <code>MultiToolBarUI</code>. The first item in the array is always + * the UI delegate from the installed default look and feel. + * + * @return An array of UI delegates. + */ + public ComponentUI[] getUIs() + { + return MultiLookAndFeel.uisToArray(uis); + } + + /** + * Calls the {@link ComponentUI#contains(JComponent, int, int)} method for all + * the UI delegates managed by this <code>MultiToolBarUI</code>, + * returning the result for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * @param x the x-coordinate. + * @param y the y-coordinate. + * + * @return <code>true</code> if the specified (x, y) coordinate falls within + * the bounds of the component as rendered by the UI delegate in the + * primary look and feel, and <code>false</code> otherwise. + */ + public boolean contains(JComponent c, int x, int y) + { + boolean result = false; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.contains(c, x, y); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* boolean ignored = */ ui.contains(c, x, y); + } + return result; + } + + /** + * Calls the {@link ComponentUI#update(Graphics, JComponent)} method for all + * the UI delegates managed by this <code>MultiToolBarUI</code>. + * + * @param g the graphics device. + * @param c the component. + */ + public void update(Graphics g, JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.update(g, c); + } + } + + /** + * Calls the <code>paint(Graphics, JComponent)</code> method for all the UI + * delegates managed by this <code>MultiToolBarUI</code>. + * + * @param g the graphics device. + * @param c the component. + */ + public void paint(Graphics g, JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.paint(g, c); + } + } + + /** + * Calls the {@link ComponentUI#getPreferredSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiToolBarUI</code>, + * returning the preferred size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The preferred size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getPreferredSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getPreferredSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getPreferredSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getMinimumSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiToolBarUI</code>, + * returning the minimum size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The minimum size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getMinimumSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getMinimumSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getMinimumSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getMaximumSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiToolBarUI</code>, + * returning the maximum size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The maximum size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getMaximumSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getMaximumSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getMaximumSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getAccessibleChildrenCount(JComponent)} method + * for all the UI delegates managed by this <code>MultiToolBarUI</code>, + * returning the count for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The count returned by the UI delegate from the primary + * look and feel. + */ + public int getAccessibleChildrenCount(JComponent c) + { + int result = 0; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getAccessibleChildrenCount(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* int ignored = */ ui.getAccessibleChildrenCount(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getAccessibleChild(JComponent, int)} method + * for all the UI delegates managed by this <code>MultiToolBarUI</code>, + * returning the child for the UI delegate from the primary look and + * feel. + * + * @param c the component + * @param i the child index. + * + * @return The child returned by the UI delegate from the primary + * look and feel. + */ + public Accessible getAccessibleChild(JComponent c, int i) + { + Accessible result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getAccessibleChild(c, i); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Accessible ignored = */ ui.getAccessibleChild(c, i); + } + return result; + } + +} diff --git a/libjava/classpath/javax/swing/plaf/multi/MultiToolTipUI.java b/libjava/classpath/javax/swing/plaf/multi/MultiToolTipUI.java new file mode 100644 index 0000000..fcd622d --- /dev/null +++ b/libjava/classpath/javax/swing/plaf/multi/MultiToolTipUI.java @@ -0,0 +1,352 @@ +/* MultiToolTipUI.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.swing.plaf.multi; + +import java.awt.Dimension; +import java.awt.Graphics; +import java.util.Iterator; +import java.util.Vector; + +import javax.accessibility.Accessible; +import javax.swing.JComponent; +import javax.swing.LookAndFeel; +import javax.swing.UIManager; +import javax.swing.plaf.ComponentUI; +import javax.swing.plaf.ToolTipUI; + +/** + * A UI delegate that that coordinates multiple {@link ToolTipUI} + * instances, one from the primary look and feel, and one or more from the + * auxiliary look and feel(s). + * + * @see UIManager#addAuxiliaryLookAndFeel(LookAndFeel) + */ +public class MultiToolTipUI extends ToolTipUI +{ + + /** A list of references to the actual component UIs. */ + protected Vector uis; + + /** + * Creates a new <code>MultiToolTipUI</code> instance. + * + * @see #createUI(JComponent) + */ + public MultiToolTipUI() + { + uis = new Vector(); + } + + /** + * Creates a delegate object for the specified component. If any auxiliary + * look and feels support this component, a <code>MultiToolTipUI</code> is + * returned, otherwise the UI from the default look and feel is returned. + * + * @param target the component. + * + * @see MultiLookAndFeel#createUIs(ComponentUI, Vector, JComponent) + */ + public static ComponentUI createUI(JComponent target) + { + MultiToolTipUI mui = new MultiToolTipUI(); + return MultiLookAndFeel.createUIs(mui, mui.uis, target); + } + + /** + * Calls the {@link ComponentUI#installUI(JComponent)} method for all + * the UI delegates managed by this <code>MultiToolTipUI</code>. + * + * @param c the component. + */ + public void installUI(JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.installUI(c); + } + } + + /** + * Calls the {@link ComponentUI#uninstallUI(JComponent)} method for all + * the UI delegates managed by this <code>MultiToolTipUI</code>. + * + * @param c the component. + */ + public void uninstallUI(JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.uninstallUI(c); + } + } + + /** + * Returns an array containing the UI delegates managed by this + * <code>MultiToolTipUI</code>. The first item in the array is always + * the UI delegate from the installed default look and feel. + * + * @return An array of UI delegates. + */ + public ComponentUI[] getUIs() + { + return MultiLookAndFeel.uisToArray(uis); + } + + /** + * Calls the {@link ComponentUI#contains(JComponent, int, int)} method for all + * the UI delegates managed by this <code>MultiToolTipUI</code>, + * returning the result for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * @param x the x-coordinate. + * @param y the y-coordinate. + * + * @return <code>true</code> if the specified (x, y) coordinate falls within + * the bounds of the component as rendered by the UI delegate in the + * primary look and feel, and <code>false</code> otherwise. + */ + public boolean contains(JComponent c, int x, int y) + { + boolean result = false; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.contains(c, x, y); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* boolean ignored = */ ui.contains(c, x, y); + } + return result; + } + + /** + * Calls the {@link ComponentUI#update(Graphics, JComponent)} method for all + * the UI delegates managed by this <code>MultiToolTipUI</code>. + * + * @param g the graphics device. + * @param c the component. + */ + public void update(Graphics g, JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.update(g, c); + } + } + + /** + * Calls the <code>paint(Graphics, JComponent)</code> method for all the UI + * delegates managed by this <code>MultiToolTipUI</code>. + * + * @param g the graphics device. + * @param c the component. + */ + public void paint(Graphics g, JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.paint(g, c); + } + } + + /** + * Calls the {@link ComponentUI#getPreferredSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiToolTipUI</code>, + * returning the preferred size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The preferred size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getPreferredSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getPreferredSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getPreferredSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getMinimumSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiToolTipUI</code>, + * returning the minimum size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The minimum size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getMinimumSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getMinimumSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getMinimumSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getMaximumSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiToolTipUI</code>, + * returning the maximum size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The maximum size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getMaximumSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getMaximumSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getMaximumSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getAccessibleChildrenCount(JComponent)} method + * for all the UI delegates managed by this <code>MultiToolTipUI</code>, + * returning the count for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The count returned by the UI delegate from the primary + * look and feel. + */ + public int getAccessibleChildrenCount(JComponent c) + { + int result = 0; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getAccessibleChildrenCount(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* int ignored = */ ui.getAccessibleChildrenCount(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getAccessibleChild(JComponent, int)} method + * for all the UI delegates managed by this <code>MultiToolTipUI</code>, + * returning the child for the UI delegate from the primary look and + * feel. + * + * @param c the component + * @param i the child index. + * + * @return The child returned by the UI delegate from the primary + * look and feel. + */ + public Accessible getAccessibleChild(JComponent c, int i) + { + Accessible result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getAccessibleChild(c, i); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Accessible ignored = */ ui.getAccessibleChild(c, i); + } + return result; + } + +} diff --git a/libjava/classpath/javax/swing/plaf/multi/MultiTreeUI.java b/libjava/classpath/javax/swing/plaf/multi/MultiTreeUI.java new file mode 100644 index 0000000..de1dc6c --- /dev/null +++ b/libjava/classpath/javax/swing/plaf/multi/MultiTreeUI.java @@ -0,0 +1,628 @@ +/* MultiTreeUI.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.swing.plaf.multi; + +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.Rectangle; +import java.util.Iterator; +import java.util.Vector; + +import javax.accessibility.Accessible; +import javax.swing.JComponent; +import javax.swing.JTree; +import javax.swing.LookAndFeel; +import javax.swing.UIManager; +import javax.swing.plaf.ComponentUI; +import javax.swing.plaf.TreeUI; +import javax.swing.tree.TreePath; + +/** + * A UI delegate that that coordinates multiple {@link TreeUI} + * instances, one from the primary look and feel, and one or more from the + * auxiliary look and feel(s). + * + * @see UIManager#addAuxiliaryLookAndFeel(LookAndFeel) + */ +public class MultiTreeUI extends TreeUI +{ + + /** A list of references to the actual component UIs. */ + protected Vector uis; + + /** + * Creates a new <code>MultiTreeUI</code> instance. + * + * @see #createUI(JComponent) + */ + public MultiTreeUI() + { + uis = new Vector(); + } + + /** + * Creates a delegate object for the specified component. If any auxiliary + * look and feels support this component, a <code>MultiTreeUI</code> is + * returned, otherwise the UI from the default look and feel is returned. + * + * @param target the component. + * + * @see MultiLookAndFeel#createUIs(ComponentUI, Vector, JComponent) + */ + public static ComponentUI createUI(JComponent target) + { + MultiTreeUI mui = new MultiTreeUI(); + return MultiLookAndFeel.createUIs(mui, mui.uis, target); + } + + /** + * Calls the {@link ComponentUI#installUI(JComponent)} method for all + * the UI delegates managed by this <code>MultiTreeUI</code>. + * + * @param c the component. + */ + public void installUI(JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.installUI(c); + } + } + + /** + * Calls the {@link ComponentUI#uninstallUI(JComponent)} method for all + * the UI delegates managed by this <code>MultiTreeUI</code>. + * + * @param c the component. + */ + public void uninstallUI(JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.uninstallUI(c); + } + } + + /** + * Returns an array containing the UI delegates managed by this + * <code>MultiTreeUI</code>. The first item in the array is always + * the UI delegate from the installed default look and feel. + * + * @return An array of UI delegates. + */ + public ComponentUI[] getUIs() + { + return MultiLookAndFeel.uisToArray(uis); + } + + /** + * Calls the {@link ComponentUI#contains(JComponent, int, int)} method for all + * the UI delegates managed by this <code>MultiTreeUI</code>, + * returning the result for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * @param x the x-coordinate. + * @param y the y-coordinate. + * + * @return <code>true</code> if the specified (x, y) coordinate falls within + * the bounds of the component as rendered by the UI delegate in the + * primary look and feel, and <code>false</code> otherwise. + */ + public boolean contains(JComponent c, int x, int y) + { + boolean result = false; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.contains(c, x, y); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* boolean ignored = */ ui.contains(c, x, y); + } + return result; + } + + /** + * Calls the {@link ComponentUI#update(Graphics, JComponent)} method for all + * the UI delegates managed by this <code>MultiTreeUI</code>. + * + * @param g the graphics device. + * @param c the component. + */ + public void update(Graphics g, JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.update(g, c); + } + } + + /** + * Calls the <code>paint(Graphics, JComponent)</code> method for all the UI + * delegates managed by this <code>MultiTreeUI</code>. + * + * @param g the graphics device. + * @param c the component. + */ + public void paint(Graphics g, JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.paint(g, c); + } + } + + /** + * Calls the {@link ComponentUI#getPreferredSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiTreeUI</code>, + * returning the preferred size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The preferred size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getPreferredSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getPreferredSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getPreferredSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getMinimumSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiTreeUI</code>, + * returning the minimum size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The minimum size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getMinimumSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getMinimumSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getMinimumSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getMaximumSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiTreeUI</code>, + * returning the maximum size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The maximum size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getMaximumSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getMaximumSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getMaximumSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getAccessibleChildrenCount(JComponent)} method + * for all the UI delegates managed by this <code>MultiTreeUI</code>, + * returning the count for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The count returned by the UI delegate from the primary + * look and feel. + */ + public int getAccessibleChildrenCount(JComponent c) + { + int result = 0; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getAccessibleChildrenCount(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* int ignored = */ ui.getAccessibleChildrenCount(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getAccessibleChild(JComponent, int)} method + * for all the UI delegates managed by this <code>MultiTreeUI</code>, + * returning the child for the UI delegate from the primary look and + * feel. + * + * @param c the component + * @param i the child index. + * + * @return The child returned by the UI delegate from the primary + * look and feel. + */ + public Accessible getAccessibleChild(JComponent c, int i) + { + Accessible result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getAccessibleChild(c, i); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Accessible ignored = */ ui.getAccessibleChild(c, i); + } + return result; + } + + /** + * Calls the {@link TreeUI#getPathBounds(JTree, TreePath)} method + * for all the UI delegates managed by this <code>MultiTreeUI</code>, + * returning the bounds for the UI delegate from the primary look and + * feel. + * + * @param tree the tree component. + * + * @return The bounds returned by the UI delegate from the primary + * look and feel. + */ + public Rectangle getPathBounds(JTree tree, TreePath path) + { + Rectangle result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + TreeUI ui = (TreeUI) iterator.next(); + result = ui.getPathBounds(tree, path); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + TreeUI ui = (TreeUI) iterator.next(); + /* Rectangle ignored = */ ui.getPathBounds(tree, path); + } + return result; + } + + /** + * Calls the {@link TreeUI#getPathForRow(JTree, int)} method + * for all the UI delegates managed by this <code>MultiTreeUI</code>, + * returning the path for the UI delegate from the primary look and + * feel. + * + * @param tree the tree component. + * + * @return The path returned by the UI delegate from the primary + * look and feel. + */ + public TreePath getPathForRow(JTree tree, int row) + { + TreePath result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + TreeUI ui = (TreeUI) iterator.next(); + result = ui.getPathForRow(tree, row); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + TreeUI ui = (TreeUI) iterator.next(); + /* TreePath ignored = */ ui.getPathForRow(tree, row); + } + return result; + } + + /** + * Calls the {@link TreeUI#getRowForPath(JTree, TreePath)} method + * for all the UI delegates managed by this <code>MultiTreeUI</code>, + * returning the row index for the UI delegate from the primary look and + * feel. + * + * @param tree the tree component. + * + * @return The row index returned by the UI delegate from the primary + * look and feel. + */ + public int getRowForPath(JTree tree, TreePath path) + { + int result = 0; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + TreeUI ui = (TreeUI) iterator.next(); + result = ui.getRowForPath(tree, path); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + TreeUI ui = (TreeUI) iterator.next(); + /* int ignored = */ ui.getRowForPath(tree, path); + } + return result; + } + + /** + * Calls the {@link TreeUI#getRowCount(JTree)} method + * for all the UI delegates managed by this <code>MultiTreeUI</code>, + * returning the count for the UI delegate from the primary look and + * feel. + * + * @param tree the tree component. + * + * @return The count returned by the UI delegate from the primary + * look and feel. + */ + public int getRowCount(JTree tree) + { + int result = 0; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + TreeUI ui = (TreeUI) iterator.next(); + result = ui.getRowCount(tree); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + TreeUI ui = (TreeUI) iterator.next(); + /* int ignored = */ ui.getRowCount(tree); + } + return result; + } + + /** + * Calls the {@link TreeUI#getClosestPathForLocation(JTree, int, int)} method + * for all the UI delegates managed by this <code>MultiTreeUI</code>, + * returning the path for the UI delegate from the primary look and + * feel. + * + * @param tree the tree component. + * + * @return The path returned by the UI delegate from the primary + * look and feel. + */ + public TreePath getClosestPathForLocation(JTree tree, int x, int y) + { + TreePath result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + TreeUI ui = (TreeUI) iterator.next(); + result = ui.getClosestPathForLocation(tree, x, y); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + TreeUI ui = (TreeUI) iterator.next(); + /* TreePath ignored = */ ui.getClosestPathForLocation(tree, x, y); + } + return result; + } + + /** + * Calls the {@link TreeUI#isEditing(JTree)} method for all + * the UI delegates managed by this <code>MultiTreeUI</code>, + * returning the result for the UI delegate from the primary look and + * feel. + * + * @param tree the tree component. + * + * @return The result returned by the UI delegate from the primary + * look and feel. + */ + public boolean isEditing(JTree tree) + { + boolean result = false; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + TreeUI ui = (TreeUI) iterator.next(); + result = ui.isEditing(tree); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + TreeUI ui = (TreeUI) iterator.next(); + /* boolean ignored = */ ui.isEditing(tree); + } + return result; + } + + /** + * Calls the {@link TreeUI#stopEditing(JTree)} method for all + * the UI delegates managed by this <code>MultiTreeUI</code>, + * returning the result for the UI delegate from the primary look and + * feel. + * + * @param tree the tree component. + * + * @return The result returned by the UI delegate from the primary + * look and feel. + */ + public boolean stopEditing(JTree tree) + { + boolean result = false; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + TreeUI ui = (TreeUI) iterator.next(); + result = ui.stopEditing(tree); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + TreeUI ui = (TreeUI) iterator.next(); + /* boolean ignored = */ ui.stopEditing(tree); + } + return result; + } + + /** + * Calls the {@link TreeUI#cancelEditing(JTree)} method for + * all the UI delegates managed by this <code>MultiTreeUI</code>. + * + * @param tree the tree component. + */ + public void cancelEditing(JTree tree) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + TreeUI ui = (TreeUI) iterator.next(); + ui.cancelEditing(tree); + } + } + + /** + * Calls the {@link TreeUI#startEditingAtPath(JTree, TreePath)} method for + * all the UI delegates managed by this <code>MultiTreeUI</code>. + * + * @param tree the tree component. + * @param path the path. + */ + public void startEditingAtPath(JTree tree, TreePath path) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + TreeUI ui = (TreeUI) iterator.next(); + ui.startEditingAtPath(tree, path); + } + } + + /** + * Calls the {@link TreeUI#getEditingPath(JTree)} method for all + * the UI delegates managed by this <code>MultiTreeUI</code>, + * returning the path for the UI delegate from the primary look and + * feel. + * + * @param tree the tree component. + * + * @return The path returned by the UI delegate from the primary + * look and feel. + */ + public TreePath getEditingPath(JTree tree) + { + TreePath result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + TreeUI ui = (TreeUI) iterator.next(); + result = ui.getEditingPath(tree); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + TreeUI ui = (TreeUI) iterator.next(); + /* TreePath ignored = */ ui.getEditingPath(tree); + } + return result; + } + +} diff --git a/libjava/classpath/javax/swing/plaf/multi/MultiViewportUI.java b/libjava/classpath/javax/swing/plaf/multi/MultiViewportUI.java new file mode 100644 index 0000000..33bbc3b --- /dev/null +++ b/libjava/classpath/javax/swing/plaf/multi/MultiViewportUI.java @@ -0,0 +1,352 @@ +/* MultiViewPortUI.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.swing.plaf.multi; + +import java.awt.Dimension; +import java.awt.Graphics; +import java.util.Iterator; +import java.util.Vector; + +import javax.accessibility.Accessible; +import javax.swing.JComponent; +import javax.swing.LookAndFeel; +import javax.swing.UIManager; +import javax.swing.plaf.ComponentUI; +import javax.swing.plaf.ViewportUI; + +/** + * A UI delegate that that coordinates multiple {@link ViewportUI} + * instances, one from the primary look and feel, and one or more from the + * auxiliary look and feel(s). + * + * @see UIManager#addAuxiliaryLookAndFeel(LookAndFeel) + */ +public class MultiViewportUI extends ViewportUI +{ + + /** A list of references to the actual component UIs. */ + protected Vector uis; + + /** + * Creates a new <code>MultiViewPortUI</code> instance. + * + * @see #createUI(JComponent) + */ + public MultiViewportUI() + { + uis = new Vector(); + } + + /** + * Creates a delegate object for the specified component. If any auxiliary + * look and feels support this component, a <code>MultiViewportUI</code> is + * returned, otherwise the UI from the default look and feel is returned. + * + * @param target the component. + * + * @see MultiLookAndFeel#createUIs(ComponentUI, Vector, JComponent) + */ + public static ComponentUI createUI(JComponent target) + { + MultiViewportUI mui = new MultiViewportUI(); + return MultiLookAndFeel.createUIs(mui, mui.uis, target); + } + + /** + * Calls the {@link ComponentUI#installUI(JComponent)} method for all + * the UI delegates managed by this <code>MultiViewportUI</code>. + * + * @param c the component. + */ + public void installUI(JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.installUI(c); + } + } + + /** + * Calls the {@link ComponentUI#uninstallUI(JComponent)} method for all + * the UI delegates managed by this <code>MultiViewportUI</code>. + * + * @param c the component. + */ + public void uninstallUI(JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.uninstallUI(c); + } + } + + /** + * Returns an array containing the UI delegates managed by this + * <code>MultiViewportUI</code>. The first item in the array is always + * the UI delegate from the installed default look and feel. + * + * @return An array of UI delegates. + */ + public ComponentUI[] getUIs() + { + return MultiLookAndFeel.uisToArray(uis); + } + + /** + * Calls the {@link ComponentUI#contains(JComponent, int, int)} method for all + * the UI delegates managed by this <code>MultiViewportUI</code>, + * returning the result for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * @param x the x-coordinate. + * @param y the y-coordinate. + * + * @return <code>true</code> if the specified (x, y) coordinate falls within + * the bounds of the component as rendered by the UI delegate in the + * primary look and feel, and <code>false</code> otherwise. + */ + public boolean contains(JComponent c, int x, int y) + { + boolean result = false; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.contains(c, x, y); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* boolean ignored = */ ui.contains(c, x, y); + } + return result; + } + + /** + * Calls the {@link ComponentUI#update(Graphics, JComponent)} method for all + * the UI delegates managed by this <code>MultiViewportUI</code>. + * + * @param g the graphics device. + * @param c the component. + */ + public void update(Graphics g, JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.update(g, c); + } + } + + /** + * Calls the <code>paint(Graphics, JComponent)</code> method for all the UI + * delegates managed by this <code>MultiViewportUI</code>. + * + * @param g the graphics device. + * @param c the component. + */ + public void paint(Graphics g, JComponent c) + { + Iterator iterator = uis.iterator(); + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + ui.paint(g, c); + } + } + + /** + * Calls the {@link ComponentUI#getPreferredSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiViewportUI</code>, + * returning the preferred size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The preferred size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getPreferredSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getPreferredSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getPreferredSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getMinimumSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiViewportUI</code>, + * returning the minimum size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The minimum size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getMinimumSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getMinimumSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getMinimumSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getMaximumSize(JComponent)} method for all + * the UI delegates managed by this <code>MultiViewportUI</code>, + * returning the maximum size for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The maximum size returned by the UI delegate from the primary + * look and feel. + */ + public Dimension getMaximumSize(JComponent c) + { + Dimension result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getMaximumSize(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Dimension ignored = */ ui.getMaximumSize(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getAccessibleChildrenCount(JComponent)} method + * for all the UI delegates managed by this <code>MultiViewportUI</code>, + * returning the count for the UI delegate from the primary look and + * feel. + * + * @param c the component. + * + * @return The count returned by the UI delegate from the primary + * look and feel. + */ + public int getAccessibleChildrenCount(JComponent c) + { + int result = 0; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getAccessibleChildrenCount(c); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* int ignored = */ ui.getAccessibleChildrenCount(c); + } + return result; + } + + /** + * Calls the {@link ComponentUI#getAccessibleChild(JComponent, int)} method + * for all the UI delegates managed by this <code>MultiViewportUI</code>, + * returning the child for the UI delegate from the primary look and + * feel. + * + * @param c the component + * @param i the child index. + * + * @return The child returned by the UI delegate from the primary + * look and feel. + */ + public Accessible getAccessibleChild(JComponent c, int i) + { + Accessible result = null; + Iterator iterator = uis.iterator(); + // first UI delegate provides the return value + if (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + result = ui.getAccessibleChild(c, i); + } + // return values from auxiliary UI delegates are ignored + while (iterator.hasNext()) + { + ComponentUI ui = (ComponentUI) iterator.next(); + /* Accessible ignored = */ ui.getAccessibleChild(c, i); + } + return result; + } + +} diff --git a/libjava/classpath/javax/swing/plaf/multi/package.html b/libjava/classpath/javax/swing/plaf/multi/package.html new file mode 100644 index 0000000..568a7d0 --- /dev/null +++ b/libjava/classpath/javax/swing/plaf/multi/package.html @@ -0,0 +1,46 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> +<!-- package.html - describes classes in javax.swing.plaf.metal package. + Copyright (C) 2002, 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. --> + +<html> +<head><title>GNU Classpath - javax.swing.plaf.multi</title></head> + +<body> +<p>Provides a look and feel that can combine a primary look and feel with one or more auxiliary look and feels.</p> + +</body> +</html> diff --git a/libjava/classpath/javax/swing/text/AbstractWriter.java b/libjava/classpath/javax/swing/text/AbstractWriter.java new file mode 100644 index 0000000..d5fc395 --- /dev/null +++ b/libjava/classpath/javax/swing/text/AbstractWriter.java @@ -0,0 +1,480 @@ +/* AbstractWriter.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.swing.text; + +import java.io.IOException; +import java.io.Writer; +import java.util.Arrays; +import java.util.Enumeration; + +/** + * This is an abstract base class for writing Document instances to a + * Writer. A concrete subclass must implement a method to iterate + * over the Elements of the Document and correctly format them. + */ +public abstract class AbstractWriter +{ + /** + * The default line separator character. + * @specnote although this is a constant, it is not static in the JDK + */ + protected static final char NEWLINE = '\n'; + + // Where we write. + private Writer writer; + // How we iterate over the document. + private ElementIterator iter; + // The document over which we iterate. + private Document document; + // Maximum number of characters per line. + private int maxLineLength = 100; + // Number of characters we have currently written. + private int lineLength; + // True if we can apply line wrapping. + private boolean canWrapLines; // FIXME default? + // The number of spaces per indentation level. + private int indentSpace = 2; + // The current indentation level. + private int indentLevel; + // True if we have indented this line. + private boolean indented; + // Starting offset in document. + private int startOffset; + // Ending offset in document. + private int endOffset; + // The line separator string. + private String lineSeparator = "" + NEWLINE; + // The characters making up the line separator. + private char[] lineSeparatorChars = lineSeparator.toCharArray(); + + /** + * Create a new AbstractWriter with the indicated Writer and + * Document. The full range of the Document will be used. The + * internal ElementIterator will be initialized with the Document's + * root node. + */ + protected AbstractWriter(Writer writer, Document doc) + { + this.writer = writer; + this.iter = new ElementIterator(doc); + this.document = doc; + this.startOffset = 0; + this.endOffset = doc.getLength(); + } + + /** + * Create a new AbstractWriter with the indicated Writer and + * Document. The full range of the Document will be used. The + * internal ElementIterator will be initialized with the Document's + * root node. + */ + protected AbstractWriter(Writer writer, Document doc, int pos, int len) + { + this.writer = writer; + this.iter = new ElementIterator(doc); + this.document = doc; + this.startOffset = pos; + this.endOffset = pos + len; + } + + /** + * Create a new AbstractWriter with the indicated Writer and + * Element. The full range of the Element will be used. + */ + protected AbstractWriter(Writer writer, Element elt) + { + this.writer = writer; + this.iter = new ElementIterator(elt); + this.document = elt.getDocument(); + this.startOffset = elt.getStartOffset(); + this.endOffset = elt.getEndOffset(); + } + + /** + * Create a new AbstractWriter with the indicated Writer and + * Element. The full range of the Element will be used. The range + * will be limited to the indicated range of the Document. + */ + protected AbstractWriter(Writer writer, Element elt, int pos, int len) + { + this.writer = writer; + this.iter = new ElementIterator(elt); + this.document = elt.getDocument(); + this.startOffset = pos; + this.endOffset = pos + len; + } + + /** + * Return the ElementIterator for this writer. + */ + protected ElementIterator getElementIterator() + { + return iter; + } + + /** + * Return the Writer to which we are writing. + * @since 1.3 + */ + protected Writer getWriter() + { + return writer; + } + + /** + * Return this writer's Document. + */ + protected Document getDocument() + { + return document; + } + + /** + * This method must be overridden by a concrete subclass. It is + * responsible for iterating over the Elements of the Document and + * writing them out. + */ + protected abstract void write() throws IOException, BadLocationException; + + /** + * Return the text of the Document that is associated with the given + * Element. If the Element is not a leaf Element, this will throw + * BadLocationException. + * + * @throws BadLocationException if the element is not a leaf + */ + protected String getText(Element elt) throws BadLocationException + { + if (! elt.isLeaf()) + throw new BadLocationException("Element is not a leaf", + elt.getStartOffset()); + return document.getText(elt.getStartOffset(), elt.getEndOffset()); + } + + /** + * This method calls Writer.write on the indicated data, and updates + * the current line length. This method does not look for newlines + * in the written data; the caller is responsible for that. + * + * @since 1.3 + */ + protected void output(char[] data, int start, int len) throws IOException + { + writer.write(data, start, len); + lineLength += len; + } + + /** + * Write a line separator using the output method, and then reset + * the current line length. + * + * @since 1.3 + */ + protected void writeLineSeparator() throws IOException + { + output(lineSeparatorChars, 0, lineSeparatorChars.length); + lineLength = 0; + indented = false; + } + + /** + * Write a single character. + */ + protected void write(char ch) throws IOException + { + write(new char[] { ch }, 0, 1); + } + + /** + * Write a String. + */ + protected void write(String s) throws IOException + { + char[] v = s.toCharArray(); + write(v, 0, v.length); + } + + /** + * Write a character array to the output Writer, properly handling + * newlines and, if needed, wrapping lines as they are output. + * @since 1.3 + */ + protected void write(char[] data, int start, int len) throws IOException + { + if (getCanWrapLines()) + { + // FIXME: should we be handling newlines specially here? + for (int i = 0; i < len; ) + { + int start_i = i; + // Find next space. + while (i < len && data[start + i] != ' ') + ++i; + if (i < len && lineLength + i - start_i >= maxLineLength) + writeLineSeparator(); + else if (i < len) + { + // Write the trailing space. + ++i; + } + // Write out the text. + output(data, start + start_i, start + i - start_i); + } + } + else + { + int saved_i = start; + for (int i = start; i < start + len; ++i) + { + if (data[i] == NEWLINE) + { + output(data, saved_i, i - saved_i); + writeLineSeparator(); + } + } + if (saved_i < start + len - 1) + output(data, saved_i, start + len - saved_i); + } + } + + /** + * Indent this line by emitting spaces, according to the current + * indent level and the current number of spaces per indent. After + * this method is called, the current line is no longer considered + * to be empty, even if no spaces are actually written. + */ + protected void indent() throws IOException + { + int spaces = indentLevel * indentSpace; + if (spaces > 0) + { + char[] v = new char[spaces]; + Arrays.fill(v, ' '); + write(v, 0, v.length); + } + indented = true; + } + + /** + * Return the index of the Document at which output starts. + * @since 1.3 + */ + public int getStartOffset() + { + return startOffset; + } + + /** + * Return the index of the Document at which output ends. + * @since 1.3 + */ + public int getEndOffset() + { + return endOffset; + } + + /** + * Return true if the Element's range overlaps our desired output + * range; false otherwise. + */ + protected boolean inRange(Element elt) + { + int eltStart = elt.getStartOffset(); + int eltEnd = elt.getEndOffset(); + return ((eltStart >= startOffset && eltStart < endOffset) + || (eltEnd >= startOffset && eltEnd < endOffset)); + } + + /** + * Output the text of the indicated Element, properly clipping it to + * the range of the Document specified when the AbstractWriter was + * created. + */ + protected void text(Element elt) throws BadLocationException, IOException + { + int eltStart = elt.getStartOffset(); + int eltEnd = elt.getEndOffset(); + + eltStart = Math.max(eltStart, startOffset); + eltEnd = Math.min(eltEnd, endOffset); + write(document.getText(eltStart, eltEnd)); + } + + /** + * Set the maximum line length. + */ + protected void setLineLength(int maxLineLength) + { + this.maxLineLength = maxLineLength; + } + + /** + * Return the maximum line length. + * @since 1.3 + */ + protected int getLineLength() + { + return maxLineLength; + } + + /** + * Set the current line length. + * @since 1.3 + */ + protected void setCurrentLineLength(int lineLength) + { + this.lineLength = lineLength; + } + + /** + * Return the current line length. + * @since 1.3 + */ + protected int getCurrentLineLength() + { + return lineLength; + } + + /** + * Return true if the line is empty, false otherwise. The line is + * empty if nothing has been written since the last newline, and + * indent has not been invoked. + */ + protected boolean isLineEmpty() + { + return lineLength == 0 && ! indented; + } + + /** + * Set the flag indicating whether lines will wrap. This affects + * the behavior of write(). + * @since 1.3 + */ + protected void setCanWrapLines(boolean canWrapLines) + { + this.canWrapLines = canWrapLines; + } + + /** + * Return true if lines printed via write() will wrap, false + * otherwise. + * @since 1.3 + */ + protected boolean getCanWrapLines() + { + return canWrapLines; + } + + /** + * Set the number of spaces per indent level. + * @since 1.3 + */ + protected void setIndentSpace(int indentSpace) + { + this.indentSpace = indentSpace; + } + + /** + * Return the number of spaces per indent level. + * @since 1.3 + */ + protected int getIndentSpace() + { + return indentSpace; + } + + /** + * Set the current line separator. + * @since 1.3 + */ + public void setLineSeparator(String lineSeparator) + { + this.lineSeparator = lineSeparator; + this.lineSeparatorChars = lineSeparator.toCharArray(); + } + + /** + * Return the current line separator. + * @since 1.3 + */ + public String getLineSeparator() + { + return lineSeparator; + } + + /** + * Increment the indent level. + */ + protected void incrIndent() + { + ++indentLevel; + } + + /** + * Decrement the indent level. + */ + protected void decrIndent() + { + --indentLevel; + } + + /** + * Return the current indent level. + * @since 1.3 + */ + protected int getIndentLevel() + { + return indentLevel; + } + + /** + * Print the given AttributeSet as a sequence of assignment-like + * strings, e.g. "key=value". + */ + protected void writeAttributes(AttributeSet attrs) throws IOException + { + Enumeration e = attrs.getAttributeNames(); + while (e.hasMoreElements()) + { + Object name = e.nextElement(); + Object val = attrs.getAttribute(name); + write(name + "=" + val); + writeLineSeparator(); + } + } +} diff --git a/libjava/classpath/javax/swing/text/BoxView.java b/libjava/classpath/javax/swing/text/BoxView.java new file mode 100644 index 0000000..0f8ba1c --- /dev/null +++ b/libjava/classpath/javax/swing/text/BoxView.java @@ -0,0 +1,714 @@ +/* BoxView.java -- An composite view + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package javax.swing.text; + +import java.awt.Graphics; +import java.awt.Rectangle; +import java.awt.Shape; + +import javax.swing.SizeRequirements; + +/** + * An implementation of {@link CompositeView} that arranges its children in + * a box along one axis. This is comparable to how the <code>BoxLayout</code> + * works, but for <code>View</code> children. + * + * @author Roman Kennke (roman@kennke.org) + */ +public class BoxView + extends CompositeView +{ + + /** + * The axis along which this <code>BoxView</code> is laid out. + */ + int myAxis; + + /** + * Indicates wether the layout in X_AXIS is valid. + */ + boolean xLayoutValid; + + /** + * Indicates whether the layout in Y_AXIS is valid. + */ + boolean yLayoutValid; + + /** + * The spans in X direction of the children. + */ + int[] spansX; + + /** + * The spans in Y direction of the children. + */ + int[] spansY; + + /** + * The offsets of the children in X direction relative to this BoxView's + * inner bounds. + */ + int[] offsetsX; + + /** + * The offsets of the children in Y direction relative to this BoxView's + * inner bounds. + */ + int[] offsetsY; + + /** + * The current width. + */ + int width; + + /** + * The current height. + */ + int height; + + /** + * Creates a new <code>BoxView</code> for the given + * <code>Element</code> and axis. Valid values for the axis are + * {@link View#X_AXIS} and {@link View#Y_AXIS}. + * + * @param element the element that is rendered by this BoxView + * @param axis the axis along which the box is laid out + */ + public BoxView(Element element, int axis) + { + super(element); + myAxis = axis; + xLayoutValid = false; + yLayoutValid = false; + + // Initialize the cache arrays. + spansX = new int[0]; + spansY = new int[0]; + offsetsX = new int[0]; + offsetsY = new int[0]; + + width = 0; + height = 0; + } + + /** + * Returns the axis along which this <code>BoxView</code> is laid out. + * + * @return the axis along which this <code>BoxView</code> is laid out + */ + public int getAxis() + { + return myAxis; + } + + /** + * Sets the axis along which this <code>BoxView</code> is laid out. + * + * Valid values for the axis are {@link View#X_AXIS} and + * {@link View#Y_AXIS}. + * + * @param axis the axis along which this <code>BoxView</code> is laid out + */ + public void setAxis(int axis) + { + myAxis = axis; + } + + /** + * Marks the layout along the specified axis as invalid. This is triggered + * automatically when any of the child view changes its preferences + * via {@link #preferenceChanged(View, boolean, boolean)}. + * + * The layout will be updated the next time when {@link #setSize()} is + * called, typically from within the {@link #paint()} method. + * + * Valid values for the axis are {@link View#X_AXIS} and + * {@link View#Y_AXIS}. + * + * @param axis an <code>int</code> value + */ + public void layoutChanged(int axis) + { + switch (axis) + { + case X_AXIS: + xLayoutValid = false; + break; + case Y_AXIS: + yLayoutValid = false; + break; + default: + throw new IllegalArgumentException("Invalid axis parameter."); + } + } + + /** + * Returns <code>true</code> if the layout along the specified + * <code>axis</code> is valid, <code>false</code> otherwise. + * + * Valid values for the axis are {@link View#X_AXIS} and + * {@link View#Y_AXIS}. + * + * @param axis the axis + * + * @return <code>true</code> if the layout along the specified + * <code>axis</code> is valid, <code>false</code> otherwise + */ + protected boolean isLayoutValid(int axis) + { + boolean valid = false; + switch (axis) + { + case X_AXIS: + valid = xLayoutValid; + break; + case Y_AXIS: + valid = yLayoutValid; + break; + default: + throw new IllegalArgumentException("Invalid axis parameter."); + } + return valid; + } + + /** + * Paints the child <code>View</code> at the specified <code>index</code>. + * This method modifies the actual values in <code>alloc</code> so make + * sure you have a copy of the original values if you need them. + * + * @param g the <code>Graphics</code> context to paint to + * @param alloc the allocated region for the child to paint into + * @param index the index of the child to be painted + * + * @see {@link #childAllocation} + */ + protected void paintChild(Graphics g, Rectangle alloc, int index) + { + View child = getView(index); + childAllocation(index, alloc); + child.paint(g, alloc); + } + + /** + * Replaces child views by some other child views. If there are no views to + * remove (<code>length == 0</code>), the result is a simple insert, if + * there are no children to add (<code>view == null</code>) the result + * is a simple removal. + * + * In addition this invalidates the layout and resizes the internal cache + * for the child allocations. The old children's cached allocations can + * still be accessed (although they are not guaranteed to be valid), and + * the new children will have an initial offset and span of 0. + * + * @param offset the start offset from where to remove children + * @param length the number of children to remove + * @param views the views that replace the removed children + */ + public void replace(int offset, int length, View[] views) + { + // Resize and copy data for cache arrays. + // The spansX cache. + int oldSize = getViewCount(); + + int[] newSpansX = new int[oldSize - length + views.length]; + System.arraycopy(spansX, 0, newSpansX, 0, offset); + System.arraycopy(spansX, offset + length, newSpansX, + offset + views.length, + oldSize - (offset + length)); + spansX = newSpansX; + + // The spansY cache. + int[] newSpansY = new int[oldSize - length + views.length]; + System.arraycopy(spansY, 0, newSpansY, 0, offset); + System.arraycopy(spansY, offset + length, newSpansY, + offset + views.length, + oldSize - (offset + length)); + spansY = newSpansY; + + // The offsetsX cache. + int[] newOffsetsX = new int[oldSize - length + views.length]; + System.arraycopy(offsetsX, 0, newOffsetsX, 0, offset); + System.arraycopy(offsetsX, offset + length, newOffsetsX, + offset + views.length, + oldSize - (offset + length)); + offsetsX = newOffsetsX; + + // The offsetsY cache. + int[] newOffsetsY = new int[oldSize - length + views.length]; + System.arraycopy(offsetsY, 0, newOffsetsY, 0, offset); + System.arraycopy(offsetsY, offset + length, newOffsetsY, + offset + views.length, + oldSize - (offset + length)); + offsetsY = newOffsetsY; + + // Actually perform the replace. + super.replace(offset, length, views); + + // Invalidate layout information. + layoutChanged(X_AXIS); + layoutChanged(Y_AXIS); + } + + /** + * Renders the <code>Element</code> that is associated with this + * <code>View</code>. + * + * @param g the <code>Graphics</code> context to render to + * @param a the allocated region for the <code>Element</code> + */ + public void paint(Graphics g, Shape a) + { + // Adjust size if the size is changed. + Rectangle bounds = a.getBounds(); + + if (bounds.width != getWidth() || bounds.height != getHeight()) + setSize(bounds.width, bounds.height); + + Rectangle inside = getInsideAllocation(a); + + Rectangle copy = new Rectangle(inside); + int count = getViewCount(); + for (int i = 0; i < count; ++i) + { + // TODO: Figure out if the parameter to paintChild is meant to + // be the child allocation or the allocation of this BoxView. + // I assume the second option here. + // We pass this method a copy of the inside rectangle here because + // it modifies the actual values. + copy.setBounds(inside); + paintChild(g, copy, i); + } + } + + /** + * Returns the preferred span of the content managed by this + * <code>View</code> along the specified <code>axis</code>. + * + * @param axis the axis + * + * @return the preferred span of this <code>View</code>. + */ + public float getPreferredSpan(int axis) + { + SizeRequirements sr = new SizeRequirements(); + int pref = baselineRequirements(axis, sr).preferred; + return (float) pref; + } + + public float getMaximumSpan(int axis) + { + if (axis == getAxis()) + return getPreferredSpan(axis); + else + return Integer.MAX_VALUE; + } + + /** + * Calculates the size requirements for this <code>BoxView</code> along + * the specified axis. + * + * @param axis the axis that is examined + * @param sr the <code>SizeRequirements</code> object to hold the result, + * if <code>null</code>, a new one is created + * + * @return the size requirements for this <code>BoxView</code> along + * the specified axis + */ + protected SizeRequirements baselineRequirements(int axis, + SizeRequirements sr) + { + SizeRequirements result; + if (axis == myAxis) + result = calculateMajorAxisRequirements(axis, sr); + else + result = calculateMinorAxisRequirements(axis, sr); + return result; + } + + /** + * Calculates the size requirements of this <code>BoxView</code> along + * its major axis, that is the axis specified in the constructor. + * + * @param axis the axis that is examined + * @param sr the <code>SizeRequirements</code> object to hold the result, + * if <code>null</code>, a new one is created + * + * @return the size requirements for this <code>BoxView</code> along + * the specified axis + */ + protected SizeRequirements calculateMajorAxisRequirements(int axis, + SizeRequirements sr) + { + if (sr == null) + sr = new SizeRequirements(); + else + { + sr.maximum = 0; + sr.minimum = 0; + sr.preferred = 0; + sr.alignment = 0.5F; + } + + int count = getViewCount(); + + // Sum up the sizes of the children along the specified axis. + for (int i = 0; i < count; ++i) + { + View child = getView(i); + sr.minimum += child.getMinimumSpan(axis); + sr.preferred += child.getPreferredSpan(axis); + sr.maximum += child.getMaximumSpan(axis); + } + return sr; + } + + /** + * Calculates the size requirements of this <code>BoxView</code> along + * its minor axis, that is the axis opposite to the axis specified in the + * constructor. + * + * @param axis the axis that is examined + * @param sr the <code>SizeRequirements</code> object to hold the result, + * if <code>null</code>, a new one is created + * + * @return the size requirements for this <code>BoxView</code> along + * the specified axis + */ + protected SizeRequirements calculateMinorAxisRequirements(int axis, + SizeRequirements sr) + { + if (sr == null) + sr = new SizeRequirements(); + else + { + sr.maximum = 0; + sr.minimum = 0; + sr.preferred = 0; + sr.alignment = 0.5F; + } + + int count = getViewCount(); + + int aboveBaseline = 0; + int belowBaseline = 0; + int aboveBaselineMin = 0; + int belowBaselineMin = 0; + int aboveBaselineMax = 0; + int belowBaselineMax = 0; + + for (int i = 0; i < count; ++i) + { + View child = getView(i); + float align = child.getAlignment(axis); + int pref = (int) child.getPreferredSpan(axis); + int min = (int) child.getMinimumSpan(axis); + int max = (int) child.getMaximumSpan(axis); + aboveBaseline += (int) (align * pref); + belowBaseline += (int) ((1.F - align) * pref); + aboveBaselineMin += (int) (align * min); + belowBaselineMin += (int) ((1.F - align) * min); + aboveBaselineMax += (int) (align * max); + belowBaselineMax += (int) ((1.F - align) * max); + } + sr.minimum = aboveBaselineMin + belowBaselineMin; + sr.maximum = aboveBaselineMax + belowBaselineMax; + sr.preferred = aboveBaseline + belowBaseline; + if (aboveBaseline == 0) + sr.alignment = 1.0F; + else + sr.alignment = (float) (sr.preferred / aboveBaseline); + + return sr; + } + + /** + * Returns <code>true</code> if the specified point lies before the + * given <code>Rectangle</code>, <code>false</code> otherwise. + * + * "Before" is typically defined as being to the left or above. + * + * @param x the X coordinate of the point + * @param y the Y coordinate of the point + * @param r the rectangle to test the point against + * + * @return <code>true</code> if the specified point lies before the + * given <code>Rectangle</code>, <code>false</code> otherwise + */ + protected boolean isBefore(int x, int y, Rectangle r) + { + boolean result = false; + + if (myAxis == X_AXIS) + result = x < r.x; + else + result = y < r.y; + + return result; + } + + /** + * Returns <code>true</code> if the specified point lies after the + * given <code>Rectangle</code>, <code>false</code> otherwise. + * + * "After" is typically defined as being to the right or below. + * + * @param x the X coordinate of the point + * @param y the Y coordinate of the point + * @param r the rectangle to test the point against + * + * @return <code>true</code> if the specified point lies after the + * given <code>Rectangle</code>, <code>false</code> otherwise + */ + protected boolean isAfter(int x, int y, Rectangle r) + { + boolean result = false; + + if (myAxis == X_AXIS) + result = x > r.x; + else + result = y > r.y; + + return result; + } + + /** + * Returns the child <code>View</code> at the specified location. + * + * @param x the X coordinate + * @param y the Y coordinate + * @param r the inner allocation of this <code>BoxView</code> on entry, + * the allocation of the found child on exit + * + * @return the child <code>View</code> at the specified location + */ + protected View getViewAtPoint(int x, int y, Rectangle r) + { + View result = null; + + int count = getViewCount(); + Rectangle copy = new Rectangle(r); + + for (int i = 0; i < count; ++i) + { + copy.setBounds(r); + childAllocation(i, r); + if (copy.contains(x, y)) + { + result = getView(i); + break; + } + } + + return result; + } + + /** + * Computes the allocation for a child <code>View</code>. The parameter + * <code>a</code> stores the allocation of this <code>CompositeView</code> + * and is then adjusted to hold the allocation of the child view. + * + * @param index the index of the child <code>View</code> + * @param a the allocation of this <code>CompositeView</code> before the + * call, the allocation of the child on exit + */ + protected void childAllocation(int index, Rectangle a) + { + if (! isAllocationValid()) + layout(a.width, a.height); + + a.x += offsetsX[index]; + a.y += offsetsY[index]; + a.width = spansX[index]; + a.height = spansY[index]; + } + + /** + * Lays out the children of this <code>BoxView</code> with the specified + * bounds. + * + * @param width the width of the allocated region for the children (that + * is the inner allocation of this <code>BoxView</code> + * @param height the height of the allocated region for the children (that + * is the inner allocation of this <code>BoxView</code> + */ + protected void layout(int width, int height) + { + this.width = width; + this.height = height; + + if (myAxis == X_AXIS) + { + layoutMajorAxis(width, X_AXIS, offsetsX, spansX); + layoutMinorAxis(height, Y_AXIS, offsetsY, spansY); + } + else + { + layoutMajorAxis(height, Y_AXIS, offsetsY, spansY); + layoutMinorAxis(width, X_AXIS, offsetsX, spansX); + } + } + + /** + * Performs the layout along the major axis of a <code>BoxView</code>. + * + * @param targetSpan the (inner) span of the <code>BoxView</code> in which + * to layout the children + * @param axis the axis along which the layout is performed + * @param offsets the array that holds the offsets of the children on exit + * @param offsets the array that holds the spans of the children on exit + */ + protected void layoutMajorAxis(int targetSpan, int axis, int[] offsets, + int[] spans) + { + // Allocate SizeRequirements for each child view. + int count = getViewCount(); + SizeRequirements[] childReqs = new SizeRequirements[count]; + for (int i = 0; i < count; ++i) + { + View view = getView(i); + childReqs[i] = new SizeRequirements((int) view.getMinimumSpan(axis), + (int) view.getPreferredSpan(axis), + (int) view.getMaximumSpan(axis), + view.getAlignment(axis)); + } + + // Calculate the spans and offsets using the SizeRequirements uility + // methods. + SizeRequirements.calculateTiledPositions(targetSpan, null, childReqs, + offsets, spans); + + validateLayout(axis); + } + + /** + * Performs the layout along the minor axis of a <code>BoxView</code>. + * + * @param targetSpan the (inner) span of the <code>BoxView</code> in which + * to layout the children + * @param axis the axis along which the layout is performed + * @param offsets the array that holds the offsets of the children on exit + * @param offsets the array that holds the spans of the children on exit + */ + protected void layoutMinorAxis(int targetSpan, int axis, int[] offsets, + int[] spans) + { + // Allocate SizeRequirements for each child view. + int count = getViewCount(); + SizeRequirements[] childReqs = new SizeRequirements[count]; + for (int i = 0; i < count; ++i) + { + View view = getView(i); + childReqs[i] = new SizeRequirements((int) view.getMinimumSpan(axis), + (int) view.getPreferredSpan(axis), + (int) view.getMaximumSpan(axis), + view.getAlignment(axis)); + } + + // Calculate the spans and offsets using the SizeRequirements uility + // methods. + SizeRequirements.calculateAlignedPositions(targetSpan, null, childReqs, + offsets, spans); + validateLayout(axis); + } + + /** + * Returns <code>true</code> if the cached allocations for the children + * are still valid, <code>false</code> otherwise. + * + * @return <code>true</code> if the cached allocations for the children + * are still valid, <code>false</code> otherwise + */ + protected boolean isAllocationValid() + { + return isLayoutValid(X_AXIS) && isLayoutValid(Y_AXIS); + } + + /** + * Return the current width of the box. This is the last allocated width. + * + * @return the current width of the box + */ + public int getWidth() + { + return width; + } + + /** + * Return the current height of the box. This is the last allocated height. + * + * @return the current height of the box + */ + public int getHeight() + { + return height; + } + + /** + * Sets the size of the view. If the actual size has changed, the layout + * is updated accordingly. + * + * @param width the new width + * @param height the new height + */ + public void setSize(float width, float height) + { + if (this.width != (int) width) + layoutChanged(X_AXIS); + if (this.height != (int) height) + layoutChanged(Y_AXIS); + + Rectangle outside = new Rectangle(0, 0, this.width, this.height); + Rectangle inside = getInsideAllocation(outside); + if (!isAllocationValid()) + layout(inside.width, inside.height); + } + + /** + * Sets the layout to valid for a specific axis. + * + * @param axis the axis for which to validate the layout + */ + void validateLayout(int axis) + { + if (axis == X_AXIS) + xLayoutValid = true; + if (axis == Y_AXIS) + yLayoutValid = true; + } +} diff --git a/libjava/classpath/javax/swing/text/CompositeView.java b/libjava/classpath/javax/swing/text/CompositeView.java new file mode 100644 index 0000000..6776c95 --- /dev/null +++ b/libjava/classpath/javax/swing/text/CompositeView.java @@ -0,0 +1,652 @@ +/* CompositeView.java -- An abstract view that manages child views + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package javax.swing.text; + +import java.awt.Insets; +import java.awt.Rectangle; +import java.awt.Shape; + +import javax.swing.SwingConstants; + +/** + * An abstract base implementation of {@link View} that manages child + * <code>View</code>s. + * + * @author Roman Kennke (roman@kennke.org) + */ +public abstract class CompositeView + extends View +{ + + /** + * The child views of this <code>CompositeView</code>. + */ + View[] children; + + /** + * The allocation of this <code>View</code> minus its insets. This is + * initialized in {@link #getInsideAllocation} and reused and modified in + * {@link childAllocation}. + */ + Rectangle insideAllocation; + + /** + * The insets of this <code>CompositeView</code>. This is initialized + * in {@link #setInsets}. + */ + Insets insets; + + /** + * Creates a new <code>CompositeView</code> for the given + * <code>Element</code>. + * + * @param element the element that is rendered by this CompositeView + */ + public CompositeView(Element element) + { + super(element); + children = new View[0]; + insets = new Insets(0, 0, 0, 0); + } + + /** + * Loads the child views of this <code>CompositeView</code>. This method + * is called from {@link #setParent} to initialize the child views of + * this composite view. + * + * @param f the view factory to use for creating new child views + * + * @see #setParent + */ + protected void loadChildren(ViewFactory f) + { + Element el = getElement(); + int count = el.getElementCount(); + View[] newChildren = new View[count]; + for (int i = 0; i < count; ++i) + { + Element child = el.getElement(i); + View view = f.create(child); + newChildren[i] = view; + } + replace(0, getViewCount(), newChildren); + } + + /** + * Sets the parent of this <code>View</code>. + * In addition to setting the parent, this calls {@link #loadChildren}, if + * this <code>View</code> does not already have its children initialized. + * + * @param parent the parent to set + */ + public void setParent(View parent) + { + super.setParent(parent); + if (parent != null && ((children == null) || children.length == 0)) + loadChildren(getViewFactory()); + } + + /** + * Returns the number of child views. + * + * @return the number of child views + */ + public int getViewCount() + { + return children.length; + } + + /** + * Returns the child view at index <code>n</code>. + * + * @param n the index of the requested child view + * + * @return the child view at index <code>n</code> + */ + public View getView(int n) + { + return children[n]; + } + + /** + * Replaces child views by some other child views. If there are no views to + * remove (<code>length == 0</code>), the result is a simple insert, if + * there are no children to add (<code>view == null</code>) the result + * is a simple removal. + * + * @param offset the start offset from where to remove children + * @param length the number of children to remove + * @param views the views that replace the removed children + */ + public void replace(int offset, int length, View[] views) + { + // Check for null views to add. + for (int i = 0; i < views.length; ++i) + if (views[i] == null) + throw new NullPointerException("Added views must not be null"); + + int endOffset = offset + length; + + // First we set the parent of the removed children to null. + for (int i = offset; i < endOffset; ++i) + children[i].setParent(null); + + View[] newChildren = new View[children.length - length + views.length]; + System.arraycopy(children, 0, newChildren, 0, offset); + System.arraycopy(views, 0, newChildren, offset, views.length); + System.arraycopy(children, offset + length, newChildren, + offset + views.length, + children.length - (offset + length)); + children = newChildren; + + // Finally we set the parent of the added children to this. + for (int i = 0; i < views.length; ++i) + views[i].setParent(this); + } + + /** + * Returns the allocation for the specified child <code>View</code>. + * + * @param index the index of the child view + * @param a the allocation for this view + * + * @return the allocation for the specified child <code>View</code> + */ + public Shape getChildAllocation(int index, Shape a) + { + Rectangle r = getInsideAllocation(a); + childAllocation(index, r); + return r; + } + + /** + * Maps a position in the document into the coordinate space of the View. + * The output rectangle usually reflects the font height but has a width + * of zero. + * + * @param pos the position of the character in the model + * @param a the area that is occupied by the view + * @param bias either {@link Position.Bias#Forward} or + * {@link Position.Bias#Backward} depending on the preferred + * direction bias. If <code>null</code> this defaults to + * <code>Position.Bias.Forward</code> + * + * @return a rectangle that gives the location of the document position + * inside the view coordinate space + * + * @throws BadLocationException if <code>pos</code> is invalid + * @throws IllegalArgumentException if b is not one of the above listed + * valid values + */ + public Shape modelToView(int pos, Shape a, Position.Bias bias) + throws BadLocationException + { + int childIndex = getViewIndex(pos, bias); + if (childIndex != -1) + { + View child = getView(childIndex); + Shape result = child.modelToView(pos, a, bias); + if (result == null) + throw new AssertionError("" + child.getClass().getName() + + ".modelToView() must not return null"); + return result; + } + else + { + // FIXME: Handle the case when we have no child view for the given + // position. + throw new AssertionError("No child views found where child views are " + + "expected. pos = " + pos + ", bias = " + + bias); + } + } + + /** + * Maps a region in the document into the coordinate space of the View. + * + * @param p1 the beginning position inside the document + * @param b1 the direction bias for the beginning position + * @param p2 the end position inside the document + * @param b2 the direction bias for the end position + * @param a the area that is occupied by the view + * + * @return a rectangle that gives the span of the document region + * inside the view coordinate space + * + * @throws BadLocationException if <code>p1</code> or <code>p2</code> are + * invalid + * @throws IllegalArgumentException if b1 or b2 is not one of the above + * listed valid values + */ + public Shape modelToView(int p1, Position.Bias b1, + int p2, Position.Bias b2, Shape a) + throws BadLocationException + { + // TODO: This is most likely not 100% ok, figure out what else is to + // do here. + return super.modelToView(p1, b1, p2, b2, a); + } + + /** + * Maps coordinates from the <code>View</code>'s space into a position + * in the document model. + * + * @param x the x coordinate in the view space + * @param y the y coordinate in the view space + * @param a the allocation of this <code>View</code> + * @param b the bias to use + * + * @return the position in the document that corresponds to the screen + * coordinates <code>x, y</code> + */ + public int viewToModel(float x, float y, Shape a, Position.Bias[] b) + { + Rectangle r = getInsideAllocation(a); + View view = getViewAtPoint((int) x, (int) y, r); + return view.viewToModel(x, y, a, b); + } + + /** + * Returns the next model location that is visible in eiter north / south + * direction or east / west direction. This is used to determine the + * placement of the caret when navigating around the document with + * the arrow keys. + * + * This is a convenience method for + * {@link #getNextNorthSouthVisualPositionFrom} and + * {@link #getNextEastWestVisualPositionFrom}. + * + * @param pos the model position to start search from + * @param b the bias for <code>pos</code> + * @param a the allocated region for this view + * @param direction the direction from the current position, can be one of + * the following: + * <ul> + * <li>{@link SwingConstants#WEST}</li> + * <li>{@link SwingConstants#EAST}</li> + * <li>{@link SwingConstants#NORTH}</li> + * <li>{@link SwingConstants#SOUTH}</li> + * </ul> + * @param biasRet the bias of the return value gets stored here + * + * @return the position inside the model that represents the next visual + * location + * + * @throws BadLocationException if <code>pos</code> is not a valid location + * inside the document model + * @throws IllegalArgumentException if <code>direction</code> is invalid + */ + public int getNextVisualPositionFrom(int pos, Position.Bias b, Shape a, + int direction, Position.Bias[] biasRet) + { + int retVal = -1; + switch (direction) + { + case SwingConstants.WEST: + case SwingConstants.EAST: + retVal = getNextEastWestVisualPositionFrom(pos, b, a, direction, + biasRet); + break; + case SwingConstants.NORTH: + case SwingConstants.SOUTH: + retVal = getNextNorthSouthVisualPositionFrom(pos, b, a, direction, + biasRet); + break; + default: + throw new IllegalArgumentException("Illegal value for direction."); + } + return retVal; + } + + /** + * Returns the index of the child view that represents the specified + * model location. + * + * @param pos the model location for which to determine the child view index + * @param b the bias to be applied to <code>pos</code> + * + * @return the index of the child view that represents the specified + * model location + */ + public int getViewIndex(int pos, Position.Bias b) + { + // FIXME: Handle bias somehow. + return getViewIndexAtPosition(pos); + } + + /** + * Returns <code>true</code> if the specified point lies before the + * given <code>Rectangle</code>, <code>false</code> otherwise. + * + * "Before" is typically defined as being to the left or above. + * + * @param x the X coordinate of the point + * @param y the Y coordinate of the point + * @param r the rectangle to test the point against + * + * @return <code>true</code> if the specified point lies before the + * given <code>Rectangle</code>, <code>false</code> otherwise + */ + protected abstract boolean isBefore(int x, int y, Rectangle r); + + /** + * Returns <code>true</code> if the specified point lies after the + * given <code>Rectangle</code>, <code>false</code> otherwise. + * + * "After" is typically defined as being to the right or below. + * + * @param x the X coordinate of the point + * @param y the Y coordinate of the point + * @param r the rectangle to test the point against + * + * @return <code>true</code> if the specified point lies after the + * given <code>Rectangle</code>, <code>false</code> otherwise + */ + protected abstract boolean isAfter(int x, int y, Rectangle r); + + /** + * Returns the child <code>View</code> at the specified location. + * + * @param x the X coordinate + * @param y the Y coordinate + * @param r the inner allocation of this <code>BoxView</code> on entry, + * the allocation of the found child on exit + * + * @return the child <code>View</code> at the specified location + */ + protected abstract View getViewAtPoint(int x, int y, Rectangle r); + + /** + * Computes the allocation for a child <code>View</code>. The parameter + * <code>a</code> stores the allocation of this <code>CompositeView</code> + * and is then adjusted to hold the allocation of the child view. + * + * @param index the index of the child <code>View</code> + * @param a the allocation of this <code>CompositeView</code> before the + * call, the allocation of the child on exit + */ + protected abstract void childAllocation(int index, Rectangle a); + + /** + * Returns the child <code>View</code> that contains the given model + * position. The given <code>Rectangle</code> gives the parent's allocation + * and is changed to the child's allocation on exit. + * + * @param pos the model position to query the child <code>View</code> for + * @param a the parent allocation on entry and the child allocation on exit + * + * @return the child view at the given model position + */ + protected View getViewAtPosition(int pos, Rectangle a) + { + int i = getViewIndexAtPosition(pos); + View view = children[i]; + childAllocation(i, a); + return view; + } + + /** + * Returns the index of the child <code>View</code> for the given model + * position. + * + * @param pos the model position for whicht the child <code>View</code> is + * queried + * + * @return the index of the child <code>View</code> for the given model + * position + */ + protected int getViewIndexAtPosition(int pos) + { + // We have one child view allocated for each child element in + // loadChildren(), so this should work. + Element el = getElement(); + int index = el.getElementIndex(pos); + return index; + } + + /** + * Returns the allocation that is given to this <code>CompositeView</code> + * minus this <code>CompositeView</code>'s insets. + * + * Also this translates from an immutable allocation to a mutable allocation + * that is typically reused and further narrowed, like in + * {@link #childAllocation}. + * + * @param a the allocation given to this <code>CompositeView</code> + * + * @return the allocation that is given to this <code>CompositeView</code> + * minus this <code>CompositeView</code>'s insets or + * <code>null</code> if a was <code>null</code> + */ + protected Rectangle getInsideAllocation(Shape a) + { + if (a == null) + return null; + + Rectangle alloc = a.getBounds(); + // Initialize the inside allocation rectangle. This is done inside + // a synchronized block in order to avoid multiple threads creating + // this instance simultanously. + Rectangle inside; + synchronized(this) + { + inside = insideAllocation; + if (inside == null) + { + inside = new Rectangle(); + insideAllocation = inside; + } + } + inside.x = alloc.x - insets.left; + inside.y = alloc.y - insets.top; + inside.width = alloc.width - insets.left - insets.right; + inside.height = alloc.height - insets.top - insets.bottom; + return inside; + } + + /** + * Sets the insets defined by attributes in <code>attributes</code>. This + * queries the attribute keys {@link StyleConstants#SpaceAbove}, + * {@link StyleConstants#SpaceBelow}, {@link StyleConstants#LeftIndent} and + * {@link StyleConstants#RightIndent} and calls {@link #setInsets} to + * actually set the insets on this <code>CompositeView</code>. + * + * @param attributes the attributes from which to query the insets + */ + protected void setParagraphInsets(AttributeSet attributes) + { + Float l = (Float) attributes.getAttribute(StyleConstants.LeftIndent); + short left = 0; + if (l != null) + left = l.shortValue(); + Float r = (Float) attributes.getAttribute(StyleConstants.RightIndent); + short right = 0; + if (r != null) + right = r.shortValue(); + Float t = (Float) attributes.getAttribute(StyleConstants.SpaceAbove); + short top = 0; + if (t != null) + top = t.shortValue(); + Float b = (Float) attributes.getAttribute(StyleConstants.SpaceBelow); + short bottom = 0; + if (b != null) + bottom = b.shortValue(); + setInsets(top, left, bottom, right); + } + + /** + * Sets the insets of this <code>CompositeView</code>. + * + * @param top the top inset + * @param left the left inset + * @param bottom the bottom inset + * @param right the right inset + */ + protected void setInsets(short top, short left, short bottom, short right) + { + insets.top = top; + insets.left = left; + insets.bottom = bottom; + insets.right = right; + } + + /** + * Returns the left inset of this <code>CompositeView</code>. + * + * @return the left inset of this <code>CompositeView</code> + */ + protected short getLeftInset() + { + return (short) insets.left; + } + + /** + * Returns the right inset of this <code>CompositeView</code>. + * + * @return the right inset of this <code>CompositeView</code> + */ + protected short getRightInset() + { + return (short) insets.right; + } + + /** + * Returns the top inset of this <code>CompositeView</code>. + * + * @return the top inset of this <code>CompositeView</code> + */ + protected short getTopInset() + { + return (short) insets.top; + } + + /** + * Returns the bottom inset of this <code>CompositeView</code>. + * + * @return the bottom inset of this <code>CompositeView</code> + */ + protected short getBottomInset() + { + return (short) insets.bottom; + } + + /** + * Returns the next model location that is visible in north or south + * direction. + * This is used to determine the + * placement of the caret when navigating around the document with + * the arrow keys. + * + * @param pos the model position to start search from + * @param b the bias for <code>pos</code> + * @param a the allocated region for this view + * @param direction the direction from the current position, can be one of + * the following: + * <ul> + * <li>{@link SwingConstants#NORTH}</li> + * <li>{@link SwingConstants#SOUTH}</li> + * </ul> + * @param biasRet the bias of the return value gets stored here + * + * @return the position inside the model that represents the next visual + * location + * + * @throws BadLocationException if <code>pos</code> is not a valid location + * inside the document model + * @throws IllegalArgumentException if <code>direction</code> is invalid + */ + protected int getNextNorthSouthVisualPositionFrom(int pos, Position.Bias b, + Shape a, int direction, + Position.Bias[] biasRet) + { + // FIXME: Implement this correctly. + return pos; + } + + /** + * Returns the next model location that is visible in east or west + * direction. + * This is used to determine the + * placement of the caret when navigating around the document with + * the arrow keys. + * + * @param pos the model position to start search from + * @param b the bias for <code>pos</code> + * @param a the allocated region for this view + * @param direction the direction from the current position, can be one of + * the following: + * <ul> + * <li>{@link SwingConstants#EAST}</li> + * <li>{@link SwingConstants#WEST}</li> + * </ul> + * @param biasRet the bias of the return value gets stored here + * + * @return the position inside the model that represents the next visual + * location + * + * @throws BadLocationException if <code>pos</code> is not a valid location + * inside the document model + * @throws IllegalArgumentException if <code>direction</code> is invalid + */ + protected int getNextEastWestVisualPositionFrom(int pos, Position.Bias b, + Shape a, int direction, + Position.Bias[] biasRet) + { + // FIXME: Implement this correctly. + return pos; + } + + /** + * Determines if the next view in horinzontal direction is located to + * the east or west of the view at position <code>pos</code>. Usually + * the <code>View</code>s are laid out from the east to the west, so + * we unconditionally return <code>false</code> here. Subclasses that + * support bidirectional text may wish to override this method. + * + * @param pos the position in the document + * @param bias the bias to be applied to <code>pos</code> + * + * @return <code>true</code> if the next <code>View</code> is located + * to the EAST, <code>false</code> otherwise + */ + protected boolean flipEastAndWestAtEnds(int pos, Position.Bias bias) + { + return false; + } +} diff --git a/libjava/classpath/javax/swing/text/ElementIterator.java b/libjava/classpath/javax/swing/text/ElementIterator.java new file mode 100644 index 0000000..a6a5ff6 --- /dev/null +++ b/libjava/classpath/javax/swing/text/ElementIterator.java @@ -0,0 +1,181 @@ +/* ElementIterator.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.swing.text; + +/** + * This class can be used to iterate over the {@link Element} tree of + * a {@link Document} or an {@link Element}. This iterator performs + * an "in-order" traversal -- first it visits a node, then each of the + * node's children in order. No locking is performed during the + * iteration; that is up to the caller. + */ +public class ElementIterator implements Cloneable +{ + // The root element. + private Element root; + // The current element. + private Element currentElement; + // The depth to which we have descended in the tree. + private int currentDepth; + + // This is at least as big as the current depth, and at index N + // contains the index of the child element we're currently + // examining. + private int[] state; + + // The previous item. + private Element previousItem; + + /** + * Create a new ElementIterator to iterate over the given document. + * @param document the Document over which we iterate + */ + public ElementIterator(Document document) + { + this.root = document.getDefaultRootElement(); + this.currentElement = root; + this.state = new int[5]; + } + + /** + * Create a new ElementIterator to iterate over the given document. + * @param root the Document over which we iterate + */ + public ElementIterator(Element root) + { + this.root = root; + this.currentElement = root; + this.state = new int[5]; + } + + /** + * Returns a new ElementIterator which is a clone of this + * ElementIterator. + */ + public Object clone() + { + try + { + return super.clone(); + } + catch (CloneNotSupportedException _) + { + // Can't happen. + return null; + } + } + + /** + * Returns the current element. + */ + public Element current() + { + return currentElement; + } + + /** + * Returns the depth to which we have descended in the tree. + */ + public int depth() + { + return currentDepth; + } + + /** + * Returns the first element in the tree. + */ + public Element first() + { + // Reset the iterator. + currentElement = root; + currentDepth = 0; + previousItem = null; + return root; + } + + /** + * Advance the iterator and return the next element of the tree, + * performing an "in-order" traversal. + */ + public Element next() + { + previousItem = currentElement; + if (currentElement == null) + return null; + if (! currentElement.isLeaf()) + { + ++currentDepth; + if (currentDepth > state.length) + { + int[] newState = new int[state.length * 2]; + System.arraycopy(state, 0, newState, 0, state.length); + state = newState; + } + state[currentDepth] = 0; + currentElement = currentElement.getElement(0); + return currentElement; + } + + while (currentDepth > 0) + { + // At a leaf, or done with a non-leaf's children, so go up a + // level. + --currentDepth; + currentElement = currentElement.getParentElement(); + ++state[currentDepth]; + if (state[currentDepth] < currentElement.getElementCount()) + { + currentElement = currentElement.getElement(state[currentDepth]); + return currentElement; + } + } + + currentElement = null; + return currentElement; + } + + /** + * Returns the previous item. Does not modify the iterator state. + */ + public Element previous() + { + if (currentElement == null || currentElement == root) + return null; + return previousItem; + } +} diff --git a/libjava/classpath/javax/swing/text/FlowView.java b/libjava/classpath/javax/swing/text/FlowView.java new file mode 100644 index 0000000..a6ef89e --- /dev/null +++ b/libjava/classpath/javax/swing/text/FlowView.java @@ -0,0 +1,617 @@ +/* FlowView.java -- A composite View + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package javax.swing.text; + +import java.awt.Container; +import java.awt.Graphics; +import java.awt.Rectangle; +import java.awt.Shape; +import java.util.Vector; + +import javax.swing.event.DocumentEvent; + +/** + * A <code>View</code> that can flows it's children into it's layout space. + * + * The <code>FlowView</code> manages a set of logical views (that are + * the children of the {@link #layoutPool} field). These are translated + * at layout time into a set of physical views. These are the views that + * are managed as the real child views. Each of these child views represents + * a row and are laid out within a box using the superclasses behaviour. + * The concrete implementation of the rows must be provided by subclasses. + * + * @author Roman Kennke (roman@kennke.org) + */ +public abstract class FlowView extends BoxView +{ + /** + * A strategy for translating the logical views of a <code>FlowView</code> + * into the real views. + */ + public static class FlowStrategy + { + /** + * Creates a new instance of <code>FlowStragegy</code>. + */ + public FlowStrategy() + { + } + + /** + * Receives notification from a <code>FlowView</code> that some content + * has been inserted into the document at a location that the + * <code>FlowView</code> is responsible for. + * + * The default implementation simply calls {@link #layout}. + * + * @param fv the flow view that sends the notification + * @param e the document event describing the change + * @param alloc the current allocation of the flow view + */ + public void insertUpdate(FlowView fv, DocumentEvent e, Rectangle alloc) + { + layout(fv); + } + + /** + * Receives notification from a <code>FlowView</code> that some content + * has been removed from the document at a location that the + * <code>FlowView</code> is responsible for. + * + * The default implementation simply calls {@link #layout}. + * + * @param fv the flow view that sends the notification + * @param e the document event describing the change + * @param alloc the current allocation of the flow view + */ + public void removeUpdate(FlowView fv, DocumentEvent e, Rectangle alloc) + { + layout(fv); + } + + /** + * Receives notification from a <code>FlowView</code> that some attributes + * have changed in the document at a location that the + * <code>FlowView</code> is responsible for. + * + * The default implementation simply calls {@link #layout}. + * + * @param fv the flow view that sends the notification + * @param e the document event describing the change + * @param alloc the current allocation of the flow view + */ + public void changedUpdate(FlowView fv, DocumentEvent e, Rectangle alloc) + { + layout(fv); + } + + /** + * Returns the logical view of the managed <code>FlowView</code>. + * + * @param fv the flow view for which to return the logical view + * + * @return the logical view of the managed <code>FlowView</code> + */ + public View getLogicalView(FlowView fv) + { + return fv.layoutPool; + } + + /** + * Performs the layout for the whole view. By default this rebuilds + * all the physical views from the logical views of the managed FlowView. + * + * This is called by {@link FlowLayout#layout} to update the layout of + * the view. + * + * @param fv the flow view for which we perform the layout + */ + public void layout(FlowView fv) + { + fv.removeAll(); + Element el = fv.getElement(); + + int rowStart = el.getStartOffset(); + int end = el.getEndOffset(); + int rowIndex = 0; + while (rowStart >= 0 && rowStart < end) + { + View row = fv.createRow(); + fv.append(row); + rowStart = layoutRow(fv, rowIndex, rowStart); + rowIndex++; + } + } + + /** + * Lays out one row of the flow view. This is called by {@link #layout} + * to fill one row with child views until the available span is exhausted. + * + * @param fv the flow view for which we perform the layout + * @param rowIndex the index of the row + * @param pos the start position for the row + * + * @return the start position of the next row + */ + protected int layoutRow(FlowView fv, int rowIndex, int pos) + { + int spanLeft = fv.getFlowSpan(rowIndex); + if (spanLeft <= 0) + return -1; + + int offset = pos; + View row = fv.getView(rowIndex); + int flowAxis = fv.getFlowAxis(); + + while (spanLeft > 0) + { + View child = createView(fv, offset, spanLeft, rowIndex); + if (child == null) + break; + + int span = (int) child.getPreferredSpan(flowAxis); + if (span > spanLeft) + break; + + row.append(child); + spanLeft -= span; + offset = child.getEndOffset(); + } + return offset; + } + + /** + * Creates physical views that form the rows of the flow view. This + * can be an entire view from the logical view (if it fits within the + * available span), a fragment of such a view (if it doesn't fit in the + * available span and can be broken down) or <code>null</code> (if it does + * not fit in the available span and also cannot be broken down). + * + * @param fv the flow view + * @param startOffset the start offset for the view to be created + * @param spanLeft the available span + * @param rowIndex the index of the row + * + * @return a view to fill the row with, or <code>null</code> if there + * is no view or view fragment that fits in the available span + */ + protected View createView(FlowView fv, int offset, int spanLeft, + int rowIndex) + { + // Find the logical element for the given offset. + View logicalView = getLogicalView(fv); + + int viewIndex = logicalView.getViewIndex(offset, Position.Bias.Forward); + View child = logicalView.getView(viewIndex); + int flowAxis = fv.getFlowAxis(); + int span = (int) child.getPreferredSpan(flowAxis); + + if (span <= spanLeft) + return child; + + else if (child.getBreakWeight(flowAxis, offset, spanLeft) + > BadBreakWeight) + // FIXME: What to do with the pos parameter here? + return child.breakView(flowAxis, offset, 0, spanLeft); + else + return null; + } + } + + /** + * This special subclass of <code>View</code> is used to represent + * the logical representation of this view. It does not support any + * visual representation, this is handled by the physical view implemented + * in the <code>FlowView</code>. + */ + class LogicalView extends View + { + /** + * The child views of this logical view. + */ + Vector children; + + /** + * Creates a new LogicalView instance. + */ + LogicalView(Element el) + { + super(el); + children = new Vector(); + } + + /** + * Returns the container that holds this view. The logical view returns + * the enclosing FlowView's container here. + * + * @return the container that holds this view + */ + public Container getContainer() + { + return FlowView.this.getContainer(); + } + + /** + * Returns the number of child views of this logical view. + * + * @return the number of child views of this logical view + */ + public int getViewCount() + { + return children.size(); + } + + /** + * Returns the child view at the specified index. + * + * @param index the index + * + * @return the child view at the specified index + */ + public View getView(int index) + { + return (View) children.get(index); + } + + /** + * Replaces some child views with other child views. + * + * @param offset the offset at which to replace child views + * @param length the number of children to remove + * @param views the views to be inserted + */ + public void replace(int offset, int length, View[] views) + { + if (length > 0) + { + for (int count = 0; count < length; ++count) + children.remove(offset); + } + + int endOffset = offset + views.length; + for (int i = offset; i < endOffset; ++i) + { + children.add(i, views[i - offset]); + // Set the parent of the child views to the flow view itself so + // it has something to resolve. + views[i - offset].setParent(FlowView.this); + } + } + + /** + * Returns the index of the child view that contains the specified + * position in the document model. + * + * @param pos the position for which we are searching the child view + * @param b the bias + * + * @return the index of the child view that contains the specified + * position in the document model + */ + public int getViewIndex(int pos, Position.Bias b) + { + return getElement().getElementIndex(pos); + } + + /** + * Throws an AssertionError because it must never be called. LogicalView + * only serves as a holder for child views and has no visual + * representation. + */ + public float getPreferredSpan(int axis) + { + throw new AssertionError("This method must not be called in " + + "LogicalView."); + } + + /** + * Throws an AssertionError because it must never be called. LogicalView + * only serves as a holder for child views and has no visual + * representation. + */ + public Shape modelToView(int pos, Shape a, Position.Bias b) + throws BadLocationException + { + throw new AssertionError("This method must not be called in " + + "LogicalView."); + } + + /** + * Throws an AssertionError because it must never be called. LogicalView + * only serves as a holder for child views and has no visual + * representation. + */ + public void paint(Graphics g, Shape s) + { + throw new AssertionError("This method must not be called in " + + "LogicalView."); + } + + /** + * Throws an AssertionError because it must never be called. LogicalView + * only serves as a holder for child views and has no visual + * representation. + */ + public int viewToModel(float x, float y, Shape a, Position.Bias[] b) + { + throw new AssertionError("This method must not be called in " + + "LogicalView."); + } + } + + /** + * The shared instance of FlowStrategy. + */ + static final FlowStrategy sharedStrategy = new FlowStrategy(); + + /** + * The span of the <code>FlowView</code> that should be flowed. + */ + protected int layoutSpan; + + /** + * Represents the logical child elements of this view, encapsulated within + * one parent view (an instance of a package private <code>LogicalView</code> + * class). These will be translated to a set of real views that are then + * displayed on screen. This translation is performed by the inner class + * {@link FlowStrategy}. + */ + protected View layoutPool; + + /** + * The <code>FlowStrategy</code> to use for translating between the + * logical and physical view. + */ + protected FlowStrategy strategy; + + /** + * Creates a new <code>FlowView</code> for the given + * <code>Element</code> and <code>axis</code>. + * + * @param element the element that is rendered by this FlowView + * @param axis the axis along which the view is tiled, either + * <code>View.X_AXIS</code> or <code>View.Y_AXIS</code>, the flow + * axis is orthogonal to this one + */ + public FlowView(Element element, int axis) + { + super(element, axis); + strategy = sharedStrategy; + } + + /** + * Returns the axis along which the view should be flowed. This is + * orthogonal to the axis along which the boxes are tiled. + * + * @return the axis along which the view should be flowed + */ + public int getFlowAxis() + { + int axis = getAxis(); + int flowAxis; + + if (axis == X_AXIS) + flowAxis = Y_AXIS; + else + flowAxis = X_AXIS; + + return flowAxis; + + } + + /** + * Returns the span of the flow for the specified child view. A flow + * layout can be shaped by providing different span values for different + * child indices. The default implementation returns the entire available + * span inside the view. + * + * @param index the index of the child for which to return the span + * + * @return the span of the flow for the specified child view + */ + public int getFlowSpan(int index) + { + return layoutSpan; + } + + /** + * Returns the location along the flow axis where the flow span starts + * given a child view index. The flow can be shaped by providing + * different values here. + * + * @param index the index of the child for which to return the flow location + * + * @return the location along the flow axis where the flow span starts + */ + public int getFlowStart(int index) + { + return getLeftInset(); // TODO: Is this correct? + } + + /** + * Creates a new view that represents a row within a flow. + * + * @return a view for a new row + */ + protected abstract View createRow(); + + /** + * Loads the children of this view. The <code>FlowView</code> does not + * directly load its children. Instead it creates a logical view + * (@{link #layoutPool}) which is filled by the logical child views. + * The real children are created at layout time and each represent one + * row. + * + * This method is called by {@link #setParent} in order to initialize + * the view. + * + * @param vf the view factory to use for creating the child views + */ + protected void loadChildren(ViewFactory vf) + { + if (layoutPool == null) + { + layoutPool = new LogicalView(getElement()); + + Element el = getElement(); + int count = el.getElementCount(); + for (int i = 0; i < count; ++i) + { + Element childEl = el.getElement(i); + View childView = vf.create(childEl); + layoutPool.append(childView); + } + } + } + + /** + * Performs the layout of this view. If the span along the flow axis changed, + * this first calls {@link FlowStrategy.layout} in order to rebuild the + * rows of this view. Then the superclass's behaviour is called to arrange + * the rows within the box. + * + * @param width the width of the view + * @param height the height of the view + */ + protected void layout(int width, int height) + { + boolean rebuild = false; + + int flowAxis = getFlowAxis(); + if (flowAxis == X_AXIS) + { + rebuild = !(width == layoutSpan); + layoutSpan = width; + } + else + { + rebuild = !(height == layoutSpan); + layoutSpan = height; + } + + if (rebuild) + strategy.layout(this); + + // TODO: If the span along the box axis has changed in the process of + // relayouting the rows (that is, if rows have been added or removed), + // call preferenceChanged in order to throw away cached layout information + // of the surrounding BoxView. + + super.layout(width, height); + } + + /** + * Receice notification that some content has been inserted in the region + * that this view is responsible for. This calls + * {@link FlowStrategy#insertUpdate}. + * + * @param changes the document event describing the changes + * @param a the current allocation of the view + * @param vf the view factory that is used for creating new child views + */ + public void insertUpdate(DocumentEvent changes, Shape a, ViewFactory vf) + { + strategy.insertUpdate(this, changes, getInsideAllocation(a)); + } + + /** + * Receice notification that some content has been removed from the region + * that this view is responsible for. This calls + * {@link FlowStrategy#removeUpdate}. + * + * @param changes the document event describing the changes + * @param a the current allocation of the view + * @param vf the view factory that is used for creating new child views + */ + public void removeUpdate(DocumentEvent changes, Shape a, ViewFactory vf) + { + strategy.removeUpdate(this, changes, getInsideAllocation(a)); + } + + /** + * Receice notification that some attributes changed in the region + * that this view is responsible for. This calls + * {@link FlowStrategy#changedUpdate}. + * + * @param changes the document event describing the changes + * @param a the current allocation of the view + * @param vf the view factory that is used for creating new child views + */ + public void changedUpdate(DocumentEvent changes, Shape a, ViewFactory vf) + { + strategy.changedUpdate(this, changes, getInsideAllocation(a)); + } + + /** + * Returns the index of the child <code>View</code> for the given model + * position. + * + * This is implemented to iterate over the children of this + * view (the rows) and return the index of the first view that contains + * the given position. + * + * @param pos the model position for whicht the child <code>View</code> is + * queried + * + * @return the index of the child <code>View</code> for the given model + * position + */ + protected int getViewIndexAtPosition(int pos) + { + // First make sure we have a valid layout. + if (!isAllocationValid()) + layout(getWidth(), getHeight()); + + int count = getViewCount(); + int result = -1; + + for (int i = 0; i < count; ++i) + { + View child = getView(i); + int start = child.getStartOffset(); + int end = child.getEndOffset(); + if (start <= pos && end > pos) + { + result = i; + break; + } + } + return result; + } +} diff --git a/libjava/classpath/javax/swing/text/GlyphView.java b/libjava/classpath/javax/swing/text/GlyphView.java new file mode 100644 index 0000000..f9e6097 --- /dev/null +++ b/libjava/classpath/javax/swing/text/GlyphView.java @@ -0,0 +1,521 @@ +/* GlyphView.java -- A view to render styled text + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package javax.swing.text; + +import java.awt.Color; +import java.awt.Font; +import java.awt.FontMetrics; +import java.awt.Graphics; +import java.awt.Rectangle; +import java.awt.Shape; + +/** + * Renders a run of styled text. This {@link View} subclass paints the + * characters of the <code>Element</code> it is responsible for using + * the style information from that <code>Element</code>. + * + * @author Roman Kennke (roman@kennke.org) + */ +public class GlyphView + extends View + implements TabableView, Cloneable +{ + + /** + * An abstract base implementation for a glyph painter for + * <code>GlyphView</code>. + */ + public abstract static class GlyphPainter + { + /** + * Creates a new <code>GlyphPainer</code>. + */ + public GlyphPainter() + { + } + + /** + * Returns the full height of the rendered text. + * + * @return the full height of the rendered text + */ + public abstract float getHeight(GlyphView view); + + /** + * Paints the glyphs. + * + * @param view the glyph view to paint + * @param g the graphics context to use for painting + * @param a the allocation of the glyph view + * @param p0 the start position (in the model) from which to paint + * @param p1 the end position (in the model) to which to paint + */ + public abstract void paint(GlyphView view, Graphics g, Shape a, int p0, + int p1); + + /** + * Maps a position in the document into the coordinate space of the View. + * The output rectangle usually reflects the font height but has a width + * of zero. + * + * @param view the glyph view + * @param pos the position of the character in the model + * @param a the area that is occupied by the view + * @param bias either {@link Position.Bias.Forward} or + * {@link Position.Bias.Backward} depending on the preferred + * direction bias. If <code>null</code> this defaults to + * <code>Position.Bias.Forward</code> + * + * @return a rectangle that gives the location of the document position + * inside the view coordinate space + * + * @throws BadLocationException if <code>pos</code> is invalid + * @throws IllegalArgumentException if b is not one of the above listed + * valid values + */ + public abstract Shape modelToView(GlyphView view, int pos, Position.Bias b, + Shape a) + throws BadLocationException; + + /** + * Determine the span of the glyphs from location <code>p0</code> to + * location <code>p1</code>. If <code>te</code> is not <code>null</code>, + * then TABs are expanded using this <code>TabExpander</code>. + * The parameter <code>x</code> is the location at which the view is + * located (this is important when using TAB expansion). + * + * @param view the glyph view + * @param p0 the starting location in the document model + * @param p0 the end location in the document model + * @param te the tab expander to use + * @param x the location at which the view is located + * + * @return the span of the glyphs from location <code>p0</code> to + * location <code>p1</code>, possibly using TAB expansion + */ + public abstract float getSpan(GlyphView view, int p0, int p1, + TabExpander te, float x); + + } + + /** + * The default <code>GlyphPainter</code> used in <code>GlyphView</code>. + */ + static class DefaultGlyphPainter extends GlyphPainter + { + /** + * Returns the full height of the rendered text. + * + * @return the full height of the rendered text + */ + public float getHeight(GlyphView view) + { + Font font = view.getFont(); + FontMetrics metrics = view.getContainer().getFontMetrics(font); + float height = metrics.getHeight(); + return height; + } + + /** + * Paints the glyphs. + * + * @param view the glyph view to paint + * @param g the graphics context to use for painting + * @param a the allocation of the glyph view + * @param p0 the start position (in the model) from which to paint + * @param p1 the end position (in the model) to which to paint + */ + public void paint(GlyphView view, Graphics g, Shape a, int p0, + int p1) + { + int height = (int) getHeight(view); + Segment txt = view.getText(p0, p1); + Rectangle bounds = a.getBounds(); + + TabExpander tabEx = null; + View parent = view.getParent(); + if (parent instanceof TabExpander) + tabEx = (TabExpander) parent; + + // FIXME: Set character attributes like font-family, font-size, colors. + Color foreground = view.getForeground(); + g.setColor(foreground); + Utilities.drawTabbedText(txt, bounds.x, bounds.y, g, tabEx, + txt.offset); + } + + /** + * Maps a position in the document into the coordinate space of the View. + * The output rectangle usually reflects the font height but has a width + * of zero. + * + * @param view the glyph view + * @param pos the position of the character in the model + * @param a the area that is occupied by the view + * @param bias either {@link Position.Bias.Forward} or + * {@link Position.Bias.Backward} depending on the preferred + * direction bias. If <code>null</code> this defaults to + * <code>Position.Bias.Forward</code> + * + * @return a rectangle that gives the location of the document position + * inside the view coordinate space + * + * @throws BadLocationException if <code>pos</code> is invalid + * @throws IllegalArgumentException if b is not one of the above listed + * valid values + */ + public Shape modelToView(GlyphView view, int pos, Position.Bias b, + Shape a) + throws BadLocationException + { + Element el = view.getElement(); + Font font = view.getFont(); + FontMetrics fm = view.getContainer().getFontMetrics(font); + Segment txt = view.getText(el.getStartOffset(), pos); + int width = fm.charsWidth(txt.array, txt.offset, txt.count); + int height = fm.getHeight(); + Rectangle bounds = a.getBounds(); + Rectangle result = new Rectangle(bounds.x + width, bounds.y, + bounds.x + width, height); + return result; + } + + /** + * Determine the span of the glyphs from location <code>p0</code> to + * location <code>p1</code>. If <code>te</code> is not <code>null</code>, + * then TABs are expanded using this <code>TabExpander</code>. + * The parameter <code>x</code> is the location at which the view is + * located (this is important when using TAB expansion). + * + * @param view the glyph view + * @param p0 the starting location in the document model + * @param p0 the end location in the document model + * @param te the tab expander to use + * @param x the location at which the view is located + * + * @return the span of the glyphs from location <code>p0</code> to + * location <code>p1</code>, possibly using TAB expansion + */ + public float getSpan(GlyphView view, int p0, int p1, + TabExpander te, float x) + { + Element el = view.getElement(); + Font font = view.getFont(); + FontMetrics fm = view.getContainer().getFontMetrics(font); + Segment txt = view.getText(p0, p1); + int span = Utilities.getTabbedTextWidth(txt, fm, (int) x, te, p0); + return span; + } + } + + /** + * The GlyphPainer used for painting the glyphs. + */ + GlyphPainter glyphPainter; + + /** + * Creates a new <code>GlyphView</code> for the given <code>Element</code>. + * + * @param element the element that is rendered by this GlyphView + */ + public GlyphView(Element element) + { + super(element); + } + + /** + * Returns the <code>GlyphPainter</code> that is used by this + * <code>GlyphView</code>. If no <code>GlyphPainer</code> has been installed + * <code>null</code> is returned. + * + * @return the glyph painter that is used by this + * glyph view or <code>null</code> if no glyph painter has been + * installed + */ + public GlyphPainter getGlyphPainter() + { + return glyphPainter; + } + + /** + * Sets the {@link GlyphPainter} to be used for this <code>GlyphView</code>. + * + * @param painter the glyph painter to be used for this glyph view + */ + public void setGlyphPainter(GlyphPainter painter) + { + glyphPainter = painter; + } + + /** + * Checks if a <code>GlyphPainer</code> is installed. If this is not the + * case, a default painter is installed. + */ + protected void checkPainter() + { + if (glyphPainter == null) + glyphPainter = new DefaultGlyphPainter(); + } + + /** + * Renders the <code>Element</code> that is associated with this + * <code>View</code>. + * + * @param g the <code>Graphics</code> context to render to + * @param a the allocated region for the <code>Element</code> + */ + public void paint(Graphics g, Shape a) + { + Element el = getElement(); + checkPainter(); + getGlyphPainter().paint(this, g, a, el.getStartOffset(), + el.getEndOffset()); + } + + + /** + * Returns the preferred span of the content managed by this + * <code>View</code> along the specified <code>axis</code>. + * + * @param axis the axis + * + * @return the preferred span of this <code>View</code>. + */ + public float getPreferredSpan(int axis) + { + Element el = getElement(); + checkPainter(); + GlyphPainter painter = getGlyphPainter(); + TabExpander tabEx = null; + View parent = getParent(); + if (parent instanceof TabExpander) + tabEx = (TabExpander) parent; + // FIXME: Figure out how to determine the x parameter. + float span = painter.getSpan(this, el.getStartOffset(), el.getEndOffset(), + tabEx, 0.F); + return span; + } + + /** + * Maps a position in the document into the coordinate space of the View. + * The output rectangle usually reflects the font height but has a width + * of zero. + * + * @param pos the position of the character in the model + * @param a the area that is occupied by the view + * @param b either {@link Position.Bias#Forward} or + * {@link Position.Bias#Backward} depending on the preferred + * direction bias. If <code>null</code> this defaults to + * <code>Position.Bias.Forward</code> + * + * @return a rectangle that gives the location of the document position + * inside the view coordinate space + * + * @throws BadLocationException if <code>pos</code> is invalid + * @throws IllegalArgumentException if b is not one of the above listed + * valid values + */ + public Shape modelToView(int pos, Shape a, Position.Bias b) + throws BadLocationException + { + GlyphPainter p = getGlyphPainter(); + return p.modelToView(this, pos, b, a); + } + + /** + * Maps coordinates from the <code>View</code>'s space into a position + * in the document model. + * + * @param x the x coordinate in the view space + * @param y the y coordinate in the view space + * @param a the allocation of this <code>View</code> + * @param b the bias to use + * + * @return the position in the document that corresponds to the screen + * coordinates <code>x, y</code> + */ + public int viewToModel(float x, float y, Shape a, Position.Bias[] b) + { + // FIXME: not implemented + return 0; + } + + /** + * Return the {@link TabExpander} to use. + * + * @return the {@link TabExpander} to use + */ + public TabExpander getTabExpander() + { + // TODO: Figure out if this is correct. + TabExpander te = null; + View parent = getParent(); + + if (parent instanceof ParagraphView) + te = (ParagraphView) parent; + + return te; + } + + /** + * Returns the preferred span of this view for tab expansion. + * + * @param x the location of the view + * @param te the tab expander to use + * + * @return the preferred span of this view for tab expansion + */ + public float getTabbedSpan(float x, TabExpander te) + { + Element el = getElement(); + return getGlyphPainter().getSpan(this, el.getStartOffset(), + el.getEndOffset(), te, x); + } + + /** + * Returns the span of a portion of the view. This is used in TAB expansion + * for fragments that don't contain TABs. + * + * @param p0 the start index + * @param p1 the end index + * + * @return the span of the specified portion of the view + */ + public float getPartialSpan(int p0, int p1) + { + Element el = getElement(); + Document doc = el.getDocument(); + Segment seg = new Segment(); + try + { + doc.getText(p0, p1 - p0, seg); + } + catch (BadLocationException ex) + { + throw new AssertionError("BadLocationException must not be thrown " + + "here"); + } + FontMetrics fm = null; // Fetch font metrics somewhere. + return Utilities.getTabbedTextWidth(seg, fm, 0, null, p0); + } + + /** + * Returns the starting offset in the document model of the portion + * of text that this view is responsible for. + * + * @return the starting offset in the document model of the portion + * of text that this view is responsible for + */ + public int getBeginIndex() + { + return getElement().getStartOffset(); + } + + /** + * Returns the end offset in the document model of the portion + * of text that this view is responsible for. + * + * @return the end offset in the document model of the portion + * of text that this view is responsible for + */ + public int getEndIndex() + { + return getElement().getEndOffset(); + } + + /** + * Returns the text segment that this view is responsible for. + * + * @param p0 the start index in the document model + * @param p1 the end index in the document model + * + * @return the text segment that this view is responsible for + */ + public Segment getText(int p0, int p1) + { + Segment txt = new Segment(); + try + { + getDocument().getText(p0, p1 - p0, txt); + } + catch (BadLocationException ex) + { + throw new AssertionError("BadLocationException should not be " + + "thrown here. p0 = " + p0 + ", p1 = " + p1); + } + + return txt; + } + + /** + * Returns the font for the text run for which this <code>GlyphView</code> + * is responsible. + * + * @return the font for the text run for which this <code>GlyphView</code> + * is responsible + */ + public Font getFont() + { + Element el = getElement(); + AttributeSet atts = el.getAttributes(); + String family = StyleConstants.getFontFamily(atts); + int size = StyleConstants.getFontSize(atts); + int style = Font.PLAIN; + if (StyleConstants.isBold(atts)) + style |= Font.BOLD; + if (StyleConstants.isItalic(atts)) + style |= Font.ITALIC; + Font font = new Font(family, style, size); + return font; + } + + /** + * Returns the foreground color which should be used to paint the text. + * This is fetched from the associated element's text attributes using + * {@link StyleConstants#getForeground}. + * + * @return the foreground color which should be used to paint the text + */ + public Color getForeground() + { + Element el = getElement(); + AttributeSet atts = el.getAttributes(); + return StyleConstants.getForeground(atts); + } +} diff --git a/libjava/classpath/javax/swing/text/IconView.java b/libjava/classpath/javax/swing/text/IconView.java new file mode 100644 index 0000000..c7e22b6 --- /dev/null +++ b/libjava/classpath/javax/swing/text/IconView.java @@ -0,0 +1,128 @@ +/* IconView.java -- A view to render icons + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package javax.swing.text; + +import java.awt.Graphics; +import java.awt.Shape; + +// TODO: Implement this class. +public class IconView + extends View +{ + + /** + * Creates a new <code>IconView</code> for the given <code>Element</code>. + * + * @param element the element that is rendered by this IconView + */ + public IconView(Element element) + { + super(element); + } + + /** + * Renders the <code>Element</code> that is associated with this + * <code>View</code>. + * + * @param g the <code>Graphics</code> context to render to + * @param a the allocated region for the <code>Element</code> + */ + public void paint(Graphics g, Shape a) + { + // TODO: Implement me. + } + + /** + * Returns the preferred span of the content managed by this + * <code>View</code> along the specified <code>axis</code>. + * + * @param axis the axis + * + * @return the preferred span of this <code>View</code>. + */ + public float getPreferredSpan(int axis) + { + // TODO: Implement me. + return 0F; + } + + /** + * Maps a position in the document into the coordinate space of the View. + * The output rectangle usually reflects the font height but has a width + * of zero. + * + * @param pos the position of the character in the model + * @param a the area that is occupied by the view + * @param b either {@link Position.Bias#Forward} or + * {@link Position.Bias#Backward} depending on the preferred + * direction bias. If <code>null</code> this defaults to + * <code>Position.Bias.Forward</code> + * + * @return a rectangle that gives the location of the document position + * inside the view coordinate space + * + * @throws BadLocationException if <code>pos</code> is invalid + * @throws IllegalArgumentException if b is not one of the above listed + * valid values + */ + public Shape modelToView(int pos, Shape a, Position.Bias b) + throws BadLocationException + { + // Implement me. + return null; + } + + /** + * Maps coordinates from the <code>View</code>'s space into a position + * in the document model. + * + * @param x the x coordinate in the view space + * @param y the y coordinate in the view space + * @param a the allocation of this <code>View</code> + * @param b the bias to use + * + * @return the position in the document that corresponds to the screen + * coordinates <code>x, y</code> + */ + public int viewToModel(float x, float y, Shape a, Position.Bias[] b) + { + // FIXME: not implemented + return 0; + } +} diff --git a/libjava/classpath/javax/swing/text/LabelView.java b/libjava/classpath/javax/swing/text/LabelView.java new file mode 100644 index 0000000..a103916 --- /dev/null +++ b/libjava/classpath/javax/swing/text/LabelView.java @@ -0,0 +1,54 @@ +/* LabelView.java -- A view to render styled text + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package javax.swing.text; + +// TODO: Implement this class. +public class LabelView + extends GlyphView +{ + /** + * Creates a new <code>GlyphView</code> for the given <code>Element</code>. + * + * @param element the element that is rendered by this GlyphView + */ + public LabelView(Element element) + { + super(element); + } +} diff --git a/libjava/classpath/javax/swing/text/LayoutQueue.java b/libjava/classpath/javax/swing/text/LayoutQueue.java new file mode 100644 index 0000000..83433b6 --- /dev/null +++ b/libjava/classpath/javax/swing/text/LayoutQueue.java @@ -0,0 +1,115 @@ +/* LayoutQueue.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package javax.swing.text; + +import java.util.LinkedList; + +/** + * This is a queue which holds {@link Runnable} objects. It is + * intended for deferring layout operations. + */ +public class LayoutQueue +{ + // The default layout queue. + private static LayoutQueue defaultQueue = new LayoutQueue(); + + // The queue of tasks. + private LinkedList list = new LinkedList(); + + /** + * Create a new layout queue. + */ + public LayoutQueue() + { + } + + /** + * Add a layout task to the queue. + */ + public void addTask(Runnable task) + { + synchronized (list) + { + list.addLast(task); + list.notify(); + } + } + + /** + * Called by a worker thread to retrieve the next layout task. This + * will block until a new task is available. This method will + * return null if the thread is interrupted while waiting. + */ + protected Runnable waitForWork() + { + synchronized (list) + { + while (list.size() == 0) + { + try + { + list.wait(); + } + catch (InterruptedException _) + { + // This seemed like a good idea, but it has not been + // tested on the JDK. + return null; + } + } + return (Runnable) list.removeFirst(); + } + } + + /** + * Return the default layout queue. + */ + public static synchronized LayoutQueue getDefaultQueue() + { + return defaultQueue; + } + + /** + * Set the default layout queue. + */ + public static synchronized void setDefaultQueue(LayoutQueue q) + { + defaultQueue = q; + } +} diff --git a/libjava/classpath/javax/swing/text/ParagraphView.java b/libjava/classpath/javax/swing/text/ParagraphView.java new file mode 100644 index 0000000..6c6006a --- /dev/null +++ b/libjava/classpath/javax/swing/text/ParagraphView.java @@ -0,0 +1,89 @@ +/* ParagraphView.java -- A composite View + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package javax.swing.text; + +/** + * A {@link FlowView} that flows it's children horizontally and boxes the rows + * vertically. + * + * @author Roman Kennke (roman@kennke.org) + */ +public class ParagraphView extends FlowView implements TabExpander +{ + /** + * A specialized horizontal <code>BoxView</code> that represents exactly + * one row in a <code>ParagraphView</code>. + */ + class Row extends BoxView + { + /** + * Creates a new instance of <code>Row</code>. + */ + Row(Element el) + { + super(el, X_AXIS); + } + } + + /** + * Creates a new <code>ParagraphView</code> for the given + * <code>Element</code>. + * + * @param element the element that is rendered by this ParagraphView + */ + public ParagraphView(Element element) + { + super(element, Y_AXIS); + } + + public float nextTabStop(float x, int tabOffset) + { + throw new InternalError("Not implemented yet"); + } + + /** + * Creates a new view that represents a row within a flow. + * + * @return a view for a new row + */ + protected View createRow() + { + return new Row(getElement()); + } +} diff --git a/libjava/classpath/javax/xml/stream/EventFilter.java b/libjava/classpath/javax/xml/stream/EventFilter.java new file mode 100644 index 0000000..288c741 --- /dev/null +++ b/libjava/classpath/javax/xml/stream/EventFilter.java @@ -0,0 +1,55 @@ +/* EventFilter.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.xml.stream; + +import javax.xml.stream.events.XMLEvent; + +/** + * Simple filter interface for XML events. + */ +public interface EventFilter + extends XMLFilter +{ + + /** + * Indicates whether this filter can accept the specified event. + */ + boolean accept(XMLEvent event); + +} + diff --git a/libjava/classpath/javax/xml/stream/FactoryConfigurationError.java b/libjava/classpath/javax/xml/stream/FactoryConfigurationError.java new file mode 100644 index 0000000..d04e71a --- /dev/null +++ b/libjava/classpath/javax/xml/stream/FactoryConfigurationError.java @@ -0,0 +1,86 @@ +/* FactoryConfigurationError.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.xml.stream; + +/** + * Error indicating that a factory could not be configured. + */ +public class FactoryConfigurationError + extends Error +{ + + private final Exception exception; + + public FactoryConfigurationError() + { + this((String) null, (Exception) null); + } + + public FactoryConfigurationError(Exception e) + { + this(e, null); + } + + public FactoryConfigurationError(Exception e, String msg) + { + super(msg); + exception = e; + } + + public FactoryConfigurationError(String msg, Exception e) + { + this(e, msg); + } + + public FactoryConfigurationError(String msg) + { + this(null, msg); + } + + public Exception getException() + { + return exception; + } + + public String getMessage() + { + return super.getMessage(); + } + +} + diff --git a/libjava/classpath/javax/xml/stream/Location.java b/libjava/classpath/javax/xml/stream/Location.java new file mode 100644 index 0000000..d043ba2 --- /dev/null +++ b/libjava/classpath/javax/xml/stream/Location.java @@ -0,0 +1,71 @@ +/* Location.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.xml.stream; + +/** + * Information about the location of an XML event within the underlying + * stream. + */ +public interface Location +{ + + /** + * Returns the line number at which the current event ends, + * or -1 if this is not available. + */ + int getLineNumber(); + + /** + * Returns the column number at which the current event ends, + * or -1 if this is not available. + */ + int getColumnNumber(); + + /** + * Returns the offset from the start of the source, in bytes or characters + * depending on the nature of the source, or -1 if this is not available. + */ + int getCharacterOffset(); + + /** + * Returns the system identifier for the underlying source. + */ + String getLocationURI(); + +} + diff --git a/libjava/classpath/javax/xml/stream/StreamFilter.java b/libjava/classpath/javax/xml/stream/StreamFilter.java new file mode 100644 index 0000000..77fbfc7 --- /dev/null +++ b/libjava/classpath/javax/xml/stream/StreamFilter.java @@ -0,0 +1,54 @@ +/* StreamFilter.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.xml.stream; + +/** + * Simple filter interface for XMLStreamReaders. + */ +public interface StreamFilter + extends XMLFilter +{ + + /** + * Indicates whether the current state of the specified reader in part of + * this stream. + */ + boolean accept(XMLStreamReader reader); + +} + diff --git a/libjava/classpath/javax/xml/stream/XMLEventFactory.java b/libjava/classpath/javax/xml/stream/XMLEventFactory.java new file mode 100644 index 0000000..456414d --- /dev/null +++ b/libjava/classpath/javax/xml/stream/XMLEventFactory.java @@ -0,0 +1,345 @@ +/* XMLEventFactory.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.xml.stream; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.IOException; +import java.io.Reader; +import java.util.Iterator; +import java.util.Properties; +import javax.xml.namespace.NamespaceContext; +import javax.xml.namespace.QName; +import javax.xml.stream.events.Attribute; +import javax.xml.stream.events.Characters; +import javax.xml.stream.events.Comment; +import javax.xml.stream.events.DTD; +import javax.xml.stream.events.EndDocument; +import javax.xml.stream.events.EndElement; +import javax.xml.stream.events.EntityDeclaration; +import javax.xml.stream.events.EntityReference; +import javax.xml.stream.events.Namespace; +import javax.xml.stream.events.ProcessingInstruction; +import javax.xml.stream.events.StartDocument; +import javax.xml.stream.events.StartElement; + +/** + * Factory for XML events. + */ +public abstract class XMLEventFactory +{ + + protected XMLEventFactory() + { + } + + /** + * Create a new factory instance. + * @see #newInstance(String,ClassLoader) + */ + public static XMLEventFactory newInstance() + throws FactoryConfigurationError + { + return newInstance(null, null); + } + + /** + * Create a new factory instance. + * The implementation class to load is the first found in the following + * locations: + * <ol> + * <li>the <code>javax.xml.stream.XMLEventFactory</code> system + * property</li> + * <li>the above named property value in the + * <code><i>$JAVA_HOME</i>/lib/stax.properties</code> file</li> + * <li>the class name specified in the + * <code>META-INF/services/javax.xml.stream.XMLEventFactory</code> + * system resource</li> + * <li>the default factory class</li> + * </ol> + */ + static XMLEventFactory newInstance(String factoryId, ClassLoader classLoader) + throws FactoryConfigurationError + { + ClassLoader loader = classLoader; + if (loader == null) + { + loader = Thread.currentThread().getContextClassLoader(); + } + if (loader == null) + { + loader = XMLEventFactory.class.getClassLoader(); + } + String className = null; + int count = 0; + do + { + className = getFactoryClassName(loader, count++); + if (className != null) + { + try + { + Class t = (loader != null) ? loader.loadClass(className) : + Class.forName(className); + return (XMLEventFactory) t.newInstance(); + } + catch (ClassNotFoundException e) + { + className = null; + } + catch (Exception e) + { + throw new FactoryConfigurationError(e, + "error instantiating class " + className); + } + } + } + while (className == null && count < 3); + return new gnu.xml.stream.XMLEventFactoryImpl(); + } + + private static String getFactoryClassName(ClassLoader loader, int attempt) + { + final String propertyName = "javax.xml.stream.XMLEventFactory"; + switch (attempt) + { + case 0: + return System.getProperty(propertyName); + case 1: + try + { + File file = new File(System.getProperty("java.home")); + file = new File(file, "lib"); + file = new File(file, "stax.properties"); + InputStream in = new FileInputStream(file); + Properties props = new Properties(); + props.load(in); + in.close(); + return props.getProperty(propertyName); + } + catch (IOException e) + { + return null; + } + case 2: + try + { + String serviceKey = "/META-INF/services/" + propertyName; + InputStream in = (loader != null) ? + loader.getResourceAsStream(serviceKey) : + XMLEventFactory.class.getResourceAsStream(serviceKey); + if (in != null) + { + BufferedReader r = + new BufferedReader(new InputStreamReader(in)); + String ret = r.readLine(); + r.close(); + return ret; + } + } + catch (IOException e) + { + } + return null; + default: + return null; + } + } + + /** + * Sets the location for each event created by this factory. + */ + public abstract void setLocation(Location location); + + /** + * Create an attribute event. + */ + public abstract Attribute createAttribute(String prefix, String namespaceURI, + String localName, String value); + + /** + * Create an attribute event. + */ + public abstract Attribute createAttribute(String localName, String value); + + /** + * Create an attribute event. + */ + public abstract Attribute createAttribute(QName name, String value); + + /** + * Create a namespace declaration event. + */ + public abstract Namespace createNamespace(String namespaceURI); + + /** + * Create a namespace declaration event. + */ + public abstract Namespace createNamespace(String prefix, String namespaceUri); + + /** + * Create a start-element event. + */ + public abstract StartElement createStartElement(QName name, + Iterator attributes, + Iterator namespaces); + + /** + * Create a start-element event. + */ + public abstract StartElement createStartElement(String prefix, + String namespaceUri, + String localName); + + /** + * Create a start-element event. + */ + public abstract StartElement createStartElement(String prefix, + String namespaceUri, + String localName, + Iterator attributes, + Iterator namespaces); + + /** + * Create a start-element event. + */ + public abstract StartElement createStartElement(String prefix, + String namespaceUri, + String localName, + Iterator attributes, + Iterator namespaces, + NamespaceContext context); + + /** + * Create an end-element event. + */ + public abstract EndElement createEndElement(QName name, + Iterator namespaces); + + /** + * Create an end-element event. + */ + public abstract EndElement createEndElement(String prefix, + String namespaceUri, + String localName); + + /** + * Create an end-element event. + */ + public abstract EndElement createEndElement(String prefix, + String namespaceUri, + String localName, + Iterator namespaces); + + /** + * Create a text event. + */ + public abstract Characters createCharacters(String content); + + /** + * Create a text event of type CDATA section. + */ + public abstract Characters createCData(String content); + + /** + * Create a text event of type whitespace. + */ + public abstract Characters createSpace(String content); + + /** + * Create a text event of type ignorable whitespace. + */ + public abstract Characters createIgnorableSpace(String content); + + /** + * Create a start-document event. + */ + public abstract StartDocument createStartDocument(); + + /** + * Create a start-document event. + */ + public abstract StartDocument createStartDocument(String encoding, + String version, + boolean standalone); + + /** + * Create a start-document event. + */ + public abstract StartDocument createStartDocument(String encoding, + String version); + + /** + * Create a start-document event. + */ + public abstract StartDocument createStartDocument(String encoding); + + /** + * Create an end-document event. + */ + public abstract EndDocument createEndDocument(); + + /** + * Create an entity reference event. + */ + //public abstract EntityReference createEntityReference(String name, + // EntityDeclaration declaration); + public abstract EntityReference createEntityReference(String name, + String replacementText); + + /** + * Create a comment event. + */ + public abstract Comment createComment(String text); + + /** + * Create a processing instruction event. + */ + public abstract ProcessingInstruction createProcessingInstruction(String target, + String data); + + /** + * Create a DOCTYPE declaration event. + */ + public abstract DTD createDTD(String dtd); + +} + diff --git a/libjava/classpath/javax/xml/stream/XMLEventReader.java b/libjava/classpath/javax/xml/stream/XMLEventReader.java new file mode 100644 index 0000000..5d4c170 --- /dev/null +++ b/libjava/classpath/javax/xml/stream/XMLEventReader.java @@ -0,0 +1,84 @@ +/* XMLEventReader.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.xml.stream; + +import java.util.Iterator; +import javax.xml.stream.events.XMLEvent; + +/** + * An XML parser. + */ +public interface XMLEventReader + extends XMLIterator +{ + + /** + * Looks at the next XML event without advancing the cursor in the stream. + * Returns <code>null</code> if there are no more events to read. + */ + XMLEvent peek() + throws XMLStreamException; + + /** + * Reads the text context of an element. + * When invoked, the current event must be START_ELEMENT. + * On completion, the current event will be END_ELEMENT. + */ + String getElementText() + throws XMLStreamException; + + /** + * Returns the next element event. + * This method skips insignificant space until a START_ELEMENT or + * END_ELEMENT event is found. + * @exception XMLStreamException if an event that was not an insignificant + * space event was encountered + */ + XMLEvent nextTag() + throws XMLStreamException; + + /** + * Returns the implementation-specific feature or property of the given + * name. + * @exception IllegalArgumentException if the property is not supported + */ + Object getProperty(String name) + throws IllegalArgumentException; + +} + diff --git a/libjava/classpath/javax/xml/stream/XMLEventWriter.java b/libjava/classpath/javax/xml/stream/XMLEventWriter.java new file mode 100644 index 0000000..60b18f9 --- /dev/null +++ b/libjava/classpath/javax/xml/stream/XMLEventWriter.java @@ -0,0 +1,109 @@ +/* XMLEventWriter.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.xml.stream; + +import javax.xml.namespace.NamespaceContext; +import javax.xml.stream.events.XMLEvent; +import javax.xml.stream.util.XMLEventConsumer; + +/** + * Interface for writing XML documents from a series of events. + */ +public interface XMLEventWriter + extends XMLEventConsumer +{ + + /** + * Ensures that any cached events are written to the underlying output + * sink. + */ + void flush() + throws XMLStreamException; + + /** + * Frees any resources used by this writer. + */ + void close() + throws XMLStreamException; + + /** + * Adds the specified event to this writer. + */ + void add(XMLEvent event) + throws XMLStreamException; + + /** + * Adds the specified XML stream to this writer. + * The implementation will call <code>next</code> on the given argument + * while <code>hasNext</code> returns true. + */ + void add(XMLEventReader reader) + throws XMLStreamException; + + /** + * Returns the namespace prefix the specified URI is currently associated + * with. + */ + String getPrefix(String uri) + throws XMLStreamException; + + /** + * Associates the given namespace prefix and URI. + */ + void setPrefix(String prefix, String uri) + throws XMLStreamException; + + /** + * Sets the current default namespace URI. + */ + void setDefaultNamespace(String uri) + throws XMLStreamException; + + /** + * Sets the namespace context for managing namespace prefixes and URIs. + */ + void setNamespaceContext(NamespaceContext context) + throws XMLStreamException; + + /** + * Returns the namespace context. + */ + NamespaceContext getNamespaceContext(); + +} + diff --git a/libjava/classpath/javax/xml/stream/XMLFilter.java b/libjava/classpath/javax/xml/stream/XMLFilter.java new file mode 100644 index 0000000..7e7698d --- /dev/null +++ b/libjava/classpath/javax/xml/stream/XMLFilter.java @@ -0,0 +1,46 @@ +/* XMLFilter.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.xml.stream; + +/** + * Marker interface for stream and event filters. + */ +public interface XMLFilter +{ +} + diff --git a/libjava/classpath/javax/xml/stream/XMLInputFactory.java b/libjava/classpath/javax/xml/stream/XMLInputFactory.java new file mode 100644 index 0000000..4c904a6 --- /dev/null +++ b/libjava/classpath/javax/xml/stream/XMLInputFactory.java @@ -0,0 +1,458 @@ +/* XMLInputFactory.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.xml.stream; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.IOException; +import java.io.Reader; +import java.io.Writer; +import java.util.Properties; +import javax.xml.stream.util.XMLEventAllocator; +import javax.xml.transform.Source; + +/** + * Factory for creating stream and event readers from various kinds of input + * source. + * <h3>Parameters</h3> + * <table> + * <tr> + * <th>Name</th> + * <th>Description</th> + * <th>Type</th> + * <th>Default</th> + * <th>Required</th> + * </tr> + * <tr> + * <td>javax.xml.stream.isValidating</td> + * <td>Controls DTD validation</td> + * <td>Boolean</td> + * <td>Boolean.FALSE</td> + * <td>no</td> + * </tr> + * <tr> + * <td>javax.xml.stream.isNamespaceAware</td> + * <td>Controls namespace processing for XML 1.0</td> + * <td>Boolean</td> + * <td>Boolean.TRUE</td> + * <td>true is required, false is optional</td> + * </tr> + * <tr> + * <td>javax.xml.stream.isCoalescing</td> + * <td>Controls coalescing (normalization of adjacent character data)</td> + * <td>Boolean</td> + * <td>Boolean.FALSE</td> + * <td>yes</td> + * </tr> + * <tr> + * <td>javax.xml.stream.isReplacingEntityReferences</td> + * <td>Controls replacement of entity references with their replacement + * text</td> + * <td>Boolean</td> + * <td>Boolean.TRUE</td> + * <td>yes</td> + * </tr> + * <tr> + * <td>javax.xml.stream.isSupportingExternalEntities</td> + * <td>Controls whether to resolve external entities</td> + * <td>Boolean</td> + * <td>not specified</td> + * <td>yes</td> + * </tr> + * <tr> + * <td>javax.xml.stream.supportDTD</td> + * <td>Controls whether to support DTDs</td> + * <td>Boolean</td> + * <td>Boolean.TRUE</td> + * <td>yes</td> + * </tr> + * <tr> + * <td>javax.xml.stream.reporter</td> + * <td></td> + * <td>javax.xml.stream.XMLReporter</td> + * <td></td> + * <td>yes</td> + * </tr> + * <tr> + * <td>javax.xml.stream.resolver</td> + * <td></td> + * <td>javax.xml.stream.XMLResolver</td> + * <td></td> + * <td>yes</td> + * </tr> + * <tr> + * <td>javax.xml.stream.allocator</td> + * <td></td> + * <td>javax.xml.stream.util.XMLEventAllocator</td> + * <td></td> + * <td>yes</td> + * </tr> + * </table> + */ +public abstract class XMLInputFactory +{ + + /** + * Property used to control namespace support. + */ + public static final String IS_NAMESPACE_AWARE = + "javax.xml.stream.isNamespaceAware"; + + /** + * Property used to control DTD validation. + */ + public static final String IS_VALIDATING = "javax.xml.stream.isValidating"; + + /** + * Property used to control whether to coalesce adjacent text events. + */ + public static final String IS_COALESCING = "javax.xml.stream.isCoalescing"; + + /** + * Property used to control whether to replace entity references with + * their replacement text. + */ + public static final String IS_REPLACING_ENTITY_REFERENCES = + "javax.xml.stream.isReplacingEntityReferences"; + + /** + * Property used to control whether to resolve external entities. + */ + public static final String IS_SUPPORTING_EXTERNAL_ENTITIES = + "javax.xml.stream.isSupportingExternalEntities"; + + /** + * Property used to indicate whether to support DTDs. + */ + public static final String SUPPORT_DTD = "javax.xml.stream.supportDTD"; + + /** + * Property used to control the error reporter implementation. + */ + public static final String REPORTER = "javax.xml.stream.reporter"; + + /** + * Property used to control the entity resolver implementation. + */ + public static final String RESOLVER = "javax.xml.stream.resolver"; + + /** + * Property used to control the event allocator implementation. + */ + public static final String ALLOCATOR = "javax.xml.stream.allocator"; + + protected XMLInputFactory() + { + } + + /** + * Creates a new factory instance. + * @see #newInstance(String,ClassLoader) + */ + public static XMLInputFactory newInstance() + throws FactoryConfigurationError + { + return newInstance(null, null); + } + + /** + * Creates a new factory instance. + * The implementation class to load is the first found in the following + * locations: + * <ol> + * <li>the <code>javax.xml.stream.XMLInputFactory</code> system + * property</li> + * <li>the above named property value in the + * <code><i>$JAVA_HOME</i>/lib/stax.properties</code> file</li> + * <li>the class name specified in the + * <code>META-INF/services/javax.xml.stream.XMLInputFactory</code> + * system resource</li> + * <li>the default factory class</li> + * </ol> + */ + public static XMLInputFactory newInstance(String factoryId, + ClassLoader classLoader) + throws FactoryConfigurationError + { + ClassLoader loader = classLoader; + if (loader == null) + { + loader = Thread.currentThread().getContextClassLoader(); + } + if (loader == null) + { + loader = XMLInputFactory.class.getClassLoader(); + } + String className = null; + int count = 0; + do + { + className = getFactoryClassName(loader, count++); + if (className != null) + { + try + { + Class t = (loader != null) ? loader.loadClass(className) : + Class.forName(className); + return (XMLInputFactory) t.newInstance(); + } + catch (ClassNotFoundException e) + { + className = null; + } + catch (Exception e) + { + throw new FactoryConfigurationError(e, + "error instantiating class " + className); + } + } + } + while (className == null && count < 3); + return new gnu.xml.stream.XMLInputFactoryImpl(); + } + + private static String getFactoryClassName(ClassLoader loader, int attempt) + { + final String propertyName = "javax.xml.stream.XMLInputFactory"; + switch (attempt) + { + case 0: + return System.getProperty(propertyName); + case 1: + try + { + File file = new File(System.getProperty("java.home")); + file = new File(file, "lib"); + file = new File(file, "stax.properties"); + InputStream in = new FileInputStream(file); + Properties props = new Properties(); + props.load(in); + in.close(); + return props.getProperty(propertyName); + } + catch (IOException e) + { + return null; + } + case 2: + try + { + String serviceKey = "/META-INF/services/" + propertyName; + InputStream in = (loader != null) ? + loader.getResourceAsStream(serviceKey) : + XMLInputFactory.class.getResourceAsStream(serviceKey); + if (in != null) + { + BufferedReader r = + new BufferedReader(new InputStreamReader(in)); + String ret = r.readLine(); + r.close(); + return ret; + } + } + catch (IOException e) + { + } + return null; + default: + return null; + } + } + + /** + * Creates a new stream reader. + */ + public abstract XMLStreamReader createXMLStreamReader(Reader reader) + throws XMLStreamException; + + /** + * Creates a new stream reader. + */ + public abstract XMLStreamReader createXMLStreamReader(Source source) + throws XMLStreamException; + + /** + * Creates a new stream reader. + */ + public abstract XMLStreamReader createXMLStreamReader(InputStream stream) + throws XMLStreamException; + + /** + * Creates a new stream reader. + */ + public abstract XMLStreamReader createXMLStreamReader(InputStream stream, + String encoding) + throws XMLStreamException; + + /** + * Creates a new stream reader. + * + public abstract XMLStreamReader createXMLStreamReader(String systemId, + InputStream stream) + throws XMLStreamException;*/ + + /** + * Creates a new stream reader. + * + public abstract XMLStreamReader createXMLStreamReader(String systemId, + Reader reader) + throws XMLStreamException;*/ + + /** + * Creates a new event reader. + */ + public abstract XMLEventReader createXMLEventReader(Reader reader) + throws XMLStreamException; + + /** + * Creates a new event reader. + * + public abstract XMLEventReader createXMLEventReader(String systemId, + Reader reader) + throws XMLStreamException;*/ + + /** + * Creates a new event reader. + */ + public abstract XMLEventReader createXMLEventReader(XMLStreamReader reader) + throws XMLStreamException; + + /** + * Creates a new event reader. + */ + public abstract XMLEventReader createXMLEventReader(Source source) + throws XMLStreamException; + + /** + * Creates a new event reader. + */ + public abstract XMLEventReader createXMLEventReader(InputStream stream) + throws XMLStreamException; + + /** + * Creates a new event reader. + */ + public abstract XMLEventReader createXMLEventReader(InputStream stream, + String encoding) + throws XMLStreamException; + + /** + * Creates a new event reader. + * + public abstract XMLEventReader createXMLEventReader(String systemId, + InputStream stream) + throws XMLStreamException;*/ + + /** + * Create a new filtered reader. + */ + public abstract XMLStreamReader createFilteredReader(XMLStreamReader reader, + StreamFilter filter) + throws XMLStreamException; + + /** + * Create a new filtered reader. + */ + public abstract XMLEventReader createFilteredReader(XMLEventReader reader, + EventFilter filter) + throws XMLStreamException; + + /** + * Returns the entity resolver. + */ + public abstract XMLResolver getXMLResolver(); + + /** + * Sets the entity resolver. + */ + public abstract void setXMLResolver(XMLResolver resolver); + + /** + * Returns the error reporter. + */ + public abstract XMLReporter getXMLReporter(); + + /** + * Sets the error reporter. + */ + public abstract void setXMLReporter(XMLReporter reporter); + + /** + * Sets the implementation-specific property of the given name. + * @exception IllegalArgumentException if the property is not supported + */ + public abstract void setProperty(String name, Object value) + throws IllegalArgumentException; + + /** + * Returns the implementation-specific property of the given name. + * @exception IllegalArgumentException if the property is not supported + */ + public abstract Object getProperty(String name) + throws IllegalArgumentException; + + /** + * Indicates whether the specified property is supported. + */ + public abstract boolean isPropertySupported(String name); + + /** + * Sets the event allocator. + */ + public abstract void setEventAllocator(XMLEventAllocator allocator); + + /** + * Returns the event allocator. + */ + public abstract XMLEventAllocator getEventAllocator(); + + /** + * Sets whether text will be coalesced. + */ + public abstract void setCoalescing(boolean coalescing); + + /** + * Indicates whether text will be coalesced. + */ + public abstract boolean isCoalescing(); + +} + diff --git a/libjava/classpath/javax/xml/stream/XMLIterator.java b/libjava/classpath/javax/xml/stream/XMLIterator.java new file mode 100644 index 0000000..e12bffa --- /dev/null +++ b/libjava/classpath/javax/xml/stream/XMLIterator.java @@ -0,0 +1,61 @@ +/* XMLIterator.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.xml.stream; + +import javax.xml.stream.events.XMLEvent; + +/** + * Simple iterator for XML events. + */ +public interface XMLIterator +{ + + /** + * Returns the next XML event. + */ + XMLEvent next() + throws XMLStreamException; + + /** + * Indicates whether there are more XML events to be read. + */ + boolean hasNext() + throws XMLStreamException; + +} + diff --git a/libjava/classpath/javax/xml/stream/XMLOutputFactory.java b/libjava/classpath/javax/xml/stream/XMLOutputFactory.java new file mode 100644 index 0000000..cf31f02 --- /dev/null +++ b/libjava/classpath/javax/xml/stream/XMLOutputFactory.java @@ -0,0 +1,286 @@ +/* XMLOutputFactory.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.xml.stream; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.IOException; +import java.io.OutputStream; +import java.io.Writer; +import java.util.Properties; +//import javax.xml.transform.Result; + +/** + * Factory for obtaining XML stream and event writers for various kinds of + * output sink. + * <h3>Configuration</h3> + * <table> + * <tr> + * <th>Name</th> + * <th>Description</th> + * <th>Type</th> + * <th>Default</th> + * <th>Required</th> + * </tr> + * <tr> + * <td>javax.xml.stream.isRepairingNamespaces</td> + * <td>default namespace prefixes</td> + * <td>Boolean</td> + * <td>Boolean.FALSE</td> + * <td>yes</td> + * </tr> + * </table> + */ +public abstract class XMLOutputFactory +{ + + /** + * Property used to control whether to default namespace prefixes. + * If true, the writer will create a namespace declaration for any + * attribute that doesn't have a namespace declaration in scope. + */ + public static final java.lang.String IS_PREFIX_DEFAULTING = + "javax.xml.stream.isPrefixDefaulting"; + + protected XMLOutputFactory() + { + } + + /** + * Creates a new <b>output</b> factory. + * The implementation class to load is the first found in the following + * locations: + * <ol> + * <li>the <code>javax.xml.stream.XMLOutputFactory</code> system + * property</li> + * <li>the above named property value in the + * <code><i>$JAVA_HOME</i>/lib/stax.properties</code> file</li> + * <li>the class name specified in the + * <code>META-INF/services/javax.xml.stream.XMLOutputFactory</code> + * system resource</li> + * <li>the default factory class</li> + * </ol> + */ + public static XMLOutputFactory newInstance() + throws FactoryConfigurationError + { + ClassLoader loader = Thread.currentThread().getContextClassLoader(); + if (loader == null) + { + loader = XMLOutputFactory.class.getClassLoader(); + } + String className = null; + int count = 0; + do + { + className = getFactoryClassName(loader, count++); + if (className != null) + { + try + { + Class t = (loader != null) ? loader.loadClass(className) : + Class.forName(className); + return (XMLOutputFactory) t.newInstance(); + } + catch (ClassNotFoundException e) + { + className = null; + } + catch (Exception e) + { + throw new FactoryConfigurationError(e, + "error instantiating class " + className); + } + } + } + while (className == null && count < 3); + return new gnu.xml.stream.XMLOutputFactoryImpl(); + } + + private static String getFactoryClassName(ClassLoader loader, int attempt) + { + final String propertyName = "javax.xml.stream.XMLOutputFactory"; + switch (attempt) + { + case 0: + return System.getProperty(propertyName); + case 1: + try + { + File file = new File(System.getProperty("java.home")); + file = new File(file, "lib"); + file = new File(file, "stax.properties"); + InputStream in = new FileInputStream(file); + Properties props = new Properties(); + props.load(in); + in.close(); + return props.getProperty(propertyName); + } + catch (IOException e) + { + return null; + } + case 2: + try + { + String serviceKey = "/META-INF/services/" + propertyName; + InputStream in = (loader != null) ? + loader.getResourceAsStream(serviceKey) : + XMLOutputFactory.class.getResourceAsStream(serviceKey); + if (in != null) + { + BufferedReader r = + new BufferedReader(new InputStreamReader(in)); + String ret = r.readLine(); + r.close(); + return ret; + } + } + catch (IOException e) + { + } + return null; + default: + return null; + } + } + + /** + * Creates a new <b>input</b> factory. + * This appears to be an API design bug. + * @see javax.xml.stream.XMLInputFactory.newInstance(String,ClassLoader) + */ + public static XMLInputFactory newInstance(String factoryId, + ClassLoader classLoader) + throws FactoryConfigurationError + { + return XMLInputFactory.newInstance(factoryId, classLoader); + } + + /** + * Creates a new stream writer. + */ + public abstract XMLStreamWriter createXMLStreamWriter(Writer stream) + throws XMLStreamException; + + /** + * Creates a new stream writer. + */ + public abstract XMLStreamWriter createXMLStreamWriter(OutputStream stream) + throws XMLStreamException; + + /** + * Creates a new stream writer. + */ + public abstract XMLStreamWriter createXMLStreamWriter(OutputStream stream, + String encoding) + throws XMLStreamException; + + /** + * Creates a new stream writer. + * @exception UnsupportedOperationException if this method is not + * supported + */ + //public abstract XMLStreamWriter createXMLStreamWriter(Result result) + // throws XMLStreamException; + + /** + * Creates a new event writer. + * @exception UnsupportedOperationException if this method is not + * supported + */ + //public abstract XMLEventWriter createXMLEventWriter(Result result) + // throws XMLStreamException; + + /** + * Creates a new event writer. + */ + public abstract XMLEventWriter createXMLEventWriter(OutputStream stream) + throws XMLStreamException; + + /** + * Creates a new event writer. + */ + public abstract XMLEventWriter createXMLEventWriter(OutputStream stream, + String encoding) + throws XMLStreamException; + + /** + * Creates a new event writer. + */ + public abstract XMLEventWriter createXMLEventWriter(Writer stream) + throws XMLStreamException; + + /** + * Sets the implementation-specific property of the given name. + * @exception IllegalArgumentException if the property is not supported + */ + public abstract void setProperty(String name, Object value) + throws IllegalArgumentException; + + /** + * Returns the implementation-specific property of the given name. + * @exception IllegalArgumentException if the property is not supported + */ + public abstract Object getProperty(String name) + throws IllegalArgumentException; + + /** + * Indicates whether writers created by this factory will perform prefix + * defaulting. + * @see #IS_PREFIX_DEFAULTING + */ + public abstract boolean isPrefixDefaulting(); + + /** + * Indicates whether the specified property is supported. + */ + public abstract boolean isPropertySupported(String name); + + /** + * Sets whether writers created by this factory will perform prefix + * defaulting. + * @see #IS_PREFIX_DEFAULTING + */ + public abstract void setPrefixDefaulting(boolean value); + +} + diff --git a/libjava/classpath/javax/xml/stream/XMLReporter.java b/libjava/classpath/javax/xml/stream/XMLReporter.java new file mode 100644 index 0000000..bdf0b8a --- /dev/null +++ b/libjava/classpath/javax/xml/stream/XMLReporter.java @@ -0,0 +1,58 @@ +/* XMLReporter.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.xml.stream; + +/** + * Interface used to report non-fatal errors during parsing. + */ +public interface XMLReporter +{ + + /** + * Reports an error. + * @param message the error message + * @param errorType an implementation-specific error type + * @param relatedInformation additional information, if any + * @param location the error location, if available + */ + void report(String message, String errorType, + Object relatedInformation, Location location) + throws XMLStreamException; + +} + diff --git a/libjava/classpath/javax/xml/stream/XMLResolver.java b/libjava/classpath/javax/xml/stream/XMLResolver.java new file mode 100644 index 0000000..148afc6 --- /dev/null +++ b/libjava/classpath/javax/xml/stream/XMLResolver.java @@ -0,0 +1,86 @@ +/* XMLResolver.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.xml.stream; + +import java.io.InputStream; + +/** + * Interface used to resolve XML external entities during parsing. + */ +public interface XMLResolver +{ + + /** + * Returns an input source from which the specified external entity can be + * read. The following return types are possible: + * <ol> + * <li><code>java.io.InputStream</code></li> + * <li><code>javax.xml.stream.XMLStreamReader</code></li> + * <li><code>java.xml.stream.XMLEventReader</code></li> + * </ol> + * If <code>null</code> is returned, the processor will attempt to resolve + * the entity itself. + * @param publicID the public ID of the external entity + * @param systemID the system ID of the external entity + * @param baseURI the absolute base URI of the referring entity + * @param namespace the namespace of the external entity + * + Object resolveEntity(String publicID, String systemID, + String baseURI, String namespace) + throws XMLStreamException;*/ + + /** + * Retrieves a resource from the specified URI. + */ + XMLEventReader resolveAsXMLEventReader(String uri) + throws XMLStreamException; + + /** + * Retrieves a resource from the specified URI. + */ + XMLStreamReader resolveAsXMLStreamReader(String uri) + throws XMLStreamException; + + /** + * Retrieves a resource from the specified URI. + */ + InputStream resolve(String uri) + throws XMLStreamException; + +} + diff --git a/libjava/classpath/javax/xml/stream/XMLStreamConstants.java b/libjava/classpath/javax/xml/stream/XMLStreamConstants.java new file mode 100644 index 0000000..1f0d2ef --- /dev/null +++ b/libjava/classpath/javax/xml/stream/XMLStreamConstants.java @@ -0,0 +1,132 @@ +/* XMLStreamConstants.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.xml.stream; + +/** + * STaX constants. + */ +public interface XMLStreamConstants +{ + + /** + * A start element event. + */ + static final int START_ELEMENT = 1; + + /** + * An end element event. + */ + static final int END_ELEMENT = 2; + + /** + * A processing instruction event. + */ + static final int PROCESSING_INSTRUCTION = 3; + + /** + * A text event. + */ + static final int CHARACTERS = 4; + + /** + * A comment event. + */ + static final int COMMENT = 5; + + /** + * An ignorable whitespace event. + */ + static final int SPACE = 6; + + /** + * A start document event. + */ + static final int START_DOCUMENT = 7; + + /** + * An end document event. + */ + static final int END_DOCUMENT = 8; + + /** + * An entity reference event. + */ + static final int ENTITY_REFERENCE = 9; + + /** + * An attribute event. + */ + static final int ATTRIBUTE = 10; + + /** + * A DOCTYPE declaration event. + */ + static final int DTD = 11; + + /** + * A CDATA section event. + */ + static final int CDATA = 12; + + /** + * A namespace event. + */ + static final int NAMESPACE = 13; + + /** + * A start-entity event. + */ + static final int START_ENTITY = 14; + + /** + * An end-entity event. + */ + static final int END_ENTITY = 15; + + /** + * A notation declaration event. + */ + static final int NOTATION_DECLARATION = 16; + + /** + * An entity declaration event. + */ + static final int ENTITY_DECLARATION = 17; + +} + diff --git a/libjava/classpath/javax/xml/stream/XMLStreamException.java b/libjava/classpath/javax/xml/stream/XMLStreamException.java new file mode 100644 index 0000000..0e91ed7 --- /dev/null +++ b/libjava/classpath/javax/xml/stream/XMLStreamException.java @@ -0,0 +1,99 @@ +/* XMLStreamException.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.xml.stream; + +/** + * Exception indicating an XML stream processing error. + */ +public class XMLStreamException + extends Exception +{ + + protected Location location; + protected Throwable nested; + + public XMLStreamException() + { + this(null, null, null); + } + + public XMLStreamException(String msg) + { + this(msg, null, null); + } + + public XMLStreamException(Throwable th) + { + this(null, null, th); + } + + public XMLStreamException(String msg, Throwable th) + { + this(msg, null, th); + } + + public XMLStreamException(String msg, Location location, Throwable th) + { + super(msg); + this.location = location; + nested = th; + } + + public XMLStreamException(String msg, Location location) + { + this(msg, location, null); + } + + /** + * Returns the nested exception. + */ + public Throwable getNestedException() + { + return nested; + } + + /** + * Returns the location of the exception. + */ + public Location getLocation() + { + return location; + } + +} + diff --git a/libjava/classpath/javax/xml/stream/XMLStreamReader.java b/libjava/classpath/javax/xml/stream/XMLStreamReader.java new file mode 100644 index 0000000..e598fab --- /dev/null +++ b/libjava/classpath/javax/xml/stream/XMLStreamReader.java @@ -0,0 +1,301 @@ +/* XMLStreamReader.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.xml.stream; + +import javax.xml.namespace.NamespaceContext; +import javax.xml.namespace.QName; + +/** + * Interface implemented by an XML parser. + */ +public interface XMLStreamReader + extends XMLStreamConstants +{ + + /** + * Returns the implementation-specific feature or property of the given + * name. + */ + Object getProperty(String name) + throws IllegalArgumentException; + + /** + * Returns the next parsing event. + */ + int next() + throws XMLStreamException; + + /** + * Tests whether the current event is of the given type and namespace. + * @exception XMLStreamException if the test fails + */ + void require(int type, String namespaceURI, String localName) + throws XMLStreamException; + + /** + * Returns the text content of a text-only element. + * When invoked, the current event must be START_ELEMENT. + * On completion, the current event will be END_ELEMENT. + */ + String getElementText() + throws XMLStreamException; + + /** + * Skips any ignorable whitespace, comments, and processing instructions + * until a START_ELEMENT or END_ELEMENT event is encountered. + * @exception XMLStreamException if an event of any other type is + * encountered + */ + int nextTag() + throws XMLStreamException; + + /** + * Indicates whether there are any remaining events to be read. + */ + boolean hasNext() + throws XMLStreamException; + + /** + * Frees any resources used by this parser. + * This method will not close the underlying input source. + */ + void close() + throws XMLStreamException; + + /** + * Returns the namespace URI for the given prefix. + */ + String getNamespaceURI(String prefix); + + /** + * Indicates whether the current event is START_ELEMENT. + */ + boolean isStartElement(); + + /** + * Indicates whether the current event is END_ELEMENT. + */ + boolean isEndElement(); + + /** + * Indicates whether the current event is character data. + */ + boolean isCharacters(); + + /** + * Indicates whether the current event is ignorable whitespace. + */ + boolean isWhiteSpace(); + + /** + * Returns the normalized attribute value for the given attribute. + */ + String getAttributeValue(String namespaceURI, String localName); + + /** + * Returns the number of attributes on this element. + * This method can only be invoked on a START_ELEMENT event. + */ + int getAttributeCount(); + + /** + * Returns the QName of the attribute at the given index. + */ + QName getAttributeQName(int index); + + /** + * Returns the namespace URI of the attribute at the given index. + */ + String getAttributeNamespace(int index); + + /** + * Returns the local-name of the attribute at the given index. + */ + String getAttributeName(int index); + + /** + * Returns the namespace prefix of the attribute at the given index. + */ + String getAttributePrefix(int index); + + /** + * Returns the type of the attribute at the specified index. + */ + String getAttributeType(int index); + + /** + * Returns the normalized value of the attribute at the given index. + */ + String getAttributeValue(int index); + + /** + * Indicates whether the attribute at the given index was specified in the + * underlying XML source or created by default. + */ + boolean isAttributeSpecified(int index); + + /** + * Returns the number of namespaces declared on this event. + * This method is only valid on a START_ELEMENT, END_ELEMENT, or NAMESPACE + * event. + */ + int getNamespaceCount(); + + /** + * Returns the prefix of the namespace at the given index, or null if this + * is the default namespace declaration. + */ + String getNamespacePrefix(int index); + + /** + * Returns the URI of the namespace at the given index. + */ + String getNamespaceURI(int index); + + /** + * Returns the namespace context for the current position. + */ + NamespaceContext getNamespaceContext(); + + /** + * Returns the type of the current event. + */ + int getEventType(); + + /** + * Returns the string value of the current event. + */ + String getText(); + + /** + * Returns the string value of the current event as a character array. + */ + char[] getTextCharacters(); + + /** + * Copies the string value of the current event into the specified + * character array. + */ + int getTextCharacters(int sourceStart, char[] target, + int targetStart, int length) + throws XMLStreamException; + + /** + * Returns the offset of the first character in the text character array. + */ + int getTextStart(); + + /** + * Returns the length of the characters in the text character array. + */ + int getTextLength(); + + /** + * Returns the input encoding. + */ + String getEncoding(); + + /** + * Indicates whether the current event has text. + */ + boolean hasText(); + + /** + * Returns the current location of the parser cursor in the underlying + * input source. + */ + Location getLocation(); + + /** + * Returns the QName of the current element. + * This method is only valid on a START_ELEMENT or END_ELEMENT event. + */ + QName getName(); + + /** + * Returns the local-name of the current element. + */ + String getLocalName(); + + /** + * Indicates whether the current event has a name. + */ + boolean hasName(); + + /** + * Returns the namespace URI of the current element. + */ + String getNamespaceURI(); + + /** + * Returns the namespace prefix of the current element. + */ + String getPrefix(); + + /** + * Returns the XML version declared in the XML declaration. + */ + String getVersion(); + + /** + * Returns the standalone flag declared in the XML declaration. + */ + boolean isStandalone(); + + /** + * Indicates whether the standalone flag was set in the document. + */ + boolean standaloneSet(); + + /** + * Returns the encoding declared in the XML declaration. + */ + String getCharacterEncodingScheme(); + + /** + * Returns the target of the current processing instruction event. + */ + String getPITarget(); + + /** + * Returns the data of the current processing instruction event. + */ + String getPIData(); + +} + diff --git a/libjava/classpath/javax/xml/stream/XMLStreamWriter.java b/libjava/classpath/javax/xml/stream/XMLStreamWriter.java new file mode 100644 index 0000000..5fe9e9f --- /dev/null +++ b/libjava/classpath/javax/xml/stream/XMLStreamWriter.java @@ -0,0 +1,244 @@ +/* XMLStreamWriter.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.xml.stream; + +import javax.xml.namespace.NamespaceContext; + +/** + * Interface for writing XML to a stream. + */ +public interface XMLStreamWriter +{ + + /** + * Write the start of a tag. + */ + void writeStartElement(String localName) + throws XMLStreamException; + + /** + * Write the start of a tag. + */ + void writeStartElement(String namespaceURI, String localName) + throws XMLStreamException; + + /** + * Write the start of a tag. + */ + void writeStartElement(String prefix, String localName, String namespaceURI) + throws XMLStreamException; + + /** + * Write an empty tag. + */ + void writeEmptyElement(String namespaceURI, String localName) + throws XMLStreamException; + + /** + * Write an empty tag. + */ + void writeEmptyElement(String prefix, String localName, String namespaceURI) + throws XMLStreamException; + + /** + * Write an empty tag. + */ + void writeEmptyElement(String localName) + throws XMLStreamException; + + /** + * Closes the currently open tag. + */ + void writeEndElement() + throws XMLStreamException; + + /** + * Closes any currently open tags. + */ + void writeEndDocument() + throws XMLStreamException; + + /** + * Frees any resources used by this writer. + * This will not close the underlying output sink. + */ + void close() + throws XMLStreamException; + + /** + * Flushes any cached information to the underlying output sink. + */ + void flush() + throws XMLStreamException; + + /** + * Write an attribute. + */ + void writeAttribute(String localName, String value) + throws XMLStreamException; + + /** + * Write an attribute. + */ + void writeAttribute(String prefix, String namespaceURI, + String localName, String value) + throws XMLStreamException; + + /** + * Write an attribute. + */ + void writeAttribute(String namespaceURI, String localName, String value) + throws XMLStreamException; + + /** + * Write a namespace declaration. + */ + void writeNamespace(String prefix, String namespaceURI) + throws XMLStreamException; + + /** + * Write a default namespace declaration. + */ + void writeDefaultNamespace(String namespaceURI) + throws XMLStreamException; + + /** + * Write a comment. + */ + void writeComment(String data) + throws XMLStreamException; + + /** + * Write a processing instruction. + */ + void writeProcessingInstruction(String target) + throws XMLStreamException; + + /** + * Write a processing instruction. + */ + void writeProcessingInstruction(String target, String data) + throws XMLStreamException; + + /** + * Write a CDATA section. + */ + void writeCData(String data) + throws XMLStreamException; + + /** + * Write a DOCTYPE declaration. + */ + void writeDTD(String dtd) + throws XMLStreamException; + + /** + * Write an entity reference. + */ + void writeEntityRef(String name) + throws XMLStreamException; + + /** + * Write an XML declaration. + */ + void writeStartDocument() + throws XMLStreamException; + + /** + * Write an XML declaration with the specified XML version. + */ + void writeStartDocument(String version) + throws XMLStreamException; + + /** + * Write an XML declaration with the specifed XML version and encoding. + */ + void writeStartDocument(String encoding, String version) + throws XMLStreamException; + + /** + * Write the specified text. + */ + void writeCharacters(String text) + throws XMLStreamException; + + /** + * Write the specified text. + */ + void writeCharacters(char[] text, int start, int len) + throws XMLStreamException; + + /** + * Returns the prefix associated with the given namespace URI. + */ + String getPrefix(String uri) + throws XMLStreamException; + + /** + * Sets the prefix for the given namespace URI. + */ + void setPrefix(String prefix, String uri) + throws XMLStreamException; + + /** + * Sets the URI for the default namespace. + */ + void setDefaultNamespace(String uri) + throws XMLStreamException; + + /** + * Sets the namespace context for namespace resolution. + */ + void setNamespaceContext(NamespaceContext context) + throws XMLStreamException; + + /** + * Returns the current namespace context. + */ + NamespaceContext getNamespaceContext(); + + /** + * Returns the implementation-specific feature or property of the given + * name. + * @exception IllegalArgumentException if the property is not supported + */ + Object getProperty(String name) + throws IllegalArgumentException; + +} + diff --git a/libjava/classpath/javax/xml/stream/events/Attribute.java b/libjava/classpath/javax/xml/stream/events/Attribute.java new file mode 100644 index 0000000..cf47113 --- /dev/null +++ b/libjava/classpath/javax/xml/stream/events/Attribute.java @@ -0,0 +1,71 @@ +/* Attribute.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.xml.stream.events; + +import javax.xml.namespace.QName; + +/** + * An attribute event. + */ +public interface Attribute + extends XMLEvent +{ + + /** + * Returns the name of this attribute. + */ + QName getName(); + + /** + * Returns the normalized value of this attribute. + */ + String getValue(); + + /** + * Returns the type of this attribute. + */ + QName getDTDType(); + + /** + * Indicates whether this attribute was specified in the input source, or + * just defaulted by the DTD. + */ + boolean isSpecified(); + +} + diff --git a/libjava/classpath/javax/xml/stream/events/Characters.java b/libjava/classpath/javax/xml/stream/events/Characters.java new file mode 100644 index 0000000..3728a99 --- /dev/null +++ b/libjava/classpath/javax/xml/stream/events/Characters.java @@ -0,0 +1,68 @@ +/* Characters.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.xml.stream.events; + +/** + * A character data (text) event. + */ +public interface Characters + extends XMLEvent +{ + + /** + * Returns the character data assocated with this event. + */ + String getData(); + + /** + * Indicates whether this text is all whitespace. + */ + boolean isWhiteSpace(); + + /** + * Indicates whether this is a CDATA section. + */ + boolean isCData(); + + /** + * Indicates whether this text is all ignorable whitespace. + */ + boolean isIgnorableWhiteSpace(); + +} + diff --git a/libjava/classpath/javax/xml/stream/events/Comment.java b/libjava/classpath/javax/xml/stream/events/Comment.java new file mode 100644 index 0000000..300e32c --- /dev/null +++ b/libjava/classpath/javax/xml/stream/events/Comment.java @@ -0,0 +1,53 @@ +/* Comment.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.xml.stream.events; + +/** + * A comment event. + */ +public interface Comment + extends XMLEvent +{ + + /** + * Returns the comment text. + */ + String getText(); + +} + diff --git a/libjava/classpath/javax/xml/stream/events/DTD.java b/libjava/classpath/javax/xml/stream/events/DTD.java new file mode 100644 index 0000000..6c7bcc4 --- /dev/null +++ b/libjava/classpath/javax/xml/stream/events/DTD.java @@ -0,0 +1,71 @@ +/* DTD.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.xml.stream.events; + +import java.util.List; + +/** + * A DOCTYPE declaration event. + */ +public interface DTD + extends XMLEvent +{ + + /** + * Returns the body of the DTD, including the internal DTD subset. + */ + String getDocumentTypeDeclaration(); + + /** + * Returns an implementation-specific representation of the DTD, or null + * if no such representation is available. + */ + Object getProcessedDTD(); + + /** + * Returns the notations declared in the DTD. + */ + List getNotations(); + + /** + * Returns the entities declared in the DTD. + */ + List getEntities(); + +} + diff --git a/libjava/classpath/javax/xml/stream/events/EndDocument.java b/libjava/classpath/javax/xml/stream/events/EndDocument.java new file mode 100644 index 0000000..57d93af --- /dev/null +++ b/libjava/classpath/javax/xml/stream/events/EndDocument.java @@ -0,0 +1,47 @@ +/* EndDocument.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.xml.stream.events; + +/** + * An end-document event. + */ +public interface EndDocument + extends XMLEvent +{ +} + diff --git a/libjava/classpath/javax/xml/stream/events/EndElement.java b/libjava/classpath/javax/xml/stream/events/EndElement.java new file mode 100644 index 0000000..86a2e16 --- /dev/null +++ b/libjava/classpath/javax/xml/stream/events/EndElement.java @@ -0,0 +1,61 @@ +/* EndElement.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.xml.stream.events; + +import java.util.Iterator; +import javax.xml.namespace.QName; + +/** + * An end-element event. + */ +public interface EndElement + extends XMLEvent +{ + + /** + * Returns the element name. + */ + QName getName(); + + /** + * Returns the namespaces that have gone out of scope. + */ + Iterator getNamespaces(); + +} + diff --git a/libjava/classpath/javax/xml/stream/events/EndEntity.java b/libjava/classpath/javax/xml/stream/events/EndEntity.java new file mode 100644 index 0000000..b5c32d7 --- /dev/null +++ b/libjava/classpath/javax/xml/stream/events/EndEntity.java @@ -0,0 +1,53 @@ +/* EndEntity.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.xml.stream.events; + +/** + * An end-entity event. + */ +public interface EndEntity + extends XMLEvent +{ + + /** + * Returns the entity name. + */ + String getName(); + +} + diff --git a/libjava/classpath/javax/xml/stream/events/EntityDeclaration.java b/libjava/classpath/javax/xml/stream/events/EntityDeclaration.java new file mode 100644 index 0000000..a319f09 --- /dev/null +++ b/libjava/classpath/javax/xml/stream/events/EntityDeclaration.java @@ -0,0 +1,78 @@ +/* EntityDeclaration.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.xml.stream.events; + +/** + * An entity declaration event. + */ +public interface EntityDeclaration + extends XMLEvent +{ + + /** + * Returns the public identifier of the entity. + */ + String getPublicId(); + + /** + * Returns the system identifier of the entity. + */ + String getSystemId(); + + /** + * Returns the name of the entity. + */ + String getName(); + + /** + * Returns the name of the associated notation. + */ + String getNotationName(); + + /** + * Returns the replacement text for the entity. + */ + //String getReplacementText(); + + /** + * Returns the base URI for the entity. + */ + //String getBaseURI(); + +} + diff --git a/libjava/classpath/javax/xml/stream/events/EntityReference.java b/libjava/classpath/javax/xml/stream/events/EntityReference.java new file mode 100644 index 0000000..7244709 --- /dev/null +++ b/libjava/classpath/javax/xml/stream/events/EntityReference.java @@ -0,0 +1,78 @@ +/* EntityReference.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.xml.stream.events; + +/** + * An entity reference event. + */ +public interface EntityReference + extends XMLEvent +{ + + /** + * Returns the base URI for the entity. + */ + String getBaseUri(); + + /** + * Returns the public identifier for the entity. + */ + String getPublicId(); + + /** + * Returns the system identifierfor the entity. + */ + String getSystemId(); + + /** + * Returns the declaration of this reference. + */ + //EntityDeclaration getDeclaration(); + + /** + * Returns the entity name. + */ + String getName(); + + /** + * Returns the replacement text for the entity. + */ + String getReplacementText(); + +} + diff --git a/libjava/classpath/javax/xml/stream/events/Namespace.java b/libjava/classpath/javax/xml/stream/events/Namespace.java new file mode 100644 index 0000000..2275432 --- /dev/null +++ b/libjava/classpath/javax/xml/stream/events/Namespace.java @@ -0,0 +1,63 @@ +/* Namespace.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.xml.stream.events; + +/** + * A namespace declaration event. + */ +public interface Namespace + extends XMLEvent +{ + + /** + * Returns the namespace prefix, if any. + */ + String getPrefix(); + + /** + * Returns the namespace URI. + */ + String getNamespaceURI(); + + /** + * Indicates whether this event declares the default namespace. + */ + boolean isDefaultNamespaceDeclaration(); + +} + diff --git a/libjava/classpath/javax/xml/stream/events/NotationDeclaration.java b/libjava/classpath/javax/xml/stream/events/NotationDeclaration.java new file mode 100644 index 0000000..9ac29e9 --- /dev/null +++ b/libjava/classpath/javax/xml/stream/events/NotationDeclaration.java @@ -0,0 +1,63 @@ +/* NotationDeclaration.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.xml.stream.events; + +/** + * A notation declaration event. + */ +public interface NotationDeclaration + extends XMLEvent +{ + + /** + * Returns the name of the notation. + */ + String getName(); + + /** + * Returns the public identifier of the notation. + */ + String getPublicId(); + + /** + * Returns the system identifier of the notation. + */ + String getSystemId(); + +} + diff --git a/libjava/classpath/javax/xml/stream/events/ProcessingInstruction.java b/libjava/classpath/javax/xml/stream/events/ProcessingInstruction.java new file mode 100644 index 0000000..861dd30 --- /dev/null +++ b/libjava/classpath/javax/xml/stream/events/ProcessingInstruction.java @@ -0,0 +1,58 @@ +/* ProcessingInstruction.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.xml.stream.events; + +/** + * A processing instruction event. + */ +public interface ProcessingInstruction + extends XMLEvent +{ + + /** + * Returns the processing instruction target. + */ + String getTarget(); + + /** + * Returns the processing instruction data. + */ + String getData(); + +} + diff --git a/libjava/classpath/javax/xml/stream/events/StartDocument.java b/libjava/classpath/javax/xml/stream/events/StartDocument.java new file mode 100644 index 0000000..2bd251e --- /dev/null +++ b/libjava/classpath/javax/xml/stream/events/StartDocument.java @@ -0,0 +1,80 @@ +/* StartDocument.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.xml.stream.events; + +/** + * A start-document event. + */ +public interface StartDocument + extends XMLEvent +{ + + /** + * Returns the system identifier of the document entity. + */ + String getSystemId(); + + /** + * Returns the character encoding of the document. + */ + String getCharacterEncodingScheme(); + + /** + * Indicates whether the character encoding was set in the XML + * declaration. + */ + boolean encodingSet(); + + /** + * Indicates whether the document is standalone. + */ + boolean isStandalone(); + + /** + * Indicates whether the standalone parameter was set in the XML + * declaration. + */ + boolean standaloneSet(); + + /** + * Returns the XML version of the document. + */ + String getVersion(); + +} + diff --git a/libjava/classpath/javax/xml/stream/events/StartElement.java b/libjava/classpath/javax/xml/stream/events/StartElement.java new file mode 100644 index 0000000..a35b3b4 --- /dev/null +++ b/libjava/classpath/javax/xml/stream/events/StartElement.java @@ -0,0 +1,82 @@ +/* StartElement.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.xml.stream.events; + +import java.util.Iterator; +import javax.xml.namespace.NamespaceContext; +import javax.xml.namespace.QName; + +/** + * A start-element event. + */ +public interface StartElement + extends XMLEvent +{ + + /** + * Returns the element name. + */ + QName getName(); + + /** + * Returns the attributes declared on this element. + */ + Iterator getAttributes(); + + /** + * Returns the namespaces declared on this element. + */ + Iterator getNamespaces(); + + /** + * Returns an attribute by name. + */ + Attribute getAttributeByName(QName name); + + /** + * Returns a read-only namespace context associated with this event. + */ + NamespaceContext getNamespaceContext(); + + /** + * Returns the namespace URI associated with the given prefix. + */ + String getNamespaceURI(String prefix); + +} + diff --git a/libjava/classpath/javax/xml/stream/events/StartEntity.java b/libjava/classpath/javax/xml/stream/events/StartEntity.java new file mode 100644 index 0000000..d41e0db --- /dev/null +++ b/libjava/classpath/javax/xml/stream/events/StartEntity.java @@ -0,0 +1,53 @@ +/* StartEntity.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.xml.stream.events; + +/** + * An start-entity event. + */ +public interface StartEntity + extends XMLEvent +{ + + /** + * Returns the entity name. + */ + String getName(); + +} + diff --git a/libjava/classpath/javax/xml/stream/events/XMLEvent.java b/libjava/classpath/javax/xml/stream/events/XMLEvent.java new file mode 100644 index 0000000..54e9516 --- /dev/null +++ b/libjava/classpath/javax/xml/stream/events/XMLEvent.java @@ -0,0 +1,146 @@ +/* XMLEvent.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.xml.stream.events; + +import java.io.Writer; +import javax.xml.namespace.QName; +import javax.xml.stream.Location; +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamException; + +/** + * An XML stream event. + */ +public interface XMLEvent + extends XMLStreamConstants +{ + + /** + * Returns the type of this event. + */ + int getEventType(); + + /** + * Returns the location of this event. + */ + Location getLocation(); + + /** + * Indicates whether this event is a start-element event. + */ + boolean isStartElement(); + + /** + * Indicates whether this event is an attribute event. + */ + boolean isAttribute(); + + /** + * Indicates whether this event is a namespace declaration event. + */ + boolean isNamespace(); + + /** + * Indicates whether this event is an end-element event. + */ + boolean isEndElement(); + + /** + * Indicates whether this event is an entity reference event. + */ + boolean isEntityReference(); + + /** + * Indicates whether this event is a processing instruction event. + */ + boolean isProcessingInstruction(); + + /** + * Indicates whether this event is a text event. + */ + boolean isCharacters(); + + /** + * Indicates whether this event is a start-document event. + */ + boolean isStartDocument(); + + /** + * Indicates whether this event is an end-document event. + */ + boolean isEndDocument(); + + /** + * Indicates whether this event is a start-entity event. + */ + boolean isStartEntity(); + + /** + * Indicates whether this event is an end-entity event. + */ + boolean isEndEntity(); + + /** + * Returns this event as a start-element event. + */ + StartElement asStartElement(); + + /** + * Returns this event as an end-element event. + */ + EndElement asEndElement(); + + /** + * Returns this event as a text event. + */ + Characters asCharacters(); + + /** + * Returns schema-related type information about this event, or null if + * not available. + */ + QName getSchemaType(); + + /** + * Writes this event to the specified writer. + */ + void writeAsEncodedUnicode(Writer writer) + throws XMLStreamException; + +} + diff --git a/libjava/classpath/javax/xml/stream/util/EventReaderDelegate.java b/libjava/classpath/javax/xml/stream/util/EventReaderDelegate.java new file mode 100644 index 0000000..f6d1585 --- /dev/null +++ b/libjava/classpath/javax/xml/stream/util/EventReaderDelegate.java @@ -0,0 +1,134 @@ +/* EventReaderDelegate.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.xml.stream.util; + +import java.util.NoSuchElementException; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLEventReader; +import javax.xml.stream.events.XMLEvent; + +/** + * Base class for event reader filters. + */ +public class EventReaderDelegate + implements XMLEventReader +{ + + private XMLEventReader parent; + + /** + * Constructs an empty filter with no parent set. + */ + public EventReaderDelegate() + { + } + + /** + * Constructs an empty filter with the given parent. + */ + public EventReaderDelegate(XMLEventReader reader) + { + parent = reader; + } + + /** + * Sets the parent. + */ + public void setParent(XMLEventReader reader) + { + parent = reader; + } + + /** + * Returns the parent. + */ + public XMLEventReader getParent() + { + return parent; + } + + public XMLEvent next() + throws XMLStreamException + { + if (parent != null) + return parent.next(); + throw new NoSuchElementException(); + } + + public boolean hasNext() + throws XMLStreamException + { + if (parent != null) + return parent.hasNext(); + return false; + } + + public XMLEvent peek() + throws XMLStreamException + { + if (parent != null) + return parent.peek(); + return null; + } + + public String getElementText() + throws XMLStreamException + { + if (parent != null) + return parent.getElementText(); + throw new XMLStreamException(); + } + + public XMLEvent nextTag() + throws XMLStreamException + { + if (parent != null) + return parent.nextTag(); + throw new XMLStreamException(); + } + + public Object getProperty(String name) + throws IllegalArgumentException + { + if (parent != null) + return parent.getProperty(name); + throw new IllegalArgumentException(name); + } + +} + diff --git a/libjava/classpath/javax/xml/stream/util/ReaderDelegate.java b/libjava/classpath/javax/xml/stream/util/ReaderDelegate.java new file mode 100644 index 0000000..ef70175 --- /dev/null +++ b/libjava/classpath/javax/xml/stream/util/ReaderDelegate.java @@ -0,0 +1,409 @@ +/* ReaderDelegate.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.xml.stream.util; + +import javax.xml.namespace.NamespaceContext; +import javax.xml.namespace.QName; +import javax.xml.stream.Location; +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +/** + * Base class for XML stream reader filters. + */ +public class ReaderDelegate + implements XMLStreamReader, XMLStreamConstants +{ + + private XMLStreamReader parent; + + /** + * Constructs an empty filter with no parent set. + */ + public ReaderDelegate() + { + } + + /** + * Constructs an empty filter with the specfied parent. + */ + public ReaderDelegate(XMLStreamReader reader) + { + parent = reader; + } + + /** + * Sets the parent. + */ + public void setParent(XMLStreamReader reader) + { + parent = reader; + } + + /** + * Returns the parent. + */ + public XMLStreamReader getParent() + { + return parent; + } + + public int next() + throws XMLStreamException + { + if (parent != null) + return parent.next(); + throw new XMLStreamException(); + } + + public int nextTag() + throws XMLStreamException + { + if (parent != null) + return parent.nextTag(); + throw new XMLStreamException(); + } + + public String getElementText() + throws XMLStreamException + { + if (parent != null) + return parent.getElementText(); + throw new XMLStreamException(); + } + + public void require(int type, String namespaceURI, String localName) + throws XMLStreamException + { + if (parent != null) + parent.require(type, namespaceURI, localName); + } + + public boolean hasNext() + throws XMLStreamException + { + if (parent != null) + return parent.hasNext(); + return false; + } + + public void close() + throws XMLStreamException + { + if (parent != null) + parent.close(); + } + + public String getNamespaceURI(String prefix) + { + if (parent != null) + return parent.getNamespaceURI(prefix); + return null; + } + + public NamespaceContext getNamespaceContext() + { + if (parent != null) + return parent.getNamespaceContext(); + return null; + } + + public boolean isStartElement() + { + if (parent != null) + return parent.isStartElement(); + return false; + } + + public boolean isEndElement() + { + if (parent != null) + return parent.isEndElement(); + return false; + } + + public boolean isCharacters() + { + if (parent != null) + return parent.isCharacters(); + return false; + } + + public boolean isWhiteSpace() + { + if (parent != null) + return parent.isWhiteSpace(); + return false; + } + + public String getAttributeValue(String namespaceUri, String localName) + { + if (parent != null) + return parent.getAttributeValue(namespaceUri, localName); + return null; + } + + public int getAttributeCount() + { + if (parent != null) + return parent.getAttributeCount(); + return 0; + } + + public QName getAttributeQName(int index) + { + if (parent != null) + return parent.getAttributeQName(index); + return null; + } + + public String getAttributePrefix(int index) + { + if (parent != null) + return parent.getAttributePrefix(index); + return null; + } + + public String getAttributeNamespace(int index) + { + if (parent != null) + return parent.getAttributeNamespace(index); + return null; + } + + public String getAttributeName(int index) + { + if (parent != null) + return parent.getAttributeName(index); + return null; + } + + public String getAttributeType(int index) + { + if (parent != null) + return parent.getAttributeType(index); + return null; + } + + public String getAttributeValue(int index) + { + if (parent != null) + return parent.getAttributeValue(index); + return null; + } + + public boolean isAttributeSpecified(int index) + { + if (parent != null) + return parent.isAttributeSpecified(index); + return false; + } + + public int getNamespaceCount() + { + if (parent != null) + return parent.getNamespaceCount(); + return 0; + } + + public String getNamespacePrefix(int index) + { + if (parent != null) + return parent.getNamespacePrefix(index); + return null; + } + + public String getNamespaceURI(int index) + { + if (parent != null) + return parent.getNamespaceURI(index); + return null; + } + + public int getEventType() + { + if (parent != null) + return parent.getEventType(); + return 0; + } + + public String getText() + { + if (parent != null) + return parent.getText(); + return null; + } + + public int getTextCharacters(int sourceStart, char[] target, + int targetStart, int length) + throws XMLStreamException + { + if (parent != null) + return parent.getTextCharacters(sourceStart, target, targetStart, length); + return 0; + } + + public char[] getTextCharacters() + { + if (parent != null) + return parent.getTextCharacters(); + return null; + } + + public int getTextStart() + { + if (parent != null) + return parent.getTextStart(); + return 0; + } + + public int getTextLength() + { + if (parent != null) + return parent.getTextLength(); + return 0; + } + + public String getEncoding() + { + if (parent != null) + return parent.getEncoding(); + return null; + } + + public boolean hasText() + { + if (parent != null) + return parent.hasText(); + return false; + } + + public Location getLocation() + { + if (parent != null) + return parent.getLocation(); + return null; + } + + public QName getName() + { + if (parent != null) + return parent.getName(); + return null; + } + + public String getLocalName() + { + if (parent != null) + return parent.getLocalName(); + return null; + } + + public boolean hasName() + { + if (parent != null) + return parent.hasName(); + return false; + } + + public String getNamespaceURI() + { + if (parent != null) + return parent.getNamespaceURI(); + return null; + } + + public String getPrefix() + { + if (parent != null) + return parent.getPrefix(); + return null; + } + + public String getVersion() + { + if (parent != null) + return parent.getVersion(); + return null; + } + + public boolean isStandalone() + { + if (parent != null) + return parent.isStandalone(); + return false; + } + + public boolean standaloneSet() + { + if (parent != null) + return parent.standaloneSet(); + return false; + } + + public String getCharacterEncodingScheme() + { + if (parent != null) + return parent.getCharacterEncodingScheme(); + return null; + } + + public String getPITarget() + { + if (parent != null) + return parent.getPITarget(); + return null; + } + + public String getPIData() + { + if (parent != null) + return parent.getPIData(); + return null; + } + + public Object getProperty(String name) + { + if (parent != null) + return parent.getProperty(name); + throw new IllegalArgumentException(); + } + +} + diff --git a/libjava/classpath/javax/xml/stream/util/XMLEventAllocator.java b/libjava/classpath/javax/xml/stream/util/XMLEventAllocator.java new file mode 100644 index 0000000..d66bcbe --- /dev/null +++ b/libjava/classpath/javax/xml/stream/util/XMLEventAllocator.java @@ -0,0 +1,69 @@ +/* XMLEventAllocator.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.xml.stream.util; + +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.events.XMLEvent; + +/** + * Interface for allocating events according to a stream reader. + */ +public interface XMLEventAllocator +{ + + /** + * Creates a new allocator. + */ + XMLEventAllocator newInstance(); + + /** + * Allocates an event based on the current state of the stream reader. + */ + XMLEvent allocate(XMLStreamReader reader) + throws XMLStreamException; + + /** + * Allocates one or more events based on the current state of the stream + * reader and adds those events to the specified consumer. + */ + void allocate(XMLStreamReader reader, XMLEventConsumer consumer) + throws XMLStreamException; + +} + diff --git a/libjava/classpath/javax/xml/stream/util/XMLEventConsumer.java b/libjava/classpath/javax/xml/stream/util/XMLEventConsumer.java new file mode 100644 index 0000000..c9deaf1 --- /dev/null +++ b/libjava/classpath/javax/xml/stream/util/XMLEventConsumer.java @@ -0,0 +1,56 @@ +/* XMLEventConsumer.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.xml.stream.util; + +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.events.XMLEvent; + +/** + * Interface for consuming XML events. + */ +public interface XMLEventConsumer +{ + + /** + * Consumes an event. + */ + void add(XMLEvent event) + throws XMLStreamException; + +} + |