diff options
author | Andrew John Hughes <gnu_andrew@member.fsf.org> | 2005-08-02 20:12:05 +0000 |
---|---|---|
committer | Andrew John Hughes <gnu_andrew@member.fsf.org> | 2005-08-02 20:12:05 +0000 |
commit | 33bace404a240c1335ab1f6e95bd6616e22c0ecd (patch) | |
tree | 004ab1587e14d3df272c6944ce325d3584b95aa5 /javax/swing/plaf | |
parent | d30622846e00f908cb5d4beac7de4e5e78dcd630 (diff) | |
download | classpath-33bace404a240c1335ab1f6e95bd6616e22c0ecd.tar.gz |
2005-08-02 Andrew John Hughes <gnu_andrew@member.fsf.org>
* Merge of HEAD --> generics-branch for 2005/06/05 - 2005/07/31.
See patch on classpath-patches@gnu.org for a full ChangeLog.
Diffstat (limited to 'javax/swing/plaf')
132 files changed, 7384 insertions, 1242 deletions
diff --git a/javax/swing/plaf/ActionMapUIResource.java b/javax/swing/plaf/ActionMapUIResource.java index 640f3a756..f6af0880d 100644 --- a/javax/swing/plaf/ActionMapUIResource.java +++ b/javax/swing/plaf/ActionMapUIResource.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/BorderUIResource.java b/javax/swing/plaf/BorderUIResource.java index 6b61f48a0..4402bbb48 100644 --- a/javax/swing/plaf/BorderUIResource.java +++ b/javax/swing/plaf/BorderUIResource.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -556,7 +556,7 @@ public class BorderUIResource * @param shadow the color that will be used for painting * the shadow part of the border. * - * @see #EtchedBorderUIResource(int, Color, Color) + * @see EtchedBorderUIResource#EtchedBorderUIResource(int, Color, Color) */ public EtchedBorderUIResource(Color highlight, Color shadow) { @@ -684,7 +684,7 @@ public class BorderUIResource * @param left the width of the border at its left edge. * @param bottom the width of the border at its bottom edge. * @param right the width of the border at its right edge. - * @param matteColor the color for filling the border. + * @param color the color for filling the border. */ public MatteBorderUIResource(int top, int left, int bottom, int right, diff --git a/javax/swing/plaf/ButtonUI.java b/javax/swing/plaf/ButtonUI.java index 4fdaee505..197299e0c 100644 --- a/javax/swing/plaf/ButtonUI.java +++ b/javax/swing/plaf/ButtonUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/ColorChooserUI.java b/javax/swing/plaf/ColorChooserUI.java index e290a972a..68ffd916d 100644 --- a/javax/swing/plaf/ColorChooserUI.java +++ b/javax/swing/plaf/ColorChooserUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/ColorUIResource.java b/javax/swing/plaf/ColorUIResource.java index caa644c49..33b1676e0 100644 --- a/javax/swing/plaf/ColorUIResource.java +++ b/javax/swing/plaf/ColorUIResource.java @@ -1,5 +1,5 @@ /* ColorUIResource.java - Copyright (C) 2002, 2003 Free Software Foundation, Inc. + Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -63,6 +63,9 @@ public class ColorUIResource * @param r the red intensity, which must be in the range [0 .. 255]. * @param g the green intensity, which must be in the range [0 .. 255]. * @param b the blue intensity, which must be in the range [0 .. 255]. + * + * @throws IllegalArgumentException if any of the values is outside the + * specified range. */ public ColorUIResource(int r, int g, int b) { @@ -71,7 +74,7 @@ public class ColorUIResource /** - * Consructs a <code>ColorUIResource</code> using the specified + * Constructs a <code>ColorUIResource</code> using the specified * RGB value. The blue value is in bits 0-7, green in bits 8-15, and * red in bits 16-23. The other bits are ignored. The alpha value is set * to 255, meaning that the color is fully opaque. @@ -93,6 +96,9 @@ public class ColorUIResource * @param r the red intensity, which must be in the range [0.0 .. 1.0]. * @param g the green intensity, which must be in the range [0.0 .. 1.0]. * @param b the blue intensity, which must be in the range [0.0 .. 1.0]. + * + * @throws IllegalArgumentException if any of the values is outside the + * specified range. */ public ColorUIResource(float r, float g, float b) { @@ -105,7 +111,10 @@ public class ColorUIResource * of another color. * * @param c the color whose intensities will be considered when - * constructing this <code>ColorUIResource</code>. + * constructing this <code>ColorUIResource</code> (<code>null</code> + * not permitted). + * + * @throws NullPointerException if <code>c</code> is <code>null</code>. */ public ColorUIResource(Color c) { diff --git a/javax/swing/plaf/ComboBoxUI.java b/javax/swing/plaf/ComboBoxUI.java index 83286d95b..9498a4815 100644 --- a/javax/swing/plaf/ComboBoxUI.java +++ b/javax/swing/plaf/ComboBoxUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/ComponentInputMapUIResource.java b/javax/swing/plaf/ComponentInputMapUIResource.java index 40a70552e..e1418710f 100644 --- a/javax/swing/plaf/ComponentInputMapUIResource.java +++ b/javax/swing/plaf/ComponentInputMapUIResource.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/ComponentUI.java b/javax/swing/plaf/ComponentUI.java index 80e60c8f1..0e7680542 100644 --- a/javax/swing/plaf/ComponentUI.java +++ b/javax/swing/plaf/ComponentUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/DesktopIconUI.java b/javax/swing/plaf/DesktopIconUI.java index dfe69cc63..2e44088ca 100644 --- a/javax/swing/plaf/DesktopIconUI.java +++ b/javax/swing/plaf/DesktopIconUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/DesktopPaneUI.java b/javax/swing/plaf/DesktopPaneUI.java index 6943bf30f..de553eaf4 100644 --- a/javax/swing/plaf/DesktopPaneUI.java +++ b/javax/swing/plaf/DesktopPaneUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/DimensionUIResource.java b/javax/swing/plaf/DimensionUIResource.java index 06ec16670..63c6838c4 100644 --- a/javax/swing/plaf/DimensionUIResource.java +++ b/javax/swing/plaf/DimensionUIResource.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/FileChooserUI.java b/javax/swing/plaf/FileChooserUI.java index 903718154..8b661e399 100644 --- a/javax/swing/plaf/FileChooserUI.java +++ b/javax/swing/plaf/FileChooserUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -98,7 +98,7 @@ public abstract class FileChooserUI * @param chooser the <code>JFileChooser</code> whose * button text is requested. * - * @see javax.swing.JFileChoose#getApproveButtonText + * @see javax.swing.JFileChooser#getApproveButtonText */ public abstract String getApproveButtonText(JFileChooser chooser); @@ -111,7 +111,7 @@ public abstract class FileChooserUI * @param chooser the <code>JFileChooser</code> whose * dialog title is requested. * - * @see javax.swing.JFileChoose#getDialogtitle + * @see javax.swing.JFileChooser#getDialogTitle */ public abstract String getDialogTitle(JFileChooser chooser); diff --git a/javax/swing/plaf/FontUIResource.java b/javax/swing/plaf/FontUIResource.java index a4a45de72..1c1731048 100644 --- a/javax/swing/plaf/FontUIResource.java +++ b/javax/swing/plaf/FontUIResource.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/IconUIResource.java b/javax/swing/plaf/IconUIResource.java index 3af16b757..1b09ed31f 100644 --- a/javax/swing/plaf/IconUIResource.java +++ b/javax/swing/plaf/IconUIResource.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/InputMapUIResource.java b/javax/swing/plaf/InputMapUIResource.java index f638dd7b8..ae032e51f 100644 --- a/javax/swing/plaf/InputMapUIResource.java +++ b/javax/swing/plaf/InputMapUIResource.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/InsetsUIResource.java b/javax/swing/plaf/InsetsUIResource.java index ad2eb1b21..755d8add1 100644 --- a/javax/swing/plaf/InsetsUIResource.java +++ b/javax/swing/plaf/InsetsUIResource.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/InternalFrameUI.java b/javax/swing/plaf/InternalFrameUI.java index 69bfb6506..fd1e3374c 100644 --- a/javax/swing/plaf/InternalFrameUI.java +++ b/javax/swing/plaf/InternalFrameUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/LabelUI.java b/javax/swing/plaf/LabelUI.java index bda4448b9..8fc1d711b 100644 --- a/javax/swing/plaf/LabelUI.java +++ b/javax/swing/plaf/LabelUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/ListUI.java b/javax/swing/plaf/ListUI.java index 1639c41d3..66d5cf588 100644 --- a/javax/swing/plaf/ListUI.java +++ b/javax/swing/plaf/ListUI.java @@ -1,5 +1,5 @@ /* ListUI.java -- - Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. + Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -75,7 +75,7 @@ public abstract class ListUI * @return the index of the closest cell, or -1 if the list model * is empty. */ - public abstract int locationToIndex(JList index, Point location); + public abstract int locationToIndex(JList list, Point location); /** diff --git a/javax/swing/plaf/MenuBarUI.java b/javax/swing/plaf/MenuBarUI.java index fa350b660..8835571ac 100644 --- a/javax/swing/plaf/MenuBarUI.java +++ b/javax/swing/plaf/MenuBarUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/MenuItemUI.java b/javax/swing/plaf/MenuItemUI.java index c44d1f441..31d73194a 100644 --- a/javax/swing/plaf/MenuItemUI.java +++ b/javax/swing/plaf/MenuItemUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/OptionPaneUI.java b/javax/swing/plaf/OptionPaneUI.java index 8a954537a..13d1caa6a 100644 --- a/javax/swing/plaf/OptionPaneUI.java +++ b/javax/swing/plaf/OptionPaneUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/PanelUI.java b/javax/swing/plaf/PanelUI.java index d39d2e547..b1171b80d 100644 --- a/javax/swing/plaf/PanelUI.java +++ b/javax/swing/plaf/PanelUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/PopupMenuUI.java b/javax/swing/plaf/PopupMenuUI.java index 7e71a4b2e..c70ad2a4e 100644 --- a/javax/swing/plaf/PopupMenuUI.java +++ b/javax/swing/plaf/PopupMenuUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/ProgressBarUI.java b/javax/swing/plaf/ProgressBarUI.java index 28ea6f3a9..79c1b95a3 100644 --- a/javax/swing/plaf/ProgressBarUI.java +++ b/javax/swing/plaf/ProgressBarUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/RootPaneUI.java b/javax/swing/plaf/RootPaneUI.java index 0943c9882..ff7d0a6e7 100644 --- a/javax/swing/plaf/RootPaneUI.java +++ b/javax/swing/plaf/RootPaneUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/ScrollBarUI.java b/javax/swing/plaf/ScrollBarUI.java index 37c0cf783..3cad39327 100644 --- a/javax/swing/plaf/ScrollBarUI.java +++ b/javax/swing/plaf/ScrollBarUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/ScrollPaneUI.java b/javax/swing/plaf/ScrollPaneUI.java index 7d0bb892a..14d2ac61e 100644 --- a/javax/swing/plaf/ScrollPaneUI.java +++ b/javax/swing/plaf/ScrollPaneUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/SeparatorUI.java b/javax/swing/plaf/SeparatorUI.java index 03778b95d..6855bd035 100644 --- a/javax/swing/plaf/SeparatorUI.java +++ b/javax/swing/plaf/SeparatorUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/SliderUI.java b/javax/swing/plaf/SliderUI.java index 2a839f802..775f19620 100644 --- a/javax/swing/plaf/SliderUI.java +++ b/javax/swing/plaf/SliderUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/SpinnerUI.java b/javax/swing/plaf/SpinnerUI.java index 497fdb237..fb4a3b13a 100644 --- a/javax/swing/plaf/SpinnerUI.java +++ b/javax/swing/plaf/SpinnerUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/SplitPaneUI.java b/javax/swing/plaf/SplitPaneUI.java index 146db7664..ea9af2b17 100644 --- a/javax/swing/plaf/SplitPaneUI.java +++ b/javax/swing/plaf/SplitPaneUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/TabbedPaneUI.java b/javax/swing/plaf/TabbedPaneUI.java index f0cf69919..6ab823b50 100644 --- a/javax/swing/plaf/TabbedPaneUI.java +++ b/javax/swing/plaf/TabbedPaneUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/TableHeaderUI.java b/javax/swing/plaf/TableHeaderUI.java index 26bc9e29b..f23ca74d7 100644 --- a/javax/swing/plaf/TableHeaderUI.java +++ b/javax/swing/plaf/TableHeaderUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/TableUI.java b/javax/swing/plaf/TableUI.java index 7062b93cc..e56bcd131 100644 --- a/javax/swing/plaf/TableUI.java +++ b/javax/swing/plaf/TableUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/TextUI.java b/javax/swing/plaf/TextUI.java index b28dd372e..dcabdfcdb 100644 --- a/javax/swing/plaf/TextUI.java +++ b/javax/swing/plaf/TextUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -40,6 +40,7 @@ package javax.swing.plaf; import java.awt.Point; import java.awt.Rectangle; +import java.awt.Shape; import javax.swing.text.BadLocationException; import javax.swing.text.EditorKit; @@ -83,9 +84,7 @@ public abstract class TextUI * @throws BadLocationException if <code>pos</code> does not * designate a valid position in the document model. * - * @see javax.swing.text.View#modelToView(int, - * javax.swing.text.Position.Bias, int, - * javax.swing.text.position.Bias, java.awt.Shape) + * @see javax.swing.text.ComponentView#modelToView(int, Shape, Position.Bias) */ public abstract Rectangle modelToView(JTextComponent tc, int pos) throws BadLocationException; @@ -113,9 +112,7 @@ public abstract class TextUI * @throws BadLocationException if <code>pos</code> does not * designate a valid position in the document model. * - * @see javax.swing.text.View#modelToView(int, - * javax.swing.text.Position.Bias, int, - * javax.swing.text.position.Bias, java.awt.Shape) + * @see javax.swing.text.ComponentView#modelToView(int, Shape, Position.Bias) */ public abstract Rectangle modelToView(JTextComponent tc, int pos, Position.Bias bias) @@ -126,10 +123,10 @@ public abstract class TextUI * Finds the caret position which is closest to the specified visual * location. * - * @param tc the <code>JTextComponent</code> for which this + * @param t the <code>JTextComponent</code> for which this * delegate object provides the user interface. * - * @param loc the position in view coordinates. + * @param pt the position in view coordinates. * * @return the caret position which is closest to <code>loc</code>. * @@ -191,7 +188,7 @@ public abstract class TextUI * * @throws IllegalArgumentException if <code>direction</code> * is not one of <code>Position.Bias.Forward</code> - * or <code>Position.Biad.Backward</code>. + * or <code>Position.Bias.Backward</code>. */ public abstract int getNextVisualPositionFrom(JTextComponent tc, int pos, diff --git a/javax/swing/plaf/ToolBarUI.java b/javax/swing/plaf/ToolBarUI.java index 18b27d3ae..730cf4887 100644 --- a/javax/swing/plaf/ToolBarUI.java +++ b/javax/swing/plaf/ToolBarUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/ToolTipUI.java b/javax/swing/plaf/ToolTipUI.java index 4f332a635..4383d0edd 100644 --- a/javax/swing/plaf/ToolTipUI.java +++ b/javax/swing/plaf/ToolTipUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/TreeUI.java b/javax/swing/plaf/TreeUI.java index d4bee57cf..e32952de7 100644 --- a/javax/swing/plaf/TreeUI.java +++ b/javax/swing/plaf/TreeUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/UIResource.java b/javax/swing/plaf/UIResource.java index 1fff8488c..59edf5666 100644 --- a/javax/swing/plaf/UIResource.java +++ b/javax/swing/plaf/UIResource.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -40,7 +40,7 @@ package javax.swing.plaf; /** * This public interface is used to designate which objects were created by - * <code>ComponentUI</code> delegates. When uninstalling the user public interface + * {@link ComponentUI} delegates. When uninstalling the user public interface * renderer with <code>ComponentUI.uninstallUI()</code> the renderer * property is set to <code>null</code>. * <br> @@ -50,6 +50,6 @@ package javax.swing.plaf; * they are initialized or set to <code>null</code>. * * @author Brian Jones - * @see java.lang.ComponentUI + * @see ComponentUI */ public interface UIResource { } diff --git a/javax/swing/plaf/ViewportUI.java b/javax/swing/plaf/ViewportUI.java index 3b2892049..087938f1e 100644 --- a/javax/swing/plaf/ViewportUI.java +++ b/javax/swing/plaf/ViewportUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/basic/BasicArrowButton.java b/javax/swing/plaf/basic/BasicArrowButton.java index 0526961a9..4da4691f6 100644 --- a/javax/swing/plaf/basic/BasicArrowButton.java +++ b/javax/swing/plaf/basic/BasicArrowButton.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/basic/BasicBorders.java b/javax/swing/plaf/basic/BasicBorders.java index dd668e353..e7d6e4338 100644 --- a/javax/swing/plaf/basic/BasicBorders.java +++ b/javax/swing/plaf/basic/BasicBorders.java @@ -1,5 +1,5 @@ /* BasicBorders.java -- - Copyright (C) 2003, 2004 Free Software Foundation, Inc. + Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -89,9 +89,9 @@ public class BasicBorders * height="170" alt="[A screen shot of the returned border]" /> * * @return a {@link - * javax.swing.plaf.BorderUIResource#CompoundBorderUIResource} - * whose outer border is a {@link #ButtonBorder} and whose - * inner border is a {@link #MarginBorder}. + * javax.swing.plaf.BorderUIResource.CompoundBorderUIResource} + * whose outer border is a {@link ButtonBorder} and whose + * inner border is a {@link MarginBorder}. */ public static Border getButtonBorder() { @@ -139,9 +139,9 @@ public class BasicBorders * height="135" alt="[A screen shot of the returned border]" /> * * @return a {@link - * javax.swing.plaf.BorderUIResource#CompoundBorderUIResource} - * whose outer border is a {@link #RadioButtonBorder} and whose - * inner border is a {@link #MarginBorder}. + * javax.swing.plaf.BorderUIResource.CompoundBorderUIResource} + * whose outer border is a {@link RadioButtonBorder} and whose + * inner border is a {@link MarginBorder}. */ public static Border getRadioButtonBorder() { @@ -191,9 +191,9 @@ public class BasicBorders * height="135" alt="[A screen shot of the returned border]" /> * * @return a {@link - * javax.swing.plaf.BorderUIResource#CompoundBorderUIResource} - * whose outer border is a {@link #ToggleButtonBorder} and whose - * inner border is a {@link #MarginBorder}. + * javax.swing.plaf.BorderUIResource.CompoundBorderUIResource} + * whose outer border is a {@link ToggleButtonBorder} and whose + * inner border is a {@link MarginBorder}. */ public static Border getToggleButtonBorder() { @@ -241,7 +241,7 @@ public class BasicBorders * <p><img src="doc-files/BasicBorders.MenuBarBorder-1.png" width="500" * height="140" alt="[A screen shot of a JMenuBar with this border]" /> * - * @return a {@link #MenuBarBorder}. + * @return a {@link MenuBarBorder}. * * @see javax.swing.JMenuBar */ @@ -272,7 +272,7 @@ public class BasicBorders * <p><img src="doc-files/BasicBorders.SplitPaneBorder-2.png" width="520" * height="200" alt="[A screen shot for JSplitPane.VERTICAL_SPLIT]" /> * - * @return a {@link #SplitPaneBorder}. + * @return a {@link SplitPaneBorder}. * * @see javax.swing.JSplitPane * @see #getSplitPaneDividerBorder() @@ -339,8 +339,7 @@ public class BasicBorders * height="200" alt="[A screen shot of a border returned by * this method]" /> * - * @return an instance of - * {@link javax.swing.plaf.basic.BasicBorders$FieldBorder}. + * @return an instance of {@link FieldBorder}. * * @see javax.swing.JTextField * @see javax.swing.text.JTextComponent @@ -592,7 +591,7 @@ public class BasicBorders * * @return the same object that was passed for <code>insets</code>. * - * @see #getBorderInsets() + * @see #getBorderInsets(Component) */ public Insets getBorderInsets(Component c, Insets insets) { @@ -756,7 +755,7 @@ public class BasicBorders * * @return the same object that was passed for <code>insets</code>. * - * @see #getBorderInsets() + * @see #getBorderInsets(Component) */ public Insets getBorderInsets(Component c, Insets insets) { @@ -1020,7 +1019,7 @@ public class BasicBorders * * @return the same object that was passed for <code>insets</code>. * - * @see #getBorderInsets() + * @see #getBorderInsets(Component) */ public Insets getBorderInsets(Component c, Insets insets) { @@ -1176,7 +1175,7 @@ public class BasicBorders * * @return the same object that was passed for <code>insets</code>. * - * @see #getBorderInsets() + * @see #getBorderInsets(Component) */ public Insets getBorderInsets(Component c, Insets insets) { @@ -1230,7 +1229,7 @@ public class BasicBorders * Paints the border around a rollover button. If <code>c</code> * is not an {@link javax.swing.AbstractButton} whose model * returns <code>true</code> for {@link - * javax.swing.ButtonModel#isRollver}, nothing gets painted at + * javax.swing.ButtonModel#isRollover}, nothing gets painted at * all. * * @param c the button whose border is to be painted. @@ -1309,8 +1308,8 @@ public class BasicBorders * appearance of the Sun reference implementation. A bug report has * been filed with Sun (review ID 188774). * - * @see {@link #getSplitPaneBorder()} - * @see {@link #getSplitPaneDividerBorder()} + * @see #getSplitPaneBorder() + * @see #getSplitPaneDividerBorder() * * @author Sascha Brawer (brawer@dandelis.ch) */ @@ -1797,7 +1796,7 @@ public class BasicBorders * * @return the same object that was passed for <code>insets</code>. * - * @see #getBorderInsets() + * @see #getBorderInsets(Component) */ public Insets getBorderInsets(Component c, Insets insets) { diff --git a/javax/swing/plaf/basic/BasicButtonListener.java b/javax/swing/plaf/basic/BasicButtonListener.java index 3a81e3ff9..5349f5240 100644 --- a/javax/swing/plaf/basic/BasicButtonListener.java +++ b/javax/swing/plaf/basic/BasicButtonListener.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -87,9 +87,6 @@ public class BasicButtonListener if (e.getSource() instanceof AbstractButton) { AbstractButton button = (AbstractButton) e.getSource(); - ButtonModel model = button.getModel(); - model.setArmed(false); - if (button.isFocusPainted()) button.repaint(); } diff --git a/javax/swing/plaf/basic/BasicButtonUI.java b/javax/swing/plaf/basic/BasicButtonUI.java index 6c0ac38b8..0c069da0f 100644 --- a/javax/swing/plaf/basic/BasicButtonUI.java +++ b/javax/swing/plaf/basic/BasicButtonUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -200,7 +200,7 @@ public class BasicButtonUI extends ButtonUI /** * Calculate the preferred size of this component, by delegating to - * {@link BasicGraphicsUtils.getPreferredButtonSize}. + * {@link BasicGraphicsUtils#getPreferredButtonSize}. * * @param c The component to measure * @@ -285,7 +285,8 @@ public class BasicButtonUI extends ButtonUI paintIcon(g, c, ir); if (text != null) paintText(g, b, tr, text); - paintFocus(g, b, vr, tr, ir); + if (b.isFocusOwner()) + paintFocus(g, b, vr, tr, ir); } /** @@ -300,21 +301,14 @@ public class BasicButtonUI extends ButtonUI * @param tr Text rectangle, contained in visible rectangle * @param ir Icon rectangle, contained in visible rectangle * - * @see AbstractButton.isFocusPainted() - * @see JComponent.hasFocus() + * @see AbstractButton#isFocusPainted() + * @see JComponent#hasFocus() */ protected void paintFocus(Graphics g, AbstractButton b, Rectangle vr, Rectangle tr, Rectangle ir) { - if (b.hasFocus() && b.isFocusPainted()) - { - Color saved_color = g.getColor(); - g.setColor(focusColor); - Rectangle focusRect = ir.union(tr); - g.drawRect(focusRect.x, focusRect.y, - focusRect.width, focusRect.height); - g.setColor(saved_color); - } + // In the BasicLookAndFeel no focus border is drawn. This can be + // overridden in subclasses to implement such behaviour. } /** diff --git a/javax/swing/plaf/basic/BasicCheckBoxMenuItemUI.java b/javax/swing/plaf/basic/BasicCheckBoxMenuItemUI.java index 5d7bbcd2c..da11898bf 100644 --- a/javax/swing/plaf/basic/BasicCheckBoxMenuItemUI.java +++ b/javax/swing/plaf/basic/BasicCheckBoxMenuItemUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/basic/BasicCheckBoxUI.java b/javax/swing/plaf/basic/BasicCheckBoxUI.java index 5e1e0f5a9..e3167327c 100644 --- a/javax/swing/plaf/basic/BasicCheckBoxUI.java +++ b/javax/swing/plaf/basic/BasicCheckBoxUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/basic/BasicColorChooserUI.java b/javax/swing/plaf/basic/BasicColorChooserUI.java index 5b876284c..4e6d38154 100644 --- a/javax/swing/plaf/basic/BasicColorChooserUI.java +++ b/javax/swing/plaf/basic/BasicColorChooserUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/basic/BasicComboBoxEditor.java b/javax/swing/plaf/basic/BasicComboBoxEditor.java index a55e13c95..dd867f0dc 100644 --- a/javax/swing/plaf/basic/BasicComboBoxEditor.java +++ b/javax/swing/plaf/basic/BasicComboBoxEditor.java @@ -1,5 +1,5 @@ /* BasicComboBoxEditor.java -- - Copyright (C) 2004 Free Software Foundation, Inc. + Copyright (C) 2004, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -81,17 +81,20 @@ public class BasicComboBoxEditor extends Object implements ComboBoxEditor, } /** - * Sets item that should be editted when any editting operation is performed + * Sets item that should be edited when any editing operation is performed * by the user. The value is always equal to the currently selected value * in the combo box. Thus whenever a different value is selected from the - * combo box list then this method should be called to change editting + * combo box list then this method should be called to change editing * item to the new selected item. * - * @param selectedItem item that is currently selected in the combo box + * @param item item that is currently selected in the combo box */ public void setItem(Object item) { - editor.setText(item.toString()); + if (item == null) + editor.setText(""); + else + editor.setText(item.toString()); } /** diff --git a/javax/swing/plaf/basic/BasicComboBoxRenderer.java b/javax/swing/plaf/basic/BasicComboBoxRenderer.java index 9f61e0d18..e4fbb8352 100644 --- a/javax/swing/plaf/basic/BasicComboBoxRenderer.java +++ b/javax/swing/plaf/basic/BasicComboBoxRenderer.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/basic/BasicComboBoxUI.java b/javax/swing/plaf/basic/BasicComboBoxUI.java index 572902ec3..68e18a6ab 100644 --- a/javax/swing/plaf/basic/BasicComboBoxUI.java +++ b/javax/swing/plaf/basic/BasicComboBoxUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/basic/BasicComboPopup.java b/javax/swing/plaf/basic/BasicComboPopup.java index 2acc21fa7..73aac8d4e 100644 --- a/javax/swing/plaf/basic/BasicComboPopup.java +++ b/javax/swing/plaf/basic/BasicComboPopup.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/basic/BasicDesktopIconUI.java b/javax/swing/plaf/basic/BasicDesktopIconUI.java index 2a87761ee..561b497f1 100644 --- a/javax/swing/plaf/basic/BasicDesktopIconUI.java +++ b/javax/swing/plaf/basic/BasicDesktopIconUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/basic/BasicDesktopPaneUI.java b/javax/swing/plaf/basic/BasicDesktopPaneUI.java index a9e7ffceb..b15700d6f 100644 --- a/javax/swing/plaf/basic/BasicDesktopPaneUI.java +++ b/javax/swing/plaf/basic/BasicDesktopPaneUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/basic/BasicDirectoryModel.java b/javax/swing/plaf/basic/BasicDirectoryModel.java index f83887e69..a694f3280 100644 --- a/javax/swing/plaf/basic/BasicDirectoryModel.java +++ b/javax/swing/plaf/basic/BasicDirectoryModel.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/basic/BasicEditorPaneUI.java b/javax/swing/plaf/basic/BasicEditorPaneUI.java index 18cacab11..d5b34d9ee 100644 --- a/javax/swing/plaf/basic/BasicEditorPaneUI.java +++ b/javax/swing/plaf/basic/BasicEditorPaneUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -39,30 +39,69 @@ exception statement from your version. */ package javax.swing.plaf.basic; import javax.swing.JComponent; +import javax.swing.JEditorPane; import javax.swing.plaf.ComponentUI; +import javax.swing.text.EditorKit; import javax.swing.text.Element; +import javax.swing.text.JTextComponent; import javax.swing.text.PlainView; import javax.swing.text.View; +/** + * The UI class for {@link JEditorPane}s. + * + * @author original author unknown + * @author Roman Kennke (roman@kennke.org) + */ public class BasicEditorPaneUI extends BasicTextUI { + /** + * Creates an instance of <code>BasicEditorPaneUI</code> for the text + * component <code>comp</code>. + * + * @param comp the component for which to create an UI + * + * @return the UI for <code>comp</code> + */ public static ComponentUI createUI(JComponent comp) { return new BasicEditorPaneUI(); } + /** + * Creates a new <code>BasicEditorPaneUI</code> + */ public BasicEditorPaneUI() { // Do nothing here. } + // FIXME: Should not be overridden here but instead be handled by the + // JEditorPane's EditorKit. However, as long as we don't have styles in + // place this doesn't make much sense. public View create(Element elem) { return new PlainView(elem); } + /** + * Returns the property prefix to be used by this UI class. This is + * <code>EditorPane</code> in this case. + * + * @return <code>EditorPane</code> + */ protected String getPropertyPrefix() { return "EditorPane"; } + + /** + * Gets the EditorKit for the text component. + * + * @param textComponent the text component for which to fetch the editor kit + */ + public EditorKit getEditorKit(JTextComponent textComponent) + { + return ((JEditorPane) textComponent).getEditorKit(); + } } diff --git a/javax/swing/plaf/basic/BasicFileChooserUI.java b/javax/swing/plaf/basic/BasicFileChooserUI.java index d425ad324..fd34fbd62 100644 --- a/javax/swing/plaf/basic/BasicFileChooserUI.java +++ b/javax/swing/plaf/basic/BasicFileChooserUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -152,8 +152,9 @@ public class BasicFileChooserUI extends FileChooserUI { File f = filechooser.getFileSystemView().createFileObject(obj .toString()); - if (filechooser.isTraversable(f)) - filechooser.setCurrentDirectory(f); + if (filechooser.isTraversable(f) && + filechooser.getFileSelectionMode() == JFileChooser.FILES_ONLY) + filechooser.setCurrentDirectory(f); else { filechooser.setSelectedFile(f); @@ -873,76 +874,74 @@ public class BasicFileChooserUI extends FileChooserUI } }; - // -- begin private -- + // -- begin private, but package local since used in inner classes -- - /** DOCUMENT ME! */ - private JFileChooser filechooser; + JFileChooser filechooser; /** DOCUMENT ME! */ - private JList filelist; + JList filelist; /** DOCUMENT ME! */ - private JComboBox filters; + JComboBox filters; /** DOCUMENT ME! */ - private BasicDirectoryModel model; + BasicDirectoryModel model; /** DOCUMENT ME! */ - private FileFilter acceptAll = new AcceptAllFileFilter(); + FileFilter acceptAll = new AcceptAllFileFilter(); /** DOCUMENT ME! */ - private FileView fv = new BasicFileView(); + FileView fv = new BasicFileView(); /** DOCUMENT ME! */ - private static final int ICON_SIZE = 24; + static final int ICON_SIZE = 24; /** DOCUMENT ME! */ - private JComboBox parents; + JComboBox parents; /** DOCUMENT ME! */ - private String filename; + String filename; /** DOCUMENT ME! */ - private JButton accept; + JButton accept; /** DOCUMENT ME! */ - private JButton cancel; + JButton cancel; /** DOCUMENT ME! */ - private JButton upFolderButton; + JButton upFolderButton; /** DOCUMENT ME! */ - private JButton newFolderButton; + JButton newFolderButton; /** DOCUMENT ME! */ - private JButton homeFolderButton; + JButton homeFolderButton; /** DOCUMENT ME! */ - private JPanel accessoryPanel; + JPanel accessoryPanel; /** DOCUMENT ME! */ - private PropertyChangeListener propertyChangeListener; + PropertyChangeListener propertyChangeListener; /** DOCUMENT ME! */ - private String acceptAllFileFilterText; + String acceptAllFileFilterText; /** DOCUMENT ME! */ - private String dirDescText; + String dirDescText; /** DOCUMENT ME! */ - private String fileDescText; + String fileDescText; /** DOCUMENT ME! */ - private boolean dirSelected = false; + boolean dirSelected = false; /** DOCUMENT ME! */ - private File currDir = null; + File currDir = null; - /** DOCUMENT ME! */ - private JPanel bottomPanel; + JPanel bottomPanel; /** DOCUMENT ME! */ - private JPanel closePanel; + JPanel closePanel; // -- end private -- private class ListLabelRenderer @@ -1028,10 +1027,7 @@ public class BasicFileChooserUI extends FileChooserUI } } - /** - * DOCUMENT ME! - */ - private void closeDialog() + void closeDialog() { Window owner = SwingUtilities.windowForComponent(filechooser); if (owner instanceof JDialog) @@ -1167,10 +1163,7 @@ public class BasicFileChooserUI extends FileChooserUI }; } - /** - * DOCUMENT ME! - */ - private void filterEntries() + void filterEntries() { FileFilter[] list = filechooser.getChoosableFileFilters(); if (filters.getItemCount() > 0) diff --git a/javax/swing/plaf/basic/BasicFormattedTextFieldUI.java b/javax/swing/plaf/basic/BasicFormattedTextFieldUI.java index c61dc40a5..3abd76fe2 100644 --- a/javax/swing/plaf/basic/BasicFormattedTextFieldUI.java +++ b/javax/swing/plaf/basic/BasicFormattedTextFieldUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/basic/BasicGraphicsUtils.java b/javax/swing/plaf/basic/BasicGraphicsUtils.java index 7eef7760f..78ee62f95 100644 --- a/javax/swing/plaf/basic/BasicGraphicsUtils.java +++ b/javax/swing/plaf/basic/BasicGraphicsUtils.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -51,6 +51,8 @@ import java.awt.font.TextLayout; import java.awt.geom.Rectangle2D; import javax.swing.AbstractButton; +import javax.swing.Icon; +import javax.swing.JComponent; import javax.swing.SwingUtilities; @@ -585,7 +587,9 @@ public class BasicGraphicsUtils * and <code>height</code> fields indicate the preferred * extent in pixels. * - * @see javax.swing.SwingUtilities#layoutCompoundLabel + * @see javax.swing.SwingUtilities#layoutCompoundLabel(JComponent, + * FontMetrics, String, Icon, int, int, int, int, Rectangle, Rectangle, + * Rectangle, int) */ public static Dimension getPreferredButtonSize(AbstractButton b, int textIconGap) diff --git a/javax/swing/plaf/basic/BasicIconFactory.java b/javax/swing/plaf/basic/BasicIconFactory.java index a2acc8116..43380c203 100644 --- a/javax/swing/plaf/basic/BasicIconFactory.java +++ b/javax/swing/plaf/basic/BasicIconFactory.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -70,10 +70,100 @@ public class BasicIconFactory implements Serializable } } + /** + * The icon used for CheckBoxes in the BasicLookAndFeel. This is an empty + * icon with a size of 13x13 pixels. + */ + static class CheckBoxIcon + implements Icon + { + /** + * Returns the height of the icon. The BasicLookAndFeel CheckBox icon + * has a height of 13 pixels. + * + * @return the height of the icon + */ + public int getIconHeight() + { + return 13; + } - public BasicIconFactory() + /** + * Returns the width of the icon. The BasicLookAndFeel CheckBox icon + * has a width of 13 pixels. + * + * @return the height of the icon + */ + public int getIconWidth() + { + return 13; + } + + /** + * Paints the icon. The BasicLookAndFeel CheckBox icon is empty and does + * not need to be painted. + * + * @param c the component to be painted + * @param g the Graphics context to be painted with + * @param x the x position of the icon + * @param y the y position of the icon + */ + public void paintIcon(Component c, Graphics g, int x, int y) + { + // The icon is empty and needs no painting. + } + } + + /** + * The icon used for RadioButtons in the BasicLookAndFeel. This is an empty + * icon with a size of 13x13 pixels. + */ + static class RadioButtonIcon + implements Icon { + /** + * Returns the height of the icon. The BasicLookAndFeel RadioButton icon + * has a height of 13 pixels. + * + * @return the height of the icon + */ + public int getIconHeight() + { + return 13; + } + + /** + * Returns the width of the icon. The BasicLookAndFeel RadioButton icon + * has a width of 13 pixels. + * + * @return the height of the icon + */ + public int getIconWidth() + { + return 13; + } + + /** + * Paints the icon. The BasicLookAndFeel RadioButton icon is empty and does + * not need to be painted. + * + * @param c the component to be painted + * @param g the Graphics context to be painted with + * @param x the x position of the icon + * @param y the y position of the icon + */ + public void paintIcon(Component c, Graphics g, int x, int y) + { + // The icon is empty and needs no painting. + } } + + /** The cached CheckBoxIcon instance. */ + private static CheckBoxIcon checkBoxIcon; + + /** The cached CheckBoxIcon instance. */ + private static RadioButtonIcon radioButtonIcon; + public static Icon getMenuItemCheckIcon() { return new DummyIcon(); @@ -114,115 +204,34 @@ public class BasicIconFactory implements Serializable }; } + /** + * Returns an icon for CheckBoxes in the BasicLookAndFeel. CheckBox icons + * in the Basic L&F are empty and have a size of 13x13 pixels. + * This method returns a shared single instance of this icon. + * + * @return an icon for CheckBoxes in the BasicLookAndFeel + */ public static Icon getCheckBoxIcon() { - return new Icon() - { - public int getIconHeight() - { - return 10; - } - public int getIconWidth() - { - return 10; - } - public void paintIcon(Component c, Graphics g, int x, int y) - { - if (c instanceof AbstractButton) - { - UIDefaults defaults; - defaults = UIManager.getLookAndFeelDefaults(); - Color hi = defaults.getColor("CheckBox.highlight"); - Color low = defaults.getColor("CheckBox.darkShadow"); - Color sel = defaults.getColor("CheckBox.foreground"); - Color dim = defaults.getColor("CheckBox.shadow"); - Polygon check = new Polygon(new int[] {x+3, x+3, x+8}, - new int[] {y+5, y+9, y+3}, 3); - AbstractButton b = (AbstractButton) c; - Color saved = g.getColor(); - if (b.isEnabled()) - { - g.setColor(low); - g.drawRect(x, y, 10, 10); - g.setColor(hi); - g.drawRect(x+1, y+1, 10, 10); - if (b.isSelected()) - { - g.setColor(sel); - if (b.isSelected()) - { - g.drawLine(x+3, y+5, x+3, y+8); - g.drawLine(x+4, y+5, x+4, y+8); - g.drawLine(x+3, y+8, x+8, y+3); - g.drawLine(x+4, y+8, x+8, y+3); - } - } - } - else - { - g.setColor(hi); - g.drawRect(x, y, 10, 10); - if (b.isSelected()) - { - g.drawLine(x+3, y+5, x+3, y+9); - g.drawLine(x+3, y+9, x+8, y+3); - } - } - g.setColor(saved); - } - } - }; + if (checkBoxIcon == null) + checkBoxIcon = new CheckBoxIcon(); + return checkBoxIcon; } + /** + * Returns an icon for RadioButtons in the BasicLookAndFeel. RadioButton + * icons in the Basic L&F are empty and have a size of 13x13 pixels. + * This method returns a shared single instance of this icon. + * + * @return an icon for RadioButtons in the BasicLookAndFeel + */ public static Icon getRadioButtonIcon() { - return new Icon() - { - public int getIconHeight() - { - return 12; - } - public int getIconWidth() - { - return 12; - } - public void paintIcon(Component c, Graphics g, int x, int y) - { - UIDefaults defaults; - defaults = UIManager.getLookAndFeelDefaults(); - Color hi = defaults.getColor("RadioButton.highlight"); - Color low = defaults.getColor("RadioButton.darkShadow"); - Color sel = defaults.getColor("RadioButton.foreground"); - Color dim = defaults.getColor("RadioButton.shadow"); - - if (c instanceof AbstractButton) - { - AbstractButton b = (AbstractButton) c; - Color saved = g.getColor(); - if (b.isEnabled()) - { - g.setColor(low); - g.drawOval(x, y, 12, 12); - g.setColor(hi); - g.drawOval(x+1, y+1, 12, 12); - if (b.isSelected()) - { - g.setColor(sel); - g.fillOval(x+4, y+4, 6, 6); - } - } - else - { - g.setColor(hi); - g.drawOval(x, y, 12, 12); - if (b.isSelected()) - g.fillOval(x+4, y+4, 6, 6); - } - g.setColor(saved); - } - } - }; + if (radioButtonIcon == null) + radioButtonIcon = new RadioButtonIcon(); + return radioButtonIcon; } + public static Icon getCheckBoxMenuItemIcon() { return getCheckBoxIcon(); diff --git a/javax/swing/plaf/basic/BasicInternalFrameTitlePane.java b/javax/swing/plaf/basic/BasicInternalFrameTitlePane.java index f3939ac6b..92a6ea0bf 100644 --- a/javax/swing/plaf/basic/BasicInternalFrameTitlePane.java +++ b/javax/swing/plaf/basic/BasicInternalFrameTitlePane.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -253,11 +253,29 @@ public class BasicInternalFrameTitlePane extends JComponent */ public void propertyChange(PropertyChangeEvent evt) { - // The title and frameIcon are taken care of during painting time. - // The only other thing this will care about are the "is----izable" - // properties. So we call enable actions to properly handle the - // buttons and menu items for us. - enableActions(); + String propName = evt.getPropertyName(); + if (propName.equals("closable")) + { + if (evt.getNewValue().equals(Boolean.TRUE)) + closeButton.setVisible(true); + else + closeButton.setVisible(false); + } + else if (propName.equals("iconifiable")) + { + if (evt.getNewValue().equals(Boolean.TRUE)) + iconButton.setVisible(true); + else + iconButton.setVisible(false); + } + else if (propName.equals("maximizable")) + { + if (evt.getNewValue().equals(Boolean.TRUE)) + maxButton.setVisible(true); + else + maxButton.setVisible(false); + } + } } @@ -349,48 +367,36 @@ public class BasicInternalFrameTitlePane extends JComponent */ public void layoutContainer(Container c) { - enableActions(); - + Dimension size = c.getSize(); Insets insets = c.getInsets(); - int width = c.getBounds().width - insets.left - insets.right; - int height = c.getBounds().height - insets.top - insets.bottom; + int width = size.width - insets.left - insets.right; + int height = size.height - insets.top - insets.bottom; // MenuBar is always present and located at the top left corner. Dimension menupref = menuBar.getPreferredSize(); menuBar.setBounds(insets.left, insets.top, menupref.width, height); - int loc = width + insets.left; - - Insets i = closeButton.getInsets(); - Dimension prefs = new Dimension(iconSize + i.left + i.right, - iconSize + i.top + i.bottom); - int top = insets.top + (height - prefs.height) / 2; - if (closeAction.isEnabled()) + int loc = width + insets.left - 1; + int top = insets.top + 1; + int buttonWidth = height - 2; + int buttonHeight = height - 4; + if (closeButton.isVisible()) { - loc -= prefs.width; - closeButton.setVisible(true); - closeButton.setBounds(loc, top, prefs.width, prefs.height); + loc -= buttonWidth + 2; + closeButton.setBounds(loc, top, buttonWidth, buttonHeight); } - else - closeButton.setVisible(false); - if (maximizeAction.isEnabled()) + if (maxButton.isVisible()) { - loc -= prefs.width; - maxButton.setVisible(true); - maxButton.setBounds(loc, top, prefs.width, prefs.height); + loc -= buttonWidth + 2; + maxButton.setBounds(loc, top, buttonWidth, buttonHeight); } - else - maxButton.setVisible(false); - if (iconifyAction.isEnabled()) + if (iconButton.isVisible()) { - loc -= prefs.width; - iconButton.setVisible(true); - iconButton.setBounds(loc, top, prefs.width, prefs.height); + loc -= buttonWidth + 2; + iconButton.setBounds(loc, top, buttonWidth, buttonHeight); } - else - iconButton.setVisible(false); if (title != null) title.setBounds(insets.left + menupref.width, insets.top, @@ -420,26 +426,7 @@ public class BasicInternalFrameTitlePane extends JComponent */ public Dimension preferredLayoutSize(Container c) { - Insets frameInsets = frame.getInsets(); - - // Height is the max of the preferredHeights of all components - // inside the pane - int height = 0; - int width = 0; - Dimension d; - - Component[] components = BasicInternalFrameTitlePane.this.getComponents(); - for (int i = 0; i < components.length; i++) - { - d = components[i].getPreferredSize(); - height = Math.max(height, d.height); - width += d.width; - } - - Insets insets = BasicInternalFrameTitlePane.this.getInsets(); - height += insets.top + insets.bottom; - - return new Dimension(width, height); + return new Dimension(22, 18); } /** @@ -468,7 +455,6 @@ public class BasicInternalFrameTitlePane extends JComponent { super(a); setMargin(new Insets(0, 0, 0, 0)); - setBorder(null); } /** @@ -540,110 +526,14 @@ public class BasicInternalFrameTitlePane extends JComponent /** Inactive foreground color. */ protected Color inactiveFGColor; - // FIXME: These icons need to be moved to MetalIconFactory. - - /** The size of the icons in the buttons. */ - private static final int iconSize = 16; - - /** The icon displayed in the close button. */ - protected Icon closeIcon = new Icon() - { - public int getIconHeight() - { - return iconSize; - } - - public int getIconWidth() - { - return iconSize; - } - - public void paintIcon(Component c, Graphics g, int x, int y) - { - g.translate(x, y); - Color saved = g.getColor(); - g.setColor(Color.BLACK); - - int four = iconSize / 4; - int six = iconSize * 6 / 16; - int ten = iconSize * 10 / 16; - int twelve = iconSize * 12 / 16; - - Polygon a = new Polygon(new int[] { four, six, ten, twelve }, - new int[] { six, four, twelve, ten }, 4); - Polygon b = new Polygon(new int[] { four, six, ten, twelve }, - new int[] { ten, twelve, four, six }, 4); - - g.fillPolygon(a); - g.fillPolygon(b); - - g.setColor(saved); - g.translate(-x, -y); - } - }; - - // FIXME: Create new icon. - /** The icon displayed in the restore button. */ - protected Icon minIcon; + protected Icon minIcon = BasicIconFactory.createEmptyFrameIcon(); /** The icon displayed in the maximize button. */ - protected Icon maxIcon = new Icon() - { - public int getIconHeight() - { - return iconSize; - } - - public int getIconWidth() - { - return iconSize; - } - - public void paintIcon(Component c, Graphics g, int x, int y) - { - g.translate(x, y); - Color saved = g.getColor(); - g.setColor(Color.BLACK); - - int four = iconSize / 4; - int two = four / 2; - int six = iconSize * 6 / 16; - int eight = four * 2; - - g.fillRect(four, four, eight, two); - g.drawRect(four, six, eight, six); - - g.setColor(saved); - g.translate(-x, -y); - } - }; + protected Icon maxIcon = BasicIconFactory.createEmptyFrameIcon(); /** The icon displayed in the iconify button. */ - protected Icon iconIcon = new Icon() - { - public int getIconHeight() - { - return iconSize; - } - - public int getIconWidth() - { - return iconSize; - } - - public void paintIcon(Component c, Graphics g, int x, int y) - { - g.translate(x, y); - Color saved = g.getColor(); - g.setColor(Color.BLACK); - - g.fillRect(iconSize / 4, iconSize * 10 / 16, iconSize / 2, iconSize / 8); - - g.setColor(saved); - g.translate(-x, -y); - } - }; + protected Icon iconIcon = BasicIconFactory.createEmptyFrameIcon(); /** The JInternalFrame that this TitlePane is used in. */ protected JInternalFrame frame; @@ -702,6 +592,7 @@ public class BasicInternalFrameTitlePane extends JComponent setOpaque(true); setBackground(Color.LIGHT_GRAY); + setOpaque(true); installTitlePane(); } @@ -813,26 +704,23 @@ public class BasicInternalFrameTitlePane extends JComponent protected void createButtons() { closeButton = new PaneButton(closeAction); - closeButton.setOpaque(false); - + if (!frame.isClosable()) + closeButton.setVisible(false); iconButton = new PaneButton(iconifyAction); - iconButton.setOpaque(false); - + if (!frame.isIconifiable()) + iconButton.setVisible(false); maxButton = new PaneButton(maximizeAction); - maxButton.setOpaque(false); + if (!frame.isMaximizable()) + maxButton.setVisible(false); } /** - * This method sets the icons in the buttons. + * This method sets the icons in the buttons. This is a no-op method here, it + * can be overridden by subclasses to set icons for the minimize-, maximize- + * and close-buttons. */ protected void setButtonIcons() { - if (closeButton != null) - closeButton.setIcon(closeIcon); - if (iconButton != null) - iconButton.setIcon(iconIcon); - if (maxButton != null) - maxButton.setIcon(maxIcon); } /** diff --git a/javax/swing/plaf/basic/BasicInternalFrameUI.java b/javax/swing/plaf/basic/BasicInternalFrameUI.java index 088c26272..3febe58f4 100644 --- a/javax/swing/plaf/basic/BasicInternalFrameUI.java +++ b/javax/swing/plaf/basic/BasicInternalFrameUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -53,7 +53,10 @@ import java.awt.event.ComponentListener; import java.awt.event.MouseEvent; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; +import java.beans.PropertyVetoException; +import java.beans.VetoableChangeListener; +import javax.swing.BorderFactory; import javax.swing.DefaultDesktopManager; import javax.swing.DesktopManager; import javax.swing.JComponent; @@ -62,11 +65,16 @@ import javax.swing.JInternalFrame; import javax.swing.KeyStroke; import javax.swing.SwingConstants; import javax.swing.SwingUtilities; +import javax.swing.UIDefaults; +import javax.swing.UIManager; import javax.swing.border.AbstractBorder; +import javax.swing.border.BevelBorder; +import javax.swing.border.Border; import javax.swing.event.InternalFrameEvent; import javax.swing.event.InternalFrameListener; import javax.swing.event.MouseInputAdapter; import javax.swing.event.MouseInputListener; +import javax.swing.plaf.BorderUIResource; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.InternalFrameUI; import javax.swing.plaf.UIResource; @@ -642,6 +650,9 @@ public class BasicInternalFrameUI extends InternalFrameUI /** The last component entered. */ private transient Component lastComponentEntered; + /** Used to store/reset lastComponentEntered. */ + private transient Component tempComponent; + /** The number of presses. */ private transient int pressCount; @@ -762,8 +773,9 @@ public class BasicInternalFrameUI extends InternalFrameUI tp.x, tp.y, me.getClickCount(), me.isPopupTrigger(), me.getButton()); - lastComponentEntered.dispatchEvent(exited); + tempComponent = lastComponentEntered; lastComponentEntered = null; + tempComponent.dispatchEvent(exited); } // If we have a candidate, maybe enter it. @@ -864,8 +876,32 @@ public class BasicInternalFrameUI extends InternalFrameUI * JInternalFrame. */ public class InternalFramePropertyChangeListener - implements PropertyChangeListener + implements PropertyChangeListener, VetoableChangeListener { + + /** + * This method is called when one of the JInternalFrame's properties + * change. This method is to allow JInternalFrame to veto an attempt + * to close the internal frame. This allows JInternalFrame to honour + * its defaultCloseOperation if that is DO_NOTHING_ON_CLOSE. + */ + public void vetoableChange(PropertyChangeEvent e) throws PropertyVetoException + { + if (e.getPropertyName().equals(JInternalFrame.IS_CLOSED_PROPERTY)) + { + if (frame.getDefaultCloseOperation() == JInternalFrame.HIDE_ON_CLOSE) + { + frame.setVisible(false); + frame.getDesktopPane().repaint(); + throw new PropertyVetoException ("close operation is HIDE_ON_CLOSE\n", e); + } + else if (frame.getDefaultCloseOperation() == JInternalFrame.DISPOSE_ON_CLOSE) + closeFrame(frame); + else + throw new PropertyVetoException ("close operation is DO_NOTHING_ON_CLOSE\n", e); + } + } + /** * This method is called when one of the JInternalFrame's properties * change. @@ -881,8 +917,6 @@ public class BasicInternalFrameUI extends InternalFrameUI else minimizeFrame(frame); } - else if (evt.getPropertyName().equals(JInternalFrame.IS_CLOSED_PROPERTY)) - closeFrame(frame); else if (evt.getPropertyName().equals(JInternalFrame.IS_ICON_PROPERTY)) { if (frame.isIcon()) @@ -1031,6 +1065,13 @@ public class BasicInternalFrameUI extends InternalFrameUI */ protected PropertyChangeListener propertyChangeListener; + /** + * The VetoableChangeListener. Listens to PropertyChangeEvents + * from the JInternalFrame and allows the JInternalFrame to + * veto attempts to close it. + */ + private VetoableChangeListener internalFrameVetoableChangeListener; + /** The InternalFrameListener that listens to the JInternalFrame. */ private transient BasicInternalFrameListener internalFrameListener; @@ -1109,7 +1150,6 @@ public class BasicInternalFrameUI extends InternalFrameUI installKeyboardActions(); frame.setOpaque(true); - titlePane.setOpaque(true); frame.invalidate(); } } @@ -1137,9 +1177,31 @@ public class BasicInternalFrameUI extends InternalFrameUI * This method installs the defaults specified by the look and feel. */ protected void installDefaults() - { - // FIXME: Move border to MetalBorders - frame.setBorder(new InternalFrameBorder()); + { + // This is the border of InternalFrames in the BasicLookAndFeel. + // Note that there exist entries for various border colors in + // BasicLookAndFeel's defaults, but obviously they differ + // from the colors that are actually used by the JDK. + UIDefaults defaults = UIManager.getLookAndFeelDefaults(); + Color borderColor = defaults.getColor("InternalFrame.borderColor"); + Border inner = BorderFactory.createLineBorder(borderColor, 1); + Color borderDarkShadow = defaults.getColor + ("InternalFrame.borderDarkShadow"); + Color borderHighlight = defaults.getColor + ("InternalFrame.borderHighlight"); + Color borderShadow = defaults.getColor("InternalFrame.borderShadow"); + Color borderLight = defaults.getColor("InternalFrame.borderLight"); + Border outer = BorderFactory.createBevelBorder(BevelBorder.RAISED, + borderShadow, + borderHighlight, + borderDarkShadow, + borderShadow); + Border border = new BorderUIResource.CompoundBorderUIResource(outer, + inner); + frame.setBorder(border); + frame.setFrameIcon(defaults.getIcon("InternalFrame.icon")); + // InternalFrames are invisible by default. + frame.setVisible(false); } /** @@ -1171,12 +1233,13 @@ public class BasicInternalFrameUI extends InternalFrameUI borderListener = createBorderListener(frame); componentListener = createComponentListener(); propertyChangeListener = createPropertyChangeListener(); + internalFrameVetoableChangeListener = new InternalFramePropertyChangeListener(); frame.addMouseListener(borderListener); frame.addMouseMotionListener(borderListener); frame.addInternalFrameListener(internalFrameListener); frame.addPropertyChangeListener(propertyChangeListener); - + frame.addVetoableChangeListener(internalFrameVetoableChangeListener); frame.getRootPane().getGlassPane().addMouseListener(glassPaneDispatcher); frame.getRootPane().getGlassPane().addMouseMotionListener(glassPaneDispatcher); } @@ -1552,7 +1615,10 @@ public class BasicInternalFrameUI extends InternalFrameUI */ protected DesktopManager getDesktopManager() { - DesktopManager value = frame.getDesktopPane().getDesktopManager(); + DesktopManager value = null; + JDesktopPane pane = frame.getDesktopPane(); + if (pane != null) + value = frame.getDesktopPane().getDesktopManager(); if (value == null) value = createDesktopManager(); return value; diff --git a/javax/swing/plaf/basic/BasicLabelUI.java b/javax/swing/plaf/basic/BasicLabelUI.java index b278f1f59..e71e82f03 100644 --- a/javax/swing/plaf/basic/BasicLabelUI.java +++ b/javax/swing/plaf/basic/BasicLabelUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -92,7 +92,8 @@ public class BasicLabelUI extends LabelUI implements PropertyChangeListener /** * Returns the preferred size of this component as calculated by the - * {@link layoutCL} method. + * {@link #layoutCL(JLabel, FontMetrics, String, Icon, Rectangle, Rectangle, + * Rectangle)} method. * * @param c This {@link JComponent} to get a preferred size for. * @@ -350,8 +351,6 @@ public class BasicLabelUI extends LabelUI implements PropertyChangeListener c.setForeground(defaults.getColor("Label.foreground")); c.setBackground(defaults.getColor("Label.background")); c.setFont(defaults.getFont("Label.font")); - c.setBorder(defaults.getBorder("Label.border")); - c.setOpaque(true); //XXX: There are properties we don't use called disabledForeground //and disabledShadow. } @@ -367,7 +366,6 @@ public class BasicLabelUI extends LabelUI implements PropertyChangeListener c.setForeground(null); c.setBackground(null); c.setFont(null); - c.setBorder(null); } /** diff --git a/javax/swing/plaf/basic/BasicListUI.java b/javax/swing/plaf/basic/BasicListUI.java index baaa04655..841bd670f 100644 --- a/javax/swing/plaf/basic/BasicListUI.java +++ b/javax/swing/plaf/basic/BasicListUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -49,6 +49,9 @@ import java.awt.event.ComponentEvent; import java.awt.event.ComponentListener; import java.awt.event.FocusEvent; import java.awt.event.FocusListener; +import java.awt.event.InputEvent; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; @@ -93,7 +96,7 @@ public class BasicListUI extends ListUI } /** - * A helper class which listens for {@link FocusEvents} + * A helper class which listens for {@link FocusEvent}s * from the JList. */ public class FocusHandler implements FocusListener @@ -131,7 +134,7 @@ public class BasicListUI extends ListUI * A helper class which listens for {@link ListDataEvent}s generated by * the {@link JList}'s {@link ListModel}. * - * @see javax.swing.JList#model + * @see javax.swing.JList#getModel() */ public class ListDataHandler implements ListDataListener { @@ -184,6 +187,138 @@ public class BasicListUI extends ListUI } /** + * A helper class which listens for {@link KeyEvents}s + * from the {@link JList}. + */ + private class KeyHandler extends KeyAdapter + { + public KeyHandler() + { + } + + public void keyPressed( KeyEvent evt ) + { + int lead = BasicListUI.this.list.getLeadSelectionIndex(); + int max = BasicListUI.this.list.getModel().getSize() - 1; + // Do nothing if list is empty + if (max == -1) + return; + + // Process the key event. Bindings can be found in + // javax.swing.plaf.basic.BasicLookAndFeel.java + if ((evt.getKeyCode() == KeyEvent.VK_DOWN) + || (evt.getKeyCode() == KeyEvent.VK_KP_DOWN)) + { + if (evt.getModifiers() == 0) + { + BasicListUI.this.list.clearSelection(); + BasicListUI.this.list.setSelectedIndex(Math.min(lead+1,max)); + } + else if (evt.getModifiers() == InputEvent.SHIFT_MASK) + { + BasicListUI.this.list.getSelectionModel(). + setLeadSelectionIndex(Math.min(lead+1,max)); + } + } + else if ((evt.getKeyCode() == KeyEvent.VK_UP) + || (evt.getKeyCode() == KeyEvent.VK_KP_UP)) + { + if (evt.getModifiers() == 0) + { + BasicListUI.this.list.clearSelection(); + BasicListUI.this.list.setSelectedIndex(Math.max(lead-1,0)); + } + else if (evt.getModifiers() == InputEvent.SHIFT_MASK) + { + BasicListUI.this.list.getSelectionModel(). + setLeadSelectionIndex(Math.max(lead-1,0)); + } + } + else if (evt.getKeyCode() == KeyEvent.VK_PAGE_UP) + { + int target; + if (lead == BasicListUI.this.list.getFirstVisibleIndex()) + { + target = Math.max + (0, lead - (BasicListUI.this.list.getLastVisibleIndex() - + BasicListUI.this.list.getFirstVisibleIndex() + 1)); + } + else + { + target = BasicListUI.this.list.getFirstVisibleIndex(); + } + if (evt.getModifiers() == 0) + BasicListUI.this.list.setSelectedIndex(target); + else if (evt.getModifiers() == InputEvent.SHIFT_MASK) + BasicListUI.this.list.getSelectionModel(). + setLeadSelectionIndex(target); + } + else if (evt.getKeyCode() == KeyEvent.VK_PAGE_DOWN) + { + int target; + if (lead == BasicListUI.this.list.getLastVisibleIndex()) + { + target = Math.min + (max, lead + (BasicListUI.this.list.getLastVisibleIndex() - + BasicListUI.this.list.getFirstVisibleIndex() + 1)); + } + else + { + target = BasicListUI.this.list.getLastVisibleIndex(); + } + if (evt.getModifiers() == 0) + BasicListUI.this.list.setSelectedIndex(target); + else if (evt.getModifiers() == InputEvent.SHIFT_MASK) + BasicListUI.this.list.getSelectionModel(). + setLeadSelectionIndex(target); + } + else if (evt.getKeyCode() == KeyEvent.VK_BACK_SLASH + && (evt.getModifiers() == InputEvent.CTRL_MASK)) + { + BasicListUI.this.list.clearSelection(); + } + else if ((evt.getKeyCode() == KeyEvent.VK_HOME) + || evt.getKeyCode() == KeyEvent.VK_END) + { + if (evt.getModifiers() != 0 && + evt.getModifiers() != InputEvent.SHIFT_MASK) + return; + // index is either 0 for HOME, or last cell for END + int index = (evt.getKeyCode() == KeyEvent.VK_HOME) ? 0 : max; + + if (!evt.isShiftDown() ||(BasicListUI.this.list.getSelectionMode() + == ListSelectionModel.SINGLE_SELECTION)) + BasicListUI.this.list.setSelectedIndex(index); + else if (BasicListUI.this.list.getSelectionMode() == + ListSelectionModel.SINGLE_INTERVAL_SELECTION) + BasicListUI.this.list.setSelectionInterval + (BasicListUI.this.list.getAnchorSelectionIndex(), index); + else + BasicListUI.this.list.getSelectionModel(). + setLeadSelectionIndex(index); + } + else if ((evt.getKeyCode() == KeyEvent.VK_A || evt.getKeyCode() + == KeyEvent.VK_SLASH) && (evt.getModifiers() == + InputEvent.CTRL_MASK)) + { + BasicListUI.this.list.setSelectionInterval(0, max); + // this next line is to restore the lead selection index to the old + // position, because select-all should not change the lead index + BasicListUI.this.list.addSelectionInterval(lead, lead); + } + else if (evt.getKeyCode() == KeyEvent.VK_SPACE && + (evt.getModifiers() == InputEvent.CTRL_MASK)) + { + BasicListUI.this.list.getSelectionModel(). + setLeadSelectionIndex(Math.min(lead+1,max)); + } + + BasicListUI.this.list.ensureIndexIsVisible + (BasicListUI.this.list.getLeadSelectionIndex()); + } + } + + /** * A helper class which listens for {@link MouseEvent}s * from the {@link JList}. */ @@ -197,6 +332,49 @@ public class BasicListUI extends ListUI */ public void mouseClicked(MouseEvent event) { + Point click = event.getPoint(); + int index = BasicListUI.this.locationToIndex(list, click); + if (index == -1) + return; + if (event.isShiftDown()) + { + if (BasicListUI.this.list.getSelectionMode() == + ListSelectionModel.SINGLE_SELECTION) + BasicListUI.this.list.setSelectedIndex(index); + else if (BasicListUI.this.list.getSelectionMode() == + ListSelectionModel.SINGLE_INTERVAL_SELECTION) + // COMPAT: the IBM VM is compatible with the following line of code. + // However, compliance with Sun's VM would correspond to replacing + // getAnchorSelectionIndex() with getLeadSelectionIndex().This is + // both unnatural and contradictory to the way they handle other + // similar UI interactions. + BasicListUI.this.list.setSelectionInterval + (BasicListUI.this.list.getAnchorSelectionIndex(), index); + else + // COMPAT: both Sun and IBM are compatible instead with: + // BasicListUI.this.list.setSelectionInterval + // (BasicListUI.this.list.getLeadSelectionIndex(),index); + // Note that for IBM this is contradictory to what they did in + // the above situation for SINGLE_INTERVAL_SELECTION. + // The most natural thing to do is the following: + BasicListUI.this.list.getSelectionModel(). + setLeadSelectionIndex(index); + } + else if (event.isControlDown()) + { + if (BasicListUI.this.list.getSelectionMode() == + ListSelectionModel.SINGLE_SELECTION) + BasicListUI.this.list.setSelectedIndex(index); + else if (BasicListUI.this.list.isSelectedIndex(index)) + BasicListUI.this.list.removeSelectionInterval(index,index); + else + BasicListUI.this.list.addSelectionInterval(index,index); + } + else + BasicListUI.this.list.setSelectedIndex(index); + + BasicListUI.this.list.ensureIndexIsVisible + (BasicListUI.this.list.getLeadSelectionIndex()); } /** @@ -207,12 +385,6 @@ public class BasicListUI extends ListUI */ public void mousePressed(MouseEvent event) { - Point click = event.getPoint(); - int index = BasicListUI.this.locationToIndex(list, click); - if (index == -1) - return; - - BasicListUI.this.list.setSelectedIndex(index); } /** @@ -315,6 +487,9 @@ public class BasicListUI extends ListUI /** The mouse listener listening to the list. */ protected MouseInputListener mouseInputListener; + /** The key listener listening to the list */ + private KeyHandler keyListener; + /** The property change listener listening to the list. */ protected PropertyChangeListener propertyChangeListener; @@ -499,8 +674,6 @@ public class BasicListUI extends ListUI void damageLayout() { updateLayoutStateNeeded = 1; - if (list != null) - list.revalidate(); } /** @@ -525,6 +698,7 @@ public class BasicListUI extends ListUI listDataListener = new ListDataHandler(); listSelectionListener = new ListSelectionHandler(); mouseInputListener = new MouseInputHandler(); + keyListener = new KeyHandler(); propertyChangeListener = new PropertyChangeHandler(); componentListener = new ComponentHandler(); updateLayoutStateNeeded = 1; @@ -572,6 +746,7 @@ public class BasicListUI extends ListUI list.getModel().addListDataListener(listDataListener); list.addListSelectionListener(listSelectionListener); list.addMouseListener(mouseInputListener); + list.addKeyListener(keyListener); list.addMouseMotionListener(mouseInputListener); list.addPropertyChangeListener(propertyChangeListener); list.addComponentListener(componentListener); @@ -586,6 +761,7 @@ public class BasicListUI extends ListUI list.getModel().removeListDataListener(listDataListener); list.removeListSelectionListener(listSelectionListener); list.removeMouseListener(mouseInputListener); + list.removeKeyListener(keyListener); list.removeMouseMotionListener(mouseInputListener); list.removePropertyChangeListener(propertyChangeListener); } @@ -711,11 +887,11 @@ public class BasicListUI extends ListUI ListCellRenderer rend, ListModel data, ListSelectionModel sel, int lead) { - boolean is_sel = list.isSelectedIndex(row); - boolean has_focus = false; + boolean isSel = list.isSelectedIndex(row); + boolean hasFocus = (list.getLeadSelectionIndex() == row) && BasicListUI.this.list.hasFocus(); Component comp = rend.getListCellRendererComponent(list, data.getElementAt(row), - 0, is_sel, has_focus); + 0, isSel, hasFocus); //comp.setBounds(new Rectangle(0, 0, bounds.width, bounds.height)); //comp.paint(g); rendererPane.paintComponent(g, comp, list, bounds); diff --git a/javax/swing/plaf/basic/BasicLookAndFeel.java b/javax/swing/plaf/basic/BasicLookAndFeel.java index 67cf25057..54d91d888 100644 --- a/javax/swing/plaf/basic/BasicLookAndFeel.java +++ b/javax/swing/plaf/basic/BasicLookAndFeel.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -47,10 +47,12 @@ import java.io.Serializable; import java.util.Enumeration; import java.util.ResourceBundle; -import javax.swing.ImageIcon; +import javax.swing.BorderFactory; import javax.swing.KeyStroke; import javax.swing.LookAndFeel; import javax.swing.UIDefaults; +import javax.swing.border.BevelBorder; +import javax.swing.border.Border; import javax.swing.plaf.BorderUIResource; import javax.swing.plaf.ColorUIResource; import javax.swing.plaf.DimensionUIResource; @@ -69,7 +71,7 @@ public abstract class BasicLookAndFeel extends LookAndFeel static final long serialVersionUID = -6096995660290287879L; /** - * Constructor BasicLookAndFeel + * Creates a new instance of the Basic look and feel. */ public BasicLookAndFeel() { @@ -77,8 +79,10 @@ public abstract class BasicLookAndFeel extends LookAndFeel } /** - * getDefaults - * @return UIDefaults + * Creates and returns a new instance of the default resources for this look + * and feel. + * + * @return The UI defaults. */ public UIDefaults getDefaults() { @@ -95,8 +99,10 @@ public abstract class BasicLookAndFeel extends LookAndFeel } /** - * initClassDefaults - * @param value0 TODO + * Populates the <code>defaults</code> table with mappings between class IDs + * and fully qualified class names for the UI delegates. + * + * @param defaults the defaults table (<code>null</code> not permitted). */ protected void initClassDefaults(UIDefaults defaults) { @@ -155,8 +161,9 @@ public abstract class BasicLookAndFeel extends LookAndFeel } /** - * initSystemColorDefaults - * @param defaults TODO + * Populates the <code>defaults</code> table with system color defaults. + * + * @param defaults the defaults table (<code>null</code> not permitted). */ protected void initSystemColorDefaults(UIDefaults defaults) { @@ -198,13 +205,14 @@ public abstract class BasicLookAndFeel extends LookAndFeel } /** - * loadSystemColors - * @param defaults TODO - * @param value1 TODO - * @param value2 TODO + * Loads the system colors. This method is not implemented yet. + * + * @param defaults the defaults table (<code>null</code> not permitted). + * @param systemColors TODO + * @param useNative TODO */ - protected void loadSystemColors(UIDefaults defaults, String[] value1, - boolean value2) + protected void loadSystemColors(UIDefaults defaults, String[] systemColors, + boolean useNative) { // TODO } @@ -232,7 +240,7 @@ public abstract class BasicLookAndFeel extends LookAndFeel /** * initComponentDefaults - * @param defaults TODO + * @param defaults the defaults table (<code>null</code> not permitted). */ protected void initComponentDefaults(UIDefaults defaults) { @@ -247,7 +255,7 @@ public abstract class BasicLookAndFeel extends LookAndFeel "AbstractUndoableEdit.undoText", "Undo", "AbstractUndoableEdit.redoText", "Redo", - "Button.background", new ColorUIResource(light), + "Button.background", new ColorUIResource(Color.LIGHT_GRAY), "Button.border", new UIDefaults.LazyValue() { @@ -256,17 +264,17 @@ public abstract class BasicLookAndFeel extends LookAndFeel return BasicBorders.getButtonBorder(); } }, - "Button.darkShadow", new ColorUIResource(shadow), + "Button.darkShadow", new ColorUIResource(Color.BLACK), "Button.focusInputMap", new UIDefaults.LazyInputMap(new Object[] { "SPACE", "pressed", "released SPACE", "released" }), "Button.font", new FontUIResource("Dialog", Font.PLAIN, 12), - "Button.foreground", new ColorUIResource(darkShadow), - "Button.highlight", new ColorUIResource(highLight), - "Button.light", new ColorUIResource(highLight), + "Button.foreground", new ColorUIResource(Color.BLACK), + "Button.highlight", new ColorUIResource(Color.WHITE), + "Button.light", new ColorUIResource(Color.LIGHT_GRAY), "Button.margin", new InsetsUIResource(2, 2, 2, 2), - "Button.shadow", new ColorUIResource(shadow), + "Button.shadow", new ColorUIResource(Color.GRAY), "Button.textIconGap", new Integer(4), "Button.textShiftOffset", new Integer(0), "CheckBox.background", new ColorUIResource(light), @@ -278,7 +286,14 @@ public abstract class BasicLookAndFeel extends LookAndFeel }), "CheckBox.font", new FontUIResource("Dialog", Font.PLAIN, 12), "CheckBox.foreground", new ColorUIResource(darkShadow), - "CheckBox.icon", BasicIconFactory.getCheckBoxIcon(), + "CheckBox.icon", + new UIDefaults.LazyValue() + { + public Object createValue(UIDefaults def) + { + return BasicIconFactory.getCheckBoxIcon(); + } + }, "CheckBox.margin",new InsetsUIResource(2, 2, 2, 2), "CheckBox.textIconGap", new Integer(4), "CheckBox.textShiftOffset", new Integer(0), @@ -449,15 +464,39 @@ public abstract class BasicLookAndFeel extends LookAndFeel "InternalFrame.activeTitleBackground", new ColorUIResource(0, 0, 128), "InternalFrame.activeTitleForeground", new ColorUIResource(Color.white), "InternalFrame.border", - new BorderUIResource.CompoundBorderUIResource(null, null), + new UIDefaults.LazyValue() + { + public Object createValue(UIDefaults table) + { + Color lineColor = new Color(238, 238, 238); + Border inner = BorderFactory.createLineBorder(lineColor, 1); + Color shadowInner = new Color(184, 207, 229); + Color shadowOuter = new Color(122, 138, 153); + Border outer = BorderFactory.createBevelBorder(BevelBorder.RAISED, + Color.WHITE, + Color.WHITE, + shadowOuter, + shadowInner); + Border border = new BorderUIResource.CompoundBorderUIResource(outer, + inner); + return border; + } + }, "InternalFrame.borderColor", new ColorUIResource(light), - "InternalFrame.borderDarkShadow", new ColorUIResource(shadow), - "InternalFrame.borderHighlight", new ColorUIResource(highLight), - "InternalFrame.borderLight", new ColorUIResource(light), - "InternalFrame.borderShadow", new ColorUIResource(shadow), + "InternalFrame.borderDarkShadow", new ColorUIResource(Color.BLACK), + "InternalFrame.borderHighlight", new ColorUIResource(Color.WHITE), + "InternalFrame.borderLight", new ColorUIResource(Color.LIGHT_GRAY), + "InternalFrame.borderShadow", new ColorUIResource(Color.GRAY), "InternalFrame.closeIcon", BasicIconFactory.createEmptyFrameIcon(), - // XXX Don't use gif -// "InternalFrame.icon", new IconUIResource(new ImageIcon("icons/JavaCup.gif")), + // FIXME: Set a nice icon for InternalFrames here. + "InternalFrame.icon", + new UIDefaults.LazyValue() + { + public Object createValue(UIDefaults def) + { + return new IconUIResource(BasicIconFactory.createEmptyFrameIcon()); + } + }, "InternalFrame.iconifyIcon", BasicIconFactory.createEmptyFrameIcon(), "InternalFrame.inactiveTitleBackground", new ColorUIResource(Color.gray), "InternalFrame.inactiveTitleForeground", @@ -500,6 +539,9 @@ public abstract class BasicLookAndFeel extends LookAndFeel "List.foreground", new ColorUIResource(darkShadow), "List.selectionBackground", new ColorUIResource(Color.black), "List.selectionForeground", new ColorUIResource(Color.white), + "List.focusCellHighlightBorder", + new BorderUIResource. + LineBorderUIResource(new ColorUIResource(Color.yellow)), "Menu.acceleratorFont", new FontUIResource("Dialog", Font.PLAIN, 12), "Menu.acceleratorForeground", new ColorUIResource(darkShadow), "Menu.acceleratorSelectionForeground", new ColorUIResource(Color.white), @@ -625,7 +667,14 @@ public abstract class BasicLookAndFeel extends LookAndFeel "RadioButton.font", new FontUIResource("Dialog", Font.PLAIN, 12), "RadioButton.foreground", new ColorUIResource(darkShadow), "RadioButton.highlight", new ColorUIResource(highLight), - "RadioButton.icon", BasicIconFactory.getRadioButtonIcon(), + "RadioButton.icon", + new UIDefaults.LazyValue() + { + public Object createValue(UIDefaults def) + { + return BasicIconFactory.getRadioButtonIcon(); + } + }, "RadioButton.light", new ColorUIResource(highLight), "RadioButton.margin", new InsetsUIResource(2, 2, 2, 2), "RadioButton.shadow", new ColorUIResource(shadow), @@ -724,7 +773,7 @@ public abstract class BasicLookAndFeel extends LookAndFeel "Slider.highlight", new ColorUIResource(highLight), "Slider.shadow", new ColorUIResource(shadow), "Slider.thumbHeight", new Integer(20), - "Slider.thumbWidth", new Integer(10), + "Slider.thumbWidth", new Integer(11), "Slider.tickHeight", new Integer(12), "Spinner.background", new ColorUIResource(light), "Spinner.foreground", new ColorUIResource(light), @@ -826,7 +875,8 @@ public abstract class BasicLookAndFeel extends LookAndFeel "Table.focusCellBackground", new ColorUIResource(light), "Table.focusCellForeground", new ColorUIResource(darkShadow), "Table.focusCellHighlightBorder", - new BorderUIResource.LineBorderUIResource(Color.white), + new BorderUIResource.LineBorderUIResource( + new ColorUIResource(255, 255, 0)), "Table.font", new FontUIResource("Dialog", Font.PLAIN, 12), "Table.foreground", new ColorUIResource(darkShadow), "Table.gridColor", new ColorUIResource(Color.gray), @@ -838,7 +888,7 @@ public abstract class BasicLookAndFeel extends LookAndFeel "TableHeader.font", new FontUIResource("Dialog", Font.PLAIN, 12), "TableHeader.foreground", new ColorUIResource(darkShadow), - "TextArea.background", new ColorUIResource(light), + "TextArea.background", new ColorUIResource(light), "TextArea.border", new BasicBorders.MarginBorder(), "TextArea.caretBlinkRate", new Integer(500), "TextArea.caretForeground", new ColorUIResource(Color.black), @@ -879,11 +929,11 @@ public abstract class BasicLookAndFeel extends LookAndFeel 0), "notify-field-accept"), new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, - InputEvent.SHIFT_DOWN_MASK), - "selection-backward"), + InputEvent.SHIFT_DOWN_MASK), + "selection-backward"), new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, - InputEvent.SHIFT_DOWN_MASK), - "selection-forward"), + InputEvent.SHIFT_DOWN_MASK), + "selection-forward"), }, "TextField.margin", new InsetsUIResource(0, 0, 0, 0), "TextField.selectionBackground", new ColorUIResource(Color.black), @@ -1011,20 +1061,18 @@ public abstract class BasicLookAndFeel extends LookAndFeel "PAGE_UP", "scrollUpChangeSelection", "ctrl PAGE_DOWN", "scrollDownChangeLead" }), - "Tree.font", new FontUIResource("Dialog", Font.PLAIN, 12), -// "Tree.expandedIcon", new IconUIResource(new ImageIcon("icons/TreeExpanded.png")), + "Tree.font", new FontUIResource(new Font("Helvetica", Font.PLAIN, 12)), "Tree.foreground", new ColorUIResource(Color.black), - "Tree.hash", new ColorUIResource(Color.gray), -// "Tree.leafIcon", new IconUIResource(new ImageIcon("icons/TreeLeaf.png")), + "Tree.hash", new ColorUIResource(new Color(128, 128, 128)), "Tree.leftChildIndent", new Integer(7), -// "Tree.openIcon", new IconUIResource(new ImageIcon("icons/TreeOpen.png")), "Tree.rightChildIndent", new Integer(13), - "Tree.rowHeight", new Integer(16), + "Tree.rowHeight", new Integer(20), // FIXME "Tree.scrollsOnExpand", Boolean.TRUE, "Tree.selectionBackground", new ColorUIResource(Color.black), + "Tree.nonSelectionBackground", new ColorUIResource(new Color(239, 235, 231)), "Tree.selectionBorderColor", new ColorUIResource(Color.black), - "Tree.selectionForeground", new ColorUIResource(Color.white), - "Tree.textBackground", new ColorUIResource(Color.white), + "Tree.selectionForeground", new ColorUIResource(new Color(255, 255, 255)), + "Tree.textBackground", new ColorUIResource(new Color(255, 255, 255)), "Tree.textForeground", new ColorUIResource(Color.black), "Viewport.background", new ColorUIResource(light), "Viewport.foreground", new ColorUIResource(Color.black), diff --git a/javax/swing/plaf/basic/BasicMenuBarUI.java b/javax/swing/plaf/basic/BasicMenuBarUI.java index 62b047506..95f6b84fb 100644 --- a/javax/swing/plaf/basic/BasicMenuBarUI.java +++ b/javax/swing/plaf/basic/BasicMenuBarUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -105,7 +105,7 @@ public class BasicMenuBarUI extends MenuBarUI * Factory method to create a BasicMenuBarUI for the given {@link * JComponent}, which should be a {@link JMenuBar}. * - * @param b The {@link JComponent} a UI is being created for. + * @param x The {@link JComponent} a UI is being created for. * * @return A BasicMenuBarUI for the {@link JComponent}. */ @@ -165,6 +165,7 @@ public class BasicMenuBarUI extends MenuBarUI menuBar.setBorder(defaults.getBorder("MenuBar.border")); menuBar.setFont(defaults.getFont("MenuBar.font")); menuBar.setForeground(defaults.getColor("MenuBar.foreground")); + menuBar.setOpaque(true); } /** diff --git a/javax/swing/plaf/basic/BasicMenuItemUI.java b/javax/swing/plaf/basic/BasicMenuItemUI.java index ae8b6c54c..bbacc5028 100644 --- a/javax/swing/plaf/basic/BasicMenuItemUI.java +++ b/javax/swing/plaf/basic/BasicMenuItemUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -506,11 +506,10 @@ public class BasicMenuItemUI extends MenuItemUI br.width += insets.right + insets.left; br.height += insets.top + insets.bottom; - /* Menu item is considered to be highlighted when it is selected. - It is considered to be selected if menu item is inside some menu - and is armed or if it is both armed and pressed */ - if (m.getModel().isArmed() - && (m.getParent() instanceof MenuElement || m.getModel().isPressed())) + // Menu item is considered to be highlighted when it is selected. + // But we don't want to paint the background of JCheckBoxMenuItems + if ((m.isSelected() && checkIcon == null) || m.getModel().isArmed() && + (m.getParent() instanceof MenuElement)) { if (m.isContentAreaFilled()) { @@ -606,12 +605,10 @@ public class BasicMenuItemUI extends MenuItemUI { if (menuItem.isEnabled()) { - /* Menu item is considered to be highlighted when it is selected. - It is considered to be selected if menu item is inside some menu - and is armed or if it is both armed and pressed */ - if (menuItem.getModel().isArmed() - && (menuItem.getParent() instanceof MenuElement - || menuItem.getModel().isPressed())) + // Menu item is considered to be highlighted when it is selected. + // But not if it's a JCheckBoxMenuItem + if ((menuItem.isSelected() && checkIcon == null) || menuItem.getModel().isArmed() && + (menuItem.getParent() instanceof MenuElement)) g.setColor(selectionForeground); else g.setColor(menuItem.getForeground()); @@ -619,7 +616,10 @@ public class BasicMenuItemUI extends MenuItemUI else // FIXME: should fix this to use 'disabledForeground', but its // default value in BasicLookAndFeel is null. - g.setColor(Color.gray); + + // FIXME: should there be different foreground colours for selected + // or deselected, when disabled? + g.setColor(Color.gray); int mnemonicIndex = menuItem.getDisplayedMnemonicIndex(); diff --git a/javax/swing/plaf/basic/BasicMenuUI.java b/javax/swing/plaf/basic/BasicMenuUI.java index 89daf3245..4b07d7069 100644 --- a/javax/swing/plaf/basic/BasicMenuUI.java +++ b/javax/swing/plaf/basic/BasicMenuUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -46,6 +46,7 @@ import java.beans.PropertyChangeListener; import javax.swing.JComponent; import javax.swing.JMenu; import javax.swing.JMenuBar; +import javax.swing.JMenuItem; import javax.swing.JPopupMenu; import javax.swing.MenuSelectionManager; import javax.swing.UIDefaults; @@ -179,6 +180,12 @@ public class BasicMenuUI extends BasicMenuItemUI */ public Dimension getMaximumSize(JComponent c) { + // If this menu is in a popup menu, treat it like a regular JMenuItem + if (!((JMenu)c).isTopLevelMenu()) + { + JMenuItem menuItem = new JMenuItem(((JMenu)c).getText(), ((JMenu)c).getIcon()); + return menuItem.getMaximumSize(); + } return c.getPreferredSize(); } @@ -292,19 +299,42 @@ public class BasicMenuUI extends BasicMenuItemUI manager.processMouseEvent(e); } + private boolean popupVisible() + { + JMenuBar mb = (JMenuBar) ((JMenu) menuItem).getParent(); + // check if mb.isSelected because if no menus are selected + // we don't have to look through the list for popup menus + if (!mb.isSelected()) + return false; + for (int i = 0; i < mb.getMenuCount(); i++) + { + JMenu m = mb.getMenu(i); + if (m != null && m.isPopupMenuVisible()) + return true; + } + return false; + } + public void mouseEntered(MouseEvent e) { /* When mouse enters menu item, it should be considered selected if (i) if this menu is a submenu in some other menu - (ii) or if this menu is in a menu bar and some other menu in a menu bar was just - selected. (If nothing was selected, menu should be pressed before + (ii) or if this menu is in a menu bar and some other menu in a + menu bar was just selected and has its popup menu visible. + (If nothing was selected, menu should be pressed before it will be selected) */ JMenu menu = (JMenu) menuItem; - if (! menu.isTopLevelMenu() - || (menu.isTopLevelMenu() - && (((JMenuBar) menu.getParent()).isSelected() && ! menu.isArmed()))) + + // NOTE: the following if used to require !menu.isArmed but I could find + // no reason for this and it was preventing some JDK-compatible behaviour. + // Specifically, if a menu is selected but its popup menu not visible, + // and then another menu is selected whose popup menu IS visible, when + // the mouse is moved over the first menu, its popup menu should become + // visible. + + if (! menu.isTopLevelMenu() || popupVisible()) { // set new selection and forward this event to MenuSelectionManager MenuSelectionManager manager = MenuSelectionManager.defaultManager(); @@ -419,7 +449,7 @@ public class BasicMenuUI extends BasicMenuItemUI * * @param e The PropertyChangeEvent. */ - public void propertyChange(PropertyChangeEvent evt) + public void propertyChange(PropertyChangeEvent e) { } } diff --git a/javax/swing/plaf/basic/BasicOptionPaneUI.java b/javax/swing/plaf/basic/BasicOptionPaneUI.java index 21bdf33ae..c9f623259 100644 --- a/javax/swing/plaf/basic/BasicOptionPaneUI.java +++ b/javax/swing/plaf/basic/BasicOptionPaneUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -161,8 +161,7 @@ public class BasicOptionPaneUI extends OptionPaneUI * but was made public by a compiler bug and is now * public for compatibility. */ - // FIXME: should be static - public class ButtonAreaLayout implements LayoutManager + public static class ButtonAreaLayout implements LayoutManager { /** Whether this layout will center the buttons. */ protected boolean centersChildren = true; @@ -249,7 +248,7 @@ public class BasicOptionPaneUI extends OptionPaneUI for (int i = 0; i < buttonList.length; i++) { Dimension dims = buttonList[i].getPreferredSize(); - if (getSizeButtonsToSameWidth()) + if (syncAllWidths) { buttonList[i].setBounds(x, 0, widthOfWidestButton, dims.height); x += widthOfWidestButton + getPadding(); @@ -347,7 +346,6 @@ public class BasicOptionPaneUI extends OptionPaneUI public void setCentersChildren(boolean newValue) { centersChildren = newValue; - optionPane.invalidate(); } /** @@ -358,7 +356,6 @@ public class BasicOptionPaneUI extends OptionPaneUI public void setPadding(int newPadding) { padding = newPadding; - optionPane.invalidate(); } /** @@ -369,7 +366,6 @@ public class BasicOptionPaneUI extends OptionPaneUI public void setSyncAllWidths(boolean newValue) { syncAllWidths = newValue; - optionPane.invalidate(); } } @@ -914,7 +910,9 @@ public class BasicOptionPaneUI extends OptionPaneUI */ protected Container createSeparator() { - return (Container) Box.createVerticalStrut(17); + // FIXME: Figure out what this method is supposed to return and where + // this should be added to the OptionPane. + return null; } /** @@ -1119,6 +1117,10 @@ public class BasicOptionPaneUI extends OptionPaneUI optionPane.add(msg); } + // FIXME: Figure out if the separator should be inserted here or what + // this thing is supposed to do. Note: The JDK does NOT insert another + // component at this place. The JOptionPane only has two panels in it + // and there actually are applications that depend on this beeing so. Container sep = createSeparator(); if (sep != null) optionPane.add(sep); @@ -1146,6 +1148,7 @@ public class BasicOptionPaneUI extends OptionPaneUI optionPane.setBackground(defaults.getColor("OptionPane.background")); optionPane.setForeground(defaults.getColor("OptionPane.foreground")); optionPane.setBorder(defaults.getBorder("OptionPane.border")); + optionPane.setOpaque(true); messageBorder = defaults.getBorder("OptionPane.messageAreaBorder"); messageForeground = defaults.getColor("OptionPane.messageForeground"); diff --git a/javax/swing/plaf/basic/BasicPanelUI.java b/javax/swing/plaf/basic/BasicPanelUI.java index 7e72d730d..b715c57b3 100644 --- a/javax/swing/plaf/basic/BasicPanelUI.java +++ b/javax/swing/plaf/basic/BasicPanelUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -39,18 +39,33 @@ exception statement from your version. */ package javax.swing.plaf.basic; import javax.swing.JComponent; +import javax.swing.JPanel; +import javax.swing.UIDefaults; +import javax.swing.UIManager; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.PanelUI; public class BasicPanelUI extends PanelUI { - public static ComponentUI createUI(JComponent x) - { - return new BasicPanelUI(); - } - - public void installUI(JComponent c) - { - super.installUI(c); - } + public static ComponentUI createUI(JComponent x) + { + return new BasicPanelUI(); + } + + public void installUI(JComponent c) + { + super.installUI(c); + if (c instanceof JPanel) + { + JPanel p = (JPanel) c; + installDefaults(p); + } + } + + public void installDefaults(JPanel p) + { + UIDefaults defaults = UIManager.getLookAndFeelDefaults(); + p.setBackground(defaults.getColor("Panel.background")); + p.setOpaque(true); + } } diff --git a/javax/swing/plaf/basic/BasicPasswordFieldUI.java b/javax/swing/plaf/basic/BasicPasswordFieldUI.java index 0350f7437..044027b0b 100644 --- a/javax/swing/plaf/basic/BasicPasswordFieldUI.java +++ b/javax/swing/plaf/basic/BasicPasswordFieldUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/basic/BasicPopupMenuSeparatorUI.java b/javax/swing/plaf/basic/BasicPopupMenuSeparatorUI.java index d0df9d347..b62947722 100644 --- a/javax/swing/plaf/basic/BasicPopupMenuSeparatorUI.java +++ b/javax/swing/plaf/basic/BasicPopupMenuSeparatorUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/basic/BasicPopupMenuUI.java b/javax/swing/plaf/basic/BasicPopupMenuUI.java index b7cbb3284..247117bc9 100644 --- a/javax/swing/plaf/basic/BasicPopupMenuUI.java +++ b/javax/swing/plaf/basic/BasicPopupMenuUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -51,6 +51,7 @@ import javax.swing.BoxLayout; import javax.swing.JComponent; import javax.swing.JLayeredPane; import javax.swing.JMenu; +import javax.swing.JMenuItem; import javax.swing.JPopupMenu; import javax.swing.MenuElement; import javax.swing.MenuSelectionManager; @@ -73,8 +74,8 @@ public class BasicPopupMenuUI extends PopupMenuUI /* popupMenu for which this UI delegate is for*/ protected JPopupMenu popupMenu; - /* MouseInputListener listens to mouse events */ - private static transient MouseInputListener mouseInputListener; + /* MouseInputListener listens to mouse events. Package private for inner classes. */ + static transient MouseInputListener mouseInputListener; /* PopupMenuListener listens to popup menu events fired by JPopupMenu*/ private transient PopupMenuListener popupMenuListener; @@ -415,6 +416,7 @@ public class BasicPopupMenuUI extends PopupMenuUI private transient Component mouseEventTarget; private transient Component pressedComponent; private transient Component lastComponentEntered; + private transient Component tempComponent; private transient int pressCount; /** @@ -552,7 +554,9 @@ public class BasicPopupMenuUI extends PopupMenuUI me.isPopupTrigger(), me.getButton()); - lastComponentEntered.dispatchEvent(exited); + tempComponent = lastComponentEntered; + lastComponentEntered = null; + tempComponent.dispatchEvent(exited); } lastComponentEntered = null; diff --git a/javax/swing/plaf/basic/BasicProgressBarUI.java b/javax/swing/plaf/basic/BasicProgressBarUI.java index acf6a97d7..d00628f53 100644 --- a/javax/swing/plaf/basic/BasicProgressBarUI.java +++ b/javax/swing/plaf/basic/BasicProgressBarUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/basic/BasicRadioButtonMenuItemUI.java b/javax/swing/plaf/basic/BasicRadioButtonMenuItemUI.java index 55cfdc033..d5cd7f448 100644 --- a/javax/swing/plaf/basic/BasicRadioButtonMenuItemUI.java +++ b/javax/swing/plaf/basic/BasicRadioButtonMenuItemUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/basic/BasicRadioButtonUI.java b/javax/swing/plaf/basic/BasicRadioButtonUI.java index 15d2e7af9..98738251c 100644 --- a/javax/swing/plaf/basic/BasicRadioButtonUI.java +++ b/javax/swing/plaf/basic/BasicRadioButtonUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -38,50 +38,125 @@ exception statement from your version. */ package javax.swing.plaf.basic; +import java.awt.Font; +import java.awt.Graphics; +import java.awt.Rectangle; + import javax.swing.AbstractButton; import javax.swing.Icon; import javax.swing.JComponent; +import javax.swing.SwingUtilities; import javax.swing.UIDefaults; import javax.swing.UIManager; import javax.swing.plaf.ComponentUI; +/** + * The BasicLookAndFeel UI implementation for + * {@link javax.swing.JRadioButton}s. + */ public class BasicRadioButtonUI extends BasicToggleButtonUI { - + /** + * The default icon for JRadioButtons. The default icon displays the usual + * RadioButton and is sensible to the selection state of the button, + * and can be used both as normal icon as well as selectedIcon. + */ protected Icon icon; + /** + * Creates and returns a new instance of <code>BasicRadioButtonUI</code>. + * + * @return a new instance of <code>BasicRadioButtonUI</code> + */ public static ComponentUI createUI(final JComponent c) { return new BasicRadioButtonUI(); } + /** + * Creates a new instance of <code>BasicButtonUI</code>. + */ public BasicRadioButtonUI() { icon = getDefaultIcon(); } - public void installUI(final JComponent c) { - super.installUI(c); - if (c instanceof AbstractButton) - { - AbstractButton b = (AbstractButton) c; - b.setIcon(icon); - } + /** + * Installs defaults from the Look & Feel table on the specified + * button. + * + * @param b the button on which to install the defaults + */ + protected void installDefaults(AbstractButton b) + { + super.installDefaults(b); + if (b.getIcon() == null) + b.setIcon(icon); + if (b.getSelectedIcon() == null) + b.setSelectedIcon(icon); } + /** + * Returns the prefix used for UIDefaults properties. This is + * <code>RadioButton</code> in this case. + * + * @return the prefix used for UIDefaults properties + */ + protected String getPropertyPrefix() + { + return "RadioButton"; + } + + /** + * Returns the default icon for JRadioButtons. + * The default icon displays the usual + * RadioButton and is sensible to the selection state of the button, + * and can be used both as normal icon as well as selectedIcon. + * + * @return the default icon for JRadioButtons + */ public Icon getDefaultIcon() { UIDefaults defaults = UIManager.getLookAndFeelDefaults(); - return defaults.getIcon("RadioButton.icon"); + return defaults.getIcon(getPropertyPrefix() + ".icon"); } - -} - - - - + /** + * Paints the RadioButton. + * + * @param g the Graphics context to paint with + * @param c the button to paint + */ + public void paint(Graphics g, JComponent c) + { + AbstractButton b = (AbstractButton) c; + Rectangle tr = new Rectangle(); + Rectangle ir = new Rectangle(); + Rectangle vr = new Rectangle(); + Font f = c.getFont(); + g.setFont(f); + Icon currentIcon = null; + if (b.isSelected()) + currentIcon = b.getSelectedIcon(); + else + currentIcon = b.getIcon(); + SwingUtilities.calculateInnerArea(b, vr); + String text = SwingUtilities.layoutCompoundLabel + (c, g.getFontMetrics(f), b.getText(), currentIcon, + b.getVerticalAlignment(), b.getHorizontalAlignment(), + b.getVerticalTextPosition(), b.getHorizontalTextPosition(), + vr, ir, tr, b.getIconTextGap() + defaultTextShiftOffset); + + if (currentIcon != null) + { + currentIcon.paintIcon(c, g, ir.x, ir.y); + } + if (text != null) + paintText(g, b, tr, text); + paintFocus(g, b, vr, tr, ir); + } +} diff --git a/javax/swing/plaf/basic/BasicRootPaneUI.java b/javax/swing/plaf/basic/BasicRootPaneUI.java index 4923b90b2..d97f7baea 100644 --- a/javax/swing/plaf/basic/BasicRootPaneUI.java +++ b/javax/swing/plaf/basic/BasicRootPaneUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -56,7 +56,6 @@ public class BasicRootPaneUI extends RootPaneUI public void installUI(JComponent c) { - c.setOpaque(true); c.setBackground(UIManager.getColor("control")); super.installUI(c); } diff --git a/javax/swing/plaf/basic/BasicScrollBarUI.java b/javax/swing/plaf/basic/BasicScrollBarUI.java index b7c5074aa..892db2b03 100644 --- a/javax/swing/plaf/basic/BasicScrollBarUI.java +++ b/javax/swing/plaf/basic/BasicScrollBarUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -45,8 +45,6 @@ import java.awt.Dimension; import java.awt.Graphics; import java.awt.Insets; import java.awt.LayoutManager; -import java.awt.Point; -import java.awt.Polygon; import java.awt.Rectangle; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -124,7 +122,6 @@ public class BasicScrollBarUI extends ScrollBarUI implements LayoutManager, { // System.err.println(this + ".stateChanged()"); calculatePreferredSize(); - layoutContainer(scrollbar); getThumbBounds(); scrollbar.repaint(); } @@ -167,9 +164,7 @@ public class BasicScrollBarUI extends ScrollBarUI implements LayoutManager, incrButton.addMouseListener(buttonListener); decrButton.addMouseListener(buttonListener); calculatePreferredSize(); - layoutContainer(scrollbar); } - layoutContainer(scrollbar); scrollbar.repaint(); } } @@ -820,6 +815,7 @@ public class BasicScrollBarUI extends ScrollBarUI implements LayoutManager, scrollbar.setBackground(defaults.getColor("ScrollBar.background")); scrollbar.setBorder(defaults.getBorder("ScrollBar.border")); scrollbar.setOpaque(true); + scrollbar.setLayout(this); thumbColor = defaults.getColor("ScrollBar.thumb"); thumbDarkShadowColor = defaults.getColor("ScrollBar.thumbDarkShadow"); @@ -888,7 +884,6 @@ public class BasicScrollBarUI extends ScrollBarUI implements LayoutManager, installListeners(); calculatePreferredSize(); - layoutContainer(scrollbar); } } @@ -973,7 +968,6 @@ public class BasicScrollBarUI extends ScrollBarUI implements LayoutManager, */ public void paint(Graphics g, JComponent c) { - layoutContainer(scrollbar); paintTrack(g, c, getTrackBounds()); paintThumb(g, c, getThumbBounds()); diff --git a/javax/swing/plaf/basic/BasicScrollPaneUI.java b/javax/swing/plaf/basic/BasicScrollPaneUI.java index 938548aeb..bd1576f37 100644 --- a/javax/swing/plaf/basic/BasicScrollPaneUI.java +++ b/javax/swing/plaf/basic/BasicScrollPaneUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -102,14 +102,6 @@ public class BasicScrollPaneUI extends ScrollPaneUI return sl.minimumLayoutSize(c); } - public Dimension getPreferredSize(JComponent c) - { - JScrollPane p = (JScrollPane ) c; - ScrollPaneLayout sl = (ScrollPaneLayout) p.getLayout(); - return sl.preferredLayoutSize(c); - } - - public void paint(Graphics g, JComponent c) { // do nothing; the normal painting-of-children algorithm, along with diff --git a/javax/swing/plaf/basic/BasicSeparatorUI.java b/javax/swing/plaf/basic/BasicSeparatorUI.java index db2d16458..38c9c7a28 100644 --- a/javax/swing/plaf/basic/BasicSeparatorUI.java +++ b/javax/swing/plaf/basic/BasicSeparatorUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -125,7 +125,7 @@ public class BasicSeparatorUI extends SeparatorUI shadow = defaults.getColor("Separator.shadow"); highlight = defaults.getColor("Separator.highlight"); - s.setOpaque(true); + s.setOpaque(false); } /** diff --git a/javax/swing/plaf/basic/BasicSliderUI.java b/javax/swing/plaf/basic/BasicSliderUI.java index 9169a6bb7..0b4058429 100644 --- a/javax/swing/plaf/basic/BasicSliderUI.java +++ b/javax/swing/plaf/basic/BasicSliderUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -470,15 +470,6 @@ public class BasicSliderUI extends SliderUI } } - /** The preferred height of the thumb. */ - private transient int thumbHeight; - - /** The preferred width of the thumb. */ - private transient int thumbWidth; - - /** The preferred height of the tick rectangle. */ - private transient int tickHeight; - /** Listener for changes from the model. */ protected ChangeListener changeListener; @@ -698,11 +689,6 @@ public class BasicSliderUI extends SliderUI focusColor = defaults.getColor("Slider.focus"); slider.setBorder(defaults.getBorder("Slider.border")); slider.setOpaque(true); - - thumbHeight = defaults.getInt("Slider.thumbHeight"); - thumbWidth = defaults.getInt("Slider.thumbWidth"); - tickHeight = defaults.getInt("Slider.tickHeight"); - focusInsets = defaults.getInsets("Slider.focusInsets"); } @@ -899,11 +885,11 @@ public class BasicSliderUI extends SliderUI width += insets.left + insets.right + focusInsets.left + focusInsets.right; // Height is determined by the thumb, the ticks and the labels. - int height = thumbHeight; + int height = getThumbSize().height; if (slider.getPaintTicks() && slider.getMajorTickSpacing() > 0 || slider.getMinorTickSpacing() > 0) - height += tickHeight; + height += getTickLength(); if (slider.getPaintLabels()) height += getHeightOfTallestLabel(); @@ -934,11 +920,11 @@ public class BasicSliderUI extends SliderUI height += insets.top + insets.bottom + focusInsets.top + focusInsets.bottom; - int width = thumbHeight; + int width = getThumbSize().width; if (slider.getPaintTicks() && slider.getMajorTickSpacing() > 0 || slider.getMinorTickSpacing() > 0) - width += tickHeight; + width += getTickLength(); if (slider.getPaintLabels()) width += getWidthOfWidestLabel(); @@ -956,7 +942,21 @@ public class BasicSliderUI extends SliderUI */ public Dimension getMinimumHorizontalSize() { - return getPreferredHorizontalSize(); + Insets insets = slider.getInsets(); + // Height is determined by the thumb, the ticks and the labels. + int height = getThumbSize().height; + + if (slider.getPaintTicks() && slider.getMajorTickSpacing() > 0 + || slider.getMinorTickSpacing() > 0) + height += getTickLength(); + + if (slider.getPaintLabels()) + height += getHeightOfTallestLabel(); + + height += insets.top + insets.bottom + focusInsets.top + + focusInsets.bottom; + + return new Dimension(36, height); } /** @@ -967,7 +967,19 @@ public class BasicSliderUI extends SliderUI */ public Dimension getMinimumVerticalSize() { - return getPreferredVerticalSize(); + Insets insets = slider.getInsets(); + int width = getThumbSize().width; + + if (slider.getPaintTicks() && slider.getMajorTickSpacing() > 0 + || slider.getMinorTickSpacing() > 0) + width += getTickLength(); + + if (slider.getPaintLabels()) + width += getWidthOfWidestLabel(); + + width += insets.left + insets.right + focusInsets.left + focusInsets.right; + + return new Dimension(width, 36); } /** @@ -999,15 +1011,14 @@ public class BasicSliderUI extends SliderUI public Dimension getMinimumSize(JComponent c) { if (slider.getOrientation() == JSlider.HORIZONTAL) - return getPreferredHorizontalSize(); + return getMinimumHorizontalSize(); else - return getPreferredVerticalSize(); + return getMinimumVerticalSize(); } /** * This method returns the maximum size for this {@link JSlider} for this - * look and feel. If it returns null, then it is up to the Layout Manager - * to give the {@link JComponent} a size. + * look and feel. * * @param c The {@link JComponent} to find a maximum size for. * @@ -1015,10 +1026,40 @@ public class BasicSliderUI extends SliderUI */ public Dimension getMaximumSize(JComponent c) { + Insets insets = slider.getInsets(); if (slider.getOrientation() == JSlider.HORIZONTAL) - return getPreferredHorizontalSize(); + { + // Height is determined by the thumb, the ticks and the labels. + int height = getThumbSize().height; + + if (slider.getPaintTicks() && slider.getMajorTickSpacing() > 0 + || slider.getMinorTickSpacing() > 0) + height += getTickLength(); + + if (slider.getPaintLabels()) + height += getHeightOfTallestLabel(); + + height += insets.top + insets.bottom + focusInsets.top + + focusInsets.bottom; + + return new Dimension(32767, height); + } else - return getPreferredVerticalSize(); + { + int width = getThumbSize().width; + + if (slider.getPaintTicks() && slider.getMajorTickSpacing() > 0 + || slider.getMinorTickSpacing() > 0) + width += getTickLength(); + + if (slider.getPaintLabels()) + width += getWidthOfWidestLabel(); + + width += insets.left + insets.right + focusInsets.left + + focusInsets.right; + + return new Dimension(width, 32767); + } } /** @@ -1045,7 +1086,6 @@ public class BasicSliderUI extends SliderUI { insetCache = slider.getInsets(); focusRect = SwingUtilities.calculateInnerArea(slider, focusRect); - if (focusRect.width < 0) focusRect.width = 0; if (focusRect.height < 0) @@ -1058,30 +1098,13 @@ public class BasicSliderUI extends SliderUI */ protected void calculateThumbSize() { + Dimension d = getThumbSize(); + thumbRect.width = d.width; + thumbRect.height = d.height; if (slider.getOrientation() == JSlider.HORIZONTAL) - { - if (thumbWidth > contentRect.width) - thumbRect.width = contentRect.width / 4; - else - thumbRect.width = thumbWidth; - if (thumbHeight > contentRect.height) - thumbRect.height = contentRect.height; - else - thumbRect.height = thumbHeight; - } + thumbRect.y = trackRect.y; else - { - // The thumb gets flipped when inverted, so thumbWidth - // actually is the height and vice versa. - if (thumbWidth > contentRect.height) - thumbRect.height = contentRect.height / 4; - else - thumbRect.height = thumbWidth; - if (thumbHeight > contentRect.width) - thumbRect.width = contentRect.width; - else - thumbRect.width = thumbHeight; - } + thumbRect.x = trackRect.x; } /** @@ -1092,9 +1115,10 @@ public class BasicSliderUI extends SliderUI { contentRect.x = focusRect.x + focusInsets.left; contentRect.y = focusRect.y + focusInsets.top; + contentRect.width = focusRect.width - focusInsets.left - focusInsets.right; - contentRect.height = focusRect.height - focusInsets.top - - focusInsets.bottom; + contentRect.height = focusRect.height - focusInsets.top + - focusInsets.bottom; if (contentRect.width < 0) contentRect.width = 0; @@ -1113,11 +1137,11 @@ public class BasicSliderUI extends SliderUI if (slider.getOrientation() == JSlider.HORIZONTAL) { thumbRect.x = xPositionForValue(value) - thumbRect.width / 2; - thumbRect.y = contentRect.y; + thumbRect.y = trackRect.y; } else { - thumbRect.x = contentRect.x; + thumbRect.x = trackRect.x; thumbRect.y = yPositionForValue(value) - thumbRect.height / 2; } } @@ -1129,9 +1153,9 @@ public class BasicSliderUI extends SliderUI protected void calculateTrackBuffer() { if (slider.getOrientation() == JSlider.HORIZONTAL) - trackBuffer = thumbRect.width; + trackBuffer = thumbRect.width / 2; else - trackBuffer = thumbRect.height; + trackBuffer = thumbRect.height / 2; } /** @@ -1141,9 +1165,11 @@ public class BasicSliderUI extends SliderUI */ protected Dimension getThumbSize() { - // This is really just the bounds box for the thumb. - // The thumb will actually be pointed (like a rectangle + triangle at bottom) - return thumbRect.getSize(); + // TODO: shouldn't create new objects every time + if (slider.getOrientation() == JSlider.HORIZONTAL) + return new Dimension(11, 20); + else + return new Dimension(20, 11); } /** @@ -1155,13 +1181,21 @@ public class BasicSliderUI extends SliderUI if (slider.getOrientation() == JSlider.HORIZONTAL) { trackRect.x = contentRect.x + trackBuffer; - trackRect.y = contentRect.y; + int h = getThumbSize().height; + if (slider.getPaintTicks() && (slider.getMajorTickSpacing() > 0 + || slider.getMinorTickSpacing() > 0)) + h += getTickLength(); + trackRect.y = contentRect.y + (contentRect.height - h) / 2 - 1; trackRect.width = contentRect.width - 2 * trackBuffer; trackRect.height = thumbRect.height; } else { - trackRect.x = contentRect.x; + int w = getThumbSize().width; + if (slider.getPaintTicks() && (slider.getMajorTickSpacing() > 0 + || slider.getMinorTickSpacing() > 0)) + w += getTickLength(); + trackRect.x = contentRect.x + (contentRect.width - w) / 2 - 1; trackRect.y = contentRect.y + trackBuffer; trackRect.width = thumbRect.width; trackRect.height = contentRect.height - 2 * trackBuffer; @@ -1180,7 +1214,7 @@ public class BasicSliderUI extends SliderUI */ protected int getTickLength() { - return tickHeight; + return 8; } /** @@ -1536,9 +1570,6 @@ public class BasicSliderUI extends SliderUI Point c = new Point(a); Point d = new Point(a); - Polygon high; - Polygon shadow; - if (slider.getOrientation() == JSlider.HORIZONTAL) { width = trackRect.width; @@ -1591,74 +1622,78 @@ public class BasicSliderUI extends SliderUI { if (slider.getOrientation() == JSlider.HORIZONTAL) { - double loc = tickRect.x; + double loc = tickRect.x + 0.5; double increment = (max == min) ? 0 - : majorSpace * (double) tickRect.width / (max - - min); - if (drawInverted()) + : majorSpace * (double) (tickRect.width - 1) / (max - min); + if (drawInverted()) { loc += tickRect.width; increment *= -1; } + g.translate(0, tickRect.y); for (int i = min; i <= max; i += majorSpace) { paintMajorTickForHorizSlider(g, tickRect, (int) loc); loc += increment; } + g.translate(0, -tickRect.y); } else { - double loc = tickRect.height + tickRect.y; + double loc = tickRect.height + tickRect.y + 0.5; double increment = (max == min) ? 0 - : -majorSpace * (double) tickRect.height / (max - - min); + : -majorSpace * (double) (tickRect.height - 1) / (max - min); if (drawInverted()) { - loc = tickRect.y; + loc = tickRect.y + 0.5; increment *= -1; } + g.translate(tickRect.x, 0); for (int i = min; i <= max; i += majorSpace) { paintMajorTickForVertSlider(g, tickRect, (int) loc); loc += increment; } + g.translate(-tickRect.x, 0); } } if (minorSpace > 0) { if (slider.getOrientation() == JSlider.HORIZONTAL) { - double loc = tickRect.x; + double loc = tickRect.x + 0.5; double increment = (max == min) ? 0 - : minorSpace * (double) tickRect.width / (max - - min); + : minorSpace * (double) (tickRect.width - 1) / (max - min); if (drawInverted()) { loc += tickRect.width; increment *= -1; } + g.translate(0, tickRect.y); for (int i = min; i <= max; i += minorSpace) { paintMinorTickForHorizSlider(g, tickRect, (int) loc); loc += increment; } + g.translate(0, -tickRect.y); } else { - double loc = tickRect.height + tickRect.y; + double loc = tickRect.height + tickRect.y + 0.5; double increment = (max == min) ? 0 - : -minorSpace * (double) tickRect.height / (max - - min); + : -minorSpace * (double) (tickRect.height - 1) / (max - min); if (drawInverted()) { - loc = tickRect.y; + loc = tickRect.y + 0.5; increment *= -1; } + g.translate(tickRect.x, 0); for (int i = min; i <= max; i += minorSpace) { paintMinorTickForVertSlider(g, tickRect, (int) loc); loc += increment; } + g.translate(-tickRect.x, 0); } } } @@ -1680,7 +1715,7 @@ public class BasicSliderUI extends SliderUI protected void paintMinorTickForHorizSlider(Graphics g, Rectangle tickBounds, int x) { - int y = tickRect.y + tickRect.height / 4; + int y = tickRect.height / 4; Color saved = g.getColor(); g.setColor(Color.BLACK); @@ -1699,7 +1734,7 @@ public class BasicSliderUI extends SliderUI protected void paintMajorTickForHorizSlider(Graphics g, Rectangle tickBounds, int x) { - int y = tickRect.y + tickRect.height / 4; + int y = tickRect.height / 4; Color saved = g.getColor(); g.setColor(Color.BLACK); @@ -1718,7 +1753,7 @@ public class BasicSliderUI extends SliderUI protected void paintMinorTickForVertSlider(Graphics g, Rectangle tickBounds, int y) { - int x = tickRect.x + tickRect.width / 4; + int x = tickRect.width / 4; Color saved = g.getColor(); g.setColor(Color.BLACK); @@ -1737,7 +1772,7 @@ public class BasicSliderUI extends SliderUI protected void paintMajorTickForVertSlider(Graphics g, Rectangle tickBounds, int y) { - int x = tickRect.x + tickRect.width / 4; + int x = tickRect.width / 4; Color saved = g.getColor(); g.setColor(Color.BLACK); @@ -1924,8 +1959,6 @@ public class BasicSliderUI extends SliderUI { Color saved_color = g.getColor(); - Polygon thumb = new Polygon(); - Point a = new Point(thumbRect.x, thumbRect.y); Point b = new Point(a); Point c = new Point(a); @@ -1933,7 +1966,8 @@ public class BasicSliderUI extends SliderUI Point e = new Point(a); Polygon bright; - Polygon dark; + Polygon light; // light shadow + Polygon dark; // dark shadow Polygon all; // This will be in X-dimension if the slider is inverted and y if it isn't. @@ -1943,36 +1977,42 @@ public class BasicSliderUI extends SliderUI { turnPoint = thumbRect.height * 3 / 4; - b.translate(thumbRect.width, 0); - c.translate(thumbRect.width, turnPoint); - d.translate(thumbRect.width / 2, thumbRect.height); + b.translate(thumbRect.width - 1, 0); + c.translate(thumbRect.width - 1, turnPoint); + d.translate(thumbRect.width / 2 - 1, thumbRect.height - 1); e.translate(0, turnPoint); - bright = new Polygon(new int[] { b.x, a.x, e.x, d.x }, + bright = new Polygon(new int[] { b.x - 1, a.x, e.x, d.x }, new int[] { b.y, a.y, e.y, d.y }, 4); - dark = new Polygon(new int[] { b.x, c.x, d.x }, - new int[] { b.y, c.y, d.y }, 3); - all = new Polygon(new int[] { a.x + 1, b.x, c.x, d.x, e.x + 1 }, - new int[] { a.y + 1, b.y + 1, c.y, d.y + 1, e.y }, 5); + dark = new Polygon(new int[] { b.x, c.x, d.x + 1 }, + new int[] { b.y, c.y - 1, d.y }, 3); + + light = new Polygon(new int[] { b.x - 1, c.x - 1, d.x + 1 }, + new int[] { b.y + 1, c.y - 1, d.y - 1 }, 3); + + all = new Polygon(new int[] { a.x + 1, b.x - 2, c.x - 2, d.x, e.x + 1 }, + new int[] { a.y + 1, b.y + 1, c.y - 1, d.y - 1, e.y }, 5); } else { - turnPoint = thumbRect.width * 3 / 4; + turnPoint = thumbRect.width * 3 / 4 - 1; b.translate(turnPoint, 0); - c.translate(thumbRect.width, thumbRect.height / 2); - d.translate(turnPoint, thumbRect.height); - e.translate(0, thumbRect.height); + c.translate(thumbRect.width - 1, thumbRect.height / 2); + d.translate(turnPoint, thumbRect.height - 1); + e.translate(0, thumbRect.height - 1); - bright = new Polygon(new int[] { c.x, b.x, a.x, e.x }, - new int[] { c.y, b.y, a.y, e.y }, 4); + bright = new Polygon(new int[] { c.x - 1, b.x, a.x, e.x }, + new int[] { c.y - 1, b.y, a.y, e.y - 1 }, 4); - dark = new Polygon(new int[] { c.x, d.x, e.x + 1 }, + dark = new Polygon(new int[] { c.x, d.x, e.x }, new int[] { c.y, d.y, e.y }, 3); - all = new Polygon(new int[] { a.x + 1, b.x, c.x - 1, d.x, e.x + 1 }, - new int[] { a.y + 1, b.y + 1, c.y, d.y, e.y }, 5); + light = new Polygon(new int[] { c.x - 1, d.x, e.x + 1}, + new int[] { c.y, d.y - 1, e.y - 1}, 3); + all = new Polygon(new int[] { a.x + 1, b.x, c.x - 2, c.x - 2, d.x, e.x + 1 }, + new int[] { a.y + 1, b.y + 1, c.y - 1, c.y, d.y - 2, e.y - 2 }, 6); } g.setColor(Color.WHITE); @@ -1982,6 +2022,10 @@ public class BasicSliderUI extends SliderUI g.drawPolyline(dark.xpoints, dark.ypoints, dark.npoints); g.setColor(Color.GRAY); + g.drawPolyline(light.xpoints, light.ypoints, light.npoints); + + g.setColor(Color.LIGHT_GRAY); + g.drawPolyline(all.xpoints, all.ypoints, all.npoints); g.fillPolygon(all); g.setColor(saved_color); @@ -2065,8 +2109,7 @@ public class BasicSliderUI extends SliderUI { int min = slider.getMinimum(); int max = slider.getMaximum(); - int extent = slider.getExtent(); - int len = trackRect.width; + int len = trackRect.width - 1; int xPos = (max == min) ? 0 : (value - min) * len / (max - min); @@ -2074,7 +2117,7 @@ public class BasicSliderUI extends SliderUI xPos += trackRect.x; else { - xPos = trackRect.width - xPos; + xPos = len - xPos; xPos += trackRect.x; } return xPos; @@ -2091,14 +2134,13 @@ public class BasicSliderUI extends SliderUI { int min = slider.getMinimum(); int max = slider.getMaximum(); - int extent = slider.getExtent(); - int len = trackRect.height; + int len = trackRect.height - 1; int yPos = (max == min) ? 0 : (value - min) * len / (max - min); if (! drawInverted()) { - yPos = trackRect.height - yPos; + yPos = len - yPos; yPos += trackRect.y; } else @@ -2123,8 +2165,9 @@ public class BasicSliderUI extends SliderUI int value; - // If the length is 0, you shouldn't be able to even see where the slider is. - // This really shouldn't ever happen, but just in case, we'll return the middle. + // If the length is 0, you shouldn't be able to even see where the slider + // is. This really shouldn't ever happen, but just in case, we'll return + // the middle. if (len == 0) return ((max - min) / 2); @@ -2158,8 +2201,9 @@ public class BasicSliderUI extends SliderUI int value; - // If the length is 0, you shouldn't be able to even see where the slider is. - // This really shouldn't ever happen, but just in case, we'll return the middle. + // If the length is 0, you shouldn't be able to even see where the slider + // is. This really shouldn't ever happen, but just in case, we'll return + // the middle. if (len == 0) return ((max - min) / 2); diff --git a/javax/swing/plaf/basic/BasicSpinnerUI.java b/javax/swing/plaf/basic/BasicSpinnerUI.java index 919cde786..97ab97b89 100644 --- a/javax/swing/plaf/basic/BasicSpinnerUI.java +++ b/javax/swing/plaf/basic/BasicSpinnerUI.java @@ -1,5 +1,5 @@ /* SpinnerUI.java -- - Copyright (C) 2003, 2004 Free Software Foundation, Inc. + Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -161,7 +161,7 @@ public class BasicSpinnerUI extends SpinnerUI * obtained from <code>UIManager.getLookAndFeelDefaults</code>, as well as * set the layout obtained from <code>createLayout</code> * - * @see #javax.swing.UIManager#getLookAndFeelDefaults + * @see javax.swing.UIManager#getLookAndFeelDefaults * @see #createLayout * @see #installUI */ @@ -178,6 +178,7 @@ public class BasicSpinnerUI extends SpinnerUI spinner.setBorder(defaults.getBorder("Spinner.border")); */ spinner.setLayout(createLayout()); + spinner.setOpaque(true); } /* diff --git a/javax/swing/plaf/basic/BasicSplitPaneDivider.java b/javax/swing/plaf/basic/BasicSplitPaneDivider.java index 3b8596e7e..b8674ed2f 100644 --- a/javax/swing/plaf/basic/BasicSplitPaneDivider.java +++ b/javax/swing/plaf/basic/BasicSplitPaneDivider.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -273,7 +273,7 @@ public class BasicSplitPaneDivider extends Container * * @param border the new border. Typically, this will be an instance of * {@link - * javax.swing.plaf.basic.BasicBorders.SplitPaneDividerBorder}. + * javax.swing.plaf.basic.BasicBorders.SplitPaneBorder}. * * @since 1.3 */ diff --git a/javax/swing/plaf/basic/BasicSplitPaneUI.java b/javax/swing/plaf/basic/BasicSplitPaneUI.java index b701a63d6..ff7e8acfb 100644 --- a/javax/swing/plaf/basic/BasicSplitPaneUI.java +++ b/javax/swing/plaf/basic/BasicSplitPaneUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -348,7 +348,7 @@ public class BasicSplitPaneUI extends SplitPaneUI height = Math.max(height, dims.height); } } - return new Dimension(500, 500); //width, height); + return new Dimension(width, height); } return null; } @@ -613,7 +613,7 @@ public class BasicSplitPaneUI extends SplitPaneUI width = Math.max(width, dims.width); } } - return new Dimension(500, 500); //width, height); + return new Dimension(width, height); } return null; } @@ -990,8 +990,8 @@ public class BasicSplitPaneUI extends SplitPaneUI */ protected void installDefaults() { - resetLayoutManager(); divider = createDefaultDivider(); + resetLayoutManager(); nonContinuousLayoutDivider = createDefaultNonContinuousLayoutDivider(); splitPane.add(divider, JSplitPane.DIVIDER); @@ -1000,6 +1000,7 @@ public class BasicSplitPaneUI extends SplitPaneUI splitPane.setBackground(defaults.getColor("SplitPane.background")); splitPane.setBorder(defaults.getBorder("SplitPane.border")); splitPane.setDividerSize(defaults.getInt("SplitPane.dividerSize")); + splitPane.setOpaque(true); } /** @@ -1384,11 +1385,6 @@ public class BasicSplitPaneUI extends SplitPaneUI */ public void paint(Graphics g, JComponent jc) { - // Make sure that the location is valid - int divLoc = splitPane.getDividerLocation(); - int valLoc = validLocation(divLoc); - if (divLoc != valLoc) - splitPane.setDividerLocation(valLoc); } /** @@ -1449,9 +1445,8 @@ public class BasicSplitPaneUI extends SplitPaneUI layoutManager = new BasicHorizontalLayoutManager(); else layoutManager = new BasicVerticalLayoutManager(); - layoutManager.invalidateLayout(splitPane); - layoutManager.updateComponents(); getSplitPane().setLayout(layoutManager); + layoutManager.updateComponents(); // invalidating by itself does not invalidate the layout. getSplitPane().revalidate(); diff --git a/javax/swing/plaf/basic/BasicTabbedPaneUI.java b/javax/swing/plaf/basic/BasicTabbedPaneUI.java index 9ea653e7f..7e9d9b982 100644 --- a/javax/swing/plaf/basic/BasicTabbedPaneUI.java +++ b/javax/swing/plaf/basic/BasicTabbedPaneUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -1541,7 +1541,7 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants tabPane.setFont(defaults.getFont("TabbedPane.font")); tabPane.setForeground(defaults.getColor("TabbedPane.foreground")); tabPane.setBackground(defaults.getColor("TabbedPane.background")); - tabPane.setOpaque(true); + tabPane.setOpaque(false); highlight = defaults.getColor("TabbedPane.highlight"); lightHighlight = defaults.getColor("TabbedPane.lightHighlight"); @@ -1680,18 +1680,6 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants } /** - * This method returns the preferred size of the JTabbedPane. - * - * @param c The JComponent to find a size for. - * - * @return The preferred size. - */ - public Dimension getPreferredSize(JComponent c) - { - return layoutManager.preferredLayoutSize(tabPane); - } - - /** * This method returns the minimum size of the JTabbedPane. * * @param c The JComponent to find a size for. diff --git a/javax/swing/plaf/basic/BasicTableHeaderUI.java b/javax/swing/plaf/basic/BasicTableHeaderUI.java index ebc702ad3..700b406d0 100644 --- a/javax/swing/plaf/basic/BasicTableHeaderUI.java +++ b/javax/swing/plaf/basic/BasicTableHeaderUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/basic/BasicTableUI.java b/javax/swing/plaf/basic/BasicTableUI.java index 93483804c..aa8f21a62 100644 --- a/javax/swing/plaf/basic/BasicTableUI.java +++ b/javax/swing/plaf/basic/BasicTableUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -46,16 +46,19 @@ import java.awt.Point; import java.awt.Rectangle; import java.awt.event.FocusEvent; import java.awt.event.FocusListener; +import java.awt.event.InputEvent; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.awt.event.MouseEvent; +import javax.swing.BorderFactory; import javax.swing.CellRendererPane; import javax.swing.JComponent; import javax.swing.JTable; import javax.swing.ListSelectionModel; import javax.swing.UIDefaults; import javax.swing.UIManager; +import javax.swing.border.Border; import javax.swing.event.MouseInputListener; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.TableUI; @@ -77,6 +80,12 @@ public class BasicTableUI protected CellRendererPane rendererPane; protected JTable table; + /** The normal cell border. */ + Border cellBorder; + + /** The cell border for selected/highlighted cells. */ + Border highlightCellBorder; + class FocusHandler implements FocusListener { public void focusGained(FocusEvent e) @@ -89,12 +98,418 @@ public class BasicTableUI class KeyHandler implements KeyListener { - public void keyPressed(KeyEvent e) + + /** + * A helper method for the keyPressed event. Used because the actions + * for TAB, SHIFT-TAB, ENTER, and SHIFT-ENTER are very similar. + * + * Selects the next (previous if SHIFT pressed) column for TAB, or row for + * ENTER from within the currently selected cells. + * + * @param firstModel the ListSelectionModel for columns (TAB) or + * rows (ENTER) + * @param firstMin the first selected index in firstModel + * @param firstMax the last selected index in firstModel + * @param secondModel the ListSelectionModel for rows (TAB) or + * columns (ENTER) + * @param secondMin the first selected index in secondModel + * @param secondMax the last selected index in secondModel + * @param reverse true if shift was held for the event + * @param eventIsTab true if TAB was pressed, false if ENTER pressed + */ + void advanceMultipleSelection (ListSelectionModel firstModel, int firstMin, + int firstMax, ListSelectionModel secondModel, + int secondMin, int secondMax, boolean reverse, + boolean eventIsTab) { + // If eventIsTab, all the "firsts" correspond to columns, otherwise, to rows + // "seconds" correspond to the opposite + int firstLead = firstModel.getLeadSelectionIndex(); + int secondLead = secondModel.getLeadSelectionIndex(); + int numFirsts = eventIsTab ? + table.getModel().getColumnCount() : table.getModel().getRowCount(); + int numSeconds = eventIsTab ? + table.getModel().getRowCount() : table.getModel().getColumnCount(); + + // check if we have to wrap the "firsts" around, going to the other side + if ((firstLead == firstMax && !reverse) || + (reverse && firstLead == firstMin)) + { + firstModel.addSelectionInterval(reverse ? firstMax : firstMin, + reverse ? firstMax : firstMin); + + // check if we have to wrap the "seconds" + if ((secondLead == secondMax && !reverse) || + (reverse && secondLead == secondMin)) + secondModel.addSelectionInterval(reverse ? secondMax : secondMin, + reverse ? secondMax : secondMin); + + // if we're not wrapping the seconds, we have to find out where we + // are within the secondModel and advance to the next cell (or + // go back to the previous cell if reverse == true) + else + { + int[] secondsSelected; + if (eventIsTab && table.getRowSelectionAllowed() || + !eventIsTab && table.getColumnSelectionAllowed()) + secondsSelected = eventIsTab ? + table.getSelectedRows() : table.getSelectedColumns(); + else + { + // if row selection is not allowed, then the entire column gets + // selected when you click on it, so consider ALL rows selected + secondsSelected = new int[numSeconds]; + for (int i = 0; i < numSeconds; i++) + secondsSelected[i] = i; + } + + // and now find the "next" index within the model + int secondIndex = reverse ? secondsSelected.length - 1 : 0; + if (!reverse) + while (secondsSelected[secondIndex] <= secondLead) + secondIndex++; + else + while (secondsSelected[secondIndex] >= secondLead) + secondIndex--; + + // and select it - updating the lead selection index + secondModel.addSelectionInterval(secondsSelected[secondIndex], + secondsSelected[secondIndex]); + } + } + // We didn't have to wrap the firsts, so just find the "next" first + // and select it, we don't have to change "seconds" + else + { + int[] firstsSelected; + if (eventIsTab && table.getColumnSelectionAllowed() || + !eventIsTab && table.getRowSelectionAllowed()) + firstsSelected = eventIsTab ? + table.getSelectedColumns() : table.getSelectedRows(); + else + { + // if selection not allowed, consider ALL firsts to be selected + firstsSelected = new int[numFirsts]; + for (int i = 0; i < numFirsts; i++) + firstsSelected[i] = i; + } + int firstIndex = reverse ? firstsSelected.length - 1 : 0; + if (!reverse) + while (firstsSelected[firstIndex] <= firstLead) + firstIndex++; + else + while (firstsSelected[firstIndex] >= firstLead) + firstIndex--; + firstModel.addSelectionInterval(firstsSelected[firstIndex], + firstsSelected[firstIndex]); + secondModel.addSelectionInterval(secondLead, secondLead); + } + } + + /** + * A helper method for the keyPressed event. Used because the actions + * for TAB, SHIFT-TAB, ENTER, and SHIFT-ENTER are very similar. + * + * Selects the next (previous if SHIFT pressed) column (TAB) or row (ENTER) + * in the table, changing the current selection. All cells in the table + * are eligible, not just the ones that are currently selected. + * @param firstModel the ListSelectionModel for columns (TAB) or rows + * (ENTER) + * @param firstMax the last index in firstModel + * @param secondModel the ListSelectionModel for rows (TAB) or columns + * (ENTER) + * @param secondMax the last index in secondModel + * @param reverse true if SHIFT was pressed for the event + */ + + void advanceSingleSelection (ListSelectionModel firstModel, int firstMax, + ListSelectionModel secondModel, int secondMax, + boolean reverse) + { + // for TABs, "first" corresponds to columns and "seconds" to rows. + // the opposite is true for ENTERs + int firstLead = firstModel.getLeadSelectionIndex(); + int secondLead = secondModel.getLeadSelectionIndex(); + + // if we are going backwards subtract 2 because we later add 1 + // for a net change of -1 + if (reverse && (firstLead == 0)) + { + // check if we have to wrap around + if (secondLead == 0) + secondLead += secondMax + 1; + secondLead -= 2; + } + + // do we have to wrap the "seconds"? + if (reverse && (firstLead == 0) || !reverse && (firstLead == firstMax)) + secondModel.setSelectionInterval((secondLead + 1)%(secondMax + 1), + (secondLead + 1)%(secondMax + 1)); + // if not, just reselect the current lead + else + secondModel.setSelectionInterval(secondLead, secondLead); + + // if we are going backwards, subtract 2 because we add 1 later + // for net change of -1 + if (reverse) + { + // check for wraparound + if (firstLead == 0) + firstLead += firstMax + 1; + firstLead -= 2; + } + // select the next "first" + firstModel.setSelectionInterval ((firstLead + 1)%(firstMax + 1), + (firstLead + 1)%(firstMax + 1)); + } + + public void keyPressed(KeyEvent evt) + { + ListSelectionModel rowModel = table.getSelectionModel(); + ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); + + int rowLead = rowModel.getLeadSelectionIndex(); + int rowMax = table.getModel().getRowCount() - 1; + + int colLead = colModel.getLeadSelectionIndex(); + int colMax = table.getModel().getColumnCount() - 1; + + if ((evt.getKeyCode() == KeyEvent.VK_DOWN) + || (evt.getKeyCode() == KeyEvent.VK_KP_DOWN)) + { + if (evt.getModifiers() == 0) + { + + table.clearSelection(); + rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax), + Math.min(rowLead + 1, rowMax)); + colModel.setSelectionInterval(colLead,colLead); + } + else if (evt.getModifiers() == InputEvent.SHIFT_MASK) + { + rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax)); + colModel.setLeadSelectionIndex(colLead); + } + } + else if ((evt.getKeyCode() == KeyEvent.VK_UP) + || (evt.getKeyCode() == KeyEvent.VK_KP_UP)) + { + if (evt.getModifiers() == 0) + { + table.clearSelection(); + rowModel.setSelectionInterval(Math.max(rowLead - 1, 0), + Math.max(rowLead - 1, 0)); + colModel.setSelectionInterval(colLead,colLead); + } + else if (evt.getModifiers() == InputEvent.SHIFT_MASK) + { + rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0)); + colModel.setLeadSelectionIndex(colLead); + } + } + else if ((evt.getKeyCode() == KeyEvent.VK_LEFT) + || (evt.getKeyCode() == KeyEvent.VK_KP_LEFT)) + { + if (evt.getModifiers() == InputEvent.SHIFT_MASK) + { + colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0)); + rowModel.setLeadSelectionIndex(rowLead); + } + else if (evt.getModifiers() == 0) + { + table.clearSelection(); + rowModel.setSelectionInterval(rowLead,rowLead); + colModel.setSelectionInterval(Math.max(colLead - 1, 0), + Math.max(colLead - 1, 0)); + } + } + else if ((evt.getKeyCode() == KeyEvent.VK_RIGHT) + || (evt.getKeyCode() == KeyEvent.VK_KP_RIGHT)) + { + if (evt.getModifiers() == InputEvent.SHIFT_MASK) + { + colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax)); + rowModel.setLeadSelectionIndex(rowLead); + } + else if (evt.getModifiers() == 0) + { + table.clearSelection(); + rowModel.setSelectionInterval(rowLead,rowLead); + colModel.setSelectionInterval(Math.min(colLead + 1, colMax), + Math.min(colLead + 1, colMax)); + } + } + else if (evt.getKeyCode() == KeyEvent.VK_END) + { + if (evt.getModifiers() == (InputEvent.SHIFT_MASK | InputEvent.CTRL_MASK)) + { + rowModel.setLeadSelectionIndex(rowMax); + colModel.setLeadSelectionIndex(colLead); + } + else if (evt.getModifiers() == InputEvent.CTRL_MASK) + { + table.clearSelection(); + rowModel.setSelectionInterval(rowMax,rowMax); + colModel.setSelectionInterval(colLead, colLead); + } + else if (evt.getModifiers() == InputEvent.SHIFT_MASK) + { + colModel.setLeadSelectionIndex(colMax); + rowModel.setLeadSelectionIndex(rowLead); + } + else if (evt.getModifiers() == 0) + { + table.clearSelection(); + rowModel.setSelectionInterval(rowLead, rowLead); + colModel.setSelectionInterval(colMax, colMax); + } + } + else if (evt.getKeyCode() == KeyEvent.VK_HOME) + { + if (evt.getModifiers() == (InputEvent.SHIFT_MASK | InputEvent.CTRL_MASK)) + { + rowModel.setLeadSelectionIndex(0); + colModel.setLeadSelectionIndex(colLead); + } + else if (evt.getModifiers() == InputEvent.CTRL_MASK) + { + table.clearSelection(); + rowModel.setSelectionInterval(0,0); + colModel.setSelectionInterval(colLead, colLead); + } + else if (evt.getModifiers() == InputEvent.SHIFT_MASK) + { + colModel.setLeadSelectionIndex(0); + rowModel.setLeadSelectionIndex(rowLead); + } + else if (evt.getModifiers() == 0) + { + table.clearSelection(); + rowModel.setSelectionInterval(rowLead, rowLead); + colModel.setSelectionInterval(0, 0); + } + } + else if (evt.getKeyCode() == KeyEvent.VK_F2) + { + // FIXME: Implement "start editing" + } + else if (evt.getKeyCode() == KeyEvent.VK_PAGE_UP) + { + // FIXME: implement, need JList.ensureIndexIsVisible to work + } + else if (evt.getKeyCode() == KeyEvent.VK_PAGE_DOWN) + { + // FIXME: implement, need JList.ensureIndexIsVisible to work + } + else if (evt.getKeyCode() == KeyEvent.VK_TAB + || evt.getKeyCode() == KeyEvent.VK_ENTER) + { + // If modifers other than SHIFT are pressed, do nothing + if (evt.getModifiers() != 0 && evt.getModifiers() != + InputEvent.SHIFT_MASK) + return; + + // If nothing is selected, select the first cell in the table + if (table.getSelectedRowCount() == 0 && + table.getSelectedColumnCount() == 0) + { + rowModel.setSelectionInterval(0, 0); + colModel.setSelectionInterval(0, 0); + return; + } + + // If the lead selection index isn't selected (ie a remove operation + // happened, then set the lead to the first selected cell in the + // table + if (!table.isCellSelected(rowLead, colLead)) + { + rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(), + rowModel.getMinSelectionIndex()); + colModel.addSelectionInterval(colModel.getMinSelectionIndex(), + colModel.getMinSelectionIndex()); + return; + } + + // multRowsSelected and multColsSelected tell us if multiple rows or + // columns are selected, respectively + boolean multRowsSelected, multColsSelected; + multRowsSelected = (table.getSelectedRowCount() > 1) || + (!table.getRowSelectionAllowed() && + table.getSelectedColumnCount() > 0); + multColsSelected = (table.getSelectedColumnCount() > 1) || + (!table.getColumnSelectionAllowed() && + table.getSelectedRowCount() > 0); + + // If there is just one selection, select the next cell, and wrap + // when you get to the edges of the table. + if (!multColsSelected || !multRowsSelected) + { + if (evt.getKeyCode() == KeyEvent.VK_TAB) + advanceSingleSelection(colModel, colMax, rowModel, rowMax, + (evt.getModifiers() == + InputEvent.SHIFT_MASK)); + else + advanceSingleSelection(rowModel, rowMax, colModel, colMax, + (evt.getModifiers() == + InputEvent.SHIFT_MASK)); + return; + } + + + // rowMinSelected and rowMaxSelected are the minimum and maximum + // values respectively of selected cells in the row selection model + // Similarly for colMinSelected and colMaxSelected. + int rowMaxSelected = table.getRowSelectionAllowed() ? + rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1; + int rowMinSelected = table.getRowSelectionAllowed() ? + rowModel.getMinSelectionIndex() : 0; + int colMaxSelected = table.getColumnSelectionAllowed() ? + colModel.getMaxSelectionIndex() : + table.getModel().getColumnCount() - 1; + int colMinSelected = table.getColumnSelectionAllowed() ? + colModel.getMinSelectionIndex() : 0; + + // If there are multiple rows and columns selected, select the next + // cell and wrap at the edges of the selection. + if (evt.getKeyCode() == KeyEvent.VK_TAB) + advanceMultipleSelection(colModel, colMinSelected, colMaxSelected, + rowModel, rowMinSelected, rowMaxSelected, + (evt.getModifiers() == + InputEvent.SHIFT_MASK), true); + else + advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected, + colModel, colMinSelected, colMaxSelected, + (evt.getModifiers() == + InputEvent.SHIFT_MASK), false); + + table.repaint(); + } + else if (evt.getKeyCode() == KeyEvent.VK_ESCAPE) + { + // FIXME: implement "cancel" + } + else if ((evt.getKeyCode() == KeyEvent.VK_A || evt.getKeyCode() + == KeyEvent.VK_SLASH) && (evt.getModifiers() == + InputEvent.CTRL_MASK)) + { + table.selectAll(); + } + else if (evt.getKeyCode() == KeyEvent.VK_BACK_SLASH + && (evt.getModifiers() == InputEvent.CTRL_MASK)) + { + table.clearSelection(); + } + else if (evt.getKeyCode() == KeyEvent.VK_SPACE + && (evt.getModifiers() == InputEvent.CTRL_MASK)) + { + table.changeSelection(rowLead, colLead, true, false); + } } + public void keyReleased(KeyEvent e) { } + public void keyTyped(KeyEvent e) { } @@ -104,23 +519,32 @@ public class BasicTableUI { Point begin, curr; - private void updateSelection() + private void updateSelection(boolean controlPressed) { - if (table.getRowSelectionAllowed()) + // Update the rows + int lo_row = table.rowAtPoint(begin); + int hi_row = table.rowAtPoint(curr); + ListSelectionModel rowModel = table.getSelectionModel(); + if (lo_row != -1 && hi_row != -1) { - int lo_row = table.rowAtPoint(begin); - int hi_row = table.rowAtPoint(curr); - ListSelectionModel rowModel = table.getSelectionModel(); - if (lo_row != -1 && hi_row != -1) + if (controlPressed && rowModel.getSelectionMode() + != ListSelectionModel.SINGLE_SELECTION) + rowModel.addSelectionInterval(lo_row, hi_row); + else rowModel.setSelectionInterval(lo_row, hi_row); } - - if (table.getColumnSelectionAllowed()) + + // Update the columns + int lo_col = table.columnAtPoint(begin); + int hi_col = table.columnAtPoint(curr); + ListSelectionModel colModel = table.getColumnModel(). + getSelectionModel(); + if (lo_col != -1 && hi_col != -1) { - int lo_col = table.columnAtPoint(begin); - int hi_col = table.columnAtPoint(curr); - ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); - if (lo_col != -1 && hi_col != -1) + if (controlPressed && colModel.getSelectionMode() != + ListSelectionModel.SINGLE_SELECTION) + colModel.addSelectionInterval(lo_col, hi_col); + else colModel.setSelectionInterval(lo_col, hi_col); } } @@ -131,7 +555,7 @@ public class BasicTableUI public void mouseDragged(MouseEvent e) { curr = new Point(e.getX(), e.getY()); - updateSelection(); + updateSelection(e.isControlDown()); } public void mouseEntered(MouseEvent e) { @@ -146,7 +570,20 @@ public class BasicTableUI { begin = new Point(e.getX(), e.getY()); curr = new Point(e.getX(), e.getY()); - updateSelection(); + //if control is pressed and the cell is already selected, deselect it + if (e.isControlDown() && table. + isCellSelected(table.rowAtPoint(begin),table.columnAtPoint(begin))) + { + table.getSelectionModel(). + removeSelectionInterval(table.rowAtPoint(begin), + table.rowAtPoint(begin)); + table.getColumnModel().getSelectionModel(). + removeSelectionInterval(table.columnAtPoint(begin), + table.columnAtPoint(begin)); + } + else + updateSelection(e.isControlDown()); + } public void mouseReleased(MouseEvent e) { @@ -195,6 +632,9 @@ public class BasicTableUI table.setSelectionForeground(defaults.getColor("Table.selectionForeground")); table.setSelectionBackground(defaults.getColor("Table.selectionBackground")); table.setOpaque(true); + + highlightCellBorder = defaults.getBorder("Table.focusCellHighlightBorder"); + cellBorder = BorderFactory.createEmptyBorder(1, 1, 1, 1); } protected void installKeyboardActions() { @@ -205,6 +645,7 @@ public class BasicTableUI table.addFocusListener(focusListener); table.addKeyListener(keyListener); table.addMouseListener(mouseInputListener); + table.addMouseMotionListener(mouseInputListener); } protected void uninstallDefaults() @@ -236,6 +677,7 @@ public class BasicTableUI table.removeFocusListener(focusListener); table.removeKeyListener(keyListener); table.removeMouseListener(mouseInputListener); + table.removeMouseMotionListener(mouseInputListener); } public void installUI(JComponent comp) @@ -292,6 +734,17 @@ public class BasicTableUI Component comp = table.prepareRenderer(rend, r, c); gfx.translate(x, y); comp.setBounds(new Rectangle(0, 0, width, height)); + // Set correct border on cell renderer. + // Only the lead selection cell gets a border + if (comp instanceof JComponent) + { + if (table.getSelectionModel().getLeadSelectionIndex() == r + && table.getColumnModel().getSelectionModel(). + getLeadSelectionIndex() == c) + ((JComponent) comp).setBorder(highlightCellBorder); + else + ((JComponent) comp).setBorder(cellBorder); + } comp.paint(gfx); gfx.translate(-x, -y); } @@ -347,5 +800,4 @@ public class BasicTableUI } } - } diff --git a/javax/swing/plaf/basic/BasicTextAreaUI.java b/javax/swing/plaf/basic/BasicTextAreaUI.java index 61d025ddd..97b0ccb6e 100644 --- a/javax/swing/plaf/basic/BasicTextAreaUI.java +++ b/javax/swing/plaf/basic/BasicTextAreaUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/basic/BasicTextFieldUI.java b/javax/swing/plaf/basic/BasicTextFieldUI.java index e7cf33b1b..a300446c2 100644 --- a/javax/swing/plaf/basic/BasicTextFieldUI.java +++ b/javax/swing/plaf/basic/BasicTextFieldUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/basic/BasicTextPaneUI.java b/javax/swing/plaf/basic/BasicTextPaneUI.java index ac20a0a99..55d908e1b 100644 --- a/javax/swing/plaf/basic/BasicTextPaneUI.java +++ b/javax/swing/plaf/basic/BasicTextPaneUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/basic/BasicTextUI.java b/javax/swing/plaf/basic/BasicTextUI.java index 1bb0fe4b2..acd0261ed 100644 --- a/javax/swing/plaf/basic/BasicTextUI.java +++ b/javax/swing/plaf/basic/BasicTextUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -78,10 +78,20 @@ import javax.swing.text.Position; import javax.swing.text.View; import javax.swing.text.ViewFactory; - +/** + * The abstract base class from which the UI classes for Swings text + * components are derived. This provides most of the functionality for + * the UI classes. + * + * @author original author unknown + * @author Roman Kennke (roman@kennke.org) + */ public abstract class BasicTextUI extends TextUI implements ViewFactory { + /** + * A {@link DefaultCaret} that implements {@link UIResource}. + */ public static class BasicCaret extends DefaultCaret implements UIResource { @@ -90,6 +100,9 @@ public abstract class BasicTextUI extends TextUI } } + /** + * A {@link DefaultHighlighter} that implements {@link UIResource}. + */ public static class BasicHighlighter extends DefaultHighlighter implements UIResource { @@ -97,40 +110,80 @@ public abstract class BasicTextUI extends TextUI { } } - + + /** + * This view forms the root of the View hierarchy. However, it delegates + * most calls to another View which is the real root of the hierarchy. + * The purpose is to make sure that all Views in the hierarchy, including + * the (real) root have a well-defined parent to which they can delegate + * calls like {@link #preferenceChanged}, {@link #getViewFactory} and + * {@link #getContainer}. + */ private class RootView extends View { + /** The real root view. */ private View view; - + + /** + * Creates a new RootView. + */ public RootView() { super(null); } - // View methods. - + /** + * Returns the ViewFactory for this RootView. If the current EditorKit + * provides a ViewFactory, this is used. Otherwise the TextUI itself + * is returned as a ViewFactory. + * + * @return the ViewFactory for this RootView + */ public ViewFactory getViewFactory() { - // FIXME: Handle EditorKit somehow. - return BasicTextUI.this; + ViewFactory factory = null; + EditorKit editorKit = BasicTextUI.this.getEditorKit(getComponent()); + factory = editorKit.getViewFactory(); + if (factory == null) + factory = BasicTextUI.this; + return factory; } + /** + * Sets the real root view. + * + * @param v the root view to set + */ public void setView(View v) { if (view != null) view.setParent(null); if (v != null) - v.setParent(null); + v.setParent(this); view = v; } + /** + * Returns the <code>Container</code> that contains this view. This + * normally will be the text component that is managed by this TextUI. + * + * @return the <code>Container</code> that contains this view + */ public Container getContainer() { return textComponent; } - + + /** + * Returns the preferred span along the specified <code>axis</code>. + * This is delegated to the real root view. + * + * @param axis the axis for which the preferred span is queried + * + * @return the preferred span along the axis + */ public float getPreferredSpan(int axis) { if (view != null) @@ -139,19 +192,47 @@ public abstract class BasicTextUI extends TextUI return Integer.MAX_VALUE; } + /** + * Paints the view. This is delegated to the real root view. + * + * @param g the <code>Graphics</code> context to paint to + * @param s the allocation for the View + */ public void paint(Graphics g, Shape s) { if (view != null) view.paint(g, s); } + + /** + * 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. + * + * This is delegated to the real root 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(int position, Shape a, Position.Bias bias) throws BadLocationException { if (view == null) return null; - return ((PlainView) view).modelToView(position, a, bias).getBounds(); + return ((View) view).modelToView(position, a, bias); } /** @@ -194,8 +275,16 @@ public abstract class BasicTextUI extends TextUI } } + /** + * Receives notifications when properties of the text component change. + */ class UpdateHandler implements PropertyChangeListener { + /** + * Notifies when a property of the text component changes. + * + * @param event the PropertyChangeEvent describing the change + */ public void propertyChange(PropertyChangeEvent event) { if (event.getPropertyName().equals("document")) @@ -208,7 +297,7 @@ public abstract class BasicTextUI extends TextUI /** * Listens for changes on the underlying model and forwards notifications - * to the View. + * to the View. This also updates the caret position of the text component. * * TODO: Maybe this should somehow be handled through EditorKits */ @@ -236,6 +325,9 @@ public abstract class BasicTextUI extends TextUI Dimension size = textComponent.getSize(); rootView.insertUpdate(ev, new Rectangle(0, 0, size.width, size.height), BasicTextUI.this); + int caretPos = textComponent.getCaretPosition(); + if (caretPos >= ev.getOffset()) + textComponent.setCaretPosition(caretPos + ev.getLength()); } /** @@ -248,37 +340,79 @@ public abstract class BasicTextUI extends TextUI Dimension size = textComponent.getSize(); rootView.removeUpdate(ev, new Rectangle(0, 0, size.width, size.height), BasicTextUI.this); + int caretPos = textComponent.getCaretPosition(); + if (caretPos >= ev.getOffset()) + textComponent.setCaretPosition(ev.getOffset()); } } + /** + * The EditorKit used by this TextUI. + */ + // FIXME: should probably be non-static. static EditorKit kit = new DefaultEditorKit(); + /** + * The root view. + */ RootView rootView = new RootView(); + + /** + * The text component that we handle. + */ JTextComponent textComponent; + + /** + * Receives notification when the model changes. + */ UpdateHandler updateHandler = new UpdateHandler(); /** The DocumentEvent handler. */ DocumentHandler documentHandler = new DocumentHandler(); + /** + * Creates a new <code>BasicTextUI</code> instance. + */ public BasicTextUI() { } + /** + * Creates a {@link Caret} that should be installed into the text component. + * + * @return a caret that should be installed into the text component + */ protected Caret createCaret() { return new BasicCaret(); } + /** + * Creates a {@link Highlighter} that should be installed into the text + * component. + * + * @return a <code>Highlighter</code> for the text component + */ protected Highlighter createHighlighter() { return new BasicHighlighter(); } - + + /** + * The text component that is managed by this UI. + * + * @return the text component that is managed by this UI + */ protected final JTextComponent getComponent() { return textComponent; } - + + /** + * Installs this UI on the text component. + * + * @param c the text component on which to install the UI + */ public void installUI(final JComponent c) { super.installUI(c); @@ -301,6 +435,9 @@ public abstract class BasicTextUI extends TextUI installKeyboardActions(); } + /** + * Installs UI defaults on the text components. + */ protected void installDefaults() { Caret caret = textComponent.getCaret(); @@ -325,6 +462,9 @@ public abstract class BasicTextUI extends TextUI caret.setBlinkRate(defaults.getInt(prefix + ".caretBlinkRate")); } + /** + * This FocusListener triggers repaints on focus shift. + */ private FocusListener focuslistener = new FocusListener() { public void focusGained(FocusEvent e) { @@ -336,6 +476,9 @@ public abstract class BasicTextUI extends TextUI } }; + /** + * Install all listeners on the text component. + */ protected void installListeners() { textComponent.addFocusListener(focuslistener); @@ -352,23 +495,49 @@ public abstract class BasicTextUI extends TextUI doc.addDocumentListener(documentHandler); } + /** + * Returns the name of the keymap for this type of TextUI. + * + * This is implemented so that the classname of this TextUI + * without the package prefix is returned. This way subclasses + * don't have to override this method. + * + * @return the name of the keymap for this TextUI + */ protected String getKeymapName() { - return "BasicTextUI"; + String fullClassName = getClass().getName(); + int index = fullClassName.lastIndexOf('.'); + String className = fullClassName.substring(index + 1); + return className; } + /** + * Creates the {@link Keymap} that is installed on the text component. + * + * @return the {@link Keymap} that is installed on the text component + */ protected Keymap createKeymap() { String prefix = getPropertyPrefix(); UIDefaults defaults = UIManager.getLookAndFeelDefaults(); JTextComponent.KeyBinding[] bindings = (JTextComponent.KeyBinding[]) defaults.get(prefix + ".keyBindings"); + if (bindings == null) + { + bindings = new JTextComponent.KeyBinding[0]; + defaults.put(prefix + ".keyBindings", bindings); + } + Keymap km = JTextComponent.addKeymap(getKeymapName(), JTextComponent.getKeymap(JTextComponent.DEFAULT_KEYMAP)); JTextComponent.loadKeymap(km, bindings, textComponent.getActions()); return km; } + /** + * Installs the keyboard actions on the text components. + */ protected void installKeyboardActions() { // load any bindings for the older Keymap interface @@ -384,6 +553,13 @@ public abstract class BasicTextUI extends TextUI SwingUtilities.replaceUIActionMap(textComponent, getActionMap()); } + /** + * Gets the input map for the specified <code>condition</code>. + * + * @param condition the condition for the InputMap + * + * @return the InputMap for the specified condition + */ InputMap getInputMap(int condition) { String prefix = getPropertyPrefix(); @@ -401,6 +577,13 @@ public abstract class BasicTextUI extends TextUI } } + /** + * Returns the ActionMap to be installed on the text component. + * + * @return the ActionMap to be installed on the text component + */ + // FIXME: The UIDefaults have no entries for .actionMap, so this should + // be handled somehow different. ActionMap getActionMap() { String prefix = getPropertyPrefix(); @@ -414,6 +597,11 @@ public abstract class BasicTextUI extends TextUI return am; } + /** + * Creates an ActionMap to be installed on the text component. + * + * @return an ActionMap to be installed on the text component + */ ActionMap createActionMap() { Action[] actions = textComponent.getActions(); @@ -426,7 +614,12 @@ public abstract class BasicTextUI extends TextUI } return am; } - + + /** + * Uninstalls this TextUI from the text component. + * + * @param component the text component to uninstall the UI from + */ public void uninstallUI(final JComponent component) { super.uninstallUI(component); @@ -441,23 +634,49 @@ public abstract class BasicTextUI extends TextUI textComponent = null; } + /** + * Uninstalls all default properties that have previously been installed by + * this UI. + */ protected void uninstallDefaults() { // Do nothing here. } + /** + * Uninstalls all listeners that have previously been installed by + * this UI. + */ protected void uninstallListeners() { textComponent.removeFocusListener(focuslistener); } + /** + * Uninstalls all keyboard actions that have previously been installed by + * this UI. + */ protected void uninstallKeyboardActions() { - // Do nothing here. + // FIXME: Uninstall keyboard actions here. } - + + /** + * Returns the property prefix by which the text component's UIDefaults + * are looked up. + * + * @return the property prefix by which the text component's UIDefaults + * are looked up + */ protected abstract String getPropertyPrefix(); + /** + * Returns the preferred size of the text component. + * + * @param c not used here + * + * @return the preferred size of the text component + */ public Dimension getPreferredSize(JComponent c) { View v = getRootView(textComponent); @@ -473,6 +692,8 @@ public abstract class BasicTextUI extends TextUI * * This returns (Integer.MAX_VALUE, Integer.MAX_VALUE). * + * @param c not used here + * * @return the maximum size for text components that use this UI */ public Dimension getMaximumSize(JComponent c) @@ -481,11 +702,22 @@ public abstract class BasicTextUI extends TextUI return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE); } + /** + * Paints the text component. + * + * @param g the <code>Graphics</code> context to paint to + * @param c not used here + */ public final void paint(Graphics g, JComponent c) { paintSafely(g); } + /** + * Actually performs the painting. + * + * @param g the <code>Graphics</code> context to paint to + */ protected void paintSafely(Graphics g) { Caret caret = textComponent.getCaret(); @@ -504,74 +736,213 @@ public abstract class BasicTextUI extends TextUI caret.paint(g); } + /** + * Paints the background of the text component. + * + * @param g the <code>Graphics</code> context to paint to + */ protected void paintBackground(Graphics g) { g.setColor(textComponent.getBackground()); g.fillRect(0, 0, textComponent.getWidth(), textComponent.getHeight()); } + /** + * Marks the specified range inside the text component's model as + * damaged and queues a repaint request. + * + * @param t the text component + * @param p0 the start location inside the document model of the range that + * is damaged + * @param p1 the end location inside the document model of the range that + * is damaged + */ public void damageRange(JTextComponent t, int p0, int p1) { damageRange(t, p0, p1, null, null); } + /** + * Marks the specified range inside the text component's model as + * damaged and queues a repaint request. This variant of this method + * allows a {@link Position.Bias} object to be specified for the start + * and end location of the range. + * + * @param t the text component + * @param p0 the start location inside the document model of the range that + * is damaged + * @param p1 the end location inside the document model of the range that + * is damaged + * @param firstBias the bias for the start location + * @param secondBias the bias for the end location + */ public void damageRange(JTextComponent t, int p0, int p1, Position.Bias firstBias, Position.Bias secondBias) { + // TODO: Implement me. } + /** + * Returns the {@link EditorKit} used for the text component that is managed + * by this UI. + * + * @param t the text component + * + * @return the {@link EditorKit} used for the text component that is managed + * by this UI + */ public EditorKit getEditorKit(JTextComponent t) { return kit; } + /** + * Gets the next position inside the document model that is visible on + * screen, starting from <code>pos</code>. + * + * @param t the text component + * @param pos the start positionn + * @param b the bias for pos + * @param direction the search direction + * @param biasRet filled by the method to indicate the bias of the return + * value + * + * @return the next position inside the document model that is visible on + * screen + */ public int getNextVisualPositionFrom(JTextComponent t, int pos, Position.Bias b, int direction, Position.Bias[] biasRet) throws BadLocationException { - return 0; + return 0; // TODO: Implement me. } + /** + * Returns the root {@link View} of a text component. + * + * @return the root {@link View} of a text component + */ public View getRootView(JTextComponent t) { return rootView; } + /** + * 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. A bias of {@link Position.Bias.Forward} is used in this method. + * + * @param pos the position of the character in the model + * @param a the area that is occupied by the view + * + * @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 Rectangle modelToView(JTextComponent t, int pos) throws BadLocationException { return modelToView(t, pos, Position.Bias.Forward); } + /** + * 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 Rectangle modelToView(JTextComponent t, int pos, Position.Bias bias) throws BadLocationException { return rootView.modelToView(pos, getVisibleEditorRect(), bias).getBounds(); } + /** + * Maps a point in the <code>View</code> coordinate space to a position + * inside a document model. + * + * @param t the text component + * @param pt the point to be mapped + * + * @return the position inside the document model that corresponds to + * <code>pt</code> + */ public int viewToModel(JTextComponent t, Point pt) { return viewToModel(t, pt, null); } + /** + * Maps a point in the <code>View</code> coordinate space to a position + * inside a document model. + * + * @param t the text component + * @param pt the point to be mapped + * @param biasReturn filled in by the method to indicate the bias of the + * return value + * + * @return the position inside the document model that corresponds to + * <code>pt</code> + */ public int viewToModel(JTextComponent t, Point pt, Position.Bias[] biasReturn) { - return 0; + return 0; // FIXME: Implement me. } + /** + * Creates a {@link View} for the specified {@link Element}. + * + * @param elem the <code>Element</code> to create a <code>View</code> for + * + * @see ViewFactory + */ public View create(Element elem) { // Subclasses have to implement this to get this functionality. return null; } + /** + * Creates a {@link View} for the specified {@link Element}. + * + * @param elem the <code>Element</code> to create a <code>View</code> for + * @param p0 the start offset + * @param p1 the end offset + * + * @see ViewFactory + */ public View create(Element elem, int p0, int p1) { // Subclasses have to implement this to get this functionality. return null; } - + + /** + * Returns the allocation to give the root view. + * + * @return the allocation to give the root view + * + * @specnote The allocation has nothing to do with visibility. According + * to the specs the naming of this method is unfortunate and + * has historical reasons + */ protected Rectangle getVisibleEditorRect() { int width = textComponent.getWidth(); @@ -586,12 +957,20 @@ public abstract class BasicTextUI extends TextUI height - insets.top + insets.bottom); } + /** + * Sets the root view for the text component. + * + * @param view the <code>View</code> to be set as root view + */ protected final void setView(View view) { rootView.setView(view); - view.setParent(rootView); } + /** + * Indicates that the model of a text component has changed. This + * triggers a rebuild of the view hierarchy. + */ protected void modelChanged() { if (textComponent == null || rootView == null) diff --git a/javax/swing/plaf/basic/BasicToggleButtonUI.java b/javax/swing/plaf/basic/BasicToggleButtonUI.java index 677e6a575..84509ad6e 100644 --- a/javax/swing/plaf/basic/BasicToggleButtonUI.java +++ b/javax/swing/plaf/basic/BasicToggleButtonUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/basic/BasicToolBarSeparatorUI.java b/javax/swing/plaf/basic/BasicToolBarSeparatorUI.java index 72554c0f4..db29fdca5 100644 --- a/javax/swing/plaf/basic/BasicToolBarSeparatorUI.java +++ b/javax/swing/plaf/basic/BasicToolBarSeparatorUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/basic/BasicToolBarUI.java b/javax/swing/plaf/basic/BasicToolBarUI.java index 18477c9dd..8be89efcf 100644 --- a/javax/swing/plaf/basic/BasicToolBarUI.java +++ b/javax/swing/plaf/basic/BasicToolBarUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -542,19 +542,6 @@ public class BasicToolBarUI extends ToolBarUI implements SwingConstants } /** - * This method returns the preferred size of the given JComponent for this - * UI. - * - * @param c The JComponent to find a preferred size for. - * - * @return The preferred size for this UI. - */ - public Dimension getPreferredSize(JComponent c) - { - return toolBar.getLayout().preferredLayoutSize(c); - } - - /** * This method installs the needed components for the JToolBar. */ protected void installComponents() diff --git a/javax/swing/plaf/basic/BasicToolTipUI.java b/javax/swing/plaf/basic/BasicToolTipUI.java index b561cce71..b7a08aa72 100644 --- a/javax/swing/plaf/basic/BasicToolTipUI.java +++ b/javax/swing/plaf/basic/BasicToolTipUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -97,7 +97,7 @@ public class BasicToolTipUI extends ToolTipUI * @param x The x coordinate to start painting at. * @param y The y coordinate to start painting at. * @param w The width of the Component. - * @param y The height of the Component. + * @param h The height of the Component. */ public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) diff --git a/javax/swing/plaf/basic/BasicTreeUI.java b/javax/swing/plaf/basic/BasicTreeUI.java index db74f067e..067cb0c3b 100644 --- a/javax/swing/plaf/basic/BasicTreeUI.java +++ b/javax/swing/plaf/basic/BasicTreeUI.java @@ -1,5 +1,5 @@ /* BasicTreeUI.java -- - Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. + Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -41,358 +41,2843 @@ package javax.swing.plaf.basic; import java.awt.Color; import java.awt.Component; import java.awt.Dimension; +import java.awt.Font; +import java.awt.FontMetrics; import java.awt.Graphics; +import java.awt.Point; import java.awt.Rectangle; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.ComponentAdapter; +import java.awt.event.ComponentEvent; +import java.awt.event.ComponentListener; +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.awt.event.MouseMotionListener; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.util.Hashtable; +import javax.swing.AbstractAction; +import javax.swing.Action; +import javax.swing.CellRendererPane; +import javax.swing.Icon; import javax.swing.JComponent; +import javax.swing.JScrollBar; +import javax.swing.JScrollPane; import javax.swing.JTree; +import javax.swing.SwingUtilities; +import javax.swing.Timer; import javax.swing.UIDefaults; import javax.swing.UIManager; +import javax.swing.event.CellEditorListener; +import javax.swing.event.ChangeEvent; +import javax.swing.event.MouseInputListener; +import javax.swing.event.TreeExpansionEvent; +import javax.swing.event.TreeExpansionListener; +import javax.swing.event.TreeModelEvent; +import javax.swing.event.TreeModelListener; +import javax.swing.event.TreeSelectionEvent; +import javax.swing.event.TreeSelectionListener; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.TreeUI; +import javax.swing.tree.AbstractLayoutCache; +import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.tree.DefaultTreeCellEditor; +import javax.swing.tree.DefaultTreeCellRenderer; +import javax.swing.tree.FixedHeightLayoutCache; +import javax.swing.tree.TreeCellEditor; +import javax.swing.tree.TreeCellRenderer; import javax.swing.tree.TreeModel; +import javax.swing.tree.TreeNode; import javax.swing.tree.TreePath; +import javax.swing.tree.TreeSelectionModel; /** - * A delegate providing the user interface for <code>JTree</code> - * according to the Basic look and feel. The current implementation - * of GNU Classpath does really work; it is just a stub that allows - * compiling the code. - * + * A delegate providing the user interface for <code>JTree</code> according to + * the Basic look and feel. + * * @see javax.swing.JTree - * * @author Sascha Brawer (brawer@dandelis.ch) + * @author Lillian Angel (langel@redhat.com) */ -public class BasicTreeUI - extends TreeUI +public class BasicTreeUI extends TreeUI { - + /** Collapse Icon for the tree. */ + protected transient Icon collapsedIcon; + + /** Expanded Icon for the tree. */ + protected transient Icon expandedIcon; + + /** Distance between left margin and where vertical dashes will be drawn. */ + protected int leftChildIndent; + + /** + * Distance between leftChildIndent and where cell contents will be drawn. + */ + protected int rightChildIndent; + + /** + * Total fistance that will be indented. The sum of leftChildIndent and + * rightChildIndent . + */ + protected int totalChildIndent; + + /** Minimum preferred size. */ + protected Dimension preferredMinsize; + + /** Index of the row that was last selected. */ + protected int lastSelectedRow; + + /** Component that we're going to be drawing onto. */ + protected JTree tree; + + /** Renderer that is being used to do the actual cell drawing. */ + protected transient TreeCellRenderer currentCellRenderer; + + /** + * Set to true if the renderer that is currently in the tree was created by + * this instance. + */ + protected boolean createdRenderer; + + /** Editor for the tree. */ + protected transient TreeCellEditor cellEditor; + + /** + * Set to true if editor that is currently in the tree was created by this + * instance. + */ + protected boolean createdCellEditor; + + /** + * Set to false when editing and shouldSelectCall() returns true meaning the + * node should be selected before editing, used in completeEditing. + */ + protected boolean stopEditingInCompleteEditing; + + /** Used to paint the TreeCellRenderer. */ + protected CellRendererPane rendererPane; + + /** Size needed to completely display all the nodes. */ + protected Dimension preferredSize; + + /** Is the preferredSize valid? */ + protected boolean validCachedPreferredSize; + + /** Object responsible for handling sizing and expanded issues. */ + protected AbstractLayoutCache treeState; + + /** Used for minimizing the drawing of vertical lines. */ + protected Hashtable drawingCache; + + /** + * True if doing optimizations for a largeModel. Subclasses that don't + * support this may wish to override createLayoutCache to not return a + * FixedHeightLayoutCache instance. + */ + protected boolean largeModel; + + /** Responsible for telling the TreeState the size needed for a node. */ + protected AbstractLayoutCache.NodeDimensions nodeDimensions; + + /** Used to determine what to display. */ + protected TreeModel treeModel; + + /** Model maintaining the selection. */ + protected TreeSelectionModel treeSelectionModel; + + /** + * How much the depth should be offset to properly calculate x locations. + * This is based on whether or not the root is visible, and if the root + * handles are visible. + */ + protected int depthOffset; + + /** + * When editing, this will be the Component that is doing the actual editing. + */ + protected Component editingComponent; + + /** Path that is being edited. */ + protected TreePath editingPath; + + /** + * Row that is being edited. Should only be referenced if editingComponent is + * null. + */ + protected int editingRow; + + /** Set to true if the editor has a different size than the renderer. */ + protected boolean editorHasDifferentSize; + + /** Listeners */ + private PropertyChangeListener propertyChangeListener; + private FocusListener focusListener; + private TreeSelectionListener treeSelectionListener; + private MouseInputListener mouseInputListener; + private KeyListener keyListener; + private PropertyChangeListener selectionModelPropertyChangeListener; + private ComponentListener componentListener; + private CellEditorListener cellEditorListener; + private TreeExpansionListener treeExpansionListener; + private TreeModelListener treeModelListener; + + /** + * Creates a new BasicTreeUI object. + */ + public BasicTreeUI() + { + drawingCache = new Hashtable(); + cellEditor = createDefaultCellEditor(); + currentCellRenderer = createDefaultCellRenderer(); + nodeDimensions = createNodeDimensions(); + rendererPane = createCellRendererPane(); + configureLayoutCache(); + + propertyChangeListener = createPropertyChangeListener(); + focusListener = createFocusListener(); + treeSelectionListener = createTreeSelectionListener(); + mouseInputListener = new MouseInputHandler(null, null, null); + keyListener = createKeyListener(); + selectionModelPropertyChangeListener = createSelectionModelPropertyChangeListener(); + componentListener = createComponentListener(); + cellEditorListener = createCellEditorListener(); + treeExpansionListener = createTreeExpansionListener(); + treeModelListener = createTreeModelListener(); + + createdRenderer = true; + createdCellEditor = true; + editingRow = -1; + lastSelectedRow = -1; + } + + /** + * Returns an instance of the UI delegate for the specified component. + * + * @param c the <code>JComponent</code> for which we need a UI delegate + * for. + * @return the <code>ComponentUI</code> for c. + */ + public static ComponentUI createUI(JComponent c) + { + return new BasicTreeUI(); + } + + /** + * Returns the Hash color. + * + * @return the <code>Color</code> of the Hash. + */ + protected Color getHashColor() + { + return UIManager.getLookAndFeelDefaults().getColor("Tree.hash"); + } + + /** + * Sets the Hash color. + * + * @param color the <code>Color</code> to set the Hash to. + */ + protected void setHashColor(Color color) + { + // FIXME: not implemented + + } + + /** + * Sets the left child's indent value. + * + * @param newAmount is the new indent value for the left child. + */ + public void setLeftChildIndent(int newAmount) + { + leftChildIndent = newAmount; + } + + /** + * Returns the indent value for the left child. + * + * @return the indent value for the left child. + */ + public int getLeftChildIndent(int newAmount) + { + return leftChildIndent; + } + + /** + * Sets the right child's indent value. + * + * @param newAmount is the new indent value for the right child. + */ + public void setRightChildIndent(int newAmount) + { + rightChildIndent = newAmount; + } + + /** + * Returns the indent value for the right child. + * + * @return the indent value for the right child. + */ + public int getRightChildIndent(int newAmount) + { + return rightChildIndent; + } + + /** + * Sets the expanded icon. + * + * @param newG is the new expanded icon. + */ + public void setExpandedIcon(Icon newG) + { + expandedIcon = newG; + } + + /** + * Returns the current expanded icon. + * + * @return the current expanded icon. + */ + public Icon getExpandedIcon() + { + return expandedIcon; + } + + /** + * Sets the collapsed icon. + * + * @param newG is the new collapsed icon. + */ + public void setCollapsedIcon(Icon newG) + { + collapsedIcon = newG; + } + + /** + * Returns the current collapsed icon. + * + * @return the current collapsed icon. + */ + public Icon getCollapsedIcon() + { + return collapsedIcon; + } + + /** + * Updates the componentListener, if necessary. + * + * @param largeModel sets this.largeModel to it. + */ + protected void setLargeModel(boolean largeModel) + { + if (largeModel != this.largeModel) + { + tree.removeComponentListener(componentListener); + this.largeModel = largeModel; + tree.addComponentListener(componentListener); + } + } + + /** + * Returns true if largeModel is set + * + * @return true if largeModel is set, otherwise false. + */ + protected boolean isLargeModel() + { + return largeModel; + } + + /** + * Sets the row height. + * + * @param rowHeight is the height to set this.rowHeight to. + */ + protected void setRowHeight(int rowHeight) + { + treeState.setRowHeight(rowHeight); + } + + /** + * Returns the current row height. + * + * @return current row height. + */ + protected int getRowHeight() + { + return treeState.getRowHeight(); + } + + /** + * Sets the TreeCellRenderer to <code>tcr</code>. This invokes + * <code>updateRenderer</code>. + * + * @param tcr is the new TreeCellRenderer. + */ + protected void setCellRenderer(TreeCellRenderer tcr) + { + currentCellRenderer = tcr; + updateRenderer(); + } + + /** + * Return currentCellRenderer, which will either be the trees renderer, or + * defaultCellRenderer, which ever was not null. + * + * @return the current Cell Renderer + */ + protected TreeCellRenderer getCellRenderer() + { + if (currentCellRenderer != null) + return currentCellRenderer; + + return createDefaultCellRenderer(); + } + + /** + * Sets the tree's model. + * + * @param model to set the treeModel to. + */ + protected void setModel(TreeModel model) + { + tree.setModel(model); + treeModel = model; + } + + /** + * Returns the tree's model + * + * @return treeModel + */ + protected TreeModel getModel() + { + return treeModel; + } + /** - * Determines the geometric extent of the label that is - * drawn for a path. - * - * @param tree the <code>JTree</code> for which this delegate - * object provides the user interface. - * - * @param path the path whose label extent is requested. - * - * @return a rectangle enclosing the label, or <code>null</code> - * if <code>path</code> contains invalid nodes. + * Sets the root to being visible. + * + * @param newValue sets the visibility of the root + */ + protected void setRootVisible(boolean newValue) + { + tree.setRootVisible(newValue); + } + + /** + * Returns true if the root is visible. + * + * @return true if the root is visible. + */ + protected boolean isRootVisible() + { + return tree.isRootVisible(); + } + + /** + * Determines whether the node handles are to be displayed. + * + * @param newValue sets whether or not node handles should be displayed. + */ + protected void setShowsRootHandles(boolean newValue) + { + tree.setShowsRootHandles(newValue); + } + + /** + * Returns true if the node handles are to be displayed. + * + * @return true if the node handles are to be displayed. + */ + protected boolean getShowsRootHandles() + { + return tree.getShowsRootHandles(); + } + + /** + * Sets the cell editor. + * + * @param editor to set the cellEditor to. + */ + protected void setCellEditor(TreeCellEditor editor) + { + cellEditor = editor; + } + + /** + * Returns the <code>TreeCellEditor</code> for this tree. + * + * @return the cellEditor for this tree. + */ + protected TreeCellEditor getCellEditor() + { + return cellEditor; + } + + /** + * Configures the receiver to allow, or not allow, editing. + * + * @param newValue sets the receiver to allow editing if true. + */ + protected void setEditable(boolean newValue) + { + tree.setEditable(newValue); + } + + /** + * Returns true if the receiver allows editing. + * + * @return true if the receiver allows editing. + */ + protected boolean isEditable() + { + return tree.isEditable(); + } + + /** + * Resets the selection model. The appropriate listeners are installed on the + * model. + * + * @param newLSM resets the selection model. + */ + protected void setSelectionModel(TreeSelectionModel newLSM) + { + if (newLSM != null) + { + treeSelectionModel = newLSM; + tree.setSelectionModel(treeSelectionModel); + } + } + + /** + * Returns the current selection model. + * + * @return the current selection model. + */ + protected TreeSelectionModel getSelectionModel() + { + return treeSelectionModel; + } + + /** + * Returns the Rectangle enclosing the label portion that the last item in + * path will be drawn to. Will return null if any component in path is + * currently valid. + * + * @param tree is the current tree the path will be drawn to. + * @param path is the current path the tree to draw to. + * @return the Rectangle enclosing the label portion that the last item in + * the path will be drawn to. */ public Rectangle getPathBounds(JTree tree, TreePath path) { - return null; // FIXME: not implemented + if (path != null) + { + Object cell = path.getLastPathComponent(); + TreeModel mod = tree.getModel(); + DefaultMutableTreeNode root = (DefaultMutableTreeNode) mod.getRoot(); + if (!tree.isRootVisible() + && tree.isExpanded(new TreePath(root))) + root = root.getNextNode(); + + Point loc = getCellLocation(0, 0, tree, mod, cell, root); + return getCellBounds(loc.x, loc.y, cell); + } + return null; } - - + /** - * Creates a <code>TreePath</code> for the specified row. - * - * @param tree the <code>JTree</code> for which this delegate - * object provides the user interface. - * - * @param row the index of the row, which should be a number - * in the range <code>[0, getRowCount(tree) - 1]</code>. - * - * @return a <code>TreePath</code> for the specified row, or - * <code>null</code> if <code>row</code> is outside - * the valid range. + * Returns the path for passed in row. If row is not visible null is + * returned. + * + * @param tree is the current tree to return path for. + * @param row is the row number of the row to return. + * @return the path for passed in row. If row is not visible null is + * returned. */ public TreePath getPathForRow(JTree tree, int row) { - return null; // FIXME: not implemented + DefaultMutableTreeNode node = ((DefaultMutableTreeNode) (tree.getModel()) + .getRoot()); + if (!tree.isRootVisible() + && tree.isExpanded(new TreePath(((DefaultMutableTreeNode) node) + .getPath()))) + node = node.getNextNode(); + + for (int i = 0; i < row; i++) + node = getNextVisibleNode(node); + + // in case nothing was found + if (node == null) + return null; + + // something was found + return new TreePath(node.getPath()); } - - + /** - * Determines in which row a <code>TreePath</code> is currently - * being displayed. - * - * @param tree the <code>JTree</code> for which this delegate - * object provides the user interface. - * - * @param path the path for which the caller wants to know - * in which row it is being displayed. - * - * @return a number in the range <code>[0, getRowCount(tree) - * - 1]</code> if the path is currently on display; - * <code>-1</code> if the path is not shown to the - * user. + * Returns the row that the last item identified in path is visible at. Will + * return -1 if any of the elments in the path are not currently visible. + * + * @param tree is the current tree to return the row for. + * @param path is the path used to find the row. + * @return the row that the last item identified in path is visible at. Will + * return -1 if any of the elments in the path are not currently + * visible. */ public int getRowForPath(JTree tree, TreePath path) { - return -1; // FIXME: not implemented + // FIXME: check visibility + // right now, just returns last element because + // expand/collapse is not implemented + return path.getPathCount() - 1; } - - + /** - * Counts how many rows are currently displayed. - * - * @param tree the <code>JTree</code> for which this delegate - * object provides the user interface. - * - * @return the number of visible rows. + * Returns the number of rows that are being displayed. + * + * @param tree is the current tree to return the number of rows for. + * @return the number of rows being displayed. */ public int getRowCount(JTree tree) { - return 0; // FIXME: not implemented + DefaultMutableTreeNode node = ((DefaultMutableTreeNode) (tree.getModel()) + .getRoot()); + if (!tree.isRootVisible() + && tree.isExpanded(new TreePath(((DefaultMutableTreeNode) node) + .getPath()))) + node = node.getNextNode(); + + int count = 0; + + while (node != null) + { + count++; + node = getNextVisibleNode(node); + } + + return count; } - - + /** - * Finds the path that is closest to the specified position. - * - * <p><img src="../doc-files/TreeUI-1.png" width="300" height="250" - * alt="[A screen shot of a JTree]" /> - * - * <p>As shown by the above illustration, the bounds of the - * closest path do not necessarily need to contain the passed - * location. - * - * @param tree the <code>JTree</code> for which this delegate - * object provides the user interface. - * - * @param x the horizontal location, relative to the origin - * of <code>tree</code>. - * - * @param y the vertical location, relative to the origin - * of <code>tree</code>. - * - * @return the closest path, or <code>null</code> if the - * tree is currenlty not displaying any paths at all. - */ - public TreePath getClosestPathForLocation(JTree tree, - int x, int y) - { - return null; // FIXME: not implemented + * Returns the path to the node that is closest to x,y. If there is nothing + * currently visible this will return null, otherwise it'll always return a + * valid path. If you need to test if the returned object is exactly at x,y + * you should get the bounds for the returned path and test x,y against that. + * + * @param tree the tree to search for the closest path + * @param x is the x coordinate of the location to search + * @param y is the y coordinate of the location to search + * @return the tree path closes to x,y. + */ + public TreePath getClosestPathForLocation(JTree tree, int x, int y) + { + //FIXME: what if root is hidden? should not depend on (0,0) + // should start counting rows from where root is. + + int row = Math.round(y / getRowHeight()); + TreePath path = getPathForRow(tree, row); + + // no row is visible at this node + while (row > 0 && path == null) + { + --row; + path = getPathForRow(tree, row); + } + + return path; } - - + /** - * Determines whether the user is currently editing a tree cell. - * - * @param tree the <code>JTree</code> for which this delegate - * object provides the user interface. - * - * @see #getEditingPath + * Returns true if the tree is being edited. The item that is being edited + * can be returned by getEditingPath(). + * + * @param tree is the tree to check for editing. + * @return true if the tree is being edited. */ public boolean isEditing(JTree tree) { - return false; // FIXME: not implemented + // FIXME: not implemented + return false; } - - + /** - * Stops editing a tree cell, committing the entered value into the - * tree’s model. If no editing session is active, or if the - * active editor does not agree to stopping, nothing happens. In - * some look and feels, this action happens when the user has - * pressed the enter key. - * - * @param tree the <code>JTree</code> for which this delegate - * object provides the user interface. - * - * @return <code>false</code> if the editing still goes on because - * the cell editor has objected to stopping the session; - * <code>true</code> if editing has been stopped. + * Stops the current editing session. This has no effect if the tree is not + * being edited. Returns true if the editor allows the editing session to + * stop. + * + * @param tree is the tree to stop the editing on + * @return true if the editor allows the editing session to stop. */ public boolean stopEditing(JTree tree) { - return true; // FIXME: not implemented + // FIXME: not implemented + return false; } - + /** - * Cancels editing a tree cell, discarding any entered value. - * If no editing session is active, nothing happens. The cell - * editor is not given an opportunity to veto the canceling. - * In some look and feels, this action happens when the user has - * pressed the escape key. - * - * @param tree the <code>JTree</code> for which this delegate - * object provides the user interface. + * Cancels the current editing session. + * + * @param tree is the tree to cancel the editing session on. */ public void cancelEditing(JTree tree) { // FIXME: not implemented } - - + /** - * Starts a session to edit a tree cell. If the cell editor - * rejects editing the cell, it will just be selected. - * - * @param tree the <code>JTree</code> for which this delegate - * object provides the user interface. - * - * @param path the cell to edit. + * Selects the last item in path and tries to edit it. Editing will fail if + * the CellEditor won't allow it for the selected item. + * + * @param tree is the tree to edit on. + * @param path is the path in tree to edit on. */ public void startEditingAtPath(JTree tree, TreePath path) { // FIXME: not implemented } - - + /** - * Retrieves the tree cell that is currently being edited. - * - * @return the currently edited path, or <code>null</code> - * if no editing session is currently active. + * Returns the path to the element that is being editted. + * + * @param tree is the tree to get the editing path from. + * @return the path that is being edited. */ public TreePath getEditingPath(JTree tree) { - return null; // FIXME: not implemented + // FIXME: not implemented + return null; } - - public static ComponentUI createUI(JComponent c) + + /** + * Invoked after the tree instance variable has been set, but before any + * default/listeners have been installed. + */ + protected void prepareForUIInstall() { - return new BasicTreeUI(); + // FIXME: not implemented } - - int rightChildIndent; - int leftChildIndent; - int rowHeight; - Color hashColor; - - protected void installDefaults(JTree tree) + + /** + * Invoked from installUI after all the defaults/listeners have been + * installed. + */ + protected void completeUIInstall() + { + // FIXME: not implemented + } + + /** + * Invoked from uninstallUI after all the defaults/listeners have been + * uninstalled. + */ + protected void completeUIUninstall() + { + // FIXME: not implemented + } + + /** + * Installs the subcomponents of the tree, which is the renderer pane. + */ + protected void installComponents() + { + // FIXME: not implemented + } + + /** + * Creates an instance of NodeDimensions that is able to determine the size + * of a given node in the tree. + * + * @return the NodeDimensions of a given node in the tree + */ + protected AbstractLayoutCache.NodeDimensions createNodeDimensions() + { + // FIXME: not implemented + return null; + } + + /** + * Creates a listener that is reponsible for the updates the UI based on how + * the tree changes. + * + * @return the PropertyChangeListener that is reposnsible for the updates + */ + protected PropertyChangeListener createPropertyChangeListener() + { + return new PropertyChangeHandler(); + } + + /** + * Creates the listener responsible for updating the selection based on mouse + * events. + * + * @return the MouseListener responsible for updating. + */ + protected MouseListener createMouseListener() + { + return new MouseHandler(); + } + + /** + * Creates the listener that is responsible for updating the display when + * focus is lost/grained. + * + * @return the FocusListener responsible for updating. + */ + protected FocusListener createFocusListener() + { + return new FocusHandler(); + } + + /** + * Creates the listener reponsible for getting key events from the tree. + * + * @return the KeyListener responsible for getting key events. + */ + protected KeyListener createKeyListener() + { + return new KeyHandler(); + } + + /** + * Creates the listener responsible for getting property change events from + * the selection model. + * + * @returns the PropertyChangeListener reponsible for getting property change + * events from the selection model. + */ + protected PropertyChangeListener createSelectionModelPropertyChangeListener() + { + return new SelectionModelPropertyChangeHandler(); + } + + /** + * Creates the listener that updates the display based on selection change + * methods. + * + * @return the TreeSelectionListener responsible for updating. + */ + protected TreeSelectionListener createTreeSelectionListener() + { + return new TreeSelectionHandler(); + } + + /** + * Creates a listener to handle events from the current editor + * + * @return the CellEditorListener that handles events from the current editor + */ + protected CellEditorListener createCellEditorListener() + { + return new CellEditorHandler(); + } + + /** + * Creates and returns a new ComponentHandler. This is used for the large + * model to mark the validCachedPreferredSize as invalid when the component + * moves. + * + * @return a new ComponentHandler. + */ + protected ComponentListener createComponentListener() + { + return new ComponentHandler(); + } + + /** + * Creates and returns the object responsible for updating the treestate when + * a nodes expanded state changes. + * + * @return the TreeExpansionListener responsible for updating the treestate + */ + protected TreeExpansionListener createTreeExpansionListener() + { + return new TreeExpansionHandler(); + } + + /** + * Creates the object responsible for managing what is expanded, as well as + * the size of nodes. + * + * @return the object responsible for managing what is expanded. + */ + protected AbstractLayoutCache createLayoutCache() + { + return new FixedHeightLayoutCache(); + } + + /** + * Returns the renderer pane that renderer components are placed in. + * + * @return the rendererpane that render components are placed in. + */ + protected CellRendererPane createCellRendererPane() + { + return new CellRendererPane(); + } + + /** + * Creates a default cell editor. + * + * @return the default cell editor. + */ + protected TreeCellEditor createDefaultCellEditor() + { + return new DefaultTreeCellEditor(tree, + (DefaultTreeCellRenderer) createDefaultCellRenderer(), cellEditor); + } + + /** + * Returns the default cell renderer that is used to do the stamping of each + * node. + * + * @return the default cell renderer that is used to do the stamping of each + * node. + */ + protected TreeCellRenderer createDefaultCellRenderer() + { + return new DefaultTreeCellRenderer(); + } + + /** + * Returns a listener that can update the tree when the model changes. + * + * @return a listener that can update the tree when the model changes. + */ + protected TreeModelListener createTreeModelListener() + { + return new TreeModelHandler(); + } + + /** + * Uninstall all registered listeners + */ + protected void uninstallListeners() + { + tree.removePropertyChangeListener(propertyChangeListener); + tree.removeFocusListener(focusListener); + tree.removeTreeSelectionListener(treeSelectionListener); + tree.removeMouseListener(mouseInputListener); + tree.removeKeyListener(keyListener); + tree.removePropertyChangeListener(selectionModelPropertyChangeListener); + tree.removeComponentListener(componentListener); + tree.removeTreeExpansionListener(treeExpansionListener); + + TreeCellEditor tce = tree.getCellEditor(); + if (tce != null) + tce.removeCellEditorListener(cellEditorListener); + TreeModel tm = tree.getModel(); + if (tm != null) + tm.removeTreeModelListener(treeModelListener); + } + + /** + * Uninstall all keyboard actions. + */ + protected void uninstallKeyboardActions() + { + } + + /** + * Uninstall the rendererPane. + */ + protected void uninstallComponents() + { + // FIXME: not implemented + } + + /** + * The vertical element of legs between nodes starts at the bottom of the + * parent node by default. This method makes the leg start below that. + * + * @return the vertical leg buffer + */ + protected int getVerticalLegBuffer() + { + // FIXME: not implemented + return 0; + } + + /** + * The horizontal element of legs between nodes starts at the right of the + * left-hand side of the child node by default. This method makes the leg end + * before that. + * + * @return the horizontal leg buffer + */ + protected int getHorizontalLegBuffer() + { + // FIXME: not implemented + return 0; + } + + /** + * Make all the nodes that are expanded in JTree expanded in LayoutCache. + * This invokes update ExpandedDescendants with the root path. + */ + protected void updateLayoutCacheExpandedNodes() + { + // FIXME: not implemented + } + + /** + * Updates the expanded state of all the descendants of the <code>path</code> + * by getting the expanded descendants from the tree and forwarding to the + * tree state. + * + * @param path the path used to update the expanded states + */ + protected void updateExpandedDescendants(TreePath path) + { + // FIXME: not implemented + } + + /** + * Returns a path to the last child of <code>parent</code> + * + * @param parent is the topmost path to specified + * @return a path to the last child of parent + */ + protected TreePath getLastChildPath(TreePath parent) + { + return ((TreePath) parent.getLastPathComponent()); + } + + /** + * Updates how much each depth should be offset by. + */ + protected void updateDepthOffset() + { + // FIXME: not implemented + } + + /** + * Updates the cellEditor based on editability of the JTree that we're + * contained in. Ig the tree is editable but doesn't have a cellEditor, a + * basic one will be used. + */ + protected void updateCellEditor() + { + // FIXME: not implemented + } + + /** + * Messaged from the tree we're in when the renderer has changed. + */ + protected void updateRenderer() + { + // FIXME: not implemented + } + + /** + * Resets the treeState instance based on the tree we're providing the look + * and feel for. + */ + protected void configureLayoutCache() + { + treeState = createLayoutCache(); + } + + /** + * Marks the cached size as being invalid, and messages the tree with + * <code>treeDidChange</code>. + */ + protected void updateSize() + { + // FIXME: not implemented + } + + /** + * Updates the <code>preferredSize</code> instance variable, which is + * returned from <code>getPreferredSize()</code>. For left to right + * orientations, the size is determined from the current AbstractLayoutCache. + * For RTL orientations, the preferred size becomes the width minus the + * minimum x position. + */ + protected void updateCachedPreferredSize() + { + // FIXME: not implemented + } + + /** + * Messaged from the VisibleTreeNode after it has been expanded. + * + * @param path is the path that has been expanded. + */ + protected void pathWasExpanded(TreePath path) + { + // FIXME: not implemented + } + + /** + * Messaged from the VisibleTreeNode after it has collapsed + */ + protected void pathWasCollapsed(TreePath path) + { + // FIXME: not implemented + } + + /** + * Install all defaults for the tree. + * + * @param tree is the JTree to install defaults for + */ + protected void installDefaults(JTree tree) { UIDefaults defaults = UIManager.getLookAndFeelDefaults(); - + tree.setFont(defaults.getFont("Tree.font")); tree.setForeground(defaults.getColor("Tree.foreground")); tree.setBackground(defaults.getColor("Tree.background")); tree.setOpaque(true); - - hashColor = defaults.getColor("Tree.hash"); + rightChildIndent = defaults.getInt("Tree.rightChildIndent"); leftChildIndent = defaults.getInt("Tree.leftChildIndent"); - rowHeight = defaults.getInt("Tree.rowHeight"); + setRowHeight(defaults.getInt("Tree.rowHeight")); } - - protected void installKeyboardActions() + + /** + * Install all keyboard actions for this + */ + protected void installKeyboardActions() { } - - protected void installListeners() + + /** + * Install all listeners for this + */ + protected void installListeners() { + tree.addPropertyChangeListener(propertyChangeListener); + tree.addFocusListener(focusListener); + tree.addTreeSelectionListener(treeSelectionListener); + tree.addMouseListener(mouseInputListener); + tree.addKeyListener(keyListener); + tree.addPropertyChangeListener(selectionModelPropertyChangeListener); + tree.addComponentListener(componentListener); + cellEditor.addCellEditorListener(cellEditorListener); + tree.addTreeExpansionListener(treeExpansionListener); + treeModel.addTreeModelListener(treeModelListener); } - + + /** + * Install the UI for the component + * + * @param c the component to install UI for + */ public void installUI(JComponent c) { + super.installUI(c); installDefaults((JTree) c); + tree = (JTree) c; + setModel(tree.getModel()); + tree.setRootVisible(true); + tree.expandPath(new TreePath(tree.getModel().getRoot())); + treeSelectionModel = tree.getSelectionModel(); + installListeners(); + installKeyboardActions(); + completeUIInstall(); } - - - protected void uninstallDefaults(JTree tree) + + /** + * Uninstall the defaults for the tree + * + * @param tree to uninstall defaults for + */ + protected void uninstallDefaults(JTree tree) { + UIDefaults defaults = UIManager.getLookAndFeelDefaults(); tree.setFont(null); tree.setForeground(null); tree.setBackground(null); - tree.setCellRenderer(null); } - + + /** + * Uninstall the UI for the component + * + * @param c the component to uninstall UI for + */ public void uninstallUI(JComponent c) { uninstallDefaults((JTree) c); + uninstallKeyboardActions(); + uninstallListeners(); + tree = null; + completeUIUninstall(); } - + + /** + * Paints the specified component appropriate for the look and feel. This + * method is invoked from the ComponentUI.update method when the specified + * component is being painted. Subclasses should override this method and use + * the specified Graphics object to render the content of the component. + * + * @param g the Graphics context in which to paint + * @param c the component being painted; this argument is often ignored, but + * might be used if the UI object is stateless and shared by multiple + * components + */ + public void paint(Graphics g, JComponent c) + { + JTree tree = (JTree) c; + TreeModel mod = tree.getModel(); + Object root = mod.getRoot(); + + if (!tree.isRootVisible()) + tree.expandPath(new TreePath(root)); + + paintRecursive(g, 0, 0, 0, 0, tree, mod, root); + + if (hasControlIcons()) + paintControlIcons(g, 0, 0, 0, 0, tree, mod, root); + } + + /** + * Ensures that the rows identified by beginRow through endRow are visible. + * + * @param beginRow is the first row + * @param endRow is the last row + */ + protected void ensureRowsAreVisible(int beginRow, int endRow) + { + // FIXME: not implemented + } + + /** + * Sets the preferred minimum size. + * + * @param newSize is the new preferred minimum size. + */ + public void setPreferredMinSize(Dimension newSize) + { + // FIXME: not implemented + } + + /** + * Gets the preferred minimum size. + * + * @returns the preferred minimum size. + */ + public Dimension getPreferredMinSize() + { + // FIXME: not implemented + return null; + } + + /** + * Returns the preferred size to properly display the tree, this is a cover + * method for getPreferredSize(c, false). + * + * @param c the component whose preferred size is being queried; this + * argument is often ignored but might be used if the UI object is + * stateless and shared by multiple components + * @return the preferred size + */ public Dimension getPreferredSize(JComponent c) { - return new Dimension(200,200); + return getPreferredSize(c, false); } - - protected void paintLeaf(Graphics g, int x, int y, JTree tree, Object leaf) - { - Component c = tree.getCellRenderer().getTreeCellRendererComponent(tree, - leaf, - false, // selected - false, // expanded - true, // leaf - 0, // row - false // hasFocus - ); - g.translate(x, y); - c.paint(g); - g.translate(-x, -y); + + /** + * Returns the preferred size to represent the tree in c. If checkConsistancy + * is true, checkConsistancy is messaged first. + * + * @param c the component whose preferred size is being queried. + * @param checkConsistancy if true must check consistancy + * @return the preferred size + */ + public Dimension getPreferredSize(JComponent c, boolean checkConsistancy) + { + // FIXME: checkConsistancy not implemented, c not used + TreeNode node = ((TreeNode) (tree.getModel()) + .getRoot()); + int maxWidth = 0; + int count = 0; + if (node != null) + { + maxWidth = (int) (getCellBounds(0, 0, node).getWidth()); + while (node != null) + { + count++; + DefaultMutableTreeNode nextNode = getNextVisibleNode( + new DefaultMutableTreeNode(node)); + if (nextNode != null) + maxWidth = Math.max(maxWidth, (int) (getCellBounds(0, 0, nextNode) + .getWidth())); + node = nextNode; + } + } + return new Dimension(maxWidth, (getRowHeight() * count)); } - - protected void paintNonLeaf(Graphics g, int x, int y, JTree tree, Object nonLeaf) - { - Component c = tree.getCellRenderer().getTreeCellRendererComponent(tree, - nonLeaf, - false, // selected - false, // expanded - false, // leaf - 0, // row - false // hasFocus - ); - g.translate(x, y); - c.paint(g); - g.translate(-x, -y); + + /** + * Returns the minimum size for this component. Which will be the min + * preferred size or (0,0). + * + * @param c the component whose min size is being queried. + * @returns the preferred size or null + */ + public Dimension getMinimumSize(JComponent c) + { + // FIXME: not implemented + return getPreferredSize(c); } - - protected int paintRecursive(Graphics g, - int indentation, - int descent, - int childNumber, - int depth, - JTree tree, - TreeModel mod, - Object curr) + + /** + * Returns the maximum size for the component, which will be the preferred + * size if the instance is currently in JTree or (0,0). + * + * @param c the component whose preferred size is being queried + * @return the max size or null + */ + public Dimension getMaximumSize(JComponent c) + { + // FIXME: not implemented + return getPreferredSize(c); + } + + /** + * Messages to stop the editing session. If the UI the receiver is providing + * the look and feel for returns true from + * <code>getInvokesStopCellEditing</code>, stopCellEditing will be invoked + * on the current editor. Then completeEditing will be messaged with false, + * true, false to cancel any lingering editing. + */ + protected void completeEditing() + { + // FIXME: not implemented + } + + /** + * Stops the editing session. If messageStop is true, the editor is messaged + * with stopEditing, if messageCancel is true the editor is messaged with + * cancelEditing. If messageTree is true, the treeModel is messaged with + * valueForPathChanged. + * + * @param messageStop message to stop editing + * @param messageCancel message to cancel editing + * @param messageTree message to treeModel + */ + protected void completeEditing(boolean messageStop, boolean messageCancel, + boolean messageTree) + { + // FIXME: not implemented + } + + /** + * Will start editing for node if there is a cellEditor and shouldSelectCall + * returns true. This assumes that path is valid and visible. + * + * @param path is the path to start editing + * @param event is the MouseEvent performed on the path + * @return true if successful + */ + protected boolean startEditing(TreePath path, MouseEvent event) + { + // FIXME: not implemented + return false; + } + + /** + * If the <code>mouseX</code> and <code>mouseY</code> are in the expand + * or collapse region of the row, this will toggle the row. + * + * @param path the path we are concerned with + * @param mouseX is the cursor's x position + * @param mouseY is the cursor's y position + */ + protected void checkForClickInExpandControl(TreePath path, int mouseX, + int mouseY) + { + // FIXME: not implemented + } + + /** + * Returns true if the <code>mouseX</code> and <code>mouseY</code> fall + * in the area of row that is used to expand/collpse the node and the node at + * row does not represent a leaf. + * + * @param path the path we are concerned with + * @param mouseX is the cursor's x position + * @param mouseY is the cursor's y position + * @return true if the <code>mouseX</code> and <code>mouseY</code> fall + * in the area of row that is used to expand/collpse the node and the + * node at row does not represent a leaf. + */ + protected boolean isLocationInExpandControl(TreePath path, int mouseX, + int mouseY) + { + // FIXME: not implemented + return false; + } + + /** + * Messaged when the user clicks the particular row, this invokes + * toggleExpandState. + * + * @param path the path we are concerned with + * @param mouseX is the cursor's x position + * @param mouseY is the cursor's y position + */ + protected void handleExpandControlClick(TreePath path, int mouseX, int mouseY) + { + // FIXME: not implemented + } + + /** + * Expands path if it is not expanded, or collapses row if it is expanded. If + * expanding a path and JTree scroll on expand, ensureRowsAreVisible is + * invoked to scroll as many of the children to visible as possible (tries to + * scroll to last visible descendant of path). + * + * @param path the path we are concerned with + */ + protected void toggleExpandState(TreePath path) + { + // FIXME: not implemented + } + + /** + * Returning true signifies a mouse event on the node should toggle the + * selection of only the row under the mouse. + * + * @param event is the MouseEvent performed on the row. + * @return true signifies a mouse event on the node should toggle the + * selection of only the row under the mouse. + */ + protected boolean isToggleSelectionEvent(MouseEvent event) + { + // FIXME: not implemented + return false; + } + + /** + * Returning true signifies a mouse event on the node should select from the + * anchor point. + * + * @param event is the MouseEvent performed on the node. + * @return true signifies a mouse event on the node should select from the + * anchor point. + */ + protected boolean isMultiSelectEvent(MouseEvent event) + { + // FIXME: not implemented + return false; + } + + /** + * Returning true indicates the row under the mouse should be toggled based + * on the event. This is invoked after checkForClickInExpandControl, implying + * the location is not in the expand (toggle) control. + * + * @param event is the MouseEvent performed on the row. + * @return true indicates the row under the mouse should be toggled based on + * the event. + */ + protected boolean isToggleEvent(MouseEvent event) + { + // FIXME: not implemented + return false; + } + + /** + * Messaged to update the selection based on a MouseEvent over a particular + * row. If the even is a toggle selection event, the row is either selected, + * or deselected. If the event identifies a multi selection event, the + * selection is updated from the anchor point. Otherwise, the row is + * selected, and if the even specified a toggle event the row is + * expanded/collapsed. + * + * @param path is the path selected for an event + * @param event is the MouseEvent performed on the path. + */ + protected void selectPathForEvent(TreePath path, MouseEvent event) + { + // FIXME: not implemented + } + + /** + * Returns true if the node at <code>row</code> is a leaf. + * + * @param row is the row we are concerned with. + * @return true if the node at <code>row</code> is a leaf. + */ + protected boolean isLeaf(int row) + { + TreePath pathForRow = getPathForRow(tree, row); + if (pathForRow == null) + return true; + + Object node = pathForRow.getLastPathComponent(); + + if (node instanceof TreeNode) + return ((TreeNode) node).isLeaf(); + else + return true; + } + + /** + * Updates the preferred size when scrolling, if necessary. + */ + public class ComponentHandler + extends ComponentAdapter + implements ActionListener + { + /** + * Timer used when inside a scrollpane and the scrollbar is adjusting + */ + protected Timer timer; + + /** ScrollBar that is being adjusted */ + protected JScrollBar scrollBar; + + /** + * Constructor + */ + public ComponentHandler() + { + } + + /** + * Invoked when the component's position changes. + * + * @param e the event that occurs when moving the component + */ + public void componentMoved(ComponentEvent e) + { + } + + /** + * Creats, if necessary, and starts a Timer to check if needed to resize + * the bounds + */ + protected void startTimer() + { + } + + /** + * Returns the JScrollPane housing the JTree, or null if one isn't found. + * + * @return JScrollPane housing the JTree, or null if one isn't found. + */ + protected JScrollPane getScrollPane() + { + return null; + } + + /** + * Public as a result of Timer. If the scrollBar is null, or not + * adjusting, this stops the timer and updates the sizing. + * + * @param ae is the action performed + */ + public void actionPerformed(ActionEvent ae) + { + } + }// ComponentHandler + + /** + * Listener responsible for getting cell editing events and updating the tree + * accordingly. + */ + public class CellEditorHandler + implements CellEditorListener + { + /** + * Constructor + */ + public CellEditorHandler() + { + } + + /** + * Messaged when editing has stopped in the tree. Tells the listeners + * editing has stopped. + * + * @param e is the notification event + */ + public void editingStopped(ChangeEvent e) + { + } + + /** + * Messaged when editing has been canceled in the tree. This tells the + * listeners the editor has canceled editing. + * + * @param e is the notification event + */ + public void editingCanceled(ChangeEvent e) + { + } + }// CellEditorHandler + + /** + * Repaints the lead selection row when focus is lost/grained. + */ + public class FocusHandler + implements FocusListener + { + /** + * Constructor + */ + public FocusHandler() + { + } + + /** + * Invoked when focus is activated on the tree we're in, redraws the lead + * row. Invoked when a component gains the keyboard focus. + * + * @param e is the focus event that is activated + */ + public void focusGained(FocusEvent e) + { + } + + /** + * Invoked when focus is deactivated on the tree we're in, redraws the + * lead row. Invoked when a component loses the keyboard focus. + * + * @param e is the focus event that is deactivated + */ + public void focusLost(FocusEvent e) + { + } + }// FocusHandler + + /** + * This is used to get multiple key down events to appropriately genereate + * events. + */ + public class KeyHandler + extends KeyAdapter + { + /** Key code that is being generated for. */ + protected Action repeatKeyAction; + + /** Set to true while keyPressed is active */ + protected boolean isKeyDown; + + /** + * Constructor + */ + public KeyHandler() + { + } + + /** + * Invoked when a key has been typed. Moves the keyboard focus to the + * first element whose first letter matches the alphanumeric key pressed + * by the user. Subsequent same key presses move the keyboard focus to the + * next object that starts with the same letter. + * + * @param e the key typed + */ + public void keyTyped(KeyEvent e) + { + } + + /** + * Invoked when a key has been pressed. + * + * @param e the key pressed + */ + public void keyPressed(KeyEvent e) + { + TreePath start = BasicTreeUI.this.tree.getLeadSelectionPath(); + DefaultMutableTreeNode last = null; + if (start != null) + last = (DefaultMutableTreeNode) start.getLastPathComponent(); + + if (last != null) + { + // DOWN, KP_DOWN + if (e.getKeyCode() == KeyEvent.VK_DOWN + || e.getKeyCode() == KeyEvent.VK_KP_DOWN) + { + DefaultMutableTreeNode next = (DefaultMutableTreeNode) + BasicTreeUI.this.getNextVisibleNode(last); + if (next != null) + { + TreePath newPath = new TreePath(next.getPath()); + BasicTreeUI.this.selectPath(BasicTreeUI.this.tree, newPath); + if (e.isControlDown()) + tree.setLeadSelectionPath(newPath); + else if (!next.isLeaf() && e.isShiftDown()) + { + BasicTreeUI.this.tree.expandPath(newPath); + BasicTreeUI.this.tree.fireTreeExpanded(newPath); + } + } + } + // UP, KP_UP + else if (e.getKeyCode() == KeyEvent.VK_UP + || e.getKeyCode() == KeyEvent.VK_KP_UP) + { + DefaultMutableTreeNode prev = (DefaultMutableTreeNode) + BasicTreeUI.this.getPreviousVisibleNode(last); + + if (prev != null) + { + TreePath newPath = new TreePath(prev.getPath()); + BasicTreeUI.this.selectPath(BasicTreeUI.this.tree, + new TreePath(prev.getPath())); + if (e.isControlDown()) + tree.setLeadSelectionPath(newPath); + else if (!prev.isLeaf() && e.isShiftDown()) + { + BasicTreeUI.this.tree.expandPath(newPath); + BasicTreeUI.this.tree.fireTreeExpanded(newPath); + } + } + } + // LEFT, KP_LEFT + else if (e.getKeyCode() == KeyEvent.VK_LEFT + || e.getKeyCode() == KeyEvent.VK_KP_LEFT) + { + TreePath path = new TreePath(last.getPath()); + DefaultMutableTreeNode p = (DefaultMutableTreeNode) last + .getParent(); + + if (!last.isLeaf() && BasicTreeUI.this.tree.isExpanded(path)) + { + BasicTreeUI.this.tree.collapsePath(path); + BasicTreeUI.this.tree.fireTreeCollapsed(path); + } + else if (p != null) + BasicTreeUI.this.selectPath(BasicTreeUI.this.tree, + new TreePath(p.getPath())); + } + // RIGHT, KP_RIGHT + else if (e.getKeyCode() == KeyEvent.VK_RIGHT + || e.getKeyCode() == KeyEvent.VK_KP_RIGHT) + { + TreePath path = new TreePath(last.getPath()); + + if (!last.isLeaf() && BasicTreeUI.this.tree.isCollapsed(path)) + { + BasicTreeUI.this.tree.expandPath(path); + BasicTreeUI.this.tree.fireTreeExpanded(path); + } + else + { + DefaultMutableTreeNode next = (DefaultMutableTreeNode) + BasicTreeUI.this.getNextVisibleNode(last); + + if (next != null) + BasicTreeUI.this.selectPath(BasicTreeUI.this.tree, + new TreePath(next.getPath())); + } + } + // Enter + else if (e.getKeyCode() == KeyEvent.VK_ENTER) + { + TreePath path = new TreePath(last.getPath()); + if (!last.isLeaf()) + { + if (BasicTreeUI.this.tree.isExpanded(path)) + { + BasicTreeUI.this.tree.collapsePath(path); + BasicTreeUI.this.tree.fireTreeCollapsed(path); + } + else + { + BasicTreeUI.this.tree.expandPath(path); + BasicTreeUI.this.tree.fireTreeExpanded(path); + } + } + } + } + } + + /** + * Invoked when a key has been released + * + * @param e the key released + */ + public void keyReleased(KeyEvent e) + { + } + }// KeyHandler + + /** + * MouseListener is responsible for updating the selevtion based on mouse + * events. + */ + public class MouseHandler + extends MouseAdapter + implements MouseMotionListener + { + /** + * Constructor + */ + public MouseHandler() + { + } + + /** + * Invoked when a mouse button has been pressed on a component. + * + * @param e is the mouse event that occured + */ + public void mousePressed(MouseEvent e) + { + } + + /** + * Invoked when a mouse button is pressed on a component and then dragged. + * MOUSE_DRAGGED events will continue to be delivered to the component + * where the drag originated until the mouse button is released + * (regardless of whether the mouse position is within the bounds of the + * component). + * + * @param e is the mouse event that occured + */ + public void mouseDragged(MouseEvent e) + { + } + + /** + * Invoked when the mouse button has been moved on a component (with no + * buttons no down). + * + * @param e the mouse event that occured + */ + public void mouseMoved(MouseEvent e) + { + } + + /** + * Invoked when a mouse button has been released on a component. + * + * @param e is the mouse event that occured + */ + public void mouseReleased(MouseEvent e) + { + } + }// MouseHandler + + /** + * MouseInputHandler handles passing all mouse events, including mouse motion + * events, until the mouse is released to the destination it is constructed + * with. + */ + public class MouseInputHandler + implements MouseInputListener + { + /** Source that events are coming from */ + protected Component source; + + /** Destination that receives all events. */ + protected Component destination; + + /** Number of mouse clicks on a non-leaf */ + private int clickCount = 0; + + /** The last non-leaf cell that was clicked */ + private Object lastClicked = null; + + /** + * Constructor + * + * @param source that events are coming from + * @param destination that receives all events + * @param e is the event received + */ + public MouseInputHandler(Component source, Component destination, + MouseEvent e) + { + } + + /** + * Invoked when the mouse button has been clicked (pressed and released) + * on a component. + * + * @param e mouse event that occured + */ + public void mouseClicked(MouseEvent e) + { + Point click = e.getPoint(); + int row = Math.round(click.y / BasicTreeUI.this.getRowHeight()); + TreePath path = BasicTreeUI.this.getClosestPathForLocation(tree, + click.x, click.y); + + if (path != null) + { + boolean inBounds = false; + boolean cntlClick = false; + Rectangle bounds = BasicTreeUI.this.getPathBounds( + BasicTreeUI.this.tree, path); + + bounds.x -= rightChildIndent - 4; + bounds.width += rightChildIndent + 4; + + if (bounds.contains(click.x, click.y)) + inBounds = true; + else if (BasicTreeUI.this.hasControlIcons() + && (click.x < (bounds.x - rightChildIndent + 5) && + click.x > (bounds.x - rightChildIndent - 5))) + cntlClick = true; + + if ((inBounds || cntlClick) + && BasicTreeUI.this.tree.isVisible(path)) + { + if (!cntlClick && !BasicTreeUI.this.isLeaf(row)) + { + Object cell = path.getLastPathComponent(); + if (lastClicked != null && lastClicked.equals(cell)) + clickCount = 2; + else + { + lastClicked = cell; + clickCount = 1; + } + } + + if (clickCount == 2 || cntlClick == true) + { + clickCount = 0; + lastClicked = null; + BasicTreeUI.this.tree.getSelectionModel().clearSelection(); + if (BasicTreeUI.this.tree.isExpanded(path)) + { + BasicTreeUI.this.tree.collapsePath(path); + BasicTreeUI.this.tree.fireTreeCollapsed(path); + } + else + { + BasicTreeUI.this.tree.expandPath(path); + BasicTreeUI.this.tree.fireTreeExpanded(path); + } + } + + BasicTreeUI.this.selectPath(BasicTreeUI.this.tree, path); + } + } + } + + /** + * Invoked when a mouse button has been pressed on a component. + * + * @param e mouse event that occured + */ + public void mousePressed(MouseEvent e) + { + } + + /** + * Invoked when a mouse button has been released on a component. + * + * @param e mouse event that occured + */ + public void mouseReleased(MouseEvent e) + { + } + + /** + * Invoked when the mouse enters a component. + * + * @param e mouse event that occured + */ + public void mouseEntered(MouseEvent e) + { + } + + /** + * Invoked when the mouse exits a component. + * + * @param e mouse event that occured + */ + public void mouseExited(MouseEvent e) + { + } + + /** + * Invoked when a mouse button is pressed on a component and then dragged. + * MOUSE_DRAGGED events will continue to be delivered to the component + * where the drag originated until the mouse button is released + * (regardless of whether the mouse position is within the bounds of the + * component). + * + * @param e mouse event that occured + */ + public void mouseDragged(MouseEvent e) + { + } + + /** + * Invoked when the mouse cursor has been moved onto a component but no + * buttons have been pushed. + * + * @param e mouse event that occured + */ + public void mouseMoved(MouseEvent e) + { + } + + /** + * Removes event from the source + */ + protected void removeFromSource() + { + } + }// MouseInputHandler + + /** + * Class responsible for getting size of node, method is forwarded to + * BasicTreeUI method. X location does not include insets, that is handled in + * getPathBounds. + */ + public class NodeDimensionsHandler + extends AbstractLayoutCache.NodeDimensions + { + /** + * Constructor + */ + public NodeDimensionsHandler() + { + } + + /** + * Responsible for getting the size of a particular node. + * + * @param value the value to be represented + * @param row row being queried + * @param depth the depth of the row + * @param expanded true if row is expanded + * @param size a Rectangle containing the size needed to represent value + * @return containing the node dimensions, or null if node has no + * dimension + */ + public Rectangle getNodeDimensions(Object value, int row, int depth, + boolean expanded, Rectangle size) + { + return null; + } + + /** + * Returns the amount to indent the given row + * + * @return amount to indent the given row. + */ + protected int getRowX(int row, int depth) + { + return 0; + } + }// NodeDimensionsHandler + + /** + * PropertyChangeListener for the tree. Updates the appropriate varaible, or + * TreeState, based on what changes. + */ + public class PropertyChangeHandler + implements PropertyChangeListener + { + + /** + * Constructor + */ + public PropertyChangeHandler() + { + } + + /** + * This method gets called when a bound property is changed. + * + * @param event A PropertyChangeEvent object describing the event source + * and the property that has changed. + */ + public void propertyChange(PropertyChangeEvent event) + { + } + }// PropertyChangeHandler + + /** + * Listener on the TreeSelectionModel, resets the row selection if any of the + * properties of the model change. + */ + public class SelectionModelPropertyChangeHandler + implements PropertyChangeListener + { + + /** + * Constructor + */ + public SelectionModelPropertyChangeHandler() + { + } + + /** + * This method gets called when a bound property is changed. + * + * @param event A PropertyChangeEvent object describing the event source + * and the property that has changed. + */ + public void propertyChange(PropertyChangeEvent event) + { + } + }// SelectionModelPropertyChangeHandler + + /** + * ActionListener that invokes cancelEditing when action performed. + */ + public class TreeCancelEditingAction + extends AbstractAction + { + + /** + * Constructor + */ + public TreeCancelEditingAction() + { + } + + /** + * Invoked when an action occurs. + * + * @param e event that occured + */ + public void actionPerformed(ActionEvent e) + { + } + + /** + * Returns true if the action is enabled. + * + * @return true if the action is enabled, false otherwise + */ + public boolean isEnabled() + { + return false; + } + }// TreeCancelEditingAction + + /** + * Updates the TreeState in response to nodes expanding/collapsing. + */ + public class TreeExpansionHandler + implements TreeExpansionListener + { + + /** + * Constructor + */ + public TreeExpansionHandler() + { + } + + /** + * Called whenever an item in the tree has been expanded. + * + * @param event is the event that occured + */ + public void treeExpanded(TreeExpansionEvent event) + { + BasicTreeUI.this.tree.repaint(); + } + + /** + * Called whenever an item in the tree has been collapsed. + * + * @param event is the event that occured + */ + public void treeCollapsed(TreeExpansionEvent event) + { + BasicTreeUI.this.tree.repaint(); + } + }// TreeExpansionHandler + + /** + * TreeHomeAction is used to handle end/home actions. Scrolls either the + * first or last cell to be visible based on direction. + */ + public class TreeHomeAction + extends AbstractAction + { + + /** direction is either home or end */ + protected int direction; + + /** + * Constructor + * + * @param direction - it is home or end + * @param name is the name of the direction + */ + public TreeHomeAction(int direction, String name) + { + } + + /** + * Invoked when an action occurs. + * + * @param e is the event that occured + */ + public void actionPerformed(ActionEvent e) + { + } + + /** + * Returns true if the action is enabled. + * + * @return true if the action is enabled. + */ + public boolean isEnabled() + { + return false; + } + }// TreeHomeAction + + /** + * TreeIncrementAction is used to handle up/down actions. Selection is moved + * up or down based on direction. + */ + public class TreeIncrementAction + extends AbstractAction + { + + /** Specifies the direction to adjust the selection by. */ + protected int direction; + + /** + * Constructor + * + * @param direction up or down + * @param name is the name of the direction + */ + public TreeIncrementAction(int direction, String name) + { + } + + /** + * Invoked when an action occurs. + * + * @param e is the event that occured + */ + public void actionPerformed(ActionEvent e) + { + } + + /** + * Returns true if the action is enabled. + * + * @return true if the action is enabled. + */ + public boolean isEnabled() + { + return false; + } + }// TreeIncrementAction + + /** + * Forwards all TreeModel events to the TreeState. + */ + public class TreeModelHandler + implements TreeModelListener + { + /** + * Constructor + */ + public TreeModelHandler() + { + } + + /** + * Invoked after a node (or a set of siblings) has changed in some way. + * The node(s) have not changed locations in the tree or altered their + * children arrays, but other attributes have changed and may affect + * presentation. Example: the name of a file has changed, but it is in the + * same location in the file system. To indicate the root has changed, + * childIndices and children will be null. Use e.getPath() to get the + * parent of the changed node(s). e.getChildIndices() returns the + * index(es) of the changed node(s). + * + * @param e is the event that occured + */ + public void treeNodesChanged(TreeModelEvent e) + { + } + + /** + * Invoked after nodes have been inserted into the tree. Use e.getPath() + * to get the parent of the new node(s). e.getChildIndices() returns the + * index(es) of the new node(s) in ascending order. + * + * @param e is the event that occured + */ + public void treeNodesInserted(TreeModelEvent e) + { + } + + /** + * Invoked after nodes have been removed from the tree. Note that if a + * subtree is removed from the tree, this method may only be invoked once + * for the root of the removed subtree, not once for each individual set + * of siblings removed. Use e.getPath() to get the former parent of the + * deleted node(s). e.getChildIndices() returns, in ascending order, the + * index(es) the node(s) had before being deleted. + * + * @param e is the event that occured + */ + public void treeNodesRemoved(TreeModelEvent e) + { + } + + /** + * Invoked after the tree has drastically changed structure from a given + * node down. If the path returned by e.getPath() is of length one and the + * first element does not identify the current root node the first element + * should become the new root of the tree. Use e.getPath() to get the path + * to the node. e.getChildIndices() returns null. + * + * @param e is the event that occured + */ + public void treeStructureChanged(TreeModelEvent e) + { + } + }// TreeModelHandler + + /** + * TreePageAction handles page up and page down events. + */ + public class TreePageAction + extends AbstractAction + { + /** Specifies the direction to adjust the selection by. */ + protected int direction; + + /** + * Constructor + * + * @param direction up or down + * @param name is the name of the direction + */ + public TreePageAction(int direction, String name) + { + } + + /** + * Invoked when an action occurs. + * + * @param e is the event that occured + */ + public void actionPerformed(ActionEvent e) + { + } + + /** + * Returns true if the action is enabled. + * + * @return true if the action is enabled. + */ + public boolean isEnabled() + { + return false; + } + }// TreePageAction + + /** + * Listens for changes in the selection model and updates the display + * accordingly. + */ + public class TreeSelectionHandler + implements TreeSelectionListener + { + /** + * Constructor + */ + public TreeSelectionHandler() + { + } + + /** + * Messaged when the selection changes in the tree we're displaying for. + * Stops editing, messages super and displays the changed paths. + * + * @param event the event that characterizes the change. + */ + public void valueChanged(TreeSelectionEvent event) + { + } + }// TreeSelectionHandler + + /** + * For the first selected row expandedness will be toggled. + */ + public class TreeToggleAction + extends AbstractAction + { + /** + * Constructor + * + * @param name is the name of <code>Action</code> field + */ + public TreeToggleAction(String name) + { + } + + /** + * Invoked when an action occurs. + * + * @param e the event that occured + */ + public void actionPerformed(ActionEvent e) + { + } + + /** + * Returns true if the action is enabled. + * + * @return true if the action is enabled, false otherwise + */ + public boolean isEnabled() + { + return false; + } + } // TreeToggleAction + + /** + * TreeTraverseAction is the action used for left/right keys. Will toggle + * the expandedness of a node, as well as potentially incrementing the + * selection. + */ + public class TreeTraverseAction + extends AbstractAction + { + /** + * Determines direction to traverse, 1 means expand, -1 means collapse. + */ + protected int direction; + + /** + * Constructor + * + * @param direction to traverse + * @param name is the name of the direction + */ + public TreeTraverseAction(int direction, String name) + { + } + + /** + * Invoked when an action occurs. + * + * @param e the event that occured + */ + public void actionPerformed(ActionEvent e) + { + } + + /** + * Returns true if the action is enabled. + * + * @return true if the action is enabled, false otherwise + */ + public boolean isEnabled() + { + return false; + } + } // TreeTraverseAction + + /** + * Returns the cell bounds for painting selected cells + * Package private for use in inner classes. + * + * @param x is the x location of the cell + * @param y is the y location of the cell + * @param cell is the Object to get the bounds for + * + * @returns Rectangle that represents the cell bounds + */ + Rectangle getCellBounds(int x, int y, Object cell) + { + if (cell != null) + { + String s = cell.toString(); + Font f = tree.getFont(); + FontMetrics fm = tree.getToolkit().getFontMetrics(tree.getFont()); + + if (s != null) + return new Rectangle(x, y, SwingUtilities.computeStringWidth(fm, s) + 4, + fm.getHeight()); + } + return new Rectangle(x, y, 0, 0); + } + + /** + * Retrieves the location of some node, recursively starting at from + * some node. + * Package private for use in inner classes. + * + * @param x is the starting x position, offset + * @param y is the starting y position, offset + * @param tree is the tree to traverse + * @param mod is the TreeModel to use + * @param node is the node to get the location for + * @param startNode is the node to start searching from + * + * @return Point - the location of node + */ + Point getCellLocation(int x, int y, JTree tree, TreeModel mod, + Object node, Object startNode) + { + int rowHeight = getRowHeight(); + if (startNode == null || startNode.equals(node)) + { + if (!tree.isRootVisible() && tree.isExpanded(new TreePath(mod.getRoot()))) + return new Point(x + ((((DefaultMutableTreeNode) node).getLevel()) + * rightChildIndent), y); + + return new Point(x + ((((DefaultMutableTreeNode) node).getLevel() + 1) + * rightChildIndent), y); + } + + if (!mod.isLeaf(startNode) + && tree.isExpanded(new TreePath( + ((DefaultMutableTreeNode) startNode).getPath()))) + { + Object child = mod.getChild(startNode, 0); + if (child != null) + return getCellLocation(x, y + rowHeight, tree, mod, + node, child); + } + + return getCellLocation(x, y + rowHeight, tree, mod, node, + getNextVisibleNode((DefaultMutableTreeNode) startNode)); + } + + /** + * Paints a node in the tree Package private for use in inner classes. + * + * @param g the Graphics context in which to paint + * @param x the x location of the node + * @param y the y location of the node + * @param tree the tree to draw on + * @param node the object to draw + */ + void paintNode(Graphics g, int x, int y, JTree tree, Object node, + boolean isLeaf) + { + TreePath curr = new TreePath(((DefaultMutableTreeNode) node).getPath()); + boolean selected = tree.isPathSelected(curr); + boolean expanded = false; + boolean hasIcons = false; + + if (tree.isVisible(curr)) + { + DefaultTreeCellRenderer dtcr = (DefaultTreeCellRenderer) tree + .getCellRenderer(); + + if (!isLeaf) + expanded = tree.isExpanded(curr); + + Icon icon = null; + if (!isLeaf && expanded) + icon = dtcr.getOpenIcon(); + else if (!isLeaf && !expanded) + icon = dtcr.getClosedIcon(); + else + icon = dtcr.getLeafIcon(); + + if (icon.getIconHeight() > -1 && icon.getIconWidth() > -1) + hasIcons = true; + + Component c = dtcr.getTreeCellRendererComponent(tree, node, selected, + expanded, isLeaf, 0, false); + + if (hasIcons) + { + if (selected) + { + Rectangle cell = getPathBounds(tree, curr); + g.setColor(dtcr.getBackgroundSelectionColor()); + g.fillRect(cell.x + icon.getIconWidth()/2, cell.y, cell.width, + cell.height); + + if (curr.equals(tree.getLeadSelectionPath())) + { + g.setColor(UIManager.getLookAndFeelDefaults().getColor( + "Tree.selectionBorderColor")); + g.drawRect(cell.x + icon.getIconWidth()/2, cell.y, + cell.width, cell.height); + } + } + + g.translate(x, y); + c.paint(g); + g.translate(-x, -y); + } + else + rendererPane.paintComponent(g, c, c.getParent(), + getCellBounds(x, y, node)); + } + } + + /** + * Recursively paints all elements of the tree Package private for use in + * inner classes. + * + * @param g the Graphics context in which to paint + * @param indentation of the current object + * @param descent is the number of elements drawn + * @param childNumber is the index of the current child in the tree + * @param depth is the depth of the current object in the tree + * @param tree is the tree to draw to + * @param mod is the TreeModel we are using to draw + * @param curr is the current object to draw + * + * @return int - current descent of the tree + */ + int paintRecursive(Graphics g, int indentation, int descent, + int childNumber, int depth, JTree tree, TreeModel mod, Object curr) { Rectangle clip = g.getClipBounds(); - if (indentation > clip.x + clip.width + rightChildIndent || - descent > clip.y + clip.height + rowHeight) + if (indentation > clip.x + clip.width + rightChildIndent + || descent > clip.y + clip.height + getRowHeight()) return descent; - - - int halfHeight = rowHeight / 2; + + int halfHeight = getRowHeight() / 2; int halfWidth = rightChildIndent / 2; int y0 = descent + halfHeight; - + int heightOfLine = descent + halfHeight; + boolean isRootVisible = tree.isRootVisible(); + if (mod.isLeaf(curr)) { - paintLeaf(g, indentation, descent, tree, curr); - descent += rowHeight; + paintNode(g, indentation + 4, descent, tree, curr, true); + descent += getRowHeight(); } else { - if (depth > 0 || tree.isRootVisible()) + if (depth > 0 || isRootVisible) { - paintNonLeaf(g, indentation, descent, tree, curr); - descent += rowHeight; + paintNode(g, indentation + 4, descent, tree, curr, false); + descent += getRowHeight(); y0 += halfHeight; } + int max = mod.getChildCount(curr); - for (int i = 0; i < max; ++i) + if (tree.isExpanded(new TreePath(((DefaultMutableTreeNode) curr) + .getPath()))) { - g.setColor(hashColor); - g.drawLine(indentation + halfWidth, descent + halfHeight, - indentation + rightChildIndent, descent + halfHeight); - descent = paintRecursive(g, - indentation + rightChildIndent, descent, - i, depth+1, - tree, mod, mod.getChild(curr, i)); + for (int i = 0; i < max; ++i) + { + int indent = indentation + rightChildIndent; + if (!isRootVisible && depth == 0) + indent = 0; + else if ((!isRootVisible && !curr.equals(mod.getRoot())) || + isRootVisible) + { + g.setColor(getHashColor()); + heightOfLine = descent + halfHeight; + g.drawLine(indentation + halfWidth, heightOfLine, indentation + + rightChildIndent, heightOfLine); + } + + descent = paintRecursive(g, indent, + descent, i, depth + 1, tree, mod, mod.getChild(curr, i)); + } } } - - int y1 = descent - halfHeight; - if (y0 != y1) + + if (tree.isExpanded(new TreePath(((DefaultMutableTreeNode) curr) + .getPath()))) + if (y0 != heightOfLine) + { + g.setColor(getHashColor()); + g.drawLine(indentation + halfWidth, y0, indentation + halfWidth, + heightOfLine); + } + + return descent; + } + + /** + * Recursively paints all the control icons on the tree. + * Package private for use in inner classes. + * + * @param g the Graphics context in which to paint + * @param indentation of the current object + * @param descent is the number of elements drawn + * @param childNumber is the index of the current child in the tree + * @param depth is the depth of the current object in the tree + * @param tree is the tree to draw to + * @param mod is the TreeModel we are using to draw + * @param curr is the current object to draw + * + * @return int - current descent of the tree + */ + int paintControlIcons(Graphics g, int indentation, int descent, + int childNumber, int depth, JTree tree, TreeModel mod, Object node) + { + int h = descent; + int rowHeight = getRowHeight(); + Icon ei = UIManager.getLookAndFeelDefaults() + .getIcon("Tree.expandedIcon"); + Icon ci = UIManager.getLookAndFeelDefaults() + .getIcon("Tree.collapsedIcon"); + Rectangle clip = g.getClipBounds(); + if (indentation > clip.x + clip.width + rightChildIndent + || descent > clip.y + clip.height + getRowHeight()) + return descent; + + if (mod.isLeaf(node)) + descent += rowHeight; + else { - g.setColor(hashColor); - g.drawLine(indentation + halfWidth, y0, - indentation + halfWidth, y1); + if (depth > 0 || tree.isRootVisible()) + descent += rowHeight; + + int max = mod.getChildCount(node); + if (tree.isExpanded(new TreePath(((DefaultMutableTreeNode) node) + .getPath()))) + { + if (!node.equals(mod.getRoot())) + ei.paintIcon(tree, g, indentation - rightChildIndent - 3, h); + + for (int i = 0; i < max; ++i) + { + int indent = indentation + rightChildIndent; + if (depth == 0 && !tree.isRootVisible()) + indent = -1; + + descent = paintControlIcons(g, indent, + descent, i, depth + 1, tree, mod, mod.getChild(node, i)); + } + } + else if (!node.equals(mod.getRoot())) + ci.paintIcon(tree, g, indentation - rightChildIndent - 3, + descent - getRowHeight()); } - + return descent; } - - public void paint(Graphics g, JComponent c) + + /** + * Returns true if the LookAndFeel implements the control icons + * Package private for use in inner classes. + * + * @return true if control icons are visible + */ + boolean hasControlIcons() { - JTree tree = (JTree) c; - TreeModel mod = tree.getModel(); - g.translate(10, 10); - paintRecursive(g, 0, 0, 0, 0, tree, mod, mod.getRoot()); - g.translate(-10, -10); + if (UIManager.getLookAndFeelDefaults(). + getIcon("Tree.expandedIcon") == null || + UIManager.getLookAndFeelDefaults(). + getIcon("Tree.collapsedIcon") == null) + return false; + return true; + } + + /** + * Get next visible node in the tree. + * Package private for use in inner classes. + * + * @param the current node + * @return the next visible node in the JTree. Return null if there are no + * more. + */ + DefaultMutableTreeNode getNextVisibleNode(DefaultMutableTreeNode node) + { + DefaultMutableTreeNode next = null; + TreePath current = null; + + if (node != null) + next = node.getNextNode(); + + if (next != null) + { + current = new TreePath(next.getPath()); + if (tree.isVisible(current)) + return next; + + while (next != null && !tree.isVisible(current)) + { + next = next.getNextNode(); + + if (next != null) + current = new TreePath(next.getPath()); + } + } + return next; + } + + /** + * Get previous visible node in the tree. + * Package private for use in inner classes. + * + * @param the current node + * @return the next visible node in the JTree. Return null if there are no + * more. + */ + DefaultMutableTreeNode getPreviousVisibleNode + (DefaultMutableTreeNode node) + { + DefaultMutableTreeNode prev = null; + TreePath current = null; + + if (node != null) + prev = node.getPreviousNode(); + + if (prev != null) + { + current = new TreePath(prev.getPath()); + if (tree.isVisible(current)) + return prev; + + while (prev != null && !tree.isVisible(current)) + { + prev = prev.getPreviousNode(); + + if (prev != null) + current = new TreePath(prev.getPath()); + } + } + return prev; + } + + /** + * Selects the specified path in the tree depending on modes. + * Package private for use in inner classes. + * + * @param tree is the tree we are selecting the path in + * @param path is the path we are selecting + */ + void selectPath(JTree tree, TreePath path) + { + if (path != null) + { + if (tree.isPathSelected(path)) + tree.removeSelectionPath(path); + else if (tree.getSelectionModel().getSelectionMode() + == TreeSelectionModel.SINGLE_TREE_SELECTION) + { + tree.getSelectionModel().clearSelection(); + tree.addSelectionPath(path); + tree.setLeadSelectionPath(path); + } + else if (tree.getSelectionModel().getSelectionMode() + == TreeSelectionModel.CONTIGUOUS_TREE_SELECTION) + { + // TODO + } + else + { + tree.getSelectionModel().setSelectionMode( + TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION); + tree.addSelectionPath(path); + tree.setLeadSelectionPath(path); + } + } } -} +} // BasicTreeUI
\ No newline at end of file diff --git a/javax/swing/plaf/basic/BasicViewportUI.java b/javax/swing/plaf/basic/BasicViewportUI.java index 07d4ba3ed..8ce772bed 100644 --- a/javax/swing/plaf/basic/BasicViewportUI.java +++ b/javax/swing/plaf/basic/BasicViewportUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/basic/ComboPopup.java b/javax/swing/plaf/basic/ComboPopup.java index 4cd518df5..8bdcc51b0 100644 --- a/javax/swing/plaf/basic/ComboPopup.java +++ b/javax/swing/plaf/basic/ComboPopup.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/basic/DefaultMenuLayout.java b/javax/swing/plaf/basic/DefaultMenuLayout.java index d6ad950f0..9760e82a6 100644 --- a/javax/swing/plaf/basic/DefaultMenuLayout.java +++ b/javax/swing/plaf/basic/DefaultMenuLayout.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/basic/package.html b/javax/swing/plaf/basic/package.html index f65518cac..700c8cdbc 100644 --- a/javax/swing/plaf/basic/package.html +++ b/javax/swing/plaf/basic/package.html @@ -1,6 +1,6 @@ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> <!-- package.html - describes classes in javax.swing.plaf.basic package. - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -16,8 +16,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -40,7 +40,7 @@ exception statement from your version. --> <head><title>GNU Classpath - javax.swing.plaf.basic</title></head> <body> -<p></p> +<p>Provides a "basic" look and feel implementation.</p> </body> </html> diff --git a/javax/swing/plaf/metal/DefaultMetalTheme.java b/javax/swing/plaf/metal/DefaultMetalTheme.java index 7c91eaadc..673aec1e4 100644 --- a/javax/swing/plaf/metal/DefaultMetalTheme.java +++ b/javax/swing/plaf/metal/DefaultMetalTheme.java @@ -1,5 +1,5 @@ /* DefaultMetalTheme.java -- - Copyright (C) 2004 Free Software Foundation, Inc. + Copyright (C) 2004, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -43,6 +43,11 @@ import java.awt.Font; import javax.swing.plaf.ColorUIResource; import javax.swing.plaf.FontUIResource; +/** + * The default theme for the {@link MetalLookAndFeel}. + * + * @see MetalLookAndFeel#setCurrentTheme(MetalTheme) + */ public class DefaultMetalTheme extends MetalTheme { private static final ColorUIResource PRIMARY1 = @@ -71,71 +76,144 @@ public class DefaultMetalTheme extends MetalTheme private static final FontUIResource WINDOW_TITLE_FONT = new FontUIResource("Dialog", Font.BOLD, 12); + /** + * Creates a new instance of this theme. + */ public DefaultMetalTheme() { // Do nothing here. } + /** + * Returns the name of the theme. + * + * @return <code>"Steel"</code>. + */ public String getName() { return "Steel"; } + /** + * Returns the first primary color for this theme. + * + * @return The first primary color. + */ protected ColorUIResource getPrimary1() { return PRIMARY1; } + /** + * Returns the second primary color for this theme. + * + * @return The second primary color. + */ protected ColorUIResource getPrimary2() { return PRIMARY2; } + /** + * Returns the third primary color for this theme. + * + * @return The third primary color. + */ protected ColorUIResource getPrimary3() { return PRIMARY3; } + /** + * Returns the first secondary color for this theme. + * + * @return The first secondary color. + */ protected ColorUIResource getSecondary1() { return SECONDARY1; } + /** + * Returns the second secondary color for this theme. + * + * @return The second secondary color. + */ protected ColorUIResource getSecondary2() { return SECONDARY2; } + /** + * Returns the third secondary color for this theme. + * + * @return The third secondary color. + */ protected ColorUIResource getSecondary3() { return SECONDARY3; } + /** + * Returns the font used for text on controls. In this case, the font is + * <code>FontUIResource("Dialog", Font.BOLD, 12)</code>. + * + * @return The font. + */ public FontUIResource getControlTextFont() { return CONTROL_TEXT_FONT; } - + /** + * Returns the font used for text in menus. In this case, the font is + * <code>FontUIResource("Dialog", Font.BOLD, 12)</code>. + * + * @return The font used for text in menus. + */ public FontUIResource getMenuTextFont() { return MENU_TEXT_FONT; } + /** + * Returns the font used for sub text. In this case, the font is + * <code>FontUIResource("Dialog", Font.PLAIN, 10)</code>. + * + * @return The font used for sub text. + */ public FontUIResource getSubTextFont() { return SUB_TEXT_FONT; } + /** + * Returns the font used for system text. In this case, the font is + * <code>FontUIResource("Dialog", Font.PLAIN, 12)</code>. + * + * @return The font used for system text. + */ public FontUIResource getSystemTextFont() { return SYSTEM_TEXT_FONT; } + /** + * Returns the font used for user text. In this case, the font is + * <code>FontUIResource("Dialog", Font.PLAIN, 12)</code>. + * + * @return The font used for user text. + */ public FontUIResource getUserTextFont() { return USER_TEXT_FONT; } + /** + * Returns the font used for window titles. In this case, the font is + * <code>FontUIResource("Dialog", Font.BOLD, 12)</code>. + * + * @return The font used for window titles. + */ public FontUIResource getWindowTitleFont() { return WINDOW_TITLE_FONT; diff --git a/javax/swing/plaf/metal/MetalBorders.java b/javax/swing/plaf/metal/MetalBorders.java index d5b467fa2..851324242 100644 --- a/javax/swing/plaf/metal/MetalBorders.java +++ b/javax/swing/plaf/metal/MetalBorders.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -46,6 +46,9 @@ import java.awt.Insets; import javax.swing.AbstractButton; import javax.swing.ButtonModel; import javax.swing.JButton; +import javax.swing.JMenu; +import javax.swing.JMenuBar; +import javax.swing.JMenuItem; import javax.swing.border.AbstractBorder; import javax.swing.border.Border; import javax.swing.plaf.BorderUIResource; @@ -78,7 +81,7 @@ public class MetalBorders /** * The border that is drawn around Swing buttons. */ - public static class MetalButtonBorder + public static class ButtonBorder extends AbstractBorder implements UIResource { @@ -88,7 +91,7 @@ public class MetalBorders /** * Creates a new instance of ButtonBorder. */ - public MetalButtonBorder() + public ButtonBorder() { } @@ -184,6 +187,168 @@ public class MetalBorders } /** + * A border used for {@link JMenu} and {@link JMenuItem} components. + */ + public static class MenuItemBorder + extends AbstractBorder + implements UIResource + { + /** The border insets. */ + protected static Insets borderInsets = new Insets(2, 2, 2, 2); + + // TODO: find where the real colors come from + private static Color borderColorDark = new Color(102, 102, 153); + private static Color borderColorLight = new Color(255, 255, 255); + + /** + * Creates a new border instance. + */ + public MenuItemBorder() + { + } + + /** + * Paints the border for the component. A border is painted only if the + * component is a selected {@link JMenu} or an armed {@link JMenuItem}. + * + * @param c the component. + * @param g the graphics device. + * @param x the x-coordinate of the border area. + * @param y the y-coordinate of the border area. + * @param w the width of the border area. + * @param h the height of the border area. + */ + public void paintBorder(Component c, Graphics g, int x, int y, int w, + int h) + { + if (c instanceof JMenu) { + JMenu menu = (JMenu) c; + if (menu.isSelected()) + { + g.setColor(borderColorDark); + g.drawLine(x, y, x, y + h); + g.drawLine(x, y, x + w, y); + g.drawLine(x + w - 2, y + 1, x + w - 2, y + h); + g.setColor(borderColorLight); + g.drawLine(x + w - 1, y + 1, x + w - 1, y + h); + } + } + else if (c instanceof JMenuItem) + { + JMenuItem item = (JMenuItem) c; + if (item.isArmed()) + { + g.setColor(borderColorDark); + g.drawLine(x, y, x + w, y); + g.setColor(borderColorLight); + g.drawLine(x, y + h - 1, x + w, y + h - 1); + } + } + } + + /** + * Returns the border insets. + * + * @param c the component (ignored). + * + * @return The border insets. + */ + public Insets getBorderInsets(Component c) + { + return borderInsets; + } + + /** + * Populates <code>insets</code> with the border insets, then returns it. + * + * @param c the component (ignored). + * @param insets the object to populate with the border insets. + * + * @return The border insets. + * + * @throws NullPointerException if <code>insets</code> is <code>null</code>. + */ + public Insets getBorderInsets(Component c, Insets insets) + { + insets.left = borderInsets.left; + insets.top = borderInsets.top; + insets.bottom = borderInsets.bottom; + insets.right = borderInsets.right; + return insets; + } + } + + /** + * A border used for {@link JMenuBar} components. + */ + public static class MenuBarBorder + extends AbstractBorder + implements UIResource + { + /** The border insets. */ + protected static Insets borderInsets = new Insets(1, 0, 1, 0); + + // TODO: find where this color really comes from + private static Color borderColor = new Color(153, 153, 153); + + /** + * Creates a new border instance. + */ + public MenuBarBorder() + { + } + + /** + * Paints the border for the component. A border is painted only if the + * component is a selected {@link JMenu} or an armed {@link JMenuItem}. + * + * @param c the component. + * @param g the graphics device. + * @param x the x-coordinate of the border area. + * @param y the y-coordinate of the border area. + * @param w the width of the border area. + * @param h the height of the border area. + */ + public void paintBorder(Component c, Graphics g, int x, int y, int w, + int h) + { + g.setColor(borderColor); + g.drawLine(x, y + h - 1, x + w, y + h - 1); + } + + /** + * Returns the border insets. + * + * @param c the component (ignored). + * + * @return The border insets. + */ + public Insets getBorderInsets(Component c) + { + return borderInsets; + } + + /** + * Populates <code>insets</code> with the border insets, then returns it. + * + * @param c the component (ignored). + * @param insets the object to populate with the border insets. + * + * @return The border insets. + * + * @throws NullPointerException if <code>insets</code> is <code>null</code>. + */ + public Insets getBorderInsets(Component c, Insets insets) + { + insets.left = borderInsets.left; + insets.top = borderInsets.top; + insets.bottom = borderInsets.bottom; + insets.right = borderInsets.right; + return insets; + } + } + + /** * A border for JScrollPanes. */ public static class ScrollPaneBorder @@ -404,7 +569,7 @@ public class MetalBorders { if (buttonBorder == null) { - Border outer = new MetalButtonBorder(); + Border outer = new ButtonBorder(); Border inner = getMarginBorder(); buttonBorder = new BorderUIResource.CompoundBorderUIResource (outer, inner); @@ -421,7 +586,7 @@ public class MetalBorders { if (toolbarButtonBorder == null) { - Border outer = new MetalButtonBorder(); + Border outer = new ButtonBorder(); Border inner = new RolloverMarginBorder(); toolbarButtonBorder = new BorderUIResource.CompoundBorderUIResource (outer, inner); diff --git a/javax/swing/plaf/metal/MetalButtonUI.java b/javax/swing/plaf/metal/MetalButtonUI.java index 7b9130e0e..0dac5ec39 100644 --- a/javax/swing/plaf/metal/MetalButtonUI.java +++ b/javax/swing/plaf/metal/MetalButtonUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -38,6 +38,8 @@ exception statement from your version. */ package javax.swing.plaf.metal; +import java.awt.Color; + import javax.swing.AbstractButton; import javax.swing.JComponent; import javax.swing.JToolBar; @@ -56,18 +58,60 @@ public class MetalButtonUI extends BasicButtonUI { - // FIXME: probably substitute with a Map in the future in the case - // that this UI becomes stateful - /** The cached MetalButtonUI instance. */ private static MetalButtonUI instance = null; + /** The color for the focus border. */ + protected Color focusColor; + + /** The color that indicates a selected button. */ + protected Color selectColor; + + /** The color for disabled button labels. */ + protected Color disabledTextColor; + /** * Creates a new instance of MetalButtonUI. */ public MetalButtonUI() { super(); + focusColor = getFocusColor(); + selectColor = getSelectColor(); + disabledTextColor = getDisabledTextColor(); + } + + /** + * Returns the color for the focus border. + * + * @return the color for the focus border + */ + protected Color getFocusColor() + { + UIDefaults def = UIManager.getLookAndFeelDefaults(); + return def.getColor(getPropertyPrefix() + ".focus"); + } + + /** + * Returns the color that indicates a selected button. + * + * @return the color that indicates a selected button + */ + protected Color getSelectColor() + { + UIDefaults def = UIManager.getLookAndFeelDefaults(); + return def.getColor(getPropertyPrefix() + ".select"); + } + + /** + * Returns the color for the text label of disabled buttons. + * + * @return the color for the text label of disabled buttons + */ + protected Color getDisabledTextColor() + { + UIDefaults def = UIManager.getLookAndFeelDefaults(); + return def.getColor(getPropertyPrefix() + ".disabledText"); } /** diff --git a/javax/swing/plaf/metal/MetalCheckBoxIcon.java b/javax/swing/plaf/metal/MetalCheckBoxIcon.java new file mode 100644 index 000000000..3f3c9ce58 --- /dev/null +++ b/javax/swing/plaf/metal/MetalCheckBoxIcon.java @@ -0,0 +1,136 @@ +/* MetalCheckBoxIcon.java -- An icon for JCheckBoxes in the Metal L&F + 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.Color; +import java.awt.Component; +import java.awt.Graphics; + +import java.io.Serializable; + +import javax.swing.Icon; +import javax.swing.JCheckBox; +import javax.swing.plaf.UIResource; + +/** + * An {@link Icon} implementation for {@link JCheckBox}es in the + * Metal Look & Feel. + * + * @author Roman Kennke (roman@kennke.org) + */ +public class MetalCheckBoxIcon + implements Icon, UIResource, Serializable +{ + + /** Used to paint the border of the icon. */ + MetalBorders.ButtonBorder border; + + /** + * Creates a new MetalCheckBoxIcon instance. + */ + public MetalCheckBoxIcon() + { + border = new MetalBorders.ButtonBorder(); + } + + /** + * Draws the check in the CheckBox. + * + * @param c the component to draw on + * @param g the Graphics context to draw with + * @param x the X position + * @param y the Y position + */ + protected void drawCheck(Component c, Graphics g, int x, int y) + { + g.setColor(Color.BLACK); + g.drawLine(3 + x, 5 + y, 3 + x, 9 + y); + g.drawLine(4 + x, 5 + y, 4 + x, 9 + y); + g.drawLine(5 + x, 7 + y, 9 + x, 3 + y); + g.drawLine(5 + x, 8 + y, 9 + x, 4 + y); + } + + /** + * Returns the size (both X and Y) of the checkbox icon. + * + * @return the size of the checkbox icon + */ + protected int getControlSize() + { + return 13; + } + + /** + * Returns the width of the icon in pixels. + * + * @return the width of the icon in pixels + */ + public int getIconWidth() + { + return getControlSize(); + } + + /** + * Returns the height of the icon in pixels. + * + * @return the height of the icon in pixels + */ + public int getIconHeight() + { + return getControlSize(); + } + + /** + * Paints the icon. This first paints the border of the CheckBox and + * if the CheckBox is selected it calls {@link #drawCheck} to draw + * the check. + * + * @param c the Component to draw on (gets casted to JCheckBox) + * @param g the Graphics context to draw with + * @param x the X position + * @param y the Y position + */ + public void paintIcon(Component c, Graphics g, int x, int y) + { + border.paintBorder(c, g, x, y, getIconWidth(), getIconHeight()); + JCheckBox cb = (JCheckBox) c; + if (cb.isSelected()) + drawCheck(c, g, x, y); + } +} diff --git a/javax/swing/plaf/metal/MetalCheckBoxUI.java b/javax/swing/plaf/metal/MetalCheckBoxUI.java index cc5ac73d7..d59e38c54 100644 --- a/javax/swing/plaf/metal/MetalCheckBoxUI.java +++ b/javax/swing/plaf/metal/MetalCheckBoxUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/metal/MetalComboBoxIcon.java b/javax/swing/plaf/metal/MetalComboBoxIcon.java new file mode 100644 index 000000000..ce4fa7d32 --- /dev/null +++ b/javax/swing/plaf/metal/MetalComboBoxIcon.java @@ -0,0 +1,100 @@ +/* MetalComboBoxButton.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.Color; +import java.awt.Component; +import java.awt.Graphics; +import java.io.Serializable; + +import javax.swing.Icon; + +/** + * An icon used by the {@link MetalComboBoxUI} class. + */ +public class MetalComboBoxIcon implements Icon, Serializable { + + /** + * Creates a new icon. + */ + public MetalComboBoxIcon() + { + // nothing required. + } + + /** + * Returns the icon width, which for this icon is 10 pixels. + * + * @return <code>10</code>. + */ + public int getIconWidth() + { + return 10; + } + + /** + * Returns the icon height, which for this icon is 5 pixels. + * + * @return <code>5</code>. + */ + public int getIconHeight() + { + return 5; + } + + /** + * Paints the icon at the location (x, y). + * + * @param c the combo box (ignored here). + * @param g the graphics device. + * @param x the x coordinate. + * @param y the y coordinate. + */ + public void paintIcon(Component c, Graphics g, int x, int y) + { + // TODO: work out whether/how the icon changes with different component + // states (and also different metal themes) + Color savedColor = g.getColor(); + g.setColor(Color.black); + for (int i = 0; i < 5; i++) + g.drawLine(x + i, y + i, x + 9 - i, y + i); + g.setColor(savedColor); + } + +} diff --git a/javax/swing/plaf/metal/MetalComboBoxUI.java b/javax/swing/plaf/metal/MetalComboBoxUI.java index 2e4ca5149..28c279d8e 100644 --- a/javax/swing/plaf/metal/MetalComboBoxUI.java +++ b/javax/swing/plaf/metal/MetalComboBoxUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/metal/MetalDesktopIconUI.java b/javax/swing/plaf/metal/MetalDesktopIconUI.java index 6ceedd0d6..00870545b 100644 --- a/javax/swing/plaf/metal/MetalDesktopIconUI.java +++ b/javax/swing/plaf/metal/MetalDesktopIconUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/metal/MetalIconFactory.java b/javax/swing/plaf/metal/MetalIconFactory.java new file mode 100644 index 000000000..2c21d2b02 --- /dev/null +++ b/javax/swing/plaf/metal/MetalIconFactory.java @@ -0,0 +1,786 @@ +/* MetalIconFactory.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.Color; +import java.awt.Component; +import java.awt.Graphics; +import java.io.Serializable; + +import javax.swing.Icon; +import javax.swing.JRadioButton; +import javax.swing.JSlider; +import javax.swing.plaf.UIResource; + +/** + * Creates icons for the {@link MetalLookAndFeel}. + */ +public class MetalIconFactory implements Serializable +{ + + /** A constant representing "dark". */ + public static final boolean DARK = false; + + /** A constant representing "light". */ + public static final boolean LIGHT = true; + + /** + * An icon representing a file (drawn as a piece of paper with the top-right + * corner turned down). + */ + public static class FileIcon16 implements Icon, Serializable + { + /** + * Returns the width of the icon, in pixels. + * + * @return The width of the icon. + */ + public int getIconWidth() + { + return 16; + } + + /** + * Returns the height of the icon, in pixels. + * + * @return The height of the icon. + */ + public int getIconHeight() + { + return 16; + } + + /** + * Paints the icon at the location (x, y). + * + * @param c the component. + * @param g the graphics context. + * @param x the x coordinate. + * @param y the y coordinate. + */ + public void paintIcon(Component c, Graphics g, int x, int y) + { + // TODO: pick up appropriate UI colors + g.setColor(Color.black); + g.drawLine(x, y, x + 9, y); + g.drawLine(x, y + 1, x, y + 15); + g.drawLine(x, y + 15, x + 12, y + 15); + g.drawLine(x + 12, y + 15, x + 12, y + 6); + g.drawLine(x + 12, y + 6, x + 9, y); + + g.drawLine(x + 7, y + 2, x + 11, y + 6); + g.drawLine(x + 8, y + 1, x + 9, y + 1); + + g.setColor(new Color(204, 204, 255)); + g.drawLine(x + 1, y + 1, x + 7, y + 1); + g.drawLine(x + 1, y + 1, x + 1, y + 14); + g.drawLine(x + 1, y + 14, x + 11, y + 14); + g.drawLine(x + 11, y + 14, x + 11, y + 7); + g.drawLine(x + 8, y + 2, x + 10, y + 4); + } + + /** + * Returns the additional height (???). + * + * @return The additional height. + */ + public int getAdditionalHeight() + { + return 0; + } + + /** + * Returns the shift (???). + * + * @return The shift. + */ + public int getShift() + { + return 0; + } + + } + + /** + * An icon representing a folder. + */ + public static class FolderIcon16 implements Icon, Serializable + { + /** + * Returns the width of the icon, in pixels. + * + * @return The width of the icon. + */ + public int getIconWidth() { + return 16; + } + + /** + * Returns the height of the icon, in pixels. + * + * @return The height of the icon. + */ + public int getIconHeight() + { + return 16; + } + + /** + * Paints the icon at the location (x, y). + * + * @param c the component. + * @param g the graphics device. + * @param x the x coordinate. + * @param y the y coordinate. + */ + public void paintIcon(Component c, Graphics g, int x, int y) + { + // TODO: pick up appropriate UI colors + g.setColor(Color.black); + g.drawLine(x, y + 3, x, y + 12); + g.drawLine(x, y + 12, x + 15, y + 12); + g.drawLine(x + 15, y + 12, x + 15, y + 2); + g.drawLine(x + 14, y + 3, x + 9, y + 3); + g.drawLine(x + 8, y + 2, x + 1, y + 2); + g.setColor(new Color(204, 204, 255)); + g.fillRect(x + 2, y + 4, 7, 8); + g.fillRect(x + 9, y + 5, 6, 7); + g.setColor(new Color(102, 102, 153)); + g.drawLine(x + 9, y + 2, x + 14, y + 2); + g.setColor(new Color(50, 50, 120)); + g.drawLine(x + 9, y + 1, x + 15, y + 1); + g.drawLine(x + 10, y, x + 15, y); + } + + /** + * Returns the additional height (???). + * + * @return The additional height. + */ + public int getAdditionalHeight() + { + return 0; + } + + /** + * Returns the shift (???). + * + * @return The shift. + */ + public int getShift() + { + return 0; + } + + } + + /** + * An {@link Icon} implementation for {@link JCheckBox}es in the + * Metal Look & Feel. + * + * @author Roman Kennke (roman@kennke.org) + */ + static class RadioButtonIcon + implements Icon, UIResource, Serializable + { + /** + * Draws the check in the RadioButton. + * + * @param c the component to draw on + * @param g the Graphics context to draw with + */ + protected void drawCheck(Component c, Graphics g) + { + g.setColor(MetalLookAndFeel.getBlack()); + g.fillRect(4, 3, 4, 6); + g.drawLine(3, 4, 3, 7); + g.drawLine(8, 4, 8, 7); + } + + /** + * Returns the width of the icon in pixels. + * + * @return the width of the icon in pixels + */ + public int getIconWidth() + { + return 13; + } + + /** + * Returns the height of the icon in pixels. + * + * @return the height of the icon in pixels + */ + public int getIconHeight() + { + return 13; + } + + /** + * Paints the icon. This first paints the border of the RadioButton and + * if the CheckBox is selected it calls {@link #drawCheck} to draw + * the check. + * + * @param c the Component to draw on (gets casted to JCheckBox) + * @param g the Graphics context to draw with + * @param x the X position + * @param y the Y position + */ + public void paintIcon(Component c, Graphics g, int x, int y) + { + Color dark = MetalLookAndFeel.getControlDarkShadow(); + Color light = MetalLookAndFeel.getWhite(); + g.translate(x, y); + + // The light 'circle' + g.setColor(light); + g.drawLine(4, 1, 10, 1); + g.drawLine(2, 2, 3, 2); + g.drawLine(8, 2, 11, 2); + g.drawLine(2, 3, 2, 3); + g.drawLine(11, 2, 11, 9); + g.drawLine(1, 4, 1, 7); + g.drawLine(12, 4, 12, 7); + g.drawLine(2, 8, 2, 11); + g.drawLine(11, 8, 11, 9); + g.drawLine(10, 10, 10, 10); + g.drawLine(2, 11, 9, 11); + g.drawLine(4, 12, 7, 12); + + // The dark 'circle' + g.setColor(dark); + g.drawLine(4, 0, 7, 0); + g.drawLine(2, 1, 3, 1); + g.drawLine(8, 1, 9, 1); + g.drawLine(1, 2, 1, 3); + g.drawLine(10, 2, 10, 3); + g.drawLine(0, 4, 0, 7); + g.drawLine(11, 4, 11, 7); + g.drawLine(1, 8, 1, 9); + g.drawLine(10, 8, 10, 9); + g.drawLine(2, 10, 3, 10); + g.drawLine(8, 10, 9, 10); + g.drawLine(4, 11, 7, 11); + + JRadioButton rb = (JRadioButton) c; + if (rb.isSelected()) + drawCheck(c, g); + + g.translate(-x, -y); + } + } + + /** + * The icon used to display the thumb control on a horizontally oriented + * {@link JSlider} component. + */ + private static class HorizontalSliderThumbIcon + implements Icon, Serializable + { + + /** + * Creates a new instance. + */ + public HorizontalSliderThumbIcon() + { + } + + /** + * Returns the width of the icon, in pixels. + * + * @return The width of the icon. + */ + public int getIconWidth() + { + return 15; + } + + /** + * Returns the height of the icon, in pixels. + * + * @return The height of the icon. + */ + public int getIconHeight() + { + return 16; + } + + /** + * Paints the icon, taking into account whether or not the component has + * the focus. + * + * @param c the component. + * @param g the graphics device. + * @param x the x-coordinate. + * @param y the y-coordinate. + */ + public void paintIcon(Component c, Graphics g, int x, int y) + { + boolean focus = false; + if (c != null) + focus = c.hasFocus(); + // TODO: pick up the colors from the look and feel + + // draw the outline + g.setColor(Color.black); + g.drawLine(x + 1, y, x + 13, y); + g.drawLine(x + 14, y + 1, x + 14, y + 7); + g.drawLine(x + 14, y + 8, x + 7, y + 15); + g.drawLine(x + 6, y + 14, x, y + 8); + g.drawLine(x, y + 7, x, y + 1); + + // fill the icon + g.setColor(focus ? new Color(153, 153, 204) : new Color(204, 204, 204)); // medium + g.fillRect(x + 2, y + 2, 12, 7); + g.drawLine(x + 2, y + 9, x + 12, y + 9); + g.drawLine(x + 3, y + 10, x + 11, y + 10); + g.drawLine(x + 4, y + 11, x + 10, y + 11); + g.drawLine(x + 5, y + 12, x + 9, y + 12); + g.drawLine(x + 6, y + 13, x + 8, y + 13); + g.drawLine(x + 7, y + 14, x + 7, y + 14); + + // draw highlights + g.setColor(focus ? new Color(204, 204, 255) : new Color(255, 255, 255)); // light + g.drawLine(x + 1, y + 1, x + 13, y + 1); + g.drawLine(x + 1, y + 2, x + 1, y + 8); + g.drawLine(x + 2, y + 2, x + 2, y + 2); + g.drawLine(x + 6, y + 2, x + 6, y + 2); + g.drawLine(x + 10, y + 2, x + 10, y + 2); + + g.drawLine(x + 4, y + 4, x + 4, y + 4); + g.drawLine(x + 8, y + 4, x + 8, y + 4); + + g.drawLine(x + 2, y + 6, x + 2, y + 6); + g.drawLine(x + 6, y + 6, x + 6, y + 6); + g.drawLine(x + 10, y + 6, x + 10, y + 6); + + // draw dots + g.setColor(focus ? new Color(102, 102, 153) : Color.black); // dark + g.drawLine(x + 3, y + 3, x + 3, y + 3); + g.drawLine(x + 7, y + 3, x + 7, y + 3); + g.drawLine(x + 11, y + 3, x + 11, y + 3); + + g.drawLine(x + 5, y + 5, x + 5, y + 5); + g.drawLine(x + 9, y + 5, x + 9, y + 5); + + g.drawLine(x + 3, y + 7, x + 3, y + 7); + g.drawLine(x + 7, y + 7, x + 7, y + 7); + g.drawLine(x + 11, y + 7, x + 11, y + 7); + + } + } + + /** + * The icon used to display the thumb control on a horizontally oriented + * {@link JSlider} component. + */ + private static class VerticalSliderThumbIcon implements Icon, Serializable + { + /** + * Creates a new instance. + */ + public VerticalSliderThumbIcon() + { + } + + /** + * Returns the width of the icon, in pixels. + * + * @return The width of the icon. + */ + public int getIconWidth() + { + return 16; + } + + /** + * Returns the height of the icon, in pixels. + * + * @return The height of the icon. + */ + public int getIconHeight() + { + return 15; + } + + /** + * Paints the icon taking into account whether the slider control has the + * focus or not. + * + * @param c the slider (must be a non-<code>null</code> instance of + * {@link JSlider}. + * @param g the graphics device. + * @param x the x-coordinate. + * @param y the y-coordinate. + */ + public void paintIcon(Component c, Graphics g, int x, int y) + { + boolean focus = false; + if (c != null) + focus = c.hasFocus(); + // TODO: pick up the colors from the look and feel + + // draw the outline + g.setColor(Color.black); + g.drawLine(x + 1, y, x + 7, y); + g.drawLine(x + 8, y, x + 15, y + 7); + g.drawLine(x + 14, y + 8, x + 8, y + 14); + g.drawLine(x + 8, y + 14, x + 1, y + 14); + g.drawLine(x, y + 13, x, y + 1); + + // fill the icon + g.setColor(focus ? new Color(153, 153, 204) : new Color(204, 204, 204)); // medium + g.fillRect(x + 2, y + 2, 7, 12); + g.drawLine(x + 9, y + 2, x + 9, y + 12); + g.drawLine(x + 10, y + 3, x + 10, y + 11); + g.drawLine(x + 11, y + 4, x + 11, y + 10); + g.drawLine(x + 12, y + 5, x + 12, y + 9); + g.drawLine(x + 13, y + 6, x + 13, y + 8); + g.drawLine(x + 14, y + 7, x + 14, y + 7); + + // draw highlights + g.setColor(focus ? new Color(204, 204, 255) : new Color(255, 255, 255)); // light + g.drawLine(x + 1, y + 1, x + 8, y + 1); + g.drawLine(x + 1, y + 2, x + 1, y + 13); + g.drawLine(x + 2, y + 2, x + 2, y + 2); + g.drawLine(x + 2, y + 6, x + 2, y + 6); + g.drawLine(x + 2, y + 10, x + 2, y + 10); + + g.drawLine(x + 4, y + 4, x + 4, y + 4); + g.drawLine(x + 4, y + 8, x + 4, y + 8); + + g.drawLine(x + 6, y + 2, x + 6, y + 2); + g.drawLine(x + 6, y + 6, x + 6, y + 6); + g.drawLine(x + 6, y + 10, x + 6, y + 10); + + // draw dots + g.setColor(focus ? new Color(102, 102, 153) : Color.black); // dark + g.drawLine(x + 3, y + 3, x + 3, y + 3); + g.drawLine(x + 3, y + 7, x + 3, y + 7); + g.drawLine(x + 3, y + 11, x + 3, y + 11); + + g.drawLine(x + 5, y + 5, x + 5, y + 5); + g.drawLine(x + 5, y + 9, x + 5, y + 9); + + g.drawLine(x + 7, y + 3, x + 7, y + 3); + g.drawLine(x + 7, y + 7, x + 7, y + 7); + g.drawLine(x + 7, y + 11, x + 7, y + 11); + } + } + + /** + * A tree control icon. This icon can be in one of two states: expanded and + * collapsed. + */ + public static class TreeControlIcon implements Icon, Serializable + { + + /** ???. */ + protected boolean isLight; + + /** A flag that controls whether or not the icon is collapsed. */ + private boolean collapsed; + + /** + * Creates a new icon. + * + * @param isCollapsed a flag that controls whether the icon is in the + * collapsed state or the expanded state. + */ + public TreeControlIcon(boolean isCollapsed) + { + collapsed = isCollapsed; + } + + /** + * Returns the width of the icon, in pixels. + * + * @return The width of the icon. + */ + public int getIconWidth() + { + return 18; + } + /** + * Returns the height of the icon, in pixels. + * + * @return The height of the icon. + */ + public int getIconHeight() + { + return 18; + } + + /** + * Paints the icon at the location (x, y). + * + * @param c the component. + * @param g the graphics device. + * @param x the x coordinate. + * @param y the y coordinate. + */ + public void paintIcon(Component c, Graphics g, int x, int y) + { + x = x + 5; + y = y + 5; + if (collapsed) + { + // TODO: pick up appropriate UI colors + g.setColor(Color.black); + g.drawLine(x + 2, y, x + 5, y); + g.drawLine(x + 6, y + 1, x + 7, y + 2); + g.fillRect(x + 7, y + 3, 5, 2); + g.drawLine(x + 7, y + 5, x + 6, y + 6); + g.drawLine(x + 1, y + 1, x + 1, y + 1); + g.drawLine(x, y + 2, x, y + 5); + g.drawLine(x + 1, y + 6, x + 1, y + 6); + g.drawLine(x + 2, y + 7, x + 5, y + 7); + g.fillRect(x + 3, y + 3, 2, 2); + + g.setColor(new Color(204, 204, 255)); + g.drawLine(x + 3, y + 2, x + 4, y + 2); + g.drawLine(x + 2, y + 3, x + 2, y + 4); + g.drawLine(x + 3, y + 5, x + 3, y + 5); + g.drawLine(x + 5, y + 3, x + 5, y + 3); + + g.setColor(new Color(153, 153, 204)); + g.drawLine(x + 2, y + 2, x + 2, y + 2); + g.drawLine(x + 2, y + 5, x + 2, y + 5); + g.drawLine(x + 2, y + 6, x + 5, y + 6); + g.drawLine(x + 5, y + 2, x + 5, y + 2); + g.drawLine(x + 6, y + 2, x + 6, y + 5); + + g.setColor(new Color(102, 102, 153)); + g.drawLine(x + 2, y + 1, x + 5, y + 1); + g.drawLine(x + 1, y + 2, x + 1, y + 5); + } + else + { + // TODO: pick up appropriate UI colors + g.setColor(Color.black); + g.drawLine(x + 2, y, x + 5, y); + g.drawLine(x + 6, y + 1, x + 7, y + 2); + g.drawLine(x + 7, y + 2, x + 7, y + 5); + g.fillRect(x + 3, y + 7, 2, 5); + g.drawLine(x + 7, y + 5, x + 6, y + 6); + g.drawLine(x + 1, y + 1, x + 1, y + 1); + g.drawLine(x, y + 2, x, y + 5); + g.drawLine(x + 1, y + 6, x + 1, y + 6); + g.drawLine(x + 2, y + 7, x + 5, y + 7); + g.fillRect(x + 3, y + 3, 2, 2); + + g.setColor(new Color(204, 204, 255)); + g.drawLine(x + 3, y + 2, x + 4, y + 2); + g.drawLine(x + 2, y + 3, x + 2, y + 4); + g.drawLine(x + 3, y + 5, x + 3, y + 5); + g.drawLine(x + 5, y + 3, x + 5, y + 3); + + g.setColor(new Color(153, 153, 204)); + g.drawLine(x + 2, y + 2, x + 2, y + 2); + g.drawLine(x + 2, y + 5, x + 2, y + 5); + g.drawLine(x + 2, y + 6, x + 5, y + 6); + g.drawLine(x + 5, y + 2, x + 5, y + 2); + g.drawLine(x + 6, y + 2, x + 6, y + 5); + + g.setColor(new Color(102, 102, 153)); + g.drawLine(x + 2, y + 1, x + 5, y + 1); + g.drawLine(x + 1, y + 2, x + 1, y + 5); + } + } + + /** + * Simply calls {@link #paintIcon(Component, Graphics, int, int)}. + * + * @param c the component. + * @param g the graphics device. + * @param x the x coordinate. + * @param y the y coordinate. + */ + public void paintMe(Component c, Graphics g, int x, int y) + { + paintIcon(c, g, x, y); + } + } + + /** + * A tree folder icon. + */ + public static class TreeFolderIcon extends FolderIcon16 + { + /** + * Creates a new instance. + */ + public TreeFolderIcon() + { + } + + /** + * Returns the additional height (???). + * + * @return The additional height. + */ + public int getAdditionalHeight() + { + return 2; + } + + /** + * Returns the shift (???). + * + * @return The shift. + */ + public int getShift() + { + return -1; + } + } + + /** + * A tree leaf icon. + */ + public static class TreeLeafIcon extends FileIcon16 + { + /** + * Creates a new instance. + */ + public TreeLeafIcon() + { + } + + /** + * Returns the additional height (???). + * + * @return The additional height. + */ + public int getAdditionalHeight() + { + return 4; + } + + /** + * Returns the shift (???). + * + * @return The shift. + */ + public int getShift() + { + return 2; + } + } + + /** The cached RadioButtonIcon instance. */ + private static RadioButtonIcon radioButtonIcon; + + /** + * Creates a new instance. All the methods are static, so creating an + * instance isn't necessary. + */ + public MetalIconFactory() + { + } + + /** + * Returns an icon for RadioButtons in the Metal L&F. + * + * @return an icon for RadioButtons in the Metal L&F + */ + public static Icon getRadioButtonIcon() + { + if (radioButtonIcon == null) + radioButtonIcon = new RadioButtonIcon(); + return radioButtonIcon; + } + + /** + * Returns the icon used to display the thumb for a horizontally oriented + * {@link JSlider}. + * + * @return The icon. + */ + public static Icon getHorizontalSliderThumbIcon() + { + return new HorizontalSliderThumbIcon(); + } + + /** + * Returns the icon used to display the thumb for a vertically oriented + * {@link JSlider}. + * + * @return The icon. + */ + public static Icon getVerticalSliderThumbIcon() + { + return new VerticalSliderThumbIcon(); + } + + /** + * Creates and returns a new tree folder icon. + * + * @return A new tree folder icon. + */ + public static Icon getTreeFolderIcon() + { + return new TreeFolderIcon(); + } + + /** + * Creates and returns a new tree leaf icon. + * + * @return A new tree leaf icon. + */ + public static Icon getTreeLeafIcon() + { + return new TreeLeafIcon(); + } + + /** + * Creates and returns a tree control icon. + * + * @param isCollapsed a flag that controls whether the icon is in the + * collapsed or expanded state. + * + * @return A tree control icon. + */ + public static Icon getTreeControlIcon(boolean isCollapsed) + { + return new TreeControlIcon(isCollapsed); + } + +} diff --git a/javax/swing/plaf/metal/MetalInternalFrameUI.java b/javax/swing/plaf/metal/MetalInternalFrameUI.java index f2f8e3600..14143512e 100644 --- a/javax/swing/plaf/metal/MetalInternalFrameUI.java +++ b/javax/swing/plaf/metal/MetalInternalFrameUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/metal/MetalLabelUI.java b/javax/swing/plaf/metal/MetalLabelUI.java index 12aa7b116..cdd861227 100644 --- a/javax/swing/plaf/metal/MetalLabelUI.java +++ b/javax/swing/plaf/metal/MetalLabelUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/metal/MetalLookAndFeel.java b/javax/swing/plaf/metal/MetalLookAndFeel.java index 77f683516..373fb0593 100644 --- a/javax/swing/plaf/metal/MetalLookAndFeel.java +++ b/javax/swing/plaf/metal/MetalLookAndFeel.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -39,49 +39,96 @@ exception statement from your version. */ package javax.swing.plaf.metal; import java.awt.Color; +import java.awt.Font; import java.awt.Insets; +import javax.swing.ImageIcon; import javax.swing.UIDefaults; import javax.swing.plaf.ColorUIResource; import javax.swing.plaf.FontUIResource; +import javax.swing.plaf.IconUIResource; +import javax.swing.plaf.InsetsUIResource; import javax.swing.plaf.basic.BasicLookAndFeel; +/** + * A custom look and feel that is designed to look similar across different + * operating systems. + */ public class MetalLookAndFeel extends BasicLookAndFeel { private static final long serialVersionUID = 6680646159193457980L; + + /** The current theme. */ private static MetalTheme theme; + + /** The look and feel defaults. */ private UIDefaults LAF_defaults; + /** + * Creates a new instance of the Metal look and feel. + */ public MetalLookAndFeel() { createDefaultTheme(); } + /** + * Sets the current theme to a new instance of {@link DefaultMetalTheme}. + */ protected void createDefaultTheme() { setCurrentTheme(new DefaultMetalTheme()); } + /** + * Returns <code>false</code> to indicate that this look and feel does not + * attempt to emulate the look and feel of native applications on the host + * platform. + * + * @return <code>false</code>. + */ public boolean isNativeLookAndFeel() { - return true; + return false; } + /** + * Returns <code>true</code> to indicate that this look and feel is supported + * on all platforms. + * + * @return <code>true</code>. + */ public boolean isSupportedLookAndFeel() { return true; } + /** + * Returns a string describing the look and feel. In this case, the method + * returns "Metal look and feel". + * + * @return A string describing the look and feel. + */ public String getDescription() { return "Metal look and feel"; } + /** + * Returns the look and feel identifier. + * + * @return "MetalLookAndFeel". + */ public String getID() { return "MetalLookAndFeel"; } + /** + * Returns the look and feel name. + * + * @return "MetalLookAndFeel". + */ public String getName() { return "MetalLookAndFeel"; @@ -90,225 +137,474 @@ public class MetalLookAndFeel extends BasicLookAndFeel public UIDefaults getDefaults() { if (LAF_defaults == null) - LAF_defaults = super.getDefaults(); + { + LAF_defaults = super.getDefaults(); - // add custom theme entries to the table - theme.addCustomEntriesToTable(LAF_defaults); + // add custom theme entries to the table + theme.addCustomEntriesToTable(LAF_defaults); + } // Returns the default values for this look and feel. return LAF_defaults; } + /** + * Returns the accelerator foreground color from the installed theme. + * + * @return The accelerator foreground color. + */ public static ColorUIResource getAcceleratorForeground() { return theme.getAcceleratorForeground(); } + /** + * Returns the accelerator selected foreground color from the installed + * theme. + * + * @return The accelerator selected foreground color. + */ public static ColorUIResource getAcceleratorSelectedForeground() { return theme.getAcceleratorSelectedForeground(); } + /** + * Returns the color black from the installed theme. + * + * @return The color black. + */ public static ColorUIResource getBlack() { return theme.getBlack(); } + /** + * Returns the control color from the installed theme. + * + * @return The control color. + */ public static ColorUIResource getControl() { return theme.getControl(); } + /** + * Returns the color used for dark shadows on controls, from the installed + * theme. + * + * @return The color used for dark shadows on controls. + */ public static ColorUIResource getControlDarkShadow() { return theme.getControlDarkShadow(); } + /** + * Returns the color used for disabled controls, from the installed theme. + * + * @return The color used for disabled controls. + */ public static ColorUIResource getControlDisabled() { return theme.getControlDisabled(); } + /** + * Returns the color used to draw highlights for controls, from the installed + * theme. + * + * @return The color used to draw highlights for controls. + */ public static ColorUIResource getControlHighlight() { return theme.getControlHighlight(); } + /** + * Returns the color used to display control info, from the installed + * theme. + * + * @return The color used to display control info. + */ public static ColorUIResource getControlInfo() { return theme.getControlInfo(); } + /** + * Returns the color used to draw shadows for controls, from the installed + * theme. + * + * @return The color used to draw shadows for controls. + */ public static ColorUIResource getControlShadow() { return theme.getControlShadow(); } + /** + * Returns the color used for text on controls, from the installed theme. + * + * @return The color used for text on controls. + */ public static ColorUIResource getControlTextColor() { return theme.getControlTextColor(); } + /** + * Returns the font used for text on controls, from the installed theme. + * + * @return The font used for text on controls. + */ public static FontUIResource getControlTextFont() { return theme.getControlTextFont(); } + /** + * Returns the color used for the desktop background, from the installed + * theme. + * + * @return The color used for the desktop background. + */ public static ColorUIResource getDesktopColor() { return theme.getDesktopColor(); } + /** + * Returns the color used to draw focus highlights, from the installed + * theme. + * + * @return The color used to draw focus highlights. + */ public static ColorUIResource getFocusColor() { return theme.getFocusColor(); } + /** + * Returns the color used to draw highlighted text, from the installed + * theme. + * + * @return The color used to draw highlighted text. + */ public static ColorUIResource getHighlightedTextColor() { return theme.getHighlightedTextColor(); } + /** + * Returns the color used to draw text on inactive controls, from the + * installed theme. + * + * @return The color used to draw text on inactive controls. + */ public static ColorUIResource getInactiveControlTextColor() { return theme.getInactiveControlTextColor(); } + /** + * Returns the color used to draw inactive system text, from the installed + * theme. + * + * @return The color used to draw inactive system text. + */ public static ColorUIResource getInactiveSystemTextColor() { return theme.getInactiveSystemTextColor(); } + /** + * Returns the background color for menu items, from the installed theme. + * + * @return The background color for menu items. + * + * @see #getMenuSelectedBackground() + */ public static ColorUIResource getMenuBackground() { return theme.getMenuBackground(); } + /** + * Returns the foreground color for disabled menu items, from the installed + * theme. + * + * @return The foreground color for disabled menu items. + * + * @see #getMenuForeground() + */ public static ColorUIResource getMenuDisabledForeground() { return theme.getMenuDisabledForeground(); } + /** + * Returns the foreground color for menu items, from the installed theme. + * + * @return The foreground color for menu items. + * + * @see #getMenuDisabledForeground() + * @see #getMenuSelectedForeground() + */ public static ColorUIResource getMenuForeground() { return theme.getMenuForeground(); } + /** + * Returns the background color for selected menu items, from the installed + * theme. + * + * @return The background color for selected menu items. + * + * @see #getMenuBackground() + */ public static ColorUIResource getMenuSelectedBackground() { return theme.getMenuSelectedBackground(); } + /** + * Returns the foreground color for selected menu items, from the installed + * theme. + * + * @return The foreground color for selected menu items. + * + * @see #getMenuForeground() + */ public static ColorUIResource getMenuSelectedForeground() { return theme.getMenuSelectedForeground(); } + /** + * Returns the font used for text in menus, from the installed theme. + * + * @return The font used for text in menus. + */ public static FontUIResource getMenuTextFont() { return theme.getMenuTextFont(); } + /** + * Returns the primary color for controls, from the installed theme. + * + * @return The primary color for controls. + */ public static ColorUIResource getPrimaryControl() { return theme.getPrimaryControl(); } + /** + * Returns the primary color for the dark shadow on controls, from the + * installed theme. + * + * @return The primary color for the dark shadow on controls. + */ public static ColorUIResource getPrimaryControlDarkShadow() { return theme.getPrimaryControlDarkShadow(); } + /** + * Returns the primary color for the highlight on controls, from the + * installed theme. + * + * @return The primary color for the highlight on controls. + */ public static ColorUIResource getPrimaryControlHighlight() { return theme.getPrimaryControlHighlight(); } + /** + * Returns the primary color for the information on controls, from the + * installed theme. + * + * @return The primary color for the information on controls. + */ public static ColorUIResource getPrimaryControlInfo() { return theme.getPrimaryControlInfo(); } + /** + * Returns the primary color for the shadow on controls, from the installed + * theme. + * + * @return The primary color for the shadow on controls. + */ public static ColorUIResource getPrimaryControlShadow() { return theme.getPrimaryControlShadow(); } + /** + * Returns the background color for separators, from the installed theme. + * + * @return The background color for separators. + */ public static ColorUIResource getSeparatorBackground() { return theme.getSeparatorBackground(); } + /** + * Returns the foreground color for separators, from the installed theme. + * + * @return The foreground color for separators. + */ public static ColorUIResource getSeparatorForeground() { return theme.getSeparatorForeground(); } + /** + * Returns the font used for sub text, from the installed theme. + * + * @return The font used for sub text. + */ public static FontUIResource getSubTextFont() { return theme.getSubTextFont(); } + /** + * Returns the color used for system text, from the installed theme. + * + * @return The color used for system text. + */ public static ColorUIResource getSystemTextColor() { return theme.getSystemTextColor(); } + /** + * Returns the font used for system text, from the installed theme. + * + * @return The font used for system text. + */ public static FontUIResource getSystemTextFont() { return theme.getSystemTextFont(); } + /** + * Returns the color used to highlight text, from the installed theme. + * + * @return The color used to highlight text. + */ public static ColorUIResource getTextHighlightColor() { return theme.getTextHighlightColor(); } + /** + * Returns the color used to display user text, from the installed theme. + * + * @return The color used to display user text. + */ public static ColorUIResource getUserTextColor() { return theme.getUserTextColor(); } + /** + * Returns the font used for user text, obtained from the current theme. + * + * @return The font used for user text. + */ public static FontUIResource getUserTextFont() { return theme.getUserTextFont(); } + /** + * Returns the color used for white, from the installed theme. + * + * @return The color used for white. + */ public static ColorUIResource getWhite() { return theme.getWhite(); } + /** + * Returns the window background color, from the installed theme. + * + * @return The window background color. + */ public static ColorUIResource getWindowBackground() { return theme.getWindowBackground(); } + /** + * Returns the window title background color, from the installed theme. + * + * @return The window title background color. + */ public static ColorUIResource getWindowTitleBackground() { return theme.getWindowTitleBackground(); } + /** + * Returns the window title font from the current theme. + * + * @return The window title font. + * + * @see MetalTheme + */ public static FontUIResource getWindowTitleFont() { return theme.getWindowTitleFont(); } + /** + * Returns the window title foreground color, from the installed theme. + * + * @return The window title foreground color. + */ public static ColorUIResource getWindowTitleForeground() { return theme.getWindowTitleForeground(); } + /** + * Returns the background color for an inactive window title, from the + * installed theme. + * + * @return The background color for an inactive window title. + */ public static ColorUIResource getWindowTitleInactiveBackground() { return theme.getWindowTitleInactiveBackground(); } + /** + * Returns the foreground color for an inactive window title, from the + * installed theme. + * + * @return The foreground color for an inactive window title. + */ public static ColorUIResource getWindowTitleInactiveForeground() { return theme.getWindowTitleInactiveForeground(); } + /** + * Sets the current theme for the look and feel. + * + * @param theme the theme. + */ public static void setCurrentTheme(MetalTheme theme) { MetalLookAndFeel.theme = theme; @@ -417,7 +713,7 @@ public class MetalLookAndFeel extends BasicLookAndFeel * </tr><tr> * <td>Button.background</td><td>0xcccccc</td> * </tr><tr> - * <td>Button.border</td><td>{@link MetalBorders.ButtonBorder}</td> + * <td>Button.border</td><td>{@link MetalBorders#getButtonBorder()}</td> * </tr><tr> * <td>Button.font</td><td>{@link #getControlTextFont}</td> * </tr><tr> @@ -476,6 +772,9 @@ public class MetalLookAndFeel extends BasicLookAndFeel "Button.select", new ColorUIResource(getPrimaryControlShadow()), "Button.shadow", new ColorUIResource(getPrimaryControlShadow()), "CheckBox.background", new ColorUIResource(getControl()), + "CheckBox.icon", + new UIDefaults.ProxyLazyValue + ("javax.swing.plaf.metal.MetalCheckBoxIcon"), "CheckBoxMenuItem.background", new ColorUIResource(getControl()), "ToolBar.background", new ColorUIResource(getControl()), "Panel.background", new ColorUIResource(getControl()), @@ -489,11 +788,28 @@ public class MetalLookAndFeel extends BasicLookAndFeel "Label.disabledForeground", new ColorUIResource(getControlDisabled()), "Label.foreground", new ColorUIResource(getSystemTextColor()), "Menu.background", new ColorUIResource(getControl()), + "Menu.border", new MetalBorders.MenuItemBorder(), + "Menu.borderPainted", Boolean.TRUE, "Menu.font", getControlTextFont(), + "Menu.selectionBackground", getMenuSelectedBackground(), + "Menu.selectionForeground", getMenuSelectedForeground(), "MenuBar.background", new ColorUIResource(getControl()), + "MenuBar.border", new MetalBorders.MenuBarBorder(), "MenuBar.font", getControlTextFont(), "MenuItem.background", new ColorUIResource(getControl()), + "MenuItem.border", new MetalBorders.MenuItemBorder(), "MenuItem.font", getControlTextFont(), + "MenuItem.selectionBackground", getMenuSelectedBackground(), + "MenuItem.selectionForeground", getMenuSelectedForeground(), + "Panel.background", new ColorUIResource(getControl()), + "RadioButton.icon", + new UIDefaults.LazyValue() + { + public Object createValue(UIDefaults def) + { + return MetalIconFactory.getRadioButtonIcon(); + } + }, "ScrollBar.background", new ColorUIResource(getControl()), "ScrollBar.shadow", new ColorUIResource(getControlShadow()), "ScrollBar.thumb", new ColorUIResource(getPrimaryControlShadow()), @@ -501,6 +817,53 @@ public class MetalLookAndFeel extends BasicLookAndFeel new ColorUIResource(getPrimaryControlDarkShadow()), "ScrollBar.thumbHighlight", new ColorUIResource(getPrimaryControl()), + + "SplitPane.darkShadow", + new ColorUIResource(getControlDarkShadow()), + "SplitPane.highlight", + new ColorUIResource(getControlHighlight()), + + "Slider.focusInsets", new InsetsUIResource(0, 0, 0, 0), + "Slider.horizontalThumbIcon", + MetalIconFactory.getHorizontalSliderThumbIcon(), + "Slider.verticalThumbIcon", + MetalIconFactory.getVerticalSliderThumbIcon(), + "Slider.trackWidth", new Integer(7), + "Slider.majorTickLength", new Integer(6), + + "ToggleButton.background", new ColorUIResource(getControl()), + "ToggleButton.border", MetalBorders.getButtonBorder(), + "ToggleButton.darkShadow", new ColorUIResource(getControlDarkShadow()), + "ToggleButton.disabledText", new ColorUIResource(getControlDisabled()), + "ToggleButton.focus", new ColorUIResource(getFocusColor()), + "ToggleButton.font", getControlTextFont(), + "ToggleButton.foreground", new ColorUIResource(getSystemTextColor()), + "ToggleButton.highlight", new ColorUIResource(getControlHighlight()), + "ToggleButton.light", new ColorUIResource(getControlHighlight()), + "ToggleButton.margin", new Insets(2, 14, 2, 14), + "ToggleButton.select", new ColorUIResource(getPrimaryControlShadow()), + "ToggleButton.shadow", new ColorUIResource(getPrimaryControlShadow()), + + "Tree.openIcon", MetalIconFactory.getTreeFolderIcon(), + "Tree.closedIcon", MetalIconFactory.getTreeFolderIcon(), + "Tree.leafIcon", MetalIconFactory.getTreeLeafIcon(), + "Tree.collapsedIcon", MetalIconFactory.getTreeControlIcon(true), + "Tree.expandedIcon", MetalIconFactory.getTreeControlIcon(false), + "Tree.font", new FontUIResource(new Font("Helvetica", Font.PLAIN, 12)), + "Tree.background", new ColorUIResource(Color.white), + "Tree.foreground", new ColorUIResource(new Color(204, 204, 255)), + "Tree.hash", new ColorUIResource(new Color(204, 204, 255)), + "Tree.leftChildIndent", new Integer(7), + "Tree.rightChildIndent", new Integer(13), + "Tree.rowHeight", new Integer(20), + "Tree.scrollsOnExpand", Boolean.TRUE, + "Tree.selectionBackground", new ColorUIResource(new Color(204, 204, 255)), + "Tree.nonSelectionBackground", new ColorUIResource(Color.white), + "Tree.selectionBorderColor", new ColorUIResource(new Color(102, 102, 153)), + "Tree.selectionForeground", new ColorUIResource(Color.black), + "Tree.textBackground", new ColorUIResource(new Color(204, 204, 255)), + "Tree.textForeground", new ColorUIResource(Color.black), + "Tree.selectionForeground", new ColorUIResource(Color.black), "PopupMenu.border", new MetalBorders.PopupMenuBorder() }; defaults.putDefaults(myDefaults); diff --git a/javax/swing/plaf/metal/MetalPopupMenuSeparatorUI.java b/javax/swing/plaf/metal/MetalPopupMenuSeparatorUI.java index 0892c56e4..ec9bf2b55 100644 --- a/javax/swing/plaf/metal/MetalPopupMenuSeparatorUI.java +++ b/javax/swing/plaf/metal/MetalPopupMenuSeparatorUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/metal/MetalProgressBarUI.java b/javax/swing/plaf/metal/MetalProgressBarUI.java index 04ca52f71..96d1988fd 100644 --- a/javax/swing/plaf/metal/MetalProgressBarUI.java +++ b/javax/swing/plaf/metal/MetalProgressBarUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/metal/MetalRadioButtonUI.java b/javax/swing/plaf/metal/MetalRadioButtonUI.java index b4ff10bd5..a668f914e 100644 --- a/javax/swing/plaf/metal/MetalRadioButtonUI.java +++ b/javax/swing/plaf/metal/MetalRadioButtonUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/metal/MetalRootPaneUI.java b/javax/swing/plaf/metal/MetalRootPaneUI.java index 5306b6182..4196a4e47 100644 --- a/javax/swing/plaf/metal/MetalRootPaneUI.java +++ b/javax/swing/plaf/metal/MetalRootPaneUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/metal/MetalScrollBarUI.java b/javax/swing/plaf/metal/MetalScrollBarUI.java index 17ac88bc7..526dfb50a 100644 --- a/javax/swing/plaf/metal/MetalScrollBarUI.java +++ b/javax/swing/plaf/metal/MetalScrollBarUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -129,28 +129,9 @@ public class MetalScrollBarUI thumbBounds.y + thumbBounds.height); // draw the pattern - int xOff = 0; - for (int y = thumbBounds.y + 4; - y < (thumbBounds.y + thumbBounds.height - 4); y++) - { - // set color alternating with every line - if ((y % 2) == 0) - g.setColor(thumbHighlightColor); - else - g.setColor(thumbDarkShadowColor); - - for (int x = thumbBounds.x + 3 + (xOff); - x < (thumbBounds.x + thumbBounds.width - 3); x = x + 4) - { - g.drawLine(x, y, x, y); - } - - // increase x offset - xOff++; - if (xOff > 3) - xOff = 0; - - } + MetalUtils.fillMetalPattern(g, thumbBounds.x + 3, thumbBounds.y + 3, + thumbBounds.width - 6, thumbBounds.height - 6, + thumbHighlightColor, thumbDarkShadowColor); } /** diff --git a/javax/swing/plaf/metal/MetalScrollPaneUI.java b/javax/swing/plaf/metal/MetalScrollPaneUI.java index 6220ea9e2..3e1198b39 100644 --- a/javax/swing/plaf/metal/MetalScrollPaneUI.java +++ b/javax/swing/plaf/metal/MetalScrollPaneUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/metal/MetalSeparatorUI.java b/javax/swing/plaf/metal/MetalSeparatorUI.java index e6c36b4e4..6e78ccb70 100644 --- a/javax/swing/plaf/metal/MetalSeparatorUI.java +++ b/javax/swing/plaf/metal/MetalSeparatorUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/metal/MetalSliderUI.java b/javax/swing/plaf/metal/MetalSliderUI.java index fafd21d3e..4b52c4b00 100644 --- a/javax/swing/plaf/metal/MetalSliderUI.java +++ b/javax/swing/plaf/metal/MetalSliderUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -38,25 +38,72 @@ exception statement from your version. */ package javax.swing.plaf.metal; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.Rectangle; +import java.beans.PropertyChangeListener; import java.util.HashMap; +import javax.swing.Icon; import javax.swing.JComponent; +import javax.swing.JSlider; +import javax.swing.UIManager; import javax.swing.plaf.ComponentUI; +import javax.swing.plaf.basic.BasicGraphicsUtils; import javax.swing.plaf.basic.BasicSliderUI; +/** + * A UI delegate for the {@link JSlider} component. + */ public class MetalSliderUI extends BasicSliderUI { + // TODO: find a use for this + protected static Color thumbColor; + + // TODO: find a use for this + protected static Color highlightColor; + + // TODO: find a use for this + protected static Color darkShadowColor; + + /** The track width. */ + protected static int trackWidth = UIManager.getInt("Slider.trackWidth"); + + /** The length of the major tick marks. */ + protected static int tickLength = UIManager.getInt("Slider.majorTickLength"); + + /** The icon used for the thumb control of horizontally oriented sliders. */ + protected static Icon horizThumbIcon = UIManager.getIcon( + "Slider.horizontalThumbIcon"); + + /** The icon used for the thumb control of vertically oriented sliders. */ + protected static Icon vertThumbIcon = UIManager.getIcon( + "Slider.verticalThumbIcon"); + /** The gap between the track and the tick marks. */ + protected final int TICK_BUFFER = 4; + + /** + * A flag that controls whether or not the track is filled up to the value + * of the slider. + */ + protected boolean filledSlider; + + /** A key to look up the filledSlider setting in the {@link UIManager}. */ + protected final String SLIDER_FILL = "JSlider.isFilled"; + /** The UI instances for MetalSliderUIs */ private static HashMap instances; /** - * Constructs a new instance of MetalSliderUI. + * Constructs a new instance. */ public MetalSliderUI() { super(null); + filledSlider = UIManager.getBoolean(SLIDER_FILL); } /** @@ -71,17 +118,225 @@ public class MetalSliderUI if (instances == null) instances = new HashMap(); - Object o = instances.get(component); MetalSliderUI instance; if (o == null) { - instance = new MetalSliderUI(); - instances.put(component, instance); + instance = new MetalSliderUI(); + instances.put(component, instance); } else instance = (MetalSliderUI) o; return instance; } + + public void installUI(JComponent c) + { + super.installUI(c); + Boolean b = (Boolean) c.getClientProperty(SLIDER_FILL); + if (b != null) + filledSlider = b.booleanValue(); + } + + /** + * Paints the thumb icon for the slider. + * + * @param g the graphics device. + */ + public void paintThumb(Graphics g) + { + if (slider.getOrientation() == JSlider.HORIZONTAL) + horizThumbIcon.paintIcon(slider, g, thumbRect.x, thumbRect.y); + else + vertThumbIcon.paintIcon(slider, g, thumbRect.x, thumbRect.y); + } + + /** + * Creates a property change listener for the slider. + * + * @param slider the slider. + */ + protected PropertyChangeListener createPropertyChangeListener(JSlider slider) + { + // TODO: try to figure out why it might be necessary to override this + // method as is done in Sun's implementation + return super.createPropertyChangeListener(slider); + } + + /** + * Paints the track along which the thumb control moves. + * + * @param g the graphics device. + */ + public void paintTrack(Graphics g) + { + if (slider.getOrientation() == JSlider.HORIZONTAL) + { + if (filledSlider) + { + // TODO: fill the track + } + BasicGraphicsUtils.drawEtchedRect(g, trackRect.x, trackRect.y + + (trackRect.height - getTrackWidth()) / 2, trackRect.width - 1, + getTrackWidth(), Color.darkGray, Color.gray, Color.darkGray, + Color.white); + } + else + { + if (filledSlider) + { + // TODO: fill the track + } + BasicGraphicsUtils.drawEtchedRect(g, trackRect.x + (trackRect.width + - getTrackWidth()) / 2, trackRect.y, getTrackWidth(), + trackRect.height - 1, Color.darkGray, Color.gray, Color.darkGray, + Color.white); + } + } + + /** + * Draws the focus rectangle for the slider. The Metal look and feel + * indicates that the {@link JSlider} has the focus by changing the color of + * the thumb control - this is handled elsewhere and so this method is empty + * (it overrides the method in the {@link BasicSliderUI} class to prevent + * a default focus highlight from being drawn). + * + * @param g the graphics device. + */ + public void paintFocus(Graphics g) + { + // do nothing as focus is shown by different color on thumb control + } + + /** + * Returns the size of the thumb icon. + * + * @return The size of the thumb icon. + */ + protected Dimension getThumbSize() + { + if (slider.getOrientation() == JSlider.HORIZONTAL) + return new Dimension(horizThumbIcon.getIconWidth(), + horizThumbIcon.getIconHeight()); + else + return new Dimension(vertThumbIcon.getIconWidth(), + vertThumbIcon.getIconHeight()); + } + + /** + * Returns the length of the major tick marks. + * + * @return The length of the major tick marks. + */ + public int getTickLength() + { + return tickLength + TICK_BUFFER; + } + + /** + * Returns the track width. + * + * @return The track width. + */ + protected int getTrackWidth() + { + return trackWidth; + } + + /** + * Returns the track length. + * + * @return The track length. + */ + protected int getTrackLength() + { + return (slider.getOrientation() == JSlider.HORIZONTAL + ? tickRect.width : tickRect.height); + } + + /** + * Returns the thumb overhang. + * + * @return The thumb overhang. + */ + protected int getThumbOverhang() + { + // TODO: figure out what this is used for + return 0; + } + + protected void scrollDueToClickInTrack(int dir) + { + super.scrollDueToClickInTrack(dir); + } + + /** + * Paints the minor ticks for a slider with a horizontal orientation. + * + * @param g the graphics device. + * @param tickBounds the tick bounds. + * @param x the x value for the tick. + */ + protected void paintMinorTickForHorizSlider(Graphics g, Rectangle tickBounds, + int x) + { + // Note the incoming 'g' has a translation in place to get us to the + // start of the tick rect already... + // TODO: get color from UIManager... + g.setColor(new Color(153, 153, 204)); + g.drawLine(x, TICK_BUFFER, x, TICK_BUFFER + tickLength / 2); + } + + /** + * Paints the major ticks for a slider with a horizontal orientation. + * + * @param g the graphics device. + * @param tickBounds the tick bounds. + * @param x the x value for the tick. + */ + protected void paintMajorTickForHorizSlider(Graphics g, Rectangle tickBounds, + int x) + { + // Note the incoming 'g' has a translation in place to get us to the + // start of the tick rect already... + // TODO: get color from UIManager... + g.setColor(new Color(153, 153, 204)); + g.drawLine(x, TICK_BUFFER, x, TICK_BUFFER + tickLength); + } + + /** + * Paints the minor ticks for a slider with a vertical orientation. + * + * @param g the graphics device. + * @param tickBounds the tick bounds. + * @param y the y value for the tick. + */ + protected void paintMinorTickForVertSlider(Graphics g, Rectangle tickBounds, + int y) + { + // Note the incoming 'g' has a translation in place to get us to the + // start of the tick rect already... + // TODO: get color from UIManager... + g.setColor(new Color(153, 153, 204)); + g.drawLine(TICK_BUFFER - 1, y, TICK_BUFFER - 1 + tickLength / 2, y); + } + + /** + * Paints the major ticks for a slider with a vertical orientation. + * + * @param g the graphics device. + * @param tickBounds the tick bounds. + * @param y the y value for the tick. + */ + protected void paintMajorTickForVertSlider(Graphics g, Rectangle tickBounds, + int y) + { + // Note the incoming 'g' has a translation in place to get us to the + // start of the tick rect already... + // TODO: get color from UIManager... + g.setColor(new Color(153, 153, 204)); + g.drawLine(TICK_BUFFER - 1, y, TICK_BUFFER - 1 + tickLength, y); + } + } diff --git a/javax/swing/plaf/metal/MetalSplitPaneDivider.java b/javax/swing/plaf/metal/MetalSplitPaneDivider.java new file mode 100644 index 000000000..60e9c0559 --- /dev/null +++ b/javax/swing/plaf/metal/MetalSplitPaneDivider.java @@ -0,0 +1,84 @@ +/* MetalSplitPaneDivider.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.Color; +import java.awt.Dimension; +import java.awt.Graphics; + +import javax.swing.plaf.basic.BasicSplitPaneDivider; + +/** + * The divider that is used by the MetalSplitPaneUI. + * + * @author Roman Kennke (roman@kennke.org) + * + */ +class MetalSplitPaneDivider extends BasicSplitPaneDivider +{ + /** The dark color in the pattern. */ + Color dark; + + /** The light color in the pattern. */ + Color light; + + /** + * Creates a new instance of MetalSplitPaneDivider. + * + * @param ui the <code>MetalSplitPaneUI</code> that uses this divider + */ + public MetalSplitPaneDivider(MetalSplitPaneUI ui, Color light, Color dark) + { + super(ui); + this.light = light; + this.dark = dark; + } + + /** + * Paints the divider. + * + * @param g the <code>Graphics</code> context to use for painting + */ + public void paint(Graphics g) + { + //super.paint(g); + Dimension s = getSize(); + MetalUtils.fillMetalPattern(g, 2, 2, s.width - 4, s.height - 4, + light, dark); + } +} diff --git a/javax/swing/plaf/metal/MetalSplitPaneUI.java b/javax/swing/plaf/metal/MetalSplitPaneUI.java index eda17f508..b7ea8984b 100644 --- a/javax/swing/plaf/metal/MetalSplitPaneUI.java +++ b/javax/swing/plaf/metal/MetalSplitPaneUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -38,11 +38,15 @@ exception statement from your version. */ package javax.swing.plaf.metal; +import java.awt.Color; import java.util.HashMap; import javax.swing.JComponent; +import javax.swing.UIDefaults; +import javax.swing.UIManager; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicSplitPaneUI; +import javax.swing.plaf.basic.BasicSplitPaneDivider; public class MetalSplitPaneUI extends BasicSplitPaneUI @@ -83,4 +87,20 @@ public class MetalSplitPaneUI return instance; } + + /** + * Returns the divider that is used by the <code>JSplitPane</code>. + * + * The divider returned by this method is a {@link BasicSplitPaneDivider} + * that is drawn using the Metal look. + * + * @return the default divider to use for <code>JSplitPane</code>s. + */ + public BasicSplitPaneDivider createDefaultDivider() + { + UIDefaults defaults = UIManager.getLookAndFeelDefaults(); + Color light = defaults.getColor("SplitPane.highlight"); + Color dark = defaults.getColor("SplitPane.darkShadow"); + return new MetalSplitPaneDivider(this, light, dark); + } } diff --git a/javax/swing/plaf/metal/MetalTabbedPaneUI.java b/javax/swing/plaf/metal/MetalTabbedPaneUI.java index 524fc5253..bf50f9172 100644 --- a/javax/swing/plaf/metal/MetalTabbedPaneUI.java +++ b/javax/swing/plaf/metal/MetalTabbedPaneUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/metal/MetalTextFieldUI.java b/javax/swing/plaf/metal/MetalTextFieldUI.java index d2e9ea529..d6e50e122 100644 --- a/javax/swing/plaf/metal/MetalTextFieldUI.java +++ b/javax/swing/plaf/metal/MetalTextFieldUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/metal/MetalTheme.java b/javax/swing/plaf/metal/MetalTheme.java index 970f83095..d5131af2e 100644 --- a/javax/swing/plaf/metal/MetalTheme.java +++ b/javax/swing/plaf/metal/MetalTheme.java @@ -1,5 +1,5 @@ /* MetalTheme.java -- - Copyright (C) 2004 Free Software Foundation, Inc. + Copyright (C) 2004, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -45,215 +45,532 @@ import javax.swing.UIDefaults; import javax.swing.plaf.ColorUIResource; import javax.swing.plaf.FontUIResource; +/** + * The base class for themes used by the {@link MetalLookAndFeel}. A default + * theme ({@link DefaultMetalTheme}) is provided, or you can create and use + * your own. + * + * @see MetalLookAndFeel#setCurrentTheme(MetalTheme) + */ public abstract class MetalTheme { private ColorUIResource BLACK = new ColorUIResource(Color.BLACK); private ColorUIResource WHITE = new ColorUIResource(Color.WHITE); + /** + * Default constructor. + */ public MetalTheme() { // Do nothing here. } + /** + * Returns the name of the theme. + * + * @return The name of the theme. + */ public abstract String getName(); + /** + * Adds custom entries to the UI defaults table. This method is empty. + * + * @param table the table. + */ public void addCustomEntriesToTable(UIDefaults table) { // Do nothing here. - // This method needs to be overloaded to actuall do something. + // This method needs to be overridden to actually do something. + // It is called from MetalLookAndFeel.getDefaults(). } + /** + * Returns the accelerator foreground color. The default implementation + * returns the color from {@link #getPrimary1()}. + * + * @return The accelerator foreground color. + */ public ColorUIResource getAcceleratorForeground() { return getPrimary1(); } + /** + * Returns the accelerator selected foreground color. The default + * implementation returns the color from {@link #getBlack()}. + * + * @return The accelerator selected foreground color. + */ public ColorUIResource getAcceleratorSelectedForeground() { return getBlack(); } + /** + * Returns the control color. The default implementation returns the color + * from {@link #getSecondary3()}. + * + * @return The control color. + */ public ColorUIResource getControl() { return getSecondary3(); } + /** + * Returns the color used for dark shadows on controls. The default + * implementation returns the color from {@link #getSecondary1()}. + * + * @return The color used for dark shadows on controls. + */ public ColorUIResource getControlDarkShadow() { return getSecondary1(); } + /** + * Returns the color used for disabled controls. The default implementation + * returns the color from {@link #getSecondary1()}. + * + * @return The color used for disabled controls. + */ public ColorUIResource getControlDisabled() { return getSecondary2(); } + /** + * Returns the color used to draw highlights for controls. The default + * implementation returns the color from {@link #getWhite()}. + * + * @return The color used to draw highlights for controls. + */ public ColorUIResource getControlHighlight() { return getWhite(); } + /** + * Returns the color used to display control info. The default + * implementation returns the color from {@link #getBlack()}. + * + * @return The color used to display control info. + */ public ColorUIResource getControlInfo() { return getBlack(); } + /** + * Returns the color used to draw shadows for controls. The default + * implementation returns the color from {@link #getSecondary2()}. + * + * @return The color used to draw shadows for controls. + */ public ColorUIResource getControlShadow() { return getSecondary2(); } + /** + * Returns the color used for text on controls. The default implementation + * returns the color from {@link #getControlInfo()}. + * + * @return The color used for text on controls. + */ public ColorUIResource getControlTextColor() { return getControlInfo(); } + /** + * Returns the color used for the desktop background. The default + * implementation returns the color from {@link #getPrimary2()}. + * + * @return The color used for the desktop background. + */ public ColorUIResource getDesktopColor() { return getPrimary2(); } + /** + * Returns the color used to draw focus highlights. The default + * implementation returns the color from {@link #getPrimary2()}. + * + * @return The color used to draw focus highlights. + */ public ColorUIResource getFocusColor() { return getPrimary2(); } + /** + * Returns the color used to draw highlighted text. The default + * implementation returns the color from {@link #getHighlightedTextColor()}. + * + * @return The color used to draw highlighted text. + */ public ColorUIResource getHighlightedTextColor() { return getControlTextColor(); } + /** + * Returns the color used to draw text on inactive controls. The default + * implementation returns the color from {@link #getControlDisabled()}. + * + * @return The color used to draw text on inactive controls. + */ public ColorUIResource getInactiveControlTextColor() { return getControlDisabled(); } + /** + * Returns the color used to draw inactive system text. The default + * implementation returns the color from {@link #getSecondary2()}. + * + * @return The color used to draw inactive system text. + */ public ColorUIResource getInactiveSystemTextColor() { return getSecondary2(); } + /** + * Returns the background color for menu items. The default implementation + * returns the color from {@link #getSecondary3()}. + * + * @return The background color for menu items. + * + * @see #getMenuSelectedBackground() + */ public ColorUIResource getMenuBackground() { return getSecondary3(); } + /** + * Returns the foreground color for disabled menu items. The default + * implementation returns the color from {@link #getSecondary2()}. + * + * @return The foreground color for disabled menu items. + * + * @see #getMenuForeground() + */ public ColorUIResource getMenuDisabledForeground() { - return getSecondary3(); + return getSecondary2(); } + /** + * Returns the foreground color for menu items. The default implementation + * returns the color from {@link #getBlack()}. + * + * @return The foreground color for menu items. + * + * @see #getMenuDisabledForeground() + * @see #getMenuSelectedForeground() + */ public ColorUIResource getMenuForeground() { return getBlack(); } + /** + * Returns the background color for selected menu items. The default + * implementation returns the color from {@link #getPrimary2()}. + * + * @return The background color for selected menu items. + * + * @see #getMenuBackground() + */ public ColorUIResource getMenuSelectedBackground() { return getPrimary2(); } + /** + * Returns the foreground color for selected menu items. The default + * implementation returns the value from {@link #getBlack()}. + * + * @return The foreground color for selected menu items. + * + * @see #getMenuForeground() + */ public ColorUIResource getMenuSelectedForeground() { return getBlack(); } + /** + * Returns the primary color for controls. The default implementation + * returns the color from {@link #getPrimary3()}. + * + * @return The primary color for controls. + */ public ColorUIResource getPrimaryControl() { return getPrimary3(); } + /** + * Returns the primary color for the dark shadow on controls. The default + * implementation returns the color from {@link #getPrimary1()}. + * + * @return The primary color for the dark shadow on controls. + */ public ColorUIResource getPrimaryControlDarkShadow() { return getPrimary1(); } + /** + * Returns the primary color for the highlight on controls. The default + * implementation returns the color from {@link #getWhite()}. + * + * @return The primary color for the highlight on controls. + */ public ColorUIResource getPrimaryControlHighlight() { return getWhite(); } + /** + * Returns the primary color for the information on controls. The default + * implementation returns the color from {@link #getBlack()}. + * + * @return The primary color for the information on controls. + */ public ColorUIResource getPrimaryControlInfo() { return getBlack(); } + /** + * Returns the primary color for the shadow on controls. The default + * implementation returns the color from {@link #getPrimary2()}. + * + * @return The primary color for the shadow on controls. + */ public ColorUIResource getPrimaryControlShadow() { return getPrimary2(); } + /** + * Returns the background color for separators. The default implementation + * returns the color from {@link #getWhite()}. + * + * @return The background color for separators. + */ public ColorUIResource getSeparatorBackground() { return getWhite(); } + /** + * Returns the foreground color for separators. The default implementation + * returns the value from {@link #getPrimary1()}. + * + * @return The foreground color for separators. + */ public ColorUIResource getSeparatorForeground() { return getPrimary1(); } + /** + * Returns the color used for system text. The default implementation + * returns the color from {@link #getBlack()}. + * + * @return The color used for system text. + */ public ColorUIResource getSystemTextColor() { return getBlack(); } + /** + * Returns the color used to highlight text. The default implementation + * returns the color from {@link #getPrimary3()}. + * + * @return The color used to highlight text. + */ public ColorUIResource getTextHighlightColor() { return getPrimary3(); } + /** + * Returns the color used to display user text. The default implementation + * returns the color from {@link #getBlack()}. + * + * @return The color used to display user text. + */ public ColorUIResource getUserTextColor() { return getBlack(); } + /** + * Returns the window background color. The default implementation returns + * the color from {@link #getWhite()}. + * + * @return The window background color. + */ public ColorUIResource getWindowBackground() { return getWhite(); } + /** + * Returns the window title background color. The default implementation + * returns the color from {@link #getPrimary3()}. + * + * @return The window title background color. + */ public ColorUIResource getWindowTitleBackground() { return getPrimary3(); } + /** + * Returns the window title foreground color. The default implementation + * returns the color from {@link #getBlack()}. + * + * @return The window title foreground color. + */ public ColorUIResource getWindowTitleForeground() { return getBlack(); } + /** + * Returns the background color for an inactive window title. The default + * implementation returns the color from {@link #getSecondary3()}. + * + * @return The background color for an inactive window title. + */ public ColorUIResource getWindowTitleInactiveBackground() { return getSecondary3(); } + /** + * Returns the foreground color for an inactive window title. The default + * implementation returns the color from {@link #getBlack()}. + * + * @return The foreground color for an inactive window title. + */ public ColorUIResource getWindowTitleInactiveForeground() { return getBlack(); } + /** + * Returns the color used for black. + * + * @return The color used for black. + */ protected ColorUIResource getBlack() { return BLACK; } + /** + * Returns the color used for white. + * + * @return The color used for white. + */ protected ColorUIResource getWhite() { return WHITE; } + /** + * Returns the first primary color for this theme. + * + * @return The first primary color. + */ protected abstract ColorUIResource getPrimary1(); + + /** + * Returns the second primary color for this theme. + * + * @return The second primary color. + */ protected abstract ColorUIResource getPrimary2(); + + /** + * Returns the third primary color for this theme. + * + * @return The third primary color. + */ protected abstract ColorUIResource getPrimary3(); + + /** + * Returns the first secondary color for this theme. + * + * @return The first secondary color. + */ protected abstract ColorUIResource getSecondary1(); + + /** + * Returns the second secondary color for this theme. + * + * @return The second secondary color. + */ protected abstract ColorUIResource getSecondary2(); + + /** + * Returns the third secondary color for this theme. + * + * @return The third secondary color. + */ protected abstract ColorUIResource getSecondary3(); + /** + * Returns the font used for text on controls. + * + * @return The font used for text on controls. + */ public abstract FontUIResource getControlTextFont(); + + /** + * Returns the font used for text in menus. + * + * @return The font used for text in menus. + */ public abstract FontUIResource getMenuTextFont(); + + /** + * Returns the font used for sub text. + * + * @return The font used for sub text. + */ public abstract FontUIResource getSubTextFont(); + + /** + * Returns the font used for system text. + * + * @return The font used for system text. + */ public abstract FontUIResource getSystemTextFont(); + + /** + * Returns the font used for user text. + * + * @return The font used for user text. + */ public abstract FontUIResource getUserTextFont(); + + /** + * Returns the font used for window titles. + * + * @return The font used for window titles. + */ public abstract FontUIResource getWindowTitleFont(); + } diff --git a/javax/swing/plaf/metal/MetalToggleButtonUI.java b/javax/swing/plaf/metal/MetalToggleButtonUI.java index 84af36a5e..be6d0c39e 100644 --- a/javax/swing/plaf/metal/MetalToggleButtonUI.java +++ b/javax/swing/plaf/metal/MetalToggleButtonUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -38,7 +38,11 @@ exception statement from your version. */ package javax.swing.plaf.metal; +import java.awt.Color; + import javax.swing.JComponent; +import javax.swing.UIDefaults; +import javax.swing.UIManager; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicToggleButtonUI; @@ -46,7 +50,15 @@ public class MetalToggleButtonUI extends BasicToggleButtonUI { - // FIXME: maybe replace by a Map of instances when this becomes stateful + /** The color for the focus border. */ + protected Color focusColor; + + /** The color that indicates a selected button. */ + protected Color selectColor; + + /** The color for disabled button labels. */ + protected Color disabledTextColor; + /** The shared UI instance for MetalToggleButtonUIs */ private static MetalToggleButtonUI instance = null; @@ -56,6 +68,43 @@ public class MetalToggleButtonUI public MetalToggleButtonUI() { super(); + focusColor = getFocusColor(); + selectColor = getSelectColor(); + disabledTextColor = getDisabledTextColor(); + } + + + /** + * Returns the color for the focus border. + * + * @return the color for the focus border + */ + protected Color getFocusColor() + { + UIDefaults def = UIManager.getLookAndFeelDefaults(); + return def.getColor(getPropertyPrefix() + ".focus"); + } + + /** + * Returns the color that indicates a selected button. + * + * @return the color that indicates a selected button + */ + protected Color getSelectColor() + { + UIDefaults def = UIManager.getLookAndFeelDefaults(); + return def.getColor(getPropertyPrefix() + ".select"); + } + + /** + * Returns the color for the text label of disabled buttons. + * + * @return the color for the text label of disabled buttons + */ + protected Color getDisabledTextColor() + { + UIDefaults def = UIManager.getLookAndFeelDefaults(); + return def.getColor(getPropertyPrefix() + ".disabledText"); } /** diff --git a/javax/swing/plaf/metal/MetalToolBarUI.java b/javax/swing/plaf/metal/MetalToolBarUI.java index 299a4c0a4..39af0011a 100644 --- a/javax/swing/plaf/metal/MetalToolBarUI.java +++ b/javax/swing/plaf/metal/MetalToolBarUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/metal/MetalToolTipUI.java b/javax/swing/plaf/metal/MetalToolTipUI.java index 303b6294a..c88b6534a 100644 --- a/javax/swing/plaf/metal/MetalToolTipUI.java +++ b/javax/swing/plaf/metal/MetalToolTipUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/javax/swing/plaf/metal/MetalTreeUI.java b/javax/swing/plaf/metal/MetalTreeUI.java index a420204b5..d85d61c24 100644 --- a/javax/swing/plaf/metal/MetalTreeUI.java +++ b/javax/swing/plaf/metal/MetalTreeUI.java @@ -15,8 +15,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -38,6 +38,8 @@ exception statement from your version. */ package javax.swing.plaf.metal; +import java.util.HashMap; + import javax.swing.JComponent; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicTreeUI; @@ -46,9 +48,8 @@ public class MetalTreeUI extends BasicTreeUI { - // FIXME: maybe replace by a Map of instances when this becomes stateful - /** The shared UI instance for MetalTreeUIs */ - private static MetalTreeUI instance = null; + /** The UI instances for MetalTreeUIs */ + private static HashMap instances = null; /** * Constructs a new instance of MetalTreeUI. @@ -67,8 +68,19 @@ public class MetalTreeUI */ public static ComponentUI createUI(JComponent component) { - if (instance == null) - instance = new MetalTreeUI(); + if (instances == null) + instances = new HashMap(); + + Object o = instances.get(component); + MetalTreeUI instance; + if (o == null) + { + instance = new MetalTreeUI(); + instances.put(component, instance); + } + else + instance = (MetalTreeUI) o; + return instance; } } diff --git a/javax/swing/plaf/metal/MetalUtils.java b/javax/swing/plaf/metal/MetalUtils.java new file mode 100644 index 000000000..a342ee02b --- /dev/null +++ b/javax/swing/plaf/metal/MetalUtils.java @@ -0,0 +1,87 @@ +/* Metaltils.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.Color; +import java.awt.Graphics; + +/** + * Some utility and helper methods for the Metal Look & Feel. + * + * @author Roman Kennke (roman@kennke.org) + */ +class MetalUtils +{ + + /** + * Fills a rectangle with the typical Metal pattern. + * + * @param g the <code>Graphics</code> context to use + * @param x the X coordinate of the upper left corner of the rectangle to + * fill + * @param y the Y coordinate of the upper left corner of the rectangle to + * fill + * @param w the width of the rectangle to fill + * @param w the height of the rectangle to fill + * @param light the light color to use + * @param dark the dark color to use + */ + static void fillMetalPattern(Graphics g, int x, int y, int w, int h, + Color light, Color dark) + { + int xOff = 0; + for (int mY = y; mY < (y + h); mY++) + { + // set color alternating with every line + if ((mY % 2) == 0) + g.setColor(light); + else + g.setColor(dark); + + for (int mX = x + (xOff); mX < (x + w); mX += 4) + { + g.drawLine(mX, mY, mX, mY); + } + + // increase x offset + xOff++; + if (xOff > 3) + xOff = 0; + } + } +} diff --git a/javax/swing/plaf/metal/package.html b/javax/swing/plaf/metal/package.html index 3d125027a..2ea787bb5 100644 --- a/javax/swing/plaf/metal/package.html +++ b/javax/swing/plaf/metal/package.html @@ -1,6 +1,6 @@ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> <!-- package.html - describes classes in javax.swing.plaf.metal package. - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -16,8 +16,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -40,7 +40,7 @@ exception statement from your version. --> <head><title>GNU Classpath - javax.swing.plaf.metal</title></head> <body> -<p></p> +<p>Provides a cross-platform look and feel known as "Metal".</p> </body> </html> diff --git a/javax/swing/plaf/package.html b/javax/swing/plaf/package.html index e4b247aea..c266074f0 100644 --- a/javax/swing/plaf/package.html +++ b/javax/swing/plaf/package.html @@ -1,6 +1,6 @@ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> <!-- package.html - describes classes in javax.swing.plaf package. - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -16,8 +16,8 @@ General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -40,7 +40,8 @@ exception statement from your version. --> <head><title>GNU Classpath - javax.swing.plaf</title></head> <body> -<p></p> +<p>A base package for the "pluggable look and feel" (plaf) mechanism used by +the <code>javax.swing</code> classes.</p> </body> </html> |