OpenJDK / jdk / hs
changeset 5960:854b333fd137
Merge
author | lana |
---|---|
date | Mon, 12 Jul 2010 19:35:11 -0700 |
parents | 5330f39cf637 3ff758c11233 |
children | 6f8500718e6e |
files | |
diffstat | 37 files changed, 1413 insertions(+), 613 deletions(-) [+] |
line wrap: on
line diff
--- a/jdk/src/share/classes/com/sun/beans/finder/InstanceFinder.java Mon Jul 12 19:33:50 2010 -0700 +++ b/jdk/src/share/classes/com/sun/beans/finder/InstanceFinder.java Mon Jul 12 19:35:11 2010 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -39,7 +39,7 @@ private final Class<? extends T> type; private final boolean allow; private final String suffix; - private String[] packages; + private volatile String[] packages; InstanceFinder(Class<? extends T> type, boolean allow, String suffix, String... packages) { this.type = type; @@ -49,9 +49,7 @@ } public String[] getPackages() { - return (this.packages.length > 0) - ? this.packages.clone() - : this.packages; + return this.packages.clone(); } public void setPackages(String... packages) {
--- a/jdk/src/share/classes/com/sun/beans/finder/MethodFinder.java Mon Jul 12 19:33:50 2010 -0700 +++ b/jdk/src/share/classes/com/sun/beans/finder/MethodFinder.java Mon Jul 12 19:35:11 2010 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -118,7 +118,7 @@ * @throws NoSuchMethodException if method is not accessible or is not found * in specified superclass or interface */ - private static Method findAccessibleMethod(Method method) throws NoSuchMethodException { + public static Method findAccessibleMethod(Method method) throws NoSuchMethodException { Class<?> type = method.getDeclaringClass(); if (Modifier.isPublic(type.getModifiers())) { return method;
--- a/jdk/src/share/classes/com/sun/beans/finder/PersistenceDelegateFinder.java Mon Jul 12 19:33:50 2010 -0700 +++ b/jdk/src/share/classes/com/sun/beans/finder/PersistenceDelegateFinder.java Mon Jul 12 19:35:11 2010 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -47,17 +47,22 @@ } public void register(Class<?> type, PersistenceDelegate delegate) { - if (delegate != null) { - this.registry.put(type, delegate); - } - else { - this.registry.remove(type); + synchronized (this.registry) { + if (delegate != null) { + this.registry.put(type, delegate); + } + else { + this.registry.remove(type); + } } } @Override public PersistenceDelegate find(Class<?> type) { - PersistenceDelegate delegate = this.registry.get(type); + PersistenceDelegate delegate; + synchronized (this.registry) { + delegate = this.registry.get(type); + } return (delegate != null) ? delegate : super.find(type); } }
--- a/jdk/src/share/classes/com/sun/beans/finder/PropertyEditorFinder.java Mon Jul 12 19:33:50 2010 -0700 +++ b/jdk/src/share/classes/com/sun/beans/finder/PropertyEditorFinder.java Mon Jul 12 19:35:11 2010 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -64,12 +64,18 @@ } public void register(Class<?> type, Class<?> editor) { - this.registry.put(type, editor); + synchronized (this.registry) { + this.registry.put(type, editor); + } } @Override public PropertyEditor find(Class<?> type) { - PropertyEditor editor = instantiate(this.registry.get(type), null); + Class<?> predefined; + synchronized (this.registry) { + predefined = this.registry.get(type); + } + PropertyEditor editor = instantiate(predefined, null); if (editor == null) { editor = super.find(type); if ((editor == null) && (null != type.getEnumConstants())) {
--- a/jdk/src/share/classes/com/sun/java/swing/plaf/gtk/GTKPainter.java Mon Jul 12 19:33:50 2010 -0700 +++ b/jdk/src/share/classes/com/sun/java/swing/plaf/gtk/GTKPainter.java Mon Jul 12 19:35:11 2010 -0700 @@ -1440,10 +1440,6 @@ } } - public Insets getBorderInsets(Component c) { - return getBorderInsets(c, null); - } - public Insets getBorderInsets(Component c, Insets i) { SynthContext context = getContext(c);
--- a/jdk/src/share/classes/com/sun/java/swing/plaf/motif/MotifFileChooserUI.java Mon Jul 12 19:33:50 2010 -0700 +++ b/jdk/src/share/classes/com/sun/java/swing/plaf/motif/MotifFileChooserUI.java Mon Jul 12 19:35:11 2010 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -271,7 +271,9 @@ } public void uninstallUI(JComponent c) { - getFileChooser().removeAll(); + c.removePropertyChangeListener(filterComboBoxModel); + approveButton.removeActionListener(getApproveSelectionAction()); + filenameTextField.removeActionListener(getApproveSelectionAction()); super.uninstallUI(c); } @@ -515,6 +517,7 @@ public void uninstallComponents(JFileChooser fc) { fc.removeAll(); + bottomPanel = null; if (filterComboBoxModel != null) { fc.removePropertyChangeListener(filterComboBoxModel); }
--- a/jdk/src/share/classes/java/beans/Encoder.java Mon Jul 12 19:33:50 2010 -0700 +++ b/jdk/src/share/classes/java/beans/Encoder.java Mon Jul 12 19:35:11 2010 -0700 @@ -194,13 +194,8 @@ * @see java.beans.BeanInfo#getBeanDescriptor */ public PersistenceDelegate getPersistenceDelegate(Class<?> type) { - synchronized (this.finder) { - PersistenceDelegate pd = this.finder.find(type); - if (pd != null) { - return pd; - } - } - return MetaData.getPersistenceDelegate(type); + PersistenceDelegate pd = this.finder.find(type); + return (pd != null) ? pd : MetaData.getPersistenceDelegate(type); } /** @@ -214,9 +209,7 @@ * @see java.beans.BeanInfo#getBeanDescriptor */ public void setPersistenceDelegate(Class<?> type, PersistenceDelegate delegate) { - synchronized (this.finder) { - this.finder.register(type, delegate); - } + this.finder.register(type, delegate); } /**
--- a/jdk/src/share/classes/java/beans/EventSetDescriptor.java Mon Jul 12 19:33:50 2010 -0700 +++ b/jdk/src/share/classes/java/beans/EventSetDescriptor.java Mon Jul 12 19:35:11 2010 -0700 @@ -27,6 +27,7 @@ import java.lang.ref.Reference; import java.lang.reflect.Method; +import java.lang.reflect.Modifier; /** * An EventSetDescriptor describes a group of events that a given Java @@ -175,10 +176,8 @@ setRemoveListenerMethod(getMethod(sourceClass, removeListenerMethodName, 1)); // Be more forgiving of not finding the getListener method. - Method method = Introspector.findMethod(sourceClass, - getListenerMethodName, 0); - if (method != null) { - setGetListenerMethod(method); + if (getListenerMethodName != null) { + setGetListenerMethod(Introspector.findInstanceMethod(sourceClass, getListenerMethodName)); } } @@ -188,7 +187,7 @@ return null; } Method method = Introspector.findMethod(cls, name, args); - if (method == null) { + if ((method == null) || Modifier.isStatic(method.getModifiers())) { throw new IntrospectionException("Method not found: " + name + " on class " + cls.getName()); }
--- a/jdk/src/share/classes/java/beans/IndexedPropertyDescriptor.java Mon Jul 12 19:33:50 2010 -0700 +++ b/jdk/src/share/classes/java/beans/IndexedPropertyDescriptor.java Mon Jul 12 19:35:11 2010 -0700 @@ -189,16 +189,11 @@ indexedReadMethodName = Introspector.GET_PREFIX + getBaseName(); } } - - Class[] args = { int.class }; - - indexedReadMethod = Introspector.findMethod(cls, indexedReadMethodName, - 1, args); + indexedReadMethod = Introspector.findInstanceMethod(cls, indexedReadMethodName, int.class); if (indexedReadMethod == null) { // no "is" method, so look for a "get" method. indexedReadMethodName = Introspector.GET_PREFIX + getBaseName(); - indexedReadMethod = Introspector.findMethod(cls, indexedReadMethodName, - 1, args); + indexedReadMethod = Introspector.findInstanceMethod(cls, indexedReadMethodName, int.class); } setIndexedReadMethod0(indexedReadMethod); } @@ -270,8 +265,7 @@ if (indexedWriteMethodName == null) { indexedWriteMethodName = Introspector.SET_PREFIX + getBaseName(); } - indexedWriteMethod = Introspector.findMethod(cls, indexedWriteMethodName, - 2, (type == null) ? null : new Class[] { int.class, type }); + indexedWriteMethod = Introspector.findInstanceMethod(cls, indexedWriteMethodName, int.class, type); if (indexedWriteMethod != null) { if (!indexedWriteMethod.getReturnType().equals(void.class)) { indexedWriteMethod = null;
--- a/jdk/src/share/classes/java/beans/Introspector.java Mon Jul 12 19:33:50 2010 -0700 +++ b/jdk/src/share/classes/java/beans/Introspector.java Mon Jul 12 19:35:11 2010 -0700 @@ -28,6 +28,7 @@ import com.sun.beans.WeakCache; import com.sun.beans.finder.BeanInfoFinder; import com.sun.beans.finder.ClassFinder; +import com.sun.beans.finder.MethodFinder; import java.lang.ref.Reference; import java.lang.ref.SoftReference; @@ -157,21 +158,23 @@ if (!ReflectUtil.isPackageAccessible(beanClass)) { return (new Introspector(beanClass, null, USE_ALL_BEANINFO)).getBeanInfo(); } + Map<Class<?>, BeanInfo> beanInfoCache; + BeanInfo beanInfo; synchronized (BEANINFO_CACHE) { - Map<Class<?>, BeanInfo> beanInfoCache = - (Map<Class<?>, BeanInfo>) AppContext.getAppContext().get(BEANINFO_CACHE); - + beanInfoCache = (Map<Class<?>, BeanInfo>) AppContext.getAppContext().get(BEANINFO_CACHE); if (beanInfoCache == null) { beanInfoCache = new WeakHashMap<Class<?>, BeanInfo>(); AppContext.getAppContext().put(BEANINFO_CACHE, beanInfoCache); } - BeanInfo beanInfo = beanInfoCache.get(beanClass); - if (beanInfo == null) { - beanInfo = (new Introspector(beanClass, null, USE_ALL_BEANINFO)).getBeanInfo(); + beanInfo = beanInfoCache.get(beanClass); + } + if (beanInfo == null) { + beanInfo = new Introspector(beanClass, null, USE_ALL_BEANINFO).getBeanInfo(); + synchronized (BEANINFO_CACHE) { beanInfoCache.put(beanClass, beanInfo); } - return beanInfo; } + return beanInfo; } /** @@ -301,10 +304,7 @@ */ public static String[] getBeanInfoSearchPath() { - BeanInfoFinder finder = getFinder(); - synchronized (finder) { - return finder.getPackages(); - } + return getFinder().getPackages(); } /** @@ -328,10 +328,7 @@ if (sm != null) { sm.checkPropertiesAccess(); } - BeanInfoFinder finder = getFinder(); - synchronized (finder) { - finder.setPackages(path); - } + getFinder().setPackages(path); } @@ -453,10 +450,7 @@ * @return Instance of an explicit BeanInfo class or null if one isn't found. */ private static BeanInfo findExplicitBeanInfo(Class beanClass) { - BeanInfoFinder finder = getFinder(); - synchronized (finder) { - return finder.find(beanClass); - } + return getFinder().find(beanClass); } /** @@ -849,8 +843,8 @@ Method read = result.getReadMethod(); if (read == null && write != null) { - read = findMethod(result.getClass0(), - GET_PREFIX + NameGenerator.capitalize(result.getName()), 0); + read = findInstanceMethod(result.getClass0(), + GET_PREFIX + NameGenerator.capitalize(result.getName())); if (read != null) { try { result.setReadMethod(read); @@ -860,9 +854,9 @@ } } if (write == null && read != null) { - write = findMethod(result.getClass0(), - SET_PREFIX + NameGenerator.capitalize(result.getName()), 1, - new Class[] { FeatureDescriptor.getReturnType(result.getClass0(), read) }); + write = findInstanceMethod(result.getClass0(), + SET_PREFIX + NameGenerator.capitalize(result.getName()), + FeatureDescriptor.getReturnType(result.getClass0(), read)); if (write != null) { try { result.setWriteMethod(write); @@ -1286,90 +1280,27 @@ // Package private support methods. //====================================================================== - /** - * Internal support for finding a target methodName with a given - * parameter list on a given class. - */ - private static Method internalFindMethod(Class start, String methodName, - int argCount, Class args[]) { - // For overriden methods we need to find the most derived version. - // So we start with the given class and walk up the superclass chain. - - Method method = null; - - for (Class cl = start; cl != null; cl = cl.getSuperclass()) { - Method methods[] = getPublicDeclaredMethods(cl); - for (int i = 0; i < methods.length; i++) { - method = methods[i]; - if (method == null) { - continue; + static Method findMethod(Class<?> type, String name, int args) { + for (Method method : type.getMethods()) { + if (method.getName().equals(name) && (args == method.getParameterTypes().length)) { + try { + return MethodFinder.findAccessibleMethod(method); } - - // make sure method signature matches. - Class params[] = FeatureDescriptor.getParameterTypes(start, method); - if (method.getName().equals(methodName) && - params.length == argCount) { - if (args != null) { - boolean different = false; - if (argCount > 0) { - for (int j = 0; j < argCount; j++) { - if (params[j] != args[j]) { - different = true; - continue; - } - } - if (different) { - continue; - } - } - } - return method; + catch (NoSuchMethodException exception) { + // continue search for a method with the specified count of parameters } } } - method = null; - - // Now check any inherited interfaces. This is necessary both when - // the argument class is itself an interface, and when the argument - // class is an abstract class. - Class ifcs[] = start.getInterfaces(); - for (int i = 0 ; i < ifcs.length; i++) { - // Note: The original implementation had both methods calling - // the 3 arg method. This is preserved but perhaps it should - // pass the args array instead of null. - method = internalFindMethod(ifcs[i], methodName, argCount, null); - if (method != null) { - break; - } - } - return method; + return null; } - /** - * Find a target methodName on a given class. - */ - static Method findMethod(Class cls, String methodName, int argCount) { - return findMethod(cls, methodName, argCount, null); - } - - /** - * Find a target methodName with specific parameter list on a given class. - * <p> - * Used in the contructors of the EventSetDescriptor, - * PropertyDescriptor and the IndexedPropertyDescriptor. - * <p> - * @param cls The Class object on which to retrieve the method. - * @param methodName Name of the method. - * @param argCount Number of arguments for the desired method. - * @param args Array of argument types for the method. - * @return the method or null if not found - */ - static Method findMethod(Class cls, String methodName, int argCount, - Class args[]) { - if (methodName == null) { + static Method findInstanceMethod(Class<?> type, String name, Class<?>... args) { + try { + return MethodFinder.findInstanceMethod(type, name, args); + } + catch (NoSuchMethodException exception) { return null; } - return internalFindMethod(cls, methodName, argCount, args); } /**
--- a/jdk/src/share/classes/java/beans/MethodDescriptor.java Mon Jul 12 19:33:50 2010 -0700 +++ b/jdk/src/share/classes/java/beans/MethodDescriptor.java Mon Jul 12 19:35:11 2010 -0700 @@ -82,21 +82,21 @@ Method method = getMethod0(); if (method == null) { Class cls = getClass0(); - if (cls != null) { + String name = getName(); + if ((cls != null) && (name != null)) { Class[] params = getParams(); if (params == null) { for (int i = 0; i < 3; i++) { // Find methods for up to 2 params. We are guessing here. // This block should never execute unless the classloader // that loaded the argument classes disappears. - method = Introspector.findMethod(cls, getName(), i, null); + method = Introspector.findMethod(cls, name, i); if (method != null) { break; } } } else { - method = Introspector.findMethod(cls, getName(), - params.length, params); + method = Statement.getMethod(cls, name, params); } setMethod(method); }
--- a/jdk/src/share/classes/java/beans/PropertyDescriptor.java Mon Jul 12 19:33:50 2010 -0700 +++ b/jdk/src/share/classes/java/beans/PropertyDescriptor.java Mon Jul 12 19:35:11 2010 -0700 @@ -112,9 +112,7 @@ // If this class or one of its base classes allow PropertyChangeListener, // then we assume that any properties we discover are "bound". // See Introspector.getTargetPropertyInfo() method. - String name = "addPropertyChangeListener"; - Class[] args = {PropertyChangeListener.class}; - this.bound = (null != Introspector.findMethod(beanClass, name, args.length, args)); + this.bound = null != Introspector.findInstanceMethod(beanClass, "addPropertyChangeListener", PropertyChangeListener.class); } /** @@ -225,10 +223,10 @@ // property type is. For booleans, there can be "is" and "get" // methods. If an "is" method exists, this is the official // reader method so look for this one first. - readMethod = Introspector.findMethod(cls, readMethodName, 0); + readMethod = Introspector.findInstanceMethod(cls, readMethodName); if (readMethod == null) { readMethodName = Introspector.GET_PREFIX + getBaseName(); - readMethod = Introspector.findMethod(cls, readMethodName, 0); + readMethod = Introspector.findInstanceMethod(cls, readMethodName); } try { setReadMethod(readMethod); @@ -293,8 +291,7 @@ writeMethodName = Introspector.SET_PREFIX + getBaseName(); } - writeMethod = Introspector.findMethod(cls, writeMethodName, 1, - (type == null) ? null : new Class[] { type }); + writeMethod = Introspector.findInstanceMethod(cls, writeMethodName, type); if (writeMethod != null) { if (!writeMethod.getReturnType().equals(void.class)) { writeMethod = null;
--- a/jdk/src/share/classes/java/beans/PropertyEditorManager.java Mon Jul 12 19:33:50 2010 -0700 +++ b/jdk/src/share/classes/java/beans/PropertyEditorManager.java Mon Jul 12 19:35:11 2010 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2009, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -81,10 +81,7 @@ if (sm != null) { sm.checkPropertiesAccess(); } - PropertyEditorFinder finder = getFinder(); - synchronized (finder) { - finder.register(targetType, editorClass); - } + getFinder().register(targetType, editorClass); } /** @@ -95,10 +92,7 @@ * The result is null if no suitable editor can be found. */ public static PropertyEditor findEditor(Class<?> targetType) { - PropertyEditorFinder finder = getFinder(); - synchronized (finder) { - return finder.find(targetType); - } + return getFinder().find(targetType); } /** @@ -110,10 +104,7 @@ * e.g. Sun implementation initially sets to {"sun.beans.editors"}. */ public static String[] getEditorSearchPath() { - PropertyEditorFinder finder = getFinder(); - synchronized (finder) { - return finder.getPackages(); - } + return getFinder().getPackages(); } /** @@ -134,10 +125,7 @@ if (sm != null) { sm.checkPropertiesAccess(); } - PropertyEditorFinder finder = getFinder(); - synchronized (finder) { - finder.setPackages(path); - } + getFinder().setPackages(path); } private static PropertyEditorFinder getFinder() {
--- a/jdk/src/share/classes/javax/swing/JSplitPane.java Mon Jul 12 19:33:50 2010 -0700 +++ b/jdk/src/share/classes/javax/swing/JSplitPane.java Mon Jul 12 19:35:11 2010 -0700 @@ -242,19 +242,19 @@ /** * Creates a new <code>JSplitPane</code> configured to arrange the child - * components side-by-side horizontally with no continuous - * layout, using two buttons for the components. + * components side-by-side horizontally, using two buttons for the components. */ public JSplitPane() { - this(JSplitPane.HORIZONTAL_SPLIT, false, - new JButton(UIManager.getString("SplitPane.leftButtonText")), - new JButton(UIManager.getString("SplitPane.rightButtonText"))); + this(JSplitPane.HORIZONTAL_SPLIT, + UIManager.getBoolean("SplitPane.continuousLayout"), + new JButton(UIManager.getString("SplitPane.leftButtonText")), + new JButton(UIManager.getString("SplitPane.rightButtonText"))); } /** * Creates a new <code>JSplitPane</code> configured with the - * specified orientation and no continuous layout. + * specified orientation. * * @param newOrientation <code>JSplitPane.HORIZONTAL_SPLIT</code> or * <code>JSplitPane.VERTICAL_SPLIT</code> @@ -263,7 +263,8 @@ */ @ConstructorProperties({"orientation"}) public JSplitPane(int newOrientation) { - this(newOrientation, false); + this(newOrientation, + UIManager.getBoolean("SplitPane.continuousLayout")); } @@ -287,9 +288,7 @@ /** * Creates a new <code>JSplitPane</code> with the specified - * orientation and - * with the specified components that do not do continuous - * redrawing. + * orientation and the specified components. * * @param newOrientation <code>JSplitPane.HORIZONTAL_SPLIT</code> or * <code>JSplitPane.VERTICAL_SPLIT</code> @@ -307,7 +306,9 @@ public JSplitPane(int newOrientation, Component newLeftComponent, Component newRightComponent){ - this(newOrientation, false, newLeftComponent, newRightComponent); + this(newOrientation, + UIManager.getBoolean("SplitPane.continuousLayout"), + newLeftComponent, newRightComponent); }
--- a/jdk/src/share/classes/javax/swing/JTable.java Mon Jul 12 19:33:50 2010 -0700 +++ b/jdk/src/share/classes/javax/swing/JTable.java Mon Jul 12 19:35:11 2010 -0700 @@ -1048,7 +1048,7 @@ /** * Returns the horizontal and vertical space between cells. - * The default spacing is (1, 1), which provides room to draw the grid. + * The default spacing is look and feel dependent. * * @return the horizontal and vertical spacing between cells * @see #setIntercellSpacing @@ -1155,7 +1155,7 @@ /** * Returns true if the table draws horizontal lines between cells, false if it - * doesn't. The default is true. + * doesn't. The default value is look and feel dependent. * * @return true if the table draws horizontal lines between cells, false if it * doesn't @@ -1167,7 +1167,7 @@ /** * Returns true if the table draws vertical lines between cells, false if it - * doesn't. The default is true. + * doesn't. The default value is look and feel dependent. * * @return true if the table draws vertical lines between cells, false if it * doesn't
--- a/jdk/src/share/classes/javax/swing/JTree.java Mon Jul 12 19:33:50 2010 -0700 +++ b/jdk/src/share/classes/javax/swing/JTree.java Mon Jul 12 19:35:11 2010 -0700 @@ -1986,20 +1986,17 @@ * true if all nodes in the path are expanded */ public boolean isExpanded(TreePath path) { + if(path == null) return false; - - // Is this node expanded? - Boolean value = expandedState.get(path); - - if(value == null || !value.booleanValue()) - return false; - - // It is, make sure its parent is also expanded. - TreePath parentPath = path.getParentPath(); - - if(parentPath != null) - return isExpanded(parentPath); + Object value; + + do{ + value = expandedState.get(path); + if(value == null || !((Boolean)value).booleanValue()) + return false; + } while( (path=path.getParentPath())!=null ); + return true; }
--- a/jdk/src/share/classes/javax/swing/border/TitledBorder.java Mon Jul 12 19:33:50 2010 -0700 +++ b/jdk/src/share/classes/javax/swing/border/TitledBorder.java Mon Jul 12 19:35:11 2010 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -24,22 +24,20 @@ */ package javax.swing.border; -import sun.swing.SwingUtilities2; - +import java.awt.Color; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.Font; import java.awt.Graphics; +import java.awt.Graphics2D; import java.awt.Insets; import java.awt.Rectangle; -import java.awt.Color; -import java.awt.Font; -import java.awt.FontMetrics; -import java.awt.Point; -import java.awt.Toolkit; -import java.awt.Component; -import java.awt.Dimension; +import java.awt.geom.Path2D; import java.beans.ConstructorProperties; - import javax.swing.JComponent; +import javax.swing.JLabel; import javax.swing.UIManager; +import javax.swing.plaf.basic.BasicHTML; /** * A class which implements an arbitrary border @@ -73,40 +71,40 @@ { protected String title; protected Border border; - protected int titlePosition; - protected int titleJustification; - protected Font titleFont; - protected Color titleColor; + protected int titlePosition; + protected int titleJustification; + protected Font titleFont; + protected Color titleColor; - private Point textLoc = new Point(); + private final JLabel label; /** * Use the default vertical orientation for the title text. */ static public final int DEFAULT_POSITION = 0; /** Position the title above the border's top line. */ - static public final int ABOVE_TOP = 1; + static public final int ABOVE_TOP = 1; /** Position the title in the middle of the border's top line. */ - static public final int TOP = 2; + static public final int TOP = 2; /** Position the title below the border's top line. */ - static public final int BELOW_TOP = 3; + static public final int BELOW_TOP = 3; /** Position the title above the border's bottom line. */ - static public final int ABOVE_BOTTOM = 4; + static public final int ABOVE_BOTTOM = 4; /** Position the title in the middle of the border's bottom line. */ - static public final int BOTTOM = 5; + static public final int BOTTOM = 5; /** Position the title below the border's bottom line. */ - static public final int BELOW_BOTTOM = 6; + static public final int BELOW_BOTTOM = 6; /** * Use the default justification for the title text. */ static public final int DEFAULT_JUSTIFICATION = 0; /** Position title text at the left side of the border line. */ - static public final int LEFT = 1; + static public final int LEFT = 1; /** Position title text in the center of the border line. */ - static public final int CENTER = 2; + static public final int CENTER = 2; /** Position title text at the right side of the border line. */ - static public final int RIGHT = 3; + static public final int RIGHT = 3; /** Position title text at the left side of the border line * for left to right orientation, at the right side of the * border line for right to left orientation. @@ -132,7 +130,7 @@ * * @param title the title the border should display */ - public TitledBorder(String title) { + public TitledBorder(String title) { this(null, title, LEADING, DEFAULT_POSITION, null, null); } @@ -142,7 +140,7 @@ * * @param border the border */ - public TitledBorder(Border border) { + public TitledBorder(Border border) { this(border, "", LEADING, DEFAULT_POSITION, null, null); } @@ -167,9 +165,9 @@ * @param titlePosition the position for the title */ public TitledBorder(Border border, - String title, - int titleJustification, - int titlePosition) { + String title, + int titleJustification, + int titlePosition) { this(border, title, titleJustification, titlePosition, null, null); } @@ -185,10 +183,10 @@ * @param titleFont the font for rendering the title */ public TitledBorder(Border border, - String title, - int titleJustification, - int titlePosition, - Font titleFont) { + String title, + int titleJustification, + int titlePosition, + Font titleFont) { this(border, title, titleJustification, titlePosition, titleFont, null); } @@ -207,11 +205,11 @@ */ @ConstructorProperties({"border", "title", "titleJustification", "titlePosition", "titleFont", "titleColor"}) public TitledBorder(Border border, - String title, - int titleJustification, - int titlePosition, - Font titleFont, - Color titleColor) { + String title, + int titleJustification, + int titlePosition, + Font titleFont, + Color titleColor) { this.title = title; this.border = border; this.titleFont = titleFont; @@ -219,6 +217,10 @@ setTitleJustification(titleJustification); setTitlePosition(titlePosition); + + this.label = new JLabel(); + this.label.setOpaque(false); + this.label.putClientProperty(BasicHTML.propertyKey, null); } /** @@ -232,178 +234,111 @@ * @param height the height of the painted border */ public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { + Border border = getBorderUI(); + String title = getTitle(); + if ((title != null) && !title.isEmpty()) { + int edge = (border instanceof TitledBorder) ? 0 : EDGE_SPACING; + JLabel label = getLabel(c); + Dimension size = label.getPreferredSize(); + Insets insets = (border != null) + ? border.getBorderInsets(c) + : new Insets(0, 0, 0, 0); - Border border = getBorder(); + int borderX = x + edge; + int borderY = y + edge; + int borderW = width - edge - edge; + int borderH = height - edge - edge; - if (getTitle() == null || getTitle().equals("")) { + int labelY = y; + int labelH = size.height; + int position = getPosition(); + switch (position) { + case ABOVE_TOP: + insets.left = 0; + insets.right = 0; + borderY += labelH - edge; + borderH -= labelH - edge; + break; + case TOP: + insets.top = edge + insets.top/2 - labelH/2; + if (insets.top < edge) { + borderY -= insets.top; + borderH += insets.top; + } + else { + labelY += insets.top; + } + break; + case BELOW_TOP: + labelY += insets.top + edge; + break; + case ABOVE_BOTTOM: + labelY += height - labelH - insets.bottom - edge; + break; + case BOTTOM: + labelY += height - labelH; + insets.bottom = edge + (insets.bottom - labelH) / 2; + if (insets.bottom < edge) { + borderH += insets.bottom; + } + else { + labelY -= insets.bottom; + } + break; + case BELOW_BOTTOM: + insets.left = 0; + insets.right = 0; + labelY += height - labelH; + borderH -= labelH - edge; + break; + } + insets.left += edge + TEXT_INSET_H; + insets.right += edge + TEXT_INSET_H; + + int labelX = x; + int labelW = width - insets.left - insets.right; + if (labelW > size.width) { + labelW = size.width; + } + switch (getJustification(c)) { + case LEFT: + labelX += insets.left; + break; + case RIGHT: + labelX += width - insets.right - labelW; + break; + case CENTER: + labelX += (width - labelW) / 2; + break; + } + if (border != null) { - border.paintBorder(c, g, x, y, width, height); + if ((position != TOP) && (position != BOTTOM)) { + border.paintBorder(c, g, borderX, borderY, borderW, borderH); + } + else { + Graphics g2 = g.create(); + if (g2 instanceof Graphics2D) { + Graphics2D g2d = (Graphics2D) g2; + Path2D path = new Path2D.Float(); + path.append(new Rectangle(borderX, borderY, borderW, labelY - borderY), false); + path.append(new Rectangle(borderX, labelY, labelX - borderX - TEXT_SPACING, labelH), false); + path.append(new Rectangle(labelX + labelW + TEXT_SPACING, labelY, borderX - labelX + borderW - labelW - TEXT_SPACING, labelH), false); + path.append(new Rectangle(borderX, labelY + labelH, borderW, borderY - labelY + borderH - labelH), false); + g2d.clip(path); + } + border.paintBorder(c, g2, borderX, borderY, borderW, borderH); + g2.dispose(); + } } - return; + g.translate(labelX, labelY); + label.setSize(labelW, labelH); + label.paint(g); + g.translate(-labelX, -labelY); } - - Rectangle grooveRect = new Rectangle(x + EDGE_SPACING, y + EDGE_SPACING, - width - (EDGE_SPACING * 2), - height - (EDGE_SPACING * 2)); - Font font = g.getFont(); - Color color = g.getColor(); - - g.setFont(getFont(c)); - - JComponent jc = (c instanceof JComponent) ? (JComponent)c : null; - FontMetrics fm = SwingUtilities2.getFontMetrics(jc, g); - int fontHeight = fm.getHeight(); - int descent = fm.getDescent(); - int ascent = fm.getAscent(); - int diff; - int stringWidth = SwingUtilities2.stringWidth(jc, fm, - getTitle()); - Insets insets; - - if (border != null) { - insets = border.getBorderInsets(c); - } else { - insets = new Insets(0, 0, 0, 0); + else if (border != null) { + border.paintBorder(c, g, x, y, width, height); } - - int titlePos = getTitlePosition(); - switch (titlePos) { - case ABOVE_TOP: - diff = ascent + descent + (Math.max(EDGE_SPACING, - TEXT_SPACING*2) - EDGE_SPACING); - grooveRect.y += diff; - grooveRect.height -= diff; - textLoc.y = grooveRect.y - (descent + TEXT_SPACING); - break; - case TOP: - case DEFAULT_POSITION: - diff = Math.max(0, ((ascent/2) + TEXT_SPACING) - EDGE_SPACING); - grooveRect.y += diff; - grooveRect.height -= diff; - textLoc.y = (grooveRect.y - descent) + - (insets.top + ascent + descent)/2; - break; - case BELOW_TOP: - textLoc.y = grooveRect.y + insets.top + ascent + TEXT_SPACING; - break; - case ABOVE_BOTTOM: - textLoc.y = (grooveRect.y + grooveRect.height) - - (insets.bottom + descent + TEXT_SPACING); - break; - case BOTTOM: - grooveRect.height -= fontHeight/2; - textLoc.y = ((grooveRect.y + grooveRect.height) - descent) + - ((ascent + descent) - insets.bottom)/2; - break; - case BELOW_BOTTOM: - grooveRect.height -= fontHeight; - textLoc.y = grooveRect.y + grooveRect.height + ascent + - TEXT_SPACING; - break; - } - - int justification = getTitleJustification(); - if(isLeftToRight(c)) { - if(justification==LEADING || - justification==DEFAULT_JUSTIFICATION) { - justification = LEFT; - } - else if(justification==TRAILING) { - justification = RIGHT; - } - } - else { - if(justification==LEADING || - justification==DEFAULT_JUSTIFICATION) { - justification = RIGHT; - } - else if(justification==TRAILING) { - justification = LEFT; - } - } - - switch (justification) { - case LEFT: - textLoc.x = grooveRect.x + TEXT_INSET_H + insets.left; - break; - case RIGHT: - textLoc.x = (grooveRect.x + grooveRect.width) - - (stringWidth + TEXT_INSET_H + insets.right); - break; - case CENTER: - textLoc.x = grooveRect.x + - ((grooveRect.width - stringWidth) / 2); - break; - } - - // If title is positioned in middle of border AND its fontsize - // is greater than the border's thickness, we'll need to paint - // the border in sections to leave space for the component's background - // to show through the title. - // - if (border != null) { - if (((titlePos == TOP || titlePos == DEFAULT_POSITION) && - (grooveRect.y > textLoc.y - ascent)) || - (titlePos == BOTTOM && - (grooveRect.y + grooveRect.height < textLoc.y + descent))) { - - Rectangle clipRect = new Rectangle(); - - // save original clip - Rectangle saveClip = g.getClipBounds(); - - // paint strip left of text - clipRect.setBounds(saveClip); - if (computeIntersection(clipRect, x, y, textLoc.x-1-x, height)) { - g.setClip(clipRect); - border.paintBorder(c, g, grooveRect.x, grooveRect.y, - grooveRect.width, grooveRect.height); - } - - // paint strip right of text - clipRect.setBounds(saveClip); - if (computeIntersection(clipRect, textLoc.x+stringWidth+1, y, - x+width-(textLoc.x+stringWidth+1), height)) { - g.setClip(clipRect); - border.paintBorder(c, g, grooveRect.x, grooveRect.y, - grooveRect.width, grooveRect.height); - } - - if (titlePos == TOP || titlePos == DEFAULT_POSITION) { - // paint strip below text - clipRect.setBounds(saveClip); - if (computeIntersection(clipRect, textLoc.x-1, textLoc.y+descent, - stringWidth+2, y+height-textLoc.y-descent)) { - g.setClip(clipRect); - border.paintBorder(c, g, grooveRect.x, grooveRect.y, - grooveRect.width, grooveRect.height); - } - - } else { // titlePos == BOTTOM - // paint strip above text - clipRect.setBounds(saveClip); - if (computeIntersection(clipRect, textLoc.x-1, y, - stringWidth+2, textLoc.y - ascent - y)) { - g.setClip(clipRect); - border.paintBorder(c, g, grooveRect.x, grooveRect.y, - grooveRect.width, grooveRect.height); - } - } - - // restore clip - g.setClip(saveClip); - - } else { - border.paintBorder(c, g, grooveRect.x, grooveRect.y, - grooveRect.width, grooveRect.height); - } - } - - g.setColor(getTitleColor()); - SwingUtilities2.drawString(jc, g, getTitle(), textLoc.x, textLoc.y); - - g.setFont(font); - g.setColor(color); } /** @@ -412,69 +347,54 @@ * @param insets the object to be reinitialized */ public Insets getBorderInsets(Component c, Insets insets) { - FontMetrics fm; - int descent = 0; - int ascent = 16; - int height = 16; + Border border = getBorderUI(); + if (border == null) { + insets.set(0, 0, 0, 0); + } + else if (border instanceof AbstractBorder) { + AbstractBorder ab = (AbstractBorder) border; + insets = ab.getBorderInsets(c, insets); + } + else { + Insets i = border.getBorderInsets(c); + insets.set(i.top, i.left, i.bottom, i.right); + } + String title = getTitle(); + if ((title != null) && !title.isEmpty()) { + int edge = (border instanceof TitledBorder) ? 0 : EDGE_SPACING; + JLabel label = getLabel(c); + Dimension size = label.getPreferredSize(); - Border border = getBorder(); - if (border != null) { - if (border instanceof AbstractBorder) { - ((AbstractBorder)border).getBorderInsets(c, insets); - } else { - // Can't reuse border insets because the Border interface - // can't be enhanced. - Insets i = border.getBorderInsets(c); - insets.top = i.top; - insets.right = i.right; - insets.bottom = i.bottom; - insets.left = i.left; + switch (getPosition()) { + case ABOVE_TOP: + insets.top += size.height - edge; + break; + case TOP: { + if (insets.top < size.height) { + insets.top = size.height - edge; + } + break; + } + case BELOW_TOP: + insets.top += size.height; + break; + case ABOVE_BOTTOM: + insets.bottom += size.height; + break; + case BOTTOM: { + if (insets.bottom < size.height) { + insets.bottom = size.height - edge; + } + break; + } + case BELOW_BOTTOM: + insets.bottom += size.height - edge; + break; } - } else { - insets.left = insets.top = insets.right = insets.bottom = 0; - } - - insets.left += EDGE_SPACING + TEXT_SPACING; - insets.right += EDGE_SPACING + TEXT_SPACING; - insets.top += EDGE_SPACING + TEXT_SPACING; - insets.bottom += EDGE_SPACING + TEXT_SPACING; - - if(c == null || getTitle() == null || getTitle().equals("")) { - return insets; - } - - Font font = getFont(c); - - fm = c.getFontMetrics(font); - - if(fm != null) { - descent = fm.getDescent(); - ascent = fm.getAscent(); - height = fm.getHeight(); - } - - switch (getTitlePosition()) { - case ABOVE_TOP: - insets.top += ascent + descent - + (Math.max(EDGE_SPACING, TEXT_SPACING*2) - - EDGE_SPACING); - break; - case TOP: - case DEFAULT_POSITION: - insets.top += ascent + descent; - break; - case BELOW_TOP: - insets.top += ascent + descent + TEXT_SPACING; - break; - case ABOVE_BOTTOM: - insets.bottom += ascent + descent + TEXT_SPACING; - break; - case BOTTOM: - insets.bottom += ascent + descent; - break; - case BELOW_BOTTOM: - insets.bottom += height; - break; + insets.top += edge + TEXT_SPACING; + insets.left += edge + TEXT_SPACING; + insets.right += edge + TEXT_SPACING; + insets.bottom += edge + TEXT_SPACING; } return insets; } @@ -492,41 +412,14 @@ /** * Returns the border of the titled border. */ - public Border getBorder() { - Border b = border; - if (b == null) - b = UIManager.getBorder("TitledBorder.border"); - return b; + public Border getBorder() { + return border; } /** * Returns the title-position of the titled border. */ public int getTitlePosition() { - if (titlePosition == DEFAULT_POSITION) { - Object value = UIManager.get("TitledBorder.position"); - if (value instanceof String) { - String s = (String)value; - if ("ABOVE_TOP".equalsIgnoreCase(s)) { - return ABOVE_TOP; - } else if ("TOP".equalsIgnoreCase(s)) { - return TOP; - } else if ("BELOW_TOP".equalsIgnoreCase(s)) { - return BELOW_TOP; - } else if ("ABOVE_BOTTOM".equalsIgnoreCase(s)) { - return ABOVE_BOTTOM; - } else if ("BOTTOM".equalsIgnoreCase(s)) { - return BOTTOM; - } else if ("BELOW_BOTTOM".equalsIgnoreCase(s)) { - return BELOW_BOTTOM; - } - } else if (value instanceof Integer) { - int i = (Integer)value; - if (i >= 0 && i <= 6) { - return i; - } - } - } return titlePosition; } @@ -539,20 +432,14 @@ * Returns the title-font of the titled border. */ public Font getTitleFont() { - Font f = titleFont; - if (f == null) - f = UIManager.getFont("TitledBorder.font"); - return f; + return titleFont; } /** * Returns the title-color of the titled border. */ public Color getTitleColor() { - Color c = titleColor; - if (c == null) - c = UIManager.getColor("TitledBorder.titleColor"); - return c; + return titleColor; } @@ -576,18 +463,18 @@ */ public void setTitlePosition(int titlePosition) { switch (titlePosition) { - case ABOVE_TOP: - case TOP: - case BELOW_TOP: - case ABOVE_BOTTOM: - case BOTTOM: - case BELOW_BOTTOM: - case DEFAULT_POSITION: + case ABOVE_TOP: + case TOP: + case BELOW_TOP: + case ABOVE_BOTTOM: + case BOTTOM: + case BELOW_BOTTOM: + case DEFAULT_POSITION: this.titlePosition = titlePosition; break; - default: - throw new IllegalArgumentException(titlePosition + - " is not a valid title position."); + default: + throw new IllegalArgumentException(titlePosition + + " is not a valid title position."); } } @@ -624,7 +511,7 @@ * @param titleColor the color for the border title */ public void setTitleColor(Color titleColor) { - this.titleColor = titleColor; + this.titleColor = titleColor; } /** @@ -636,22 +523,18 @@ Insets insets = getBorderInsets(c); Dimension minSize = new Dimension(insets.right+insets.left, insets.top+insets.bottom); - Font font = getFont(c); - FontMetrics fm = c.getFontMetrics(font); - JComponent jc = (c instanceof JComponent) ? (JComponent)c : null; - switch (getTitlePosition()) { - case ABOVE_TOP: - case BELOW_BOTTOM: - minSize.width = Math.max(SwingUtilities2.stringWidth(jc, fm, - getTitle()), minSize.width); - break; - case BELOW_TOP: - case ABOVE_BOTTOM: - case TOP: - case BOTTOM: - case DEFAULT_POSITION: - default: - minSize.width += SwingUtilities2.stringWidth(jc, fm, getTitle()); + String title = getTitle(); + if ((title != null) && !title.isEmpty()) { + JLabel label = getLabel(c); + Dimension size = label.getPreferredSize(); + + int position = getPosition(); + if ((position != ABOVE_TOP) && (position != BELOW_BOTTOM)) { + minSize.width += size.width; + } + else if (minSize.width < size.width) { + minSize.width += size.width; + } } return minSize; } @@ -674,48 +557,36 @@ if (height < 0) { throw new IllegalArgumentException("Height must be >= 0"); } + Border border = getBorderUI(); String title = getTitle(); - if (title != null && !"".equals(title)) { - Font font = getFont(c); - Border border2 = getBorder(); - Insets borderInsets; - if (border2 != null) { - borderInsets = border2.getBorderInsets(c); - } - else { - borderInsets = new Insets(0, 0, 0, 0); - } - FontMetrics fm = c.getFontMetrics(font); - int fontHeight = fm.getHeight(); - int descent = fm.getDescent(); - int ascent = fm.getAscent(); - int y = EDGE_SPACING; - int h = height - EDGE_SPACING * 2; - int diff; - switch (getTitlePosition()) { - case ABOVE_TOP: - diff = ascent + descent + (Math.max(EDGE_SPACING, - TEXT_SPACING * 2) - - EDGE_SPACING); - return y + diff - (descent + TEXT_SPACING); - case TOP: - case DEFAULT_POSITION: - diff = Math.max(0, ((ascent/2) + TEXT_SPACING) - - EDGE_SPACING); - return (y + diff - descent) + - (borderInsets.top + ascent + descent)/2; - case BELOW_TOP: - return y + borderInsets.top + ascent + TEXT_SPACING; - case ABOVE_BOTTOM: - return (y + h) - (borderInsets.bottom + descent + - TEXT_SPACING); - case BOTTOM: - h -= fontHeight / 2; - return ((y + h) - descent) + - ((ascent + descent) - borderInsets.bottom)/2; - case BELOW_BOTTOM: - h -= fontHeight; - return y + h + ascent + TEXT_SPACING; + if ((title != null) && !title.isEmpty()) { + int edge = (border instanceof TitledBorder) ? 0 : EDGE_SPACING; + JLabel label = getLabel(c); + Dimension size = label.getPreferredSize(); + Insets insets = (border != null) + ? border.getBorderInsets(c) + : new Insets(0, 0, 0, 0); + + int baseline = label.getBaseline(size.width, size.height); + switch (getPosition()) { + case ABOVE_TOP: + return baseline; + case TOP: + insets.top = edge + (insets.top - size.height) / 2; + return (insets.top < edge) + ? baseline + : baseline + insets.top; + case BELOW_TOP: + return baseline + insets.top + edge; + case ABOVE_BOTTOM: + return baseline + height - size.height - insets.bottom - edge; + case BOTTOM: + insets.bottom = edge + (insets.bottom - size.height) / 2; + return (insets.bottom < edge) + ? baseline + height - size.height + : baseline + height - size.height + insets.bottom; + case BELOW_BOTTOM: + return baseline + height - size.height; } } return -1; @@ -732,44 +603,111 @@ public Component.BaselineResizeBehavior getBaselineResizeBehavior( Component c) { super.getBaselineResizeBehavior(c); - switch(getTitlePosition()) { - case TitledBorder.ABOVE_TOP: - case TitledBorder.TOP: - case TitledBorder.DEFAULT_POSITION: - case TitledBorder.BELOW_TOP: - return Component.BaselineResizeBehavior.CONSTANT_ASCENT; - case TitledBorder.ABOVE_BOTTOM: - case TitledBorder.BOTTOM: - case TitledBorder.BELOW_BOTTOM: - return JComponent.BaselineResizeBehavior.CONSTANT_DESCENT; + switch (getPosition()) { + case TitledBorder.ABOVE_TOP: + case TitledBorder.TOP: + case TitledBorder.BELOW_TOP: + return Component.BaselineResizeBehavior.CONSTANT_ASCENT; + case TitledBorder.ABOVE_BOTTOM: + case TitledBorder.BOTTOM: + case TitledBorder.BELOW_BOTTOM: + return JComponent.BaselineResizeBehavior.CONSTANT_DESCENT; } return Component.BaselineResizeBehavior.OTHER; } + private Border getBorderUI() { + Border border = getBorder(); + return border != null + ? border + : UIManager.getBorder("TitledBorder.border"); + } + + private int getPosition() { + int position = getTitlePosition(); + if (position != DEFAULT_POSITION) { + return position; + } + Object value = UIManager.get("TitledBorder.position"); + if (value instanceof Integer) { + int i = (Integer) value; + if ((0 < i) && (i <= 6)) { + return i; + } + } + else if (value instanceof String) { + String s = (String) value; + if (s.equalsIgnoreCase("ABOVE_TOP")) { + return ABOVE_TOP; + } + if (s.equalsIgnoreCase("TOP")) { + return TOP; + } + if (s.equalsIgnoreCase("BELOW_TOP")) { + return BELOW_TOP; + } + if (s.equalsIgnoreCase("ABOVE_BOTTOM")) { + return ABOVE_BOTTOM; + } + if (s.equalsIgnoreCase("BOTTOM")) { + return BOTTOM; + } + if (s.equalsIgnoreCase("BELOW_BOTTOM")) { + return BELOW_BOTTOM; + } + } + return TOP; + } + + private int getJustification(Component c) { + int justification = getTitleJustification(); + if ((justification == LEADING) || (justification == DEFAULT_JUSTIFICATION)) { + return c.getComponentOrientation().isLeftToRight() ? LEFT : RIGHT; + } + if (justification == TRAILING) { + return c.getComponentOrientation().isLeftToRight() ? RIGHT : LEFT; + } + return justification; + } + protected Font getFont(Component c) { - Font font; - if ((font = getTitleFont()) != null) { + Font font = getTitleFont(); + if (font != null) { return font; - } else if (c != null && (font = c.getFont()) != null) { + } + font = UIManager.getFont("TitledBorder.font"); + if (font != null) { return font; } + if (c != null) { + font = c.getFont(); + if (font != null) { + return font; + } + } return new Font(Font.DIALOG, Font.PLAIN, 12); } - private static boolean computeIntersection(Rectangle dest, - int rx, int ry, int rw, int rh) { - int x1 = Math.max(rx, dest.x); - int x2 = Math.min(rx + rw, dest.x + dest.width); - int y1 = Math.max(ry, dest.y); - int y2 = Math.min(ry + rh, dest.y + dest.height); - dest.x = x1; - dest.y = y1; - dest.width = x2 - x1; - dest.height = y2 - y1; + private Color getColor(Component c) { + Color color = getTitleColor(); + if (color != null) { + return color; + } + color = UIManager.getColor("TitledBorder.titleColor"); + if (color != null) { + return color; + } + return (c != null) + ? c.getForeground() + : null; + } - if (dest.width <= 0 || dest.height <= 0) { - return false; - } - return true; + private JLabel getLabel(Component c) { + this.label.setText(getTitle()); + this.label.setFont(getFont(c)); + this.label.setForeground(getColor(c)); + this.label.setComponentOrientation(c.getComponentOrientation()); + this.label.setEnabled(c.isEnabled()); + return this.label; } }
--- a/jdk/src/share/classes/javax/swing/plaf/basic/BasicButtonListener.java Mon Jul 12 19:33:50 2010 -0700 +++ b/jdk/src/share/classes/javax/swing/plaf/basic/BasicButtonListener.java Mon Jul 12 19:35:11 2010 -0700 @@ -195,9 +195,8 @@ } ButtonModel model = b.getModel(); + model.setPressed(false); model.setArmed(false); - model.setPressed(false); - b.repaint(); }
--- a/jdk/src/share/classes/javax/swing/plaf/basic/BasicTableHeaderUI.java Mon Jul 12 19:33:50 2010 -0700 +++ b/jdk/src/share/classes/javax/swing/plaf/basic/BasicTableHeaderUI.java Mon Jul 12 19:35:11 2010 -0700 @@ -876,7 +876,7 @@ String name = getName(); if (TOGGLE_SORT_ORDER == name) { JTable table = th.getTable(); - RowSorter sorter = table.getRowSorter(); + RowSorter sorter = table == null ? null : table.getRowSorter(); if (sorter != null) { int columnIndex = ui.getSelectedColumnIndex(); columnIndex = table.convertColumnIndexToModel(
--- a/jdk/src/share/classes/javax/swing/plaf/nimbus/skin.laf Mon Jul 12 19:33:50 2010 -0700 +++ b/jdk/src/share/classes/javax/swing/plaf/nimbus/skin.laf Mon Jul 12 19:35:11 2010 -0700 @@ -21276,6 +21276,7 @@ <uiProperty name="centerOneTouchButtons" type="BOOLEAN" value="true"/> <uiProperty name="oneTouchButtonOffset" type="INT" value="30"/> <uiProperty name="oneTouchExpandable" type="BOOLEAN" value="false"/> + <uiProperty name="continuousLayout" type="BOOLEAN" value="true"/> </uiproperties> </style> <backgroundStates>
--- a/jdk/src/share/classes/sun/swing/SwingUtilities2.java Mon Jul 12 19:33:50 2010 -0700 +++ b/jdk/src/share/classes/sun/swing/SwingUtilities2.java Mon Jul 12 19:35:11 2010 -0700 @@ -438,8 +438,12 @@ // c may be null here. String clipString = "..."; availTextWidth -= SwingUtilities2.stringWidth(c, fm, clipString); + if (availTextWidth <= 0) { + //can not fit any characters + return clipString; + } + boolean needsTextLayout; - synchronized (charsBufferLock) { int stringLength = syncCharsBuffer(string); needsTextLayout =
--- a/jdk/test/ProblemList.txt Mon Jul 12 19:33:50 2010 -0700 +++ b/jdk/test/ProblemList.txt Mon Jul 12 19:35:11 2010 -0700 @@ -295,9 +295,6 @@ # jdk_misc -# On Windows com.sun.java.swing.plaf.gtk does not exist, always fails there -com/sun/java/swing/plaf/gtk/Test6635110.java windows-all - # Need to be marked othervm, or changed to be samevm safe com/sun/jndi/ldap/ReadTimeoutTest.java generic-all com/sun/jndi/rmi/registry/RegistryContext/UnbindIdempotent.java generic-all @@ -848,9 +845,6 @@ # jdk_swing (not using samevm) -# Fails on solaris 10 sparc, throws RuntimeException that just says "failed" -javax/swing/JLabel/6501991/bug6501991.java generic-all - # Fails on solaris 11 i586, with othervm javax/swing/JFileChooser/6570445/bug6570445.java generic-all javax/swing/JFileChooser/6738668/bug6738668.java generic-all
--- a/jdk/test/com/sun/java/swing/plaf/gtk/Test6635110.java Mon Jul 12 19:33:50 2010 -0700 +++ b/jdk/test/com/sun/java/swing/plaf/gtk/Test6635110.java Mon Jul 12 19:35:11 2010 -0700 @@ -28,7 +28,6 @@ @run main Test6635110 */ -import com.sun.java.swing.plaf.gtk.GTKLookAndFeel; import javax.swing.*; import java.awt.*; import java.awt.image.BufferedImage; @@ -59,7 +58,12 @@ } public static void main(String[] args) throws Exception { - UIManager.setLookAndFeel(new GTKLookAndFeel()); + try { + UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel"); + } catch (Exception e) { + System.out.println("GTKLookAndFeel cannot be set, skipping this test"); + return; + } SwingUtilities.invokeAndWait(new Test6635110()); } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/com/sun/java/swing/plaf/gtk/Test6963870.java Mon Jul 12 19:35:11 2010 -0700 @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code 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 + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/* @test + @bug 6963870 + @summary Tests that GTKPainter.ListTableFocusBorder.getBorderInsets() + doesn't return null + @author Peter Zhelezniakov + @run main Test6963870 +*/ + +import java.awt.Insets; +import javax.swing.SwingUtilities; +import javax.swing.UIManager; +import javax.swing.border.Border; + +public class Test6963870 implements Runnable { + + final static String[] UI_NAMES = { + "List.focusCellHighlightBorder", + "List.focusSelectedCellHighlightBorder", + "List.noFocusBorder", + "Table.focusCellHighlightBorder", + "Table.focusSelectedCellHighlightBorder", + }; + + public void run() { + for (String uiName: UI_NAMES) { + test(uiName); + } + } + + void test(String uiName) { + Border b = UIManager.getBorder(uiName); + Insets i = b.getBorderInsets(null); + if (i == null) { + throw new RuntimeException("getBorderInsets() returns null for " + uiName); + } + } + + public static void main(String[] args) throws Exception { + try { + UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel"); + } catch (Exception e) { + System.out.println("GTKLookAndFeel cannot be set, skipping this test"); + return; + } + + SwingUtilities.invokeAndWait(new Test6963870()); + } +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/beans/Introspector/Test6707234.java Mon Jul 12 19:35:11 2010 -0700 @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code 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 + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 6707234 + * @summary Tests setter in a complex bean + * @author Sergey Malenkov + */ + +public class Test6707234 { + public static void main(String[] args) { + if (null == BeanUtils.getPropertyDescriptor(C.class, "number").getWriteMethod()) { + throw new Error("no write method"); + } + } + + public interface I { + void setNumber(Object number); + Number getNumber(); + } + + public class C implements I { + public void setNumber(Object value) { + } + public void setNumber(Long value) { + } + public Long getNumber() { + return null; + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/beans/Introspector/Test6963811.java Mon Jul 12 19:35:11 2010 -0700 @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code 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 + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 6963811 + * @summary Tests deadlock in Introspector + * @author Sergey Malenkov + */ + +import java.beans.Introspector; +import java.beans.SimpleBeanInfo; + +public class Test6963811 implements Runnable { + private final long time; + private final boolean sync; + + public Test6963811(long time, boolean sync) { + this.time = time; + this.sync = sync; + } + + public void run() { + try { + Thread.sleep(this.time); // increase the chance of the deadlock + Introspector.getBeanInfo( + this.sync ? Super.class : Sub.class, + this.sync ? null : Object.class); + } + catch (Exception exception) { + exception.printStackTrace(); + } + } + + public static void main(String[] args) throws Exception { + Thread[] threads = new Thread[2]; + for (int i = 0; i < threads.length; i++) { + threads[i] = new Thread(new Test6963811(0L, i > 0)); + threads[i].start(); + Thread.sleep(500L); // increase the chance of the deadlock + } + for (Thread thread : threads) { + thread.join(); + } + } + + public static class Super { + } + + public static class Sub extends Super { + } + + public static class SubBeanInfo extends SimpleBeanInfo { + public SubBeanInfo() { + new Test6963811(1000L, true).run(); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/beans/PropertyEditor/Test6963811.java Mon Jul 12 19:35:11 2010 -0700 @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code 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 + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 6963811 + * @summary Tests deadlock in PropertyEditorManager + * @author Sergey Malenkov + */ + +import java.beans.PropertyEditorManager; +import sun.beans.editors.StringEditor; + +public class Test6963811 implements Runnable { + private final long time; + private final boolean sync; + + public Test6963811(long time, boolean sync) { + this.time = time; + this.sync = sync; + } + + public void run() { + try { + Thread.sleep(this.time); // increase the chance of the deadlock + if (this.sync) { + synchronized (Test6963811.class) { + PropertyEditorManager.findEditor(Super.class); + } + } + else { + PropertyEditorManager.findEditor(Sub.class); + } + } + catch (Exception exception) { + exception.printStackTrace(); + } + } + + public static void main(String[] args) throws Exception { + Thread[] threads = new Thread[2]; + for (int i = 0; i < threads.length; i++) { + threads[i] = new Thread(new Test6963811(0L, i > 0)); + threads[i].start(); + Thread.sleep(500L); // increase the chance of the deadlock + } + for (Thread thread : threads) { + thread.join(); + } + } + + public static class Super { + } + + public static class Sub extends Super { + } + + public static class SubEditor extends StringEditor { + public SubEditor() { + new Test6963811(1000L, true).run(); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/beans/XMLEncoder/Test6963811.java Mon Jul 12 19:35:11 2010 -0700 @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code 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 + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 6963811 + * @summary Tests deadlock in Encoder + * @author Sergey Malenkov + */ + +import java.beans.Encoder; +import java.beans.DefaultPersistenceDelegate; + +public class Test6963811 implements Runnable { + private static final Encoder ENCODER = new Encoder(); + private final long time; + private final boolean sync; + + public Test6963811(long time, boolean sync) { + this.time = time; + this.sync = sync; + } + + public void run() { + try { + Thread.sleep(this.time); // increase the chance of the deadlock + if (this.sync) { + synchronized (Test6963811.class) { + ENCODER.getPersistenceDelegate(Super.class); + } + } + else { + ENCODER.getPersistenceDelegate(Sub.class); + } + } + catch (Exception exception) { + exception.printStackTrace(); + } + } + + public static void main(String[] args) throws Exception { + Thread[] threads = new Thread[2]; + for (int i = 0; i < threads.length; i++) { + threads[i] = new Thread(new Test6963811(0L, i > 0)); + threads[i].start(); + Thread.sleep(500L); // increase the chance of the deadlock + } + for (Thread thread : threads) { + thread.join(); + } + } + + public static class Super { + } + + public static class Sub extends Super { + } + + public static class SubPersistenceDelegate extends DefaultPersistenceDelegate { + public SubPersistenceDelegate() { + new Test6963811(1000L, true).run(); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/javax/swing/AbstractButton/6711682/bug6711682.java Mon Jul 12 19:35:11 2010 -0700 @@ -0,0 +1,151 @@ +/* + * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code 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 + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* @test + @bug 6711682 + @summary JCheckBox in JTable: checkbox doesn't alaways respond to the first mouse click + @author Alexander Potochkin + @run main bug6711682 +*/ + +import sun.awt.SunToolkit; + +import javax.swing.*; +import javax.swing.event.CellEditorListener; +import javax.swing.table.TableCellEditor; +import javax.swing.table.TableCellRenderer; +import java.awt.*; +import java.awt.event.InputEvent; +import java.awt.event.KeyEvent; +import java.util.EventObject; + +public class bug6711682 { + private static JCheckBox editorCb; + private static JCheckBox rendererCb; + private static JTable table; + + public static void main(String[] args) throws Exception { + Robot robot = new Robot(); + robot.setAutoDelay(50); + SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + createAndShowGUI(); + } + }); + toolkit.realSync(); + Point l = table.getLocationOnScreen(); + int h = table.getRowHeight(); + for (int i = 0; i < 3; i++) { + robot.mouseMove(l.x + 5, l.y + 5 + i * h); + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + } + // Without pressing F2 the last table's cell + // reported <code>false</code> value + // note that I can't press it inside the for loop + // because it doesn't reproduce the bug + robot.keyPress(KeyEvent.VK_F2); + robot.keyRelease(KeyEvent.VK_F2); + + for (int i = 0; i < 3; i++) { + if (!Boolean.TRUE.equals(table.getValueAt(i, 0))) { + throw new RuntimeException("Row #" + i + " checkbox is not selected"); + } + } + for (int i = 2; i >= 0; i--) { + robot.mouseMove(l.x + 5, l.y + 5 + i * h); + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + } + robot.keyPress(KeyEvent.VK_F2); + robot.keyRelease(KeyEvent.VK_F2); + for (int i = 0; i < 3; i++) { + if (Boolean.TRUE.equals(table.getValueAt(i, 0))) { + throw new RuntimeException("Row #" + i + " checkbox is selected"); + } + } + } + + private static void createAndShowGUI() { + editorCb = new JCheckBox(); + rendererCb = new JCheckBox(); + JFrame f = new JFrame("Table with CheckBox"); + Container p = f.getContentPane(); + p.setLayout(new BorderLayout()); + table = new JTable(new Object[][]{{false}, {false}, {false}}, new Object[]{"CheckBox"}); + TableCellEditor editor = new TableCellEditor() { + int editedRow; + + public Component getTableCellEditorComponent(JTable table, + Object value, boolean isSelected, int row, int column) { + this.editedRow = row; + editorCb.setSelected(Boolean.TRUE.equals(value)); + editorCb.setBackground(UIManager.getColor("Table.selectionBackground")); + return editorCb; + } + + public void addCellEditorListener(CellEditorListener l) { + } + + public void cancelCellEditing() { + } + + public Object getCellEditorValue() { + return editorCb.isSelected(); + } + + public boolean isCellEditable(EventObject anEvent) { + return true; + } + + public void removeCellEditorListener(CellEditorListener l) { + } + + public boolean shouldSelectCell(EventObject anEvent) { + return true; + } + + public boolean stopCellEditing() { + table.getModel().setValueAt(editorCb.isSelected(), editedRow, 0); + return true; + } + }; + table.getColumnModel().getColumn(0).setCellEditor(editor); + + TableCellRenderer renderer = new TableCellRenderer() { + public Component getTableCellRendererComponent(JTable table, + Object value, boolean isSelected, boolean hasFocus, + int row, int column) { + rendererCb.setSelected(Boolean.TRUE.equals(value)); + return rendererCb; + } + }; + table.getColumnModel().getColumn(0).setCellRenderer(renderer); + + p.add(table, BorderLayout.CENTER); + + f.pack(); + f.setVisible(true); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/javax/swing/JFileChooser/6520101/bug6520101.java Mon Jul 12 19:35:11 2010 -0700 @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code 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 + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test @(#)bug6520101 + * @bug 6520101 + * @summary JFileChooser throws OOM in 1.4.2, 5.0u4 and 1.6.0 + * @author Praveen Gupta + * @run main/othervm/timeout=600 -Xmx8m -verify bug6520101 +*/ + +import javax.swing.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +public class bug6520101 implements Runnable { + + private static final int ATTEMPTS = 500; + private static final int INTERVAL = 100; + + private static final boolean ALWAYS_NEW_INSTANCE = false; + private static final boolean DO_GC_EACH_INTERVAL = false; + private static final boolean UPDATE_UI_EACH_INTERVAL = true; + private static final boolean AUTO_CLOSE_DIALOG = true; + + private static JFileChooser CHOOSER; + + public static void main(String[] args) throws Exception { + UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel"); + + for (int i = 0; i < ATTEMPTS; i++) { + doAttempt(); + } + + System.out.println("Test passed successfully"); + } + + private static void doAttempt() throws InterruptedException { + if (ALWAYS_NEW_INSTANCE || (CHOOSER == null)) + CHOOSER = new JFileChooser("."); + + if (UPDATE_UI_EACH_INTERVAL) { + CHOOSER.updateUI(); + } + + if (AUTO_CLOSE_DIALOG) { + Thread t = new Thread(new bug6520101(CHOOSER)); + t.start(); + CHOOSER.showOpenDialog(null); + t.join(); + } else { + CHOOSER.showOpenDialog(null); + } + + if (DO_GC_EACH_INTERVAL) { + System.gc(); + } + } + + private final JFileChooser chooser; + + bug6520101(JFileChooser chooser) { + this.chooser = chooser; + } + + public void run() { + while (!this.chooser.isShowing()) { + try { + Thread.sleep(30); + } catch (InterruptedException exception) { + exception.printStackTrace(); + } + } + + Timer timer = new Timer(INTERVAL, new ActionListener() { + public void actionPerformed(ActionEvent e) { + chooser.cancelSelection(); + } + }); + + timer.setRepeats(false); + timer.start(); + } +}
--- a/jdk/test/javax/swing/JInternalFrame/6725409/bug6725409.java Mon Jul 12 19:33:50 2010 -0700 +++ b/jdk/test/javax/swing/JInternalFrame/6725409/bug6725409.java Mon Jul 12 19:35:11 2010 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -43,7 +43,7 @@ new com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel()); } catch(UnsupportedLookAndFeelException e) { System.out.println("The test is for Windows LaF only"); - System.exit(0); + return; } final bug6725409 bug6725409 = new bug6725409();
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/javax/swing/JPopupMenu/6495920/bug6495920.java Mon Jul 12 19:35:11 2010 -0700 @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code 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 + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 6495920 + * @summary Tests that if the JPopupMenu.setVisible method throws an exception, + interaction with GNOME is not crippled + * @author Sergey Malenkov + * @library ../.. + */ + +import sun.awt.AppContext; + +import java.awt.Point; +import java.awt.Robot; +import java.awt.event.InputEvent; +import java.lang.reflect.Field; +import javax.swing.JFrame; +import javax.swing.JMenuItem; +import javax.swing.JPanel; +import javax.swing.JPopupMenu; +import javax.swing.SwingUtilities; +import javax.swing.plaf.basic.BasicPopupMenuUI; + +public class bug6495920 implements Thread.UncaughtExceptionHandler { + + public static void main(String[] args) throws Throwable { + SwingTest.start(bug6495920.class); + } + + private static Robot robot; + private final JPanel panel; + + public bug6495920(JFrame frame) { + JPopupMenu menu = new JPopupMenu() { + public void setVisible(boolean visible) { + super.setVisible(visible); + throw new AssertionError(visible ? "show popup" : "hide popup"); + } + }; + for (int i = 0; i < 10; i++) { + menu.add(new JMenuItem(String.valueOf(i))); + } + this.panel = new JPanel(); + this.panel.setComponentPopupMenu(menu); + frame.add(this.panel); + } + + public void firstShowPopup() throws Exception { + Point point = this.panel.getLocation(); + SwingUtilities.convertPointToScreen(point, this.panel); + + robot = new Robot(); // initialize shared static field first time + robot.mouseMove(point.x + 1, point.y + 1); + robot.mousePress(InputEvent.BUTTON3_MASK); + Thread.currentThread().setUncaughtExceptionHandler(this); + robot.mouseRelease(InputEvent.BUTTON3_MASK); // causes first AssertionError on EDT + } + + public void secondHidePopup() { + Point point = this.panel.getLocation(); + SwingUtilities.convertPointToScreen(point, this.panel); + + robot.mouseMove(point.x - 1, point.y - 1); + Thread.currentThread().setUncaughtExceptionHandler(this); + robot.mousePress(InputEvent.BUTTON1_MASK); // causes second AssertionError on EDT + robot.mouseRelease(InputEvent.BUTTON1_MASK); + } + + public void thirdValidate() throws Exception { + Field key = BasicPopupMenuUI.class.getDeclaredField("MOUSE_GRABBER_KEY"); + key.setAccessible(true); + + Object grabber = AppContext.getAppContext().get(key.get(null)); + if (grabber == null) { + throw new Exception("cannot find a mouse grabber in app's context"); + } + + Field field = grabber.getClass().getDeclaredField("grabbedWindow"); + field.setAccessible(true); + + Object window = field.get(grabber); + if (window != null) { + throw new Exception("interaction with GNOME is crippled"); + } + } + + public void uncaughtException(Thread thread, Throwable throwable) { + System.out.println(throwable); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/javax/swing/JTable/6777378/bug6777378.java Mon Jul 12 19:35:11 2010 -0700 @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code 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 + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* @test + @bug 6777378 + @summary NullPointerException in XPDefaultRenderer.paint() + @author Alexander Potochkin + @run main bug6777378 +*/ + +import sun.awt.SunToolkit; + +import javax.swing.*; +import javax.swing.table.AbstractTableModel; +import javax.swing.table.JTableHeader; +import javax.swing.plaf.metal.MetalLookAndFeel; +import java.awt.event.MouseEvent; +import java.awt.event.InputEvent; +import java.awt.*; + +public class bug6777378 { + private static JFrame frame; + private static JTableHeader header; + + public static void main(String[] args) throws Exception { + SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); + Robot robot = new Robot(); + robot.setAutoDelay(20); + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + try { + UIManager.setLookAndFeel(new MetalLookAndFeel()); + } catch (Exception e) { + e.printStackTrace(); + } + JTable table = new JTable(new AbstractTableModel() { + public int getRowCount() { + return 10; + } + + public int getColumnCount() { + return 10; + } + + public Object getValueAt(int rowIndex, int columnIndex) { + return "" + rowIndex + " " + columnIndex; + } + }); + + header = new JTableHeader(table.getColumnModel()); + header.setToolTipText("hello"); + + frame = new JFrame(); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.add(header); + + frame.setSize(300, 300); + frame.setVisible(true); + } + }); + toolkit.realSync(); + Point point = header.getLocationOnScreen(); + robot.mouseMove(point.x + 20, point.y + 50); + robot.mouseMove(point.x + 30, point.y + 50); + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/javax/swing/border/Test4129681.html Mon Jul 12 19:35:11 2010 -0700 @@ -0,0 +1,10 @@ +<html> +<body> +When applet starts, you'll see a checkbox and a label with a titled border. +Turn on the checkbox to disable the label. +The test passes if the title of the border is disabled as well as the label. + +<applet width="300" height="200" code="Test4129681.class"> +</applet> +</body> +</html>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/javax/swing/border/Test4129681.java Mon Jul 12 19:35:11 2010 -0700 @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code 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 + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 4129681 + * @summary Tests enabling/disabling of titled border's caption + * @author Sergey Malenkov + * @run applet/manual=yesno Test4129681.html + */ + +import java.awt.BorderLayout; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import javax.swing.BorderFactory; +import javax.swing.JApplet; +import javax.swing.JCheckBox; +import javax.swing.JLabel; + +public class Test4129681 extends JApplet implements ItemListener { + private JLabel label; + + @Override + public void init() { + JCheckBox check = new JCheckBox("disable"); + check.addItemListener(this); + + this.label = new JLabel("message"); + this.label.setBorder(BorderFactory.createTitledBorder("label")); + this.label.setEnabled(!check.isSelected()); + + add(BorderLayout.NORTH, check); + add(BorderLayout.CENTER, this.label); + } + + public void itemStateChanged(ItemEvent event) { + this.label.setEnabled(ItemEvent.DESELECTED == event.getStateChange()); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/javax/swing/border/Test4760089.html Mon Jul 12 19:35:11 2010 -0700 @@ -0,0 +1,10 @@ +<html> +<body> +When applet starts, you'll see a panel with a compound titled border. +If one of its titles is overstriken with the border's line then test fails. +Otherwise test passes. + +<applet width="600" height="300" code="Test4760089.class"> +</applet> +</body> +</html>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/javax/swing/border/Test4760089.java Mon Jul 12 19:35:11 2010 -0700 @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code 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 + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 4760089 + * @summary Tests that titled border do not paint inner titled border over its caption + * @author Sergey Malenkov + * @run applet/manual=yesno Test4760089.html + */ + +import javax.swing.JApplet; +import javax.swing.JPanel; +import javax.swing.border.Border; +import javax.swing.border.EtchedBorder; +import javax.swing.border.TitledBorder; + +public class Test4760089 extends JApplet { + @Override + public void init() { + Border border = new EtchedBorder(); + border = new TitledBorder(border, "LEFT", TitledBorder.LEFT, TitledBorder.TOP); + border = new TitledBorder(border, "RIGHT", TitledBorder.RIGHT, TitledBorder.TOP); + + JPanel panel = new JPanel(); + panel.setBorder(border); + getContentPane().add(panel); + } +}