From 317553031c74d47019b9aefcfaf18b0e2cc4526b Mon Sep 17 00:00:00 2001 From: Vladimir Ivanov Date: Mon, 19 Oct 2015 17:52:39 +0300 Subject: [PATCH 01/43] 8139881: Exclude java/lang/invoke/LFCaching/LFSingleThreadCachingTest.java from execution Reviewed-by: kvn --- .../java/lang/invoke/LFCaching/LFSingleThreadCachingTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/jdk/test/java/lang/invoke/LFCaching/LFSingleThreadCachingTest.java b/jdk/test/java/lang/invoke/LFCaching/LFSingleThreadCachingTest.java index 3a97456e1a4..6f4ad86a280 100644 --- a/jdk/test/java/lang/invoke/LFCaching/LFSingleThreadCachingTest.java +++ b/jdk/test/java/lang/invoke/LFCaching/LFSingleThreadCachingTest.java @@ -23,6 +23,7 @@ /* * @test LFSingleThreadCachingTest + * @ignore 8129523 * @bug 8046703 * @key randomness * @summary Test verifies that lambda forms are cached when run with single thread From cdd7249f6e1537f9c2b9e26d6a1a80f91e090356 Mon Sep 17 00:00:00 2001 From: Roger Riggs Date: Fri, 30 Oct 2015 11:12:20 -0400 Subject: [PATCH 02/43] 8139390: Very long classname in jimage causes SIGSEGV Correct issues with ImageNativeSubstrate and JImageReadTest Reviewed-by: mchung --- .../native/libjimage/ImageNativeSubstrate.cpp | 86 +++++++++++++++---- .../share/native/libjimage/jimage.cpp | 29 +++++-- .../jdk/internal/jimage/JImageReadTest.java | 30 ++++++- 3 files changed, 117 insertions(+), 28 deletions(-) diff --git a/jdk/src/java.base/share/native/libjimage/ImageNativeSubstrate.cpp b/jdk/src/java.base/share/native/libjimage/ImageNativeSubstrate.cpp index d2217e4fe62..0f803cb4fa9 100644 --- a/jdk/src/java.base/share/native/libjimage/ImageNativeSubstrate.cpp +++ b/jdk/src/java.base/share/native/libjimage/ImageNativeSubstrate.cpp @@ -26,8 +26,7 @@ #include #include "jni.h" -#include "jni_util.h" -#include "jdk_util.h" + #include "endian.hpp" #include "imageDecompressor.hpp" #include "imageFile.hpp" @@ -39,6 +38,17 @@ extern bool MemoryMapImage; +///////////////////////////////////////////////////////////////////////////// + +// Static function for primitive throw since libjimage is not linked with libjava +static void JNICALL ThrowByName(JNIEnv *env, const char *name, const char *msg) +{ + jclass cls = (env)->FindClass(name); + + if (cls != 0) /* Otherwise an exception has already been thrown */ + (env)->ThrowNew(cls, msg); +} + // jdk.internal.jimage ///////////////////////////////////////////////////////// // Java entry to open an image file for sharing. @@ -446,6 +456,23 @@ JNIEXPORT jlong JNICALL Java_jdk_internal_jimage_ImageNativeSubstrate_JIMAGE_1Fi jlong size = 0; jlong ret = 0; + if (moduleName == NULL) { + ThrowByName(env, "java/lang/NullPointerException", "moduleName"); + return 0; + } + if (version == NULL) { + ThrowByName(env, "java/lang/NullPointerException", "version"); + return 0; + } + if (path == NULL) { + ThrowByName(env, "java/lang/NullPointerException", "path"); + return 0; + } + if (output_size == NULL) { + ThrowByName(env, "java/lang/NullPointerException", "size"); + return 0; + } + do { native_module = env->GetStringUTFChars(moduleName, NULL); if (native_module == NULL) @@ -529,25 +556,47 @@ static bool resourceVisitor(JImageFile* image, // Store if there is room in the array // Concatenate to get full path char fullpath[IMAGE_MAX_PATH]; - fullpath[0] = '\0'; - if (*module != '\0') { - strncpy(fullpath, "/", IMAGE_MAX_PATH - 1); - strncat(fullpath, module, IMAGE_MAX_PATH - 1); - strncat(fullpath, "/", IMAGE_MAX_PATH - 1); + size_t moduleLen = strlen(module); + size_t packageLen = strlen(package); + size_t nameLen = strlen(name); + size_t extLen = strlen(extension); + size_t index; + + if (1 + moduleLen + 1 + packageLen + 1 + nameLen + 1 + extLen + 1 > IMAGE_MAX_PATH) { + ThrowByName(env, "java/lang/InternalError", "concatenated name too long"); + return true; } - if (*package != '\0') { - strncat(fullpath, package, IMAGE_MAX_PATH - 1); - strncat(fullpath, "/", IMAGE_MAX_PATH - 1); + + index = 0; + if (moduleLen > 0) { + fullpath[index++] = '/'; + memcpy(&fullpath[index], module, moduleLen); + index += moduleLen; + fullpath[index++] = '/'; } - strncat(fullpath, name, IMAGE_MAX_PATH - 1); - if (*extension != '\0') { - strncat(fullpath, ".", IMAGE_MAX_PATH - 1); - strncat(fullpath, extension, IMAGE_MAX_PATH - 1); + if (packageLen > 0) { + memcpy(&fullpath[index], package, packageLen); + index += packageLen; + fullpath[index++] = '/'; } + memcpy(&fullpath[index], name, nameLen); + index += nameLen; + if (extLen > 0) { + fullpath[index++] = '.'; + memcpy(&fullpath[index], extension, extLen); + index += extLen; + } + fullpath[index++] = '\0'; + jobject str = env->NewStringUTF(fullpath); - JNU_CHECK_EXCEPTION_RETURN(env, true); + if (env->ExceptionCheck()) { + return true; + } + env->SetObjectArrayElement(vdata->array, vdata->size, str); - JNU_CHECK_EXCEPTION_RETURN(env, true); + if (env->ExceptionCheck()) { + return true; + } } vdata->size++; // always count so the total size is returned return true; @@ -584,7 +633,10 @@ JNIEXPORT jstring JNICALL Java_jdk_internal_jimage_ImageNativeSubstrate_JIMAGE_1 jstring module = NULL; native_package = env->GetStringUTFChars(package_name, NULL); - JNU_CHECK_EXCEPTION_RETURN(env, NULL); + if (env->ExceptionCheck()) { + return NULL; + } + native_module = JIMAGE_PackageToModule((JImageFile*) jimageHandle, native_package); if (native_module != NULL) { diff --git a/jdk/src/java.base/share/native/libjimage/jimage.cpp b/jdk/src/java.base/share/native/libjimage/jimage.cpp index cd09ffa2339..371cb1dc706 100644 --- a/jdk/src/java.base/share/native/libjimage/jimage.cpp +++ b/jdk/src/java.base/share/native/libjimage/jimage.cpp @@ -102,14 +102,29 @@ extern "C" const char* JIMAGE_PackageToModule(JImageFile* image, const char* pac extern "C" JImageLocationRef JIMAGE_FindResource(JImageFile* image, const char* module_name, const char* version, const char* name, jlong* size) { - ImageLocation location; - char fullpath[IMAGE_MAX_PATH]; - // Concatenate to get full path - strncpy(fullpath, "/", IMAGE_MAX_PATH - 1); - strncat(fullpath, module_name, IMAGE_MAX_PATH - 1); - strncat(fullpath, "/", IMAGE_MAX_PATH - 1); - strncat(fullpath, name, IMAGE_MAX_PATH - 1); + char fullpath[IMAGE_MAX_PATH]; + size_t moduleNameLen = strlen(module_name); + size_t nameLen = strlen(name); + size_t index; + + // TBD: assert(moduleNameLen > 0 && "module name must be non-empty"); + assert(nameLen > 0 && "name must non-empty"); + + // If the concatenated string is too long for the buffer, return not found + if (1 + moduleNameLen + 1 + nameLen + 1 > IMAGE_MAX_PATH) { + return 0L; + } + + index = 0; + fullpath[index++] = '/'; + memcpy(&fullpath[index], module_name, moduleNameLen); + index += moduleNameLen; + fullpath[index++] = '/'; + memcpy(&fullpath[index], name, nameLen); + index += nameLen; + fullpath[index++] = '\0'; + JImageLocationRef loc = (JImageLocationRef) ((ImageFileReader*) image)->find_location_index(fullpath, (u8*) size); return loc; diff --git a/jdk/test/jdk/internal/jimage/JImageReadTest.java b/jdk/test/jdk/internal/jimage/JImageReadTest.java index 910c35aec4a..82df8c83384 100644 --- a/jdk/test/jdk/internal/jimage/JImageReadTest.java +++ b/jdk/test/jdk/internal/jimage/JImageReadTest.java @@ -22,7 +22,9 @@ */ /* + * @test * @modules java.base/jdk.internal.jimage + * @run testng JImageReadTest * @summary Unit test for libjimage JIMAGE_Open/Read/Close */ @@ -57,8 +59,7 @@ public class JImageReadTest { {"java.base", "java/lang/String.class"}, {"java.base", "java/lang/Object.class"}, {"java.base", "sun/reflect/generics/tree/TypeArgument.class"}, - {"jdk.jdeps", "com/sun/tools/javap/StackMapWriter$StackMapBuilder.class"}, - {"jdk.hotspot.agent", "sa.properties"}, + {"java.base", "sun/net/www/content-types.properties"}, {"java.logging", "java/util/logging/Logger.class"}, {"java.base", "java/NOSUCHCLASS/yyy.class"}, // non-existent {"NOSUCHMODULE", "java/lang/Class.class"}, // non-existent @@ -165,8 +166,10 @@ public class JImageReadTest { int count = ImageNativeSubstrate.JIMAGE_Resources(jimageHandle, names); System.out.printf(" count: %d, a class: %s\n", count, names[0]); - Assert.assertTrue(max > 31000, - "missing entries, should be more than 31000, reported: " + count); + int minEntryCount = 16000; + Assert.assertTrue(max > minEntryCount, + "missing entries, should be more than " + minEntryCount + + ", reported: " + count); Assert.assertTrue(count == max, "unexpected count of entries, count: " + count + ", max: " + max); @@ -310,6 +313,7 @@ public class JImageReadTest { static boolean isMetaName(String name) { return name.startsWith("/modules") || name.startsWith("/packages") + || name.startsWith("META-INF/services") || name.equals("bootmodules.jdata"); } @@ -362,6 +366,24 @@ public class JImageReadTest { System.out.printf(" %s: %d names%n", fname, names.length); } + @Test + static void test5_nameTooLong() throws IOException { + long[] size = new long[1]; + String moduleName = "FictiousModuleName"; + String className = String.format("A%09999d", 1); + + long jimageHandle = ImageNativeSubstrate.JIMAGE_Open(imageFile); + Assert.assertTrue(jimageHandle != 0, "JIMAGE_Open failed: id: " + jimageHandle); + + long locationHandle = + ImageNativeSubstrate.JIMAGE_FindResource(jimageHandle, + moduleName, "9.0", className, size); + + Assert.assertEquals(0, locationHandle, "Too long name should have failed"); + + ImageNativeSubstrate.JIMAGE_Close(jimageHandle); + } + // main method to run standalone from jtreg @Test(enabled=false) From 638270935d3c48b079f423030a0d2da7ca240ae1 Mon Sep 17 00:00:00 2001 From: Volker Simonis Date: Mon, 2 Nov 2015 14:57:04 +0100 Subject: [PATCH 03/43] 8140514: [TESTBUG] enable sun/security/pkcs11 tests on Linux/ppc64 Reviewed-by: wetmore --- jdk/test/sun/security/pkcs11/PKCS11Test.java | 1 + 1 file changed, 1 insertion(+) diff --git a/jdk/test/sun/security/pkcs11/PKCS11Test.java b/jdk/test/sun/security/pkcs11/PKCS11Test.java index 6ee011a294d..1e738601104 100644 --- a/jdk/test/sun/security/pkcs11/PKCS11Test.java +++ b/jdk/test/sun/security/pkcs11/PKCS11Test.java @@ -539,6 +539,7 @@ public abstract class PKCS11Test { osMap.put("Linux-amd64-64", new String[]{ "/usr/lib/x86_64-linux-gnu/", "/usr/lib/x86_64-linux-gnu/nss/", "/usr/lib64/"}); + osMap.put("Linux-ppc64-64", new String[]{"/usr/lib64/"}); osMap.put("Windows-x86-32", new String[]{ PKCS11_BASE + "/nss/lib/windows-i586/".replace('/', SEP)}); osMap.put("Windows-amd64-64", new String[]{ From 5710e3c7543e7effef4cea30bad8b66f3c31a627 Mon Sep 17 00:00:00 2001 From: Naoto Sato Date: Mon, 2 Nov 2015 08:46:19 -0800 Subject: [PATCH 04/43] 8062006: Add a new locale data name "COMPAT" for java.locale.providers system property to reduce ambiguity Reviewed-by: okutsu --- .../java/util/spi/LocaleServiceProvider.java | 14 ++++---- .../provider/LocaleProviderAdapter.java | 4 +++ jdk/test/java/util/Locale/LocaleProviders.sh | 33 ++++++++++++------- 3 files changed, 33 insertions(+), 18 deletions(-) diff --git a/jdk/src/java.base/share/classes/java/util/spi/LocaleServiceProvider.java b/jdk/src/java.base/share/classes/java/util/spi/LocaleServiceProvider.java index 582bbba95c8..a9bc8863ded 100644 --- a/jdk/src/java.base/share/classes/java/util/spi/LocaleServiceProvider.java +++ b/jdk/src/java.base/share/classes/java/util/spi/LocaleServiceProvider.java @@ -123,25 +123,27 @@ import java.util.Locale; *
    *
  • "CLDR": A provider based on Unicode Consortium's * CLDR Project. - *
  • "JRE": represents the locale sensitive services that is compatible - * with the prior JDK releases (same with JDK8's "JRE"). + *
  • "COMPAT": represents the locale sensitive services that is compatible + * with the prior JDK releases up to JDK8 (same as JDK8's "JRE"). *
  • "SPI": represents the locale sensitive services implementing the subclasses of * this {@code LocaleServiceProvider} class. *
  • "HOST": A provider that reflects the user's custom settings in the * underlying operating system. This provider may not be available, depending * on the Java Runtime Environment implementation. + *
  • "JRE": represents a synonym to "COMPAT". This name + * is deprecated and will be removed in the future release of JDK. *
*

* For example, if the following is specified in the property: *

- * java.locale.providers=SPI,CLDR,JRE
+ * java.locale.providers=SPI,CLDR,COMPAT
  * 
* the locale sensitive services in the SPI providers are looked up first. If the * desired locale sensitive service is not available, then the runtime looks for CLDR, - * JRE in that order. + * COMPAT in that order. *

- * The default order for looking up the preferred locale providers is "CLDR,JRE", - * so specifying "CLDR,JRE" is identical to the default behavior. Applications which + * The default order for looking up the preferred locale providers is "CLDR,COMPAT", + * so specifying "CLDR,COMPAT" is identical to the default behavior. Applications which * require implementations of the locale sensitive services must explicitly specify * "SPI" in order for the Java runtime to load them from the classpath. * diff --git a/jdk/src/java.base/share/classes/sun/util/locale/provider/LocaleProviderAdapter.java b/jdk/src/java.base/share/classes/sun/util/locale/provider/LocaleProviderAdapter.java index 0844a701594..c17856ffe9a 100644 --- a/jdk/src/java.base/share/classes/sun/util/locale/provider/LocaleProviderAdapter.java +++ b/jdk/src/java.base/share/classes/sun/util/locale/provider/LocaleProviderAdapter.java @@ -124,6 +124,10 @@ public abstract class LocaleProviderAdapter { if (order != null && order.length() != 0) { String[] types = order.split(","); for (String type : types) { + type = type.trim().toUpperCase(Locale.ROOT); + if (type.equals("COMPAT")) { + type = "JRE"; + } try { Type aType = Type.valueOf(type.trim().toUpperCase(Locale.ROOT)); if (!typeList.contains(aType)) { diff --git a/jdk/test/java/util/Locale/LocaleProviders.sh b/jdk/test/java/util/Locale/LocaleProviders.sh index 5e1b79383f5..fb8043e21c3 100644 --- a/jdk/test/java/util/Locale/LocaleProviders.sh +++ b/jdk/test/java/util/Locale/LocaleProviders.sh @@ -1,6 +1,6 @@ #!/bin/sh # -# Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2012, 2015, 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,7 +24,7 @@ # # @test # @bug 6336885 7196799 7197573 7198834 8000245 8000615 8001440 8008577 -# 8010666 8013086 8013233 8013903 8015960 8028771 +# 8010666 8013086 8013233 8013903 8015960 8028771 8062006 # @summary tests for "java.locale.providers" system property # @compile -XDignore.symbol.file LocaleProviders.java # @run shell/timeout=600 LocaleProviders.sh @@ -182,7 +182,7 @@ PARAM1=JRE if [ "${DEFLANG}" != "en" ] && [ "${DEFFMTLANG}" != "en" ]; then PARAM2=en PARAM3=US -elif [ "${DEFLANG}" != "ja" ] && [ "${DEFFMTLANG}" != "ja" ]; then +elif [ "${DEFLANG}" != "ja" ] && [ "${DEFFMTLANG}" != "ja" ]; then PARAM2=ja PARAM3=JP else @@ -200,6 +200,8 @@ PARAM2=en PARAM3=US SPICLASSES= runTest +PREFLIST=SPI,COMPAT +runTest # testing the order, variaton #1. This assumes en_GB DateFormat data are available both in JRE & CLDR METHODNAME=adapterTest @@ -209,6 +211,8 @@ PARAM2=en PARAM3=GB SPICLASSES= runTest +PREFLIST=CLDR,COMPAT +runTest # testing the order, variaton #2. This assumes en_GB DateFormat data are available both in JRE & CLDR METHODNAME=adapterTest @@ -218,6 +222,8 @@ PARAM2=en PARAM3=GB SPICLASSES= runTest +PREFLIST=COMPAT,CLDR +runTest # testing the order, variaton #3 for non-existent locale in JRE assuming "haw" is not in JRE. METHODNAME=adapterTest @@ -227,6 +233,8 @@ PARAM2=haw PARAM3= SPICLASSES= runTest +PREFLIST=COMPAT,CLDR +runTest # testing the order, variaton #4 for the bug 7196799. CLDR's "zh" data should be used in "zh_CN" METHODNAME=adapterTest @@ -275,6 +283,8 @@ PARAM2= PARAM3= SPICLASSES=${SPIDIR} runTest +PREFLIST=COMPAT +runTest # testing 8000615 fix. METHODNAME=tzNameTest @@ -284,6 +294,8 @@ PARAM2= PARAM3= SPICLASSES=${SPIDIR} runTest +PREFLIST=COMPAT +runTest # testing 8001440 fix. METHODNAME=bug8001440Test @@ -314,6 +326,8 @@ PARAM2=JP PARAM3= SPICLASSES=${SPIDIR} runTest +PREFLIST=COMPAT,SPI +runTest # testing 8013903 fix. (Windows only) METHODNAME=bug8013903Test @@ -323,12 +337,9 @@ PARAM2= PARAM3= SPICLASSES= runTest -METHODNAME=bug8013903Test PREFLIST=HOST -PARAM1= -PARAM2= -PARAM3= -SPICLASSES= +runTest +PREFLIST=HOST,COMPAT runTest # testing 8027289 fix, if the platform format default is zh_CN @@ -342,12 +353,10 @@ if [ "${DEFFMTLANG}" = "zh" ] && [ "${DEFFMTCTRY}" = "CN" ]; then PARAM3= SPICLASSES= runTest - METHODNAME=bug8027289Test + PREFLIST=COMPAT,HOST + runTest PREFLIST=HOST PARAM1=00A5 - PARAM2= - PARAM3= - SPICLASSES= runTest fi From dc711078d4f29a414c91750e222f82fabe5ca92e Mon Sep 17 00:00:00 2001 From: Jaroslav Bachorik Date: Wed, 23 Sep 2015 14:25:02 +0200 Subject: [PATCH 05/43] 8139727: Define ConstructorParameters annotation type for MXBeans Reviewed-by: alanb, mchung, dfuchs, abuckley, plevart, mr --- .../DefaultMXBeanMappingFactory.java | 58 ++++++---- .../management/ConstructorParameters.java | 76 +++++++++++++ .../classes/javax/management/MXBean.java | 42 ++++--- .../Introspector/AnnotationSecurityTest.java | 8 +- .../management/Introspector/Described.java | 4 +- .../management/Introspector/DescribedMX.java | 4 +- .../LegacyConstructorPropertiesTest.java | 106 ++++++++++++++++++ .../mxbean/AmbiguousConstructorTest.java | 18 ++- .../mxbean/ExceptionDiagnosisTest.java | 7 +- .../javax/management/mxbean/LeakTest.java | 3 +- .../javax/management/mxbean/MXBeanTest.java | 3 +- .../management/mxbean/PropertyNamesTest.java | 13 +-- .../javax/management/mxbean/TigerMXBean.java | 6 +- 13 files changed, 272 insertions(+), 76 deletions(-) create mode 100644 jdk/src/java.management/share/classes/javax/management/ConstructorParameters.java create mode 100644 jdk/test/javax/management/Introspector/LegacyConstructorPropertiesTest.java diff --git a/jdk/src/java.management/share/classes/com/sun/jmx/mbeanserver/DefaultMXBeanMappingFactory.java b/jdk/src/java.management/share/classes/com/sun/jmx/mbeanserver/DefaultMXBeanMappingFactory.java index 0b2835f9ee0..c322ed4f028 100644 --- a/jdk/src/java.management/share/classes/com/sun/jmx/mbeanserver/DefaultMXBeanMappingFactory.java +++ b/jdk/src/java.management/share/classes/com/sun/jmx/mbeanserver/DefaultMXBeanMappingFactory.java @@ -60,6 +60,7 @@ import java.util.WeakHashMap; import javax.management.JMX; import javax.management.ObjectName; +import javax.management.ConstructorParameters; import javax.management.openmbean.ArrayType; import javax.management.openmbean.CompositeData; import javax.management.openmbean.CompositeDataInvocationHandler; @@ -1132,8 +1133,8 @@ public class DefaultMXBeanMappingFactory extends MXBeanMappingFactory { } /** Builder for when the target class has a constructor that is - annotated with @ConstructorProperties so we can see the correspondence - to getters. */ + annotated with {@linkplain ConstructorParameters @ConstructorParameters} + or {@code @ConstructorProperties} so we can see the correspondence to getters. */ private static final class CompositeBuilderViaConstructor extends CompositeBuilder { @@ -1141,10 +1142,19 @@ public class DefaultMXBeanMappingFactory extends MXBeanMappingFactory { super(targetClass, itemNames); } - String applicable(Method[] getters) throws InvalidObjectException { - if (!JavaBeansAccessor.isAvailable()) - return "@ConstructorProperties annotation not available"; + private String[] getConstPropValues(Constructor ctr) { + // is constructor annotated by javax.management.ConstructorParameters ? + ConstructorParameters ctrProps = ctr.getAnnotation(ConstructorParameters.class); + if (ctrProps != null) { + return ctrProps.value(); + } else { + // try the legacy java.beans.ConstructorProperties annotation + String[] vals = JavaBeansAccessor.getConstructorPropertiesValue(ctr); + return vals; + } + } + String applicable(Method[] getters) throws InvalidObjectException { Class targetClass = getTargetClass(); Constructor[] constrs = targetClass.getConstructors(); @@ -1152,12 +1162,13 @@ public class DefaultMXBeanMappingFactory extends MXBeanMappingFactory { List> annotatedConstrList = newList(); for (Constructor constr : constrs) { if (Modifier.isPublic(constr.getModifiers()) - && JavaBeansAccessor.getConstructorPropertiesValue(constr) != null) + && getConstPropValues(constr) != null) annotatedConstrList.add(constr); } if (annotatedConstrList.isEmpty()) - return "no constructor has @ConstructorProperties annotation"; + return "no constructor has either @ConstructorParameters " + + "or @ConstructorProperties annotation"; annotatedConstructors = newList(); @@ -1181,13 +1192,17 @@ public class DefaultMXBeanMappingFactory extends MXBeanMappingFactory { // so we can test unambiguity. Set getterIndexSets = newSet(); for (Constructor constr : annotatedConstrList) { - String[] propertyNames = JavaBeansAccessor.getConstructorPropertiesValue(constr); + String annotationName = + constr.isAnnotationPresent(ConstructorParameters.class) ? + "@ConstructorParameters" : "@ConstructorProperties"; + + String[] propertyNames = getConstPropValues(constr); Type[] paramTypes = constr.getGenericParameterTypes(); if (paramTypes.length != propertyNames.length) { final String msg = "Number of constructor params does not match " + - "@ConstructorProperties annotation: " + constr; + annotationName + " annotation: " + constr; throw new InvalidObjectException(msg); } @@ -1200,7 +1215,7 @@ public class DefaultMXBeanMappingFactory extends MXBeanMappingFactory { String propertyName = propertyNames[i]; if (!getterMap.containsKey(propertyName)) { String msg = - "@ConstructorProperties includes name " + propertyName + + annotationName + " includes name " + propertyName + " which does not correspond to a property"; for (String getterName : getterMap.keySet()) { if (getterName.equalsIgnoreCase(propertyName)) { @@ -1215,7 +1230,7 @@ public class DefaultMXBeanMappingFactory extends MXBeanMappingFactory { paramIndexes[getterIndex] = i; if (present.get(getterIndex)) { final String msg = - "@ConstructorProperties contains property " + + annotationName + " contains property " + propertyName + " more than once: " + constr; throw new InvalidObjectException(msg); } @@ -1224,7 +1239,7 @@ public class DefaultMXBeanMappingFactory extends MXBeanMappingFactory { Type propertyType = getter.getGenericReturnType(); if (!propertyType.equals(paramTypes[i])) { final String msg = - "@ConstructorProperties gives property " + propertyName + + annotationName + " gives property " + propertyName + " of type " + propertyType + " for parameter " + " of type " + paramTypes[i] + ": " + constr; throw new InvalidObjectException(msg); @@ -1233,7 +1248,8 @@ public class DefaultMXBeanMappingFactory extends MXBeanMappingFactory { if (!getterIndexSets.add(present)) { final String msg = - "More than one constructor has a @ConstructorProperties " + + "More than one constructor has " + + "@ConstructorParameters or @ConstructorProperties " + "annotation with this set of names: " + Arrays.toString(propertyNames); throw new InvalidObjectException(msg); @@ -1252,10 +1268,10 @@ public class DefaultMXBeanMappingFactory extends MXBeanMappingFactory { * just the bigger constructor. * * The algorithm here is quadratic in the number of constructors - * with a @ConstructorProperties annotation. Typically this corresponds - * to the number of versions of the class there have been. Ten - * would already be a large number, so although it's probably - * possible to have an O(n lg n) algorithm it wouldn't be + * with a @ConstructorParameters or @ConstructructorProperties annotation. + * Typically this corresponds to the number of versions of the class + * there have been. Ten would already be a large number, so although + * it's probably possible to have an O(n lg n) algorithm it wouldn't be * worth the complexity. */ for (BitSet a : getterIndexSets) { @@ -1272,8 +1288,9 @@ public class DefaultMXBeanMappingFactory extends MXBeanMappingFactory { i = u.nextSetBit(i+1)) names.add(itemNames[i]); final String msg = - "Constructors with @ConstructorProperties annotation " + - " would be ambiguous for these items: " + + "Constructors with @ConstructorParameters or " + + "@ConstructorProperties annotation " + + "would be ambiguous for these items: " + names; throw new InvalidObjectException(msg); } @@ -1310,7 +1327,8 @@ public class DefaultMXBeanMappingFactory extends MXBeanMappingFactory { if (max == null) { final String msg = - "No constructor has a @ConstructorProperties for this set of " + + "No constructor has either @ConstructorParameters " + + "or @ConstructorProperties annotation for this set of " + "items: " + ct.keySet(); throw new InvalidObjectException(msg); } diff --git a/jdk/src/java.management/share/classes/javax/management/ConstructorParameters.java b/jdk/src/java.management/share/classes/javax/management/ConstructorParameters.java new file mode 100644 index 00000000000..d3d447e2a53 --- /dev/null +++ b/jdk/src/java.management/share/classes/javax/management/ConstructorParameters.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2006, 2015 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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. + */ + +package javax.management; + +import java.lang.annotation.*; +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.*; + +/** + *

+ * An annotation on a constructor that shows how the parameters of + * that constructor correspond to the constructed object's getter + * methods. For example: + *

+ *
+ *
+ *         public class MemoryUsage {
+ *             // standard JavaBean conventions with getters
+ *             @ConstructorParameters({"init", "used", "committed", "max"})
+ *             public MemoryUsage(long init, long used,
+ *                                long committed, long max) {...}
+ *             public long getInit() {...}
+ *             public long getUsed() {...}
+ *             public long getCommitted() {...}
+ *             public long getMax() {...}
+ *         }
+ *     
+ *
+ *

+ * The annotation shows that the first parameter of the constructor + * can be retrieved with the {@code getInit()} method, the second one with + * the {@code getUsed()} method, and so on. Since parameter names are not in + * general available at runtime, without the annotation there would be + * no way of knowing which parameter corresponds to which property. + *

+ *

+ * If a constructor is annotated by the both {@code @java.beans.ConstructorProperties} + * and {@code @javax.management.ConstructorParameters} annotations + * the JMX introspection will give an absolute precedence to the latter one. + *

+ * + * @since 1.9 + */ +@Documented @Target(CONSTRUCTOR) @Retention(RUNTIME) +public @interface ConstructorParameters { + /** + *

The getter names.

+ * + * @return the getter names corresponding to the parameters in the + * annotated constructor. + */ + String[] value(); +} diff --git a/jdk/src/java.management/share/classes/javax/management/MXBean.java b/jdk/src/java.management/share/classes/javax/management/MXBean.java index 766e36feda6..8784a5fbaf8 100644 --- a/jdk/src/java.management/share/classes/javax/management/MXBean.java +++ b/jdk/src/java.management/share/classes/javax/management/MXBean.java @@ -153,7 +153,7 @@ public class MemoryUsage implements Serializable {
 public class MemoryUsage {
     // standard JavaBean conventions with getters
-    @ConstructorProperties({"init", "used", "committed", "max"})
+    @ConstructorParameters({"init", "used", "committed", "max"})
     public MemoryUsage(long init, long used,
                        long committed, long max) {...}
     long getInit() {...}
@@ -168,8 +168,8 @@ public class MemoryUsage {
     

The definitions are the same in the two cases, except that with the MXBean, MemoryUsage no longer needs to be marked Serializable (though it can be). On - the other hand, we have added a {@code @ConstructorProperties} annotation - to link the constructor parameters to the corresponding getters. + the other hand, we have added a {@link ConstructorParameters @ConstructorParameters} + annotation to link the constructor parameters to the corresponding getters. We will see more about this below.

MemoryUsage is a model-specific class. @@ -850,18 +850,24 @@ public interface ModuleMXBean { J.

  • Otherwise, if J has at least one public - constructor with a {@link java.beans.ConstructorProperties - ConstructorProperties} annotation, then one - of those constructors (not necessarily always the same one) - will be called to reconstruct an instance of J. + constructor with either {@link javax.management.ConstructorParameters + @javax.management.ConstructorParameters} or + {@code @java.beans.ConstructoProperties} annotation, then one of those + constructors (not necessarily always the same one) will be called to + reconstruct an instance of J. + If a constructor is annotated with both + {@code @javax.management.ConstructorParameters} and + {@code @java.beans.ConstructorProperties}, + {@code @javax.management.ConstructorParameters} will be used and + {@code @java.beans.ConstructorProperties} will be ignored. Every such annotation must list as many strings as the constructor has parameters; each string must name a property corresponding to a getter of J; and the type of this getter must be the same as the corresponding constructor parameter. It is not an error for there to be getters that - are not mentioned in the {@code ConstructorProperties} annotation - (these may correspond to information that is not needed to - reconstruct the object).

    + are not mentioned in the {@code @ConstructorParameters} or + {@code @ConstructorProperties} annotations (these may correspond to + information that is not needed to reconstruct the object).

    An instance of J is reconstructed by calling a constructor with the appropriate reconstructed items from the @@ -871,9 +877,10 @@ public interface ModuleMXBean { CompositeData} might come from an earlier version of J where not all the items were present. A constructor is applicable if all the properties named - in its {@code ConstructorProperties} annotation are present as items - in the {@code CompositeData}. If no constructor is - applicable, then the attempt to reconstruct J fails.

    + in its {@code @ConstructorParameters} or {@code @ConstructorProperties} + annotation are present as items in the {@code CompositeData}. + If no constructor is applicable, then the attempt to reconstruct + J fails.

    For any possible combination of properties, it must be the case that either (a) there are no applicable constructors, or @@ -909,8 +916,9 @@ public interface ModuleMXBean {

  • Otherwise, J is not reconstructible.

  • -

    Rule 2 is not applicable to subset Profiles of Java SE that do not - include the {@code java.beans} package. When targeting a runtime that does +

    When only {@code @java.beans.ConstructorProperties} is present then + rule 2 is not applicable to subset Profiles of Java SE that do not include + the {@code java.beans} package. When targeting a runtime that does not include the {@code java.beans} package, and where there is a mismatch between the compile-time and runtime environment whereby J is compiled with a public constructor and the {@code ConstructorProperties} @@ -957,14 +965,14 @@ public class NamedNumber { -

  • Public constructor with @ConstructorProperties annotation: +
  • Public constructor with @ConstructorParameters annotation:
     public class NamedNumber {
         public int getNumber() {return number;}
         public String getName() {return name;}
    -    @ConstructorProperties({"number", "name"})
    +    @ConstructorParameters({"number", "name"})
         public NamedNumber(int number, String name) {
             this.number = number;
             this.name = name;
    diff --git a/jdk/test/javax/management/Introspector/AnnotationSecurityTest.java b/jdk/test/javax/management/Introspector/AnnotationSecurityTest.java
    index 2d07a0a61bd..0afb509272c 100644
    --- a/jdk/test/javax/management/Introspector/AnnotationSecurityTest.java
    +++ b/jdk/test/javax/management/Introspector/AnnotationSecurityTest.java
    @@ -27,8 +27,7 @@
      * @summary Test that having a security manager doesn't trigger a
      *          NotCompliantMBeanException
      * @author Daniel Fuchs, Yves Joan
    - * @modules java.desktop
    - *          java.management
    + * @modules java.management
      * @run clean AnnotationSecurityTest Described UnDescribed DescribedMBean
      *            UnDescribedMBean SqeDescriptorKey DescribedMX DescribedMXBean
      * @run build AnnotationSecurityTest Described UnDescribed DescribedMBean
    @@ -40,13 +39,8 @@
     import java.io.File;
     import java.io.IOException;
     
    -import java.lang.annotation.Annotation;
     import java.lang.management.ManagementFactory;
    -import java.lang.reflect.AnnotatedElement;
     import java.lang.reflect.Method;
    -import java.lang.reflect.UndeclaredThrowableException;
    -
    -import javax.management.JMException;
     import javax.management.MBeanServer;
     import javax.management.ObjectName;
     /**
    diff --git a/jdk/test/javax/management/Introspector/Described.java b/jdk/test/javax/management/Introspector/Described.java
    index 1ef62efb54c..2b9d0684755 100644
    --- a/jdk/test/javax/management/Introspector/Described.java
    +++ b/jdk/test/javax/management/Introspector/Described.java
    @@ -25,7 +25,7 @@
      *
      * Used by AnnotationSecurityTest.java
      **/
    -import java.beans.ConstructorProperties;
    +import javax.management.ConstructorParameters;
     
     /**
      * An MBean used by AnnotationSecurityTest.java
    @@ -37,7 +37,7 @@ public class Described implements DescribedMBean {
         public Described() {}
     
         @SqeDescriptorKey("ONE PARAMETER CONSTRUCTOR Described")
    -    @ConstructorProperties({"name", "unused"})
    +    @ConstructorParameters({"name", "unused"})
         public Described(@SqeDescriptorKey("CONSTRUCTOR PARAMETER name")String name,
                 @SqeDescriptorKey("CONSTRUCTOR PARAMETER unused")String unused) {
             this.name = name ;
    diff --git a/jdk/test/javax/management/Introspector/DescribedMX.java b/jdk/test/javax/management/Introspector/DescribedMX.java
    index 625cc65f8af..b6e8c2652dc 100644
    --- a/jdk/test/javax/management/Introspector/DescribedMX.java
    +++ b/jdk/test/javax/management/Introspector/DescribedMX.java
    @@ -25,7 +25,7 @@
      *
      * Used by AnnotationSecurityTest.java
      **/
    -import java.beans.ConstructorProperties;
    +import javax.management.ConstructorParameters;
     
     /**
      * An MXBean used by AnnotationSecurityTest.java
    @@ -37,7 +37,7 @@ public class DescribedMX implements DescribedMXBean {
         public DescribedMX() {}
     
         @SqeDescriptorKey("ONE PARAMETER CONSTRUCTOR DescribedMX")
    -    @ConstructorProperties({"name", "unused"})
    +    @ConstructorParameters({"name", "unused"})
         public DescribedMX(@SqeDescriptorKey("CONSTRUCTOR PARAMETER name")String name,
                 @SqeDescriptorKey("CONSTRUCTOR PARAMETER unused")String unused) {
             this.name = name ;
    diff --git a/jdk/test/javax/management/Introspector/LegacyConstructorPropertiesTest.java b/jdk/test/javax/management/Introspector/LegacyConstructorPropertiesTest.java
    new file mode 100644
    index 00000000000..4848aad5473
    --- /dev/null
    +++ b/jdk/test/javax/management/Introspector/LegacyConstructorPropertiesTest.java
    @@ -0,0 +1,106 @@
    +
    +/*
    + * Copyright (c) 2015, 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.
    + */
    +
    +import java.beans.ConstructorProperties;
    +import javax.management.ConstructorParameters;
    +import javax.management.MBeanServer;
    +import javax.management.MBeanServerFactory;
    +import javax.management.ObjectName;
    +
    +/*
    + * @test
    + * @bug 7199353
    + * @summary Asserts that 'java.beans.ConstructorProperties' annotation is still
    + *          recognized and properly handled for custom types mapped to open types.
    + *          Also, makes sure that if the same constructor is annotated by both
    + *          j.b.ConstructorProperties and j.m.ConstructorProperties annotations
    + *          only j.m.ConstructorProperties annotation is considered.
    + * @author Jaroslav Bachorik
    + * @modules java.management
    + *          java.desktop
    + * @run main LegacyConstructorPropertiesTest
    + */
    +
    +public class LegacyConstructorPropertiesTest {
    +    public static class CustomType {
    +        private String name;
    +        private int value;
    +        @ConstructorProperties({"name", "value"})
    +        public CustomType(String name, int value) {
    +            this.name = name;
    +            this.value = value;
    +        }
    +
    +        // if @java.beans.ConstructorProperties would be used
    +        // the introspector would choke on this
    +        @ConstructorProperties("noname")
    +        @ConstructorParameters("name")
    +        public CustomType(String name) {
    +            this.name = name;
    +            this.value = -1;
    +        }
    +
    +        public String getName() {
    +            return name;
    +        }
    +
    +        public void setName(String name) {
    +            this.name = name;
    +        }
    +
    +        public int getValue() {
    +            return value;
    +        }
    +
    +        public void setValue(int value) {
    +            this.value = value;
    +        }
    +    }
    +
    +    public static interface CustomMXBean {
    +        public CustomType getProp();
    +        public void setProp(CustomType prop);
    +    }
    +
    +    public static final class Custom implements CustomMXBean {
    +        private CustomType prop;
    +
    +        @Override
    +        public CustomType getProp() {
    +            return prop;
    +        }
    +
    +        @Override
    +        public void setProp(CustomType prop) {
    +            this.prop = prop;
    +        }
    +    }
    +
    +    public static void main(String[] args) throws Exception {
    +        MBeanServer mbs = MBeanServerFactory.createMBeanServer();
    +        CustomMXBean mbean = new Custom();
    +
    +        mbs.registerMBean(mbean, ObjectName.getInstance("test:type=Custom"));
    +    }
    +}
    diff --git a/jdk/test/javax/management/mxbean/AmbiguousConstructorTest.java b/jdk/test/javax/management/mxbean/AmbiguousConstructorTest.java
    index 2b251f66d26..0766d1a8050 100644
    --- a/jdk/test/javax/management/mxbean/AmbiguousConstructorTest.java
    +++ b/jdk/test/javax/management/mxbean/AmbiguousConstructorTest.java
    @@ -26,15 +26,13 @@
      * @bug 6175517 6278707
      * @summary Test that ambiguous ConstructorProperties annotations are detected.
      * @author Eamonn McManus
    - * @modules java.desktop
    - *          java.management
    + * @modules java.management
      * @run clean AmbiguousConstructorTest
      * @run build AmbiguousConstructorTest
      * @run main AmbiguousConstructorTest
      */
     
    -import java.beans.ConstructorProperties;
    -import java.io.InvalidObjectException;
    +import javax.management.ConstructorParameters;
     import javax.management.*;
     
     public class AmbiguousConstructorTest {
    @@ -76,13 +74,13 @@ public class AmbiguousConstructorTest {
             public int getC() {return 0;}
             public long getD() {return 0;}
     
    -        @ConstructorProperties({"a", "b"})
    +        @ConstructorParameters({"a", "b"})
             public Unambiguous(byte a, short b) {}
     
    -        @ConstructorProperties({"b", "c"})
    +        @ConstructorParameters({"b", "c"})
             public Unambiguous(short b, int c) {}
     
    -        @ConstructorProperties({"a", "b", "c"})
    +        @ConstructorParameters({"a", "b", "c"})
             public Unambiguous(byte a, short b, int c) {}
         }
     
    @@ -92,13 +90,13 @@ public class AmbiguousConstructorTest {
             public int getC() {return 0;}
             public long getD() {return 0;}
     
    -        @ConstructorProperties({"a", "b"})
    +        @ConstructorParameters({"a", "b"})
             public Ambiguous(byte a, short b) {}
     
    -        @ConstructorProperties({"b", "c"})
    +        @ConstructorParameters({"b", "c"})
             public Ambiguous(short b, int c) {}
     
    -        @ConstructorProperties({"a", "b", "c", "d"})
    +        @ConstructorParameters({"a", "b", "c", "d"})
             public Ambiguous(byte a, short b, int c, long d) {}
         }
     
    diff --git a/jdk/test/javax/management/mxbean/ExceptionDiagnosisTest.java b/jdk/test/javax/management/mxbean/ExceptionDiagnosisTest.java
    index 89ca763cfea..16ece4db261 100644
    --- a/jdk/test/javax/management/mxbean/ExceptionDiagnosisTest.java
    +++ b/jdk/test/javax/management/mxbean/ExceptionDiagnosisTest.java
    @@ -26,11 +26,10 @@
      * @bug 6713777
      * @summary Test that exception messages include all relevant information
      * @author Eamonn McManus
    - * @modules java.desktop
    - *          java.management
    + * @modules java.management
      */
     
    -import java.beans.ConstructorProperties;
    +import javax.management.ConstructorParameters;
     import java.io.File;
     import java.lang.reflect.InvocationTargetException;
     import java.lang.reflect.Method;
    @@ -131,7 +130,7 @@ public class ExceptionDiagnosisTest {
         }
     
         public static class CaseProb {
    -        @ConstructorProperties({"urlPath"})
    +        @ConstructorParameters({"urlPath"})
             public CaseProb(String urlPath) {}
     
             public String getURLPath() {return null;}
    diff --git a/jdk/test/javax/management/mxbean/LeakTest.java b/jdk/test/javax/management/mxbean/LeakTest.java
    index 982ec225d4b..43ac996ab5e 100644
    --- a/jdk/test/javax/management/mxbean/LeakTest.java
    +++ b/jdk/test/javax/management/mxbean/LeakTest.java
    @@ -25,8 +25,7 @@
      * @bug 6482247
      * @summary Test that creating MXBeans does not introduce memory leaks.
      * @author Eamonn McManus
    - * @modules java.desktop
    - *          java.management
    + * @modules java.management
      * @run build LeakTest RandomMXBeanTest MerlinMXBean TigerMXBean
      * @run main LeakTest
      */
    diff --git a/jdk/test/javax/management/mxbean/MXBeanTest.java b/jdk/test/javax/management/mxbean/MXBeanTest.java
    index 9017d497a0d..6123be2365e 100644
    --- a/jdk/test/javax/management/mxbean/MXBeanTest.java
    +++ b/jdk/test/javax/management/mxbean/MXBeanTest.java
    @@ -27,8 +27,7 @@
      * @summary General MXBean test.
      * @author Eamonn McManus
      * @author Jaroslav Bachorik
    - * @modules java.desktop
    - *          java.management
    + * @modules java.management
      * @run clean MXBeanTest MerlinMXBean TigerMXBean
      * @run build MXBeanTest MerlinMXBean TigerMXBean
      * @run main MXBeanTest
    diff --git a/jdk/test/javax/management/mxbean/PropertyNamesTest.java b/jdk/test/javax/management/mxbean/PropertyNamesTest.java
    index d8f6845ffd2..534f76c11d9 100644
    --- a/jdk/test/javax/management/mxbean/PropertyNamesTest.java
    +++ b/jdk/test/javax/management/mxbean/PropertyNamesTest.java
    @@ -26,14 +26,13 @@
      * @bug 6175517
      * @summary Test the PropertyNames annotation with MXBeans
      * @author Eamonn McManus
    - * @modules java.desktop
    - *          java.management
    + * @modules java.management
      * @run clean PropertyNamesTest
      * @run build PropertyNamesTest
      * @run main PropertyNamesTest
      */
     
    -import java.beans.ConstructorProperties;
    +import javax.management.ConstructorParameters;
     import java.util.Collections;
     import java.util.List;
     import javax.management.JMX;
    @@ -95,7 +94,7 @@ public class PropertyNamesTest {
         }
     
         public static class Point {
    -        @ConstructorProperties({"x", "y"})
    +        @ConstructorParameters({"x", "y"})
             public Point(int x, int y) {
                 this.x = x;
                 this.y = y;
    @@ -123,17 +122,17 @@ public class PropertyNamesTest {
         }
     
         public static class Evolve {
    -        @ConstructorProperties({"oldInt"})
    +        @ConstructorParameters({"oldInt"})
             public Evolve(int oldInt) {
                 this(oldInt, "defaultString");
             }
     
    -        @ConstructorProperties({"oldInt", "newString"})
    +        @ConstructorParameters({"oldInt", "newString"})
             public Evolve(int oldInt, String newString) {
                 this(oldInt, newString, Collections.emptyList());
             }
     
    -        @ConstructorProperties({"oldInt", "newString", "newerList"})
    +        @ConstructorParameters({"oldInt", "newString", "newerList"})
             public Evolve(int oldInt, String newString, List newerList) {
                 this.oldInt = oldInt;
                 this.newString = newString;
    diff --git a/jdk/test/javax/management/mxbean/TigerMXBean.java b/jdk/test/javax/management/mxbean/TigerMXBean.java
    index cfc47a90b2c..e4129b77806 100644
    --- a/jdk/test/javax/management/mxbean/TigerMXBean.java
    +++ b/jdk/test/javax/management/mxbean/TigerMXBean.java
    @@ -1,5 +1,5 @@
     /*
    - * Copyright (c) 2005, 2008, Oracle and/or its affiliates. All rights reserved.
    + * Copyright (c) 2005, 2015, 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
    @@ -21,7 +21,7 @@
      * questions.
      */
     
    -import java.beans.ConstructorProperties;
    +import javax.management.ConstructorParameters;
     import java.util.Arrays;
     import java.util.Collections;
     import java.util.HashSet;
    @@ -42,7 +42,7 @@ import javax.management.openmbean.TabularType;
     public interface TigerMXBean {
     
         class Point {
    -        @ConstructorProperties({"x", "y"})
    +        @ConstructorParameters({"x", "y"})
             public Point(double x, double y) {
                 this.x = x;
                 this.y = y;
    
    From 83a08bb60b91f3dd78a463f37201e322d8646f5e Mon Sep 17 00:00:00 2001
    From: Alexander Zvegintsev 
    Date: Wed, 30 Sep 2015 13:31:01 +0300
    Subject: [PATCH 06/43] 8076540: [macosx] NPE due to incorrect threading
    
    Reviewed-by: alexsch, azvegint
    ---
     jdk/test/sun/java2d/loops/CopyAreaSpeed.html |  39 +++
     jdk/test/sun/java2d/loops/CopyAreaSpeed.java | 268 +++++++++++++++++++
     2 files changed, 307 insertions(+)
     create mode 100644 jdk/test/sun/java2d/loops/CopyAreaSpeed.html
     create mode 100644 jdk/test/sun/java2d/loops/CopyAreaSpeed.java
    
    diff --git a/jdk/test/sun/java2d/loops/CopyAreaSpeed.html b/jdk/test/sun/java2d/loops/CopyAreaSpeed.html
    new file mode 100644
    index 00000000000..a60ef8caa3c
    --- /dev/null
    +++ b/jdk/test/sun/java2d/loops/CopyAreaSpeed.html
    @@ -0,0 +1,39 @@
    +
    +
    +
    +  
    +    CopyAreaSpeed
    +  
    +
    +  
    +      

    CopyAreaSpeed

    +
    +
    Thanh Nguyen
    + + +Last modified: Tue Jan 19 16:18:37 PST 1999 + + + + diff --git a/jdk/test/sun/java2d/loops/CopyAreaSpeed.java b/jdk/test/sun/java2d/loops/CopyAreaSpeed.java new file mode 100644 index 00000000000..00d1cff5c38 --- /dev/null +++ b/jdk/test/sun/java2d/loops/CopyAreaSpeed.java @@ -0,0 +1,268 @@ +/* + * Copyright (c) 2015, 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 4189070 + * @summary This test prints out the time it takes for a certain amount of + * copyArea calls to be completed. Because the performance measurement is + * relative, this code only provides a benchmark to run with different releases + * to compare the outcomes. + * @run applet/manual=done CopyAreaSpeed.html + */ + +import java.applet.Applet; +import java.awt.*; +import java.awt.event.*; +import java.util.*; + +public class CopyAreaSpeed extends Applet implements Runnable { + int top = 0; + + public void init() { + } + + public CopyAreaSpeed() + { + super(); + String[] instructions = + { + "This test prints out the time it takes for a certain amount ", + "of copyArea calls to be completed. Because the performance ", + "measurement is relative, this code only provides a benchmark ", + "to run with different releases to compare the outcomes." + }; + Sysout.createDialogWithInstructions( instructions ); + (new Thread(this)).start(); + Button bt = new Button("Hello"); + bt.setBounds(50, 10, 50, 22); + bt.setVisible(false); + add(bt); + } + + public void update(Graphics g) + { + paint(g); + } + + public void paint(Graphics g) + { + synchronized(this) { + Rectangle rct = g.getClipBounds(); + g.setColor(Color.white); + g.fillRect(rct.x, rct.y, rct.width, rct.height); + g.setFont(getFont()); + g.setColor(Color.black); + + Dimension dm = getSize(); + for (int y = 0; y <= (dm.height + 10); y += 20) { + if (y > rct.y) { + int z = y / 20 + top; + g.drawString("" + z, 10, y); + } /* endif */ + } // endfor + } + } + + static long millsec(Date s, Date e) { + long ts = s.getTime(); + long te = e.getTime(); + return te-ts; + } + + public void run() + { + int count = 1000; + int loops = count; + Date start; + Date end; + + start = new Date(); + while (count-- > 0) { + Dimension dm = getSize(); + if (dm != null && dm.width != 0 && dm.height != 0) { + synchronized(this) { + top++; + Graphics g = getGraphics(); + g.copyArea(0, 20, dm.width, dm.height - 20, 0, -20); + g.setClip(0, dm.height - 20, dm.width, 20); + paint(g); + g.dispose(); + } + } + try { + Thread.sleep(1); + } catch(Exception ex) { + ex.printStackTrace(); + } + } + end = new Date(); + Sysout.println("copyArea X "+loops+" = "+ millsec(start, end) + " msec"); + } + + public static void main(String args[]) { + Frame frm = new Frame("CopyAreaSpeed"); + frm.add(new CopyAreaSpeed()); + frm.addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent ev) { + System.exit(0); + } + }); + frm.setSize(500, 500); + frm.show(); + } +} +/**************************************************** + Standard Test Machinery + DO NOT modify anything below -- it's a standard + chunk of code whose purpose is to make user + interaction uniform, and thereby make it simpler + to read and understand someone else's test. + ****************************************************/ + +/** + This is part of the standard test machinery. + It creates a dialog (with the instructions), and is the interface + for sending text messages to the user. + To print the instructions, send an array of strings to Sysout.createDialog + WithInstructions method. Put one line of instructions per array entry. + To display a message for the tester to see, simply call Sysout.println + with the string to be displayed. + This mimics System.out.println but works within the test harness as well + as standalone. + */ +class Sysout +{ + private static TestDialog dialog; + + public static void createDialogWithInstructions( String[] instructions ) + { + dialog = new TestDialog( new Frame(), "Instructions" ); + dialog.printInstructions( instructions ); + dialog.show(); + println( "Any messages for the tester will display here." ); + } + + public static void createDialog( ) + { + dialog = new TestDialog( new Frame(), "Instructions" ); + String[] defInstr = { "Instructions will appear here. ", "" } ; + dialog.printInstructions( defInstr ); + dialog.show(); + println( "Any messages for the tester will display here." ); + } + + + public static void printInstructions( String[] instructions ) + { + dialog.printInstructions( instructions ); + } + + + public static void println( String messageIn ) + { + dialog.displayMessage( messageIn ); + } + +}// Sysout class + +/** + This is part of the standard test machinery. It provides a place for the + test instructions to be displayed, and a place for interactive messages + to the user to be displayed. + To have the test instructions displayed, see Sysout. + To have a message to the user be displayed, see Sysout. + Do not call anything in this dialog directly. + */ +class TestDialog extends Dialog +{ + + TextArea instructionsText; + TextArea messageText; + int maxStringLength = 80; + + //DO NOT call this directly, go through Sysout + public TestDialog( Frame frame, String name ) + { + super( frame, name ); + int scrollBoth = TextArea.SCROLLBARS_BOTH; + instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth ); + add( "North", instructionsText ); + + messageText = new TextArea( "", 5, maxStringLength, scrollBoth ); + add("South", messageText); + + pack(); + + show(); + }// TestDialog() + + //DO NOT call this directly, go through Sysout + public void printInstructions( String[] instructions ) + { + //Clear out any current instructions + instructionsText.setText( "" ); + + //Go down array of instruction strings + + String printStr, remainingStr; + for( int i=0; i < instructions.length; i++ ) + { + //chop up each into pieces maxSringLength long + remainingStr = instructions[ i ]; + while( remainingStr.length() > 0 ) + { + //if longer than max then chop off first max chars to print + if( remainingStr.length() >= maxStringLength ) + { + //Try to chop on a word boundary + int posOfSpace = remainingStr. + lastIndexOf( ' ', maxStringLength - 1 ); + + if( posOfSpace <= 0 ) { + posOfSpace = maxStringLength - 1; + } + + printStr = remainingStr.substring( 0, posOfSpace + 1 ); + remainingStr = remainingStr.substring( posOfSpace + 1 ); + } + else //else just print + { + printStr = remainingStr; + remainingStr = ""; + } + + instructionsText.append( printStr + "\n" ); + + }// while + + }// for + + }//printInstructions() + + //DO NOT call this directly, go through Sysout + public void displayMessage( String messageIn ) + { + messageText.append( messageIn + "\n" ); + } + +}// TestDialog class From 6a2fabcbd7bd90f2ef7e30144894dba49efcacb4 Mon Sep 17 00:00:00 2001 From: Ambarish Rapte Date: Wed, 30 Sep 2015 17:46:11 +0400 Subject: [PATCH 07/43] 8040322: TextArea.replaceRange() and insert() are broken with setText(null) Reviewed-by: serb, azvegint --- .../share/classes/java/awt/TextArea.java | 10 +- .../TextAreaEditing/TextAreaEditing.java | 145 ++++++++++++++++++ 2 files changed, 147 insertions(+), 8 deletions(-) create mode 100644 jdk/test/java/awt/TextArea/TextAreaEditing/TextAreaEditing.java diff --git a/jdk/src/java.desktop/share/classes/java/awt/TextArea.java b/jdk/src/java.desktop/share/classes/java/awt/TextArea.java index 6579a35a3d1..eab879730de 100644 --- a/jdk/src/java.desktop/share/classes/java/awt/TextArea.java +++ b/jdk/src/java.desktop/share/classes/java/awt/TextArea.java @@ -327,9 +327,8 @@ public class TextArea extends TextComponent { TextAreaPeer peer = (TextAreaPeer)this.peer; if (peer != null) { peer.insert(str, pos); - } else { - text = text.substring(0, pos) + str + text.substring(pos); } + text = text.substring(0, pos) + str + text.substring(pos); } /** @@ -355,11 +354,7 @@ public class TextArea extends TextComponent { */ @Deprecated public synchronized void appendText(String str) { - if (peer != null) { insertText(str, getText().length()); - } else { - text = text + str; - } } /** @@ -403,9 +398,8 @@ public class TextArea extends TextComponent { TextAreaPeer peer = (TextAreaPeer)this.peer; if (peer != null) { peer.replaceRange(str, start, end); - } else { - text = text.substring(0, start) + str + text.substring(end); } + text = text.substring(0, start) + str + text.substring(end); } /** diff --git a/jdk/test/java/awt/TextArea/TextAreaEditing/TextAreaEditing.java b/jdk/test/java/awt/TextArea/TextAreaEditing/TextAreaEditing.java new file mode 100644 index 00000000000..f3306784ef8 --- /dev/null +++ b/jdk/test/java/awt/TextArea/TextAreaEditing/TextAreaEditing.java @@ -0,0 +1,145 @@ +/* + * Copyright (c) 2015, 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 8040322 + @summary Test TextArea APIs replaceRange, insert, append & setText + @run main TextAreaEditing + */ + +import java.awt.Frame; +import java.awt.TextArea; + +public class TextAreaEditing { + + private int testFailCount; + private boolean isTestFail; + private StringBuilder testFailMessage; + + private Frame mainFrame; + private TextArea textArea; + + private TextAreaEditing() { + testFailMessage = new StringBuilder(); + mainFrame = new Frame(); + mainFrame.setSize(200, 200); + + textArea = new TextArea(); + mainFrame.add(textArea); + mainFrame.setVisible(true); + } + + private void dispose() { + if (mainFrame != null) { + mainFrame.dispose(); + } + } + + public static void main(String[] s) { + TextAreaEditing textArea = new TextAreaEditing(); + textArea.testReplaceRange(); + textArea.testInsert(); + textArea.testAppend(); + textArea.checkFailures(); + textArea.dispose(); + } + + private void testReplaceRange() { + textArea.setText(null); + textArea.replaceRange("Replace", 0, 0); + textArea.setText(null); + checkTest(""); + + textArea.setText("SetText"); + textArea.replaceRange("Replace", 0, 3); + checkTest("ReplaceText"); + + textArea.replaceRange("String", textArea.getText().length(), + textArea.getText().length()); + checkTest("ReplaceTextString"); + + textArea.replaceRange("String", 0, 0); + checkTest("StringReplaceTextString"); + + textArea.replaceRange("replaceRange", 0, textArea.getText().length()); + checkTest("replaceRange"); + } + + private void testInsert() { + textArea.setText(null); + textArea.insert("Insert", 0); + textArea.setText(""); + checkTest(""); + + textArea.setText("SetText"); + textArea.insert("Insert", 3); + checkTest("SetInsertText"); + + textArea.insert("Insert", 0); + checkTest("InsertSetInsertText"); + + textArea.insert("Insert", textArea.getText().length()); + checkTest("InsertSetInsertTextInsert"); + } + + private void testAppend() { + textArea.setText(null); + textArea.append("Append"); + textArea.setText(null); + checkTest(""); + + textArea.setText("SetText"); + textArea.append("Append"); + checkTest("SetTextAppend"); + + textArea.append(""); + checkTest("SetTextAppend"); + textArea.setText(""); + checkTest(""); + } + + private void checkTest(String str) { + if (str != null && !str.equals(textArea.getText())) { + testFailMessage.append("TestFail line : "); + testFailMessage.append(Thread.currentThread().getStackTrace()[2]. + getLineNumber()); + testFailMessage.append(" TextArea string : \""); + testFailMessage.append(textArea.getText()); + testFailMessage.append("\" does not match expected string : \""); + testFailMessage.append(str).append("\""); + testFailMessage.append(System.getProperty("line.separator")); + testFailCount++; + isTestFail = true; + } + } + + private void checkFailures() { + if (isTestFail) { + testFailMessage.insert(0, "Test Fail count : " + testFailCount + + System.getProperty("line.separator")); + dispose(); + throw new RuntimeException(testFailMessage.toString()); + } + } +} From e57e3d381086b25fa9631bf05b9de0b434cdffdc Mon Sep 17 00:00:00 2001 From: Alexander Scherbatiy Date: Fri, 2 Oct 2015 10:29:36 +0400 Subject: [PATCH 08/43] 8138674: Some platforms may not support showing the user-specified title in a file dialog Reviewed-by: serb --- .../share/classes/java/awt/FileDialog.java | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/jdk/src/java.desktop/share/classes/java/awt/FileDialog.java b/jdk/src/java.desktop/share/classes/java/awt/FileDialog.java index 44fa670c4f6..5b9c17d58ce 100644 --- a/jdk/src/java.desktop/share/classes/java/awt/FileDialog.java +++ b/jdk/src/java.desktop/share/classes/java/awt/FileDialog.java @@ -174,6 +174,12 @@ public class FileDialog extends Dialog { * Creates a file dialog for loading a file. The title of the * file dialog is initially empty. This is a convenience method for * FileDialog(parent, "", LOAD). + *

    + * Note: Some platforms may not support + * showing the user-specified title in a file dialog. + * In this situation, either no title will be displayed in the file dialog's + * title bar or, on some systems, the file dialog's title bar will not be + * displayed. * * @param parent the owner of the dialog * @since 1.1 @@ -187,6 +193,12 @@ public class FileDialog extends Dialog { * a file. The files shown are those in the current directory. * This is a convenience method for * FileDialog(parent, title, LOAD). + *

    + * Note: Some platforms may not support + * showing the user-specified title in a file dialog. + * In this situation, either no title will be displayed in the file dialog's + * title bar or, on some systems, the file dialog's title bar will not be + * displayed. * * @param parent the owner of the dialog * @param title the title of the dialog @@ -204,6 +216,12 @@ public class FileDialog extends Dialog { * in the current directory. If the value of * mode is SAVE, the file dialog is finding * a place to write a file. + *

    + * Note: Some platforms may not support + * showing the user-specified title in a file dialog. + * In this situation, either no title will be displayed in the file dialog's + * title bar or, on some systems, the file dialog's title bar will not be + * displayed. * * @param parent the owner of the dialog * @param title the title of the dialog @@ -224,6 +242,12 @@ public class FileDialog extends Dialog { * Creates a file dialog for loading a file. The title of the * file dialog is initially empty. This is a convenience method for * FileDialog(parent, "", LOAD). + *

    + * Note: Some platforms may not support + * showing the user-specified title in a file dialog. + * In this situation, either no title will be displayed in the file dialog's + * title bar or, on some systems, the file dialog's title bar will not be + * displayed. * * @param parent the owner of the dialog * @exception java.lang.IllegalArgumentException if the parent's @@ -245,6 +269,12 @@ public class FileDialog extends Dialog { * a file. The files shown are those in the current directory. * This is a convenience method for * FileDialog(parent, title, LOAD). + *

    + * Note: Some platforms may not support + * showing the user-specified title in a file dialog. + * In this situation, either no title will be displayed in the file dialog's + * title bar or, on some systems, the file dialog's title bar will not be + * displayed. * * @param parent the owner of the dialog * @param title the title of the dialog; a null value @@ -273,6 +303,12 @@ public class FileDialog extends Dialog { * in the current directory. If the value of * mode is SAVE, the file dialog is finding * a place to write a file. + *

    + * Note: Some platforms may not support + * showing the user-specified title in a file dialog. + * In this situation, either no title will be displayed in the file dialog's + * title bar or, on some systems, the file dialog's title bar will not be + * displayed. * * @param parent the owner of the dialog * @param title the title of the dialog; a null value @@ -300,6 +336,22 @@ public class FileDialog extends Dialog { setLayout(null); } + + /** + * {@inheritDoc} + *

    + * Note: Some platforms may not support + * showing the user-specified title in a file dialog. + * In this situation, either no title will be displayed in the file dialog's + * title bar or, on some systems, the file dialog's title bar will not be + * displayed. + */ + @Override + public void setTitle(String title) { + super.setTitle(title); + } + + /** * Constructs a name for this component. Called by getName() * when the name is null. From 8ec737728d9a759179ff8d729fcb9fa2bc1b9ca6 Mon Sep 17 00:00:00 2001 From: Rajeev Chamyal Date: Fri, 2 Oct 2015 17:12:47 +0400 Subject: [PATCH 09/43] 8067346: Swing submenu has a changed starting offset Reviewed-by: serb, alexsch --- .../plaf/windows/WindowsLookAndFeel.java | 47 +++--- .../share/classes/sun/awt/OSInfo.java | 2 + .../javax/swing/JMenu/8067346/bug8067346.java | 142 ++++++++++++++++++ 3 files changed, 171 insertions(+), 20 deletions(-) create mode 100644 jdk/test/javax/swing/JMenu/8067346/bug8067346.java diff --git a/jdk/src/java.desktop/share/classes/com/sun/java/swing/plaf/windows/WindowsLookAndFeel.java b/jdk/src/java.desktop/share/classes/com/sun/java/swing/plaf/windows/WindowsLookAndFeel.java index abdcb841f9a..16bb987de3a 100644 --- a/jdk/src/java.desktop/share/classes/com/sun/java/swing/plaf/windows/WindowsLookAndFeel.java +++ b/jdk/src/java.desktop/share/classes/com/sun/java/swing/plaf/windows/WindowsLookAndFeel.java @@ -1569,6 +1569,11 @@ public class WindowsLookAndFeel extends BasicLookAndFeel && OSInfo.getWindowsVersion().compareTo(OSInfo.WINDOWS_VISTA) >= 0; } + static boolean isOnWindows7() { + return OSInfo.getOSType() == OSInfo.OSType.WINDOWS + && OSInfo.getWindowsVersion().compareTo(OSInfo.WINDOWS_7) >= 0; + } + private void initVistaComponentDefaults(UIDefaults table) { if (! isOnVista()) { return; @@ -1638,28 +1643,30 @@ public class WindowsLookAndFeel extends BasicLookAndFeel } table.putDefaults(menuDefaults); - /* no margins */ - InsetsUIResource insets = new InsetsUIResource(0, 0, 0, 0); - for (int i = 0, j = 0; i < menuClasses.length; i++) { - String key = menuClasses[i] + ".margin"; - Object oldValue = table.get(key); - menuDefaults[j++] = key; - menuDefaults[j++] = new XPValue(insets, oldValue); - } - table.putDefaults(menuDefaults); + /*For Windows7 margin and checkIconOffset should be greater than 0 */ + if (!isOnWindows7()) { + /* no margins */ + InsetsUIResource insets = new InsetsUIResource(0, 0, 0, 0); + for (int i = 0, j = 0; i < menuClasses.length; i++) { + String key = menuClasses[i] + ".margin"; + Object oldValue = table.get(key); + menuDefaults[j++] = key; + menuDefaults[j++] = new XPValue(insets, oldValue); + } + table.putDefaults(menuDefaults); - /* set checkIcon offset */ - Integer checkIconOffsetInteger = - Integer.valueOf(0); - for (int i = 0, j = 0; i < menuClasses.length; i++) { - String key = menuClasses[i] + ".checkIconOffset"; - Object oldValue = table.get(key); - menuDefaults[j++] = key; - menuDefaults[j++] = - new XPValue(checkIconOffsetInteger, oldValue); + /* set checkIcon offset */ + Integer checkIconOffsetInteger = + Integer.valueOf(0); + for (int i = 0, j = 0; i < menuClasses.length; i++) { + String key = menuClasses[i] + ".checkIconOffset"; + Object oldValue = table.get(key); + menuDefaults[j++] = key; + menuDefaults[j++] = + new XPValue(checkIconOffsetInteger, oldValue); + } + table.putDefaults(menuDefaults); } - table.putDefaults(menuDefaults); - /* set width of the gap after check icon */ Integer afterCheckIconGap = WindowsPopupMenuUI.getSpanBeforeGutter() + WindowsPopupMenuUI.getGutterWidth() diff --git a/jdk/src/java.desktop/share/classes/sun/awt/OSInfo.java b/jdk/src/java.desktop/share/classes/sun/awt/OSInfo.java index 57226bef8ca..b5c6bd7eb89 100644 --- a/jdk/src/java.desktop/share/classes/sun/awt/OSInfo.java +++ b/jdk/src/java.desktop/share/classes/sun/awt/OSInfo.java @@ -56,6 +56,7 @@ public class OSInfo { public static final WindowsVersion WINDOWS_XP = new WindowsVersion(5, 1); public static final WindowsVersion WINDOWS_2003 = new WindowsVersion(5, 2); public static final WindowsVersion WINDOWS_VISTA = new WindowsVersion(6, 0); + public static final WindowsVersion WINDOWS_7 = new WindowsVersion(6, 1); private static final String OS_NAME = "os.name"; private static final String OS_VERSION = "os.version"; @@ -70,6 +71,7 @@ public class OSInfo { windowsVersionMap.put(WINDOWS_XP.toString(), WINDOWS_XP); windowsVersionMap.put(WINDOWS_2003.toString(), WINDOWS_2003); windowsVersionMap.put(WINDOWS_VISTA.toString(), WINDOWS_VISTA); + windowsVersionMap.put(WINDOWS_VISTA.toString(), WINDOWS_7); } private static final PrivilegedAction osTypeAction = new PrivilegedAction() { diff --git a/jdk/test/javax/swing/JMenu/8067346/bug8067346.java b/jdk/test/javax/swing/JMenu/8067346/bug8067346.java new file mode 100644 index 00000000000..ffa2fe4a034 --- /dev/null +++ b/jdk/test/javax/swing/JMenu/8067346/bug8067346.java @@ -0,0 +1,142 @@ +/* + * Copyright (c) 2015, 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 8067346 + @summary Submenu has a changed offset on Windows7 with Windows look and feel + @requires (os.family == "windows") + @run main bug8067346 + */ +import com.sun.java.swing.plaf.windows.WindowsLookAndFeel; +import java.awt.Insets; +import javax.swing.JFrame; +import javax.swing.JMenu; +import javax.swing.JMenuBar; +import javax.swing.JMenuItem; +import javax.swing.SwingUtilities; +import javax.swing.UIManager; +import javax.swing.UnsupportedLookAndFeelException; + + +public class bug8067346 { + + private JMenuBar menuBar; + private JFrame frame; + private String[] menuClasses = {"MenuItem", "Menu", + "CheckBoxMenuItem", "RadioButtonMenuItem"}; + private String MARGIN = ".margin"; + private String CHECKICONOFFSET = ".checkIconOffset"; + private static boolean runTest = true; + + public static void main(String[] args) throws Exception { + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + bug8067346 test = new bug8067346(); + try { + // set windows look and feel + UIManager.setLookAndFeel(new WindowsLookAndFeel()); + } catch (UnsupportedLookAndFeelException e) { + runTest = false; + } + if(runTest) { + test.createUI(); + test.performTest(); + test.dispose(); + } + } + }); + } + + public void createUI() { + + frame = new JFrame(); + menuBar = new JMenuBar(); + frame.setJMenuBar(menuBar); + JMenu menu, submenu; + JMenuItem menuItem; + + menu = new JMenu("A Menu"); + menuBar.add(menu); + menu.addSeparator(); + + submenu = new JMenu("A submenu"); + + menuItem = new JMenuItem("An item in the submenu"); + submenu.add(menuItem); + menu.add(submenu); + } + + public void performTest() { + try { + String errorMessage = "Incorrect value for "; + StringBuilder errorMessageBuilder = new StringBuilder(errorMessage); + boolean error = false; + int retVal = testMargin(); + if (retVal != 0) { + errorMessageBuilder.append(menuClasses[retVal]) + .append(MARGIN).append("\n"); + error = true; + } + retVal = testCheckIconOffset(); + if (retVal != 0) { + errorMessageBuilder.append(errorMessage) + .append(menuClasses[retVal]).append(CHECKICONOFFSET); + } + if (error || retVal != 0) { + throw new RuntimeException(errorMessageBuilder.toString()); + } + } finally { + dispose(); + } + } + + private int testMargin() { + + for (int inx = 0; inx < menuClasses.length; inx++) { + Insets margin = (Insets) UIManager.get(menuClasses[inx] + MARGIN); + if (margin != null && margin.bottom == 0 && margin.left == 0 + && margin.right == 0 && margin.top == 0) { + return inx + 1; + } + } + return 0; + } + + private int testCheckIconOffset() { + + for (int inx = 0; inx < menuClasses.length; inx++) { + Object checkIconOffset = UIManager.get(menuClasses[inx] + + CHECKICONOFFSET); + if (checkIconOffset != null && ((Integer) checkIconOffset) == 0) { + return inx + 1; + } + } + return 0; + } + + public void dispose() { + frame.dispose(); + } +} From 93b47119484e0bd4170e07f9f8a0806dae2ed0fb Mon Sep 17 00:00:00 2001 From: Semyon Sadetsky Date: Mon, 5 Oct 2015 15:13:14 +0300 Subject: [PATCH 10/43] 8058959: closed/java/awt/event/ComponentEvent/MovedResizedTwiceTest/MovedResizedTwiceTest.java failed automatically Reviewed-by: alexsch, serb --- .../java.desktop/unix/classes/sun/awt/X11/XDecoratedPeer.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jdk/src/java.desktop/unix/classes/sun/awt/X11/XDecoratedPeer.java b/jdk/src/java.desktop/unix/classes/sun/awt/X11/XDecoratedPeer.java index 0df07fb6fd7..d5e2a0be3cd 100644 --- a/jdk/src/java.desktop/unix/classes/sun/awt/X11/XDecoratedPeer.java +++ b/jdk/src/java.desktop/unix/classes/sun/awt/X11/XDecoratedPeer.java @@ -792,8 +792,8 @@ abstract class XDecoratedPeer extends XWindowPeer { XToolkit.awtLock(); try { updateSizeHints(rec.x, rec.y, rec.width, rec.height); - XlibWrapper.XResizeWindow(XToolkit.getDisplay(), getShell(), rec.width, rec.height); - XlibWrapper.XMoveWindow(XToolkit.getDisplay(), getShell(), rec.x, rec.y); + XlibWrapper.XMoveResizeWindow(XToolkit.getDisplay(), getShell(), + rec.x, rec.y, rec.width, rec.height); } finally { XToolkit.awtUnlock(); From 4a3dff3ee5723f53fa7453aef9b3413d2de961e5 Mon Sep 17 00:00:00 2001 From: Semyon Sadetsky Date: Mon, 5 Oct 2015 15:29:23 +0300 Subject: [PATCH 11/43] 8079595: Resizing dialog which is JWindow parent makes JVM crash Reviewed-by: alexsch, serb --- .../native/libawt/windows/awt_Component.cpp | 9 +- .../ShowChildWhileResizingTest.java | 88 +++++++++++++++++++ 2 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 jdk/test/java/awt/Frame/FrameResize/ShowChildWhileResizingTest.java diff --git a/jdk/src/java.desktop/windows/native/libawt/windows/awt_Component.cpp b/jdk/src/java.desktop/windows/native/libawt/windows/awt_Component.cpp index 07669bc9e11..6b1c1255319 100644 --- a/jdk/src/java.desktop/windows/native/libawt/windows/awt_Component.cpp +++ b/jdk/src/java.desktop/windows/native/libawt/windows/awt_Component.cpp @@ -4058,14 +4058,19 @@ HWND AwtComponent::GetProxyFocusOwner() return (HWND)NULL; } -/* Call DefWindowProc for the focus proxy, if any */ +/* Redirects message to the focus proxy, if any */ void AwtComponent::CallProxyDefWindowProc(UINT message, WPARAM wParam, LPARAM lParam, LRESULT &retVal, MsgRouting &mr) { if (mr != mrConsume) { HWND proxy = GetProxyFocusOwner(); if (proxy != NULL && ::IsWindowEnabled(proxy)) { - retVal = ComCtl32Util::GetInstance().DefWindowProc(NULL, proxy, message, wParam, lParam); + if (proxy != GetHWnd()) { + retVal = ::SendMessage(proxy, message, wParam, lParam); + } else { + retVal = ComCtl32Util::GetInstance().DefWindowProc(NULL, + proxy, message, wParam, lParam); + } mr = mrConsume; } } diff --git a/jdk/test/java/awt/Frame/FrameResize/ShowChildWhileResizingTest.java b/jdk/test/java/awt/Frame/FrameResize/ShowChildWhileResizingTest.java new file mode 100644 index 00000000000..ee722f44236 --- /dev/null +++ b/jdk/test/java/awt/Frame/FrameResize/ShowChildWhileResizingTest.java @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2015 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 8079595 + @summary Resizing dialog which is JWindow parent makes JVM crash + @author Semyon Sadetsky + */ + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.InputEvent; + +public class ShowChildWhileResizingTest { + + private static Window dialog; + private static Timer timer; + private static Point point; + + public static void main(String[] args) throws Exception { + dialog = new Frame(); + dialog.add(new JPanel()); + dialog.setVisible(true); + dialog.setBounds(100, 100, 200, 200); + SwingUtilities.invokeAndWait(new Runnable() { + @Override + public void run() { + final Window dependentWindow = new JWindow(dialog); + JPanel panel = new JPanel(); + panel.add(new JButton("button")); + dependentWindow.add(panel); + dependentWindow.setVisible(true); + dependentWindow.setBounds(0, 0, 50, 50); + timer = new Timer(100, new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + dependentWindow + .setVisible(!dependentWindow.isVisible()); + } + }); + timer.start(); + } + + }); + + Robot robot = new Robot(); + robot.setAutoDelay(5); + robot.delay(300); + SwingUtilities.invokeAndWait(new Runnable() { + @Override + public void run() { + point = dialog.getLocationOnScreen(); + } + }); + robot.mouseMove(point.x + 200 - dialog.getInsets().right/2, + point.y + 200 - dialog.getInsets().bottom/2); + robot.mousePress(InputEvent.BUTTON1_MASK); + for(int i = 0; i < 100; i++) { + robot.mouseMove(point.x + 200 + i, point.y + 200 + i); + } + robot.mouseRelease(InputEvent.BUTTON1_MASK); + timer.stop(); + dialog.dispose(); + System.out.println("ok"); + } +} From 13ee9e097fed00f39dc9f7253cc329bce136acdf Mon Sep 17 00:00:00 2001 From: Prasanta Sadhukhan Date: Mon, 5 Oct 2015 15:36:43 +0300 Subject: [PATCH 12/43] 8132985: Crash in freetypescaler.c due to double free Reviewed-by: prr, simonis --- .../native/libfontmanager/freetypeScaler.c | 25 +++--- .../FontDisposer/FontDisposeTest.java | 84 +++++++++++++++++++ 2 files changed, 95 insertions(+), 14 deletions(-) create mode 100644 jdk/test/java/awt/FontClass/FontDisposer/FontDisposeTest.java diff --git a/jdk/src/java.desktop/share/native/libfontmanager/freetypeScaler.c b/jdk/src/java.desktop/share/native/libfontmanager/freetypeScaler.c index 7ba84cada65..8f8c33139d9 100644 --- a/jdk/src/java.desktop/share/native/libfontmanager/freetypeScaler.c +++ b/jdk/src/java.desktop/share/native/libfontmanager/freetypeScaler.c @@ -60,6 +60,7 @@ typedef struct { JNIEnv* env; FT_Library library; FT_Face face; + FT_Stream faceStream; jobject font2D; jobject directBuffer; @@ -107,16 +108,10 @@ static void freeNativeResources(JNIEnv *env, FTScalerInfo* scalerInfo) { if (scalerInfo == NULL) return; - //apparently Done_Face will only close the stream - // but will not relase the memory of stream structure. - // We need to free it explicitly to avoid leak. - //Direct access to the stream field might be not ideal solution as - // it is considred to be "private". - //Alternatively we could have stored pointer to the structure - // in the scalerInfo but this will increase size of the structure - // for no good reason - stream = scalerInfo->face->stream; - + // FT_Done_Face always closes the stream, but only frees the memory + // of the data structure if it was internally allocated by FT. + // We hold on to a pointer to the stream structure if we provide it + // ourselves, so that we can free it here. FT_Done_Face(scalerInfo->face); FT_Done_FreeType(scalerInfo->library); @@ -128,10 +123,9 @@ static void freeNativeResources(JNIEnv *env, FTScalerInfo* scalerInfo) { free(scalerInfo->fontData); } - if (stream != NULL) { - free(stream); - } - + if (scalerInfo->faceStream != NULL) { + free(scalerInfo->faceStream); + } free(scalerInfo); } @@ -302,6 +296,9 @@ Java_sun_font_FreetypeFontScaler_initNativeScaler( &ft_open_args, indexInCollection, &scalerInfo->face); + if (!error) { + scalerInfo->faceStream = ftstream; + } } if (error || scalerInfo->directBuffer == NULL) { free(ftstream); diff --git a/jdk/test/java/awt/FontClass/FontDisposer/FontDisposeTest.java b/jdk/test/java/awt/FontClass/FontDisposer/FontDisposeTest.java new file mode 100644 index 00000000000..319dcbd4562 --- /dev/null +++ b/jdk/test/java/awt/FontClass/FontDisposer/FontDisposeTest.java @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2015, 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. + */ +import java.awt.Font; +import java.awt.Graphics2D; +import java.awt.font.FontRenderContext; +import java.awt.image.BufferedImage; +import java.io.FileInputStream; +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.lang.reflect.Field; +import java.lang.reflect.Method; + +import sun.font.Font2DHandle; +import sun.font.Font2D; +import sun.font.FontScaler; +import sun.font.Type1Font; + +/** + * @bug 8132985 + * @summary Tests to verify Type1 Font scaler dispose crashes + * @modules java.desktop/sun.font + */ +public class FontDisposeTest +{ + public static void main(String[] args) throws Exception + { + // The bug only happens with Type 1 fonts. The Ghostscript font files + // should be commonly available. From distro pacakge or + // ftp://ftp.gnu.org/gnu/ghostscript/gnu-gs-fonts-other-6.0.tar.gz + // Pass pfa/pfb font file as argument + String path = args[0]; + + // Load + InputStream stream = new FileInputStream(path); + Font font = Font.createFont(Font.TYPE1_FONT,stream); + + // Ensure native bits have been generated + BufferedImage img = new BufferedImage(100,100, + BufferedImage.TYPE_INT_ARGB); + Graphics2D g2d = img.createGraphics(); + FontRenderContext frc = g2d.getFontRenderContext(); + + font.getLineMetrics("derp",frc); + + // Force disposal - + // System.gc() is not sufficient. + Field font2DHandleField = Font.class.getDeclaredField("font2DHandle"); + font2DHandleField.setAccessible(true); + sun.font.Font2DHandle font2DHandle = + (sun.font.Font2DHandle)font2DHandleField.get(font); + + sun.font.Font2D font2D = font2DHandle.font2D; + sun.font.Type1Font type1Font = (sun.font.Type1Font)font2D; + + Method getScalerMethod = + sun.font.Type1Font.class.getDeclaredMethod("getScaler"); + getScalerMethod.setAccessible(true); + sun.font.FontScaler scaler = + (sun.font.FontScaler)getScalerMethod.invoke(type1Font); + + // dispose should not crash due to double free + scaler.dispose(); + } +} From 329d125db728a53dda9b316b9738958f268bdcd0 Mon Sep 17 00:00:00 2001 From: Mikhail Cherkasov Date: Tue, 6 Oct 2015 10:24:12 +0300 Subject: [PATCH 13/43] 8086038: [macosx] No available data flavors when copying from Microsoft Word for Mac Reviewed-by: serb, alexsch --- .../classes/sun/datatransfer/resources/flavormap.properties | 1 + .../macosx/classes/sun/lwawt/macosx/CDataTransferer.java | 4 +++- .../macosx/native/libawt_lwawt/awt/CDataTransferer.m | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/jdk/src/java.datatransfer/macosx/classes/sun/datatransfer/resources/flavormap.properties b/jdk/src/java.datatransfer/macosx/classes/sun/datatransfer/resources/flavormap.properties index b50c523279e..10d625fc494 100644 --- a/jdk/src/java.datatransfer/macosx/classes/sun/datatransfer/resources/flavormap.properties +++ b/jdk/src/java.datatransfer/macosx/classes/sun/datatransfer/resources/flavormap.properties @@ -74,3 +74,4 @@ RICH_TEXT=text/rtf HTML=text/html;charset=utf-8;eoln="\r\n";terminators=1 URL=application/x-java-url;class=java.net.URL,\ text/uri-list;eoln="\r\n";terminators=1 +XPICT=image/x-pict;class=java.io.InputStream diff --git a/jdk/src/java.desktop/macosx/classes/sun/lwawt/macosx/CDataTransferer.java b/jdk/src/java.desktop/macosx/classes/sun/lwawt/macosx/CDataTransferer.java index 2805211d3d1..ae1d4446c05 100644 --- a/jdk/src/java.desktop/macosx/classes/sun/lwawt/macosx/CDataTransferer.java +++ b/jdk/src/java.desktop/macosx/classes/sun/lwawt/macosx/CDataTransferer.java @@ -54,7 +54,8 @@ public class CDataTransferer extends DataTransferer { "PDF", "URL", "PNG", - "JFIF" + "JFIF", + "XPICT" }; static { @@ -78,6 +79,7 @@ public class CDataTransferer extends DataTransferer { public static final int CF_URL = 7; public static final int CF_PNG = 8; public static final int CF_JPEG = 9; + public static final int CF_XPICT = 10; private CDataTransferer() {} diff --git a/jdk/src/java.desktop/macosx/native/libawt_lwawt/awt/CDataTransferer.m b/jdk/src/java.desktop/macosx/native/libawt_lwawt/awt/CDataTransferer.m index 6a6339facfe..ed6a7c8bf67 100644 --- a/jdk/src/java.desktop/macosx/native/libawt_lwawt/awt/CDataTransferer.m +++ b/jdk/src/java.desktop/macosx/native/libawt_lwawt/awt/CDataTransferer.m @@ -56,6 +56,8 @@ NSMutableDictionary *getMappingTable() { forKey:[NSNumber numberWithLong:sun_lwawt_macosx_CDataTransferer_CF_PNG]]; [sStandardMappings setObject:(NSString*)kUTTypeJPEG forKey:[NSNumber numberWithLong:sun_lwawt_macosx_CDataTransferer_CF_JPEG]]; + [sStandardMappings setObject:NSPICTPboardType + forKey:[NSNumber numberWithLong:sun_lwawt_macosx_CDataTransferer_CF_XPICT]]; } return sStandardMappings; } From 66383b080d0979708b574ee538fc39c01ef17132 Mon Sep 17 00:00:00 2001 From: Sergey Bylokhov Date: Wed, 7 Oct 2015 19:47:35 +0300 Subject: [PATCH 14/43] 4763438: Replace uses of @beaninfo with meta facility in core j2se Reviewed-by: alexsch, erikj --- jdk/make/gensrc/GensrcSwing.gmk | 69 +----- .../share/classes/java/awt/Button.java | 6 +- .../share/classes/java/awt/Component.java | 14 -- .../share/classes/java/awt/Container.java | 10 - .../java/awt/KeyboardFocusManager.java | 14 -- .../classes/java/beans/SimpleBeanInfo.java | 65 +++++- .../accessibility/AccessibleContext.java | 26 +-- .../classes/javax/swing/AbstractButton.java | 210 +++++++----------- .../share/classes/javax/swing/Box.java | 11 +- .../share/classes/javax/swing/ImageIcon.java | 8 +- .../share/classes/javax/swing/JApplet.java | 52 ++--- .../share/classes/javax/swing/JButton.java | 37 ++- .../share/classes/javax/swing/JCheckBox.java | 30 +-- .../javax/swing/JCheckBoxMenuItem.java | 26 +-- .../classes/javax/swing/JColorChooser.java | 55 ++--- .../share/classes/javax/swing/JComboBox.java | 108 ++++----- .../share/classes/javax/swing/JComponent.java | 165 ++++++-------- .../classes/javax/swing/JDesktopPane.java | 37 ++- .../share/classes/javax/swing/JDialog.java | 66 ++---- .../classes/javax/swing/JEditorPane.java | 37 ++- .../classes/javax/swing/JFileChooser.java | 158 +++++-------- .../javax/swing/JFormattedTextField.java | 49 ++-- .../share/classes/javax/swing/JFrame.java | 70 +++--- .../classes/javax/swing/JInternalFrame.java | 147 +++++------- .../share/classes/javax/swing/JLabel.java | 138 ++++-------- .../classes/javax/swing/JLayeredPane.java | 8 +- .../share/classes/javax/swing/JList.java | 124 +++++------ .../share/classes/javax/swing/JMenu.java | 58 ++--- .../share/classes/javax/swing/JMenuBar.java | 44 ++-- .../share/classes/javax/swing/JMenuItem.java | 46 ++-- .../classes/javax/swing/JOptionPane.java | 88 +++----- .../share/classes/javax/swing/JPanel.java | 23 +- .../classes/javax/swing/JPasswordField.java | 21 +- .../share/classes/javax/swing/JPopupMenu.java | 80 +++---- .../classes/javax/swing/JProgressBar.java | 94 +++----- .../classes/javax/swing/JRadioButton.java | 25 +-- .../javax/swing/JRadioButtonMenuItem.java | 20 +- .../share/classes/javax/swing/JRootPane.java | 41 ++-- .../share/classes/javax/swing/JScrollBar.java | 78 +++---- .../classes/javax/swing/JScrollPane.java | 112 +++------- .../share/classes/javax/swing/JSeparator.java | 33 ++- .../share/classes/javax/swing/JSlider.java | 122 ++++------ .../share/classes/javax/swing/JSpinner.java | 26 +-- .../share/classes/javax/swing/JSplitPane.java | 106 ++++----- .../classes/javax/swing/JTabbedPane.java | 132 ++++------- .../share/classes/javax/swing/JTable.java | 191 +++++++--------- .../share/classes/javax/swing/JTextArea.java | 46 ++-- .../share/classes/javax/swing/JTextField.java | 52 +++-- .../share/classes/javax/swing/JTextPane.java | 19 +- .../classes/javax/swing/JToggleButton.java | 22 +- .../share/classes/javax/swing/JToolBar.java | 65 ++---- .../share/classes/javax/swing/JToolTip.java | 15 +- .../share/classes/javax/swing/JTree.java | 137 ++++++------ .../share/classes/javax/swing/JViewport.java | 23 +- .../share/classes/javax/swing/JWindow.java | 53 ++--- .../AbstractColorChooserPanel.java | 10 +- .../javax/swing/table/JTableHeader.java | 24 +- .../javax/swing/table/TableColumn.java | 56 ++--- .../javax/swing/text/JTextComponent.java | 100 ++++----- .../javax/swing/tree/AbstractLayoutCache.java | 16 +- .../swing/tree/DefaultTreeCellEditor.java | 9 +- .../swing/tree/VariableHeightLayoutCache.java | 18 +- 62 files changed, 1468 insertions(+), 2277 deletions(-) diff --git a/jdk/make/gensrc/GensrcSwing.gmk b/jdk/make/gensrc/GensrcSwing.gmk index 74b4f8a81dd..2f643d4abc2 100644 --- a/jdk/make/gensrc/GensrcSwing.gmk +++ b/jdk/make/gensrc/GensrcSwing.gmk @@ -41,71 +41,4 @@ $(SUPPORT_OUTPUTDIR)/gensrc/java.desktop/_the.generated_nimbus: $(NIMBUS_SKIN_FI GENSRC_SWING_NIMBUS := $(SUPPORT_OUTPUTDIR)/gensrc/java.desktop/_the.generated_nimbus -# -# Generate beaninfo java files -# - -BEANINFO_OUTPUTDIR := $(SUPPORT_OUTPUTDIR)/gensrc_no_docs/java.desktop -DOCLET_DATA_DIR := $(JDK_TOPDIR)/make/data/swingbeaninfo - -# javax.swing package -BEANS = AbstractButton Box JComponent JApplet JButton \ - JCheckBox JCheckBoxMenuItem JComboBox JColorChooser \ - JDesktopPane JDialog JEditorPane JFileChooser JFrame \ - JFormattedTextField JInternalFrame JLabel JLayeredPane \ - JList JMenu JMenuBar JMenuItem JOptionPane JPanel \ - JPasswordField JPopupMenu JProgressBar JRadioButton \ - JRadioButtonMenuItem JScrollBar JScrollPane JSeparator \ - JSlider JSplitPane JSpinner JTabbedPane JTable \ - JTextArea JTextField JTextPane JToggleButton JToolBar \ - JTree JWindow - -# javax.swing.text package -BEANS_TEXT = JTextComponent - -BEANS_SRC = $(BEANS:%=$(JDK_TOPDIR)/src/java.desktop/share/classes/javax/swing/%.java) \ - $(BEANS_TEXT:%=$(JDK_TOPDIR)/src/java.desktop/share/classes/javax/swing/text/%.java) - -# Dummy variable so far, in the old build system it was false by default -SWINGBEAN_DEBUG_FLAG = false -# GenDocletBeanInfo is compiled in Tools.gmk and picks up from $(BUILDTOOLS_OUTPUTDIR)/jdk_tools_classes -# LocaleDataMetaInfo needs to be generated before running this to avoid confusing errors -# in the build log. -$(BEANINFO_OUTPUTDIR)/_the.generated_beaninfo: $(BEANS_SRC) \ - $(BEANINFO_OUTPUTDIR)/javax/swing/SwingBeanInfoBase.java \ - $(BEANINFO_OUTPUTDIR)/sun/swing/BeanInfoUtils.java $(BUILD_TOOLS_JDK) - $(ECHO) Generating beaninfo - $(MKDIR) -p $(BEANINFO_OUTPUTDIR)/javax/swing - $(JAVA) -Djava.awt.headless=true $(NEW_JAVADOC) \ - -sourcepath $(call PathList,\ - $(wildcard $(JDK_TOPDIR)/src/*/*/classes) \ - $(SUPPORT_OUTPUTDIR)/gensrc/java.base) \ - -doclet build.tools.swingbeaninfo.GenDocletBeanInfo \ - -x $(SWINGBEAN_DEBUG_FLAG) -d $(BEANINFO_OUTPUTDIR)/javax/swing \ - -t $(DOCLET_DATA_DIR)/SwingBeanInfo.template \ - -docletpath $(BUILDTOOLS_OUTPUTDIR)/jdk_tools_classes \ - -XDignore.symbol.file=true \ - -classpath $(BUILDTOOLS_OUTPUTDIR)/jdk_tools_classes $(BEANS_SRC) $(LOG_INFO) - # Move the JTextComponent into its proper package directory. - $(MKDIR) -p $(BEANINFO_OUTPUTDIR)/javax/swing/text - $(MV) $(BEANINFO_OUTPUTDIR)/javax/swing/JTextComponentBeanInfo.java \ - $(BEANINFO_OUTPUTDIR)/javax/swing/text/JTextComponentBeanInfo.java - $(TOUCH) $@ - -# This file is the part of dt.jar -# For some reason it is under $(JDK_TOPDIR)/make/data/swingbeaninfo -# Should it be moved under $(JDK_TOPDIR)/src/java.desktop/share/classes/javax/swing instead? -$(BEANINFO_OUTPUTDIR)/javax/swing/SwingBeanInfoBase.java: \ - $(DOCLET_DATA_DIR)/javax/swing/SwingBeanInfoBase.java - $(call install-file) - -# This file is the part of dt.jar -# For some reason it is under $(JDK_TOPDIR)/make/data/swingbeaninfo -# Should it be moved under $(JDK_TOPDIR)/src/java.desktop/share/classes/sun/swing instead? -$(BEANINFO_OUTPUTDIR)/sun/swing/BeanInfoUtils.java: \ - $(DOCLET_DATA_DIR)/sun/swing/BeanInfoUtils.java - $(call install-file) - -GENSRC_SWING_BEANINFO = $(BEANINFO_OUTPUTDIR)/_the.generated_beaninfo - -GENSRC_JAVA_DESKTOP += $(GENSRC_SWING_BEANINFO) $(GENSRC_SWING_NIMBUS) +GENSRC_JAVA_DESKTOP += $(GENSRC_SWING_NIMBUS) diff --git a/jdk/src/java.desktop/share/classes/java/awt/Button.java b/jdk/src/java.desktop/share/classes/java/awt/Button.java index 5c92ce22486..faa8068cf8c 100644 --- a/jdk/src/java.desktop/share/classes/java/awt/Button.java +++ b/jdk/src/java.desktop/share/classes/java/awt/Button.java @@ -26,6 +26,7 @@ package java.awt; import java.awt.peer.ButtonPeer; +import java.beans.BeanProperty; import java.util.EventListener; import java.awt.event.*; import java.io.ObjectOutputStream; @@ -511,11 +512,10 @@ public class Button extends Component implements Accessible { * * @return an AccessibleAWTButton that serves as the * AccessibleContext of this Button - * @beaninfo - * expert: true - * description: The AccessibleContext associated with this Button. * @since 1.3 */ + @BeanProperty(expert = true, description + = "The AccessibleContext associated with this Button.") public AccessibleContext getAccessibleContext() { if (accessibleContext == null) { accessibleContext = new AccessibleAWTButton(); diff --git a/jdk/src/java.desktop/share/classes/java/awt/Component.java b/jdk/src/java.desktop/share/classes/java/awt/Component.java index 87bab7eac20..3c50dceecce 100644 --- a/jdk/src/java.desktop/share/classes/java/awt/Component.java +++ b/jdk/src/java.desktop/share/classes/java/awt/Component.java @@ -1763,8 +1763,6 @@ public abstract class Component implements ImageObserver, MenuContainer, * is returned * @see #setForeground * @since 1.0 - * @beaninfo - * bound: true */ @Transient public Color getForeground() { @@ -1843,8 +1841,6 @@ public abstract class Component implements ImageObserver, MenuContainer, * component will inherit the background color of its parent * @see #getBackground * @since 1.0 - * @beaninfo - * bound: true */ public void setBackground(Color c) { Color oldColor = background; @@ -1911,8 +1907,6 @@ public abstract class Component implements ImageObserver, MenuContainer, * @see #getFont * @see #invalidate * @since 1.0 - * @beaninfo - * bound: true */ public void setFont(Font f) { Font oldFont, newFont; @@ -7234,8 +7228,6 @@ public abstract class Component implements ImageObserver, MenuContainer, * @param focusable indicates whether this Component is focusable * @see #isFocusable * @since 1.4 - * @beaninfo - * bound: true */ public void setFocusable(boolean focusable) { boolean oldFocusable; @@ -7327,8 +7319,6 @@ public abstract class Component implements ImageObserver, MenuContainer, * or if any keystroke already maps to another focus traversal * operation for this Component * @since 1.4 - * @beaninfo - * bound: true */ public void setFocusTraversalKeys(int id, Set keystrokes) @@ -7479,8 +7469,6 @@ public abstract class Component implements ImageObserver, MenuContainer, * @see #setFocusTraversalKeys * @see #getFocusTraversalKeys * @since 1.4 - * @beaninfo - * bound: true */ public void setFocusTraversalKeysEnabled(boolean focusTraversalKeysEnabled) { @@ -8995,8 +8983,6 @@ public abstract class Component implements ImageObserver, MenuContainer, * @see #invalidate * * @author Laura Werner, IBM - * @beaninfo - * bound: true */ public void setComponentOrientation(ComponentOrientation o) { ComponentOrientation oldValue = componentOrientation; diff --git a/jdk/src/java.desktop/share/classes/java/awt/Container.java b/jdk/src/java.desktop/share/classes/java/awt/Container.java index 6e19e26c5d5..f3e7b3b5d6e 100644 --- a/jdk/src/java.desktop/share/classes/java/awt/Container.java +++ b/jdk/src/java.desktop/share/classes/java/awt/Container.java @@ -3131,8 +3131,6 @@ public class Container extends Component { * or if any keystroke already maps to another focus traversal * operation for this Container * @since 1.4 - * @beaninfo - * bound: true */ public void setFocusTraversalKeys(int id, Set keystrokes) @@ -3347,8 +3345,6 @@ public class Container extends Component { * @see #setFocusCycleRoot * @see #isFocusCycleRoot * @since 1.4 - * @beaninfo - * bound: true */ public void setFocusTraversalPolicy(FocusTraversalPolicy policy) { FocusTraversalPolicy oldPolicy; @@ -3427,8 +3423,6 @@ public class Container extends Component { * @see ContainerOrderFocusTraversalPolicy * @see #setFocusTraversalPolicyProvider * @since 1.4 - * @beaninfo - * bound: true */ public void setFocusCycleRoot(boolean focusCycleRoot) { boolean oldFocusCycleRoot; @@ -3472,8 +3466,6 @@ public class Container extends Component { * @see #getFocusTraversalPolicy * @see #isFocusTraversalPolicyProvider * @since 1.5 - * @beaninfo - * bound: true */ public final void setFocusTraversalPolicyProvider(boolean provider) { boolean oldProvider; @@ -3499,8 +3491,6 @@ public class Container extends Component { * @return true if this container provides focus traversal * policy, false otherwise * @since 1.5 - * @beaninfo - * bound: true */ public final boolean isFocusTraversalPolicyProvider() { return focusTraversalPolicyProvider; diff --git a/jdk/src/java.desktop/share/classes/java/awt/KeyboardFocusManager.java b/jdk/src/java.desktop/share/classes/java/awt/KeyboardFocusManager.java index 7f1c6dcd88a..75cf0e0c918 100644 --- a/jdk/src/java.desktop/share/classes/java/awt/KeyboardFocusManager.java +++ b/jdk/src/java.desktop/share/classes/java/awt/KeyboardFocusManager.java @@ -528,8 +528,6 @@ public abstract class KeyboardFocusManager * current KeyboardFocusManager for the calling thread's context * and if the calling thread does not have "replaceKeyboardFocusManager" * permission - * @beaninfo - * bound: true */ protected void setGlobalFocusOwner(Component focusOwner) throws SecurityException @@ -744,8 +742,6 @@ public abstract class KeyboardFocusManager * current KeyboardFocusManager for the calling thread's context * and if the calling thread does not have "replaceKeyboardFocusManager" * permission - * @beaninfo - * bound: true */ protected void setGlobalPermanentFocusOwner(Component permanentFocusOwner) throws SecurityException @@ -847,8 +843,6 @@ public abstract class KeyboardFocusManager * current KeyboardFocusManager for the calling thread's context * and if the calling thread does not have "replaceKeyboardFocusManager" * permission - * @beaninfo - * bound: true */ protected void setGlobalFocusedWindow(Window focusedWindow) throws SecurityException @@ -952,8 +946,6 @@ public abstract class KeyboardFocusManager * current KeyboardFocusManager for the calling thread's context * and if the calling thread does not have "replaceKeyboardFocusManager" * permission - * @beaninfo - * bound: true */ protected void setGlobalActiveWindow(Window activeWindow) throws SecurityException @@ -1008,8 +1000,6 @@ public abstract class KeyboardFocusManager * @see Container#setFocusTraversalPolicy * @see Container#getFocusTraversalPolicy * @throws IllegalArgumentException if defaultPolicy is null - * @beaninfo - * bound: true */ public void setDefaultFocusTraversalPolicy(FocusTraversalPolicy defaultPolicy) { @@ -1113,8 +1103,6 @@ public abstract class KeyboardFocusManager * represents a {@code KEY_TYPED} event, * or if any keystroke already maps * to another default focus traversal operation - * @beaninfo - * bound: true */ public void setDefaultFocusTraversalKeys(int id, @@ -1272,8 +1260,6 @@ public abstract class KeyboardFocusManager * @see #getGlobalCurrentFocusCycleRoot * @throws SecurityException if the calling thread does not have * "replaceKeyboardFocusManager" permission - * @beaninfo - * bound: true */ public void setGlobalCurrentFocusCycleRoot(Container newFocusCycleRoot) throws SecurityException diff --git a/jdk/src/java.desktop/share/classes/java/beans/SimpleBeanInfo.java b/jdk/src/java.desktop/share/classes/java/beans/SimpleBeanInfo.java index 20d23127cdf..ddef0cffad5 100644 --- a/jdk/src/java.desktop/share/classes/java/beans/SimpleBeanInfo.java +++ b/jdk/src/java.desktop/share/classes/java/beans/SimpleBeanInfo.java @@ -28,6 +28,8 @@ package java.beans; import java.awt.Image; import java.awt.Toolkit; import java.io.InputStream; +import java.security.AccessController; +import java.security.PrivilegedAction; /** * This is a support class to make it easier for people to provide @@ -41,13 +43,13 @@ import java.io.InputStream; * * @since 1.1 */ - public class SimpleBeanInfo implements BeanInfo { /** * Deny knowledge about the class and customizer of the bean. * You can override this if you wish to provide explicit info. */ + @Override public BeanDescriptor getBeanDescriptor() { return null; } @@ -56,6 +58,7 @@ public class SimpleBeanInfo implements BeanInfo { * Deny knowledge of properties. You can override this * if you wish to provide explicit property info. */ + @Override public PropertyDescriptor[] getPropertyDescriptors() { return null; } @@ -64,6 +67,7 @@ public class SimpleBeanInfo implements BeanInfo { * Deny knowledge of a default property. You can override this * if you wish to define a default property for the bean. */ + @Override public int getDefaultPropertyIndex() { return -1; } @@ -72,6 +76,7 @@ public class SimpleBeanInfo implements BeanInfo { * Deny knowledge of event sets. You can override this * if you wish to provide explicit event set info. */ + @Override public EventSetDescriptor[] getEventSetDescriptors() { return null; } @@ -80,6 +85,7 @@ public class SimpleBeanInfo implements BeanInfo { * Deny knowledge of a default event. You can override this * if you wish to define a default event for the bean. */ + @Override public int getDefaultEventIndex() { return -1; } @@ -88,6 +94,7 @@ public class SimpleBeanInfo implements BeanInfo { * Deny knowledge of methods. You can override this * if you wish to provide explicit method info. */ + @Override public MethodDescriptor[] getMethodDescriptors() { return null; } @@ -97,6 +104,7 @@ public class SimpleBeanInfo implements BeanInfo { * may override this if you want to (for example) return a * BeanInfo for a base class. */ + @Override public BeanInfo[] getAdditionalBeanInfo() { return null; } @@ -105,10 +113,63 @@ public class SimpleBeanInfo implements BeanInfo { * Claim there are no icons available. You can override * this if you want to provide icons for your bean. */ - public Image getIcon(int iconKind) { + @Override + public Image getIcon(final int iconKind) { + final BeanDescriptor descriptor = getBeanDescriptor(); + if (descriptor != null) { + final Class type = descriptor.getBeanClass(); + if (type != null && type.getClassLoader() == null + && type.getAnnotation(JavaBean.class) != null) { + final String name = type.getName(); + final int index = name.lastIndexOf('.'); + if (name.substring(0, index).equals("javax.swing")) { + final String className = type.getSimpleName(); + switch (iconKind) { + case ICON_COLOR_32x32: + return loadImage(className, "Color32.gif"); + case ICON_COLOR_16x16: + return loadImage(className, "Color16.gif"); + case ICON_MONO_32x32: + return loadImage(className, "Mono32.gif"); + case ICON_MONO_16x16: + return loadImage(className, "Mono16.gif"); + } + } + } + } return null; } + /** + * This is a utility method to help in loading standard icon images. + * + * @param resourceName A pathname relative to the directory holding the + * class file of the current class + * @return an image object. May be null if the load failed. + * @see java.beans.SimpleBeanInfo#loadImage(String) + */ + private Image loadStandardImage(final String resourceName) { + return AccessController.doPrivileged( + (PrivilegedAction) () -> loadImage(resourceName)); + } + + /** + * This is a utility method to help in loading standard icon images. + * + * @param resourceName A pathname relative to the directory holding the + * class file of the current class + * @param suffix A {@code String} containing a file suffix (e.g., + * "Color32.gif" or "Mono32.gif") + * @return an image object. May be null if the load failed. + * @see java.beans.SimpleBeanInfo#loadImage(String) + */ + private Image loadImage(final String resourceName, final String suffix) { + final String prefix = "/javax/swing/beaninfo/images/"; + final Image image = loadStandardImage(prefix + resourceName + suffix); + return image == null ? loadStandardImage(prefix + "JComponent" + suffix) + : image; + } + /** * This is a utility method to help in loading icon images. * It takes the name of a resource file associated with the diff --git a/jdk/src/java.desktop/share/classes/javax/accessibility/AccessibleContext.java b/jdk/src/java.desktop/share/classes/javax/accessibility/AccessibleContext.java index b7f584b95db..65a163fa4ca 100644 --- a/jdk/src/java.desktop/share/classes/javax/accessibility/AccessibleContext.java +++ b/jdk/src/java.desktop/share/classes/javax/accessibility/AccessibleContext.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -29,11 +29,15 @@ import sun.awt.AWTAccessor; import sun.awt.AppContext; import java.util.Locale; +import java.beans.JavaBean; +import java.beans.BeanProperty; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; import java.beans.PropertyChangeEvent; import java.awt.IllegalComponentStateException; +import javax.swing.SwingContainer; + /** * AccessibleContext represents the minimum information all accessible objects * return. This information includes the accessible name, description, role, @@ -69,17 +73,13 @@ import java.awt.IllegalComponentStateException; * minimum and maximum values. Any object that supports a numerical value * should support this interface. * - * - * @beaninfo - * attribute: isContainer false - * description: Minimal information that all accessible objects return - * - * @author Peter Korn * @author Hans Muller * @author Willie Walker * @author Lynn Monsanto */ +@JavaBean(description = "Minimal information that all accessible objects return") +@SwingContainer(false) public abstract class AccessibleContext { /** @@ -447,11 +447,9 @@ public abstract class AccessibleContext { * * @see #getAccessibleName * @see #addPropertyChangeListener - * - * @beaninfo - * preferred: true - * description: Sets the accessible name for the component. */ + @BeanProperty(preferred = true, description + = "Sets the accessible name for the component.") public void setAccessibleName(String s) { String oldName = accessibleName; accessibleName = s; @@ -483,11 +481,9 @@ public abstract class AccessibleContext { * * @see #setAccessibleName * @see #addPropertyChangeListener - * - * @beaninfo - * preferred: true - * description: Sets the accessible description for the component. */ + @BeanProperty(preferred = true, description + = "Sets the accessible description for the component.") public void setAccessibleDescription(String s) { String oldDescription = accessibleDescription; accessibleDescription = s; diff --git a/jdk/src/java.desktop/share/classes/javax/swing/AbstractButton.java b/jdk/src/java.desktop/share/classes/javax/swing/AbstractButton.java index 89da3cf30c9..64ac496c509 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/AbstractButton.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/AbstractButton.java @@ -26,23 +26,19 @@ package javax.swing; import java.awt.*; import java.awt.event.*; -import java.awt.image.*; import java.text.*; import java.awt.geom.*; +import java.beans.JavaBean; +import java.beans.BeanProperty; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.beans.Transient; import java.util.Enumeration; -import java.util.Vector; import java.io.Serializable; import javax.swing.event.*; -import javax.swing.border.*; import javax.swing.plaf.*; import javax.accessibility.*; import javax.swing.text.*; -import javax.swing.text.html.*; -import javax.swing.plaf.basic.*; -import java.util.*; /** * Defines common behaviors for buttons and menu items. @@ -73,6 +69,7 @@ import java.util.*; * @author Jeff Dinkins * @since 1.2 */ +@JavaBean(defaultProperty = "UI") @SuppressWarnings("serial") // Same-version serialization only public abstract class AbstractButton extends JComponent implements ItemSelectable, SwingConstants { @@ -251,12 +248,9 @@ public abstract class AbstractButton extends JComponent implements ItemSelectabl * @see Swing Components Supporting * Action * @since 1.6 - * @beaninfo - * bound: true - * expert: true - * description: Whether the text of the button should come from - * the Action. */ + @BeanProperty(expert = true, description + = "Whether the text of the button should come from the Action.") public void setHideActionText(boolean hideActionText) { if (hideActionText != this.hideActionText) { this.hideActionText = hideActionText; @@ -296,12 +290,9 @@ public abstract class AbstractButton extends JComponent implements ItemSelectabl * Sets the button's text. * @param text the string used to set the text * @see #getText - * @beaninfo - * bound: true - * preferred: true - * attribute: visualUpdate true - * description: The button's text. */ + @BeanProperty(preferred = true, visualUpdate = true, description + = "The button's text.") public void setText(String text) { String oldValue = this.text; this.text = text; @@ -390,12 +381,9 @@ public abstract class AbstractButton extends JComponent implements ItemSelectabl * effectively be ignored). * * @param m the space between the border and the label - * - * @beaninfo - * bound: true - * attribute: visualUpdate true - * description: The space between the button's border and the label. */ + @BeanProperty(visualUpdate = true, description + = "The space between the button's border and the label.") public void setMargin(Insets m) { // Cache the old margin if it comes from the UI if(m instanceof UIResource) { @@ -448,11 +436,9 @@ public abstract class AbstractButton extends JComponent implements ItemSelectabl * @param defaultIcon the icon used as the default image * @see #getIcon * @see #setPressedIcon - * @beaninfo - * bound: true - * attribute: visualUpdate true - * description: The button's default icon */ + @BeanProperty(visualUpdate = true, description + = "The button's default icon") public void setIcon(Icon defaultIcon) { Icon oldValue = this.defaultIcon; this.defaultIcon = defaultIcon; @@ -495,11 +481,9 @@ public abstract class AbstractButton extends JComponent implements ItemSelectabl * Sets the pressed icon for the button. * @param pressedIcon the icon used as the "pressed" image * @see #getPressedIcon - * @beaninfo - * bound: true - * attribute: visualUpdate true - * description: The pressed icon for the button. */ + @BeanProperty(visualUpdate = true, description + = "The pressed icon for the button.") public void setPressedIcon(Icon pressedIcon) { Icon oldValue = this.pressedIcon; this.pressedIcon = pressedIcon; @@ -529,11 +513,9 @@ public abstract class AbstractButton extends JComponent implements ItemSelectabl * Sets the selected icon for the button. * @param selectedIcon the icon used as the "selected" image * @see #getSelectedIcon - * @beaninfo - * bound: true - * attribute: visualUpdate true - * description: The selected icon for the button. */ + @BeanProperty(visualUpdate = true, description + = "The selected icon for the button.") public void setSelectedIcon(Icon selectedIcon) { Icon oldValue = this.selectedIcon; this.selectedIcon = selectedIcon; @@ -575,11 +557,9 @@ public abstract class AbstractButton extends JComponent implements ItemSelectabl * Sets the rollover icon for the button. * @param rolloverIcon the icon used as the "rollover" image * @see #getRolloverIcon - * @beaninfo - * bound: true - * attribute: visualUpdate true - * description: The rollover icon for the button. */ + @BeanProperty(visualUpdate = true, description + = "The rollover icon for the button.") public void setRolloverIcon(Icon rolloverIcon) { Icon oldValue = this.rolloverIcon; this.rolloverIcon = rolloverIcon; @@ -612,11 +592,9 @@ public abstract class AbstractButton extends JComponent implements ItemSelectabl * @param rolloverSelectedIcon the icon used as the * "selected rollover" image * @see #getRolloverSelectedIcon - * @beaninfo - * bound: true - * attribute: visualUpdate true - * description: The rollover selected icon for the button. */ + @BeanProperty(visualUpdate = true, description + = "The rollover selected icon for the button.") public void setRolloverSelectedIcon(Icon rolloverSelectedIcon) { Icon oldValue = this.rolloverSelectedIcon; this.rolloverSelectedIcon = rolloverSelectedIcon; @@ -664,11 +642,9 @@ public abstract class AbstractButton extends JComponent implements ItemSelectabl * Sets the disabled icon for the button. * @param disabledIcon the icon used as the disabled image * @see #getDisabledIcon - * @beaninfo - * bound: true - * attribute: visualUpdate true - * description: The disabled icon for the button. */ + @BeanProperty(visualUpdate = true, description + = "The disabled icon for the button.") public void setDisabledIcon(Icon disabledIcon) { Icon oldValue = this.disabledIcon; this.disabledIcon = disabledIcon; @@ -717,11 +693,9 @@ public abstract class AbstractButton extends JComponent implements ItemSelectabl * @param disabledSelectedIcon the icon used as the disabled * selection image * @see #getDisabledSelectedIcon - * @beaninfo - * bound: true - * attribute: visualUpdate true - * description: The disabled selection icon for the button. */ + @BeanProperty(visualUpdate = true, description + = "The disabled selection icon for the button.") public void setDisabledSelectedIcon(Icon disabledSelectedIcon) { Icon oldValue = this.disabledSelectedIcon; this.disabledSelectedIcon = disabledSelectedIcon; @@ -768,14 +742,12 @@ public abstract class AbstractButton extends JComponent implements ItemSelectabl * * @throws IllegalArgumentException if the alignment is not one of the legal * values listed above - * @beaninfo - * bound: true - * enum: TOP SwingConstants.TOP - * CENTER SwingConstants.CENTER - * BOTTOM SwingConstants.BOTTOM - * attribute: visualUpdate true - * description: The vertical alignment of the icon and text. */ + @BeanProperty(visualUpdate = true, enumerationValues = { + "SwingConstants.TOP", + "SwingConstants.CENTER", + "SwingConstants.BOTTOM"}, description + = "The vertical alignment of the icon and text.") public void setVerticalAlignment(int alignment) { if (alignment == verticalAlignment) return; int oldValue = verticalAlignment; @@ -817,16 +789,14 @@ public abstract class AbstractButton extends JComponent implements ItemSelectabl * * @throws IllegalArgumentException if the alignment is not one of the * valid values - * @beaninfo - * bound: true - * enum: LEFT SwingConstants.LEFT - * CENTER SwingConstants.CENTER - * RIGHT SwingConstants.RIGHT - * LEADING SwingConstants.LEADING - * TRAILING SwingConstants.TRAILING - * attribute: visualUpdate true - * description: The horizontal alignment of the icon and text. */ + @BeanProperty(visualUpdate = true, enumerationValues = { + "SwingConstants.LEFT", + "SwingConstants.CENTER", + "SwingConstants.RIGHT", + "SwingConstants.LEADING", + "SwingConstants.TRAILING"}, description + = "The horizontal alignment of the icon and text.") public void setHorizontalAlignment(int alignment) { if (alignment == horizontalAlignment) return; int oldValue = horizontalAlignment; @@ -860,14 +830,12 @@ public abstract class AbstractButton extends JComponent implements ItemSelectabl *

  • {@code SwingConstants.TOP} *
  • {@code SwingConstants.BOTTOM} * - * @beaninfo - * bound: true - * enum: TOP SwingConstants.TOP - * CENTER SwingConstants.CENTER - * BOTTOM SwingConstants.BOTTOM - * attribute: visualUpdate true - * description: The vertical position of the text relative to the icon. */ + @BeanProperty(visualUpdate = true, enumerationValues = { + "SwingConstants.TOP", + "SwingConstants.CENTER", + "SwingConstants.BOTTOM"}, description + = "The vertical position of the text relative to the icon.") public void setVerticalTextPosition(int textPosition) { if (textPosition == verticalTextPosition) return; int oldValue = verticalTextPosition; @@ -905,16 +873,14 @@ public abstract class AbstractButton extends JComponent implements ItemSelectabl * * @exception IllegalArgumentException if textPosition * is not one of the legal values listed above - * @beaninfo - * bound: true - * enum: LEFT SwingConstants.LEFT - * CENTER SwingConstants.CENTER - * RIGHT SwingConstants.RIGHT - * LEADING SwingConstants.LEADING - * TRAILING SwingConstants.TRAILING - * attribute: visualUpdate true - * description: The horizontal position of the text relative to the icon. */ + @BeanProperty(visualUpdate = true, enumerationValues = { + "SwingConstants.LEFT", + "SwingConstants.CENTER", + "SwingConstants.RIGHT", + "SwingConstants.LEADING", + "SwingConstants.TRAILING"}, description + = "The horizontal position of the text relative to the icon.") public void setHorizontalTextPosition(int textPosition) { if (textPosition == horizontalTextPosition) return; int oldValue = horizontalTextPosition; @@ -951,12 +917,9 @@ public abstract class AbstractButton extends JComponent implements ItemSelectabl * @param iconTextGap the space between icon and text if these properties are set. * @since 1.4 * @see #getIconTextGap - * @beaninfo - * bound: true - * attribute: visualUpdate true - * description: If both the icon and text properties are set, this - * property defines the space between them. */ + @BeanProperty(visualUpdate = true, description + = "If both the icon and text properties are set, this property defines the space between them.") public void setIconTextGap(int iconTextGap) { int oldValue = this.iconTextGap; this.iconTextGap = iconTextGap; @@ -1095,11 +1058,9 @@ public abstract class AbstractButton extends JComponent implements ItemSelectabl * @see #configurePropertiesFromAction * @see #createActionPropertyChangeListener * @see #actionPropertyChanged - * @beaninfo - * bound: true - * attribute: visualUpdate true - * description: the Action instance connected with this ActionEvent source */ + @BeanProperty(visualUpdate = true, description + = "the Action instance connected with this ActionEvent source") public void setAction(Action a) { Action oldValue = getAction(); if (action==null || !action.equals(a)) { @@ -1393,11 +1354,9 @@ public abstract class AbstractButton extends JComponent implements ItemSelectabl * @param b if true and border property is not null, * the border is painted * @see #isBorderPainted - * @beaninfo - * bound: true - * attribute: visualUpdate true - * description: Whether the border should be painted. */ + @BeanProperty(visualUpdate = true, description + = "Whether the border should be painted.") public void setBorderPainted(boolean b) { boolean oldValue = paintBorder; paintBorder = b; @@ -1443,11 +1402,9 @@ public abstract class AbstractButton extends JComponent implements ItemSelectabl * * @param b if true, the focus state should be painted * @see #isFocusPainted - * @beaninfo - * bound: true - * attribute: visualUpdate true - * description: Whether focus should be painted */ + @BeanProperty(visualUpdate = true, description + = "Whether focus should be painted") public void setFocusPainted(boolean b) { boolean oldValue = paintFocus; paintFocus = b; @@ -1486,12 +1443,9 @@ public abstract class AbstractButton extends JComponent implements ItemSelectabl * the content area is not filled * @see #isContentAreaFilled * @see #setOpaque - * @beaninfo - * bound: true - * attribute: visualUpdate true - * description: Whether the button should paint the content area - * or leave it transparent. */ + @BeanProperty(visualUpdate = true, description + = "Whether the button should paint the content area or leave it transparent.") public void setContentAreaFilled(boolean b) { boolean oldValue = contentAreaFilled; contentAreaFilled = b; @@ -1522,11 +1476,9 @@ public abstract class AbstractButton extends JComponent implements ItemSelectabl * * @param b if true, rollover effects should be painted * @see #isRolloverEnabled - * @beaninfo - * bound: true - * attribute: visualUpdate true - * description: Whether rollover effects should be enabled. */ + @BeanProperty(visualUpdate = true, description + = "Whether rollover effects should be enabled.") public void setRolloverEnabled(boolean b) { boolean oldValue = rolloverEnabled; rolloverEnabled = b; @@ -1569,12 +1521,9 @@ public abstract class AbstractButton extends JComponent implements ItemSelectabl * @param mnemonic the key code which represents the mnemonic * @see java.awt.event.KeyEvent * @see #setDisplayedMnemonicIndex - * - * @beaninfo - * bound: true - * attribute: visualUpdate true - * description: the keyboard character mnemonic */ + @BeanProperty(visualUpdate = true, description + = "the keyboard character mnemonic") public void setMnemonic(int mnemonic) { int oldValue = getMnemonic(); model.setMnemonic(mnemonic); @@ -1589,11 +1538,9 @@ public abstract class AbstractButton extends JComponent implements ItemSelectabl * * @param mnemonic a char specifying the mnemonic value * @see #setMnemonic(int) - * @beaninfo - * bound: true - * attribute: visualUpdate true - * description: the keyboard character mnemonic */ + @BeanProperty(visualUpdate = true, description + = "the keyboard character mnemonic") public void setMnemonic(char mnemonic) { int vk = (int) mnemonic; if(vk >= 'a' && vk <='z') @@ -1622,13 +1569,9 @@ public abstract class AbstractButton extends JComponent implements ItemSelectabl * @exception IllegalArgumentException will be thrown if index * is >= length of the text, or < -1 * @see #getDisplayedMnemonicIndex - * - * @beaninfo - * bound: true - * attribute: visualUpdate true - * description: the index into the String to draw the keyboard character - * mnemonic at */ + @BeanProperty(visualUpdate = true, description + = "the index into the String to draw the keyboard character mnemonic at") public void setDisplayedMnemonicIndex(int index) throws IllegalArgumentException { int oldValue = mnemonicIndex; @@ -1743,10 +1686,9 @@ public abstract class AbstractButton extends JComponent implements ItemSelectabl * Sets the model that this button represents. * @param newModel the new ButtonModel * @see #getModel - * @beaninfo - * bound: true - * description: Model that the Button uses. */ + @BeanProperty(description + = "Model that the Button uses.") public void setModel(ButtonModel newModel) { ButtonModel oldModel = getModel(); @@ -1804,12 +1746,9 @@ public abstract class AbstractButton extends JComponent implements ItemSelectabl * Sets the L&F object that renders this component. * @param ui the ButtonUI L&F object * @see #getUI - * @beaninfo - * bound: true - * hidden: true - * attribute: visualUpdate true - * description: The UI object that implements the LookAndFeel. */ + @BeanProperty(hidden = true, visualUpdate = true, description + = "The UI object that implements the LookAndFeel.") public void setUI(ButtonUI ui) { super.setUI(ui); // disabled icons are generated by the LF so they should be unset here @@ -1897,6 +1836,7 @@ public abstract class AbstractButton extends JComponent implements ItemSelectabl * array if no listeners have been added * @since 1.4 */ + @BeanProperty(bound = false) public ChangeListener[] getChangeListeners() { return listenerList.getListeners(ChangeListener.class); } @@ -1954,6 +1894,7 @@ public abstract class AbstractButton extends JComponent implements ItemSelectabl * array if no listeners have been added * @since 1.4 */ + @BeanProperty(bound = false) public ActionListener[] getActionListeners() { return listenerList.getListeners(ActionListener.class); } @@ -2122,11 +2063,10 @@ public abstract class AbstractButton extends JComponent implements ItemSelectabl * * @param label a String containing the text * @deprecated - Replaced by setText(text) - * @beaninfo - * bound: true - * description: Replace by setText(text) */ @Deprecated + @BeanProperty(description + = "Replace by setText(text)") public void setLabel(String label) { setText(label); } @@ -2155,6 +2095,7 @@ public abstract class AbstractButton extends JComponent implements ItemSelectabl * array if no listeners have been added * @since 1.4 */ + @BeanProperty(bound = false) public ItemListener[] getItemListeners() { return listenerList.getListeners(ItemListener.class); } @@ -2166,7 +2107,8 @@ public abstract class AbstractButton extends JComponent implements ItemSelectabl * @return an array containing 1 Object: the text of the button, * if the item is selected; otherwise null */ - public Object[] getSelectedObjects() { + @BeanProperty(bound = false) + public Object[] getSelectedObjects() { if (isSelected() == false) { return null; } diff --git a/jdk/src/java.desktop/share/classes/javax/swing/Box.java b/jdk/src/java.desktop/share/classes/javax/swing/Box.java index 73588b3cda6..84d98ae7fed 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/Box.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/Box.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -22,15 +22,12 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ - - package javax.swing; import java.awt.*; -import java.awt.event.*; +import java.beans.JavaBean; +import java.beans.BeanProperty; import java.beans.ConstructorProperties; -import java.util.Locale; -import java.io.Serializable; import javax.accessibility.*; /** @@ -77,6 +74,7 @@ import javax.accessibility.*; * @author Timothy Prinzing * @since 1.2 */ +@JavaBean(defaultProperty = "accessibleContext") @SuppressWarnings("serial") public class Box extends JComponent implements Accessible { @@ -413,6 +411,7 @@ public class Box extends JComponent implements Accessible { * @return an AccessibleBox that serves as the * AccessibleContext of this Box */ + @BeanProperty(bound = false) public AccessibleContext getAccessibleContext() { if (accessibleContext == null) { accessibleContext = new AccessibleBox(); diff --git a/jdk/src/java.desktop/share/classes/javax/swing/ImageIcon.java b/jdk/src/java.desktop/share/classes/javax/swing/ImageIcon.java index 8c913e17332..8a63fe74cab 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/ImageIcon.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/ImageIcon.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -27,6 +27,7 @@ package javax.swing; import java.awt.*; import java.awt.image.*; import java.beans.ConstructorProperties; +import java.beans.BeanProperty; import java.beans.Transient; import java.net.URL; @@ -567,11 +568,10 @@ public class ImageIcon implements Icon, Serializable, Accessible { * * @return an AccessibleImageIcon that serves as the * AccessibleContext of this ImageIcon - * @beaninfo - * expert: true - * description: The AccessibleContext associated with this ImageIcon. * @since 1.3 */ + @BeanProperty(expert = true, description + = "The AccessibleContext associated with this ImageIcon.") public AccessibleContext getAccessibleContext() { if (accessibleContext == null) { accessibleContext = new AccessibleImageIcon(); diff --git a/jdk/src/java.desktop/share/classes/javax/swing/JApplet.java b/jdk/src/java.desktop/share/classes/javax/swing/JApplet.java index 6a00de486d2..2d9ce397bc5 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/JApplet.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/JApplet.java @@ -33,6 +33,8 @@ import java.awt.Container; import java.awt.Graphics; import java.awt.HeadlessException; import java.awt.LayoutManager; +import java.beans.BeanProperty; +import java.beans.JavaBean; import javax.accessibility.Accessible; import javax.accessibility.AccessibleContext; @@ -87,14 +89,12 @@ import javax.accessibility.AccessibleContext; * Please see {@link java.beans.XMLEncoder}. * * @see javax.swing.RootPaneContainer - * @beaninfo - * attribute: isContainer true - * attribute: containerDelegate getContentPane - * description: Swing's Applet subclass. * * @author Arnaud Weber * @since 1.2 */ +@JavaBean(defaultProperty = "JMenuBar", description = "Swing's Applet subclass.") +@SwingContainer(delegate = "getContentPane") @SuppressWarnings("serial") // Same-version serialization only public class JApplet extends Applet implements Accessible, RootPaneContainer, @@ -203,12 +203,9 @@ public class JApplet extends Applet implements Accessible, * @see #getTransferHandler * @see java.awt.Component#setDropTarget * @since 1.6 - * - * @beaninfo - * bound: true - * hidden: true - * description: Mechanism for transfer of data into the component */ + @BeanProperty(hidden = true, description + = "Mechanism for transfer of data into the component") public void setTransferHandler(TransferHandler newHandler) { TransferHandler oldHandler = transferHandler; transferHandler = newHandler; @@ -242,11 +239,9 @@ public class JApplet extends Applet implements Accessible, * @param menuBar the menubar being placed in the applet * * @see #getJMenuBar - * - * @beaninfo - * hidden: true - * description: The menubar for accessing pulldown menus from this applet. */ + @BeanProperty(bound = false, hidden = true, description + = "The menubar for accessing pulldown menus from this applet.") public void setJMenuBar(final JMenuBar menuBar) { getRootPane().setJMenuBar(menuBar); } @@ -291,10 +286,9 @@ public class JApplet extends Applet implements Accessible, * @see #setLayout * @see #isRootPaneCheckingEnabled * @see javax.swing.RootPaneContainer - * @beaninfo - * hidden: true - * description: Whether the add and setLayout methods are forwarded */ + @BeanProperty(hidden = true, description + = "Whether the add and setLayout methods are forwarded") protected void setRootPaneCheckingEnabled(boolean enabled) { rootPaneCheckingEnabled = enabled; } @@ -377,6 +371,8 @@ public class JApplet extends Applet implements Accessible, * @see #setRootPane * @see RootPaneContainer#getRootPane */ + @BeanProperty(bound = false, hidden = true, description + = "the RootPane object for this applet.") public JRootPane getRootPane() { return rootPane; } @@ -387,10 +383,6 @@ public class JApplet extends Applet implements Accessible, * @param root the rootPane object for this applet * * @see #getRootPane - * - * @beaninfo - * hidden: true - * description: the RootPane object for this applet. */ protected void setRootPane(JRootPane root) { if(rootPane != null) { @@ -428,12 +420,9 @@ public class JApplet extends Applet implements Accessible, * exception) if the content pane parameter is null * @see #getContentPane * @see RootPaneContainer#setContentPane - * - * @beaninfo - * hidden: true - * description: The client area of the applet where child - * components are normally inserted. */ + @BeanProperty(bound = false, hidden = true, description + = "The client area of the applet where child components are normally inserted.") public void setContentPane(Container contentPane) { getRootPane().setContentPane(contentPane); } @@ -456,11 +445,9 @@ public class JApplet extends Applet implements Accessible, * * @see #getLayeredPane * @see RootPaneContainer#setLayeredPane - * - * @beaninfo - * hidden: true - * description: The pane which holds the various applet layers. */ + @BeanProperty(bound = false, hidden = true, description + = "The pane which holds the various applet layers.") public void setLayeredPane(JLayeredPane layeredPane) { getRootPane().setLayeredPane(layeredPane); } @@ -482,11 +469,9 @@ public class JApplet extends Applet implements Accessible, * * @see #getGlassPane * @see RootPaneContainer#setGlassPane - * - * @beaninfo - * hidden: true - * description: A transparent pane used for menu rendering. */ + @BeanProperty(bound = false, hidden = true, description + = "A transparent pane used for menu rendering.") public void setGlassPane(Component glassPane) { getRootPane().setGlassPane(glassPane); } @@ -496,6 +481,7 @@ public class JApplet extends Applet implements Accessible, * * @since 1.6 */ + @BeanProperty(bound = false) public Graphics getGraphics() { JComponent.getGraphicsInvoked(this); return super.getGraphics(); diff --git a/jdk/src/java.desktop/share/classes/javax/swing/JButton.java b/jdk/src/java.desktop/share/classes/javax/swing/JButton.java index 937de3adad6..dc2dcbcea32 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/JButton.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/JButton.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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,21 +24,16 @@ */ package javax.swing; +import java.beans.JavaBean; +import java.beans.BeanProperty; import java.beans.ConstructorProperties; -import java.awt.*; -import java.awt.event.*; -import java.awt.image.*; - import javax.swing.plaf.*; -import javax.swing.event.*; import javax.accessibility.*; import java.io.ObjectOutputStream; -import java.io.ObjectInputStream; import java.io.IOException; - /** * An implementation of a "push" button. *

    @@ -69,13 +64,11 @@ import java.io.IOException; * has been added to the java.beans package. * Please see {@link java.beans.XMLEncoder}. * - * @beaninfo - * attribute: isContainer false - * description: An implementation of a \"push\" button. - * * @author Jeff Dinkins * @since 1.2 */ +@JavaBean(defaultProperty = "UIClassID", description = "An implementation of a \"push\" button.") +@SwingContainer(false) @SuppressWarnings("serial") public class JButton extends AbstractButton implements Accessible { @@ -156,10 +149,9 @@ public class JButton extends AbstractButton implements Accessible { * @return the string "ButtonUI" * @see JComponent#getUIClassID * @see UIDefaults#getUI - * @beaninfo - * expert: true - * description: A string that specifies the name of the L&F class. */ + @BeanProperty(bound = false, expert = true, description + = "A string that specifies the name of the L&F class.") public String getUIClassID() { return uiClassID; } @@ -176,9 +168,9 @@ public class JButton extends AbstractButton implements Accessible { * @return the value of the defaultButton property * @see JRootPane#setDefaultButton * @see #isDefaultCapable - * @beaninfo - * description: Whether or not this button is the default button */ + @BeanProperty(bound = false, description + = "Whether or not this button is the default button") public boolean isDefaultButton() { JRootPane root = SwingUtilities.getRootPane(this); if (root != null) { @@ -211,11 +203,9 @@ public class JButton extends AbstractButton implements Accessible { * capable of being the default button on the * RootPane; otherwise false * @see #isDefaultCapable - * @beaninfo - * bound: true - * attribute: visualUpdate true - * description: Whether or not this button can be the default button */ + @BeanProperty(visualUpdate = true, description + = "Whether or not this button can be the default button") public void setDefaultCapable(boolean defaultCapable) { boolean oldDefaultCapable = this.defaultCapable; this.defaultCapable = defaultCapable; @@ -283,10 +273,9 @@ public class JButton extends AbstractButton implements Accessible { * * @return an AccessibleJButton that serves as the * AccessibleContext of this JButton - * @beaninfo - * expert: true - * description: The AccessibleContext associated with this Button. */ + @BeanProperty(bound = false, expert = true, description + = "The AccessibleContext associated with this Button.") public AccessibleContext getAccessibleContext() { if (accessibleContext == null) { accessibleContext = new AccessibleJButton(); diff --git a/jdk/src/java.desktop/share/classes/javax/swing/JCheckBox.java b/jdk/src/java.desktop/share/classes/javax/swing/JCheckBox.java index 400b8efae78..c793112f98f 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/JCheckBox.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/JCheckBox.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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,9 +24,8 @@ */ package javax.swing; -import java.awt.*; -import java.awt.event.*; -import java.beans.*; +import java.beans.JavaBean; +import java.beans.BeanProperty; import javax.swing.plaf.*; import javax.accessibility.*; @@ -35,7 +34,6 @@ import java.io.ObjectOutputStream; import java.io.ObjectInputStream; import java.io.IOException; - /** * An implementation of a check box -- an item that can be selected or * deselected, and which displays its state to the user. @@ -69,13 +67,11 @@ import java.io.IOException; * * @see JRadioButton * - * @beaninfo - * attribute: isContainer false - * description: A component which can be selected or deselected. - * * @author Jeff Dinkins * @since 1.2 */ +@JavaBean(description = "A component which can be selected or deselected.") +@SwingContainer(false) @SuppressWarnings("serial") // Same-version serialization only public class JCheckBox extends JToggleButton implements Accessible { @@ -195,12 +191,10 @@ public class JCheckBox extends JToggleButton implements Accessible { * @param b true requests that the border be painted flat; * false requests normal borders * @see #isBorderPaintedFlat - * @beaninfo - * bound: true - * attribute: visualUpdate true - * description: Whether the border is painted flat. * @since 1.3 */ + @BeanProperty(visualUpdate = true, description + = "Whether the border is painted flat.") public void setBorderPaintedFlat(boolean b) { boolean oldValue = flat; flat = b; @@ -239,10 +233,9 @@ public class JCheckBox extends JToggleButton implements Accessible { * @return the string "CheckBoxUI" * @see JComponent#getUIClassID * @see UIDefaults#getUI - * @beaninfo - * expert: true - * description: A string that specifies the name of the L&F class */ + @BeanProperty(bound = false, expert = true, description + = "A string that specifies the name of the L&F class") public String getUIClassID() { return uiClassID; } @@ -311,10 +304,9 @@ public class JCheckBox extends JToggleButton implements Accessible { * * @return an AccessibleJCheckBox that serves as the * AccessibleContext of this JCheckBox - * @beaninfo - * expert: true - * description: The AccessibleContext associated with this CheckBox. */ + @BeanProperty(bound = false, expert = true, description + = "The AccessibleContext associated with this CheckBox.") public AccessibleContext getAccessibleContext() { if (accessibleContext == null) { accessibleContext = new AccessibleJCheckBox(); diff --git a/jdk/src/java.desktop/share/classes/javax/swing/JCheckBoxMenuItem.java b/jdk/src/java.desktop/share/classes/javax/swing/JCheckBoxMenuItem.java index 4aaa4417caa..f37a6db0083 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/JCheckBoxMenuItem.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/JCheckBoxMenuItem.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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,20 +24,14 @@ */ package javax.swing; -import java.util.EventListener; - -import java.awt.*; -import java.awt.event.*; -import java.awt.image.*; +import java.beans.JavaBean; +import java.beans.BeanProperty; import java.io.ObjectOutputStream; -import java.io.ObjectInputStream; import java.io.IOException; -import javax.swing.plaf.*; import javax.accessibility.*; - /** * A menu item that can be selected or deselected. If selected, the menu * item typically appears with a checkmark next to it. If unselected or @@ -81,14 +75,12 @@ import javax.accessibility.*; * has been added to the java.beans package. * Please see {@link java.beans.XMLEncoder}. * - * @beaninfo - * attribute: isContainer false - * description: A menu item which can be selected or deselected. - * * @author Georges Saab * @author David Karlton * @since 1.2 */ +@JavaBean(description = "A menu item which can be selected or deselected.") +@SwingContainer(false) @SuppressWarnings("serial") // Same-version serialization only public class JCheckBoxMenuItem extends JMenuItem implements SwingConstants, Accessible @@ -178,6 +170,7 @@ public class JCheckBoxMenuItem extends JMenuItem implements SwingConstants, * @see JComponent#getUIClassID * @see UIDefaults#getUI */ + @BeanProperty(bound = false) public String getUIClassID() { return uiClassID; } @@ -200,10 +193,9 @@ public class JCheckBoxMenuItem extends JMenuItem implements SwingConstants, * * @param b a boolean value indicating the item's * selected-state, where true=selected - * @beaninfo - * description: The selection state of the check box menu item - * hidden: true */ + @BeanProperty(bound = false, hidden = true, description + = "The selection state of the check box menu item") public synchronized void setState(boolean b) { setSelected(b); } @@ -216,6 +208,7 @@ public class JCheckBoxMenuItem extends JMenuItem implements SwingConstants, * @return an array containing one Object -- the text of the menu item * -- if the item is selected; otherwise null */ + @BeanProperty(bound = false) public Object[] getSelectedObjects() { if (isSelected() == false) return null; @@ -274,6 +267,7 @@ public class JCheckBoxMenuItem extends JMenuItem implements SwingConstants, * @return an AccessibleJCheckBoxMenuItem that serves as the * AccessibleContext of this AccessibleJCheckBoxMenuItem */ + @BeanProperty(bound = false) public AccessibleContext getAccessibleContext() { if (accessibleContext == null) { accessibleContext = new AccessibleJCheckBoxMenuItem(); diff --git a/jdk/src/java.desktop/share/classes/javax/swing/JColorChooser.java b/jdk/src/java.desktop/share/classes/javax/swing/JColorChooser.java index d7300157e02..1e524c4dd66 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/JColorChooser.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/JColorChooser.java @@ -22,11 +22,12 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ - package javax.swing; import java.awt.*; import java.awt.event.*; +import java.beans.JavaBean; +import java.beans.BeanProperty; import java.io.*; import java.util.*; @@ -36,7 +37,6 @@ import javax.accessibility.*; import sun.swing.SwingUtilities2; - /** * JColorChooser provides a pane of controls designed to allow * a user to manipulate and select a color. @@ -73,17 +73,13 @@ import sun.swing.SwingUtilities2; * has been added to the java.beans package. * Please see {@link java.beans.XMLEncoder}. * - * - * @beaninfo - * attribute: isContainer false - * description: A component that supports selecting a Color. - * - * * @author James Gosling * @author Amy Fowler * @author Steve Wilson * @since 1.2 */ +@JavaBean(defaultProperty = "UI", description = "A component that supports selecting a Color.") +@SwingContainer(false) @SuppressWarnings("serial") // Same-version serialization only public class JColorChooser extends JComponent implements Accessible { @@ -261,12 +257,9 @@ public class JColorChooser extends JComponent implements Accessible { * * @param ui the ColorChooserUI L&F object * @see UIDefaults#getUI - * - * @beaninfo - * bound: true - * hidden: true - * description: The UI object that implements the color chooser's LookAndFeel. */ + @BeanProperty(hidden = true, description + = "The UI object that implements the color chooser's LookAndFeel.") public void setUI(ColorChooserUI ui) { super.setUI(ui); } @@ -289,6 +282,7 @@ public class JColorChooser extends JComponent implements Accessible { * @see JComponent#getUIClassID * @see UIDefaults#getUI */ + @BeanProperty(bound = false) public String getUIClassID() { return uiClassID; } @@ -308,12 +302,9 @@ public class JColorChooser extends JComponent implements Accessible { * The ColorSelectionModel will fire a ChangeEvent * @param color the color to be set in the color chooser * @see JComponent#addPropertyChangeListener - * - * @beaninfo - * bound: false - * hidden: false - * description: The current color the chooser is to display. */ + @BeanProperty(bound = false, description + = "The current color the chooser is to display.") public void setColor(Color color) { selectionModel.setSelectedColor(color); @@ -381,11 +372,9 @@ public class JColorChooser extends JComponent implements Accessible { * @see #getDragEnabled * @see #setTransferHandler * @see TransferHandler - * - * @beaninfo - * description: Determines whether automatic drag handling is enabled. - * bound: false */ + @BeanProperty(bound = false, description + = "Determines whether automatic drag handling is enabled.") public void setDragEnabled(boolean b) { if (b && GraphicsEnvironment.isHeadless()) { throw new HeadlessException(); @@ -411,12 +400,9 @@ public class JColorChooser extends JComponent implements Accessible { * * @param preview the JComponent which displays the current color * @see JComponent#addPropertyChangeListener - * - * @beaninfo - * bound: true - * hidden: true - * description: The UI component which displays the current color. */ + @BeanProperty(hidden = true, description + = "The UI component which displays the current color.") public void setPreviewPanel(JComponent preview) { if (previewPanel != preview) { @@ -496,12 +482,9 @@ public class JColorChooser extends JComponent implements Accessible { * * @param panels an array of AbstractColorChooserPanel * objects - * - * @beaninfo - * bound: true - * hidden: true - * description: An array of different chooser types. */ + @BeanProperty(hidden = true, description + = "An array of different chooser types.") public void setChooserPanels( AbstractColorChooserPanel[] panels) { AbstractColorChooserPanel[] oldValue = chooserPanels; chooserPanels = panels; @@ -531,12 +514,9 @@ public class JColorChooser extends JComponent implements Accessible { * Sets the model containing the selected color. * * @param newModel the new ColorSelectionModel object - * - * @beaninfo - * bound: true - * hidden: true - * description: The model which contains the currently selected color. */ + @BeanProperty(hidden = true, description + = "The model which contains the currently selected color.") public void setSelectionModel(ColorSelectionModel newModel ) { ColorSelectionModel oldModel = selectionModel; selectionModel = newModel; @@ -603,6 +583,7 @@ public class JColorChooser extends JComponent implements Accessible { * @return an AccessibleJColorChooser that serves as the * AccessibleContext of this JColorChooser */ + @BeanProperty(bound = false) public AccessibleContext getAccessibleContext() { if (accessibleContext == null) { accessibleContext = new AccessibleJColorChooser(); diff --git a/jdk/src/java.desktop/share/classes/javax/swing/JComboBox.java b/jdk/src/java.desktop/share/classes/javax/swing/JComboBox.java index b8aff5ab832..17d9e64d91f 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/JComboBox.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/JComboBox.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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,6 +24,8 @@ */ package javax.swing; +import java.beans.JavaBean; +import java.beans.BeanProperty; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.beans.Transient; @@ -71,14 +73,12 @@ import javax.accessibility.*; * * @param the type of the elements of this combo box * - * @beaninfo - * attribute: isContainer false - * description: A combination of a text field and a drop-down list. - * * @author Arnaud Weber * @author Mark Davidson * @since 1.2 */ +@JavaBean(defaultProperty = "UI", description = "A combination of a text field and a drop-down list.") +@SwingContainer(false) @SuppressWarnings("serial") // Same-version serialization only public class JComboBox extends JComponent implements ItemSelectable,ListDataListener,ActionListener, Accessible { @@ -255,13 +255,9 @@ implements ItemSelectable,ListDataListener,ActionListener, Accessible { * * @param ui the ComboBoxUI L&F object * @see UIDefaults#getUI - * - * @beaninfo - * bound: true - * hidden: true - * attribute: visualUpdate true - * description: The UI object that implements the Component's LookAndFeel. */ + @BeanProperty(hidden = true, visualUpdate = true, description + = "The UI object that implements the Component's LookAndFeel.") public void setUI(ComboBoxUI ui) { super.setUI(ui); } @@ -288,6 +284,7 @@ implements ItemSelectable,ListDataListener,ActionListener, Accessible { * @see JComponent#getUIClassID * @see UIDefaults#getUI */ + @BeanProperty(bound = false) public String getUIClassID() { return uiClassID; } @@ -308,11 +305,9 @@ implements ItemSelectable,ListDataListener,ActionListener, Accessible { * * @param aModel the ComboBoxModel that provides the * displayed list of items - * - * @beaninfo - * bound: true - * description: Model that the combo box uses to get data to display. */ + @BeanProperty(description + = "Model that the combo box uses to get data to display.") public void setModel(ComboBoxModel aModel) { ComboBoxModel oldModel = dataModel; if (oldModel != null) { @@ -363,12 +358,9 @@ implements ItemSelectable,ListDataListener,ActionListener, Accessible { * This method fires a property changed event. * * @param aFlag if true, lightweight popups are desired - * - * @beaninfo - * bound: true - * expert: true - * description: Set to false to require heavyweight popups. */ + @BeanProperty(expert = true, description + = "Set to false to require heavyweight popups.") public void setLightWeightPopupEnabled(boolean aFlag) { boolean oldFlag = lightWeightPopupEnabled; lightWeightPopupEnabled = aFlag; @@ -398,12 +390,9 @@ implements ItemSelectable,ListDataListener,ActionListener, Accessible { * * @param aFlag a boolean value, where true indicates that the * field is editable - * - * @beaninfo - * bound: true - * preferred: true - * description: If true, the user can type a new value in the combo box. */ + @BeanProperty(preferred = true, description + = "If true, the user can type a new value in the combo box.") public void setEditable(boolean aFlag) { boolean oldFlag = isEditable; isEditable = aFlag; @@ -427,11 +416,9 @@ implements ItemSelectable,ListDataListener,ActionListener, Accessible { * * @param count an integer specifying the maximum number of items to * display in the list before using a scrollbar - * @beaninfo - * bound: true - * preferred: true - * description: The maximum number of rows the popup should have */ + @BeanProperty(preferred = true, description + = "The maximum number of rows the popup should have") public void setMaximumRowCount(int count) { int oldCount = maximumRowCount; maximumRowCount = count; @@ -465,11 +452,9 @@ implements ItemSelectable,ListDataListener,ActionListener, Accessible { * @param aRenderer the ListCellRenderer that * displays the selected item * @see #setEditor - * @beaninfo - * bound: true - * expert: true - * description: The renderer that paints the item selected in the list. */ + @BeanProperty(expert = true, description + = "The renderer that paints the item selected in the list.") public void setRenderer(ListCellRenderer aRenderer) { ListCellRenderer oldRenderer = renderer; renderer = aRenderer; @@ -497,11 +482,9 @@ implements ItemSelectable,ListDataListener,ActionListener, Accessible { * @param anEditor the ComboBoxEditor that * displays the selected item * @see #setRenderer - * @beaninfo - * bound: true - * expert: true - * description: The editor that combo box uses to edit the current value */ + @BeanProperty(expert = true, description + = "The editor that combo box uses to edit the current value") public void setEditor(ComboBoxEditor anEditor) { ComboBoxEditor oldEditor = editor; @@ -553,10 +536,9 @@ implements ItemSelectable,ListDataListener,ActionListener, Accessible { * * @param anObject the list object to select; use null to clear the selection - * @beaninfo - * preferred: true - * description: Sets the selected item in the JComboBox. */ + @BeanProperty(bound = false, preferred = true, description + = "Sets the selected item in the JComboBox.") public void setSelectedItem(Object anObject) { Object oldSelection = selectedItemReminder; Object objectToSelect = anObject; @@ -618,10 +600,9 @@ implements ItemSelectable,ListDataListener,ActionListener, Accessible { * where 0 specifies the first item in the list and -1 indicates no selection * @exception IllegalArgumentException if anIndex < -1 or * anIndex is greater than or equal to size - * @beaninfo - * preferred: true - * description: The item at index is selected. */ + @BeanProperty(bound = false, preferred = true, description + = "The item at index is selected.") public void setSelectedIndex(int anIndex) { int size = dataModel.getSize(); @@ -689,11 +670,9 @@ implements ItemSelectable,ListDataListener,ActionListener, Accessible { * @param prototypeDisplayValue the prototype display value * @see #getPrototypeDisplayValue * @since 1.4 - * @beaninfo - * bound: true - * attribute: visualUpdate true - * description: The display prototype value, used to compute display width and height. */ + @BeanProperty(visualUpdate = true, description + = "The display prototype value, used to compute display width and height.") public void setPrototypeDisplayValue(E prototypeDisplayValue) { Object oldValue = this.prototypeDisplayValue; this.prototypeDisplayValue = prototypeDisplayValue; @@ -869,6 +848,7 @@ implements ItemSelectable,ListDataListener,ActionListener, Accessible { * array if no listeners have been added * @since 1.4 */ + @BeanProperty(bound = false) public ItemListener[] getItemListeners() { return listenerList.getListeners(ItemListener.class); } @@ -907,6 +887,7 @@ implements ItemSelectable,ListDataListener,ActionListener, Accessible { * array if no listeners have been added * @since 1.4 */ + @BeanProperty(bound = false) public ActionListener[] getActionListeners() { return listenerList.getListeners(ActionListener.class); } @@ -946,6 +927,7 @@ implements ItemSelectable,ListDataListener,ActionListener, Accessible { * array if no listeners have been added * @since 1.4 */ + @BeanProperty(bound = false) public PopupMenuListener[] getPopupMenuListeners() { return listenerList.getListeners(PopupMenuListener.class); } @@ -1074,11 +1056,9 @@ implements ItemSelectable,ListDataListener,ActionListener, Accessible { * @see #configurePropertiesFromAction * @see #createActionPropertyChangeListener * @see #actionPropertyChanged - * @beaninfo - * bound: true - * attribute: visualUpdate true - * description: the Action instance connected with this ActionEvent source */ + @BeanProperty(visualUpdate = true, description + = "the Action instance connected with this ActionEvent source") public void setAction(Action a) { Action oldValue = getAction(); if (action==null || !action.equals(a)) { @@ -1305,6 +1285,7 @@ implements ItemSelectable,ListDataListener,ActionListener, Accessible { * @return an array of Objects containing one * element -- the selected item */ + @BeanProperty(bound = false) public Object[] getSelectedObjects() { Object selectedObject = getSelectedItem(); if ( selectedObject == null ) @@ -1394,11 +1375,9 @@ implements ItemSelectable,ListDataListener,ActionListener, Accessible { * * @param b a boolean value, where true enables the component and * false disables it - * @beaninfo - * bound: true - * preferred: true - * description: Whether the combo box is enabled. */ + @BeanProperty(preferred = true, description + = "The enabled state of the component.") public void setEnabled(boolean b) { super.setEnabled(b); firePropertyChange( "enabled", !isEnabled(), isEnabled() ); @@ -1458,10 +1437,9 @@ implements ItemSelectable,ListDataListener,ActionListener, Accessible { * character becomes the selected item. * * @param aManager a key selection manager - * @beaninfo - * expert: true - * description: The objects that changes the selection when a key is pressed. */ + @BeanProperty(bound = false, expert = true, description + = "The objects that changes the selection when a key is pressed.") public void setKeySelectionManager(KeySelectionManager aManager) { keySelectionManager = aManager; } @@ -1481,6 +1459,7 @@ implements ItemSelectable,ListDataListener,ActionListener, Accessible { * * @return an integer equal to the number of items in the list */ + @BeanProperty(bound = false) public int getItemCount() { return dataModel.getSize(); } @@ -1629,6 +1608,7 @@ implements ItemSelectable,ListDataListener,ActionListener, Accessible { * @return an AccessibleJComboBox that serves as the * AccessibleContext of this JComboBox */ + @BeanProperty(bound = false) public AccessibleContext getAccessibleContext() { if ( accessibleContext == null ) { accessibleContext = new AccessibleJComboBox(); @@ -2131,11 +2111,9 @@ implements ItemSelectable,ListDataListener,ActionListener, Accessible { * * @see #getAccessibleName * @see #addPropertyChangeListener - * - * @beaninfo - * preferred: true - * description: Sets the accessible name for the component. */ + @BeanProperty(preferred = true, description + = "Sets the accessible name for the component.") public void setAccessibleName(String s) { ac.setAccessibleName(s); } @@ -2165,11 +2143,9 @@ implements ItemSelectable,ListDataListener,ActionListener, Accessible { * * @see #setAccessibleName * @see #addPropertyChangeListener - * - * @beaninfo - * preferred: true - * description: Sets the accessible description for the component. */ + @BeanProperty(preferred = true, description + = "Sets the accessible description for the component.") public void setAccessibleDescription(String s) { ac.setAccessibleDescription(s); } diff --git a/jdk/src/java.desktop/share/classes/javax/swing/JComponent.java b/jdk/src/java.desktop/share/classes/javax/swing/JComponent.java index 7c85698cc9f..3276d534a48 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/JComponent.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/JComponent.java @@ -25,6 +25,7 @@ package javax.swing; +import java.beans.*; import java.util.HashSet; import java.util.Hashtable; import java.util.Enumeration; @@ -36,10 +37,6 @@ import java.util.Set; import java.awt.*; import java.awt.event.*; import java.awt.peer.LightweightPeer; -import java.beans.PropertyChangeListener; -import java.beans.VetoableChangeListener; -import java.beans.VetoableChangeSupport; -import java.beans.Transient; import java.applet.Applet; @@ -176,6 +173,7 @@ import sun.swing.UIClientPropertyKey; * @author Arnaud Weber * @since 1.2 */ +@JavaBean(defaultProperty = "UIClassID") @SuppressWarnings("serial") // Same-version serialization only public abstract class JComponent extends Container implements Serializable, TransferHandler.HasGetTransferHandler @@ -479,11 +477,10 @@ public abstract class JComponent extends Container implements Serializable, * * @param value whether or not the JPopupMenu is inherited * @see #setComponentPopupMenu - * @beaninfo - * bound: true - * description: Whether or not the JPopupMenu is inherited * @since 1.5 */ + @BeanProperty(description + = "Whether or not the JPopupMenu is inherited") public void setInheritsPopupMenu(boolean value) { boolean oldValue = getFlag(INHERITS_POPUP_MENU); setFlag(INHERITS_POPUP_MENU, value); @@ -519,12 +516,10 @@ public abstract class JComponent extends Container implements Serializable, * @param popup - the popup that will be assigned to this component * may be null * @see #getComponentPopupMenu - * @beaninfo - * bound: true - * preferred: true - * description: Popup to show * @since 1.5 */ + @BeanProperty(preferred = true, description + = "Popup to show") public void setComponentPopupMenu(JPopupMenu popup) { if(popup != null) { enableEvents(AWTEvent.MOUSE_EVENT_MASK); @@ -649,12 +644,9 @@ public abstract class JComponent extends Container implements Serializable, * @see #updateUI * @see UIManager#getLookAndFeel * @see UIManager#getUI - * @beaninfo - * bound: true - * hidden: true - * attribute: visualUpdate true - * description: The component's look and feel delegate. */ + @BeanProperty(hidden = true, visualUpdate = true, description + = "The component's look and feel delegate.") protected void setUI(ComponentUI newUI) { /* We do not check that the UI instance is different * before allowing the switch in order to enable the @@ -718,10 +710,9 @@ public abstract class JComponent extends Container implements Serializable, * @return the UIDefaults key for a * ComponentUI subclass * @see UIDefaults#getUI - * @beaninfo - * expert: true - * description: UIClassID */ + @BeanProperty(bound = false, expert = true, description + = "UIClassID") public String getUIClassID() { return uiClassID; } @@ -1265,6 +1256,7 @@ public abstract class JComponent extends Container implements Serializable, * @return true if the component is currently painting a tile, * false otherwise */ + @BeanProperty(bound = false) public boolean isPaintingTile() { return getFlag(IS_PAINTING_TILE); } @@ -1295,6 +1287,7 @@ public abstract class JComponent extends Container implements Serializable, * @see #print * @since 1.6 */ + @BeanProperty(bound = false) public final boolean isPaintingForPrint() { return getFlag(IS_PRINTING); } @@ -1319,6 +1312,7 @@ public abstract class JComponent extends Container implements Serializable, * Container.setFocusCycleRoot(boolean). */ @Deprecated + @BeanProperty(bound = false) public boolean isManagingFocus() { return false; } @@ -1589,11 +1583,9 @@ public abstract class JComponent extends Container implements Serializable, * @see #getVerifyInputWhenFocusTarget * * @since 1.3 - * @beaninfo - * bound: true - * description: Whether the Component verifies input before accepting - * focus. */ + @BeanProperty(description + = "Whether the Component verifies input before accepting focus.") public void setVerifyInputWhenFocusTarget(boolean verifyInputWhenFocusTarget) { boolean oldVerifyInputWhenFocusTarget = @@ -1641,11 +1633,9 @@ public abstract class JComponent extends Container implements Serializable, * Sets the preferred size of this component. * If preferredSize is null, the UI will * be asked for the preferred size. - * @beaninfo - * preferred: true - * bound: true - * description: The preferred size of the component. */ + @BeanProperty(preferred = true, description + = "The preferred size of the component.") public void setPreferredSize(Dimension preferredSize) { super.setPreferredSize(preferredSize); } @@ -1685,10 +1675,9 @@ public abstract class JComponent extends Container implements Serializable, * @param maximumSize a Dimension containing the * desired maximum allowable size * @see #getMaximumSize - * @beaninfo - * bound: true - * description: The maximum size of the component. */ + @BeanProperty(description + = "The maximum size of the component.") public void setMaximumSize(Dimension maximumSize) { super.setMaximumSize(maximumSize); } @@ -1726,10 +1715,9 @@ public abstract class JComponent extends Container implements Serializable, * * @param minimumSize the new minimum size of this component * @see #getMinimumSize - * @beaninfo - * bound: true - * description: The minimum size of the component. */ + @BeanProperty(description + = "The minimum size of the component.") public void setMinimumSize(Dimension minimumSize) { super.setMinimumSize(minimumSize); } @@ -1793,12 +1781,9 @@ public abstract class JComponent extends Container implements Serializable, * @param border the border to be rendered for this component * @see Border * @see CompoundBorder - * @beaninfo - * bound: true - * preferred: true - * attribute: visualUpdate true - * description: The component's border. */ + @BeanProperty(preferred = true, visualUpdate = true, description + = "The component's border.") public void setBorder(Border border) { Border oldBorder = this.border; @@ -1831,6 +1816,7 @@ public abstract class JComponent extends Container implements Serializable, * @return the value of the insets property * @see #setBorder */ + @BeanProperty(expert = true) public Insets getInsets() { if (border != null) { return border.getBorderInsets(this); @@ -1849,8 +1835,6 @@ public abstract class JComponent extends Container implements Serializable, * @param insets the Insets object, which can be reused * @return the Insets object * @see #getInsets - * @beaninfo - * expert: true */ public Insets getInsets(Insets insets) { if (insets == null) { @@ -1892,9 +1876,9 @@ public abstract class JComponent extends Container implements Serializable, * * @param alignmentY the new vertical alignment * @see #getAlignmentY - * @beaninfo - * description: The preferred vertical alignment of the component. */ + @BeanProperty(description + = "The preferred vertical alignment of the component.") public void setAlignmentY(float alignmentY) { this.alignmentY = validateAlignment(alignmentY); isAlignmentYSet = true; @@ -1921,9 +1905,9 @@ public abstract class JComponent extends Container implements Serializable, * * @param alignmentX the new horizontal alignment * @see #getAlignmentX - * @beaninfo - * description: The preferred horizontal alignment of the component. */ + @BeanProperty(description + = "The preferred horizontal alignment of the component.") public void setAlignmentX(float alignmentX) { this.alignmentX = validateAlignment(alignmentX); isAlignmentXSet = true; @@ -1939,10 +1923,9 @@ public abstract class JComponent extends Container implements Serializable, * @param inputVerifier the new input verifier * @since 1.3 * @see InputVerifier - * @beaninfo - * bound: true - * description: The component's input verifier. */ + @BeanProperty(description + = "The component's input verifier.") public void setInputVerifier(InputVerifier inputVerifier) { InputVerifier oldInputVerifier = (InputVerifier)getClientProperty( JComponent_INPUT_VERIFIER); @@ -1967,6 +1950,7 @@ public abstract class JComponent extends Container implements Serializable, * then invoke operations on that object to draw on the component. * @return this components graphics context */ + @BeanProperty(bound = false) public Graphics getGraphics() { if (DEBUG_GRAPHICS_LOADED && shouldDebugGraphics() != 0) { DebugGraphics graphics = new DebugGraphics(super.getGraphics(), @@ -1993,15 +1977,13 @@ public abstract class JComponent extends Container implements Serializable, *

  • A value of 0 causes no changes to the debugging options. * * debugOptions is bitwise OR'd into the current value - * - * @beaninfo - * preferred: true - * enum: NONE_OPTION DebugGraphics.NONE_OPTION - * LOG_OPTION DebugGraphics.LOG_OPTION - * FLASH_OPTION DebugGraphics.FLASH_OPTION - * BUFFERED_OPTION DebugGraphics.BUFFERED_OPTION - * description: Diagnostic options for graphics operations. */ + @BeanProperty(bound = false, preferred = true, enumerationValues = { + "DebugGraphics.NONE_OPTION", + "DebugGraphics.LOG_OPTION", + "DebugGraphics.FLASH_OPTION", + "DebugGraphics.BUFFERED_OPTION"}, description + = "Diagnostic options for graphics operations.") public void setDebugGraphicsOptions(int debugOptions) { DebugGraphics.setDebugOptions(this, debugOptions); } @@ -2278,6 +2260,7 @@ public abstract class JComponent extends Container implements Serializable, * @return an array of KeyStroke objects * @see #registerKeyboardAction */ + @BeanProperty(bound = false) public KeyStroke[] getRegisteredKeyStrokes() { int[] counts = new int[3]; KeyStroke[][] strokes = new KeyStroke[3][]; @@ -2616,6 +2599,7 @@ public abstract class JComponent extends Container implements Serializable, * @see #getBaseline(int, int) * @since 1.6 */ + @BeanProperty(bound = false) public BaselineResizeBehavior getBaselineResizeBehavior() { if (ui != null) { return ui.getBaselineResizeBehavior(this); @@ -2666,10 +2650,8 @@ public abstract class JComponent extends Container implements Serializable, * * @param aFlag true to make the component visible; false to * make it invisible - * - * @beaninfo - * attribute: visualUpdate true */ + @BeanProperty(hidden = true, visualUpdate = true) public void setVisible(boolean aFlag) { if (aFlag != isVisible()) { super.setVisible(aFlag); @@ -2699,13 +2681,9 @@ public abstract class JComponent extends Container implements Serializable, * @param enabled true if this component should be enabled, false otherwise * @see java.awt.Component#isEnabled * @see java.awt.Component#isLightweight - * - * @beaninfo - * preferred: true - * bound: true - * attribute: visualUpdate true - * description: The enabled state of the component. */ + @BeanProperty(expert = true, preferred = true, visualUpdate = true, description + = "The enabled state of the component.") public void setEnabled(boolean enabled) { boolean oldEnabled = isEnabled(); super.setEnabled(enabled); @@ -2722,13 +2700,9 @@ public abstract class JComponent extends Container implements Serializable, * * @param fg the desired foreground Color * @see java.awt.Component#getForeground - * - * @beaninfo - * preferred: true - * bound: true - * attribute: visualUpdate true - * description: The foreground color of the component. */ + @BeanProperty(preferred = true, visualUpdate = true, description + = "The foreground color of the component.") public void setForeground(Color fg) { Color oldFg = getForeground(); super.setForeground(fg); @@ -2752,13 +2726,9 @@ public abstract class JComponent extends Container implements Serializable, * @param bg the desired background Color * @see java.awt.Component#getBackground * @see #setOpaque - * - * @beaninfo - * preferred: true - * bound: true - * attribute: visualUpdate true - * description: The background color of the component. */ + @BeanProperty(preferred = true, visualUpdate = true, description + = "The background color of the component.") public void setBackground(Color bg) { Color oldBg = getBackground(); super.setBackground(bg); @@ -2773,13 +2743,9 @@ public abstract class JComponent extends Container implements Serializable, * * @param font the desired Font for this component * @see java.awt.Component#getFont - * - * @beaninfo - * preferred: true - * bound: true - * attribute: visualUpdate true - * description: The font for the component. */ + @BeanProperty(preferred = true, visualUpdate = true, description + = "The font for the component.") public void setFont(Font font) { Font oldFont = getFont(); super.setFont(font); @@ -3028,10 +2994,9 @@ public abstract class JComponent extends Container implements Serializable, * @param text the string to display; if the text is null, * the tool tip is turned off for this component * @see #TOOL_TIP_TEXT_KEY - * @beaninfo - * preferred: true - * description: The text to display in a tool tip. */ + @BeanProperty(bound = false, preferred = true, description + = "The text to display in a tool tip.") public void setToolTipText(String text) { String oldText = getToolTipText(); putClientProperty(TOOL_TIP_TEXT_KEY, text); @@ -3190,11 +3155,9 @@ public abstract class JComponent extends Container implements Serializable, * @see #getAutoscrolls * @see JViewport * @see JScrollPane - * - * @beaninfo - * expert: true - * description: Determines if this component automatically scrolls its contents when dragged. */ + @BeanProperty(bound = false, expert = true, description + = "Determines if this component automatically scrolls its contents when dragged.") public void setAutoscrolls(boolean autoscrolls) { setFlag(AUTOSCROLLS_SET, true); if (this.autoscrolls != autoscrolls) { @@ -3254,11 +3217,9 @@ public abstract class JComponent extends Container implements Serializable, * @see TransferHandler * @see #getTransferHandler * @since 1.4 - * @beaninfo - * bound: true - * hidden: true - * description: Mechanism for transfer of data to and from the component */ + @BeanProperty(hidden = true, description + = "Mechanism for transfer of data to and from the component") public void setTransferHandler(TransferHandler newHandler) { TransferHandler oldHandler = (TransferHandler)getClientProperty( JComponent_TRANSFER_HANDLER); @@ -4208,8 +4169,6 @@ public abstract class JComponent extends Container implements Serializable, * or if any keystroke already maps to another focus traversal * operation for this Component * @since 1.5 - * @beaninfo - * bound: true */ public void setFocusTraversalKeys(int id, Set keystrokes) @@ -4336,6 +4295,7 @@ public abstract class JComponent extends Container implements Serializable, * * @return the current x coordinate of the component's origin */ + @BeanProperty(bound = false) public int getX() { return super.getX(); } @@ -4348,6 +4308,7 @@ public abstract class JComponent extends Container implements Serializable, * * @return the current y coordinate of the component's origin */ + @BeanProperty(bound = false) public int getY() { return super.getY(); } @@ -4360,6 +4321,7 @@ public abstract class JComponent extends Container implements Serializable, * * @return the current width of this component */ + @BeanProperty(bound = false) public int getWidth() { return super.getWidth(); } @@ -4372,6 +4334,7 @@ public abstract class JComponent extends Container implements Serializable, * * @return the current height of this component */ + @BeanProperty(bound = false) public int getHeight() { return super.getHeight(); } /** @@ -4405,11 +4368,9 @@ public abstract class JComponent extends Container implements Serializable, * * @param isOpaque true if this component should be opaque * @see #isOpaque - * @beaninfo - * bound: true - * expert: true - * description: The component's opacity */ + @BeanProperty(expert = true, description + = "The component's opacity") public void setOpaque(boolean isOpaque) { boolean oldValue = getFlag(IS_OPAQUE); setFlag(IS_OPAQUE, isOpaque); @@ -4520,6 +4481,7 @@ public abstract class JComponent extends Container implements Serializable, * * @return the visible rectangle */ + @BeanProperty(bound = false) public Rectangle getVisibleRect() { Rectangle visibleRect = new Rectangle(); @@ -4628,6 +4590,7 @@ public abstract class JComponent extends Container implements Serializable, * * @since 1.4 */ + @BeanProperty(bound = false) public synchronized VetoableChangeListener[] getVetoableChangeListeners() { if (vetoableChangeSupport == null) { return new VetoableChangeListener[0]; @@ -4645,6 +4608,7 @@ public abstract class JComponent extends Container implements Serializable, * @return the top-level Container that this component is in, * or null if not in any container */ + @BeanProperty(bound = false) public Container getTopLevelAncestor() { for(Container p = this; p != null; p = p.getParent()) { if(p instanceof Window || p instanceof Applet) { @@ -4711,6 +4675,7 @@ public abstract class JComponent extends Container implements Serializable, * * @since 1.4 */ + @BeanProperty(bound = false) public AncestorListener[] getAncestorListeners() { AncestorNotifier ancestorNotifier = getAncestorNotifier(); if (ancestorNotifier == null) { @@ -4943,6 +4908,7 @@ public abstract class JComponent extends Container implements Serializable, * * @return always returns true */ + @BeanProperty(bound = false) public boolean isOptimizedDrawingEnabled() { return true; } @@ -5392,6 +5358,7 @@ public abstract class JComponent extends Container implements Serializable, * @return the JRootPane that contains this component, * or null if no JRootPane is found */ + @BeanProperty(bound = false) public JRootPane getRootPane() { return SwingUtilities.getRootPane(this); } diff --git a/jdk/src/java.desktop/share/classes/javax/swing/JDesktopPane.java b/jdk/src/java.desktop/share/classes/javax/swing/JDesktopPane.java index 047070460bc..99a2fe8ab6a 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/JDesktopPane.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/JDesktopPane.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -22,7 +22,6 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ - package javax.swing; import java.util.List; @@ -34,16 +33,15 @@ import javax.accessibility.*; import java.awt.Component; import java.awt.Container; -import java.awt.DefaultFocusTraversalPolicy; -import java.awt.FocusTraversalPolicy; -import java.awt.Window; +import java.beans.JavaBean; +import java.beans.BeanProperty; import java.io.ObjectOutputStream; -import java.io.ObjectInputStream; import java.io.IOException; import java.beans.PropertyVetoException; import java.util.Set; import java.util.TreeSet; import java.util.LinkedHashSet; + /** * A container used to create a multiple-document interface or a virtual desktop. * You create JInternalFrame objects and add them to the @@ -88,6 +86,7 @@ import java.util.LinkedHashSet; * @author David Kloba * @since 1.2 */ +@JavaBean(defaultProperty = "UI") @SuppressWarnings("serial") // Same-version serialization only public class JDesktopPane extends JLayeredPane implements Accessible { @@ -163,12 +162,9 @@ public class JDesktopPane extends JLayeredPane implements Accessible * * @param ui the DesktopPaneUI L&F object * @see UIDefaults#getUI - * @beaninfo - * bound: true - * hidden: true - * attribute: visualUpdate true - * description: The UI object that implements the Component's LookAndFeel. */ + @BeanProperty(hidden = true, visualUpdate = true, description + = "The UI object that implements the Component's LookAndFeel.") public void setUI(DesktopPaneUI ui) { super.setUI(ui); } @@ -183,13 +179,12 @@ public class JDesktopPane extends JLayeredPane implements Accessible * @see #LIVE_DRAG_MODE * @see #OUTLINE_DRAG_MODE * - * @beaninfo - * bound: true - * description: Dragging style for internal frame children. - * enum: LIVE_DRAG_MODE JDesktopPane.LIVE_DRAG_MODE - * OUTLINE_DRAG_MODE JDesktopPane.OUTLINE_DRAG_MODE * @since 1.3 */ + @BeanProperty(enumerationValues = { + "JDesktopPane.LIVE_DRAG_MODE", + "JDesktopPane.OUTLINE_DRAG_MODE"}, description + = "Dragging style for internal frame children.") public void setDragMode(int dragMode) { int oldDragMode = this.dragMode; this.dragMode = dragMode; @@ -225,12 +220,9 @@ public class JDesktopPane extends JLayeredPane implements Accessible * {@code LookAndFeel}. * * @param d the DesktopManager to use - * - * @beaninfo - * bound: true - * description: Desktop manager to handle the internal frames in the - * desktop pane. */ + @BeanProperty(description + = "Desktop manager to handle the internal frames in the desktop pane.") public void setDesktopManager(DesktopManager d) { DesktopManager oldValue = desktopManager; desktopManager = d; @@ -256,6 +248,7 @@ public class JDesktopPane extends JLayeredPane implements Accessible * @see JComponent#getUIClassID * @see UIDefaults#getUI */ + @BeanProperty(bound = false) public String getUIClassID() { return uiClassID; } @@ -266,6 +259,7 @@ public class JDesktopPane extends JLayeredPane implements Accessible * * @return an array of JInternalFrame objects */ + @BeanProperty(bound = false) public JInternalFrame[] getAllFrames() { return getAllFrames(this).toArray(new JInternalFrame[0]); } @@ -600,6 +594,7 @@ public class JDesktopPane extends JLayeredPane implements Accessible * @return an AccessibleJDesktopPane that serves as the * AccessibleContext of this JDesktopPane */ + @BeanProperty(bound = false) public AccessibleContext getAccessibleContext() { if (accessibleContext == null) { accessibleContext = new AccessibleJDesktopPane(); diff --git a/jdk/src/java.desktop/share/classes/javax/swing/JDialog.java b/jdk/src/java.desktop/share/classes/javax/swing/JDialog.java index b33bb15f30d..29ad6f88fbb 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/JDialog.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/JDialog.java @@ -26,6 +26,8 @@ package javax.swing; import java.awt.*; import java.awt.event.*; +import java.beans.JavaBean; +import java.beans.BeanProperty; import javax.accessibility.*; /** @@ -86,16 +88,13 @@ import javax.accessibility.*; * @see JRootPane * @see javax.swing.RootPaneContainer * - * @beaninfo - * attribute: isContainer true - * attribute: containerDelegate getContentPane - * description: A toplevel window for creating dialog boxes. - * * @author David Kloba * @author James Gosling * @author Scott Violet * @since 1.2 */ +@JavaBean(defaultProperty = "JMenuBar", description = "A toplevel window for creating dialog boxes.") +@SwingContainer(delegate = "getContentPane") @SuppressWarnings("serial") // Same-version serialization only public class JDialog extends Dialog implements WindowConstants, Accessible, @@ -743,15 +742,12 @@ public class JDialog extends Dialog implements WindowConstants, * @see #addWindowListener * @see #getDefaultCloseOperation * @see WindowConstants - * - * @beaninfo - * preferred: true - * bound: true - * enum: DO_NOTHING_ON_CLOSE WindowConstants.DO_NOTHING_ON_CLOSE - * HIDE_ON_CLOSE WindowConstants.HIDE_ON_CLOSE - * DISPOSE_ON_CLOSE WindowConstants.DISPOSE_ON_CLOSE - * description: The dialog's default close operation. */ + @BeanProperty(preferred = true, enumerationValues = { + "WindowConstants.DO_NOTHING_ON_CLOSE", + "WindowConstants.HIDE_ON_CLOSE", + "WindowConstants.DISPOSE_ON_CLOSE"}, description + = "The dialog's default close operation.") public void setDefaultCloseOperation(int operation) { if (operation != DO_NOTHING_ON_CLOSE && operation != HIDE_ON_CLOSE && @@ -802,12 +798,9 @@ public class JDialog extends Dialog implements WindowConstants, * @see #getTransferHandler * @see java.awt.Component#setDropTarget * @since 1.6 - * - * @beaninfo - * bound: true - * hidden: true - * description: Mechanism for transfer of data into the component */ + @BeanProperty(hidden = true, description + = "Mechanism for transfer of data into the component") public void setTransferHandler(TransferHandler newHandler) { TransferHandler oldHandler = transferHandler; transferHandler = newHandler; @@ -844,11 +837,9 @@ public class JDialog extends Dialog implements WindowConstants, * @param menu the menubar being placed in the dialog * * @see #getJMenuBar - * - * @beaninfo - * hidden: true - * description: The menubar for accessing pulldown menus from this dialog. */ + @BeanProperty(bound = false, hidden = true, description + = "The menubar for accessing pulldown menus from this dialog.") public void setJMenuBar(final JMenuBar menu) { getRootPane().setJMenuBar(menu); } @@ -892,10 +883,9 @@ public class JDialog extends Dialog implements WindowConstants, * @see #setLayout * @see #isRootPaneCheckingEnabled * @see javax.swing.RootPaneContainer - * @beaninfo - * hidden: true - * description: Whether the add and setLayout methods are forwarded */ + @BeanProperty(hidden = true, description + = "Whether the add and setLayout methods are forwarded") protected void setRootPaneCheckingEnabled(boolean enabled) { rootPaneCheckingEnabled = enabled; } @@ -977,6 +967,8 @@ public class JDialog extends Dialog implements WindowConstants, * @see #setRootPane * @see RootPaneContainer#getRootPane */ + @BeanProperty(bound = false, hidden = true, description + = "the RootPane object for this dialog.") public JRootPane getRootPane() { return rootPane; } @@ -989,10 +981,6 @@ public class JDialog extends Dialog implements WindowConstants, * @param root the {@code rootPane} object for this dialog * * @see #getRootPane - * - * @beaninfo - * hidden: true - * description: the RootPane object for this dialog. */ protected void setRootPane(JRootPane root) { if(rootPane != null) { @@ -1041,12 +1029,9 @@ public class JDialog extends Dialog implements WindowConstants, * exception) if the content pane parameter is {@code null} * @see #getContentPane * @see RootPaneContainer#setContentPane - * - * @beaninfo - * hidden: true - * description: The client area of the dialog where child - * components are normally inserted. */ + @BeanProperty(bound = false, hidden = true, description + = "The client area of the dialog where child components are normally inserted.") public void setContentPane(Container contentPane) { getRootPane().setContentPane(contentPane); } @@ -1073,11 +1058,9 @@ public class JDialog extends Dialog implements WindowConstants, * exception) if the layered pane parameter is null * @see #getLayeredPane * @see RootPaneContainer#setLayeredPane - * - * @beaninfo - * hidden: true - * description: The pane which holds the various dialog layers. */ + @BeanProperty(bound = false, hidden = true, description + = "The pane which holds the various dialog layers.") public void setLayeredPane(JLayeredPane layeredPane) { getRootPane().setLayeredPane(layeredPane); } @@ -1101,11 +1084,9 @@ public class JDialog extends Dialog implements WindowConstants, * @param glassPane the {@code glassPane} object for this dialog * @see #getGlassPane * @see RootPaneContainer#setGlassPane - * - * @beaninfo - * hidden: true - * description: A transparent pane used for menu rendering. */ + @BeanProperty(bound = false, hidden = true, description + = "A transparent pane used for menu rendering.") public void setGlassPane(Component glassPane) { getRootPane().setGlassPane(glassPane); } @@ -1115,6 +1096,7 @@ public class JDialog extends Dialog implements WindowConstants, * * @since 1.6 */ + @BeanProperty(bound = false) public Graphics getGraphics() { JComponent.getGraphicsInvoked(this); return super.getGraphics(); diff --git a/jdk/src/java.desktop/share/classes/javax/swing/JEditorPane.java b/jdk/src/java.desktop/share/classes/javax/swing/JEditorPane.java index cfcd56585be..3211d572c1c 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/JEditorPane.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/JEditorPane.java @@ -24,15 +24,13 @@ */ package javax.swing; -import sun.swing.SwingUtilities2; - import java.awt.*; -import java.awt.event.*; +import java.beans.JavaBean; +import java.beans.BeanProperty; import java.lang.reflect.*; import java.net.*; import java.util.*; import java.io.*; -import java.util.*; import javax.swing.plaf.*; import javax.swing.text.*; @@ -184,13 +182,11 @@ import sun.reflect.misc.ReflectUtil; * has been added to the java.beans package. * Please see {@link java.beans.XMLEncoder}. * - * @beaninfo - * attribute: isContainer false - * description: A text component to edit various types of content. - * * @author Timothy Prinzing * @since 1.2 */ +@JavaBean(defaultProperty = "UIClassID", description = "A text component to edit various types of content.") +@SwingContainer(false) @SuppressWarnings("serial") // Same-version serialization only public class JEditorPane extends JTextComponent { @@ -323,6 +319,7 @@ public class JEditorPane extends JTextComponent { * array if no listeners have been added * @since 1.4 */ + @BeanProperty(bound = false) public synchronized HyperlinkListener[] getHyperlinkListeners() { return listenerList.getListeners(javax.swing.event.HyperlinkListener.class); } @@ -411,11 +408,9 @@ public class JEditorPane extends JTextComponent { * @exception IOException for a null or invalid * page specification, or exception from the stream being read * @see #getPage - * @beaninfo - * description: the URL used to set content - * bound: true - * expert: true */ + @BeanProperty(expert = true, description + = "the URL used to set content") public void setPage(URL page) throws IOException { if (page == null) { throw new IOException("invalid url"); @@ -895,6 +890,7 @@ public class JEditorPane extends JTextComponent { * @see JComponent#getUIClassID * @see UIDefaults#getUI */ + @BeanProperty(bound = false) public String getUIClassID() { return uiClassID; } @@ -960,11 +956,11 @@ public class JEditorPane extends JTextComponent { * @param type the non-null mime type for the content editing * support * @see #getContentType - * @beaninfo - * description: the type of content * @throws NullPointerException if the type parameter * is null */ + @BeanProperty(bound = false, description + = "the type of content") public final void setContentType(String type) { // The type could have optional info is part of it, // for example some charset info. We need to strip that @@ -1046,11 +1042,9 @@ public class JEditorPane extends JTextComponent { * * @param kit the desired editor behavior * @see #getEditorKit - * @beaninfo - * description: the currently installed kit for handling content - * bound: true - * expert: true */ + @BeanProperty(expert = true, description + = "the currently installed kit for handling content") public void setEditorKit(EditorKit kit) { EditorKit old = this.kit; isUserSetEditorKit = true; @@ -1414,9 +1408,9 @@ public class JEditorPane extends JTextComponent { * @param t the new text to be set; if null the old * text will be deleted * @see #getText - * @beaninfo - * description: the text of this component */ + @BeanProperty(bound = false, description + = "the text of this component") public void setText(String t) { try { Document doc = getDocument(); @@ -1466,6 +1460,7 @@ public class JEditorPane extends JTextComponent { * @return true if a viewport should force the Scrollables width to * match its own, false otherwise */ + @BeanProperty(bound = false) public boolean getScrollableTracksViewportWidth() { Container parent = SwingUtilities.getUnwrappedParent(this); if (parent instanceof JViewport) { @@ -1489,6 +1484,7 @@ public class JEditorPane extends JTextComponent { * Scrollable's height to match its own, * false otherwise */ + @BeanProperty(bound = false) public boolean getScrollableTracksViewportHeight() { Container parent = SwingUtilities.getUnwrappedParent(this); if (parent instanceof JViewport) { @@ -1626,6 +1622,7 @@ public class JEditorPane extends JTextComponent { * @return an AccessibleJEditorPane that serves as the * AccessibleContext of this JEditorPane */ + @BeanProperty(bound = false) public AccessibleContext getAccessibleContext() { if (getEditorKit() instanceof HTMLEditorKit) { if (accessibleContext == null || accessibleContext.getClass() != diff --git a/jdk/src/java.desktop/share/classes/javax/swing/JFileChooser.java b/jdk/src/java.desktop/share/classes/javax/swing/JFileChooser.java index 45a5a907f24..01edf5d0486 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/JFileChooser.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/JFileChooser.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -22,7 +22,6 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ - package javax.swing; import javax.swing.event.*; @@ -48,6 +47,8 @@ import java.awt.HeadlessException; import java.awt.EventQueue; import java.awt.Toolkit; import java.awt.event.*; +import java.beans.JavaBean; +import java.beans.BeanProperty; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeEvent; import java.io.InvalidObjectException; @@ -83,13 +84,11 @@ import java.lang.ref.WeakReference; * href="package-summary.html#threading">Swing's Threading * Policy. * - * @beaninfo - * attribute: isContainer false - * description: A component which allows for the interactive selection of a file. - * * @author Jeff Dinkins * @since 1.2 */ +@JavaBean(defaultProperty = "UI", description = "A component which allows for the interactive selection of a file.") +@SwingContainer(false) @SuppressWarnings("serial") // Superclass is not serializable across versions public class JFileChooser extends JComponent implements Accessible { @@ -456,11 +455,9 @@ public class JFileChooser extends JComponent implements Accessible { * @see #setTransferHandler * @see TransferHandler * @since 1.4 - * - * @beaninfo - * description: determines whether automatic drag handling is enabled - * bound: false */ + @BeanProperty(bound = false, description + = "determines whether automatic drag handling is enabled") public void setDragEnabled(boolean b) { checkDragEnabled(b); dragEnabled = b; @@ -505,14 +502,11 @@ public class JFileChooser extends JComponent implements Accessible { * not the current directory, changes the current directory * to be the file's parent directory. * - * @beaninfo - * preferred: true - * bound: true - * * @see #getSelectedFile * * @param file the selected file */ + @BeanProperty(preferred = true) public void setSelectedFile(File file) { File oldValue = selectedFile; selectedFile = file; @@ -546,10 +540,9 @@ public class JFileChooser extends JComponent implements Accessible { * set to allow multiple selection. * * @param selectedFiles an array {@code File}s to be selected - * @beaninfo - * bound: true - * description: The list of selected files if the chooser is in multiple selection mode. */ + @BeanProperty(description + = "The list of selected files if the chooser is in multiple selection mode.") public void setSelectedFiles(File[] selectedFiles) { File[] oldValue = this.selectedFiles; if (selectedFiles == null || selectedFiles.length == 0) { @@ -586,14 +579,11 @@ public class JFileChooser extends JComponent implements Accessible { * until it finds a traversable directory, or hits the root of the * file system. * - * @beaninfo - * preferred: true - * bound: true - * description: The directory that the JFileChooser is showing files of. - * * @param dir the current directory to point to * @see #getCurrentDirectory */ + @BeanProperty(preferred = true, description + = "The directory that the JFileChooser is showing files of.") public void setCurrentDirectory(File dir) { File oldValue = currentDirectory; @@ -881,15 +871,12 @@ public class JFileChooser extends JComponent implements Accessible { * @param b false if control buttons should not be * shown; otherwise, true * - * @beaninfo - * preferred: true - * bound: true - * description: Sets whether the approve & cancel buttons are shown. - * * @see #getControlButtonsAreShown * @see #CONTROL_BUTTONS_ARE_SHOWN_CHANGED_PROPERTY * @since 1.3 */ + @BeanProperty(preferred = true, description + = "Sets whether the approve & cancel buttons are shown.") public void setControlButtonsAreShown(boolean b) { if(controlsShown == b) { return; @@ -939,19 +926,16 @@ public class JFileChooser extends JComponent implements Accessible { * * @exception IllegalArgumentException if dialogType is * not legal - * @beaninfo - * preferred: true - * bound: true - * description: The type (open, save, custom) of the JFileChooser. - * enum: - * OPEN_DIALOG JFileChooser.OPEN_DIALOG - * SAVE_DIALOG JFileChooser.SAVE_DIALOG - * CUSTOM_DIALOG JFileChooser.CUSTOM_DIALOG * * @see #getDialogType * @see #setApproveButtonText */ // PENDING(jeff) - fire button text change property + @BeanProperty(preferred = true, enumerationValues = { + "JFileChooser.OPEN_DIALOG", + "JFileChooser.SAVE_DIALOG", + "JFileChooser.CUSTOM_DIALOG"}, description + = "The type (open, save, custom) of the JFileChooser.") public void setDialogType(int dialogType) { if(this.dialogType == dialogType) { return; @@ -979,14 +963,11 @@ public class JFileChooser extends JComponent implements Accessible { * * @param dialogTitle the new String for the title bar * - * @beaninfo - * preferred: true - * bound: true - * description: The title of the JFileChooser dialog window. - * * @see #getDialogTitle * */ + @BeanProperty(preferred = true, description + = "The title of the JFileChooser dialog window.") public void setDialogTitle(String dialogTitle) { String oldValue = this.dialogTitle; this.dialogTitle = dialogTitle; @@ -1016,16 +997,13 @@ public class JFileChooser extends JComponent implements Accessible { * Sets the tooltip text used in the ApproveButton. * If null, the UI object will determine the button's text. * - * @beaninfo - * preferred: true - * bound: true - * description: The tooltip text for the ApproveButton. - * * @param toolTipText the tooltip text for the approve button * @see #setApproveButtonText * @see #setDialogType * @see #showDialog */ + @BeanProperty(preferred = true, description + = "The tooltip text for the ApproveButton.") public void setApproveButtonToolTipText(String toolTipText) { if(approveButtonToolTipText == toolTipText) { return; @@ -1065,13 +1043,10 @@ public class JFileChooser extends JComponent implements Accessible { * * @param mnemonic an integer value for the mnemonic key * - * @beaninfo - * preferred: true - * bound: true - * description: The mnemonic key accelerator for the ApproveButton. - * * @see #getApproveButtonMnemonic */ + @BeanProperty(preferred = true, description + = "The mnemonic key accelerator for the ApproveButton.") public void setApproveButtonMnemonic(int mnemonic) { if(approveButtonMnemonic == mnemonic) { return; @@ -1100,11 +1075,6 @@ public class JFileChooser extends JComponent implements Accessible { * Sets the text used in the ApproveButton in the * FileChooserUI. * - * @beaninfo - * preferred: true - * bound: true - * description: The text that goes in the ApproveButton. - * * @param approveButtonText the text used in the ApproveButton * * @see #getApproveButtonText @@ -1112,6 +1082,8 @@ public class JFileChooser extends JComponent implements Accessible { * @see #showDialog */ // PENDING(jeff) - have ui set this on dialog type change + @BeanProperty(preferred = true, description + = "The text that goes in the ApproveButton.") public void setApproveButtonText(String approveButtonText) { if(this.approveButtonText == approveButtonText) { return; @@ -1148,6 +1120,7 @@ public class JFileChooser extends JComponent implements Accessible { * @see #removeChoosableFileFilter * @see #resetChoosableFileFilters */ + @BeanProperty(bound = false) public FileFilter[] getChoosableFileFilters() { FileFilter[] filterArray = new FileFilter[filters.size()]; filters.copyInto(filterArray); @@ -1162,16 +1135,13 @@ public class JFileChooser extends JComponent implements Accessible { * @param filter the FileFilter to add to the choosable file * filter list * - * @beaninfo - * preferred: true - * bound: true - * description: Adds a filter to the list of user choosable file filters. - * * @see #getChoosableFileFilters * @see #removeChoosableFileFilter * @see #resetChoosableFileFilters * @see #setFileSelectionMode */ + @BeanProperty(preferred = true, description + = "Adds a filter to the list of user choosable file filters.") public void addChoosableFileFilter(FileFilter filter) { if(filter != null && !filters.contains(filter)) { FileFilter[] oldValue = getChoosableFileFilters(); @@ -1249,6 +1219,7 @@ public class JFileChooser extends JComponent implements Accessible { * * @return the {@code AcceptAll} file filter */ + @BeanProperty(bound = false) public FileFilter getAcceptAllFileFilter() { FileFilter filter = null; if(getUI() != null) { @@ -1277,16 +1248,14 @@ public class JFileChooser extends JComponent implements Accessible { * * @param b a {@code boolean} which determines whether the {@code AcceptAll} * file filter is an available choice in the choosable filter list - * @beaninfo - * preferred: true - * bound: true - * description: Sets whether the AcceptAll FileFilter is used as an available choice in the choosable filter list. * * @see #isAcceptAllFileFilterUsed * @see #getAcceptAllFileFilter * @see #setFileFilter * @since 1.3 */ + @BeanProperty(preferred = true, description + = "Sets whether the AcceptAll FileFilter is used as an available choice in the choosable filter list.") public void setAcceptAllFileFilterUsed(boolean b) { boolean oldValue = useAcceptAllFileFilter; useAcceptAllFileFilter = b; @@ -1320,11 +1289,9 @@ public class JFileChooser extends JComponent implements Accessible { * file chooser. * * @param newAccessory the accessory component to be set - * @beaninfo - * preferred: true - * bound: true - * description: Sets the accessory component on the JFileChooser. */ + @BeanProperty(preferred = true, description + = "Sets the accessory component on the JFileChooser.") public void setAccessory(JComponent newAccessory) { JComponent oldValue = accessory; accessory = newAccessory; @@ -1346,17 +1313,14 @@ public class JFileChooser extends JComponent implements Accessible { * * @exception IllegalArgumentException if mode is an * illegal file selection mode - * @beaninfo - * preferred: true - * bound: true - * description: Sets the types of files that the JFileChooser can choose. - * enum: FILES_ONLY JFileChooser.FILES_ONLY - * DIRECTORIES_ONLY JFileChooser.DIRECTORIES_ONLY - * FILES_AND_DIRECTORIES JFileChooser.FILES_AND_DIRECTORIES - * * * @see #getFileSelectionMode */ + @BeanProperty(preferred = true, enumerationValues = { + "JFileChooser.FILES_ONLY", + "JFileChooser.DIRECTORIES_ONLY", + "JFileChooser.FILES_AND_DIRECTORIES"}, description + = "Sets the types of files that the JFileChooser can choose.") public void setFileSelectionMode(int mode) { if(fileSelectionMode == mode) { return; @@ -1400,6 +1364,7 @@ public class JFileChooser extends JComponent implements Accessible { * @see #setFileSelectionMode * @see #getFileSelectionMode */ + @BeanProperty(bound = false) public boolean isFileSelectionEnabled() { return ((fileSelectionMode == FILES_ONLY) || (fileSelectionMode == FILES_AND_DIRECTORIES)); } @@ -1412,6 +1377,7 @@ public class JFileChooser extends JComponent implements Accessible { * @see #setFileSelectionMode * @see #getFileSelectionMode */ + @BeanProperty(bound = false) public boolean isDirectorySelectionEnabled() { return ((fileSelectionMode == DIRECTORIES_ONLY) || (fileSelectionMode == FILES_AND_DIRECTORIES)); } @@ -1420,12 +1386,11 @@ public class JFileChooser extends JComponent implements Accessible { * Sets the file chooser to allow multiple file selections. * * @param b true if multiple files may be selected - * @beaninfo - * bound: true - * description: Sets multiple file selection mode. * * @see #isMultiSelectionEnabled */ + @BeanProperty(description + = "Sets multiple file selection mode.") public void setMultiSelectionEnabled(boolean b) { if(multiSelectionEnabled == b) { return; @@ -1461,15 +1426,12 @@ public class JFileChooser extends JComponent implements Accessible { * in the file chooser. The job of determining which files are * shown is done by the FileView. * - * @beaninfo - * preferred: true - * bound: true - * description: Sets file hiding on or off. - * * @param b the boolean value that determines whether file hiding is * turned on * @see #isFileHidingEnabled */ + @BeanProperty(preferred = true, description + = "Sets file hiding on or off.") public void setFileHidingEnabled(boolean b) { // Dump showFilesListener since we'll ignore it from now on if (showFilesListener != null) { @@ -1485,14 +1447,11 @@ public class JFileChooser extends JComponent implements Accessible { * Sets the current file filter. The file filter is used by the * file chooser to filter out files from the user's view. * - * @beaninfo - * preferred: true - * bound: true - * description: Sets the File Filter used to filter out files of type. - * * @param filter the new current file filter to use * @see #getFileFilter */ + @BeanProperty(preferred = true, description + = "Sets the File Filter used to filter out files of type.") public void setFileFilter(FileFilter filter) { FileFilter oldValue = fileFilter; fileFilter = filter; @@ -1534,13 +1493,11 @@ public class JFileChooser extends JComponent implements Accessible { * the icon that represents a file or the type description of a file. * * @param fileView a {@code FileView} to be used to retrieve UI information - * @beaninfo - * preferred: true - * bound: true - * description: Sets the File View used to get file type information. * * @see #getFileView */ + @BeanProperty(preferred = true, description + = "Sets the File View used to get file type information.") public void setFileView(FileView fileView) { FileView oldValue = this.fileView; this.fileView = fileView; @@ -1704,13 +1661,10 @@ public class JFileChooser extends JComponent implements Accessible { * the floppy drive and getting a list of root drives. * @param fsv the new FileSystemView * - * @beaninfo - * expert: true - * bound: true - * description: Sets the FileSytemView used to get filesystem information. - * * @see FileSystemView */ + @BeanProperty(expert = true, description + = "Sets the FileSytemView used to get filesystem information.") public void setFileSystemView(FileSystemView fsv) { FileSystemView oldValue = fileSystemView; fileSystemView = fsv; @@ -1801,6 +1755,7 @@ public class JFileChooser extends JComponent implements Accessible { * * @since 1.4 */ + @BeanProperty(bound = false) public ActionListener[] getActionListeners() { return listenerList.getListeners(ActionListener.class); } @@ -1895,10 +1850,9 @@ public class JFileChooser extends JComponent implements Accessible { * @return the string "FileChooserUI" * @see JComponent#getUIClassID * @see UIDefaults#getUI - * @beaninfo - * expert: true - * description: A string that specifies the name of the L&F class. */ + @BeanProperty(bound = false, expert = true, description + = "A string that specifies the name of the L&F class.") public String getUIClassID() { return uiClassID; } @@ -1908,6 +1862,7 @@ public class JFileChooser extends JComponent implements Accessible { * * @return the FileChooserUI object that implements the FileChooserUI L&F */ + @BeanProperty(bound = false) public FileChooserUI getUI() { return (FileChooserUI) ui; } @@ -2070,6 +2025,7 @@ public class JFileChooser extends JComponent implements Accessible { * @return an AccessibleJFileChooser that serves as the * AccessibleContext of this JFileChooser */ + @BeanProperty(bound = false) public AccessibleContext getAccessibleContext() { if (accessibleContext == null) { accessibleContext = new AccessibleJFileChooser(); diff --git a/jdk/src/java.desktop/share/classes/javax/swing/JFormattedTextField.java b/jdk/src/java.desktop/share/classes/javax/swing/JFormattedTextField.java index e15d327a0f8..b30f3a52f7f 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/JFormattedTextField.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/JFormattedTextField.java @@ -27,6 +27,8 @@ package javax.swing; import java.awt.*; import java.awt.event.*; import java.awt.im.InputContext; +import java.beans.BeanProperty; +import java.beans.JavaBean; import java.io.*; import java.text.*; import java.util.*; @@ -176,6 +178,7 @@ import javax.swing.text.*; * * @since 1.4 */ +@JavaBean @SuppressWarnings("serial") // Same-version serialization only public class JFormattedTextField extends JTextField { private static final String uiClassID = "FormattedTextFieldUI"; @@ -357,13 +360,13 @@ public class JFormattedTextField extends JTextField { * @param behavior Identifies behavior when focus is lost * @throws IllegalArgumentException if behavior is not one of the known * values - * @beaninfo - * enum: COMMIT JFormattedTextField.COMMIT - * COMMIT_OR_REVERT JFormattedTextField.COMMIT_OR_REVERT - * REVERT JFormattedTextField.REVERT - * PERSIST JFormattedTextField.PERSIST - * description: Behavior when component loses focus */ + @BeanProperty(bound = false, enumerationValues = { + "JFormattedTextField.COMMIT", + "JFormattedTextField.COMMIT_OR_REVERT", + "JFormattedTextField.REVERT", + "JFormattedTextField.PERSIST"}, description + = "Behavior when component loses focus") public void setFocusLostBehavior(int behavior) { if (behavior != COMMIT && behavior != COMMIT_OR_REVERT && behavior != PERSIST && behavior != REVERT) { @@ -407,12 +410,9 @@ public class JFormattedTextField extends JTextField { * * @param tf AbstractFormatterFactory used to lookup * instances of AbstractFormatter - * @beaninfo - * bound: true - * attribute: visualUpdate true - * description: AbstractFormatterFactory, responsible for returning an - * AbstractFormatter that can format the current value. */ + @BeanProperty(visualUpdate = true, description + = "AbstractFormatterFactory, responsible for returning an AbstractFormatter that can format the current value.") public void setFormatterFactory(AbstractFormatterFactory tf) { AbstractFormatterFactory oldFactory = factory; @@ -448,10 +448,6 @@ public class JFormattedTextField extends JTextField { * * @see #setFormatterFactory * @param format AbstractFormatter to use for formatting - * @beaninfo - * bound: true - * attribute: visualUpdate true - * description: TextFormatter, responsible for formatting the current value */ protected void setFormatter(AbstractFormatter format) { AbstractFormatter oldFormat = this.format; @@ -474,6 +470,8 @@ public class JFormattedTextField extends JTextField { * * @return AbstractFormatter used for formatting */ + @BeanProperty(visualUpdate = true, description + = "TextFormatter, responsible for formatting the current value") public AbstractFormatter getFormatter() { return format; } @@ -490,11 +488,9 @@ public class JFormattedTextField extends JTextField { * This is a JavaBeans bound property. * * @param value Current value to display - * @beaninfo - * bound: true - * attribute: visualUpdate true - * description: The value to be formatted. */ + @BeanProperty(visualUpdate = true, description + = "The value to be formatted.") public void setValue(Object value) { if (value != null && getFormatterFactory() == null) { setFormatterFactory(getDefaultFormatterFactory(value)); @@ -544,11 +540,9 @@ public class JFormattedTextField extends JTextField { * * @param isValid boolean indicating if the currently edited value is * valid. - * @beaninfo - * bound: true - * attribute: visualUpdate true - * description: True indicates the edited value is valid */ + @BeanProperty(visualUpdate = true, description + = "True indicates the edited value is valid") private void setEditValid(boolean isValid) { if (isValid != editValid) { editValid = isValid; @@ -564,6 +558,7 @@ public class JFormattedTextField extends JTextField { * * @return true if the current value being edited is valid. */ + @BeanProperty(bound = false) public boolean isEditValid() { return editValid; } @@ -673,6 +668,7 @@ public class JFormattedTextField extends JTextField { * * @return the command list */ + @BeanProperty(bound = false) public Action[] getActions() { return TextAction.augmentList(super.getActions(), defaultActions); } @@ -683,6 +679,7 @@ public class JFormattedTextField extends JTextField { * @return the string "FormattedTextFieldUI" * @see JComponent#getUIClassID */ + @BeanProperty(bound = false) public String getUIClassID() { return uiClassID; } @@ -695,11 +692,9 @@ public class JFormattedTextField extends JTextField { * * @param doc the document to display/edit * @see #getDocument - * @beaninfo - * description: the text document model - * bound: true - * expert: true */ + @BeanProperty(expert = true, description + = "the text document model") public void setDocument(Document doc) { if (documentListener != null && getDocument() != null) { getDocument().removeDocumentListener(documentListener); diff --git a/jdk/src/java.desktop/share/classes/javax/swing/JFrame.java b/jdk/src/java.desktop/share/classes/javax/swing/JFrame.java index c8415e70f58..275137d503a 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/JFrame.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/JFrame.java @@ -36,12 +36,14 @@ import java.awt.Image; import java.awt.LayoutManager; import java.awt.event.WindowEvent; +import java.beans.JavaBean; +import java.beans.BeanProperty; + import javax.accessibility.Accessible; import javax.accessibility.AccessibleContext; import javax.accessibility.AccessibleState; import javax.accessibility.AccessibleStateSet; - /** * An extended version of java.awt.Frame that adds support for * the JFC/Swing component architecture. @@ -111,16 +113,13 @@ import javax.accessibility.AccessibleStateSet; * @see java.awt.event.WindowListener#windowClosing * @see javax.swing.RootPaneContainer * - * @beaninfo - * attribute: isContainer true - * attribute: containerDelegate getContentPane - * description: A toplevel window which can be minimized to an icon. - * * @author Jeff Dinkins * @author Georges Saab * @author David Kloba * @since 1.2 */ +@JavaBean(defaultProperty = "JMenuBar", description = "A toplevel window which can be minimized to an icon.") +@SwingContainer(delegate = "getContentPane") @SuppressWarnings("serial") // Same-version serialization only public class JFrame extends Frame implements WindowConstants, Accessible, @@ -368,16 +367,13 @@ public class JFrame extends Frame implements WindowConstants, * SecurityManager will * not allow the caller to invoke System.exit * @see java.lang.Runtime#exit(int) - * - * @beaninfo - * preferred: true - * bound: true - * enum: DO_NOTHING_ON_CLOSE WindowConstants.DO_NOTHING_ON_CLOSE - * HIDE_ON_CLOSE WindowConstants.HIDE_ON_CLOSE - * DISPOSE_ON_CLOSE WindowConstants.DISPOSE_ON_CLOSE - * EXIT_ON_CLOSE WindowConstants.EXIT_ON_CLOSE - * description: The frame's default close operation. */ + @BeanProperty(preferred = true, enumerationValues = { + "WindowConstants.DO_NOTHING_ON_CLOSE", + "WindowConstants.HIDE_ON_CLOSE", + "WindowConstants.DISPOSE_ON_CLOSE", + "WindowConstants.EXIT_ON_CLOSE"}, description + = "The frame's default close operation.") public void setDefaultCloseOperation(int operation) { if (operation != DO_NOTHING_ON_CLOSE && operation != HIDE_ON_CLOSE && @@ -440,12 +436,9 @@ public class JFrame extends Frame implements WindowConstants, * @see #getTransferHandler * @see java.awt.Component#setDropTarget * @since 1.6 - * - * @beaninfo - * bound: true - * hidden: true - * description: Mechanism for transfer of data into the component */ + @BeanProperty(hidden = true, description + = "Mechanism for transfer of data into the component") public void setTransferHandler(TransferHandler newHandler) { TransferHandler oldHandler = transferHandler; transferHandler = newHandler; @@ -481,11 +474,9 @@ public class JFrame extends Frame implements WindowConstants, * @param menubar the menubar being placed in the frame * * @see #getJMenuBar - * - * @beaninfo - * hidden: true - * description: The menubar for accessing pulldown menus from this frame. */ + @BeanProperty(bound = false, hidden = true, description + = "The menubar for accessing pulldown menus from this frame.") public void setJMenuBar(final JMenuBar menubar) { getRootPane().setJMenuBar(menubar); } @@ -529,10 +520,9 @@ public class JFrame extends Frame implements WindowConstants, * @see #setLayout * @see #isRootPaneCheckingEnabled * @see javax.swing.RootPaneContainer - * @beaninfo - * hidden: true - * description: Whether the add and setLayout methods are forwarded */ + @BeanProperty(hidden = true, description + = "Whether the add and setLayout methods are forwarded") protected void setRootPaneCheckingEnabled(boolean enabled) { rootPaneCheckingEnabled = enabled; } @@ -616,6 +606,8 @@ public class JFrame extends Frame implements WindowConstants, * @see #setRootPane * @see RootPaneContainer#getRootPane */ + @BeanProperty(bound = false, hidden = true, description + = "the RootPane object for this frame.") public JRootPane getRootPane() { return rootPane; } @@ -627,10 +619,6 @@ public class JFrame extends Frame implements WindowConstants, * @param root the rootPane object for this frame * * @see #getRootPane - * - * @beaninfo - * hidden: true - * description: the RootPane object for this frame. */ protected void setRootPane(JRootPane root) { @@ -684,12 +672,9 @@ public class JFrame extends Frame implements WindowConstants, * @see #getContentPane * @see RootPaneContainer#setContentPane * @see JRootPane - * - * @beaninfo - * hidden: true - * description: The client area of the frame where child - * components are normally inserted. */ + @BeanProperty(bound = false, hidden = true, description + = "The client area of the frame where child components are normally inserted.") public void setContentPane(Container contentPane) { getRootPane().setContentPane(contentPane); } @@ -714,11 +699,9 @@ public class JFrame extends Frame implements WindowConstants, * exception) if the layered pane parameter is null * @see #getLayeredPane * @see RootPaneContainer#setLayeredPane - * - * @beaninfo - * hidden: true - * description: The pane that holds the various frame layers. */ + @BeanProperty(bound = false, hidden = true, description + = "The pane that holds the various frame layers.") public void setLayeredPane(JLayeredPane layeredPane) { getRootPane().setLayeredPane(layeredPane); } @@ -741,11 +724,9 @@ public class JFrame extends Frame implements WindowConstants, * * @see #getGlassPane * @see RootPaneContainer#setGlassPane - * - * @beaninfo - * hidden: true - * description: A transparent pane used for menu rendering. */ + @BeanProperty(bound = false, hidden = true, description + = "A transparent pane used for menu rendering.") public void setGlassPane(Component glassPane) { getRootPane().setGlassPane(glassPane); } @@ -755,6 +736,7 @@ public class JFrame extends Frame implements WindowConstants, * * @since 1.6 */ + @BeanProperty(bound = false) public Graphics getGraphics() { JComponent.getGraphicsInvoked(this); return super.getGraphics(); diff --git a/jdk/src/java.desktop/share/classes/javax/swing/JInternalFrame.java b/jdk/src/java.desktop/share/classes/javax/swing/JInternalFrame.java index 8860915a82e..2297fdacdc0 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/JInternalFrame.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/JInternalFrame.java @@ -27,8 +27,7 @@ package javax.swing; import java.awt.*; -import java.beans.PropertyVetoException; -import java.beans.PropertyChangeEvent; +import java.beans.*; import javax.swing.event.InternalFrameEvent; import javax.swing.event.InternalFrameListener; @@ -38,7 +37,7 @@ import javax.accessibility.*; import java.io.ObjectOutputStream; import java.io.IOException; -import java.beans.PropertyChangeListener; + import sun.awt.AppContext; import sun.swing.SwingUtilities2; @@ -104,12 +103,9 @@ import sun.swing.SwingUtilities2; * @author David Kloba * @author Rich Schiavi * @since 1.2 - * @beaninfo - * attribute: isContainer true - * attribute: containerDelegate getContentPane - * description: A frame container which is contained within - * another window. */ +@JavaBean(defaultProperty = "JMenuBar", description = "A frame container which is contained within another window.") +@SwingContainer(delegate = "getContentPane") @SuppressWarnings("serial") // Same-version serialization only public class JInternalFrame extends JComponent implements Accessible, WindowConstants, @@ -377,12 +373,9 @@ public class JInternalFrame extends JComponent implements /** * Sets the UI delegate for this JInternalFrame. * @param ui the UI delegate - * @beaninfo - * bound: true - * hidden: true - * attribute: visualUpdate true - * description: The UI object that implements the Component's LookAndFeel. */ + @BeanProperty(hidden = true, visualUpdate = true, description + = "The UI object that implements the Component's LookAndFeel.") public void setUI(InternalFrameUI ui) { boolean checkingEnabled = isRootPaneCheckingEnabled(); try { @@ -434,10 +427,9 @@ public class JInternalFrame extends JComponent implements * * @see JComponent#getUIClassID * @see UIDefaults#getUI - * - * @beaninfo - * description: UIClassID */ + @BeanProperty(bound = false, description + = "UIClassID") public String getUIClassID() { return uiClassID; } @@ -470,10 +462,9 @@ public class JInternalFrame extends JComponent implements * @see #setLayout * @see #isRootPaneCheckingEnabled * @see javax.swing.RootPaneContainer - * @beaninfo - * hidden: true - * description: Whether the add and setLayout methods are forwarded */ + @BeanProperty(hidden = true, description + = "Whether the add and setLayout methods are forwarded") protected void setRootPaneCheckingEnabled(boolean enabled) { rootPaneCheckingEnabled = enabled; } @@ -595,12 +586,9 @@ public class JInternalFrame extends JComponent implements * * @param m the JMenuBar to use in this internal frame * @see #getJMenuBar - * @beaninfo - * bound: true - * preferred: true - * description: The menu bar for accessing pulldown menus - * from this internal frame. */ + @BeanProperty(preferred = true, description + = "The menu bar for accessing pulldown menus from this internal frame.") public void setJMenuBar(JMenuBar m){ JMenuBar oldValue = getMenuBar(); getRootPane().setJMenuBar(m); @@ -626,12 +614,9 @@ public class JInternalFrame extends JComponent implements * @exception java.awt.IllegalComponentStateException (a runtime * exception) if the content pane parameter is null * @see RootPaneContainer#getContentPane - * @beaninfo - * bound: true - * hidden: true - * description: The client area of the internal frame where child - * components are normally inserted. */ + @BeanProperty(hidden = true, description + = "The client area of the internal frame where child components are normally inserted.") public void setContentPane(Container c) { Container oldValue = getContentPane(); getRootPane().setContentPane(c); @@ -658,11 +643,9 @@ public class JInternalFrame extends JComponent implements * @exception java.awt.IllegalComponentStateException (a runtime * exception) if the layered pane parameter is null * @see RootPaneContainer#setLayeredPane - * @beaninfo - * hidden: true - * bound: true - * description: The pane which holds the various desktop layers. */ + @BeanProperty(hidden = true, description + = "The pane which holds the various desktop layers.") public void setLayeredPane(JLayeredPane layered) { JLayeredPane oldValue = getLayeredPane(); getRootPane().setLayeredPane(layered); @@ -685,11 +668,9 @@ public class JInternalFrame extends JComponent implements * * @param glass the glass pane for this internal frame * @see RootPaneContainer#getGlassPane - * @beaninfo - * bound: true - * hidden: true - * description: A transparent pane used for menu rendering. */ + @BeanProperty(hidden = true, description + = "A transparent pane used for menu rendering.") public void setGlassPane(Component glass) { Component oldValue = getGlassPane(); getRootPane().setGlassPane(glass); @@ -702,6 +683,8 @@ public class JInternalFrame extends JComponent implements * @return the rootPane property * @see RootPaneContainer#getRootPane */ + @BeanProperty(hidden = true, description + = "The root pane used by this internal frame.") public JRootPane getRootPane() { return rootPane; } @@ -713,10 +696,6 @@ public class JInternalFrame extends JComponent implements * This method is called by the constructor. * * @param root the new JRootPane object - * @beaninfo - * bound: true - * hidden: true - * description: The root pane used by this internal frame. */ protected void setRootPane(JRootPane root) { if(rootPane != null) { @@ -741,11 +720,9 @@ public class JInternalFrame extends JComponent implements * Sets whether this JInternalFrame can be closed by * some user action. * @param b a boolean value, where true means this internal frame can be closed - * @beaninfo - * preferred: true - * bound: true - * description: Indicates whether this internal frame can be closed. */ + @BeanProperty(preferred = true, description + = "Indicates whether this internal frame can be closed.") public void setClosable(boolean b) { Boolean oldValue = closable ? Boolean.TRUE : Boolean.FALSE; Boolean newValue = b ? Boolean.TRUE : Boolean.FALSE; @@ -807,12 +784,9 @@ public class JInternalFrame extends JComponent implements * @see #setDefaultCloseOperation * @see #dispose * @see javax.swing.event.InternalFrameEvent#INTERNAL_FRAME_CLOSING - * - * @beaninfo - * bound: true - * constrained: true - * description: Indicates whether this internal frame has been closed. */ + @BeanProperty(description + = "Indicates whether this internal frame has been closed.") public void setClosed(boolean b) throws PropertyVetoException { if (isClosed == b) { return; @@ -844,12 +818,9 @@ public class JInternalFrame extends JComponent implements * user action. * * @param b a boolean, where true means this internal frame can be resized - * @beaninfo - * preferred: true - * bound: true - * description: Determines whether this internal frame can be resized - * by the user. */ + @BeanProperty(preferred = true, description + = "Determines whether this internal frame can be resized by the user.") public void setResizable(boolean b) { Boolean oldValue = resizable ? Boolean.TRUE : Boolean.FALSE; Boolean newValue = b ? Boolean.TRUE : Boolean.FALSE; @@ -877,11 +848,9 @@ public class JInternalFrame extends JComponent implements * they will ignore this property. * * @param b a boolean, where true means this internal frame can be iconified - * @beaninfo - * preferred: true - bound: true - * description: Determines whether this internal frame can be iconified. */ + @BeanProperty(preferred = true, description + = "Determines whether this internal frame can be iconified.") public void setIconifiable(boolean b) { Boolean oldValue = iconable ? Boolean.TRUE : Boolean.FALSE; Boolean newValue = b ? Boolean.TRUE : Boolean.FALSE; @@ -925,12 +894,9 @@ public class JInternalFrame extends JComponent implements * * @see InternalFrameEvent#INTERNAL_FRAME_ICONIFIED * @see InternalFrameEvent#INTERNAL_FRAME_DEICONIFIED - * - * @beaninfo - * bound: true - * constrained: true - * description: The image displayed when this internal frame is minimized. */ + @BeanProperty(description + = "The image displayed when this internal frame is minimized.") public void setIcon(boolean b) throws PropertyVetoException { if (isIcon == b) { return; @@ -964,11 +930,9 @@ public class JInternalFrame extends JComponent implements * they will ignore this property. * * @param b true to specify that this internal frame should be maximizable; false to specify that it should not be - * @beaninfo - * bound: true - * preferred: true - * description: Determines whether this internal frame can be maximized. */ + @BeanProperty(preferred = true, description + = "Determines whether this internal frame can be maximized.") public void setMaximizable(boolean b) { Boolean oldValue = maximizable ? Boolean.TRUE : Boolean.FALSE; Boolean newValue = b ? Boolean.TRUE : Boolean.FALSE; @@ -1006,11 +970,9 @@ public class JInternalFrame extends JComponent implements * restores it * @exception PropertyVetoException when the attempt to set the * property is vetoed by the JInternalFrame - * @beaninfo - * bound: true - * constrained: true - * description: Indicates whether this internal frame is maximized. */ + @BeanProperty(description + = "Indicates whether this internal frame is maximized.") public void setMaximum(boolean b) throws PropertyVetoException { if (isMaximum == b) { return; @@ -1042,11 +1004,9 @@ public class JInternalFrame extends JComponent implements * @see #getTitle * * @param title the String to display in the title bar - * @beaninfo - * preferred: true - * bound: true - * description: The text displayed in the title bar. */ + @BeanProperty(preferred = true, description + = "The text displayed in the title bar.") public void setTitle(String title) { String oldValue = this.title; this.title = title; @@ -1076,13 +1036,9 @@ public class JInternalFrame extends JComponent implements * @see #isShowing * @see InternalFrameEvent#INTERNAL_FRAME_ACTIVATED * @see InternalFrameEvent#INTERNAL_FRAME_DEACTIVATED - * - * @beaninfo - * constrained: true - * bound: true - * description: Indicates whether this internal frame is currently - * the active frame. */ + @BeanProperty(description + = "Indicates whether this internal frame is currently the active frame.") public void setSelected(boolean selected) throws PropertyVetoException { // The InternalFrame may already be selected, but the focus // may be outside it, so restore the focus to the subcomponent @@ -1153,10 +1109,9 @@ public class JInternalFrame extends JComponent implements * * @param icon the Icon to display in the title bar * @see #getFrameIcon - * @beaninfo - * bound: true - * description: The icon shown in the top-left corner of this internal frame. */ + @BeanProperty(description + = "The icon shown in the top-left corner of this internal frame.") public void setFrameIcon(Icon icon) { Icon oldIcon = frameIcon; frameIcon = icon; @@ -1214,6 +1169,7 @@ public class JInternalFrame extends JComponent implements * @return the last non-resizable Cursor * @since 1.6 */ + @BeanProperty(bound = false) public Cursor getLastCursor() { return lastCursor; } @@ -1249,10 +1205,9 @@ public class JInternalFrame extends JComponent implements * frame's desktop layer * @throws NullPointerException if {@code layer} is {@code null} * @see JLayeredPane - * @beaninfo - * expert: true - * description: Specifies what desktop layer is used. */ + @BeanProperty(bound = false, expert = true, description + = "Specifies what desktop layer is used.") public void setLayer(Integer layer) { if(getParent() != null && getParent() instanceof JLayeredPane) { // Normally we want to do this, as it causes the LayeredPane @@ -1280,10 +1235,9 @@ public class JInternalFrame extends JComponent implements * * @see #setLayer(Integer) * @see JLayeredPane - * @beaninfo - * expert: true - * description: Specifies what desktop layer is used. */ + @BeanProperty(bound = false, expert = true, description + = "Specifies what desktop layer is used.") public void setLayer(int layer) { this.setLayer(Integer.valueOf(layer)); } @@ -1307,6 +1261,7 @@ public class JInternalFrame extends JComponent implements * @return the JDesktopPane this internal frame belongs to, * or null if none is found */ + @BeanProperty(bound = false) public JDesktopPane getDesktopPane() { Container p; @@ -1331,10 +1286,9 @@ public class JInternalFrame extends JComponent implements * * @param d the JDesktopIcon to display on the desktop * @see #getDesktopIcon - * @beaninfo - * bound: true - * description: The icon shown when this internal frame is minimized. */ + @BeanProperty(description + = "The icon shown when this internal frame is minimized.") public void setDesktopIcon(JDesktopIcon d) { JDesktopIcon oldValue = getDesktopIcon(); desktopIcon = d; @@ -1424,6 +1378,7 @@ public class JInternalFrame extends JComponent implements * @see #isSelected * @since 1.4 */ + @BeanProperty(bound = false) public Component getMostRecentFocusOwner() { if (isSelected()) { return getFocusOwner(); @@ -1538,6 +1493,7 @@ public class JInternalFrame extends JComponent implements * * @see #addInternalFrameListener */ + @BeanProperty(bound = false) public InternalFrameListener[] getInternalFrameListeners() { return listenerList.getListeners(InternalFrameListener.class); } @@ -1871,6 +1827,7 @@ public class JInternalFrame extends JComponent implements * @see java.awt.Container#isFocusCycleRoot() * @since 1.4 */ + @BeanProperty(bound = false) public final Container getFocusCycleRootAncestor() { return null; } @@ -1883,6 +1840,7 @@ public class JInternalFrame extends JComponent implements * @return null * @see java.awt.Window#getWarningString */ + @BeanProperty(bound = false) public final String getWarningString() { return null; } @@ -2018,6 +1976,7 @@ public class JInternalFrame extends JComponent implements * JInternalFrame * @see AccessibleJInternalFrame */ + @BeanProperty(bound = false) public AccessibleContext getAccessibleContext() { if (accessibleContext == null) { accessibleContext = new AccessibleJInternalFrame(); diff --git a/jdk/src/java.desktop/share/classes/javax/swing/JLabel.java b/jdk/src/java.desktop/share/classes/javax/swing/JLabel.java index 3191f84ccf5..6426c7de84f 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/JLabel.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/JLabel.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -22,28 +22,23 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ - package javax.swing; import java.awt.Component; -import java.awt.Font; import java.awt.Image; import java.awt.*; import java.text.*; import java.awt.geom.*; +import java.beans.JavaBean; +import java.beans.BeanProperty; import java.beans.Transient; import java.io.ObjectOutputStream; -import java.io.ObjectInputStream; import java.io.IOException; import javax.swing.plaf.LabelUI; import javax.accessibility.*; import javax.swing.text.*; -import javax.swing.text.html.*; -import javax.swing.plaf.basic.*; -import java.util.*; - /** * A display area for a short text string or an image, @@ -98,13 +93,11 @@ import java.util.*; * has been added to the java.beans package. * Please see {@link java.beans.XMLEncoder}. * - * @beaninfo - * attribute: isContainer false - * description: A component that displays a short string and an icon. - * * @author Hans Muller * @since 1.2 */ +@JavaBean(defaultProperty = "UI", description = "A component that displays a short string and an icon.") +@SwingContainer(false) @SuppressWarnings("serial") public class JLabel extends JComponent implements SwingConstants, Accessible { @@ -256,12 +249,9 @@ public class JLabel extends JComponent implements SwingConstants, Accessible * * @param ui the LabelUI L&F object * @see UIDefaults#getUI - * @beaninfo - * bound: true - * hidden: true - * attribute: visualUpdate true - * description: The UI object that implements the Component's LookAndFeel. */ + @BeanProperty(hidden = true, visualUpdate = true, description + = "The UI object that implements the Component's LookAndFeel.") public void setUI(LabelUI ui) { super.setUI(ui); // disabled icon is generated by LF so it should be unset here @@ -277,7 +267,7 @@ public class JLabel extends JComponent implements SwingConstants, Accessible * @see JComponent#updateUI */ public void updateUI() { - setUI((LabelUI)UIManager.getUI(this)); + setUI((LabelUI) UIManager.getUI(this)); } @@ -290,6 +280,7 @@ public class JLabel extends JComponent implements SwingConstants, Accessible * @see JComponent#getUIClassID * @see UIDefaults#getUI */ + @BeanProperty(bound = false) public String getUIClassID() { return uiClassID; } @@ -318,12 +309,9 @@ public class JLabel extends JComponent implements SwingConstants, Accessible * @see #setVerticalTextPosition * @see #setHorizontalTextPosition * @see #setIcon - * @beaninfo - * preferred: true - * bound: true - * attribute: visualUpdate true - * description: Defines the single line of text this component will display. */ + @BeanProperty(preferred = true, visualUpdate = true, description + = "Defines the single line of text this component will display.") public void setText(String text) { String oldAccessibleName = null; @@ -375,12 +363,9 @@ public class JLabel extends JComponent implements SwingConstants, Accessible * @see #setVerticalTextPosition * @see #setHorizontalTextPosition * @see #getIcon - * @beaninfo - * preferred: true - * bound: true - * attribute: visualUpdate true - * description: The icon this component will display. */ + @BeanProperty(preferred = true, visualUpdate = true, description + = "The icon this component will display.") public void setIcon(Icon icon) { Icon oldValue = defaultIcon; defaultIcon = icon; @@ -452,11 +437,9 @@ public class JLabel extends JComponent implements SwingConstants, Accessible * @param disabledIcon the Icon to display when the component is disabled * @see #getDisabledIcon * @see #setEnabled - * @beaninfo - * bound: true - * attribute: visualUpdate true - * description: The icon to display if the label is disabled. */ + @BeanProperty(visualUpdate = true, description + = "The icon to display if the label is disabled.") public void setDisabledIcon(Icon disabledIcon) { Icon oldValue = this.disabledIcon; this.disabledIcon = disabledIcon; @@ -485,11 +468,9 @@ public class JLabel extends JComponent implements SwingConstants, Accessible * @param key a keycode that indicates a mnemonic key * @see #getLabelFor * @see #setLabelFor - * @beaninfo - * bound: true - * attribute: visualUpdate true - * description: The mnemonic keycode. */ + @BeanProperty(visualUpdate = true, description + = "The mnemonic keycode.") public void setDisplayedMnemonic(int key) { int oldKey = mnemonic; mnemonic = key; @@ -555,13 +536,9 @@ public class JLabel extends JComponent implements SwingConstants, Accessible * @param index Index into the String to underline * @exception IllegalArgumentException will be thrown if index * is >= length of the text, or < -1 - * - * @beaninfo - * bound: true - * attribute: visualUpdate true - * description: the index into the String to draw the keyboard character - * mnemonic at */ + @BeanProperty(visualUpdate = true, description + = "the index into the String to draw the keyboard character mnemonic at") public void setDisplayedMnemonicIndex(int index) throws IllegalArgumentException { int oldValue = mnemonicIndex; @@ -665,12 +642,9 @@ public class JLabel extends JComponent implements SwingConstants, Accessible * * @param iconTextGap the space between the icon and text properties * @see #getIconTextGap - * @beaninfo - * bound: true - * attribute: visualUpdate true - * description: If both the icon and text properties are set, this - * property defines the space between them. */ + @BeanProperty(visualUpdate = true, description + = "If both the icon and text properties are set, this property defines the space between them.") public void setIconTextGap(int iconTextGap) { int oldValue = this.iconTextGap; this.iconTextGap = iconTextGap; @@ -713,14 +687,12 @@ public class JLabel extends JComponent implements SwingConstants, Accessible * * @see SwingConstants * @see #getVerticalAlignment - * @beaninfo - * bound: true - * enum: TOP SwingConstants.TOP - * CENTER SwingConstants.CENTER - * BOTTOM SwingConstants.BOTTOM - * attribute: visualUpdate true - * description: The alignment of the label's contents along the Y axis. */ + @BeanProperty(visualUpdate = true, enumerationValues = { + "SwingConstants.TOP", + "SwingConstants.CENTER", + "SwingConstants.BOTTOM"}, + description = "The alignment of the label's contents along the Y axis.") public void setVerticalAlignment(int alignment) { if (alignment == verticalAlignment) return; int oldValue = verticalAlignment; @@ -763,16 +735,14 @@ public class JLabel extends JComponent implements SwingConstants, Accessible * * @see SwingConstants * @see #getHorizontalAlignment - * @beaninfo - * bound: true - * enum: LEFT SwingConstants.LEFT - * CENTER SwingConstants.CENTER - * RIGHT SwingConstants.RIGHT - * LEADING SwingConstants.LEADING - * TRAILING SwingConstants.TRAILING - * attribute: visualUpdate true - * description: The alignment of the label's content along the X axis. */ + @BeanProperty(visualUpdate = true, enumerationValues = { + "SwingConstants.LEFT", + "SwingConstants.CENTER", + "SwingConstants.RIGHT", + "SwingConstants.LEADING", + "SwingConstants.TRAILING"}, description + = "The alignment of the label's content along the X axis.") public void setHorizontalAlignment(int alignment) { if (alignment == horizontalAlignment) return; int oldValue = horizontalAlignment; @@ -818,15 +788,12 @@ public class JLabel extends JComponent implements SwingConstants, Accessible * * @see SwingConstants * @see #getVerticalTextPosition - * @beaninfo - * bound: true - * enum: TOP SwingConstants.TOP - * CENTER SwingConstants.CENTER - * BOTTOM SwingConstants.BOTTOM - * expert: true - * attribute: visualUpdate true - * description: The vertical position of the text relative to it's image. */ + @BeanProperty(expert = true, visualUpdate = true, enumerationValues = { + "SwingConstants.TOP", + "SwingConstants.CENTER", + "SwingConstants.BOTTOM"}, + description = "The vertical position of the text relative to it's image.") public void setVerticalTextPosition(int textPosition) { if (textPosition == verticalTextPosition) return; int old = verticalTextPosition; @@ -870,18 +837,14 @@ public class JLabel extends JComponent implements SwingConstants, Accessible * TRAILING (the default). * * @see SwingConstants - * @beaninfo - * expert: true - * bound: true - * enum: LEFT SwingConstants.LEFT - * CENTER SwingConstants.CENTER - * RIGHT SwingConstants.RIGHT - * LEADING SwingConstants.LEADING - * TRAILING SwingConstants.TRAILING - * attribute: visualUpdate true - * description: The horizontal position of the label's text, - * relative to its image. */ + @BeanProperty(expert = true, visualUpdate = true, enumerationValues = { + "SwingConstants.LEFT", + "SwingConstants.CENTER", + "SwingConstants.RIGHT", + "SwingConstants.LEADING", + "SwingConstants.TRAILING"}, description + = "The horizontal position of the label's text, relative to its image.") public void setHorizontalTextPosition(int textPosition) { int old = horizontalTextPosition; this.horizontalTextPosition = checkHorizontalKey(textPosition, @@ -1035,11 +998,9 @@ public class JLabel extends JComponent implements SwingConstants, Accessible * * @see #getDisplayedMnemonic * @see #setDisplayedMnemonic - * - * @beaninfo - * bound: true - * description: The component this is labelling. */ + @BeanProperty(description + = "The component this is labelling.") public void setLabelFor(Component c) { Component oldC = labelFor; labelFor = c; @@ -1057,10 +1018,9 @@ public class JLabel extends JComponent implements SwingConstants, Accessible * Get the AccessibleContext of this object * * @return the AccessibleContext of this object - * @beaninfo - * expert: true - * description: The AccessibleContext associated with this Label. */ + @BeanProperty(bound = false, expert = true, description + = "The AccessibleContext associated with this Label.") public AccessibleContext getAccessibleContext() { if (accessibleContext == null) { accessibleContext = new AccessibleJLabel(); diff --git a/jdk/src/java.desktop/share/classes/javax/swing/JLayeredPane.java b/jdk/src/java.desktop/share/classes/javax/swing/JLayeredPane.java index ce5998f8f56..3d561b99bef 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/JLayeredPane.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/JLayeredPane.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -30,6 +30,9 @@ import java.util.Hashtable; import java.awt.Color; import java.awt.Graphics; import java.awt.Rectangle; +import java.beans.JavaBean; +import java.beans.BeanProperty; + import sun.awt.SunToolkit; import javax.accessibility.*; @@ -155,6 +158,7 @@ import javax.accessibility.*; * @author David Kloba * @since 1.2 */ +@JavaBean(defaultProperty = "accessibleContext") @SuppressWarnings("serial") public class JLayeredPane extends JComponent implements Accessible { /// Watch the values in getObjectForLayer() @@ -275,6 +279,7 @@ public class JLayeredPane extends JComponent implements Accessible { * @return false if components can overlap, else true * @see JComponent#isOptimizedDrawingEnabled */ + @BeanProperty(bound = false) public boolean isOptimizedDrawingEnabled() { return optimizedDrawingPossible; } @@ -738,6 +743,7 @@ public class JLayeredPane extends JComponent implements Accessible { * @return an AccessibleJLayeredPane that serves as the * AccessibleContext of this JLayeredPane */ + @BeanProperty(bound = false) public AccessibleContext getAccessibleContext() { if (accessibleContext == null) { accessibleContext = new AccessibleJLayeredPane(); diff --git a/jdk/src/java.desktop/share/classes/javax/swing/JList.java b/jdk/src/java.desktop/share/classes/javax/swing/JList.java index 14379bd5668..0b5986e7b09 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/JList.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/JList.java @@ -22,7 +22,6 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ - package javax.swing; import java.awt.*; @@ -34,6 +33,8 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.beans.JavaBean; +import java.beans.BeanProperty; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.beans.Transient; @@ -44,7 +45,6 @@ import javax.swing.plaf.*; import javax.swing.text.Position; import java.io.ObjectOutputStream; -import java.io.ObjectInputStream; import java.io.IOException; import java.io.Serializable; @@ -52,7 +52,6 @@ import sun.swing.SwingUtilities2; import sun.swing.SwingUtilities2.Section; import static sun.swing.SwingUtilities2.Section.*; - /** * A component that displays a list of objects and allows the user to select * one or more items. A separate model, {@code ListModel}, maintains the @@ -271,13 +270,11 @@ import static sun.swing.SwingUtilities2.Section.*; * * @param the type of the elements of this list * - * @beaninfo - * attribute: isContainer false - * description: A component which allows for the selection of one or more objects from a list. - * * @author Hans Muller * @since 1.2 */ +@JavaBean(defaultProperty = "UI", description = "A component which allows for the selection of one or more objects from a list.") +@SwingContainer(false) @SuppressWarnings("serial") // Same-version serialization only public class JList extends JComponent implements Scrollable, Accessible { @@ -515,12 +512,9 @@ public class JList extends JComponent implements Scrollable, Accessible * * @param ui the ListUI object * @see UIDefaults#getUI - * @beaninfo - * bound: true - * hidden: true - * attribute: visualUpdate true - * description: The UI object that implements the Component's LookAndFeel. */ + @BeanProperty(hidden = true, visualUpdate = true, description + = "The UI object that implements the Component's LookAndFeel.") public void setUI(ListUI ui) { super.setUI(ui); } @@ -555,6 +549,7 @@ public class JList extends JComponent implements Scrollable, Accessible * @see JComponent#getUIClassID * @see UIDefaults#getUI */ + @BeanProperty(bound = false) public String getUIClassID() { return uiClassID; } @@ -640,11 +635,9 @@ public class JList extends JComponent implements Scrollable, Accessible * @see #setFixedCellWidth * @see #setFixedCellHeight * @see JComponent#addPropertyChangeListener - * @beaninfo - * bound: true - * attribute: visualUpdate true - * description: The cell prototype value, used to compute cell width and height. */ + @BeanProperty(visualUpdate = true, description + = "The cell prototype value, used to compute cell width and height.") public void setPrototypeCellValue(E prototypeCellValue) { E oldValue = this.prototypeCellValue; this.prototypeCellValue = prototypeCellValue; @@ -685,11 +678,9 @@ public class JList extends JComponent implements Scrollable, Accessible * @see #setPrototypeCellValue * @see #setFixedCellWidth * @see JComponent#addPropertyChangeListener - * @beaninfo - * bound: true - * attribute: visualUpdate true - * description: Defines a fixed cell width when greater than zero. */ + @BeanProperty(visualUpdate = true, description + = "Defines a fixed cell width when greater than zero.") public void setFixedCellWidth(int width) { int oldValue = fixedCellWidth; fixedCellWidth = width; @@ -721,11 +712,9 @@ public class JList extends JComponent implements Scrollable, Accessible * @see #setPrototypeCellValue * @see #setFixedCellWidth * @see JComponent#addPropertyChangeListener - * @beaninfo - * bound: true - * attribute: visualUpdate true - * description: Defines a fixed cell height when greater than zero. */ + @BeanProperty(visualUpdate = true, description + = "Defines a fixed cell height when greater than zero.") public void setFixedCellHeight(int height) { int oldValue = fixedCellHeight; fixedCellHeight = height; @@ -763,11 +752,9 @@ public class JList extends JComponent implements Scrollable, Accessible * @param cellRenderer the ListCellRenderer * that paints list cells * @see #getCellRenderer - * @beaninfo - * bound: true - * attribute: visualUpdate true - * description: The component used to draw the cells. */ + @BeanProperty(visualUpdate = true, description + = "The component used to draw the cells.") public void setCellRenderer(ListCellRenderer cellRenderer) { ListCellRenderer oldValue = this.cellRenderer; this.cellRenderer = cellRenderer; @@ -818,11 +805,9 @@ public class JList extends JComponent implements Scrollable, Accessible * @see #setBackground * @see #setFont * @see DefaultListCellRenderer - * @beaninfo - * bound: true - * attribute: visualUpdate true - * description: The foreground color of selected cells. */ + @BeanProperty(visualUpdate = true, description + = "The foreground color of selected cells.") public void setSelectionForeground(Color selectionForeground) { Color oldValue = this.selectionForeground; this.selectionForeground = selectionForeground; @@ -865,11 +850,9 @@ public class JList extends JComponent implements Scrollable, Accessible * @see #setBackground * @see #setFont * @see DefaultListCellRenderer - * @beaninfo - * bound: true - * attribute: visualUpdate true - * description: The background color of selected cells. */ + @BeanProperty(visualUpdate = true, description + = "The background color of selected cells.") public void setSelectionBackground(Color selectionBackground) { Color oldValue = this.selectionBackground; this.selectionBackground = selectionBackground; @@ -920,12 +903,9 @@ public class JList extends JComponent implements Scrollable, Accessible * @see #setLayoutOrientation * @see JComponent#getVisibleRect * @see JViewport - * @beaninfo - * bound: true - * attribute: visualUpdate true - * description: The preferred number of rows to display without - * requiring scrolling */ + @BeanProperty(visualUpdate = true, description + = "The preferred number of rows to display without requiring scrolling") public void setVisibleRowCount(int visibleRowCount) { int oldValue = this.visibleRowCount; this.visibleRowCount = Math.max(0, visibleRowCount); @@ -999,14 +979,12 @@ public class JList extends JComponent implements Scrollable, Accessible * @throws IllegalArgumentException if {@code layoutOrientation} isn't one of the * allowable values * @since 1.4 - * @beaninfo - * bound: true - * attribute: visualUpdate true - * description: Defines the way list cells are layed out. - * enum: VERTICAL JList.VERTICAL - * HORIZONTAL_WRAP JList.HORIZONTAL_WRAP - * VERTICAL_WRAP JList.VERTICAL_WRAP */ + @BeanProperty(visualUpdate = true, enumerationValues = { + "JList.VERTICAL", + "JList.HORIZONTAL_WRAP", + "JList.VERTICAL_WRAP"}, description + = "Defines the way list cells are layed out.") public void setLayoutOrientation(int layoutOrientation) { int oldValue = this.layoutOrientation; switch (layoutOrientation) { @@ -1034,6 +1012,7 @@ public class JList extends JComponent implements Scrollable, Accessible * @see #getLastVisibleIndex * @see JComponent#getVisibleRect */ + @BeanProperty(bound = false) public int getFirstVisibleIndex() { Rectangle r = getVisibleRect(); int first; @@ -1064,6 +1043,7 @@ public class JList extends JComponent implements Scrollable, Accessible * @see #getFirstVisibleIndex * @see JComponent#getVisibleRect */ + @BeanProperty(bound = false) public int getLastVisibleIndex() { boolean leftToRight = this.getComponentOrientation().isLeftToRight(); Rectangle r = getVisibleRect(); @@ -1180,11 +1160,9 @@ public class JList extends JComponent implements Scrollable, Accessible * @see #setTransferHandler * @see TransferHandler * @since 1.4 - * - * @beaninfo - * description: determines whether automatic drag handling is enabled - * bound: false */ + @BeanProperty(bound = false, description + = "determines whether automatic drag handling is enabled") public void setDragEnabled(boolean b) { if (b && GraphicsEnvironment.isHeadless()) { throw new HeadlessException(); @@ -1449,6 +1427,7 @@ public class JList extends JComponent implements Scrollable, Accessible * @see TransferHandler#canImport(TransferHandler.TransferSupport) * @since 1.6 */ + @BeanProperty(bound = false) public final DropLocation getDropLocation() { return dropLocation; } @@ -1664,11 +1643,9 @@ public class JList extends JComponent implements Scrollable, Accessible * null * @see #getModel * @see #clearSelection - * @beaninfo - * bound: true - * attribute: visualUpdate true - * description: The object that contains the data to be drawn by this JList. */ + @BeanProperty(visualUpdate = true, description + = "The object that contains the data to be drawn by this JList.") public void setModel(ListModel model) { if (model == null) { throw new IllegalArgumentException("model must be non null"); @@ -1860,6 +1837,7 @@ public class JList extends JComponent implements Scrollable, Accessible * @see #addListSelectionListener * @since 1.4 */ + @BeanProperty(bound = false) public ListSelectionListener[] getListSelectionListeners() { return listenerList.getListeners(ListSelectionListener.class); } @@ -1879,10 +1857,9 @@ public class JList extends JComponent implements Scrollable, Accessible * @exception IllegalArgumentException if selectionModel * is null * @see #getSelectionModel - * @beaninfo - * bound: true - * description: The selection model, recording which cells are selected. */ + @BeanProperty(description + = "The selection model, recording which cells are selected.") public void setSelectionModel(ListSelectionModel selectionModel) { if (selectionModel == null) { throw new IllegalArgumentException("selectionModel must be non null"); @@ -1928,12 +1905,12 @@ public class JList extends JComponent implements Scrollable, Accessible * @see #getSelectionMode * @throws IllegalArgumentException if the selection mode isn't * one of those allowed - * @beaninfo - * description: The selection mode. - * enum: SINGLE_SELECTION ListSelectionModel.SINGLE_SELECTION - * SINGLE_INTERVAL_SELECTION ListSelectionModel.SINGLE_INTERVAL_SELECTION - * MULTIPLE_INTERVAL_SELECTION ListSelectionModel.MULTIPLE_INTERVAL_SELECTION */ + @BeanProperty(bound = false, enumerationValues = { + "ListSelectionModel.SINGLE_SELECTION", + "ListSelectionModel.SINGLE_INTERVAL_SELECTION", + "ListSelectionModel.MULTIPLE_INTERVAL_SELECTION"}, description + = "The selection mode.") public void setSelectionMode(int selectionMode) { getSelectionModel().setSelectionMode(selectionMode); } @@ -1958,6 +1935,7 @@ public class JList extends JComponent implements Scrollable, Accessible * @return the anchor selection index * @see ListSelectionModel#getAnchorSelectionIndex */ + @BeanProperty(bound = false) public int getAnchorSelectionIndex() { return getSelectionModel().getAnchorSelectionIndex(); } @@ -1969,9 +1947,9 @@ public class JList extends JComponent implements Scrollable, Accessible * * @return the lead selection index * @see ListSelectionModel#getLeadSelectionIndex - * @beaninfo - * description: The lead selection index. */ + @BeanProperty(bound = false, description + = "The lead selection index.") public int getLeadSelectionIndex() { return getSelectionModel().getLeadSelectionIndex(); } @@ -1985,6 +1963,7 @@ public class JList extends JComponent implements Scrollable, Accessible * @return the smallest selected cell index, or {@code -1} * @see ListSelectionModel#getMinSelectionIndex */ + @BeanProperty(bound = false) public int getMinSelectionIndex() { return getSelectionModel().getMinSelectionIndex(); } @@ -1998,6 +1977,7 @@ public class JList extends JComponent implements Scrollable, Accessible * @return the largest selected cell index * @see ListSelectionModel#getMaxSelectionIndex */ + @BeanProperty(bound = false) public int getMaxSelectionIndex() { return getSelectionModel().getMaxSelectionIndex(); } @@ -2028,6 +2008,7 @@ public class JList extends JComponent implements Scrollable, Accessible * @see ListSelectionModel#isSelectionEmpty * @see #clearSelection */ + @BeanProperty(bound = false) public boolean isSelectionEmpty() { return getSelectionModel().isSelectionEmpty(); } @@ -2202,9 +2183,9 @@ public class JList extends JComponent implements Scrollable, Accessible * @see ListSelectionModel#setSelectionInterval * @see #isSelectedIndex * @see #addListSelectionListener - * @beaninfo - * description: The index of the selected cell. */ + @BeanProperty(bound = false, description + = "The index of the selected cell.") public void setSelectedIndex(int index) { if (index >= getModel().getSize()) { return; @@ -2252,6 +2233,7 @@ public class JList extends JComponent implements Scrollable, Accessible * @deprecated As of JDK 1.7, replaced by {@link #getSelectedValuesList()} */ @Deprecated + @BeanProperty(bound = false) public Object[] getSelectedValues() { ListSelectionModel sm = getSelectionModel(); ListModel dm = getModel(); @@ -2286,6 +2268,7 @@ public class JList extends JComponent implements Scrollable, Accessible * * @since 1.7 */ + @BeanProperty(bound = false) public List getSelectedValuesList() { ListSelectionModel sm = getSelectionModel(); ListModel dm = getModel(); @@ -2338,6 +2321,7 @@ public class JList extends JComponent implements Scrollable, Accessible * @see #getModel * @see #addListSelectionListener */ + @BeanProperty(bound = false) public E getSelectedValue() { int i = getMinSelectionIndex(); return (i == -1) ? null : getModel().getElementAt(i); @@ -2427,6 +2411,7 @@ public class JList extends JComponent implements Scrollable, Accessible * @see #getPreferredScrollableViewportSize * @see #setPrototypeCellValue */ + @BeanProperty(bound = false) public Dimension getPreferredScrollableViewportSize() { if (getLayoutOrientation() != VERTICAL) { @@ -2764,6 +2749,7 @@ public class JList extends JComponent implements Scrollable, Accessible * width to match its own * @see Scrollable#getScrollableTracksViewportWidth */ + @BeanProperty(bound = false) public boolean getScrollableTracksViewportWidth() { if (getLayoutOrientation() == HORIZONTAL_WRAP && getVisibleRowCount() <= 0) { @@ -2790,6 +2776,7 @@ public class JList extends JComponent implements Scrollable, Accessible * height to match its own * @see Scrollable#getScrollableTracksViewportHeight */ + @BeanProperty(bound = false) public boolean getScrollableTracksViewportHeight() { if (getLayoutOrientation() == VERTICAL_WRAP && getVisibleRowCount() <= 0) { @@ -2861,6 +2848,7 @@ public class JList extends JComponent implements Scrollable, Accessible * @return an {@code AccessibleJList} that serves as the * {@code AccessibleContext} of this {@code JList} */ + @BeanProperty(bound = false) public AccessibleContext getAccessibleContext() { if (accessibleContext == null) { accessibleContext = new AccessibleJList(); diff --git a/jdk/src/java.desktop/share/classes/javax/swing/JMenu.java b/jdk/src/java.desktop/share/classes/javax/swing/JMenu.java index 47834d02d58..c9a279a5ed0 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/JMenu.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/JMenu.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -22,41 +22,34 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ - package javax.swing; -import java.awt.AWTEvent; import java.awt.Component; import java.awt.ComponentOrientation; import java.awt.Container; import java.awt.Dimension; -import java.awt.Frame; -import java.awt.Graphics; import java.awt.GraphicsConfiguration; import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment; import java.awt.Insets; import java.awt.Point; -import java.awt.Polygon; import java.awt.Rectangle; import java.awt.Toolkit; import java.awt.event.*; -import java.beans.*; +import java.beans.JavaBean; +import java.beans.BeanProperty; +import java.beans.PropertyChangeListener; import java.util.*; import java.io.Serializable; import java.io.ObjectOutputStream; -import java.io.ObjectInputStream; import java.io.IOException; import javax.swing.event.*; import javax.swing.plaf.*; -import javax.swing.plaf.basic.*; import javax.accessibility.*; -import java.lang.ref.WeakReference; - /** * An implementation of a menu -- a popup window containing * JMenuItems that @@ -97,10 +90,6 @@ import java.lang.ref.WeakReference; * has been added to the java.beans package. * Please see {@link java.beans.XMLEncoder}. * - * @beaninfo - * attribute: isContainer true - * description: A popup window containing menu items displayed in a menu bar. - * * @author Georges Saab * @author David Karlton * @author Arnaud Weber @@ -110,6 +99,8 @@ import java.lang.ref.WeakReference; * @see JPopupMenu * @since 1.2 */ +@JavaBean(description = "A popup window containing menu items displayed in a menu bar.") +@SwingContainer @SuppressWarnings("serial") public class JMenu extends JMenuItem implements Accessible,MenuElement { @@ -232,6 +223,7 @@ public class JMenu extends JMenuItem implements Accessible,MenuElement * @see JComponent#getUIClassID * @see UIDefaults#getUI */ + @BeanProperty(bound = false) public String getUIClassID() { return uiClassID; } @@ -247,11 +239,6 @@ public class JMenu extends JMenuItem implements Accessible,MenuElement * * @param newModel the ButtonModel * @see #getModel - * @beaninfo - * description: The menu's model - * bound: true - * expert: true - * hidden: true */ public void setModel(ButtonModel newModel) { ButtonModel oldModel = getModel(); @@ -285,11 +272,9 @@ public class JMenu extends JMenuItem implements Accessible,MenuElement * * @param b true to select (highlight) the menu; false to de-select * the menu - * @beaninfo - * description: When the menu is selected, its popup child is shown. - * expert: true - * hidden: true */ + @BeanProperty(expert = true, hidden = true, description + = "When the menu is selected, its popup child is shown.") public void setSelected(boolean b) { ButtonModel model = getModel(); boolean oldValue = model.isSelected(); @@ -323,11 +308,9 @@ public class JMenu extends JMenuItem implements Accessible,MenuElement * * @param b a boolean value -- true to make the menu visible, * false to hide it - * @beaninfo - * description: The popup menu's visibility - * expert: true - * hidden: true */ + @BeanProperty(bound = false, expert = true, hidden = true, description + = "The popup menu's visibility") public void setPopupMenuVisible(boolean b) { if (DEBUG) { System.out.println("in JMenu.setPopupMenuVisible " + b); @@ -517,10 +500,9 @@ public class JMenu extends JMenuItem implements Accessible,MenuElement * @param d the number of milliseconds to delay * @exception IllegalArgumentException if d * is less than 0 - * @beaninfo - * description: The delay between menu selection and making the popup menu visible - * expert: true */ + @BeanProperty(bound = false, expert = true, description + = "The delay between menu selection and making the popup menu visible") public void setDelay(int d) { if (d < 0) throw new IllegalArgumentException("Delay must be a positive integer"); @@ -788,6 +770,7 @@ public class JMenu extends JMenuItem implements Accessible,MenuElement * @return an integer equal to the number of items on the menu * @see #getMenuComponentCount */ + @BeanProperty(bound = false) public int getItemCount() { return getMenuComponentCount(); } @@ -799,6 +782,7 @@ public class JMenu extends JMenuItem implements Accessible,MenuElement * @return true if the menu can be torn off, else false * @exception Error if invoked -- this method is not yet implemented */ + @BeanProperty(bound = false) public boolean isTearOff() { throw new Error("boolean isTearOff() {} not yet implemented"); } @@ -856,6 +840,7 @@ public class JMenu extends JMenuItem implements Accessible,MenuElement * * @return an integer containing the number of components on the menu */ + @BeanProperty(bound = false) public int getMenuComponentCount() { int componentCount = 0; if (popupMenu != null) @@ -886,6 +871,7 @@ public class JMenu extends JMenuItem implements Accessible,MenuElement * @return an array of Components or an empty array * if there is no popup menu */ + @BeanProperty(bound = false) public Component[] getMenuComponents() { if (popupMenu != null) return popupMenu.getComponents(); @@ -901,6 +887,7 @@ public class JMenu extends JMenuItem implements Accessible,MenuElement * false if the menu is activated from a menu item * on another menu */ + @BeanProperty(bound = false) public boolean isTopLevelMenu() { return getParent() instanceof JMenuBar; @@ -985,6 +972,7 @@ public class JMenu extends JMenuItem implements Accessible,MenuElement * * @return the {@code JPopupMenu} associated with this menu */ + @BeanProperty(bound = false) public JPopupMenu getPopupMenu() { ensurePopupMenuCreated(); return popupMenu; @@ -1016,6 +1004,7 @@ public class JMenu extends JMenuItem implements Accessible,MenuElement * array if no listeners have been added * @since 1.4 */ + @BeanProperty(bound = false) public MenuListener[] getMenuListeners() { return listenerList.getListeners(MenuListener.class); } @@ -1208,6 +1197,7 @@ public class JMenu extends JMenuItem implements Accessible,MenuElement * * @return an array of MenuElement objects */ + @BeanProperty(bound = false) public MenuElement[] getSubElements() { if(popupMenu == null) return new MenuElement[0]; @@ -1270,11 +1260,6 @@ public class JMenu extends JMenuItem implements Accessible,MenuElement * without navigating the menu hierarchy * @exception Error if invoked -- this method is not defined for JMenu. * Use setMnemonic instead - * - * @beaninfo - * description: The keystroke combination which will invoke the JMenuItem's - * actionlisteners without navigating the menu hierarchy - * hidden: true */ public void setAccelerator(KeyStroke keyStroke) { throw new Error("setAccelerator() is not defined for JMenu. Use setMnemonic() instead."); @@ -1381,6 +1366,7 @@ public class JMenu extends JMenuItem implements Accessible,MenuElement * @return an AccessibleJMenu that serves as the * AccessibleContext of this JMenu */ + @BeanProperty(bound = false) public AccessibleContext getAccessibleContext() { if (accessibleContext == null) { accessibleContext = new AccessibleJMenu(); diff --git a/jdk/src/java.desktop/share/classes/javax/swing/JMenuBar.java b/jdk/src/java.desktop/share/classes/javax/swing/JMenuBar.java index c8fcb6673c6..979d2b8a3d7 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/JMenuBar.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/JMenuBar.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -22,27 +22,22 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ - package javax.swing; import java.awt.Component; -import java.awt.Dimension; import java.awt.Graphics; import java.awt.Insets; -import java.awt.Point; -import java.awt.Rectangle; import java.awt.event.*; +import java.beans.JavaBean; +import java.beans.BeanProperty; import java.beans.Transient; import java.util.Vector; -import java.util.Enumeration; import java.io.Serializable; import java.io.ObjectOutputStream; import java.io.ObjectInputStream; import java.io.IOException; -import javax.swing.event.*; -import javax.swing.border.Border; import javax.swing.plaf.*; import javax.accessibility.*; @@ -78,9 +73,6 @@ import javax.accessibility.*; * of JMenuBar is set to false. To resolve this, * you should call the JMenuBar.setFocusTraversalKeysEnabled(true) * method. - * @beaninfo - * attribute: isContainer true - * description: A container for holding and displaying menus. * * @author Georges Saab * @author David Karlton @@ -90,6 +82,8 @@ import javax.accessibility.*; * @see JMenuItem * @since 1.2 */ +@JavaBean(defaultProperty = "UI", description = "A container for holding and displaying menus.") +@SwingContainer @SuppressWarnings("serial") public class JMenuBar extends JComponent implements Accessible,MenuElement { @@ -137,12 +131,9 @@ public class JMenuBar extends JComponent implements Accessible,MenuElement * * @param ui the new MenuBarUI L&F object * @see UIDefaults#getUI - * @beaninfo - * bound: true - * hidden: true - * attribute: visualUpdate true - * description: The UI object that implements the Component's LookAndFeel. */ + @BeanProperty(hidden = true, visualUpdate = true, description + = "The UI object that implements the Component's LookAndFeel.") public void setUI(MenuBarUI ui) { super.setUI(ui); } @@ -164,6 +155,7 @@ public class JMenuBar extends JComponent implements Accessible,MenuElement * @see JComponent#getUIClassID * @see UIDefaults#getUI */ + @BeanProperty(bound = false) public String getUIClassID() { return uiClassID; } @@ -184,10 +176,8 @@ public class JMenuBar extends JComponent implements Accessible,MenuElement * * @param model the SingleSelectionModel to use * @see SingleSelectionModel - * @beaninfo - * bound: true - * description: The selection model, recording which child is selected. */ + @BeanProperty(description = "The selection model, recording which child is selected.") public void setSelectionModel(SingleSelectionModel model) { SingleSelectionModel oldValue = selectionModel; this.selectionModel = model; @@ -227,6 +217,7 @@ public class JMenuBar extends JComponent implements Accessible,MenuElement * * @return the number of items in the menu bar */ + @BeanProperty(bound = false) public int getMenuCount() { return getComponentCount(); } @@ -304,6 +295,7 @@ public class JMenuBar extends JComponent implements Accessible,MenuElement * * @return true if a selection has been made, else false */ + @BeanProperty(bound = false) public boolean isSelected() { return selectionModel.isSelected(); } @@ -323,11 +315,9 @@ public class JMenuBar extends JComponent implements Accessible,MenuElement * @param b if true and border property is not null, * the border is painted. * @see #isBorderPainted - * @beaninfo - * bound: true - * attribute: visualUpdate true - * description: Whether the border should be painted. */ + @BeanProperty(visualUpdate = true, description + = "Whether the border should be painted.") public void setBorderPainted(boolean b) { boolean oldValue = paintBorder; paintBorder = b; @@ -359,11 +349,9 @@ public class JMenuBar extends JComponent implements Accessible,MenuElement * * @param m an Insets object containing the margin values * @see Insets - * @beaninfo - * bound: true - * attribute: visualUpdate true - * description: The space between the menubar's border and its contents */ + @BeanProperty(visualUpdate = true, description + = "The space between the menubar's border and its contents") public void setMargin(Insets m) { Insets old = margin; this.margin = m; @@ -423,6 +411,7 @@ public class JMenuBar extends JComponent implements Accessible,MenuElement * other menu elements. * @return an array of menu items in the menu bar. */ + @BeanProperty(bound = false) public MenuElement[] getSubElements() { MenuElement result[]; Vector tmp = new Vector(); @@ -487,6 +476,7 @@ public class JMenuBar extends JComponent implements Accessible,MenuElement * @return an AccessibleJMenuBar that serves as the * AccessibleContext of this JMenuBar */ + @BeanProperty(bound = false) public AccessibleContext getAccessibleContext() { if (accessibleContext == null) { accessibleContext = new AccessibleJMenuBar(); diff --git a/jdk/src/java.desktop/share/classes/javax/swing/JMenuItem.java b/jdk/src/java.desktop/share/classes/javax/swing/JMenuItem.java index 7af01881951..cf80c9827a9 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/JMenuItem.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/JMenuItem.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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,13 +24,11 @@ */ package javax.swing; -import java.util.EventListener; import java.awt.*; import java.awt.event.*; -import java.awt.image.*; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; +import java.beans.JavaBean; +import java.beans.BeanProperty; import java.io.Serializable; import java.io.ObjectOutputStream; @@ -38,7 +36,6 @@ import java.io.ObjectInputStream; import java.io.IOException; import javax.swing.plaf.*; -import javax.swing.plaf.basic.*; import javax.swing.event.*; import javax.accessibility.*; @@ -76,10 +73,6 @@ import javax.accessibility.*; * has been added to the java.beans package. * Please see {@link java.beans.XMLEncoder}. * - * @beaninfo - * attribute: isContainer false - * description: An item which can be selected in a menu. - * * @author Georges Saab * @author David Karlton * @see JPopupMenu @@ -88,6 +81,8 @@ import javax.accessibility.*; * @see JRadioButtonMenuItem * @since 1.2 */ +@JavaBean(defaultProperty = "UIClassID", description = "An item which can be selected in a menu.") +@SwingContainer(false) @SuppressWarnings("serial") public class JMenuItem extends AbstractButton implements Accessible,MenuElement { @@ -232,12 +227,9 @@ public class JMenuItem extends AbstractButton implements Accessible,MenuElement * * @param ui the JMenuItemUI L&F object * @see UIDefaults#getUI - * @beaninfo - * bound: true - * hidden: true - * attribute: visualUpdate true - * description: The UI object that implements the Component's LookAndFeel. */ + @BeanProperty(hidden = true, visualUpdate = true, description + = "The UI object that implements the LookAndFeel.") public void setUI(MenuItemUI ui) { super.setUI(ui); } @@ -260,6 +252,7 @@ public class JMenuItem extends AbstractButton implements Accessible,MenuElement * @see JComponent#getUIClassID * @see UIDefaults#getUI */ + @BeanProperty(bound = false) public String getUIClassID() { return uiClassID; } @@ -272,10 +265,9 @@ public class JMenuItem extends AbstractButton implements Accessible,MenuElement * event will not fire and the menu item will be disarmed. * * @param b true to arm the menu item so it can be selected - * @beaninfo - * description: Mouse release will fire an action event - * hidden: true */ + @BeanProperty(bound = false, hidden = true, description + = "Mouse release will fire an action event") public void setArmed(boolean b) { ButtonModel model = getModel(); @@ -300,11 +292,9 @@ public class JMenuItem extends AbstractButton implements Accessible,MenuElement * Enables or disables the menu item. * * @param b true to enable the item - * @beaninfo - * description: Does the component react to user interaction - * bound: true - * preferred: true */ + @BeanProperty(preferred = true, description + = "The enabled state of the component.") public void setEnabled(boolean b) { // Make sure we aren't armed! if (!b && !UIManager.getBoolean("MenuItem.disabledAreNavigable")) { @@ -344,13 +334,9 @@ public class JMenuItem extends AbstractButton implements Accessible,MenuElement * * @param keyStroke the KeyStroke which will * serve as an accelerator - * @beaninfo - * description: The keystroke combination which will invoke the - * JMenuItem's actionlisteners without navigating the - * menu hierarchy - * bound: true - * preferred: true */ + @BeanProperty(preferred = true, description + = "The keystroke combination which will invoke the JMenuItem's actionlisteners without navigating the menu hierarchy") public void setAccelerator(KeyStroke keyStroke) { KeyStroke oldAccelerator = accelerator; this.accelerator = keyStroke; @@ -681,6 +667,7 @@ public class JMenuItem extends AbstractButton implements Accessible,MenuElement * * @return an array of MenuElements */ + @BeanProperty(bound = false) public MenuElement[] getSubElements() { return new MenuElement[0]; } @@ -722,6 +709,7 @@ public class JMenuItem extends AbstractButton implements Accessible,MenuElement * array if no listeners have been added * @since 1.4 */ + @BeanProperty(bound = false) public MenuDragMouseListener[] getMenuDragMouseListeners() { return listenerList.getListeners(MenuDragMouseListener.class); } @@ -752,6 +740,7 @@ public class JMenuItem extends AbstractButton implements Accessible,MenuElement * array if no listeners have been added * @since 1.4 */ + @BeanProperty(bound = false) public MenuKeyListener[] getMenuKeyListeners() { return listenerList.getListeners(MenuKeyListener.class); } @@ -808,6 +797,7 @@ public class JMenuItem extends AbstractButton implements Accessible,MenuElement * @return an AccessibleJMenuItem that serves as the * AccessibleContext of this JMenuItem */ + @BeanProperty(bound = false) public AccessibleContext getAccessibleContext() { if (accessibleContext == null) { accessibleContext = new AccessibleJMenuItem(); diff --git a/jdk/src/java.desktop/share/classes/javax/swing/JOptionPane.java b/jdk/src/java.desktop/share/classes/javax/swing/JOptionPane.java index 491fddee12f..77eb97e9e03 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/JOptionPane.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/JOptionPane.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -22,7 +22,6 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ - package javax.swing; import java.awt.BorderLayout; @@ -35,6 +34,8 @@ import java.awt.Frame; import java.awt.Point; import java.awt.HeadlessException; import java.awt.Window; +import java.beans.JavaBean; +import java.beans.BeanProperty; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.awt.event.WindowListener; @@ -301,14 +302,12 @@ import sun.awt.AWTAccessor; * * @see JInternalFrame * - * @beaninfo - * attribute: isContainer true - * description: A component which implements standard dialog box controls. - * * @author James Gosling * @author Scott Violet * @since 1.2 */ +@JavaBean(defaultProperty = "UI", description = "A component which implements standard dialog box controls.") +@SwingContainer @SuppressWarnings("serial") // Same-version serialization only public class JOptionPane extends JComponent implements Accessible { @@ -1828,11 +1827,9 @@ public class JOptionPane extends JComponent implements Accessible * * @param ui the OptionPaneUI {@literal L&F} object * @see UIDefaults#getUI - * @beaninfo - * bound: true - * hidden: true - * description: The UI object that implements the optionpane's LookAndFeel */ + @BeanProperty(hidden = true, description + = "The UI object that implements the optionpane's LookAndFeel") public void setUI(OptionPaneUI ui) { if (this.ui != ui) { super.setUI(ui); @@ -1869,6 +1866,7 @@ public class JOptionPane extends JComponent implements Accessible * @see JComponent#getUIClassID * @see UIDefaults#getUI */ + @BeanProperty(bound = false) public String getUIClassID() { return uiClassID; } @@ -1878,12 +1876,9 @@ public class JOptionPane extends JComponent implements Accessible * Sets the option pane's message-object. * @param newMessage the Object to display * @see #getMessage - * - * @beaninfo - * preferred: true - * bound: true - * description: The optionpane's message object. */ + @BeanProperty(preferred = true, description + = "The optionpane's message object.") public void setMessage(Object newMessage) { Object oldMessage = message; @@ -1907,11 +1902,9 @@ public class JOptionPane extends JComponent implements Accessible * @param newIcon the Icon to display * * @see #getIcon - * @beaninfo - * preferred: true - * bound: true - * description: The option pane's type icon. */ + @BeanProperty(preferred = true, description + = "The option pane's type icon.") public void setIcon(Icon newIcon) { Object oldIcon = icon; @@ -1934,11 +1927,9 @@ public class JOptionPane extends JComponent implements Accessible * @param newValue the chosen value * * @see #getValue - * @beaninfo - * preferred: true - * bound: true - * description: The option pane's value object. */ + @BeanProperty(preferred = true, description + = "The option pane's value object.") public void setValue(Object newValue) { Object oldValue = value; @@ -1975,10 +1966,9 @@ public class JOptionPane extends JComponent implements Accessible * Components to add to the pane * * @see #getOptions - * @beaninfo - * bound: true - * description: The option pane's options objects. */ + @BeanProperty(description + = "The option pane's options objects.") public void setOptions(Object[] newOptions) { Object[] oldOptions = options; @@ -2012,11 +2002,9 @@ public class JOptionPane extends JComponent implements Accessible * keyboard focus * * @see #getInitialValue - * @beaninfo - * preferred: true - * bound: true - * description: The option pane's initial value object. */ + @BeanProperty(preferred = true, description + = "The option pane's initial value object.") public void setInitialValue(Object newInitialValue) { Object oldIV = initialValue; @@ -2048,11 +2036,9 @@ public class JOptionPane extends JComponent implements Accessible * legal values listed above * @see #getMessageType - * @beaninfo - * preferred: true - * bound: true - * description: The option pane's message type. */ + @BeanProperty(preferred = true, description + = "The option pane's message type.") public void setMessageType(int newType) { checkMessageType(newType); int oldType = messageType; @@ -2097,11 +2083,9 @@ public class JOptionPane extends JComponent implements Accessible * * @see #getOptionType * @see #setOptions - * @beaninfo - * preferred: true - * bound: true - * description: The option pane's option type. */ + @BeanProperty(preferred = true, description + = "The option pane's option type.") public void setOptionType(int newType) { checkOptionType(newType); int oldType = optionType; @@ -2149,10 +2133,9 @@ public class JOptionPane extends JComponent implements Accessible * @see #setWantsInput * @see #setInitialSelectionValue * @see #getSelectionValues - * @beaninfo - * bound: true - * description: The option pane's selection values. */ + @BeanProperty(description + = "The option pane's selection values.") public void setSelectionValues(Object[] newValues) { Object[] oldValues = selectionValues; @@ -2178,10 +2161,9 @@ public class JOptionPane extends JComponent implements Accessible * @param newValue the initially selected value * @see #setSelectionValues * @see #getInitialSelectionValue - * @beaninfo - * bound: true - * description: The option pane's initial selection value object. */ + @BeanProperty(description + = "The option pane's initial selection value object.") public void setInitialSelectionValue(Object newValue) { Object oldValue = initialSelectionValue; @@ -2215,11 +2197,9 @@ public class JOptionPane extends JComponent implements Accessible * @see #setInitialSelectionValue * @see #setWantsInput * @see #getInputValue - * @beaninfo - * preferred: true - * bound: true - * description: The option pane's input value object. */ + @BeanProperty(preferred = true, description + = "The option pane's input value object.") public void setInputValue(Object newValue) { Object oldValue = inputValue; @@ -2251,6 +2231,7 @@ public class JOptionPane extends JComponent implements Accessible * * @return an integer giving the maximum number of characters on a line */ + @BeanProperty(bound = false) public int getMaxCharactersPerLineCount() { return Integer.MAX_VALUE; } @@ -2271,11 +2252,9 @@ public class JOptionPane extends JComponent implements Accessible * is provided to allow the user to input a value. * @see #setSelectionValues * @see #setInputValue - * @beaninfo - * preferred: true - * bound: true - * description: Flag which allows the user to input a value. */ + @BeanProperty(preferred = true, description + = "Flag which allows the user to input a value.") public void setWantsInput(boolean newValue) { boolean oldValue = wantsInput; @@ -2525,10 +2504,9 @@ public class JOptionPane extends JComponent implements Accessible * * @return an AccessibleJOptionPane that serves as the * AccessibleContext of this AccessibleJOptionPane - * @beaninfo - * expert: true - * description: The AccessibleContext associated with this option pane */ + @BeanProperty(bound = false, expert = true, description + = "The AccessibleContext associated with this option pane") public AccessibleContext getAccessibleContext() { if (accessibleContext == null) { accessibleContext = new AccessibleJOptionPane(); diff --git a/jdk/src/java.desktop/share/classes/javax/swing/JPanel.java b/jdk/src/java.desktop/share/classes/javax/swing/JPanel.java index 293ca2237df..ac0be8dfe9e 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/JPanel.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/JPanel.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -25,13 +25,13 @@ package javax.swing; import java.awt.*; +import java.beans.JavaBean; +import java.beans.BeanProperty; import javax.swing.plaf.*; import javax.accessibility.*; -import java.io.Serializable; import java.io.ObjectOutputStream; -import java.io.ObjectInputStream; import java.io.IOException; @@ -56,13 +56,11 @@ import java.io.IOException; * has been added to the java.beans package. * Please see {@link java.beans.XMLEncoder}. * - * @beaninfo - * description: A generic lightweight container. - * * @author Arnaud Weber * @author Steve Wilson * @since 1.2 */ +@JavaBean(defaultProperty = "UI", description = "A generic lightweight container.") @SuppressWarnings("serial") // Same-version serialization only public class JPanel extends JComponent implements Accessible { @@ -145,12 +143,9 @@ public class JPanel extends JComponent implements Accessible * @param ui the PanelUI L&F object * @see UIDefaults#getUI * @since 1.4 - * @beaninfo - * bound: true - * hidden: true - * attribute: visualUpdate true - * description: The UI object that implements the Component's LookAndFeel. */ + @BeanProperty(hidden = true, visualUpdate = true, description + = "The UI object that implements the Component's LookAndFeel.") public void setUI(PanelUI ui) { super.setUI(ui); } @@ -162,10 +157,9 @@ public class JPanel extends JComponent implements Accessible * @return "PanelUI" * @see JComponent#getUIClassID * @see UIDefaults#getUI - * @beaninfo - * expert: true - * description: A string that specifies the name of the L&F class. */ + @BeanProperty(bound = false, expert = true, description + = "A string that specifies the name of the L&F class.") public String getUIClassID() { return uiClassID; } @@ -213,6 +207,7 @@ public class JPanel extends JComponent implements Accessible * @return an AccessibleJPanel that serves as the * AccessibleContext of this JPanel */ + @BeanProperty(bound = false) public AccessibleContext getAccessibleContext() { if (accessibleContext == null) { accessibleContext = new AccessibleJPanel(); diff --git a/jdk/src/java.desktop/share/classes/javax/swing/JPasswordField.java b/jdk/src/java.desktop/share/classes/javax/swing/JPasswordField.java index 82b6457e8ec..0094b1adb4c 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/JPasswordField.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/JPasswordField.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -25,13 +25,12 @@ package javax.swing; import javax.swing.text.*; -import javax.swing.plaf.*; import javax.accessibility.*; +import java.beans.JavaBean; +import java.beans.BeanProperty; import java.io.ObjectOutputStream; -import java.io.ObjectInputStream; import java.io.IOException; -import java.io.*; import java.util.Arrays; /** @@ -68,13 +67,11 @@ import java.util.Arrays; * has been added to the java.beans package. * Please see {@link java.beans.XMLEncoder}. * - * @beaninfo - * attribute: isContainer false - * description: Allows the editing of a line of text but doesn't show the characters. - * * @author Timothy Prinzing * @since 1.2 */ +@JavaBean(description = "Allows the editing of a line of text but doesn't show the characters.") +@SwingContainer(false) @SuppressWarnings("serial") // Same-version serialization only public class JPasswordField extends JTextField { @@ -151,6 +148,7 @@ public class JPasswordField extends JTextField { * @see JComponent#getUIClassID * @see UIDefaults#getUI */ + @BeanProperty(bound = false) public String getUIClassID() { return uiClassID; } @@ -191,10 +189,9 @@ public class JPasswordField extends JTextField { * @param c the echo character to display * @see #echoCharIsSet * @see #getEchoChar - * @beaninfo - * description: character to display in place of the real characters - * attribute: visualUpdate true */ + @BeanProperty(bound = false, visualUpdate = true, description + = "character to display in place of the real characters") public void setEchoChar(char c) { echoChar = c; echoCharSet = true; @@ -292,6 +289,7 @@ public class JPasswordField extends JTextField { * * @return the text */ + @BeanProperty(bound = false) public char[] getPassword() { Document doc = getDocument(); Segment txt = new Segment(); @@ -383,6 +381,7 @@ public class JPasswordField extends JTextField { * AccessibleContext of this * JPasswordField */ + @BeanProperty(bound = false) public AccessibleContext getAccessibleContext() { if (accessibleContext == null) { accessibleContext = new AccessibleJPasswordField(); diff --git a/jdk/src/java.desktop/share/classes/javax/swing/JPopupMenu.java b/jdk/src/java.desktop/share/classes/javax/swing/JPopupMenu.java index 0df8c126308..f225b2d44ee 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/JPopupMenu.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/JPopupMenu.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -22,7 +22,6 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ - package javax.swing; import java.awt.*; @@ -31,21 +30,18 @@ import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; -import java.beans.*; +import java.beans.JavaBean; +import java.beans.BeanProperty; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; -import java.util.Locale; import java.util.Vector; -import java.util.Hashtable; import javax.accessibility.*; import javax.swing.plaf.PopupMenuUI; -import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicComboPopup; import javax.swing.event.*; import sun.awt.SunToolkit; -import sun.security.util.SecurityConstants; - -import java.applet.Applet; /** * An implementation of a popup menu -- a small window that pops up @@ -75,15 +71,13 @@ import java.applet.Applet; * has been added to the java.beans package. * Please see {@link java.beans.XMLEncoder}. * - * @beaninfo - * attribute: isContainer false - * description: A small window that pops up and displays a series of choices. - * * @author Georges Saab * @author David Karlton * @author Arnaud Weber * @since 1.2 */ +@JavaBean(defaultProperty = "UI", description = "A small window that pops up and displays a series of choices.") +@SwingContainer(false) @SuppressWarnings("serial") public class JPopupMenu extends JComponent implements Accessible,MenuElement { @@ -210,12 +204,9 @@ public class JPopupMenu extends JComponent implements Accessible,MenuElement { * * @param ui the new PopupMenuUI L&F object * @see UIDefaults#getUI - * @beaninfo - * bound: true - * hidden: true - * attribute: visualUpdate true - * description: The UI object that implements the Component's LookAndFeel. */ + @BeanProperty(hidden = true, visualUpdate = true, description + = "The UI object that implements the Component's LookAndFeel.") public void setUI(PopupMenuUI ui) { super.setUI(ui); } @@ -237,6 +228,7 @@ public class JPopupMenu extends JComponent implements Accessible,MenuElement { * @see JComponent#getUIClassID * @see UIDefaults#getUI */ + @BeanProperty(bound = false) public String getUIClassID() { return uiClassID; } @@ -274,10 +266,9 @@ public class JPopupMenu extends JComponent implements Accessible,MenuElement { * * @param model the new SingleSelectionModel * @see SingleSelectionModel - * @beaninfo - * description: The selection model for the popup menu - * expert: true */ + @BeanProperty(bound = false, expert = true, description + = "The selection model for the popup menu") public void setSelectionModel(SingleSelectionModel model) { selectionModel = model; } @@ -495,12 +486,11 @@ public class JPopupMenu extends JComponent implements Accessible,MenuElement { * no matter what the value of this property. * * @param aFlag false to disable lightweight popups - * @beaninfo - * description: Determines whether lightweight popups are used when possible - * expert: true * * @see #isLightWeightPopupEnabled */ + @BeanProperty(bound = false, expert = true, description + = "Determines whether lightweight popups are used when possible") public void setLightWeightPopupEnabled(boolean aFlag) { // NOTE: this use to set the flag on a shared JPopupMenu, which meant // this effected ALL JPopupMenus. @@ -534,10 +524,9 @@ public class JPopupMenu extends JComponent implements Accessible,MenuElement { * @param label a string specifying the label for the popup menu * * @see #setLabel - * @beaninfo - * description: The label for the popup menu. - * bound: true */ + @BeanProperty(description + = "The label for the popup menu.") public void setLabel(String label) { String oldValue = this.label; this.label = label; @@ -637,6 +626,7 @@ public class JPopupMenu extends JComponent implements Accessible,MenuElement { * array if no listeners have been added * @since 1.4 */ + @BeanProperty(bound = false) public PopupMenuListener[] getPopupMenuListeners() { return listenerList.getListeners(PopupMenuListener.class); } @@ -669,6 +659,7 @@ public class JPopupMenu extends JComponent implements Accessible,MenuElement { * array if no listeners have been added * @since 1.5 */ + @BeanProperty(bound = false) public MenuKeyListener[] getMenuKeyListeners() { return listenerList.getListeners(MenuKeyListener.class); } @@ -753,10 +744,9 @@ public class JPopupMenu extends JComponent implements Accessible,MenuElement { * * @param b true to make the popup visible, or false to * hide it - * @beaninfo - * bound: true - * description: Makes the popup visible */ + @BeanProperty(description + = "Makes the popup visible") public void setVisible(boolean b) { if (DEBUG) { System.out.println("JPopupMenu.setVisible " + b); @@ -868,9 +858,9 @@ public class JPopupMenu extends JComponent implements Accessible,MenuElement { * in the screen's coordinate space * @param y the y coordinate of the popup's new position * in the screen's coordinate space - * @beaninfo - * description: The location of the popup menu. */ + @BeanProperty(description + = "The location of the popup menu.") public void setLocation(int x, int y) { int oldX = desiredLocationX; int oldY = desiredLocationY; @@ -908,10 +898,9 @@ public class JPopupMenu extends JComponent implements Accessible,MenuElement { * * @param invoker the Component in which the popup * menu is displayed - * @beaninfo - * description: The invoking component for the popup menu - * expert: true */ + @BeanProperty(bound = false, expert = true, description + = "The invoking component for the popup menu") public void setInvoker(Component invoker) { Component oldInvoker = this.invoker; this.invoker = invoker; @@ -1024,9 +1013,9 @@ public class JPopupMenu extends JComponent implements Accessible,MenuElement { * * @param d the Dimension specifying the new size * of this component. - * @beaninfo - * description: The size of the popup menu */ + @BeanProperty(description + = "The size of the popup menu") public void setPopupSize(Dimension d) { Dimension oldSize = getPreferredSize(); @@ -1047,9 +1036,9 @@ public class JPopupMenu extends JComponent implements Accessible,MenuElement { * * @param width the new width of the Popup in pixels * @param height the new height of the Popup in pixels - * @beaninfo - * description: The size of the popup menu */ + @BeanProperty(description + = "The size of the popup menu") public void setPopupSize(int width, int height) { setPopupSize(new Dimension(width, height)); } @@ -1059,11 +1048,9 @@ public class JPopupMenu extends JComponent implements Accessible,MenuElement { * in a change to the selection model. * * @param sel the Component to select - * @beaninfo - * description: The selected component on the popup menu - * expert: true - * hidden: true */ + @BeanProperty(expert = true, hidden = true, description + = "The selected component on the popup menu") public void setSelected(Component sel) { SingleSelectionModel model = getSelectionModel(); int index = getComponentIndex(sel); @@ -1085,9 +1072,9 @@ public class JPopupMenu extends JComponent implements Accessible,MenuElement { * * @param b if true, the border is painted. * @see #isBorderPainted - * @beaninfo - * description: Is the border of the popup menu painted */ + @BeanProperty(bound = false, description + = "Is the border of the popup menu painted") public void setBorderPainted(boolean b) { paintBorder = b; repaint(); @@ -1113,6 +1100,7 @@ public class JPopupMenu extends JComponent implements Accessible,MenuElement { * * @return an Insets object containing the margin values. */ + @BeanProperty(bound = false) public Insets getMargin() { if(margin == null) { return new Insets(0,0,0,0); @@ -1198,6 +1186,7 @@ public class JPopupMenu extends JComponent implements Accessible,MenuElement { * @return an AccessibleJPopupMenu that serves as the * AccessibleContext of this JPopupMenu */ + @BeanProperty(bound = false) public AccessibleContext getAccessibleContext() { if (accessibleContext == null) { accessibleContext = new AccessibleJPopupMenu(); @@ -1512,6 +1501,7 @@ public class JPopupMenu extends JComponent implements Accessible,MenuElement { * @return an array of MenuElement objects * @see MenuElement#getSubElements */ + @BeanProperty(bound = false) public MenuElement[] getSubElements() { MenuElement result[]; Vector tmp = new Vector(); diff --git a/jdk/src/java.desktop/share/classes/javax/swing/JProgressBar.java b/jdk/src/java.desktop/share/classes/javax/swing/JProgressBar.java index c823176ca36..3504f2ef16a 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/JProgressBar.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/JProgressBar.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -22,25 +22,23 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ - package javax.swing; -import java.awt.Color; import java.awt.Graphics; +import java.beans.JavaBean; +import java.beans.BeanProperty; import java.text.Format; import java.text.NumberFormat; import java.io.Serializable; import java.io.ObjectOutputStream; -import java.io.ObjectInputStream; import java.io.IOException; import javax.swing.event.*; import javax.accessibility.*; import javax.swing.plaf.ProgressBarUI; - /** * A component that visually displays the progress of some task. As the task * progresses towards completion, the progress bar displays the @@ -122,14 +120,12 @@ import javax.swing.plaf.ProgressBarUI; * @see javax.swing.BoundedRangeModel * @see javax.swing.SwingWorker * - * @beaninfo - * attribute: isContainer false - * description: A component that displays an integer value. - * * @author Michael C. Albers * @author Kathy Walrath * @since 1.2 */ +@JavaBean(defaultProperty = "UI", description = "A component that displays an integer value.") +@SwingContainer(false) @SuppressWarnings("serial") // Same-version serialization only public class JProgressBar extends JComponent implements SwingConstants, Accessible { @@ -394,13 +390,9 @@ public class JProgressBar extends JComponent implements SwingConstants, Accessib * @exception IllegalArgumentException if newOrientation * is an illegal value * @see #getOrientation - * - * @beaninfo - * preferred: true - * bound: true - * attribute: visualUpdate true - * description: Set the progress bar's orientation. */ + @BeanProperty(preferred = true, visualUpdate = true, description + = "Set the progress bar's orientation.") public void setOrientation(int newOrientation) { if (orientation != newOrientation) { switch (newOrientation) { @@ -453,11 +445,9 @@ public class JProgressBar extends JComponent implements SwingConstants, Accessib * @param b true if the progress bar should render a string * @see #isStringPainted * @see #setString - * @beaninfo - * bound: true - * attribute: visualUpdate true - * description: Whether the progress bar should render a string. */ + @BeanProperty(visualUpdate = true, description + = "Whether the progress bar should render a string.") public void setStringPainted(boolean b) { //PENDING: specify that string not painted when in indeterminate mode? // or just leave that to the L&F? @@ -506,11 +496,9 @@ public class JProgressBar extends JComponent implements SwingConstants, Accessib * @see #getString * @see #setStringPainted * @see #isStringPainted - * @beaninfo - * bound: true - * attribute: visualUpdate true - * description: Specifies the progress string to paint */ + @BeanProperty(visualUpdate = true, description + = "Specifies the progress string to paint") public void setString(String s){ String oldValue = progressString; progressString = s; @@ -526,6 +514,7 @@ public class JProgressBar extends JComponent implements SwingConstants, Accessib * * @return the percent complete for this progress bar */ + @BeanProperty(bound = false) public double getPercentComplete() { long span = model.getMaximum() - model.getMinimum(); double currentValue = model.getValue(); @@ -538,8 +527,6 @@ public class JProgressBar extends JComponent implements SwingConstants, Accessib * * @return the value of the borderPainted property * @see #setBorderPainted - * @beaninfo - * description: Does the progress bar paint its border */ public boolean isBorderPainted() { return paintBorder; @@ -556,11 +543,9 @@ public class JProgressBar extends JComponent implements SwingConstants, Accessib * should paint its border; * otherwise, false * @see #isBorderPainted - * @beaninfo - * bound: true - * attribute: visualUpdate true - * description: Whether the progress bar should paint its border. */ + @BeanProperty(visualUpdate = true, description + = "Whether the progress bar should paint its border.") public void setBorderPainted(boolean b) { boolean oldValue = paintBorder; paintBorder = b; @@ -601,12 +586,9 @@ public class JProgressBar extends JComponent implements SwingConstants, Accessib * * @param ui a ProgressBarUI object * @see UIDefaults#getUI - * @beaninfo - * bound: true - * hidden: true - * attribute: visualUpdate true - * description: The UI object that implements the Component's LookAndFeel. */ + @BeanProperty(hidden = true, visualUpdate = true, description + = "The UI object that implements the Component's LookAndFeel.") public void setUI(ProgressBarUI ui) { super.setUI(ui); } @@ -628,10 +610,9 @@ public class JProgressBar extends JComponent implements SwingConstants, Accessib * @return the string "ProgressBarUI" * @see JComponent#getUIClassID * @see UIDefaults#getUI - * @beaninfo - * expert: true - * description: A string that specifies the name of the look-and-feel class. */ + @BeanProperty(bound = false, expert = true, description + = "A string that specifies the name of the look-and-feel class.") public String getUIClassID() { return uiClassID; } @@ -702,6 +683,7 @@ public class JProgressBar extends JComponent implements SwingConstants, Accessib * array if no listeners have been added * @since 1.4 */ + @BeanProperty(bound = false) public ChangeListener[] getChangeListeners() { return listenerList.getListeners(ChangeListener.class); } @@ -752,11 +734,9 @@ public class JProgressBar extends JComponent implements SwingConstants, Accessib * and is set to {@code 0}. * * @param newModel the BoundedRangeModel to use - * - * @beaninfo - * expert: true - * description: The data model used by the JProgressBar. */ + @BeanProperty(bound = false, expert = true, description + = "The data model used by the JProgressBar.") public void setModel(BoundedRangeModel newModel) { // PENDING(???) setting the same model to multiple bars is broken; listeners BoundedRangeModel oldModel = getModel(); @@ -841,10 +821,9 @@ public class JProgressBar extends JComponent implements SwingConstants, Accessib * @see #getValue * @see #addChangeListener * @see BoundedRangeModel#setValue - * @beaninfo - * preferred: true - * description: The progress bar's current value. */ + @BeanProperty(bound = false, preferred = true, description + = "The progress bar's current value.") public void setValue(int n) { BoundedRangeModel brm = getModel(); int oldValue = brm.getValue(); @@ -874,10 +853,9 @@ public class JProgressBar extends JComponent implements SwingConstants, Accessib * @see #getMinimum * @see #addChangeListener * @see BoundedRangeModel#setMinimum - * @beaninfo - * preferred: true - * description: The progress bar's minimum value. */ + @BeanProperty(bound = false, preferred = true, description + = "The progress bar's minimum value.") public void setMinimum(int n) { getModel().setMinimum(n); } /** @@ -895,10 +873,9 @@ public class JProgressBar extends JComponent implements SwingConstants, Accessib * @see #getMaximum * @see #addChangeListener * @see BoundedRangeModel#setMaximum - * @beaninfo - * preferred: true - * description: The progress bar's maximum value. */ + @BeanProperty(bound = false, preferred = true, description + = "The progress bar's maximum value.") public void setMaximum(int n) { getModel().setMaximum(n); } /** @@ -925,12 +902,6 @@ public class JProgressBar extends JComponent implements SwingConstants, Accessib * @see javax.swing.plaf.basic.BasicProgressBarUI * * @since 1.4 - * - * @beaninfo - * bound: true - * attribute: visualUpdate true - * description: Set whether the progress bar is indeterminate (true) - * or normal (false). */ public void setIndeterminate(boolean newValue) { boolean oldValue = indeterminate; @@ -945,11 +916,9 @@ public class JProgressBar extends JComponent implements SwingConstants, Accessib * @see #setIndeterminate * * @since 1.4 - * - * @beaninfo - * description: Is the progress bar indeterminate (true) - * or normal (false)? */ + @BeanProperty(bound = false, description + = "Is the progress bar indeterminate (true) or normal (false)?") public boolean isIndeterminate() { return indeterminate; } @@ -1013,10 +982,9 @@ public class JProgressBar extends JComponent implements SwingConstants, Accessib * * @return an AccessibleJProgressBar that serves as the * AccessibleContext of this JProgressBar - * @beaninfo - * expert: true - * description: The AccessibleContext associated with this ProgressBar. */ + @BeanProperty(bound = false, expert = true, description + = "The AccessibleContext associated with this ProgressBar.") public AccessibleContext getAccessibleContext() { if (accessibleContext == null) { accessibleContext = new AccessibleJProgressBar(); diff --git a/jdk/src/java.desktop/share/classes/javax/swing/JRadioButton.java b/jdk/src/java.desktop/share/classes/javax/swing/JRadioButton.java index c5eaf6813bd..85c85407390 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/JRadioButton.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/JRadioButton.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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,18 +24,15 @@ */ package javax.swing; -import java.awt.*; -import java.awt.event.*; -import java.beans.*; +import java.beans.JavaBean; +import java.beans.BeanProperty; import javax.swing.plaf.*; import javax.accessibility.*; import java.io.ObjectOutputStream; -import java.io.ObjectInputStream; import java.io.IOException; - /** * An implementation of a radio button -- an item that can be selected or * deselected, and which displays its state to the user. @@ -78,15 +75,13 @@ import java.io.IOException; * has been added to the java.beans package. * Please see {@link java.beans.XMLEncoder}. * - * @beaninfo - * attribute: isContainer false - * description: A component which can display it's state as selected or deselected. - * * @see ButtonGroup * @see JCheckBox * @author Jeff Dinkins * @since 1.2 */ +@JavaBean(description = "A component which can display it's state as selected or deselected.") +@SwingContainer(false) @SuppressWarnings("serial") // Same-version serialization only public class JRadioButton extends JToggleButton implements Accessible { @@ -204,10 +199,9 @@ public class JRadioButton extends JToggleButton implements Accessible { * @return String "RadioButtonUI" * @see JComponent#getUIClassID * @see UIDefaults#getUI - * @beaninfo - * expert: true - * description: A string that specifies the name of the L&F class. */ + @BeanProperty(bound = false, expert = true, description + = "A string that specifies the name of the L&F class.") public String getUIClassID() { return uiClassID; } @@ -263,10 +257,9 @@ public class JRadioButton extends JToggleButton implements Accessible { * * @return an AccessibleJRadioButton that serves as the * AccessibleContext of this JRadioButton - * @beaninfo - * expert: true - * description: The AccessibleContext associated with this Button */ + @BeanProperty(bound = false, expert = true, description + = "The AccessibleContext associated with this Button") public AccessibleContext getAccessibleContext() { if (accessibleContext == null) { accessibleContext = new AccessibleJRadioButton(); diff --git a/jdk/src/java.desktop/share/classes/javax/swing/JRadioButtonMenuItem.java b/jdk/src/java.desktop/share/classes/javax/swing/JRadioButtonMenuItem.java index e1c219b4037..34a6cb7e0e5 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/JRadioButtonMenuItem.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/JRadioButtonMenuItem.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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,17 +24,11 @@ */ package javax.swing; -import java.util.EventListener; - -import java.awt.*; -import java.awt.event.*; -import java.awt.image.*; - +import java.beans.JavaBean; +import java.beans.BeanProperty; import java.io.ObjectOutputStream; -import java.io.ObjectInputStream; import java.io.IOException; -import javax.swing.plaf.*; import javax.accessibility.*; /** @@ -75,15 +69,13 @@ import javax.accessibility.*; * has been added to the java.beans package. * Please see {@link java.beans.XMLEncoder}. * - * @beaninfo - * attribute: isContainer false - * description: A component within a group of menu items which can be selected. - * * @author Georges Saab * @author David Karlton * @see ButtonGroup * @since 1.2 */ +@JavaBean(description = "A component within a group of menu items which can be selected.") +@SwingContainer(false) @SuppressWarnings("serial") // Same-version serialization only public class JRadioButtonMenuItem extends JMenuItem implements Accessible { /** @@ -191,6 +183,7 @@ public class JRadioButtonMenuItem extends JMenuItem implements Accessible { * @see JComponent#getUIClassID * @see UIDefaults#getUI */ + @BeanProperty(bound = false) public String getUIClassID() { return uiClassID; } @@ -248,6 +241,7 @@ public class JRadioButtonMenuItem extends JMenuItem implements Accessible { * @return an AccessibleJRadioButtonMenuItem that serves as the * AccessibleContext of this JRadioButtonMenuItem */ + @BeanProperty(bound = false) public AccessibleContext getAccessibleContext() { if (accessibleContext == null) { accessibleContext = new AccessibleJRadioButtonMenuItem(); diff --git a/jdk/src/java.desktop/share/classes/javax/swing/JRootPane.java b/jdk/src/java.desktop/share/classes/javax/swing/JRootPane.java index f9dea90da3e..4061f2e2471 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/JRootPane.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/JRootPane.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -34,6 +34,7 @@ import javax.swing.plaf.RootPaneUI; import java.util.Vector; import java.io.Serializable; import javax.swing.border.*; + import sun.awt.AWTAccessor; import sun.security.action.GetBooleanAction; @@ -421,21 +422,18 @@ public class JRootPane extends JComponent implements Accessible { * FILE_CHOOSER_DIALOG, QUESTION_DIALOG, or * WARNING_DIALOG. * @since 1.4 - * @beaninfo - * bound: true - * enum: NONE JRootPane.NONE - * FRAME JRootPane.FRAME - * PLAIN_DIALOG JRootPane.PLAIN_DIALOG - * INFORMATION_DIALOG JRootPane.INFORMATION_DIALOG - * ERROR_DIALOG JRootPane.ERROR_DIALOG - * COLOR_CHOOSER_DIALOG JRootPane.COLOR_CHOOSER_DIALOG - * FILE_CHOOSER_DIALOG JRootPane.FILE_CHOOSER_DIALOG - * QUESTION_DIALOG JRootPane.QUESTION_DIALOG - * WARNING_DIALOG JRootPane.WARNING_DIALOG - * expert: true - * attribute: visualUpdate true - * description: Identifies the type of Window decorations to provide */ + @BeanProperty(expert = true, visualUpdate = true, enumerationValues = { + "JRootPane.NONE", + "JRootPane.FRAME", + "JRootPane.PLAIN_DIALOG", + "JRootPane.INFORMATION_DIALOG", + "JRootPane.ERROR_DIALOG", + "JRootPane.COLOR_CHOOSER_DIALOG", + "JRootPane.FILE_CHOOSER_DIALOG", + "JRootPane.QUESTION_DIALOG", + "JRootPane.WARNING_DIALOG"}, description + = "Identifies the type of Window decorations to provide") public void setWindowDecorationStyle(int windowDecorationStyle) { if (windowDecorationStyle < 0 || windowDecorationStyle > WARNING_DIALOG) { @@ -463,14 +461,10 @@ public class JRootPane extends JComponent implements Accessible { * * @param ui the LabelUI L&F object * @see UIDefaults#getUI - * @beaninfo - * bound: true - * hidden: true - * expert: true - * attribute: visualUpdate true - * description: The UI object that implements the Component's LookAndFeel. * @since 1.3 */ + @BeanProperty(expert = true, hidden = true, visualUpdate = true, description + = "The UI object that implements the Component's LookAndFeel.") public void setUI(RootPaneUI ui) { super.setUI(ui); } @@ -783,10 +777,9 @@ public class JRootPane extends JComponent implements Accessible { * * @see JButton#isDefaultButton * @param defaultButton the JButton which is to be the default button - * - * @beaninfo - * description: The button activated by default in this root pane */ + @BeanProperty(description + = "The button activated by default in this root pane") public void setDefaultButton(JButton defaultButton) { JButton oldDefault = this.defaultButton; diff --git a/jdk/src/java.desktop/share/classes/javax/swing/JScrollBar.java b/jdk/src/java.desktop/share/classes/javax/swing/JScrollBar.java index 0f6b61640e7..39bae157b13 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/JScrollBar.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/JScrollBar.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -22,7 +22,6 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ - package javax.swing; import java.io.Serializable; @@ -31,18 +30,16 @@ import java.awt.Adjustable; import java.awt.Dimension; import java.awt.event.AdjustmentListener; import java.awt.event.AdjustmentEvent; -import java.awt.Graphics; +import java.beans.JavaBean; +import java.beans.BeanProperty; import javax.swing.event.*; import javax.swing.plaf.*; import javax.accessibility.*; import java.io.ObjectOutputStream; -import java.io.ObjectInputStream; import java.io.IOException; - - /** * An implementation of a scrollbar. The user positions the knob in the * scrollbar to determine the contents of the viewing area. The @@ -72,13 +69,12 @@ import java.io.IOException; * Please see {@link java.beans.XMLEncoder}. * * @see JScrollPane - * @beaninfo - * attribute: isContainer false - * description: A component that helps determine the visible content range of an area. * * @author David Kloba * @since 1.2 */ +@JavaBean(defaultProperty = "UI", description = "A component that helps determine the visible content range of an area.") +@SwingContainer(false) @SuppressWarnings("serial") // Same-version serialization only public class JScrollBar extends JComponent implements Adjustable, Accessible { @@ -207,12 +203,9 @@ public class JScrollBar extends JComponent implements Adjustable, Accessible * @param ui the ScrollBarUI {@literal L&F} object * @see UIDefaults#getUI * @since 1.4 - * @beaninfo - * bound: true - * hidden: true - * attribute: visualUpdate true - * description: The UI object that implements the Component's LookAndFeel */ + @BeanProperty(hidden = true, visualUpdate = true, description + = "The UI object that implements the Component's LookAndFeel") public void setUI(ScrollBarUI ui) { super.setUI(ui); } @@ -246,6 +239,7 @@ public class JScrollBar extends JComponent implements Adjustable, Accessible * @see JComponent#getUIClassID * @see UIDefaults#getUI */ + @BeanProperty(bound = false) public String getUIClassID() { return uiClassID; } @@ -271,14 +265,11 @@ public class JScrollBar extends JComponent implements Adjustable, Accessible * @param orientation an orientation of the {@code JScrollBar} * @exception IllegalArgumentException if orientation is not one of VERTICAL, HORIZONTAL * @see #getOrientation - * @beaninfo - * preferred: true - * bound: true - * attribute: visualUpdate true - * description: The scrollbar's orientation. - * enum: VERTICAL JScrollBar.VERTICAL - * HORIZONTAL JScrollBar.HORIZONTAL */ + @BeanProperty(preferred = true, visualUpdate = true, enumerationValues = { + "JScrollBar.VERTICAL", + "JScrollBar.HORIZONTAL"}, description + = "The scrollbar's orientation.") public void setOrientation(int orientation) { checkOrientation(orientation); @@ -319,11 +310,9 @@ public class JScrollBar extends JComponent implements Adjustable, Accessible * * @param newModel a new model * @see #getModel - * @beaninfo - * bound: true - * expert: true - * description: The scrollbar's BoundedRangeModel. */ + @BeanProperty(expert = true, description + = "The scrollbar's BoundedRangeModel.") public void setModel(BoundedRangeModel newModel) { Integer oldValue = null; BoundedRangeModel oldModel = model; @@ -384,11 +373,9 @@ public class JScrollBar extends JComponent implements Adjustable, Accessible * and ignore this property. * * @see #getUnitIncrement - * @beaninfo - * preferred: true - * bound: true - * description: The scrollbar's unit increment. */ + @BeanProperty(preferred = true, description + = "The scrollbar's unit increment.") public void setUnitIncrement(int unitIncrement) { int oldValue = this.unitIncrement; this.unitIncrement = unitIncrement; @@ -434,11 +421,9 @@ public class JScrollBar extends JComponent implements Adjustable, Accessible * and ignore this property. * * @see #getBlockIncrement() - * @beaninfo - * preferred: true - * bound: true - * description: The scrollbar's block increment. */ + @BeanProperty(preferred = true, description + = "The scrollbar's block increment.") public void setBlockIncrement(int blockIncrement) { int oldValue = this.blockIncrement; this.blockIncrement = blockIncrement; @@ -482,10 +467,9 @@ public class JScrollBar extends JComponent implements Adjustable, Accessible * * @see #getValue * @see BoundedRangeModel#setValue - * @beaninfo - * preferred: true - * description: The scrollbar's current value. */ + @BeanProperty(bound = false, preferred = true, description + = "The scrollbar's current value.") public void setValue(int value) { BoundedRangeModel m = getModel(); int oldValue = m.getValue(); @@ -518,10 +502,9 @@ public class JScrollBar extends JComponent implements Adjustable, Accessible * * @see #getVisibleAmount * @see BoundedRangeModel#setExtent - * @beaninfo - * preferred: true - * description: The amount of the view that is currently visible. */ + @BeanProperty(bound = false, preferred = true, description + = "The amount of the view that is currently visible.") public void setVisibleAmount(int extent) { getModel().setExtent(extent); } @@ -544,10 +527,9 @@ public class JScrollBar extends JComponent implements Adjustable, Accessible * * @see #getMinimum * @see BoundedRangeModel#setMinimum - * @beaninfo - * preferred: true - * description: The scrollbar's minimum value. */ + @BeanProperty(bound = false, preferred = true, description + = "The scrollbar's minimum value.") public void setMinimum(int minimum) { getModel().setMinimum(minimum); } @@ -570,10 +552,9 @@ public class JScrollBar extends JComponent implements Adjustable, Accessible * * @see #getMaximum * @see BoundedRangeModel#setMaximum - * @beaninfo - * preferred: true - * description: The scrollbar's maximum value. */ + @BeanProperty(bound = false, preferred = true, description + = "The scrollbar's maximum value.") public void setMaximum(int maximum) { getModel().setMaximum(maximum); } @@ -601,10 +582,9 @@ public class JScrollBar extends JComponent implements Adjustable, Accessible * * @see #getValueIsAdjusting * @see BoundedRangeModel#setValueIsAdjusting - * @beaninfo - * expert: true - * description: True if the scrollbar thumb is being dragged. */ + @BeanProperty(bound = false, expert = true, description + = "True if the scrollbar thumb is being dragged.") public void setValueIsAdjusting(boolean b) { BoundedRangeModel m = getModel(); boolean oldValue = m.getValueIsAdjusting(); @@ -693,6 +673,7 @@ public class JScrollBar extends JComponent implements Adjustable, Accessible * array if no listeners have been added * @since 1.4 */ + @BeanProperty(bound = false) public AdjustmentListener[] getAdjustmentListeners() { return listenerList.getListeners(AdjustmentListener.class); } @@ -845,6 +826,7 @@ public class JScrollBar extends JComponent implements Adjustable, Accessible * @return an AccessibleJScrollBar that serves as the * AccessibleContext of this JScrollBar */ + @BeanProperty(bound = false) public AccessibleContext getAccessibleContext() { if (accessibleContext == null) { accessibleContext = new AccessibleJScrollBar(); diff --git a/jdk/src/java.desktop/share/classes/javax/swing/JScrollPane.java b/jdk/src/java.desktop/share/classes/javax/swing/JScrollPane.java index 39700a68429..a51509baec3 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/JScrollPane.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/JScrollPane.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -22,7 +22,6 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ - package javax.swing; import javax.swing.plaf.*; @@ -40,6 +39,8 @@ import java.awt.Point; import java.io.ObjectOutputStream; import java.io.IOException; +import java.beans.JavaBean; +import java.beans.BeanProperty; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.beans.Transient; @@ -161,14 +162,11 @@ import java.beans.Transient; * @see #setCorner * @see #setViewportBorder * - * @beaninfo - * attribute: isContainer true - * attribute: containerDelegate getViewport - * description: A specialized container that manages a viewport, optional scrollbars and headers - * * @author Hans Muller * @since 1.2 */ +@JavaBean(defaultProperty = "UI", description = "A specialized container that manages a viewport, optional scrollbars and headers") +@SwingContainer(delegate = "getViewport") @SuppressWarnings("serial") // Same-version serialization only public class JScrollPane extends JComponent implements ScrollPaneConstants, Accessible { @@ -360,12 +358,9 @@ public class JScrollPane extends JComponent implements ScrollPaneConstants, Acce * @return the ScrollPaneUI object that renders this * component * @see #setUI - * @beaninfo - * bound: true - * hidden: true - * attribute: visualUpdate true - * description: The UI object that implements the Component's LookAndFeel. */ + @BeanProperty(hidden = true, visualUpdate = true, description + = "The UI object that implements the Component's LookAndFeel.") public ScrollPaneUI getUI() { return (ScrollPaneUI)ui; } @@ -403,10 +398,8 @@ public class JScrollPane extends JComponent implements ScrollPaneConstants, Acce * @return the string "ScrollPaneUI" * @see JComponent#getUIClassID * @see UIDefaults#getUI - * - * @beaninfo - * hidden: true */ + @BeanProperty(bound = false, hidden = true) public String getUIClassID() { return uiClassID; } @@ -427,9 +420,6 @@ public class JScrollPane extends JComponent implements ScrollPaneConstants, Acce * ScrollPaneLayout * @see java.awt.Container#getLayout * @see java.awt.Container#setLayout - * - * @beaninfo - * hidden: true */ public void setLayout(LayoutManager layout) { if (layout instanceof ScrollPaneLayout) { @@ -456,11 +446,9 @@ public class JScrollPane extends JComponent implements ScrollPaneConstants, Acce * @see JComponent#revalidate * @see JComponent#isValidateRoot * @see java.awt.Container#isValidateRoot - * - * @beaninfo - * hidden: true */ @Override + @BeanProperty(hidden = true) public boolean isValidateRoot() { return true; } @@ -489,15 +477,12 @@ public class JScrollPane extends JComponent implements ScrollPaneConstants, Acce * @exception IllegalArgumentException if policy * is not one of the legal values shown above * @see #getVerticalScrollBarPolicy - * - * @beaninfo - * preferred: true - * bound: true - * description: The scrollpane vertical scrollbar policy - * enum: VERTICAL_SCROLLBAR_AS_NEEDED ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED - * VERTICAL_SCROLLBAR_NEVER ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER - * VERTICAL_SCROLLBAR_ALWAYS ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS */ + @BeanProperty(preferred = true, enumerationValues = { + "ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED", + "ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER", + "ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS"}, description + = "The scrollpane vertical scrollbar policy") public void setVerticalScrollBarPolicy(int policy) { switch (policy) { case VERTICAL_SCROLLBAR_AS_NEEDED: @@ -537,15 +522,12 @@ public class JScrollPane extends JComponent implements ScrollPaneConstants, Acce * @exception IllegalArgumentException if policy * is not one of the legal values shown above * @see #getHorizontalScrollBarPolicy - * - * @beaninfo - * preferred: true - * bound: true - * description: The scrollpane scrollbar policy - * enum: HORIZONTAL_SCROLLBAR_AS_NEEDED ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED - * HORIZONTAL_SCROLLBAR_NEVER ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER - * HORIZONTAL_SCROLLBAR_ALWAYS ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS */ + @BeanProperty(preferred = true, enumerationValues = { + "ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED", + "ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER", + "ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS"}, description + = "The scrollpane scrollbar policy") public void setHorizontalScrollBarPolicy(int policy) { switch (policy) { case HORIZONTAL_SCROLLBAR_AS_NEEDED: @@ -587,12 +569,9 @@ public class JScrollPane extends JComponent implements ScrollPaneConstants, Acce * @param viewportBorder the border to be added * @see #getViewportBorder * @see #setViewport - * - * @beaninfo - * preferred: true - * bound: true - * description: The border around the viewport. */ + @BeanProperty(preferred = true, description + = "The border around the viewport.") public void setViewportBorder(Border viewportBorder) { Border oldValue = this.viewportBorder; this.viewportBorder = viewportBorder; @@ -605,6 +584,7 @@ public class JScrollPane extends JComponent implements ScrollPaneConstants, Acce * * @return a Rectangle object specifying the viewport border */ + @BeanProperty(bound = false) public Rectangle getViewportBorderBounds() { Rectangle borderR = new Rectangle(getSize()); @@ -840,12 +820,9 @@ public class JScrollPane extends JComponent implements ScrollPaneConstants, Acce * @param horizontalScrollBar the horizontal scrollbar to be added * @see #createHorizontalScrollBar * @see #getHorizontalScrollBar - * - * @beaninfo - * expert: true - * bound: true - * description: The horizontal scrollbar. */ + @BeanProperty(expert = true, description + = "The horizontal scrollbar.") public void setHorizontalScrollBar(JScrollBar horizontalScrollBar) { JScrollBar old = getHorizontalScrollBar(); this.horizontalScrollBar = horizontalScrollBar; @@ -899,12 +876,9 @@ public class JScrollPane extends JComponent implements ScrollPaneConstants, Acce * @param verticalScrollBar the new vertical scrollbar to be added * @see #createVerticalScrollBar * @see #getVerticalScrollBar - * - * @beaninfo - * expert: true - * bound: true - * description: The vertical scrollbar. */ + @BeanProperty(expert = true, description + = "The vertical scrollbar.") public void setVerticalScrollBar(JScrollBar verticalScrollBar) { JScrollBar old = getVerticalScrollBar(); this.verticalScrollBar = verticalScrollBar; @@ -959,14 +933,9 @@ public class JScrollPane extends JComponent implements ScrollPaneConstants, Acce * @see #createViewport * @see #getViewport * @see #setViewportView - * - * @beaninfo - * expert: true - * bound: true - * attribute: visualUpdate true - * description: The viewport child for this scrollpane - * */ + @BeanProperty(expert = true, visualUpdate = true, description + = "The viewport child for this scrollpane") public void setViewport(JViewport viewport) { JViewport old = getViewport(); this.viewport = viewport; @@ -1038,12 +1007,9 @@ public class JScrollPane extends JComponent implements ScrollPaneConstants, Acce * is set to null * @see #getRowHeader * @see #setRowHeaderView - * - * @beaninfo - * bound: true - * expert: true - * description: The row header child for this scrollpane */ + @BeanProperty(expert = true, description + = "The row header child for this scrollpane") public void setRowHeader(JViewport rowHeader) { JViewport old = getRowHeader(); this.rowHeader = rowHeader; @@ -1105,12 +1071,9 @@ public class JScrollPane extends JComponent implements ScrollPaneConstants, Acce * @param columnHeader a {@code JViewport} which is the new column header * @see #getColumnHeader * @see #setColumnHeaderView - * - * @beaninfo - * bound: true - * description: The column header child for this scrollpane - * attribute: visualUpdate true */ + @BeanProperty(visualUpdate = true, description + = "The column header child for this scrollpane") public void setColumnHeader(JViewport columnHeader) { JViewport old = getColumnHeader(); this.columnHeader = columnHeader; @@ -1303,10 +1266,9 @@ public class JScrollPane extends JComponent implements ScrollPaneConstants, Acce * @return true if mouse wheel scrolling is enabled, false otherwise * @see #setWheelScrollingEnabled * @since 1.4 - * @beaninfo - * bound: true - * description: Flag for enabling/disabling mouse wheel scrolling */ + @BeanProperty(description + = "Flag for enabling/disabling mouse wheel scrolling") public boolean isWheelScrollingEnabled() {return wheelScrollState;} /** @@ -1320,10 +1282,9 @@ public class JScrollPane extends JComponent implements ScrollPaneConstants, Acce * @see java.awt.event.MouseWheelEvent * @see java.awt.event.MouseWheelListener * @since 1.4 - * @beaninfo - * bound: true - * description: Flag for enabling/disabling mouse wheel scrolling */ + @BeanProperty(description + = "Flag for enabling/disabling mouse wheel scrolling") public void setWheelScrollingEnabled(boolean handleWheel) { boolean old = wheelScrollState; wheelScrollState = handleWheel; @@ -1424,6 +1385,7 @@ public class JScrollPane extends JComponent implements ScrollPaneConstants, Acce * @return an AccessibleJScrollPane that serves as the * AccessibleContext of this JScrollPane */ + @BeanProperty(bound = false) public AccessibleContext getAccessibleContext() { if (accessibleContext == null) { accessibleContext = new AccessibleJScrollPane(); diff --git a/jdk/src/java.desktop/share/classes/javax/swing/JSeparator.java b/jdk/src/java.desktop/share/classes/javax/swing/JSeparator.java index 2614096679b..cb3828a70c4 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/JSeparator.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/JSeparator.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -22,17 +22,16 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ - package javax.swing; import javax.swing.plaf.*; import javax.accessibility.*; +import java.beans.JavaBean; +import java.beans.BeanProperty; import java.io.ObjectOutputStream; -import java.io.ObjectInputStream; import java.io.IOException; - /** * JSeparator provides a general purpose component for * implementing divider lines - most commonly used as a divider @@ -64,14 +63,12 @@ import java.io.IOException; * has been added to the java.beans package. * Please see {@link java.beans.XMLEncoder}. * - * @beaninfo - * attribute: isContainer false - * description: A divider between menu items. - * * @author Georges Saab * @author Jeff Shapiro * @since 1.2 */ +@JavaBean(defaultProperty = "UI", description = "A divider between menu items.") +@SwingContainer(false) @SuppressWarnings("serial") public class JSeparator extends JComponent implements SwingConstants, Accessible { @@ -122,12 +119,9 @@ public class JSeparator extends JComponent implements SwingConstants, Accessible * * @param ui the SeparatorUI L&F object * @see UIDefaults#getUI - * @beaninfo - * bound: true - * hidden: true - * attribute: visualUpdate true - * description: The UI object that implements the Component's LookAndFeel. */ + @BeanProperty(hidden = true, visualUpdate = true, description + = "The UI object that implements the Component's LookAndFeel.") public void setUI(SeparatorUI ui) { super.setUI(ui); } @@ -149,6 +143,7 @@ public class JSeparator extends JComponent implements SwingConstants, Accessible * @see JComponent#getUIClassID * @see UIDefaults#getUI */ + @BeanProperty(bound = false) public String getUIClassID() { return uiClassID; } @@ -196,14 +191,11 @@ public class JSeparator extends JComponent implements SwingConstants, Accessible * * @see SwingConstants * @see #getOrientation - * @beaninfo - * bound: true - * preferred: true - * enum: HORIZONTAL SwingConstants.HORIZONTAL - * VERTICAL SwingConstants.VERTICAL - * attribute: visualUpdate true - * description: The orientation of the separator. */ + @BeanProperty(preferred = true, visualUpdate = true, enumerationValues = { + "SwingConstants.HORIZONTAL", + "SwingConstants.VERTICAL"}, description + = "The orientation of the separator.") public void setOrientation( int orientation ) { if (this.orientation == orientation) { return; @@ -260,6 +252,7 @@ public class JSeparator extends JComponent implements SwingConstants, Accessible * @return an AccessibleJSeparator that serves as the * AccessibleContext of this JSeparator */ + @BeanProperty(bound = false) public AccessibleContext getAccessibleContext() { if (accessibleContext == null) { accessibleContext = new AccessibleJSeparator(); diff --git a/jdk/src/java.desktop/share/classes/javax/swing/JSlider.java b/jdk/src/java.desktop/share/classes/javax/swing/JSlider.java index 5475d51ffc4..dce14e15bcf 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/JSlider.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/JSlider.java @@ -22,7 +22,6 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ - package javax.swing; import javax.swing.event.*; @@ -35,8 +34,10 @@ import java.io.IOException; import java.awt.*; import java.util.*; -import java.beans.*; - +import java.beans.JavaBean; +import java.beans.BeanProperty; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; /** * A component that lets the user graphically select a value by sliding @@ -72,13 +73,11 @@ import java.beans.*; * has been added to the java.beans package. * Please see {@link java.beans.XMLEncoder}. * - * @beaninfo - * attribute: isContainer false - * description: A component that supports selecting a integer value from a range. - * * @author David Kloba * @since 1.2 */ +@JavaBean(defaultProperty = "UI", description = "A component that supports selecting a integer value from a range.") +@SwingContainer(false) @SuppressWarnings("serial") // Same-version serialization only public class JSlider extends JComponent implements SwingConstants, Accessible { /** @@ -310,12 +309,9 @@ public class JSlider extends JComponent implements SwingConstants, Accessible { * * @param ui the SliderUI L&F object * @see UIDefaults#getUI - * @beaninfo - * bound: true - * hidden: true - * attribute: visualUpdate true - * description: The UI object that implements the slider's LookAndFeel. */ + @BeanProperty(hidden = true, visualUpdate = true, description + = "The UI object that implements the slider's LookAndFeel.") public void setUI(SliderUI ui) { super.setUI(ui); } @@ -343,6 +339,7 @@ public class JSlider extends JComponent implements SwingConstants, Accessible { * @see JComponent#getUIClassID * @see UIDefaults#getUI */ + @BeanProperty(bound = false) public String getUIClassID() { return uiClassID; } @@ -413,6 +410,7 @@ public class JSlider extends JComponent implements SwingConstants, Accessible { * array if no listeners have been added * @since 1.4 */ + @BeanProperty(bound = false) public ChangeListener[] getChangeListeners() { return listenerList.getListeners(ChangeListener.class); } @@ -468,10 +466,9 @@ public class JSlider extends JComponent implements SwingConstants, Accessible { * * @see #getModel * @see BoundedRangeModel - * @beaninfo - * bound: true - * description: The sliders BoundedRangeModel. */ + @BeanProperty(description + = "The sliders BoundedRangeModel.") public void setModel(BoundedRangeModel newModel) { BoundedRangeModel oldModel = getModel(); @@ -527,10 +524,9 @@ public class JSlider extends JComponent implements SwingConstants, Accessible { * @see #getValue * @see #addChangeListener * @see BoundedRangeModel#setValue - * @beaninfo - * preferred: true - * description: The sliders current value. */ + @BeanProperty(bound = false, preferred = true, description + = "The sliders current value.") public void setValue(int n) { BoundedRangeModel m = getModel(); int oldValue = m.getValue(); @@ -577,11 +573,9 @@ public class JSlider extends JComponent implements SwingConstants, Accessible { * @see #getMinimum * @see #addChangeListener * @see BoundedRangeModel#setMinimum - * @beaninfo - * bound: true - * preferred: true - * description: The sliders minimum value. */ + @BeanProperty(preferred = true, description + = "The sliders minimum value.") public void setMinimum(int minimum) { int oldMin = getModel().getMinimum(); getModel().setMinimum(minimum); @@ -618,11 +612,9 @@ public class JSlider extends JComponent implements SwingConstants, Accessible { * @see #getMaximum * @see #addChangeListener * @see BoundedRangeModel#setMaximum - * @beaninfo - * bound: true - * preferred: true - * description: The sliders maximum value. */ + @BeanProperty(preferred = true, description + = "The sliders maximum value.") public void setMaximum(int maximum) { int oldMax = getModel().getMaximum(); getModel().setMaximum(maximum); @@ -651,10 +643,9 @@ public class JSlider extends JComponent implements SwingConstants, Accessible { * @param b the new value for the {@code valueIsAdjusting} property * @see #getValueIsAdjusting * @see BoundedRangeModel#setValueIsAdjusting - * @beaninfo - * expert: true - * description: True if the slider knob is being dragged. */ + @BeanProperty(bound = false, expert = true, description + = "True if the slider knob is being dragged.") public void setValueIsAdjusting(boolean b) { BoundedRangeModel m = getModel(); boolean oldValue = m.getValueIsAdjusting(); @@ -699,10 +690,9 @@ public class JSlider extends JComponent implements SwingConstants, Accessible { * @param extent the new extent * @see #getExtent * @see BoundedRangeModel#setExtent - * @beaninfo - * expert: true - * description: Size of the range covered by the knob. */ + @BeanProperty(bound = false, expert = true, description + = "Size of the range covered by the knob.") public void setExtent(int extent) { getModel().setExtent(extent); } @@ -726,15 +716,11 @@ public class JSlider extends JComponent implements SwingConstants, Accessible { * @param orientation {@code HORIZONTAL} or {@code VERTICAL} * @throws IllegalArgumentException if orientation is not one of {@code VERTICAL}, {@code HORIZONTAL} * @see #getOrientation - * @beaninfo - * preferred: true - * bound: true - * attribute: visualUpdate true - * description: Set the scrollbars orientation to either VERTICAL or HORIZONTAL. - * enum: VERTICAL JSlider.VERTICAL - * HORIZONTAL JSlider.HORIZONTAL - * */ + @BeanProperty(preferred = true, visualUpdate = true, enumerationValues = { + "JSlider.VERTICAL", + "JSlider.HORIZONTAL"}, description + = "Set the scrollbars orientation to either VERTICAL or HORIZONTAL.") public void setOrientation(int orientation) { checkOrientation(orientation); @@ -828,12 +814,9 @@ public class JSlider extends JComponent implements SwingConstants, Accessible { * @see #createStandardLabels(int) * @see #getLabelTable * @see #setPaintLabels - * @beaninfo - * hidden: true - * bound: true - * attribute: visualUpdate true - * description: Specifies what labels will be drawn for any given value. */ + @BeanProperty(hidden = true, visualUpdate = true, description + = "Specifies what labels will be drawn for any given value.") @SuppressWarnings("rawtypes") public void setLabelTable( Dictionary labels ) { Dictionary oldTable = labelTable; @@ -1062,12 +1045,9 @@ public class JSlider extends JComponent implements SwingConstants, Accessible { * By default, the value of this property is {@code false}. * * @param b true to reverse the slider values from their normal order - * @beaninfo - * bound: true - * attribute: visualUpdate true - * description: If true reverses the slider values from their normal order - * */ + @BeanProperty(visualUpdate = true, description + = "If true reverses the slider values from their normal order") public void setInverted( boolean b ) { boolean oldValue = isInverted; isInverted = b; @@ -1118,12 +1098,9 @@ public class JSlider extends JComponent implements SwingConstants, Accessible { * @see #setPaintTicks * @see #setLabelTable * @see #createStandardLabels(int) - * @beaninfo - * bound: true - * attribute: visualUpdate true - * description: Sets the number of values between major tick marks. - * */ + @BeanProperty(visualUpdate = true, description + = "Sets the number of values between major tick marks.") public void setMajorTickSpacing(int n) { int oldValue = majorTickSpacing; majorTickSpacing = n; @@ -1166,11 +1143,9 @@ public class JSlider extends JComponent implements SwingConstants, Accessible { * @param n new value for the {@code minorTickSpacing} property * @see #getMinorTickSpacing * @see #setPaintTicks - * @beaninfo - * bound: true - * attribute: visualUpdate true - * description: Sets the number of values between minor tick marks. */ + @BeanProperty(visualUpdate = true, description + = "Sets the number of values between minor tick marks.") public void setMinorTickSpacing(int n) { int oldValue = minorTickSpacing; minorTickSpacing = n; @@ -1215,10 +1190,9 @@ public class JSlider extends JComponent implements SwingConstants, Accessible { * * @param b true to snap the knob to the nearest tick mark * @see #getSnapToTicks - * @beaninfo - * bound: true - * description: If true snap the knob to the nearest tick mark. */ + @BeanProperty(description + = "If true snap the knob to the nearest tick mark.") public void setSnapToTicks(boolean b) { boolean oldValue = snapToTicks; snapToTicks = b; @@ -1236,10 +1210,9 @@ public class JSlider extends JComponent implements SwingConstants, Accessible { * @param b true to snap the knob to the nearest slider value * @see #getSnapToValue * @see #setSnapToTicks - * @beaninfo - * bound: true - * description: If true snap the knob to the nearest slider value. */ + @BeanProperty(description + = "If true snap the knob to the nearest slider value.") void setSnapToValue(boolean b) { boolean oldValue = snapToValue; snapToValue = b; @@ -1263,11 +1236,9 @@ public class JSlider extends JComponent implements SwingConstants, Accessible { * * @param b whether or not tick marks should be painted * @see #getPaintTicks - * @beaninfo - * bound: true - * attribute: visualUpdate true - * description: If true tick marks are painted on the slider. */ + @BeanProperty(visualUpdate = true, description + = "If true tick marks are painted on the slider.") public void setPaintTicks(boolean b) { boolean oldValue = paintTicks; paintTicks = b; @@ -1294,11 +1265,9 @@ public class JSlider extends JComponent implements SwingConstants, Accessible { * * @param b whether or not to paint the slider track * @see #getPaintTrack - * @beaninfo - * bound: true - * attribute: visualUpdate true - * description: If true, the track is painted on the slider. */ + @BeanProperty(visualUpdate = true, description + = "If true, the track is painted on the slider.") public void setPaintTrack(boolean b) { boolean oldValue = paintTrack; paintTrack = b; @@ -1336,11 +1305,9 @@ public class JSlider extends JComponent implements SwingConstants, Accessible { * @see #getPaintLabels * @see #getLabelTable * @see #createStandardLabels(int) - * @beaninfo - * bound: true - * attribute: visualUpdate true - * description: If true labels are painted on the slider. */ + @BeanProperty(visualUpdate = true, description + = "If true labels are painted on the slider.") public void setPaintLabels(boolean b) { boolean oldValue = paintLabels; paintLabels = b; @@ -1422,6 +1389,7 @@ public class JSlider extends JComponent implements SwingConstants, Accessible { * @return an AccessibleJSlider that serves as the * AccessibleContext of this JSlider */ + @BeanProperty(bound = false) public AccessibleContext getAccessibleContext() { if (accessibleContext == null) { accessibleContext = new AccessibleJSlider(); diff --git a/jdk/src/java.desktop/share/classes/javax/swing/JSpinner.java b/jdk/src/java.desktop/share/classes/javax/swing/JSpinner.java index 42b1dc39b3b..b9a26cf4b40 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/JSpinner.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/JSpinner.java @@ -108,11 +108,6 @@ import sun.util.locale.provider.LocaleResources; * has been added to the java.beans package. * Please see {@link java.beans.XMLEncoder}. * - * @beaninfo - * attribute: isContainer false - * description: A single line input field that lets the user select a - * number or an object value from an ordered set. - * * @see SpinnerModel * @see AbstractSpinnerModel * @see SpinnerListModel @@ -124,6 +119,8 @@ import sun.util.locale.provider.LocaleResources; * @author Lynn Monsanto (accessibility) * @since 1.4 */ +@JavaBean(defaultProperty = "UI", description = "A single line input field that lets the user select a number or an object value from an ordered set.") +@SwingContainer(false) @SuppressWarnings("serial") // Same-version serialization only public class JSpinner extends JComponent implements Accessible { @@ -199,6 +196,7 @@ public class JSpinner extends JComponent implements Accessible * @see JComponent#getUIClassID * @see UIDefaults#getUI */ + @BeanProperty(bound = false) public String getUIClassID() { return uiClassID; } @@ -273,12 +271,9 @@ public class JSpinner extends JComponent implements Accessible * @see #getEditor * @see #setEditor * @throws IllegalArgumentException if model is null - * - * @beaninfo - * bound: true - * attribute: visualUpdate true - * description: Model that represents the value of this spinner. */ + @BeanProperty(visualUpdate = true, description + = "Model that represents the value of this spinner.") public void setModel(SpinnerModel model) { if (model == null) { throw new IllegalArgumentException("null model"); @@ -376,6 +371,7 @@ public class JSpinner extends JComponent implements Accessible * @see #getPreviousValue * @see SpinnerModel#getNextValue */ + @BeanProperty(bound = false) public Object getNextValue() { return getModel().getNextValue(); } @@ -436,6 +432,7 @@ public class JSpinner extends JComponent implements Accessible * array if no listeners have been added * @since 1.4 */ + @BeanProperty(bound = false) public ChangeListener[] getChangeListeners() { return listenerList.getListeners(ChangeListener.class); } @@ -484,6 +481,7 @@ public class JSpinner extends JComponent implements Accessible * @see #getNextValue * @see SpinnerModel#getPreviousValue */ + @BeanProperty(bound = false) public Object getPreviousValue() { return getModel().getPreviousValue(); } @@ -502,12 +500,9 @@ public class JSpinner extends JComponent implements Accessible * @see #createEditor * @see #getModel * @throws IllegalArgumentException if editor is null - * - * @beaninfo - * bound: true - * attribute: visualUpdate true - * description: JComponent that displays the current value of the model */ + @BeanProperty(visualUpdate = true, description + = "JComponent that displays the current value of the model") public void setEditor(JComponent editor) { if (editor == null) { throw new IllegalArgumentException("null editor"); @@ -1427,6 +1422,7 @@ public class JSpinner extends JComponent implements Accessible * @return the AccessibleContext for the JSpinner * @since 1.5 */ + @BeanProperty(bound = false) public AccessibleContext getAccessibleContext() { if (accessibleContext == null) { accessibleContext = new AccessibleJSpinner(); diff --git a/jdk/src/java.desktop/share/classes/javax/swing/JSplitPane.java b/jdk/src/java.desktop/share/classes/javax/swing/JSplitPane.java index 4b490b76cc4..8c38fa2df59 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/JSplitPane.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/JSplitPane.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -23,12 +23,10 @@ * questions. */ - - package javax.swing; - - +import java.beans.JavaBean; +import java.beans.BeanProperty; import java.beans.ConstructorProperties; import javax.swing.plaf.*; import javax.accessibility.*; @@ -36,11 +34,8 @@ import javax.accessibility.*; import java.awt.*; import java.io.ObjectOutputStream; -import java.io.ObjectInputStream; import java.io.IOException; - - /** * JSplitPane is used to divide two (and only two) * Components. The two Components @@ -99,6 +94,7 @@ import java.io.IOException; * @author Scott Violet * @since 1.2 */ +@JavaBean(defaultProperty = "UI") @SuppressWarnings("serial") // Same-version serialization only public class JSplitPane extends JComponent implements Accessible { @@ -365,11 +361,6 @@ public class JSplitPane extends JComponent implements Accessible * * @param ui the SplitPaneUI L&F object * @see UIDefaults#getUI - * @beaninfo - * bound: true - * hidden: true - * attribute: visualUpdate true - * description: The UI object that implements the Component's LookAndFeel. */ public void setUI(SplitPaneUI ui) { if ((SplitPaneUI)this.ui != ui) { @@ -384,10 +375,9 @@ public class JSplitPane extends JComponent implements Accessible * current look and feel. * * @return the SplitPaneUI object that renders this component - * @beaninfo - * expert: true - * description: The L&F object that renders this component. */ + @BeanProperty(bound = false, expert = true, description + = "The L&F object that renders this component.") public SplitPaneUI getUI() { return (SplitPaneUI)ui; } @@ -412,10 +402,9 @@ public class JSplitPane extends JComponent implements Accessible * @return the string "SplitPaneUI" * @see JComponent#getUIClassID * @see UIDefaults#getUI - * @beaninfo - * expert: true - * description: A string that specifies the name of the L&F class. */ + @BeanProperty(bound = false, expert = true, description + = "A string that specifies the name of the L&F class.") public String getUIClassID() { return uiClassID; } @@ -425,10 +414,9 @@ public class JSplitPane extends JComponent implements Accessible * Sets the size of the divider. * * @param newSize an integer giving the size of the divider in pixels - * @beaninfo - * bound: true - * description: The size of the divider. */ + @BeanProperty(description + = "The size of the divider.") public void setDividerSize(int newSize) { int oldSize = dividerSize; @@ -471,10 +459,9 @@ public class JSplitPane extends JComponent implements Accessible * Returns the component to the left (or above) the divider. * * @return the Component displayed in that position - * @beaninfo - * preferred: true - * description: The component to the left (or above) the divider. */ + @BeanProperty(bound = false, preferred = true, description + = "The component to the left (or above) the divider.") public Component getLeftComponent() { return leftComponent; } @@ -484,9 +471,9 @@ public class JSplitPane extends JComponent implements Accessible * Sets the component above, or to the left of the divider. * * @param comp the Component to display in that position - * @beaninfo - * description: The component above, or to the left of the divider. */ + @BeanProperty(bound = false, description + = "The component above, or to the left of the divider.") public void setTopComponent(Component comp) { setLeftComponent(comp); } @@ -506,10 +493,9 @@ public class JSplitPane extends JComponent implements Accessible * Sets the component to the right (or below) the divider. * * @param comp the Component to display in that position - * @beaninfo - * preferred: true - * description: The component to the right (or below) the divider. */ + @BeanProperty(bound = false, preferred = true, description + = "The component to the right (or below) the divider.") public void setRightComponent(Component comp) { if (comp == null) { if (rightComponent != null) { @@ -536,9 +522,9 @@ public class JSplitPane extends JComponent implements Accessible * Sets the component below, or to the right of the divider. * * @param comp the Component to display in that position - * @beaninfo - * description: The component below, or to the right of the divider. */ + @BeanProperty(bound = false, description + = "The component below, or to the right of the divider.") public void setBottomComponent(Component comp) { setRightComponent(comp); } @@ -565,13 +551,11 @@ public class JSplitPane extends JComponent implements Accessible * * @param newValue true to specify that the split pane should provide a * collapse/expand widget - * @beaninfo - * bound: true - * description: UI widget on the divider to quickly - * expand/collapse the divider. * * @see #isOneTouchExpandable */ + @BeanProperty(description + = "UI widget on the divider to quickly expand/collapse the divider.") public void setOneTouchExpandable(boolean newValue) { boolean oldValue = oneTouchExpandable; @@ -600,10 +584,9 @@ public class JSplitPane extends JComponent implements Accessible * @param newLastLocation an integer specifying the last divider location * in pixels, from the left (or upper) edge of the pane to the * left (or upper) edge of the divider - * @beaninfo - * bound: true - * description: The last location the divider was at. */ + @BeanProperty(description + = "The last location the divider was at.") public void setLastDividerLocation(int newLastLocation) { int oldLocation = lastDividerLocation; @@ -635,12 +618,11 @@ public class JSplitPane extends JComponent implements Accessible * @param orientation an integer specifying the orientation * @exception IllegalArgumentException if orientation is not one of: * HORIZONTAL_SPLIT or VERTICAL_SPLIT. - * @beaninfo - * bound: true - * description: The orientation, or how the splitter is divided. - * enum: HORIZONTAL_SPLIT JSplitPane.HORIZONTAL_SPLIT - * VERTICAL_SPLIT JSplitPane.VERTICAL_SPLIT */ + @BeanProperty(enumerationValues = { + "JSplitPane.HORIZONTAL_SPLIT", + "JSplitPane.VERTICAL_SPLIT"}, description + = "The orientation, or how the splitter is divided.") public void setOrientation(int orientation) { if ((orientation != VERTICAL_SPLIT) && (orientation != HORIZONTAL_SPLIT)) { @@ -679,13 +661,10 @@ public class JSplitPane extends JComponent implements Accessible * * @param newContinuousLayout true if the components * should continuously be redrawn as the divider changes position - * @beaninfo - * bound: true - * description: Whether the child components are - * continuously redisplayed and laid out during - * user intervention. * @see #isContinuousLayout */ + @BeanProperty(description + = "Whether the child components are continuously redisplayed and laid out during user intervention.") public void setContinuousLayout(boolean newContinuousLayout) { boolean oldCD = continuousLayout; @@ -718,11 +697,9 @@ public class JSplitPane extends JComponent implements Accessible * @param value as described above * @exception IllegalArgumentException if value is < 0 or > 1 * @since 1.3 - * @beaninfo - * bound: true - * description: Specifies how to distribute extra space when the split pane - * resizes. */ + @BeanProperty(description + = "Specifies how to distribute extra space when the split pane resizes.") public void setResizeWeight(double value) { if (value < 0 || value > 1) { throw new IllegalArgumentException("JSplitPane weight must be between 0 and 1"); @@ -773,9 +750,9 @@ public class JSplitPane extends JComponent implements Accessible * (bottom/right) * @exception IllegalArgumentException if the specified location is < 0 * or > 1.0 - * @beaninfo - * description: The location of the divider. */ + @BeanProperty(description + = "The location of the divider.") public void setDividerLocation(double proportionalLocation) { if (proportionalLocation < 0.0 || proportionalLocation > 1.0) { @@ -802,10 +779,9 @@ public class JSplitPane extends JComponent implements Accessible * * @param location an int specifying a UI-specific value (typically a * pixel count) - * @beaninfo - * bound: true - * description: The location of the divider. */ + @BeanProperty(description + = "The location of the divider.") public void setDividerLocation(int location) { int oldValue = dividerLocation; @@ -846,9 +822,9 @@ public class JSplitPane extends JComponent implements Accessible * @return an integer specifying a UI-specific value for the minimum * location (typically a pixel count); or -1 if the UI is * null - * @beaninfo - * description: The minimum location of the divider from the L&F. */ + @BeanProperty(bound = false, description + = "The minimum location of the divider from the L&F.") public int getMinimumDividerLocation() { SplitPaneUI ui = getUI(); @@ -867,6 +843,7 @@ public class JSplitPane extends JComponent implements Accessible * location (typically a pixel count); or -1 if the UI is * null */ + @BeanProperty(bound = false) public int getMaximumDividerLocation() { SplitPaneUI ui = getUI(); @@ -947,11 +924,9 @@ public class JSplitPane extends JComponent implements Accessible * @return true * @see JComponent#revalidate * @see java.awt.Container#isValidateRoot - * - * @beaninfo - * hidden: true */ @Override + @BeanProperty(hidden = true) public boolean isValidateRoot() { return true; } @@ -1132,10 +1107,9 @@ public class JSplitPane extends JComponent implements Accessible * * @return an AccessibleJSplitPane that serves as the * AccessibleContext of this JSplitPane - * @beaninfo - * expert: true - * description: The AccessibleContext associated with this SplitPane. */ + @BeanProperty(bound = false, expert = true, description + = "The AccessibleContext associated with this SplitPane.") public AccessibleContext getAccessibleContext() { if (accessibleContext == null) { accessibleContext = new AccessibleJSplitPane(); diff --git a/jdk/src/java.desktop/share/classes/javax/swing/JTabbedPane.java b/jdk/src/java.desktop/share/classes/javax/swing/JTabbedPane.java index 7afe712868a..d50e660e413 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/JTabbedPane.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/JTabbedPane.java @@ -22,16 +22,18 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ - package javax.swing; import java.awt.*; import java.awt.event.*; +import java.beans.JavaBean; +import java.beans.BeanProperty; import java.beans.Transient; import java.util.*; import javax.swing.event.*; import javax.swing.plaf.*; import javax.accessibility.*; + import sun.swing.SwingUtilities2; import java.io.Serializable; @@ -95,11 +97,6 @@ import java.io.IOException; * has been added to the java.beans package. * Please see {@link java.beans.XMLEncoder}. * - * @beaninfo - * attribute: isContainer true - * description: A component which provides a tab folder metaphor for - * displaying one component from a set of components. - * * @author Dave Moore * @author Philip Milne * @author Amy Fowler @@ -107,6 +104,8 @@ import java.io.IOException; * @see SingleSelectionModel * @since 1.2 */ +@JavaBean(defaultProperty = "UI", description = "A component which provides a tab folder metaphor for displaying one component from a set of components.") +@SwingContainer @SuppressWarnings("serial") // Same-version serialization only public class JTabbedPane extends JComponent implements Serializable, Accessible, SwingConstants { @@ -223,12 +222,9 @@ public class JTabbedPane extends JComponent * * @param ui the new UI object * @see UIDefaults#getUI - * @beaninfo - * bound: true - * hidden: true - * attribute: visualUpdate true - * description: The UI object that implements the tabbedpane's LookAndFeel */ + @BeanProperty(hidden = true, visualUpdate = true, description + = "The UI object that implements the tabbedpane's LookAndFeel") public void setUI(TabbedPaneUI ui) { super.setUI(ui); // disabled icons are generated by LF so they should be unset here @@ -258,6 +254,7 @@ public class JTabbedPane extends JComponent * @see JComponent#getUIClassID * @see UIDefaults#getUI */ + @BeanProperty(bound = false) public String getUIClassID() { return uiClassID; } @@ -315,7 +312,8 @@ public class JTabbedPane extends JComponent * array if no listeners have been added * @since 1.4 */ - public ChangeListener[] getChangeListeners() { + @BeanProperty(bound = false) + public ChangeListener[] getChangeListeners() { return listenerList.getListeners(ChangeListener.class); } @@ -437,10 +435,9 @@ public class JTabbedPane extends JComponent * * @param model the model to be used * @see #getModel - * @beaninfo - * bound: true - * description: The tabbedpane's SingleSelectionModel. */ + @BeanProperty(description + = "The tabbedpane's SingleSelectionModel.") public void setModel(SingleSelectionModel model) { SingleSelectionModel oldModel = getModel(); @@ -483,18 +480,13 @@ public class JTabbedPane extends JComponent * @param tabPlacement the placement for the tabs relative to the content * @exception IllegalArgumentException if tab placement value isn't one * of the above valid values - * - * @beaninfo - * preferred: true - * bound: true - * attribute: visualUpdate true - * enum: TOP JTabbedPane.TOP - * LEFT JTabbedPane.LEFT - * BOTTOM JTabbedPane.BOTTOM - * RIGHT JTabbedPane.RIGHT - * description: The tabbedpane's tab placement. - * */ + @BeanProperty(preferred = true, visualUpdate = true, enumerationValues = { + "JTabbedPane.TOP", + "JTabbedPane.LEFT", + "JTabbedPane.BOTTOM", + "JTabbedPane.RIGHT"}, description + = "The tabbedpane's tab placement.") public void setTabPlacement(int tabPlacement) { checkTabPlacement(tabPlacement); if (this.tabPlacement != tabPlacement) { @@ -546,16 +538,11 @@ public class JTabbedPane extends JComponent * of the above valid values * @see #getTabLayoutPolicy * @since 1.4 - * - * @beaninfo - * preferred: true - * bound: true - * attribute: visualUpdate true - * enum: WRAP_TAB_LAYOUT JTabbedPane.WRAP_TAB_LAYOUT - * SCROLL_TAB_LAYOUT JTabbedPane.SCROLL_TAB_LAYOUT - * description: The tabbedpane's policy for laying out the tabs - * */ + @BeanProperty(preferred = true, visualUpdate = true, enumerationValues = { + "JTabbedPane.WRAP_TAB_LAYOUT", + "JTabbedPane.SCROLL_TAB_LAYOUT"}, description + = "The tabbedpane's policy for laying out the tabs") public void setTabLayoutPolicy(int tabLayoutPolicy) { checkTabLayoutPolicy(tabLayoutPolicy); if (this.tabLayoutPolicy != tabLayoutPolicy) { @@ -600,10 +587,9 @@ public class JTabbedPane extends JComponent * * @see #getSelectedIndex * @see SingleSelectionModel#setSelectedIndex - * @beaninfo - * preferred: true - * description: The tabbedpane's selected tab index. */ + @BeanProperty(bound = false, preferred = true, description + = "The tabbedpane's selected tab index.") public void setSelectedIndex(int index) { if (index != -1) { checkIndex(index); @@ -686,10 +672,9 @@ public class JTabbedPane extends JComponent * @exception IllegalArgumentException if component not found in tabbed * pane * @see #getSelectedComponent - * @beaninfo - * preferred: true - * description: The tabbedpane's selected component. */ + @BeanProperty(bound = false, preferred = true, description + = "The tabbedpane's selected component.") public void setSelectedComponent(Component c) { int index = indexOfComponent(c); if (index != -1) { @@ -1096,6 +1081,7 @@ public class JTabbedPane extends JComponent * * @return an integer specifying the number of tabbed pages */ + @BeanProperty(bound = false) public int getTabCount() { return pages.size(); } @@ -1111,6 +1097,7 @@ public class JTabbedPane extends JComponent * is LEFT or RIGHT, * or 0 if there is no UI set on this tabbedpane */ + @BeanProperty(bound = false) public int getTabRunCount() { if (ui != null) { return ((TabbedPaneUI)ui).getTabRunCount(this); @@ -1329,11 +1316,9 @@ public class JTabbedPane extends JComponent * * @see #getTitleAt * @see #setTabComponentAt - * @beaninfo - * preferred: true - * attribute: visualUpdate true - * description: The title at the specified tab index. */ + @BeanProperty(preferred = true, visualUpdate = true, description + = "The title at the specified tab index.") public void setTitleAt(int index, String title) { Page page = pages.get(index); String oldTitle =page.title; @@ -1373,11 +1358,9 @@ public class JTabbedPane extends JComponent * @see #getIconAt * @see #getDisabledIconAt * @see #setTabComponentAt - * @beaninfo - * preferred: true - * attribute: visualUpdate true - * description: The icon at the specified tab index. */ + @BeanProperty(preferred = true, visualUpdate = true, description + = "The icon at the specified tab index.") public void setIconAt(int index, Icon icon) { Page page = pages.get(index); Icon oldIcon = page.icon; @@ -1414,11 +1397,9 @@ public class JTabbedPane extends JComponent * {@code (index < 0 || index >= tab count)} * * @see #getDisabledIconAt - * @beaninfo - * preferred: true - * attribute: visualUpdate true - * description: The disabled icon at the specified tab index. */ + @BeanProperty(preferred = true, visualUpdate = true, description + = "The disabled icon at the specified tab index.") public void setDisabledIconAt(int index, Icon disabledIcon) { Icon oldIcon = pages.get(index).disabledIcon; pages.get(index).disabledIcon = disabledIcon; @@ -1439,11 +1420,10 @@ public class JTabbedPane extends JComponent * {@code (index < 0 || index >= tab count)} * * @see #getToolTipTextAt - * @beaninfo - * preferred: true - * description: The tooltip text at the specified tab index. * @since 1.3 */ + @BeanProperty(preferred = true, description + = "The tooltip text at the specified tab index.") public void setToolTipTextAt(int index, String toolTipText) { String oldToolTipText = pages.get(index).tip; pages.get(index).tip = toolTipText; @@ -1475,11 +1455,9 @@ public class JTabbedPane extends JComponent * {@code (index < 0 || index >= tab count)} * * @see #getBackgroundAt - * @beaninfo - * preferred: true - * attribute: visualUpdate true - * description: The background color at the specified tab index. */ + @BeanProperty(preferred = true, visualUpdate = true, description + = "The background color at the specified tab index.") public void setBackgroundAt(int index, Color background) { Color oldBg = pages.get(index).background; pages.get(index).setBackground(background); @@ -1508,11 +1486,9 @@ public class JTabbedPane extends JComponent * {@code (index < 0 || index >= tab count)} * * @see #getForegroundAt - * @beaninfo - * preferred: true - * attribute: visualUpdate true - * description: The foreground color at the specified tab index. */ + @BeanProperty(preferred = true, visualUpdate = true, description + = "The foreground color at the specified tab index.") public void setForegroundAt(int index, Color foreground) { Color oldFg = pages.get(index).foreground; pages.get(index).setForeground(foreground); @@ -1555,10 +1531,9 @@ public class JTabbedPane extends JComponent * {@code (index < 0 || index >= tab count)} * * @see #getComponentAt - * @beaninfo - * attribute: visualUpdate true - * description: The component at the specified tab index. */ + @BeanProperty(visualUpdate = true, description + = "The component at the specified tab index.") @SuppressWarnings("deprecation") public void setComponentAt(int index, Component component) { Page page = pages.get(index); @@ -1635,13 +1610,9 @@ public class JTabbedPane extends JComponent * title , or < -1 * @see #setMnemonicAt(int,int) * @see #getDisplayedMnemonicIndexAt(int) - * - * @beaninfo - * bound: true - * attribute: visualUpdate true - * description: the index into the String to draw the keyboard character - * mnemonic at */ + @BeanProperty(visualUpdate = true, description + = "the index into the String to draw the keyboard character mnemonic at") public void setDisplayedMnemonicIndexAt(int tabIndex, int mnemonicIndex) { checkIndex(tabIndex); @@ -1675,13 +1646,9 @@ public class JTabbedPane extends JComponent * of range ({@code tabIndex < 0 || tabIndex >= tab count}) * @see #getMnemonicAt(int) * @see #setDisplayedMnemonicIndexAt(int,int) - * - * @beaninfo - * bound: true - * attribute: visualUpdate true - * description: The keyboard mnenmonic, as a KeyEvent VK constant, - * for the specified tab */ + @BeanProperty(visualUpdate = true, description + = "The keyboard mnenmonic, as a KeyEvent VK constant, for the specified tab") public void setMnemonicAt(int tabIndex, int mnemonic) { checkIndex(tabIndex); @@ -1896,6 +1863,7 @@ public class JTabbedPane extends JComponent * @return an AccessibleJTabbedPane that serves as the * AccessibleContext of this JTabbedPane */ + @BeanProperty(bound = false) public AccessibleContext getAccessibleContext() { if (accessibleContext == null) { accessibleContext = new AccessibleJTabbedPane(); @@ -2397,12 +2365,10 @@ public class JTabbedPane extends JComponent * added to this JTabbedPane * * @see #getTabComponentAt - * @beaninfo - * preferred: true - * attribute: visualUpdate true - * description: The tab component at the specified tab index. * @since 1.6 */ + @BeanProperty(preferred = true, visualUpdate = true, description + = "The tab component at the specified tab index.") public void setTabComponentAt(int index, Component component) { if (component != null && indexOfComponent(component) != -1) { throw new IllegalArgumentException("Component is already added to this JTabbedPane"); diff --git a/jdk/src/java.desktop/share/classes/javax/swing/JTable.java b/jdk/src/java.desktop/share/classes/javax/swing/JTable.java index 6b83043597e..f00473866a7 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/JTable.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/JTable.java @@ -22,7 +22,6 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ - package javax.swing; import java.util.*; @@ -32,7 +31,10 @@ import java.awt.*; import java.awt.event.*; import java.awt.print.*; -import java.beans.*; +import java.beans.JavaBean; +import java.beans.BeanProperty; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; import java.io.ObjectOutputStream; import java.io.ObjectInputStream; @@ -207,11 +209,6 @@ import sun.swing.PrintingStatus; * has been added to the java.beans package. * Please see {@link java.beans.XMLEncoder}. * - * - * @beaninfo - * attribute: isContainer false - * description: A component which displays data in a two dimensional grid. - * * @author Philip Milne * @author Shannon Hickey (printing support) * @see javax.swing.table.DefaultTableModel @@ -221,6 +218,8 @@ import sun.swing.PrintingStatus; /* The first versions of the JTable, contained in Swing-0.1 through * Swing-0.4, were written by Alan Chung. */ +@JavaBean(defaultProperty = "UI", description = "A component which displays data in a two dimensional grid.") +@SwingContainer(false) @SuppressWarnings("serial") // Same-version serialization only public class JTable extends JComponent implements TableModelListener, Scrollable, TableColumnModelListener, ListSelectionListener, CellEditorListener, @@ -894,10 +893,9 @@ public class JTable extends JComponent implements TableModelListener, Scrollable * * @param tableHeader new tableHeader * @see #getTableHeader - * @beaninfo - * bound: true - * description: The JTableHeader instance which renders the column headers. */ + @BeanProperty(description + = "The JTableHeader instance which renders the column headers.") public void setTableHeader(JTableHeader tableHeader) { if (this.tableHeader != tableHeader) { JTableHeader old = this.tableHeader; @@ -933,10 +931,9 @@ public class JTable extends JComponent implements TableModelListener, Scrollable * @exception IllegalArgumentException if rowHeight is * less than 1 * @see #getRowHeight - * @beaninfo - * bound: true - * description: The height of the specified row. */ + @BeanProperty(description + = "The height of the specified row.") public void setRowHeight(int rowHeight) { if (rowHeight <= 0) { throw new IllegalArgumentException("New row height less than 1"); @@ -979,11 +976,10 @@ public class JTable extends JComponent implements TableModelListener, Scrollable * @param rowHeight new row height, in pixels * @exception IllegalArgumentException if rowHeight is * less than 1 - * @beaninfo - * bound: true - * description: The height in pixels of the cells in row * @since 1.3 */ + @BeanProperty(description + = "The height in pixels of the cells in row") public void setRowHeight(int row, int rowHeight) { if (rowHeight <= 0) { throw new IllegalArgumentException("New row height less than 1"); @@ -1010,10 +1006,9 @@ public class JTable extends JComponent implements TableModelListener, Scrollable * * @param rowMargin the number of pixels between cells in a row * @see #getRowMargin - * @beaninfo - * bound: true - * description: The amount of space between cells. */ + @BeanProperty(description + = "The amount of space between cells.") public void setRowMargin(int rowMargin) { int old = this.rowMargin; this.rowMargin = rowMargin; @@ -1041,10 +1036,9 @@ public class JTable extends JComponent implements TableModelListener, Scrollable * specifying the new width * and height between cells * @see #getIntercellSpacing - * @beaninfo - * description: The spacing between the cells, - * drawn in the background color of the JTable. */ + @BeanProperty(bound = false, description + = "The spacing between the cells, drawn in the background color of the JTable.") public void setIntercellSpacing(Dimension intercellSpacing) { // Set the rowMargin here and columnMargin in the TableColumnModel setRowMargin(intercellSpacing.height); @@ -1071,10 +1065,9 @@ public class JTable extends JComponent implements TableModelListener, Scrollable * @param gridColor the new color of the grid lines * @exception IllegalArgumentException if gridColor is null * @see #getGridColor - * @beaninfo - * bound: true - * description: The grid color. */ + @BeanProperty(description + = "The grid color.") public void setGridColor(Color gridColor) { if (gridColor == null) { throw new IllegalArgumentException("New color is null"); @@ -1108,9 +1101,9 @@ public class JTable extends JComponent implements TableModelListener, Scrollable * * @see #setShowVerticalLines * @see #setShowHorizontalLines - * @beaninfo - * description: The color used to draw the grid lines. */ + @BeanProperty(description + = "The color used to draw the grid lines.") public void setShowGrid(boolean showGrid) { setShowHorizontalLines(showGrid); setShowVerticalLines(showGrid); @@ -1127,10 +1120,9 @@ public class JTable extends JComponent implements TableModelListener, Scrollable * @see #getShowHorizontalLines * @see #setShowGrid * @see #setShowVerticalLines - * @beaninfo - * bound: true - * description: Whether horizontal lines should be drawn in between the cells. */ + @BeanProperty(description + = "Whether horizontal lines should be drawn in between the cells.") public void setShowHorizontalLines(boolean showHorizontalLines) { boolean old = this.showHorizontalLines; this.showHorizontalLines = showHorizontalLines; @@ -1148,10 +1140,9 @@ public class JTable extends JComponent implements TableModelListener, Scrollable * @see #getShowVerticalLines * @see #setShowGrid * @see #setShowHorizontalLines - * @beaninfo - * bound: true - * description: Whether vertical lines should be drawn in between the cells. */ + @BeanProperty(description + = "Whether vertical lines should be drawn in between the cells.") public void setShowVerticalLines(boolean showVerticalLines) { boolean old = this.showVerticalLines; this.showVerticalLines = showVerticalLines; @@ -1198,15 +1189,14 @@ public class JTable extends JComponent implements TableModelListener, Scrollable * * @see #getAutoResizeMode * @see #doLayout - * @beaninfo - * bound: true - * description: Whether the columns should adjust themselves automatically. - * enum: AUTO_RESIZE_OFF JTable.AUTO_RESIZE_OFF - * AUTO_RESIZE_NEXT_COLUMN JTable.AUTO_RESIZE_NEXT_COLUMN - * AUTO_RESIZE_SUBSEQUENT_COLUMNS JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS - * AUTO_RESIZE_LAST_COLUMN JTable.AUTO_RESIZE_LAST_COLUMN - * AUTO_RESIZE_ALL_COLUMNS JTable.AUTO_RESIZE_ALL_COLUMNS */ + @BeanProperty(enumerationValues = { + "JTable.AUTO_RESIZE_OFF", + "JTable.AUTO_RESIZE_NEXT_COLUMN", + "JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS", + "JTable.AUTO_RESIZE_LAST_COLUMN", + "JTable.AUTO_RESIZE_ALL_COLUMNS"}, description + = "Whether the columns should adjust themselves automatically.") public void setAutoResizeMode(int mode) { if (isValidAutoResizeMode(mode)) { int old = autoResizeMode; @@ -1248,10 +1238,9 @@ public class JTable extends JComponent implements TableModelListener, Scrollable * @param autoCreateColumnsFromModel true if JTable should automatically create columns * @see #getAutoCreateColumnsFromModel * @see #createDefaultColumnsFromModel - * @beaninfo - * bound: true - * description: Automatically populates the columnModel when a new TableModel is submitted. */ + @BeanProperty(description + = "Automatically populates the columnModel when a new TableModel is submitted.") public void setAutoCreateColumnsFromModel(boolean autoCreateColumnsFromModel) { if (this.autoCreateColumnsFromModel != autoCreateColumnsFromModel) { boolean old = this.autoCreateColumnsFromModel; @@ -1442,11 +1431,9 @@ public class JTable extends JComponent implements TableModelListener, Scrollable * @see #setTransferHandler * @see TransferHandler * @since 1.4 - * - * @beaninfo - * description: determines whether automatic drag handling is enabled - * bound: false */ + @BeanProperty(bound = false, description + = "determines whether automatic drag handling is enabled") public void setDragEnabled(boolean b) { checkDragEnabled(b); dragEnabled = b; @@ -1834,6 +1821,7 @@ public class JTable extends JComponent implements TableModelListener, Scrollable * @see TransferHandler#canImport(TransferHandler.TransferSupport) * @since 1.6 */ + @BeanProperty(bound = false) public final DropLocation getDropLocation() { return dropLocation; } @@ -1853,12 +1841,10 @@ public class JTable extends JComponent implements TableModelListener, Scrollable * @param autoCreateRowSorter whether or not a {@code RowSorter} * should be automatically created * @see javax.swing.table.TableRowSorter - * @beaninfo - * bound: true - * preferred: true - * description: Whether or not to turn on sorting by default. * @since 1.6 */ + @BeanProperty(preferred = true, description + = "Whether or not to turn on sorting by default.") public void setAutoCreateRowSorter(boolean autoCreateRowSorter) { boolean oldValue = this.autoCreateRowSorter; this.autoCreateRowSorter = autoCreateRowSorter; @@ -1889,12 +1875,10 @@ public class JTable extends JComponent implements TableModelListener, Scrollable * is true. * * @param update whether or not to update the selection on sorting - * @beaninfo - * bound: true - * expert: true - * description: Whether or not to update the selection on sorting * @since 1.6 */ + @BeanProperty(expert = true, description + = "Whether or not to update the selection on sorting") public void setUpdateSelectionOnSort(boolean update) { if (updateSelectionOnSort != update) { updateSelectionOnSort = update; @@ -1929,11 +1913,10 @@ public class JTable extends JComponent implements TableModelListener, Scrollable * @param sorter the RowSorter; null turns * sorting off * @see javax.swing.table.TableRowSorter - * @beaninfo - * bound: true - * description: The table's RowSorter * @since 1.6 */ + @BeanProperty(description + = "The table's RowSorter") public void setRowSorter(RowSorter sorter) { RowSorter oldRowSorter = null; if (sortManager != null) { @@ -1985,12 +1968,12 @@ public class JTable extends JComponent implements TableModelListener, Scrollable * * @param selectionMode the mode used by the row and column selection models * @see JList#setSelectionMode - * @beaninfo - * description: The selection mode used by the row and column selection models. - * enum: SINGLE_SELECTION ListSelectionModel.SINGLE_SELECTION - * SINGLE_INTERVAL_SELECTION ListSelectionModel.SINGLE_INTERVAL_SELECTION - * MULTIPLE_INTERVAL_SELECTION ListSelectionModel.MULTIPLE_INTERVAL_SELECTION */ + @BeanProperty(enumerationValues = { + "ListSelectionModel.SINGLE_SELECTION", + "ListSelectionModel.SINGLE_INTERVAL_SELECTION", + "ListSelectionModel.MULTIPLE_INTERVAL_SELECTION"}, description + = "The selection mode used by the row and column selection models.") public void setSelectionMode(int selectionMode) { clearSelection(); getSelectionModel().setSelectionMode(selectionMode); @@ -2002,11 +1985,9 @@ public class JTable extends JComponent implements TableModelListener, Scrollable * * @param rowSelectionAllowed true if this model will allow row selection * @see #getRowSelectionAllowed - * @beaninfo - * bound: true - * attribute: visualUpdate true - * description: If true, an entire row is selected for each selected cell. */ + @BeanProperty(visualUpdate = true, description + = "If true, an entire row is selected for each selected cell.") public void setRowSelectionAllowed(boolean rowSelectionAllowed) { boolean old = this.rowSelectionAllowed; this.rowSelectionAllowed = rowSelectionAllowed; @@ -2031,11 +2012,9 @@ public class JTable extends JComponent implements TableModelListener, Scrollable * * @param columnSelectionAllowed true if this model will allow column selection * @see #getColumnSelectionAllowed - * @beaninfo - * bound: true - * attribute: visualUpdate true - * description: If true, an entire column is selected for each selected cell. */ + @BeanProperty(visualUpdate = true, description + = "If true, an entire column is selected for each selected cell.") public void setColumnSelectionAllowed(boolean columnSelectionAllowed) { boolean old = columnModel.getColumnSelectionAllowed(); columnModel.setColumnSelectionAllowed(columnSelectionAllowed); @@ -2069,12 +2048,9 @@ public class JTable extends JComponent implements TableModelListener, Scrollable * selection is allowed * @see #getCellSelectionEnabled * @see #isCellSelected - * @beaninfo - * bound: true - * attribute: visualUpdate true - * description: Select a rectangular region of cells rather than - * rows or columns. */ + @BeanProperty(visualUpdate = true, description + = "Select a rectangular region of cells rather than rows or columns.") public void setCellSelectionEnabled(boolean cellSelectionEnabled) { setRowSelectionAllowed(cellSelectionEnabled); setColumnSelectionAllowed(cellSelectionEnabled); @@ -2262,6 +2238,7 @@ public class JTable extends JComponent implements TableModelListener, Scrollable * Returns the index of the first selected row, -1 if no row is selected. * @return the index of the first selected row */ + @BeanProperty(bound = false) public int getSelectedRow() { return selectionModel.getMinSelectionIndex(); } @@ -2271,6 +2248,7 @@ public class JTable extends JComponent implements TableModelListener, Scrollable * -1 if no column is selected. * @return the index of the first selected column */ + @BeanProperty(bound = false) public int getSelectedColumn() { return columnModel.getSelectionModel().getMinSelectionIndex(); } @@ -2282,6 +2260,7 @@ public class JTable extends JComponent implements TableModelListener, Scrollable * or an empty array if no row is selected * @see #getSelectedRow */ + @BeanProperty(bound = false) public int[] getSelectedRows() { int iMin = selectionModel.getMinSelectionIndex(); int iMax = selectionModel.getMaxSelectionIndex(); @@ -2309,6 +2288,7 @@ public class JTable extends JComponent implements TableModelListener, Scrollable * or an empty array if no column is selected * @see #getSelectedColumn */ + @BeanProperty(bound = false) public int[] getSelectedColumns() { return columnModel.getSelectedColumns(); } @@ -2318,6 +2298,7 @@ public class JTable extends JComponent implements TableModelListener, Scrollable * * @return the number of selected rows, 0 if no rows are selected */ + @BeanProperty(bound = false) public int getSelectedRowCount() { int iMin = selectionModel.getMinSelectionIndex(); int iMax = selectionModel.getMaxSelectionIndex(); @@ -2336,6 +2317,7 @@ public class JTable extends JComponent implements TableModelListener, Scrollable * * @return the number of selected columns, 0 if no columns are selected */ + @BeanProperty(bound = false) public int getSelectedColumnCount() { return columnModel.getSelectedColumnCount(); } @@ -2523,10 +2505,9 @@ public class JTable extends JComponent implements TableModelListener, Scrollable * @see #setForeground * @see #setBackground * @see #setFont - * @beaninfo - * bound: true - * description: A default foreground color for selected cells. */ + @BeanProperty(description + = "A default foreground color for selected cells.") public void setSelectionForeground(Color selectionForeground) { Color old = this.selectionForeground; this.selectionForeground = selectionForeground; @@ -2561,10 +2542,9 @@ public class JTable extends JComponent implements TableModelListener, Scrollable * @see #setForeground * @see #setBackground * @see #setFont - * @beaninfo - * bound: true - * description: A default background color for selected cells. */ + @BeanProperty(description + = "A default background color for selected cells.") public void setSelectionBackground(Color selectionBackground) { Color old = this.selectionBackground; this.selectionBackground = selectionBackground; @@ -2680,6 +2660,7 @@ public class JTable extends JComponent implements TableModelListener, Scrollable * @return the number of rows shown in the JTable * @see #getColumnCount */ + @BeanProperty(bound = false) public int getRowCount() { RowSorter sorter = getRowSorter(); if (sorter != null) { @@ -2696,6 +2677,7 @@ public class JTable extends JComponent implements TableModelListener, Scrollable * @see #getRowCount * @see #removeColumn */ + @BeanProperty(bound = false) public int getColumnCount() { return getColumnModel().getColumnCount(); } @@ -3564,6 +3546,7 @@ public class JTable extends JComponent implements TableModelListener, Scrollable * @see #editingColumn * @see #editingRow */ + @BeanProperty(bound = false) public boolean isEditing() { return cellEditor != null; } @@ -3574,6 +3557,7 @@ public class JTable extends JComponent implements TableModelListener, Scrollable * * @return Component handling editing session */ + @BeanProperty(bound = false) public Component getEditorComponent() { return editorComp; } @@ -3620,12 +3604,9 @@ public class JTable extends JComponent implements TableModelListener, Scrollable * * @param ui the TableUI L&F object * @see UIDefaults#getUI - * @beaninfo - * bound: true - * hidden: true - * attribute: visualUpdate true - * description: The UI object that implements the Component's LookAndFeel. */ + @BeanProperty(hidden = true, visualUpdate = true, description + = "The UI object that implements the Component's LookAndFeel.") public void setUI(TableUI ui) { if (this.ui != ui) { super.setUI(ui); @@ -3681,6 +3662,7 @@ public class JTable extends JComponent implements TableModelListener, Scrollable * @see JComponent#getUIClassID * @see UIDefaults#getUI */ + @BeanProperty(bound = false) public String getUIClassID() { return uiClassID; } @@ -3697,10 +3679,9 @@ public class JTable extends JComponent implements TableModelListener, Scrollable * @param dataModel the new data source for this table * @throws IllegalArgumentException if {@code dataModel} is {@code null} * @see #getModel - * @beaninfo - * bound: true - * description: The model that is the source of the data for this view. */ + @BeanProperty(description + = "The model that is the source of the data for this view.") public void setModel(final TableModel dataModel) { if (dataModel == null) { throw new IllegalArgumentException("Cannot set a null TableModel"); @@ -3743,10 +3724,9 @@ public class JTable extends JComponent implements TableModelListener, Scrollable * @param columnModel the new data source for this table * @throws IllegalArgumentException if {@code columnModel} is {@code null} * @see #getColumnModel - * @beaninfo - * bound: true - * description: The object governing the way columns appear in the view. */ + @BeanProperty(description + = "The object governing the way columns appear in the view.") public void setColumnModel(final TableColumnModel columnModel) { if (columnModel == null) { throw new IllegalArgumentException("Cannot set a null ColumnModel"); @@ -3788,10 +3768,9 @@ public class JTable extends JComponent implements TableModelListener, Scrollable * @throws IllegalArgumentException if {@code selectionModel} is * {@code null} * @see #getSelectionModel - * @beaninfo - * bound: true - * description: The selection model for rows. */ + @BeanProperty(description + = "The selection model for rows.") public void setSelectionModel(final ListSelectionModel selectionModel) { if (selectionModel == null) { throw new IllegalArgumentException("Cannot set a null SelectionModel"); @@ -4784,9 +4763,9 @@ public class JTable extends JComponent implements TableModelListener, Scrollable * @param size a Dimension object specifying the preferredSize of a * JViewport whose view is this table * @see Scrollable#getPreferredScrollableViewportSize - * @beaninfo - * description: The preferred size of the viewport. */ + @BeanProperty(bound = false, description + = "The preferred size of the viewport.") public void setPreferredScrollableViewportSize(Dimension size) { preferredViewportSize = size; } @@ -5222,6 +5201,7 @@ public class JTable extends JComponent implements TableModelListener, Scrollable * to AUTO_RESIZE_OFF, otherwise returns true * @see Scrollable#getScrollableTracksViewportWidth */ + @BeanProperty(bound = false) public boolean getScrollableTracksViewportWidth() { return !(autoResizeMode == AUTO_RESIZE_OFF); } @@ -5239,6 +5219,7 @@ public class JTable extends JComponent implements TableModelListener, Scrollable * @see #setFillsViewportHeight * @see #getFillsViewportHeight */ + @BeanProperty(bound = false) public boolean getScrollableTracksViewportHeight() { Container parent = SwingUtilities.getUnwrappedParent(this); return getFillsViewportHeight() @@ -5260,11 +5241,9 @@ public class JTable extends JComponent implements TableModelListener, Scrollable * @see #getFillsViewportHeight * @see #getScrollableTracksViewportHeight * @since 1.6 - * @beaninfo - * bound: true - * description: Whether or not this table is always made large enough - * to fill the height of an enclosing viewport */ + @BeanProperty(description + = "Whether or not this table is always made large enough to fill the height of an enclosing viewport") public void setFillsViewportHeight(boolean fillsViewportHeight) { boolean old = this.fillsViewportHeight; this.fillsViewportHeight = fillsViewportHeight; @@ -5661,10 +5640,9 @@ public class JTable extends JComponent implements TableModelListener, Scrollable * * @param anEditor the active cell editor * @see #cellEditor - * @beaninfo - * bound: true - * description: The table's active cell editor. */ + @BeanProperty(description + = "The table's active cell editor.") public void setCellEditor(TableCellEditor anEditor) { TableCellEditor oldEditor = cellEditor; cellEditor = anEditor; @@ -6656,6 +6634,7 @@ public class JTable extends JComponent implements TableModelListener, Scrollable * @return an AccessibleJTable that serves as the * AccessibleContext of this JTable */ + @BeanProperty(bound = false) public AccessibleContext getAccessibleContext() { if (accessibleContext == null) { accessibleContext = new AccessibleJTable(); diff --git a/jdk/src/java.desktop/share/classes/javax/swing/JTextArea.java b/jdk/src/java.desktop/share/classes/javax/swing/JTextArea.java index 48b586e8ca0..d64fa02721b 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/JTextArea.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/JTextArea.java @@ -25,17 +25,12 @@ package javax.swing; import java.awt.*; -import java.awt.event.*; +import java.beans.JavaBean; +import java.beans.BeanProperty; import javax.swing.text.*; -import javax.swing.plaf.*; import javax.accessibility.*; -import java.util.Collections; -import java.util.Set; -import java.util.StringTokenizer; - import java.io.ObjectOutputStream; -import java.io.ObjectInputStream; import java.io.IOException; /** @@ -116,15 +111,13 @@ import java.io.IOException; * has been added to the java.beans package. * Please see {@link java.beans.XMLEncoder}. * - * @beaninfo - * attribute: isContainer false - * description: A multi-line area that displays plain text. - * * @author Timothy Prinzing * @see JTextPane * @see JEditorPane * @since 1.2 */ +@JavaBean(defaultProperty = "UIClassID", description = "A multi-line area that displays plain text.") +@SwingContainer(false) @SuppressWarnings("serial") // Same-version serialization only public class JTextArea extends JTextComponent { @@ -237,6 +230,7 @@ public class JTextArea extends JTextComponent { * @see JComponent#getUIClassID * @see UIDefaults#getUI */ + @BeanProperty(bound = false) public String getUIClassID() { return uiClassID; } @@ -260,11 +254,9 @@ public class JTextArea extends JTextComponent { * * @param size number of characters to expand to * @see #getTabSize - * @beaninfo - * preferred: true - * bound: true - * description: the number of characters to expand tabs to */ + @BeanProperty(preferred = true, description + = "the number of characters to expand tabs to") public void setTabSize(int size) { Document doc = getDocument(); if (doc != null) { @@ -302,11 +294,9 @@ public class JTextArea extends JTextComponent { * * @param wrap indicates if lines should be wrapped * @see #getLineWrap - * @beaninfo - * preferred: true - * bound: true - * description: should lines be wrapped */ + @BeanProperty(preferred = true, description + = "should lines be wrapped") public void setLineWrap(boolean wrap) { boolean old = this.wrap; this.wrap = wrap; @@ -336,11 +326,9 @@ public class JTextArea extends JTextComponent { * @param word indicates if word boundaries should be used * for line wrapping * @see #getWrapStyleWord - * @beaninfo - * preferred: false - * bound: true - * description: should wrapping occur at word boundaries */ + @BeanProperty(description + = "should wrapping occur at word boundaries") public void setWrapStyleWord(boolean word) { boolean old = this.word; this.word = word; @@ -388,6 +376,7 @@ public class JTextArea extends JTextComponent { * * @return the number of lines > 0 */ + @BeanProperty(bound = false) public int getLineCount() { Element map = getDocument().getDefaultRootElement(); return map.getElementCount(); @@ -531,9 +520,9 @@ public class JTextArea extends JTextComponent { * @param rows the number of rows >= 0 * @exception IllegalArgumentException if rows is less than 0 * @see #getRows - * @beaninfo - * description: the number of rows preferred for display */ + @BeanProperty(bound = false, description + = "the number of rows preferred for display") public void setRows(int rows) { int oldVal = this.rows; if (rows < 0) { @@ -575,9 +564,9 @@ public class JTextArea extends JTextComponent { * @param columns the number of columns >= 0 * @exception IllegalArgumentException if columns is less than 0 * @see #getColumns - * @beaninfo - * description: the number of columns preferred for display */ + @BeanProperty(bound = false, description + = "the number of columns preferred for display") public void setColumns(int columns) { int oldVal = this.columns; if (columns < 0) { @@ -680,6 +669,7 @@ public class JTextArea extends JTextComponent { * @return true if a viewport should force the Scrollables width * to match its own. */ + @BeanProperty(bound = false) public boolean getScrollableTracksViewportWidth() { return (wrap) ? true : super.getScrollableTracksViewportWidth(); } @@ -693,6 +683,7 @@ public class JTextArea extends JTextComponent { * @return The preferredSize of a JViewport whose view is this Scrollable. * @see JViewport#getPreferredSize */ + @BeanProperty(bound = false) public Dimension getPreferredScrollableViewportSize() { Dimension size = super.getPreferredScrollableViewportSize(); size = (size == null) ? new Dimension(400,400) : size; @@ -766,6 +757,7 @@ public class JTextArea extends JTextComponent { * @return an AccessibleJTextArea that serves as the * AccessibleContext of this JTextArea */ + @BeanProperty(bound = false) public AccessibleContext getAccessibleContext() { if (accessibleContext == null) { accessibleContext = new AccessibleJTextArea(); diff --git a/jdk/src/java.desktop/share/classes/javax/swing/JTextField.java b/jdk/src/java.desktop/share/classes/javax/swing/JTextField.java index 94290052870..d3ec0dad46b 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/JTextField.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/JTextField.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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,18 +24,17 @@ */ package javax.swing; -import sun.swing.SwingUtilities2; - import java.awt.*; import java.awt.event.*; -import java.beans.*; +import java.beans.JavaBean; +import java.beans.BeanProperty; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; import javax.swing.text.*; -import javax.swing.plaf.*; import javax.swing.event.*; import javax.accessibility.*; import java.io.ObjectOutputStream; -import java.io.ObjectInputStream; import java.io.IOException; import java.io.Serializable; @@ -152,16 +151,14 @@ import java.io.Serializable; * has been added to the java.beans package. * Please see {@link java.beans.XMLEncoder}. * - * @beaninfo - * attribute: isContainer false - * description: A component which allows for the editing of a single line of text. - * * @author Timothy Prinzing * @see #setActionCommand * @see JPasswordField * @see #addActionListener * @since 1.2 */ +@JavaBean(defaultProperty = "UIClassID", description = "A component which allows for the editing of a single line of text.") +@SwingContainer(false) @SuppressWarnings("serial") // Same-version serialization only public class JTextField extends JTextComponent implements SwingConstants { @@ -253,6 +250,7 @@ public class JTextField extends JTextComponent implements SwingConstants { * @see JComponent#getUIClassID * @see UIDefaults#getUI */ + @BeanProperty(bound = false) public String getUIClassID() { return uiClassID; } @@ -266,11 +264,9 @@ public class JTextField extends JTextComponent implements SwingConstants { * * @param doc the document to display/edit * @see #getDocument - * @beaninfo - * description: the text document model - * bound: true - * expert: true */ + @BeanProperty(expert = true, description + = "the text document model") public void setDocument(Document doc) { if (doc != null) { doc.putProperty("filterNewlines", Boolean.TRUE); @@ -332,14 +328,14 @@ public class JTextField extends JTextComponent implements SwingConstants { * @param alignment the alignment * @exception IllegalArgumentException if alignment * is not a valid key - * @beaninfo - * preferred: true - * bound: true - * description: Set the field alignment to LEFT, CENTER, RIGHT, - * LEADING (the default) or TRAILING - * enum: LEFT JTextField.LEFT CENTER JTextField.CENTER RIGHT JTextField.RIGHT - * LEADING JTextField.LEADING TRAILING JTextField.TRAILING */ + @BeanProperty(preferred = true, enumerationValues = { + "JTextField.LEFT", + "JTextField.CENTER", + "JTextField.RIGHT", + "JTextField.LEADING", + "JTextField.TRAILING"}, description + = "Set the field alignment to LEFT, CENTER, RIGHT, LEADING (the default) or TRAILING") public void setHorizontalAlignment(int alignment) { if (alignment == horizontalAlignment) return; int oldValue = horizontalAlignment; @@ -382,9 +378,9 @@ public class JTextField extends JTextComponent implements SwingConstants { * @param columns the number of columns >= 0 * @exception IllegalArgumentException if columns * is less than 0 - * @beaninfo - * description: the number of columns preferred for display */ + @BeanProperty(bound = false, description + = "the number of columns preferred for display") public void setColumns(int columns) { int oldVal = this.columns; if (columns < 0) { @@ -476,6 +472,7 @@ public class JTextField extends JTextComponent implements SwingConstants { * array if no listeners have been added * @since 1.4 */ + @BeanProperty(bound = false) public synchronized ActionListener[] getActionListeners() { return listenerList.getListeners(ActionListener.class); } @@ -559,11 +556,9 @@ public class JTextField extends JTextComponent implements SwingConstants { * @see #configurePropertiesFromAction * @see #createActionPropertyChangeListener * @see #actionPropertyChanged - * @beaninfo - * bound: true - * attribute: visualUpdate true - * description: the Action instance connected with this ActionEvent source */ + @BeanProperty(visualUpdate = true, description + = "the Action instance connected with this ActionEvent source") public void setAction(Action a) { Action oldValue = getAction(); if (action==null || !action.equals(a)) { @@ -712,6 +707,7 @@ public class JTextField extends JTextComponent implements SwingConstants { * * @return the command list */ + @BeanProperty(bound = false) public Action[] getActions() { return TextAction.augmentList(super.getActions(), defaultActions); } @@ -742,6 +738,7 @@ public class JTextField extends JTextComponent implements SwingConstants { * @return the visibility * @see BoundedRangeModel */ + @BeanProperty(bound = false) public BoundedRangeModel getHorizontalVisibility() { return visibility; } @@ -926,6 +923,7 @@ public class JTextField extends JTextComponent implements SwingConstants { * @return an AccessibleJTextField that serves as the * AccessibleContext of this JTextField */ + @BeanProperty(bound = false) public AccessibleContext getAccessibleContext() { if (accessibleContext == null) { accessibleContext = new AccessibleJTextField(); diff --git a/jdk/src/java.desktop/share/classes/javax/swing/JTextPane.java b/jdk/src/java.desktop/share/classes/javax/swing/JTextPane.java index f9c2de42a65..e5ef17b27d0 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/JTextPane.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/JTextPane.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -25,15 +25,12 @@ package javax.swing; import java.awt.*; -import java.awt.event.ActionEvent; - +import java.beans.JavaBean; +import java.beans.BeanProperty; import java.io.ObjectOutputStream; -import java.io.ObjectInputStream; import java.io.IOException; import javax.swing.text.*; -import javax.swing.event.*; -import javax.swing.plaf.*; /** * A text component that can be marked up with attributes that are @@ -72,14 +69,12 @@ import javax.swing.plaf.*; * has been added to the java.beans package. * Please see {@link java.beans.XMLEncoder}. * - * @beaninfo - * attribute: isContainer true - * description: A text component that can be marked up with attributes that are graphically represented. - * * @author Timothy Prinzing * @see javax.swing.text.StyledEditorKit * @since 1.2 */ +@JavaBean(description = "A text component that can be marked up with attributes that are graphically represented.") +@SwingContainer @SuppressWarnings("serial") // Same-version serialization only public class JTextPane extends JEditorPane { @@ -120,6 +115,7 @@ public class JTextPane extends JEditorPane { * @see JComponent#getUIClassID * @see UIDefaults#getUI */ + @BeanProperty(bound = false) public String getUIClassID() { return uiClassID; } @@ -338,6 +334,7 @@ public class JTextPane extends JEditorPane { * * @return the attributes, or null */ + @BeanProperty(bound = false) public AttributeSet getCharacterAttributes() { StyledDocument doc = getStyledDocument(); Element run = doc.getCharacterElement(getCaretPosition()); @@ -379,6 +376,7 @@ public class JTextPane extends JEditorPane { * * @return the attributes */ + @BeanProperty(bound = false) public AttributeSet getParagraphAttributes() { StyledDocument doc = getStyledDocument(); Element paragraph = doc.getParagraphElement(getCaretPosition()); @@ -410,6 +408,7 @@ public class JTextPane extends JEditorPane { * * @return the attributes */ + @BeanProperty(bound = false) public MutableAttributeSet getInputAttributes() { return getStyledEditorKit().getInputAttributes(); } diff --git a/jdk/src/java.desktop/share/classes/javax/swing/JToggleButton.java b/jdk/src/java.desktop/share/classes/javax/swing/JToggleButton.java index 08ec0be8659..da9387e3061 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/JToggleButton.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/JToggleButton.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -26,16 +26,15 @@ package javax.swing; import java.awt.*; import java.awt.event.*; +import java.beans.JavaBean; +import java.beans.BeanProperty; -import javax.swing.event.*; import javax.swing.plaf.*; import javax.accessibility.*; import java.io.ObjectOutputStream; -import java.io.ObjectInputStream; import java.io.IOException; - /** * An implementation of a two-state button. * The JRadioButton and JCheckBox classes @@ -68,15 +67,13 @@ import java.io.IOException; * has been added to the java.beans package. * Please see {@link java.beans.XMLEncoder}. * - * @beaninfo - * attribute: isContainer false - * description: An implementation of a two-state button. - * * @see JRadioButton * @see JCheckBox * @author Jeff Dinkins * @since 1.2 */ +@JavaBean(defaultProperty = "UIClassID", description = "An implementation of a two-state button.") +@SwingContainer(false) @SuppressWarnings("serial") // Same-version serialization only public class JToggleButton extends AbstractButton implements Accessible { @@ -195,9 +192,9 @@ public class JToggleButton extends AbstractButton implements Accessible { * @return String "ToggleButtonUI" * @see JComponent#getUIClassID * @see UIDefaults#getUI - * @beaninfo - * description: A string that specifies the name of the L&F class */ + @BeanProperty(bound = false, description + = "A string that specifies the name of the L&F class") public String getUIClassID() { return uiClassID; } @@ -362,10 +359,9 @@ public class JToggleButton extends AbstractButton implements Accessible { * * @return an AccessibleJToggleButton that serves as the * AccessibleContext of this JToggleButton - * @beaninfo - * expert: true - * description: The AccessibleContext associated with this ToggleButton. */ + @BeanProperty(bound = false, expert = true, description + = "The AccessibleContext associated with this ToggleButton.") public AccessibleContext getAccessibleContext() { if (accessibleContext == null) { accessibleContext = new AccessibleJToggleButton(); diff --git a/jdk/src/java.desktop/share/classes/javax/swing/JToolBar.java b/jdk/src/java.desktop/share/classes/javax/swing/JToolBar.java index 0a7e6fef71d..f13e5c41161 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/JToolBar.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/JToolBar.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -22,31 +22,26 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ - package javax.swing; -import java.awt.Color; import java.awt.Component; -import java.awt.ComponentOrientation; import java.awt.Container; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Insets; import java.awt.LayoutManager; import java.awt.LayoutManager2; -import java.awt.event.*; -import java.beans.*; +import java.beans.JavaBean; +import java.beans.BeanProperty; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; -import javax.swing.border.Border; import javax.swing.plaf.*; import javax.accessibility.*; import java.io.Serializable; import java.io.ObjectOutputStream; -import java.io.ObjectInputStream; import java.io.IOException; -import java.util.Hashtable; - /** * JToolBar provides a component that is useful for @@ -78,15 +73,13 @@ import java.util.Hashtable; * has been added to the java.beans package. * Please see {@link java.beans.XMLEncoder}. * - * @beaninfo - * attribute: isContainer true - * description: A component which displays commonly used controls or Actions. - * * @author Georges Saab * @author Jeff Shapiro * @see Action * @since 1.2 */ +@JavaBean(defaultProperty = "UI", description = "A component which displays commonly used controls or Actions.") +@SwingContainer @SuppressWarnings("serial") // Same-version serialization only public class JToolBar extends JComponent implements SwingConstants, Accessible { @@ -175,12 +168,9 @@ public class JToolBar extends JComponent implements SwingConstants, Accessible * * @param ui the ToolBarUI L&F object * @see UIDefaults#getUI - * @beaninfo - * bound: true - * hidden: true - * attribute: visualUpdate true - * description: The UI object that implements the Component's LookAndFeel. */ + @BeanProperty(hidden = true, visualUpdate = true, description + = "The UI object that implements the Component's LookAndFeel.") public void setUI(ToolBarUI ui) { super.setUI(ui); } @@ -212,6 +202,7 @@ public class JToolBar extends JComponent implements SwingConstants, Accessible * @see JComponent#getUIClassID * @see UIDefaults#getUI */ + @BeanProperty(bound = false) public String getUIClassID() { return uiClassID; } @@ -266,11 +257,9 @@ public class JToolBar extends JComponent implements SwingConstants, Accessible * @param m an Insets object that defines the space * between the border and the buttons * @see Insets - * @beaninfo - * description: The margin between the tool bar's border and contents - * bound: true - * expert: true */ + @BeanProperty(expert = true, description + = "The margin between the tool bar's border and contents") public void setMargin(Insets m) { Insets old = margin; @@ -317,11 +306,9 @@ public class JToolBar extends JComponent implements SwingConstants, Accessible * * @param b if true, the border is painted * @see #isBorderPainted - * @beaninfo - * description: Does the tool bar paint its borders? - * bound: true - * expert: true */ + @BeanProperty(expert = true, description + = "Does the tool bar paint its borders?") public void setBorderPainted(boolean b) { if ( paintBorder != b ) @@ -376,11 +363,9 @@ public class JToolBar extends JComponent implements SwingConstants, Accessible * @param b if true, the tool bar can be moved; * false otherwise * @see #isFloatable - * @beaninfo - * description: Can the tool bar be made to float by the user? - * bound: true - * preferred: true */ + @BeanProperty(preferred = true, description + = "Can the tool bar be made to float by the user?") public void setFloatable( boolean b ) { if ( floatable != b ) @@ -418,13 +403,11 @@ public class JToolBar extends JComponent implements SwingConstants, Accessible * @exception IllegalArgumentException if orientation is neither * HORIZONTAL nor VERTICAL * @see #getOrientation - * @beaninfo - * description: The current orientation of the tool bar - * bound: true - * preferred: true - * enum: HORIZONTAL SwingConstants.HORIZONTAL - * VERTICAL SwingConstants.VERTICAL */ + @BeanProperty(preferred = true, enumerationValues = { + "SwingConstants.HORIZONTAL", + "SwingConstants.VERTICAL"}, description + = "The current orientation of the tool bar") public void setOrientation( int o ) { checkOrientation( o ); @@ -451,12 +434,9 @@ public class JToolBar extends JComponent implements SwingConstants, Accessible * * @param rollover true for rollover toolbar buttons; otherwise false * @since 1.4 - * @beaninfo - * bound: true - * preferred: true - * attribute: visualUpdate true - * description: Will draw rollover button borders in the toolbar. */ + @BeanProperty(preferred = true, visualUpdate = true, description + = "Will draw rollover button borders in the toolbar.") public void setRollover(boolean rollover) { putClientProperty("JToolBar.isRollover", rollover ? Boolean.TRUE : Boolean.FALSE); @@ -836,6 +816,7 @@ public class JToolBar extends JComponent implements SwingConstants, Accessible * @return an AccessibleJToolBar that serves as the * AccessibleContext of this JToolBar */ + @BeanProperty(bound = false) public AccessibleContext getAccessibleContext() { if (accessibleContext == null) { accessibleContext = new AccessibleJToolBar(); diff --git a/jdk/src/java.desktop/share/classes/javax/swing/JToolTip.java b/jdk/src/java.desktop/share/classes/javax/swing/JToolTip.java index dad092dc5fd..7d2ac8c6ad8 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/JToolTip.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/JToolTip.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -25,9 +25,11 @@ package javax.swing; + import javax.swing.plaf.*; import javax.accessibility.*; +import java.beans.BeanProperty; import java.io.ObjectOutputStream; import java.io.ObjectInputStream; import java.io.IOException; @@ -121,11 +123,9 @@ public class JToolTip extends JComponent implements Accessible { * The string tipText may be null. * * @param tipText the String to display - * @beaninfo - * preferred: true - * bound: true - * description: Sets the text of the tooltip */ + @BeanProperty(preferred = true, description + = "Sets the text of the tooltip") public void setTipText(String tipText) { String oldValue = this.tipText; this.tipText = tipText; @@ -156,10 +156,9 @@ public class JToolTip extends JComponent implements Accessible { * * @param c the JComponent being described * @see JComponent#createToolTip - * @beaninfo - * bound: true - * description: Sets the component that the tooltip describes. */ + @BeanProperty(description + = "Sets the component that the tooltip describes.") public void setComponent(JComponent c) { JComponent oldValue = this.component; diff --git a/jdk/src/java.desktop/share/classes/javax/swing/JTree.java b/jdk/src/java.desktop/share/classes/javax/swing/JTree.java index 9d58f86ea09..a46217fa64d 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/JTree.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/JTree.java @@ -22,12 +22,15 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ - package javax.swing; import java.awt.*; import java.awt.event.*; -import java.beans.*; +import java.beans.JavaBean; +import java.beans.BeanProperty; +import java.beans.ConstructorProperties; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; import java.io.*; import java.util.*; import javax.swing.event.*; @@ -35,11 +38,11 @@ import javax.swing.plaf.*; import javax.swing.tree.*; import javax.swing.text.Position; import javax.accessibility.*; + import sun.swing.SwingUtilities2; import sun.swing.SwingUtilities2.Section; import static sun.swing.SwingUtilities2.Section.*; - /** * * A control that displays a set of hierarchical data as an outline. @@ -134,15 +137,14 @@ import static sun.swing.SwingUtilities2.Section.*; * has been added to the java.beans package. * Please see {@link java.beans.XMLEncoder}. *

    - * @beaninfo - * attribute: isContainer false - * description: A component that displays a set of hierarchical data as an outline. * * @author Rob Davis * @author Ray Ryan * @author Scott Violet * @since 1.2 */ +@JavaBean(defaultProperty = "UI", description = "A component that displays a set of hierarchical data as an outline.") +@SwingContainer(false) @SuppressWarnings("serial") public class JTree extends JComponent implements Scrollable, Accessible { @@ -687,12 +689,9 @@ public class JTree extends JComponent implements Scrollable, Accessible * * @param ui the TreeUI L&F object * @see UIDefaults#getUI - * @beaninfo - * bound: true - * hidden: true - * attribute: visualUpdate true - * description: The UI object that implements the Component's LookAndFeel. */ + @BeanProperty(hidden = true, visualUpdate = true, description + = "The UI object that implements the Component's LookAndFeel.") public void setUI(TreeUI ui) { if (this.ui != ui) { settingUI = true; @@ -728,6 +727,7 @@ public class JTree extends JComponent implements Scrollable, Accessible * @see JComponent#getUIClassID * @see UIDefaults#getUI */ + @BeanProperty(bound = false) public String getUIClassID() { return uiClassID; } @@ -750,11 +750,9 @@ public class JTree extends JComponent implements Scrollable, Accessible * This is a bound property. * * @param x the TreeCellRenderer that is to render each cell - * @beaninfo - * bound: true - * description: The TreeCellRenderer that will be used to draw - * each cell. */ + @BeanProperty(description + = "The TreeCellRenderer that will be used to draw each cell.") public void setCellRenderer(TreeCellRenderer x) { TreeCellRenderer oldValue = cellRenderer; @@ -771,10 +769,9 @@ public class JTree extends JComponent implements Scrollable, Accessible * This is a bound property. * * @param flag a boolean value, true if the tree is editable - * @beaninfo - * bound: true - * description: Whether the tree is editable. */ + @BeanProperty(description + = "Whether the tree is editable.") public void setEditable(boolean flag) { boolean oldValue = this.editable; @@ -806,11 +803,9 @@ public class JTree extends JComponent implements Scrollable, Accessible * This is a bound property. * * @param cellEditor the TreeCellEditor to use - * @beaninfo - * bound: true - * description: The cell editor. A null value implies the tree - * cannot be edited. */ + @BeanProperty(description + = "The cell editor. A null value implies the tree cannot be edited.") public void setCellEditor(TreeCellEditor cellEditor) { TreeCellEditor oldEditor = this.cellEditor; @@ -844,10 +839,9 @@ public class JTree extends JComponent implements Scrollable, Accessible * This is a bound property. * * @param newModel the TreeModel that is to provide the data - * @beaninfo - * bound: true - * description: The TreeModel that will provide the data. */ + @BeanProperty(description + = "The TreeModel that will provide the data.") public void setModel(TreeModel newModel) { clearSelection(); @@ -903,11 +897,9 @@ public class JTree extends JComponent implements Scrollable, Accessible * * @param rootVisible true if the root node of the tree is to be displayed * @see #rootVisible - * @beaninfo - * bound: true - * description: Whether or not the root node - * from the TreeModel is visible. */ + @BeanProperty(description + = "Whether or not the root node from the TreeModel is visible.") public void setRootVisible(boolean rootVisible) { boolean oldValue = this.rootVisible; @@ -932,11 +924,9 @@ public class JTree extends JComponent implements Scrollable, Accessible * otherwise, false * @see #showsRootHandles * @see #getShowsRootHandles - * @beaninfo - * bound: true - * description: Whether the node handles are to be - * displayed. */ + @BeanProperty(description + = "Whether the node handles are to be displayed.") public void setShowsRootHandles(boolean newValue) { boolean oldValue = showsRootHandles; TreeModel model = getModel(); @@ -970,10 +960,9 @@ public class JTree extends JComponent implements Scrollable, Accessible * This is a bound property. * * @param rowHeight the height of each cell, in pixels - * @beaninfo - * bound: true - * description: The height of each cell. */ + @BeanProperty(description + = "The height of each cell.") public void setRowHeight(int rowHeight) { int oldValue = this.rowHeight; @@ -1001,6 +990,7 @@ public class JTree extends JComponent implements Scrollable, Accessible * * @return true if the height of each row is a fixed size */ + @BeanProperty(bound = false) public boolean isFixedRowHeight() { return (rowHeight > 0); @@ -1015,11 +1005,9 @@ public class JTree extends JComponent implements Scrollable, Accessible * * @param newValue true to suggest a large model to the UI * @see #largeModel - * @beaninfo - * bound: true - * description: Whether the UI should use a - * large model. */ + @BeanProperty(description + = "Whether the UI should use a large model.") public void setLargeModel(boolean newValue) { boolean oldValue = largeModel; @@ -1048,12 +1036,10 @@ public class JTree extends JComponent implements Scrollable, Accessible * @param newValue true means that stopCellEditing is invoked * when editing is interrupted, and data is saved; false means that * cancelCellEditing is invoked, and changes are lost - * @beaninfo - * bound: true - * description: Determines what happens when editing is interrupted, - * selecting another node in the tree, a change in the - * tree's data, or some other means. */ + @BeanProperty(description + = "Determines what happens when editing is interrupted, selecting another node in the tree, " + + "a change in the tree's data, or some other means.") public void setInvokesStopCellEditing(boolean newValue) { boolean oldValue = invokesStopCellEditing; @@ -1090,11 +1076,9 @@ public class JTree extends JComponent implements Scrollable, Accessible * @param newValue false to disable scrolling on expansion; * true to enable it * @see #getScrollsOnExpand - * - * @beaninfo - * bound: true - * description: Indicates if a node descendant should be scrolled when expanded. */ + @BeanProperty(description + = "Indicates if a node descendant should be scrolled when expanded.") public void setScrollsOnExpand(boolean newValue) { boolean oldValue = scrollsOnExpand; @@ -1121,10 +1105,9 @@ public class JTree extends JComponent implements Scrollable, Accessible * * @param clickCount the number of mouse clicks to get a node expanded or closed * @since 1.3 - * @beaninfo - * bound: true - * description: Number of clicks before a node will expand/collapse. */ + @BeanProperty(description + = "Number of clicks before a node will expand/collapse.") public void setToggleClickCount(int clickCount) { int oldCount = toggleClickCount; @@ -1160,11 +1143,9 @@ public class JTree extends JComponent implements Scrollable, Accessible * @param newValue the new value for expandsSelectedPaths * * @since 1.3 - * @beaninfo - * bound: true - * description: Indicates whether changes to the selection should make - * the parent of the path visible. */ + @BeanProperty(description + = "Indicates whether changes to the selection should make the parent of the path visible.") public void setExpandsSelectedPaths(boolean newValue) { boolean oldValue = expandsSelectedPaths; @@ -1212,11 +1193,9 @@ public class JTree extends JComponent implements Scrollable, Accessible * @see #setTransferHandler * @see TransferHandler * @since 1.4 - * - * @beaninfo - * description: determines whether automatic drag handling is enabled - * bound: false */ + @BeanProperty(bound = false, description + = "determines whether automatic drag handling is enabled") public void setDragEnabled(boolean b) { checkDragEnabled(b); dragEnabled = b; @@ -1505,6 +1484,7 @@ public class JTree extends JComponent implements Scrollable, Accessible * @see TransferHandler#canImport(TransferHandler.TransferSupport) * @since 1.6 */ + @BeanProperty(bound = false) public final DropLocation getDropLocation() { return dropLocation; } @@ -1635,6 +1615,7 @@ public class JTree extends JComponent implements Scrollable, Accessible * * @return the number of viewable nodes */ + @BeanProperty(bound = false) public int getRowCount() { TreeUI tree = getUI(); @@ -1677,10 +1658,9 @@ public class JTree extends JComponent implements Scrollable, Accessible * * @param newPath the new lead path * @since 1.3 - * @beaninfo - * bound: true - * description: Lead selection path */ + @BeanProperty(description + = "Lead selection path") public void setLeadSelectionPath(TreePath newPath) { TreePath oldValue = leadPath; @@ -1705,10 +1685,9 @@ public class JTree extends JComponent implements Scrollable, Accessible * * @param newPath the new anchor path * @since 1.3 - * @beaninfo - * bound: true - * description: Anchor selection path */ + @BeanProperty(description + = "Anchor selection path") public void setAnchorSelectionPath(TreePath newPath) { TreePath oldValue = anchorPath; @@ -1828,6 +1807,7 @@ public class JTree extends JComponent implements Scrollable, Accessible * null if nothing is selected * @see TreePath#getLastPathComponent */ + @BeanProperty(bound = false) public Object getLastSelectedPathComponent() { TreePath selPath = getSelectionModel().getSelectionPath(); @@ -1894,6 +1874,7 @@ public class JTree extends JComponent implements Scrollable, Accessible * * @return the number of nodes selected */ + @BeanProperty(bound = false) public int getSelectionCount() { return selectionModel.getSelectionCount(); } @@ -1904,6 +1885,7 @@ public class JTree extends JComponent implements Scrollable, Accessible * * @return the smallest selected row */ + @BeanProperty(bound = false) public int getMinSelectionRow() { return getSelectionModel().getMinSelectionRow(); } @@ -1914,6 +1896,7 @@ public class JTree extends JComponent implements Scrollable, Accessible * * @return the largest selected row */ + @BeanProperty(bound = false) public int getMaxSelectionRow() { return getSelectionModel().getMaxSelectionRow(); } @@ -1925,6 +1908,7 @@ public class JTree extends JComponent implements Scrollable, Accessible * where 0 is the first row in the display; or -1 * if leadPath is null */ + @BeanProperty(bound = false) public int getLeadSelectionRow() { TreePath leadPath = getLeadSelectionPath(); @@ -2198,6 +2182,7 @@ public class JTree extends JComponent implements Scrollable, Accessible * null if row < 0 * or row >= getRowCount() */ + @BeanProperty(bound = false) public TreePath getPathForRow(int row) { TreeUI tree = getUI(); @@ -2368,6 +2353,7 @@ public class JTree extends JComponent implements Scrollable, Accessible * @return true if the user is currently editing a node * @see #getSelectionPath */ + @BeanProperty(bound = false) public boolean isEditing() { TreeUI tree = getUI(); @@ -2430,6 +2416,7 @@ public class JTree extends JComponent implements Scrollable, Accessible * * @return the TreePath for the node being edited */ + @BeanProperty(bound = false) public TreePath getEditingPath() { TreeUI tree = getUI(); @@ -2457,10 +2444,9 @@ public class JTree extends JComponent implements Scrollable, Accessible * @param selectionModel the TreeSelectionModel to use, * or null to disable selections * @see TreeSelectionModel - * @beaninfo - * bound: true - * description: The tree's selection model. */ + @BeanProperty(description + = "The tree's selection model.") public void setSelectionModel(TreeSelectionModel selectionModel) { if(selectionModel == null) selectionModel = EmptySelectionModel.sharedInstance(); @@ -2700,6 +2686,7 @@ public class JTree extends JComponent implements Scrollable, Accessible * * @return true if the selection is currently empty */ + @BeanProperty(bound = false) public boolean isSelectionEmpty() { return getSelectionModel().isSelectionEmpty(); } @@ -2738,6 +2725,7 @@ public class JTree extends JComponent implements Scrollable, Accessible * array if no listeners have been added * @since 1.4 */ + @BeanProperty(bound = false) public TreeExpansionListener[] getTreeExpansionListeners() { return listenerList.getListeners(TreeExpansionListener.class); } @@ -2770,6 +2758,7 @@ public class JTree extends JComponent implements Scrollable, Accessible * array if no listeners have been added * @since 1.4 */ + @BeanProperty(bound = false) public TreeWillExpandListener[] getTreeWillExpandListeners() { return listenerList.getListeners(TreeWillExpandListener.class); } @@ -2929,6 +2918,7 @@ public class JTree extends JComponent implements Scrollable, Accessible * array if no listeners have been added * @since 1.4 */ + @BeanProperty(bound = false) public TreeSelectionListener[] getTreeSelectionListeners() { return listenerList.getListeners(TreeSelectionListener.class); } @@ -2980,10 +2970,9 @@ public class JTree extends JComponent implements Scrollable, Accessible * This is a bound property. * * @param newCount the number of rows to display - * @beaninfo - * bound: true - * description: The number of rows that are to be displayed. */ + @BeanProperty(description + = "The number of rows that are to be displayed.") public void setVisibleRowCount(int newCount) { int oldCount = visibleRowCount; @@ -3459,6 +3448,7 @@ public class JTree extends JComponent implements Scrollable, Accessible * * @return a Dimension object containing the preferred size */ + @BeanProperty(bound = false) public Dimension getPreferredScrollableViewportSize() { int width = getPreferredSize().width; int visRows = getVisibleRowCount(); @@ -3565,6 +3555,7 @@ public class JTree extends JComponent implements Scrollable, Accessible * @return whether the tree should track the width of the viewport * @see Scrollable#getScrollableTracksViewportWidth */ + @BeanProperty(bound = false) public boolean getScrollableTracksViewportWidth() { Container parent = SwingUtilities.getUnwrappedParent(this); if (parent instanceof JViewport) { @@ -3582,6 +3573,7 @@ public class JTree extends JComponent implements Scrollable, Accessible * @return whether the tree should track the height of the viewport * @see Scrollable#getScrollableTracksViewportHeight */ + @BeanProperty(bound = false) public boolean getScrollableTracksViewportHeight() { Container parent = SwingUtilities.getUnwrappedParent(this); if (parent instanceof JViewport) { @@ -4160,6 +4152,7 @@ public class JTree extends JComponent implements Scrollable, Accessible * @return an AccessibleJTree that serves as the * AccessibleContext of this JTree */ + @BeanProperty(bound = false) public AccessibleContext getAccessibleContext() { if (accessibleContext == null) { accessibleContext = new AccessibleJTree(); diff --git a/jdk/src/java.desktop/share/classes/javax/swing/JViewport.java b/jdk/src/java.desktop/share/classes/javax/swing/JViewport.java index 8090dc78087..d416dd7c39d 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/JViewport.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/JViewport.java @@ -28,6 +28,7 @@ package javax.swing; import java.awt.*; import java.awt.event.*; import java.awt.peer.ComponentPeer; +import java.beans.BeanProperty; import java.beans.Transient; import javax.swing.plaf.ViewportUI; @@ -300,13 +301,10 @@ public class JViewport extends JComponent implements Accessible * * @param ui the ViewportUI L&F object * @see UIDefaults#getUI - * @beaninfo - * bound: true - * hidden: true - * attribute: visualUpdate true - * description: The UI object that implements the Component's LookAndFeel. * @since 1.3 */ + @BeanProperty(hidden = true, visualUpdate = true, description + = "The UI object that implements the Component's LookAndFeel.") public void setUI(ViewportUI ui) { super.setUI(ui); } @@ -588,9 +586,8 @@ public class JViewport extends JComponent implements Accessible * @param insets the Insets object which can be reused * @return this viewports inset values * @see #getInsets - * @beaninfo - * expert: true */ + @BeanProperty(expert = true) public final Insets getInsets(Insets insets) { insets.left = insets.top = insets.right = insets.bottom = 0; return insets; @@ -861,15 +858,13 @@ public class JViewport extends JComponent implements Accessible * @see #BACKINGSTORE_SCROLL_MODE * @see #SIMPLE_SCROLL_MODE * - * @beaninfo - * bound: false - * description: Method of moving contents for incremental scrolls. - * enum: BLIT_SCROLL_MODE JViewport.BLIT_SCROLL_MODE - * BACKINGSTORE_SCROLL_MODE JViewport.BACKINGSTORE_SCROLL_MODE - * SIMPLE_SCROLL_MODE JViewport.SIMPLE_SCROLL_MODE - * * @since 1.3 */ + @BeanProperty(bound = false, enumerationValues = { + "JViewport.BLIT_SCROLL_MODE", + "JViewport.BACKINGSTORE_SCROLL_MODE", + "JViewport.SIMPLE_SCROLL_MODE"}, description + = "Method of moving contents for incremental scrolls.") public void setScrollMode(int mode) { scrollMode = mode; backingStore = mode == BACKINGSTORE_SCROLL_MODE; diff --git a/jdk/src/java.desktop/share/classes/javax/swing/JWindow.java b/jdk/src/java.desktop/share/classes/javax/swing/JWindow.java index 804d4e3edc7..d25bad42691 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/JWindow.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/JWindow.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -26,10 +26,8 @@ package javax.swing; import java.awt.*; import java.awt.event.*; -import java.beans.PropertyChangeListener; -import java.util.Locale; -import java.util.Vector; -import java.io.Serializable; +import java.beans.JavaBean; +import java.beans.BeanProperty; import javax.accessibility.*; @@ -83,14 +81,11 @@ import javax.accessibility.*; * * @see JRootPane * - * @beaninfo - * attribute: isContainer true - * attribute: containerDelegate getContentPane - * description: A toplevel window which has no system border or controls. - * * @author David Kloba * @since 1.2 */ +@JavaBean(defaultProperty = "accessibleContext", description = "A toplevel window which has no system border or controls.") +@SwingContainer(delegate = "getContentPane") @SuppressWarnings("serial") public class JWindow extends Window implements Accessible, RootPaneContainer, @@ -328,12 +323,9 @@ public class JWindow extends Window implements Accessible, * @see #getTransferHandler * @see java.awt.Component#setDropTarget * @since 1.6 - * - * @beaninfo - * bound: true - * hidden: true - * description: Mechanism for transfer of data into the component */ + @BeanProperty(hidden = true, description + = "Mechanism for transfer of data into the component") public void setTransferHandler(TransferHandler newHandler) { TransferHandler oldHandler = transferHandler; transferHandler = newHandler; @@ -376,10 +368,9 @@ public class JWindow extends Window implements Accessible, * @see #setLayout * @see #isRootPaneCheckingEnabled * @see javax.swing.RootPaneContainer - * @beaninfo - * hidden: true - * description: Whether the add and setLayout methods are forwarded */ + @BeanProperty(hidden = true, description + = "Whether the add and setLayout methods are forwarded") protected void setRootPaneCheckingEnabled(boolean enabled) { rootPaneCheckingEnabled = enabled; } @@ -463,6 +454,8 @@ public class JWindow extends Window implements Accessible, * @see #setRootPane * @see RootPaneContainer#getRootPane */ + @BeanProperty(bound = false, hidden = true, description + = "the RootPane object for this window.") public JRootPane getRootPane() { return rootPane; } @@ -474,10 +467,6 @@ public class JWindow extends Window implements Accessible, * * @param root the new rootPane property * @see #getRootPane - * - * @beaninfo - * hidden: true - * description: the RootPane object for this window. */ protected void setRootPane(JRootPane root) { if(rootPane != null) { @@ -519,12 +508,9 @@ public class JWindow extends Window implements Accessible, * exception) if the content pane parameter is null * @see #getContentPane * @see RootPaneContainer#setContentPane - * - * @beaninfo - * hidden: true - * description: The client area of the window where child - * components are normally inserted. */ + @BeanProperty(bound = false, hidden = true, description + = "The client area of the window where child components are normally inserted.") public void setContentPane(Container contentPane) { getRootPane().setContentPane(contentPane); } @@ -550,11 +536,9 @@ public class JWindow extends Window implements Accessible, * exception) if the content pane parameter is null * @see #getLayeredPane * @see RootPaneContainer#setLayeredPane - * - * @beaninfo - * hidden: true - * description: The pane which holds the various window layers. */ + @BeanProperty(bound = false, hidden = true, description + = "The pane which holds the various window layers.") public void setLayeredPane(JLayeredPane layeredPane) { getRootPane().setLayeredPane(layeredPane); } @@ -577,11 +561,9 @@ public class JWindow extends Window implements Accessible, * * @see #getGlassPane * @see RootPaneContainer#setGlassPane - * - * @beaninfo - * hidden: true - * description: A transparent pane used for menu rendering. */ + @BeanProperty(bound = false, hidden = true, description + = "A transparent pane used for menu rendering.") public void setGlassPane(Component glassPane) { getRootPane().setGlassPane(glassPane); } @@ -591,6 +573,7 @@ public class JWindow extends Window implements Accessible, * * @since 1.6 */ + @BeanProperty(bound = false) public Graphics getGraphics() { JComponent.getGraphicsInvoked(this); return super.getGraphics(); diff --git a/jdk/src/java.desktop/share/classes/javax/swing/colorchooser/AbstractColorChooserPanel.java b/jdk/src/java.desktop/share/classes/javax/swing/colorchooser/AbstractColorChooserPanel.java index 374882a6cea..b3fda891612 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/colorchooser/AbstractColorChooserPanel.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/colorchooser/AbstractColorChooserPanel.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2015, 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 @@ -26,6 +26,7 @@ package javax.swing.colorchooser; import java.awt.*; +import java.beans.BeanProperty; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import javax.swing.*; @@ -222,13 +223,10 @@ public abstract class AbstractColorChooserPanel extends JPanel { *

    The default value is {@code true}. * * @param b true if the transparency of a color can be selected - * - * @beaninfo - * bound: true - * description: Sets the transparency of a color selection on or off. - * * @see #isColorTransparencySelectionEnabled() */ + @BeanProperty(description + = "Sets the transparency of a color selection on or off.") public void setColorTransparencySelectionEnabled(boolean b){ } diff --git a/jdk/src/java.desktop/share/classes/javax/swing/table/JTableHeader.java b/jdk/src/java.desktop/share/classes/javax/swing/table/JTableHeader.java index 546e962c9fa..ac2802d93c4 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/table/JTableHeader.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/table/JTableHeader.java @@ -22,7 +22,6 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ - package javax.swing.table; import sun.swing.table.DefaultTableCellHeaderRenderer; @@ -36,14 +35,13 @@ import javax.swing.event.*; import javax.swing.plaf.*; import javax.accessibility.*; +import java.beans.BeanProperty; import java.beans.PropertyChangeListener; import java.beans.Transient; import java.io.ObjectOutputStream; -import java.io.ObjectInputStream; import java.io.IOException; - /** * This is the object which manages the header of the JTable. *

    @@ -167,10 +165,9 @@ public class JTableHeader extends JComponent implements TableColumnModelListener /** * Sets the table associated with this header. * @param table the new table - * @beaninfo - * bound: true - * description: The table associated with this header. */ + @BeanProperty(description + = "The table associated with this header.") public void setTable(JTable table) { JTable old = this.table; this.table = table; @@ -191,10 +188,9 @@ public class JTableHeader extends JComponent implements TableColumnModelListener * @param reorderingAllowed true if the table view should allow * reordering; otherwise false * @see #getReorderingAllowed - * @beaninfo - * bound: true - * description: Whether the user can drag column headers to reorder columns. */ + @BeanProperty(description + = "Whether the user can drag column headers to reorder columns.") public void setReorderingAllowed(boolean reorderingAllowed) { boolean old = this.reorderingAllowed; this.reorderingAllowed = reorderingAllowed; @@ -219,10 +215,9 @@ public class JTableHeader extends JComponent implements TableColumnModelListener * @param resizingAllowed true if table view should allow * resizing * @see #getResizingAllowed - * @beaninfo - * bound: true - * description: Whether the user can resize columns by dragging between headers. */ + @BeanProperty(description + = "Whether the user can resize columns by dragging between headers.") public void setResizingAllowed(boolean resizingAllowed) { boolean old = this.resizingAllowed; this.resizingAllowed = resizingAllowed; @@ -516,10 +511,9 @@ public class JTableHeader extends JComponent implements TableColumnModelListener * @exception IllegalArgumentException * if newModel is null * @see #getColumnModel - * @beaninfo - * bound: true - * description: The object governing the way columns appear in the view. */ + @BeanProperty(description + = "The object governing the way columns appear in the view.") public void setColumnModel(TableColumnModel columnModel) { if (columnModel == null) { throw new IllegalArgumentException("Cannot set a null ColumnModel"); diff --git a/jdk/src/java.desktop/share/classes/javax/swing/table/TableColumn.java b/jdk/src/java.desktop/share/classes/javax/swing/table/TableColumn.java index 0d54da6d1d7..e1d908124d4 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/table/TableColumn.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/table/TableColumn.java @@ -26,6 +26,7 @@ package javax.swing.table; import java.awt.Component; +import java.beans.BeanProperty; import java.beans.PropertyChangeListener; import java.io.Serializable; @@ -308,10 +309,9 @@ public class TableColumn extends Object implements Serializable { * TableColumn. As the TableColumn * is moved around in the view the model index remains constant. * @param modelIndex the new modelIndex - * @beaninfo - * bound: true - * description: The model index. */ + @BeanProperty(description + = "The model index.") public void setModelIndex(int modelIndex) { int old = this.modelIndex; this.modelIndex = modelIndex; @@ -335,10 +335,9 @@ public class TableColumn extends Object implements Serializable { * * @param identifier an identifier for this column * @see #getIdentifier - * @beaninfo - * bound: true - * description: A unique identifier for this column. */ + @BeanProperty(description + = "A unique identifier for this column.") public void setIdentifier(Object identifier) { Object old = this.identifier; this.identifier = identifier; @@ -369,10 +368,9 @@ public class TableColumn extends Object implements Serializable { * is null. * @param headerValue the new headerValue * @see #getHeaderValue - * @beaninfo - * bound: true - * description: The text to be used by the header renderer. */ + @BeanProperty(description + = "The text to be used by the header renderer.") public void setHeaderValue(Object headerValue) { Object old = this.headerValue; this.headerValue = headerValue; @@ -405,10 +403,9 @@ public class TableColumn extends Object implements Serializable { * @param headerRenderer the new headerRenderer * * @see #getHeaderRenderer - * @beaninfo - * bound: true - * description: The header renderer. */ + @BeanProperty(description + = "The header renderer.") public void setHeaderRenderer(TableCellRenderer headerRenderer) { TableCellRenderer old = this.headerRenderer; this.headerRenderer = headerRenderer; @@ -437,10 +434,9 @@ public class TableColumn extends Object implements Serializable { * * @param cellRenderer the new cellRenderer * @see #getCellRenderer - * @beaninfo - * bound: true - * description: The renderer to use for cell values. */ + @BeanProperty(description + = "The renderer to use for cell values.") public void setCellRenderer(TableCellRenderer cellRenderer) { TableCellRenderer old = this.cellRenderer; this.cellRenderer = cellRenderer; @@ -471,10 +467,9 @@ public class TableColumn extends Object implements Serializable { * * @param cellEditor the new cellEditor * @see #getCellEditor - * @beaninfo - * bound: true - * description: The editor to use for cell values. */ + @BeanProperty(description + = "The editor to use for cell values.") public void setCellEditor(TableCellEditor cellEditor){ TableCellEditor old = this.cellEditor; this.cellEditor = cellEditor; @@ -515,10 +510,9 @@ public class TableColumn extends Object implements Serializable { * @see #setMaxWidth * @see #setPreferredWidth * @see JTable#doLayout() - * @beaninfo - * bound: true - * description: The width of the column. */ + @BeanProperty(description + = "The width of the column.") public void setWidth(int width) { int old = this.width; this.width = Math.min(Math.max(width, minWidth), maxWidth); @@ -549,10 +543,9 @@ public class TableColumn extends Object implements Serializable { * @param preferredWidth the new preferred width * @see #getPreferredWidth * @see JTable#doLayout() - * @beaninfo - * bound: true - * description: The preferred width of the column. */ + @BeanProperty(description + = "The preferred width of the column.") public void setPreferredWidth(int preferredWidth) { int old = this.preferredWidth; this.preferredWidth = Math.min(Math.max(preferredWidth, minWidth), maxWidth); @@ -588,10 +581,9 @@ public class TableColumn extends Object implements Serializable { * @see #getMinWidth * @see #setPreferredWidth * @see #setMaxWidth - * @beaninfo - * bound: true - * description: The minimum width of the column. */ + @BeanProperty(description + = "The minimum width of the column.") public void setMinWidth(int minWidth) { int old = this.minWidth; this.minWidth = Math.max(Math.min(minWidth, maxWidth), 0); @@ -633,10 +625,9 @@ public class TableColumn extends Object implements Serializable { * @see #getMaxWidth * @see #setPreferredWidth * @see #setMinWidth - * @beaninfo - * bound: true - * description: The maximum width of the column. */ + @BeanProperty(description + = "The maximum width of the column.") public void setMaxWidth(int maxWidth) { int old = this.maxWidth; this.maxWidth = Math.max(minWidth, maxWidth); @@ -667,10 +658,9 @@ public class TableColumn extends Object implements Serializable { * * @param isResizable if true, resizing is allowed; otherwise false * @see #getResizable - * @beaninfo - * bound: true - * description: Whether or not this column can be resized. */ + @BeanProperty(description + = "Whether or not this column can be resized.") public void setResizable(boolean isResizable) { boolean old = this.isResizable; this.isResizable = isResizable; diff --git a/jdk/src/java.desktop/share/classes/javax/swing/text/JTextComponent.java b/jdk/src/java.desktop/share/classes/javax/swing/text/JTextComponent.java index a088bb6f082..571745be89d 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/text/JTextComponent.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/text/JTextComponent.java @@ -29,6 +29,8 @@ import com.sun.beans.util.Cache; import java.security.AccessController; import java.security.PrivilegedAction; +import java.beans.JavaBean; +import java.beans.BeanProperty; import java.beans.Transient; import java.util.HashMap; import java.util.Hashtable; @@ -276,9 +278,6 @@ import sun.swing.SwingAccessor; * has been added to the java.beans package. * Please see {@link java.beans.XMLEncoder}. * - * @beaninfo - * attribute: isContainer false - * * @author Timothy Prinzing * @author Igor Kushnirskiy (printing support) * @see Document @@ -291,6 +290,8 @@ import sun.swing.SwingAccessor; * @see View * @see ViewFactory */ +@JavaBean(defaultProperty = "UI") +@SwingContainer(false) @SuppressWarnings("serial") // Same-version serialization only public abstract class JTextComponent extends JComponent implements Scrollable, Accessible { @@ -375,6 +376,7 @@ public abstract class JTextComponent extends JComponent implements Scrollable, A * * @since 1.4 */ + @BeanProperty(bound = false) public CaretListener[] getCaretListeners() { return listenerList.getListeners(CaretListener.class); } @@ -409,11 +411,9 @@ public abstract class JTextComponent extends JComponent implements Scrollable, A * * @param doc the document to display/edit * @see #getDocument - * @beaninfo - * description: the text document model - * bound: true - * expert: true */ + @BeanProperty(expert = true, description + = "the text document model") public void setDocument(Document doc) { Document old = model; @@ -496,6 +496,7 @@ public abstract class JTextComponent extends JComponent implements Scrollable, A * * @return the command list */ + @BeanProperty(bound = false) public Action[] getActions() { return getUI().getEditorKit(this).getActions(); } @@ -511,10 +512,9 @@ public abstract class JTextComponent extends JComponent implements Scrollable, A * A PropertyChange event ("margin") is sent to all listeners. * * @param m the space between the border and the text - * @beaninfo - * description: desired space between the border and text area - * bound: true */ + @BeanProperty(description + = "desired space between the border and text area") public void setMargin(Insets m) { Insets old = margin; margin = m; @@ -576,11 +576,9 @@ public abstract class JTextComponent extends JComponent implements Scrollable, A * * @param c the caret * @see #getCaret - * @beaninfo - * description: the caret used to select/navigate - * bound: true - * expert: true */ + @BeanProperty(expert = true, description + = "the caret used to select/navigate") public void setCaret(Caret c) { if (caret != null) { caret.removeChangeListener(caretEvent); @@ -614,11 +612,9 @@ public abstract class JTextComponent extends JComponent implements Scrollable, A * * @param h the highlighter * @see #getHighlighter - * @beaninfo - * description: object responsible for background highlights - * bound: true - * expert: true */ + @BeanProperty(expert = true, description + = "object responsible for background highlights") public void setHighlighter(Highlighter h) { if (highlighter != null) { highlighter.deinstall(this); @@ -640,10 +636,9 @@ public abstract class JTextComponent extends JComponent implements Scrollable, A * * @param map the keymap * @see #getKeymap - * @beaninfo - * description: set of key event to action bindings to use - * bound: true */ + @BeanProperty(description + = "set of key event to action bindings to use") public void setKeymap(Keymap map) { Keymap old = keymap; keymap = map; @@ -679,11 +674,9 @@ public abstract class JTextComponent extends JComponent implements Scrollable, A * @see #setTransferHandler * @see TransferHandler * @since 1.4 - * - * @beaninfo - * description: determines whether automatic drag handling is enabled - * bound: false */ + @BeanProperty(bound = false, description + = "determines whether automatic drag handling is enabled") public void setDragEnabled(boolean b) { checkDragEnabled(b); dragEnabled = b; @@ -955,6 +948,7 @@ public abstract class JTextComponent extends JComponent implements Scrollable, A * @see TransferHandler#canImport(TransferHandler.TransferSupport) * @since 1.6 */ + @BeanProperty(bound = false) public final DropLocation getDropLocation() { return dropLocation; } @@ -1220,11 +1214,9 @@ public abstract class JTextComponent extends JComponent implements Scrollable, A * * @param c the color * @see #getCaretColor - * @beaninfo - * description: the color used to render the caret - * bound: true - * preferred: true */ + @BeanProperty(preferred = true, description + = "the color used to render the caret") public void setCaretColor(Color c) { Color old = caretColor; caretColor = c; @@ -1249,11 +1241,9 @@ public abstract class JTextComponent extends JComponent implements Scrollable, A * * @param c the color * @see #getSelectionColor - * @beaninfo - * description: color used to render selection background - * bound: true - * preferred: true */ + @BeanProperty(preferred = true, description + = "color used to render selection background") public void setSelectionColor(Color c) { Color old = selectionColor; selectionColor = c; @@ -1278,11 +1268,9 @@ public abstract class JTextComponent extends JComponent implements Scrollable, A * * @param c the color * @see #getSelectedTextColor - * @beaninfo - * description: color used to render selected text - * bound: true - * preferred: true */ + @BeanProperty(preferred = true, description + = "color used to render selected text") public void setSelectedTextColor(Color c) { Color old = selectedTextColor; selectedTextColor = c; @@ -1306,11 +1294,9 @@ public abstract class JTextComponent extends JComponent implements Scrollable, A * * @param c the color * @see #getDisabledTextColor - * @beaninfo - * description: color used to render disabled text - * bound: true - * preferred: true */ + @BeanProperty(preferred = true, description + = "color used to render disabled text") public void setDisabledTextColor(Color c) { Color old = disabledTextColor; disabledTextColor = c; @@ -1535,10 +1521,9 @@ public abstract class JTextComponent extends JComponent implements Scrollable, A * * @param aKey the key * @see #getFocusAccelerator - * @beaninfo - * description: accelerator character used to grab focus - * bound: true */ + @BeanProperty(description + = "accelerator character used to grab focus") public void setFocusAccelerator(char aKey) { aKey = Character.toUpperCase(aKey); char old = focusAccelerator; @@ -1632,9 +1617,9 @@ public abstract class JTextComponent extends JComponent implements Scrollable, A * @exception IllegalArgumentException if the value supplied * for position is less than zero or greater * than the component's text length - * @beaninfo - * description: the caret position */ + @BeanProperty(bound = false, description + = "the caret position") public void setCaretPosition(int position) { Document doc = getDocument(); if (doc != null) { @@ -1672,9 +1657,9 @@ public abstract class JTextComponent extends JComponent implements Scrollable, A * @param t the new text to be set * @see #getText * @see DefaultCaret - * @beaninfo - * description: the text of this component */ + @BeanProperty(bound = false, description + = "the text of this component") public void setText(String t) { try { Document doc = getDocument(); @@ -1724,6 +1709,7 @@ public abstract class JTextComponent extends JComponent implements Scrollable, A * have a valid mapping into the document for some reason * @see #setText */ + @BeanProperty(bound = false) public String getSelectedText() { String txt = null; int p0 = Math.min(caret.getDot(), caret.getMark()); @@ -1758,10 +1744,9 @@ public abstract class JTextComponent extends JComponent implements Scrollable, A * * @param b the boolean to be set * @see #isEditable - * @beaninfo - * description: specifies if the text can be edited - * bound: true */ + @BeanProperty(description + = "specifies if the text can be edited") public void setEditable(boolean b) { if (b != editable) { boolean oldVal = editable; @@ -1795,9 +1780,9 @@ public abstract class JTextComponent extends JComponent implements Scrollable, A * implementation which is where the actual selection is maintained. * * @param selectionStart the start position of the text ≥ 0 - * @beaninfo - * description: starting location of the selection. */ + @BeanProperty(bound = false, description + = "starting location of the selection.") public void setSelectionStart(int selectionStart) { /* Route through select method to enforce consistent policy * between selectionStart and selectionEnd. @@ -1828,9 +1813,9 @@ public abstract class JTextComponent extends JComponent implements Scrollable, A * implementation which is where the actual selection is maintained. * * @param selectionEnd the end position of the text ≥ 0 - * @beaninfo - * description: ending location of the selection. */ + @BeanProperty(bound = false, description + = "ending location of the selection.") public void setSelectionEnd(int selectionEnd) { /* Route through select method to enforce consistent policy * between selectionStart and selectionEnd. @@ -1946,6 +1931,7 @@ public abstract class JTextComponent extends JComponent implements Scrollable, A * @return the preferredSize of a JViewport * whose view is this Scrollable */ + @BeanProperty(bound = false) public Dimension getPreferredScrollableViewportSize() { return getPreferredSize(); } @@ -2029,6 +2015,7 @@ public abstract class JTextComponent extends JComponent implements Scrollable, A * @return true if a viewport should force the Scrollables * width to match its own */ + @BeanProperty(bound = false) public boolean getScrollableTracksViewportWidth() { Container parent = SwingUtilities.getUnwrappedParent(this); if (parent instanceof JViewport) { @@ -2050,6 +2037,7 @@ public abstract class JTextComponent extends JComponent implements Scrollable, A * @return true if a viewport should force the Scrollables height * to match its own */ + @BeanProperty(bound = false) public boolean getScrollableTracksViewportHeight() { Container parent = SwingUtilities.getUnwrappedParent(this); if (parent instanceof JViewport) { @@ -2484,6 +2472,7 @@ public abstract class JTextComponent extends JComponent implements Scrollable, A * AccessibleContext of this * JTextComponent */ + @BeanProperty(bound = false) public AccessibleContext getAccessibleContext() { if (accessibleContext == null) { accessibleContext = new AccessibleJTextComponent(); @@ -4539,6 +4528,7 @@ public abstract class JTextComponent extends JComponent implements Scrollable, A // // Overrides this method to become an active input method client. // + @BeanProperty(bound = false) public InputMethodRequests getInputMethodRequests() { if (inputMethodRequestsHandler == null) { inputMethodRequestsHandler = new InputMethodRequestsHandler(); diff --git a/jdk/src/java.desktop/share/classes/javax/swing/tree/AbstractLayoutCache.java b/jdk/src/java.desktop/share/classes/javax/swing/tree/AbstractLayoutCache.java index 3d0f4ef9d1f..23272555363 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/tree/AbstractLayoutCache.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/tree/AbstractLayoutCache.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2015, 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 @@ -22,12 +22,11 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ - package javax.swing.tree; import javax.swing.event.TreeModelEvent; -import java.awt.Dimension; import java.awt.Rectangle; +import java.beans.BeanProperty; import java.util.Enumeration; /** @@ -112,11 +111,9 @@ public abstract class AbstractLayoutCache implements RowMapper { * * @param rootVisible true if the root node of the tree is to be displayed * @see #rootVisible - * @beaninfo - * bound: true - * description: Whether or not the root node - * from the TreeModel is visible. */ + @BeanProperty(description + = "Whether or not the root node from the TreeModel is visible.") public void setRootVisible(boolean rootVisible) { this.rootVisible = rootVisible; } @@ -137,10 +134,9 @@ public abstract class AbstractLayoutCache implements RowMapper { * queried for each row's height. * * @param rowHeight the height of each cell, in pixels - * @beaninfo - * bound: true - * description: The height of each cell. */ + @BeanProperty(description + = "The height of each cell.") public void setRowHeight(int rowHeight) { this.rowHeight = rowHeight; } diff --git a/jdk/src/java.desktop/share/classes/javax/swing/tree/DefaultTreeCellEditor.java b/jdk/src/java.desktop/share/classes/javax/swing/tree/DefaultTreeCellEditor.java index 0fe4e7eb1cd..8f76fe2952c 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/tree/DefaultTreeCellEditor.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/tree/DefaultTreeCellEditor.java @@ -22,7 +22,6 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ - package javax.swing.tree; import javax.swing.*; @@ -31,6 +30,7 @@ import javax.swing.event.*; import javax.swing.plaf.FontUIResource; import java.awt.*; import java.awt.event.*; +import java.beans.BeanProperty; import java.util.EventObject; /** @@ -592,12 +592,9 @@ public class DefaultTreeCellEditor implements ActionListener, TreeCellEditor, * @param border the border to be rendered for this component * @see Border * @see CompoundBorder - * @beaninfo - * bound: true - * preferred: true - * attribute: visualUpdate true - * description: The component's border. */ + @BeanProperty(preferred = true, visualUpdate = true, description + = "The component's border.") public void setBorder(Border border) { super.setBorder(border); this.border = border; diff --git a/jdk/src/java.desktop/share/classes/javax/swing/tree/VariableHeightLayoutCache.java b/jdk/src/java.desktop/share/classes/javax/swing/tree/VariableHeightLayoutCache.java index 470f07d930a..fea3a16131d 100644 --- a/jdk/src/java.desktop/share/classes/javax/swing/tree/VariableHeightLayoutCache.java +++ b/jdk/src/java.desktop/share/classes/javax/swing/tree/VariableHeightLayoutCache.java @@ -22,11 +22,11 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ - package javax.swing.tree; import javax.swing.event.TreeModelEvent; import java.awt.Rectangle; +import java.beans.BeanProperty; import java.util.Enumeration; import java.util.Hashtable; import java.util.NoSuchElementException; @@ -103,10 +103,9 @@ public class VariableHeightLayoutCache extends AbstractLayoutCache { * Sets the TreeModel that will provide the data. * * @param newModel the TreeModel that is to provide the data - * @beaninfo - * bound: true - * description: The TreeModel that will provide the data. */ + @BeanProperty(description + = "The TreeModel that will provide the data.") public void setModel(TreeModel newModel) { super.setModel(newModel); rebuild(false); @@ -118,11 +117,9 @@ public class VariableHeightLayoutCache extends AbstractLayoutCache { * * @param rootVisible true if the root node of the tree is to be displayed * @see #rootVisible - * @beaninfo - * bound: true - * description: Whether or not the root node - * from the TreeModel is visible. */ + @BeanProperty(description + = "Whether or not the root node from the TreeModel is visible.") public void setRootVisible(boolean rootVisible) { if(isRootVisible() != rootVisible && root != null) { if(rootVisible) { @@ -151,10 +148,9 @@ public class VariableHeightLayoutCache extends AbstractLayoutCache { * queried for each row's height. * * @param rowHeight the height of each cell, in pixels - * @beaninfo - * bound: true - * description: The height of each cell. */ + @BeanProperty(description + = "The height of each cell.") public void setRowHeight(int rowHeight) { if(rowHeight != getRowHeight()) { super.setRowHeight(rowHeight); From 279a05d2b2fa486d3127b854d70c51b5248aa711 Mon Sep 17 00:00:00 2001 From: Prasanta Sadhukhan Date: Mon, 12 Oct 2015 15:28:03 +0300 Subject: [PATCH 15/43] 8072682: getBounds call on graphics.getDeviceConfiguration() returning cached information Reviewed-by: serb, flar --- .../image/BufferedImageGraphicsConfig.java | 5 +- .../java/awt/Graphics2D/DeviceBounds.java | 54 +++++++++++++++++++ 2 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 jdk/test/java/awt/Graphics2D/DeviceBounds.java diff --git a/jdk/src/java.desktop/share/classes/sun/awt/image/BufferedImageGraphicsConfig.java b/jdk/src/java.desktop/share/classes/sun/awt/image/BufferedImageGraphicsConfig.java index dd831a65bf9..bddb83f6999 100644 --- a/jdk/src/java.desktop/share/classes/sun/awt/image/BufferedImageGraphicsConfig.java +++ b/jdk/src/java.desktop/share/classes/sun/awt/image/BufferedImageGraphicsConfig.java @@ -67,7 +67,6 @@ public class BufferedImageGraphicsConfig GraphicsDevice gd; ColorModel model; Raster raster; - int width, height; public BufferedImageGraphicsConfig(BufferedImage bufImg, Component comp) { if (comp == null) { @@ -78,8 +77,6 @@ public class BufferedImageGraphicsConfig } this.model = bufImg.getColorModel(); this.raster = bufImg.getRaster().createCompatibleWritableRaster(1, 1); - this.width = bufImg.getWidth(); - this.height = bufImg.getHeight(); } /** @@ -168,6 +165,6 @@ public class BufferedImageGraphicsConfig } public Rectangle getBounds() { - return new Rectangle(0, 0, width, height); + return new Rectangle(0, 0, Integer.MAX_VALUE, Integer.MAX_VALUE); } } diff --git a/jdk/test/java/awt/Graphics2D/DeviceBounds.java b/jdk/test/java/awt/Graphics2D/DeviceBounds.java new file mode 100644 index 00000000000..7559b7d8a57 --- /dev/null +++ b/jdk/test/java/awt/Graphics2D/DeviceBounds.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2015, 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. + */ +import java.awt.*; +import java.awt.image.BufferedImage; + +/** + * @test + * @bug 8072682 + * @summary Graphics.getDeviceConfiguration().getBounds returns wrong width/height + * @run main DeviceBounds + */ +public class DeviceBounds { + public static void main(String[] args) { + // NB: all images have the same type + BufferedImage[] images = new BufferedImage[] { + new BufferedImage(200, 200, BufferedImage.TYPE_3BYTE_BGR), + new BufferedImage(400, 400, BufferedImage.TYPE_3BYTE_BGR), + new BufferedImage(100, 100, BufferedImage.TYPE_3BYTE_BGR) + }; + int count = 0; + for (BufferedImage i : images) { + Graphics2D g = i.createGraphics(); + Rectangle bounds[] = new Rectangle[images.length]; + bounds[count] = g.getDeviceConfiguration().getBounds(); + System.out.println(bounds[count]); + + g.dispose(); + if (bounds[count].width != Integer.MAX_VALUE) { + throw new RuntimeException("Wrong getBounds"); + } + count++; + } + } +} From f07facd339f6ab29d10ae29e86c22b31977b55e0 Mon Sep 17 00:00:00 2001 From: Sergey Bylokhov Date: Mon, 12 Oct 2015 16:26:58 +0300 Subject: [PATCH 16/43] 8136858: Examine the usage of ThreadGroup.stop() in sun.awt.AppContext Reviewed-by: alexsch, chegar --- .../share/classes/sun/awt/AppContext.java | 5 +- .../ApplicationThreadsStop.java | 76 +++++++++++++++++++ .../ApplicationThreadsStop/java.policy | 5 ++ 3 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 jdk/test/java/awt/AppContext/ApplicationThreadsStop/ApplicationThreadsStop.java create mode 100644 jdk/test/java/awt/AppContext/ApplicationThreadsStop/java.policy diff --git a/jdk/src/java.desktop/share/classes/sun/awt/AppContext.java b/jdk/src/java.desktop/share/classes/sun/awt/AppContext.java index db0659eb587..9023251171d 100644 --- a/jdk/src/java.desktop/share/classes/sun/awt/AppContext.java +++ b/jdk/src/java.desktop/share/classes/sun/awt/AppContext.java @@ -525,7 +525,10 @@ public final class AppContext { } // Then, we stop any remaining Threads - this.threadGroup.stop(); + AccessController.doPrivileged((PrivilegedAction) () -> { + threadGroup.stop(); + return null; + }); // Next, we sleep 10ms at a time, waiting for all of the active // Threads in the ThreadGroup to die. diff --git a/jdk/test/java/awt/AppContext/ApplicationThreadsStop/ApplicationThreadsStop.java b/jdk/test/java/awt/AppContext/ApplicationThreadsStop/ApplicationThreadsStop.java new file mode 100644 index 00000000000..0819c5e905e --- /dev/null +++ b/jdk/test/java/awt/AppContext/ApplicationThreadsStop/ApplicationThreadsStop.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2015, 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. + */ + +import java.awt.AWTException; +import java.awt.Frame; +import java.awt.Robot; + +import sun.awt.AppContext; +import sun.awt.SunToolkit; + +/** + * @test + * @bug 8136858 + * @modules java.desktop/sun.awt + * @run main/othervm/java.security.policy=java.policy -Djava.security.manager ApplicationThreadsStop + */ +public final class ApplicationThreadsStop implements Runnable { + + private static AppContext contextToDispose; + private static Thread thread; + + public static void main(final String[] args) throws Exception { + ThreadGroup tg = new ThreadGroup("TestThreadGroup"); + Thread t = new Thread(tg, new ApplicationThreadsStop()); + t.start(); + t.join(); + contextToDispose.dispose(); + // wait for appcontext to be destroyed + Thread.sleep(10000); + if(thread.isAlive()){ + throw new RuntimeException("Thread is alive"); + } + } + + @Override + public void run() { + contextToDispose = SunToolkit.createNewAppContext(); + Frame f = new Frame(); + f.setSize(300, 300); + f.setLocationRelativeTo(null); + f.setVisible(true); + thread = new Thread(() -> { + while(true); + }); + thread.start(); + sync(); + } + + private static void sync() { + try { + new Robot().waitForIdle(); + } catch (AWTException e) { + throw new RuntimeException(e); + } + } +} diff --git a/jdk/test/java/awt/AppContext/ApplicationThreadsStop/java.policy b/jdk/test/java/awt/AppContext/ApplicationThreadsStop/java.policy new file mode 100644 index 00000000000..0ca7756397b --- /dev/null +++ b/jdk/test/java/awt/AppContext/ApplicationThreadsStop/java.policy @@ -0,0 +1,5 @@ +grant { + permission java.lang.RuntimePermission "accessClassInPackage.sun.awt"; + permission java.awt.AWTPermission "createRobot"; + permission java.util.PropertyPermission "AWT.EventQueueClass", "read"; +}; From 059474a6eeb08560d8fb63c4f5c5b8d9dc721a32 Mon Sep 17 00:00:00 2001 From: Jayathirth D V Date: Tue, 13 Oct 2015 14:59:44 +0300 Subject: [PATCH 17/43] 8066904: NullPointerException when calling ImageIO.read(InputStream) with corrupt BMP Reviewed-by: serb, prr --- .../imageio/plugins/bmp/BMPImageReader.java | 11 ++++ .../plugins/common/iio-plugin.properties | 1 + .../javax/imageio/plugins/bmp/Bug8066904.java | 65 +++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 jdk/test/javax/imageio/plugins/bmp/Bug8066904.java diff --git a/jdk/src/java.desktop/share/classes/com/sun/imageio/plugins/bmp/BMPImageReader.java b/jdk/src/java.desktop/share/classes/com/sun/imageio/plugins/bmp/BMPImageReader.java index ccfc4187a83..27a935d715a 100644 --- a/jdk/src/java.desktop/share/classes/com/sun/imageio/plugins/bmp/BMPImageReader.java +++ b/jdk/src/java.desktop/share/classes/com/sun/imageio/plugins/bmp/BMPImageReader.java @@ -290,6 +290,8 @@ public class BMPImageReader extends ImageReader implements BMPConstants { imageType = VERSION_2_8_BIT; } else if (bitsPerPixel == 24) { imageType = VERSION_2_24_BIT; + } else { + throw new IIOException(I18N.getString("BMPImageReader8")); } // Read in the palette @@ -364,6 +366,9 @@ public class BMPImageReader extends ImageReader implements BMPConstants { metadata.redMask = redMask; metadata.greenMask = greenMask; metadata.blueMask = blueMask; + } else { + throw new + IIOException(I18N.getString("BMPImageReader8")); } metadata.bmpVersion = VERSION_3; @@ -375,6 +380,9 @@ public class BMPImageReader extends ImageReader implements BMPConstants { imageType = VERSION_3_NT_16_BIT; } else if (bitsPerPixel == 32) { imageType = VERSION_3_NT_32_BIT; + } else { + throw new + IIOException(I18N.getString("BMPImageReader8")); } // BitsField encoding @@ -493,6 +501,9 @@ public class BMPImageReader extends ImageReader implements BMPConstants { greenMask = 0x0000FF00; blueMask = 0x000000FF; } + } else { + throw new + IIOException(I18N.getString("BMPImageReader8")); } metadata.redMask = redMask; diff --git a/jdk/src/java.desktop/share/classes/com/sun/imageio/plugins/common/iio-plugin.properties b/jdk/src/java.desktop/share/classes/com/sun/imageio/plugins/common/iio-plugin.properties index 85b108f8e3b..181446bca21 100644 --- a/jdk/src/java.desktop/share/classes/com/sun/imageio/plugins/common/iio-plugin.properties +++ b/jdk/src/java.desktop/share/classes/com/sun/imageio/plugins/common/iio-plugin.properties @@ -23,6 +23,7 @@ BMPImageReader4=No ImageIO-style reader is found for BMPImageReader5=Input has not been set. BMPImageReader6=Unable to read the image header. BMPImageReader7=Invalid bitmap offset. +BMPImageReader8=Invalid bits per pixel in image header. BMPImageWriter0=Output is not an ImageOutputStream. BMPImageWriter1=The image region to be encoded is empty. BMPImageWriter2=Only 1 or 3 band image is encoded. diff --git a/jdk/test/javax/imageio/plugins/bmp/Bug8066904.java b/jdk/test/javax/imageio/plugins/bmp/Bug8066904.java new file mode 100644 index 00000000000..82bcf202db9 --- /dev/null +++ b/jdk/test/javax/imageio/plugins/bmp/Bug8066904.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2015, 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 8066904 + * @summary Test verifies whether Bits per Pixel in BMP + * Header is corrupted or not + * @run main Bug8066904 + */ + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import javax.imageio.ImageIO; + +public class Bug8066904 { + + public static void main(String[] args) throws IOException { + // corrupted byte array with improper Bits per pixel in header + byte[] corruptedBmp = { (byte) 0x42, (byte) 0x4d, (byte) 0x7e, + (byte) 0x06, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x00, (byte) 0x3e, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x28, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0x64, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x64, + (byte) 0x00, (byte) 0x40, (byte) 0x06, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0x00, (byte) 0xff, + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, + (byte) 0xff }; + + /** if IOException is caught then test will + * pass otherwise throws a different exception. + */ + try { + ImageIO.read(new ByteArrayInputStream(corruptedBmp)); + } catch(Exception ex) { + if (!(ex instanceof IOException)) + throw ex; + } + } +} From 206483e8b3a6992650461fe6e118131825ea8f2e Mon Sep 17 00:00:00 2001 From: Sergey Bylokhov Date: Sun, 18 Oct 2015 13:33:20 +0300 Subject: [PATCH 18/43] 6815345: java.awt.Component.createImage(int width,int height) should remove behavioral optionality Reviewed-by: prr, ssadetsky --- .../share/classes/java/awt/Component.java | 67 ++++++----- .../Component/CreateImage/CreateImage.java | 111 ++++++++++++++++++ 2 files changed, 146 insertions(+), 32 deletions(-) create mode 100644 jdk/test/java/awt/Component/CreateImage/CreateImage.java diff --git a/jdk/src/java.desktop/share/classes/java/awt/Component.java b/jdk/src/java.desktop/share/classes/java/awt/Component.java index 3c50dceecce..72c459943b3 100644 --- a/jdk/src/java.desktop/share/classes/java/awt/Component.java +++ b/jdk/src/java.desktop/share/classes/java/awt/Component.java @@ -3622,18 +3622,17 @@ public abstract class Component implements ImageObserver, MenuContainer, } /** - * Creates an off-screen drawable image - * to be used for double buffering. - * @param width the specified width - * @param height the specified height - * @return an off-screen drawable image, which can be used for double - * buffering. The return value may be null if the - * component is not displayable. This will always happen if - * GraphicsEnvironment.isHeadless() returns - * true. + * Creates an off-screen drawable image to be used for double buffering. + * + * @param width the specified width + * @param height the specified height + * @return an off-screen drawable image, which can be used for double + * buffering. The {@code null} value if the component is not + * displayable or {@code GraphicsEnvironment.isHeadless()} returns + * {@code true}. * @see #isDisplayable * @see GraphicsEnvironment#isHeadless - * @since 1.0 + * @since 1.0 */ public Image createImage(int width, int height) { ComponentPeer peer = this.peer; @@ -3646,19 +3645,19 @@ public abstract class Component implements ImageObserver, MenuContainer, } /** - * Creates a volatile off-screen drawable image - * to be used for double buffering. - * @param width the specified width. - * @param height the specified height. - * @return an off-screen drawable image, which can be used for double - * buffering. The return value may be null if the - * component is not displayable. This will always happen if - * GraphicsEnvironment.isHeadless() returns - * true. + * Creates a volatile off-screen drawable image to be used for double + * buffering. + * + * @param width the specified width + * @param height the specified height + * @return an off-screen drawable image, which can be used for double + * buffering. The {@code null} value if the component is not + * displayable or {@code GraphicsEnvironment.isHeadless()} returns + * {@code true}. * @see java.awt.image.VolatileImage * @see #isDisplayable * @see GraphicsEnvironment#isHeadless - * @since 1.4 + * @since 1.4 */ public VolatileImage createVolatileImage(int width, int height) { ComponentPeer peer = this.peer; @@ -3674,22 +3673,26 @@ public abstract class Component implements ImageObserver, MenuContainer, } /** - * Creates a volatile off-screen drawable image, with the given capabilities. - * The contents of this image may be lost at any time due - * to operating system issues, so the image must be managed - * via the VolatileImage interface. - * @param width the specified width. - * @param height the specified height. - * @param caps the image capabilities - * @exception AWTException if an image with the specified capabilities cannot - * be created - * @return a VolatileImage object, which can be used - * to manage surface contents loss and capabilities. + * Creates a volatile off-screen drawable image, with the given + * capabilities. The contents of this image may be lost at any time due to + * operating system issues, so the image must be managed via the + * {@code VolatileImage} interface. + * + * @param width the specified width + * @param height the specified height + * @param caps the image capabilities + * @return a VolatileImage object, which can be used to manage surface + * contents loss and capabilities. The {@code null} value if the + * component is not displayable or + * {@code GraphicsEnvironment.isHeadless()} returns {@code true}. + * @throws AWTException if an image with the specified capabilities cannot + * be created * @see java.awt.image.VolatileImage * @since 1.4 */ public VolatileImage createVolatileImage(int width, int height, - ImageCapabilities caps) throws AWTException { + ImageCapabilities caps) + throws AWTException { // REMIND : check caps return createVolatileImage(width, height); } diff --git a/jdk/test/java/awt/Component/CreateImage/CreateImage.java b/jdk/test/java/awt/Component/CreateImage/CreateImage.java new file mode 100644 index 00000000000..aa977ce0ac5 --- /dev/null +++ b/jdk/test/java/awt/Component/CreateImage/CreateImage.java @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2015, 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. + */ + +import java.awt.AWTException; +import java.awt.Button; +import java.awt.Component; +import java.awt.EventQueue; +import java.awt.Frame; +import java.awt.GraphicsEnvironment; + +import javax.swing.JButton; + +/** + * @test + * @bug 6815345 + * @run main CreateImage + * @run main/othervm -Djava.awt.headless=true CreateImage + */ +public final class CreateImage { + + public static void main(final String[] args) throws Exception { + EventQueue.invokeAndWait(CreateImage::test); + } + + private static void test() { + final JButton jbutton1 = new JButton(); + final JButton jbutton2 = new JButton(); + + if (GraphicsEnvironment.isHeadless()) { + checkCreateImage(jbutton1, true); + checkCreateImage(jbutton2, true); + return; + } + + final Frame frame = new Frame(); + final Button button1 = new Button(); + final Button button2 = new Button(); + try { + // all components are not displayable + checkCreateImage(frame, true); + checkCreateImage(button1, true); + checkCreateImage(button2, true); + checkCreateImage(jbutton1, true); + checkCreateImage(jbutton2, true); + + // some components added to the non-displayable frame + frame.add(button1); + frame.add(jbutton1); + checkCreateImage(button1, true); + checkCreateImage(jbutton1, true); + frame.pack(); + + // tests previously added components when the frame is displayable + checkCreateImage(frame, false); + checkCreateImage(button1, false); + checkCreateImage(jbutton1, false); + + // some components added to the displayable frame + frame.add(button2); + frame.add(jbutton2); + checkCreateImage(button2, false); + checkCreateImage(jbutton2, false); + + } finally { + frame.dispose(); + } + // tests all components after the frame became non-displayable again + checkCreateImage(frame, true); + checkCreateImage(button1, true); + checkCreateImage(button2, true); + checkCreateImage(jbutton1, true); + checkCreateImage(jbutton2, true); + } + + private static void checkCreateImage(final Component comp, + final boolean isNull) { + if ((comp.createImage(10, 10) != null) == isNull) { + throw new RuntimeException("Image is wrong"); + } + if ((comp.createVolatileImage(10, 10) != null) == isNull) { + throw new RuntimeException("Image is wrong"); + } + try { + if ((comp.createVolatileImage(10, 10, null) != null) == isNull) { + throw new RuntimeException("Image is wrong"); + } + } catch (final AWTException ignored) { + // this check is not applicable + } + } +} From 1127171d12fbf88449682447644348f5f32b0b0e Mon Sep 17 00:00:00 2001 From: Renjith Alexander Date: Tue, 20 Oct 2015 12:42:21 +0300 Subject: [PATCH 19/43] 8136592: [TEST_BUG] Fix 2 platform-specific closed regtests for jigsaw Reviewed-by: serb, yan --- .../GraphicsConfigTest.java | 159 ++++++++++++++++++ .../FocusEmptyListTest.html | 47 ++++++ .../FocusEmptyListTest.java | 96 +++++++++++ 3 files changed, 302 insertions(+) create mode 100644 jdk/test/java/awt/EmbeddedFrame/GraphicsConfigTest/GraphicsConfigTest.java create mode 100644 jdk/test/java/awt/List/FocusEmptyListTest/FocusEmptyListTest.html create mode 100644 jdk/test/java/awt/List/FocusEmptyListTest/FocusEmptyListTest.java diff --git a/jdk/test/java/awt/EmbeddedFrame/GraphicsConfigTest/GraphicsConfigTest.java b/jdk/test/java/awt/EmbeddedFrame/GraphicsConfigTest/GraphicsConfigTest.java new file mode 100644 index 00000000000..f2d56675c91 --- /dev/null +++ b/jdk/test/java/awt/EmbeddedFrame/GraphicsConfigTest/GraphicsConfigTest.java @@ -0,0 +1,159 @@ +/* + * Copyright (c) 2007, 2015, 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 6356322 + * @summary Tests that embedded frame's graphics configuration is updated + * correctly when it is moved to another screen in multiscreen system, + * XToolkit + * @author artem.ananiev@sun.com: area=awt.multiscreen + * @requires (os.family == "linux") | (os.family == "solaris") + * @modules java.desktop/sun.awt + * java.desktop/sun.awt.X11 + * java.desktop/java.awt.peer + * @run main GraphicsConfigTest + */ + +import java.awt.*; +import java.awt.peer.*; +import java.lang.reflect.*; +import java.util.*; +import sun.awt.*; + +public class GraphicsConfigTest { + + private static void init() + throws InterruptedException, AWTException { + if (!isXToolkit()) { + System.err.println("The test should be run only on XToolkit"); + return; + } + + GraphicsEnvironment ge = + GraphicsEnvironment.getLocalGraphicsEnvironment(); + GraphicsDevice[] gds = ge.getScreenDevices(); + if (gds.length < 2) { + System.err.println("The test should be run only in" + + " multiscreen configuration"); + return; + } + + boolean xinerama = Arrays.stream(gds) + .map((gd) -> gd.getDefaultConfiguration().getBounds()) + .filter((r) -> r.x != 0 || r.y != 0).findFirst().isPresent(); + + if (!xinerama) { + System.err.println("The test should be run only with Xinerama ON"); + return; + } + + Rectangle r0 = gds[0].getDefaultConfiguration().getBounds(); + Rectangle r1 = gds[1].getDefaultConfiguration().getBounds(); + + System.setProperty("sun.awt.xembedserver", "true"); + Frame f = new Frame("F"); + try { + final Robot robot = new Robot(); + + f.setBounds(r0.x + 100, r0.y + 100, 200, 200); + f.setVisible(true); + robot.waitForIdle(); + Thread.sleep(1000); + + Canvas c = new Canvas(); + f.add(c); + AWTAccessor.ComponentAccessor acc = + AWTAccessor.getComponentAccessor(); + WindowIDProvider wip = acc.getPeer(c); + long h = wip.getWindow(); + + EmbeddedFrame e = createEmbeddedFrame(h); + acc.getPeer(e).setBoundsPrivate(0, 0, 100, + 100); // triggers XConfigureEvent + e.registerListeners(); + e.setVisible(true); + robot.waitForIdle(); + Thread.sleep(1000); + + if (!checkGC(f, e)) { + throw new RuntimeException("Failed at checkpoint 1"); + } + + f.setLocation(r1.x + 100, r1.y + 100); + Thread.sleep(100); + acc.getPeer(e).setBoundsPrivate(0, 0, 101, + 101); // triggers XConfigureEvent + robot.waitForIdle(); + Thread.sleep(1000); + + if (!checkGC(f, e)) { + throw new RuntimeException("Failed at checkpoint 2"); + } + + f.setLocation(r0.x + 100, r0.y + 100); + Thread.sleep(100); + acc.getPeer(e).setBoundsPrivate(0, 0, 102, + 102); // triggers XConfigureEvent + robot.waitForIdle(); + Thread.sleep(1000); + + if (!checkGC(f, e)) { + throw new RuntimeException("Failed at checkpoint 3"); + } + + } finally { + f.dispose(); + } + } + + private static boolean isXToolkit() { + return Toolkit.getDefaultToolkit().getClass() + .getName().equals("sun.awt.X11.XToolkit"); + } + + private static EmbeddedFrame createEmbeddedFrame(long window) { + try { + Class cl = Class.forName("sun.awt.X11.XEmbeddedFrame"); + Constructor cons = cl.getConstructor( + new Class[]{Long.TYPE, Boolean.TYPE}); + return (EmbeddedFrame) cons.newInstance(new Object[]{window, true}); + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException("Can't create embedded frame"); + } + } + + private static boolean checkGC(Component c, Component d) { + GraphicsConfiguration g1 = c.getGraphicsConfiguration(); + System.err.println(g1); + GraphicsConfiguration g2 = d.getGraphicsConfiguration(); + System.err.println(g2); + + return g1.equals(g2); + } + + public static void main(String args[]) throws InterruptedException, AWTException { + init(); + } +} diff --git a/jdk/test/java/awt/List/FocusEmptyListTest/FocusEmptyListTest.html b/jdk/test/java/awt/List/FocusEmptyListTest/FocusEmptyListTest.html new file mode 100644 index 00000000000..5bbd8f7f197 --- /dev/null +++ b/jdk/test/java/awt/List/FocusEmptyListTest/FocusEmptyListTest.html @@ -0,0 +1,47 @@ + + + + + FocusEmptyListTest + + + +

    FocusEmptyListTest
    Bug ID: 6387275

    + +

    This is an AUTOMATIC test, simply wait for completion

    + + + + + diff --git a/jdk/test/java/awt/List/FocusEmptyListTest/FocusEmptyListTest.java b/jdk/test/java/awt/List/FocusEmptyListTest/FocusEmptyListTest.java new file mode 100644 index 00000000000..59d8c61269c --- /dev/null +++ b/jdk/test/java/awt/List/FocusEmptyListTest/FocusEmptyListTest.java @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2007, 2015, 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 6387275 + @summary List: the focus is at the top of the first item, XAWT + @author Dmitry.Cherepanov@SUN.COM area=awt.list + @run applet FocusEmptyListTest.html +*/ + +import java.applet.Applet; +import java.awt.*; +import java.lang.reflect.*; +import java.awt.peer.ListPeer; + +import sun.awt.AWTAccessor; + +public class FocusEmptyListTest extends Applet { + + public void init() { + setLayout(new BorderLayout()); + }//End init() + + public void start() { + boolean isXToolkit = Toolkit.getDefaultToolkit() + .getClass().getName().equals("sun.awt.X11.XToolkit"); + if (!isXToolkit) { + System.out.println("The test is XAWT-only."); + return; + } + + List list = new List(); + Object isIndexDisplayed = null; + setLayout(new FlowLayout()); + + getToolkit().addAWTEventListener(System.out::println, + AWTEvent.FOCUS_EVENT_MASK | AWTEvent.WINDOW_FOCUS_EVENT_MASK); + + add(list); + list.add("item1"); + + setSize(200, 200); + setVisible(true); + validate(); + + list.removeAll(); + + try { + + // peer = List.getPeer() + ListPeer peer = AWTAccessor.getComponentAccessor().getPeer(list); + System.out.println("peer = " + peer); + Class peerClass = peer.getClass(); + System.out.println("peer's class = " + peerClass); + + // isIndexDisplayed = peer.isIndexDisplayed(-1) + Method isIndexDisplayedM + = peerClass.getDeclaredMethod("isIndexDisplayed", Integer.TYPE); + System.out.println("method = " + isIndexDisplayedM); + isIndexDisplayedM.setAccessible(true); + isIndexDisplayed = isIndexDisplayedM.invoke(peer, -1); + System.out.println("isIndexDisplayed=" + isIndexDisplayed); + + } catch (Throwable thr) { + throw new RuntimeException("TEST FAILED: " + thr); + } + + if ((Boolean) isIndexDisplayed) { + throw new RuntimeException("TEST FAILED: -1 should be" + + " invisible index"); + } + + }// start() + +}// class AutomaticAppletTest From d1544f66ebadfafcfb9c9d79442c19aa99145c6b Mon Sep 17 00:00:00 2001 From: Semyon Sadetsky Date: Tue, 20 Oct 2015 15:42:59 +0300 Subject: [PATCH 20/43] 8011616: JWindow.getLocation and JWindow.getLocationOnScreen return different values on Unity Reviewed-by: alexsch, serb --- .../unix/classes/sun/awt/X11/XWindow.java | 3 + .../ScreenLocation/ScreenLocationTest.java | 92 +++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 jdk/test/java/awt/Window/ScreenLocation/ScreenLocationTest.java diff --git a/jdk/src/java.desktop/unix/classes/sun/awt/X11/XWindow.java b/jdk/src/java.desktop/unix/classes/sun/awt/X11/XWindow.java index 597020da9e3..a90a938086d 100644 --- a/jdk/src/java.desktop/unix/classes/sun/awt/X11/XWindow.java +++ b/jdk/src/java.desktop/unix/classes/sun/awt/X11/XWindow.java @@ -992,10 +992,13 @@ class XWindow extends XBaseWindow implements X11ComponentPeer { // if ( Check if it's a resize, a move, or a stacking order change ) // { Rectangle bounds = getBounds(); + final ComponentAccessor acc = AWTAccessor.getComponentAccessor(); if (!bounds.getSize().equals(oldBounds.getSize())) { + acc.setSize(target, bounds.width, bounds.height); postEventToEventQueue(new ComponentEvent(getEventSource(), ComponentEvent.COMPONENT_RESIZED)); } if (!bounds.getLocation().equals(oldBounds.getLocation())) { + acc.setLocation(target, bounds.x, bounds.y); postEventToEventQueue(new ComponentEvent(getEventSource(), ComponentEvent.COMPONENT_MOVED)); } // } diff --git a/jdk/test/java/awt/Window/ScreenLocation/ScreenLocationTest.java b/jdk/test/java/awt/Window/ScreenLocation/ScreenLocationTest.java new file mode 100644 index 00000000000..ef89ef0c0cb --- /dev/null +++ b/jdk/test/java/awt/Window/ScreenLocation/ScreenLocationTest.java @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2015, 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 8011616 + @summary JWindow.getLocation and JWindow.getLocationOnScreen return different + values on Unity + @author Semyon Sadetsky + */ + +import java.awt.*; + +public class ScreenLocationTest { + + + public static void main(String[] args) throws Exception { + testLocation(); + testSize(); + System.out.println("ok"); + } + + public static void testLocation() throws Exception { + Window window = new Window((Frame) null); + window.setSize(100, 100); + window.setLocation(0, 0); + window.setVisible(true); + + Robot robot = new Robot(); + robot.delay(200); + robot.waitForIdle(); + + Point location1 = window.getLocation(); + Point location2 = window.getLocationOnScreen(); + window.setLocation(10000, 10000); + + if (!location1.equals(location2)) { + window.dispose(); + throw new RuntimeException("getLocation is different"); + } + + robot.delay(200); + robot.waitForIdle(); + location1 = window.getLocation(); + location2 = window.getLocationOnScreen(); + + if (!location1.equals(location2)) { + window.dispose(); + throw new RuntimeException("getLocation is different"); + } + + window.dispose(); + } + + public static void testSize() throws Exception { + Window window = new Window((Frame) null); + window.setSize(Integer.MAX_VALUE, Integer.MAX_VALUE); + window.setVisible(true); + + Robot robot = new Robot(); + robot.delay(200); + robot.waitForIdle(); + + Dimension size = window.getSize(); + if (size.width == Integer.MAX_VALUE || + size.height == Integer.MAX_VALUE) { + window.dispose(); + throw new RuntimeException("size is wrong"); + } + + window.dispose(); + } +} From d910e3843fb093117b7118371afc1e4efc71afac Mon Sep 17 00:00:00 2001 From: Semyon Sadetsky Date: Tue, 20 Oct 2015 15:59:51 +0300 Subject: [PATCH 21/43] 8022334: After calling frame.toBack() dialog goes to the back on Ubuntu 12.04 Reviewed-by: alexsch, serb --- .../unix/classes/sun/awt/X11/XWindow.java | 3 +- .../MultiWindowApp/MultiWindowAppTest.java | 81 +++++++++++++++++++ 2 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 jdk/test/java/awt/Window/MultiWindowApp/MultiWindowAppTest.java diff --git a/jdk/src/java.desktop/unix/classes/sun/awt/X11/XWindow.java b/jdk/src/java.desktop/unix/classes/sun/awt/X11/XWindow.java index a90a938086d..42a03359f1f 100644 --- a/jdk/src/java.desktop/unix/classes/sun/awt/X11/XWindow.java +++ b/jdk/src/java.desktop/unix/classes/sun/awt/X11/XWindow.java @@ -272,7 +272,8 @@ class XWindow extends XBaseWindow implements X11ComponentPeer { } protected String[] getWMClass() { - return new String[] {XToolkit.getCorrectXIDString(getClass().getName()), XToolkit.getAWTAppClassName()}; + return new String[] {XToolkit.getAWTAppClassName(), + XToolkit.getAWTAppClassName()}; } void setReparented(boolean newValue) { diff --git a/jdk/test/java/awt/Window/MultiWindowApp/MultiWindowAppTest.java b/jdk/test/java/awt/Window/MultiWindowApp/MultiWindowAppTest.java new file mode 100644 index 00000000000..41b4b7fbe5d --- /dev/null +++ b/jdk/test/java/awt/Window/MultiWindowApp/MultiWindowAppTest.java @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2015, 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 @summary After calling frame.toBack() dialog goes to the back on Ubuntu 12.04 + * @bug 8022334 + * @author Semyon Sadetsky + * @run main MultiWindowAppTest + */ + +import java.awt.*; + +public class MultiWindowAppTest { + + public static void main(String[] args) throws Exception { + Window win1 = new Frame(); + Window win2 = new Dialog((Frame) null); + + win1.setBounds(100, 100, 200, 200); + win1.setBackground(Color.RED); + win1.setVisible(true); + + Robot robot = new Robot(); + robot.delay(200); + robot.waitForIdle(); + + win2.setBounds(win1.getBounds()); + win2.setVisible(true); + + robot.delay(200); + robot.waitForIdle(); + + win1.toFront(); + robot.delay(200); + robot.waitForIdle(); + + Point point = win1.getLocationOnScreen(); + Color color = robot.getPixelColor(point.x + 100, point.y + 100); + + if(!color.equals(Color.RED)) { + win1.dispose(); + win2.dispose(); + throw new RuntimeException("Window was not sent to front."); + } + + win1.toBack(); + robot.delay(200); + robot.waitForIdle(); + + color = robot.getPixelColor(point.x + 100, point.y + 100); + + win1.dispose(); + win2.dispose(); + + if(color.equals(Color.RED)) { + throw new RuntimeException("Window was not sent to back."); + } + + System.out.println("ok"); + } +} From 69da2a817d28868dae9fdb6f099e337a4da0f74f Mon Sep 17 00:00:00 2001 From: Alexey Ivanov Date: Tue, 20 Oct 2015 16:55:08 +0300 Subject: [PATCH 22/43] 8130136: Swing window sometimes fails to repaint partially when it becomes exposed Reviewed-by: alexp, serb --- .../libawt/java2d/windows/GDIWindowSurfaceData.cpp | 8 +++++--- .../libawt/java2d/windows/GDIWindowSurfaceData.h | 3 ++- .../native/libawt/windows/awt_Component.cpp | 14 +++++++------- .../windows/native/libawt/windows/awt_Component.h | 6 +++--- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/jdk/src/java.desktop/windows/native/libawt/java2d/windows/GDIWindowSurfaceData.cpp b/jdk/src/java.desktop/windows/native/libawt/java2d/windows/GDIWindowSurfaceData.cpp index b52dce038a0..95e737340fb 100644 --- a/jdk/src/java.desktop/windows/native/libawt/java2d/windows/GDIWindowSurfaceData.cpp +++ b/jdk/src/java.desktop/windows/native/libawt/java2d/windows/GDIWindowSurfaceData.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2015, 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 @@ -114,8 +114,9 @@ void SetupThreadGraphicsInfo(JNIEnv *env, GDIWinSDOps *wsdo) { // which may've been disposed by this time, and we have // no means of checking against it. if (oldhDC != NULL) { - MoveDCToPassiveList(oldhDC); + MoveDCToPassiveList(oldhDC, info->hWnd); info->hDC = NULL; + info->hWnd = NULL; } if (wsdo->window != NULL){ @@ -150,6 +151,7 @@ void SetupThreadGraphicsInfo(JNIEnv *env, GDIWinSDOps *wsdo) { // Finally, set these new values in the info for this thread info->hDC = hDC; + info->hWnd = wsdo->window; } // cached brush and pen are not associated with any DC, and can be @@ -187,7 +189,7 @@ void DisposeThreadGraphicsInfo(JNIEnv *env, jlong tgi) { if (info->hDC != NULL) { // move the DC from the active dcs list to // the passive dc list to be released later - MoveDCToPassiveList(info->hDC); + MoveDCToPassiveList(info->hDC, info->hWnd); } if (info->clip != NULL) { diff --git a/jdk/src/java.desktop/windows/native/libawt/java2d/windows/GDIWindowSurfaceData.h b/jdk/src/java.desktop/windows/native/libawt/java2d/windows/GDIWindowSurfaceData.h index 3dfaa161c02..a954874e9c8 100644 --- a/jdk/src/java.desktop/windows/native/libawt/java2d/windows/GDIWindowSurfaceData.h +++ b/jdk/src/java.desktop/windows/native/libawt/java2d/windows/GDIWindowSurfaceData.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2015, 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 @@ -196,6 +196,7 @@ extern "C" { */ typedef struct { HDC hDC; + HWND hWnd; GDIWinSDOps *wsdo; LONG wsdoTimeStamp; // wsdo creation time stamp. // Other threads may deallocate wsdo diff --git a/jdk/src/java.desktop/windows/native/libawt/windows/awt_Component.cpp b/jdk/src/java.desktop/windows/native/libawt/windows/awt_Component.cpp index 6b1c1255319..b234ec0221b 100644 --- a/jdk/src/java.desktop/windows/native/libawt/windows/awt_Component.cpp +++ b/jdk/src/java.desktop/windows/native/libawt/windows/awt_Component.cpp @@ -1382,7 +1382,7 @@ LRESULT AwtComponent::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) case WM_AWT_RELEASEDC: { HDC hDC = (HDC)wParam; - MoveDCToPassiveList(hDC); + MoveDCToPassiveList(hDC, GetHWnd()); ReleaseDCList(GetHWnd(), passiveDCList); mr = mrConsume; break; @@ -7165,8 +7165,8 @@ void DCList::AddDCItem(DCItem *newItem) } /** - * Given a DC, remove it from the DC list and return - * TRUE if it exists on the current list. Otherwise + * Given a DC and window handle, remove the DC from the DC list + * and return TRUE if it exists on the current list. Otherwise * return FALSE. * A DC may not exist on the list because it has already * been released elsewhere (for example, the window @@ -7174,14 +7174,14 @@ void DCList::AddDCItem(DCItem *newItem) * thread may also want to release a DC when it notices that * its DC is obsolete for the current window). */ -DCItem *DCList::RemoveDC(HDC hDC) +DCItem *DCList::RemoveDC(HDC hDC, HWND hWnd) { listLock.Enter(); DCItem **prevPtrPtr = &head; DCItem *listPtr = head; while (listPtr) { DCItem *nextPtr = listPtr->next; - if (listPtr->hDC == hDC) { + if (listPtr->hDC == hDC && listPtr->hWnd == hWnd) { *prevPtrPtr = nextPtr; break; } @@ -7235,9 +7235,9 @@ void DCList::RealizePalettes(int screen) listLock.Leave(); } -void MoveDCToPassiveList(HDC hDC) { +void MoveDCToPassiveList(HDC hDC, HWND hWnd) { DCItem *removedDC; - if ((removedDC = activeDCList.RemoveDC(hDC)) != NULL) { + if ((removedDC = activeDCList.RemoveDC(hDC, hWnd)) != NULL) { passiveDCList.AddDCItem(removedDC); } } diff --git a/jdk/src/java.desktop/windows/native/libawt/windows/awt_Component.h b/jdk/src/java.desktop/windows/native/libawt/windows/awt_Component.h index 9fe2754142b..f09b41f5b54 100644 --- a/jdk/src/java.desktop/windows/native/libawt/windows/awt_Component.h +++ b/jdk/src/java.desktop/windows/native/libawt/windows/awt_Component.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2015, 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 @@ -900,13 +900,13 @@ public: void AddDC(HDC hDC, HWND hWnd); void AddDCItem(DCItem *newItem); - DCItem *RemoveDC(HDC hDC); + DCItem *RemoveDC(HDC hDC, HWND hWnd); DCItem *RemoveAllDCs(HWND hWnd); void RealizePalettes(int screen); }; void ReleaseDCList(HWND hwnd, DCList &list); -void MoveDCToPassiveList(HDC hDC); +void MoveDCToPassiveList(HDC hDC, HWND hWnd); #include "ObjectList.h" From bfcf012a014ff1ffa356eea85ba437ef06209b35 Mon Sep 17 00:00:00 2001 From: Jayathirth D V Date: Tue, 20 Oct 2015 22:46:29 +0300 Subject: [PATCH 23/43] 7182758: BMPMetadata returns invalid PhysicalPixelSpacing Reviewed-by: serb, vadim --- .../sun/imageio/plugins/bmp/BMPMetadata.java | 4 +- .../plugins/bmp/BMPPixelSpacingTest.java | 115 ++++++++++++++++++ 2 files changed, 117 insertions(+), 2 deletions(-) create mode 100644 jdk/test/javax/imageio/plugins/bmp/BMPPixelSpacingTest.java diff --git a/jdk/src/java.desktop/share/classes/com/sun/imageio/plugins/bmp/BMPMetadata.java b/jdk/src/java.desktop/share/classes/com/sun/imageio/plugins/bmp/BMPMetadata.java index c22415b7575..d955c5f593c 100644 --- a/jdk/src/java.desktop/share/classes/com/sun/imageio/plugins/bmp/BMPMetadata.java +++ b/jdk/src/java.desktop/share/classes/com/sun/imageio/plugins/bmp/BMPMetadata.java @@ -247,11 +247,11 @@ public class BMPMetadata extends IIOMetadata implements BMPConstants { node.appendChild(subNode); subNode = new IIOMetadataNode("HorizontalPhysicalPixelSpacing"); - subNode.setAttribute("value", "" + (1 / xPixelsPerMeter * 1000)); + subNode.setAttribute("value", "" + (1000.0F / xPixelsPerMeter)); node.appendChild(subNode); subNode = new IIOMetadataNode("VerticalPhysicalPixelSpacing"); - subNode.setAttribute("value", "" + (1 / yPixelsPerMeter * 1000)); + subNode.setAttribute("value", "" + (1000.0F / yPixelsPerMeter)); node.appendChild(subNode); return node; diff --git a/jdk/test/javax/imageio/plugins/bmp/BMPPixelSpacingTest.java b/jdk/test/javax/imageio/plugins/bmp/BMPPixelSpacingTest.java new file mode 100644 index 00000000000..7f2c989014f --- /dev/null +++ b/jdk/test/javax/imageio/plugins/bmp/BMPPixelSpacingTest.java @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2015, 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 7182758 + * @summary Test verifies whether we are getting correct Horizontal + * & Vertical Physical pixel spacing for active BMP image + * through stored metadata or not. + * @run main BMPPixelSpacingTest + */ + +import java.io.ByteArrayInputStream; +import java.util.Iterator; +import javax.imageio.ImageIO; +import javax.imageio.ImageReader; +import javax.imageio.metadata.IIOMetadata; +import javax.imageio.stream.ImageInputStream; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +public class BMPPixelSpacingTest { + + public static void main(String[] args) throws Exception { + // Header contaning X & Y pixels-per-meter more than value 1 + byte[] bmpHeaderData = { (byte) 0x42, (byte) 0x4d, (byte) 0x7e, + (byte) 0x06, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x00, (byte) 0x3e, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x28, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0x64, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x64, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x02, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0x00, (byte) 0xff, + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, + (byte) 0xff }; + + ImageInputStream imageInput = ImageIO. + createImageInputStream(new ByteArrayInputStream(bmpHeaderData)); + + for (Iterator it = ImageIO.getImageReaders(imageInput); + it.hasNext(); ) { + ImageReader reader = it.next(); + reader.setInput(imageInput); + IIOMetadata metadata = reader.getImageMetadata(0); + + Node rootNode = metadata.getAsTree("javax_imageio_1.0"); + NodeList nl = rootNode.getChildNodes(); + + //Parse until you get Dimension child node + for (int i = 0; i < nl.getLength(); i++) { + Node node = nl.item(i); + if ((node.getNodeName()).equals("Dimension")) { + //get childnode list under Dimension node + NodeList cl = node.getChildNodes(); + //Corresponding node indices under Dimension node + int horizontalNodeIndex = 1; + int verticalNodeIndex = 2; + Node horizontalNode = cl.item(horizontalNodeIndex); + Node verticalNode = cl.item(verticalNodeIndex); + + //get attributes for horizontal and vertical nodes + NamedNodeMap horizontalAttr = horizontalNode. + getAttributes(); + NamedNodeMap verticalAttr = verticalNode.getAttributes(); + + //since they have only one attribute index is 0 + int attributeIndex = 0; + Node horizontalValue = horizontalAttr.item(attributeIndex); + Node verticalValue = verticalAttr.item(attributeIndex); + float horizontalNodeValue = Float. + parseFloat((horizontalValue.getNodeValue())); + float verticalNodeValue = Float. + parseFloat((verticalValue.getNodeValue())); + + float expectedHorizontalValue, expectedVerticalValue; + // in test metadata xPixelsPerMeter & yPixelsPerMeter is 2 + expectedHorizontalValue = expectedVerticalValue = + 1000.0F / 2; + //expected and returned values should be same + if ((Float.compare(horizontalNodeValue, + expectedHorizontalValue) != 0) || + (Float.compare(verticalNodeValue, + expectedVerticalValue) != 0)) { + throw new RuntimeException("Invalid pixel spacing"); + } + } + } + } + } +} From b96af1d249a237b9f897638f1df78d1d8258840b Mon Sep 17 00:00:00 2001 From: Sergey Bylokhov Date: Wed, 21 Oct 2015 18:32:56 +0300 Subject: [PATCH 24/43] 8138764: In some cases the usage of TreeLock can be replaced by other synchronization Reviewed-by: alexp, alexsch --- .../share/classes/java/awt/Component.java | 6 +- .../share/classes/java/awt/Window.java | 20 ++--- .../classes/sun/swing/CachedPainter.java | 22 +---- .../TreeLockDeadlock/TreeLockDeadlock.java | 88 +++++++++++++++++++ 4 files changed, 100 insertions(+), 36 deletions(-) create mode 100644 jdk/test/java/awt/Component/TreeLockDeadlock/TreeLockDeadlock.java diff --git a/jdk/src/java.desktop/share/classes/java/awt/Component.java b/jdk/src/java.desktop/share/classes/java/awt/Component.java index 72c459943b3..1d80c9e01e0 100644 --- a/jdk/src/java.desktop/share/classes/java/awt/Component.java +++ b/jdk/src/java.desktop/share/classes/java/awt/Component.java @@ -312,7 +312,7 @@ public abstract class Component implements ImageObserver, MenuContainer, * @see GraphicsConfiguration * @see #getGraphicsConfiguration */ - private transient GraphicsConfiguration graphicsConfig = null; + private transient volatile GraphicsConfiguration graphicsConfig; /** * A reference to a BufferStrategy object @@ -1143,9 +1143,7 @@ public abstract class Component implements ImageObserver, MenuContainer, * @since 1.3 */ public GraphicsConfiguration getGraphicsConfiguration() { - synchronized(getTreeLock()) { - return getGraphicsConfiguration_NoClientCode(); - } + return getGraphicsConfiguration_NoClientCode(); } final GraphicsConfiguration getGraphicsConfiguration_NoClientCode() { diff --git a/jdk/src/java.desktop/share/classes/java/awt/Window.java b/jdk/src/java.desktop/share/classes/java/awt/Window.java index 6f834a3f152..72fee8d1c9c 100644 --- a/jdk/src/java.desktop/share/classes/java/awt/Window.java +++ b/jdk/src/java.desktop/share/classes/java/awt/Window.java @@ -347,7 +347,7 @@ public class Window extends Container implements Accessible { * @see #getOpacity() * @since 1.7 */ - private float opacity = 1.0f; + private volatile float opacity = 1.0f; /** * The shape assigned to this window. This field is set to {@code null} if @@ -1040,9 +1040,7 @@ public class Window extends Container implements Accessible { closeSplashScreen(); Dialog.checkShouldBeBlocked(this); super.show(); - synchronized (getTreeLock()) { - this.locationByPlatform = false; - } + locationByPlatform = false; for (int i = 0; i < ownedWindowList.size(); i++) { Window child = ownedWindowList.elementAt(i).get(); if ((child != null) && child.showWithParent) { @@ -1115,9 +1113,7 @@ public class Window extends Container implements Accessible { modalBlocker.unblockWindow(this); } super.hide(); - synchronized (getTreeLock()) { - this.locationByPlatform = false; - } + locationByPlatform = false; } final void clearMostRecentFocusOwnerOnHide() { @@ -3411,7 +3407,7 @@ public class Window extends Container implements Accessible { return super.canContainFocusOwner(focusOwnerCandidate) && isFocusableWindow(); } - private boolean locationByPlatform = locationByPlatformProp; + private volatile boolean locationByPlatform = locationByPlatformProp; /** @@ -3482,9 +3478,7 @@ public class Window extends Container implements Accessible { * @since 1.5 */ public boolean isLocationByPlatform() { - synchronized (getTreeLock()) { - return locationByPlatform; - } + return locationByPlatform; } /** @@ -3573,9 +3567,7 @@ public class Window extends Container implements Accessible { * @since 1.7 */ public float getOpacity() { - synchronized (getTreeLock()) { - return opacity; - } + return opacity; } /** diff --git a/jdk/src/java.desktop/share/classes/sun/swing/CachedPainter.java b/jdk/src/java.desktop/share/classes/sun/swing/CachedPainter.java index ef9a3c2baaf..9e9ca37e912 100644 --- a/jdk/src/java.desktop/share/classes/sun/swing/CachedPainter.java +++ b/jdk/src/java.desktop/share/classes/sun/swing/CachedPainter.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2004, 2015, 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 @@ -53,9 +53,7 @@ import java.util.*; */ public abstract class CachedPainter { // CacheMap maps from class to ImageCache. - private static final Map cacheMap = - new HashMap(); - + private static final Map cacheMap = new HashMap<>(); private static ImageCache getCache(Object key) { synchronized(CachedPainter.class) { @@ -96,20 +94,8 @@ public abstract class CachedPainter { if (w <= 0 || h <= 0) { return; } - if (c != null) { - synchronized(c.getTreeLock()) { - synchronized(CachedPainter.class) { - // If c is non-null, synchronize on the tree lock. - // This is necessary because asking for the - // GraphicsConfiguration will grab a tree lock. - paint0(c, g, x, y, w, h, args); - } - } - } - else { - synchronized(CachedPainter.class) { - paint0(c, g, x, y, w, h, args); - } + synchronized (CachedPainter.class) { + paint0(c, g, x, y, w, h, args); } } diff --git a/jdk/test/java/awt/Component/TreeLockDeadlock/TreeLockDeadlock.java b/jdk/test/java/awt/Component/TreeLockDeadlock/TreeLockDeadlock.java new file mode 100644 index 00000000000..91e651cebb9 --- /dev/null +++ b/jdk/test/java/awt/Component/TreeLockDeadlock/TreeLockDeadlock.java @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2015, 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. + */ + +import java.awt.Frame; +import java.awt.GraphicsConfiguration; +import java.awt.Window; + +import static java.util.concurrent.TimeUnit.MINUTES; +import static java.util.concurrent.TimeUnit.NANOSECONDS; + +/** + * @test + * @bug 8138764 + */ +public final class TreeLockDeadlock extends Frame { + + @Override + public synchronized GraphicsConfiguration getGraphicsConfiguration() { + return super.getGraphicsConfiguration(); + } + + @Override + public synchronized void reshape(int x, int y, int width, int height) { + super.reshape(x, y, width, height); + } + + @Override + public synchronized float getOpacity() { + return super.getOpacity(); + } + + public static void main(final String[] args) throws Exception { + final Window window = new TreeLockDeadlock(); + window.setSize(300, 300); + test(window); + } + + private static void test(final Window window) throws Exception { + final long start = System.nanoTime(); + final long end = start + NANOSECONDS.convert(1, MINUTES); + + final Runnable r1 = () -> { + while (System.nanoTime() < end) { + window.setBounds(window.getBounds()); + } + }; + final Runnable r2 = () -> { + while (System.nanoTime() < end) { + window.getGraphicsConfiguration(); + window.getOpacity(); + } + }; + + final Thread t1 = new Thread(r1); + final Thread t2 = new Thread(r1); + final Thread t3 = new Thread(r2); + final Thread t4 = new Thread(r2); + + t1.start(); + t2.start(); + t3.start(); + t4.start(); + t1.join(); + t2.join(); + t3.join(); + t4.join(); + } +} From d9ebc2b4c2c47e16b264648bee8dda5fc80d90ee Mon Sep 17 00:00:00 2001 From: Mikhail Cherkasov Date: Wed, 21 Oct 2015 18:58:19 +0300 Subject: [PATCH 25/43] 8136763: [macosx] java always returns only one value for "text/uri-list" dataflavor even if several files were copied Reviewed-by: alexsch, serb --- .../resources/flavormap.properties | 5 +- .../sun/lwawt/macosx/CDataTransferer.java | 72 +++++++++---------- .../MacOsXFileAndMultipleFileCopingTest.java} | 57 ++++++++++----- 3 files changed, 75 insertions(+), 59 deletions(-) rename jdk/test/java/awt/datatransfer/DataFlavor/{XJavaUrlDataFlavorTest/XJavaUrlDataFlavorTest.java => MacOsXFileAndMultipleFileCopingTest/MacOsXFileAndMultipleFileCopingTest.java} (85%) diff --git a/jdk/src/java.datatransfer/macosx/classes/sun/datatransfer/resources/flavormap.properties b/jdk/src/java.datatransfer/macosx/classes/sun/datatransfer/resources/flavormap.properties index 10d625fc494..370c7de21fb 100644 --- a/jdk/src/java.datatransfer/macosx/classes/sun/datatransfer/resources/flavormap.properties +++ b/jdk/src/java.datatransfer/macosx/classes/sun/datatransfer/resources/flavormap.properties @@ -72,6 +72,7 @@ JFIF=image/x-java-image;class=java.awt.Image TIFF=image/x-java-image;class=java.awt.Image RICH_TEXT=text/rtf HTML=text/html;charset=utf-8;eoln="\r\n";terminators=1 -URL=application/x-java-url;class=java.net.URL,\ - text/uri-list;eoln="\r\n";terminators=1 +URL=application/x-java-url;class=java.net.URL +FILE_NAME=text/uri-list;eoln="\r\n";terminators=1 +URL=text/uri-list;eoln="\r\n";terminators=1 XPICT=image/x-pict;class=java.io.InputStream diff --git a/jdk/src/java.desktop/macosx/classes/sun/lwawt/macosx/CDataTransferer.java b/jdk/src/java.desktop/macosx/classes/sun/lwawt/macosx/CDataTransferer.java index ae1d4446c05..3f05185c091 100644 --- a/jdk/src/java.desktop/macosx/classes/sun/lwawt/macosx/CDataTransferer.java +++ b/jdk/src/java.desktop/macosx/classes/sun/lwawt/macosx/CDataTransferer.java @@ -1,3 +1,4 @@ + /* * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. @@ -28,12 +29,13 @@ package sun.lwawt.macosx; import java.awt.*; import java.io.*; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.nio.charset.Charset; import java.text.Normalizer; import java.text.Normalizer.Form; import java.util.*; -import java.util.regex.*; import java.awt.datatransfer.*; import sun.awt.datatransfer.*; @@ -127,51 +129,33 @@ public class CDataTransferer extends DataTransferer { long format, Transferable transferable) throws IOException { if (format == CF_URL && URL.class.equals(flavor.getRepresentationClass())) { - String charset = Charset.defaultCharset().name(); - if (transferable != null && transferable.isDataFlavorSupported(javaTextEncodingFlavor)) { - try { - charset = new String((byte[]) transferable.getTransferData(javaTextEncodingFlavor), "UTF-8"); - } catch (UnsupportedFlavorException cannotHappen) { - } + String[] strings = dragQueryFile(bytes); + if(strings == null || strings.length == 0) { + return null; } - String xml = new String(bytes, charset); - // macosx pasteboard returns a property list that consists of one URL - // let's extract it. - return new URL(extractURL(xml)); - } - - if (format == CF_STRING) { + return new URL(strings[0]); + } else if(isUriListFlavor(flavor)) { + // dragQueryFile works fine with files and url, + // it parses and extracts values from property list. + // maxosx always returns property list for + // CF_URL and CF_FILE + String[] strings = dragQueryFile(bytes); + if(strings == null) { + return null; + } + bytes = String.join(System.getProperty("line.separator"), + strings).getBytes(); + // now we extracted uri from xml, now we should treat it as + // regular string that allows to translate data to target represantation + // class by base method + format = CF_STRING; + } else if (format == CF_STRING) { bytes = Normalizer.normalize(new String(bytes, "UTF8"), Form.NFC).getBytes("UTF8"); } return super.translateBytes(bytes, flavor, format, transferable); } - /** - * Macosx pasteboard returns xml document that contains one URL, for exmple: - *
    -     *     {@code
    -     * 
    -     * 
    -     * 
    -     *      
    -     *          file:///path_to_file
    -     *          
    -     *      
    -     * 
    -     *     }
    -     * 
    - */ - private String extractURL(String xml) { - Pattern urlExtractorPattern = Pattern.compile("(.*)"); - Matcher matcher = urlExtractorPattern.matcher(xml); - if (matcher.find()) { - return matcher.group(1); - } else { - return null; - } - } - @Override protected synchronized Long getFormatForNativeAsLong(String str) { Long format = predefinedClipboardNameMap.get(str); @@ -247,6 +231,7 @@ public class CDataTransferer extends DataTransferer { return nativeDragQueryFile(bytes); } + @Override protected Image platformImageBytesToImage(byte[] bytes, long format) throws IOException { return CImage.getCreator().createImageFromPlatformImageBytes(bytes); @@ -271,7 +256,7 @@ public class CDataTransferer extends DataTransferer { } try { DataFlavor df = new DataFlavor(nat); - if (df.getPrimaryType().equals("text") && df.getSubType().equals("uri-list")) { + if (isUriListFlavor(df)) { return true; } } catch (Exception e) { @@ -279,4 +264,11 @@ public class CDataTransferer extends DataTransferer { } return false; } + + private boolean isUriListFlavor(DataFlavor df) { + if (df.getPrimaryType().equals("text") && df.getSubType().equals("uri-list")) { + return true; + } + return false; + } } diff --git a/jdk/test/java/awt/datatransfer/DataFlavor/XJavaUrlDataFlavorTest/XJavaUrlDataFlavorTest.java b/jdk/test/java/awt/datatransfer/DataFlavor/MacOsXFileAndMultipleFileCopingTest/MacOsXFileAndMultipleFileCopingTest.java similarity index 85% rename from jdk/test/java/awt/datatransfer/DataFlavor/XJavaUrlDataFlavorTest/XJavaUrlDataFlavorTest.java rename to jdk/test/java/awt/datatransfer/DataFlavor/MacOsXFileAndMultipleFileCopingTest/MacOsXFileAndMultipleFileCopingTest.java index 7e86b92e192..18b70121aab 100644 --- a/jdk/test/java/awt/datatransfer/DataFlavor/XJavaUrlDataFlavorTest/XJavaUrlDataFlavorTest.java +++ b/jdk/test/java/awt/datatransfer/DataFlavor/MacOsXFileAndMultipleFileCopingTest/MacOsXFileAndMultipleFileCopingTest.java @@ -23,10 +23,9 @@ /* @test - @bug 8081787 - @summary MalformedURLException is thrown during reading data for application/x-java-url;class=java.net.URL flavor + @bug 8081787 8136763 @author Mikhail Cherkasov - @run main/manual XJavaUrlDataFlavorTest + @run main/manual MacOsXFileAndMultipleFileCopingTest */ import javax.swing.*; @@ -36,17 +35,24 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.net.URL; -public class XJavaUrlDataFlavorTest { +public class MacOsXFileAndMultipleFileCopingTest { private static void init() { String[] instructions = {"Test for MacOS X only:", "1. The aim is to test that java works fine with \"application/" + - "x-java-url;class=java.net.URL\"falvor.", + "x-java-url;class=java.net.URL\"falvor and support coping of multiple files", "2. Open finder and select any file.", "3. Press CMD+C or press \"Copy\" in context menu", - "4. Focus window with \"Test\" Button.", + "4. Focus window with \"Test URL\" Button.", "5. If you see URL for selected file, then test PASSED,", - "otherwise test FAILED." + "otherwise test FAILED.", + + "6. Open finder again and select several files.", + "7. Press CMD+C or press \"Copy\" in context menu", + "8. Focus window with \"Test multiple files coping\" Button.", + "9. If you see list of selected files, then test PASSED,", + "otherwise test FAILED.", + }; Sysout.createDialog(); @@ -57,22 +63,36 @@ public class XJavaUrlDataFlavorTest { panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS)); frame.add(panel); - Button testButton = new Button("Test"); - final TextField textField = new TextField(40); - testButton.addActionListener(new AbstractAction() { + Button testUrlBtn = new Button("Test URL"); + final TextArea textArea = new TextArea(5, 80); + testUrlBtn.addActionListener(new AbstractAction() { @Override public void actionPerformed(ActionEvent ae) { try { Clipboard board = Toolkit.getDefaultToolkit().getSystemClipboard(); - URL url = (URL)board.getData(new DataFlavor("application/x-java-url;class=java.net.URL")); - textField.setText(url.toString()); + URL url = (URL) board.getData(new DataFlavor("application/x-java-url;class=java.net.URL")); + textArea.setText(url.toString()); } catch (Exception e) { throw new RuntimeException(e); } } }); - panel.add(testButton); - panel.add(textField); + panel.add(testUrlBtn); + Button testUriList = new Button("Test multiple files coping"); + testUriList.addActionListener(new AbstractAction() { + @Override + public void actionPerformed(ActionEvent ae) { + try { + Clipboard board = Toolkit.getDefaultToolkit().getSystemClipboard(); + String files = (String) board.getData(new DataFlavor("text/uri-list;class=java.lang.String")); + textArea.setText(files); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + }); + panel.add(testUriList); + panel.add(textArea); frame.setBounds(200, 200, 400, 400); frame.setVisible(true); @@ -100,6 +120,9 @@ public class XJavaUrlDataFlavorTest { private static int sleepTime = 300000; public static void main(String args[]) throws InterruptedException { + if (!System.getProperty("os.name").startsWith("Mac")) { + return; + } mainThread = Thread.currentThread(); try { init(); @@ -336,10 +359,10 @@ class TestDialog extends Dialog implements ActionListener { //ManualMainTest public void actionPerformed(ActionEvent e) { if (e.getActionCommand() == "pass") { - XJavaUrlDataFlavorTest.pass(); + MacOsXFileAndMultipleFileCopingTest.pass(); } else { - XJavaUrlDataFlavorTest.fail(); + MacOsXFileAndMultipleFileCopingTest.fail(); } } -}// TestDialog class +}// TestDialog class \ No newline at end of file From 5c2672351683467fdeeda7796d971634fc3c51ae Mon Sep 17 00:00:00 2001 From: Phil Race Date: Wed, 21 Oct 2015 09:21:25 -0700 Subject: [PATCH 26/43] 8132890: Text overlapping on dot matrix printers Reviewed-by: jgodinez, serb --- .../sun/awt/windows/WPathGraphics.java | 85 ++++++++++++++----- .../awt/print/PrinterJob/PrintTextTest.java | 52 +++++++++++- 2 files changed, 116 insertions(+), 21 deletions(-) diff --git a/jdk/src/java.desktop/windows/classes/sun/awt/windows/WPathGraphics.java b/jdk/src/java.desktop/windows/classes/sun/awt/windows/WPathGraphics.java index 75e51636ec2..f892a88bf6c 100644 --- a/jdk/src/java.desktop/windows/classes/sun/awt/windows/WPathGraphics.java +++ b/jdk/src/java.desktop/windows/classes/sun/awt/windows/WPathGraphics.java @@ -494,24 +494,48 @@ final class WPathGraphics extends PathGraphics { */ float fontSize = font.getSize2D(); + double devResX = wPrinterJob.getXRes(); + double devResY = wPrinterJob.getYRes(); + + double fontDevScaleY = devResY / DEFAULT_USER_RES; + + int orient = getPageFormat().getOrientation(); + if (orient == PageFormat.LANDSCAPE || + orient == PageFormat.REVERSE_LANDSCAPE) + { + double tmp = devResX; + devResX = devResY; + devResY = tmp; + } + + double devScaleX = devResX / DEFAULT_USER_RES; + double devScaleY = devResY / DEFAULT_USER_RES; + fontTransform.scale(1.0/devScaleX, 1.0/devScaleY); + Point2D.Double pty = new Point2D.Double(0.0, 1.0); fontTransform.deltaTransform(pty, pty); double scaleFactorY = Math.sqrt(pty.x*pty.x+pty.y*pty.y); - float scaledFontSizeY = (float)(fontSize * scaleFactorY); + float scaledFontSizeY = (float)(fontSize * scaleFactorY * fontDevScaleY); Point2D.Double ptx = new Point2D.Double(1.0, 0.0); fontTransform.deltaTransform(ptx, ptx); double scaleFactorX = Math.sqrt(ptx.x*ptx.x+ptx.y*ptx.y); - float scaledFontSizeX = (float)(fontSize * scaleFactorX); float awScale = getAwScale(scaleFactorX, scaleFactorY); int iangle = getAngle(ptx); + ptx = new Point2D.Double(1.0, 0.0); + deviceTransform.deltaTransform(ptx, ptx); + double advanceScaleX = Math.sqrt(ptx.x*ptx.x+ptx.y*ptx.y); + pty = new Point2D.Double(0.0, 1.0); + deviceTransform.deltaTransform(pty, pty); + double advanceScaleY = Math.sqrt(pty.x*pty.x+pty.y*pty.y); + Font2D font2D = FontUtilities.getFont2D(font); if (font2D instanceof TrueTypeFont) { textOut(str, font, (TrueTypeFont)font2D, frc, scaledFontSizeY, iangle, awScale, - deviceTransform, scaleFactorX, + advanceScaleX, advanceScaleY, x, y, devpos.x, devpos.y, targetW); } else if (font2D instanceof CompositeFont) { /* Composite fonts are made up of multiple fonts and each @@ -542,7 +566,7 @@ final class WPathGraphics extends PathGraphics { PhysicalFont slotFont = compFont.getSlotFont(slot); textOut(substr, font, slotFont, frc, scaledFontSizeY, iangle, awScale, - deviceTransform, scaleFactorX, + advanceScaleX, advanceScaleY, userx, usery, devx, devy, 0f); Rectangle2D bds = font.getStringBounds(substr, frc); float xAdvance = (float)bds.getWidth(); @@ -635,18 +659,42 @@ final class WPathGraphics extends PathGraphics { */ float fontSize = font.getSize2D(); + double devResX = wPrinterJob.getXRes(); + double devResY = wPrinterJob.getYRes(); + + double fontDevScaleY = devResY / DEFAULT_USER_RES; + + int orient = getPageFormat().getOrientation(); + if (orient == PageFormat.LANDSCAPE || + orient == PageFormat.REVERSE_LANDSCAPE) + { + double tmp = devResX; + devResX = devResY; + devResY = tmp; + } + + double devScaleX = devResX / DEFAULT_USER_RES; + double devScaleY = devResY / DEFAULT_USER_RES; + fontTransform.scale(1.0/devScaleX, 1.0/devScaleY); + Point2D.Double pty = new Point2D.Double(0.0, 1.0); fontTransform.deltaTransform(pty, pty); double scaleFactorY = Math.sqrt(pty.x*pty.x+pty.y*pty.y); - float scaledFontSizeY = (float)(fontSize * scaleFactorY); + float scaledFontSizeY = (float)(fontSize * scaleFactorY * fontDevScaleY); - Point2D.Double pt = new Point2D.Double(1.0, 0.0); - fontTransform.deltaTransform(pt, pt); - double scaleFactorX = Math.sqrt(pt.x*pt.x+pt.y*pt.y); - float scaledFontSizeX = (float)(fontSize * scaleFactorX); + Point2D.Double ptx = new Point2D.Double(1.0, 0.0); + fontTransform.deltaTransform(ptx, ptx); + double scaleFactorX = Math.sqrt(ptx.x*ptx.x+ptx.y*ptx.y); float awScale = getAwScale(scaleFactorX, scaleFactorY); - int iangle = getAngle(pt); + int iangle = getAngle(ptx); + + ptx = new Point2D.Double(1.0, 0.0); + deviceTransform.deltaTransform(ptx, ptx); + double advanceScaleX = Math.sqrt(ptx.x*ptx.x+ptx.y*ptx.y); + pty = new Point2D.Double(0.0, 1.0); + deviceTransform.deltaTransform(pty, pty); + double advanceScaleY = Math.sqrt(pty.x*pty.x+pty.y*pty.y); int numGlyphs = gv.getNumGlyphs(); int[] glyphCodes = gv.getGlyphCodes(0, numGlyphs, null); @@ -705,8 +753,7 @@ final class WPathGraphics extends PathGraphics { * rotation element of the deviceTransform. */ AffineTransform advanceTransform = - new AffineTransform(deviceTransform); - advanceTransform.rotate(iangle*Math.PI/1800.0); + AffineTransform.getScaleInstance(advanceScaleX, advanceScaleY); float[] glyphAdvPos = new float[glyphPos.length]; advanceTransform.transform(glyphPos, 0, //source @@ -784,8 +831,7 @@ final class WPathGraphics extends PathGraphics { Font font, PhysicalFont font2D, FontRenderContext frc, float deviceSize, int rotation, float awScale, - AffineTransform deviceTransform, - double scaleFactorX, + double scaleFactorX, double scaleFactorY, float userx, float usery, float devx, float devy, float targetW) { @@ -826,8 +872,7 @@ final class WPathGraphics extends PathGraphics { * See earlier comment in printGlyphVector() for details. */ AffineTransform advanceTransform = - new AffineTransform(deviceTransform); - advanceTransform.rotate(rotation*Math.PI/1800.0); + AffineTransform.getScaleInstance(scaleFactorX, scaleFactorY); float[] glyphAdvPos = new float[glyphPos.length]; advanceTransform.transform(glyphPos, 0, //source @@ -841,11 +886,11 @@ final class WPathGraphics extends PathGraphics { /* If 2D and GDI agree on the advance of the string we do not * need to explicitly assign glyph positions. * If we are to use the GDI advance, require it to agree with - * JDK to a precision of <= 0.2% - ie 1 pixel in 500 + * JDK to a precision of <= 1.0% - ie 1 pixel in 100 * discrepancy after rounding the 2D advance to the * nearest pixel and is greater than one pixel in total. - * ie strings < 500 pixels in length will be OK so long - * as they differ by only 1 pixel even though that is > 0.02% + * ie strings < 100 pixels in length will be OK so long + * as they differ by only 1 pixel even though that is > 1% * The bounds from 2D are in user space so need to * be scaled to device space for comparison with GDI. * scaleX is the scale from user space to device space needed for this. @@ -863,7 +908,7 @@ final class WPathGraphics extends PathGraphics { if (ratio < 1) { ratio = 1/ratio; } - return diff <= 1 || ratio < 1.002; + return diff <= 1 || ratio < 1.01; } return true; } diff --git a/jdk/test/java/awt/print/PrinterJob/PrintTextTest.java b/jdk/test/java/awt/print/PrinterJob/PrintTextTest.java index 6b58454318d..6ad45dd6f4f 100644 --- a/jdk/test/java/awt/print/PrinterJob/PrintTextTest.java +++ b/jdk/test/java/awt/print/PrinterJob/PrintTextTest.java @@ -23,7 +23,7 @@ /** * @test - * @bug 6425068 7157659 + * @bug 6425068 7157659 8132890 * @summary Confirm that text prints where we expect to the length we expect. * @run main/manual=yesno PrintTextTest */ @@ -113,6 +113,32 @@ public class PrintTextTest extends Component implements Printable { book.append(ptt, portrait); book.append(ptt, landscape); + font = new Font("Dialog", Font.PLAIN, 18); + AffineTransform scaleTx = AffineTransform.getScaleInstance(1.25, 1.25); + name = "Page " + new Integer(page++); + ptt = new PrintTextTest(name, font, scaleTx, false); + p.add(name, ptt); + book.append(ptt, portrait); + book.append(ptt, landscape); + + font = new Font("Dialog", Font.PLAIN, 18); + scaleTx = AffineTransform.getScaleInstance(-1.25, 1.25); + scaleTx.translate(-preferredSize/1.25, 0); + name = "Page " + new Integer(page++); + ptt = new PrintTextTest(name, font, scaleTx, false); + p.add(name, ptt); + book.append(ptt, portrait); + book.append(ptt, landscape); + + font = new Font("Dialog", Font.PLAIN, 18); + scaleTx = AffineTransform.getScaleInstance(1.25, -1.25); + scaleTx.translate(0, -preferredSize/1.25); + name = "Page " + new Integer(page++); + ptt = new PrintTextTest(name, font, scaleTx, false); + p.add(name, ptt); + book.append(ptt, portrait); + book.append(ptt, landscape); + font = font.deriveFont(rotTx); name = "Page " + new Integer(page++); ptt = new PrintTextTest(name, font, null, false); @@ -121,6 +147,30 @@ public class PrintTextTest extends Component implements Printable { book.append(ptt, portrait); book.append(ptt, landscape); + font = new Font("Monospaced", Font.PLAIN, 12); + name = "Page " + new Integer(page++); + ptt = new PrintTextTest(name, font, null, false); + p.add(ptt, BorderLayout.CENTER); + p.add(name, ptt); + book.append(ptt, portrait); + book.append(ptt, landscape); + + Font xfont = font.deriveFont(AffineTransform.getScaleInstance(1.5, 1)); + name = "Page " + new Integer(page++); + ptt = new PrintTextTest(name, xfont, null, false); + p.add(ptt, BorderLayout.CENTER); + p.add(name, ptt); + book.append(ptt, portrait); + book.append(ptt, landscape); + + Font yfont = font.deriveFont(AffineTransform.getScaleInstance(1, 1.5)); + name = "Page " + new Integer(page++); + ptt = new PrintTextTest(name, yfont, null, false); + p.add(ptt, BorderLayout.CENTER); + p.add(name, ptt); + book.append(ptt, portrait); + book.append(ptt, landscape); + if (System.getProperty("os.name").startsWith("Windows")) { font = new Font("MS Gothic", Font.PLAIN, 12); name = "Page " + new Integer(page++); From 9a971332651ee29b10defb696fe09feeb4829ed6 Mon Sep 17 00:00:00 2001 From: Sergey Bylokhov Date: Wed, 21 Oct 2015 21:28:59 +0300 Subject: [PATCH 27/43] 8041900: [macosx] Java forces the use of discrete GPU Reviewed-by: ssadetsky, alexsch --- .../native/libawt_lwawt/awt/CGraphicsEnv.m | 24 +++++++++++-------- .../java2d/opengl/CGLGraphicsConfig.m | 1 + 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/jdk/src/java.desktop/macosx/native/libawt_lwawt/awt/CGraphicsEnv.m b/jdk/src/java.desktop/macosx/native/libawt_lwawt/awt/CGraphicsEnv.m index 745569452d6..1c3baf40dde 100644 --- a/jdk/src/java.desktop/macosx/native/libawt_lwawt/awt/CGraphicsEnv.m +++ b/jdk/src/java.desktop/macosx/native/libawt_lwawt/awt/CGraphicsEnv.m @@ -26,6 +26,7 @@ #import "AWT_debug.h" #import "jni_util.h" +#import "ThreadUtilities.h" #import @@ -114,17 +115,20 @@ static void displaycb_handle { if (flags == kCGDisplayBeginConfigurationFlag) return; - JNFPerformEnvBlock(JNFThreadDetachImmediately, ^(JNIEnv *env) { - JNFWeakJObjectWrapper *wrapper = (JNFWeakJObjectWrapper *)userInfo; + [ThreadUtilities performOnMainThreadWaiting:NO block:^() { - jobject graphicsEnv = [wrapper jObjectWithEnv:env]; - if (graphicsEnv == NULL) return; // ref already GC'd - static JNF_CLASS_CACHE(jc_CGraphicsEnvironment, "sun/awt/CGraphicsEnvironment"); - static JNF_MEMBER_CACHE(jm_displayReconfiguration, jc_CGraphicsEnvironment, "_displayReconfiguration", "(IZ)V"); - JNFCallVoidMethod(env, graphicsEnv, jm_displayReconfiguration, - (jint) display, - (jboolean) flags & kCGDisplayRemoveFlag); - }); + JNFPerformEnvBlock(JNFThreadDetachImmediately, ^(JNIEnv *env) { + JNFWeakJObjectWrapper *wrapper = (JNFWeakJObjectWrapper *)userInfo; + + jobject graphicsEnv = [wrapper jObjectWithEnv:env]; + if (graphicsEnv == NULL) return; // ref already GC'd + static JNF_CLASS_CACHE(jc_CGraphicsEnvironment, "sun/awt/CGraphicsEnvironment"); + static JNF_MEMBER_CACHE(jm_displayReconfiguration, + jc_CGraphicsEnvironment, "_displayReconfiguration","(IZ)V"); + JNFCallVoidMethod(env, graphicsEnv, jm_displayReconfiguration, + (jint) display, (jboolean) flags & kCGDisplayRemoveFlag); + }); + }]; } /* diff --git a/jdk/src/java.desktop/macosx/native/libawt_lwawt/java2d/opengl/CGLGraphicsConfig.m b/jdk/src/java.desktop/macosx/native/libawt_lwawt/java2d/opengl/CGLGraphicsConfig.m index 605c345f2ce..775b92f5b2b 100644 --- a/jdk/src/java.desktop/macosx/native/libawt_lwawt/java2d/opengl/CGLGraphicsConfig.m +++ b/jdk/src/java.desktop/macosx/native/libawt_lwawt/java2d/opengl/CGLGraphicsConfig.m @@ -233,6 +233,7 @@ Java_sun_java2d_opengl_CGLGraphicsConfig_getCGLConfigInfo } NSOpenGLPixelFormatAttribute attrs[] = { + NSOpenGLPFAAllowOfflineRenderers, NSOpenGLPFAClosestPolicy, NSOpenGLPFAWindow, NSOpenGLPFAPixelBuffer, From 80a6875dbf751a7d089cff7381ada3ac3e297693 Mon Sep 17 00:00:00 2001 From: Sebastian Sickelmann Date: Thu, 22 Oct 2015 13:46:52 +0400 Subject: [PATCH 28/43] 8139754: Change Boolean constructor use to the use of Boolean factorymethods. For the macosx-port-dev area Reviewed-by: serb, alexsch --- .../macosx/classes/com/apple/laf/AquaTabbedPaneUI.java | 2 +- .../macosx/classes/sun/lwawt/macosx/CAccessibility.java | 2 +- .../macosx/classes/sun/lwawt/macosx/LWCToolkit.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/jdk/src/java.desktop/macosx/classes/com/apple/laf/AquaTabbedPaneUI.java b/jdk/src/java.desktop/macosx/classes/com/apple/laf/AquaTabbedPaneUI.java index b07ab5ab066..f5c8cd1bcf0 100644 --- a/jdk/src/java.desktop/macosx/classes/com/apple/laf/AquaTabbedPaneUI.java +++ b/jdk/src/java.desktop/macosx/classes/com/apple/laf/AquaTabbedPaneUI.java @@ -845,7 +845,7 @@ public class AquaTabbedPaneUI extends AquaTabbedPaneCopyFromBasicUI { boolean isDefaultFocusReceiver(final JComponent component) { if (isDefaultFocusReceiver == null) { Component defaultFocusReceiver = KeyboardFocusManager.getCurrentKeyboardFocusManager().getDefaultFocusTraversalPolicy().getDefaultComponent(getTopLevelFocusCycleRootAncestor(component)); - isDefaultFocusReceiver = new Boolean(defaultFocusReceiver != null && defaultFocusReceiver.equals(component)); + isDefaultFocusReceiver = defaultFocusReceiver != null && defaultFocusReceiver.equals(component); } return isDefaultFocusReceiver.booleanValue(); } diff --git a/jdk/src/java.desktop/macosx/classes/sun/lwawt/macosx/CAccessibility.java b/jdk/src/java.desktop/macosx/classes/sun/lwawt/macosx/CAccessibility.java index 919c31cb234..3bf3cf8f44e 100644 --- a/jdk/src/java.desktop/macosx/classes/sun/lwawt/macosx/CAccessibility.java +++ b/jdk/src/java.desktop/macosx/classes/sun/lwawt/macosx/CAccessibility.java @@ -175,7 +175,7 @@ class CAccessibility implements PropertyChangeListener { final AccessibleSelection as = ac.getAccessibleSelection(); if (as == null) return Boolean.FALSE; - return new Boolean(as.isAccessibleChildSelected(index)); + return as.isAccessibleChildSelected(index); } }, c); } diff --git a/jdk/src/java.desktop/macosx/classes/sun/lwawt/macosx/LWCToolkit.java b/jdk/src/java.desktop/macosx/classes/sun/lwawt/macosx/LWCToolkit.java index eccba3032dd..8f9e1459103 100644 --- a/jdk/src/java.desktop/macosx/classes/sun/lwawt/macosx/LWCToolkit.java +++ b/jdk/src/java.desktop/macosx/classes/sun/lwawt/macosx/LWCToolkit.java @@ -380,7 +380,7 @@ public final class LWCToolkit extends LWToolkit { desktopProperties.put("DnD.Autoscroll.interval", new Integer(50)); desktopProperties.put("DnD.Autoscroll.cursorHysteresis", new Integer(5)); - desktopProperties.put("DnD.isDragImageSupported", new Boolean(true)); + desktopProperties.put("DnD.isDragImageSupported", Boolean.TRUE); // Register DnD cursors desktopProperties.put("DnD.Cursor.CopyDrop", new NamedCursor("DnD.Cursor.CopyDrop")); From 4671194aaf2c20c56a1c55f2ef8c5e4b27301ce6 Mon Sep 17 00:00:00 2001 From: Magnus Ihse Bursie Date: Tue, 3 Nov 2015 16:15:52 +0100 Subject: [PATCH 29/43] 6512052: Remove java-rmi.exe and java-rmi.cgi Reviewed-by: alanb --- jdk/make/launcher/Launcher-java.rmi.gmk | 31 ---------- jdk/src/java.rmi/unix/bin/java-rmi.cgi.sh | 74 ----------------------- 2 files changed, 105 deletions(-) delete mode 100644 jdk/src/java.rmi/unix/bin/java-rmi.cgi.sh diff --git a/jdk/make/launcher/Launcher-java.rmi.gmk b/jdk/make/launcher/Launcher-java.rmi.gmk index 26f9b7dc627..58b2328713e 100644 --- a/jdk/make/launcher/Launcher-java.rmi.gmk +++ b/jdk/make/launcher/Launcher-java.rmi.gmk @@ -30,34 +30,3 @@ $(eval $(call SetupLauncher,rmid, \ $(eval $(call SetupLauncher,rmiregistry, \ -DJAVA_ARGS='{ "-J-ms8m"$(COMMA) "sun.rmi.registry.RegistryImpl"$(COMMA) }')) - -########################################################################################## - -# -# The java-rmi.cgi script in bin/ only gets delivered in certain situations -# -JAVA_RMI_CGI := $(SUPPORT_OUTPUTDIR)/modules_cmds/$(MODULE)/java-rmi.cgi -ifeq ($(OPENJDK_TARGET_OS), linux) - TARGETS += $(JAVA_RMI_CGI) -endif -ifeq ($(OPENJDK_TARGET_OS), solaris) - TARGETS += $(JAVA_RMI_CGI) -endif - -# TODO: -# On windows java-rmi.cgi shouldn't be bundled since Java 1.2, but has been built all -# this time anyway. Since jdk6, it has been built from the wrong source and resulted -# in a (almost) copy of the standard java launcher named "java-rmi.exe" ending up in -# the final images bin dir. This weird behavior is mimicked here in the converted -# makefiles for now. Should probably just be deleted. -# http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6512052 -ifeq ($(OPENJDK_TARGET_OS), windows) - $(eval $(call SetupLauncher,java-rmi, , \ - $(call SET_SHARED_LIBRARY_MAPFILE,$(JDK_TOPDIR)/make/java/main/java/mapfile-$(OPENJDK_TARGET_CPU)),,,,,,,,,RMI)) -else - $(JAVA_RMI_CGI): $(JDK_TOPDIR)/src/java.rmi/unix/bin/java-rmi.cgi.sh - $(call install-file) - $(CHMOD) a+x $@ -endif - -########################################################################################## diff --git a/jdk/src/java.rmi/unix/bin/java-rmi.cgi.sh b/jdk/src/java.rmi/unix/bin/java-rmi.cgi.sh deleted file mode 100644 index f5d00feac55..00000000000 --- a/jdk/src/java.rmi/unix/bin/java-rmi.cgi.sh +++ /dev/null @@ -1,74 +0,0 @@ -#!/bin/sh - -# -# Copyright (c) 1996, 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. Oracle designates this -# particular file as subject to the "Classpath" exception as provided -# by Oracle in the LICENSE file that accompanied this code. -# -# 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. -# - -# -# - -# -# This script executes the Java interpreter, defines properties -# that correspond to the CGI 1.0 environment variables, and executes -# the class "sun.rmi.transport.proxy.CGIHandler". It should be -# installed in the directory to which the HTTP server maps the -# URL path "/cgi-bin". -# -# (Configuration is necessary as noted below.) -# -# This class will support a QUERY_STRING of the form "forward=" -# with a REQUEST_METHOD "POST". The body of the request will be -# forwarded (as another POST request) to the server listening on the -# specified port (must be >= 1024). The response from this forwarded -# request will be the response to the original request. -# -# CONFIGURATION: -# -# Fill in correct absolute path to Java interpreter below. For example, -# the "PATH=" line might be changed to the follow if the JDK is installed -# at the path "/home/peter/java": -# -# PATH=/home/peter/java/bin:$PATH -# -PATH=/usr/local/java/bin:$PATH -exec java \ - -DAUTH_TYPE="$AUTH_TYPE" \ - -DCONTENT_LENGTH="$CONTENT_LENGTH" \ - -DCONTENT_TYPE="$CONTENT_TYPE" \ - -DGATEWAY_INTERFACE="$GATEWAY_INTERFACE" \ - -DHTTP_ACCEPT="$HTTP_ACCEPT" \ - -DPATH_INFO="$PATH_INFO" \ - -DPATH_TRANSLATED="$PATH_TRANSLATED" \ - -DQUERY_STRING="$QUERY_STRING" \ - -DREMOTE_ADDR="$REMOTE_ADDR" \ - -DREMOTE_HOST="$REMOTE_HOST" \ - -DREMOTE_IDENT="$REMOTE_IDENT" \ - -DREMOTE_USER="$REMOTE_USER" \ - -DREQUEST_METHOD="$REQUEST_METHOD" \ - -DSCRIPT_NAME="$SCRIPT_NAME" \ - -DSERVER_NAME="$SERVER_NAME" \ - -DSERVER_PORT="$SERVER_PORT" \ - -DSERVER_PROTOCOL="$SERVER_PROTOCOL" \ - -DSERVER_SOFTWARE="$SERVER_SOFTWARE" \ - sun.rmi.transport.proxy.CGIHandler From 937b5e1d5e77c7d2da1b359e1a124f1e05abcdca Mon Sep 17 00:00:00 2001 From: Roger Riggs Date: Tue, 3 Nov 2015 10:20:14 -0500 Subject: [PATCH 30/43] 8139345: java/lang/ProcessHandle/TreeTest.java test fails with ... Wrong number of children expected [3] but found [2] Reviewed-by: darcy --- .../java/lang/ProcessHandle/TreeTest.java | 70 +++++++++++++++++-- 1 file changed, 64 insertions(+), 6 deletions(-) diff --git a/jdk/test/java/lang/ProcessHandle/TreeTest.java b/jdk/test/java/lang/ProcessHandle/TreeTest.java index b41f3c276af..ea12d3f361f 100644 --- a/jdk/test/java/lang/ProcessHandle/TreeTest.java +++ b/jdk/test/java/lang/ProcessHandle/TreeTest.java @@ -27,9 +27,11 @@ import java.util.ArrayList; import java.time.Duration; import java.time.Instant; import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -44,6 +46,7 @@ import org.testng.annotations.Test; * @library /lib/testlibrary * Test counting and JavaChild.spawning and counting of Processes. * @run testng/othervm InfoTest + * @key intermittent * @author Roger Riggs */ public class TreeTest extends ProcessUtil { @@ -195,7 +198,7 @@ public class TreeTest extends ProcessUtil { allChildren.stream().map(p -> p.getPid()) .collect(Collectors.toList())); - // Verify that all spawned children show up in the allChildrenList + // Verify that all spawned children show up in the allChildren List processes.forEach((p, parent) -> { Assert.assertEquals(p.isAlive(), true, "Child should be alive: " + p); Assert.assertTrue(allChildren.contains(p), "Spawned child should be listed in allChildren: " + p); @@ -241,6 +244,7 @@ public class TreeTest extends ProcessUtil { printf(" p1: %s%n", p1.getPid()); int newChildren = 3; + CountDownLatch spawnCount = new CountDownLatch(newChildren); // Spawn children and have them wait p1.sendAction("spawn", newChildren, "stdin"); @@ -251,11 +255,26 @@ public class TreeTest extends ProcessUtil { Long child = Long.valueOf(split[2]); Long parent = Long.valueOf(split[0].split(":")[0]); processes.put(ProcessHandle.of(child).get(), ProcessHandle.of(parent).get()); + spawnCount.countDown(); } }); - // Wait for the new processes and save the list - List allChildren = waitForAllChildren(p1Handle, newChildren); + // Wait for all the subprocesses to be listed as started + Assert.assertTrue(spawnCount.await(Utils.adjustTimeout(30L), TimeUnit.SECONDS), + "Timeout waiting for processes to start"); + + // Debugging; list allChildren that are not expected in processes + List allChildren = ProcessUtil.getAllChildren(p1Handle); + long count = allChildren.stream() + .filter(ph -> !processes.containsKey(ph)) + .count(); + if (count > 0) { + allChildren.stream() + .filter(ph -> !processes.containsKey(ph)) + .forEach(ph1 -> ProcessUtil.printProcess(ph1, "Extra process: ")); + ProcessUtil.logTaskList(); + Assert.assertEquals(0, count, "Extra processes in allChildren"); + } // Verify that all spawned children are alive, show up in the allChildren list // then destroy them @@ -266,6 +285,7 @@ public class TreeTest extends ProcessUtil { }); Assert.assertEquals(processes.size(), newChildren, "Wrong number of children"); + // Wait for each of the processes to exit processes.forEach((p, parent) -> { for (long retries = Utils.adjustTimeout(100L); retries > 0 ; retries--) { if (!p.isAlive()) { @@ -285,8 +305,10 @@ public class TreeTest extends ProcessUtil { p1.destroyForcibly(); p1.waitFor(); + // Verify that none of the spawned children are still listed by allChildren List remaining = getAllChildren(self); - remaining = remaining.stream().filter(processes::contains).collect(Collectors.toList()); + Assert.assertFalse(remaining.remove(p1Handle), "Child p1 should have exited"); + remaining = remaining.stream().filter(processes::containsKey).collect(Collectors.toList()); Assert.assertEquals(remaining.size(), 0, "Subprocess(es) should have exited: " + remaining); } catch (IOException ioe) { @@ -354,6 +376,8 @@ public class TreeTest extends ProcessUtil { */ @Test public static void test5() { + ConcurrentHashMap processes = new ConcurrentHashMap<>(); + int factor = 2; JavaChild p1 = null; Instant start = Instant.now(); @@ -374,11 +398,39 @@ public class TreeTest extends ProcessUtil { p1.sendAction("child", "child", "spawn", factor, "stdin"); int newChildren = factor * (1 + factor * (1 + factor)); - List children = ProcessUtil.waitForAllChildren(p1Handle, newChildren); + CountDownLatch spawnCount = new CountDownLatch(newChildren); + + // Gather the PIDs from the output of the spawning process + p1.forEachOutputLine((s) -> { + String[] split = s.trim().split(" "); + if (split.length == 3 && split[1].equals("spawn")) { + Long child = Long.valueOf(split[2]); + Long parent = Long.valueOf(split[0].split(":")[0]); + processes.put(ProcessHandle.of(child).get(), ProcessHandle.of(parent).get()); + spawnCount.countDown(); + } + }); + + // Wait for all the subprocesses to be listed as started + Assert.assertTrue(spawnCount.await(Utils.adjustTimeout(30L), TimeUnit.SECONDS), + "Timeout waiting for processes to start"); + + // Debugging; list allChildren that are not expected in processes + List allChildren = ProcessUtil.getAllChildren(p1Handle); + long count = allChildren.stream() + .filter(ph -> !processes.containsKey(ph)) + .count(); + if (count > 0) { + allChildren.stream() + .filter(ph -> !processes.containsKey(ph)) + .forEach(ph1 -> ProcessUtil.printProcess(ph1, "Extra process: ")); + ProcessUtil.logTaskList(); + Assert.assertEquals(0, count, "Extra processes in allChildren"); + } Assert.assertEquals(getChildren(p1Handle).size(), factor, "expected direct children"); - long count = getAllChildren(p1Handle).size(); + count = getAllChildren(p1Handle).size(); long totalChildren = factor * factor * factor + factor * factor + factor; Assert.assertTrue(count >= totalChildren, "expected at least " + totalChildren + ", actual: " + count); @@ -397,6 +449,12 @@ public class TreeTest extends ProcessUtil { if (p1 != null) { p1.destroyForcibly(); } + processes.forEach((p, parent) -> { + if (p.isAlive()) { + ProcessUtil.printProcess(p, "Process Cleanup: "); + p.destroyForcibly(); + } + }); } } From 3449e253b899ed5298e65b6c4c60891565f2b3eb Mon Sep 17 00:00:00 2001 From: Magnus Ihse Bursie Date: Tue, 3 Nov 2015 17:48:19 +0100 Subject: [PATCH 31/43] 8141261: Clean up building of demos Reviewed-by: erikj, tbell --- jdk/make/CompileDemos.gmk | 695 +++++++++++++++++++++----------------- 1 file changed, 379 insertions(+), 316 deletions(-) diff --git a/jdk/make/CompileDemos.gmk b/jdk/make/CompileDemos.gmk index 03b84fb725d..258b3425707 100644 --- a/jdk/make/CompileDemos.gmk +++ b/jdk/make/CompileDemos.gmk @@ -23,6 +23,10 @@ # questions. # +################################################################################ +# Build demos for the JDK into $(SUPPORT_OUTPUTDIR)/demos/image. +################################################################################ + default: all include $(SPEC) @@ -31,428 +35,487 @@ include JavaCompilation.gmk include NativeCompilation.gmk include SetupJavaCompilers.gmk include TextFileProcessing.gmk +include ZipArchive.gmk # Prepare the find cache. $(eval $(call FillCacheFind, $(JDK_TOPDIR)/src)) # Append demo goals to this variable. -BUILD_DEMOS = +TARGETS = # The demo structure and contents should really be cleaned up. # Now every other demo has its own quirks where to put the # READMEs and other files. DEMO_SHARE_SRC := $(JDK_TOPDIR)/src/demo/share -DEMO_CLOSED_SHARE_SRC := $(JDK_TOPDIR)/src/closed/demo/share -DEMO_SOLARIS_SRC := $(JDK_TOPDIR)/src/demo/solaris -DEMO_OS_TYPE_SRC := $(JDK_TOPDIR)/src/demo/$(OPENJDK_TARGET_OS_TYPE) GLOBAL_VERSION_INFO_RESOURCE := $(JDK_TOPDIR)/src/java.base/windows/native/common/version.rc -################################################################################################## +DEMO_MANIFEST := $(SUPPORT_OUTPUTDIR)/demos/java-main-manifest.mf -# This rule will be depended on due to the MANIFEST line +# This rule will be depended on due to the MANIFEST line in SetupBuildDemo +# and SetupBuildJvmtiDemo. $(eval $(call SetupTextFileProcessing, BUILD_JAVA_MANIFEST, \ SOURCE_FILES := $(JDK_TOPDIR)/make/data/mainmanifest/manifest.mf, \ - OUTPUT_FILE := $(SUPPORT_OUTPUTDIR)/demo/java-main-manifest.mf, \ + OUTPUT_FILE := $(DEMO_MANIFEST), \ REPLACEMENTS := \ @@RELEASE@@ => $(RELEASE) ; \ @@COMPANY_NAME@@ => $(COMPANY_NAME) , \ )) -define SetupAppletDemo - $$(eval $$(call SetupJavaCompilation,BUILD_DEMO_APPLET_$1, \ +################################################################################ +# Build applet demos. + +# Setup make rules for building a demo applet. +# +# Parameter 1 is the name of the rule. This name is used as variable prefix, +# and the targets generated are listed in a variable by that name. It is also +# used to locate the name of the applet subdir, and to determine the name +# of the output directory. +# +# Remaining parameters are named arguments. These include: +# SRC_DIR Alternative source directory to use for the demos. +# DISABLE_SJAVAC Passed to SetupJavaCompilation + +SetupBuildAppletDemo = $(NamedParamsMacroTemplate) +define SetupBuildAppletDemoBody + ifeq ($$($1_SRC_DIR), ) + $1_SRC_DIR := $(DEMO_SHARE_SRC)/applets + endif + + $$(eval $$(call SetupJavaCompilation, BUILD_DEMO_APPLET_$1, \ SETUP := GENERATE_USINGJDKBYTECODE, \ - SRC := $(JDK_TOPDIR)/src/$3demo/share/applets/$1, \ - BIN := $(SUPPORT_OUTPUTDIR)/demo/image/applets/$1, \ + SRC := $$($1_SRC_DIR)/$1, \ + BIN := $(SUPPORT_OUTPUTDIR)/demos/image/applets/$1, \ COPY := .html .java .xyz .obj .au .gif, \ - DISABLE_SJAVAC := $2)) - BUILD_DEMOS += $$(BUILD_DEMO_APPLET_$1) + DISABLE_SJAVAC := $$($1_DISABLE_SJAVAC), \ + )) + + $1 := $$(BUILD_DEMO_APPLET_$1) + + TARGETS += $$($1) endef ifneq ($(OPENJDK_TARGET_OS), solaris) - $(eval $(call SetupAppletDemo,ArcTest)) - $(eval $(call SetupAppletDemo,BarChart)) - $(eval $(call SetupAppletDemo,Blink)) - $(eval $(call SetupAppletDemo,CardTest)) - $(eval $(call SetupAppletDemo,Clock)) - $(eval $(call SetupAppletDemo,DitherTest)) - $(eval $(call SetupAppletDemo,DrawTest)) - $(eval $(call SetupAppletDemo,Fractal)) - $(eval $(call SetupAppletDemo,GraphicsTest)) - $(eval $(call SetupAppletDemo,NervousText)) - $(eval $(call SetupAppletDemo,SimpleGraph)) - $(eval $(call SetupAppletDemo,SortDemo)) - $(eval $(call SetupAppletDemo,SpreadSheet)) - - ifndef OPENJDK - $(eval $(call SetupAppletDemo,Animator,,closed/)) - $(eval $(call SetupAppletDemo,GraphLayout,true,closed/)) - $(eval $(call SetupAppletDemo,JumpingBox,,closed/)) - $(eval $(call SetupAppletDemo,TicTacToe,,closed/)) - endif + $(eval $(call SetupBuildAppletDemo, ArcTest)) + $(eval $(call SetupBuildAppletDemo, BarChart)) + $(eval $(call SetupBuildAppletDemo, Blink)) + $(eval $(call SetupBuildAppletDemo, CardTest)) + $(eval $(call SetupBuildAppletDemo, Clock)) + $(eval $(call SetupBuildAppletDemo, DitherTest)) + $(eval $(call SetupBuildAppletDemo, DrawTest)) + $(eval $(call SetupBuildAppletDemo, Fractal)) + $(eval $(call SetupBuildAppletDemo, GraphicsTest)) + $(eval $(call SetupBuildAppletDemo, NervousText)) + $(eval $(call SetupBuildAppletDemo, SimpleGraph)) + $(eval $(call SetupBuildAppletDemo, SortDemo)) + $(eval $(call SetupBuildAppletDemo, SpreadSheet)) endif -################################################################################################## +################################################################################ +# Build normal demos. -PATTERNS_TO_COPY = .html .txt .properties .js .gif .jpg .theme .data .opt README .c .h .png .ttf .xyz .obj +COPY_TO_JAR := .html .txt .properties .js .gif .jpg .theme .data .opt .c .h \ + .png .ttf .xyz .obj README COPYRIGHT -define SetupDemo - # Param 1 = Name of the demo - # Param 2 = Subdirectory of the demo below the demo directory. - # Param 3 = Additional javac flags. - # Param 4 = The main class for the jar. - # Param 5 = Additional source directory. - # Param 6 = Extra dir below $(JDK_TOPDIR)/src (closed) - # Param 7 = List of files to copy - # Param 8 = Base name of jar file. Defaults to $1 - # Param 9 = Exclude list - # Param 10 = Extra copy patterns - # Param 11 = Extra manifest attribute - # Param 12 = Suffix for compiler setup name +COPY_TO_IMAGE := *.html *.txt *.png *.xml README* - $1_SRC_BASE := $(JDK_TOPDIR)/src/$6demo/share/$2/$1 - # In some demos the source is found in a subdir called src. - $1_MAIN_SRC := $$(wildcard $$($1_SRC_BASE)/src) - ifeq ($$($1_MAIN_SRC), ) +# Setup make rules for building a demo. +# +# Parameter 1 is the name of the rule. This name is used as variable prefix, +# and the targets generated are listed in a variable by that name. +# +# Remaining parameters are named arguments. These include: +# DEMO_SUBDIR The name of the subdir of the demo, below the demo top dir. +# EXTRA_SRC_DIR Additional source directory. +# SRC_SUB_DIR Optional subdir to locate source code in +# SRC_DIR Alternative source directory to use for the demos. +# EXCLUDE_FILES Exclude file list +# JAR_NAME Base name of jar file. Defaults to $1. +# MAIN_CLASS The main class for the jar. Defaults to $1. +# EXTRA_COPY_TO_JAR Additional files to copy to jar (as patterns) +# EXTRA_COPY_TO_IMAGE Additional files to copy to images (as wildcards) +# EXTRA_MANIFEST_ATTR Extra manifest attribute +# SKIP_COMPILATION Skip Java compilation iff true +# DISABLE_SJAVAC Passed to SetupJavaCompilation +SetupBuildDemo = $(NamedParamsMacroTemplate) +define SetupBuildDemoBody + ifeq ($$($1_SRC_DIR), ) + $1_SRC_DIR := $(DEMO_SHARE_SRC) + endif + + $1_SRC_BASE := $$($1_SRC_DIR)/$$($1_DEMO_SUBDIR)/$1 + + # In some demos the source is found in a subdir + ifneq ($$($1_SRC_SUB_DIR), ) + $1_MAIN_SRC := $$($1_SRC_BASE)/$$($1_SRC_SUB_DIR) + else + # for allmost all $1_MAIN_SRC := $$($1_SRC_BASE) endif - ifneq ($8, ) - $1_JARFILE := $8.jar - else - $1_JARFILE := $1.jar + # Default is to use demo name as jar file name. + ifeq ($$($1_JAR_NAME), ) + $1_JAR_NAME := $1 endif - ifeq ($(findstring $1,Laffy SwingSet3), ) - $$(eval $$(call SetupJavaCompilation,BUILD_DEMO_$1, \ + # Default is to use demo name as jar main class. + ifeq ($$($1_MAIN_CLASS), ) + $1_MAIN_CLASS := $1 + else ifeq ($$($1_MAIN_CLASS), NONE) + $1_MAIN_CLASS := + $1_EXTRA_MANIFEST_ATTR += Main-Class: \n + endif + + ifneq ($$($1_SKIP_COMPILATION), true) + $$(eval $$(call SetupJavaCompilation, BUILD_DEMO_$1, \ SETUP := GENERATE_USINGJDKBYTECODE, \ - ADD_JAVAC_FLAGS := $3, \ - SRC := $$($1_MAIN_SRC) $5, \ - BIN := $(SUPPORT_OUTPUTDIR)/demo/classes/$2/$1, \ - COPY := $(PATTERNS_TO_COPY) $(10), \ - JAR := $(SUPPORT_OUTPUTDIR)/demo/image/$2/$1/$$($1_JARFILE), \ - JARMAIN := $4, \ - MANIFEST := $(SUPPORT_OUTPUTDIR)/demo/java-main-manifest.mf, \ - EXTRA_MANIFEST_ATTR := $(11), \ - SRCZIP := $(SUPPORT_OUTPUTDIR)/demo/image/$2/$1/src.zip, \ - EXCLUDE_FILES := $9, \ - DISABLE_SJAVAC := $(12))) + SRC := $$($1_MAIN_SRC) $$($1_EXTRA_SRC_DIR), \ + BIN := $(SUPPORT_OUTPUTDIR)/demos/classes/$$($1_DEMO_SUBDIR)/$1, \ + COPY := $(COPY_TO_JAR) $$($1_EXTRA_COPY_TO_JAR), \ + JAR := $(SUPPORT_OUTPUTDIR)/demos/image/$$($1_DEMO_SUBDIR)/$1/$$($1_JAR_NAME).jar, \ + JARMAIN := $$($1_MAIN_CLASS), \ + MANIFEST := $(DEMO_MANIFEST), \ + EXTRA_MANIFEST_ATTR := $$($1_EXTRA_MANIFEST_ATTR), \ + SRCZIP := $(SUPPORT_OUTPUTDIR)/demos/image/$$($1_DEMO_SUBDIR)/$1/src.zip, \ + EXCLUDE_FILES := $$($1_EXCLUDE_FILES), \ + DISABLE_SJAVAC := $$($1_DISABLE_SJAVAC), \ + )) - BUILD_DEMOS += $$(BUILD_DEMO_$1) \ - $(SUPPORT_OUTPUTDIR)/demo/image/$2/$1/$$($1_JARFILE) \ - $(SUPPORT_OUTPUTDIR)/demo/image/$2/$1/src.zip + $1 += $$(BUILD_DEMO_$1) endif - # Copy files. - $1_COPY_TARGETS := $$(patsubst $$($1_SRC_BASE)/%, \ - $(SUPPORT_OUTPUTDIR)/demo/image/$2/$1/%, \ - $$(wildcard $$(addprefix $$($1_SRC_BASE)/, $7))) - ifneq ($7, ) - $(SUPPORT_OUTPUTDIR)/demo/image/$2/$1/%: $$($1_SRC_BASE)/% - $$(call install-file) - $(CHMOD) -f ug+w $$@ + # Copy files. Sort is needed to remove duplicates. + $1_COPY_FILES := $$(sort $$(wildcard $$(addprefix $$($1_SRC_BASE)/, \ + $(COPY_TO_IMAGE) $$($1_EXTRA_COPY_TO_IMAGE)))) + $$(eval $$(call SetupCopyFiles, COPY_DEMO_$1, \ + SRC := $$($1_SRC_BASE), \ + DEST := $(SUPPORT_OUTPUTDIR)/demos/image/$$($1_DEMO_SUBDIR)/$1, \ + FILES := $$($1_COPY_FILES), \ + )) - BUILD_DEMOS += $$($1_COPY_TARGETS) - endif + $1 += $$(COPY_DEMO_$1) + TARGETS += $$($1) endef -$(eval $(call SetupDemo,CodePointIM,jfc,,CodePointIM,,,*.html)) -$(SUPPORT_OUTPUTDIR)/demo/image/jfc/CodePointIM/_the.services: \ - $(SUPPORT_OUTPUTDIR)/demo/image/jfc/CodePointIM/CodePointIM.jar \ - $(DEMO_SHARE_SRC)/jfc/CodePointIM/java.awt.im.spi.InputMethodDescriptor - (cd $(SUPPORT_OUTPUTDIR)/demo/image/jfc/CodePointIM && \ - $(MKDIR) -p _the.tmp/META-INF/services && \ - $(CP) $(DEMO_SHARE_SRC)/jfc/CodePointIM/java.awt.im.spi.InputMethodDescriptor _the.tmp/META-INF/services && \ - cd ./_the.tmp && \ - $(JAR) uf $(SUPPORT_OUTPUTDIR)/demo/image/jfc/CodePointIM/CodePointIM.jar META-INF/services/java.awt.im.spi.InputMethodDescriptor && \ - cd ./META-INF/services && \ - $(JAR) uf $(SUPPORT_OUTPUTDIR)/demo/image/jfc/CodePointIM/CodePointIM.jar java.awt.im.spi.InputMethodDescriptor) - $(RM) -r $(SUPPORT_OUTPUTDIR)/demo/image/jfc/CodePointIM/_the.tmp - $(TOUCH) $@ +CODEPOINT_SERVICE := java.awt.im.spi.InputMethodDescriptor +CODEPOINT_METAINF_SERVICE_FILE := \ + $(SUPPORT_OUTPUTDIR)/demos/classes/jfc/CodePointIM/META-INF/services/$(CODEPOINT_SERVICE) -BUILD_DEMOS += $(SUPPORT_OUTPUTDIR)/demo/image/jfc/CodePointIM/_the.services +$(eval $(call SetupBuildDemo, CodePointIM, \ + DEMO_SUBDIR := jfc, \ + EXTRA_COPY_TO_JAR := $(CODEPOINT_SERVICE), \ +)) + +# We also need to copy the CODEPOINT_SERVICE file to the META-INF/services +# location, and make sure the jar depends on that file to get it included. +$(CODEPOINT_METAINF_SERVICE_FILE): $(DEMO_SHARE_SRC)/jfc/CodePointIM/$(CODEPOINT_SERVICE) + $(call install-file) + +$(BUILD_DEMO_CodePointIM_JAR): $(CODEPOINT_METAINF_SERVICE_FILE) ifneq ($(OPENJDK_TARGET_OS), solaris) - $(eval $(call SetupDemo,MoleculeViewer,applets,,XYZChemModel,,,example*.html *.java)) - $(eval $(call SetupDemo,WireFrame,applets,,ThreeD,,,example*.html *.java)) - $(eval $(call SetupDemo,SwingApplet,jfc,,SwingApplet,,,README* *.html)) -endif -$(eval $(call SetupDemo,FileChooserDemo,jfc,,FileChooserDemo,,,README*)) -$(eval $(call SetupDemo,Font2DTest,jfc,,Font2DTest,,,*.html *.txt)) -$(eval $(call SetupDemo,Metalworks,jfc,,Metalworks,,,README*)) -$(eval $(call SetupDemo,Notepad,jfc,,Notepad,,,README*)) -$(eval $(call SetupDemo,SampleTree,jfc,,SampleTree,,,README*)) -$(eval $(call SetupDemo,TableExample,jfc,,TableExample,,,README*)) -$(eval $(call SetupDemo,TransparentRuler,jfc,,transparentruler.Ruler,,,README*)) -$(eval $(call SetupDemo,jconsole-plugin,scripting,,,,,*.xml *.txt,,,,Main-Class: \n)) -$(eval $(call SetupDemo,FullThreadDump,management,,FullThreadDump,,,README*)) -$(eval $(call SetupDemo,JTop,management,,JTop,,,README*)) -$(eval $(call SetupDemo,MemoryMonitor,management,,MemoryMonitor,,,README*)) -$(eval $(call SetupDemo,VerboseGC,management,,VerboseGC,,,README*)) + $(eval $(call SetupBuildDemo, MoleculeViewer, \ + DEMO_SUBDIR := applets, \ + MAIN_CLASS := XYZChemModel, \ + EXTRA_COPY_TO_IMAGE := *.java, \ + )) -ifndef OPENJDK - $(eval $(call SetupDemo,Laffy,jfc,,,,closed/,*)) - $(eval $(call SetupDemo,SwingSet3,jfc,,,,closed/,*)) + $(eval $(call SetupBuildDemo, WireFrame, \ + DEMO_SUBDIR := applets, \ + MAIN_CLASS := ThreeD, \ + EXTRA_COPY_TO_IMAGE := *.java, \ + )) - $(eval $(call SetupDemo,Java2D,jfc,,java2d.Java2Demo,,closed/,*.html README*,Java2Demo)) - $(eval $(call SetupDemo,Stylepad,jfc,,Stylepad, \ - $(DEMO_SHARE_SRC)/jfc/Notepad,closed/,*.txt,,$(DEMO_SHARE_SRC)/jfc/Notepad/README.txt)) - $(eval $(call SetupDemo,SwingSet2,jfc,,SwingSet2,,closed/,README* *.html,,,.java COPYRIGHT, \ - SplashScreen-Image: resources/images/splash.png,true)) - - BUILD_DEMOS += $(patsubst $(DEMO_CLOSED_SHARE_SRC)/nbproject/%, \ - $(SUPPORT_OUTPUTDIR)/demo/image/nbproject/%, \ - $(call CacheFind, $(DEMO_CLOSED_SHARE_SRC)/nbproject)) - - $(SUPPORT_OUTPUTDIR)/demo/image/nbproject/%: $(DEMO_CLOSED_SHARE_SRC)/nbproject/% - $(call install-file) - $(CHMOD) -f ug+w $@ + $(eval $(call SetupBuildDemo, SwingApplet, \ + DEMO_SUBDIR := jfc, \ + )) endif -################################################################################################## +$(eval $(call SetupBuildDemo, FileChooserDemo, \ + DEMO_SUBDIR := jfc, \ +)) -# In the old makefiles, j2dbench was not compiled. -#$(eval $(call SetupDemo,J2DBench, java2d, /src, , j2dbench/J2DBench)) +$(eval $(call SetupBuildDemo, Font2DTest, \ + DEMO_SUBDIR := jfc, \ +)) -# JVMTI demos are a bit strange and share some files, but be careful the -# shared files are just the *.c and *.h files, not the README or sample -# makefiles. So we always exclude the README.txt and sample.makefile.txt -# from the extra sources. -define SetupJVMTIDemo - # Param 1 = Name of the demo - # Param 2 = add these directories to the includes, default is agent_util - # Param 3 = extra CFLAGS - # Param 4 = C or C++ (defaults to C) - # Param 5 = libs for unix - # Param 6 = libs for windows - # Param 7 = libs for solaris - # Param 8 = libs for linux - # Param 9 = extra directories with required sources - # Param 10 = DISABLED_WARNINGS_gcc - # Param 11 = DISABLED_WARNINGS_microsoft - # Param 12 = DISABLED_WARNINGS_clang - BUILD_DEMO_JVMTI_$1_EXTRA_SRC := \ - $$(wildcard $(DEMO_OS_TYPE_SRC)/jvmti/$1) \ - $$(wildcard $$(addprefix $(DEMO_SHARE_SRC)/jvmti/, $2)) \ - $9 - BUILD_DEMO_JVMTI_$1_EXTRA_SRC_EXCLUDE := \ - $$(wildcard $$(patsubst %, $(DEMO_SHARE_SRC)/jvmti/%/README.txt, $2)) \ - $$(wildcard $$(patsubst %, $(DEMO_SHARE_SRC)/jvmti/%/sample.makefile.txt, $2)) - BUILD_DEMO_JVMTI_$1_EXTRA_INC := $$(addprefix -I, $$(BUILD_DEMO_JVMTI_$1_EXTRA_SRC)) - ifeq (C++, $4) - BUILD_DEMO_JVMTI_$1_TOOLCHAIN := TOOLCHAIN_LINK_CXX - $1_EXTRA_CXX := $(LDFLAGS_CXX_JDK) $(LIBCXX) +$(eval $(call SetupBuildDemo, Metalworks, \ + DEMO_SUBDIR := jfc, \ +)) + +$(eval $(call SetupBuildDemo, Notepad, \ + DEMO_SUBDIR := jfc, \ +)) + +$(eval $(call SetupBuildDemo, SampleTree, \ + DEMO_SUBDIR := jfc, \ +)) + +$(eval $(call SetupBuildDemo, TableExample, \ + DEMO_SUBDIR := jfc, \ +)) + +$(eval $(call SetupBuildDemo, TransparentRuler, \ + DEMO_SUBDIR := jfc, \ + MAIN_CLASS := transparentruler.Ruler, \ +)) + +$(eval $(call SetupBuildDemo, jconsole-plugin, \ + DEMO_SUBDIR := scripting, \ + SRC_SUB_DIR := src, \ + MAIN_CLASS := NONE, \ +)) + +$(eval $(call SetupBuildDemo, FullThreadDump, \ + DEMO_SUBDIR := management, \ +)) + +$(eval $(call SetupBuildDemo, JTop, \ + DEMO_SUBDIR := management, \ +)) + +$(eval $(call SetupBuildDemo, MemoryMonitor, \ + DEMO_SUBDIR := management, \ +)) + +$(eval $(call SetupBuildDemo, VerboseGC, \ + DEMO_SUBDIR := management, \ +)) + +################################################################################ +# Build JVMTI demos. + +# Setup make rules for building a JVMTI demo. +# +# Parameter 1 is the name of the rule. This name is used as variable prefix, +# and the targets generated are listed in a variable by that name. +# +# Remaining parameters are named arguments. These include: +# EXTRA_SRC_SUBDIR Also include these subdirectories +# TOOLCHAIN Optionally specify toolchain to use +SetupBuildJvmtiDemo = $(NamedParamsMacroTemplate) +define SetupBuildJvmtiDemoBody + $1_SRC := \ + $(DEMO_SHARE_SRC)/jvmti/$1 \ + $$(wildcard $$(addprefix $(DEMO_SHARE_SRC)/jvmti/, \ + agent_util $$($1_EXTRA_SRC_SUBDIR))) + + ### Build the native lib + $1_CFLAGS_INCLUDE := $$(addprefix -I, $$($1_SRC)) + + $1_CXXFLAGS := $$($1_CFLAGS_INCLUDE) $(CXXFLAGS_JDKLIB) $(CXXFLAGS_DEBUG_SYMBOLS) + + ifeq ($$($1_TOOLCHAIN), TOOLCHAIN_LINK_CXX) + # For C++, we also need some special treatment. + $1_LDFLAGS := $(LDFLAGS_CXX_JDK) + $1_LIBS := $(LIBCXX) + + ifeq ($(OPENJDK_TARGET_CPU_ARCH), sparc) + $1_CXXFLAGS := $$(filter-out -xregs=no%appl, $$($1_CXXFLAGS)) + endif endif - $1_CXXFLAGS := $(CXXFLAGS_JDKLIB) -I$(DEMO_SHARE_SRC)/jvmti/$1 \ - $$(BUILD_DEMO_JVMTI_$1_EXTRA_INC) $3 \ - $(CXXFLAGS_DEBUG_SYMBOLS) - ifeq ($1-$(OPENJDK_TARGET_CPU_ARCH), waiters-sparc) - $1_FILTER := -xregs=no%appl - $1_CXXFLAGS := $$(filter-out $$($1_FILTER), $$($1_CXXFLAGS)) - endif - - # Workaround for CFLAGS_JDKLIB containing ',' on solaris. If this is added as 'CFLAGS' to the - # eval call below, the comma gets expanded too early. - BUILD_DEMO_JVMTI_$1_CFLAGS := $(CFLAGS_JDKLIB) $(CFLAGS_DEBUG_SYMBOLS) \ - -I$(DEMO_SHARE_SRC)/jvmti/$1 $$(BUILD_DEMO_JVMTI_$1_EXTRA_INC) $3 - # Remove the -incremental:no setting to get .ilk-files like in the old build. - $$(eval $$(call SetupNativeCompilation,BUILD_DEMO_JVMTI_$1, \ - SRC := $(DEMO_SHARE_SRC)/jvmti/$1 $$(BUILD_DEMO_JVMTI_$1_EXTRA_SRC), \ - TOOLCHAIN := $$(BUILD_DEMO_JVMTI_$1_TOOLCHAIN), \ + $$(eval $$(call SetupNativeCompilation, BUILD_DEMO_JVMTI_NATIVE_$1, \ + SRC := $$($1_SRC), \ + TOOLCHAIN := $$($1_TOOLCHAIN), \ OPTIMIZATION := LOW, \ + CFLAGS := $$($1_CFLAGS_INCLUDE) $$(CFLAGS_JDKLIB) $$(CFLAGS_DEBUG_SYMBOLS), \ CXXFLAGS := $$($1_CXXFLAGS), \ - DISABLED_WARNINGS_gcc := $(10), \ - DISABLED_WARNINGS_clang := $(12), \ - DISABLED_WARNINGS_microsoft := $(11), \ - LDFLAGS := $(filter-out -incremental:no -opt:ref, $(LDFLAGS_JDKLIB)), \ + LDFLAGS := $(filter-out -incremental:no -opt:ref, $(LDFLAGS_JDKLIB)) \ + $$($1_LDFLAGS), \ LDFLAGS_macosx := $(call SET_EXECUTABLE_ORIGIN), \ - LIBS := $$($1_EXTRA_CXX), \ - LIBS_unix := $5, \ - LIBS_linux := $8, \ - LIBS_solaris := $7 -lc, \ - LIBS_windows := $6, \ + LIBS := $$($1_LIBS), \ + LIBS_solaris := -lc, \ VERSIONINFO_RESOURCE := $(GLOBAL_VERSION_INFO_RESOURCE), \ RC_FLAGS := $$(RC_FLAGS) \ -D "JDK_FNAME=$1.dll" \ -D "JDK_INTERNAL_NAME=$1" \ -D "JDK_FTYPE=0x2L", \ - OBJECT_DIR := $(SUPPORT_OUTPUTDIR)/demo/native/jvmti/$1, \ - OUTPUT_DIR := $(SUPPORT_OUTPUTDIR)/demo/image/jvmti/$1/lib, \ - LIBRARY := $1)) + OBJECT_DIR := $(SUPPORT_OUTPUTDIR)/demos/native/jvmti/$1, \ + OUTPUT_DIR := $(SUPPORT_OUTPUTDIR)/demos/image/jvmti/$1/lib, \ + LIBRARY := $1, \ + )) - $$(eval $$(call SetupZipArchive,BUILD_DEMO_JVMTI_SRC_$1, \ - SRC := $(DEMO_SHARE_SRC)/jvmti/$1 $$(BUILD_DEMO_JVMTI_$1_EXTRA_SRC), \ - EXCLUDE_FILES := $$(BUILD_DEMO_JVMTI_$1_EXTRA_SRC_EXCLUDE), \ - ZIP := $(SUPPORT_OUTPUTDIR)/demo/image/jvmti/$1/src.zip)) + $1 += $$(BUILD_DEMO_JVMTI_NATIVE_$1) - $(SUPPORT_OUTPUTDIR)/demo/image/jvmti/$1/README.txt: $(DEMO_SHARE_SRC)/jvmti/$1/README.txt + ### Build the jar, if we have java sources + ifneq ($$(wildcard $(DEMO_SHARE_SRC)/jvmti/$1/*.java), ) + $$(eval $$(call SetupJavaCompilation, BUILD_DEMO_JVMTI_JAVA_$1, \ + SETUP := GENERATE_USINGJDKBYTECODE, \ + SRC := $(DEMO_SHARE_SRC)/jvmti/$1, \ + BIN := $(SUPPORT_OUTPUTDIR)/demos/classes/jvmti/$1, \ + COPY := $(COPY_TO_JAR), \ + JAR := $(SUPPORT_OUTPUTDIR)/demos/image/jvmti/$1/$1.jar, \ + EXTRA_MANIFEST_ATTR := Main-Class: \n, \ + MANIFEST := $(DEMO_MANIFEST), \ + )) + + $1 += $$(BUILD_DEMO_JVMTI_JAVA_$1_JAR) + endif + + ### Build the source zip + $1_EXCLUDE_FILES := \ + $$(wildcard $$(patsubst %, $(DEMO_SHARE_SRC)/jvmti/%/README.txt, \ + agent_util $$($1_EXTRA_SRC_SUBDIR))) \ + $$(wildcard $$(patsubst %, $(DEMO_SHARE_SRC)/jvmti/%/sample.makefile.txt, \ + agent_util $$($1_EXTRA_SRC_SUBDIR))) + + $$(eval $$(call SetupZipArchive, BUILD_DEMO_JVMTI_SRC_$1, \ + SRC := $$($1_SRC), \ + EXCLUDE_FILES := $$($1_EXCLUDE_FILES), \ + ZIP := $(SUPPORT_OUTPUTDIR)/demos/image/jvmti/$1/src.zip, \ + )) + + $1 += $$(BUILD_DEMO_JVMTI_SRC_$1) + + # Copy files to image + $(SUPPORT_OUTPUTDIR)/demos/image/jvmti/$1/README.txt: $(DEMO_SHARE_SRC)/jvmti/$1/README.txt $$(call install-file) $(CHMOD) -f ug+w $$@ - ifneq (, $$(wildcard $(DEMO_SHARE_SRC)/jvmti/$1/*.java)) - $$(eval $$(call SetupJavaCompilation,BUILD_DEMO_JVMTI_$1_JAVA, \ - SETUP := GENERATE_USINGJDKBYTECODE, \ - SRC := $(DEMO_SHARE_SRC)/jvmti/$1, \ - BIN := $(SUPPORT_OUTPUTDIR)/demo/classes/jvmti/$1, \ - COPY := $(PATTERNS_TO_COPY), \ - JAR := $(SUPPORT_OUTPUTDIR)/demo/image/jvmti/$1/$1.jar, \ - EXTRA_MANIFEST_ATTR := Main-Class: \n, \ - MANIFEST := $(SUPPORT_OUTPUTDIR)/demo/java-main-manifest.mf)) - - BUILD_DEMOS += $(SUPPORT_OUTPUTDIR)/demo/image/jvmti/$1/$1.jar - endif - - BUILD_DEMOS += $$(BUILD_DEMO_JVMTI_$1) \ - $(SUPPORT_OUTPUTDIR)/demo/image/jvmti/$1/src.zip \ - $(SUPPORT_OUTPUTDIR)/demo/image/jvmti/$1/README.txt + $1 += $(SUPPORT_OUTPUTDIR)/demos/image/jvmti/$1/README.txt ifeq ($(OPENJDK_TARGET_OS), windows) - # These files normally end up in OBJECT_DIR but for demos they - # are supposed to be included in the distro. - $(SUPPORT_OUTPUTDIR)/demo/image/jvmti/$1/lib/$1.lib: $$(BUILD_DEMO_JVMTI_$1) - $(CP) $(SUPPORT_OUTPUTDIR)/demo/native/jvmti/$1/$1.lib $$@ + # These lib and exp files normally end up in OBJECT_DIR but for demos they + # are supposed to be included in the distro. Since they are created as + # a side-effect of the library compilation, make does not know about them. + $1_SUPPORT_OUTPUTDIR := $(SUPPORT_OUTPUTDIR)/demos/native/jvmti/$1 + $1_IMAGE_OUTPUTDIR := $(SUPPORT_OUTPUTDIR)/demos/image/jvmti/$1/lib - $(SUPPORT_OUTPUTDIR)/demo/image/jvmti/$1/lib/$1.exp: $$(BUILD_DEMO_JVMTI_$1) - $(CP) $(SUPPORT_OUTPUTDIR)/demo/native/jvmti/$1/$1.exp $$@ + $$($1_SUPPORT_OUTPUTDIR)/$1.lib: $$(BUILD_DEMO_JVMTI_NATIVE_$1) - BUILD_DEMOS += $(SUPPORT_OUTPUTDIR)/demo/image/jvmti/$1/lib/$1.lib \ - $(SUPPORT_OUTPUTDIR)/demo/image/jvmti/$1/lib/$1.exp + $$($1_SUPPORT_OUTPUTDIR)/$1.exp: $$(BUILD_DEMO_JVMTI_NATIVE_$1) + + $$($1_IMAGE_OUTPUTDIR)/$1.lib: $$($1_SUPPORT_OUTPUTDIR)/$1.lib + $$(call install-file) + + $$($1_IMAGE_OUTPUTDIR)/$1.exp: $$($1_SUPPORT_OUTPUTDIR)/$1.exp + $$(call install-file) + + $1 += $$($1_IMAGE_OUTPUTDIR)/$1.lib $$($1_IMAGE_OUTPUTDIR)/$1.exp endif + + TARGETS += $$($1) endef -$(eval $(call SetupJVMTIDemo,compiledMethodLoad, agent_util)) -$(eval $(call SetupJVMTIDemo,gctest, agent_util)) -$(eval $(call SetupJVMTIDemo,heapTracker, agent_util java_crw_demo)) -$(eval $(call SetupJVMTIDemo,heapViewer, agent_util)) -$(eval $(call SetupJVMTIDemo,minst, agent_util java_crw_demo)) -$(eval $(call SetupJVMTIDemo,mtrace, agent_util java_crw_demo)) -$(eval $(call SetupJVMTIDemo,waiters, agent_util, , C++)) -$(eval $(call SetupJVMTIDemo,versionCheck, agent_util)) +$(eval $(call SetupBuildJvmtiDemo, compiledMethodLoad)) +$(eval $(call SetupBuildJvmtiDemo, gctest)) +$(eval $(call SetupBuildJvmtiDemo, heapViewer)) +$(eval $(call SetupBuildJvmtiDemo, versionCheck)) -################################################################################################## +$(eval $(call SetupBuildJvmtiDemo, heapTracker, \ + EXTRA_SRC_SUBDIR := java_crw_demo, \ +)) -$(SUPPORT_OUTPUTDIR)/demo/image/management/index.html: $(DEMO_SHARE_SRC)/management/index.html - $(call install-file) - $(CHMOD) -f ug+w $@ +$(eval $(call SetupBuildJvmtiDemo, minst, \ + EXTRA_SRC_SUBDIR := java_crw_demo, \ +)) -$(SUPPORT_OUTPUTDIR)/demo/image/jvmti/index.html: $(DEMO_SHARE_SRC)/jvmti/index.html - $(call install-file) - $(CHMOD) -f ug+w $@ +$(eval $(call SetupBuildJvmtiDemo, mtrace, \ + EXTRA_SRC_SUBDIR := java_crw_demo, \ +)) -BUILD_DEMOS += $(SUPPORT_OUTPUTDIR)/demo/image/management/index.html \ - $(SUPPORT_OUTPUTDIR)/demo/image/jvmti/index.html +$(eval $(call SetupBuildJvmtiDemo, waiters, \ + TOOLCHAIN := TOOLCHAIN_LINK_CXX, \ +)) -################################################################################################## - -# The netbeans project files are copied into the demo directory. -ifeq ($(OPENJDK_TARGET_OS), solaris) - BUILD_DEMOS += $(patsubst $(DEMO_SHARE_SRC)/nbproject/%, \ - $(SUPPORT_OUTPUTDIR)/demo/image/nbproject/%, \ - $(filter-out $(DEMO_SHARE_SRC)/nbproject/jfc/SwingApplet%, \ - $(call CacheFind, $(DEMO_SHARE_SRC)/nbproject))) -else - BUILD_DEMOS += $(patsubst $(DEMO_SHARE_SRC)/nbproject/%, \ - $(SUPPORT_OUTPUTDIR)/demo/image/nbproject/%, \ - $(call CacheFind, $(DEMO_SHARE_SRC)/nbproject)) -endif - -$(SUPPORT_OUTPUTDIR)/demo/image/nbproject/%: $(DEMO_SHARE_SRC)/nbproject/% - $(call install-file) - $(CHMOD) -f ug+w $@ - -################################################################################################## - -$(SUPPORT_OUTPUTDIR)/demo/image/README: $(DEMO_SHARE_SRC)/README - $(call install-file) - -BUILD_DEMOS += $(SUPPORT_OUTPUTDIR)/demo/image/README - -################################################################################################## +################################################################################ +# Build the Poller demo (on Solaris only). ifeq ($(OPENJDK_TARGET_OS), solaris) + DEMO_SOLARIS_SRC := $(JDK_TOPDIR)/src/demo/solaris - $(SUPPORT_OUTPUTDIR)/demo/classes/jni/Poller/%: $(DEMO_SOLARIS_SRC)/jni/Poller/% - $(call install-file) - $(CHMOD) -f ug+w $@ - - $(SUPPORT_OUTPUTDIR)/demo/image/jni/Poller/README.txt: $(DEMO_SOLARIS_SRC)/jni/Poller/README.txt - $(call install-file) - $(CHMOD) -f ug+w $@ - - $(SUPPORT_OUTPUTDIR)/demo/image/jni/Poller/Poller.jar: \ - $(SUPPORT_OUTPUTDIR)/demo/classes/jni/Poller/README.txt \ - $(SUPPORT_OUTPUTDIR)/demo/classes/jni/Poller/Poller.c - - $(eval $(call SetupJavaCompilation,BUILD_DEMO_POLLER_JAR, \ + $(eval $(call SetupJavaCompilation, BUILD_DEMO_JAVA_Poller, \ SETUP := GENERATE_USINGJDKBYTECODE, \ SRC := $(DEMO_SOLARIS_SRC)/jni/Poller, \ - BIN := $(SUPPORT_OUTPUTDIR)/demo/classes/jni/Poller, \ - HEADERS := $(SUPPORT_OUTPUTDIR)/demo/classes/jni/Poller, \ - JAR := $(SUPPORT_OUTPUTDIR)/demo/image/jni/Poller/Poller.jar, \ - MANIFEST := $(SUPPORT_OUTPUTDIR)/demo/java-main-manifest.mf, \ - SRCZIP := $(SUPPORT_OUTPUTDIR)/demo/image/jni/Poller/src.zip, \ + BIN := $(SUPPORT_OUTPUTDIR)/demos/classes/jni/Poller, \ + HEADERS := $(SUPPORT_OUTPUTDIR)/demos/classes/jni/Poller, \ + JAR := $(SUPPORT_OUTPUTDIR)/demos/image/jni/Poller/Poller.jar, \ + MANIFEST := $(SUPPORT_OUTPUTDIR)/demos/java-main-manifest.mf, \ + SRCZIP := $(SUPPORT_OUTPUTDIR)/demos/image/jni/Poller/src.zip, \ COPY := README.txt Poller.c, \ - JARMAIN := Client)) + JARMAIN := Client, \ + )) + TARGETS += $(BUILD_DEMO_JAVA_Poller) - - BUILD_DEMOS += $(SUPPORT_OUTPUTDIR)/demo/image/jni/Poller/Poller.jar \ - $(SUPPORT_OUTPUTDIR)/demo/image/jni/Poller/src.zip \ - $(SUPPORT_OUTPUTDIR)/demo/image/jni/Poller/README.txt - - $(eval $(call SetupNativeCompilation,BUILD_LIBPOLLER, \ + $(eval $(call SetupNativeCompilation, BUILD_DEMO_NATIVE_Poller, \ SRC := $(DEMO_SOLARIS_SRC)/jni/Poller, \ OPTIMIZATION := LOW, \ CFLAGS := $(CFLAGS_JDKLIB) \ - -I$(SUPPORT_OUTPUTDIR)/demo/classes/jni/Poller, \ + -I$(SUPPORT_OUTPUTDIR)/demos/classes/jni/Poller, \ LDFLAGS := $(LDFLAGS_JDKLIB), \ LIBS_solaris := -lc, \ - OBJECT_DIR := $(SUPPORT_OUTPUTDIR)/demo/native/jni/Poller, \ - OUTPUT_DIR := $(SUPPORT_OUTPUTDIR)/demo/native, \ - LIBRARY := Poller)) + OBJECT_DIR := $(SUPPORT_OUTPUTDIR)/demos/native/jni/Poller, \ + OUTPUT_DIR := $(SUPPORT_OUTPUTDIR)/demos/native, \ + LIBRARY := Poller, \ + )) - # - # We can only compile native code after jar has been build (since we depend on generated .h files) - # - $(SUPPORT_OUTPUTDIR)/demo/native/jni/Poller/Poller.o: $(SUPPORT_OUTPUTDIR)/demo/image/jni/Poller/Poller.jar + TARGETS += $(BUILD_DEMO_NATIVE_Poller) - $(SUPPORT_OUTPUTDIR)/demo/image/jni/Poller/lib/$(LIBRARY_PREFIX)Poller$(SHARED_LIBRARY_SUFFIX): \ - $(SUPPORT_OUTPUTDIR)/demo/native/$(LIBRARY_PREFIX)Poller$(SHARED_LIBRARY_SUFFIX) + # We can only compile native code after java has been compiled (since we + # depend on generated .h files) + $(SUPPORT_OUTPUTDIR)/demos/native/jni/Poller/Poller.o: \ + $(BUILD_DEMO_JAVA_POLLER_COMPILE_TARGETS) + + # Copy to image + $(SUPPORT_OUTPUTDIR)/demos/image/jni/Poller/README.txt: \ + $(DEMO_SOLARIS_SRC)/jni/Poller/README.txt + $(call install-file) + $(CHMOD) -f ug+w $@ + + TARGETS += $(SUPPORT_OUTPUTDIR)/demos/image/jni/Poller/README.txt + + $(SUPPORT_OUTPUTDIR)/demos/image/jni/Poller/lib/libPoller.so: \ + $(SUPPORT_OUTPUTDIR)/demos/native/libPoller.so $(call install-file) - BUILD_DEMOS += $(SUPPORT_OUTPUTDIR)/demo/image/jni/Poller/lib/$(LIBRARY_PREFIX)Poller$(SHARED_LIBRARY_SUFFIX) - + TARGETS += $(SUPPORT_OUTPUTDIR)/demos/image/jni/Poller/lib/libPoller.so endif -################################################################################################## +################################################################################ +# Copy html and README files. -ifndef OPENJDK - DB_ZIP_DIR := $(wildcard $(JDK_TOPDIR)/src/closed/db) - DB_DEMO_ZIPFILE := $(wildcard $(DB_ZIP_DIR)/*.zip) +$(SUPPORT_OUTPUTDIR)/demos/image/management/index.html: $(DEMO_SHARE_SRC)/management/index.html + $(call install-file) + $(CHMOD) -f ug+w $@ - $(SUPPORT_OUTPUTDIR)/demo/image/_the.db.unzipped: $(DB_DEMO_ZIPFILE) - $(MKDIR) -p $(@D) - $(RM) -r $(SUPPORT_OUTPUTDIR)/demo/image/db $(SUPPORT_OUTPUTDIR)/demo/image/demo - $(CD) $(SUPPORT_OUTPUTDIR)/demo/image && $(UNZIP) -q -o $< - $(MV) $(SUPPORT_OUTPUTDIR)/demo/image/db-derby-*-bin/demo $(SUPPORT_OUTPUTDIR)/demo/image/db - $(CD) $(SUPPORT_OUTPUTDIR)/demo/image && $(RM) -r db-derby-*-bin - $(TOUCH) $@ +$(SUPPORT_OUTPUTDIR)/demos/image/jvmti/index.html: $(DEMO_SHARE_SRC)/jvmti/index.html + $(call install-file) + $(CHMOD) -f ug+w $@ - # Copy this after the unzip above to avoid race with directory creation and mv command. - $(SUPPORT_OUTPUTDIR)/demo/image/db/README-JDK-DEMOS.html: \ - $(DB_ZIP_DIR)/README-JDK-DEMOS.html \ - | $(SUPPORT_OUTPUTDIR)/demo/image/_the.db.unzipped - $(MKDIR) -p $(@D) - $(CAT) $< | $(SED) "s/XXXX/$(shell cat $(DB_ZIP_DIR)/COPYRIGHTYEAR)/" > $@ +$(SUPPORT_OUTPUTDIR)/demos/image/README: $(DEMO_SHARE_SRC)/README + $(call install-file) - BUILD_DEMOS += $(SUPPORT_OUTPUTDIR)/demo/image/_the.db.unzipped $(SUPPORT_OUTPUTDIR)/demo/image/db/README-JDK-DEMOS.html +TARGETS += $(SUPPORT_OUTPUTDIR)/demos/image/management/index.html \ + $(SUPPORT_OUTPUTDIR)/demos/image/jvmti/index.html \ + $(SUPPORT_OUTPUTDIR)/demos/image/README + +################################################################################ +# Copy netbeans project files. + +$(SUPPORT_OUTPUTDIR)/demos/image/nbproject/%: $(DEMO_SHARE_SRC)/nbproject/% + $(call install-file) + $(CHMOD) -f ug+w $@ + +ifeq ($(OPENJDK_TARGET_OS), solaris) + TARGETS += $(patsubst $(DEMO_SHARE_SRC)/nbproject/%, \ + $(SUPPORT_OUTPUTDIR)/demos/image/nbproject/%, \ + $(filter-out $(DEMO_SHARE_SRC)/nbproject/jfc/SwingApplet%, \ + $(call CacheFind, $(DEMO_SHARE_SRC)/nbproject))) +else + TARGETS += $(patsubst $(DEMO_SHARE_SRC)/nbproject/%, \ + $(SUPPORT_OUTPUTDIR)/demos/image/nbproject/%, \ + $(call CacheFind, $(DEMO_SHARE_SRC)/nbproject)) endif -################################################################################################## +################################################################################ -all: $(BUILD_DEMOS) +# Hook to include the corresponding custom file, if present. +$(eval $(call IncludeCustomExtension, jdk, CompileDemos.gmk)) + +all: $(TARGETS) .PHONY: all From 61aa204f408415fd3b4c99fe16500ac84b557004 Mon Sep 17 00:00:00 2001 From: Magnus Ihse Bursie Date: Tue, 3 Nov 2015 17:54:25 +0100 Subject: [PATCH 32/43] 8141333: Rename SetupArchive to SetupJarArchive Reviewed-by: erikj, tbell --- jdk/make/gendata/GendataPolicyJars.gmk | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/jdk/make/gendata/GendataPolicyJars.gmk b/jdk/make/gendata/GendataPolicyJars.gmk index 256b32e2b58..82e2e424446 100644 --- a/jdk/make/gendata/GendataPolicyJars.gmk +++ b/jdk/make/gendata/GendataPolicyJars.gmk @@ -27,7 +27,7 @@ default: all include $(SPEC) include MakeBase.gmk -include JavaCompilation.gmk +include JarArchive.gmk ################################################################################ @@ -57,7 +57,7 @@ ifndef OPENJDK endif # -# TODO fix so that SetupArchive does not write files into SRCS +# TODO fix so that SetupJarArchive does not write files into SRCS # then we don't need this extra copying # # NOTE: We currently do not place restrictions on our limited export @@ -76,13 +76,14 @@ $(US_EXPORT_POLICY_JAR_TMP)/%: $(US_EXPORT_POLICY_JAR_SRC_DIR)/% US_EXPORT_POLICY_JAR_DEPS := \ $(US_EXPORT_POLICY_JAR_TMP)/default_US_export.policy -$(eval $(call SetupArchive,BUILD_US_EXPORT_POLICY_JAR, \ +$(eval $(call SetupJarArchive, BUILD_US_EXPORT_POLICY_JAR, \ DEPENDENCIES := $(US_EXPORT_POLICY_JAR_DEPS), \ SRCS := $(US_EXPORT_POLICY_JAR_TMP), \ SUFFIXES := .policy, \ JAR := $(US_EXPORT_POLICY_JAR_UNLIMITED), \ EXTRA_MANIFEST_ATTR := Crypto-Strength: unlimited, \ - SKIP_METAINF := true)) + SKIP_METAINF := true, \ +)) $(US_EXPORT_POLICY_JAR_LIMITED): \ $(US_EXPORT_POLICY_JAR_UNLIMITED) @@ -122,7 +123,7 @@ LOCAL_POLICY_JAR_UNLIMITED := \ $(SUPPORT_OUTPUTDIR)/jce/policy/unlimited/local_policy.jar # -# TODO fix so that SetupArchive does not write files into SRCS +# TODO fix so that SetupJarArchive does not write files into SRCS # then we don't need this extra copying # LOCAL_POLICY_JAR_LIMITED_TMP := \ @@ -138,22 +139,24 @@ $(LOCAL_POLICY_JAR_UNLIMITED_TMP)/%: \ $(JDK_TOPDIR)/make/data/cryptopolicy/unlimited/% $(install-file) -$(eval $(call SetupArchive,BUILD_LOCAL_POLICY_JAR_LIMITED, \ +$(eval $(call SetupJarArchive, BUILD_LOCAL_POLICY_JAR_LIMITED, \ DEPENDENCIES := $(LOCAL_POLICY_JAR_LIMITED_TMP)/exempt_local.policy \ $(LOCAL_POLICY_JAR_LIMITED_TMP)/default_local.policy, \ SRCS := $(LOCAL_POLICY_JAR_LIMITED_TMP), \ SUFFIXES := .policy, \ JAR := $(LOCAL_POLICY_JAR_LIMITED), \ EXTRA_MANIFEST_ATTR := Crypto-Strength: limited, \ - SKIP_METAINF := true)) + SKIP_METAINF := true, \ +)) -$(eval $(call SetupArchive,BUILD_LOCAL_POLICY_JAR_UNLIMITED, \ +$(eval $(call SetupJarArchive, BUILD_LOCAL_POLICY_JAR_UNLIMITED, \ DEPENDENCIES := $(LOCAL_POLICY_JAR_UNLIMITED_TMP)/default_local.policy, \ SRCS := $(LOCAL_POLICY_JAR_UNLIMITED_TMP), \ SUFFIXES := .policy, \ JAR := $(LOCAL_POLICY_JAR_UNLIMITED), \ EXTRA_MANIFEST_ATTR := Crypto-Strength: unlimited, \ - SKIP_METAINF := true)) + SKIP_METAINF := true, \ +)) TARGETS += $(LOCAL_POLICY_JAR_LIMITED) $(LOCAL_POLICY_JAR_UNLIMITED) From 03a416db62e77e75ad03869109efbd89017a7e35 Mon Sep 17 00:00:00 2001 From: Joe Darcy Date: Tue, 3 Nov 2015 17:41:38 -0800 Subject: [PATCH 33/43] 8141368: Typo in java/lang/Class/IsEnum.java test Reviewed-by: jjg --- jdk/test/java/lang/Class/IsEnum.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/jdk/test/java/lang/Class/IsEnum.java b/jdk/test/java/lang/Class/IsEnum.java index 355f944e607..55175cf10be 100644 --- a/jdk/test/java/lang/Class/IsEnum.java +++ b/jdk/test/java/lang/Class/IsEnum.java @@ -32,8 +32,8 @@ import java.lang.annotation.*; public class IsEnum { - static int test(Class clazz, boolean expected) { - int status = (clazz.isEnum() == expected)?0:1; + static int test(Class clazz, boolean expected) { + int status = (clazz.isEnum() == expected) ? 0 : 1; if (status == 1) { System.err.println("Unexpected enum status for " + clazz); @@ -41,23 +41,23 @@ public class IsEnum { return status; } - public static void main(String argv[]) { + public static void main(String... argv) { int failures = 0; failures += test(IsEnum.class, false); failures += test(String.class, false); failures += test(Enum.class, false); + failures += test(EnumPoseur.class, false); failures += test(java.math.RoundingMode.class, true); - // Classes in java.lang.annoation + // Classes in java.lang.annotation failures += test(Annotation.class, false); failures += test(ElementType.class, true); failures += test(Retention.class, false); failures += test(RetentionPolicy.class, true); failures += test(Target.class, false); - failures += test(EnumPoseur.class, false); - // Classes for specialized enum constants aren't enum's + // A class for a specialized enum constant isn't itself an enum failures += test(SpecialEnum.class, true); failures += test(SpecialEnum.RED.getClass(), false); failures += test(SpecialEnum.GREEN.getClass(), true); From 01355aa18c0cd88becc19604afd2c638df8f28cb Mon Sep 17 00:00:00 2001 From: Volker Simonis Date: Wed, 4 Nov 2015 12:46:05 +0100 Subject: [PATCH 34/43] 8141290: AIX: fix build after '8140661: Rename LDFLAGS_SUFFIX to LIBS' Reviewed-by: ihse --- jdk/make/lib/Awt2dLibraries.gmk | 4 ++-- jdk/make/lib/Lib-java.instrument.gmk | 5 +++-- jdk/make/lib/Lib-jdk.jdwp.agent.gmk | 5 +++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/jdk/make/lib/Awt2dLibraries.gmk b/jdk/make/lib/Awt2dLibraries.gmk index 7a26bbfc304..ad60e8a8146 100644 --- a/jdk/make/lib/Awt2dLibraries.gmk +++ b/jdk/make/lib/Awt2dLibraries.gmk @@ -890,9 +890,9 @@ ifndef BUILD_HEADLESS_ONLY MAPFILE := $(JDK_TOPDIR)/make/mapfiles/libsplashscreen/mapfile-vers, \ LDFLAGS := $(LIBSPLASHSCREEN_LDFLAGS) $(LDFLAGS_JDKLIB) \ $(call SET_SHARED_LIBRARY_ORIGIN), \ - LIBS := $(LIBSPLASHSCREEN_LIBS) $(LIBZ) \ + LIBS := $(JDKLIB_LIBS) $(LIBSPLASHSCREEN_LIBS) $(LIBZ) \ $(GIFLIB_LIBS) $(LIBJPEG_LIBS) $(PNG_LIBS), \ - LIBS_solaris := -lc, \ + LIBS_aix := -liconv, \ VERSIONINFO_RESOURCE := $(GLOBAL_VERSION_INFO_RESOURCE), \ RC_FLAGS := $(RC_FLAGS) \ -D "JDK_FNAME=splashscreen.dll" \ diff --git a/jdk/make/lib/Lib-java.instrument.gmk b/jdk/make/lib/Lib-java.instrument.gmk index 5b4eacc4703..76ff764ed36 100644 --- a/jdk/make/lib/Lib-java.instrument.gmk +++ b/jdk/make/lib/Lib-java.instrument.gmk @@ -68,10 +68,11 @@ $(eval $(call SetupNativeCompilation,BUILD_LIBINSTRUMENT, \ LDFLAGS_macosx := -Xlinker -all_load $(SUPPORT_OUTPUTDIR)/native/java.base/libjli_static.a, \ LDFLAGS_aix := -L$(SUPPORT_OUTPUTDIR)/native/java.base, \ LDFLAGS_windows := -export:Agent_OnAttach, \ + LIBS := $(JDKLIB_LIBS), \ LIBS_unix := -ljava $(LIBZ), \ LIBS_linux := -ljli $(LIBDL), \ - LIBS_solaris := -ljli $(LIBDL) -lc, \ - LIBS_aix := -ljli_static $(LIBDL),\ + LIBS_solaris := -ljli $(LIBDL), \ + LIBS_aix := -liconv -ljli_static $(LIBDL), \ LIBS_macosx := -liconv -framework Cocoa -framework Security \ -framework ApplicationServices, \ LIBS_windows := $(WIN_JAVA_LIB) advapi32.lib \ diff --git a/jdk/make/lib/Lib-jdk.jdwp.agent.gmk b/jdk/make/lib/Lib-jdk.jdwp.agent.gmk index da2df699f52..504df6dd4d0 100644 --- a/jdk/make/lib/Lib-jdk.jdwp.agent.gmk +++ b/jdk/make/lib/Lib-jdk.jdwp.agent.gmk @@ -84,10 +84,11 @@ $(eval $(call SetupNativeCompilation,BUILD_LIBJDWP, \ MAPFILE := $(JDK_TOPDIR)/make/mapfiles/libjdwp/mapfile-vers, \ LDFLAGS := $(LDFLAGS_JDKLIB) \ $(call SET_SHARED_LIBRARY_ORIGIN), \ + LIBS := $(JDKLIB_LIBS), \ LIBS_linux := $(LIBDL), \ - LIBS_solaris := $(LIBDL) -lc, \ + LIBS_solaris := $(LIBDL), \ LIBS_macosx := -liconv, \ - LIBS_windows := $(JDKLIB_LIBS), \ + LIBS_aix := -liconv, \ VERSIONINFO_RESOURCE := $(GLOBAL_VERSION_INFO_RESOURCE), \ RC_FLAGS := $(RC_FLAGS) \ -D "JDK_FNAME=jdwp.dll" \ From b6f45b188974f26347646e207f8cf9e157be4625 Mon Sep 17 00:00:00 2001 From: Paul Sandoz Date: Wed, 4 Nov 2015 16:44:38 +0100 Subject: [PATCH 35/43] 8033148: Lexicographic comparators for arrays Reviewed-by: jrose, chegar, bchristi, mduigou --- .../share/classes/java/lang/Byte.java | 16 + .../share/classes/java/lang/Short.java | 16 + .../share/classes/java/util/Arrays.java | 3719 ++++++++++++++++- .../java/util/Arrays/ArraysEqCmpTest.java | 1083 +++++ 4 files changed, 4823 insertions(+), 11 deletions(-) create mode 100644 jdk/test/java/util/Arrays/ArraysEqCmpTest.java diff --git a/jdk/src/java.base/share/classes/java/lang/Byte.java b/jdk/src/java.base/share/classes/java/lang/Byte.java index 0ae3903ca7e..51f687cb389 100644 --- a/jdk/src/java.base/share/classes/java/lang/Byte.java +++ b/jdk/src/java.base/share/classes/java/lang/Byte.java @@ -462,6 +462,22 @@ public final class Byte extends Number implements Comparable { return x - y; } + /** + * Compares two {@code byte} values numerically treating the values + * as unsigned. + * + * @param x the first {@code byte} to compare + * @param y the second {@code byte} to compare + * @return the value {@code 0} if {@code x == y}; a value less + * than {@code 0} if {@code x < y} as unsigned values; and + * a value greater than {@code 0} if {@code x > y} as + * unsigned values + * @since 9 + */ + public static int compareUnsigned(byte x, byte y) { + return Byte.toUnsignedInt(x) - Byte.toUnsignedInt(y); + } + /** * Converts the argument to an {@code int} by an unsigned * conversion. In an unsigned conversion to an {@code int}, the diff --git a/jdk/src/java.base/share/classes/java/lang/Short.java b/jdk/src/java.base/share/classes/java/lang/Short.java index 6cc4d17d35a..9fa79f3d8c2 100644 --- a/jdk/src/java.base/share/classes/java/lang/Short.java +++ b/jdk/src/java.base/share/classes/java/lang/Short.java @@ -467,6 +467,22 @@ public final class Short extends Number implements Comparable { return x - y; } + /** + * Compares two {@code short} values numerically treating the values + * as unsigned. + * + * @param x the first {@code short} to compare + * @param y the second {@code short} to compare + * @return the value {@code 0} if {@code x == y}; a value less + * than {@code 0} if {@code x < y} as unsigned values; and + * a value greater than {@code 0} if {@code x > y} as + * unsigned values + * @since 9 + */ + public static int compareUnsigned(short x, short y) { + return Short.toUnsignedInt(x) - Short.toUnsignedInt(y); + } + /** * The number of bits used to represent a {@code short} value in two's * complement binary form. diff --git a/jdk/src/java.base/share/classes/java/util/Arrays.java b/jdk/src/java.base/share/classes/java/util/Arrays.java index 35962987cc8..f18180ac84d 100644 --- a/jdk/src/java.base/share/classes/java/util/Arrays.java +++ b/jdk/src/java.base/share/classes/java/util/Arrays.java @@ -25,6 +25,8 @@ package java.util; +import jdk.internal.HotSpotIntrinsicCandidate; + import java.lang.reflect.Array; import java.util.concurrent.ForkJoinPool; import java.util.function.BinaryOperator; @@ -42,7 +44,6 @@ import java.util.stream.IntStream; import java.util.stream.LongStream; import java.util.stream.Stream; import java.util.stream.StreamSupport; -import jdk.internal.HotSpotIntrinsicCandidate; /** * This class contains various methods for manipulating arrays (such as @@ -2585,6 +2586,55 @@ public class Arrays { return true; } + /** + * Returns true if the two specified arrays of longs, over the specified + * ranges, are equal to one another. + * + *

    Two arrays are considered equal if the number of elements covered by + * each range is the same, and all corresponding pairs of elements over the + * specified ranges in the two arrays are equal. In other words, two arrays + * are equal if they contain, over the specified ranges, the same elements + * in the same order. + * + * @param a the first array to be tested for equality + * @param aFromIndex the index (inclusive) of the first element in the + * first array to be tested + * @param aToIndex the index (exclusive) of the last element in the + * first array to be tested + * @param b the second array to be tested fro equality + * @param bFromIndex the index (inclusive) of the first element in the + * second array to be tested + * @param bToIndex the index (exclusive) of the last element in the + * second array to be tested + * @return {@code true} if the two arrays, over the specified ranges, are + * equal + * @throws IllegalArgumentException + * if {@code aFromIndex > aToIndex} or + * if {@code bFromIndex > bToIndex} + * @throws ArrayIndexOutOfBoundsException + * if {@code aFromIndex < 0 or aToIndex > a.length} or + * if {@code bFromIndex < 0 or bToIndex > b.length} + * @throws NullPointerException + * if either array is {@code null} + * @since 9 + */ + public static boolean equals(long[] a, int aFromIndex, int aToIndex, + long[] b, int bFromIndex, int bToIndex) { + rangeCheck(a.length, aFromIndex, aToIndex); + rangeCheck(b.length, bFromIndex, bToIndex); + + int aLength = aToIndex - aFromIndex; + int bLength = bToIndex - bFromIndex; + if (aLength != bLength) + return false; + + for (int i = 0; i < aLength; i++) + if (a[aFromIndex++] != b[bFromIndex++]) + return false; + + return true; + } + /** * Returns {@code true} if the two specified arrays of ints are * equal to one another. Two arrays are considered equal if both @@ -2614,6 +2664,55 @@ public class Arrays { return true; } + /** + * Returns true if the two specified arrays of ints, over the specified + * ranges, are equal to one another. + * + *

    Two arrays are considered equal if the number of elements covered by + * each range is the same, and all corresponding pairs of elements over the + * specified ranges in the two arrays are equal. In other words, two arrays + * are equal if they contain, over the specified ranges, the same elements + * in the same order. + * + * @param a the first array to be tested for equality + * @param aFromIndex the index (inclusive) of the first element in the + * first array to be tested + * @param aToIndex the index (exclusive) of the last element in the + * first array to be tested + * @param b the second array to be tested fro equality + * @param bFromIndex the index (inclusive) of the first element in the + * second array to be tested + * @param bToIndex the index (exclusive) of the last element in the + * second array to be tested + * @return {@code true} if the two arrays, over the specified ranges, are + * equal + * @throws IllegalArgumentException + * if {@code aFromIndex > aToIndex} or + * if {@code bFromIndex > bToIndex} + * @throws ArrayIndexOutOfBoundsException + * if {@code aFromIndex < 0 or aToIndex > a.length} or + * if {@code bFromIndex < 0 or bToIndex > b.length} + * @throws NullPointerException + * if either array is {@code null} + * @since 9 + */ + public static boolean equals(int[] a, int aFromIndex, int aToIndex, + int[] b, int bFromIndex, int bToIndex) { + rangeCheck(a.length, aFromIndex, aToIndex); + rangeCheck(b.length, bFromIndex, bToIndex); + + int aLength = aToIndex - aFromIndex; + int bLength = bToIndex - bFromIndex; + if (aLength != bLength) + return false; + + for (int i = 0; i < aLength; i++) + if (a[aFromIndex++] != b[bFromIndex++]) + return false; + + return true; + } + /** * Returns {@code true} if the two specified arrays of shorts are * equal to one another. Two arrays are considered equal if both @@ -2643,6 +2742,55 @@ public class Arrays { return true; } + /** + * Returns true if the two specified arrays of shorts, over the specified + * ranges, are equal to one another. + * + *

    Two arrays are considered equal if the number of elements covered by + * each range is the same, and all corresponding pairs of elements over the + * specified ranges in the two arrays are equal. In other words, two arrays + * are equal if they contain, over the specified ranges, the same elements + * in the same order. + * + * @param a the first array to be tested for equality + * @param aFromIndex the index (inclusive) of the first element in the + * first array to be tested + * @param aToIndex the index (exclusive) of the last element in the + * first array to be tested + * @param b the second array to be tested fro equality + * @param bFromIndex the index (inclusive) of the first element in the + * second array to be tested + * @param bToIndex the index (exclusive) of the last element in the + * second array to be tested + * @return {@code true} if the two arrays, over the specified ranges, are + * equal + * @throws IllegalArgumentException + * if {@code aFromIndex > aToIndex} or + * if {@code bFromIndex > bToIndex} + * @throws ArrayIndexOutOfBoundsException + * if {@code aFromIndex < 0 or aToIndex > a.length} or + * if {@code bFromIndex < 0 or bToIndex > b.length} + * @throws NullPointerException + * if either array is {@code null} + * @since 9 + */ + public static boolean equals(short[] a, int aFromIndex, int aToIndex, + short[] b, int bFromIndex, int bToIndex) { + rangeCheck(a.length, aFromIndex, aToIndex); + rangeCheck(b.length, bFromIndex, bToIndex); + + int aLength = aToIndex - aFromIndex; + int bLength = bToIndex - bFromIndex; + if (aLength != bLength) + return false; + + for (int i = 0; i < aLength; i++) + if (a[aFromIndex++] != b[bFromIndex++]) + return false; + + return true; + } + /** * Returns {@code true} if the two specified arrays of chars are * equal to one another. Two arrays are considered equal if both @@ -2673,6 +2821,55 @@ public class Arrays { return true; } + /** + * Returns true if the two specified arrays of chars, over the specified + * ranges, are equal to one another. + * + *

    Two arrays are considered equal if the number of elements covered by + * each range is the same, and all corresponding pairs of elements over the + * specified ranges in the two arrays are equal. In other words, two arrays + * are equal if they contain, over the specified ranges, the same elements + * in the same order. + * + * @param a the first array to be tested for equality + * @param aFromIndex the index (inclusive) of the first element in the + * first array to be tested + * @param aToIndex the index (exclusive) of the last element in the + * first array to be tested + * @param b the second array to be tested fro equality + * @param bFromIndex the index (inclusive) of the first element in the + * second array to be tested + * @param bToIndex the index (exclusive) of the last element in the + * second array to be tested + * @return {@code true} if the two arrays, over the specified ranges, are + * equal + * @throws IllegalArgumentException + * if {@code aFromIndex > aToIndex} or + * if {@code bFromIndex > bToIndex} + * @throws ArrayIndexOutOfBoundsException + * if {@code aFromIndex < 0 or aToIndex > a.length} or + * if {@code bFromIndex < 0 or bToIndex > b.length} + * @throws NullPointerException + * if either array is {@code null} + * @since 9 + */ + public static boolean equals(char[] a, int aFromIndex, int aToIndex, + char[] b, int bFromIndex, int bToIndex) { + rangeCheck(a.length, aFromIndex, aToIndex); + rangeCheck(b.length, bFromIndex, bToIndex); + + int aLength = aToIndex - aFromIndex; + int bLength = bToIndex - bFromIndex; + if (aLength != bLength) + return false; + + for (int i = 0; i < aLength; i++) + if (a[aFromIndex++] != b[bFromIndex++]) + return false; + + return true; + } + /** * Returns {@code true} if the two specified arrays of bytes are * equal to one another. Two arrays are considered equal if both @@ -2702,6 +2899,55 @@ public class Arrays { return true; } + /** + * Returns true if the two specified arrays of bytes, over the specified + * ranges, are equal to one another. + * + *

    Two arrays are considered equal if the number of elements covered by + * each range is the same, and all corresponding pairs of elements over the + * specified ranges in the two arrays are equal. In other words, two arrays + * are equal if they contain, over the specified ranges, the same elements + * in the same order. + * + * @param a the first array to be tested for equality + * @param aFromIndex the index (inclusive) of the first element in the + * first array to be tested + * @param aToIndex the index (exclusive) of the last element in the + * first array to be tested + * @param b the second array to be tested fro equality + * @param bFromIndex the index (inclusive) of the first element in the + * second array to be tested + * @param bToIndex the index (exclusive) of the last element in the + * second array to be tested + * @return {@code true} if the two arrays, over the specified ranges, are + * equal + * @throws IllegalArgumentException + * if {@code aFromIndex > aToIndex} or + * if {@code bFromIndex > bToIndex} + * @throws ArrayIndexOutOfBoundsException + * if {@code aFromIndex < 0 or aToIndex > a.length} or + * if {@code bFromIndex < 0 or bToIndex > b.length} + * @throws NullPointerException + * if either array is {@code null} + * @since 9 + */ + public static boolean equals(byte[] a, int aFromIndex, int aToIndex, + byte[] b, int bFromIndex, int bToIndex) { + rangeCheck(a.length, aFromIndex, aToIndex); + rangeCheck(b.length, bFromIndex, bToIndex); + + int aLength = aToIndex - aFromIndex; + int bLength = bToIndex - bFromIndex; + if (aLength != bLength) + return false; + + for (int i = 0; i < aLength; i++) + if (a[aFromIndex++] != b[bFromIndex++]) + return false; + + return true; + } + /** * Returns {@code true} if the two specified arrays of booleans are * equal to one another. Two arrays are considered equal if both @@ -2731,6 +2977,55 @@ public class Arrays { return true; } + /** + * Returns true if the two specified arrays of booleans, over the specified + * ranges, are equal to one another. + * + *

    Two arrays are considered equal if the number of elements covered by + * each range is the same, and all corresponding pairs of elements over the + * specified ranges in the two arrays are equal. In other words, two arrays + * are equal if they contain, over the specified ranges, the same elements + * in the same order. + * + * @param a the first array to be tested for equality + * @param aFromIndex the index (inclusive) of the first element in the + * first array to be tested + * @param aToIndex the index (exclusive) of the last element in the + * first array to be tested + * @param b the second array to be tested fro equality + * @param bFromIndex the index (inclusive) of the first element in the + * second array to be tested + * @param bToIndex the index (exclusive) of the last element in the + * second array to be tested + * @return {@code true} if the two arrays, over the specified ranges, are + * equal + * @throws IllegalArgumentException + * if {@code aFromIndex > aToIndex} or + * if {@code bFromIndex > bToIndex} + * @throws ArrayIndexOutOfBoundsException + * if {@code aFromIndex < 0 or aToIndex > a.length} or + * if {@code bFromIndex < 0 or bToIndex > b.length} + * @throws NullPointerException + * if either array is {@code null} + * @since 9 + */ + public static boolean equals(boolean[] a, int aFromIndex, int aToIndex, + boolean[] b, int bFromIndex, int bToIndex) { + rangeCheck(a.length, aFromIndex, aToIndex); + rangeCheck(b.length, bFromIndex, bToIndex); + + int aLength = aToIndex - aFromIndex; + int bLength = bToIndex - bFromIndex; + if (aLength != bLength) + return false; + + for (int i = 0; i < aLength; i++) + if (a[aFromIndex++] != b[bFromIndex++]) + return false; + + return true; + } + /** * Returns {@code true} if the two specified arrays of doubles are * equal to one another. Two arrays are considered equal if both @@ -2759,9 +3054,70 @@ public class Arrays { if (a2.length != length) return false; - for (int i=0; iequal to one another. + * + *

    Two arrays are considered equal if the number of elements covered by + * each range is the same, and all corresponding pairs of elements over the + * specified ranges in the two arrays are equal. In other words, two arrays + * are equal if they contain, over the specified ranges, the same elements + * in the same order. + * + *

    Two doubles {@code d1} and {@code d2} are considered equal if: + *

        {@code new Double(d1).equals(new Double(d2))}
    + * (Unlike the {@code ==} operator, this method considers + * {@code NaN} equals to itself, and 0.0d unequal to -0.0d.) + * + * @param a the first array to be tested for equality + * @param aFromIndex the index (inclusive) of the first element in the + * first array to be tested + * @param aToIndex the index (exclusive) of the last element in the + * first array to be tested + * @param b the second array to be tested fro equality + * @param bFromIndex the index (inclusive) of the first element in the + * second array to be tested + * @param bToIndex the index (exclusive) of the last element in the + * second array to be tested + * @return {@code true} if the two arrays, over the specified ranges, are + * equal + * @throws IllegalArgumentException + * if {@code aFromIndex > aToIndex} or + * if {@code bFromIndex > bToIndex} + * @throws ArrayIndexOutOfBoundsException + * if {@code aFromIndex < 0 or aToIndex > a.length} or + * if {@code bFromIndex < 0 or bToIndex > b.length} + * @throws NullPointerException + * if either array is {@code null} + * @see Double#equals(Object) + * @since 9 + */ + public static boolean equals(double[] a, int aFromIndex, int aToIndex, + double[] b, int bFromIndex, int bToIndex) { + rangeCheck(a.length, aFromIndex, aToIndex); + rangeCheck(b.length, bFromIndex, bToIndex); + + int aLength = aToIndex - aFromIndex; + int bLength = bToIndex - bFromIndex; + if (aLength != bLength) + return false; + + for (int i = 0; i < aLength; i++) { + Double va = a[aFromIndex++], vb = b[bFromIndex++]; + if (Double.doubleToRawLongBits(va) != Double.doubleToRawLongBits(vb)) + if (!Double.isNaN(va) || !Double.isNaN(vb)) + return false; + } return true; } @@ -2794,9 +3150,70 @@ public class Arrays { if (a2.length != length) return false; - for (int i=0; iequal to one another. + * + *

    Two arrays are considered equal if the number of elements covered by + * each range is the same, and all corresponding pairs of elements over the + * specified ranges in the two arrays are equal. In other words, two arrays + * are equal if they contain, over the specified ranges, the same elements + * in the same order. + * + *

    Two floats {@code f1} and {@code f2} are considered equal if: + *

        {@code new Float(f1).equals(new Float(f2))}
    + * (Unlike the {@code ==} operator, this method considers + * {@code NaN} equals to itself, and 0.0f unequal to -0.0f.) + * + * @param a the first array to be tested for equality + * @param aFromIndex the index (inclusive) of the first element in the + * first array to be tested + * @param aToIndex the index (exclusive) of the last element in the + * first array to be tested + * @param b the second array to be tested fro equality + * @param bFromIndex the index (inclusive) of the first element in the + * second array to be tested + * @param bToIndex the index (exclusive) of the last element in the + * second array to be tested + * @return {@code true} if the two arrays, over the specified ranges, are + * equal + * @throws IllegalArgumentException + * if {@code aFromIndex > aToIndex} or + * if {@code bFromIndex > bToIndex} + * @throws ArrayIndexOutOfBoundsException + * if {@code aFromIndex < 0 or aToIndex > a.length} or + * if {@code bFromIndex < 0 or bToIndex > b.length} + * @throws NullPointerException + * if either array is {@code null} + * @see Float#equals(Object) + * @since 9 + */ + public static boolean equals(float[] a, int aFromIndex, int aToIndex, + float[] b, int bFromIndex, int bToIndex) { + rangeCheck(a.length, aFromIndex, aToIndex); + rangeCheck(b.length, bFromIndex, bToIndex); + + int aLength = aToIndex - aFromIndex; + int bLength = bToIndex - bFromIndex; + if (aLength != bLength) + return false; + + for (int i = 0; i < aLength; i++) { + float va = a[aFromIndex++], vb = b[bFromIndex++]; + if (Float.floatToRawIntBits(va) != Float.floatToRawIntBits(vb)) + if (!Float.isNaN(va) || !Float.isNaN(vb)) + return false; + } return true; } @@ -2827,9 +3244,60 @@ public class Arrays { return false; for (int i=0; iequal to one another. + * + *

    Two arrays are considered equal if the number of elements covered by + * each range is the same, and all corresponding pairs of elements over the + * specified ranges in the two arrays are equal. In other words, two arrays + * are equal if they contain, over the specified ranges, the same elements + * in the same order. + * + *

    Two objects {@code e1} and {@code e2} are considered equal if + * {@code Objects.equals(e1, e2)}. + * + * @param a the first array to be tested for equality + * @param aFromIndex the index (inclusive) of the first element in the + * first array to be tested + * @param aToIndex the index (exclusive) of the last element in the + * first array to be tested + * @param b the second array to be tested fro equality + * @param bFromIndex the index (inclusive) of the first element in the + * second array to be tested + * @param bToIndex the index (exclusive) of the last element in the + * second array to be tested + * @return {@code true} if the two arrays, over the specified ranges, are + * equal + * @throws IllegalArgumentException + * if {@code aFromIndex > aToIndex} or + * if {@code bFromIndex > bToIndex} + * @throws ArrayIndexOutOfBoundsException + * if {@code aFromIndex < 0 or aToIndex > a.length} or + * if {@code bFromIndex < 0 or bToIndex > b.length} + * @throws NullPointerException + * if either array is {@code null} + * @since 9 + */ + public static boolean equals(Object[] a, int aFromIndex, int aToIndex, + Object[] b, int bFromIndex, int bToIndex) { + rangeCheck(a.length, aFromIndex, aToIndex); + rangeCheck(b.length, bFromIndex, bToIndex); + + int aLength = aToIndex - aFromIndex; + int bLength = bToIndex - bFromIndex; + if (aLength != bLength) + return false; + + for (int i = 0; i < aLength; i++) { + if (!Objects.equals(a[aFromIndex++], b[bFromIndex++])) return false; } @@ -5185,4 +5653,3233 @@ public class Arrays { public static DoubleStream stream(double[] array, int startInclusive, int endExclusive) { return StreamSupport.doubleStream(spliterator(array, startInclusive, endExclusive), false); } -} + + + // Comparison methods + + // Compare boolean + + /** + * Compares two {@code boolean} arrays lexicographically. + * + *

    If the two arrays share a common prefix then the lexicographic + * comparison is the result of comparing two elements, as if by + * {@link Boolean#compare(boolean, boolean)}, at an index within the + * respective arrays that is the prefix length. + * Otherwise, one array is a proper prefix of the other and, lexicographic + * comparison is the result of comparing the two array lengths. + * (See {@link #mismatch(boolean[], boolean[])} for the definition of a + * common and proper prefix.) + * + *

    A {@code null} array reference is considered lexicographically less + * than a non-{@code null} array reference. Two {@code null} array + * references are considered equal. + * + *

    The comparison is consistent with {@link #equals(boolean[], boolean[]) equals}, + * more specifically the following holds for arrays {@code a} and {@code b}: + *

    {@code
    +     *     Arrays.equals(a, b) == (Arrays.compare(a, b) == 0)
    +     * }
    + * + * @apiNote + *

    This method behaves as if (for non-{@code null} array references): + *

    {@code
    +     *     int i = Arrays.mismatch(a, b);
    +     *     if (i >= 0 && i < Math.min(a.length, b.length))
    +     *         return Boolean.compare(a[i], b[i]);
    +     *     return a.length - b.length;
    +     * }
    + * + * @param a the first array to compare + * @param b the second array to compare + * @return the value {@code 0} if the first and second array are equal and + * contain the same elements in the same order; + * a value less than {@code 0} if the first array is + * lexicographically less than the second array; and + * a value greater than {@code 0} if the first array is + * lexicographically greater than the second array + * @since 9 + */ + public static int compare(boolean[] a, boolean[] b) { + if (a == b) + return 0; + if (a == null || b == null) + return a == null ? -1 : 1; + + int length = Math.min(a.length, b.length); + for (int i = 0; i < length; i++) { + if (a[i] != b[i]) return Boolean.compare(a[i], b[i]); + } + + return a.length - b.length; + } + + /** + * Compares two {@code boolean} arrays lexicographically over the specified + * ranges. + * + *

    If the two arrays, over the specified ranges, share a common prefix + * then the lexicographic comparison is the result of comparing two + * elements, as if by {@link Boolean#compare(boolean, boolean)}, at a + * relative index within the respective arrays that is the length of the + * prefix. + * Otherwise, one array is a proper prefix of the other and, lexicographic + * comparison is the result of comparing the two range lengths. + * (See {@link #mismatch(boolean[], int, int, boolean[], int, int)} for the + * definition of a common and proper prefix.) + * + *

    The comparison is consistent with + * {@link #equals(boolean[], int, int, boolean[], int, int) equals}, more + * specifically the following holds for arrays {@code a} and {@code b} with + * specified ranges [{@code aFromIndex}, {@code atoIndex}) and + * [{@code bFromIndex}, {@code btoIndex}) respectively: + *

    {@code
    +     *     Arrays.equals(a, aFromIndex, aToIndex, b, bFromIndex, bToIndex) ==
    +     *         (Arrays.compare(a, aFromIndex, aToIndex, b, bFromIndex, bToIndex) == 0)
    +     * }
    + * + * @apiNote + *

    This method behaves as if: + *

    {@code
    +     *     int i = Arrays.mismatch(a, aFromIndex, aToIndex,
    +     *                             b, bFromIndex, bToIndex);
    +     *     if (i >= 0 && i < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex))
    +     *         return Boolean.compare(a[aFromIndex + i], b[bFromIndex + i]);
    +     *     return (aToIndex - aFromIndex) - (bToIndex - bFromIndex);
    +     * }
    + * + * @param a the first array to compare + * @param aFromIndex the index (inclusive) of the first element in the + * first array to be compared + * @param aToIndex the index (exclusive) of the last element in the + * first array to be compared + * @param b the second array to compare + * @param bFromIndex the index (inclusive) of the first element in the + * second array to be compared + * @param bToIndex the index (exclusive) of the last element in the + * second array to be compared + * @return the value {@code 0} if, over the specified ranges, the first and + * second array are equal and contain the same elements in the same + * order; + * a value less than {@code 0} if, over the specified ranges, the + * first array is lexicographically less than the second array; and + * a value greater than {@code 0} if, over the specified ranges, the + * first array is lexicographically greater than the second array + * @throws IllegalArgumentException + * if {@code aFromIndex > aToIndex} or + * if {@code bFromIndex > bToIndex} + * @throws ArrayIndexOutOfBoundsException + * if {@code aFromIndex < 0 or aToIndex > a.length} or + * if {@code bFromIndex < 0 or bToIndex > b.length} + * @throws NullPointerException + * if either array is {@code null} + * @since 9 + */ + public static int compare(boolean[] a, int aFromIndex, int aToIndex, + boolean[] b, int bFromIndex, int bToIndex) { + rangeCheck(a.length, aFromIndex, aToIndex); + rangeCheck(b.length, bFromIndex, bToIndex); + + int aLength = aToIndex - aFromIndex; + int bLength = bToIndex - bFromIndex; + int length = Math.min(aLength, bLength); + for (int i = 0; i < length; i++) { + boolean va = a[aFromIndex++]; + boolean vb = b[bFromIndex++]; + if (va != vb) return Boolean.compare(va, vb); + } + + return aLength - bLength; + } + + // Compare byte + + /** + * Compares two {@code byte} arrays lexicographically. + * + *

    If the two arrays share a common prefix then the lexicographic + * comparison is the result of comparing two elements, as if by + * {@link Byte#compare(byte, byte)}, at an index within the respective + * arrays that is the prefix length. + * Otherwise, one array is a proper prefix of the other and, lexicographic + * comparison is the result of comparing the two array lengths. + * (See {@link #mismatch(byte[], byte[])} for the definition of a common and + * proper prefix.) + * + *

    A {@code null} array reference is considered lexicographically less + * than a non-{@code null} array reference. Two {@code null} array + * references are considered equal. + * + *

    The comparison is consistent with {@link #equals(byte[], byte[]) equals}, + * more specifically the following holds for arrays {@code a} and {@code b}: + *

    {@code
    +     *     Arrays.equals(a, b) == (Arrays.compare(a, b) == 0)
    +     * }
    + * + * @apiNote + *

    This method behaves as if (for non-{@code null} array references): + *

    {@code
    +     *     int i = Arrays.mismatch(a, b);
    +     *     if (i >= 0 && i < Math.min(a.length, b.length))
    +     *         return Byte.compare(a[i], b[i]);
    +     *     return a.length - b.length;
    +     * }
    + * + * @param a the first array to compare + * @param b the second array to compare + * @return the value {@code 0} if the first and second array are equal and + * contain the same elements in the same order; + * a value less than {@code 0} if the first array is + * lexicographically less than the second array; and + * a value greater than {@code 0} if the first array is + * lexicographically greater than the second array + * @since 9 + */ + public static int compare(byte[] a, byte[] b) { + if (a == b) + return 0; + if (a == null || b == null) + return a == null ? -1 : 1; + + int length = Math.min(a.length, b.length); + for (int i = 0; i < length; i++) { + if (a[i] != b[i]) return Byte.compare(a[i], b[i]); + } + + return a.length - b.length; + } + + /** + * Compares two {@code byte} arrays lexicographically over the specified + * ranges. + * + *

    If the two arrays, over the specified ranges, share a common prefix + * then the lexicographic comparison is the result of comparing two + * elements, as if by {@link Byte#compare(byte, byte)}, at a relative index + * within the respective arrays that is the length of the prefix. + * Otherwise, one array is a proper prefix of the other and, lexicographic + * comparison is the result of comparing the two range lengths. + * (See {@link #mismatch(byte[], int, int, byte[], int, int)} for the + * definition of a common and proper prefix.) + * + *

    The comparison is consistent with + * {@link #equals(byte[], int, int, byte[], int, int) equals}, more + * specifically the following holds for arrays {@code a} and {@code b} with + * specified ranges [{@code aFromIndex}, {@code atoIndex}) and + * [{@code bFromIndex}, {@code btoIndex}) respectively: + *

    {@code
    +     *     Arrays.equals(a, aFromIndex, aToIndex, b, bFromIndex, bToIndex) ==
    +     *         (Arrays.compare(a, aFromIndex, aToIndex, b, bFromIndex, bToIndex) == 0)
    +     * }
    + * + * @apiNote + *

    This method behaves as if: + *

    {@code
    +     *     int i = Arrays.mismatch(a, aFromIndex, aToIndex,
    +     *                             b, bFromIndex, bToIndex);
    +     *     if (i >= 0 && i < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex))
    +     *         return Byte.compare(a[aFromIndex + i], b[bFromIndex + i]);
    +     *     return (aToIndex - aFromIndex) - (bToIndex - bFromIndex);
    +     * }
    + * + * @param a the first array to compare + * @param aFromIndex the index (inclusive) of the first element in the + * first array to be compared + * @param aToIndex the index (exclusive) of the last element in the + * first array to be compared + * @param b the second array to compare + * @param bFromIndex the index (inclusive) of the first element in the + * second array to be compared + * @param bToIndex the index (exclusive) of the last element in the + * second array to be compared + * @return the value {@code 0} if, over the specified ranges, the first and + * second array are equal and contain the same elements in the same + * order; + * a value less than {@code 0} if, over the specified ranges, the + * first array is lexicographically less than the second array; and + * a value greater than {@code 0} if, over the specified ranges, the + * first array is lexicographically greater than the second array + * @throws IllegalArgumentException + * if {@code aFromIndex > aToIndex} or + * if {@code bFromIndex > bToIndex} + * @throws ArrayIndexOutOfBoundsException + * if {@code aFromIndex < 0 or aToIndex > a.length} or + * if {@code bFromIndex < 0 or bToIndex > b.length} + * @throws NullPointerException + * if either array is {@code null} + * @since 9 + */ + public static int compare(byte[] a, int aFromIndex, int aToIndex, + byte[] b, int bFromIndex, int bToIndex) { + rangeCheck(a.length, aFromIndex, aToIndex); + rangeCheck(b.length, bFromIndex, bToIndex); + + int aLength = aToIndex - aFromIndex; + int bLength = bToIndex - bFromIndex; + int length = Math.min(aLength, bLength); + for (int i = 0; i < length; i++) { + byte va = a[aFromIndex++]; + byte vb = b[bFromIndex++]; + if (va != vb) return Byte.compare(va, vb); + } + + return aLength - bLength; + } + + /** + * Compares two {@code byte} arrays lexicographically, numerically treating + * elements as unsigned. + * + *

    If the two arrays share a common prefix then the lexicographic + * comparison is the result of comparing two elements, as if by + * {@link Byte#compareUnsigned(byte, byte)}, at an index within the + * respective arrays that is the prefix length. + * Otherwise, one array is a proper prefix of the other and, lexicographic + * comparison is the result of comparing the two array lengths. + * (See {@link #mismatch(byte[], byte[])} for the definition of a common + * and proper prefix.) + * + *

    A {@code null} array reference is considered lexicographically less + * than a non-{@code null} array reference. Two {@code null} array + * references are considered equal. + * + * @apiNote + *

    This method behaves as if (for non-{@code null} array references): + *

    {@code
    +     *     int i = Arrays.mismatch(a, b);
    +     *     if (i >= 0 && i < Math.min(a.length, b.length))
    +     *         return Byte.compareUnsigned(a[i], b[i]);
    +     *     return a.length - b.length;
    +     * }
    + * + * @param a the first array to compare + * @param b the second array to compare + * @return the value {@code 0} if the first and second array are + * equal and contain the same elements in the same order; + * a value less than {@code 0} if the first array is + * lexicographically less than the second array; and + * a value greater than {@code 0} if the first array is + * lexicographically greater than the second array + * @since 9 + */ + public static int compareUnsigned(byte[] a, byte[] b) { + if (a == b) + return 0; + if (a == null || b == null) + return a == null ? -1 : 1; + + int length = Math.min(a.length, b.length); + for (int i = 0; i < length; i++) { + if (a[i] != b[i]) return Byte.compareUnsigned(a[i], b[i]); + } + + return a.length - b.length; + } + + + /** + * Compares two {@code byte} arrays lexicographically over the specified + * ranges, numerically treating elements as unsigned. + * + *

    If the two arrays, over the specified ranges, share a common prefix + * then the lexicographic comparison is the result of comparing two + * elements, as if by {@link Byte#compareUnsigned(byte, byte)}, at a + * relative index within the respective arrays that is the length of the + * prefix. + * Otherwise, one array is a proper prefix of the other and, lexicographic + * comparison is the result of comparing the two range lengths. + * (See {@link #mismatch(byte[], int, int, byte[], int, int)} for the + * definition of a common and proper prefix.) + * + * @apiNote + *

    This method behaves as if: + *

    {@code
    +     *     int i = Arrays.mismatch(a, aFromIndex, aToIndex,
    +     *                             b, bFromIndex, bToIndex);
    +     *     if (i >= 0 && i < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex))
    +     *         return Byte.compareUnsigned(a[aFromIndex + i], b[bFromIndex + i]);
    +     *     return (aToIndex - aFromIndex) - (bToIndex - bFromIndex);
    +     * }
    + * + * @param a the first array to compare + * @param aFromIndex the index (inclusive) of the first element in the + * first array to be compared + * @param aToIndex the index (exclusive) of the last element in the + * first array to be compared + * @param b the second array to compare + * @param bFromIndex the index (inclusive) of the first element in the + * second array to be compared + * @param bToIndex the index (exclusive) of the last element in the + * second array to be compared + * @return the value {@code 0} if, over the specified ranges, the first and + * second array are equal and contain the same elements in the same + * order; + * a value less than {@code 0} if, over the specified ranges, the + * first array is lexicographically less than the second array; and + * a value greater than {@code 0} if, over the specified ranges, the + * first array is lexicographically greater than the second array + * @throws IllegalArgumentException + * if {@code aFromIndex > aToIndex} or + * if {@code bFromIndex > bToIndex} + * @throws ArrayIndexOutOfBoundsException + * if {@code aFromIndex < 0 or aToIndex > a.length} or + * if {@code bFromIndex < 0 or bToIndex > b.length} + * @throws NullPointerException + * if either array is null + * @since 9 + */ + public static int compareUnsigned(byte[] a, int aFromIndex, int aToIndex, + byte[] b, int bFromIndex, int bToIndex) { + rangeCheck(a.length, aFromIndex, aToIndex); + rangeCheck(b.length, bFromIndex, bToIndex); + + int aLength = aToIndex - aFromIndex; + int bLength = bToIndex - bFromIndex; + int length = Math.min(aLength, bLength); + for (int i = 0; i < length; i++) { + byte va = a[aFromIndex++]; + byte vb = b[bFromIndex++]; + if (va != vb) return Byte.compareUnsigned(va, vb); + } + + return aLength - bLength; + } + + // Compare short + + /** + * Compares two {@code short} arrays lexicographically. + * + *

    If the two arrays share a common prefix then the lexicographic + * comparison is the result of comparing two elements, as if by + * {@link Short#compare(short, short)}, at an index within the respective + * arrays that is the prefix length. + * Otherwise, one array is a proper prefix of the other and, lexicographic + * comparison is the result of comparing the two array lengths. + * (See {@link #mismatch(short[], short[])} for the definition of a common + * and proper prefix.) + * + *

    A {@code null} array reference is considered lexicographically less + * than a non-{@code null} array reference. Two {@code null} array + * references are considered equal. + * + *

    The comparison is consistent with {@link #equals(short[], short[]) equals}, + * more specifically the following holds for arrays {@code a} and {@code b}: + *

    {@code
    +     *     Arrays.equals(a, b) == (Arrays.compare(a, b) == 0)
    +     * }
    + * + * @apiNote + *

    This method behaves as if (for non-{@code null} array references): + *

    {@code
    +     *     int i = Arrays.mismatch(a, b);
    +     *     if (i >= 0 && i < Math.min(a.length, b.length))
    +     *         return Short.compare(a[i], b[i]);
    +     *     return a.length - b.length;
    +     * }
    + * + * @param a the first array to compare + * @param b the second array to compare + * @return the value {@code 0} if the first and second array are equal and + * contain the same elements in the same order; + * a value less than {@code 0} if the first array is + * lexicographically less than the second array; and + * a value greater than {@code 0} if the first array is + * lexicographically greater than the second array + * @since 9 + */ + public static int compare(short[] a, short[] b) { + if (a == b) + return 0; + if (a == null || b == null) + return a == null ? -1 : 1; + + int length = Math.min(a.length, b.length); + for (int i = 0; i < length; i++) { + if (a[i] != b[i]) return Short.compare(a[i], b[i]); + } + + return a.length - b.length; + } + + /** + * Compares two {@code short} arrays lexicographically over the specified + * ranges. + * + *

    If the two arrays, over the specified ranges, share a common prefix + * then the lexicographic comparison is the result of comparing two + * elements, as if by {@link Short#compare(short, short)}, at a relative + * index within the respective arrays that is the length of the prefix. + * Otherwise, one array is a proper prefix of the other and, lexicographic + * comparison is the result of comparing the two range lengths. + * (See {@link #mismatch(short[], int, int, short[], int, int)} for the + * definition of a common and proper prefix.) + * + *

    The comparison is consistent with + * {@link #equals(short[], int, int, short[], int, int) equals}, more + * specifically the following holds for arrays {@code a} and {@code b} with + * specified ranges [{@code aFromIndex}, {@code atoIndex}) and + * [{@code bFromIndex}, {@code btoIndex}) respectively: + *

    {@code
    +     *     Arrays.equals(a, aFromIndex, aToIndex, b, bFromIndex, bToIndex) ==
    +     *         (Arrays.compare(a, aFromIndex, aToIndex, b, bFromIndex, bToIndex) == 0)
    +     * }
    + * + * @apiNote + *

    This method behaves as if: + *

    {@code
    +     *     int i = Arrays.mismatch(a, aFromIndex, aToIndex,
    +     *                             b, bFromIndex, bToIndex);
    +     *     if (i >= 0 && i < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex))
    +     *         return Short.compare(a[aFromIndex + i], b[bFromIndex + i]);
    +     *     return (aToIndex - aFromIndex) - (bToIndex - bFromIndex);
    +     * }
    + * + * @param a the first array to compare + * @param aFromIndex the index (inclusive) of the first element in the + * first array to be compared + * @param aToIndex the index (exclusive) of the last element in the + * first array to be compared + * @param b the second array to compare + * @param bFromIndex the index (inclusive) of the first element in the + * second array to be compared + * @param bToIndex the index (exclusive) of the last element in the + * second array to be compared + * @return the value {@code 0} if, over the specified ranges, the first and + * second array are equal and contain the same elements in the same + * order; + * a value less than {@code 0} if, over the specified ranges, the + * first array is lexicographically less than the second array; and + * a value greater than {@code 0} if, over the specified ranges, the + * first array is lexicographically greater than the second array + * @throws IllegalArgumentException + * if {@code aFromIndex > aToIndex} or + * if {@code bFromIndex > bToIndex} + * @throws ArrayIndexOutOfBoundsException + * if {@code aFromIndex < 0 or aToIndex > a.length} or + * if {@code bFromIndex < 0 or bToIndex > b.length} + * @throws NullPointerException + * if either array is {@code null} + * @since 9 + */ + public static int compare(short[] a, int aFromIndex, int aToIndex, + short[] b, int bFromIndex, int bToIndex) { + rangeCheck(a.length, aFromIndex, aToIndex); + rangeCheck(b.length, bFromIndex, bToIndex); + + int aLength = aToIndex - aFromIndex; + int bLength = bToIndex - bFromIndex; + int length = Math.min(aLength, bLength); + for (int i = 0; i < length; i++) { + short va = a[aFromIndex++]; + short vb = b[bFromIndex++]; + if (va != vb) return Short.compare(va, vb); + } + + return aLength - bLength; + } + + /** + * Compares two {@code short} arrays lexicographically, numerically treating + * elements as unsigned. + * + *

    If the two arrays share a common prefix then the lexicographic + * comparison is the result of comparing two elements, as if by + * {@link Short#compareUnsigned(short, short)}, at an index within the + * respective arrays that is the prefix length. + * Otherwise, one array is a proper prefix of the other and, lexicographic + * comparison is the result of comparing the two array lengths. + * (See {@link #mismatch(short[], short[])} for the definition of a common + * and proper prefix.) + * + *

    A {@code null} array reference is considered lexicographically less + * than a non-{@code null} array reference. Two {@code null} array + * references are considered equal. + * + * @apiNote + *

    This method behaves as if (for non-{@code null} array references): + *

    {@code
    +     *     int i = Arrays.mismatch(a, b);
    +     *     if (i >= 0 && i < Math.min(a.length, b.length))
    +     *         return Short.compareUnsigned(a[i], b[i]);
    +     *     return a.length - b.length;
    +     * }
    + * + * @param a the first array to compare + * @param b the second array to compare + * @return the value {@code 0} if the first and second array are + * equal and contain the same elements in the same order; + * a value less than {@code 0} if the first array is + * lexicographically less than the second array; and + * a value greater than {@code 0} if the first array is + * lexicographically greater than the second array + * @since 9 + */ + public static int compareUnsigned(short[] a, short[] b) { + if (a == b) + return 0; + if (a == null || b == null) + return a == null ? -1 : 1; + + int length = Math.min(a.length, b.length); + for (int i = 0; i < length; i++) { + if (a[i] != b[i]) return Short.compareUnsigned(a[i], b[i]); + } + + return a.length - b.length; + } + + /** + * Compares two {@code short} arrays lexicographically over the specified + * ranges, numerically treating elements as unsigned. + * + *

    If the two arrays, over the specified ranges, share a common prefix + * then the lexicographic comparison is the result of comparing two + * elements, as if by {@link Short#compareUnsigned(short, short)}, at a + * relative index within the respective arrays that is the length of the + * prefix. + * Otherwise, one array is a proper prefix of the other and, lexicographic + * comparison is the result of comparing the two range lengths. + * (See {@link #mismatch(short[], int, int, short[], int, int)} for the + * definition of a common and proper prefix.) + * + * @apiNote + *

    This method behaves as if: + *

    {@code
    +     *     int i = Arrays.mismatch(a, aFromIndex, aToIndex,
    +     *                             b, bFromIndex, bToIndex);
    +     *     if (i >= 0 && i < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex))
    +     *         return Short.compareUnsigned(a[aFromIndex + i], b[bFromIndex + i]);
    +     *     return (aToIndex - aFromIndex) - (bToIndex - bFromIndex);
    +     * }
    + * + * @param a the first array to compare + * @param aFromIndex the index (inclusive) of the first element in the + * first array to be compared + * @param aToIndex the index (exclusive) of the last element in the + * first array to be compared + * @param b the second array to compare + * @param bFromIndex the index (inclusive) of the first element in the + * second array to be compared + * @param bToIndex the index (exclusive) of the last element in the + * second array to be compared + * @return the value {@code 0} if, over the specified ranges, the first and + * second array are equal and contain the same elements in the same + * order; + * a value less than {@code 0} if, over the specified ranges, the + * first array is lexicographically less than the second array; and + * a value greater than {@code 0} if, over the specified ranges, the + * first array is lexicographically greater than the second array + * @throws IllegalArgumentException + * if {@code aFromIndex > aToIndex} or + * if {@code bFromIndex > bToIndex} + * @throws ArrayIndexOutOfBoundsException + * if {@code aFromIndex < 0 or aToIndex > a.length} or + * if {@code bFromIndex < 0 or bToIndex > b.length} + * @throws NullPointerException + * if either array is null + * @since 9 + */ + public static int compareUnsigned(short[] a, int aFromIndex, int aToIndex, + short[] b, int bFromIndex, int bToIndex) { + rangeCheck(a.length, aFromIndex, aToIndex); + rangeCheck(b.length, bFromIndex, bToIndex); + + int aLength = aToIndex - aFromIndex; + int bLength = bToIndex - bFromIndex; + int length = Math.min(aLength, bLength); + for (int i = 0; i < length; i++) { + short va = a[aFromIndex++]; + short vb = b[bFromIndex++]; + if (va != vb) return Short.compareUnsigned(va, vb); + } + + return aLength - bLength; + } + + // Compare char + + /** + * Compares two {@code char} arrays lexicographically. + * + *

    If the two arrays share a common prefix then the lexicographic + * comparison is the result of comparing two elements, as if by + * {@link Character#compare(char, char)}, at an index within the respective + * arrays that is the prefix length. + * Otherwise, one array is a proper prefix of the other and, lexicographic + * comparison is the result of comparing the two array lengths. + * (See {@link #mismatch(char[], char[])} for the definition of a common and + * proper prefix.) + * + *

    A {@code null} array reference is considered lexicographically less + * than a non-{@code null} array reference. Two {@code null} array + * references are considered equal. + * + *

    The comparison is consistent with {@link #equals(char[], char[]) equals}, + * more specifically the following holds for arrays {@code a} and {@code b}: + *

    {@code
    +     *     Arrays.equals(a, b) == (Arrays.compare(a, b) == 0)
    +     * }
    + * + * @apiNote + *

    This method behaves as if (for non-{@code null} array references): + *

    {@code
    +     *     int i = Arrays.mismatch(a, b);
    +     *     if (i >= 0 && i < Math.min(a.length, b.length))
    +     *         return Character.compare(a[i], b[i]);
    +     *     return a.length - b.length;
    +     * }
    + * + * @param a the first array to compare + * @param b the second array to compare + * @return the value {@code 0} if the first and second array are equal and + * contain the same elements in the same order; + * a value less than {@code 0} if the first array is + * lexicographically less than the second array; and + * a value greater than {@code 0} if the first array is + * lexicographically greater than the second array + * @since 9 + */ + public static int compare(char[] a, char[] b) { + if (a == b) + return 0; + if (a == null || b == null) + return a == null ? -1 : 1; + + int length = Math.min(a.length, b.length); + for (int i = 0; i < length; i++) { + if (a[i] != b[i]) return Character.compare(a[i], b[i]); + } + + return a.length - b.length; + } + + /** + * Compares two {@code char} arrays lexicographically over the specified + * ranges. + * + *

    If the two arrays, over the specified ranges, share a common prefix + * then the lexicographic comparison is the result of comparing two + * elements, as if by {@link Character#compare(char, char)}, at a relative + * index within the respective arrays that is the length of the prefix. + * Otherwise, one array is a proper prefix of the other and, lexicographic + * comparison is the result of comparing the two range lengths. + * (See {@link #mismatch(char[], int, int, char[], int, int)} for the + * definition of a common and proper prefix.) + * + *

    The comparison is consistent with + * {@link #equals(char[], int, int, char[], int, int) equals}, more + * specifically the following holds for arrays {@code a} and {@code b} with + * specified ranges [{@code aFromIndex}, {@code atoIndex}) and + * [{@code bFromIndex}, {@code btoIndex}) respectively: + *

    {@code
    +     *     Arrays.equals(a, aFromIndex, aToIndex, b, bFromIndex, bToIndex) ==
    +     *         (Arrays.compare(a, aFromIndex, aToIndex, b, bFromIndex, bToIndex) == 0)
    +     * }
    + * + * @apiNote + *

    This method behaves as if: + *

    {@code
    +     *     int i = Arrays.mismatch(a, aFromIndex, aToIndex,
    +     *                             b, bFromIndex, bToIndex);
    +     *     if (i >= 0 && i < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex))
    +     *         return Character.compare(a[aFromIndex + i], b[bFromIndex + i]);
    +     *     return (aToIndex - aFromIndex) - (bToIndex - bFromIndex);
    +     * }
    + * + * @param a the first array to compare + * @param aFromIndex the index (inclusive) of the first element in the + * first array to be compared + * @param aToIndex the index (exclusive) of the last element in the + * first array to be compared + * @param b the second array to compare + * @param bFromIndex the index (inclusive) of the first element in the + * second array to be compared + * @param bToIndex the index (exclusive) of the last element in the + * second array to be compared + * @return the value {@code 0} if, over the specified ranges, the first and + * second array are equal and contain the same elements in the same + * order; + * a value less than {@code 0} if, over the specified ranges, the + * first array is lexicographically less than the second array; and + * a value greater than {@code 0} if, over the specified ranges, the + * first array is lexicographically greater than the second array + * @throws IllegalArgumentException + * if {@code aFromIndex > aToIndex} or + * if {@code bFromIndex > bToIndex} + * @throws ArrayIndexOutOfBoundsException + * if {@code aFromIndex < 0 or aToIndex > a.length} or + * if {@code bFromIndex < 0 or bToIndex > b.length} + * @throws NullPointerException + * if either array is {@code null} + * @since 9 + */ + public static int compare(char[] a, int aFromIndex, int aToIndex, + char[] b, int bFromIndex, int bToIndex) { + rangeCheck(a.length, aFromIndex, aToIndex); + rangeCheck(b.length, bFromIndex, bToIndex); + + int aLength = aToIndex - aFromIndex; + int bLength = bToIndex - bFromIndex; + int length = Math.min(aLength, bLength); + for (int i = 0; i < length; i++) { + char va = a[aFromIndex++]; + char vb = b[bFromIndex++]; + if (va != vb) return Character.compare(va, vb); + } + + return aLength - bLength; + } + + // Compare int + + /** + * Compares two {@code int} arrays lexicographically. + * + *

    If the two arrays share a common prefix then the lexicographic + * comparison is the result of comparing two elements, as if by + * {@link Integer#compare(int, int)}, at an index within the respective + * arrays that is the prefix length. + * Otherwise, one array is a proper prefix of the other and, lexicographic + * comparison is the result of comparing the two array lengths. + * (See {@link #mismatch(int[], int[])} for the definition of a common and + * proper prefix.) + * + *

    A {@code null} array reference is considered lexicographically less + * than a non-{@code null} array reference. Two {@code null} array + * references are considered equal. + * + *

    The comparison is consistent with {@link #equals(int[], int[]) equals}, + * more specifically the following holds for arrays {@code a} and {@code b}: + *

    {@code
    +     *     Arrays.equals(a, b) == (Arrays.compare(a, b) == 0)
    +     * }
    + * + * @apiNote + *

    This method behaves as if (for non-{@code null} array references): + *

    {@code
    +     *     int i = Arrays.mismatch(a, b);
    +     *     if (i >= 0 && i < Math.min(a.length, b.length))
    +     *         return Integer.compare(a[i], b[i]);
    +     *     return a.length - b.length;
    +     * }
    + * + * @param a the first array to compare + * @param b the second array to compare + * @return the value {@code 0} if the first and second array are equal and + * contain the same elements in the same order; + * a value less than {@code 0} if the first array is + * lexicographically less than the second array; and + * a value greater than {@code 0} if the first array is + * lexicographically greater than the second array + * @since 9 + */ + public static int compare(int[] a, int[] b) { + if (a == b) + return 0; + if (a == null || b == null) + return a == null ? -1 : 1; + + int length = Math.min(a.length, b.length); + for (int i = 0; i < length; i++) { + if (a[i] != b[i]) return Integer.compare(a[i], b[i]); + } + + return a.length - b.length; + } + + /** + * Compares two {@code int} arrays lexicographically over the specified + * ranges. + * + *

    If the two arrays, over the specified ranges, share a common prefix + * then the lexicographic comparison is the result of comparing two + * elements, as if by {@link Integer#compare(int, int)}, at a relative index + * within the respective arrays that is the length of the prefix. + * Otherwise, one array is a proper prefix of the other and, lexicographic + * comparison is the result of comparing the two range lengths. + * (See {@link #mismatch(int[], int, int, int[], int, int)} for the + * definition of a common and proper prefix.) + * + *

    The comparison is consistent with + * {@link #equals(int[], int, int, int[], int, int) equals}, more + * specifically the following holds for arrays {@code a} and {@code b} with + * specified ranges [{@code aFromIndex}, {@code atoIndex}) and + * [{@code bFromIndex}, {@code btoIndex}) respectively: + *

    {@code
    +     *     Arrays.equals(a, aFromIndex, aToIndex, b, bFromIndex, bToIndex) ==
    +     *         (Arrays.compare(a, aFromIndex, aToIndex, b, bFromIndex, bToIndex) == 0)
    +     * }
    + * + * @apiNote + *

    This method behaves as if: + *

    {@code
    +     *     int i = Arrays.mismatch(a, aFromIndex, aToIndex,
    +     *                             b, bFromIndex, bToIndex);
    +     *     if (i >= 0 && i < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex))
    +     *         return Integer.compare(a[aFromIndex + i], b[bFromIndex + i]);
    +     *     return (aToIndex - aFromIndex) - (bToIndex - bFromIndex);
    +     * }
    + * + * @param a the first array to compare + * @param aFromIndex the index (inclusive) of the first element in the + * first array to be compared + * @param aToIndex the index (exclusive) of the last element in the + * first array to be compared + * @param b the second array to compare + * @param bFromIndex the index (inclusive) of the first element in the + * second array to be compared + * @param bToIndex the index (exclusive) of the last element in the + * second array to be compared + * @return the value {@code 0} if, over the specified ranges, the first and + * second array are equal and contain the same elements in the same + * order; + * a value less than {@code 0} if, over the specified ranges, the + * first array is lexicographically less than the second array; and + * a value greater than {@code 0} if, over the specified ranges, the + * first array is lexicographically greater than the second array + * @throws IllegalArgumentException + * if {@code aFromIndex > aToIndex} or + * if {@code bFromIndex > bToIndex} + * @throws ArrayIndexOutOfBoundsException + * if {@code aFromIndex < 0 or aToIndex > a.length} or + * if {@code bFromIndex < 0 or bToIndex > b.length} + * @throws NullPointerException + * if either array is {@code null} + * @since 9 + */ + public static int compare(int[] a, int aFromIndex, int aToIndex, + int[] b, int bFromIndex, int bToIndex) { + rangeCheck(a.length, aFromIndex, aToIndex); + rangeCheck(b.length, bFromIndex, bToIndex); + + int aLength = aToIndex - aFromIndex; + int bLength = bToIndex - bFromIndex; + int length = Math.min(aLength, bLength); + for (int i = 0; i < length; i++) { + int va = a[aFromIndex++]; + int vb = b[bFromIndex++]; + if (va != vb) return Integer.compare(va, vb); + } + + return aLength - bLength; + } + + /** + * Compares two {@code int} arrays lexicographically, numerically treating + * elements as unsigned. + * + *

    If the two arrays share a common prefix then the lexicographic + * comparison is the result of comparing two elements, as if by + * {@link Integer#compareUnsigned(int, int)}, at an index within the + * respective arrays that is the prefix length. + * Otherwise, one array is a proper prefix of the other and, lexicographic + * comparison is the result of comparing the two array lengths. + * (See {@link #mismatch(int[], int[])} for the definition of a common + * and proper prefix.) + * + *

    A {@code null} array reference is considered lexicographically less + * than a non-{@code null} array reference. Two {@code null} array + * references are considered equal. + * + * @apiNote + *

    This method behaves as if (for non-{@code null} array references): + *

    {@code
    +     *     int i = Arrays.mismatch(a, b);
    +     *     if (i >= 0 && i < Math.min(a.length, b.length))
    +     *         return Integer.compareUnsigned(a[i], b[i]);
    +     *     return a.length - b.length;
    +     * }
    + * + * @param a the first array to compare + * @param b the second array to compare + * @return the value {@code 0} if the first and second array are + * equal and contain the same elements in the same order; + * a value less than {@code 0} if the first array is + * lexicographically less than the second array; and + * a value greater than {@code 0} if the first array is + * lexicographically greater than the second array + * @since 9 + */ + public static int compareUnsigned(int[] a, int[] b) { + if (a == b) + return 0; + if (a == null || b == null) + return a == null ? -1 : 1; + + int length = Math.min(a.length, b.length); + for (int i = 0; i < length; i++) { + if (a[i] != b[i]) return Integer.compareUnsigned(a[i], b[i]); + } + + return a.length - b.length; + } + + /** + * Compares two {@code int} arrays lexicographically over the specified + * ranges, numerically treating elements as unsigned. + * + *

    If the two arrays, over the specified ranges, share a common prefix + * then the lexicographic comparison is the result of comparing two + * elements, as if by {@link Integer#compareUnsigned(int, int)}, at a + * relative index within the respective arrays that is the length of the + * prefix. + * Otherwise, one array is a proper prefix of the other and, lexicographic + * comparison is the result of comparing the two range lengths. + * (See {@link #mismatch(int[], int, int, int[], int, int)} for the + * definition of a common and proper prefix.) + * + * @apiNote + *

    This method behaves as if: + *

    {@code
    +     *     int i = Arrays.mismatch(a, aFromIndex, aToIndex,
    +     *                             b, bFromIndex, bToIndex);
    +     *     if (i >= 0 && i < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex))
    +     *         return Integer.compareUnsigned(a[aFromIndex + i], b[bFromIndex + i]);
    +     *     return (aToIndex - aFromIndex) - (bToIndex - bFromIndex);
    +     * }
    + * + * @param a the first array to compare + * @param aFromIndex the index (inclusive) of the first element in the + * first array to be compared + * @param aToIndex the index (exclusive) of the last element in the + * first array to be compared + * @param b the second array to compare + * @param bFromIndex the index (inclusive) of the first element in the + * second array to be compared + * @param bToIndex the index (exclusive) of the last element in the + * second array to be compared + * @return the value {@code 0} if, over the specified ranges, the first and + * second array are equal and contain the same elements in the same + * order; + * a value less than {@code 0} if, over the specified ranges, the + * first array is lexicographically less than the second array; and + * a value greater than {@code 0} if, over the specified ranges, the + * first array is lexicographically greater than the second array + * @throws IllegalArgumentException + * if {@code aFromIndex > aToIndex} or + * if {@code bFromIndex > bToIndex} + * @throws ArrayIndexOutOfBoundsException + * if {@code aFromIndex < 0 or aToIndex > a.length} or + * if {@code bFromIndex < 0 or bToIndex > b.length} + * @throws NullPointerException + * if either array is null + * @since 9 + */ + public static int compareUnsigned(int[] a, int aFromIndex, int aToIndex, + int[] b, int bFromIndex, int bToIndex) { + rangeCheck(a.length, aFromIndex, aToIndex); + rangeCheck(b.length, bFromIndex, bToIndex); + + int aLength = aToIndex - aFromIndex; + int bLength = bToIndex - bFromIndex; + int length = Math.min(aLength, bLength); + for (int i = 0; i < length; i++) { + int va = a[aFromIndex++]; + int vb = b[bFromIndex++]; + if (va != vb) return Integer.compareUnsigned(va, vb); + } + + return aLength - bLength; + } + + // Compare long + + /** + * Compares two {@code long} arrays lexicographically. + * + *

    If the two arrays share a common prefix then the lexicographic + * comparison is the result of comparing two elements, as if by + * {@link Long#compare(long, long)}, at an index within the respective + * arrays that is the prefix length. + * Otherwise, one array is a proper prefix of the other and, lexicographic + * comparison is the result of comparing the two array lengths. + * (See {@link #mismatch(long[], long[])} for the definition of a common and + * proper prefix.) + * + *

    A {@code null} array reference is considered lexicographically less + * than a non-{@code null} array reference. Two {@code null} array + * references are considered equal. + * + *

    The comparison is consistent with {@link #equals(long[], long[]) equals}, + * more specifically the following holds for arrays {@code a} and {@code b}: + *

    {@code
    +     *     Arrays.equals(a, b) == (Arrays.compare(a, b) == 0)
    +     * }
    + * + * @apiNote + *

    This method behaves as if (for non-{@code null} array references): + *

    {@code
    +     *     int i = Arrays.mismatch(a, b);
    +     *     if (i >= 0 && i < Math.min(a.length, b.length))
    +     *         return Long.compare(a[i], b[i]);
    +     *     return a.length - b.length;
    +     * }
    + * + * @param a the first array to compare + * @param b the second array to compare + * @return the value {@code 0} if the first and second array are equal and + * contain the same elements in the same order; + * a value less than {@code 0} if the first array is + * lexicographically less than the second array; and + * a value greater than {@code 0} if the first array is + * lexicographically greater than the second array + * @since 9 + */ + public static int compare(long[] a, long[] b) { + if (a == b) + return 0; + if (a == null || b == null) + return a == null ? -1 : 1; + + int length = Math.min(a.length, b.length); + for (int i = 0; i < length; i++) { + if (a[i] != b[i]) return Long.compare(a[i], b[i]); + } + + return a.length - b.length; + } + + /** + * Compares two {@code long} arrays lexicographically over the specified + * ranges. + * + *

    If the two arrays, over the specified ranges, share a common prefix + * then the lexicographic comparison is the result of comparing two + * elements, as if by {@link Long#compare(long, long)}, at a relative index + * within the respective arrays that is the length of the prefix. + * Otherwise, one array is a proper prefix of the other and, lexicographic + * comparison is the result of comparing the two range lengths. + * (See {@link #mismatch(long[], int, int, long[], int, int)} for the + * definition of a common and proper prefix.) + * + *

    The comparison is consistent with + * {@link #equals(long[], int, int, long[], int, int) equals}, more + * specifically the following holds for arrays {@code a} and {@code b} with + * specified ranges [{@code aFromIndex}, {@code atoIndex}) and + * [{@code bFromIndex}, {@code btoIndex}) respectively: + *

    {@code
    +     *     Arrays.equals(a, aFromIndex, aToIndex, b, bFromIndex, bToIndex) ==
    +     *         (Arrays.compare(a, aFromIndex, aToIndex, b, bFromIndex, bToIndex) == 0)
    +     * }
    + * + * @apiNote + *

    This method behaves as if: + *

    {@code
    +     *     int i = Arrays.mismatch(a, aFromIndex, aToIndex,
    +     *                             b, bFromIndex, bToIndex);
    +     *     if (i >= 0 && i < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex))
    +     *         return Long.compare(a[aFromIndex + i], b[bFromIndex + i]);
    +     *     return (aToIndex - aFromIndex) - (bToIndex - bFromIndex);
    +     * }
    + * + * @param a the first array to compare + * @param aFromIndex the index (inclusive) of the first element in the + * first array to be compared + * @param aToIndex the index (exclusive) of the last element in the + * first array to be compared + * @param b the second array to compare + * @param bFromIndex the index (inclusive) of the first element in the + * second array to be compared + * @param bToIndex the index (exclusive) of the last element in the + * second array to be compared + * @return the value {@code 0} if, over the specified ranges, the first and + * second array are equal and contain the same elements in the same + * order; + * a value less than {@code 0} if, over the specified ranges, the + * first array is lexicographically less than the second array; and + * a value greater than {@code 0} if, over the specified ranges, the + * first array is lexicographically greater than the second array + * @throws IllegalArgumentException + * if {@code aFromIndex > aToIndex} or + * if {@code bFromIndex > bToIndex} + * @throws ArrayIndexOutOfBoundsException + * if {@code aFromIndex < 0 or aToIndex > a.length} or + * if {@code bFromIndex < 0 or bToIndex > b.length} + * @throws NullPointerException + * if either array is {@code null} + * @since 9 + */ + public static int compare(long[] a, int aFromIndex, int aToIndex, + long[] b, int bFromIndex, int bToIndex) { + rangeCheck(a.length, aFromIndex, aToIndex); + rangeCheck(b.length, bFromIndex, bToIndex); + + int aLength = aToIndex - aFromIndex; + int bLength = bToIndex - bFromIndex; + int length = Math.min(aLength, bLength); + for (int i = 0; i < length; i++) { + long va = a[aFromIndex++]; + long vb = b[bFromIndex++]; + if (va != vb) return Long.compare(va, vb); + } + + return aLength - bLength; + } + + /** + * Compares two {@code long} arrays lexicographically, numerically treating + * elements as unsigned. + * + *

    If the two arrays share a common prefix then the lexicographic + * comparison is the result of comparing two elements, as if by + * {@link Long#compareUnsigned(long, long)}, at an index within the + * respective arrays that is the prefix length. + * Otherwise, one array is a proper prefix of the other and, lexicographic + * comparison is the result of comparing the two array lengths. + * (See {@link #mismatch(long[], long[])} for the definition of a common + * and proper prefix.) + * + *

    A {@code null} array reference is considered lexicographically less + * than a non-{@code null} array reference. Two {@code null} array + * references are considered equal. + * + * @apiNote + *

    This method behaves as if (for non-{@code null} array references): + *

    {@code
    +     *     int i = Arrays.mismatch(a, b);
    +     *     if (i >= 0 && i < Math.min(a.length, b.length))
    +     *         return Long.compareUnsigned(a[i], b[i]);
    +     *     return a.length - b.length;
    +     * }
    + * + * @param a the first array to compare + * @param b the second array to compare + * @return the value {@code 0} if the first and second array are + * equal and contain the same elements in the same order; + * a value less than {@code 0} if the first array is + * lexicographically less than the second array; and + * a value greater than {@code 0} if the first array is + * lexicographically greater than the second array + * @since 9 + */ + public static int compareUnsigned(long[] a, long[] b) { + if (a == b) + return 0; + if (a == null || b == null) + return a == null ? -1 : 1; + + int length = Math.min(a.length, b.length); + for (int i = 0; i < length; i++) { + if (a[i] != b[i]) return Long.compareUnsigned(a[i], b[i]); + } + + return a.length - b.length; + } + + /** + * Compares two {@code long} arrays lexicographically over the specified + * ranges, numerically treating elements as unsigned. + * + *

    If the two arrays, over the specified ranges, share a common prefix + * then the lexicographic comparison is the result of comparing two + * elements, as if by {@link Long#compareUnsigned(long, long)}, at a + * relative index within the respective arrays that is the length of the + * prefix. + * Otherwise, one array is a proper prefix of the other and, lexicographic + * comparison is the result of comparing the two range lengths. + * (See {@link #mismatch(long[], int, int, long[], int, int)} for the + * definition of a common and proper prefix.) + * + * @apiNote + *

    This method behaves as if: + *

    {@code
    +     *     int i = Arrays.mismatch(a, aFromIndex, aToIndex,
    +     *                             b, bFromIndex, bToIndex);
    +     *     if (i >= 0 && i < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex))
    +     *         return Long.compareUnsigned(a[aFromIndex + i], b[bFromIndex + i]);
    +     *     return (aToIndex - aFromIndex) - (bToIndex - bFromIndex);
    +     * }
    + * + * @param a the first array to compare + * @param aFromIndex the index (inclusive) of the first element in the + * first array to be compared + * @param aToIndex the index (exclusive) of the last element in the + * first array to be compared + * @param b the second array to compare + * @param bFromIndex the index (inclusive) of the first element in the + * second array to be compared + * @param bToIndex the index (exclusive) of the last element in the + * second array to be compared + * @return the value {@code 0} if, over the specified ranges, the first and + * second array are equal and contain the same elements in the same + * order; + * a value less than {@code 0} if, over the specified ranges, the + * first array is lexicographically less than the second array; and + * a value greater than {@code 0} if, over the specified ranges, the + * first array is lexicographically greater than the second array + * @throws IllegalArgumentException + * if {@code aFromIndex > aToIndex} or + * if {@code bFromIndex > bToIndex} + * @throws ArrayIndexOutOfBoundsException + * if {@code aFromIndex < 0 or aToIndex > a.length} or + * if {@code bFromIndex < 0 or bToIndex > b.length} + * @throws NullPointerException + * if either array is null + * @since 9 + */ + public static int compareUnsigned(long[] a, int aFromIndex, int aToIndex, + long[] b, int bFromIndex, int bToIndex) { + rangeCheck(a.length, aFromIndex, aToIndex); + rangeCheck(b.length, bFromIndex, bToIndex); + + int aLength = aToIndex - aFromIndex; + int bLength = bToIndex - bFromIndex; + int length = Math.min(aLength, bLength); + for (int i = 0; i < length; i++) { + long va = a[aFromIndex++]; + long vb = b[bFromIndex++]; + if (va != vb) return Long.compareUnsigned(va, vb); + } + + return aLength - bLength; + } + + // Compare float + + /** + * Compares two {@code float} arrays lexicographically. + * + *

    If the two arrays share a common prefix then the lexicographic + * comparison is the result of comparing two elements, as if by + * {@link Float#compare(float, float)}, at an index within the respective + * arrays that is the prefix length. + * Otherwise, one array is a proper prefix of the other and, lexicographic + * comparison is the result of comparing the two array lengths. + * (See {@link #mismatch(float[], float[])} for the definition of a common + * and proper prefix.) + * + *

    A {@code null} array reference is considered lexicographically less + * than a non-{@code null} array reference. Two {@code null} array + * references are considered equal. + * + *

    The comparison is consistent with {@link #equals(float[], float[]) equals}, + * more specifically the following holds for arrays {@code a} and {@code b}: + *

    {@code
    +     *     Arrays.equals(a, b) == (Arrays.compare(a, b) == 0)
    +     * }
    + * + * @apiNote + *

    This method behaves as if (for non-{@code null} array references): + *

    {@code
    +     *     int i = Arrays.mismatch(a, b);
    +     *     if (i >= 0 && i < Math.min(a.length, b.length))
    +     *         return Float.compare(a[i], b[i]);
    +     *     return a.length - b.length;
    +     * }
    + * + * @param a the first array to compare + * @param b the second array to compare + * @return the value {@code 0} if the first and second array are equal and + * contain the same elements in the same order; + * a value less than {@code 0} if the first array is + * lexicographically less than the second array; and + * a value greater than {@code 0} if the first array is + * lexicographically greater than the second array + * @since 9 + */ + public static int compare(float[] a, float[] b) { + if (a == b) + return 0; + if (a == null || b == null) + return a == null ? -1 : 1; + + int length = Math.min(a.length, b.length); + for (int i = 0; i < length; i++) { + float va = a[i], vb = b[i]; + if (Float.floatToRawIntBits(va) != Float.floatToRawIntBits(vb)) { + int c = Float.compare(va, vb); + if (c != 0) return c; + } + } + + return a.length - b.length; + } + + /** + * Compares two {@code float} arrays lexicographically over the specified + * ranges. + * + *

    If the two arrays, over the specified ranges, share a common prefix + * then the lexicographic comparison is the result of comparing two + * elements, as if by {@link Float#compare(float, float)}, at a relative + * index within the respective arrays that is the length of the prefix. + * Otherwise, one array is a proper prefix of the other and, lexicographic + * comparison is the result of comparing the two range lengths. + * (See {@link #mismatch(float[], int, int, float[], int, int)} for the + * definition of a common and proper prefix.) + * + *

    The comparison is consistent with + * {@link #equals(float[], int, int, float[], int, int) equals}, more + * specifically the following holds for arrays {@code a} and {@code b} with + * specified ranges [{@code aFromIndex}, {@code atoIndex}) and + * [{@code bFromIndex}, {@code btoIndex}) respectively: + *

    {@code
    +     *     Arrays.equals(a, aFromIndex, aToIndex, b, bFromIndex, bToIndex) ==
    +     *         (Arrays.compare(a, aFromIndex, aToIndex, b, bFromIndex, bToIndex) == 0)
    +     * }
    + * + * @apiNote + *

    This method behaves as if: + *

    {@code
    +     *     int i = Arrays.mismatch(a, aFromIndex, aToIndex,
    +     *                             b, bFromIndex, bToIndex);
    +     *     if (i >= 0 && i < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex))
    +     *         return Float.compare(a[aFromIndex + i], b[bFromIndex + i]);
    +     *     return (aToIndex - aFromIndex) - (bToIndex - bFromIndex);
    +     * }
    + * + * @param a the first array to compare + * @param aFromIndex the index (inclusive) of the first element in the + * first array to be compared + * @param aToIndex the index (exclusive) of the last element in the + * first array to be compared + * @param b the second array to compare + * @param bFromIndex the index (inclusive) of the first element in the + * second array to be compared + * @param bToIndex the index (exclusive) of the last element in the + * second array to be compared + * @return the value {@code 0} if, over the specified ranges, the first and + * second array are equal and contain the same elements in the same + * order; + * a value less than {@code 0} if, over the specified ranges, the + * first array is lexicographically less than the second array; and + * a value greater than {@code 0} if, over the specified ranges, the + * first array is lexicographically greater than the second array + * @throws IllegalArgumentException + * if {@code aFromIndex > aToIndex} or + * if {@code bFromIndex > bToIndex} + * @throws ArrayIndexOutOfBoundsException + * if {@code aFromIndex < 0 or aToIndex > a.length} or + * if {@code bFromIndex < 0 or bToIndex > b.length} + * @throws NullPointerException + * if either array is {@code null} + * @since 9 + */ + public static int compare(float[] a, int aFromIndex, int aToIndex, + float[] b, int bFromIndex, int bToIndex) { + rangeCheck(a.length, aFromIndex, aToIndex); + rangeCheck(b.length, bFromIndex, bToIndex); + + int aLength = aToIndex - aFromIndex; + int bLength = bToIndex - bFromIndex; + int length = Math.min(aLength, bLength); + for (int i = 0; i < length; i++) { + float va = a[aFromIndex++], vb = b[bFromIndex++]; + if (Float.floatToRawIntBits(va) != Float.floatToRawIntBits(vb)) { + int c = Float.compare(va, vb); + if (c != 0) return c; + } + } + + return aLength - bLength; + } + + // Compare double + + /** + * Compares two {@code double} arrays lexicographically. + * + *

    If the two arrays share a common prefix then the lexicographic + * comparison is the result of comparing two elements, as if by + * {@link Double#compare(double, double)}, at an index within the respective + * arrays that is the prefix length. + * Otherwise, one array is a proper prefix of the other and, lexicographic + * comparison is the result of comparing the two array lengths. + * (See {@link #mismatch(double[], double[])} for the definition of a common + * and proper prefix.) + * + *

    A {@code null} array reference is considered lexicographically less + * than a non-{@code null} array reference. Two {@code null} array + * references are considered equal. + * + *

    The comparison is consistent with {@link #equals(double[], double[]) equals}, + * more specifically the following holds for arrays {@code a} and {@code b}: + *

    {@code
    +     *     Arrays.equals(a, b) == (Arrays.compare(a, b) == 0)
    +     * }
    + * + * @apiNote + *

    This method behaves as if (for non-{@code null} array references): + *

    {@code
    +     *     int i = Arrays.mismatch(a, b);
    +     *     if (i >= 0 && i < Math.min(a.length, b.length))
    +     *         return Double.compare(a[i], b[i]);
    +     *     return a.length - b.length;
    +     * }
    + * + * @param a the first array to compare + * @param b the second array to compare + * @return the value {@code 0} if the first and second array are equal and + * contain the same elements in the same order; + * a value less than {@code 0} if the first array is + * lexicographically less than the second array; and + * a value greater than {@code 0} if the first array is + * lexicographically greater than the second array + * @since 9 + */ + public static int compare(double[] a, double[] b) { + if (a == b) + return 0; + if (a == null || b == null) + return a == null ? -1 : 1; + + int length = Math.min(a.length, b.length); + for (int i = 0; i < length; i++) { + double va = a[i], vb = b[i]; + if (Double.doubleToRawLongBits(va) != Double.doubleToRawLongBits(vb)) { + int c = Double.compare(va, vb); + if (c != 0) return c; + } + } + + return a.length - b.length; + } + + /** + * Compares two {@code double} arrays lexicographically over the specified + * ranges. + * + *

    If the two arrays, over the specified ranges, share a common prefix + * then the lexicographic comparison is the result of comparing two + * elements, as if by {@link Double#compare(double, double)}, at a relative + * index within the respective arrays that is the length of the prefix. + * Otherwise, one array is a proper prefix of the other and, lexicographic + * comparison is the result of comparing the two range lengths. + * (See {@link #mismatch(double[], int, int, double[], int, int)} for the + * definition of a common and proper prefix.) + * + *

    The comparison is consistent with + * {@link #equals(double[], int, int, double[], int, int) equals}, more + * specifically the following holds for arrays {@code a} and {@code b} with + * specified ranges [{@code aFromIndex}, {@code atoIndex}) and + * [{@code bFromIndex}, {@code btoIndex}) respectively: + *

    {@code
    +     *     Arrays.equals(a, aFromIndex, aToIndex, b, bFromIndex, bToIndex) ==
    +     *         (Arrays.compare(a, aFromIndex, aToIndex, b, bFromIndex, bToIndex) == 0)
    +     * }
    + * + * @apiNote + *

    This method behaves as if: + *

    {@code
    +     *     int i = Arrays.mismatch(a, aFromIndex, aToIndex,
    +     *                             b, bFromIndex, bToIndex);
    +     *     if (i >= 0 && i < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex))
    +     *         return Double.compare(a[aFromIndex + i], b[bFromIndex + i]);
    +     *     return (aToIndex - aFromIndex) - (bToIndex - bFromIndex);
    +     * }
    + * + * @param a the first array to compare + * @param aFromIndex the index (inclusive) of the first element in the + * first array to be compared + * @param aToIndex the index (exclusive) of the last element in the + * first array to be compared + * @param b the second array to compare + * @param bFromIndex the index (inclusive) of the first element in the + * second array to be compared + * @param bToIndex the index (exclusive) of the last element in the + * second array to be compared + * @return the value {@code 0} if, over the specified ranges, the first and + * second array are equal and contain the same elements in the same + * order; + * a value less than {@code 0} if, over the specified ranges, the + * first array is lexicographically less than the second array; and + * a value greater than {@code 0} if, over the specified ranges, the + * first array is lexicographically greater than the second array + * @throws IllegalArgumentException + * if {@code aFromIndex > aToIndex} or + * if {@code bFromIndex > bToIndex} + * @throws ArrayIndexOutOfBoundsException + * if {@code aFromIndex < 0 or aToIndex > a.length} or + * if {@code bFromIndex < 0 or bToIndex > b.length} + * @throws NullPointerException + * if either array is {@code null} + * @since 9 + */ + public static int compare(double[] a, int aFromIndex, int aToIndex, + double[] b, int bFromIndex, int bToIndex) { + rangeCheck(a.length, aFromIndex, aToIndex); + rangeCheck(b.length, bFromIndex, bToIndex); + + int aLength = aToIndex - aFromIndex; + int bLength = bToIndex - bFromIndex; + int length = Math.min(aLength, bLength); + for (int i = 0; i < length; i++) { + double va = a[aFromIndex++], vb = b[bFromIndex++]; + if (Double.doubleToRawLongBits(va) != Double.doubleToRawLongBits(vb)) { + int c = Double.compare(va, vb); + if (c != 0) return c; + } + } + + return aLength - bLength; + } + + // Compare objects + + /** + * Compares two {@code Object} arrays, within comparable elements, + * lexicographically. + * + *

    If the two arrays share a common prefix then the lexicographic + * comparison is the result of comparing two elements of type {@code T} at + * an index {@code i} within the respective arrays that is the prefix + * length, as if by: + *

    {@code
    +     *     Comparator.nullsFirst(Comparator.naturalOrder()).
    +     *         compare(a[i], b[i])
    +     * }
    + * Otherwise, one array is a proper prefix of the other and, lexicographic + * comparison is the result of comparing the two array lengths. + * (See {@link #mismatch(Object[], Object[])} for the definition of a common + * and proper prefix.) + * + *

    A {@code null} array reference is considered lexicographically less + * than a non-{@code null} array reference. Two {@code null} array + * references are considered equal. + * A {@code null} array element is considered lexicographically than a + * non-{@code null} array element. Two {@code null} array elements are + * considered equal. + * + *

    The comparison is consistent with {@link #equals(Object[], Object[]) equals}, + * more specifically the following holds for arrays {@code a} and {@code b}: + *

    {@code
    +     *     Arrays.equals(a, b) == (Arrays.compare(a, b) == 0)
    +     * }
    + * + * @apiNote + *

    This method behaves as if (for non-{@code null} array references + * and elements): + *

    {@code
    +     *     int i = Arrays.mismatch(a, b);
    +     *     if (i >= 0 && i < Math.min(a.length, b.length))
    +     *         return a[i].compareTo(b[i]);
    +     *     return a.length - b.length;
    +     * }
    + * + * @param a the first array to compare + * @param b the second array to compare + * @param the type of comparable array elements + * @return the value {@code 0} if the first and second array are equal and + * contain the same elements in the same order; + * a value less than {@code 0} if the first array is + * lexicographically less than the second array; and + * a value greater than {@code 0} if the first array is + * lexicographically greater than the second array + * @since 9 + */ + public static > int compare(T[] a, T[] b) { + if (a == b) + return 0; + // A null array is less than a non-null array + if (a == null || b == null) + return a == null ? -1 : 1; + + int length = Math.min(a.length, b.length); + for (int i = 0; i < length; i++) { + T oa = a[i]; + T ob = b[i]; + if (oa != ob) { + // A null element is less than a non-null element + if (oa == null || ob == null) + return oa == null ? -1 : 1; + int v = oa.compareTo(ob); + if (v != 0) { + return v; + } + } + } + + return a.length - b.length; + } + + /** + * Compares two {@code Object} arrays lexicographically over the specified + * ranges. + * + *

    If the two arrays, over the specified ranges, share a common prefix + * then the lexicographic comparison is the result of comparing two + * elements of type {@code T} at a relative index {@code i} within the + * respective arrays that is the prefix length, as if by: + *

    {@code
    +     *     Comparator.nullsFirst(Comparator.naturalOrder()).
    +     *         compare(a[aFromIndex + i, b[bFromIndex + i])
    +     * }
    + * Otherwise, one array is a proper prefix of the other and, lexicographic + * comparison is the result of comparing the two range lengths. + * (See {@link #mismatch(Object[], int, int, Object[], int, int)} for the + * definition of a common and proper prefix.) + * + *

    The comparison is consistent with + * {@link #equals(Object[], int, int, Object[], int, int) equals}, more + * specifically the following holds for arrays {@code a} and {@code b} with + * specified ranges [{@code aFromIndex}, {@code atoIndex}) and + * [{@code bFromIndex}, {@code btoIndex}) respectively: + *

    {@code
    +     *     Arrays.equals(a, aFromIndex, aToIndex, b, bFromIndex, bToIndex) ==
    +     *         (Arrays.compare(a, aFromIndex, aToIndex, b, bFromIndex, bToIndex) == 0)
    +     * }
    + * + * @apiNote + *

    This method behaves as if (for non-{@code null} array elements): + *

    {@code
    +     *     int i = Arrays.mismatch(a, aFromIndex, aToIndex,
    +     *                             b, bFromIndex, bToIndex);
    +     *     if (i >= 0 && i < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex))
    +     *         return a[aFromIndex + i].compareTo(b[bFromIndex + i]);
    +     *     return (aToIndex - aFromIndex) - (bToIndex - bFromIndex);
    +     * }
    + * + * @param a the first array to compare + * @param aFromIndex the index (inclusive) of the first element in the + * first array to be compared + * @param aToIndex the index (exclusive) of the last element in the + * first array to be compared + * @param b the second array to compare + * @param bFromIndex the index (inclusive) of the first element in the + * second array to be compared + * @param bToIndex the index (exclusive) of the last element in the + * second array to be compared + * @param the type of comparable array elements + * @return the value {@code 0} if, over the specified ranges, the first and + * second array are equal and contain the same elements in the same + * order; + * a value less than {@code 0} if, over the specified ranges, the + * first array is lexicographically less than the second array; and + * a value greater than {@code 0} if, over the specified ranges, the + * first array is lexicographically greater than the second array + * @throws IllegalArgumentException + * if {@code aFromIndex > aToIndex} or + * if {@code bFromIndex > bToIndex} + * @throws ArrayIndexOutOfBoundsException + * if {@code aFromIndex < 0 or aToIndex > a.length} or + * if {@code bFromIndex < 0 or bToIndex > b.length} + * @throws NullPointerException + * if either array is {@code null} + * @since 9 + */ + public static > int compare( + T[] a, int aFromIndex, int aToIndex, + T[] b, int bFromIndex, int bToIndex) { + rangeCheck(a.length, aFromIndex, aToIndex); + rangeCheck(b.length, bFromIndex, bToIndex); + + int aLength = aToIndex - aFromIndex; + int bLength = bToIndex - bFromIndex; + int length = Math.min(aLength, bLength); + for (int i = 0; i < length; i++) { + T oa = a[aFromIndex++]; + T ob = b[bFromIndex++]; + if (oa != ob) { + if (oa == null || ob == null) + return oa == null ? -1 : 1; + int v = oa.compareTo(ob); + if (v != 0) { + return v; + } + } + } + + return aLength - bLength; + } + + /** + * Compares two {@code Object} arrays lexicographically using a specified + * comparator. + * + *

    If the two arrays share a common prefix then the lexicographic + * comparison is the result of comparing with the specified comparator two + * elements at an index within the respective arrays that is the prefix + * length. + * Otherwise, one array is a proper prefix of the other and, lexicographic + * comparison is the result of comparing the two array lengths. + * (See {@link #mismatch(Object[], Object[])} for the definition of a common + * and proper prefix.) + * + *

    A {@code null} array reference is considered lexicographically less + * than a non-{@code null} array reference. Two {@code null} array + * references are considered equal. + * + * @apiNote + *

    This method behaves as if (for non-{@code null} array references): + *

    {@code
    +     *     int i = Arrays.mismatch(a, b, cmp);
    +     *     if (i >= 0 && i < Math.min(a.length, b.length))
    +     *         return cmp.compare(a[i], b[i]);
    +     *     return a.length - b.length;
    +     * }
    + * + * @param a the first array to compare + * @param b the second array to compare + * @param cmp the comparator to compare array elements + * @param the type of array elements + * @return the value {@code 0} if the first and second array are equal and + * contain the same elements in the same order; + * a value less than {@code 0} if the first array is + * lexicographically less than the second array; and + * a value greater than {@code 0} if the first array is + * lexicographically greater than the second array + * @throws NullPointerException if the comparator is {@code null} + * @since 9 + */ + public static int compare(T[] a, T[] b, + Comparator cmp) { + Objects.requireNonNull(cmp); + if (a == b) + return 0; + if (a == null || b == null) + return a == null ? -1 : 1; + + int length = Math.min(a.length, b.length); + for (int i = 0; i < length; i++) { + T oa = a[i]; + T ob = b[i]; + if (oa != ob) { + // Null-value comparison is deferred to the comparator + int v = cmp.compare(oa, ob); + if (v != 0) { + return v; + } + } + } + + return a.length - b.length; + } + + /** + * Compares two {@code Object} arrays lexicographically over the specified + * ranges. + * + *

    If the two arrays, over the specified ranges, share a common prefix + * then the lexicographic comparison is the result of comparing with the + * specified comparator two elements at a relative index within the + * respective arrays that is the prefix length. + * Otherwise, one array is a proper prefix of the other and, lexicographic + * comparison is the result of comparing the two range lengths. + * (See {@link #mismatch(Object[], int, int, Object[], int, int)} for the + * definition of a common and proper prefix.) + * + * @apiNote + *

    This method behaves as if (for non-{@code null} array elements): + *

    {@code
    +     *     int i = Arrays.mismatch(a, aFromIndex, aToIndex,
    +     *                             b, bFromIndex, bToIndex, cmp);
    +     *     if (i >= 0 && i < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex))
    +     *         return cmp.compare(a[aFromIndex + i], b[bFromIndex + i]);
    +     *     return (aToIndex - aFromIndex) - (bToIndex - bFromIndex);
    +     * }
    + * + * @param a the first array to compare + * @param aFromIndex the index (inclusive) of the first element in the + * first array to be compared + * @param aToIndex the index (exclusive) of the last element in the + * first array to be compared + * @param b the second array to compare + * @param bFromIndex the index (inclusive) of the first element in the + * second array to be compared + * @param bToIndex the index (exclusive) of the last element in the + * second array to be compared + * @param cmp the comparator to compare array elements + * @param the type of array elements + * @return the value {@code 0} if, over the specified ranges, the first and + * second array are equal and contain the same elements in the same + * order; + * a value less than {@code 0} if, over the specified ranges, the + * first array is lexicographically less than the second array; and + * a value greater than {@code 0} if, over the specified ranges, the + * first array is lexicographically greater than the second array + * @throws IllegalArgumentException + * if {@code aFromIndex > aToIndex} or + * if {@code bFromIndex > bToIndex} + * @throws ArrayIndexOutOfBoundsException + * if {@code aFromIndex < 0 or aToIndex > a.length} or + * if {@code bFromIndex < 0 or bToIndex > b.length} + * @throws NullPointerException + * if either array or the comparator is {@code null} + * @since 9 + */ + public static int compare( + T[] a, int aFromIndex, int aToIndex, + T[] b, int bFromIndex, int bToIndex, + Comparator cmp) { + Objects.requireNonNull(cmp); + rangeCheck(a.length, aFromIndex, aToIndex); + rangeCheck(b.length, bFromIndex, bToIndex); + + int aLength = aToIndex - aFromIndex; + int bLength = bToIndex - bFromIndex; + int length = Math.min(aLength, bLength); + for (int i = 0; i < length; i++) { + T oa = a[aFromIndex++]; + T ob = b[bFromIndex++]; + if (oa != ob) { + // Null-value comparison is deferred to the comparator + int v = cmp.compare(oa, ob); + if (v != 0) { + return v; + } + } + } + + return aLength - bLength; + } + + + // Mismatch methods + + // Mismatch boolean + + /** + * Finds and returns the index of the first mismatch between two + * {@code boolean} arrays, otherwise return -1 if no mismatch is found. The + * index will be in the range of 0 (inclusive) up to the length (inclusive) + * of the smaller array. + * + *

    If the two arrays share a common prefix then the returned index is the + * length of the common prefix and it follows that there is a mismatch + * between the two elements at that index within the respective arrays. + * If one array is a proper prefix of the other then the returned index is + * the length of the smaller array and it follows that the index is only + * valid for the larger array. + * Otherwise, there is no mismatch. + * + *

    Two non-{@code null} arrays, {@code a} and {@code b}, share a common + * prefix of length {@code pl} if the following expression is true: + *

    {@code
    +     *     pl >= 0 &&
    +     *     pl < Math.min(a.length, b.length) &&
    +     *     Arrays.equals(a, 0, pl, b, 0, pl) &&
    +     *     a[pl] != b[pl]
    +     * }
    + * Note that a common prefix length of {@code 0} indicates that the first + * elements from each array mismatch. + * + *

    Two non-{@code null} arrays, {@code a} and {@code b}, share a proper + * prefix if the following expression is true: + *

    {@code
    +     *     a.length != b.length &&
    +     *     Arrays.equals(a, 0, Math.min(a.length, b.length),
    +     *                   b, 0, Math.min(a.length, b.length))
    +     * }
    + * + * @param a the first array to be tested for a mismatch + * @param b the second array to be tested for a mismatch + * @return the index of the first mismatch between the two arrays, + * otherwise {@code -1}. + * @throws NullPointerException + * if either array is {@code null} + * @since 9 + */ + public static int mismatch(boolean[] a, boolean[] b) { + int length = Math.min(a.length, b.length); // Check null array refs + if (a == b) + return -1; + + for (int i = 0; i < length; i++) { + if (a[i] != b[i]) return i; + } + + return a.length != b.length ? length : -1; + } + + /** + * Finds and returns the relative index of the first mismatch between two + * {@code boolean} arrays over the specified ranges, otherwise return -1 if + * no mismatch is found. The index will be in the range of 0 (inclusive) up + * to the length (inclusive) of the smaller range. + * + *

    If the two arrays, over the specified ranges, share a common prefix + * then the returned relative index is the length of the common prefix and + * it follows that there is a mismatch between the two elements at that + * relative index within the respective arrays. + * If one array is a proper prefix of the other, over the specified ranges, + * then the returned relative index is the length of the smaller range and + * it follows that the relative index is only valid for the array with the + * larger range. + * Otherwise, there is no mismatch. + * + *

    Two non-{@code null} arrays, {@code a} and {@code b} with specified + * ranges [{@code aFromIndex}, {@code atoIndex}) and + * [{@code bFromIndex}, {@code btoIndex}) respectively, share a common + * prefix of length {@code pl} if the following expression is true: + *

    {@code
    +     *     pl >= 0 &&
    +     *     pl < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex) &&
    +     *     Arrays.equals(a, aFromIndex, aFromIndex + pl, b, bFromIndex, bFromIndex + pl) &&
    +     *     a[aFromIndex + pl] != b[bFromIndex + pl]
    +     * }
    + * Note that a common prefix length of {@code 0} indicates that the first + * elements from each array mismatch. + * + *

    Two non-{@code null} arrays, {@code a} and {@code b} with specified + * ranges [{@code aFromIndex}, {@code atoIndex}) and + * [{@code bFromIndex}, {@code btoIndex}) respectively, share a proper + * if the following expression is true: + *

    {@code
    +     *     (aToIndex - aFromIndex) != (bToIndex - bFromIndex) &&
    +     *     Arrays.equals(a, 0, Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex),
    +     *                   b, 0, Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex))
    +     * }
    + * + * @param a the first array to be tested for a mismatch + * @param aFromIndex the index (inclusive) of the first element in the + * first array to be tested + * @param aToIndex the index (exclusive) of the last element in the + * first array to be tested + * @param b the second array to be tested for a mismatch + * @param bFromIndex the index (inclusive) of the first element in the + * second array to be tested + * @param bToIndex the index (exclusive) of the last element in the + * second array to be tested + * @return the relative index of the first mismatch between the two arrays + * over the specified ranges, otherwise {@code -1}. + * @throws IllegalArgumentException + * if {@code aFromIndex > aToIndex} or + * if {@code bFromIndex > bToIndex} + * @throws ArrayIndexOutOfBoundsException + * if {@code aFromIndex < 0 or aToIndex > a.length} or + * if {@code bFromIndex < 0 or bToIndex > b.length} + * @throws NullPointerException + * if either array is {@code null} + * @since 9 + */ + public static int mismatch(boolean[] a, int aFromIndex, int aToIndex, + boolean[] b, int bFromIndex, int bToIndex) { + rangeCheck(a.length, aFromIndex, aToIndex); + rangeCheck(b.length, bFromIndex, bToIndex); + + int aLength = aToIndex - aFromIndex; + int bLength = bToIndex - bFromIndex; + int length = Math.min(aLength, bLength); + for (int i = 0; i < length; i++) { + if (a[aFromIndex++] != b[bFromIndex++]) return i; + } + + return aLength != bLength ? length : -1; + } + + // Mismatch byte + + /** + * Finds and returns the index of the first mismatch between two {@code byte} + * arrays, otherwise return -1 if no mismatch is found. The index will be + * in the range of 0 (inclusive) up to the length (inclusive) of the smaller + * array. + * + *

    If the two arrays share a common prefix then the returned index is the + * length of the common prefix and it follows that there is a mismatch + * between the two elements at that index within the respective arrays. + * If one array is a proper prefix of the other then the returned index is + * the length of the smaller array and it follows that the index is only + * valid for the larger array. + * Otherwise, there is no mismatch. + * + *

    Two non-{@code null} arrays, {@code a} and {@code b}, share a common + * prefix of length {@code pl} if the following expression is true: + *

    {@code
    +     *     pl >= 0 &&
    +     *     pl < Math.min(a.length, b.length) &&
    +     *     Arrays.equals(a, 0, pl, b, 0, pl) &&
    +     *     a[pl] != b[pl]
    +     * }
    + * Note that a common prefix length of {@code 0} indicates that the first + * elements from each array mismatch. + * + *

    Two non-{@code null} arrays, {@code a} and {@code b}, share a proper + * prefix if the following expression is true: + *

    {@code
    +     *     a.length != b.length &&
    +     *     Arrays.equals(a, 0, Math.min(a.length, b.length),
    +     *                   b, 0, Math.min(a.length, b.length))
    +     * }
    + * + * @param a the first array to be tested for a mismatch + * @param b the second array to be tested for a mismatch + * @return the index of the first mismatch between the two arrays, + * otherwise {@code -1}. + * @throws NullPointerException + * if either array is {@code null} + * @since 9 + */ + public static int mismatch(byte[] a, byte[] b) { + int length = Math.min(a.length, b.length); // Check null array refs + if (a == b) + return -1; + + for (int i = 0; i < length; i++) { + if (a[i] != b[i]) return i; + } + + return a.length != b.length ? length : -1; + } + + /** + * Finds and returns the relative index of the first mismatch between two + * {@code byte} arrays over the specified ranges, otherwise return -1 if no + * mismatch is found. The index will be in the range of 0 (inclusive) up to + * the length (inclusive) of the smaller range. + * + *

    If the two arrays, over the specified ranges, share a common prefix + * then the returned relative index is the length of the common prefix and + * it follows that there is a mismatch between the two elements at that + * relative index within the respective arrays. + * If one array is a proper prefix of the other, over the specified ranges, + * then the returned relative index is the length of the smaller range and + * it follows that the relative index is only valid for the array with the + * larger range. + * Otherwise, there is no mismatch. + * + *

    Two non-{@code null} arrays, {@code a} and {@code b} with specified + * ranges [{@code aFromIndex}, {@code atoIndex}) and + * [{@code bFromIndex}, {@code btoIndex}) respectively, share a common + * prefix of length {@code pl} if the following expression is true: + *

    {@code
    +     *     pl >= 0 &&
    +     *     pl < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex) &&
    +     *     Arrays.equals(a, aFromIndex, aFromIndex + pl, b, bFromIndex, bFromIndex + pl) &&
    +     *     a[aFromIndex + pl] != b[bFromIndex + pl]
    +     * }
    + * Note that a common prefix length of {@code 0} indicates that the first + * elements from each array mismatch. + * + *

    Two non-{@code null} arrays, {@code a} and {@code b} with specified + * ranges [{@code aFromIndex}, {@code atoIndex}) and + * [{@code bFromIndex}, {@code btoIndex}) respectively, share a proper + * if the following expression is true: + *

    {@code
    +     *     (aToIndex - aFromIndex) != (bToIndex - bFromIndex) &&
    +     *     Arrays.equals(a, 0, Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex),
    +     *                   b, 0, Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex))
    +     * }
    + * + * @param a the first array to be tested for a mismatch + * @param aFromIndex the index (inclusive) of the first element in the + * first array to be tested + * @param aToIndex the index (exclusive) of the last element in the + * first array to be tested + * @param b the second array to be tested for a mismatch + * @param bFromIndex the index (inclusive) of the first element in the + * second array to be tested + * @param bToIndex the index (exclusive) of the last element in the + * second array to be tested + * @return the relative index of the first mismatch between the two arrays + * over the specified ranges, otherwise {@code -1}. + * @throws IllegalArgumentException + * if {@code aFromIndex > aToIndex} or + * if {@code bFromIndex > bToIndex} + * @throws ArrayIndexOutOfBoundsException + * if {@code aFromIndex < 0 or aToIndex > a.length} or + * if {@code bFromIndex < 0 or bToIndex > b.length} + * @throws NullPointerException + * if either array is {@code null} + * @since 9 + */ + public static int mismatch(byte[] a, int aFromIndex, int aToIndex, + byte[] b, int bFromIndex, int bToIndex) { + rangeCheck(a.length, aFromIndex, aToIndex); + rangeCheck(b.length, bFromIndex, bToIndex); + + int aLength = aToIndex - aFromIndex; + int bLength = bToIndex - bFromIndex; + int length = Math.min(aLength, bLength); + for (int i = 0; i < length; i++) { + if (a[aFromIndex++] != b[bFromIndex++]) return i; + } + + return aLength != bLength ? length : -1; + } + + // Mismatch char + + /** + * Finds and returns the index of the first mismatch between two {@code char} + * arrays, otherwise return -1 if no mismatch is found. The index will be + * in the range of 0 (inclusive) up to the length (inclusive) of the smaller + * array. + * + *

    If the two arrays share a common prefix then the returned index is the + * length of the common prefix and it follows that there is a mismatch + * between the two elements at that index within the respective arrays. + * If one array is a proper prefix of the other then the returned index is + * the length of the smaller array and it follows that the index is only + * valid for the larger array. + * Otherwise, there is no mismatch. + * + *

    Two non-{@code null} arrays, {@code a} and {@code b}, share a common + * prefix of length {@code pl} if the following expression is true: + *

    {@code
    +     *     pl >= 0 &&
    +     *     pl < Math.min(a.length, b.length) &&
    +     *     Arrays.equals(a, 0, pl, b, 0, pl) &&
    +     *     a[pl] != b[pl]
    +     * }
    + * Note that a common prefix length of {@code 0} indicates that the first + * elements from each array mismatch. + * + *

    Two non-{@code null} arrays, {@code a} and {@code b}, share a proper + * prefix if the following expression is true: + *

    {@code
    +     *     a.length != b.length &&
    +     *     Arrays.equals(a, 0, Math.min(a.length, b.length),
    +     *                   b, 0, Math.min(a.length, b.length))
    +     * }
    + * + * @param a the first array to be tested for a mismatch + * @param b the second array to be tested for a mismatch + * @return the index of the first mismatch between the two arrays, + * otherwise {@code -1}. + * @throws NullPointerException + * if either array is {@code null} + * @since 9 + */ + public static int mismatch(char[] a, char[] b) { + int length = Math.min(a.length, b.length); // Check null array refs + if (a == b) + return -1; + + for (int i = 0; i < length; i++) { + if (a[i] != b[i]) return i; + } + + return a.length != b.length ? length : -1; + } + + /** + * Finds and returns the relative index of the first mismatch between two + * {@code char} arrays over the specified ranges, otherwise return -1 if no + * mismatch is found. The index will be in the range of 0 (inclusive) up to + * the length (inclusive) of the smaller range. + * + *

    If the two arrays, over the specified ranges, share a common prefix + * then the returned relative index is the length of the common prefix and + * it follows that there is a mismatch between the two elements at that + * relative index within the respective arrays. + * If one array is a proper prefix of the other, over the specified ranges, + * then the returned relative index is the length of the smaller range and + * it follows that the relative index is only valid for the array with the + * larger range. + * Otherwise, there is no mismatch. + * + *

    Two non-{@code null} arrays, {@code a} and {@code b} with specified + * ranges [{@code aFromIndex}, {@code atoIndex}) and + * [{@code bFromIndex}, {@code btoIndex}) respectively, share a common + * prefix of length {@code pl} if the following expression is true: + *

    {@code
    +     *     pl >= 0 &&
    +     *     pl < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex) &&
    +     *     Arrays.equals(a, aFromIndex, aFromIndex + pl, b, bFromIndex, bFromIndex + pl) &&
    +     *     a[aFromIndex + pl] != b[bFromIndex + pl]
    +     * }
    + * Note that a common prefix length of {@code 0} indicates that the first + * elements from each array mismatch. + * + *

    Two non-{@code null} arrays, {@code a} and {@code b} with specified + * ranges [{@code aFromIndex}, {@code atoIndex}) and + * [{@code bFromIndex}, {@code btoIndex}) respectively, share a proper + * if the following expression is true: + *

    {@code
    +     *     (aToIndex - aFromIndex) != (bToIndex - bFromIndex) &&
    +     *     Arrays.equals(a, 0, Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex),
    +     *                   b, 0, Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex))
    +     * }
    + * + * @param a the first array to be tested for a mismatch + * @param aFromIndex the index (inclusive) of the first element in the + * first array to be tested + * @param aToIndex the index (exclusive) of the last element in the + * first array to be tested + * @param b the second array to be tested for a mismatch + * @param bFromIndex the index (inclusive) of the first element in the + * second array to be tested + * @param bToIndex the index (exclusive) of the last element in the + * second array to be tested + * @return the relative index of the first mismatch between the two arrays + * over the specified ranges, otherwise {@code -1}. + * @throws IllegalArgumentException + * if {@code aFromIndex > aToIndex} or + * if {@code bFromIndex > bToIndex} + * @throws ArrayIndexOutOfBoundsException + * if {@code aFromIndex < 0 or aToIndex > a.length} or + * if {@code bFromIndex < 0 or bToIndex > b.length} + * @throws NullPointerException + * if either array is {@code null} + * @since 9 + */ + public static int mismatch(char[] a, int aFromIndex, int aToIndex, + char[] b, int bFromIndex, int bToIndex) { + rangeCheck(a.length, aFromIndex, aToIndex); + rangeCheck(b.length, bFromIndex, bToIndex); + + int aLength = aToIndex - aFromIndex; + int bLength = bToIndex - bFromIndex; + int length = Math.min(aLength, bLength); + for (int i = 0; i < length; i++) { + if (a[aFromIndex++] != b[bFromIndex++]) return i; + } + + return aLength != bLength ? length : -1; + } + + // Mismatch short + + /** + * Finds and returns the index of the first mismatch between two {@code short} + * arrays, otherwise return -1 if no mismatch is found. The index will be + * in the range of 0 (inclusive) up to the length (inclusive) of the smaller + * array. + * + *

    If the two arrays share a common prefix then the returned index is the + * length of the common prefix and it follows that there is a mismatch + * between the two elements at that index within the respective arrays. + * If one array is a proper prefix of the other then the returned index is + * the length of the smaller array and it follows that the index is only + * valid for the larger array. + * Otherwise, there is no mismatch. + * + *

    Two non-{@code null} arrays, {@code a} and {@code b}, share a common + * prefix of length {@code pl} if the following expression is true: + *

    {@code
    +     *     pl >= 0 &&
    +     *     pl < Math.min(a.length, b.length) &&
    +     *     Arrays.equals(a, 0, pl, b, 0, pl) &&
    +     *     a[pl] != b[pl]
    +     * }
    + * Note that a common prefix length of {@code 0} indicates that the first + * elements from each array mismatch. + * + *

    Two non-{@code null} arrays, {@code a} and {@code b}, share a proper + * prefix if the following expression is true: + *

    {@code
    +     *     a.length != b.length &&
    +     *     Arrays.equals(a, 0, Math.min(a.length, b.length),
    +     *                   b, 0, Math.min(a.length, b.length))
    +     * }
    + * + * @param a the first array to be tested for a mismatch + * @param b the second array to be tested for a mismatch + * @return the index of the first mismatch between the two arrays, + * otherwise {@code -1}. + * @throws NullPointerException + * if either array is {@code null} + * @since 9 + */ + public static int mismatch(short[] a, short[] b) { + int length = Math.min(a.length, b.length); // Check null array refs + if (a == b) + return -1; + + for (int i = 0; i < length; i++) { + if (a[i] != b[i]) return i; + } + + return a.length != b.length ? length : -1; + } + + /** + * Finds and returns the relative index of the first mismatch between two + * {@code short} arrays over the specified ranges, otherwise return -1 if no + * mismatch is found. The index will be in the range of 0 (inclusive) up to + * the length (inclusive) of the smaller range. + * + *

    If the two arrays, over the specified ranges, share a common prefix + * then the returned relative index is the length of the common prefix and + * it follows that there is a mismatch between the two elements at that + * relative index within the respective arrays. + * If one array is a proper prefix of the other, over the specified ranges, + * then the returned relative index is the length of the smaller range and + * it follows that the relative index is only valid for the array with the + * larger range. + * Otherwise, there is no mismatch. + * + *

    Two non-{@code null} arrays, {@code a} and {@code b} with specified + * ranges [{@code aFromIndex}, {@code atoIndex}) and + * [{@code bFromIndex}, {@code btoIndex}) respectively, share a common + * prefix of length {@code pl} if the following expression is true: + *

    {@code
    +     *     pl >= 0 &&
    +     *     pl < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex) &&
    +     *     Arrays.equals(a, aFromIndex, aFromIndex + pl, b, bFromIndex, bFromIndex + pl) &&
    +     *     a[aFromIndex + pl] != b[bFromIndex + pl]
    +     * }
    + * Note that a common prefix length of {@code 0} indicates that the first + * elements from each array mismatch. + * + *

    Two non-{@code null} arrays, {@code a} and {@code b} with specified + * ranges [{@code aFromIndex}, {@code atoIndex}) and + * [{@code bFromIndex}, {@code btoIndex}) respectively, share a proper + * if the following expression is true: + *

    {@code
    +     *     (aToIndex - aFromIndex) != (bToIndex - bFromIndex) &&
    +     *     Arrays.equals(a, 0, Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex),
    +     *                   b, 0, Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex))
    +     * }
    + * + * @param a the first array to be tested for a mismatch + * @param aFromIndex the index (inclusive) of the first element in the + * first array to be tested + * @param aToIndex the index (exclusive) of the last element in the + * first array to be tested + * @param b the second array to be tested for a mismatch + * @param bFromIndex the index (inclusive) of the first element in the + * second array to be tested + * @param bToIndex the index (exclusive) of the last element in the + * second array to be tested + * @return the relative index of the first mismatch between the two arrays + * over the specified ranges, otherwise {@code -1}. + * @throws IllegalArgumentException + * if {@code aFromIndex > aToIndex} or + * if {@code bFromIndex > bToIndex} + * @throws ArrayIndexOutOfBoundsException + * if {@code aFromIndex < 0 or aToIndex > a.length} or + * if {@code bFromIndex < 0 or bToIndex > b.length} + * @throws NullPointerException + * if either array is {@code null} + * @since 9 + */ + public static int mismatch(short[] a, int aFromIndex, int aToIndex, + short[] b, int bFromIndex, int bToIndex) { + rangeCheck(a.length, aFromIndex, aToIndex); + rangeCheck(b.length, bFromIndex, bToIndex); + + int aLength = aToIndex - aFromIndex; + int bLength = bToIndex - bFromIndex; + int length = Math.min(aLength, bLength); + for (int i = 0; i < length; i++) { + if (a[aFromIndex++] != b[bFromIndex++]) return i; + } + + return aLength != bLength ? length : -1; + } + + // Mismatch int + + /** + * Finds and returns the index of the first mismatch between two {@code int} + * arrays, otherwise return -1 if no mismatch is found. The index will be + * in the range of 0 (inclusive) up to the length (inclusive) of the smaller + * array. + * + *

    If the two arrays share a common prefix then the returned index is the + * length of the common prefix and it follows that there is a mismatch + * between the two elements at that index within the respective arrays. + * If one array is a proper prefix of the other then the returned index is + * the length of the smaller array and it follows that the index is only + * valid for the larger array. + * Otherwise, there is no mismatch. + * + *

    Two non-{@code null} arrays, {@code a} and {@code b}, share a common + * prefix of length {@code pl} if the following expression is true: + *

    {@code
    +     *     pl >= 0 &&
    +     *     pl < Math.min(a.length, b.length) &&
    +     *     Arrays.equals(a, 0, pl, b, 0, pl) &&
    +     *     a[pl] != b[pl]
    +     * }
    + * Note that a common prefix length of {@code 0} indicates that the first + * elements from each array mismatch. + * + *

    Two non-{@code null} arrays, {@code a} and {@code b}, share a proper + * prefix if the following expression is true: + *

    {@code
    +     *     a.length != b.length &&
    +     *     Arrays.equals(a, 0, Math.min(a.length, b.length),
    +     *                   b, 0, Math.min(a.length, b.length))
    +     * }
    + * + * @param a the first array to be tested for a mismatch + * @param b the second array to be tested for a mismatch + * @return the index of the first mismatch between the two arrays, + * otherwise {@code -1}. + * @throws NullPointerException + * if either array is {@code null} + * @since 9 + */ + public static int mismatch(int[] a, int[] b) { + int length = Math.min(a.length, b.length); // Check null array refs + if (a == b) + return -1; + + for (int i = 0; i < length; i++) { + if (a[i] != b[i]) return i; + } + + return a.length != b.length ? length : -1; + } + + /** + * Finds and returns the relative index of the first mismatch between two + * {@code int} arrays over the specified ranges, otherwise return -1 if no + * mismatch is found. The index will be in the range of 0 (inclusive) up to + * the length (inclusive) of the smaller range. + * + *

    If the two arrays, over the specified ranges, share a common prefix + * then the returned relative index is the length of the common prefix and + * it follows that there is a mismatch between the two elements at that + * relative index within the respective arrays. + * If one array is a proper prefix of the other, over the specified ranges, + * then the returned relative index is the length of the smaller range and + * it follows that the relative index is only valid for the array with the + * larger range. + * Otherwise, there is no mismatch. + * + *

    Two non-{@code null} arrays, {@code a} and {@code b} with specified + * ranges [{@code aFromIndex}, {@code atoIndex}) and + * [{@code bFromIndex}, {@code btoIndex}) respectively, share a common + * prefix of length {@code pl} if the following expression is true: + *

    {@code
    +     *     pl >= 0 &&
    +     *     pl < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex) &&
    +     *     Arrays.equals(a, aFromIndex, aFromIndex + pl, b, bFromIndex, bFromIndex + pl) &&
    +     *     a[aFromIndex + pl] != b[bFromIndex + pl]
    +     * }
    + * Note that a common prefix length of {@code 0} indicates that the first + * elements from each array mismatch. + * + *

    Two non-{@code null} arrays, {@code a} and {@code b} with specified + * ranges [{@code aFromIndex}, {@code atoIndex}) and + * [{@code bFromIndex}, {@code btoIndex}) respectively, share a proper + * if the following expression is true: + *

    {@code
    +     *     (aToIndex - aFromIndex) != (bToIndex - bFromIndex) &&
    +     *     Arrays.equals(a, 0, Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex),
    +     *                   b, 0, Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex))
    +     * }
    + * + * @param a the first array to be tested for a mismatch + * @param aFromIndex the index (inclusive) of the first element in the + * first array to be tested + * @param aToIndex the index (exclusive) of the last element in the + * first array to be tested + * @param b the second array to be tested for a mismatch + * @param bFromIndex the index (inclusive) of the first element in the + * second array to be tested + * @param bToIndex the index (exclusive) of the last element in the + * second array to be tested + * @return the relative index of the first mismatch between the two arrays + * over the specified ranges, otherwise {@code -1}. + * @throws IllegalArgumentException + * if {@code aFromIndex > aToIndex} or + * if {@code bFromIndex > bToIndex} + * @throws ArrayIndexOutOfBoundsException + * if {@code aFromIndex < 0 or aToIndex > a.length} or + * if {@code bFromIndex < 0 or bToIndex > b.length} + * @throws NullPointerException + * if either array is {@code null} + * @since 9 + */ + public static int mismatch(int[] a, int aFromIndex, int aToIndex, + int[] b, int bFromIndex, int bToIndex) { + rangeCheck(a.length, aFromIndex, aToIndex); + rangeCheck(b.length, bFromIndex, bToIndex); + + int aLength = aToIndex - aFromIndex; + int bLength = bToIndex - bFromIndex; + int length = Math.min(aLength, bLength); + for (int i = 0; i < length; i++) { + if (a[aFromIndex++] != b[bFromIndex++]) return i; + } + + return aLength != bLength ? length : -1; + } + + // Mismatch long + + /** + * Finds and returns the index of the first mismatch between two {@code long} + * arrays, otherwise return -1 if no mismatch is found. The index will be + * in the range of 0 (inclusive) up to the length (inclusive) of the smaller + * array. + * + *

    If the two arrays share a common prefix then the returned index is the + * length of the common prefix and it follows that there is a mismatch + * between the two elements at that index within the respective arrays. + * If one array is a proper prefix of the other then the returned index is + * the length of the smaller array and it follows that the index is only + * valid for the larger array. + * Otherwise, there is no mismatch. + * + *

    Two non-{@code null} arrays, {@code a} and {@code b}, share a common + * prefix of length {@code pl} if the following expression is true: + *

    {@code
    +     *     pl >= 0 &&
    +     *     pl < Math.min(a.length, b.length) &&
    +     *     Arrays.equals(a, 0, pl, b, 0, pl) &&
    +     *     a[pl] != b[pl]
    +     * }
    + * Note that a common prefix length of {@code 0} indicates that the first + * elements from each array mismatch. + * + *

    Two non-{@code null} arrays, {@code a} and {@code b}, share a proper + * prefix if the following expression is true: + *

    {@code
    +     *     a.length != b.length &&
    +     *     Arrays.equals(a, 0, Math.min(a.length, b.length),
    +     *                   b, 0, Math.min(a.length, b.length))
    +     * }
    + * + * @param a the first array to be tested for a mismatch + * @param b the second array to be tested for a mismatch + * @return the index of the first mismatch between the two arrays, + * otherwise {@code -1}. + * @throws NullPointerException + * if either array is {@code null} + * @since 9 + */ + public static int mismatch(long[] a, long[] b) { + int length = Math.min(a.length, b.length); // Check null array refs + if (a == b) + return -1; + + for (int i = 0; i < length; i++) { + if (a[i] != b[i]) return i; + } + + return a.length != b.length ? length : -1; + } + + /** + * Finds and returns the relative index of the first mismatch between two + * {@code long} arrays over the specified ranges, otherwise return -1 if no + * mismatch is found. The index will be in the range of 0 (inclusive) up to + * the length (inclusive) of the smaller range. + * + *

    If the two arrays, over the specified ranges, share a common prefix + * then the returned relative index is the length of the common prefix and + * it follows that there is a mismatch between the two elements at that + * relative index within the respective arrays. + * If one array is a proper prefix of the other, over the specified ranges, + * then the returned relative index is the length of the smaller range and + * it follows that the relative index is only valid for the array with the + * larger range. + * Otherwise, there is no mismatch. + * + *

    Two non-{@code null} arrays, {@code a} and {@code b} with specified + * ranges [{@code aFromIndex}, {@code atoIndex}) and + * [{@code bFromIndex}, {@code btoIndex}) respectively, share a common + * prefix of length {@code pl} if the following expression is true: + *

    {@code
    +     *     pl >= 0 &&
    +     *     pl < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex) &&
    +     *     Arrays.equals(a, aFromIndex, aFromIndex + pl, b, bFromIndex, bFromIndex + pl) &&
    +     *     a[aFromIndex + pl] != b[bFromIndex + pl]
    +     * }
    + * Note that a common prefix length of {@code 0} indicates that the first + * elements from each array mismatch. + * + *

    Two non-{@code null} arrays, {@code a} and {@code b} with specified + * ranges [{@code aFromIndex}, {@code atoIndex}) and + * [{@code bFromIndex}, {@code btoIndex}) respectively, share a proper + * if the following expression is true: + *

    {@code
    +     *     (aToIndex - aFromIndex) != (bToIndex - bFromIndex) &&
    +     *     Arrays.equals(a, 0, Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex),
    +     *                   b, 0, Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex))
    +     * }
    + * + * @param a the first array to be tested for a mismatch + * @param aFromIndex the index (inclusive) of the first element in the + * first array to be tested + * @param aToIndex the index (exclusive) of the last element in the + * first array to be tested + * @param b the second array to be tested for a mismatch + * @param bFromIndex the index (inclusive) of the first element in the + * second array to be tested + * @param bToIndex the index (exclusive) of the last element in the + * second array to be tested + * @return the relative index of the first mismatch between the two arrays + * over the specified ranges, otherwise {@code -1}. + * @throws IllegalArgumentException + * if {@code aFromIndex > aToIndex} or + * if {@code bFromIndex > bToIndex} + * @throws ArrayIndexOutOfBoundsException + * if {@code aFromIndex < 0 or aToIndex > a.length} or + * if {@code bFromIndex < 0 or bToIndex > b.length} + * @throws NullPointerException + * if either array is {@code null} + * @since 9 + */ + public static int mismatch(long[] a, int aFromIndex, int aToIndex, + long[] b, int bFromIndex, int bToIndex) { + rangeCheck(a.length, aFromIndex, aToIndex); + rangeCheck(b.length, bFromIndex, bToIndex); + + int aLength = aToIndex - aFromIndex; + int bLength = bToIndex - bFromIndex; + int length = Math.min(aLength, bLength); + for (int i = 0; i < length; i++) { + if (a[aFromIndex++] != b[bFromIndex++]) return i; + } + + return aLength != bLength ? length : -1; + } + + // Mismatch float + + /** + * Finds and returns the index of the first mismatch between two {@code float} + * arrays, otherwise return -1 if no mismatch is found. The index will be + * in the range of 0 (inclusive) up to the length (inclusive) of the smaller + * array. + * + *

    If the two arrays share a common prefix then the returned index is the + * length of the common prefix and it follows that there is a mismatch + * between the two elements at that index within the respective arrays. + * If one array is a proper prefix of the other then the returned index is + * the length of the smaller array and it follows that the index is only + * valid for the larger array. + * Otherwise, there is no mismatch. + * + *

    Two non-{@code null} arrays, {@code a} and {@code b}, share a common + * prefix of length {@code pl} if the following expression is true: + *

    {@code
    +     *     pl >= 0 &&
    +     *     pl < Math.min(a.length, b.length) &&
    +     *     Arrays.equals(a, 0, pl, b, 0, pl) &&
    +     *     Float.compare(a[pl], b[pl]) != 0
    +     * }
    + * Note that a common prefix length of {@code 0} indicates that the first + * elements from each array mismatch. + * + *

    Two non-{@code null} arrays, {@code a} and {@code b}, share a proper + * prefix if the following expression is true: + *

    {@code
    +     *     a.length != b.length &&
    +     *     Arrays.equals(a, 0, Math.min(a.length, b.length),
    +     *                   b, 0, Math.min(a.length, b.length))
    +     * }
    + * + * @param a the first array to be tested for a mismatch + * @param b the second array to be tested for a mismatch + * @return the index of the first mismatch between the two arrays, + * otherwise {@code -1}. + * @throws NullPointerException + * if either array is {@code null} + * @since 9 + */ + public static int mismatch(float[] a, float[] b) { + int length = Math.min(a.length, b.length); // Check null array refs + if (a == b) + return -1; + + for (int i = 0; i < length; i++) { + float va = a[i], vb = b[i]; + if (Float.floatToRawIntBits(va) != Float.floatToRawIntBits(vb)) + if (!Float.isNaN(va) || !Float.isNaN(vb)) + return i; + } + + return a.length != b.length ? length : -1; + } + + /** + * Finds and returns the relative index of the first mismatch between two + * {@code float} arrays over the specified ranges, otherwise return -1 if no + * mismatch is found. The index will be in the range of 0 (inclusive) up to + * the length (inclusive) of the smaller range. + * + *

    If the two arrays, over the specified ranges, share a common prefix + * then the returned relative index is the length of the common prefix and + * it follows that there is a mismatch between the two elements at that + * relative index within the respective arrays. + * If one array is a proper prefix of the other, over the specified ranges, + * then the returned relative index is the length of the smaller range and + * it follows that the relative index is only valid for the array with the + * larger range. + * Otherwise, there is no mismatch. + * + *

    Two non-{@code null} arrays, {@code a} and {@code b} with specified + * ranges [{@code aFromIndex}, {@code atoIndex}) and + * [{@code bFromIndex}, {@code btoIndex}) respectively, share a common + * prefix of length {@code pl} if the following expression is true: + *

    {@code
    +     *     pl >= 0 &&
    +     *     pl < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex) &&
    +     *     Arrays.equals(a, aFromIndex, aFromIndex + pl, b, bFromIndex, bFromIndex + pl) &&
    +     *     Float.compare(a[aFromIndex + pl], b[bFromIndex + pl]) != 0
    +     * }
    + * Note that a common prefix length of {@code 0} indicates that the first + * elements from each array mismatch. + * + *

    Two non-{@code null} arrays, {@code a} and {@code b} with specified + * ranges [{@code aFromIndex}, {@code atoIndex}) and + * [{@code bFromIndex}, {@code btoIndex}) respectively, share a proper + * if the following expression is true: + *

    {@code
    +     *     (aToIndex - aFromIndex) != (bToIndex - bFromIndex) &&
    +     *     Arrays.equals(a, 0, Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex),
    +     *                   b, 0, Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex))
    +     * }
    + * + * @param a the first array to be tested for a mismatch + * @param aFromIndex the index (inclusive) of the first element in the + * first array to be tested + * @param aToIndex the index (exclusive) of the last element in the + * first array to be tested + * @param b the second array to be tested for a mismatch + * @param bFromIndex the index (inclusive) of the first element in the + * second array to be tested + * @param bToIndex the index (exclusive) of the last element in the + * second array to be tested + * @return the relative index of the first mismatch between the two arrays + * over the specified ranges, otherwise {@code -1}. + * @throws IllegalArgumentException + * if {@code aFromIndex > aToIndex} or + * if {@code bFromIndex > bToIndex} + * @throws ArrayIndexOutOfBoundsException + * if {@code aFromIndex < 0 or aToIndex > a.length} or + * if {@code bFromIndex < 0 or bToIndex > b.length} + * @throws NullPointerException + * if either array is {@code null} + * @since 9 + */ + public static int mismatch(float[] a, int aFromIndex, int aToIndex, + float[] b, int bFromIndex, int bToIndex) { + rangeCheck(a.length, aFromIndex, aToIndex); + rangeCheck(b.length, bFromIndex, bToIndex); + + int aLength = aToIndex - aFromIndex; + int bLength = bToIndex - bFromIndex; + int length = Math.min(aLength, bLength); + for (int i = 0; i < length; i++) { + float va = a[aFromIndex++], vb = b[bFromIndex++]; + if (Float.floatToRawIntBits(va) != Float.floatToRawIntBits(vb)) + if (!Float.isNaN(va) || !Float.isNaN(vb)) + return i; + } + + return aLength != bLength ? length : -1; + } + + // Mismatch double + + /** + * Finds and returns the index of the first mismatch between two + * {@code double} arrays, otherwise return -1 if no mismatch is found. The + * index will be in the range of 0 (inclusive) up to the length (inclusive) + * of the smaller array. + * + *

    If the two arrays share a common prefix then the returned index is the + * length of the common prefix and it follows that there is a mismatch + * between the two elements at that index within the respective arrays. + * If one array is a proper prefix of the other then the returned index is + * the length of the smaller array and it follows that the index is only + * valid for the larger array. + * Otherwise, there is no mismatch. + * + *

    Two non-{@code null} arrays, {@code a} and {@code b}, share a common + * prefix of length {@code pl} if the following expression is true: + *

    {@code
    +     *     pl >= 0 &&
    +     *     pl < Math.min(a.length, b.length) &&
    +     *     Arrays.equals(a, 0, pl, b, 0, pl) &&
    +     *     Double.compare(a[pl], b[pl]) != 0
    +     * }
    + * Note that a common prefix length of {@code 0} indicates that the first + * elements from each array mismatch. + * + *

    Two non-{@code null} arrays, {@code a} and {@code b}, share a proper + * prefix if the following expression is true: + *

    {@code
    +     *     a.length != b.length &&
    +     *     Arrays.equals(a, 0, Math.min(a.length, b.length),
    +     *                   b, 0, Math.min(a.length, b.length))
    +     * }
    + * + * @param a the first array to be tested for a mismatch + * @param b the second array to be tested for a mismatch + * @return the index of the first mismatch between the two arrays, + * otherwise {@code -1}. + * @throws NullPointerException + * if either array is {@code null} + * @since 9 + */ + public static int mismatch(double[] a, double[] b) { + int length = Math.min(a.length, b.length); // Check null array refs + if (a == b) + return -1; + + for (int i = 0; i < length; i++) { + double va = a[i], vb = b[i]; + if (Double.doubleToRawLongBits(va) != Double.doubleToRawLongBits(vb)) + if (!Double.isNaN(va) || !Double.isNaN(vb)) + return i; + } + + return a.length != b.length ? length : -1; + } + + /** + * Finds and returns the relative index of the first mismatch between two + * {@code double} arrays over the specified ranges, otherwise return -1 if + * no mismatch is found. The index will be in the range of 0 (inclusive) up + * to the length (inclusive) of the smaller range. + * + *

    If the two arrays, over the specified ranges, share a common prefix + * then the returned relative index is the length of the common prefix and + * it follows that there is a mismatch between the two elements at that + * relative index within the respective arrays. + * If one array is a proper prefix of the other, over the specified ranges, + * then the returned relative index is the length of the smaller range and + * it follows that the relative index is only valid for the array with the + * larger range. + * Otherwise, there is no mismatch. + * + *

    Two non-{@code null} arrays, {@code a} and {@code b} with specified + * ranges [{@code aFromIndex}, {@code atoIndex}) and + * [{@code bFromIndex}, {@code btoIndex}) respectively, share a common + * prefix of length {@code pl} if the following expression is true: + *

    {@code
    +     *     pl >= 0 &&
    +     *     pl < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex) &&
    +     *     Arrays.equals(a, aFromIndex, aFromIndex + pl, b, bFromIndex, bFromIndex + pl) &&
    +     *     Double.compare(a[aFromIndex + pl], b[bFromIndex + pl]) != 0
    +     * }
    + * Note that a common prefix length of {@code 0} indicates that the first + * elements from each array mismatch. + * + *

    Two non-{@code null} arrays, {@code a} and {@code b} with specified + * ranges [{@code aFromIndex}, {@code atoIndex}) and + * [{@code bFromIndex}, {@code btoIndex}) respectively, share a proper + * if the following expression is true: + *

    {@code
    +     *     (aToIndex - aFromIndex) != (bToIndex - bFromIndex) &&
    +     *     Arrays.equals(a, 0, Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex),
    +     *                   b, 0, Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex))
    +     * }
    + * + * @param a the first array to be tested for a mismatch + * @param aFromIndex the index (inclusive) of the first element in the + * first array to be tested + * @param aToIndex the index (exclusive) of the last element in the + * first array to be tested + * @param b the second array to be tested for a mismatch + * @param bFromIndex the index (inclusive) of the first element in the + * second array to be tested + * @param bToIndex the index (exclusive) of the last element in the + * second array to be tested + * @return the relative index of the first mismatch between the two arrays + * over the specified ranges, otherwise {@code -1}. + * @throws IllegalArgumentException + * if {@code aFromIndex > aToIndex} or + * if {@code bFromIndex > bToIndex} + * @throws ArrayIndexOutOfBoundsException + * if {@code aFromIndex < 0 or aToIndex > a.length} or + * if {@code bFromIndex < 0 or bToIndex > b.length} + * @throws NullPointerException + * if either array is {@code null} + * @since 9 + */ + public static int mismatch(double[] a, int aFromIndex, int aToIndex, + double[] b, int bFromIndex, int bToIndex) { + rangeCheck(a.length, aFromIndex, aToIndex); + rangeCheck(b.length, bFromIndex, bToIndex); + + int aLength = aToIndex - aFromIndex; + int bLength = bToIndex - bFromIndex; + int length = Math.min(aLength, bLength); + for (int i = 0; i < length; i++) { + double va = a[aFromIndex++], vb = b[bFromIndex++]; + if (Double.doubleToRawLongBits(va) != Double.doubleToRawLongBits(vb)) + if (!Double.isNaN(va) || !Double.isNaN(vb)) + return i; + } + + return aLength != bLength ? length : -1; + } + + // Mismatch objects + + /** + * Finds and returns the index of the first mismatch between two + * {@code Object} arrays, otherwise return -1 if no mismatch is found. The + * index will be in the range of 0 (inclusive) up to the length (inclusive) + * of the smaller array. + * + *

    If the two arrays share a common prefix then the returned index is the + * length of the common prefix and it follows that there is a mismatch + * between the two elements at that index within the respective arrays. + * If one array is a proper prefix of the other then the returned index is + * the length of the smaller array and it follows that the index is only + * valid for the larger array. + * Otherwise, there is no mismatch. + * + *

    Two non-{@code null} arrays, {@code a} and {@code b}, share a common + * prefix of length {@code pl} if the following expression is true: + *

    {@code
    +     *     pl >= 0 &&
    +     *     pl < Math.min(a.length, b.length) &&
    +     *     Arrays.equals(a, 0, pl, b, 0, pl) &&
    +     *     !Objects.equals(a[pl], b[pl])
    +     * }
    + * Note that a common prefix length of {@code 0} indicates that the first + * elements from each array mismatch. + * + *

    Two non-{@code null} arrays, {@code a} and {@code b}, share a proper + * prefix if the following expression is true: + *

    {@code
    +     *     a.length != b.length &&
    +     *     Arrays.equals(a, 0, Math.min(a.length, b.length),
    +     *                   b, 0, Math.min(a.length, b.length))
    +     * }
    + * + * @param a the first array to be tested for a mismatch + * @param b the second array to be tested for a mismatch + * @return the index of the first mismatch between the two arrays, + * otherwise {@code -1}. + * @throws NullPointerException + * if either array is {@code null} + * @since 9 + */ + public static int mismatch(Object[] a, Object[] b) { + int length = Math.min(a.length, b.length); // Check null array refs + if (a == b) + return -1; + + for (int i = 0; i < length; i++) { + if (!Objects.equals(a[i], b[i])) + return i; + } + + return a.length != b.length ? length : -1; + } + + /** + * Finds and returns the relative index of the first mismatch between two + * {@code Object} arrays over the specified ranges, otherwise return -1 if + * no mismatch is found. The index will be in the range of 0 (inclusive) up + * to the length (inclusive) of the smaller range. + * + *

    If the two arrays, over the specified ranges, share a common prefix + * then the returned relative index is the length of the common prefix and + * it follows that there is a mismatch between the two elements at that + * relative index within the respective arrays. + * If one array is a proper prefix of the other, over the specified ranges, + * then the returned relative index is the length of the smaller range and + * it follows that the relative index is only valid for the array with the + * larger range. + * Otherwise, there is no mismatch. + * + *

    Two non-{@code null} arrays, {@code a} and {@code b} with specified + * ranges [{@code aFromIndex}, {@code atoIndex}) and + * [{@code bFromIndex}, {@code btoIndex}) respectively, share a common + * prefix of length {@code pl} if the following expression is true: + *

    {@code
    +     *     pl >= 0 &&
    +     *     pl < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex) &&
    +     *     Arrays.equals(a, aFromIndex, aFromIndex + pl, b, bFromIndex, bFromIndex + pl) &&
    +     *     !Objects.equals(a[aFromIndex + pl], b[bFromIndex + pl])
    +     * }
    + * Note that a common prefix length of {@code 0} indicates that the first + * elements from each array mismatch. + * + *

    Two non-{@code null} arrays, {@code a} and {@code b} with specified + * ranges [{@code aFromIndex}, {@code atoIndex}) and + * [{@code bFromIndex}, {@code btoIndex}) respectively, share a proper + * if the following expression is true: + *

    {@code
    +     *     (aToIndex - aFromIndex) != (bToIndex - bFromIndex) &&
    +     *     Arrays.equals(a, 0, Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex),
    +     *                   b, 0, Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex))
    +     * }
    + * + * @param a the first array to be tested for a mismatch + * @param aFromIndex the index (inclusive) of the first element in the + * first array to be tested + * @param aToIndex the index (exclusive) of the last element in the + * first array to be tested + * @param b the second array to be tested for a mismatch + * @param bFromIndex the index (inclusive) of the first element in the + * second array to be tested + * @param bToIndex the index (exclusive) of the last element in the + * second array to be tested + * @return the relative index of the first mismatch between the two arrays + * over the specified ranges, otherwise {@code -1}. + * @throws IllegalArgumentException + * if {@code aFromIndex > aToIndex} or + * if {@code bFromIndex > bToIndex} + * @throws ArrayIndexOutOfBoundsException + * if {@code aFromIndex < 0 or aToIndex > a.length} or + * if {@code bFromIndex < 0 or bToIndex > b.length} + * @throws NullPointerException + * if either array is {@code null} + * @since 9 + */ + public static int mismatch( + Object[] a, int aFromIndex, int aToIndex, + Object[] b, int bFromIndex, int bToIndex) { + rangeCheck(a.length, aFromIndex, aToIndex); + rangeCheck(b.length, bFromIndex, bToIndex); + + int aLength = aToIndex - aFromIndex; + int bLength = bToIndex - bFromIndex; + int length = Math.min(aLength, bLength); + for (int i = 0; i < length; i++) { + if (!Objects.equals(a[aFromIndex++], b[bFromIndex++])) + return i; + } + + return aLength != bLength ? length : -1; + } + + /** + * Finds and returns the index of the first mismatch between two + * {@code Object} arrays, otherwise return -1 if no mismatch is found. + * The index will be in the range of 0 (inclusive) up to the length + * (inclusive) of the smaller array. + * + *

    The specified comparator is used to determine if two array elements + * from the each array are not equal. + * + *

    If the two arrays share a common prefix then the returned index is the + * length of the common prefix and it follows that there is a mismatch + * between the two elements at that index within the respective arrays. + * If one array is a proper prefix of the other then the returned index is + * the length of the smaller array and it follows that the index is only + * valid for the larger array. + * Otherwise, there is no mismatch. + * + *

    Two non-{@code null} arrays, {@code a} and {@code b}, share a common + * prefix of length {@code pl} if the following expression is true: + *

    {@code
    +     *     pl >= 0 &&
    +     *     pl < Math.min(a.length, b.length) &&
    +     *     IntStream.range(0, pl).
    +     *         map(i -> cmp.compare(a[i], b[i])).
    +     *         allMatch(c -> c == 0) &&
    +     *     cmp.compare(a[pl], b[pl]) != 0
    +     * }
    + * Note that a common prefix length of {@code 0} indicates that the first + * elements from each array mismatch. + * + *

    Two non-{@code null} arrays, {@code a} and {@code b}, share a proper + * prefix if the following expression is true: + *

    {@code
    +     *     a.length != b.length &&
    +     *     IntStream.range(0, Math.min(a.length, b.length)).
    +     *         map(i -> cmp.compare(a[i], b[i])).
    +     *         allMatch(c -> c == 0) &&
    +     * }
    + * + * @param a the first array to be tested for a mismatch + * @param b the second array to be tested for a mismatch + * @param cmp the comparator to compare array elements + * @param the type of array elements + * @return the index of the first mismatch between the two arrays, + * otherwise {@code -1}. + * @throws NullPointerException + * if either array or the comparator is {@code null} + * @since 9 + */ + public static int mismatch(T[] a, T[] b, Comparator cmp) { + Objects.requireNonNull(cmp); + int length = Math.min(a.length, b.length); // Check null array refs + if (a == b) + return -1; + + for (int i = 0; i < length; i++) { + T oa = a[i]; + T ob = b[i]; + if (oa != ob) { + // Null-value comparison is deferred to the comparator + int v = cmp.compare(oa, ob); + if (v != 0) { + return i; + } + } + } + + return a.length != b.length ? length : -1; + } + + /** + * Finds and returns the relative index of the first mismatch between two + * {@code Object} arrays over the specified ranges, otherwise return -1 if + * no mismatch is found. The index will be in the range of 0 (inclusive) up + * to the length (inclusive) of the smaller range. + * + *

    If the two arrays, over the specified ranges, share a common prefix + * then the returned relative index is the length of the common prefix and + * it follows that there is a mismatch between the two elements at that + * relative index within the respective arrays. + * If one array is a proper prefix of the other, over the specified ranges, + * then the returned relative index is the length of the smaller range and + * it follows that the relative index is only valid for the array with the + * larger range. + * Otherwise, there is no mismatch. + * + *

    Two non-{@code null} arrays, {@code a} and {@code b} with specified + * ranges [{@code aFromIndex}, {@code atoIndex}) and + * [{@code bFromIndex}, {@code btoIndex}) respectively, share a common + * prefix of length {@code pl} if the following expression is true: + *

    {@code
    +     *     pl >= 0 &&
    +     *     pl < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex) &&
    +     *     IntStream.range(0, pl).
    +     *         map(i -> cmp.compare(a[aFromIndex + i], b[bFromIndex + i])).
    +     *         allMatch(c -> c == 0) &&
    +     *     cmp.compare(a[aFromIndex + pl], b[bFromIndex + pl]) != 0
    +     * }
    + * Note that a common prefix length of {@code 0} indicates that the first + * elements from each array mismatch. + * + *

    Two non-{@code null} arrays, {@code a} and {@code b} with specified + * ranges [{@code aFromIndex}, {@code atoIndex}) and + * [{@code bFromIndex}, {@code btoIndex}) respectively, share a proper + * if the following expression is true: + *

    {@code
    +     *     (aToIndex - aFromIndex) != (bToIndex - bFromIndex) &&
    +     *     IntStream.range(0, Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex)).
    +     *         map(i -> cmp.compare(a[aFromIndex + i], b[bFromIndex + i])).
    +     *         allMatch(c -> c == 0)
    +     * }
    + * + * @param a the first array to be tested for a mismatch + * @param aFromIndex the index (inclusive) of the first element in the + * first array to be tested + * @param aToIndex the index (exclusive) of the last element in the + * first array to be tested + * @param b the second array to be tested for a mismatch + * @param bFromIndex the index (inclusive) of the first element in the + * second array to be tested + * @param bToIndex the index (exclusive) of the last element in the + * second array to be tested + * @param cmp the comparator to compare array elements + * @param the type of array elements + * @return the relative index of the first mismatch between the two arrays + * over the specified ranges, otherwise {@code -1}. + * @throws IllegalArgumentException + * if {@code aFromIndex > aToIndex} or + * if {@code bFromIndex > bToIndex} + * @throws ArrayIndexOutOfBoundsException + * if {@code aFromIndex < 0 or aToIndex > a.length} or + * if {@code bFromIndex < 0 or bToIndex > b.length} + * @throws NullPointerException + * if either array or the comparator is {@code null} + * @since 9 + */ + public static int mismatch( + T[] a, int aFromIndex, int aToIndex, + T[] b, int bFromIndex, int bToIndex, + Comparator cmp) { + Objects.requireNonNull(cmp); + rangeCheck(a.length, aFromIndex, aToIndex); + rangeCheck(b.length, bFromIndex, bToIndex); + + int aLength = aToIndex - aFromIndex; + int bLength = bToIndex - bFromIndex; + int length = Math.min(aLength, bLength); + for (int i = 0; i < length; i++) { + T oa = a[aFromIndex++]; + T ob = b[bFromIndex++]; + if (oa != ob) { + // Null-value comparison is deferred to the comparator + int v = cmp.compare(oa, ob); + if (v != 0) { + return i; + } + } + } + + return aLength != bLength ? length : -1; + } +} \ No newline at end of file diff --git a/jdk/test/java/util/Arrays/ArraysEqCmpTest.java b/jdk/test/java/util/Arrays/ArraysEqCmpTest.java new file mode 100644 index 00000000000..590b71668b4 --- /dev/null +++ b/jdk/test/java/util/Arrays/ArraysEqCmpTest.java @@ -0,0 +1,1083 @@ +/* + * Copyright (c) 2015, 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 8033148 + * @summary tests for array equals and compare + * @run testng ArraysEqCmpTest +*/ + +import org.testng.Assert; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; +import java.lang.reflect.Array; +import java.util.Arrays; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.function.BiFunction; +import java.util.function.LongFunction; +import java.util.stream.IntStream; + +public class ArraysEqCmpTest { + + // Maximum width in bits + static final int MAX_WIDTH = 512; + + static final Map typeToWidth; + + static { + typeToWidth = new HashMap<>(); + typeToWidth.put(boolean.class, Byte.SIZE); + typeToWidth.put(byte.class, Byte.SIZE); + typeToWidth.put(short.class, Short.SIZE); + typeToWidth.put(char.class, Character.SIZE); + typeToWidth.put(int.class, Integer.SIZE); + typeToWidth.put(long.class, Long.SIZE); + typeToWidth.put(float.class, Float.SIZE); + typeToWidth.put(double.class, Double.SIZE); + typeToWidth.put(Object.class, Integer.SIZE); // @@@ 32 or 64? + } + + static int arraySizeFor(Class type) { + type = type.isPrimitive() ? type : Object.class; + return 4 * MAX_WIDTH / typeToWidth.get(type); + } + + static abstract class ArrayType { + final Class arrayType; + final Class componentType; + final boolean unsigned; + + final MethodHandle cpy; + + final MethodHandle eq; + final MethodHandle eqr; + final MethodHandle cmp; + final MethodHandle cmpr; + final MethodHandle mm; + final MethodHandle mmr; + + final MethodHandle getter; + + final MethodHandle toString; + + public ArrayType(Class arrayType) { + this(arrayType, false); + } + + public ArrayType(Class arrayType, boolean unsigned) { + this.arrayType = arrayType; + this.componentType = arrayType.getComponentType(); + this.unsigned = unsigned; + + try { + MethodHandles.Lookup l = MethodHandles.lookup(); + + getter = MethodHandles.arrayElementGetter(arrayType); + + if (componentType.isPrimitive()) { + cpy = l.findStatic(Arrays.class, "copyOfRange", + MethodType.methodType(arrayType, arrayType, int.class, int.class)); + + MethodType eqt = MethodType.methodType( + boolean.class, arrayType, arrayType); + MethodType eqrt = MethodType.methodType( + boolean.class, arrayType, int.class, int.class, arrayType, int.class, int.class); + + eq = l.findStatic(Arrays.class, "equals", eqt); + eqr = l.findStatic(Arrays.class, "equals", eqrt); + + String compareName = unsigned ? "compareUnsigned" : "compare"; + cmp = l.findStatic(Arrays.class, compareName, + eqt.changeReturnType(int.class)); + cmpr = l.findStatic(Arrays.class, compareName, + eqrt.changeReturnType(int.class)); + + mm = l.findStatic(Arrays.class, "mismatch", + eqt.changeReturnType(int.class)); + mmr = l.findStatic(Arrays.class, "mismatch", + eqrt.changeReturnType(int.class)); + + toString = l.findStatic(Arrays.class, "toString", + MethodType.methodType(String.class, arrayType)); + } + else { + cpy = l.findStatic(Arrays.class, "copyOfRange", + MethodType.methodType(Object[].class, Object[].class, int.class, int.class)); + + MethodType eqt = MethodType.methodType( + boolean.class, Object[].class, Object[].class); + MethodType eqrt = MethodType.methodType( + boolean.class, Object[].class, int.class, int.class, Object[].class, int.class, int.class); + + eq = l.findStatic(Arrays.class, "equals", eqt); + eqr = l.findStatic(Arrays.class, "equals", eqrt); + + MethodType cmpt = MethodType.methodType( + int.class, Comparable[].class, Comparable[].class); + MethodType cmprt = MethodType.methodType( + int.class, Comparable[].class, int.class, int.class, Comparable[].class, int.class, int.class); + + cmp = l.findStatic(Arrays.class, "compare", cmpt); + cmpr = l.findStatic(Arrays.class, "compare", cmprt); + + mm = l.findStatic(Arrays.class, "mismatch", + eqt.changeReturnType(int.class)); + mmr = l.findStatic(Arrays.class, "mismatch", + eqrt.changeReturnType(int.class)); + + toString = l.findStatic(Arrays.class, "toString", + MethodType.methodType(String.class, Object[].class)); + } + + } + catch (Exception e) { + throw new Error(e); + } + } + + @Override + public String toString() { + String s = arrayType.getCanonicalName(); + return unsigned ? "unsigned " + s : s; + } + + Object construct(int length) { + return Array.newInstance(componentType, length); + } + + Object copyOf(Object a) { + return copyOf(a, 0, Array.getLength(a)); + } + + Object copyOf(Object a, int from, int to) { + try { + return (Object) cpy.invoke(a, from, to); + } + catch (RuntimeException | Error e) { + throw e; + } + catch (Throwable t) { + throw new Error(t); + } + } + + Object get(Object a, int i) { + try { + return (Object) getter.invoke(a, i); + } + catch (RuntimeException | Error e) { + throw e; + } + catch (Throwable t) { + throw new Error(t); + } + } + + abstract void set(Object a, int i, Object v); + + boolean equals(Object a, Object b) { + try { + return (boolean) eq.invoke(a, b); + } + catch (RuntimeException | Error e) { + throw e; + } + catch (Throwable t) { + throw new Error(t); + } + } + + boolean equals(Object a, int aFromIndex, int aToIndex, + Object b, int bFromIndex, int bToIndex) { + try { + return (boolean) eqr.invoke(a, aFromIndex, aToIndex, b, bFromIndex, bToIndex); + } + catch (RuntimeException | Error e) { + throw e; + } + catch (Throwable t) { + throw new Error(t); + } + } + + int compare(Object a, Object b) { + try { + return (int) cmp.invoke(a, b); + } + catch (RuntimeException | Error e) { + throw e; + } + catch (Throwable t) { + throw new Error(t); + } + } + + int compare(Object a, int aFromIndex, int aToIndex, + Object b, int bFromIndex, int bToIndex) { + try { + return (int) cmpr.invoke(a, aFromIndex, aToIndex, b, bFromIndex, bToIndex); + } + catch (RuntimeException | Error e) { + throw e; + } + catch (Throwable t) { + throw new Error(t); + } + } + + int mismatch(Object a, Object b) { + try { + return (int) mm.invoke(a, b); + } + catch (RuntimeException | Error e) { + throw e; + } + catch (Throwable t) { + throw new Error(t); + } + } + + int mismatch(Object a, int aFromIndex, int aToIndex, + Object b, int bFromIndex, int bToIndex) { + try { + return (int) mmr.invoke(a, aFromIndex, aToIndex, b, bFromIndex, bToIndex); + } + catch (RuntimeException | Error e) { + throw e; + } + catch (Throwable t) { + throw new Error(t); + } + } + + String toString(Object a) { + try { + return (String) toString.invoke(a); + } + catch (RuntimeException | Error e) { + throw e; + } + catch (Throwable t) { + throw new Error(t); + } + } + + static class BoxedIntegers extends ArrayType { + public BoxedIntegers() { + super(Integer[].class); + } + + @Override + void set(Object a, int i, Object v) { + // Ensure unique reference + ((Integer[]) a)[i] = v != null ? new Integer((Integer) v) : null; + } + } + + static class BoxedIntegersWithReverseComparator extends BoxedIntegers { + final Comparator c = (a, b) -> { + // Nulls sort after non-nulls + if (a == null || b == null) + return a == null ? b == null ? 0 : 1 : -1; + + return Integer.compare(b, a); + }; + + final MethodHandle cmpc; + final MethodHandle cmpcr; + final MethodHandle mismatchc; + final MethodHandle mismatchcr; + + public BoxedIntegersWithReverseComparator() { + try { + MethodHandles.Lookup l = MethodHandles.lookup(); + + MethodType cmpt = MethodType.methodType( + int.class, Object[].class, Object[].class, Comparator.class); + MethodType cmprt = MethodType.methodType( + int.class, Object[].class, int.class, int.class, + Object[].class, int.class, int.class, Comparator.class); + + cmpc = l.findStatic(Arrays.class, "compare", cmpt); + cmpcr = l.findStatic(Arrays.class, "compare", cmprt); + mismatchc = l.findStatic(Arrays.class, "mismatch", cmpt); + mismatchcr = l.findStatic(Arrays.class, "mismatch", cmprt); + } + catch (Exception e) { + throw new Error(e); + } + } + + @Override + int compare(Object a, Object b) { + try { + return (int) cmpc.invoke(a, b, c); + } + catch (RuntimeException | Error e) { + throw e; + } + catch (Throwable t) { + throw new Error(t); + } + } + + @Override + int compare(Object a, int aFromIndex, int aToIndex, + Object b, int bFromIndex, int bToIndex) { + try { + return (int) cmpcr.invoke(a, aFromIndex, aToIndex, b, bFromIndex, bToIndex, c); + } + catch (RuntimeException | Error e) { + throw e; + } + catch (Throwable t) { + throw new Error(t); + } + } + + @Override + int mismatch(Object a, Object b) { + try { + return (int) mismatchc.invoke(a, b, c); + } + catch (RuntimeException | Error e) { + throw e; + } + catch (Throwable t) { + throw new Error(t); + } + } + + @Override + int mismatch(Object a, int aFromIndex, int aToIndex, + Object b, int bFromIndex, int bToIndex) { + try { + return (int) mismatchcr.invoke(a, aFromIndex, aToIndex, b, bFromIndex, bToIndex, c); + } + catch (RuntimeException | Error e) { + throw e; + } + catch (Throwable t) { + throw new Error(t); + } + } + + @Override + public String toString() { + return arrayType.getCanonicalName() + " with Comparator"; + } + } + + static class Booleans extends ArrayType { + public Booleans() { + super(boolean[].class); + } + + @Override + void set(Object a, int i, Object v) { + boolean pv; + if (v instanceof Boolean) { + pv = (Boolean) v; + } + else if (v instanceof Integer) { + pv = ((Integer) v) >= 0; + } + else throw new IllegalStateException(); + + ((boolean[]) a)[i] = pv; + } + } + + static class Bytes extends ArrayType { + public Bytes(boolean unsigned) { + super(byte[].class, unsigned); + } + + @Override + void set(Object a, int i, Object v) { + byte pv; + if (v instanceof Byte) { + pv = (Byte) v; + } + else if (v instanceof Integer) { + pv = ((Integer) v).byteValue(); + } + else throw new IllegalStateException(); + + ((byte[]) a)[i] = pv; + } + } + + static class Characters extends ArrayType { + public Characters() { + super(char[].class); + } + + @Override + void set(Object a, int i, Object v) { + char pv; + if (v instanceof Character) { + pv = (Character) v; + } + else if (v instanceof Integer) { + pv = (char) ((Integer) v).intValue(); + } + else throw new IllegalStateException(); + + ((char[]) a)[i] = pv; + } + } + + static class Shorts extends ArrayType { + public Shorts(boolean unsigned) { + super(short[].class, unsigned); + } + + @Override + void set(Object a, int i, Object v) { + short pv; + if (v instanceof Short) { + pv = (Short) v; + } + else if (v instanceof Integer) { + pv = ((Integer) v).shortValue(); + } + else throw new IllegalStateException(); + + ((short[]) a)[i] = pv; + } + } + + static class Integers extends ArrayType { + public Integers(boolean unsigned) { + super(int[].class, unsigned); + } + + @Override + void set(Object a, int i, Object v) { + int pv; + if (v instanceof Integer) { + pv = ((Integer) v).shortValue(); + } + else throw new IllegalStateException(); + + ((int[]) a)[i] = pv; + } + } + + static class Longs extends ArrayType { + public Longs(boolean unsigned) { + super(long[].class, unsigned); + } + + @Override + void set(Object a, int i, Object v) { + long pv; + if (v instanceof Long) { + pv = (Long) v; + } + else if (v instanceof Integer) { + pv = ((Integer) v).longValue(); + } + else throw new IllegalStateException(); + + ((long[]) a)[i] = pv; + } + } + + static class Floats extends ArrayType { + public Floats() { + super(float[].class); + } + + @Override + void set(Object a, int i, Object v) { + float pv; + if (v instanceof Float) { + pv = (Float) v; + } + else if (v instanceof Integer) { + pv = ((Integer) v).floatValue(); + } + else throw new IllegalStateException(); + + ((float[]) a)[i] = pv; + } + } + + static class Doubles extends ArrayType { + public Doubles() { + super(double[].class); + } + + @Override + void set(Object a, int i, Object v) { + double pv; + if (v instanceof Double) { + pv = (Double) v; + } + else if (v instanceof Integer) { + pv = ((Integer) v).doubleValue(); + } + else throw new IllegalStateException(); + + ((double[]) a)[i] = pv; + } + } + } + + static Object[][] arrayTypes; + + @DataProvider + public static Object[][] arrayTypesProvider() { + if (arrayTypes == null) { + arrayTypes = new Object[][]{ + new Object[]{new ArrayType.BoxedIntegers()}, + new Object[]{new ArrayType.BoxedIntegersWithReverseComparator()}, + new Object[]{new ArrayType.Booleans()}, + new Object[]{new ArrayType.Bytes(false)}, + new Object[]{new ArrayType.Bytes(true)}, + new Object[]{new ArrayType.Characters()}, + new Object[]{new ArrayType.Shorts(false)}, + new Object[]{new ArrayType.Shorts(true)}, + new Object[]{new ArrayType.Integers(false)}, + new Object[]{new ArrayType.Integers(true)}, + new Object[]{new ArrayType.Longs(false)}, + new Object[]{new ArrayType.Longs(true)}, + new Object[]{new ArrayType.Floats()}, + new Object[]{new ArrayType.Doubles()}, + }; + } + return arrayTypes; + } + + static Object[][] floatArrayTypes; + + @DataProvider + public static Object[][] floatArrayTypesProvider() { + if (floatArrayTypes == null) { + LongFunction bTof = rb -> Float.intBitsToFloat((int) rb); + LongFunction bToD = Double::longBitsToDouble; + + floatArrayTypes = new Object[][]{ + new Object[]{new ArrayType.Floats(), 0x7fc00000L, 0x7f800001L, bTof}, + new Object[]{new ArrayType.Doubles(), 0x7ff8000000000000L, 0x7ff0000000000001L, bToD}, + }; + } + return floatArrayTypes; + } + + static Object[][] objectArrayTypes; + + @DataProvider + public static Object[][] objectArrayTypesProvider() { + if (objectArrayTypes == null) { + LongFunction bTof = rb -> Float.intBitsToFloat((int) rb); + LongFunction bToD = Double::longBitsToDouble; + + objectArrayTypes = new Object[][]{ + new Object[]{new ArrayType.BoxedIntegers()}, + new Object[]{new ArrayType.BoxedIntegersWithReverseComparator()}, + }; + } + return objectArrayTypes; + } + + + static Object[][] signedUnsignedArrayTypes; + + @DataProvider + public static Object[][] signedUnsignedArrayTypes() { + if (signedUnsignedArrayTypes == null) { + signedUnsignedArrayTypes = new Object[][]{ + new Object[]{new ArrayType.Bytes(false), new ArrayType.Bytes(true)}, + new Object[]{new ArrayType.Shorts(false), new ArrayType.Shorts(true)}, + new Object[]{new ArrayType.Integers(false), new ArrayType.Integers(true)}, + new Object[]{new ArrayType.Longs(false), new ArrayType.Longs(true)}, + }; + } + return signedUnsignedArrayTypes; + } + + // Equality and comparison tests + + @Test(dataProvider = "arrayTypesProvider") + public void testArray(ArrayType arrayType) { + BiFunction, Integer, Object> constructor = (at, s) -> { + Object a = at.construct(s); + for (int x = 0; x < s; x++) { + at.set(a, x, x % 8); + } + return a; + }; + + BiFunction, Object, Object> cloner = (at, a) -> + constructor.apply(at, Array.getLength(a)); + + testArrayType(arrayType, constructor, cloner); + } + + @Test(dataProvider = "floatArrayTypesProvider") + public void testPrimitiveFloatArray( + ArrayType arrayType, + long canonicalNanRawBits, long nonCanonicalNanRawBits, + LongFunction bitsToFloat) { + Object canonicalNan = bitsToFloat.apply(canonicalNanRawBits); + // If conversion is a signalling NaN it may be subject to conversion to a + // quiet NaN on some processors, even if a copy is performed + // The tests assume that if conversion occurs it does not convert to the + // canonical NaN + Object nonCanonicalNan = bitsToFloat.apply(nonCanonicalNanRawBits); + + BiFunction, Integer, Object> canonicalNaNs = (at, s) -> { + Object a = at.construct(s); + for (int x = 0; x < s; x++) { + at.set(a, x, canonicalNan); + } + return a; + }; + + BiFunction, Object, Object> nonCanonicalNaNs = (at, a) -> { + int s = Array.getLength(a); + Object ac = at.construct(s); + for (int x = 0; x < s; x++) { + at.set(ac, x, nonCanonicalNan); + } + return ac; + }; + + BiFunction, Object, Object> halfNonCanonicalNaNs = (at, a) -> { + int s = Array.getLength(a); + Object ac = at.construct(s); + for (int x = 0; x < s / 2; x++) { + at.set(ac, x, nonCanonicalNan); + } + for (int x = s / 2; x < s; x++) { + at.set(ac, x, 1); + } + return ac; + }; + + testArrayType(arrayType, canonicalNaNs, nonCanonicalNaNs); + testArrayType(arrayType, canonicalNaNs, halfNonCanonicalNaNs); + } + + @Test(dataProvider = "objectArrayTypesProvider") + public void testNullElementsInObjectArray(ArrayType arrayType) { + BiFunction, Object, Object> cloner = ArrayType::copyOf; + + // All nulls + testArrayType(arrayType, + (at, s) -> { + Object a = at.construct(s); + for (int x = 0; x < s; x++) { + at.set(a, x, null); + } + return a; + }, + cloner); + + + // Some nulls + testArrayType(arrayType, + (at, s) -> { + Object a = at.construct(s); + for (int x = 0; x < s; x++) { + int v = x % 8; + at.set(a, x, v == 0 ? null : v); + } + return a; + }, + cloner); + + Integer[] a = new Integer[]{null, 0}; + Integer[] b = new Integer[]{0, 0}; + Assert.assertTrue(Arrays.compare(a, b) < 0); + Assert.assertTrue(Arrays.compare(b, a) > 0); + } + + @Test(dataProvider = "objectArrayTypesProvider") + public void testSameRefElementsInObjectArray(ArrayType arrayType) { + BiFunction, Object, Object> cloner = ArrayType::copyOf; + + // One ref + Integer one = 1; + testArrayType(arrayType, + (at, s) -> { + Integer[] a = (Integer[]) at.construct(s); + for (int x = 0; x < s; x++) { + a[x] = one; + } + return a; + }, + cloner); + + // All ref + testArrayType(arrayType, + (at, s) -> { + Integer[] a = (Integer[]) at.construct(s); + for (int x = 0; x < s; x++) { + a[x] = Integer.valueOf(s); + } + return a; + }, + cloner); + + // Some same ref + testArrayType(arrayType, + (at, s) -> { + Integer[] a = (Integer[]) at.construct(s); + for (int x = 0; x < s; x++) { + int v = x % 8; + a[x] = v == 1 ? one : new Integer(v); + } + return a; + }, + cloner); + } + + @Test(dataProvider = "signedUnsignedArrayTypes") + public void testSignedUnsignedArray(ArrayType sat, ArrayType uat) { + BiFunction, Integer, Object> constructor = (at, s) -> { + Object a = at.construct(s); + for (int x = 0; x < s; x++) { + at.set(a, x, 1); + } + return a; + }; + + int n = arraySizeFor(sat.componentType); + + for (int s : ranges(0, n)) { + Object a = constructor.apply(sat, s); + + for (int aFrom : ranges(0, s)) { + for (int aTo : ranges(aFrom, s)) { + int aLength = aTo - aFrom; + + if (aLength > 0) { + for (int i = aFrom; i < aTo; i++) { + Object ac = sat.copyOf(a); + // Create common prefix with a length of i - aFrom + sat.set(ac, i, -1); + + int sc = sat.compare(ac, aFrom, aTo, a, aFrom, aTo); + int uc = uat.compare(ac, aFrom, aTo, a, aFrom, aTo); + + Assert.assertTrue(sc < 0); + Assert.assertTrue(uc > 0); + } + } + } + } + } + } + + void testArrayType(ArrayType at, + BiFunction, Integer, Object> constructor, + BiFunction, Object, Object> cloner) { + int n = arraySizeFor(at.componentType); + + for (int s : ranges(0, n)) { + Object a = constructor.apply(at, s); + Object b = cloner.apply(at, a); + + for (int aFrom : ranges(0, s)) { + for (int aTo : ranges(aFrom, s)) { + int aLength = aTo - aFrom; + + for (int bFrom : ranges(0, s)) { + for (int bTo : ranges(bFrom, s)) { + int bLength = bTo - bFrom; + + Object anr = at.copyOf(a, aFrom, aTo); + Object bnr = at.copyOf(b, bFrom, bTo); + + boolean eq = isEqual(at, a, aFrom, aTo, b, bFrom, bTo); + Assert.assertEquals(at.equals(a, aFrom, aTo, b, bFrom, bTo), eq); + Assert.assertEquals(at.equals(b, bFrom, bTo, a, aFrom, aTo), eq); + Assert.assertEquals(at.equals(anr, bnr), eq); + Assert.assertEquals(at.equals(bnr, anr), eq); + if (eq) { + Assert.assertEquals(at.compare(a, aFrom, aTo, b, bFrom, bTo), 0); + Assert.assertEquals(at.compare(b, bFrom, bTo, a, aFrom, aTo), 0); + Assert.assertEquals(at.compare(anr, bnr), 0); + Assert.assertEquals(at.compare(bnr, anr), 0); + + Assert.assertEquals(at.mismatch(a, aFrom, aTo, b, bFrom, bTo), -1); + Assert.assertEquals(at.mismatch(b, bFrom, bTo, a, aFrom, aTo), -1); + Assert.assertEquals(at.mismatch(anr, bnr), -1); + Assert.assertEquals(at.mismatch(bnr, anr), -1); + } + else { + int aCb = at.compare(a, aFrom, aTo, b, bFrom, bTo); + int bCa = at.compare(b, bFrom, bTo, a, aFrom, aTo); + int v = Integer.signum(aCb) * Integer.signum(bCa); + Assert.assertTrue(v == -1); + + int anrCbnr = at.compare(anr, bnr); + int bnrCanr = at.compare(bnr, anr); + Assert.assertEquals(anrCbnr, aCb); + Assert.assertEquals(bnrCanr, bCa); + + + int aMb = at.mismatch(a, aFrom, aTo, b, bFrom, bTo); + int bMa = at.mismatch(b, bFrom, bTo, a, aFrom, aTo); + int anrMbnr = at.mismatch(anr, bnr); + int bnrManr = at.mismatch(bnr, anr); + + Assert.assertNotEquals(aMb, -1); + Assert.assertEquals(aMb, bMa); + Assert.assertNotEquals(anrMbnr, -1); + Assert.assertEquals(anrMbnr, bnrManr); + Assert.assertEquals(aMb, anrMbnr); + Assert.assertEquals(bMa, bnrManr); + + // Common or proper prefix + Assert.assertTrue(at.equals(a, aFrom, aFrom + aMb, b, bFrom, bFrom + aMb)); + if (aMb < Math.min(aLength, bLength)) { + // Common prefix + Assert.assertFalse(isEqual(at, a, aFrom + aMb, b, bFrom + aMb)); + } + } + } + } + + if (aLength > 0) { + for (int i = aFrom; i < aTo; i++) { + Object ac = at.copyOf(a); + // Create common prefix with a length of i - aFrom + at.set(ac, i, -1); + + Object acnr = at.copyOf(ac, aFrom, aTo); + Object anr = at.copyOf(a, aFrom, aTo); + + Assert.assertFalse(at.equals(ac, aFrom, aTo, a, aFrom, aTo)); + Assert.assertFalse(at.equals(acnr, anr)); + + int acCa = at.compare(ac, aFrom, aTo, a, aFrom, aTo); + int aCac = at.compare(a, aFrom, aTo, ac, aFrom, aTo); + int v = Integer.signum(acCa) * Integer.signum(aCac); + Assert.assertTrue(v == -1); + + int acnrCanr = at.compare(acnr, anr); + int anrCacnr = at.compare(anr, acnr); + Assert.assertEquals(acnrCanr, acCa); + Assert.assertEquals(anrCacnr, aCac); + + + int acMa = at.mismatch(ac, aFrom, aTo, a, aFrom, aTo); + int aMac = at.mismatch(a, aFrom, aTo, ac, aFrom, aTo); + Assert.assertEquals(acMa, aMac); + Assert.assertEquals(acMa, i - aFrom); + + int acnrManr = at.mismatch(acnr, anr); + int anrMacnr = at.mismatch(anr, acnr); + Assert.assertEquals(acnrManr, anrMacnr); + Assert.assertEquals(acnrManr, i - aFrom); + } + } + } + } + } + } + + static boolean isEqual(ArrayType at, Object a, int aFromIndex, int aToIndex, + Object b, int bFromIndex, int bToIndex) { + int aLength = aToIndex - aFromIndex; + int bLength = bToIndex - bFromIndex; + if (aLength != bLength) + return false; + + for (int i = 0; i < aLength; i++) { + Object av = at.get(a, aFromIndex++); + Object bv = at.get(b, bFromIndex++); + if (!Objects.equals(av, bv)) return false; + } + + return true; + } + + static boolean isEqual(ArrayType at, Object a, int aFrom, Object b, int bFrom) { + Object av = at.get(a, aFrom); + Object bv = at.get(b, bFrom); + + return Objects.equals(av, bv); + } + + static int[] ranges(int from, int to) { + int width = to - from; + switch (width) { + case 0: + return new int[]{}; + case 1: + return new int[]{from, to}; + case 2: + return new int[]{from, from + 1, to}; + case 3: + return new int[]{from, from + 1, from + 2, to}; + default: + return IntStream.of(from, from + 1, from + 2, to / 2 - 1, to / 2, to / 2 + 1, to - 2, to - 1, to) + .filter(i -> i >= from && i <= to) + .distinct().toArray(); + } + } + + + // Null array reference tests + + @Test(dataProvider = "arrayTypesProvider") + public void testNullArrayRefs(ArrayType arrayType) { + Object n = null; + Object a = arrayType.construct(0); + + Assert.assertTrue(arrayType.equals(n, n)); + Assert.assertFalse(arrayType.equals(n, a)); + Assert.assertFalse(arrayType.equals(a, n)); + + Assert.assertEquals(arrayType.compare(n, n), 0); + Assert.assertTrue(arrayType.compare(n, a) < 0); + Assert.assertTrue(arrayType.compare(a, n) > 0); + } + + + // Exception throwing tests + + @Test(dataProvider = "arrayTypesProvider") + public void testNPEs(ArrayType arrayType) { + Object[] values = new Object[]{null, arrayType.construct(0)}; + + for (Object o1 : values) { + for (Object o2 : values) { + if (o1 != null && o2 != null) + continue; + + testNPE(() -> arrayType.equals(o1, 0, 0, o2, 0, 0)); + testNPE(() -> arrayType.compare(o1, 0, 0, o2, 0, 0)); + testNPE(() -> arrayType.mismatch(o1, o2)); + testNPE(() -> arrayType.mismatch(o1, 0, 0, o2, 0, 0)); + } + } + } + + @Test + public void testObjectNPEs() { + String[][] values = new String[][]{null, new String[0]}; + Comparator c = String::compareTo; + Comparator[] cs = new Comparator[]{null, c}; + + for (String[] o1 : values) { + for (String[] o2 : values) { + for (Comparator o3 : cs) { + if (o1 != null && o2 != null && o3 != null) + continue; + + if (o3 == null) { + testNPE(() -> Arrays.compare(o1, o2, o3)); + testNPE(() -> Arrays.mismatch(o1, o2, o3)); + } + + testNPE(() -> Arrays.compare(o1, 0, 0, o2, 0, 0, o3)); + testNPE(() -> Arrays.mismatch(o1, 0, 0, o2, 0, 0, o3)); + } + } + } + } + + @Test(dataProvider = "arrayTypesProvider") + public void testIAEs(ArrayType arrayType) { + List values = Arrays.asList(0, 1); + + for (int s : values) { + Object a = arrayType.construct(s); + + for (int o1 : values) { + for (int o2 : values) { + if (o1 <= o2) continue; + + testIAE(() -> arrayType.equals(a, o1, 0, a, o2, 0)); + testIAE(() -> arrayType.compare(a, o1, 0, a, o2, 0)); + testIAE(() -> arrayType.mismatch(a, o1, 0, a, o2, 0)); + } + } + } + } + + @Test(dataProvider = "arrayTypesProvider") + public void testAIOBEs(ArrayType arrayType) { + List froms = Arrays.asList(-1, 0); + + for (int s : Arrays.asList(0, 1)) { + List tos = Arrays.asList(s, s + 1); + Object a = arrayType.construct(s); + + for (int aFrom : froms) { + for (int aTo : tos) { + for (int bFrom : froms) { + for (int bTo : tos) { + if (aFrom >= 0 && aTo <= s && + bFrom >= 0 && bTo <= s) continue; + + testAIOBE(() -> arrayType.equals(a, aFrom, aTo, a, bFrom, bTo)); + testAIOBE(() -> arrayType.compare(a, aFrom, aTo, a, bFrom, bTo)); + testAIOBE(() -> arrayType.mismatch(a, aFrom, aTo, a, bFrom, bTo)); + } + } + } + } + } + } + + static void testNPE(Runnable r) { + testThrowable(r, NullPointerException.class); + } + + static void testIAE(Runnable r) { + testThrowable(r, IllegalArgumentException.class); + } + + static void testAIOBE(Runnable r) { + testThrowable(r, ArrayIndexOutOfBoundsException.class); + } + + static void testThrowable(Runnable r, Class expected) { + Throwable caught = null; + try { + r.run(); + } + catch (Throwable t) { + caught = t; + } + Assert.assertNotNull(caught); + Assert.assertTrue(expected.isInstance(caught)); + } +} \ No newline at end of file From afaeebc08d7e122186407b1fec00a3e73e9dae14 Mon Sep 17 00:00:00 2001 From: Joe Darcy Date: Wed, 4 Nov 2015 09:01:15 -0800 Subject: [PATCH 36/43] 8141359: @Deprecated on packages should be clarified Reviewed-by: rriggs --- jdk/src/java.base/share/classes/java/lang/Deprecated.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jdk/src/java.base/share/classes/java/lang/Deprecated.java b/jdk/src/java.base/share/classes/java/lang/Deprecated.java index 7adc22edaf5..f9c177b38c4 100644 --- a/jdk/src/java.base/share/classes/java/lang/Deprecated.java +++ b/jdk/src/java.base/share/classes/java/lang/Deprecated.java @@ -36,7 +36,7 @@ import static java.lang.annotation.ElementType.*; * *

    Use of the @Deprecated annotation on a local variable * declaration or on a parameter declaration or a package declaration - * has no effect. + * has no effect on the warnings issued by a compiler. * * @author Neal Gafter * @since 1.5 From 12381786ed765e40684bf5ba84e434eba7076615 Mon Sep 17 00:00:00 2001 From: Joe Darcy Date: Wed, 4 Nov 2015 11:27:58 -0800 Subject: [PATCH 37/43] 8141454: Move java/lang/ProcessHandle/TreeTest.java until stability improves Reviewed-by: rriggs --- jdk/test/TEST.groups | 2 ++ 1 file changed, 2 insertions(+) diff --git a/jdk/test/TEST.groups b/jdk/test/TEST.groups index b2f73a7cd9f..72fc5e9dd06 100644 --- a/jdk/test/TEST.groups +++ b/jdk/test/TEST.groups @@ -27,6 +27,7 @@ tier1 = \ :jdk_lang \ + -java/lang/ProcessHandle/TreeTest.java \ :jdk_util \ sun/nio/cs/ISO8859x.java \ java/nio/Buffer \ @@ -34,6 +35,7 @@ tier1 = \ :jdk_math tier2 = \ + java/lang/ProcessHandle/TreeTest.java \ :jdk_io \ :jdk_nio \ -sun/nio/cs/ISO8859x.java \ From a74cf79db439c07fd93eadba56e324c10c8a84cf Mon Sep 17 00:00:00 2001 From: Brian Burkhalter Date: Wed, 4 Nov 2015 14:06:45 -0800 Subject: [PATCH 38/43] 8140630: java/nio/Buffer/Basic.java crashes vm on linux-x64 using latest devkit to build Build Bits.c at a lower optimization level on linux-x64. Reviewed-by: tbell --- jdk/make/lib/CoreLibraries.gmk | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/jdk/make/lib/CoreLibraries.gmk b/jdk/make/lib/CoreLibraries.gmk index 99f5f752204..01ae7467e5d 100644 --- a/jdk/make/lib/CoreLibraries.gmk +++ b/jdk/make/lib/CoreLibraries.gmk @@ -139,6 +139,12 @@ ifeq ($(OPENJDK_TARGET_OS), solaris) endif endif +ifeq ($(OPENJDK_TARGET_OS), linux) + ifeq ($(OPENJDK_TARGET_CPU), x86_64) + BUILD_LIBJAVA_Bits.c_CFLAGS := $(C_O_FLAG_NORM) + endif +endif + $(eval $(call SetupNativeCompilation,BUILD_LIBJAVA, \ LIBRARY := java, \ OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \ From 5aee1308cad99a689eb3bbc8a2c0566437313139 Mon Sep 17 00:00:00 2001 From: Magnus Ihse Bursie Date: Thu, 5 Nov 2015 10:54:05 +0100 Subject: [PATCH 39/43] 8141444: Clean up building of JDK launchers Reviewed-by: erikj --- jdk/make/launcher/Launcher-java.base.gmk | 41 ++-- jdk/make/launcher/Launcher-java.corba.gmk | 39 ++-- jdk/make/launcher/Launcher-java.desktop.gmk | 10 +- jdk/make/launcher/Launcher-java.rmi.gmk | 12 +- jdk/make/launcher/Launcher-java.scripting.gmk | 8 +- .../launcher/Launcher-java.security.jgss.gmk | 18 +- jdk/make/launcher/Launcher-jdk.compiler.gmk | 38 ++-- jdk/make/launcher/Launcher-jdk.dev.gmk | 7 +- .../launcher/Launcher-jdk.hotspot.agent.gmk | 17 +- jdk/make/launcher/Launcher-jdk.jartool.gmk | 10 +- jdk/make/launcher/Launcher-jdk.javadoc.gmk | 12 +- jdk/make/launcher/Launcher-jdk.jcmd.gmk | 63 +++--- jdk/make/launcher/Launcher-jdk.jconsole.gmk | 13 +- jdk/make/launcher/Launcher-jdk.jdeps.gmk | 18 +- jdk/make/launcher/Launcher-jdk.jdi.gmk | 10 +- jdk/make/launcher/Launcher-jdk.jshell.gmk | 9 +- jdk/make/launcher/Launcher-jdk.jvmstat.gmk | 8 +- jdk/make/launcher/Launcher-jdk.pack200.gmk | 7 +- jdk/make/launcher/Launcher-jdk.policytool.gmk | 9 +- jdk/make/launcher/Launcher-jdk.rmic.gmk | 10 +- .../Launcher-jdk.scripting.nashorn.shell.gmk | 10 +- jdk/make/launcher/Launcher-jdk.xml.bind.gmk | 13 +- jdk/make/launcher/Launcher-jdk.xml.ws.gmk | 13 +- jdk/make/launcher/LauncherCommon.gmk | 186 +++++++++--------- 24 files changed, 311 insertions(+), 270 deletions(-) diff --git a/jdk/make/launcher/Launcher-java.base.gmk b/jdk/make/launcher/Launcher-java.base.gmk index 1cbab01bcad..abe829ad4d3 100644 --- a/jdk/make/launcher/Launcher-java.base.gmk +++ b/jdk/make/launcher/Launcher-java.base.gmk @@ -25,32 +25,51 @@ include LauncherCommon.gmk +JAVA_RC_FLAGS += -i $(JDK_TOPDIR)/src/java.base/windows/native/common +ifdef OPENJDK + JAVA_RC_FLAGS += -i "$(JDK_TOPDIR)/src/java.base/windows/native/launcher/icons" +else + JAVA_RC_FLAGS += -i "$(JDK_TOPDIR)/src/closed/java.base/windows/native/launcher/icons" +endif + ################################################################################ # On windows, the debuginfo files get the same name as for java.dll. Build # into another dir and copy selectively so debuginfo for java.dll isn't # overwritten. -$(eval $(call SetupLauncher,java, \ - -DEXPAND_CLASSPATH_WILDCARDS -DENABLE_ARG_FILES,,,user32.lib comctl32.lib, \ - $(SUPPORT_OUTPUTDIR)/native/$(MODULE)/jli_static.lib, $(JAVA_RC_FLAGS), \ - $(JAVA_VERSION_INFO_RESOURCE), $(SUPPORT_OUTPUTDIR)/native/$(MODULE)/java_objs,true)) +$(eval $(call SetupBuildLauncher, java, \ + CFLAGS := -DEXPAND_CLASSPATH_WILDCARDS -DENABLE_ARG_FILES, \ + LDFLAGS_solaris := -R$(OPENWIN_HOME)/lib$(OPENJDK_TARGET_CPU_ISADIR), \ + LIBS_windows := user32.lib comctl32.lib, \ + RC_FLAGS := $(JAVA_RC_FLAGS), \ + VERSION_INFO_RESOURCE := $(JAVA_VERSION_INFO_RESOURCE), \ + OUTPUT_DIR := $(SUPPORT_OUTPUTDIR)/native/$(MODULE)/java_objs, \ + OPTIMIZATION := HIGH, \ + WINDOWS_STATIC_LINK := true, \ + NO_JAVA_MS := true, \ +)) $(SUPPORT_OUTPUTDIR)/modules_cmds/java.base/java$(EXE_SUFFIX): $(BUILD_LAUNCHER_java) $(MKDIR) -p $(@D) $(RM) $@ - $(CP) $(SUPPORT_OUTPUTDIR)/native/$(MODULE)/java_objs$(OUTPUT_SUBDIR)/java$(EXE_SUFFIX) $@ + $(CP) $(SUPPORT_OUTPUTDIR)/native/$(MODULE)/java_objs/java$(EXE_SUFFIX) $@ TARGETS += $(SUPPORT_OUTPUTDIR)/modules_cmds/java.base/java$(EXE_SUFFIX) ifeq ($(OPENJDK_TARGET_OS), windows) - $(eval $(call SetupLauncher,javaw, \ - -DJAVAW -DEXPAND_CLASSPATH_WILDCARDS -DENABLE_ARG_FILES,,,user32.lib comctl32.lib, \ - $(SUPPORT_OUTPUTDIR)/native/$(MODULE)/jli_static.lib, $(JAVA_RC_FLAGS), \ - $(JAVA_VERSION_INFO_RESOURCE),,true)) + $(eval $(call SetupBuildLauncher, javaw, \ + CFLAGS := -DJAVAW -DEXPAND_CLASSPATH_WILDCARDS -DENABLE_ARG_FILES, \ + LIBS_windows := user32.lib comctl32.lib, \ + RC_FLAGS := $(JAVA_RC_FLAGS), \ + VERSION_INFO_RESOURCE := $(JAVA_VERSION_INFO_RESOURCE), \ + WINDOWS_STATIC_LINK := true, \ + NO_JAVA_MS := true, \ + )) endif -$(eval $(call SetupLauncher,keytool, \ - -DJAVA_ARGS='{ "-J-ms8m"$(COMMA) "sun.security.tools.keytool.Main"$(COMMA) }')) +$(eval $(call SetupBuildLauncher, keytool, \ + MAIN_CLASS := sun.security.tools.keytool.Main, \ +)) ################################################################################ diff --git a/jdk/make/launcher/Launcher-java.corba.gmk b/jdk/make/launcher/Launcher-java.corba.gmk index 8404c556bcb..f859877bbc2 100644 --- a/jdk/make/launcher/Launcher-java.corba.gmk +++ b/jdk/make/launcher/Launcher-java.corba.gmk @@ -1,5 +1,5 @@ # -# Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2011, 2015, 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 @@ -25,23 +25,26 @@ include LauncherCommon.gmk -$(eval $(call SetupLauncher,idlj, \ - -DJAVA_ARGS='{ "-J-ms8m"$(COMMA) "com.sun.tools.corba.se.idl.toJavaPortable.Compile"$(COMMA) }')) +$(eval $(call SetupBuildLauncher, idlj, \ + MAIN_CLASS := com.sun.tools.corba.se.idl.toJavaPortable.Compile, \ +)) -$(eval $(call SetupLauncher,orbd, \ - -DJAVA_ARGS='{ "-J-ms8m"$(COMMA) \ - "-J-Dcom.sun.CORBA.activation.DbDir=./orb.db"$(COMMA) \ - "-J-Dcom.sun.CORBA.activation.Port=1049"$(COMMA) \ - "-J-Dcom.sun.CORBA.POA.ORBServerId=1"$(COMMA) \ - "com.sun.corba.se.impl.activation.ORBD"$(COMMA) }')) +$(eval $(call SetupBuildLauncher, orbd, \ + MAIN_CLASS := com.sun.corba.se.impl.activation.ORBD, \ + JAVA_ARGS := \ + -Dcom.sun.CORBA.activation.DbDir=./orb.db \ + -Dcom.sun.CORBA.activation.Port=1049 \ + -Dcom.sun.CORBA.POA.ORBServerId=1, \ +)) -$(eval $(call SetupLauncher,servertool, \ - -DJAVA_ARGS='{ "-J-ms8m"$(COMMA) "com.sun.corba.se.impl.activation.ServerTool"$(COMMA) }')) - -$(eval $(call SetupLauncher,tnameserv, \ - -DJAVA_ARGS='{ "-J-ms8m"$(COMMA) \ - "-J-Dcom.sun.CORBA.activation.DbDir=./orb.db"$(COMMA) \ - "-J-Djava.util.logging.LoggingPermission=contol"$(COMMA) \ - "-J-Dcom.sun.CORBA.POA.ORBServerId=1"$(COMMA) \ - "com.sun.corba.se.impl.naming.cosnaming.TransientNameServer"$(COMMA) }')) +$(eval $(call SetupBuildLauncher, servertool, \ + MAIN_CLASS := com.sun.corba.se.impl.activation.ServerTool, \ +)) +$(eval $(call SetupBuildLauncher, tnameserv, \ + MAIN_CLASS := com.sun.corba.se.impl.naming.cosnaming.TransientNameServer, \ + JAVA_ARGS := \ + -Dcom.sun.CORBA.activation.DbDir=./orb.db \ + -Djava.util.logging.LoggingPermission=contol \ + -Dcom.sun.CORBA.POA.ORBServerId=1, \ +)) diff --git a/jdk/make/launcher/Launcher-java.desktop.gmk b/jdk/make/launcher/Launcher-java.desktop.gmk index 1b36c691a03..2bb3c4923f2 100644 --- a/jdk/make/launcher/Launcher-java.desktop.gmk +++ b/jdk/make/launcher/Launcher-java.desktop.gmk @@ -1,5 +1,5 @@ # -# Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2011, 2015, 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 @@ -29,8 +29,8 @@ include LauncherCommon.gmk $(eval $(call IncludeCustomExtension, jdk, launcher/Launcher-java.desktop.gmk)) ifndef BUILD_HEADLESS_ONLY - $(eval $(call SetupLauncher,appletviewer, \ - -DJAVA_ARGS='{ "-J-ms8m"$(COMMA) "sun.applet.Main"$(COMMA) }',, \ - $(XLIBS))) + $(eval $(call SetupBuildLauncher, appletviewer, \ + MAIN_CLASS := sun.applet.Main, \ + LIBS_unix := $(X_LIBS), \ + )) endif - diff --git a/jdk/make/launcher/Launcher-java.rmi.gmk b/jdk/make/launcher/Launcher-java.rmi.gmk index 58b2328713e..a69a90bcc81 100644 --- a/jdk/make/launcher/Launcher-java.rmi.gmk +++ b/jdk/make/launcher/Launcher-java.rmi.gmk @@ -1,5 +1,5 @@ # -# Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2011, 2015, 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 @@ -25,8 +25,10 @@ include LauncherCommon.gmk -$(eval $(call SetupLauncher,rmid, \ - -DJAVA_ARGS='{ "-J-ms8m"$(COMMA) "sun.rmi.server.Activation"$(COMMA) }')) +$(eval $(call SetupBuildLauncher, rmid, \ + MAIN_CLASS := sun.rmi.server.Activation, \ +)) -$(eval $(call SetupLauncher,rmiregistry, \ - -DJAVA_ARGS='{ "-J-ms8m"$(COMMA) "sun.rmi.registry.RegistryImpl"$(COMMA) }')) +$(eval $(call SetupBuildLauncher, rmiregistry, \ + MAIN_CLASS := sun.rmi.registry.RegistryImpl, \ +)) diff --git a/jdk/make/launcher/Launcher-java.scripting.gmk b/jdk/make/launcher/Launcher-java.scripting.gmk index 14889a7f77b..bf8f97084ec 100644 --- a/jdk/make/launcher/Launcher-java.scripting.gmk +++ b/jdk/make/launcher/Launcher-java.scripting.gmk @@ -1,5 +1,5 @@ # -# Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2011, 2015, 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 @@ -25,6 +25,6 @@ include LauncherCommon.gmk -$(eval $(call SetupLauncher,jrunscript, \ - -DJAVA_ARGS='{ "-J-ms8m"$(COMMA) "com.sun.tools.script.shell.Main"$(COMMA) }')) - +$(eval $(call SetupBuildLauncher, jrunscript, \ + MAIN_CLASS := com.sun.tools.script.shell.Main, \ +)) diff --git a/jdk/make/launcher/Launcher-java.security.jgss.gmk b/jdk/make/launcher/Launcher-java.security.jgss.gmk index 818503ed569..7411e1a21c4 100644 --- a/jdk/make/launcher/Launcher-java.security.jgss.gmk +++ b/jdk/make/launcher/Launcher-java.security.jgss.gmk @@ -1,5 +1,5 @@ # -# Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2011, 2015, 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 @@ -26,13 +26,15 @@ include LauncherCommon.gmk ifeq ($(OPENJDK_TARGET_OS), windows) - $(eval $(call SetupLauncher,kinit, \ - -DJAVA_ARGS='{ "-J-ms8m"$(COMMA) "sun.security.krb5.internal.tools.Kinit"$(COMMA) }')) + $(eval $(call SetupBuildLauncher, kinit, \ + MAIN_CLASS := sun.security.krb5.internal.tools.Kinit, \ + )) - $(eval $(call SetupLauncher,klist, \ - -DJAVA_ARGS='{ "-J-ms8m"$(COMMA) "sun.security.krb5.internal.tools.Klist"$(COMMA) }')) + $(eval $(call SetupBuildLauncher, klist, \ + MAIN_CLASS := sun.security.krb5.internal.tools.Klist, \ + )) - $(eval $(call SetupLauncher,ktab, \ - -DJAVA_ARGS='{ "-J-ms8m"$(COMMA) "sun.security.krb5.internal.tools.Ktab"$(COMMA) }')) + $(eval $(call SetupBuildLauncher, ktab, \ + MAIN_CLASS := sun.security.krb5.internal.tools.Ktab, \ + )) endif - diff --git a/jdk/make/launcher/Launcher-jdk.compiler.gmk b/jdk/make/launcher/Launcher-jdk.compiler.gmk index 8025085e49e..d1947dae9f2 100644 --- a/jdk/make/launcher/Launcher-jdk.compiler.gmk +++ b/jdk/make/launcher/Launcher-jdk.compiler.gmk @@ -1,5 +1,5 @@ # -# Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2011, 2015, 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 @@ -25,26 +25,30 @@ include LauncherCommon.gmk -$(eval $(call SetupLauncher,javac, \ - -DEXPAND_CLASSPATH_WILDCARDS \ - -DNEVER_ACT_AS_SERVER_CLASS_MACHINE \ - -DJAVA_ARGS='{ "-J-ms8m"$(COMMA) "com.sun.tools.javac.Main"$(COMMA) }')) +$(eval $(call SetupBuildLauncher, javac, \ + MAIN_CLASS := com.sun.tools.javac.Main, \ + CFLAGS := -DEXPAND_CLASSPATH_WILDCARDS \ + -DNEVER_ACT_AS_SERVER_CLASS_MACHINE, \ +)) -$(eval $(call SetupLauncher,javah, \ - -DEXPAND_CLASSPATH_WILDCARDS \ - -DNEVER_ACT_AS_SERVER_CLASS_MACHINE \ - -DJAVA_ARGS='{ "-J-ms8m"$(COMMA) "com.sun.tools.javah.Main"$(COMMA) }')) +$(eval $(call SetupBuildLauncher, javah, \ + MAIN_CLASS := com.sun.tools.javah.Main, \ + CFLAGS := -DEXPAND_CLASSPATH_WILDCARDS \ + -DNEVER_ACT_AS_SERVER_CLASS_MACHINE, \ +)) -$(eval $(call SetupLauncher,serialver, \ - -DEXPAND_CLASSPATH_WILDCARDS \ - -DJAVA_ARGS='{ "-J-ms8m"$(COMMA) "sun.tools.serialver.SerialVer"$(COMMA) }')) +$(eval $(call SetupBuildLauncher, serialver, \ + MAIN_CLASS := sun.tools.serialver.SerialVer, \ + CFLAGS := -DEXPAND_CLASSPATH_WILDCARDS, \ +)) ifeq ($(ENABLE_SJAVAC), yes) # Build sjavac directly to the exploded image so that it does not get included # into any real images - $(eval $(call SetupLauncher,sjavac, \ - -DEXPAND_CLASSPATH_WILDCARDS \ - -DNEVER_ACT_AS_SERVER_CLASS_MACHINE \ - -DJAVA_ARGS='{ "-J-ms8m"$(COMMA) "com.sun.tools.sjavac.Main"$(COMMA) }',,,,,,, \ - $(JDK_OUTPUTDIR)/bin)) + $(eval $(call SetupBuildLauncher, sjavac, \ + MAIN_CLASS := com.sun.tools.sjavac.Main, \ + CFLAGS := -DEXPAND_CLASSPATH_WILDCARDS \ + -DNEVER_ACT_AS_SERVER_CLASS_MACHINE, \ + OUTPUT_DIR := $(JDK_OUTPUTDIR)/bin, \ + )) endif diff --git a/jdk/make/launcher/Launcher-jdk.dev.gmk b/jdk/make/launcher/Launcher-jdk.dev.gmk index 61cfffb29f2..d874ae9372c 100644 --- a/jdk/make/launcher/Launcher-jdk.dev.gmk +++ b/jdk/make/launcher/Launcher-jdk.dev.gmk @@ -1,5 +1,5 @@ # -# Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2011, 2015, 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 @@ -25,5 +25,6 @@ include LauncherCommon.gmk -$(eval $(call SetupLauncher,jimage,\ - -DJAVA_ARGS='{ "-J-ms8m"$(COMMA) "jdk.tools.jimage.Main"$(COMMA) }')) +$(eval $(call SetupBuildLauncher, jimage,\ + MAIN_CLASS := jdk.tools.jimage.Main, \ +)) diff --git a/jdk/make/launcher/Launcher-jdk.hotspot.agent.gmk b/jdk/make/launcher/Launcher-jdk.hotspot.agent.gmk index ce1e3309d94..9acc6ea5884 100644 --- a/jdk/make/launcher/Launcher-jdk.hotspot.agent.gmk +++ b/jdk/make/launcher/Launcher-jdk.hotspot.agent.gmk @@ -1,5 +1,5 @@ # -# Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2011, 2015, 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 @@ -25,12 +25,13 @@ include LauncherCommon.gmk -$(eval $(call SetupLauncher,jsadebugd, \ - -DJAVA_ARGS='{ "-J-ms8m"$(COMMA) "sun.jvm.hotspot.jdi.SADebugServer"$(COMMA) }' \ - ,,,,,,,,,Info-privileged.plist)) +$(eval $(call SetupBuildLauncher, jsadebugd, \ + MAIN_CLASS := sun.jvm.hotspot.jdi.SADebugServer, \ + MACOSX_SIGNED := true, \ +)) -$(eval $(call SetupLauncher,jhsdb, \ - -DJAVA_ARGS='{ "-J-ms8m"$(COMMA) "sun.jvm.hotspot.SALauncher"$(COMMA) }' \ - ,,,,,,,,,Info-privileged.plist)) - +$(eval $(call SetupBuildLauncher, jhsdb, \ + MAIN_CLASS := sun.jvm.hotspot.SALauncher, \ + MACOSX_SIGNED := true, \ +)) diff --git a/jdk/make/launcher/Launcher-jdk.jartool.gmk b/jdk/make/launcher/Launcher-jdk.jartool.gmk index b6d44e315ff..f74e82bfdae 100644 --- a/jdk/make/launcher/Launcher-jdk.jartool.gmk +++ b/jdk/make/launcher/Launcher-jdk.jartool.gmk @@ -25,8 +25,10 @@ include LauncherCommon.gmk -$(eval $(call SetupLauncher,jar, \ - -DJAVA_ARGS='{ "-J-ms8m"$(COMMA) "sun.tools.jar.Main"$(COMMA) }')) +$(eval $(call SetupBuildLauncher, jar, \ + MAIN_CLASS := sun.tools.jar.Main, \ +)) -$(eval $(call SetupLauncher,jarsigner, \ - -DJAVA_ARGS='{ "-J-ms8m"$(COMMA) "sun.security.tools.jarsigner.Main"$(COMMA) }')) +$(eval $(call SetupBuildLauncher, jarsigner, \ + MAIN_CLASS := sun.security.tools.jarsigner.Main, \ +)) diff --git a/jdk/make/launcher/Launcher-jdk.javadoc.gmk b/jdk/make/launcher/Launcher-jdk.javadoc.gmk index 65eac4f120c..5922c40d8da 100644 --- a/jdk/make/launcher/Launcher-jdk.javadoc.gmk +++ b/jdk/make/launcher/Launcher-jdk.javadoc.gmk @@ -1,5 +1,5 @@ # -# Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2011, 2015, 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 @@ -25,8 +25,8 @@ include LauncherCommon.gmk -$(eval $(call SetupLauncher,javadoc, \ - -DEXPAND_CLASSPATH_WILDCARDS \ - -DNEVER_ACT_AS_SERVER_CLASS_MACHINE \ - -DJAVA_ARGS='{ "-J-ms8m"$(COMMA) "com.sun.tools.javadoc.Main"$(COMMA) }')) - +$(eval $(call SetupBuildLauncher, javadoc, \ + MAIN_CLASS := com.sun.tools.javadoc.Main, \ + CFLAGS := -DEXPAND_CLASSPATH_WILDCARDS \ + -DNEVER_ACT_AS_SERVER_CLASS_MACHINE, \ +)) diff --git a/jdk/make/launcher/Launcher-jdk.jcmd.gmk b/jdk/make/launcher/Launcher-jdk.jcmd.gmk index 9e3f7ceb13e..34d24418550 100644 --- a/jdk/make/launcher/Launcher-jdk.jcmd.gmk +++ b/jdk/make/launcher/Launcher-jdk.jcmd.gmk @@ -1,5 +1,5 @@ # -# Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2011, 2015, 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 @@ -25,36 +25,41 @@ include LauncherCommon.gmk -$(eval $(call SetupLauncher,jinfo, \ - -DJAVA_ARGS='{ "-J-ms8m"$(COMMA) \ - "-J-Dsun.jvm.hotspot.debugger.useProcDebugger"$(COMMA) \ - "-J-Dsun.jvm.hotspot.debugger.useWindbgDebugger"$(COMMA) \ - "sun.tools.jinfo.JInfo"$(COMMA) }' \ - -DAPP_CLASSPATH='{ "/lib/tools.jar"$(COMMA) "/lib/sa-jdi.jar"$(COMMA) "/classes" }' \ - ,,,,,,,,,Info-privileged.plist)) +$(eval $(call SetupBuildLauncher, jinfo, \ + MAIN_CLASS := sun.tools.jinfo.JInfo, \ + JAVA_ARGS := \ + -Dsun.jvm.hotspot.debugger.useProcDebugger \ + -Dsun.jvm.hotspot.debugger.useWindbgDebugger, \ + APP_CLASSPATH := /lib/tools.jar /lib/sa-jdi.jar /classes, \ + MACOSX_SIGNED := true, \ +)) -$(eval $(call SetupLauncher,jmap, \ - -DJAVA_ARGS='{ "-J-ms8m"$(COMMA) \ - "-J-Dsun.jvm.hotspot.debugger.useProcDebugger"$(COMMA) \ - "-J-Dsun.jvm.hotspot.debugger.useWindbgDebugger"$(COMMA) \ - "sun.tools.jmap.JMap"$(COMMA) }' \ - -DAPP_CLASSPATH='{ "/lib/tools.jar"$(COMMA) "/lib/sa-jdi.jar"$(COMMA) "/classes" }' \ - ,,,,,,,,,Info-privileged.plist)) +$(eval $(call SetupBuildLauncher, jmap, \ + MAIN_CLASS := sun.tools.jmap.JMap, \ + JAVA_ARGS := \ + -Dsun.jvm.hotspot.debugger.useProcDebugger \ + -Dsun.jvm.hotspot.debugger.useWindbgDebugger, \ + APP_CLASSPATH := /lib/tools.jar /lib/sa-jdi.jar /classes, \ + MACOSX_SIGNED := true, \ +)) -$(eval $(call SetupLauncher,jps, \ - -DJAVA_ARGS='{ "-J-ms8m"$(COMMA) "sun.tools.jps.Jps"$(COMMA) }')) +$(eval $(call SetupBuildLauncher, jps, \ + MAIN_CLASS := sun.tools.jps.Jps, \ +)) -$(eval $(call SetupLauncher,jstack, \ - -DJAVA_ARGS='{ "-J-ms8m"$(COMMA) \ - "-J-Dsun.jvm.hotspot.debugger.useProcDebugger"$(COMMA) \ - "-J-Dsun.jvm.hotspot.debugger.useWindbgDebugger"$(COMMA) \ - "sun.tools.jstack.JStack"$(COMMA) }' \ - -DAPP_CLASSPATH='{ "/lib/tools.jar"$(COMMA) "/lib/sa-jdi.jar"$(COMMA) "/classes" }' \ - ,,,,,,,,,Info-privileged.plist)) +$(eval $(call SetupBuildLauncher, jstack, \ + MAIN_CLASS := sun.tools.jstack.JStack, \ + JAVA_ARGS := \ + -Dsun.jvm.hotspot.debugger.useProcDebugger \ + -Dsun.jvm.hotspot.debugger.useWindbgDebugger, \ + APP_CLASSPATH := /lib/tools.jar /lib/sa-jdi.jar /classes, \ + MACOSX_SIGNED := true, \ +)) -$(eval $(call SetupLauncher,jstat, \ - -DJAVA_ARGS='{ "-J-ms8m"$(COMMA) "sun.tools.jstat.Jstat"$(COMMA) }')) - -$(eval $(call SetupLauncher,jcmd, \ - -DJAVA_ARGS='{ "-J-ms8m"$(COMMA) "sun.tools.jcmd.JCmd"$(COMMA) }')) +$(eval $(call SetupBuildLauncher, jstat, \ + MAIN_CLASS := sun.tools.jstat.Jstat, \ +)) +$(eval $(call SetupBuildLauncher, jcmd, \ + MAIN_CLASS := sun.tools.jcmd.JCmd, \ +)) diff --git a/jdk/make/launcher/Launcher-jdk.jconsole.gmk b/jdk/make/launcher/Launcher-jdk.jconsole.gmk index 905117cb53b..7c5ada82382 100644 --- a/jdk/make/launcher/Launcher-jdk.jconsole.gmk +++ b/jdk/make/launcher/Launcher-jdk.jconsole.gmk @@ -25,9 +25,10 @@ include LauncherCommon.gmk -BUILD_LAUNCHER_jconsole_CFLAGS_windows := -DJAVAW -BUILD_LAUNCHER_jconsole_LIBS_windows := user32.lib - -$(eval $(call SetupLauncher,jconsole, \ - -DJAVA_ARGS='{ "-J-ms8m"$(COMMA) "-J-Djconsole.showOutputViewer"$(COMMA) "sun.tools.jconsole.JConsole"$(COMMA) }' \ - -DAPP_CLASSPATH='{ "/lib/jconsole.jar"$(COMMA) "/lib/tools.jar"$(COMMA) "/classes" }')) +$(eval $(call SetupBuildLauncher, jconsole, \ + MAIN_CLASS := sun.tools.jconsole.JConsole, \ + JAVA_ARGS := -Djconsole.showOutputViewer, \ + APP_CLASSPATH := /lib/jconsole.jar /lib/tools.jar /classes, \ + CFLAGS_windows := -DJAVAW, \ + LIBS_windows := user32.lib, \ +)) diff --git a/jdk/make/launcher/Launcher-jdk.jdeps.gmk b/jdk/make/launcher/Launcher-jdk.jdeps.gmk index 5448946f93b..6cbcaf47163 100644 --- a/jdk/make/launcher/Launcher-jdk.jdeps.gmk +++ b/jdk/make/launcher/Launcher-jdk.jdeps.gmk @@ -25,12 +25,14 @@ include LauncherCommon.gmk -$(eval $(call SetupLauncher,javap, \ - -DEXPAND_CLASSPATH_WILDCARDS \ - -DNEVER_ACT_AS_SERVER_CLASS_MACHINE \ - -DJAVA_ARGS='{ "-J-ms8m"$(COMMA) "com.sun.tools.javap.Main"$(COMMA) }')) +$(eval $(call SetupBuildLauncher, javap, \ + MAIN_CLASS := com.sun.tools.javap.Main, \ + CFLAGS := -DEXPAND_CLASSPATH_WILDCARDS \ + -DNEVER_ACT_AS_SERVER_CLASS_MACHINE, \ +)) -$(eval $(call SetupLauncher,jdeps, \ - -DEXPAND_CLASSPATH_WILDCARDS \ - -DNEVER_ACT_AS_SERVER_CLASS_MACHINE \ - -DJAVA_ARGS='{ "-J-ms8m"$(COMMA) "com.sun.tools.jdeps.Main"$(COMMA) }')) +$(eval $(call SetupBuildLauncher, jdeps, \ + MAIN_CLASS := com.sun.tools.jdeps.Main, \ + CFLAGS := -DEXPAND_CLASSPATH_WILDCARDS \ + -DNEVER_ACT_AS_SERVER_CLASS_MACHINE, \ +)) diff --git a/jdk/make/launcher/Launcher-jdk.jdi.gmk b/jdk/make/launcher/Launcher-jdk.jdi.gmk index 9d05f255626..acb2a7125ba 100644 --- a/jdk/make/launcher/Launcher-jdk.jdi.gmk +++ b/jdk/make/launcher/Launcher-jdk.jdi.gmk @@ -1,5 +1,5 @@ # -# Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2011, 2015, 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 @@ -25,7 +25,7 @@ include LauncherCommon.gmk -$(eval $(call SetupLauncher,jdb, \ - -DJAVA_ARGS='{ "-J-ms8m"$(COMMA) "com.sun.tools.example.debug.tty.TTY"$(COMMA) }' \ - -DAPP_CLASSPATH='{ "/lib/tools.jar"$(COMMA) "/lib/sa-jdi.jar"$(COMMA) "/classes" }')) - +$(eval $(call SetupBuildLauncher, jdb, \ + MAIN_CLASS := com.sun.tools.example.debug.tty.TTY, \ + APP_CLASSPATH := /lib/tools.jar /lib/sa-jdi.jar /classes, \ +)) diff --git a/jdk/make/launcher/Launcher-jdk.jshell.gmk b/jdk/make/launcher/Launcher-jdk.jshell.gmk index ca1a69d0d67..b03f044c9c3 100644 --- a/jdk/make/launcher/Launcher-jdk.jshell.gmk +++ b/jdk/make/launcher/Launcher-jdk.jshell.gmk @@ -25,7 +25,8 @@ include LauncherCommon.gmk -$(eval $(call SetupLauncher,jshell, \ - -DEXPAND_CLASSPATH_WILDCARDS \ - -DNEVER_ACT_AS_SERVER_CLASS_MACHINE \ - -DJAVA_ARGS='{ "-J-ms8m"$(COMMA) "jdk.internal.jshell.tool.JShellTool"$(COMMA) }')) +$(eval $(call SetupBuildLauncher, jshell, \ + MAIN_CLASS := jdk.internal.jshell.tool.JShellTool, \ + CFLAGS := -DEXPAND_CLASSPATH_WILDCARDS \ + -DNEVER_ACT_AS_SERVER_CLASS_MACHINE, \ +)) diff --git a/jdk/make/launcher/Launcher-jdk.jvmstat.gmk b/jdk/make/launcher/Launcher-jdk.jvmstat.gmk index b93ef16716e..ee0ba2ad61d 100644 --- a/jdk/make/launcher/Launcher-jdk.jvmstat.gmk +++ b/jdk/make/launcher/Launcher-jdk.jvmstat.gmk @@ -1,5 +1,5 @@ # -# Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2011, 2015, 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 @@ -25,6 +25,6 @@ include LauncherCommon.gmk -$(eval $(call SetupLauncher,jstatd, \ - -DJAVA_ARGS='{ "-J-ms8m"$(COMMA) "sun.tools.jstatd.Jstatd"$(COMMA) }')) - +$(eval $(call SetupBuildLauncher, jstatd, \ + MAIN_CLASS := sun.tools.jstatd.Jstatd, \ +)) diff --git a/jdk/make/launcher/Launcher-jdk.pack200.gmk b/jdk/make/launcher/Launcher-jdk.pack200.gmk index 11611623a3b..425363c7856 100644 --- a/jdk/make/launcher/Launcher-jdk.pack200.gmk +++ b/jdk/make/launcher/Launcher-jdk.pack200.gmk @@ -25,8 +25,9 @@ include LauncherCommon.gmk -$(eval $(call SetupLauncher,pack200, \ - -DJAVA_ARGS='{ "-J-ms8m"$(COMMA) "com.sun.java.util.jar.pack.Driver"$(COMMA) }')) +$(eval $(call SetupBuildLauncher, pack200, \ + MAIN_CLASS := com.sun.java.util.jar.pack.Driver, \ +)) ################################################################################ # The order of the object files on the link command line affects the size of the resulting @@ -92,7 +93,7 @@ $(eval $(call SetupNativeCompilation,BUILD_UNPACKEXE, \ $(call SET_SHARED_LIBRARY_ORIGIN), \ LIBS := $(UNPACKEXE_LIBS) $(LIBCXX), \ LIBS_solaris := -lc, \ - OBJECT_DIR := $(SUPPORT_OUTPUTDIR)/native/$(MODULE)/unpackexe$(OUTPUT_SUBDIR), \ + OBJECT_DIR := $(SUPPORT_OUTPUTDIR)/native/$(MODULE)/unpackexe, \ OUTPUT_DIR := $(SUPPORT_OUTPUTDIR)/modules_cmds/$(MODULE), \ PROGRAM := unpack200, \ VERSIONINFO_RESOURCE := $(GLOBAL_VERSION_INFO_RESOURCE), \ diff --git a/jdk/make/launcher/Launcher-jdk.policytool.gmk b/jdk/make/launcher/Launcher-jdk.policytool.gmk index 133e3f612d8..26ec6a4b96a 100644 --- a/jdk/make/launcher/Launcher-jdk.policytool.gmk +++ b/jdk/make/launcher/Launcher-jdk.policytool.gmk @@ -1,5 +1,5 @@ # -# Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2011, 2015, 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 @@ -26,7 +26,8 @@ include LauncherCommon.gmk ifndef BUILD_HEADLESS_ONLY - $(eval $(call SetupLauncher,policytool, \ - -DJAVA_ARGS='{ "-J-ms8m"$(COMMA) "sun.security.tools.policytool.PolicyTool"$(COMMA) }',, \ - $(XLIBS))) + $(eval $(call SetupBuildLauncher, policytool, \ + MAIN_CLASS := sun.security.tools.policytool.PolicyTool, \ + LIBS_unix := $(X_LIBS), \ + )) endif diff --git a/jdk/make/launcher/Launcher-jdk.rmic.gmk b/jdk/make/launcher/Launcher-jdk.rmic.gmk index 2fc8742497c..d60c3d9b60b 100644 --- a/jdk/make/launcher/Launcher-jdk.rmic.gmk +++ b/jdk/make/launcher/Launcher-jdk.rmic.gmk @@ -1,5 +1,5 @@ # -# Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2011, 2015, 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 @@ -25,7 +25,7 @@ include LauncherCommon.gmk -$(eval $(call SetupLauncher,rmic, \ - -DEXPAND_CLASSPATH_WILDCARDS \ - -DJAVA_ARGS='{ "-J-ms8m"$(COMMA) "sun.rmi.rmic.Main"$(COMMA) }')) - +$(eval $(call SetupBuildLauncher, rmic, \ + MAIN_CLASS := sun.rmi.rmic.Main, \ + CFLAGS := -DEXPAND_CLASSPATH_WILDCARDS, \ +)) diff --git a/jdk/make/launcher/Launcher-jdk.scripting.nashorn.shell.gmk b/jdk/make/launcher/Launcher-jdk.scripting.nashorn.shell.gmk index 87353a2d3e9..4b3049cbc09 100644 --- a/jdk/make/launcher/Launcher-jdk.scripting.nashorn.shell.gmk +++ b/jdk/make/launcher/Launcher-jdk.scripting.nashorn.shell.gmk @@ -1,5 +1,5 @@ # -# Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2011, 2015, 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 @@ -25,7 +25,7 @@ include LauncherCommon.gmk -$(eval $(call SetupLauncher,jjs, \ - -DENABLE_ARG_FILES \ - -DJAVA_ARGS='{ "-J-ms8m"$(COMMA) "jdk.nashorn.tools.jjs.Main"$(COMMA) }')) - +$(eval $(call SetupBuildLauncher, jjs, \ + MAIN_CLASS := jdk.nashorn.tools.jjs.Main, \ + CFLAGS := -DENABLE_ARG_FILES, \ +)) diff --git a/jdk/make/launcher/Launcher-jdk.xml.bind.gmk b/jdk/make/launcher/Launcher-jdk.xml.bind.gmk index 5dd0ff0fce4..19ede8880b6 100644 --- a/jdk/make/launcher/Launcher-jdk.xml.bind.gmk +++ b/jdk/make/launcher/Launcher-jdk.xml.bind.gmk @@ -1,5 +1,5 @@ # -# Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2011, 2015, 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 @@ -25,9 +25,10 @@ include LauncherCommon.gmk -$(eval $(call SetupLauncher,schemagen, \ - -DJAVA_ARGS='{ "-J-ms8m"$(COMMA) "com.sun.tools.internal.jxc.SchemaGenerator"$(COMMA) }')) - -$(eval $(call SetupLauncher,xjc, \ - -DJAVA_ARGS='{ "-J-ms8m"$(COMMA) "com.sun.tools.internal.xjc.Driver"$(COMMA) }')) +$(eval $(call SetupBuildLauncher, schemagen, \ + MAIN_CLASS := com.sun.tools.internal.jxc.SchemaGenerator, \ +)) +$(eval $(call SetupBuildLauncher, xjc, \ + MAIN_CLASS := com.sun.tools.internal.xjc.Driver, \ +)) diff --git a/jdk/make/launcher/Launcher-jdk.xml.ws.gmk b/jdk/make/launcher/Launcher-jdk.xml.ws.gmk index 4085ba1a967..9a5bbeff599 100644 --- a/jdk/make/launcher/Launcher-jdk.xml.ws.gmk +++ b/jdk/make/launcher/Launcher-jdk.xml.ws.gmk @@ -1,5 +1,5 @@ # -# Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2011, 2015, 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 @@ -25,9 +25,10 @@ include LauncherCommon.gmk -$(eval $(call SetupLauncher,wsgen, \ - -DJAVA_ARGS='{ "-J-ms8m"$(COMMA) "com.sun.tools.internal.ws.WsGen"$(COMMA) }')) - -$(eval $(call SetupLauncher,wsimport, \ - -DJAVA_ARGS='{ "-J-ms8m"$(COMMA) "com.sun.tools.internal.ws.WsImport"$(COMMA) }')) +$(eval $(call SetupBuildLauncher, wsgen, \ + MAIN_CLASS := com.sun.tools.internal.ws.WsGen, \ +)) +$(eval $(call SetupBuildLauncher, wsimport, \ + MAIN_CLASS := com.sun.tools.internal.ws.WsImport, \ +)) diff --git a/jdk/make/launcher/LauncherCommon.gmk b/jdk/make/launcher/LauncherCommon.gmk index 0065114e687..942224f4697 100644 --- a/jdk/make/launcher/LauncherCommon.gmk +++ b/jdk/make/launcher/LauncherCommon.gmk @@ -28,28 +28,17 @@ include NativeCompilation.gmk # Prepare the find cache. $(eval $(call FillCacheFind, $(JDK_TOPDIR)/src/java.base/share/native/launcher)) -# When building a legacy overlay image (on solaris 64 bit), the launchers -# need to be built with a different rpath and a different output dir. -ifeq ($(OVERLAY_IMAGES), true) - ORIGIN_ROOT := /../.. - OUTPUT_SUBDIR := $(OPENJDK_TARGET_CPU_ISADIR) -else - ORIGIN_ROOT := /.. -endif - ifeq ($(OPENJDK_TARGET_OS), macosx) ORIGIN_ARG := $(call SET_EXECUTABLE_ORIGIN) else - ORIGIN_ARG := $(call SET_EXECUTABLE_ORIGIN,$(ORIGIN_ROOT)/lib$(OPENJDK_TARGET_CPU_LIBDIR)/jli) -endif + ORIGIN_ARG := $(call SET_EXECUTABLE_ORIGIN,/../lib$(OPENJDK_TARGET_CPU_LIBDIR)/jli) -# -# Applications expect to be able to link against libjawt without invoking -# System.loadLibrary("jawt") first. This was the behaviour described in the -# devloper documentation of JAWT and what worked with OpenJDK6. -# -ifneq ($(findstring $(OPENJDK_TARGET_OS), linux solaris), ) - ORIGIN_ARG += $(call SET_EXECUTABLE_ORIGIN,$(ORIGIN_ROOT)/lib$(OPENJDK_TARGET_CPU_LIBDIR)) + # Applications expect to be able to link against libjawt without invoking + # System.loadLibrary("jawt") first. This was the behaviour described in the + # devloper documentation of JAWT and what worked with OpenJDK6. + ifneq ($(findstring $(OPENJDK_TARGET_OS), linux solaris), ) + ORIGIN_ARG += $(call SET_EXECUTABLE_ORIGIN,/../lib$(OPENJDK_TARGET_CPU_LIBDIR)) + endif endif LAUNCHER_SRC := $(JDK_TOPDIR)/src/java.base/share/native/launcher @@ -61,51 +50,78 @@ LAUNCHER_CFLAGS := -I$(JDK_TOPDIR)/src/java.base/share/native/launcher \ GLOBAL_VERSION_INFO_RESOURCE := $(JDK_TOPDIR)/src/java.base/windows/native/common/version.rc JAVA_VERSION_INFO_RESOURCE := $(JDK_TOPDIR)/src/java.base/windows/native/launcher/java.rc MACOSX_PLIST_DIR := $(JDK_TOPDIR)/src/java.base/macosx/native/launcher -# Until the shuffle is permanent, we can't add this in configure -CFLAGS_JDKEXE := $(filter-out %javavm/export, $(CFLAGS_JDKEXE)) -CFLAGS_JDKEXE += -I$(JDK_TOPDIR)/src/java.base/share/native/include \ - -I$(JDK_TOPDIR)/src/java.base/$(OPENJDK_TARGET_OS_TYPE)/native/include -CXXFLAGS_JDKEXE := $(filter-out %javavm/export, $(CXXFLAGS_JDKEXE)) -CXXFLAGS_JDKEXE += -I$(JDK_TOPDIR)/src/java.base/share/native/include \ - -I$(JDK_TOPDIR)/src/java.base/$(OPENJDK_TARGET_OS_TYPE)/native/include JAVA_MANIFEST := $(JDK_TOPDIR)/src/java.base/windows/native/launcher/java.manifest -define SetupLauncher - # TODO: Fix mapfile on solaris. Won't work with ld as linker. - # Parameter 1 is the name of the launcher (java, javac, jar...) - # Parameter 2 is extra CFLAGS - # Parameter 3 is extra LDFLAGS - # Parameter 4 is extra LIBS_unix - # Parameter 5 is extra LIBS_windows - # Parameter 6 is optional Windows JLI library (full path) - # Parameter 7 is optional Windows resource (RC) flags - # Parameter 8 is optional Windows version resource file (.rc) - # Parameter 9 is different output dir - # Parameter 10 if set, link statically with c runtime on windows. - # Parameter 11 if set, override plist file on macosx. - $(call LogSetupMacroEntry,SetupLauncher($1),$2,$3,$4,$5,$6,$7,$8,$9,$(10),$(11)) - $(if $(13),$(error Internal makefile error: Too many arguments to SetupLauncher, please update CompileLaunchers.gmk)) +################################################################################ +# Build standard launcher. - $1_WINDOWS_JLI_LIB := $(SUPPORT_OUTPUTDIR)/native/java.base/libjli/jli.lib - ifneq ($6, ) - $1_WINDOWS_JLI_LIB := $6 - endif - $1_VERSION_INFO_RESOURCE := $(GLOBAL_VERSION_INFO_RESOURCE) - ifneq ($8, ) - $1_VERSION_INFO_RESOURCE := $8 +# Setup make rules for building a standard launcher. +# +# Parameter 1 is the name of the rule. This name is used as variable prefix, +# and the targets generated are listed in a variable by that name. It is also +# used as the name of the executable. +# +# Remaining parameters are named arguments. These include: +# MAIN_CLASS The Java main class to launch +# JAVA_ARGS Processed into a -DJAVA_ARGS C flag +# APP_CLASSPATH Processed into a -DAPP_CLASSPATH C flag +# CFLAGS Additional CFLAGS +# CFLAGS_windows Additional CFLAGS_windows +# LIBS_unix Additional LIBS_unix +# LIBS_windows Additional LIBS_windows +# LDFLAGS_solaris Additional LDFLAGS_solaris +# RC_FLAGS Additional RC_FLAGS +# MACOSX_SIGNED On macosx, sign this binary +# WINDOWS_STATIC_LINK On windows, link statically with C runtime and libjli. +# OPTIMIZATION Override default optimization level (LOW) +# OUTPUT_DIR Override default output directory +# VERSION_INFO_RESOURCE Override default Windows resource file +# NO_JAVA_MS Do not add -ms8m to JAVA_ARGS. +SetupBuildLauncher = $(NamedParamsMacroTemplate) +define SetupBuildLauncherBody + # Setup default values (unless overridden) + ifeq ($$($1_VERSION_INFO_RESOURCE), ) + $1_VERSION_INFO_RESOURCE := $(GLOBAL_VERSION_INFO_RESOURCE) + endif + + ifeq ($$($1_OUTPUT_DIR), ) + $1_OUTPUT_DIR := $(SUPPORT_OUTPUTDIR)/modules_cmds/$(MODULE) + endif + + ifeq ($$($1_OPTIMIZATION), ) + $1_OPTIMIZATION := LOW + endif + + ifneq ($$($1_NO_JAVA_MS), true) + # The norm is to append -ms8m, unless otherwise instructed. + $1_JAVA_ARGS += -ms8m + endif + + ifneq ($$($1_JAVA_ARGS), ) + $1_JAVA_ARGS_STR := '{ $$(strip $$(foreach a, \ + $$(addprefix -J, $$($1_JAVA_ARGS)) $$($1_MAIN_CLASS), "$$a"$(COMMA) )) }' + $1_CFLAGS += -DJAVA_ARGS=$$($1_JAVA_ARGS_STR) + endif + + ifneq ($$($1_APP_CLASSPATH), ) + $1_APP_CLASSPATH_STR := '{ $$(strip $$(foreach a, \ + $$($1_APP_CLASSPATH), "$$a"$(COMMA) )) }' + # Remove the trailing comma + $1_APP_CLASSPATH_STR := $$(strip $$(subst $$(COMMA) }', }', \ + $$($1_APP_CLASSPATH_STR))) + $1_CFLAGS += -DAPP_CLASSPATH=$$($1_APP_CLASSPATH_STR) endif - $1_LDFLAGS := $3 $1_LIBS := ifeq ($(OPENJDK_TARGET_OS), macosx) - $1_PLIST_FILE := Info-cmdline.plist - ifneq ($(11), ) - $1_PLIST_FILE := $(11) - ifneq ($$(findstring privileged, $$($1_PLIST_FILE)), ) + ifeq ($$($1_MACOSX_SIGNED), true) + $1_PLIST_FILE := Info-privileged.plist $1_CODESIGN := true - endif + else + $1_PLIST_FILE := Info-cmdline.plist endif + $1_CFLAGS += -DPACKAGE_PATH='"$(PACKAGE_PATH)"' $1_LDFLAGS += -Wl,-all_load $(SUPPORT_OUTPUTDIR)/native/java.base/libjli_static.a \ -sectcreate __TEXT __info_plist $(MACOSX_PLIST_DIR)/$$($1_PLIST_FILE) $1_LIBS += -framework Cocoa -framework Security \ @@ -121,22 +137,12 @@ define SetupLauncher $1_LIBS += -lz endif - $1_OUTPUT_DIR_ARG := $9 - ifeq (, $$($1_OUTPUT_DIR_ARG)) - $1_OUTPUT_DIR_ARG := $(SUPPORT_OUTPUTDIR)/modules_cmds/$(MODULE) - endif - - # TODO: maybe it's better to move this if-statement out of this function - ifeq ($1, java) - $1_OPTIMIZATION_ARG := HIGH - $1_LDFLAGS_solaris := -R$(OPENWIN_HOME)/lib$(OPENJDK_TARGET_CPU_ISADIR) + ifeq ($$($1_WINDOWS_STATIC_LINK), true) + $1_CFLAGS += $(filter-out -MD, $(CFLAGS_JDKEXE)) + $1_WINDOWS_JLI_LIB := $(SUPPORT_OUTPUTDIR)/native/java.base/jli_static.lib else - $1_OPTIMIZATION_ARG := LOW - endif - - $1_CFLAGS := $(CFLAGS_JDKEXE) - ifeq ($(10), true) - $1_CFLAGS := $(filter-out -MD, $(CFLAGS_JDKEXE)) + $1_CFLAGS += $(CFLAGS_JDKEXE) + $1_WINDOWS_JLI_LIB := $(SUPPORT_OUTPUTDIR)/native/java.base/libjli/jli.lib endif # The linker on older SuSE distros (e.g. on SLES 10) complains with: @@ -156,22 +162,23 @@ define SetupLauncher endif endif - $(call SetupNativeCompilation,BUILD_LAUNCHER_$1, \ + $$(eval $$(call SetupNativeCompilation, BUILD_LAUNCHER_$1, \ SRC := $(LAUNCHER_SRC), \ INCLUDE_FILES := main.c, \ - OPTIMIZATION := $$($1_OPTIMIZATION_ARG), \ + OPTIMIZATION := $$($1_OPTIMIZATION), \ CFLAGS := $$($1_CFLAGS) \ $(LAUNCHER_CFLAGS) \ -DFULL_VERSION='"$(FULL_VERSION)"' \ -DJDK_MAJOR_VERSION='"$(JDK_MAJOR_VERSION)"' \ -DJDK_MINOR_VERSION='"$(JDK_MINOR_VERSION)"' \ -DLAUNCHER_NAME='"$(LAUNCHER_NAME)"' \ - -DPROGNAME='"$1"' $(DPACKAGEPATH) \ - $2, \ + -DPROGNAME='"$1"' \ + $$($1_CFLAGS), \ CFLAGS_linux := -fPIC, \ CFLAGS_solaris := -KPIC -DHAVE_GETHRTIME, \ + CFLAGS_windows := $$($1_CFLAGS_windows), \ LDFLAGS := $(LDFLAGS_JDKEXE) \ - $(ORIGIN_ARG) \ + $$(ORIGIN_ARG) \ $$($1_LDFLAGS), \ LDFLAGS_linux := \ $(call SET_SHARED_LIBRARY_NAME,$(LIBRARY_PREFIX)$(SHARED_LIBRARY_SUFFIX)) \ @@ -182,27 +189,29 @@ define SetupLauncher -L$(SUPPORT_OUTPUTDIR)/modules_libs/java.base$(OPENJDK_TARGET_CPU_LIBDIR)/jli, \ MAPFILE := $$($1_MAPFILE), \ LIBS := $(JDKEXE_LIBS) $$($1_LIBS), \ - LIBS_unix := $4, \ + LIBS_unix := $$($1_LIBS_unix), \ LIBS_linux := -lpthread -ljli $(LIBDL) -lc, \ LIBS_solaris := -ljli -lthread $(LIBDL) -lc, \ LIBS_windows := $$($1_WINDOWS_JLI_LIB) \ - $(SUPPORT_OUTPUTDIR)/native/java.base/libjava/java.lib advapi32.lib $5, \ - OBJECT_DIR := $(SUPPORT_OUTPUTDIR)/native/$(MODULE)/$1_objs$(OUTPUT_SUBDIR), \ - OUTPUT_DIR := $$($1_OUTPUT_DIR_ARG)$(OUTPUT_SUBDIR), \ + $(SUPPORT_OUTPUTDIR)/native/java.base/libjava/java.lib advapi32.lib \ + $$($1_LIBS_windows), \ + OBJECT_DIR := $(SUPPORT_OUTPUTDIR)/native/$(MODULE)/$1_objs, \ + OUTPUT_DIR := $$($1_OUTPUT_DIR), \ PROGRAM := $1, \ DEBUG_SYMBOLS := true, \ VERSIONINFO_RESOURCE := $$($1_VERSION_INFO_RESOURCE), \ - RC_FLAGS := $(RC_FLAGS) \ + RC_FLAGS := $$(RC_FLAGS) \ -D "JDK_FNAME=$1$(EXE_SUFFIX)" \ -D "JDK_INTERNAL_NAME=$1" \ -D "JDK_FTYPE=0x1L" \ - $7, \ + $$($1_RC_FLAGS), \ MANIFEST := $(JAVA_MANIFEST), \ MANIFEST_VERSION := $(JDK_VERSION_FOR_MANIFEST), \ CODESIGN := $$($1_CODESIGN), \ - ) + )) - TARGETS += $$(BUILD_LAUNCHER_$1) + $1 += $$(BUILD_LAUNCHER_$1) + TARGETS += $$($1) ifneq (,$(filter $(OPENJDK_TARGET_OS), macosx aix)) $$(BUILD_LAUNCHER_$1): $(SUPPORT_OUTPUTDIR)/native/java.base/libjli_static.a @@ -213,18 +222,3 @@ define SetupLauncher $$($1_WINDOWS_JLI_LIB) endif endef - -########################################################################################## - -XLIBS := $(X_LIBS) -lX11 -ifeq ($(OPENJDK_TARGET_OS), macosx) - DPACKAGEPATH := -DPACKAGE_PATH='"$(PACKAGE_PATH)"' - XLIBS := -endif - -JAVA_RC_FLAGS += -i $(JDK_TOPDIR)/src/java.base/windows/native/common -ifdef OPENJDK - JAVA_RC_FLAGS += -i "$(JDK_TOPDIR)/src/java.base/windows/native/launcher/icons" -else - JAVA_RC_FLAGS += -i "$(JDK_TOPDIR)/src/closed/java.base/windows/native/launcher/icons" -endif From f10554d7c202f35164edd1324bba3c4db70c6789 Mon Sep 17 00:00:00 2001 From: Lance Andersen Date: Thu, 5 Nov 2015 10:37:08 -0500 Subject: [PATCH 40/43] 8136496: Add Connection.begin/endRequest Reviewed-by: joehw, rriggs, psandoz --- .../share/classes/java/sql/Connection.java | 107 +++++++++++++++++- .../classes/javax/sql/PooledConnection.java | 13 ++- 2 files changed, 117 insertions(+), 3 deletions(-) diff --git a/jdk/src/java.sql/share/classes/java/sql/Connection.java b/jdk/src/java.sql/share/classes/java/sql/Connection.java index ac5d3158b6e..880c2cb3904 100644 --- a/jdk/src/java.sql/share/classes/java/sql/Connection.java +++ b/jdk/src/java.sql/share/classes/java/sql/Connection.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2015, 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 @@ -1482,4 +1482,109 @@ throws SQLException; * @since 1.7 */ int getNetworkTimeout() throws SQLException; + + // JDBC 4.3 + + /** + * Hints to the driver that a request, an independent unit of work, is beginning + * on this connection. Each request is independent of all other requests + * with regard to state local to the connection either on the client or the + * server. Work done between {@code beginRequest}, {@code endRequest} + * pairs does not depend on any other work done on the connection either as + * part of another request or outside of any request. A request may include multiple + * transactions. There may be dependencies on committed database state as + * that is not local to the connection. + *

    + * Local state is defined as any state associated with a Connection that is + * local to the current Connection either in the client or the database that + * is not transparently reproducible. + *

    + * Calls to {@code beginRequest} and {@code endRequest} are not nested. + * Multiple calls to {@code beginRequest} without an intervening call + * to {@code endRequest} is not an error. The first {@code beginRequest} call + * marks the start of the request and subsequent calls are treated as + * a no-op + *

    + * Use of {@code beginRequest} and {@code endRequest} is optional, vendor + * specific and should largely be transparent. In particular + * implementations may detect conditions that indicate dependence on + * other work such as an open transaction. It is recommended though not + * required that implementations throw a {@code SQLException} if there is an active + * transaction and {@code beginRequest} is called. + * Using these methods may improve performance or provide other benefits. + * Consult your vendors documentation for additional information. + *

    + * It is recommended to + * enclose each unit of work in {@code beginRequest}, {@code endRequest} + * pairs such that there is no open transaction at the beginning or end of + * the request and no dependency on local state that crosses request + * boundaries. Committed database state is not local. + * + * @implSpec + * The default implementation is a no-op. + *

    + * @apiNote + * This method is to be used by Connection pooling managers. + *

    + * The pooling manager should call {@code beginRequest} on the underlying connection + * prior to returning a connection to the caller. + *

    + * The pooling manager does not need to call {@code beginRequest} if: + *

      + *
    • The connection pool caches {@code PooledConnection} objects
    • + *
    • Returns a logical connection handle when {@code getConnection} is + * called by the application
    • + *
    • The pool manager calls {@code Connection.close} on the logical connection handle + * prior to returning the {@code PooledConnection} back to the cache
    • + *
    + * @throws SQLException if an error occurs + * @since 1.9 + * @see endRequest + * @see PooledConnection + */ + default void beginRequest() throws SQLException { + // Default method takes no action + } + + /** + * Hints to the driver that a request, an independent unit of work, + * has completed. Calls to {@code beginRequest} + * and {@code endRequest} are not nested. Multiple + * calls to {@code endRequest} without an intervening call to {@code beginRequest} + * is not an error. The first {@code endRequest} call + * marks the request completed and subsequent calls are treated as + * a no-op. If {@code endRequest} is called without an initial call to + * {@code beginRequest} is a no-op. + *

    + * The exact behavior of this method is vendor specific. In particular + * implementations may detect conditions that indicate dependence on + * other work such as an open transaction. It is recommended though not + * required that implementations throw a {@code SQLException} if there is an active + * transaction and {@code endRequest} is called. + * + * @implSpec + * The default implementation is a no-op. + * @apiNote + * + * This method is to be used by Connection pooling managers. + *

    + * The pooling manager should call {@code endRequest} on the underlying connection + * when the applications returns the connection back to the connection pool. + * + *

  • The connection pool caches {@code PooledConnection} objects
  • + *
  • Returns a logical connection handle when {@code getConnection} is + * called by the application
  • + *
  • The pool manager calls {@code Connection.close} on the logical connection handle + * prior to returning the {@code PooledConnection} back to the cache
  • + * + * @throws SQLException if an error occurs + * @since 1.9 + * @see beginRequest + * @see PooledConnection + */ + default void endRequest() throws SQLException { + // Default method takes no action + } } diff --git a/jdk/src/java.sql/share/classes/javax/sql/PooledConnection.java b/jdk/src/java.sql/share/classes/javax/sql/PooledConnection.java index c16e73bdeec..50b0acd85d2 100644 --- a/jdk/src/java.sql/share/classes/javax/sql/PooledConnection.java +++ b/jdk/src/java.sql/share/classes/javax/sql/PooledConnection.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2015, 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 @@ -66,7 +66,16 @@ import java.sql.SQLException; * PooledConnection object to the pool of connections so that * it can be used again. Thus, when an application closes its connection, * the underlying physical connection is recycled rather than being closed. - *

    + *

    + * If the connection pool manager wraps or provides a proxy to the logical + * handle returned from a call to {@code PoolConnection.getConnection}, the pool + * manager must do + * one of the following when the application calls {@code Connection.close}: + *

      + *
    • call {@code endRequest} on the logical {@code Connection} handle + *
    • call {@code close} on the logical {@code Connection} handle + *
    + *

    * The physical connection is not closed until the connection pool manager * calls the PooledConnection method close. * This method is generally called to have an orderly shutdown of the server or From 6f0997408acdbaea73ca07b82226211f9afd8579 Mon Sep 17 00:00:00 2001 From: Claes Redestad Date: Thu, 5 Nov 2015 16:29:16 +0100 Subject: [PATCH 41/43] 8141539: Avoid calculating string constants in InnerClassLambdaMetaFactory Reviewed-by: vlivanov --- .../lang/invoke/InnerClassLambdaMetafactory.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/jdk/src/java.base/share/classes/java/lang/invoke/InnerClassLambdaMetafactory.java b/jdk/src/java.base/share/classes/java/lang/invoke/InnerClassLambdaMetafactory.java index 69d80ec0e61..5f821977c0f 100644 --- a/jdk/src/java.base/share/classes/java/lang/invoke/InnerClassLambdaMetafactory.java +++ b/jdk/src/java.base/share/classes/java/lang/invoke/InnerClassLambdaMetafactory.java @@ -66,15 +66,15 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*; private static final String NAME_METHOD_WRITE_REPLACE = "writeReplace"; private static final String NAME_METHOD_READ_OBJECT = "readObject"; private static final String NAME_METHOD_WRITE_OBJECT = "writeObject"; + + private static final String DESCR_CLASS = "Ljava/lang/Class;"; + private static final String DESCR_STRING = "Ljava/lang/String;"; + private static final String DESCR_OBJECT = "Ljava/lang/Object;"; private static final String DESCR_CTOR_SERIALIZED_LAMBDA - = MethodType.methodType(void.class, - Class.class, - String.class, String.class, String.class, - int.class, String.class, String.class, String.class, - String.class, - Object[].class).toMethodDescriptorString(); - private static final String DESCR_CTOR_NOT_SERIALIZABLE_EXCEPTION - = MethodType.methodType(void.class, String.class).toMethodDescriptorString(); + = "(" + DESCR_CLASS + DESCR_STRING + DESCR_STRING + DESCR_STRING + "I" + + DESCR_STRING + DESCR_STRING + DESCR_STRING + DESCR_STRING + "[" + DESCR_OBJECT + ")V"; + + private static final String DESCR_CTOR_NOT_SERIALIZABLE_EXCEPTION = "(Ljava/lang/String;)V"; private static final String[] SER_HOSTILE_EXCEPTIONS = new String[] {NAME_NOT_SERIALIZABLE_EXCEPTION}; From 05e8afd0ef6e7fe1f2c66a7b6c8a3317d51081d2 Mon Sep 17 00:00:00 2001 From: Claes Redestad Date: Thu, 5 Nov 2015 16:36:55 +0100 Subject: [PATCH 42/43] 8141536: MethodType field offset calculation could be lazy Reviewed-by: vlivanov --- .../classes/java/lang/invoke/MethodType.java | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/jdk/src/java.base/share/classes/java/lang/invoke/MethodType.java b/jdk/src/java.base/share/classes/java/lang/invoke/MethodType.java index 1a986a4bf64..7f77c5e84ad 100644 --- a/jdk/src/java.base/share/classes/java/lang/invoke/MethodType.java +++ b/jdk/src/java.base/share/classes/java/lang/invoke/MethodType.java @@ -1187,20 +1187,23 @@ s.writeObject(this.parameterArray()); // store them into the implementation-specific final fields. checkRtype(rtype); checkPtypes(ptypes); - UNSAFE.putObject(this, rtypeOffset, rtype); - UNSAFE.putObject(this, ptypesOffset, ptypes); + UNSAFE.putObject(this, OffsetHolder.rtypeOffset, rtype); + UNSAFE.putObject(this, OffsetHolder.ptypesOffset, ptypes); } - // Support for resetting final fields while deserializing - private static final long rtypeOffset, ptypesOffset; - static { - try { - rtypeOffset = UNSAFE.objectFieldOffset - (MethodType.class.getDeclaredField("rtype")); - ptypesOffset = UNSAFE.objectFieldOffset - (MethodType.class.getDeclaredField("ptypes")); - } catch (Exception ex) { - throw new Error(ex); + // Support for resetting final fields while deserializing. Implement Holder + // pattern to make the rarely needed offset calculation lazy. + private static class OffsetHolder { + private static final long rtypeOffset, ptypesOffset; + static { + try { + rtypeOffset = UNSAFE.objectFieldOffset + (MethodType.class.getDeclaredField("rtype")); + ptypesOffset = UNSAFE.objectFieldOffset + (MethodType.class.getDeclaredField("ptypes")); + } catch (Exception ex) { + throw new Error(ex); + } } } From c00f85ddb188e2860707a250870102339735ed93 Mon Sep 17 00:00:00 2001 From: Lance Andersen Date: Thu, 5 Nov 2015 14:57:27 -0500 Subject: [PATCH 43/43] 8141546: Fix javadoc warnings in Connection due to 8136496 Reviewed-by: alanb --- jdk/src/java.sql/share/classes/java/sql/Connection.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/jdk/src/java.sql/share/classes/java/sql/Connection.java b/jdk/src/java.sql/share/classes/java/sql/Connection.java index 880c2cb3904..40aa3de0730 100644 --- a/jdk/src/java.sql/share/classes/java/sql/Connection.java +++ b/jdk/src/java.sql/share/classes/java/sql/Connection.java @@ -1540,7 +1540,7 @@ throws SQLException; * @throws SQLException if an error occurs * @since 1.9 * @see endRequest - * @see PooledConnection + * @see javax.sql.PooledConnection */ default void beginRequest() throws SQLException { // Default method takes no action @@ -1570,7 +1570,7 @@ throws SQLException; *

    * The pooling manager should call {@code endRequest} on the underlying connection * when the applications returns the connection back to the connection pool. - * * The pooling manager does not need to call {@code endRequest} if: *

      *
    • The connection pool caches {@code PooledConnection} objects
    • @@ -1582,7 +1582,7 @@ throws SQLException; * @throws SQLException if an error occurs * @since 1.9 * @see beginRequest - * @see PooledConnection + * @see javax.sql.PooledConnection */ default void endRequest() throws SQLException { // Default method takes no action